--- /dev/null
+/** @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
+ 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
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#include "ReportStatusCodeLibInternal.h"\r
+\r
+/**\r
+ Locate he report status code service.\r
+\r
+ @return EFI_REPORT_STATUS_CODE function point to\r
+ ReportStatusCode.\r
+**/\r
+EFI_REPORT_STATUS_CODE\r
+InternalGetReportStatusCode (\r
+ VOID\r
+ )\r
+{\r
+ EFI_STATUS_CODE_PROTOCOL *StatusCodeProtocol;\r
+ EFI_STATUS Status;\r
+ EFI_PEI_HOB_POINTERS GuidHob;\r
+ \r
+ if (gRT->Hdr.Revision < 0x20000) {\r
+ return ((FRAMEWORK_EFI_RUNTIME_SERVICES*)gRT)->ReportStatusCode;\r
+ } else if (gBS != NULL) {\r
+ Status = gBS->LocateProtocol (&gEfiStatusCodeRuntimeProtocolGuid, NULL, (VOID**)&StatusCodeProtocol);\r
+ if (!EFI_ERROR (Status) && StatusCodeProtocol != NULL) {\r
+ return StatusCodeProtocol->ReportStatusCode;\r
+ } else {\r
+ GuidHob.Raw = GetFirstGuidHob(&gEfiStatusCodeRuntimeProtocolGuid);\r
+ if (GuidHob.Raw != NULL) {\r
+ return (EFI_REPORT_STATUS_CODE) (*(UINTN *) GET_GUID_HOB_DATA (GuidHob.Guid));\r
+ }\r
+ }\r
+ }\r
+\r
+ return NULL;\r
+}\r
+\r
+/**\r
+ Reports a status code with full parameters.\r
+\r
+ The function reports a status code. If ExtendedData is NULL and ExtendedDataSize\r
+ is 0, then an extended data buffer is not reported. If ExtendedData is not\r
+ NULL and ExtendedDataSize is not 0, then an extended data buffer is allocated.\r
+ ExtendedData is assumed not have the standard status code header, so this function\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
+ 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
+ ReportStatusCodeEx()must actively prevent recursion. If ReportStatusCodeEx()\r
+ is called while processing another any other Report Status Code Library function,\r
+ then ReportStatusCodeEx() must return EFI_DEVICE_ERROR immediately.\r
+\r
+ If ExtendedData is NULL and ExtendedDataSize is not zero, then ASSERT().\r
+ If ExtendedData is not NULL and ExtendedDataSize is zero, then ASSERT().\r
+\r
+ @param Type Status code type.\r
+ @param Value Status code value.\r
+ @param Instance Status code instance number.\r
+ @param CallerId Pointer to a GUID that identifies the caller of this\r
+ function. If this parameter is NULL, then a caller\r
+ ID of gEfiCallerIdGuid is used.\r
+ @param ExtendedDataGuid Pointer to the GUID for the extended data buffer.\r
+ If this parameter is NULL, then a the status code\r
+ standard header is filled in with\r
+ gEfiStatusCodeSpecificDataGuid.\r
+ @param ExtendedData Pointer to the extended data buffer. This is an\r
+ optional parameter that may be NULL.\r
+ @param ExtendedDataSize The size, in bytes, of the extended data buffer.\r
+\r
+ @retval EFI_SUCCESS The status code was reported.\r
+ @retval EFI_OUT_OF_RESOURCES There were not enough resources to allocate\r
+ the extended data section if it was specified.\r
+ @retval EFI_UNSUPPORTED Report status code is not supported\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+InternalReportStatusCodeEx (\r
+ IN EFI_STATUS_CODE_TYPE Type,\r
+ IN EFI_STATUS_CODE_VALUE Value,\r
+ IN UINT32 Instance,\r
+ IN CONST EFI_GUID *CallerId OPTIONAL,\r
+ IN CONST EFI_GUID *ExtendedDataGuid OPTIONAL,\r
+ IN CONST VOID *ExtendedData OPTIONAL,\r
+ IN UINTN ExtendedDataSize\r
+ )\r
+{\r
+ EFI_STATUS Status;\r
+ EFI_STATUS_CODE_DATA *StatusCodeData;\r
+\r
+ ASSERT (!((ExtendedData == NULL) && (ExtendedDataSize != 0)));\r
+ ASSERT (!((ExtendedData != NULL) && (ExtendedDataSize == 0)));\r
+\r
+ if (gBS == NULL) {\r
+ return EFI_UNSUPPORTED;\r
+ }\r
+\r
+ //\r
+ // Allocate space for the Status Code Header and its buffer\r
+ //\r
+ StatusCodeData = NULL;\r
+ gBS->AllocatePool (EfiBootServicesData, sizeof (EFI_STATUS_CODE_DATA) + ExtendedDataSize, (VOID **)&StatusCodeData);\r
+ if (StatusCodeData == NULL) {\r
+ return EFI_OUT_OF_RESOURCES;\r
+ }\r
+\r
+ //\r
+ // Fill in the extended data header\r
+ //\r
+ StatusCodeData->HeaderSize = 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
+ CopyMem (StatusCodeData + 1, ExtendedData, ExtendedDataSize);\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
+ gBS->FreePool (StatusCodeData);\r
+\r
+ return Status;\r
+}\r
+\r