/** @file\r
Report Status Code Library for DXE Phase.\r
\r
- Copyright (c) 2006 - 2007, Intel Corporation<BR>\r
- All rights reserved. This program and the accompanying materials\r
+ Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r
+ This program and the accompanying materials\r
are licensed and made available under the terms and conditions of the BSD License\r
which accompanies this distribution. The full text of the license may be found at\r
http://opensource.org/licenses/bsd-license.php\r
\r
**/\r
\r
-#include "ReportStatusCodeLibInternal.h"\r
- \r
+#include <FrameworkDxe.h>\r
+\r
+#include <Library/ReportStatusCodeLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <Library/BaseLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+#include <Library/PcdLib.h>\r
+#include <Library/UefiRuntimeServicesTableLib.h>\r
+#include <Library/DevicePathLib.h>\r
+\r
+#include <Guid/StatusCodeDataTypeId.h>\r
+#include <Guid/StatusCodeDataTypeDebug.h>\r
+#include <Protocol/StatusCode.h>\r
+\r
+//\r
+// Define the maximum extended data size that is supported when a status code is\r
+// reported at TPL_HIGH_LEVEL.\r
+//\r
+#define MAX_EXTENDED_DATA_SIZE 0x200\r
+\r
EFI_REPORT_STATUS_CODE mReportStatusCode = NULL;\r
\r
/**\r
- Internal worker function that reports a status code through the Status Code Protocol\r
+ Locate the report status code service.\r
\r
- This function checks to see if a Status Code Protocol is present in the handle\r
- database. If a Status Code Protocol is not present, then EFI_UNSUPPORTED is\r
- returned. If a Status Code Protocol is present, then it is cached in gStatusCode,\r
- and the ReportStatusCode() service of the Status Code Protocol is called passing in\r
- Type, Value, Instance, CallerId, and Data. The result of this call is returned.\r
+ @return Function pointer to the report status code service.\r
+ NULL is returned if no status code service is available.\r
+\r
+**/\r
+EFI_REPORT_STATUS_CODE\r
+InternalGetReportStatusCode (\r
+ VOID\r
+ )\r
+{\r
+ EFI_STATUS_CODE_PROTOCOL *StatusCodeProtocol;\r
+ EFI_STATUS Status;\r
+\r
+ if (gRT != NULL && gRT->Hdr.Revision < 0x20000) {\r
+ return ((FRAMEWORK_EFI_RUNTIME_SERVICES*)gRT)->ReportStatusCode;\r
+ } else if (gBS != NULL && gBS->LocateProtocol != NULL) {\r
+ Status = gBS->LocateProtocol (&gEfiStatusCodeRuntimeProtocolGuid, NULL, (VOID**)&StatusCodeProtocol);\r
+ if (!EFI_ERROR (Status) && StatusCodeProtocol != NULL) {\r
+ return StatusCodeProtocol->ReportStatusCode;\r
+ }\r
+ }\r
+\r
+ return NULL;\r
+}\r
+\r
+/**\r
+ Internal worker function that reports a status code through the status code service.\r
+\r
+ If status code service is not cached, then this function checks if status code service is\r
+ available in system. If status code service is not available, then EFI_UNSUPPORTED is\r
+ returned. If status code service is present, then it is cached in mReportStatusCode.\r
+ Finally this function reports status code through the status code service.\r
\r
@param Type Status code type.\r
@param Value Status code value.\r
@param Data Pointer to the extended data buffer. This is an\r
optional parameter that may be NULL.\r
\r
- @retval EFI_SUCCESS The status code was reported.\r
- @retval EFI_OUT_OF_RESOURCES There were not enough resources to report the status code.\r
- @retval EFI_UNSUPPORTED Status Code Protocol is not available.\r
+ @retval EFI_SUCCESS The status code was reported.\r
+ @retval EFI_UNSUPPORTED Status code service is not available.\r
+ @retval EFI_UNSUPPORTED Status code type is not supported.\r
\r
**/\r
EFI_STATUS\r
IN EFI_STATUS_CODE_DATA *Data OPTIONAL\r
)\r
{\r
- //\r
- // If gStatusCode is NULL, then see if a Status Code Protocol instance is present\r
- // in the handle database.\r
- //\r
- if (mReportStatusCode == NULL) {\r
- mReportStatusCode = InternalGetReportStatusCode ();\r
+ if ((ReportProgressCodeEnabled() && ((Type) & EFI_STATUS_CODE_TYPE_MASK) == EFI_PROGRESS_CODE) ||\r
+ (ReportErrorCodeEnabled() && ((Type) & EFI_STATUS_CODE_TYPE_MASK) == EFI_ERROR_CODE) ||\r
+ (ReportDebugCodeEnabled() && ((Type) & EFI_STATUS_CODE_TYPE_MASK) == EFI_DEBUG_CODE)) {\r
+ //\r
+ // If mReportStatusCode is NULL, then check if status code service is available in system.\r
+ //\r
if (mReportStatusCode == NULL) {\r
- return EFI_UNSUPPORTED;\r
+ mReportStatusCode = InternalGetReportStatusCode ();\r
+ if (mReportStatusCode == NULL) {\r
+ return EFI_UNSUPPORTED;\r
+ }\r
}\r
+ \r
+ //\r
+ // A status code service is present in system, so pass in all the parameters to the service.\r
+ //\r
+ return (*mReportStatusCode) (Type, Value, Instance, (EFI_GUID *)CallerId, Data);\r
}\r
-\r
- //\r
- // A Status Code Protocol is present in the handle database, so pass in all the\r
- // parameters to the ReportStatusCode() service of the Status Code Protocol\r
- //\r
- return (*mReportStatusCode) (Type, Value, Instance, (EFI_GUID *)CallerId, Data);\r
-}\r
-\r
-\r
-/**\r
- Computes and returns the size, in bytes, of a device path.\r
-\r
- @param DevicePath A pointer to a device path.\r
-\r
- @return The size, in bytes, of DevicePath.\r
-\r
-**/\r
-UINTN\r
-InternalReportStatusCodeDevicePathSize (\r
- IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath\r
- )\r
-{\r
- CONST EFI_DEVICE_PATH_PROTOCOL *Start;\r
-\r
- //\r
- // Search for the end of the device path structure\r
- //\r
- Start = DevicePath;\r
- while (!EfiIsDevicePathEnd (DevicePath)) {\r
- DevicePath = EfiNextDevicePathNode (DevicePath);\r
- }\r
-\r
- //\r
- // Subtract the start node from the end node and add in the size of the end node\r
- //\r
- return ((UINTN) DevicePath - (UINTN) Start) + DevicePathNodeLength (DevicePath);\r
+ \r
+ return EFI_UNSUPPORTED;\r
}\r
\r
\r
ReportStatusCodeExtractDebugInfo (\r
IN CONST EFI_STATUS_CODE_DATA *Data,\r
OUT UINT32 *ErrorLevel,\r
- OUT VA_LIST *Marker,\r
+ OUT BASE_LIST *Marker,\r
OUT CHAR8 **Format\r
)\r
{\r
*ErrorLevel = DebugInfo->ErrorLevel;\r
\r
//\r
- // The first 12 * UINTN bytes of the string are really an\r
- // argument stack to support varargs on the Format string.\r
+ // The first 12 * sizeof (UINT64) bytes following EFI_DEBUG_INFO are for variable arguments\r
+ // of format in DEBUG string. Its address is returned in Marker and has to be 64-bit aligned.\r
+ // It must be noticed that EFI_DEBUG_INFO follows EFI_STATUS_CODE_DATA, whose size is\r
+ // 20 bytes. The size of EFI_DEBUG_INFO is 4 bytes, so we can ensure that Marker\r
+ // returned is 64-bit aligned.\r
+ // 64-bit aligned is a must, otherwise retrieving 64-bit parameter from BASE_LIST will\r
+ // cause unalignment exception.\r
//\r
- *Marker = (VA_LIST) (DebugInfo + 1);\r
+ *Marker = (BASE_LIST) (DebugInfo + 1);\r
*Format = (CHAR8 *)(((UINT64 *)*Marker) + 12);\r
\r
return TRUE;\r
Type,\r
Value,\r
(VOID *)DevicePath,\r
- InternalReportStatusCodeDevicePathSize (DevicePath)\r
+ GetDevicePathSize (DevicePath)\r
);\r
}\r
\r
is responsible for allocating a buffer large enough for the standard header and\r
the extended data passed into this function. The standard header is filled in\r
with a GUID specified by ExtendedDataGuid. If ExtendedDataGuid is NULL, then a\r
- GUID of gEfiStatusCodeSpecificDatauid is used. The status code is reported with\r
+ GUID of gEfiStatusCodeSpecificDataGuid is used. The status code is reported with\r
an instance specified by Instance and a caller ID specified by CallerId. If\r
CallerId is NULL, then a caller ID of gEfiCallerIdGuid is used.\r
\r
IN UINTN ExtendedDataSize\r
)\r
{\r
- EFI_STATUS Status;\r
-\r
- Status = InternalReportStatusCodeEx (\r
- Type,\r
- Value,\r
- Instance,\r
- CallerId,\r
- ExtendedDataGuid,\r
- ExtendedData,\r
- ExtendedDataSize\r
- );\r
+ EFI_STATUS Status;\r
+ EFI_STATUS_CODE_DATA *StatusCodeData;\r
+ EFI_TPL Tpl;\r
+ UINT64 Buffer[(MAX_EXTENDED_DATA_SIZE / sizeof (UINT64)) + 1];\r
+\r
+ ASSERT (!((ExtendedData == NULL) && (ExtendedDataSize != 0)));\r
+ ASSERT (!((ExtendedData != NULL) && (ExtendedDataSize == 0)));\r
+\r
+ if (gBS == NULL || gBS->AllocatePool == NULL || gBS->FreePool == NULL) {\r
+ return EFI_UNSUPPORTED;\r
+ }\r
+\r
+ //\r
+ // Retrieve the current TPL\r
+ //\r
+ Tpl = gBS->RaiseTPL (TPL_HIGH_LEVEL);\r
+ gBS->RestoreTPL (Tpl);\r
+ \r
+ StatusCodeData = NULL;\r
+ if (Tpl <= TPL_NOTIFY) {\r
+ //\r
+ // Allocate space for the Status Code Header and its buffer\r
+ //\r
+ gBS->AllocatePool (EfiBootServicesData, sizeof (EFI_STATUS_CODE_DATA) + ExtendedDataSize, (VOID **)&StatusCodeData);\r
+ }\r
+\r
+ if (StatusCodeData == NULL) {\r
+ //\r
+ // If a buffer could not be allocated, then see if the local variable Buffer can be used\r
+ //\r
+ if (ExtendedDataSize > (MAX_EXTENDED_DATA_SIZE - sizeof (EFI_STATUS_CODE_DATA))) {\r
+ //\r
+ // The local variable Buffer not large enough to hold the extended data associated\r
+ // with the status code being reported.\r
+ //\r
+ DEBUG ((EFI_D_ERROR, "Status code extended data is too large to be reported!\n"));\r
+ return EFI_OUT_OF_RESOURCES;\r
+ }\r
+ StatusCodeData = (EFI_STATUS_CODE_DATA *)Buffer;\r
+ }\r
+\r
+ //\r
+ // Fill in the extended data header\r
+ //\r
+ StatusCodeData->HeaderSize = (UINT16) sizeof (EFI_STATUS_CODE_DATA);\r
+ StatusCodeData->Size = (UINT16)ExtendedDataSize;\r
+ if (ExtendedDataGuid == NULL) {\r
+ ExtendedDataGuid = &gEfiStatusCodeSpecificDataGuid;\r
+ }\r
+ CopyGuid (&StatusCodeData->Type, ExtendedDataGuid);\r
+\r
+ //\r
+ // Fill in the extended data buffer\r
+ //\r
+ if (ExtendedData != NULL) {\r
+ CopyMem (StatusCodeData + 1, ExtendedData, ExtendedDataSize);\r
+ }\r
+\r
+ //\r
+ // Report the status code\r
+ //\r
+ if (CallerId == NULL) {\r
+ CallerId = &gEfiCallerIdGuid;\r
+ }\r
+ Status = InternalReportStatusCode (Type, Value, Instance, CallerId, StatusCodeData);\r
+\r
+ //\r
+ // Free the allocated buffer\r
+ //\r
+ if (StatusCodeData != (EFI_STATUS_CODE_DATA *)Buffer) {\r
+ gBS->FreePool (StatusCodeData);\r
+ }\r
\r
return Status;\r
}\r
VOID\r
)\r
{\r
- return (BOOLEAN) ((PcdGet8(PcdReportStatusCodePropertyMask) & REPORT_STATUS_CODE_PROPERTY_PROGRESS_CODE_ENABLED) != 0);\r
+ return (BOOLEAN) ((PcdGet8 (PcdReportStatusCodePropertyMask) & REPORT_STATUS_CODE_PROPERTY_PROGRESS_CODE_ENABLED) != 0);\r
}\r
\r
\r
VOID\r
)\r
{\r
- return (BOOLEAN) ((PcdGet8(PcdReportStatusCodePropertyMask) & REPORT_STATUS_CODE_PROPERTY_ERROR_CODE_ENABLED) != 0);\r
+ return (BOOLEAN) ((PcdGet8 (PcdReportStatusCodePropertyMask) & REPORT_STATUS_CODE_PROPERTY_ERROR_CODE_ENABLED) != 0);\r
}\r
\r
\r
VOID\r
)\r
{\r
- return (BOOLEAN) ((PcdGet8(PcdReportStatusCodePropertyMask) & REPORT_STATUS_CODE_PROPERTY_DEBUG_CODE_ENABLED) != 0);\r
+ return (BOOLEAN) ((PcdGet8 (PcdReportStatusCodePropertyMask) & REPORT_STATUS_CODE_PROPERTY_DEBUG_CODE_ENABLED) != 0);\r
}\r