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