UefiCpuPkg CpuMpPei: Update return status to follow spec.
[mirror_edk2.git] / UefiCpuPkg / CpuMpPei / CpuBist.c
CommitLineData
ea0f431c
JF
1/** @file\r
2 Update and publish processors' BIST information.\r
3\r
4 Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>\r
5 This program and the accompanying materials\r
6 are licensed and made available under the terms and conditions of the BSD License\r
7 which accompanies this distribution. The full text of the license may be found at\r
8 http://opensource.org/licenses/bsd-license.php\r
9\r
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13**/\r
14\r
15#include "CpuMpPei.h"\r
16\r
17EFI_SEC_PLATFORM_INFORMATION2_PPI mSecPlatformInformation2Ppi = {\r
18 SecPlatformInformation2\r
19};\r
20\r
21EFI_PEI_PPI_DESCRIPTOR mPeiSecPlatformInformation2Ppi = {\r
22 (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r
23 &gEfiSecPlatformInformation2PpiGuid,\r
24 &mSecPlatformInformation2Ppi\r
25};\r
26\r
27/**\r
28 Implementation of the PlatformInformation2 service in EFI_SEC_PLATFORM_INFORMATION2_PPI.\r
29\r
30 @param PeiServices The pointer to the PEI Services Table.\r
31 @param StructureSize The pointer to the variable describing size of the input buffer.\r
32 @param PlatformInformationRecord2 The pointer to the EFI_SEC_PLATFORM_INFORMATION_RECORD2.\r
33\r
34 @retval EFI_SUCCESS The data was successfully returned.\r
35 @retval EFI_BUFFER_TOO_SMALL The buffer was too small. The current buffer size needed to\r
36 hold the record is returned in StructureSize.\r
37\r
38**/\r
39EFI_STATUS\r
40EFIAPI\r
41SecPlatformInformation2 (\r
42 IN CONST EFI_PEI_SERVICES **PeiServices,\r
43 IN OUT UINT64 *StructureSize,\r
44 OUT EFI_SEC_PLATFORM_INFORMATION_RECORD2 *PlatformInformationRecord2\r
45 )\r
46{\r
86432994
JF
47 EFI_HOB_GUID_TYPE *GuidHob;\r
48 VOID *DataInHob;\r
49 UINTN DataSize;\r
ea0f431c 50\r
86432994
JF
51 GuidHob = GetFirstGuidHob (&gEfiSecPlatformInformation2PpiGuid);\r
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
ea0f431c 59\r
ea0f431c 60 //\r
86432994 61 // return the information from BistHob\r
ea0f431c 62 //\r
86432994
JF
63 if ((*StructureSize) < (UINT64) DataSize) {\r
64 *StructureSize = (UINT64) DataSize;\r
ea0f431c
JF
65 return EFI_BUFFER_TOO_SMALL;\r
66 }\r
67\r
86432994
JF
68 *StructureSize = (UINT64) DataSize;\r
69 CopyMem (PlatformInformationRecord2, DataInHob, DataSize);\r
ea0f431c
JF
70 return EFI_SUCCESS;\r
71}\r
72\r
73/**\r
74 Worker function to get CPUs' BIST by calling SecPlatformInformationPpi\r
75 or SecPlatformInformation2Ppi.\r
76\r
77 @param PeiServices Pointer to PEI Services Table\r
78 @param Guid PPI Guid\r
79 @param PpiDescriptor Return a pointer to instance of the\r
80 EFI_PEI_PPI_DESCRIPTOR\r
81 @param BistInformationData Pointer to BIST information data\r
dfb0e659 82 @param BistInformationSize Return the size in bytes of BIST information\r
ea0f431c
JF
83\r
84 @retval EFI_SUCCESS Retrieve of the BIST data successfully\r
85 @retval EFI_NOT_FOUND No sec platform information(2) ppi export\r
86 @retval EFI_DEVICE_ERROR Failed to get CPU Information\r
87\r
88**/\r
89EFI_STATUS\r
90GetBistInfoFromPpi (\r
91 IN CONST EFI_PEI_SERVICES **PeiServices,\r
92 IN CONST EFI_GUID *Guid,\r
93 OUT EFI_PEI_PPI_DESCRIPTOR **PpiDescriptor,\r
dfb0e659
JF
94 OUT VOID **BistInformationData,\r
95 OUT UINT64 *BistInformationSize OPTIONAL\r
ea0f431c
JF
96 )\r
97{\r
98 EFI_STATUS Status;\r
99 EFI_SEC_PLATFORM_INFORMATION2_PPI *SecPlatformInformation2Ppi;\r
100 EFI_SEC_PLATFORM_INFORMATION_RECORD2 *SecPlatformInformation2;\r
101 UINT64 InformationSize;\r
102\r
103 Status = PeiServicesLocatePpi (\r
104 Guid, // GUID\r
105 0, // INSTANCE\r
106 PpiDescriptor, // EFI_PEI_PPI_DESCRIPTOR\r
107 (VOID **)&SecPlatformInformation2Ppi // PPI\r
108 );\r
109 if (Status == EFI_NOT_FOUND) {\r
110 return EFI_NOT_FOUND;\r
111 }\r
112\r
113 if (Status == EFI_SUCCESS) {\r
114 //\r
115 // Get the size of the sec platform information2(BSP/APs' BIST data)\r
116 //\r
117 InformationSize = 0;\r
118 SecPlatformInformation2 = NULL;\r
119 Status = SecPlatformInformation2Ppi->PlatformInformation2 (\r
120 PeiServices,\r
121 &InformationSize,\r
122 SecPlatformInformation2\r
123 );\r
124 if (Status == EFI_BUFFER_TOO_SMALL) {\r
125 Status = PeiServicesAllocatePool (\r
126 (UINTN) InformationSize,\r
127 (VOID **) &SecPlatformInformation2\r
128 );\r
129 if (Status == EFI_SUCCESS) {\r
130 //\r
131 // Retrieve BIST data\r
132 //\r
133 Status = SecPlatformInformation2Ppi->PlatformInformation2 (\r
134 PeiServices,\r
135 &InformationSize,\r
136 SecPlatformInformation2\r
137 );\r
138 if (Status == EFI_SUCCESS) {\r
139 *BistInformationData = SecPlatformInformation2;\r
dfb0e659
JF
140 if (BistInformationSize != NULL) {\r
141 *BistInformationSize = InformationSize;\r
142 }\r
ea0f431c
JF
143 return EFI_SUCCESS;\r
144 }\r
145 }\r
146 }\r
147 }\r
148\r
149 return EFI_DEVICE_ERROR;\r
150}\r
151\r
152/**\r
153 Collects BIST data from PPI.\r
154\r
155 This function collects BIST data from Sec Platform Information2 PPI\r
156 or SEC Platform Information PPI.\r
157\r
158 @param PeiServices Pointer to PEI Services Table\r
ea0f431c
JF
159\r
160**/\r
161VOID\r
162CollectBistDataFromPpi (\r
a1a4c7a4 163 IN CONST EFI_PEI_SERVICES **PeiServices\r
ea0f431c
JF
164 )\r
165{\r
166 EFI_STATUS Status;\r
167 EFI_PEI_PPI_DESCRIPTOR *SecInformationDescriptor;\r
168 EFI_SEC_PLATFORM_INFORMATION_RECORD2 *SecPlatformInformation2;\r
169 EFI_SEC_PLATFORM_INFORMATION_RECORD *SecPlatformInformation;\r
170 UINTN NumberOfData;\r
171 EFI_SEC_PLATFORM_INFORMATION_CPU *CpuInstance;\r
172 EFI_SEC_PLATFORM_INFORMATION_CPU BspCpuInstance;\r
173 UINTN ProcessorNumber;\r
174 UINTN CpuIndex;\r
a1a4c7a4
JF
175 EFI_PROCESSOR_INFORMATION ProcessorInfo;\r
176 EFI_HEALTH_FLAGS BistData;\r
177 UINTN NumberOfProcessors;\r
178 UINTN NumberOfEnabledProcessors;\r
86432994
JF
179 UINTN BistInformationSize;\r
180 EFI_SEC_PLATFORM_INFORMATION_RECORD2 *PlatformInformationRecord2;\r
181 EFI_SEC_PLATFORM_INFORMATION_CPU *CpuInstanceInHob;\r
182 \r
a1a4c7a4
JF
183\r
184 MpInitLibGetNumberOfProcessors(&NumberOfProcessors, &NumberOfEnabledProcessors);\r
ea0f431c 185\r
86432994
JF
186 BistInformationSize = sizeof (EFI_SEC_PLATFORM_INFORMATION_RECORD2) +\r
187 sizeof (EFI_SEC_PLATFORM_INFORMATION_CPU) * NumberOfProcessors;\r
188 Status = PeiServicesAllocatePool (\r
189 (UINTN) BistInformationSize,\r
190 (VOID **) &PlatformInformationRecord2\r
191 );\r
192 ASSERT_EFI_ERROR (Status);\r
193 PlatformInformationRecord2->NumberOfCpus = (UINT32)NumberOfProcessors;\r
194\r
ea0f431c
JF
195 SecPlatformInformation2 = NULL;\r
196 SecPlatformInformation = NULL;\r
197 NumberOfData = 0;\r
198 CpuInstance = NULL;\r
ea0f431c
JF
199 //\r
200 // Get BIST information from Sec Platform Information2 Ppi firstly\r
201 //\r
202 Status = GetBistInfoFromPpi (\r
203 PeiServices,\r
204 &gEfiSecPlatformInformation2PpiGuid,\r
205 &SecInformationDescriptor,\r
dfb0e659
JF
206 (VOID *) &SecPlatformInformation2,\r
207 NULL\r
ea0f431c
JF
208 );\r
209 if (Status == EFI_SUCCESS) {\r
210 //\r
211 // Sec Platform Information2 PPI includes BSP/APs' BIST information\r
212 //\r
213 NumberOfData = SecPlatformInformation2->NumberOfCpus;\r
214 CpuInstance = SecPlatformInformation2->CpuInstance;\r
215 } else {\r
216 //\r
217 // Otherwise, get BIST information from Sec Platform Information Ppi\r
218 //\r
219 Status = GetBistInfoFromPpi (\r
220 PeiServices,\r
221 &gEfiSecPlatformInformationPpiGuid,\r
222 &SecInformationDescriptor,\r
dfb0e659
JF
223 (VOID *) &SecPlatformInformation,\r
224 NULL\r
ea0f431c
JF
225 );\r
226 if (Status == EFI_SUCCESS) {\r
227 NumberOfData = 1;\r
228 //\r
229 // SEC Platform Information only includes BSP's BIST information\r
230 // and does not have BSP's APIC ID\r
231 //\r
232 BspCpuInstance.CpuLocation = GetInitialApicId ();\r
233 BspCpuInstance.InfoRecord.IA32HealthFlags.Uint32 = SecPlatformInformation->IA32HealthFlags.Uint32;\r
234 CpuInstance = &BspCpuInstance;\r
235 } else {\r
236 DEBUG ((EFI_D_INFO, "Does not find any stored CPU BIST information from PPI!\n"));\r
237 }\r
238 }\r
a1a4c7a4
JF
239 for (ProcessorNumber = 0; ProcessorNumber < NumberOfProcessors; ProcessorNumber ++) {\r
240 MpInitLibGetProcessorInfo (ProcessorNumber, &ProcessorInfo, &BistData);\r
ea0f431c
JF
241 for (CpuIndex = 0; CpuIndex < NumberOfData; CpuIndex ++) {\r
242 ASSERT (CpuInstance != NULL);\r
a1a4c7a4 243 if (ProcessorInfo.ProcessorId == CpuInstance[CpuIndex].CpuLocation) {\r
ea0f431c
JF
244 //\r
245 // Update processor's BIST data if it is already stored before\r
246 //\r
a1a4c7a4 247 BistData = CpuInstance[CpuIndex].InfoRecord.IA32HealthFlags;\r
ea0f431c
JF
248 }\r
249 }\r
a1a4c7a4 250 if (BistData.Uint32 != 0) {\r
ea0f431c
JF
251 //\r
252 // Report Status Code that self test is failed\r
253 //\r
254 REPORT_STATUS_CODE (\r
255 EFI_ERROR_CODE | EFI_ERROR_MAJOR,\r
256 (EFI_COMPUTING_UNIT_HOST_PROCESSOR | EFI_CU_HP_EC_SELF_TEST)\r
257 );\r
258 }\r
259 DEBUG ((EFI_D_INFO, " APICID - 0x%08x, BIST - 0x%08x\n",\r
8dc56dde 260 (UINT32) ProcessorInfo.ProcessorId,\r
a1a4c7a4 261 BistData\r
ea0f431c 262 ));\r
86432994
JF
263 CpuInstanceInHob = PlatformInformationRecord2->CpuInstance;\r
264 CpuInstanceInHob[ProcessorNumber].CpuLocation = (UINT32) ProcessorInfo.ProcessorId;\r
265 CpuInstanceInHob[ProcessorNumber].InfoRecord.IA32HealthFlags = BistData;\r
ea0f431c 266 }\r
86432994
JF
267 \r
268 //\r
269 // Build SecPlatformInformation2 PPI GUIDed HOB that also could be consumed\r
270 // by CPU MP driver to get CPU BIST data\r
271 //\r
272 BuildGuidDataHob (\r
273 &gEfiSecPlatformInformation2PpiGuid,\r
274 PlatformInformationRecord2,\r
275 (UINTN) BistInformationSize\r
276 );\r
ea0f431c 277\r
a1a4c7a4 278 if (SecPlatformInformation2 != NULL && NumberOfData < NumberOfProcessors) {\r
ea0f431c 279 //\r
a1a4c7a4 280 // Reinstall SecPlatformInformation2 PPI to include new BIST information\r
ea0f431c
JF
281 //\r
282 Status = PeiServicesReInstallPpi (\r
283 SecInformationDescriptor,\r
284 &mPeiSecPlatformInformation2Ppi\r
285 );\r
286 ASSERT_EFI_ERROR (Status);\r
287 } else {\r
288 //\r
a1a4c7a4 289 // Install SecPlatformInformation2 PPI to include new BIST information\r
ea0f431c
JF
290 //\r
291 Status = PeiServicesInstallPpi (&mPeiSecPlatformInformation2Ppi);\r
292 ASSERT_EFI_ERROR(Status);\r
293 }\r
294}\r
a1a4c7a4 295\r