5 * AMD Family_10 revision Dx specific utility functions.
7 * Provides numerous utility functions specific to family 10h rev D.
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_REVD_F10REVDUTILITIES_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 *----------------------------------------------------------------------------------------
82 F10CommonRevDSetDownCoreRegister (
83 IN CPU_CORE_LEVELING_FAMILY_SERVICES *FamilySpecificServices,
86 IN UINT32 *LeveledCores,
87 IN CORE_LEVELING_TYPE CoreLevelMode,
88 IN AMD_CONFIG_PARAMS *StdHeader
92 F10CommonRevDGetProcIddMax (
93 IN CPU_SPECIFIC_SERVICES *FamilySpecificServices,
95 OUT UINT32 *ProcIddMax,
96 IN AMD_CONFIG_PARAMS *StdHeader
100 F10CommonRevDGetNbCofVidUpdate (
101 IN CPU_SPECIFIC_SERVICES *FamilySpecificServices,
102 IN PCI_ADDR *PciAddress,
103 OUT BOOLEAN *NbVidUpdateAll,
104 IN AMD_CONFIG_PARAMS *StdHeader
108 F10CommonRevDGetNbPstateInfo (
109 IN CPU_SPECIFIC_SERVICES *FamilySpecificServices,
110 IN PLATFORM_CONFIGURATION *PlatformConfig,
111 IN PCI_ADDR *PciAddress,
113 OUT UINT32 *FreqNumeratorInMHz,
114 OUT UINT32 *FreqDivisor,
115 OUT UINT32 *VoltageInuV,
116 IN AMD_CONFIG_PARAMS *StdHeader
120 F10RevDGetMinMaxNbFrequency (
121 IN CPU_SPECIFIC_SERVICES *FamilySpecificServices,
122 IN PLATFORM_CONFIGURATION *PlatformConfig,
123 IN PCI_ADDR *PciAddress,
124 OUT UINT32 *MinFreqInMHz,
125 OUT UINT32 *MaxFreqInMHz,
126 IN AMD_CONFIG_PARAMS *StdHeader
130 F10CommonRevDGetNumberOfPhysicalCores (
131 IN CPU_SPECIFIC_SERVICES *FamilySpecificServices,
132 IN AMD_CONFIG_PARAMS *StdHeader
135 /*----------------------------------------------------------------------------------------
136 * E X P O R T E D F U N C T I O N S
137 *----------------------------------------------------------------------------------------
140 /*---------------------------------------------------------------------------------------*/
142 * Set down core register on a revision D processor.
144 * This function set F3x190 Downcore Control Register[5:0]
146 * @param[in] FamilySpecificServices The current Family Specific Services.
147 * @param[in] Socket Socket ID.
148 * @param[in] Module Module ID in socket.
149 * @param[in] LeveledCores Number of core.
150 * @param[in] CoreLevelMode Core level mode.
151 * @param[in] StdHeader Header for library and services.
153 * @retval TRUE Down Core register is updated.
154 * @retval FALSE Down Core register is not updated.
157 F10CommonRevDSetDownCoreRegister (
158 IN CPU_CORE_LEVELING_FAMILY_SERVICES *FamilySpecificServices,
161 IN UINT32 *LeveledCores,
162 IN CORE_LEVELING_TYPE CoreLevelMode,
163 IN AMD_CONFIG_PARAMS *StdHeader
167 UINT32 CoreDisableBits;
170 AGESA_STATUS AgesaStatus;
174 switch (*LeveledCores) {
176 CoreDisableBits = DOWNCORE_MASK_SINGLE;
179 CoreDisableBits = DOWNCORE_MASK_DUAL;
182 CoreDisableBits = DOWNCORE_MASK_TRI;
185 CoreDisableBits = DOWNCORE_MASK_FOUR;
188 CoreDisableBits = DOWNCORE_MASK_FIVE;
195 if (CoreDisableBits != 0) {
196 if (GetPciAddress (StdHeader, (UINT8) *Socket, (UINT8) *Module, &PciAddress, &AgesaStatus)) {
197 PciAddress.Address.Function = FUNC_3;
198 PciAddress.Address.Register = NORTH_BRIDGE_CAPABILITIES_REG;
200 LibAmdPciRead (AccessWidth32, PciAddress, &TempVar32_a, StdHeader);
201 TempVar32_a = ((TempVar32_a >> 12) & 0x3) | ((TempVar32_a >> 13) & 0x4);
202 if (TempVar32_a == 0) {
203 CoreDisableBits &= 0x1;
204 } else if (TempVar32_a == 1) {
205 CoreDisableBits &= 0x3;
206 } else if (TempVar32_a == 2) {
207 CoreDisableBits &= 0x7;
208 } else if (TempVar32_a == 3) {
209 CoreDisableBits &= 0x0F;
210 } else if (TempVar32_a == 4) {
211 CoreDisableBits &= 0x1F;
212 } else if (TempVar32_a == 5) {
213 CoreDisableBits &= 0x3F;
215 PciAddress.Address.Register = DOWNCORE_CTRL;
216 LibAmdPciRead (AccessWidth32, PciAddress, &TempVar32_a, StdHeader);
217 if ((TempVar32_a | CoreDisableBits) != TempVar32_a) {
218 TempVar32_a |= CoreDisableBits;
219 LibAmdPciWrite (AccessWidth32, PciAddress, &TempVar32_a, StdHeader);
229 CONST CPU_CORE_LEVELING_FAMILY_SERVICES ROMDATA F10RevDCoreLeveling =
232 F10CommonRevDSetDownCoreRegister
235 /*---------------------------------------------------------------------------------------*/
237 * Get CPU pstate current on a revision D processor.
239 * @CpuServiceMethod{::F_CPU_GET_IDD_MAX}.
241 * This function returns the ProcIddMax.
243 * @param[in] FamilySpecificServices The current Family Specific Services.
244 * @param[in] Pstate The P-state to check.
245 * @param[out] ProcIddMax P-state current in mA.
246 * @param[in] StdHeader Handle of Header for calling lib functions and services.
248 * @retval TRUE P-state is enabled
249 * @retval FALSE P-state is disabled
252 F10CommonRevDGetProcIddMax (
253 IN CPU_SPECIFIC_SERVICES *FamilySpecificServices,
255 OUT UINT32 *ProcIddMax,
256 IN AMD_CONFIG_PARAMS *StdHeader
265 BOOLEAN IsPstateEnabled;
268 IsPstateEnabled = FALSE;
270 MsrAddress = (UINT32) (Pstate + PS_REG_BASE);
271 ASSERT (MsrAddress <= PS_MAX_REG);
273 LibAmdMsrRead (MsrAddress, &PstateMsr, StdHeader);
274 if (((PSTATE_MSR *) &PstateMsr)->PsEnable == 1) {
275 OptionMultiSocketConfiguration.GetCurrPciAddr (&PciAddress, StdHeader);
276 PciAddress.Address.Function = FUNC_3;
277 PciAddress.Address.Register = NB_CAPS_REG;
278 LibAmdPciRead (AccessWidth32, PciAddress, &NbCaps, StdHeader); // F3xE8
280 switch (((PSTATE_MSR *) &PstateMsr)->IddDiv) {
290 default: // IddDiv = 3 is reserved. Use 10
294 MultiNodeCpu = (UINT32) (((NB_CAPS_REGISTER *) &NbCaps)->MultiNodeCpu + 1);
295 CmpCap = (UINT32) (((NB_CAPS_REGISTER *) &NbCaps)->CmpCapHi << 2);
296 CmpCap |= (UINT32) (((NB_CAPS_REGISTER *) &NbCaps)->CmpCapLo);
298 *ProcIddMax = (UINT32) ((PSTATE_MSR *) &PstateMsr)->IddValue * IddDiv * CmpCap * MultiNodeCpu;
299 IsPstateEnabled = TRUE;
301 return IsPstateEnabled;
304 /*---------------------------------------------------------------------------------------*/
306 * Returns whether or not BIOS is responsible for configuring the NB COFVID.
308 * @CpuServiceMethod{::F_CPU_IS_NBCOF_INIT_NEEDED}.
310 * @param[in] FamilySpecificServices The current Family Specific Services.
311 * @param[in] PciAddress The northbridge to query by pci base address.
312 * @param[out] NbVidUpdateAll Do all NbVids need to be updated
313 * @param[in] StdHeader Header for library and services
315 * @retval TRUE Perform northbridge frequency and voltage config.
316 * @retval FALSE Do not configure them.
319 F10CommonRevDGetNbCofVidUpdate (
320 IN CPU_SPECIFIC_SERVICES *FamilySpecificServices,
321 IN PCI_ADDR *PciAddress,
322 OUT BOOLEAN *NbVidUpdateAll,
323 IN AMD_CONFIG_PARAMS *StdHeader
326 *NbVidUpdateAll = FALSE;
330 /*---------------------------------------------------------------------------------------*/
332 * Determines the NB clock on the desired node.
334 * @CpuServiceMethod{::F_CPU_GET_NB_PSTATE_INFO}.
336 * @param[in] FamilySpecificServices The current Family Specific Services.
337 * @param[in] PlatformConfig Platform profile/build option config structure.
338 * @param[in] PciAddress The segment, bus, and device numbers of the CPU in question.
339 * @param[in] NbPstate The NB P-state number to check.
340 * @param[out] FreqNumeratorInMHz The desired node's frequency numerator in megahertz.
341 * @param[out] FreqDivisor The desired node's frequency divisor.
342 * @param[out] VoltageInuV The desired node's voltage in microvolts.
343 * @param[in] StdHeader Handle of Header for calling lib functions and services.
345 * @retval TRUE NbPstate is valid
346 * @retval FALSE NbPstate is disabled or invalid
349 F10CommonRevDGetNbPstateInfo (
350 IN CPU_SPECIFIC_SERVICES *FamilySpecificServices,
351 IN PLATFORM_CONFIGURATION *PlatformConfig,
352 IN PCI_ADDR *PciAddress,
354 OUT UINT32 *FreqNumeratorInMHz,
355 OUT UINT32 *FreqDivisor,
356 OUT UINT32 *VoltageInuV,
357 IN AMD_CONFIG_PARAMS *StdHeader
360 UINT32 LocalPciRegister;
361 UINT64 LocalMsrRegister;
362 BOOLEAN PstateIsValid;
364 PstateIsValid = FALSE;
366 PciAddress->Address.Function = FUNC_3;
367 PciAddress->Address.Register = CPTC0_REG;
368 LibAmdPciRead (AccessWidth32, *PciAddress, &LocalPciRegister, StdHeader);
369 *FreqNumeratorInMHz = ((((CLK_PWR_TIMING_CTRL_REGISTER *) &LocalPciRegister)->NbFid + 4) * 200);
371 LibAmdMsrRead (MSR_COFVID_STS, &LocalMsrRegister, StdHeader);
372 *VoltageInuV = (1550000 - (12500 * ((UINT32) ((COFVID_STS_MSR *) &LocalMsrRegister)->CurNbVid)));
373 PstateIsValid = TRUE;
375 return PstateIsValid;
378 /*---------------------------------------------------------------------------------------*/
380 * Returns the node's minimum and maximum northbridge frequency.
382 * @CpuServiceMethod{::F_CPU_GET_MIN_MAX_NB_FREQ}.
384 * @param[in] FamilySpecificServices The current Family Specific Services.
385 * @param[in] PlatformConfig Platform profile/build option config structure.
386 * @param[in] PciAddress The segment, bus, and device numbers of the CPU in question.
387 * @param[out] MinFreqInMHz The node's minimum northbridge frequency.
388 * @param[out] MaxFreqInMHz The node's maximum northbridge frequency.
389 * @param[in] StdHeader Handle of Header for calling lib functions and services.
391 * @retval AGESA_STATUS Northbridge frequency is valid
394 F10RevDGetMinMaxNbFrequency (
395 IN CPU_SPECIFIC_SERVICES *FamilySpecificServices,
396 IN PLATFORM_CONFIGURATION *PlatformConfig,
397 IN PCI_ADDR *PciAddress,
398 OUT UINT32 *MinFreqInMHz,
399 OUT UINT32 *MaxFreqInMHz,
400 IN AMD_CONFIG_PARAMS *StdHeader
403 UINT32 LocalPciRegister;
405 PciAddress->Address.Function = FUNC_3;
406 PciAddress->Address.Register = CPTC0_REG;
407 LibAmdPciRead (AccessWidth32, *PciAddress, &LocalPciRegister, StdHeader);
408 *MinFreqInMHz = ((((CLK_PWR_TIMING_CTRL_REGISTER *) &LocalPciRegister)->NbFid + 4) * 200);
409 *MaxFreqInMHz = *MinFreqInMHz;
411 return AGESA_SUCCESS;
414 /*---------------------------------------------------------------------------------------*/
416 * Get the number of physical cores of current processor.
418 * @CpuServiceMethod{::F_CPU_NUMBER_OF_PHYSICAL_CORES}.
420 * @param[in] FamilySpecificServices The current Family Specific Services.
421 * @param[in] StdHeader Handle of Header for calling lib functions and services.
423 * @return The number of physical cores.
426 F10CommonRevDGetNumberOfPhysicalCores (
427 IN CPU_SPECIFIC_SERVICES *FamilySpecificServices,
428 IN AMD_CONFIG_PARAMS *StdHeader
436 UINT32 LocalPciRegister;
438 AGESA_STATUS IgnoredSts;
441 IdentifyCore (StdHeader, &Socket, &Module, &Core, &IgnoredSts);
442 for (Module = 0; Module < GetPlatformNumberOfModules (); Module++) {
443 if (GetPciAddress (StdHeader, Socket, Module, &PciAddress, &IgnoredSts)) {
444 PciAddress.Address.Function = FUNC_3;
445 PciAddress.Address.Register = NB_CAPS_REG;
446 LibAmdPciRead (AccessWidth32, PciAddress, &LocalPciRegister, StdHeader);
447 CmpCapOnNode = (UINT8) (((NB_CAPS_REGISTER *) &LocalPciRegister)->CmpCapHi << 2);
448 CmpCapOnNode |= (UINT8) (((NB_CAPS_REGISTER *) &LocalPciRegister)->CmpCapLo);
450 CmpCap += CmpCapOnNode;
453 return ((UINT8) CmpCap);