5 * AMD CPU Late Init API
7 * Contains code for doing any late CPU initialization.
9 * @xrefitem bom "File Content Label" "Release Content"
12 * @e \$Revision: 44324 $ @e \$Date: 2010-12-22 17:16:51 +0800 (Wed, 22 Dec 2010) $
16 ******************************************************************************
18 * Copyright (c) 2011, 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.
42 ******************************************************************************
45 /*----------------------------------------------------------------------------------------
46 * M O D U L E S U S E D
47 *----------------------------------------------------------------------------------------
52 #include "cpuLateInit.h"
53 #include "cpuRegisters.h"
54 #include "GeneralServices.h"
55 #include "cpuServices.h"
60 #define FILECODE PROC_CPU_CPULATEINIT_FILECODE
61 /*----------------------------------------------------------------------------------------
62 * D E F I N I T I O N S A N D M A C R O S
63 *----------------------------------------------------------------------------------------
66 /*----------------------------------------------------------------------------------------
67 * T Y P E D E F S A N D S T R U C T U R E S
68 *----------------------------------------------------------------------------------------
71 /*----------------------------------------------------------------------------------------
72 * 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
73 *----------------------------------------------------------------------------------------
77 IN AMD_CONFIG_PARAMS *StdHeader
79 /*----------------------------------------------------------------------------------------
80 * E X P O R T E D F U N C T I O N S
81 *----------------------------------------------------------------------------------------
85 /*---------------------------------------------------------------------------------------*/
87 * Performs CPU related initialization at the late entry point
89 * This function should be the last function run by the AGESA
90 * CPU module and prepares the processor for the operating system
91 * bootstrap load process.
93 * @param[in] StdHeader Config handle for library and services
95 * @retval AGESA_SUCCESS
100 IN AMD_CONFIG_PARAMS *StdHeader
103 DisableCf8ExtCfg (StdHeader);
104 return (AGESA_SUCCESS);
107 /*---------------------------------------------------------------------------------------*/
109 * Clear EnableCf8ExtCfg on all socket
111 * Clear F3x8C bit 14 EnableCf8ExtCfg
113 * @param[in] StdHeader Config handle for library and services
119 IN AMD_CONFIG_PARAMS *StdHeader
122 AGESA_STATUS AgesaStatus;
127 UINT32 LegacyPciAccess;
129 ASSERT (IsBsp (StdHeader, &AgesaStatus));
131 for (Socket = 0; Socket < GetPlatformNumberOfSockets (); Socket++) {
132 for (Module = 0; Module < GetPlatformNumberOfModules (); Module++) {
133 if (GetPciAddress (StdHeader, Socket, Module, &PciAddress, &AgesaStatus)) {
134 PciAddress.Address.Function = FUNC_3;
135 PciAddress.Address.Register = NB_CFG_HIGH_REG;
136 LegacyPciAccess = ((1 << 31) + (PciAddress.Address.Register & 0xFC) + (PciAddress.Address.Function << 8) + (PciAddress.Address.Device << 11) + (PciAddress.Address.Bus << 16) + ((PciAddress.Address.Register & 0xF00) << (24 - 8)));
137 // read from PCI register
138 LibAmdIoWrite (AccessWidth32, IOCF8, &LegacyPciAccess, StdHeader);
139 LibAmdIoRead (AccessWidth32, IOCFC, &PciData, StdHeader);
141 PciData &= 0xFFFFBFFF;
142 // write to PCI register
143 LibAmdIoWrite (AccessWidth32, IOCF8, &LegacyPciAccess, StdHeader);
144 LibAmdIoWrite (AccessWidth32, IOCFC, &PciData, StdHeader);
150 /*---------------------------------------------------------------------------------------*/
152 * Calculate an ACPI style checksum
154 * Computes the checksum and stores the value to the checksum
155 * field of the passed in ACPI table's header.
157 * @param[in] Table ACPI table to checksum
158 * @param[in] StdHeader Config handle for library and services
163 IN OUT ACPI_TABLE_HEADER *Table,
164 IN AMD_CONFIG_PARAMS *StdHeader
173 BuffTempPtr = (UINT8 *) Table;
174 for (BufferOffset = 0; BufferOffset < Table->TableLength; BufferOffset++) {
175 Checksum = Checksum - *(BuffTempPtr + BufferOffset);
178 Table->Checksum = Checksum;
181 /*---------------------------------------------------------------------------------------*/
184 * Run code on every AP in the system.
186 * @param[in] ApParams AP task pointer.
187 * @param[in] StdHeader Handle to config for library and services
189 * @return The most severe AGESA_STATUS returned by an AP.
193 RunLateApTaskOnAllAPs (
194 IN AP_EXE_PARAMS *ApParams,
195 IN AMD_CONFIG_PARAMS *StdHeader
198 UINT32 NumberOfSockets;
199 UINT32 NumberOfCores;
206 AGESA_STATUS CalledStatus;
207 AGESA_STATUS IgnoredStatus;
208 AGESA_STATUS AgesaStatus;
210 ASSERT (IsBsp (StdHeader, &IgnoredStatus));
212 AgesaStatus = AGESA_SUCCESS;
214 IdentifyCore (StdHeader, &BscSocket, &Ignored, &BscCoreNum, &IgnoredStatus);
215 NumberOfSockets = GetPlatformNumberOfSockets ();
217 for (Socket = 0; Socket < NumberOfSockets; Socket++) {
218 if (GetActiveCoresInGivenSocket (Socket, &NumberOfCores, StdHeader)) {
219 for (Core = 0; Core < NumberOfCores; Core++) {
220 if ((Socket != BscSocket) || (Core != BscCoreNum)) {
221 GetApicId (StdHeader, Socket, Core, &ApicId, &IgnoredStatus);
222 AGESA_TESTPOINT (TpIfBeforeRunApFromAllAps, StdHeader);
223 CalledStatus = AgesaRunFcnOnAp ((UINTN) ApicId, ApParams);
224 AGESA_TESTPOINT (TpIfAfterRunApFromAllAps, StdHeader);
225 if (CalledStatus > AgesaStatus) {
226 AgesaStatus = CalledStatus;
236 /*---------------------------------------------------------------------------------------*/
239 * Run code on core 0 of every socket in the system.
241 * @param[in] ApParams AP task pointer.
242 * @param[in] StdHeader Handle to config for library and services
244 * @return The most severe AGESA_STATUS returned by an AP.
248 RunLateApTaskOnAllCore0s (
249 IN AP_EXE_PARAMS *ApParams,
250 IN AMD_CONFIG_PARAMS *StdHeader
253 UINT32 NumberOfSockets;
257 UINT32 IgnoredModule;
259 AGESA_STATUS CalledStatus;
260 AGESA_STATUS IgnoredStatus;
261 AGESA_STATUS AgesaStatus;
263 ASSERT (IsBsp (StdHeader, &IgnoredStatus));
265 AgesaStatus = AGESA_SUCCESS;
267 IdentifyCore (StdHeader, &BscSocket, &IgnoredModule, &IgnoredCore, &IgnoredStatus);
268 NumberOfSockets = GetPlatformNumberOfSockets ();
270 for (Socket = 0; Socket < NumberOfSockets; Socket++) {
271 if (IsProcessorPresent (Socket, StdHeader)) {
272 if (Socket != BscSocket) {
273 GetApicId (StdHeader, Socket, 0, &ApicId, &IgnoredStatus);
274 AGESA_TESTPOINT (TpIfBeforeRunApFromAllCore0s, StdHeader);
275 CalledStatus = AgesaRunFcnOnAp ((UINTN) ApicId, ApParams);
276 AGESA_TESTPOINT (TpIfAfterRunApFromAllCore0s, StdHeader);
277 if (CalledStatus > AgesaStatus) {
278 AgesaStatus = CalledStatus;