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