AGESA F15: AMD family15 AGESA code
[coreboot.git] / src / vendorcode / amd / agesa / f15 / Proc / CPU / Feature / cpuCpb.c
1 /* $NoKeywords:$ */
2 /**
3  * @file
4  *
5  * AMD AGESA CPU Core performance boost feature support code.
6  *
7  * Contains code that declares the AGESA CPU CPB related APIs
8  *
9  * @xrefitem bom "File Content Label" "Release Content"
10  * @e project:      AGESA
11  * @e sub-project:  CPU/Feature
12  * @e \$Revision: 56279 $   @e \$Date: 2011-07-11 13:11:28 -0600 (Mon, 11 Jul 2011) $
13  *
14  */
15 /*
16  ******************************************************************************
17  *
18  * Copyright (C) 2012 Advanced Micro Devices, Inc.
19  * All rights reserved.
20  *
21  * Redistribution and use in source and binary forms, with or without
22  * modification, are permitted provided that the following conditions are met:
23  *     * Redistributions of source code must retain the above copyright
24  *       notice, this list of conditions and the following disclaimer.
25  *     * Redistributions in binary form must reproduce the above copyright
26  *       notice, this list of conditions and the following disclaimer in the
27  *       documentation and/or other materials provided with the distribution.
28  *     * Neither the name of Advanced Micro Devices, Inc. nor the names of
29  *       its contributors may be used to endorse or promote products derived
30  *       from this software without specific prior written permission.
31  *
32  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
33  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
34  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
35  * DISCLAIMED. IN NO EVENT SHALL ADVANCED MICRO DEVICES, INC. BE LIABLE FOR ANY
36  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
37  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
38  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
39  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
40  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
41  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42  *
43  ******************************************************************************
44  */
45
46 /*----------------------------------------------------------------------------------------
47  *                             M O D U L E S    U S E D
48  *----------------------------------------------------------------------------------------
49  */
50 #include "AGESA.h"
51 #include "cpuFamilyTranslation.h"
52 #include "cpuFeatures.h"
53 #include "cpuCpb.h"
54 #include "Filecode.h"
55 CODE_GROUP (G1_PEICC)
56 RDATA_GROUP (G2_PEI)
57
58 #define FILECODE PROC_CPU_FEATURE_CPUCPB_FILECODE
59
60 /*----------------------------------------------------------------------------------------
61  *                   D E F I N I T I O N S    A N D    M A C R O S
62  *----------------------------------------------------------------------------------------
63  */
64
65 /*----------------------------------------------------------------------------------------
66  *                  T Y P E D E F S     A N D     S T R U C T U  R E S
67  *----------------------------------------------------------------------------------------
68  */
69
70 /*----------------------------------------------------------------------------------------
71  *           P R O T O T Y P E S     O F     L O C A L     F U  N C T I O N S
72  *----------------------------------------------------------------------------------------
73  */
74
75 /*----------------------------------------------------------------------------------------
76  *                          E X P O R T E D    F U N C T I O N S
77  *----------------------------------------------------------------------------------------
78  */
79 extern CPU_FAMILY_SUPPORT_TABLE CpbFamilyServiceTable;
80
81 /*---------------------------------------------------------------------------------------*/
82 /**
83  *  Should CPB be enabled
84  *
85  * @param[in]    PlatformConfig     Contains the runtime modifiable feature input data.
86  * @param[in]    StdHeader          Config Handle for library, services.
87  *
88  * @retval       TRUE               CPB is supported.
89  * @retval       FALSE              CPB cannot be enabled.
90  *
91  */
92 BOOLEAN
93 STATIC
94 IsCpbFeatureEnabled (
95   IN       PLATFORM_CONFIGURATION *PlatformConfig,
96   IN       AMD_CONFIG_PARAMS      *StdHeader
97   )
98 {
99   UINT32              Socket;
100   BOOLEAN             IsEnabled;
101   CPB_FAMILY_SERVICES *FamilyServices;
102
103   IsEnabled = FALSE;
104
105   ASSERT (PlatformConfig->CpbMode < MaxCpbMode);
106
107   if (PlatformConfig->CpbMode == CpbModeAuto) {
108     for (Socket = 0; Socket < GetPlatformNumberOfSockets (); Socket++) {
109       if (IsProcessorPresent (Socket, StdHeader)) {
110         GetFeatureServicesOfSocket (&CpbFamilyServiceTable, Socket, (CONST VOID **)&FamilyServices, StdHeader);
111         if (FamilyServices != NULL) {
112           if (FamilyServices->IsCpbSupported (FamilyServices, PlatformConfig, Socket, StdHeader)) {
113             IsEnabled = TRUE;
114             break;
115           }
116         }
117       }
118     }
119   }
120   return IsEnabled;
121 }
122
123 /*---------------------------------------------------------------------------------------*/
124 /**
125  *  Enable core performance boost
126  *
127  * @param[in]    EntryPoint         Timepoint designator.
128  * @param[in]    PlatformConfig     Contains the runtime modifiable feature input data.
129  * @param[in]    StdHeader          Config Handle for library, services.
130  *
131  * @retval       AGESA_SUCCESS      Always succeeds.
132  *
133  */
134 AGESA_STATUS
135 STATIC
136 InitializeCpbFeature (
137   IN       UINT64                 EntryPoint,
138   IN       PLATFORM_CONFIGURATION *PlatformConfig,
139   IN       AMD_CONFIG_PARAMS      *StdHeader
140   )
141 {
142   UINT32              Socket;
143   AGESA_STATUS        AgesaStatus;
144   AGESA_STATUS        CalledStatus;
145   CPB_FAMILY_SERVICES *FamilyServices;
146
147   AgesaStatus = AGESA_SUCCESS;
148   CalledStatus = AGESA_SUCCESS;
149
150   IDS_HDT_CONSOLE (CPU_TRACE, "    Boost is enabled\n");
151
152   for (Socket = 0; Socket < GetPlatformNumberOfSockets (); Socket++) {
153     if (IsProcessorPresent (Socket, StdHeader)) {
154       GetFeatureServicesOfSocket (&CpbFamilyServiceTable, Socket, (CONST VOID **)&FamilyServices, StdHeader);
155       if (FamilyServices != NULL) {
156         if (FamilyServices->IsCpbSupported (FamilyServices, PlatformConfig, Socket, StdHeader)) {
157           CalledStatus = FamilyServices->EnableCpbOnSocket (FamilyServices, PlatformConfig, EntryPoint, Socket, StdHeader);
158           if (CalledStatus > AgesaStatus) {
159             AgesaStatus = CalledStatus;
160           }
161         }
162       }
163     }
164   }
165
166   return AgesaStatus;
167 }
168
169
170 CONST CPU_FEATURE_DESCRIPTOR ROMDATA CpuFeatureCpb =
171 {
172   CoreBoost,
173   (CPU_FEAT_BEFORE_PM_INIT | CPU_FEAT_AFTER_PM_INIT | CPU_FEAT_INIT_LATE_END | CPU_FEAT_AFTER_POST_MTRR_SYNC | CPU_FEAT_S3_LATE_RESTORE_END | CPU_FEAT_AFTER_RESUME_MTRR_SYNC),
174   IsCpbFeatureEnabled,
175   InitializeCpbFeature
176 };