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