zbao | 7d94cf9 | 2012-07-02 14:19:14 +0800 | [diff] [blame] | 1 | /* $NoKeywords:$ */ |
| 2 | /** |
| 3 | * @file |
| 4 | * |
| 5 | * AMD CPU Warm Reset Implementation. |
| 6 | * |
| 7 | * Implement Warm Reset Interface. |
| 8 | * |
| 9 | * @xrefitem bom "File Content Label" "Release Content" |
| 10 | * @e project: AGESA |
| 11 | * @e sub-project: CPU |
| 12 | * @e \$Revision: 63425 $ @e \$Date: 2011-12-22 11:24:10 -0600 (Thu, 22 Dec 2011) $ |
| 13 | * |
| 14 | */ |
| 15 | /* |
| 16 | ****************************************************************************** |
| 17 | * |
Siyuan Wang | 641f00c | 2013-06-08 11:50:55 +0800 | [diff] [blame] | 18 | * Copyright (c) 2008 - 2012, Advanced Micro Devices, Inc. |
| 19 | * All rights reserved. |
zbao | 7d94cf9 | 2012-07-02 14:19:14 +0800 | [diff] [blame] | 20 | * |
Siyuan Wang | 641f00c | 2013-06-08 11:50:55 +0800 | [diff] [blame] | 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. |
zbao | 7d94cf9 | 2012-07-02 14:19:14 +0800 | [diff] [blame] | 31 | * |
Siyuan Wang | 641f00c | 2013-06-08 11:50:55 +0800 | [diff] [blame] | 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. |
zbao | 7d94cf9 | 2012-07-02 14:19:14 +0800 | [diff] [blame] | 42 | ****************************************************************************** |
| 43 | */ |
| 44 | |
| 45 | /*---------------------------------------------------------------------------------------- |
| 46 | * M O D U L E S U S E D |
| 47 | *---------------------------------------------------------------------------------------- |
| 48 | */ |
| 49 | |
| 50 | #include "AGESA.h" |
| 51 | #include "cpuRegisters.h" |
| 52 | #include "cpuServices.h" |
| 53 | #include "cpuFamilyTranslation.h" |
| 54 | #include "Filecode.h" |
| 55 | CODE_GROUP (G1_PEICC) |
| 56 | RDATA_GROUP (G1_PEICC) |
| 57 | |
| 58 | #define FILECODE PROC_CPU_CPUWARMRESET_FILECODE |
| 59 | /*---------------------------------------------------------------------------------------- |
| 60 | * D E F I N I T I O N S A N D M A C R O S |
| 61 | *---------------------------------------------------------------------------------------- |
| 62 | */ |
| 63 | |
| 64 | /*---------------------------------------------------------------------------------------- |
| 65 | * T Y P E D E F S A N D S T R U C T U R E S |
| 66 | *---------------------------------------------------------------------------------------- |
| 67 | */ |
| 68 | |
| 69 | /*---------------------------------------------------------------------------------------- |
| 70 | * 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 |
| 71 | *---------------------------------------------------------------------------------------- |
| 72 | */ |
| 73 | |
| 74 | /*---------------------------------------------------------------------------------------- |
| 75 | * E X P O R T E D F U N C T I O N S |
| 76 | *---------------------------------------------------------------------------------------- |
| 77 | */ |
| 78 | |
| 79 | /*---------------------------------------------------------------------------------------*/ |
| 80 | /** |
| 81 | * This function will set the CPU register warm reset bits. |
| 82 | * |
| 83 | * Note: This function will be called by UEFI BIOS's |
| 84 | * The UEFI wrapper code should register this function, to be called back later point |
| 85 | * in time, before the wrapper code does warm reset. |
| 86 | * |
| 87 | * @param[in] StdHeader Config handle for library and services |
| 88 | * @param[in] Request Indicate warm reset status |
| 89 | * |
| 90 | *--------------------------------------------------------------------------------------- |
| 91 | **/ |
| 92 | VOID |
| 93 | SetWarmResetFlag ( |
| 94 | IN AMD_CONFIG_PARAMS *StdHeader, |
| 95 | IN WARM_RESET_REQUEST *Request |
| 96 | ) |
| 97 | { |
| 98 | CPU_SPECIFIC_SERVICES *FamilySpecificServices; |
| 99 | FamilySpecificServices = NULL; |
| 100 | |
| 101 | GetCpuServicesOfCurrentCore ((CONST CPU_SPECIFIC_SERVICES **)&FamilySpecificServices, StdHeader); |
| 102 | FamilySpecificServices->SetWarmResetFlag (FamilySpecificServices, StdHeader, Request); |
| 103 | } |
| 104 | |
| 105 | /*---------------------------------------------------------------------------------------*/ |
| 106 | /** |
| 107 | * This function will get the CPU register warm reset bits. |
| 108 | * |
| 109 | * Note: This function will be called by UEFI BIOS's |
| 110 | * The UEFI wrapper code should register this function, to be called back later point |
| 111 | * in time, before the wrapper code does warm reset. |
| 112 | * |
| 113 | * @param[in] StdHeader Config handle for library and services |
| 114 | * @param[out] Request Indicate warm reset status |
| 115 | * |
| 116 | *--------------------------------------------------------------------------------------- |
| 117 | **/ |
| 118 | VOID |
| 119 | GetWarmResetFlag ( |
| 120 | IN AMD_CONFIG_PARAMS *StdHeader, |
| 121 | OUT WARM_RESET_REQUEST *Request |
| 122 | ) |
| 123 | { |
| 124 | CPU_SPECIFIC_SERVICES *FamilySpecificServices; |
| 125 | FamilySpecificServices = NULL; |
| 126 | |
| 127 | GetCpuServicesOfCurrentCore ((CONST CPU_SPECIFIC_SERVICES **)&FamilySpecificServices, StdHeader); |
| 128 | FamilySpecificServices->GetWarmResetFlag (FamilySpecificServices, StdHeader, Request); |
| 129 | |
| 130 | switch (StdHeader->Func) { |
| 131 | case AMD_INIT_RESET: |
| 132 | Request->PostStage = (UINT8) WR_STATE_RESET; |
| 133 | break; |
| 134 | case AMD_INIT_EARLY: |
| 135 | Request->PostStage = (UINT8) WR_STATE_EARLY; |
| 136 | break; |
| 137 | case AMD_INIT_POST: |
| 138 | // Fall through to default case |
| 139 | default: |
| 140 | Request->PostStage = (UINT8) WR_STATE_POST; |
| 141 | break; |
| 142 | } |
| 143 | } |
| 144 | /*---------------------------------------------------------------------------------------- |
| 145 | * E X P O R T E D F U N C T I O N S - (AGESA ONLY) |
| 146 | *---------------------------------------------------------------------------------------- |
| 147 | */ |
| 148 | |
| 149 | |
| 150 | |
| 151 | /*---------------------------------------------------------------------------------------*/ |
| 152 | /** |
| 153 | * Is this boot a warm reset? |
| 154 | * |
| 155 | * This function reads the CPU register warm reset bit that is preserved after a warm reset. |
| 156 | * Which in fact gets set before issuing warm reset. We just use the BSP's register always. |
| 157 | * |
| 158 | * @param[in] StdHeader Config handle for library and services |
| 159 | * |
| 160 | * @retval TRUE Warm Reset |
| 161 | * @retval FALSE Not Warm Reset |
| 162 | * |
| 163 | */ |
| 164 | BOOLEAN |
| 165 | IsWarmReset ( |
| 166 | IN AMD_CONFIG_PARAMS *StdHeader |
| 167 | ) |
| 168 | { |
| 169 | UINT8 PostStage; |
| 170 | WARM_RESET_REQUEST Request; |
| 171 | BOOLEAN WarmReset; |
| 172 | CPU_SPECIFIC_SERVICES *FamilySpecificServices; |
| 173 | |
| 174 | FamilySpecificServices = NULL; |
| 175 | |
| 176 | switch (StdHeader->Func) { |
| 177 | case AMD_INIT_RESET: |
| 178 | PostStage = WR_STATE_RESET; |
| 179 | break; |
| 180 | case AMD_INIT_EARLY: |
| 181 | PostStage = WR_STATE_EARLY; |
| 182 | break; |
| 183 | case AMD_INIT_POST: |
| 184 | default: |
| 185 | PostStage = WR_STATE_POST; |
| 186 | break; |
| 187 | } |
| 188 | |
| 189 | GetCpuServicesOfCurrentCore ((CONST CPU_SPECIFIC_SERVICES **)&FamilySpecificServices, StdHeader); |
| 190 | FamilySpecificServices->GetWarmResetFlag (FamilySpecificServices, StdHeader, &Request); |
| 191 | |
| 192 | if (Request.StateBits >= PostStage) { |
| 193 | WarmReset = TRUE; |
| 194 | } else { |
| 195 | WarmReset = FALSE; |
| 196 | } |
| 197 | |
| 198 | return WarmReset; |
| 199 | } |
| 200 | |
| 201 | /*---------------------------------------------------------------------------------------*/ |
| 202 | /** |
| 203 | * This function will set the CPU register warm reset bits at AmdInitEarly if it is |
| 204 | * currently in cold boot. To request for a warm reset, set the RequestBit to TRUE |
| 205 | * and the StateBits to (current poststage - 1) |
| 206 | * |
| 207 | * @param[in] Data The table data value (unused in this routine) |
| 208 | * @param[in] StdHeader Config handle for library and services |
| 209 | * |
| 210 | *--------------------------------------------------------------------------------------- |
| 211 | **/ |
| 212 | VOID |
| 213 | SetWarmResetAtEarly ( |
| 214 | IN UINT32 Data, |
| 215 | IN AMD_CONFIG_PARAMS *StdHeader |
| 216 | ) |
| 217 | { |
| 218 | WARM_RESET_REQUEST Request; |
| 219 | |
| 220 | if (!IsWarmReset (StdHeader)) { |
| 221 | GetWarmResetFlag (StdHeader, &Request); |
| 222 | |
| 223 | Request.RequestBit = TRUE; |
| 224 | Request.StateBits = (Request.PostStage - 1); |
| 225 | |
| 226 | SetWarmResetFlag (StdHeader, &Request); |
| 227 | } |
| 228 | } |
| 229 | |
| 230 | /*---------------------------------------------------------------------------------------- |
| 231 | * L O C A L F U N C T I O N S |
| 232 | *---------------------------------------------------------------------------------------- |
| 233 | */ |
| 234 | |