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