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