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