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