AGESA F15: AMD family15 AGESA code
[coreboot.git] / src / vendorcode / amd / agesa / f15 / Proc / CPU / Family / 0x15 / OR / F15OrCpb.c
1 /* $NoKeywords:$ */
2 /**
3  * @file
4  *
5  * AMD Family_15 CPB Initialization
6  *
7  * Enables core performance boost.
8  *
9  * @xrefitem bom "File Content Label" "Release Content"
10  * @e project:      AGESA
11  * @e sub-project:  CPU/F15/OR
12  * @e \$Revision: 54493 $   @e \$Date: 2011-06-08 15:21:06 -0600 (Wed, 08 Jun 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 "amdlib.h"
52 #include "GeneralServices.h"
53 #include "cpuFamilyTranslation.h"
54 #include "cpuF15PowerMgmt.h"
55 #include "cpuF15OrPowerMgmt.h"
56 #include "cpuFeatures.h"
57 #include "cpuCpb.h"
58 #include "F15PackageType.h"
59 #include "OptionFamily15hEarlySample.h"
60 #include "Filecode.h"
61 CODE_GROUP (G3_DXE)
62 RDATA_GROUP (G3_DXE)
63
64 #define FILECODE PROC_CPU_FAMILY_0X15_OR_F15ORCPB_FILECODE
65
66 /*----------------------------------------------------------------------------------------
67  *                   D E F I N I T I O N S    A N D    M A C R O S
68  *----------------------------------------------------------------------------------------
69  */
70 extern F15_OR_ES_CPB_SUPPORT F15OrEarlySampleCpbSupport;
71 /*----------------------------------------------------------------------------------------
72  *                  T Y P E D E F S     A N D     S T R U C T U R E S
73  *----------------------------------------------------------------------------------------
74  */
75
76 /*----------------------------------------------------------------------------------------
77  *           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
78  *----------------------------------------------------------------------------------------
79  */
80
81 /*----------------------------------------------------------------------------------------
82  *                          E X P O R T E D    F U N C T I O N S
83  *----------------------------------------------------------------------------------------
84  */
85
86 /*---------------------------------------------------------------------------------------*/
87 /**
88  * BSC entry point for checking whether or not CPB is supported.
89  *
90  * @param[in]  CpbServices             The current CPU's family services.
91  * @param[in]  PlatformConfig          Contains the runtime modifiable feature input data.
92  * @param[in]  Socket                  Zero based socket number to check.
93  * @param[in]  StdHeader               Config handle for library and services.
94  *
95  * @retval     TRUE                    CPB is supported.
96  * @retval     FALSE                   CPB is not supported.
97  *
98  */
99 BOOLEAN
100 STATIC
101 F15OrIsCpbSupported (
102   IN       CPB_FAMILY_SERVICES    *CpbServices,
103   IN       PLATFORM_CONFIGURATION *PlatformConfig,
104   IN       UINT32                 Socket,
105   IN       AMD_CONFIG_PARAMS      *StdHeader
106   )
107 {
108   UINT32       CpbControl;
109   PCI_ADDR     PciAddress;
110   AGESA_STATUS IgnoredSts;
111   BOOLEAN  IsEnabled;
112
113   IsEnabled = TRUE;
114
115   GetPciAddress (StdHeader, Socket, 0, &PciAddress, &IgnoredSts);
116   PciAddress.Address.Function = FUNC_4;
117   PciAddress.Address.Register = CPB_CTRL_REG;
118   LibAmdPciRead (AccessWidth32, PciAddress, &CpbControl, StdHeader);
119   IsEnabled = (BOOLEAN) (((CPB_CTRL_REGISTER *) (&CpbControl))->NumBoostStates != 0);
120
121   F15OrEarlySampleCpbSupport.F15OrIsCpbSupportedHook (&IsEnabled, StdHeader);
122
123   return IsEnabled;
124 }
125
126
127 /*---------------------------------------------------------------------------------------*/
128 /**
129  * BSC entry point for for enabling Core Performance Boost.
130  *
131  * Set up D18F4x15C[BoostSrc] and start the PDMs according to the BKDG.
132  *
133  * @param[in]  CpbServices             The current CPU's family services.
134  * @param[in]  PlatformConfig          Contains the runtime modifiable feature input data.
135  * @param[in]  EntryPoint              Current CPU feature dispatch point.
136  * @param[in]  Socket                  Zero based socket number to check.
137  * @param[in]  StdHeader               Config handle for library and services.
138  *
139  * @retval     AGESA_SUCCESS           Always succeeds.
140  *
141  */
142 AGESA_STATUS
143 STATIC
144 F15OrInitializeCpb (
145   IN       CPB_FAMILY_SERVICES    *CpbServices,
146   IN       PLATFORM_CONFIGURATION *PlatformConfig,
147   IN       UINT64                 EntryPoint,
148   IN       UINT32                 Socket,
149   IN       AMD_CONFIG_PARAMS      *StdHeader
150   )
151 {
152   UINT32       CpbControl;
153   UINT32       Module;
154   UINT32       PackageType;
155   PCI_ADDR     PciAddress;
156   AGESA_STATUS IgnoredSts;
157
158   if ((EntryPoint & (CPU_FEAT_BEFORE_PM_INIT | CPU_FEAT_INIT_LATE_END | CPU_FEAT_S3_LATE_RESTORE_END)) != 0) {
159     for (Module = 0; Module < (UINT8)GetPlatformNumberOfModules (); Module++) {
160       PackageType = LibAmdGetPackageType (StdHeader);
161       GetPciAddress (StdHeader, Socket, Module, &PciAddress, &IgnoredSts);
162       PciAddress.Address.Function = FUNC_4;
163       PciAddress.Address.Register = CPB_CTRL_REG;
164       LibAmdPciRead (AccessWidth32, PciAddress, &CpbControl, StdHeader);
165       if (PackageType == PACKAGE_TYPE_AM3r2) {
166         ((CPB_CTRL_REGISTER *) (&CpbControl))->BoostSrc = 1;
167       } else {
168         if ((EntryPoint & CPU_FEAT_BEFORE_PM_INIT) != 0) {
169           ((CPB_CTRL_REGISTER *) (&CpbControl))->BoostSrc = 1;
170         }
171       }
172       LibAmdPciWrite (AccessWidth32, PciAddress, &CpbControl, StdHeader);
173     }
174   }
175   return AGESA_SUCCESS;
176 }
177
178 CONST CPB_FAMILY_SERVICES ROMDATA F15OrCpbSupport =
179 {
180   0,
181   F15OrIsCpbSupported,
182   F15OrInitializeCpb
183 };