]> git.proxmox.com Git - mirror_edk2.git/blob - EdkCompatibilityPkg/Foundation/Library/EdkIIGlueLib/Library/PeiReportStatusCodeLib/ReportStatusCodeLib.c
Add in the 1st version of ECP.
[mirror_edk2.git] / EdkCompatibilityPkg / Foundation / Library / EdkIIGlueLib / Library / PeiReportStatusCodeLib / ReportStatusCodeLib.c
1 /*++
2
3 Copyright (c) 2004 - 2006, Intel Corporation
4 All rights reserved. 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 *Marker = (VA_LIST) (DebugInfo + 1);
252 *Format = (CHAR8 *)(((UINT64 *)*Marker) + 12);
253
254 return TRUE;
255 }
256
257
258 /**
259 Reports a status code.
260
261 Reports the status code specified by the parameters Type and Value. Status
262 code also require an instance, caller ID, and extended data. This function
263 passed in a zero instance, NULL extended data, and a caller ID of
264 gEfiCallerIdGuid, which is the GUID for the module.
265
266 ReportStatusCode()must actively prevent recusrsion. If ReportStatusCode()
267 is called while processing another any other Report Status Code Library function,
268 then ReportStatusCode() must return immediately.
269
270 @param Type Status code type.
271 @param Value Status code value.
272
273 @retval EFI_SUCCESS The status code was reported.
274 @retval EFI_DEVICE_ERROR There status code could not be reported due to a
275 device error.
276 @retval EFI_UNSUPPORTED Report status code is not supported
277
278 **/
279 EFI_STATUS
280 EFIAPI
281 GlueReportStatusCode (
282 IN EFI_STATUS_CODE_TYPE Type,
283 IN EFI_STATUS_CODE_VALUE Value
284 )
285 {
286 return InternalReportStatusCode (Type, Value, 0, &gEfiCallerIdGuid, NULL);
287 }
288
289
290 /**
291 Reports a status code with a Device Path Protocol as the extended data.
292
293 Allocates and fills in the extended data section of a status code with the
294 Device Path Protocol specified by DevicePath. This function is responsible
295 for allocating a buffer large enough for the standard header and the device
296 path. The standard header is filled in with a GUID of
297 gEfiStatusCodeSpecificDataGuid. The status code is reported with a zero
298 instance and a caller ID of gEfiCallerIdGuid.
299
300 ReportStatusCodeWithDevicePath()must actively prevent recursion. If
301 ReportStatusCodeWithDevicePath() is called while processing another any other
302 Report Status Code Library function, then ReportStatusCodeWithDevicePath()
303 must return EFI_DEVICE_ERROR immediately.
304
305 If DevicePath is NULL, then ASSERT().
306
307 @param Type Status code type.
308 @param Value Status code value.
309 @param DevicePath Pointer to the Device Path Protocol to be reported.
310
311 @retval EFI_SUCCESS The status code was reported with the extended
312 data specified by DevicePath.
313 @retval EFI_OUT_OF_RESOURCES There were not enough resources to allocate the
314 extended data section.
315 @retval EFI_UNSUPPORTED Report status code is not supported
316
317 **/
318 EFI_STATUS
319 EFIAPI
320 GlueReportStatusCodeWithDevicePath (
321 IN EFI_STATUS_CODE_TYPE Type,
322 IN EFI_STATUS_CODE_VALUE Value,
323 IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath
324 )
325 {
326 ASSERT (DevicePath != NULL);
327 return EFI_UNSUPPORTED;
328 }
329
330
331 /**
332 Reports a status code with an extended data buffer.
333
334 Allocates and fills in the extended data section of a status code with the
335 extended data specified by ExtendedData and ExtendedDataSize. ExtendedData
336 is assumed to be one of the data structures specified in Related Definitions.
337 These data structure do not have the standard header, so this function is
338 responsible for allocating a buffer large enough for the standard header and
339 the extended data passed into this function. The standard header is filled
340 in with a GUID of gEfiStatusCodeSpecificDataGuid. The status code is reported
341 with a zero instance and a caller ID of gEfiCallerIdGuid.
342
343 ReportStatusCodeWithExtendedData()must actively prevent recursion. If
344 ReportStatusCodeWithExtendedData() is called while processing another any other
345 Report Status Code Library function, then ReportStatusCodeWithExtendedData()
346 must return EFI_DEVICE_ERROR immediately.
347
348 If ExtendedData is NULL, then ASSERT().
349 If ExtendedDataSize is 0, then ASSERT().
350
351 @param Type Status code type.
352 @param Value Status code value.
353 @param ExtendedData Pointer to the extended data buffer to be reported.
354 @param ExtendedDataSize The size, in bytes, of the extended data buffer to
355 be reported.
356
357 @retval EFI_SUCCESS The status code was reported with the extended
358 data specified by ExtendedData and ExtendedDataSize.
359 @retval EFI_OUT_OF_RESOURCES There were not enough resources to allocate the
360 extended data section.
361 @retval EFI_UNSUPPORTED Report status code is not supported
362
363 **/
364 EFI_STATUS
365 EFIAPI
366 GlueReportStatusCodeWithExtendedData (
367 IN EFI_STATUS_CODE_TYPE Type,
368 IN EFI_STATUS_CODE_VALUE Value,
369 IN CONST VOID *ExtendedData,
370 IN UINTN ExtendedDataSize
371 )
372 {
373 ASSERT (ExtendedData != NULL);
374 ASSERT (ExtendedDataSize != 0);
375 return ReportStatusCodeEx (
376 Type,
377 Value,
378 0,
379 NULL,
380 NULL,
381 ExtendedData,
382 ExtendedDataSize
383 );
384 }
385
386
387 /**
388 Reports a status code with full parameters.
389
390 The function reports a status code. If ExtendedData is NULL and ExtendedDataSize
391 is 0, then an extended data buffer is not reported. If ExtendedData is not
392 NULL and ExtendedDataSize is not 0, then an extended data buffer is allocated.
393 ExtendedData is assumed not have the standard status code header, so this function
394 is responsible for allocating a buffer large enough for the standard header and
395 the extended data passed into this function. The standard header is filled in
396 with a GUID specified by ExtendedDataGuid. If ExtendedDataGuid is NULL, then a
397 GUID of gEfiStatusCodeSpecificDatauid is used. The status code is reported with
398 an instance specified by Instance and a caller ID specified by CallerId. If
399 CallerId is NULL, then a caller ID of gEfiCallerIdGuid is used.
400
401 ReportStatusCodeEx()must actively prevent recursion. If ReportStatusCodeEx()
402 is called while processing another any other Report Status Code Library function,
403 then ReportStatusCodeEx() must return EFI_DEVICE_ERROR immediately.
404
405 If ExtendedData is NULL and ExtendedDataSize is not zero, then ASSERT().
406 If ExtendedData is not NULL and ExtendedDataSize is zero, then ASSERT().
407
408 @param Type Status code type.
409 @param Value Status code value.
410 @param Instance Status code instance number.
411 @param CallerId Pointer to a GUID that identifies the caller of this
412 function. If this parameter is NULL, then a caller
413 ID of gEfiCallerIdGuid is used.
414 @param ExtendedDataGuid Pointer to the GUID for the extended data buffer.
415 If this parameter is NULL, then a the status code
416 standard header is filled in with
417 gEfiStatusCodeSpecificDataGuid.
418 @param ExtendedData Pointer to the extended data buffer. This is an
419 optional parameter that may be NULL.
420 @param ExtendedDataSize The size, in bytes, of the extended data buffer.
421
422 @retval EFI_SUCCESS The status code was reported.
423 @retval EFI_OUT_OF_RESOURCES There were not enough resources to allocate
424 the extended data section if it was specified.
425 @retval EFI_UNSUPPORTED Report status code is not supported
426
427 **/
428 EFI_STATUS
429 EFIAPI
430 GlueReportStatusCodeEx (
431 IN EFI_STATUS_CODE_TYPE Type,
432 IN EFI_STATUS_CODE_VALUE Value,
433 IN UINT32 Instance,
434 IN CONST EFI_GUID *CallerId OPTIONAL,
435 IN CONST EFI_GUID *ExtendedDataGuid OPTIONAL,
436 IN CONST VOID *ExtendedData OPTIONAL,
437 IN UINTN ExtendedDataSize
438 )
439 {
440 EFI_STATUS_CODE_DATA *StatusCodeData;
441 UINT64 Buffer[MAX_EXTENDED_DATA_SIZE / sizeof (UINT64)];
442
443 ASSERT (!((ExtendedData == NULL) && (ExtendedDataSize != 0)));
444 ASSERT (!((ExtendedData != NULL) && (ExtendedDataSize == 0)));
445
446 if (ExtendedDataSize > (MAX_EXTENDED_DATA_SIZE - sizeof (EFI_STATUS_CODE_DATA))) {
447 return EFI_OUT_OF_RESOURCES;
448 }
449 StatusCodeData = (EFI_STATUS_CODE_DATA *)Buffer;
450 StatusCodeData->HeaderSize = sizeof (EFI_STATUS_CODE_DATA);
451 StatusCodeData->Size = (UINT16)ExtendedDataSize;
452 if (ExtendedDataGuid == NULL) {
453 ExtendedDataGuid = &gEfiStatusCodeSpecificDataGuid;
454 }
455 CopyGuid (&StatusCodeData->Type, ExtendedDataGuid);
456 CopyMem (StatusCodeData + 1, ExtendedData, ExtendedDataSize);
457 if (CallerId == NULL) {
458 CallerId = &gEfiCallerIdGuid;
459 }
460 return InternalReportStatusCode (Type, Value, Instance, CallerId, StatusCodeData);
461 }
462
463
464 /**
465 Returns TRUE if status codes of type EFI_PROGRESS_CODE are enabled
466
467 This function returns TRUE if the REPORT_STATUS_CODE_PROPERTY_PROGRESS_CODE_ENABLED
468 bit of PcdReportStatusCodeProperyMask is set. Otherwise FALSE is returned.
469
470 @retval TRUE The REPORT_STATUS_CODE_PROPERTY_PROGRESS_CODE_ENABLED bit of
471 PcdReportStatusCodeProperyMask is set.
472 @retval FALSE The REPORT_STATUS_CODE_PROPERTY_PROGRESS_CODE_ENABLED bit of
473 PcdReportStatusCodeProperyMask is clear.
474
475 **/
476 BOOLEAN
477 EFIAPI
478 GlueReportProgressCodeEnabled (
479 VOID
480 )
481 {
482 return (BOOLEAN) ((PcdGet8(PcdReportStatusCodePropertyMask) & REPORT_STATUS_CODE_PROPERTY_PROGRESS_CODE_ENABLED) != 0);
483 }
484
485
486 /**
487 Returns TRUE if status codes of type EFI_ERROR_CODE are enabled
488
489 This function returns TRUE if the REPORT_STATUS_CODE_PROPERTY_ERROR_CODE_ENABLED
490 bit of PcdReportStatusCodeProperyMask is set. Otherwise FALSE is returned.
491
492 @retval TRUE The REPORT_STATUS_CODE_PROPERTY_ERROR_CODE_ENABLED bit of
493 PcdReportStatusCodeProperyMask is set.
494 @retval FALSE The REPORT_STATUS_CODE_PROPERTY_ERROR_CODE_ENABLED bit of
495 PcdReportStatusCodeProperyMask is clear.
496
497 **/
498 BOOLEAN
499 EFIAPI
500 GlueReportErrorCodeEnabled (
501 VOID
502 )
503 {
504 return (BOOLEAN) ((PcdGet8(PcdReportStatusCodePropertyMask) & REPORT_STATUS_CODE_PROPERTY_ERROR_CODE_ENABLED) != 0);
505 }
506
507
508 /**
509 Returns TRUE if status codes of type EFI_DEBUG_CODE are enabled
510
511 This function returns TRUE if the REPORT_STATUS_CODE_PROPERTY_DEBUG_CODE_ENABLED
512 bit of PcdReportStatusCodeProperyMask is set. Otherwise FALSE is returned.
513
514 @retval TRUE The REPORT_STATUS_CODE_PROPERTY_DEBUG_CODE_ENABLED bit of
515 PcdReportStatusCodeProperyMask is set.
516 @retval FALSE The REPORT_STATUS_CODE_PROPERTY_DEBUG_CODE_ENABLED bit of
517 PcdReportStatusCodeProperyMask is clear.
518
519 **/
520 BOOLEAN
521 EFIAPI
522 GlueReportDebugCodeEnabled (
523 VOID
524 )
525 {
526 return (BOOLEAN) ((PcdGet8(PcdReportStatusCodePropertyMask) & REPORT_STATUS_CODE_PROPERTY_DEBUG_CODE_ENABLED) != 0);
527 }