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