5 * AMD Family_10 revision Ex specific utility functions.
7 * Provides numerous utility functions specific to family 10h rev E.
9 * @xrefitem bom "File Content Label" "Release Content"
11 * @e sub-project: CPU/F10
12 * @e \$Revision: 56279 $ @e \$Date: 2011-07-11 13:11:28 -0600 (Mon, 11 Jul 2011) $
16 ******************************************************************************
18 * Copyright (C) 2012 Advanced Micro Devices, Inc.
19 * All rights reserved.
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.
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.
43 ******************************************************************************
46 /*----------------------------------------------------------------------------------------
47 * M O D U L E S U S E D
48 *----------------------------------------------------------------------------------------
53 #include "cpuRegisters.h"
54 #include "cpuFamilyTranslation.h"
55 #include "cpuF10PowerMgmt.h"
56 #include "GeneralServices.h"
57 #include "cpuEarlyInit.h"
58 #include "cpuRegisters.h"
59 #include "OptionMultiSocket.h"
64 #define FILECODE PROC_CPU_FAMILY_0X10_REVE_F10REVEUTILITIES_FILECODE
66 /*----------------------------------------------------------------------------------------
67 * D E F I N I T I O N S A N D M A C R O S
68 *----------------------------------------------------------------------------------------
70 extern OPTION_MULTISOCKET_CONFIGURATION OptionMultiSocketConfiguration;
71 /*----------------------------------------------------------------------------------------
72 * T Y P E D E F S A N D S T R U C T U R E S
73 *----------------------------------------------------------------------------------------
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 *----------------------------------------------------------------------------------------
81 /*----------------------------------------------------------------------------------------
82 * E X P O R T E D F U N C T I O N S
83 *----------------------------------------------------------------------------------------
86 /*---------------------------------------------------------------------------------------*/
88 * Set down core register on a revision E processor.
90 * This function set F3x190 Downcore Control Register[5:0]
92 * @param[in] FamilySpecificServices The current Family Specific Services.
93 * @param[in] Socket Socket ID.
94 * @param[in] Module Module ID in socket.
95 * @param[in] LeveledCores Number of core.
96 * @param[in] CoreLevelMode Core level mode.
97 * @param[in] StdHeader Header for library and services.
99 * @retval TRUE Down Core register is updated.
100 * @retval FALSE Down Core register is not updated.
103 F10CommonRevESetDownCoreRegister (
104 IN CPU_CORE_LEVELING_FAMILY_SERVICES *FamilySpecificServices,
107 IN UINT32 *LeveledCores,
108 IN CORE_LEVELING_TYPE CoreLevelMode,
109 IN AMD_CONFIG_PARAMS *StdHeader
113 UINT32 CoreDisableBits;
116 AGESA_STATUS AgesaStatus;
120 switch (*LeveledCores) {
122 CoreDisableBits = DOWNCORE_MASK_SINGLE;
125 CoreDisableBits = DOWNCORE_MASK_DUAL;
128 CoreDisableBits = DOWNCORE_MASK_TRI;
131 CoreDisableBits = DOWNCORE_MASK_FOUR;
134 CoreDisableBits = DOWNCORE_MASK_FIVE;
141 if (CoreDisableBits != 0) {
142 if (GetPciAddress (StdHeader, (UINT8) *Socket, (UINT8) *Module, &PciAddress, &AgesaStatus)) {
143 PciAddress.Address.Function = FUNC_3;
144 PciAddress.Address.Register = NORTH_BRIDGE_CAPABILITIES_REG;
146 LibAmdPciRead (AccessWidth32, PciAddress, &TempVar32_a, StdHeader);
147 TempVar32_a = ((TempVar32_a >> 12) & 0x3) | ((TempVar32_a >> 13) & 0x4);
148 if (TempVar32_a == 0) {
149 CoreDisableBits &= 0x1;
150 } else if (TempVar32_a == 1) {
151 CoreDisableBits &= 0x3;
152 } else if (TempVar32_a == 2) {
153 CoreDisableBits &= 0x7;
154 } else if (TempVar32_a == 3) {
155 CoreDisableBits &= 0x0F;
156 } else if (TempVar32_a == 4) {
157 CoreDisableBits &= 0x1F;
158 } else if (TempVar32_a == 5) {
159 CoreDisableBits &= 0x3F;
161 PciAddress.Address.Register = DOWNCORE_CTRL;
162 LibAmdPciRead (AccessWidth32, PciAddress, &TempVar32_a, StdHeader);
163 if ((TempVar32_a | CoreDisableBits) != TempVar32_a) {
164 TempVar32_a |= CoreDisableBits;
165 LibAmdPciWrite (AccessWidth32, PciAddress, &TempVar32_a, StdHeader);
175 CONST CPU_CORE_LEVELING_FAMILY_SERVICES ROMDATA F10RevECoreLeveling =
178 F10CommonRevESetDownCoreRegister
181 /*---------------------------------------------------------------------------------------*/
183 * Get CPU pstate current on a revision E processor.
185 * @CpuServiceMethod{::F_CPU_GET_IDD_MAX}.
187 * This function returns the ProcIddMax.
189 * @param[in] FamilySpecificServices The current Family Specific Services.
190 * @param[in] Pstate The P-state to check.
191 * @param[out] ProcIddMax P-state current in mA.
192 * @param[in] StdHeader Handle of Header for calling lib functions and services.
194 * @retval TRUE P-state is enabled
195 * @retval FALSE P-state is disabled
198 F10CommonRevEGetProcIddMax (
199 IN CPU_SPECIFIC_SERVICES *FamilySpecificServices,
201 OUT UINT32 *ProcIddMax,
202 IN AMD_CONFIG_PARAMS *StdHeader
207 UINT32 LocalPciRegister;
211 BOOLEAN IsPstateEnabled;
214 IsPstateEnabled = FALSE;
216 MsrAddress = (UINT32) (Pstate + PS_REG_BASE);
217 ASSERT (MsrAddress <= PS_MAX_REG);
219 LibAmdMsrRead (MsrAddress, &PstateMsr, StdHeader);
220 if (((PSTATE_MSR *) &PstateMsr)->PsEnable == 1) {
221 OptionMultiSocketConfiguration.GetCurrPciAddr (&PciAddress, StdHeader);
223 PciAddress.Address.Function = FUNC_3;
224 PciAddress.Address.Register = NB_CAPS_REG;
225 LibAmdPciRead (AccessWidth32, PciAddress, &LocalPciRegister, StdHeader); // F3xE8
227 switch (((PSTATE_MSR *) &PstateMsr)->IddDiv) {
237 default: // IddDiv = 3 is reserved. Use 10
242 MultiNodeCpu = (UINT32) (((NB_CAPS_REGISTER *) &LocalPciRegister)->MultiNodeCpu + 1);
243 CmpCap = (UINT32) (((NB_CAPS_REGISTER *) &LocalPciRegister)->CmpCapHi << 2);
244 CmpCap |= (UINT32) (((NB_CAPS_REGISTER *) &LocalPciRegister)->CmpCapLo);
246 *ProcIddMax = (UINT32) ((PSTATE_MSR *) &PstateMsr)->IddValue * IddDiv * CmpCap * MultiNodeCpu;
247 IsPstateEnabled = TRUE;
249 return IsPstateEnabled;
252 /*---------------------------------------------------------------------------------------*/
254 * Determines the NB clock on the desired node.
256 * @CpuServiceMethod{::F_CPU_GET_NB_PSTATE_INFO}.
258 * @param[in] FamilySpecificServices The current Family Specific Services.
259 * @param[in] PlatformConfig Platform profile/build option config structure.
260 * @param[in] PciAddress The segment, bus, and device numbers of the CPU in question.
261 * @param[in] NbPstate The NB P-state number to check.
262 * @param[out] FreqNumeratorInMHz The desired node's frequency numerator in megahertz.
263 * @param[out] FreqDivisor The desired node's frequency divisor.
264 * @param[out] VoltageInuV The desired node's voltage in microvolts.
265 * @param[in] StdHeader Handle of Header for calling lib functions and services.
267 * @retval TRUE NbPstate is valid
268 * @retval FALSE NbPstate is disabled or invalid
271 F10CommonRevEGetNbPstateInfo (
272 IN CPU_SPECIFIC_SERVICES *FamilySpecificServices,
273 IN PLATFORM_CONFIGURATION *PlatformConfig,
274 IN PCI_ADDR *PciAddress,
276 OUT UINT32 *FreqNumeratorInMHz,
277 OUT UINT32 *FreqDivisor,
278 OUT UINT32 *VoltageInuV,
279 IN AMD_CONFIG_PARAMS *StdHeader
282 UINT32 LocalPciRegister;
283 UINT64 LocalMsrRegister;
284 BOOLEAN PstateIsValid;
286 PstateIsValid = FALSE;
288 PciAddress->Address.Function = FUNC_3;
289 PciAddress->Address.Register = CPTC0_REG;
290 LibAmdPciRead (AccessWidth32, *PciAddress, &LocalPciRegister, StdHeader);
291 *FreqNumeratorInMHz = ((((CLK_PWR_TIMING_CTRL_REGISTER *) &LocalPciRegister)->NbFid + 4) * 200);
293 LibAmdMsrRead (MSR_COFVID_STS, &LocalMsrRegister, StdHeader);
294 *VoltageInuV = (1550000 - (12500 * ((UINT32) ((COFVID_STS_MSR *) &LocalMsrRegister)->CurNbVid)));
295 PstateIsValid = TRUE;
297 return PstateIsValid;
300 /*---------------------------------------------------------------------------------------*/
302 * Returns the node's minimum and maximum northbridge frequency.
304 * @CpuServiceMethod{::F_CPU_GET_MIN_MAX_NB_FREQ}.
306 * @param[in] FamilySpecificServices The current Family Specific Services.
307 * @param[in] PlatformConfig Platform profile/build option config structure.
308 * @param[in] PciAddress The segment, bus, and device numbers of the CPU in question.
309 * @param[out] MinFreqInMHz The node's minimum northbridge frequency.
310 * @param[out] MaxFreqInMHz The node's maximum northbridge frequency.
311 * @param[in] StdHeader Handle of Header for calling lib functions and services.
313 * @retval AGESA_STATUS Northbridge frequency is valid
316 F10RevEGetMinMaxNbFrequency (
317 IN CPU_SPECIFIC_SERVICES *FamilySpecificServices,
318 IN PLATFORM_CONFIGURATION *PlatformConfig,
319 IN PCI_ADDR *PciAddress,
320 OUT UINT32 *MinFreqInMHz,
321 OUT UINT32 *MaxFreqInMHz,
322 IN AMD_CONFIG_PARAMS *StdHeader
325 UINT32 LocalPciRegister;
327 PciAddress->Address.Function = FUNC_3;
328 PciAddress->Address.Register = CPTC0_REG;
329 LibAmdPciRead (AccessWidth32, *PciAddress, &LocalPciRegister, StdHeader);
330 *MinFreqInMHz = ((((CLK_PWR_TIMING_CTRL_REGISTER *) &LocalPciRegister)->NbFid + 4) * 200);
331 *MaxFreqInMHz = *MinFreqInMHz;
333 return AGESA_SUCCESS;
336 /*---------------------------------------------------------------------------------------*/
338 * Returns whether or not BIOS is responsible for configuring the NB COFVID.
340 * @CpuServiceMethod{::F_CPU_IS_NBCOF_INIT_NEEDED}.
342 * @param[in] FamilySpecificServices The current Family Specific Services.
343 * @param[in] PciAddress The northbridge to query by pci base address.
344 * @param[out] NbVidUpdateAll Do all NbVids need to be updated
345 * @param[in] StdHeader Header for library and services
347 * @retval TRUE Perform northbridge frequency and voltage config.
348 * @retval FALSE Do not configure them.
351 F10CommonRevEGetNbCofVidUpdate (
352 IN CPU_SPECIFIC_SERVICES *FamilySpecificServices,
353 IN PCI_ADDR *PciAddress,
354 OUT BOOLEAN *NbVidUpdateAll,
355 IN AMD_CONFIG_PARAMS *StdHeader
358 UINT32 ProductInfoRegister;
360 PciAddress->Address.Register = PRCT_INFO_REG;
361 PciAddress->Address.Function = FUNC_3;
362 LibAmdPciRead (AccessWidth32, *PciAddress, &ProductInfoRegister, StdHeader);
363 *NbVidUpdateAll = (BOOLEAN) (((PRODUCT_INFO_REGISTER *) &ProductInfoRegister)->NbVidUpdateAll == 1);
364 return (BOOLEAN) (((PRODUCT_INFO_REGISTER *) &ProductInfoRegister)->NbCofVidUpdate == 1);
367 /*---------------------------------------------------------------------------------------*/
369 * Get the number of physical cores of current processor.
371 * @CpuServiceMethod{::F_CPU_NUMBER_OF_PHYSICAL_CORES}.
373 * @param[in] FamilySpecificServices The current Family Specific Services.
374 * @param[in] StdHeader Handle of Header for calling lib functions and services.
376 * @return The number of physical cores.
379 F10CommonRevEGetNumberOfPhysicalCores (
380 IN CPU_SPECIFIC_SERVICES *FamilySpecificServices,
381 IN AMD_CONFIG_PARAMS *StdHeader
385 UINT32 LocalPciRegister;
388 OptionMultiSocketConfiguration.GetCurrPciAddr (&PciAddress, StdHeader);
389 PciAddress.Address.Function = FUNC_3;
390 PciAddress.Address.Register = NB_CAPS_REG;
391 LibAmdPciRead (AccessWidth32, PciAddress, &LocalPciRegister, StdHeader);
392 CmpCap = (UINT8) (((NB_CAPS_REGISTER *) &LocalPciRegister)->CmpCapHi << 2);
393 CmpCap |= (UINT8) (((NB_CAPS_REGISTER *) &LocalPciRegister)->CmpCapLo);
395 return (UINT8) (CmpCap + 1);