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