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