5 * AMD Family_15 models 0 - 0Fh specific utility functions.
7 * Provides numerous utility functions specific to family 15h OR.
9 * @xrefitem bom "File Content Label" "Release Content"
11 * @e sub-project: CPU/Family/0x15/OR
12 * @e \$Revision: 58928 $ @e \$Date: 2011-09-08 16:43:14 -0600 (Thu, 08 Sep 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 *----------------------------------------------------------------------------------------
52 #include "cpuFamilyTranslation.h"
53 #include "cpuF15PowerMgmt.h"
54 #include "cpuF15OrPowerMgmt.h"
55 #include "cpuApicUtilities.h"
56 #include "cpuServices.h"
57 #include "cpuEarlyInit.h"
58 #include "GeneralServices.h"
59 #include "OptionMultiSocket.h"
60 #include "F15OrUtilities.h"
64 #define FILECODE PROC_CPU_FAMILY_0X15_OR_F15ORUTILITIES_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 *----------------------------------------------------------------------------------------
77 * Node ID MSR register fields.
78 * Provide the layout of fields in the Node ID MSR.
81 UINT64 NodeId:3; ///< The core is on the node with this node id.
82 UINT64 NodesPerProcessor:3; ///< The number of Nodes in this processor.
83 UINT64 BiosScratch:6; ///< BiosScratch, use as the AP core heap index.
84 UINT64 :(63 - 11); ///< Reserved.
89 NODE_ID_MSR_FIELDS Fields; ///< Access the register as individual fields
90 UINT64 Value; ///< Access the register value.
93 /*----------------------------------------------------------------------------------------
94 * 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
95 *----------------------------------------------------------------------------------------
100 F15OrNbPstateDisCore (
101 IN AMD_CONFIG_PARAMS *StdHeader
105 F15OrSetDownCoreRegister (
106 IN CPU_CORE_LEVELING_FAMILY_SERVICES *FamilySpecificServices,
109 IN UINT32 *LeveledCores,
110 IN CORE_LEVELING_TYPE CoreLevelMode,
111 IN AMD_CONFIG_PARAMS *StdHeader
115 /*----------------------------------------------------------------------------------------
116 * E X P O R T E D F U N C T I O N S
117 *----------------------------------------------------------------------------------------
120 /*---------------------------------------------------------------------------------------*/
122 * Get CPU pstate current.
124 * @CpuServiceMethod{::F_CPU_GET_IDD_MAX}.
126 * This function returns the ProcIddMax.
128 * @param[in] FamilySpecificServices The current Family Specific Services.
129 * @param[in] Pstate The P-state to check.
130 * @param[out] ProcIddMax P-state current in mA.
131 * @param[in] StdHeader Handle of Header for calling lib functions and services.
133 * @retval TRUE P-state is enabled
134 * @retval FALSE P-state is disabled
138 IN CPU_SPECIFIC_SERVICES *FamilySpecificServices,
140 OUT UINT32 *ProcIddMax,
141 IN AMD_CONFIG_PARAMS *StdHeader
145 UINT32 NumberOfPhysicalCores;
148 BOOLEAN IsPstateEnabled;
151 IsPstateEnabled = FALSE;
153 MsrAddress = (UINT32) (Pstate + PS_REG_BASE);
154 ASSERT (MsrAddress <= PS_MAX_REG);
156 LibAmdMsrRead (MsrAddress, &PstateMsr, StdHeader);
157 if (((PSTATE_MSR *) &PstateMsr)->PsEnable == 1) {
158 switch (((PSTATE_MSR *) &PstateMsr)->IddDiv) {
168 default: // IddDiv = 3 is reserved. Use 10
172 LibAmdCpuidRead (AMD_CPUID_ASIZE_PCCOUNT, &CpuId, StdHeader);
173 NumberOfPhysicalCores = ((CpuId.ECX_Reg & 0xFF) + 1);
175 *ProcIddMax = (UINT32) ((PSTATE_MSR *) &PstateMsr)->IddValue * IddDiv * NumberOfPhysicalCores;
176 IsPstateEnabled = TRUE;
178 return IsPstateEnabled;
181 /*---------------------------------------------------------------------------------------*/
183 * Set down core register on Orochi
185 * This function set F3x190 Downcore Control Register[5:0]
187 * @param[in] FamilySpecificServices The current Family Specific Services.
188 * @param[in] Socket Socket ID.
189 * @param[in] Module Module ID in socket.
190 * @param[in] LeveledCores Number of core.
191 * @param[in] CoreLevelMode Core level mode.
192 * @param[in] StdHeader Header for library and services.
194 * @retval TRUE Down Core register is updated.
195 * @retval FALSE Down Core register is not updated.
198 F15OrSetDownCoreRegister (
199 IN CPU_CORE_LEVELING_FAMILY_SERVICES *FamilySpecificServices,
202 IN UINT32 *LeveledCores,
203 IN CORE_LEVELING_TYPE CoreLevelMode,
204 IN AMD_CONFIG_PARAMS *StdHeader
207 UINT8 Xbar2SriFreeListCBC;
210 UINT32 CoreDisableBits;
211 UINT32 NumberOfEnabledCores;
212 UINT32 NumberOfEnabledCU;
215 AGESA_STATUS AgesaStatus;
216 NB_CAPS_REGISTER NbCaps;
217 FREE_LIST_BUFFER_COUNT_REGISTER FreeListBufferCount;
218 L3_BUFFER_COUNT_REGISTER L3BufferCnt;
222 if (CoreLevelMode == CORE_LEVEL_COMPUTE_UNIT) {
223 switch (*LeveledCores) {
225 CoreDisableBits = DOWNCORE_MASK_SINGLE;
228 CoreDisableBits = DOWNCORE_MASK_DUAL_COMPUTE_UNIT;
231 CoreDisableBits = DOWNCORE_MASK_TRI_COMPUTE_UNIT;
234 CoreDisableBits = DOWNCORE_MASK_FOUR_COMPUTE_UNIT;
242 switch (*LeveledCores) {
244 CoreDisableBits = DOWNCORE_MASK_SINGLE;
247 CoreDisableBits = DOWNCORE_MASK_DUAL;
250 CoreDisableBits = DOWNCORE_MASK_FOUR;
253 CoreDisableBits = DOWNCORE_MASK_SIX;
261 if (CoreDisableBits != 0) {
262 if (GetPciAddress (StdHeader, (UINT8) *Socket, (UINT8) *Module, &PciAddress, &AgesaStatus)) {
263 PciAddress.Address.Function = FUNC_5;
264 PciAddress.Address.Register = NORTH_BRIDGE_CAPABILITIES_2_REG;
265 LibAmdPciRead (AccessWidth32, PciAddress, &TempVar32_a, StdHeader);
266 TempVar32_a = (TempVar32_a & 0xFF) + 1;
267 TempVar32_a = (1 << TempVar32_a) - 1;
268 CoreDisableBits &= TempVar32_a;
269 NumberOfEnabledCores = ~(CoreDisableBits | ~(TempVar32_a));
271 PciAddress.Address.Function = FUNC_3;
272 PciAddress.Address.Register = DOWNCORE_CTRL;
273 LibAmdPciRead (AccessWidth32, PciAddress, &TempVar32_a, StdHeader);
274 if ((TempVar32_a | CoreDisableBits) != TempVar32_a) {
275 TempVar32_a |= CoreDisableBits;
276 LibAmdPciWrite (AccessWidth32, PciAddress, &TempVar32_a, StdHeader);
279 for (NumberOfEnabledCU = 0; NumberOfEnabledCores != 0; NumberOfEnabledCores >>= 2) {
280 NumberOfEnabledCU += ((NumberOfEnabledCores & 3) != 0) ? 1 : 0;
282 switch (NumberOfEnabledCU) {
284 Xbar2SriFreeListCBC = 0x16;
285 L3FreeListCBC = 0x1C;
288 Xbar2SriFreeListCBC = 0x14;
289 L3FreeListCBC = 0x18;
292 Xbar2SriFreeListCBC = 0x12;
293 L3FreeListCBC = 0x14;
296 Xbar2SriFreeListCBC = 0x10;
297 L3FreeListCBC = 0x10;
300 Xbar2SriFreeListCBC = 0x16;
304 //D18F3x1A0[8:4] L3FreeListCBC:
305 //BIOS: IF (NumOfCompUnitsOnNode==1) THEN 1Ch ELSEIF (NumOfCompUnitsOnNode==2)
306 //THEN 18h ELSEIF (NumOfCompUnitsOnNode==3) THEN 14h ELSEIF
307 //(NumOfCompUnitsOnNode==4) THEN 10h ELSEIF (NumOfCompUnitsOnNode==5) THEN 11h
309 PciAddress.Address.Function = FUNC_3;
310 PciAddress.Address.Register = L3_BUFFER_COUNT_REG;
311 LibAmdPciRead (AccessWidth32, PciAddress, &L3BufferCnt, StdHeader);
312 L3BufferCnt.L3FreeListCBC = L3FreeListCBC;
313 LibAmdPciWrite (AccessWidth32, PciAddress, &L3BufferCnt, StdHeader);
315 //D18F3x7C[4:0]Xbar2SriFreeListCBC:
316 //BIOS: IF (L3Enabled) THEN 16h ELSEIF (D18F5x80[Enabled[3]]==1) THEN 10h ELSEIF
317 //(D18F5x80[Enabled[2]]==1) THEN 12h ELSEIF (D18F5x80[Enabled[1]]==1) THEN 14h ELSE 16h ENDIF.
318 PciAddress.Address.Function = FUNC_3;
319 PciAddress.Address.Register = NB_CAPS_REG;
320 LibAmdPciRead (AccessWidth32, PciAddress, &NbCaps, StdHeader);
321 if (NbCaps.L3Capable == 0) {
322 PciAddress.Address.Function = FUNC_3;
323 PciAddress.Address.Register = FREE_LIST_BUFFER_COUNT_REG;
324 LibAmdPciRead (AccessWidth32, PciAddress, &FreeListBufferCount, StdHeader);
325 FreeListBufferCount.Xbar2SriFreeListCBC = Xbar2SriFreeListCBC;
326 LibAmdPciWrite (AccessWidth32, PciAddress, &FreeListBufferCount, StdHeader);
336 CONST CPU_CORE_LEVELING_FAMILY_SERVICES ROMDATA F15OrCoreLeveling =
339 F15OrSetDownCoreRegister
343 /*---------------------------------------------------------------------------------------*/
345 * Determines the NB clock on the desired node.
347 * @CpuServiceMethod{::F_CPU_GET_NB_FREQ}.
349 * @param[in] FamilySpecificServices The current Family Specific Services.
350 * @param[out] FrequencyInMHz Northbridge clock frequency in MHz.
351 * @param[in] StdHeader Header for library and services.
353 * @return AGESA_SUCCESS FrequencyInMHz is valid.
356 F15OrGetCurrentNbFrequency (
357 IN CPU_SPECIFIC_SERVICES *FamilySpecificServices,
358 OUT UINT32 *FrequencyInMHz,
359 IN AMD_CONFIG_PARAMS *StdHeader
364 UINT32 LocalPciRegister;
367 if (OptionMultiSocketConfiguration.GetCurrPciAddr (&PciAddress, StdHeader)) {
368 PciAddress.Address.Function = FUNC_5;
369 PciAddress.Address.Register = NB_PSTATE_STATUS;
370 LibAmdPciRead (AccessWidth32, PciAddress, &LocalPciRegister, StdHeader);
371 NbFid = ((NB_PSTATE_STS_REGISTER *) &LocalPciRegister)->CurNbFid;
372 NbDid = ((NB_PSTATE_STS_REGISTER *) &LocalPciRegister)->CurNbDid;
373 *FrequencyInMHz = (((NbFid + 4) * 200) / (1 << NbDid));
375 return AGESA_SUCCESS;
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_SUCCESS Northbridge frequency is valid
394 F15OrGetMinMaxNbFrequency (
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
404 UINT32 LocalPciRegister;
405 UINT32 FreqNumerator;
408 AGESA_STATUS AgesaStatus;
411 AgesaStatus = AGESA_ERROR;
413 // Obtain the max NB frequency on the node
414 PciAddress->Address.Function = FUNC_5;
415 PciAddress->Address.Register = NB_PSTATE_0;
416 LibAmdPciRead (AccessWidth32, *PciAddress, &LocalPciRegister, StdHeader);
417 if (((NB_PSTATE_REGISTER *) &LocalPciRegister)->NbPstateEn == 1) {
418 FreqNumerator = ((((NB_PSTATE_REGISTER *) &LocalPciRegister)->NbFid + 4) * 200);
419 FreqDivisor = (1 << ((NB_PSTATE_REGISTER *) &LocalPciRegister)->NbDid);
421 *MaxFreqInMHz = (FreqNumerator / FreqDivisor);
422 AgesaStatus = AGESA_SUCCESS;
425 // If platform configuration disable NB P-states, return the NB P0 frequency
426 // as both the min and max frequency on the node.
427 if (PlatformConfig->PlatformProfile.PlatformPowerPolicy == Performance) {
428 *MinFreqInMHz = *MaxFreqInMHz;
430 PciAddress->Address.Function = FUNC_5;
431 PciAddress->Address.Register = NB_PSTATE_CTRL;
432 LibAmdPciRead (AccessWidth32, *PciAddress, &LocalPciRegister, StdHeader);
433 NbPsMaxVal = (INT8) ((NB_PSTATE_CTRL_REGISTER *) &LocalPciRegister)->NbPstateMaxVal;
435 // Obtain the min NB frequency on the node, starting from NB Pmin
436 for (; NbPsMaxVal >= 0; NbPsMaxVal--) {
437 PciAddress->Address.Function = FUNC_5;
438 PciAddress->Address.Register = (NB_PSTATE_0 + (4 * NbPsMaxVal));
439 LibAmdPciRead (AccessWidth32, *PciAddress, &LocalPciRegister, StdHeader);
441 // Ensure that the NB Pstate is enabled
442 if (((NB_PSTATE_REGISTER *) &LocalPciRegister)->NbPstateEn == 1) {
443 FreqNumerator = ((((NB_PSTATE_REGISTER *) &LocalPciRegister)->NbFid + 4) * 200);
444 FreqDivisor = (1 << ((NB_PSTATE_REGISTER *) &LocalPciRegister)->NbDid);
446 *MinFreqInMHz = (FreqNumerator / FreqDivisor);
447 AgesaStatus = AGESA_SUCCESS;
452 IDS_OPTION_HOOK (IDS_NBPS_MIN_FREQ, MinFreqInMHz, StdHeader);
456 /*---------------------------------------------------------------------------------------*/
458 * Determines the NB clock on the desired node.
460 * @CpuServiceMethod{::F_CPU_GET_NB_PSTATE_INFO}.
462 * @param[in] FamilySpecificServices The current Family Specific Services.
463 * @param[in] PlatformConfig Platform profile/build option config structure.
464 * @param[in] PciAddress The segment, bus, and device numbers of the CPU in question.
465 * @param[in] NbPstate The NB P-state number to check.
466 * @param[out] FreqNumeratorInMHz The desired node's frequency numerator in megahertz.
467 * @param[out] FreqDivisor The desired node's frequency divisor.
468 * @param[out] VoltageInuV The desired node's voltage in microvolts.
469 * @param[in] StdHeader Handle of Header for calling lib functions and services.
471 * @retval TRUE NbPstate is valid
472 * @retval FALSE NbPstate is disabled or invalid
475 F15OrGetNbPstateInfo (
476 IN CPU_SPECIFIC_SERVICES *FamilySpecificServices,
477 IN PLATFORM_CONFIGURATION *PlatformConfig,
478 IN PCI_ADDR *PciAddress,
480 OUT UINT32 *FreqNumeratorInMHz,
481 OUT UINT32 *FreqDivisor,
482 OUT UINT32 *VoltageInuV,
483 IN AMD_CONFIG_PARAMS *StdHeader
486 UINT32 LocalPciRegister;
487 BOOLEAN PstateIsValid;
489 PstateIsValid = FALSE;
491 // If NB P1, P2, or P3 is requested, make sure that NB Pstate is enabled
492 if ((NbPstate == 0) || (FamilySpecificServices->IsNbPstateEnabled (FamilySpecificServices, PlatformConfig, StdHeader))) {
493 PciAddress->Address.Function = FUNC_5;
494 PciAddress->Address.Register = NB_PSTATE_CTRL;
495 LibAmdPciRead (AccessWidth32, *PciAddress, &LocalPciRegister, StdHeader);
497 if (NbPstate <= ((NB_PSTATE_CTRL_REGISTER *) &LocalPciRegister)->NbPstateMaxVal) {
498 PciAddress->Address.Register = (NB_PSTATE_0 + (4 * NbPstate));
499 LibAmdPciRead (AccessWidth32, *PciAddress, &LocalPciRegister, StdHeader);
501 // Ensure that requested NbPstate is enabled
502 if (((NB_PSTATE_REGISTER *) &LocalPciRegister)->NbPstateEn == 1) {
503 *FreqNumeratorInMHz = ((((NB_PSTATE_REGISTER *) &LocalPciRegister)->NbFid + 4) * 200);
504 *FreqDivisor = (1 << ((NB_PSTATE_REGISTER *) &LocalPciRegister)->NbDid);
505 *VoltageInuV = (1550000 - (12500 * (((NB_PSTATE_REGISTER *) &LocalPciRegister)->NbVid)));
506 PstateIsValid = TRUE;
510 return PstateIsValid;
513 /*---------------------------------------------------------------------------------------*/
515 * Get the number of physical cores of current processor.
517 * @CpuServiceMethod{::F_CPU_NUMBER_OF_PHYSICAL_CORES}.
519 * @param[in] FamilySpecificServices The current Family Specific Services.
520 * @param[in] StdHeader Handle of Header for calling lib functions and services.
522 * @return The number of physical cores.
525 F15OrGetNumberOfPhysicalCores (
526 IN CPU_SPECIFIC_SERVICES *FamilySpecificServices,
527 IN AMD_CONFIG_PARAMS *StdHeader
535 UINT32 LocalPciRegister;
537 AGESA_STATUS IgnoredSts;
540 IdentifyCore (StdHeader, &Socket, &Module, &Core, &IgnoredSts);
541 for (Module = 0; Module < GetPlatformNumberOfModules (); Module++) {
542 if (GetPciAddress (StdHeader, Socket, Module, &PciAddress, &IgnoredSts)) {
543 PciAddress.Address.Function = FUNC_5;
544 PciAddress.Address.Register = NORTH_BRIDGE_CAPABILITIES_2_REG;
545 LibAmdPciRead (AccessWidth32, PciAddress, &LocalPciRegister, StdHeader);
546 CmpCapOnNode = (UINT8) (LocalPciRegister & 0xFF);
548 CmpCap += CmpCapOnNode;
551 return ((UINT8) CmpCap);
554 /*---------------------------------------------------------------------------------------*/
556 * Use the Mailbox Register to get the Ap Mailbox info for the current core.
558 * @CpuServiceMethod{::F_CPU_AMD_GET_AP_MAILBOX_FROM_HARDWARE}.
560 * Access the mailbox register used with this NB family. This is valid until the
561 * point that some init code initializes the mailbox register for its normal use.
562 * The Machine Check Misc (Thresholding) register is available as both a PCI config
563 * register and a MSR, so it can be used as a mailbox from HT to other functions.
565 * @param[in] FamilySpecificServices The current Family Specific Services.
566 * @param[out] ApMailboxInfo The AP Mailbox info
567 * @param[in] StdHeader Handle of Header for calling lib functions and services.
571 F15OrGetApMailboxFromHardware (
572 IN CPU_SPECIFIC_SERVICES *FamilySpecificServices,
573 OUT AP_MAILBOXES *ApMailboxInfo,
574 IN AMD_CONFIG_PARAMS *StdHeader
579 LibAmdMsrRead (MSR_MC_MISC_LINK_THRESHOLD, &MailboxInfo, StdHeader);
580 // Mailbox info is in bits 32 thru 43, 12 bits.
581 ApMailboxInfo->ApMailInfo.Info = (((UINT32) (MailboxInfo >> 32)) & (UINT32)0x00000FFF);
582 LibAmdMsrRead (MSR_MC_MISC_L3_THRESHOLD, &MailboxInfo, StdHeader);
583 // Mailbox info is in bits 32 thru 43, 12 bits.
584 ApMailboxInfo->ApMailExtInfo.Info = (((UINT32) (MailboxInfo >> 32)) & (UINT32)0x00000FFF);
588 /*---------------------------------------------------------------------------------------*/
590 * Set the system AP core number in the AP's Mailbox.
592 * @CpuServiceMethod{::F_CPU_SET_AP_CORE_NUMBER}.
594 * Access the mailbox register used with this NB family. This is only intended to
595 * run on the BSC at the time of initial AP launch.
597 * @param[in] FamilySpecificServices The current Family Specific Services.
598 * @param[in] Socket The AP's socket
599 * @param[in] Module The AP's module
600 * @param[in] ApCoreNumber The AP's unique core number
601 * @param[in] StdHeader Handle of Header for calling lib functions and services.
605 F15OrSetApCoreNumber (
606 IN CPU_SPECIFIC_SERVICES *FamilySpecificServices,
609 IN UINT32 ApCoreNumber,
610 IN AMD_CONFIG_PARAMS *StdHeader
613 UINT32 LocalPciRegister;
615 AGESA_STATUS IgnoredStatus;
617 GetPciAddress (StdHeader, Socket, Module, &PciAddress, &IgnoredStatus);
618 PciAddress.Address.Function = FUNC_3;
619 PciAddress.Address.Register = 0x170;
620 LibAmdPciRead (AccessWidth32, PciAddress, &LocalPciRegister, StdHeader);
621 ((AP_MAIL_EXT_INFO *) &LocalPciRegister)->Fields.HeapIndex = ApCoreNumber;
622 LibAmdPciWrite (AccessWidth32, PciAddress, &LocalPciRegister, StdHeader);
626 /*---------------------------------------------------------------------------------------*/
628 * Get this AP's system core number from hardware.
630 * @CpuServiceMethod{::F_CPU_GET_AP_CORE_NUMBER}.
632 * Returns the system core number from the scratch MSR, where
633 * it was saved at heap initialization.
635 * @param[in] FamilySpecificServices The current Family Specific Services.
636 * @param[in] StdHeader Handle of Header for calling lib functions and services.
638 * @return The AP's unique core number
641 F15OrGetApCoreNumber (
642 IN CPU_SPECIFIC_SERVICES *FamilySpecificServices,
643 IN AMD_CONFIG_PARAMS *StdHeader
646 NODE_ID_MSR NodeIdMsr;
648 LibAmdMsrRead (0xC001100C, &NodeIdMsr.Value, StdHeader);
649 return (UINT32) NodeIdMsr.Fields.BiosScratch;
653 /*---------------------------------------------------------------------------------------*/
655 * Move the AP's core number from the mailbox to hardware.
657 * @CpuServiceMethod{::F_CPU_TRANSFER_AP_CORE_NUMBER}.
659 * Transfers this AP's system core number from the mailbox to
660 * the NodeId MSR and initializes the other NodeId fields.
662 * @param[in] FamilySpecificServices The current Family Specific Services.
663 * @param[in] StdHeader Handle of Header for calling lib functions and services.
667 F15OrTransferApCoreNumber (
668 IN CPU_SPECIFIC_SERVICES *FamilySpecificServices,
669 IN AMD_CONFIG_PARAMS *StdHeader
672 AP_MAILBOXES Mailboxes;
673 NODE_ID_MSR NodeIdMsr;
677 FamilySpecificServices->GetApMailboxFromHardware (FamilySpecificServices, &Mailboxes, StdHeader);
678 NodeIdMsr.Fields.BiosScratch = Mailboxes.ApMailExtInfo.Fields.HeapIndex;
679 NodeIdMsr.Fields.NodeId = Mailboxes.ApMailInfo.Fields.Node;
680 NodeIdMsr.Fields.NodesPerProcessor = Mailboxes.ApMailInfo.Fields.ModuleType;
681 LibAmdMsrWrite (0xC001100C, &NodeIdMsr.Value, StdHeader);
683 // Indicate that the NodeId MSR is supported.
684 LibAmdMsrRead (MSR_CPUID_EXT_FEATS, &ExtFeatures, StdHeader);
685 ExtFeatures = (ExtFeatures | BIT51);
686 LibAmdMsrWrite (MSR_CPUID_EXT_FEATS, &ExtFeatures, StdHeader);
690 /*---------------------------------------------------------------------------------------*/
692 * Disable NB P-state.
693 * - clear F5x1[6C:64]
694 * - clear F5x170[NbPstateMaxVal]
695 * - set F5x170[SwNbPstateLoDis]
696 * - clear MSRC001_00[6B:64][NbPstate]
698 * @param[in] FamilySpecificServices The current Family Specific Services
699 * @param[in] CpuEarlyParamsPtr Service Parameters
700 * @param[in] StdHeader Handle of Header for calling lib functions and services.
704 IN CPU_SPECIFIC_SERVICES *FamilySpecificServices,
705 IN AMD_CPU_EARLY_PARAMS *CpuEarlyParamsPtr,
706 IN AMD_CONFIG_PARAMS *StdHeader
715 // Check whether NB P-state is disabled
716 if (!FamilySpecificServices->IsNbPstateEnabled (FamilySpecificServices, &CpuEarlyParamsPtr->PlatformConfig, StdHeader)) {
718 IDS_HDT_CONSOLE (CPU_TRACE, " NB Pstates disabled\n");
720 OptionMultiSocketConfiguration.GetCurrPciAddr (&PciAddress, StdHeader);
722 AndMask = 0x00000000;
723 // If NbPstateHi is not NB P0, get the Pstate pointed to by NbPstateHi and copy it's value to NB P0
724 PciAddress.Address.Function = FUNC_5;
725 PciAddress.Address.Register = NB_PSTATE_CTRL;
726 LibAmdPciRead (AccessWidth32, PciAddress, &PciData, StdHeader);
727 if (((NB_PSTATE_CTRL_REGISTER *) &PciData)->NbPstateHi != 0) {
728 PciAddress.Address.Register = NB_PSTATE_0 + (((NB_PSTATE_CTRL_REGISTER *) &PciData)->NbPstateHi * 4);
729 LibAmdPciRead (AccessWidth32, PciAddress, &PciData, StdHeader);
730 PciAddress.Address.Register = NB_PSTATE_0;
731 OptionMultiSocketConfiguration.ModifyCurrSocketPci (&PciAddress, AndMask, PciData, StdHeader);
735 for (i = 1; i < NM_NB_PS_REG; i++) {
736 PciAddress.Address.Register = NB_PSTATE_0 + (i * 4);
737 OptionMultiSocketConfiguration.ModifyCurrSocketPci (&PciAddress, AndMask, AndMask, StdHeader);
740 // Clear F5x170[NbPstateMaxVal] and set F5x170[SwNbPstateLoDis]
741 PciAddress.Address.Register = NB_PSTATE_CTRL;
742 AndMask = 0xFFFFFFFF;
743 PciData = 0x00000000;
744 ((NB_PSTATE_CTRL_REGISTER *) &AndMask)->NbPstateMaxVal = 0;
745 ((NB_PSTATE_CTRL_REGISTER *) &PciData)->SwNbPstateLoDis = 1;
746 OptionMultiSocketConfiguration.ModifyCurrSocketPci (&PciAddress, AndMask, PciData, StdHeader);
748 // Clear MSRC001_00[6B:64][NbPstate] on cores
749 TaskPtr.FuncAddress.PfApTask = F15OrNbPstateDisCore;
750 TaskPtr.DataTransfer.DataSizeInDwords = 0;
751 TaskPtr.DataTransfer.DataPtr = NULL;
752 TaskPtr.ExeFlags = WAIT_FOR_CORE;
753 ApUtilRunCodeOnAllLocalCoresAtEarly (&TaskPtr, StdHeader, CpuEarlyParamsPtr);
755 // Once we are done disabling NB Pstates, clear F5x170[SwNbPstateLoDis]
756 AndMask = 0xFFFFFFFF;
757 PciData = 0x00000000;
758 ((NB_PSTATE_CTRL_REGISTER *) &AndMask)->SwNbPstateLoDis = 0;
759 OptionMultiSocketConfiguration.ModifyCurrSocketPci (&PciAddress, AndMask, PciData, StdHeader);
764 /*---------------------------------------------------------------------------------------*/
766 * Disable NB P-state on core.
767 * - clear MSRC001_00[6B:64][NbPstate].
769 * @param[in] StdHeader Handle of Header for calling lib functions and services.
773 F15OrNbPstateDisCore (
774 IN AMD_CONFIG_PARAMS *StdHeader
780 // Only one core per compute unit needs to clear NbPstate in P-state MSRs
781 if (IsCorePairPrimary (FirstCoreIsComputeUnitPrimary, StdHeader)) {
782 for (i = MSR_PSTATE_0; i <= MSR_PSTATE_7; i++) {
783 LibAmdMsrRead (i, &MsrData, StdHeader);
784 ((PSTATE_MSR *) &MsrData)->NbPstate = 0;
785 LibAmdMsrWrite (i, &MsrData, StdHeader);
790 /*---------------------------------------------------------------------------------------*/
792 * A Family Specific Workaround method, to override CPU TDP Limit 2 setting.
794 * \@TableTypeFamSpecificInstances.
796 * @param[in] Data The table data value, for example to indicate which CPU and Platform types matched.
797 * @param[in] StdHeader Config params for library, services.
800 F15OrOverrideNodeTdpLimit (
802 IN AMD_CONFIG_PARAMS *StdHeader
806 UINT32 LocalPciRegister;
807 BOOLEAN IsMultiNodeCpu;
810 IsMultiNodeCpu = FALSE;
811 // check if it is MCM part
812 if (OptionMultiSocketConfiguration.GetCurrPciAddr (&PciAddress, StdHeader)) {
813 PciAddress.Address.Function = FUNC_3;
814 PciAddress.Address.Register = NB_CAPS_REG;
815 LibAmdPciRead (AccessWidth32, PciAddress, &LocalPciRegister, StdHeader);
816 IsMultiNodeCpu = (BOOLEAN) (((NB_CAPS_REGISTER *) &LocalPciRegister)->MultiNodeCpu == 1);
819 if (IsMultiNodeCpu) {
820 PciAddress.Address.Function = FUNC_4;
821 PciAddress.Address.Register = 0x10C;
822 LibAmdPciRead (AccessWidth32, PciAddress, &LocalPciRegister, StdHeader);
824 // The correct value is the half of the fused value
825 OrMask = LocalPciRegister & 0xFFFFF000;
826 LocalPciRegister = ((LocalPciRegister & 0x00000FFF) >> 1) | OrMask;
827 LibAmdPciWrite (AccessWidth32, PciAddress, &LocalPciRegister, StdHeader);
831 /*---------------------------------------------------------------------------------------*/
833 * A Family Specific Workaround method, to override CPU Node TDP Accumulator Throttle Threshold setting.
835 * \@TableTypeFamSpecificInstances.
837 * @param[in] Data The table data value, for example to indicate which CPU and Platform types matched.
838 * @param[in] StdHeader Config params for library, services.
841 F15OrOverrideNodeTdpAccumulatorThrottleThreshold (
843 IN AMD_CONFIG_PARAMS *StdHeader
849 UINT32 LocalPciRegister;
852 if (OptionMultiSocketConfiguration.GetCurrPciAddr (&PciAddress, StdHeader)) {
853 PciAddress.Address.Function = FUNC_5;
854 PciAddress.Address.Register = 0x84;
855 LibAmdPciRead (AccessWidth32, PciAddress, &LocalPciRegister, StdHeader);
856 CmpCap = (UINT8) (LocalPciRegister & 0x000000FF);
859 // check if the part is fused with 1 core enabled per compute unit
860 PciAddress.Address.Register = 0x80;
861 LibAmdPciRead (AccessWidth32, PciAddress, &CUStatus, StdHeader);
862 if ((CUStatus & 0x000F0000) != 0) {
863 CmpCap = CmpCap >> 1;
866 PciAddress.Address.Register = 0xBC;
867 LibAmdPciRead (AccessWidth32, PciAddress, &OrMask, StdHeader);
868 OrMask = (UINT32) ((OrMask & 0x000FFFFF) * CmpCap);
870 PciAddress.Address.Register = 0xB4;
871 LibAmdPciRead (AccessWidth32, PciAddress, &LocalPciRegister, StdHeader);
872 // The correct value is F5xBC[CmpUnitTdpAccThrottleThreshold] x ((F5x84[CmpCap] + 1) / 2).
873 LocalPciRegister = (LocalPciRegister & 0xFFF00000) | (OrMask & 0x000FFFFF);
874 LibAmdPciWrite (AccessWidth32, PciAddress, &LocalPciRegister, StdHeader);
878 /*---------------------------------------------------------------------------------------*/
880 * A Family Specific Workaround method, to sync internal node 1 SbiAddr setting.
882 * \@TableTypeFamSpecificInstances.
884 * @param[in] Data The table data value, for example to indicate which CPU and Platform types matched.
885 * @param[in] StdHeader Config params for library, services.
888 F15OrSyncInternalNode1SbiAddr (
890 IN AMD_CONFIG_PARAMS *StdHeader
899 AGESA_STATUS AgesaStatus;
901 AP_MAIL_INFO ApMailboxInfo;
902 UINT32 LocalPciRegister;
904 ApMailboxInfo.Info = 0;
906 GetApMailbox (&ApMailboxInfo.Info, StdHeader);
907 ASSERT (ApMailboxInfo.Fields.Socket < MAX_SOCKETS);
908 ASSERT (ApMailboxInfo.Fields.Module < MAX_DIES);
909 Socket = ApMailboxInfo.Fields.Socket;
910 Module = ApMailboxInfo.Fields.Module;
911 ModuleType = ApMailboxInfo.Fields.ModuleType;
913 // sync is just needed on multinode cpu
914 if (ModuleType != 0) {
915 // check if it is internal node 0 of every socket
917 if (GetPciAddress (StdHeader, Socket, Module, &PciAddress, &AgesaStatus)) {
918 PciAddress.Address.Function = FUNC_3;
919 PciAddress.Address.Register = 0x1E4;
920 // read internal node 0 F3x1E4[6:4]
921 LibAmdPciRead (AccessWidth32, PciAddress, &LocalPciRegister, StdHeader);
922 DataOr = LocalPciRegister & ((UINT32) (7 << 4));
923 DataAnd = ~(UINT32) (7 << 4);
924 for (SyncToModule = 1; SyncToModule < GetPlatformNumberOfModules (); SyncToModule++) {
925 if (GetPciAddress (StdHeader, Socket, SyncToModule, &PciAddress, &AgesaStatus)) {
926 PciAddress.Address.Function = FUNC_3;
927 PciAddress.Address.Register = 0x1E4;
928 // sync the other internal node F3x1E4[6:4]
929 LibAmdPciRead (AccessWidth32, PciAddress, &LocalPciRegister, StdHeader);
930 LocalPciRegister &= DataAnd;
931 LocalPciRegister |= DataOr;
932 LibAmdPciWrite (AccessWidth32, PciAddress, &LocalPciRegister, StdHeader);