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