]> git.proxmox.com Git - mirror_edk2.git/blame - UefiCpuPkg/SecCore/SecBist.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / UefiCpuPkg / SecCore / SecBist.c
CommitLineData
863c738c
JF
1/** @file\r
2 Get SEC platform information(2) PPI and reinstall it.\r
3\r
4 Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>\r
0acd8697 5 SPDX-License-Identifier: BSD-2-Clause-Patent\r
863c738c
JF
6\r
7**/\r
8\r
9#include "SecMain.h"\r
10\r
053e878b 11EFI_SEC_PLATFORM_INFORMATION_PPI mSecPlatformInformation = {\r
8a5b8cef
JF
12 SecPlatformInformationBist\r
13};\r
14\r
053e878b 15EFI_PEI_PPI_DESCRIPTOR mPeiSecPlatformInformation = {\r
8a5b8cef
JF
16 (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r
17 &gEfiSecPlatformInformationPpiGuid,\r
18 &mSecPlatformInformation\r
19};\r
20\r
053e878b 21EFI_SEC_PLATFORM_INFORMATION2_PPI mSecPlatformInformation2 = {\r
8a5b8cef
JF
22 SecPlatformInformation2Bist\r
23};\r
24\r
053e878b 25EFI_PEI_PPI_DESCRIPTOR mPeiSecPlatformInformation2 = {\r
8a5b8cef
JF
26 (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r
27 &gEfiSecPlatformInformation2PpiGuid,\r
28 &mSecPlatformInformation2\r
29};\r
30\r
863c738c 31/**\r
d157de8b 32 Worker function to parse CPU BIST information from Guided HOB.\r
863c738c 33\r
367284e7
DB
34 @param[in, out] StructureSize Pointer to the variable describing size of the input buffer.\r
35 @param[in, out] StructureBuffer Pointer to the buffer save CPU BIST information.\r
863c738c 36\r
d157de8b
JF
37 @retval EFI_SUCCESS The data was successfully returned.\r
38 @retval EFI_BUFFER_TOO_SMALL The buffer was too small.\r
863c738c
JF
39\r
40**/\r
41EFI_STATUS\r
d157de8b 42GetBistFromHob (\r
053e878b
MK
43 IN OUT UINT64 *StructureSize,\r
44 IN OUT VOID *StructureBuffer\r
863c738c
JF
45 )\r
46{\r
053e878b
MK
47 EFI_HOB_GUID_TYPE *GuidHob;\r
48 VOID *DataInHob;\r
49 UINTN DataSize;\r
863c738c 50\r
d157de8b 51 GuidHob = GetFirstGuidHob (&gEfiCallerIdGuid);\r
863c738c
JF
52 if (GuidHob == NULL) {\r
53 *StructureSize = 0;\r
54 return EFI_SUCCESS;\r
55 }\r
56\r
57 DataInHob = GET_GUID_HOB_DATA (GuidHob);\r
58 DataSize = GET_GUID_HOB_DATA_SIZE (GuidHob);\r
59\r
60 //\r
61 // return the information from BistHob\r
62 //\r
053e878b
MK
63 if ((*StructureSize) < (UINT64)DataSize) {\r
64 *StructureSize = (UINT64)DataSize;\r
863c738c
JF
65 return EFI_BUFFER_TOO_SMALL;\r
66 }\r
67\r
053e878b 68 *StructureSize = (UINT64)DataSize;\r
d157de8b 69 CopyMem (StructureBuffer, DataInHob, DataSize);\r
863c738c
JF
70 return EFI_SUCCESS;\r
71}\r
72\r
d157de8b
JF
73/**\r
74 Implementation of the PlatformInformation service in EFI_SEC_PLATFORM_INFORMATION_PPI.\r
75\r
367284e7
DB
76 @param[in] PeiServices Pointer to the PEI Services Table.\r
77 @param[in, out] StructureSize Pointer to the variable describing size of the input buffer.\r
78 @param[out] PlatformInformationRecord Pointer to the EFI_SEC_PLATFORM_INFORMATION_RECORD.\r
d157de8b
JF
79\r
80 @retval EFI_SUCCESS The data was successfully returned.\r
81 @retval EFI_BUFFER_TOO_SMALL The buffer was too small.\r
82\r
83**/\r
84EFI_STATUS\r
85EFIAPI\r
86SecPlatformInformationBist (\r
053e878b
MK
87 IN CONST EFI_PEI_SERVICES **PeiServices,\r
88 IN OUT UINT64 *StructureSize,\r
89 OUT EFI_SEC_PLATFORM_INFORMATION_RECORD *PlatformInformationRecord\r
d157de8b
JF
90 )\r
91{\r
92 return GetBistFromHob (StructureSize, PlatformInformationRecord);\r
93}\r
94\r
95/**\r
96 Implementation of the PlatformInformation2 service in EFI_SEC_PLATFORM_INFORMATION2_PPI.\r
97\r
367284e7
DB
98 @param[in] PeiServices The pointer to the PEI Services Table.\r
99 @param[in, out] StructureSize The pointer to the variable describing size of the input buffer.\r
100 @param[out] PlatformInformationRecord2 The pointer to the EFI_SEC_PLATFORM_INFORMATION_RECORD2.\r
d157de8b
JF
101\r
102 @retval EFI_SUCCESS The data was successfully returned.\r
103 @retval EFI_BUFFER_TOO_SMALL The buffer was too small. The current buffer size needed to\r
104 hold the record is returned in StructureSize.\r
105\r
106**/\r
107EFI_STATUS\r
108EFIAPI\r
109SecPlatformInformation2Bist (\r
053e878b
MK
110 IN CONST EFI_PEI_SERVICES **PeiServices,\r
111 IN OUT UINT64 *StructureSize,\r
112 OUT EFI_SEC_PLATFORM_INFORMATION_RECORD2 *PlatformInformationRecord2\r
d157de8b
JF
113 )\r
114{\r
115 return GetBistFromHob (StructureSize, PlatformInformationRecord2);\r
116}\r
117\r
863c738c
JF
118/**\r
119 Worker function to get CPUs' BIST by calling SecPlatformInformationPpi\r
120 or SecPlatformInformation2Ppi.\r
121\r
d157de8b
JF
122 @param[in] PeiServices Pointer to PEI Services Table\r
123 @param[in] Guid PPI Guid\r
124 @param[out] PpiDescriptor Return a pointer to instance of the\r
125 EFI_PEI_PPI_DESCRIPTOR\r
126 @param[out] BistInformationData Pointer to BIST information data\r
127 @param[out] BistInformationSize Return the size in bytes of BIST information\r
863c738c
JF
128\r
129 @retval EFI_SUCCESS Retrieve of the BIST data successfully\r
130 @retval EFI_NOT_FOUND No sec platform information(2) ppi export\r
131 @retval EFI_DEVICE_ERROR Failed to get CPU Information\r
132\r
133**/\r
134EFI_STATUS\r
135GetBistInfoFromPpi (\r
053e878b
MK
136 IN CONST EFI_PEI_SERVICES **PeiServices,\r
137 IN CONST EFI_GUID *Guid,\r
138 OUT EFI_PEI_PPI_DESCRIPTOR **PpiDescriptor,\r
139 OUT VOID **BistInformationData,\r
140 OUT UINT64 *BistInformationSize OPTIONAL\r
863c738c
JF
141 )\r
142{\r
143 EFI_STATUS Status;\r
144 EFI_SEC_PLATFORM_INFORMATION2_PPI *SecPlatformInformation2Ppi;\r
145 EFI_SEC_PLATFORM_INFORMATION_RECORD2 *SecPlatformInformation2;\r
146 UINT64 InformationSize;\r
147\r
148 Status = PeiServicesLocatePpi (\r
149 Guid, // GUID\r
150 0, // INSTANCE\r
151 PpiDescriptor, // EFI_PEI_PPI_DESCRIPTOR\r
152 (VOID **)&SecPlatformInformation2Ppi // PPI\r
153 );\r
154 if (Status == EFI_NOT_FOUND) {\r
155 return EFI_NOT_FOUND;\r
156 }\r
157\r
158 if (Status == EFI_SUCCESS) {\r
159 //\r
160 // Get the size of the sec platform information2(BSP/APs' BIST data)\r
161 //\r
162 InformationSize = 0;\r
163 SecPlatformInformation2 = NULL;\r
053e878b
MK
164 Status = SecPlatformInformation2Ppi->PlatformInformation2 (\r
165 PeiServices,\r
166 &InformationSize,\r
167 SecPlatformInformation2\r
168 );\r
863c738c
JF
169 if (Status == EFI_BUFFER_TOO_SMALL) {\r
170 Status = PeiServicesAllocatePool (\r
053e878b
MK
171 (UINTN)InformationSize,\r
172 (VOID **)&SecPlatformInformation2\r
863c738c
JF
173 );\r
174 if (Status == EFI_SUCCESS) {\r
175 //\r
176 // Retrieve BIST data\r
177 //\r
178 Status = SecPlatformInformation2Ppi->PlatformInformation2 (\r
179 PeiServices,\r
180 &InformationSize,\r
181 SecPlatformInformation2\r
182 );\r
183 if (Status == EFI_SUCCESS) {\r
184 *BistInformationData = SecPlatformInformation2;\r
185 if (BistInformationSize != NULL) {\r
186 *BistInformationSize = InformationSize;\r
187 }\r
053e878b 188\r
863c738c
JF
189 return EFI_SUCCESS;\r
190 }\r
191 }\r
192 }\r
193 }\r
194\r
195 return EFI_DEVICE_ERROR;\r
196}\r
8a5b8cef
JF
197\r
198/**\r
199 Get CPUs' BIST by calling SecPlatformInformationPpi/SecPlatformInformation2Ppi.\r
200\r
201**/\r
202VOID\r
203RepublishSecPlatformInformationPpi (\r
204 VOID\r
205 )\r
206{\r
053e878b
MK
207 EFI_STATUS Status;\r
208 CONST EFI_PEI_SERVICES **PeiServices;\r
209 UINT64 BistInformationSize;\r
210 VOID *BistInformationData;\r
211 EFI_PEI_PPI_DESCRIPTOR *SecInformationDescriptor;\r
8a5b8cef
JF
212\r
213 PeiServices = GetPeiServicesTablePointer ();\r
053e878b
MK
214 Status = GetBistInfoFromPpi (\r
215 PeiServices,\r
216 &gEfiSecPlatformInformation2PpiGuid,\r
217 &SecInformationDescriptor,\r
218 &BistInformationData,\r
219 &BistInformationSize\r
220 );\r
8a5b8cef
JF
221 if (Status == EFI_SUCCESS) {\r
222 BuildGuidDataHob (\r
223 &gEfiCallerIdGuid,\r
224 BistInformationData,\r
053e878b 225 (UINTN)BistInformationSize\r
8a5b8cef
JF
226 );\r
227 //\r
030d2de7
JF
228 // The old SecPlatformInformation2 data is on temporary memory.\r
229 // After memory discovered, we should never get it from temporary memory,\r
230 // or the data will be crashed. So, we reinstall SecPlatformInformation2 PPI here.\r
8a5b8cef
JF
231 //\r
232 Status = PeiServicesReInstallPpi (\r
233 SecInformationDescriptor,\r
234 &mPeiSecPlatformInformation2\r
235 );\r
053e878b
MK
236 }\r
237\r
238 if (Status == EFI_NOT_FOUND) {\r
8a5b8cef
JF
239 Status = GetBistInfoFromPpi (\r
240 PeiServices,\r
241 &gEfiSecPlatformInformationPpiGuid,\r
242 &SecInformationDescriptor,\r
243 &BistInformationData,\r
244 &BistInformationSize\r
245 );\r
246 if (Status == EFI_SUCCESS) {\r
247 BuildGuidDataHob (\r
248 &gEfiCallerIdGuid,\r
249 BistInformationData,\r
053e878b 250 (UINTN)BistInformationSize\r
8a5b8cef
JF
251 );\r
252 //\r
030d2de7
JF
253 // The old SecPlatformInformation data is on temporary memory.\r
254 // After memory discovered, we should never get it from temporary memory,\r
255 // or the data will be crashed. So, we reinstall SecPlatformInformation PPI here.\r
8a5b8cef
JF
256 //\r
257 Status = PeiServicesReInstallPpi (\r
258 SecInformationDescriptor,\r
259 &mPeiSecPlatformInformation\r
260 );\r
93638568
JF
261 } else if (Status == EFI_NOT_FOUND) {\r
262 return;\r
8a5b8cef
JF
263 }\r
264 }\r
265\r
053e878b 266 ASSERT_EFI_ERROR (Status);\r
8a5b8cef 267}\r