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