]> git.proxmox.com Git - mirror_edk2.git/blame - IntelFrameworkModulePkg/Library/SmmRuntimeDxeReportStatusCodeLibFramework/ReportStatusCodeLib.c
IntelFrameworkModulePkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / IntelFrameworkModulePkg / Library / SmmRuntimeDxeReportStatusCodeLibFramework / ReportStatusCodeLib.c
CommitLineData
e5516b49 1/** @file\r
29f766e4 2 API implementation for instance of Report Status Code Library.\r
e5516b49 3\r
13314ba3 4 Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r
c0a00b14 5 SPDX-License-Identifier: BSD-2-Clause-Patent\r
e5516b49 6\r
7**/\r
8\r
9#include "ReportStatusCodeLibInternal.h"\r
10\r
e5516b49 11/**\r
12 Converts a status code to an 8-bit POST code value.\r
13\r
14 Converts the status code specified by CodeType and Value to an 8-bit POST code\r
15 and returns the 8-bit POST code in PostCode. If CodeType is an\r
16 EFI_PROGRESS_CODE or CodeType is an EFI_ERROR_CODE, then bits 0..4 of PostCode\r
17 are set to bits 16..20 of Value, and bits 5..7 of PostCode are set to bits\r
18 24..26 of Value., and TRUE is returned. Otherwise, FALSE is returned.\r
19\r
20 If PostCode is NULL, then ASSERT().\r
21\r
22 @param CodeType The type of status code being converted.\r
23 @param Value The status code value being converted.\r
24 @param PostCode A pointer to the 8-bit POST code value to return.\r
25\r
26 @retval TRUE The status code specified by CodeType and Value was converted\r
27 to an 8-bit POST code and returned in PostCode.\r
28 @retval FALSE The status code specified by CodeType and Value could not be\r
29 converted to an 8-bit POST code value.\r
30\r
31**/\r
32BOOLEAN\r
33EFIAPI\r
34CodeTypeToPostCode (\r
35 IN EFI_STATUS_CODE_TYPE CodeType,\r
36 IN EFI_STATUS_CODE_VALUE Value,\r
37 OUT UINT8 *PostCode\r
38 )\r
39{\r
40 //\r
41 // If PostCode is NULL, then ASSERT()\r
42 //\r
43 ASSERT (PostCode != NULL);\r
44\r
45 //\r
46 // Convert Value to an 8 bit post code\r
47 //\r
48 if (((CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_PROGRESS_CODE) ||\r
49 ((CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_ERROR_CODE) ) {\r
50 *PostCode = (UINT8) ((((Value & EFI_STATUS_CODE_CLASS_MASK) >> 24) << 5) |\r
51 (((Value & EFI_STATUS_CODE_SUBCLASS_MASK) >> 16) & 0x1f));\r
52 return TRUE;\r
53 }\r
54 return FALSE;\r
55}\r
56\r
57\r
58/**\r
59 Extracts ASSERT() information from a status code structure.\r
60\r
61 Converts the status code specified by CodeType, Value, and Data to the ASSERT()\r
62 arguments specified by Filename, Description, and LineNumber. If CodeType is\r
63 an EFI_ERROR_CODE, and CodeType has a severity of EFI_ERROR_UNRECOVERED, and\r
64 Value has an operation mask of EFI_SW_EC_ILLEGAL_SOFTWARE_STATE, extract\r
65 Filename, Description, and LineNumber from the optional data area of the\r
66 status code buffer specified by Data. The optional data area of Data contains\r
67 a Null-terminated ASCII string for the FileName, followed by a Null-terminated\r
68 ASCII string for the Description, followed by a 32-bit LineNumber. If the\r
69 ASSERT() information could be extracted from Data, then return TRUE.\r
70 Otherwise, FALSE is returned.\r
71\r
72 If Data is NULL, then ASSERT().\r
73 If Filename is NULL, then ASSERT().\r
74 If Description is NULL, then ASSERT().\r
75 If LineNumber is NULL, then ASSERT().\r
76\r
77 @param CodeType The type of status code being converted.\r
78 @param Value The status code value being converted.\r
79 @param Data Pointer to status code data buffer.\r
80 @param Filename Pointer to the source file name that generated the ASSERT().\r
81 @param Description Pointer to the description of the ASSERT().\r
82 @param LineNumber Pointer to source line number that generated the ASSERT().\r
83\r
84 @retval TRUE The status code specified by CodeType, Value, and Data was\r
85 converted ASSERT() arguments specified by Filename, Description,\r
86 and LineNumber.\r
87 @retval FALSE The status code specified by CodeType, Value, and Data could\r
88 not be converted to ASSERT() arguments.\r
89\r
90**/\r
91BOOLEAN\r
92EFIAPI\r
93ReportStatusCodeExtractAssertInfo (\r
94 IN EFI_STATUS_CODE_TYPE CodeType,\r
95 IN EFI_STATUS_CODE_VALUE Value,\r
96 IN CONST EFI_STATUS_CODE_DATA *Data,\r
97 OUT CHAR8 **Filename,\r
98 OUT CHAR8 **Description,\r
99 OUT UINT32 *LineNumber\r
100 )\r
101{\r
102 EFI_DEBUG_ASSERT_DATA *AssertData;\r
103\r
104 ASSERT (Data != NULL);\r
105 ASSERT (Filename != NULL);\r
106 ASSERT (Description != NULL);\r
107 ASSERT (LineNumber != NULL);\r
108\r
109 if (((CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_ERROR_CODE) &&\r
110 ((CodeType & EFI_STATUS_CODE_SEVERITY_MASK) == EFI_ERROR_UNRECOVERED) &&\r
111 ((Value & EFI_STATUS_CODE_OPERATION_MASK) == EFI_SW_EC_ILLEGAL_SOFTWARE_STATE)) {\r
112 AssertData = (EFI_DEBUG_ASSERT_DATA *)(Data + 1);\r
113 *Filename = (CHAR8 *)(AssertData + 1);\r
114 *Description = *Filename + AsciiStrLen (*Filename) + 1;\r
115 *LineNumber = AssertData->LineNumber;\r
116 return TRUE;\r
117 }\r
118 return FALSE;\r
119}\r
120\r
121\r
122/**\r
123 Extracts DEBUG() information from a status code structure.\r
124\r
125 Converts the status code specified by Data to the DEBUG() arguments specified\r
126 by ErrorLevel, Marker, and Format. If type GUID in Data is\r
127 EFI_STATUS_CODE_DATA_TYPE_DEBUG_GUID, then extract ErrorLevel, Marker, and\r
128 Format from the optional data area of the status code buffer specified by Data.\r
129 The optional data area of Data contains a 32-bit ErrorLevel followed by Marker\r
130 which is 12 UINTN parameters, followed by a Null-terminated ASCII string for\r
131 the Format. If the DEBUG() information could be extracted from Data, then\r
132 return TRUE. Otherwise, FALSE is returned.\r
133\r
134 If Data is NULL, then ASSERT().\r
135 If ErrorLevel is NULL, then ASSERT().\r
136 If Marker is NULL, then ASSERT().\r
137 If Format is NULL, then ASSERT().\r
138\r
139 @param Data Pointer to status code data buffer.\r
140 @param ErrorLevel Pointer to error level mask for a debug message.\r
141 @param Marker Pointer to the variable argument list associated with Format.\r
142 @param Format Pointer to a Null-terminated ASCII format string of a\r
143 debug message.\r
144\r
145 @retval TRUE The status code specified by Data was converted DEBUG() arguments\r
146 specified by ErrorLevel, Marker, and Format.\r
147 @retval FALSE The status code specified by Data could not be converted to\r
148 DEBUG() arguments.\r
149\r
150**/\r
151BOOLEAN\r
152EFIAPI\r
153ReportStatusCodeExtractDebugInfo (\r
154 IN CONST EFI_STATUS_CODE_DATA *Data,\r
155 OUT UINT32 *ErrorLevel,\r
ca9938b8 156 OUT BASE_LIST *Marker,\r
e5516b49 157 OUT CHAR8 **Format\r
158 )\r
159{\r
160 EFI_DEBUG_INFO *DebugInfo;\r
161\r
29f766e4 162 ASSERT (Data != NULL);\r
163 ASSERT (ErrorLevel != NULL);\r
e5516b49 164 ASSERT (Marker != NULL);\r
165 ASSERT (Format != NULL);\r
166\r
167 //\r
168 // If the GUID type is not EFI_STATUS_CODE_DATA_TYPE_DEBUG_GUID then return FALSE\r
169 //\r
170 if (!CompareGuid (&Data->Type, &gEfiStatusCodeDataTypeDebugGuid)) {\r
171 return FALSE;\r
172 }\r
173\r
174 //\r
175 // Retrieve the debug information from the status code record\r
176 //\r
177 DebugInfo = (EFI_DEBUG_INFO *)(Data + 1);\r
178\r
179 *ErrorLevel = DebugInfo->ErrorLevel;\r
180\r
181 //\r
29f766e4 182 // The first 12 * sizeof (UINT64) bytes following EFI_DEBUG_INFO are for variable arguments\r
183 // of format in DEBUG string. Its address is returned in Marker and has to be 64-bit aligned.\r
184 // It must be noticed that EFI_DEBUG_INFO follows EFI_STATUS_CODE_DATA, whose size is\r
185 // 20 bytes. The size of EFI_DEBUG_INFO is 4 bytes, so we can ensure that Marker\r
186 // returned is 64-bit aligned.\r
187 // 64-bit aligned is a must, otherwise retrieving 64-bit parameter from BASE_LIST will\r
188 // cause unalignment exception.\r
e5516b49 189 //\r
ca9938b8 190 *Marker = (BASE_LIST) (DebugInfo + 1);\r
e5516b49 191 *Format = (CHAR8 *)(((UINT64 *)*Marker) + 12);\r
192\r
193 return TRUE;\r
194}\r
195\r
196\r
197/**\r
198 Reports a status code.\r
199\r
200 Reports the status code specified by the parameters Type and Value. Status\r
201 code also require an instance, caller ID, and extended data. This function\r
202 passed in a zero instance, NULL extended data, and a caller ID of\r
203 gEfiCallerIdGuid, which is the GUID for the module.\r
204\r
205 ReportStatusCode()must actively prevent recusrsion. If ReportStatusCode()\r
206 is called while processing another any other Report Status Code Library function,\r
207 then ReportStatusCode() must return immediately.\r
208\r
209 @param Type Status code type.\r
210 @param Value Status code value.\r
211\r
212 @retval EFI_SUCCESS The status code was reported.\r
213 @retval EFI_DEVICE_ERROR There status code could not be reported due to a\r
214 device error.\r
215 @retval EFI_UNSUPPORTED Report status code is not supported\r
216\r
217**/\r
218EFI_STATUS\r
219EFIAPI\r
220ReportStatusCode (\r
221 IN EFI_STATUS_CODE_TYPE Type,\r
222 IN EFI_STATUS_CODE_VALUE Value\r
223 )\r
224{\r
225 return InternalReportStatusCode (Type, Value, 0, &gEfiCallerIdGuid, NULL);\r
226}\r
227\r
228\r
229/**\r
230 Reports a status code with a Device Path Protocol as the extended data.\r
231\r
232 Allocates and fills in the extended data section of a status code with the\r
233 Device Path Protocol specified by DevicePath. This function is responsible\r
234 for allocating a buffer large enough for the standard header and the device\r
235 path. The standard header is filled in with a GUID of\r
236 gEfiStatusCodeSpecificDataGuid. The status code is reported with a zero\r
237 instance and a caller ID of gEfiCallerIdGuid.\r
238\r
239 ReportStatusCodeWithDevicePath()must actively prevent recursion. If\r
240 ReportStatusCodeWithDevicePath() is called while processing another any other\r
241 Report Status Code Library function, then ReportStatusCodeWithDevicePath()\r
242 must return EFI_DEVICE_ERROR immediately.\r
243\r
244 If DevicePath is NULL, then ASSERT().\r
245\r
246 @param Type Status code type.\r
247 @param Value Status code value.\r
248 @param DevicePath Pointer to the Device Path Protocol to be reported.\r
249\r
250 @retval EFI_SUCCESS The status code was reported with the extended\r
251 data specified by DevicePath.\r
252 @retval EFI_OUT_OF_RESOURCES There were not enough resources to allocate the\r
253 extended data section.\r
254 @retval EFI_UNSUPPORTED Report status code is not supported\r
255\r
256**/\r
257EFI_STATUS\r
258EFIAPI\r
259ReportStatusCodeWithDevicePath (\r
260 IN EFI_STATUS_CODE_TYPE Type,\r
261 IN EFI_STATUS_CODE_VALUE Value,\r
262 IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath\r
263 )\r
264{\r
265 ASSERT (DevicePath != NULL);\r
266 return ReportStatusCodeWithExtendedData (\r
267 Type,\r
268 Value,\r
269 (VOID *)DevicePath,\r
29f766e4 270 GetDevicePathSize (DevicePath)\r
e5516b49 271 );\r
272}\r
273\r
274\r
275/**\r
276 Reports a status code with an extended data buffer.\r
277\r
278 Allocates and fills in the extended data section of a status code with the\r
279 extended data specified by ExtendedData and ExtendedDataSize. ExtendedData\r
280 is assumed to be one of the data structures specified in Related Definitions.\r
281 These data structure do not have the standard header, so this function is\r
282 responsible for allocating a buffer large enough for the standard header and\r
283 the extended data passed into this function. The standard header is filled\r
284 in with a GUID of gEfiStatusCodeSpecificDataGuid. The status code is reported\r
285 with a zero instance and a caller ID of gEfiCallerIdGuid.\r
286\r
287 ReportStatusCodeWithExtendedData()must actively prevent recursion. If\r
288 ReportStatusCodeWithExtendedData() is called while processing another any other\r
289 Report Status Code Library function, then ReportStatusCodeWithExtendedData()\r
290 must return EFI_DEVICE_ERROR immediately.\r
291\r
292 If ExtendedData is NULL, then ASSERT().\r
293 If ExtendedDataSize is 0, then ASSERT().\r
294\r
295 @param Type Status code type.\r
296 @param Value Status code value.\r
297 @param ExtendedData Pointer to the extended data buffer to be reported.\r
298 @param ExtendedDataSize The size, in bytes, of the extended data buffer to\r
299 be reported.\r
300\r
301 @retval EFI_SUCCESS The status code was reported with the extended\r
302 data specified by ExtendedData and ExtendedDataSize.\r
303 @retval EFI_OUT_OF_RESOURCES There were not enough resources to allocate the\r
304 extended data section.\r
305 @retval EFI_UNSUPPORTED Report status code is not supported\r
306\r
307**/\r
308EFI_STATUS\r
309EFIAPI\r
310ReportStatusCodeWithExtendedData (\r
311 IN EFI_STATUS_CODE_TYPE Type,\r
312 IN EFI_STATUS_CODE_VALUE Value,\r
313 IN CONST VOID *ExtendedData,\r
314 IN UINTN ExtendedDataSize\r
315 )\r
316{\r
317 ASSERT (ExtendedData != NULL);\r
318 ASSERT (ExtendedDataSize != 0);\r
319 return ReportStatusCodeEx (\r
320 Type,\r
321 Value,\r
322 0,\r
323 NULL,\r
324 NULL,\r
325 ExtendedData,\r
326 ExtendedDataSize\r
327 );\r
328}\r
329\r
330\r
331/**\r
332 Reports a status code with full parameters.\r
333\r
334 The function reports a status code. If ExtendedData is NULL and ExtendedDataSize\r
335 is 0, then an extended data buffer is not reported. If ExtendedData is not\r
336 NULL and ExtendedDataSize is not 0, then an extended data buffer is allocated.\r
337 ExtendedData is assumed not have the standard status code header, so this function\r
338 is responsible for allocating a buffer large enough for the standard header and\r
339 the extended data passed into this function. The standard header is filled in\r
340 with a GUID specified by ExtendedDataGuid. If ExtendedDataGuid is NULL, then a\r
29f766e4 341 GUID of gEfiStatusCodeSpecificDataGuid is used. The status code is reported with\r
e5516b49 342 an instance specified by Instance and a caller ID specified by CallerId. If\r
343 CallerId is NULL, then a caller ID of gEfiCallerIdGuid is used.\r
344\r
345 ReportStatusCodeEx()must actively prevent recursion. If\r
346 ReportStatusCodeEx() is called while processing another any\r
347 other Report Status Code Library function, then\r
348 ReportStatusCodeEx() must return EFI_DEVICE_ERROR immediately.\r
349\r
350 If ExtendedData is NULL and ExtendedDataSize is not zero, then ASSERT().\r
351 If ExtendedData is not NULL and ExtendedDataSize is zero, then ASSERT().\r
352\r
353 @param Type Status code type.\r
354 @param Value Status code value.\r
355 @param Instance Status code instance number.\r
356 @param CallerId Pointer to a GUID that identifies the caller of this\r
357 function. If this parameter is NULL, then a caller\r
358 ID of gEfiCallerIdGuid is used.\r
359 @param ExtendedDataGuid Pointer to the GUID for the extended data buffer.\r
360 If this parameter is NULL, then a the status code\r
361 standard header is filled in with\r
362 gEfiStatusCodeSpecificDataGuid.\r
363 @param ExtendedData Pointer to the extended data buffer. This is an\r
364 optional parameter that may be NULL.\r
365 @param ExtendedDataSize The size, in bytes, of the extended data buffer.\r
366\r
367 @retval EFI_SUCCESS The status code was reported.\r
368 @retval EFI_OUT_OF_RESOURCES There were not enough resources to allocate\r
369 the extended data section if it was specified.\r
370 @retval EFI_UNSUPPORTED Report status code is not supported\r
371\r
372**/\r
373EFI_STATUS\r
374EFIAPI\r
375ReportStatusCodeEx (\r
376 IN EFI_STATUS_CODE_TYPE Type,\r
377 IN EFI_STATUS_CODE_VALUE Value,\r
378 IN UINT32 Instance,\r
379 IN CONST EFI_GUID *CallerId OPTIONAL,\r
380 IN CONST EFI_GUID *ExtendedDataGuid OPTIONAL,\r
381 IN CONST VOID *ExtendedData OPTIONAL,\r
382 IN UINTN ExtendedDataSize\r
383 )\r
384{\r
29f766e4 385 EFI_STATUS Status;\r
386\r
387 ASSERT (!((ExtendedData == NULL) && (ExtendedDataSize != 0)));\r
388 ASSERT (!((ExtendedData != NULL) && (ExtendedDataSize == 0)));\r
389\r
390 if (ExtendedDataSize > EFI_STATUS_CODE_DATA_MAX_SIZE) {\r
8185265e 391 DEBUG ((EFI_D_ERROR, "Status code extended data is too large to be reported!\n"));\r
29f766e4 392 return EFI_OUT_OF_RESOURCES;\r
393 }\r
394\r
395 //\r
396 // Fill in the extended data header\r
397 //\r
13314ba3 398 mStatusCodeData->HeaderSize = (UINT16) sizeof (EFI_STATUS_CODE_DATA);\r
29f766e4 399 mStatusCodeData->Size = (UINT16)ExtendedDataSize;\r
400 if (ExtendedDataGuid == NULL) {\r
401 ExtendedDataGuid = &gEfiStatusCodeSpecificDataGuid;\r
402 }\r
403 CopyGuid (&mStatusCodeData->Type, ExtendedDataGuid);\r
404\r
405 //\r
406 // Fill in the extended data buffer\r
407 //\r
408 if (ExtendedData != NULL) {\r
409 CopyMem (mStatusCodeData + 1, ExtendedData, ExtendedDataSize);\r
410 }\r
411\r
412 //\r
413 // Report the status code\r
414 //\r
415 if (CallerId == NULL) {\r
416 CallerId = &gEfiCallerIdGuid;\r
417 }\r
418 Status = InternalReportStatusCode (Type, Value, Instance, CallerId, mStatusCodeData);\r
e5516b49 419\r
420 return Status;\r
421}\r
422\r
423\r
424/**\r
425 Returns TRUE if status codes of type EFI_PROGRESS_CODE are enabled\r
426\r
427 This function returns TRUE if the REPORT_STATUS_CODE_PROPERTY_PROGRESS_CODE_ENABLED\r
428 bit of PcdReportStatusCodeProperyMask is set. Otherwise FALSE is returned.\r
429\r
430 @retval TRUE The REPORT_STATUS_CODE_PROPERTY_PROGRESS_CODE_ENABLED bit of\r
431 PcdReportStatusCodeProperyMask is set.\r
432 @retval FALSE The REPORT_STATUS_CODE_PROPERTY_PROGRESS_CODE_ENABLED bit of\r
433 PcdReportStatusCodeProperyMask is clear.\r
434\r
435**/\r
436BOOLEAN\r
437EFIAPI\r
438ReportProgressCodeEnabled (\r
439 VOID\r
440 )\r
441{\r
29f766e4 442 return (BOOLEAN) ((PcdGet8 (PcdReportStatusCodePropertyMask) & REPORT_STATUS_CODE_PROPERTY_PROGRESS_CODE_ENABLED) != 0);\r
e5516b49 443}\r
444\r
445\r
446/**\r
447 Returns TRUE if status codes of type EFI_ERROR_CODE are enabled\r
448\r
449 This function returns TRUE if the REPORT_STATUS_CODE_PROPERTY_ERROR_CODE_ENABLED\r
450 bit of PcdReportStatusCodeProperyMask is set. Otherwise FALSE is returned.\r
451\r
452 @retval TRUE The REPORT_STATUS_CODE_PROPERTY_ERROR_CODE_ENABLED bit of\r
453 PcdReportStatusCodeProperyMask is set.\r
454 @retval FALSE The REPORT_STATUS_CODE_PROPERTY_ERROR_CODE_ENABLED bit of\r
455 PcdReportStatusCodeProperyMask is clear.\r
456\r
457**/\r
458BOOLEAN\r
459EFIAPI\r
460ReportErrorCodeEnabled (\r
461 VOID\r
462 )\r
463{\r
29f766e4 464 return (BOOLEAN) ((PcdGet8 (PcdReportStatusCodePropertyMask) & REPORT_STATUS_CODE_PROPERTY_ERROR_CODE_ENABLED) != 0);\r
e5516b49 465}\r
466\r
467\r
468/**\r
469 Returns TRUE if status codes of type EFI_DEBUG_CODE are enabled\r
470\r
471 This function returns TRUE if the REPORT_STATUS_CODE_PROPERTY_DEBUG_CODE_ENABLED\r
472 bit of PcdReportStatusCodeProperyMask is set. Otherwise FALSE is returned.\r
473\r
474 @retval TRUE The REPORT_STATUS_CODE_PROPERTY_DEBUG_CODE_ENABLED bit of\r
475 PcdReportStatusCodeProperyMask is set.\r
476 @retval FALSE The REPORT_STATUS_CODE_PROPERTY_DEBUG_CODE_ENABLED bit of\r
477 PcdReportStatusCodeProperyMask is clear.\r
478\r
479**/\r
480BOOLEAN\r
481EFIAPI\r
482ReportDebugCodeEnabled (\r
483 VOID\r
484 )\r
485{\r
29f766e4 486 return (BOOLEAN) ((PcdGet8 (PcdReportStatusCodePropertyMask) & REPORT_STATUS_CODE_PROPERTY_DEBUG_CODE_ENABLED) != 0);\r
e5516b49 487}\r