5 * AMD Family_15 Orochi NB COF VID Initialization
7 * Performs the "BIOS Northbridge COF and VID Configuration" as
8 * described in the BKDG.
10 * @xrefitem bom "File Content Label" "Release Content"
12 * @e sub-project: CPU/Family/0x15/OR
13 * @e \$Revision: 51891 $ @e \$Date: 2011-04-28 12:39:55 -0600 (Thu, 28 Apr 2011) $
17 ******************************************************************************
19 * Copyright (C) 2012 Advanced Micro Devices, Inc.
20 * All rights reserved.
22 * Redistribution and use in source and binary forms, with or without
23 * modification, are permitted provided that the following conditions are met:
24 * * Redistributions of source code must retain the above copyright
25 * notice, this list of conditions and the following disclaimer.
26 * * Redistributions in binary form must reproduce the above copyright
27 * notice, this list of conditions and the following disclaimer in the
28 * documentation and/or other materials provided with the distribution.
29 * * Neither the name of Advanced Micro Devices, Inc. nor the names of
30 * its contributors may be used to endorse or promote products derived
31 * from this software without specific prior written permission.
33 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
34 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
35 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
36 * DISCLAIMED. IN NO EVENT SHALL ADVANCED MICRO DEVICES, INC. BE LIABLE FOR ANY
37 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
38 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
39 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
40 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
41 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
42 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
44 ******************************************************************************
47 /*----------------------------------------------------------------------------------------
48 * M O D U L E S U S E D
49 *----------------------------------------------------------------------------------------
53 #include "cpuRegisters.h"
54 #include "cpuF15PowerMgmt.h"
55 #include "cpuF15OrPowerMgmt.h"
56 #include "cpuApicUtilities.h"
57 #include "OptionMultiSocket.h"
58 #include "cpuServices.h"
59 #include "GeneralServices.h"
60 #include "cpuFamilyTranslation.h"
61 #include "F15OrPmNbCofVidInit.h"
66 #define FILECODE PROC_CPU_FAMILY_0X15_OR_F15ORPMNBCOFVIDINIT_FILECODE
69 /*----------------------------------------------------------------------------------------
70 * D E F I N I T I O N S A N D M A C R O S
71 *----------------------------------------------------------------------------------------
74 /*----------------------------------------------------------------------------------------
75 * T Y P E D E F S A N D S T R U C T U R E S
76 *----------------------------------------------------------------------------------------
79 /*----------------------------------------------------------------------------------------
80 * 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
81 *----------------------------------------------------------------------------------------
85 F15OrPmNbCofVidInitOnCore (
86 IN AMD_CONFIG_PARAMS *StdHeader
89 /*----------------------------------------------------------------------------------------
90 * E X P O R T E D F U N C T I O N S
91 *----------------------------------------------------------------------------------------
93 extern OPTION_MULTISOCKET_CONFIGURATION OptionMultiSocketConfiguration;
95 /*---------------------------------------------------------------------------------------*/
97 * Family 15h Orochi core 0 entry point for performing the "Mixed Northbridge Frequency
98 * Configuration Sequence"
100 * BIOS must match F5x1[6C:60][NbFid, NbDid, NbPstateEn] between all
101 * processors of a multi-socket system. The lowest setting from all
102 * processors is used as the common F5x1[6C:60][NbFid, NbDid]. All
103 * processors must have the same number of NB P-states.
105 * For each node in the system {
106 * For (i = 0; i <= F5x170[NbPstateMaxVal]; i++) {
107 * NewNbFreq = the lowest NBCOF from all processors for NB P-state i
108 * NewNbFid = F5x1[6C:60][NbFid] that corresponds to NewNbFreq
109 * NewNbDid = F5x1[6C:60][NbDid] that corresponds to NewNbFreq
110 * Write NewNbFid and NewNbDid to F5x1[6C:60][NbFid, NbDid] indexed
113 * If (F5x170[NbPstateMaxVal] == 0) {
114 * Save F5x170 and F5x1[6C:60] indexed by NB P-state 1
115 * Copy F5x1[6C:60] indexed by NB P-state 0 to F5x1[6C:60] indexed by NB P-state 1
116 * Write 1 to F5x170[NbPstateMaxVal, NbPstateLo]
117 * Write 0 to F5x170[SwNbPstateLoDis, NbPstateDisOnP0, NbPstateThreshold]
118 * Wait for F5x174[CurNbPstate] = F5x170[NbPstateLo] and F5x174[CurNbFid, CurNb-
119 * Did]=[NbFid, NbDid] from F5x1[6C:60] indexed by F5x170[NbPstateLo]
120 * Restore F5x170 and F5x1[6C:60] indexed by NB P-state 1
121 * Wait for F5x174[CurNbPstate] = F5x170[NbPstateHi]
125 * @param[in] FamilySpecificServices The current Family Specific Services.
126 * @param[in] CpuEarlyParamsPtr Service related parameters (unused).
127 * @param[in] StdHeader Config handle for library and services.
131 F15OrPmNbCofVidInit (
132 IN CPU_SPECIFIC_SERVICES *FamilySpecificServices,
133 IN AMD_CPU_EARLY_PARAMS *CpuEarlyParamsPtr,
134 IN AMD_CONFIG_PARAMS *StdHeader
143 UINT32 LocalPciRegister;
149 BOOLEAN PstateSettingsChanged;
150 BOOLEAN PstatesMatch;
151 BOOLEAN PstateEnabledAll;
154 AGESA_STATUS IgnoredSts;
156 // Get the local node ID
157 IdentifyCore (StdHeader, &Socket, &Module, &Core, &IgnoredSts);
161 PstateSettingsChanged = FALSE;
162 GetPciAddress (StdHeader, Socket, Module, &PciAddress, &IgnoredSts);
163 PciAddress.Address.Function = FUNC_5;
164 PciAddress.Address.Register = NB_PSTATE_CTRL;
165 LibAmdPciRead (AccessWidth32, PciAddress, &NbPsCtrl, StdHeader);
166 for (i = 0; i <= ((NB_PSTATE_CTRL_REGISTER *) &NbPsCtrl)->NbPstateMaxVal; i++) {
167 if (OptionMultiSocketConfiguration.GetSystemNbPstateSettings (i, &CpuEarlyParamsPtr->PlatformConfig, &NbFreq, &NbDiv, &PstatesMatch, &PstateEnabledAll, StdHeader)) {
168 if (PstateEnabledAll) {
169 // Valid system-wide NB P-state
171 // Configure NbPstate[i] to match the slowest
172 PciAddress.Address.Register = (NB_PSTATE_0 + (4 * i));
173 LibAmdPciRead (AccessWidth32, PciAddress, &LocalPciRegister, StdHeader);
175 ((NB_PSTATE_REGISTER *) &OrMask)->NbFid = ((NbFreq / 200) - 4);
176 ((NB_PSTATE_REGISTER *) &OrMask)->NbDid = (UINT32) LibAmdBitScanForward (NbDiv);
177 if ((((NB_PSTATE_REGISTER *) &OrMask)->NbFid != ((NB_PSTATE_REGISTER *) &LocalPciRegister)->NbFid) ||
178 (((NB_PSTATE_REGISTER *) &OrMask)->NbDid != ((NB_PSTATE_REGISTER *) &LocalPciRegister)->NbDid)) {
179 AndMask = 0xFFFFFFFF;
180 ((NB_PSTATE_REGISTER *) &AndMask)->NbFid = 0;
181 ((NB_PSTATE_REGISTER *) &AndMask)->NbDid = 0;
182 OptionMultiSocketConfiguration.ModifyCurrSocketPci (&PciAddress, AndMask, OrMask, StdHeader);
183 PstateSettingsChanged = TRUE;
187 // At least one processor in the system does not have NbPstate[i]
188 PciAddress.Address.Register = NB_PSTATE_CTRL;
189 AndMask = 0xFFFFFFFF;
190 ((NB_PSTATE_CTRL_REGISTER *) &AndMask)->NbPstateMaxVal = 0;
193 ((NB_PSTATE_CTRL_REGISTER *) &OrMask)->NbPstateMaxVal = (i - 1);
195 // Modify NbPstateMaxVal to reflect the system value
196 OptionMultiSocketConfiguration.ModifyCurrSocketPci (&PciAddress, AndMask, OrMask, StdHeader);
198 // Disable this NB P-state
199 PciAddress.Address.Register = (NB_PSTATE_0 + (4 * i));
200 AndMask = 0xFFFFFFFF;
201 ((NB_PSTATE_REGISTER *) &AndMask)->NbPstateEn = 0;
203 OptionMultiSocketConfiguration.ModifyCurrSocketPci (&PciAddress, AndMask, OrMask, StdHeader);
205 // Log error for the invalid configuration
206 PutEventLog (AGESA_ERROR,
207 CPU_ERROR_PM_NB_PSTATE_MISMATCH,
208 Socket, i, 0, 0, StdHeader);
214 if (PstateSettingsChanged) {
215 PciAddress.Address.Register = NB_PSTATE_CTRL;
216 LibAmdPciRead (AccessWidth32, PciAddress, &NbPsCtrl, StdHeader);
217 if (((NB_PSTATE_CTRL_REGISTER *) &NbPsCtrl)->NbPstateMaxVal == 0) {
218 // Launch one core per node.
219 TaskPtr.FuncAddress.PfApTask = F15OrPmNbCofVidInitOnCore;
220 TaskPtr.DataTransfer.DataSizeInDwords = 0;
221 TaskPtr.ExeFlags = WAIT_FOR_CORE;
222 for (Module = 0; Module < GetPlatformNumberOfModules (); Module++) {
223 if (GetGivenModuleCoreRange (Socket, Module, &TaskedCore, &Ignored, StdHeader)) {
224 if (TaskedCore != 0) {
225 ApUtilRunCodeOnSocketCore ((UINT8) Socket, (UINT8) TaskedCore, &TaskPtr, StdHeader);
229 ApUtilTaskOnExecutingCore (&TaskPtr, StdHeader, (VOID *) CpuEarlyParamsPtr);
234 /*---------------------------------------------------------------------------------------
235 * L O C A L F U N C T I O N S
236 *---------------------------------------------------------------------------------------
239 /*---------------------------------------------------------------------------------------*/
241 * Support routine for F15OrPmNbCofVidInit to perform the actual NB P-state transition
242 * to the leveled NB P-state settings on one core of each die in a family 15h socket.
244 * The following steps are performed:
245 * 1. Save F5x170 and F5x1[6C:60] indexed by NB P-state 1
246 * 2. Copy F5x1[6C:60] indexed by NB P-state 0 to F5x1[6C:60] indexed by NB P-state 1
247 * 3, Write 1 to F5x170[NbPstateMaxVal, NbPstateLo]
248 * 4. Write 0 to F5x170[SwNbPstateLoDis, NbPstateDisOnP0, NbPstateThreshold]
249 * 5. Wait for F5x174[CurNbPstate] = F5x170[NbPstateLo] and F5x174[CurNbFid, CurNb-
250 * Did]=[NbFid, NbDid] from F5x1[6C:60] indexed by F5x170[NbPstateLo]
251 * 6. Restore F5x170 and F5x1[6C:60] indexed by NB P-state 1
252 * 7. Wait for F5x174[CurNbPstate] = F5x170[NbPstateHi]
254 * @param[in] StdHeader Config handle for library and services.
259 F15OrPmNbCofVidInitOnCore (
260 IN AMD_CONFIG_PARAMS *StdHeader
266 UINT32 LocalPciRegister;
269 OptionMultiSocketConfiguration.GetCurrPciAddr (&PciAddress, StdHeader);
271 // Save F5x170 and F5x164
272 PciAddress.Address.Function = FUNC_5;
273 PciAddress.Address.Register = NB_PSTATE_CTRL;
274 LibAmdPciRead (AccessWidth32, PciAddress, &NbPsCtrl, StdHeader);
276 PciAddress.Address.Register = NB_PSTATE_0;
277 LibAmdPciRead (AccessWidth32, PciAddress, &NbPs0, StdHeader);
278 PciAddress.Address.Register = NB_PSTATE_1;
279 LibAmdPciRead (AccessWidth32, PciAddress, &NbPs1, StdHeader);
281 // Copy F5x160 to F5x164
282 LibAmdPciWrite (AccessWidth32, PciAddress, &NbPs0, StdHeader);
284 // Write 1 to F5x170[NbPstateMaxVal, NbPstateLo]
285 PciAddress.Address.Register = NB_PSTATE_CTRL;
286 LocalPciRegister = NbPsCtrl;
287 ((NB_PSTATE_CTRL_REGISTER *) &LocalPciRegister)->NbPstateMaxVal = 1;
288 ((NB_PSTATE_CTRL_REGISTER *) &LocalPciRegister)->NbPstateLo = 1;
289 LibAmdPciWrite (AccessWidth32, PciAddress, &LocalPciRegister, StdHeader);
291 // Write 0 to F5x170[SwNbPstateLoDis, NbPstateDisOnP0, NbPstateThreshold]
292 ((NB_PSTATE_CTRL_REGISTER *) &LocalPciRegister)->SwNbPstateLoDis = 0;
293 ((NB_PSTATE_CTRL_REGISTER *) &LocalPciRegister)->NbPstateDisOnP0 = 0;
294 ((NB_PSTATE_CTRL_REGISTER *) &LocalPciRegister)->NbPstateThreshold = 0;
295 LibAmdPciWrite (AccessWidth32, PciAddress, &LocalPciRegister, StdHeader);
297 // Wait for F5x174[CurNbPstate] = F5x170[NbPstateLo] (written to 1 above) and
298 // F5x174[CurNbFid, CurNbDid] = F5x164[NbFid, NbDid]
299 PciAddress.Address.Register = NB_PSTATE_STATUS;
301 LibAmdPciRead (AccessWidth32, PciAddress, &LocalPciRegister, StdHeader);
302 } while ((((NB_PSTATE_STS_REGISTER *) &LocalPciRegister)->CurNbPstate != 1) &&
303 (((NB_PSTATE_STS_REGISTER *) &LocalPciRegister)->CurNbFid != ((NB_PSTATE_REGISTER *) &NbPs0)->NbFid) &&
304 (((NB_PSTATE_STS_REGISTER *) &LocalPciRegister)->CurNbDid != ((NB_PSTATE_REGISTER *) &NbPs0)->NbDid));
306 // Restore F5x170 and F5x164
307 PciAddress.Address.Register = NB_PSTATE_CTRL;
308 LibAmdPciWrite (AccessWidth32, PciAddress, &NbPsCtrl, StdHeader);
309 PciAddress.Address.Register = NB_PSTATE_1;
310 LibAmdPciWrite (AccessWidth32, PciAddress, &NbPs1, StdHeader);
312 // Wait for F5x174[CurNbPstate] = F5x170[NbPstateHi]
313 PciAddress.Address.Register = NB_PSTATE_STATUS;
315 LibAmdPciRead (AccessWidth32, PciAddress, &LocalPciRegister, StdHeader);
316 } while (((NB_PSTATE_STS_REGISTER *) &LocalPciRegister)->CurNbPstate != ((NB_PSTATE_CTRL_REGISTER *) &NbPsCtrl)->NbPstateHi);