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