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