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