]>
Commit | Line | Data |
---|---|---|
30c8ee5c | 1 | /** @file\r |
2 | API implementation for instance of Report Status Code Library.\r | |
3 | \r | |
e5c1acc5 | 4 | Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>\r |
cd5ebaa0 | 5 | This program and the accompanying materials\r |
30c8ee5c | 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 | |
4adf0008 | 15 | #include <Library/ReportStatusCodeLib.h>\r |
16 | #include <Library/BaseLib.h>\r | |
17 | #include <Library/DebugLib.h>\r | |
18 | #include <Library/UefiBootServicesTableLib.h>\r | |
19 | #include <Library/BaseMemoryLib.h>\r | |
20 | #include <Library/PcdLib.h>\r | |
21 | #include <Library/DevicePathLib.h>\r | |
22 | #include <Library/UefiRuntimeLib.h>\r | |
23 | \r | |
24 | #include <Protocol/StatusCode.h>\r | |
25 | \r | |
26 | #include <Guid/StatusCodeDataTypeId.h>\r | |
27 | #include <Guid/StatusCodeDataTypeDebug.h>\r | |
28 | #include <Guid/EventGroup.h>\r | |
29 | \r | |
e5c1acc5 SZ |
30 | \r |
31 | //\r | |
32 | // Define the maximum extended data size that is supported when a status code is reported.\r | |
33 | //\r | |
34 | #define MAX_EXTENDED_DATA_SIZE 0x200\r | |
35 | \r | |
4adf0008 | 36 | EFI_STATUS_CODE_PROTOCOL *mReportStatusCodeLibStatusCodeProtocol = NULL;\r |
37 | EFI_EVENT mReportStatusCodeLibVirtualAddressChangeEvent;\r | |
c05e7994 LG |
38 | EFI_EVENT mReportStatusCodeLibExitBootServicesEvent;\r |
39 | BOOLEAN mHaveExitedBootServices = FALSE;\r | |
4adf0008 | 40 | \r |
41 | /**\r | |
42 | Locate the report status code service.\r | |
43 | \r | |
44 | Retrieve ReportStatusCode() API of Report Status Code Protocol.\r | |
45 | \r | |
46 | **/\r | |
47 | VOID\r | |
48 | InternalGetReportStatusCode (\r | |
49 | VOID\r | |
50 | )\r | |
51 | {\r | |
52 | EFI_STATUS Status;\r | |
53 | \r | |
54 | if (mReportStatusCodeLibStatusCodeProtocol != NULL) {\r | |
55 | return;\r | |
56 | }\r | |
57 | \r | |
c05e7994 | 58 | if (mHaveExitedBootServices) {\r |
4adf0008 | 59 | return;\r |
60 | }\r | |
61 | \r | |
62 | //\r | |
63 | // Check gBS just in case ReportStatusCode is called before gBS is initialized.\r | |
64 | //\r | |
65 | if (gBS != NULL && gBS->LocateProtocol != NULL) {\r | |
66 | Status = gBS->LocateProtocol (&gEfiStatusCodeRuntimeProtocolGuid, NULL, (VOID**) &mReportStatusCodeLibStatusCodeProtocol);\r | |
67 | if (EFI_ERROR (Status)) {\r | |
68 | mReportStatusCodeLibStatusCodeProtocol = NULL;\r | |
69 | }\r | |
70 | }\r | |
71 | }\r | |
72 | \r | |
73 | /**\r | |
74 | Notification function of EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE.\r | |
75 | \r | |
76 | @param Event Event whose notification function is being invoked.\r | |
77 | @param Context Pointer to the notification function's context\r | |
78 | \r | |
79 | **/\r | |
80 | VOID\r | |
81 | EFIAPI\r | |
82 | ReportStatusCodeLibVirtualAddressChange (\r | |
83 | IN EFI_EVENT Event,\r | |
84 | IN VOID *Context\r | |
85 | )\r | |
86 | {\r | |
87 | if (mReportStatusCodeLibStatusCodeProtocol == NULL) {\r | |
88 | return;\r | |
89 | }\r | |
90 | EfiConvertPointer (0, (VOID **) &mReportStatusCodeLibStatusCodeProtocol);\r | |
91 | }\r | |
92 | \r | |
c05e7994 LG |
93 | /**\r |
94 | Notification function of EVT_SIGNAL_EXIT_BOOT_SERVICES.\r | |
95 | \r | |
96 | @param Event Event whose notification function is being invoked.\r | |
97 | @param Context Pointer to the notification function's context\r | |
98 | \r | |
99 | **/\r | |
100 | VOID\r | |
101 | EFIAPI\r | |
102 | ReportStatusCodeLibExitBootServices (\r | |
103 | IN EFI_EVENT Event,\r | |
104 | IN VOID *Context\r | |
105 | )\r | |
106 | {\r | |
107 | //\r | |
108 | // Locate the report status code service before enter runtime.\r | |
109 | // \r | |
110 | InternalGetReportStatusCode ();\r | |
111 | \r | |
112 | mHaveExitedBootServices = TRUE;\r | |
113 | }\r | |
114 | \r | |
4adf0008 | 115 | /**\r |
116 | The constructor function of Runtime DXE Report Status Code Lib.\r | |
117 | \r | |
118 | This function allocates memory for extended status code data, caches\r | |
119 | the report status code service, and registers events.\r | |
120 | \r | |
121 | @param ImageHandle The firmware allocated handle for the EFI image.\r | |
122 | @param SystemTable A pointer to the EFI System Table.\r | |
123 | \r | |
124 | @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.\r | |
125 | \r | |
126 | **/\r | |
127 | EFI_STATUS\r | |
128 | EFIAPI\r | |
129 | ReportStatusCodeLibConstructor (\r | |
130 | IN EFI_HANDLE ImageHandle,\r | |
131 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
132 | )\r | |
133 | {\r | |
134 | EFI_STATUS Status;\r | |
135 | \r | |
136 | //\r | |
137 | // Cache the report status code service\r | |
138 | // \r | |
139 | InternalGetReportStatusCode ();\r | |
140 | \r | |
141 | //\r | |
142 | // Register notify function for EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE\r | |
143 | // \r | |
144 | Status = gBS->CreateEventEx (\r | |
145 | EVT_NOTIFY_SIGNAL,\r | |
146 | TPL_NOTIFY,\r | |
147 | ReportStatusCodeLibVirtualAddressChange,\r | |
148 | NULL,\r | |
149 | &gEfiEventVirtualAddressChangeGuid,\r | |
150 | &mReportStatusCodeLibVirtualAddressChangeEvent\r | |
151 | );\r | |
152 | ASSERT_EFI_ERROR (Status);\r | |
153 | \r | |
c05e7994 LG |
154 | //\r |
155 | // Register notify function for EVT_SIGNAL_EXIT_BOOT_SERVICES\r | |
156 | // \r | |
157 | Status = gBS->CreateEventEx (\r | |
158 | EVT_NOTIFY_SIGNAL,\r | |
159 | TPL_NOTIFY,\r | |
160 | ReportStatusCodeLibExitBootServices,\r | |
161 | NULL,\r | |
162 | &gEfiEventExitBootServicesGuid,\r | |
163 | &mReportStatusCodeLibExitBootServicesEvent\r | |
164 | );\r | |
165 | ASSERT_EFI_ERROR (Status);\r | |
166 | \r | |
4adf0008 | 167 | return EFI_SUCCESS;\r |
168 | }\r | |
169 | \r | |
170 | /**\r | |
171 | The destructor function of Runtime DXE Report Status Code Lib.\r | |
172 | \r | |
173 | The destructor function frees memory allocated by constructor, and closes related events.\r | |
174 | It will ASSERT() if that related operation fails and it will always return EFI_SUCCESS. \r | |
175 | \r | |
176 | @param ImageHandle The firmware allocated handle for the EFI image.\r | |
177 | @param SystemTable A pointer to the EFI System Table.\r | |
178 | \r | |
179 | @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.\r | |
180 | \r | |
181 | **/\r | |
182 | EFI_STATUS\r | |
183 | EFIAPI\r | |
184 | ReportStatusCodeLibDestructor (\r | |
185 | IN EFI_HANDLE ImageHandle,\r | |
186 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
187 | )\r | |
188 | {\r | |
189 | EFI_STATUS Status;\r | |
190 | \r | |
191 | ASSERT (gBS != NULL);\r | |
192 | Status = gBS->CloseEvent (mReportStatusCodeLibVirtualAddressChangeEvent);\r | |
193 | ASSERT_EFI_ERROR (Status);\r | |
194 | \r | |
c05e7994 LG |
195 | Status = gBS->CloseEvent (mReportStatusCodeLibExitBootServicesEvent);\r |
196 | ASSERT_EFI_ERROR (Status);\r | |
197 | \r | |
4adf0008 | 198 | return EFI_SUCCESS;\r |
199 | }\r | |
200 | \r | |
201 | /**\r | |
202 | Internal worker function that reports a status code through the Report Status Code Protocol.\r | |
203 | \r | |
204 | If status code service is not cached, then this function checks if Report Status Code\r | |
205 | Protocol is available in system. If Report Status Code Protocol is not available, then\r | |
206 | EFI_UNSUPPORTED is returned. If Report Status Code Protocol is present, then it is\r | |
207 | cached in mReportStatusCodeLibStatusCodeProtocol. Finally this function reports status\r | |
208 | code through the Report Status Code Protocol.\r | |
209 | \r | |
210 | @param Type Status code type.\r | |
211 | @param Value Status code value.\r | |
212 | @param Instance Status code instance number.\r | |
213 | @param CallerId Pointer to a GUID that identifies the caller of this\r | |
214 | function. This is an optional parameter that may be\r | |
215 | NULL.\r | |
216 | @param Data Pointer to the extended data buffer. This is an\r | |
217 | optional parameter that may be NULL.\r | |
218 | \r | |
219 | @retval EFI_SUCCESS The status code was reported.\r | |
220 | @retval EFI_UNSUPPORTED Report Status Code Protocol is not available.\r | |
221 | @retval EFI_UNSUPPORTED Status code type is not supported.\r | |
222 | \r | |
223 | **/\r | |
224 | EFI_STATUS\r | |
225 | InternalReportStatusCode (\r | |
226 | IN EFI_STATUS_CODE_TYPE Type,\r | |
227 | IN EFI_STATUS_CODE_VALUE Value,\r | |
228 | IN UINT32 Instance,\r | |
229 | IN CONST EFI_GUID *CallerId OPTIONAL,\r | |
230 | IN EFI_STATUS_CODE_DATA *Data OPTIONAL\r | |
231 | )\r | |
232 | {\r | |
233 | if ((ReportProgressCodeEnabled() && ((Type) & EFI_STATUS_CODE_TYPE_MASK) == EFI_PROGRESS_CODE) ||\r | |
234 | (ReportErrorCodeEnabled() && ((Type) & EFI_STATUS_CODE_TYPE_MASK) == EFI_ERROR_CODE) ||\r | |
235 | (ReportDebugCodeEnabled() && ((Type) & EFI_STATUS_CODE_TYPE_MASK) == EFI_DEBUG_CODE)) {\r | |
236 | //\r | |
237 | // If mReportStatusCodeLibStatusCodeProtocol is NULL, then check if Report Status Code Protocol is available in system.\r | |
238 | //\r | |
239 | InternalGetReportStatusCode ();\r | |
240 | if (mReportStatusCodeLibStatusCodeProtocol == NULL) {\r | |
241 | return EFI_UNSUPPORTED;\r | |
242 | }\r | |
243 | \r | |
244 | //\r | |
245 | // A Report Status Code Protocol is present in system, so pass in all the parameters to the service.\r | |
246 | //\r | |
247 | return mReportStatusCodeLibStatusCodeProtocol->ReportStatusCode (Type, Value, Instance, (EFI_GUID *)CallerId, Data);\r | |
248 | }\r | |
249 | \r | |
250 | return EFI_UNSUPPORTED;\r | |
251 | }\r | |
252 | \r | |
30c8ee5c | 253 | \r |
254 | /**\r | |
255 | Converts a status code to an 8-bit POST code value.\r | |
256 | \r | |
257 | Converts the status code specified by CodeType and Value to an 8-bit POST code\r | |
258 | and returns the 8-bit POST code in PostCode. If CodeType is an\r | |
259 | EFI_PROGRESS_CODE or CodeType is an EFI_ERROR_CODE, then bits 0..4 of PostCode\r | |
260 | are set to bits 16..20 of Value, and bits 5..7 of PostCode are set to bits\r | |
261 | 24..26 of Value., and TRUE is returned. Otherwise, FALSE is returned.\r | |
262 | \r | |
263 | If PostCode is NULL, then ASSERT().\r | |
264 | \r | |
265 | @param CodeType The type of status code being converted.\r | |
266 | @param Value The status code value being converted.\r | |
267 | @param PostCode A pointer to the 8-bit POST code value to return.\r | |
268 | \r | |
269 | @retval TRUE The status code specified by CodeType and Value was converted\r | |
270 | to an 8-bit POST code and returned in PostCode.\r | |
271 | @retval FALSE The status code specified by CodeType and Value could not be\r | |
272 | converted to an 8-bit POST code value.\r | |
273 | \r | |
274 | **/\r | |
275 | BOOLEAN\r | |
276 | EFIAPI\r | |
277 | CodeTypeToPostCode (\r | |
278 | IN EFI_STATUS_CODE_TYPE CodeType,\r | |
279 | IN EFI_STATUS_CODE_VALUE Value,\r | |
280 | OUT UINT8 *PostCode\r | |
281 | )\r | |
282 | {\r | |
283 | //\r | |
284 | // If PostCode is NULL, then ASSERT()\r | |
285 | //\r | |
286 | ASSERT (PostCode != NULL);\r | |
287 | \r | |
288 | //\r | |
289 | // Convert Value to an 8 bit post code\r | |
290 | //\r | |
291 | if (((CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_PROGRESS_CODE) ||\r | |
292 | ((CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_ERROR_CODE) ) {\r | |
293 | *PostCode = (UINT8) ((((Value & EFI_STATUS_CODE_CLASS_MASK) >> 24) << 5) |\r | |
294 | (((Value & EFI_STATUS_CODE_SUBCLASS_MASK) >> 16) & 0x1f));\r | |
295 | return TRUE;\r | |
296 | }\r | |
297 | return FALSE;\r | |
298 | }\r | |
299 | \r | |
300 | \r | |
301 | /**\r | |
302 | Extracts ASSERT() information from a status code structure.\r | |
303 | \r | |
304 | Converts the status code specified by CodeType, Value, and Data to the ASSERT()\r | |
305 | arguments specified by Filename, Description, and LineNumber. If CodeType is\r | |
306 | an EFI_ERROR_CODE, and CodeType has a severity of EFI_ERROR_UNRECOVERED, and\r | |
307 | Value has an operation mask of EFI_SW_EC_ILLEGAL_SOFTWARE_STATE, extract\r | |
308 | Filename, Description, and LineNumber from the optional data area of the\r | |
309 | status code buffer specified by Data. The optional data area of Data contains\r | |
310 | a Null-terminated ASCII string for the FileName, followed by a Null-terminated\r | |
311 | ASCII string for the Description, followed by a 32-bit LineNumber. If the\r | |
312 | ASSERT() information could be extracted from Data, then return TRUE.\r | |
313 | Otherwise, FALSE is returned.\r | |
314 | \r | |
315 | If Data is NULL, then ASSERT().\r | |
316 | If Filename is NULL, then ASSERT().\r | |
317 | If Description is NULL, then ASSERT().\r | |
318 | If LineNumber is NULL, then ASSERT().\r | |
319 | \r | |
320 | @param CodeType The type of status code being converted.\r | |
321 | @param Value The status code value being converted.\r | |
322 | @param Data Pointer to status code data buffer.\r | |
323 | @param Filename Pointer to the source file name that generated the ASSERT().\r | |
324 | @param Description Pointer to the description of the ASSERT().\r | |
325 | @param LineNumber Pointer to source line number that generated the ASSERT().\r | |
326 | \r | |
327 | @retval TRUE The status code specified by CodeType, Value, and Data was\r | |
328 | converted ASSERT() arguments specified by Filename, Description,\r | |
329 | and LineNumber.\r | |
330 | @retval FALSE The status code specified by CodeType, Value, and Data could\r | |
331 | not be converted to ASSERT() arguments.\r | |
332 | \r | |
333 | **/\r | |
334 | BOOLEAN\r | |
335 | EFIAPI\r | |
336 | ReportStatusCodeExtractAssertInfo (\r | |
337 | IN EFI_STATUS_CODE_TYPE CodeType,\r | |
338 | IN EFI_STATUS_CODE_VALUE Value,\r | |
339 | IN CONST EFI_STATUS_CODE_DATA *Data,\r | |
340 | OUT CHAR8 **Filename,\r | |
341 | OUT CHAR8 **Description,\r | |
342 | OUT UINT32 *LineNumber\r | |
343 | )\r | |
344 | {\r | |
345 | EFI_DEBUG_ASSERT_DATA *AssertData;\r | |
346 | \r | |
347 | ASSERT (Data != NULL);\r | |
348 | ASSERT (Filename != NULL);\r | |
349 | ASSERT (Description != NULL);\r | |
350 | ASSERT (LineNumber != NULL);\r | |
351 | \r | |
352 | if (((CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_ERROR_CODE) &&\r | |
353 | ((CodeType & EFI_STATUS_CODE_SEVERITY_MASK) == EFI_ERROR_UNRECOVERED) &&\r | |
354 | ((Value & EFI_STATUS_CODE_OPERATION_MASK) == EFI_SW_EC_ILLEGAL_SOFTWARE_STATE)) {\r | |
355 | AssertData = (EFI_DEBUG_ASSERT_DATA *)(Data + 1);\r | |
356 | *Filename = (CHAR8 *)(AssertData + 1);\r | |
357 | *Description = *Filename + AsciiStrLen (*Filename) + 1;\r | |
358 | *LineNumber = AssertData->LineNumber;\r | |
359 | return TRUE;\r | |
360 | }\r | |
361 | return FALSE;\r | |
362 | }\r | |
363 | \r | |
364 | \r | |
365 | /**\r | |
366 | Extracts DEBUG() information from a status code structure.\r | |
367 | \r | |
368 | Converts the status code specified by Data to the DEBUG() arguments specified\r | |
369 | by ErrorLevel, Marker, and Format. If type GUID in Data is\r | |
370 | EFI_STATUS_CODE_DATA_TYPE_DEBUG_GUID, then extract ErrorLevel, Marker, and\r | |
371 | Format from the optional data area of the status code buffer specified by Data.\r | |
372 | The optional data area of Data contains a 32-bit ErrorLevel followed by Marker\r | |
373 | which is 12 UINTN parameters, followed by a Null-terminated ASCII string for\r | |
374 | the Format. If the DEBUG() information could be extracted from Data, then\r | |
375 | return TRUE. Otherwise, FALSE is returned.\r | |
376 | \r | |
377 | If Data is NULL, then ASSERT().\r | |
378 | If ErrorLevel is NULL, then ASSERT().\r | |
379 | If Marker is NULL, then ASSERT().\r | |
380 | If Format is NULL, then ASSERT().\r | |
381 | \r | |
382 | @param Data Pointer to status code data buffer.\r | |
383 | @param ErrorLevel Pointer to error level mask for a debug message.\r | |
384 | @param Marker Pointer to the variable argument list associated with Format.\r | |
385 | @param Format Pointer to a Null-terminated ASCII format string of a\r | |
386 | debug message.\r | |
387 | \r | |
388 | @retval TRUE The status code specified by Data was converted DEBUG() arguments\r | |
389 | specified by ErrorLevel, Marker, and Format.\r | |
390 | @retval FALSE The status code specified by Data could not be converted to\r | |
391 | DEBUG() arguments.\r | |
392 | \r | |
393 | **/\r | |
394 | BOOLEAN\r | |
395 | EFIAPI\r | |
396 | ReportStatusCodeExtractDebugInfo (\r | |
397 | IN CONST EFI_STATUS_CODE_DATA *Data,\r | |
398 | OUT UINT32 *ErrorLevel,\r | |
399 | OUT BASE_LIST *Marker,\r | |
400 | OUT CHAR8 **Format\r | |
401 | )\r | |
402 | {\r | |
403 | EFI_DEBUG_INFO *DebugInfo;\r | |
404 | \r | |
405 | ASSERT (Data != NULL);\r | |
406 | ASSERT (ErrorLevel != NULL);\r | |
407 | ASSERT (Marker != NULL);\r | |
408 | ASSERT (Format != NULL);\r | |
409 | \r | |
410 | //\r | |
411 | // If the GUID type is not EFI_STATUS_CODE_DATA_TYPE_DEBUG_GUID then return FALSE\r | |
412 | //\r | |
413 | if (!CompareGuid (&Data->Type, &gEfiStatusCodeDataTypeDebugGuid)) {\r | |
414 | return FALSE;\r | |
415 | }\r | |
416 | \r | |
417 | //\r | |
418 | // Retrieve the debug information from the status code record\r | |
419 | //\r | |
420 | DebugInfo = (EFI_DEBUG_INFO *)(Data + 1);\r | |
421 | \r | |
422 | *ErrorLevel = DebugInfo->ErrorLevel;\r | |
423 | \r | |
424 | //\r | |
425 | // The first 12 * sizeof (UINT64) bytes following EFI_DEBUG_INFO are for variable arguments\r | |
426 | // of format in DEBUG string. Its address is returned in Marker and has to be 64-bit aligned.\r | |
427 | // It must be noticed that EFI_DEBUG_INFO follows EFI_STATUS_CODE_DATA, whose size is\r | |
428 | // 20 bytes. The size of EFI_DEBUG_INFO is 4 bytes, so we can ensure that Marker\r | |
429 | // returned is 64-bit aligned.\r | |
430 | // 64-bit aligned is a must, otherwise retrieving 64-bit parameter from BASE_LIST will\r | |
431 | // cause unalignment exception.\r | |
432 | //\r | |
433 | *Marker = (BASE_LIST) (DebugInfo + 1);\r | |
434 | *Format = (CHAR8 *)(((UINT64 *)*Marker) + 12);\r | |
435 | \r | |
436 | return TRUE;\r | |
437 | }\r | |
438 | \r | |
439 | \r | |
440 | /**\r | |
441 | Reports a status code.\r | |
442 | \r | |
443 | Reports the status code specified by the parameters Type and Value. Status\r | |
444 | code also require an instance, caller ID, and extended data. This function\r | |
445 | passed in a zero instance, NULL extended data, and a caller ID of\r | |
446 | gEfiCallerIdGuid, which is the GUID for the module.\r | |
447 | \r | |
448 | ReportStatusCode()must actively prevent recusrsion. If ReportStatusCode()\r | |
449 | is called while processing another any other Report Status Code Library function,\r | |
450 | then ReportStatusCode() must return immediately.\r | |
451 | \r | |
452 | @param Type Status code type.\r | |
453 | @param Value Status code value.\r | |
454 | \r | |
455 | @retval EFI_SUCCESS The status code was reported.\r | |
456 | @retval EFI_DEVICE_ERROR There status code could not be reported due to a\r | |
457 | device error.\r | |
458 | @retval EFI_UNSUPPORTED Report status code is not supported\r | |
459 | \r | |
460 | **/\r | |
461 | EFI_STATUS\r | |
462 | EFIAPI\r | |
463 | ReportStatusCode (\r | |
464 | IN EFI_STATUS_CODE_TYPE Type,\r | |
465 | IN EFI_STATUS_CODE_VALUE Value\r | |
466 | )\r | |
467 | {\r | |
468 | return InternalReportStatusCode (Type, Value, 0, &gEfiCallerIdGuid, NULL);\r | |
469 | }\r | |
470 | \r | |
471 | \r | |
472 | /**\r | |
473 | Reports a status code with a Device Path Protocol as the extended data.\r | |
474 | \r | |
475 | Allocates and fills in the extended data section of a status code with the\r | |
476 | Device Path Protocol specified by DevicePath. This function is responsible\r | |
477 | for allocating a buffer large enough for the standard header and the device\r | |
478 | path. The standard header is filled in with a GUID of\r | |
479 | gEfiStatusCodeSpecificDataGuid. The status code is reported with a zero\r | |
480 | instance and a caller ID of gEfiCallerIdGuid.\r | |
481 | \r | |
482 | ReportStatusCodeWithDevicePath()must actively prevent recursion. If\r | |
483 | ReportStatusCodeWithDevicePath() is called while processing another any other\r | |
484 | Report Status Code Library function, then ReportStatusCodeWithDevicePath()\r | |
485 | must return EFI_DEVICE_ERROR immediately.\r | |
486 | \r | |
487 | If DevicePath is NULL, then ASSERT().\r | |
488 | \r | |
489 | @param Type Status code type.\r | |
490 | @param Value Status code value.\r | |
491 | @param DevicePath Pointer to the Device Path Protocol to be reported.\r | |
492 | \r | |
493 | @retval EFI_SUCCESS The status code was reported with the extended\r | |
494 | data specified by DevicePath.\r | |
495 | @retval EFI_OUT_OF_RESOURCES There were not enough resources to allocate the\r | |
496 | extended data section.\r | |
497 | @retval EFI_UNSUPPORTED Report status code is not supported\r | |
498 | \r | |
499 | **/\r | |
500 | EFI_STATUS\r | |
501 | EFIAPI\r | |
502 | ReportStatusCodeWithDevicePath (\r | |
503 | IN EFI_STATUS_CODE_TYPE Type,\r | |
504 | IN EFI_STATUS_CODE_VALUE Value,\r | |
505 | IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath\r | |
506 | )\r | |
507 | {\r | |
508 | ASSERT (DevicePath != NULL);\r | |
509 | return ReportStatusCodeWithExtendedData (\r | |
510 | Type,\r | |
511 | Value,\r | |
512 | (VOID *)DevicePath,\r | |
513 | GetDevicePathSize (DevicePath)\r | |
514 | );\r | |
515 | }\r | |
516 | \r | |
517 | \r | |
518 | /**\r | |
519 | Reports a status code with an extended data buffer.\r | |
520 | \r | |
521 | Allocates and fills in the extended data section of a status code with the\r | |
522 | extended data specified by ExtendedData and ExtendedDataSize. ExtendedData\r | |
523 | is assumed to be one of the data structures specified in Related Definitions.\r | |
524 | These data structure do not have the standard header, so this function is\r | |
525 | responsible for allocating a buffer large enough for the standard header and\r | |
526 | the extended data passed into this function. The standard header is filled\r | |
527 | in with a GUID of gEfiStatusCodeSpecificDataGuid. The status code is reported\r | |
528 | with a zero instance and a caller ID of gEfiCallerIdGuid.\r | |
529 | \r | |
530 | ReportStatusCodeWithExtendedData()must actively prevent recursion. If\r | |
531 | ReportStatusCodeWithExtendedData() is called while processing another any other\r | |
532 | Report Status Code Library function, then ReportStatusCodeWithExtendedData()\r | |
533 | must return EFI_DEVICE_ERROR immediately.\r | |
534 | \r | |
535 | If ExtendedData is NULL, then ASSERT().\r | |
536 | If ExtendedDataSize is 0, then ASSERT().\r | |
537 | \r | |
538 | @param Type Status code type.\r | |
539 | @param Value Status code value.\r | |
540 | @param ExtendedData Pointer to the extended data buffer to be reported.\r | |
541 | @param ExtendedDataSize The size, in bytes, of the extended data buffer to\r | |
542 | be reported.\r | |
543 | \r | |
544 | @retval EFI_SUCCESS The status code was reported with the extended\r | |
545 | data specified by ExtendedData and ExtendedDataSize.\r | |
546 | @retval EFI_OUT_OF_RESOURCES There were not enough resources to allocate the\r | |
547 | extended data section.\r | |
548 | @retval EFI_UNSUPPORTED Report status code is not supported\r | |
549 | \r | |
550 | **/\r | |
551 | EFI_STATUS\r | |
552 | EFIAPI\r | |
553 | ReportStatusCodeWithExtendedData (\r | |
554 | IN EFI_STATUS_CODE_TYPE Type,\r | |
555 | IN EFI_STATUS_CODE_VALUE Value,\r | |
556 | IN CONST VOID *ExtendedData,\r | |
557 | IN UINTN ExtendedDataSize\r | |
558 | )\r | |
559 | {\r | |
560 | ASSERT (ExtendedData != NULL);\r | |
561 | ASSERT (ExtendedDataSize != 0);\r | |
562 | return ReportStatusCodeEx (\r | |
563 | Type,\r | |
564 | Value,\r | |
565 | 0,\r | |
566 | NULL,\r | |
567 | NULL,\r | |
568 | ExtendedData,\r | |
569 | ExtendedDataSize\r | |
570 | );\r | |
571 | }\r | |
572 | \r | |
573 | \r | |
574 | /**\r | |
575 | Reports a status code with full parameters.\r | |
576 | \r | |
577 | The function reports a status code. If ExtendedData is NULL and ExtendedDataSize\r | |
578 | is 0, then an extended data buffer is not reported. If ExtendedData is not\r | |
579 | NULL and ExtendedDataSize is not 0, then an extended data buffer is allocated.\r | |
580 | ExtendedData is assumed not have the standard status code header, so this function\r | |
581 | is responsible for allocating a buffer large enough for the standard header and\r | |
582 | the extended data passed into this function. The standard header is filled in\r | |
583 | with a GUID specified by ExtendedDataGuid. If ExtendedDataGuid is NULL, then a\r | |
584 | GUID of gEfiStatusCodeSpecificDataGuid is used. The status code is reported with\r | |
585 | an instance specified by Instance and a caller ID specified by CallerId. If\r | |
586 | CallerId is NULL, then a caller ID of gEfiCallerIdGuid is used.\r | |
587 | \r | |
588 | ReportStatusCodeEx()must actively prevent recursion. If\r | |
589 | ReportStatusCodeEx() is called while processing another any\r | |
590 | other Report Status Code Library function, then\r | |
591 | ReportStatusCodeEx() must return EFI_DEVICE_ERROR immediately.\r | |
592 | \r | |
593 | If ExtendedData is NULL and ExtendedDataSize is not zero, then ASSERT().\r | |
594 | If ExtendedData is not NULL and ExtendedDataSize is zero, then ASSERT().\r | |
595 | \r | |
596 | @param Type Status code type.\r | |
597 | @param Value Status code value.\r | |
598 | @param Instance Status code instance number.\r | |
599 | @param CallerId Pointer to a GUID that identifies the caller of this\r | |
600 | function. If this parameter is NULL, then a caller\r | |
601 | ID of gEfiCallerIdGuid is used.\r | |
602 | @param ExtendedDataGuid Pointer to the GUID for the extended data buffer.\r | |
603 | If this parameter is NULL, then a the status code\r | |
604 | standard header is filled in with\r | |
605 | gEfiStatusCodeSpecificDataGuid.\r | |
606 | @param ExtendedData Pointer to the extended data buffer. This is an\r | |
607 | optional parameter that may be NULL.\r | |
608 | @param ExtendedDataSize The size, in bytes, of the extended data buffer.\r | |
609 | \r | |
610 | @retval EFI_SUCCESS The status code was reported.\r | |
611 | @retval EFI_OUT_OF_RESOURCES There were not enough resources to allocate\r | |
612 | the extended data section if it was specified.\r | |
613 | @retval EFI_UNSUPPORTED Report status code is not supported\r | |
614 | \r | |
615 | **/\r | |
616 | EFI_STATUS\r | |
617 | EFIAPI\r | |
618 | ReportStatusCodeEx (\r | |
619 | IN EFI_STATUS_CODE_TYPE Type,\r | |
620 | IN EFI_STATUS_CODE_VALUE Value,\r | |
621 | IN UINT32 Instance,\r | |
622 | IN CONST EFI_GUID *CallerId OPTIONAL,\r | |
623 | IN CONST EFI_GUID *ExtendedDataGuid OPTIONAL,\r | |
624 | IN CONST VOID *ExtendedData OPTIONAL,\r | |
625 | IN UINTN ExtendedDataSize\r | |
626 | )\r | |
627 | {\r | |
628 | EFI_STATUS Status;\r | |
4adf0008 | 629 | EFI_STATUS_CODE_DATA *StatusCodeData;\r |
e5c1acc5 | 630 | UINT64 StatusCodeBuffer[(MAX_EXTENDED_DATA_SIZE / sizeof (UINT64)) + 1];\r |
30c8ee5c | 631 | \r |
632 | ASSERT (!((ExtendedData == NULL) && (ExtendedDataSize != 0)));\r | |
633 | ASSERT (!((ExtendedData != NULL) && (ExtendedDataSize == 0)));\r | |
634 | \r | |
c05e7994 | 635 | if (mHaveExitedBootServices) {\r |
e5c1acc5 | 636 | if (sizeof (EFI_STATUS_CODE_DATA) + ExtendedDataSize > MAX_EXTENDED_DATA_SIZE) {\r |
4adf0008 | 637 | return EFI_OUT_OF_RESOURCES;\r |
638 | }\r | |
c9325700 | 639 | StatusCodeData = (EFI_STATUS_CODE_DATA *) StatusCodeBuffer;\r |
4adf0008 | 640 | } else {\r |
641 | if (gBS == NULL || gBS->AllocatePool == NULL || gBS->FreePool == NULL) {\r | |
642 | return EFI_UNSUPPORTED;\r | |
643 | }\r | |
644 | \r | |
645 | //\r | |
646 | // Allocate space for the Status Code Header and its buffer\r | |
647 | //\r | |
648 | StatusCodeData = NULL;\r | |
649 | gBS->AllocatePool (EfiBootServicesData, sizeof (EFI_STATUS_CODE_DATA) + ExtendedDataSize, (VOID **)&StatusCodeData);\r | |
650 | if (StatusCodeData == NULL) {\r | |
651 | return EFI_OUT_OF_RESOURCES;\r | |
652 | }\r | |
30c8ee5c | 653 | }\r |
654 | \r | |
655 | //\r | |
656 | // Fill in the extended data header\r | |
657 | //\r | |
c9325700 ED |
658 | StatusCodeData->HeaderSize = (UINT16) sizeof (EFI_STATUS_CODE_DATA);\r |
659 | StatusCodeData->Size = (UINT16) ExtendedDataSize;\r | |
30c8ee5c | 660 | if (ExtendedDataGuid == NULL) {\r |
661 | ExtendedDataGuid = &gEfiStatusCodeSpecificDataGuid;\r | |
662 | }\r | |
4adf0008 | 663 | CopyGuid (&StatusCodeData->Type, ExtendedDataGuid);\r |
30c8ee5c | 664 | \r |
665 | //\r | |
666 | // Fill in the extended data buffer\r | |
667 | //\r | |
668 | if (ExtendedData != NULL) {\r | |
4adf0008 | 669 | CopyMem (StatusCodeData + 1, ExtendedData, ExtendedDataSize);\r |
30c8ee5c | 670 | }\r |
671 | \r | |
672 | //\r | |
673 | // Report the status code\r | |
674 | //\r | |
675 | if (CallerId == NULL) {\r | |
676 | CallerId = &gEfiCallerIdGuid;\r | |
677 | }\r | |
4adf0008 | 678 | Status = InternalReportStatusCode (Type, Value, Instance, CallerId, StatusCodeData);\r |
679 | \r | |
680 | //\r | |
681 | // Free the allocated buffer\r | |
682 | //\r | |
c05e7994 | 683 | if (!mHaveExitedBootServices) {\r |
4adf0008 | 684 | gBS->FreePool (StatusCodeData);\r |
685 | }\r | |
30c8ee5c | 686 | \r |
687 | return Status;\r | |
688 | }\r | |
689 | \r | |
690 | \r | |
691 | /**\r | |
692 | Returns TRUE if status codes of type EFI_PROGRESS_CODE are enabled\r | |
693 | \r | |
694 | This function returns TRUE if the REPORT_STATUS_CODE_PROPERTY_PROGRESS_CODE_ENABLED\r | |
695 | bit of PcdReportStatusCodeProperyMask is set. Otherwise FALSE is returned.\r | |
696 | \r | |
697 | @retval TRUE The REPORT_STATUS_CODE_PROPERTY_PROGRESS_CODE_ENABLED bit of\r | |
698 | PcdReportStatusCodeProperyMask is set.\r | |
699 | @retval FALSE The REPORT_STATUS_CODE_PROPERTY_PROGRESS_CODE_ENABLED bit of\r | |
700 | PcdReportStatusCodeProperyMask is clear.\r | |
701 | \r | |
702 | **/\r | |
703 | BOOLEAN\r | |
704 | EFIAPI\r | |
705 | ReportProgressCodeEnabled (\r | |
706 | VOID\r | |
707 | )\r | |
708 | {\r | |
709 | return (BOOLEAN) ((PcdGet8 (PcdReportStatusCodePropertyMask) & REPORT_STATUS_CODE_PROPERTY_PROGRESS_CODE_ENABLED) != 0);\r | |
710 | }\r | |
711 | \r | |
712 | \r | |
713 | /**\r | |
714 | Returns TRUE if status codes of type EFI_ERROR_CODE are enabled\r | |
715 | \r | |
716 | This function returns TRUE if the REPORT_STATUS_CODE_PROPERTY_ERROR_CODE_ENABLED\r | |
717 | bit of PcdReportStatusCodeProperyMask is set. Otherwise FALSE is returned.\r | |
718 | \r | |
719 | @retval TRUE The REPORT_STATUS_CODE_PROPERTY_ERROR_CODE_ENABLED bit of\r | |
720 | PcdReportStatusCodeProperyMask is set.\r | |
721 | @retval FALSE The REPORT_STATUS_CODE_PROPERTY_ERROR_CODE_ENABLED bit of\r | |
722 | PcdReportStatusCodeProperyMask is clear.\r | |
723 | \r | |
724 | **/\r | |
725 | BOOLEAN\r | |
726 | EFIAPI\r | |
727 | ReportErrorCodeEnabled (\r | |
728 | VOID\r | |
729 | )\r | |
730 | {\r | |
731 | return (BOOLEAN) ((PcdGet8 (PcdReportStatusCodePropertyMask) & REPORT_STATUS_CODE_PROPERTY_ERROR_CODE_ENABLED) != 0);\r | |
732 | }\r | |
733 | \r | |
734 | \r | |
735 | /**\r | |
736 | Returns TRUE if status codes of type EFI_DEBUG_CODE are enabled\r | |
737 | \r | |
738 | This function returns TRUE if the REPORT_STATUS_CODE_PROPERTY_DEBUG_CODE_ENABLED\r | |
739 | bit of PcdReportStatusCodeProperyMask is set. Otherwise FALSE is returned.\r | |
740 | \r | |
741 | @retval TRUE The REPORT_STATUS_CODE_PROPERTY_DEBUG_CODE_ENABLED bit of\r | |
742 | PcdReportStatusCodeProperyMask is set.\r | |
743 | @retval FALSE The REPORT_STATUS_CODE_PROPERTY_DEBUG_CODE_ENABLED bit of\r | |
744 | PcdReportStatusCodeProperyMask is clear.\r | |
745 | \r | |
746 | **/\r | |
747 | BOOLEAN\r | |
748 | EFIAPI\r | |
749 | ReportDebugCodeEnabled (\r | |
750 | VOID\r | |
751 | )\r | |
752 | {\r | |
753 | return (BOOLEAN) ((PcdGet8 (PcdReportStatusCodePropertyMask) & REPORT_STATUS_CODE_PROPERTY_DEBUG_CODE_ENABLED) != 0);\r | |
754 | }\r |