AGESA F15: AMD family15 AGESA code
[coreboot.git] / src / vendorcode / amd / agesa / f15 / Proc / Common / AmdInitResume.c
1 /* $NoKeywords:$ */
2 /**
3  * @file
4  *
5  * AMD AGESA Basic Level Public APIs
6  *
7  * Contains basic Level Initialization routines.
8  *
9  * @xrefitem bom "File Content Label" "Release Content"
10  * @e project:      AGESA
11  * @e sub-project:  Interface
12  * @e \$Revision: 56279 $   @e \$Date: 2011-07-11 13:11:28 -0600 (Mon, 11 Jul 2011) $
13  *
14  */
15 /*****************************************************************************
16  *
17  * Copyright (C) 2012 Advanced Micro Devices, Inc.
18  * All rights reserved.
19  *
20  * Redistribution and use in source and binary forms, with or without
21  * modification, are permitted provided that the following conditions are met:
22  *     * Redistributions of source code must retain the above copyright
23  *       notice, this list of conditions and the following disclaimer.
24  *     * Redistributions in binary form must reproduce the above copyright
25  *       notice, this list of conditions and the following disclaimer in the
26  *       documentation and/or other materials provided with the distribution.
27  *     * Neither the name of Advanced Micro Devices, Inc. nor the names of
28  *       its contributors may be used to endorse or promote products derived
29  *       from this software without specific prior written permission.
30  *
31  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
32  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
33  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
34  * DISCLAIMED. IN NO EVENT SHALL ADVANCED MICRO DEVICES, INC. BE LIABLE FOR ANY
35  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
36  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
37  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
38  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
39  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
40  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41  *
42  ******************************************************************************
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 "mm.h"
54 #include "mn.h"
55 #include "S3.h"
56 #include "mfs3.h"
57 #include "Filecode.h"
58 #include "cpuRegisters.h"
59 #include "cpuApicUtilities.h"
60 #include "cpuPostInit.h"
61 #include "CommonInits.h"
62 #include "cpuFeatures.h"
63 #include "heapManager.h"
64 #include "CreateStruct.h"
65 CODE_GROUP (G1_PEICC)
66 RDATA_GROUP (G2_PEI)
67
68 #define FILECODE PROC_COMMON_AMDINITRESUME_FILECODE
69 /*----------------------------------------------------------------------------------------
70  *                   D E F I N I T I O N S    A N D    M A C R O S
71  *----------------------------------------------------------------------------------------
72  */
73
74
75 /*----------------------------------------------------------------------------------------
76  *                  T Y P E D E F S     A N D     S T R U C T U R E S
77  *----------------------------------------------------------------------------------------
78  */
79
80
81 /*----------------------------------------------------------------------------------------
82  *           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
83  *----------------------------------------------------------------------------------------
84  */
85
86
87 /*----------------------------------------------------------------------------------------
88  *                          E X P O R T E D    F U N C T I O N S
89  *----------------------------------------------------------------------------------------
90  */
91
92 /*---------------------------------------------------------------------------------------*/
93 /**
94  * Main entry point for the AMD_INIT_RESUME function.
95  *
96  * This entry point is responsible for performing silicon device and memory
97  * re-initialization for the resume boot path.
98  *
99  * @param[in]     ResumeParams   Required input parameters for the AMD_INIT_RESUME
100  *                                  entry point.
101  *
102  * @return        Aggregated status across all internal AMD resume calls invoked.
103  *
104  */
105 AGESA_STATUS
106 AmdInitResume (
107   IN       AMD_RESUME_PARAMS *ResumeParams
108   )
109 {
110   VOID   *OrMaskPtr;
111   AGESA_STATUS ReturnStatus;
112   AGESA_STATUS AmdInitResumeStatus;
113   BSC_AP_MSR_SYNC ApMsrSync[4];
114
115   AGESA_TESTPOINT (TpIfAmdInitResumeEntry, &ResumeParams->StdHeader);
116   IDS_HDT_CONSOLE (MAIN_FLOW, "AmdInitResume Start\n");
117
118   AmdInitResumeStatus = AGESA_SUCCESS;
119
120   ASSERT (ResumeParams != NULL);
121
122   if (ResumeParams->S3DataBlock.NvStorage != NULL) {
123
124     MemS3ResumeInitNB (&ResumeParams->StdHeader);
125
126     // Restore registers before exiting self refresh
127     RestorePreESRContext (&OrMaskPtr,
128                           ResumeParams->S3DataBlock.NvStorage,
129                           INIT_RESUME,
130                           &ResumeParams->StdHeader);
131     // Exit self refresh
132     ReturnStatus = AmdMemS3Resume (&ResumeParams->StdHeader);
133     if (ReturnStatus > AmdInitResumeStatus) {
134       AmdInitResumeStatus = ReturnStatus;
135     }
136     if (ReturnStatus == AGESA_SUCCESS) {
137
138       // Restore registers after exiting self refresh
139       RestorePostESRContext (OrMaskPtr,
140                              ResumeParams->S3DataBlock.NvStorage,
141                              INIT_RESUME,
142                              &ResumeParams->StdHeader);
143
144       ApMsrSync[0].RegisterAddress = SYS_CFG;
145       ApMsrSync[1].RegisterAddress = TOP_MEM;
146       ApMsrSync[2].RegisterAddress = TOP_MEM2;
147       ApMsrSync[3].RegisterAddress = 0;
148       SyncApMsrsToBsc (ApMsrSync, &ResumeParams->StdHeader);
149
150       IDS_HDT_CONSOLE (CPU_TRACE, "  Dispatch CPU features after S3 AP MTRR sync\n");
151       ReturnStatus = DispatchCpuFeatures (CPU_FEAT_AFTER_RESUME_MTRR_SYNC, &ResumeParams->PlatformConfig, &ResumeParams->StdHeader);
152       if (ReturnStatus > AmdInitResumeStatus) {
153         AmdInitResumeStatus = ReturnStatus;
154       }
155     }
156   }
157
158   // Set TscFreqSel at the rate specified by the core P0
159   SetCoresTscFreqSel (&ResumeParams->StdHeader);
160
161   IDS_HDT_CONSOLE (MAIN_FLOW, "AmdInitResume End\n");
162   // HDT out of All Aps
163   IDS_HDT_CONSOLE_FLUSH_BUFFER (&ResumeParams->StdHeader);
164   // Relinquish control of all APs to IBV
165   RelinquishControlOfAllAPs (&ResumeParams->StdHeader);
166
167   // Restore IDT
168   IDS_EXCEPTION_TRAP (IDS_IDT_RESTORE_IDTR_FOR_BSC, NULL, &ResumeParams->StdHeader);
169   IDS_OPTION_HOOK (IDS_AFTER_S3_RESUME, NULL, &ResumeParams->StdHeader);
170   AGESA_TESTPOINT (TpIfAmdInitResumeExit, &ResumeParams->StdHeader);
171   return (AmdInitResumeStatus);
172 }
173
174 /*---------------------------------------------------------------------------------------*/
175 /**
176  * Constructor for the AMD_INIT_RESUME function.
177  *
178  * This routine is responsible for setting default values for the
179  * input parameters needed by the AMD_INIT_RESUME entry point.
180  *
181  * @param[in]     StdHeader       The standard header.
182  * @param[in,out] ResumeParams   Required input parameters for the AMD_INIT_RESUME
183  *                               entry point.
184  *
185  * @retval        AGESA_SUCCESS  Always Succeeds.
186  *
187  */
188 AGESA_STATUS
189 AmdInitResumeInitializer (
190   IN       AMD_CONFIG_PARAMS *StdHeader,
191   IN OUT   AMD_RESUME_PARAMS *ResumeParams
192   )
193 {
194   ASSERT (StdHeader != NULL);
195   ASSERT (ResumeParams != NULL);
196
197   ResumeParams->StdHeader = *StdHeader;
198
199   AmdS3ParamsInitializer (&ResumeParams->S3DataBlock);
200   CommonPlatformConfigInit (&ResumeParams->PlatformConfig, &ResumeParams->StdHeader);
201
202   return AGESA_SUCCESS;
203 }
204
205 /*---------------------------------------------------------------------------------------*/
206 /**
207  * Destructor for the AMD_INIT_RESUME function.
208  *
209  * This routine is responsible for deallocation of heap space allocated during
210  * AMD_INIT_RESUME entry point.
211  *
212  * @param[in]    StdHeader       The standard header.
213  * @param[in,out] ResumeParams   Required input parameters for the AMD_INIT_RESUME
214  *                               entry point.
215  *
216  * @retval        AGESA_STATUS
217  *
218  */
219 AGESA_STATUS
220 AmdInitResumeDestructor (
221   IN       AMD_CONFIG_PARAMS *StdHeader,
222   IN OUT   AMD_RESUME_PARAMS *ResumeParams
223   )
224 {
225   AGESA_STATUS ReturnStatus;
226   AGESA_STATUS RetVal;
227
228   ASSERT (ResumeParams != NULL);
229
230   ReturnStatus = AGESA_SUCCESS;
231
232   // Deallocate heap space allocated during memory S3 resume
233   RetVal = MemS3Deallocate (&ResumeParams->StdHeader);
234   if (RetVal > ReturnStatus) {
235     ReturnStatus = RetVal;
236   }
237
238   return ReturnStatus;
239 }