]> git.proxmox.com Git - mirror_edk2.git/blame - UefiCpuPkg/SecCore/SecBist.c
UefiCpuPkg/MpInitLib: Skip reading PlatformId on AMD processors.
[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
8a5b8cef
JF
11EFI_SEC_PLATFORM_INFORMATION_PPI mSecPlatformInformation = {\r
12 SecPlatformInformationBist\r
13};\r
14\r
15EFI_PEI_PPI_DESCRIPTOR mPeiSecPlatformInformation = {\r
16 (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r
17 &gEfiSecPlatformInformationPpiGuid,\r
18 &mSecPlatformInformation\r
19};\r
20\r
21EFI_SEC_PLATFORM_INFORMATION2_PPI mSecPlatformInformation2 = {\r
22 SecPlatformInformation2Bist\r
23};\r
24\r
25EFI_PEI_PPI_DESCRIPTOR mPeiSecPlatformInformation2 = {\r
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
JF
42GetBistFromHob (\r
43 IN OUT UINT64 *StructureSize,\r
44 IN OUT VOID *StructureBuffer\r
863c738c
JF
45 )\r
46{\r
47 EFI_HOB_GUID_TYPE *GuidHob;\r
48 VOID *DataInHob;\r
49 UINTN DataSize;\r
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
63 if ((*StructureSize) < (UINT64) DataSize) {\r
64 *StructureSize = (UINT64) DataSize;\r
65 return EFI_BUFFER_TOO_SMALL;\r
66 }\r
67\r
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
87 IN CONST EFI_PEI_SERVICES **PeiServices,\r
88 IN OUT UINT64 *StructureSize,\r
89 OUT EFI_SEC_PLATFORM_INFORMATION_RECORD *PlatformInformationRecord\r
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
110 IN CONST EFI_PEI_SERVICES **PeiServices,\r
111 IN OUT UINT64 *StructureSize,\r
112 OUT EFI_SEC_PLATFORM_INFORMATION_RECORD2 *PlatformInformationRecord2\r
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
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
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
164 Status = SecPlatformInformation2Ppi->PlatformInformation2 (\r
165 PeiServices,\r
166 &InformationSize,\r
167 SecPlatformInformation2\r
168 );\r
169 if (Status == EFI_BUFFER_TOO_SMALL) {\r
170 Status = PeiServicesAllocatePool (\r
171 (UINTN) InformationSize,\r
172 (VOID **) &SecPlatformInformation2\r
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
188 return EFI_SUCCESS;\r
189 }\r
190 }\r
191 }\r
192 }\r
193\r
194 return EFI_DEVICE_ERROR;\r
195}\r
8a5b8cef
JF
196\r
197/**\r
198 Get CPUs' BIST by calling SecPlatformInformationPpi/SecPlatformInformation2Ppi.\r
199\r
200**/\r
201VOID\r
202RepublishSecPlatformInformationPpi (\r
203 VOID\r
204 )\r
205{\r
206 EFI_STATUS Status;\r
207 CONST EFI_PEI_SERVICES **PeiServices;\r
208 UINT64 BistInformationSize;\r
209 VOID *BistInformationData;\r
210 EFI_PEI_PPI_DESCRIPTOR *SecInformationDescriptor;\r
211\r
212 PeiServices = GetPeiServicesTablePointer ();\r
213 Status = GetBistInfoFromPpi (\r
214 PeiServices,\r
215 &gEfiSecPlatformInformation2PpiGuid,\r
216 &SecInformationDescriptor,\r
217 &BistInformationData,\r
218 &BistInformationSize\r
219 );\r
220 if (Status == EFI_SUCCESS) {\r
221 BuildGuidDataHob (\r
222 &gEfiCallerIdGuid,\r
223 BistInformationData,\r
224 (UINTN) BistInformationSize\r
225 );\r
226 //\r
030d2de7
JF
227 // The old SecPlatformInformation2 data is on temporary memory.\r
228 // After memory discovered, we should never get it from temporary memory,\r
229 // or the data will be crashed. So, we reinstall SecPlatformInformation2 PPI here.\r
8a5b8cef
JF
230 //\r
231 Status = PeiServicesReInstallPpi (\r
232 SecInformationDescriptor,\r
233 &mPeiSecPlatformInformation2\r
234 );\r
235 } if (Status == EFI_NOT_FOUND) {\r
236 Status = GetBistInfoFromPpi (\r
237 PeiServices,\r
238 &gEfiSecPlatformInformationPpiGuid,\r
239 &SecInformationDescriptor,\r
240 &BistInformationData,\r
241 &BistInformationSize\r
242 );\r
243 if (Status == EFI_SUCCESS) {\r
244 BuildGuidDataHob (\r
245 &gEfiCallerIdGuid,\r
246 BistInformationData,\r
247 (UINTN) BistInformationSize\r
248 );\r
249 //\r
030d2de7
JF
250 // The old SecPlatformInformation data is on temporary memory.\r
251 // After memory discovered, we should never get it from temporary memory,\r
252 // or the data will be crashed. So, we reinstall SecPlatformInformation PPI here.\r
8a5b8cef
JF
253 //\r
254 Status = PeiServicesReInstallPpi (\r
255 SecInformationDescriptor,\r
256 &mPeiSecPlatformInformation\r
257 );\r
93638568
JF
258 } else if (Status == EFI_NOT_FOUND) {\r
259 return;\r
8a5b8cef
JF
260 }\r
261 }\r
262\r
263 ASSERT_EFI_ERROR(Status);\r
264}\r