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