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