5 * AMD AGESA CPU Preserve Registers used for AP Mailbox.
7 * Save and Restore the normal feature content of the registers being used for
10 * @xrefitem bom "File Content Label" "Release Content"
12 * @e sub-project: CPU/Feature
13 * @e \$Revision: 56279 $ @e \$Date: 2011-07-11 13:11:28 -0600 (Mon, 11 Jul 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 *----------------------------------------------------------------------------------------
55 #include "GeneralServices.h"
56 #include "OptionMultiSocket.h"
57 #include "cpuRegisters.h"
58 #include "cpuApicUtilities.h"
59 #include "cpuServices.h"
60 #include "cpuFamilyTranslation.h"
61 #include "cpuFeatures.h"
62 #include "PreserveMailbox.h"
63 #include "heapManager.h"
68 #define FILECODE PROC_CPU_FEATURE_PRESERVEMAILBOX_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 *----------------------------------------------------------------------------------------
84 /*----------------------------------------------------------------------------------------
85 * E X P O R T E D F U N C T I O N S
86 *----------------------------------------------------------------------------------------
88 extern CPU_FAMILY_SUPPORT_TABLE PreserveMailboxFamilyServiceTable;
90 /*---------------------------------------------------------------------------------------*/
92 * The contents of the mailbox registers should always be preserved.
94 * @param[in] PlatformConfig Contains the runtime modifiable feature input data.
95 * @param[in] StdHeader Config Handle for library, services.
97 * @retval TRUE Always TRUE
102 IsPreserveAroundMailboxEnabled (
103 IN PLATFORM_CONFIGURATION *PlatformConfig,
104 IN AMD_CONFIG_PARAMS *StdHeader
110 /*---------------------------------------------------------------------------------------*/
112 * Save and Restore or Initialize the content of the mailbox registers.
114 * The registers used for AP mailbox should have the content related to their function
117 * @param[in] EntryPoint Timepoint designator.
118 * @param[in] PlatformConfig Contains the runtime modifiable feature input data.
119 * @param[in] StdHeader Config Handle for library, services.
121 * @return AGESA_SUCCESS Always succeeds.
127 IN UINT64 EntryPoint,
128 IN PLATFORM_CONFIGURATION *PlatformConfig,
129 IN AMD_CONFIG_PARAMS *StdHeader
132 PRESERVE_MAILBOX_FAMILY_SERVICES *FamilySpecificServices;
135 PCI_ADDR BaseAddress;
136 PCI_ADDR MailboxRegister;
137 PRESERVE_MAILBOX_FAMILY_REGISTER *NextRegister;
138 AGESA_STATUS IgnoredStatus;
139 AGESA_STATUS HeapStatus;
141 ALLOCATE_HEAP_PARAMS AllocateParams;
142 LOCATE_HEAP_PTR LocateParams;
143 UINT32 RegisterEntryIndex;
145 BaseAddress.AddressValue = ILLEGAL_SBDFO;
147 if (EntryPoint == CPU_FEAT_AFTER_COHERENT_DISCOVERY) {
148 // The save step. Save either the register content or zero (for cold boot, if family specifies that).
149 AllocateParams.BufferHandle = PRESERVE_MAIL_BOX_HANDLE;
150 AllocateParams.RequestedBufferSize = (sizeof (UINT32) * (MAX_PRESERVE_REGISTER_ENTRIES * (MAX_SOCKETS * MAX_DIES)));
151 AllocateParams.Persist = HEAP_SYSTEM_MEM;
152 HeapStatus = HeapAllocateBuffer (&AllocateParams, StdHeader);
153 ASSERT ((HeapStatus == AGESA_SUCCESS) && (AllocateParams.BufferPtr != NULL));
154 LibAmdMemFill (AllocateParams.BufferPtr, 0xFF, AllocateParams.RequestedBufferSize, StdHeader);
155 RegisterEntryIndex = 0;
156 for (Socket = 0; Socket < GetPlatformNumberOfSockets (); Socket++) {
157 for (Module = 0; Module < GetPlatformNumberOfModules (); Module++) {
158 if (GetPciAddress (StdHeader, Socket, Module, &BaseAddress, &IgnoredStatus)) {
159 GetFeatureServicesOfSocket (&PreserveMailboxFamilyServiceTable, Socket, (CONST VOID **)&FamilySpecificServices, StdHeader);
160 ASSERT (FamilySpecificServices != NULL);
161 NextRegister = FamilySpecificServices->RegisterList;
162 while (NextRegister->Register.AddressValue != ILLEGAL_SBDFO) {
163 ASSERT (RegisterEntryIndex <
164 (MAX_PRESERVE_REGISTER_ENTRIES * GetPlatformNumberOfSockets () * GetPlatformNumberOfModules ()));
165 if (FamilySpecificServices->IsZeroOnCold && (!IsWarmReset (StdHeader))) {
168 MailboxRegister = BaseAddress;
169 MailboxRegister.Address.Function = NextRegister->Register.Address.Function;
170 MailboxRegister.Address.Register = NextRegister->Register.Address.Register;
171 LibAmdPciRead (AccessWidth32, MailboxRegister, &Value, StdHeader);
172 Value &= NextRegister->Mask;
174 (* (MAILBOX_REGISTER_SAVE_ENTRY) AllocateParams.BufferPtr) [RegisterEntryIndex] = Value;
175 RegisterEntryIndex++;
181 } else if ((EntryPoint == CPU_FEAT_INIT_LATE_END) || (EntryPoint == CPU_FEAT_AFTER_RESUME_MTRR_SYNC)) {
182 // The restore step. Just write out the saved content in the buffer.
183 LocateParams.BufferHandle = PRESERVE_MAIL_BOX_HANDLE;
184 HeapStatus = HeapLocateBuffer (&LocateParams, StdHeader);
185 ASSERT ((HeapStatus == AGESA_SUCCESS) && (LocateParams.BufferPtr != NULL));
186 RegisterEntryIndex = 0;
187 for (Socket = 0; Socket < GetPlatformNumberOfSockets (); Socket++) {
188 for (Module = 0; Module < GetPlatformNumberOfModules (); Module++) {
189 if (GetPciAddress (StdHeader, Socket, Module, &BaseAddress, &IgnoredStatus)) {
190 GetFeatureServicesOfSocket (&PreserveMailboxFamilyServiceTable, Socket, (CONST VOID **)&FamilySpecificServices, StdHeader);
191 NextRegister = FamilySpecificServices->RegisterList;
192 while (NextRegister->Register.AddressValue != ILLEGAL_SBDFO) {
193 ASSERT (RegisterEntryIndex <
194 (MAX_PRESERVE_REGISTER_ENTRIES * GetPlatformNumberOfSockets () * GetPlatformNumberOfModules ()));
195 MailboxRegister = BaseAddress;
196 MailboxRegister.Address.Function = NextRegister->Register.Address.Function;
197 MailboxRegister.Address.Register = NextRegister->Register.Address.Register;
198 LibAmdPciRead (AccessWidth32, MailboxRegister, &Value, StdHeader);
199 Value = ((Value & ~NextRegister->Mask) | (* (MAILBOX_REGISTER_SAVE_ENTRY) LocateParams.BufferPtr) [RegisterEntryIndex]);
200 LibAmdPciWrite (AccessWidth32, MailboxRegister, &Value, StdHeader);
201 RegisterEntryIndex++;
207 HeapStatus = HeapDeallocateBuffer (PRESERVE_MAIL_BOX_HANDLE, StdHeader);
209 return AGESA_SUCCESS;
213 CONST CPU_FEATURE_DESCRIPTOR ROMDATA CpuFeaturePreserveAroundMailbox =
215 PreserveAroundMailbox,
216 (CPU_FEAT_AFTER_COHERENT_DISCOVERY | CPU_FEAT_INIT_LATE_END | CPU_FEAT_AFTER_RESUME_MTRR_SYNC),
217 IsPreserveAroundMailboxEnabled,