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