zbao | 7d94cf9 | 2012-07-02 14:19:14 +0800 | [diff] [blame] | 1 | /* $NoKeywords:$ */ |
| 2 | /** |
| 3 | * @file |
| 4 | * |
| 5 | * AMD AGESA CPU Preserve Registers used for AP Mailbox. |
| 6 | * |
| 7 | * Save and Restore the normal feature content of the registers being used for |
| 8 | * the AP Mailbox. |
| 9 | * |
| 10 | * @xrefitem bom "File Content Label" "Release Content" |
| 11 | * @e project: AGESA |
| 12 | * @e sub-project: CPU/Feature |
| 13 | * @e \$Revision: 63425 $ @e \$Date: 2011-12-22 11:24:10 -0600 (Thu, 22 Dec 2011) $ |
| 14 | * |
| 15 | */ |
| 16 | /* |
| 17 | ****************************************************************************** |
| 18 | * |
Siyuan Wang | 641f00c | 2013-06-08 11:50:55 +0800 | [diff] [blame] | 19 | * Copyright (c) 2008 - 2012, Advanced Micro Devices, Inc. |
| 20 | * All rights reserved. |
zbao | 7d94cf9 | 2012-07-02 14:19:14 +0800 | [diff] [blame] | 21 | * |
Siyuan Wang | 641f00c | 2013-06-08 11:50:55 +0800 | [diff] [blame] | 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. |
zbao | 7d94cf9 | 2012-07-02 14:19:14 +0800 | [diff] [blame] | 32 | * |
Siyuan Wang | 641f00c | 2013-06-08 11:50:55 +0800 | [diff] [blame] | 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. |
zbao | 7d94cf9 | 2012-07-02 14:19:14 +0800 | [diff] [blame] | 43 | ****************************************************************************** |
| 44 | */ |
| 45 | |
| 46 | /*---------------------------------------------------------------------------------------- |
| 47 | * M O D U L E S U S E D |
| 48 | *---------------------------------------------------------------------------------------- |
| 49 | */ |
| 50 | #include "AGESA.h" |
| 51 | #include "amdlib.h" |
| 52 | #include "Ids.h" |
| 53 | #include "Topology.h" |
| 54 | #include "GeneralServices.h" |
| 55 | #include "OptionMultiSocket.h" |
| 56 | #include "cpuRegisters.h" |
| 57 | #include "cpuApicUtilities.h" |
| 58 | #include "cpuServices.h" |
| 59 | #include "cpuFamilyTranslation.h" |
| 60 | #include "cpuFeatures.h" |
| 61 | #include "PreserveMailbox.h" |
| 62 | #include "heapManager.h" |
| 63 | #include "Filecode.h" |
| 64 | CODE_GROUP (G1_PEICC) |
| 65 | RDATA_GROUP (G1_PEICC) |
| 66 | |
| 67 | #define FILECODE PROC_CPU_FEATURE_PRESERVEMAILBOX_FILECODE |
| 68 | /*---------------------------------------------------------------------------------------- |
| 69 | * D E F I N I T I O N S A N D M A C R O S |
| 70 | *---------------------------------------------------------------------------------------- |
| 71 | */ |
| 72 | |
| 73 | /*---------------------------------------------------------------------------------------- |
| 74 | * T Y P E D E F S A N D S T R U C T U R E S |
| 75 | *---------------------------------------------------------------------------------------- |
| 76 | */ |
| 77 | |
| 78 | /*---------------------------------------------------------------------------------------- |
| 79 | * 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 |
| 80 | *---------------------------------------------------------------------------------------- |
| 81 | */ |
| 82 | |
| 83 | /*---------------------------------------------------------------------------------------- |
| 84 | * E X P O R T E D F U N C T I O N S |
| 85 | *---------------------------------------------------------------------------------------- |
| 86 | */ |
| 87 | extern CPU_FAMILY_SUPPORT_TABLE PreserveMailboxFamilyServiceTable; |
| 88 | |
| 89 | /*---------------------------------------------------------------------------------------*/ |
| 90 | /** |
| 91 | * The contents of the mailbox registers should always be preserved. |
| 92 | * |
| 93 | * @param[in] PlatformConfig Contains the runtime modifiable feature input data. |
| 94 | * @param[in] StdHeader Config Handle for library, services. |
| 95 | * |
| 96 | * @retval TRUE Always TRUE |
| 97 | * |
| 98 | */ |
| 99 | BOOLEAN |
| 100 | STATIC |
| 101 | IsPreserveAroundMailboxEnabled ( |
| 102 | IN PLATFORM_CONFIGURATION *PlatformConfig, |
| 103 | IN AMD_CONFIG_PARAMS *StdHeader |
| 104 | ) |
| 105 | { |
| 106 | return TRUE; |
| 107 | } |
| 108 | |
| 109 | /*---------------------------------------------------------------------------------------*/ |
| 110 | /** |
| 111 | * Save and Restore or Initialize the content of the mailbox registers. |
| 112 | * |
| 113 | * The registers used for AP mailbox should have the content related to their function |
| 114 | * preserved. |
| 115 | * |
| 116 | * @param[in] EntryPoint Timepoint designator. |
| 117 | * @param[in] PlatformConfig Contains the runtime modifiable feature input data. |
| 118 | * @param[in] StdHeader Config Handle for library, services. |
| 119 | * |
| 120 | * @return AGESA_SUCCESS Always succeeds. |
| 121 | * |
| 122 | */ |
| 123 | AGESA_STATUS |
| 124 | STATIC |
| 125 | PreserveMailboxes ( |
| 126 | IN UINT64 EntryPoint, |
| 127 | IN PLATFORM_CONFIGURATION *PlatformConfig, |
| 128 | IN AMD_CONFIG_PARAMS *StdHeader |
| 129 | ) |
| 130 | { |
| 131 | PRESERVE_MAILBOX_FAMILY_SERVICES *FamilySpecificServices; |
| 132 | UINT32 Socket; |
| 133 | UINT32 Module; |
| 134 | PCI_ADDR BaseAddress; |
| 135 | PCI_ADDR MailboxRegister; |
| 136 | PRESERVE_MAILBOX_FAMILY_REGISTER *NextRegister; |
| 137 | AGESA_STATUS IgnoredStatus; |
| 138 | AGESA_STATUS HeapStatus; |
| 139 | UINT32 Value; |
| 140 | ALLOCATE_HEAP_PARAMS AllocateParams; |
| 141 | LOCATE_HEAP_PTR LocateParams; |
| 142 | UINT32 RegisterEntryIndex; |
| 143 | |
| 144 | BaseAddress.AddressValue = ILLEGAL_SBDFO; |
| 145 | |
| 146 | if (EntryPoint == CPU_FEAT_AFTER_COHERENT_DISCOVERY) { |
| 147 | // The save step. Save either the register content or zero (for cold boot, if family specifies that). |
| 148 | AllocateParams.BufferHandle = PRESERVE_MAIL_BOX_HANDLE; |
| 149 | AllocateParams.RequestedBufferSize = (sizeof (UINT32) * (MAX_PRESERVE_REGISTER_ENTRIES * (MAX_SOCKETS * MAX_DIES))); |
| 150 | AllocateParams.Persist = HEAP_SYSTEM_MEM; |
| 151 | HeapStatus = HeapAllocateBuffer (&AllocateParams, StdHeader); |
| 152 | ASSERT ((HeapStatus == AGESA_SUCCESS) && (AllocateParams.BufferPtr != NULL)); |
| 153 | LibAmdMemFill (AllocateParams.BufferPtr, 0xFF, AllocateParams.RequestedBufferSize, StdHeader); |
| 154 | RegisterEntryIndex = 0; |
| 155 | for (Socket = 0; Socket < GetPlatformNumberOfSockets (); Socket++) { |
| 156 | for (Module = 0; Module < GetPlatformNumberOfModules (); Module++) { |
| 157 | if (GetPciAddress (StdHeader, Socket, Module, &BaseAddress, &IgnoredStatus)) { |
| 158 | GetFeatureServicesOfSocket (&PreserveMailboxFamilyServiceTable, Socket, (CONST VOID **)&FamilySpecificServices, StdHeader); |
| 159 | ASSERT (FamilySpecificServices != NULL); |
| 160 | NextRegister = FamilySpecificServices->RegisterList; |
| 161 | while (NextRegister->Register.AddressValue != ILLEGAL_SBDFO) { |
| 162 | ASSERT (RegisterEntryIndex < |
| 163 | (MAX_PRESERVE_REGISTER_ENTRIES * GetPlatformNumberOfSockets () * GetPlatformNumberOfModules ())); |
| 164 | if (FamilySpecificServices->IsZeroOnCold && (!IsWarmReset (StdHeader))) { |
| 165 | Value = 0; |
| 166 | } else { |
| 167 | MailboxRegister = BaseAddress; |
| 168 | MailboxRegister.Address.Function = NextRegister->Register.Address.Function; |
| 169 | MailboxRegister.Address.Register = NextRegister->Register.Address.Register; |
| 170 | LibAmdPciRead (AccessWidth32, MailboxRegister, &Value, StdHeader); |
| 171 | Value &= NextRegister->Mask; |
| 172 | } |
| 173 | (* (MAILBOX_REGISTER_SAVE_ENTRY) AllocateParams.BufferPtr) [RegisterEntryIndex] = Value; |
| 174 | RegisterEntryIndex++; |
| 175 | NextRegister++; |
| 176 | } |
| 177 | } |
| 178 | } |
| 179 | } |
| 180 | } else if ((EntryPoint == CPU_FEAT_INIT_LATE_END) || (EntryPoint == CPU_FEAT_AFTER_RESUME_MTRR_SYNC)) { |
| 181 | // The restore step. Just write out the saved content in the buffer. |
| 182 | LocateParams.BufferHandle = PRESERVE_MAIL_BOX_HANDLE; |
| 183 | HeapStatus = HeapLocateBuffer (&LocateParams, StdHeader); |
| 184 | ASSERT ((HeapStatus == AGESA_SUCCESS) && (LocateParams.BufferPtr != NULL)); |
| 185 | RegisterEntryIndex = 0; |
| 186 | for (Socket = 0; Socket < GetPlatformNumberOfSockets (); Socket++) { |
| 187 | for (Module = 0; Module < GetPlatformNumberOfModules (); Module++) { |
| 188 | if (GetPciAddress (StdHeader, Socket, Module, &BaseAddress, &IgnoredStatus)) { |
| 189 | GetFeatureServicesOfSocket (&PreserveMailboxFamilyServiceTable, Socket, (CONST VOID **)&FamilySpecificServices, StdHeader); |
| 190 | NextRegister = FamilySpecificServices->RegisterList; |
| 191 | while (NextRegister->Register.AddressValue != ILLEGAL_SBDFO) { |
| 192 | ASSERT (RegisterEntryIndex < |
| 193 | (MAX_PRESERVE_REGISTER_ENTRIES * GetPlatformNumberOfSockets () * GetPlatformNumberOfModules ())); |
| 194 | MailboxRegister = BaseAddress; |
| 195 | MailboxRegister.Address.Function = NextRegister->Register.Address.Function; |
| 196 | MailboxRegister.Address.Register = NextRegister->Register.Address.Register; |
| 197 | LibAmdPciRead (AccessWidth32, MailboxRegister, &Value, StdHeader); |
| 198 | Value = ((Value & ~NextRegister->Mask) | (* (MAILBOX_REGISTER_SAVE_ENTRY) LocateParams.BufferPtr) [RegisterEntryIndex]); |
| 199 | LibAmdPciWrite (AccessWidth32, MailboxRegister, &Value, StdHeader); |
| 200 | RegisterEntryIndex++; |
| 201 | NextRegister++; |
| 202 | } |
| 203 | } |
| 204 | } |
| 205 | } |
| 206 | HeapStatus = HeapDeallocateBuffer (PRESERVE_MAIL_BOX_HANDLE, StdHeader); |
| 207 | } |
| 208 | return AGESA_SUCCESS; |
| 209 | } |
| 210 | |
| 211 | |
| 212 | CONST CPU_FEATURE_DESCRIPTOR ROMDATA CpuFeaturePreserveAroundMailbox = |
| 213 | { |
| 214 | PreserveAroundMailbox, |
| 215 | (CPU_FEAT_AFTER_COHERENT_DISCOVERY | CPU_FEAT_INIT_LATE_END | CPU_FEAT_AFTER_RESUME_MTRR_SYNC), |
| 216 | IsPreserveAroundMailboxEnabled, |
| 217 | PreserveMailboxes |
| 218 | }; |