2 Report Status Code Library that depends on a GUIDed HOB for report status
5 Copyright (c) 2009, Intel Corporation. All rights reserved.<BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 #include "ReportStatusCodeLibInternal.h"
19 // Handle to install report status code protocol interface
21 EFI_HANDLE mHandle
= NULL
;
24 // Report status protocol interface.
26 EFI_STATUS_CODE_PROTOCOL mStatusProtocol
= {
31 Initializes report status code infrastructure for DXE phase.
33 The constructor function assumes the PEI phase has published the GUIDed HOB
34 tagged by gEfiStatusCodeRuntimeProtocolGuid and publish status code runtime
35 protocol based on the GUID data. It will ASSERT() if one of these operations
36 fails and it will always return EFI_SUCCESS.
38 @param ImageHandle The firmware allocated handle for the EFI image.
39 @param SystemTable A pointer to the EFI System Table.
41 @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.
46 DxeCoreReportStatusCodeFromHobLibConstructor (
47 IN EFI_HANDLE ImageHandle
,
48 IN EFI_SYSTEM_TABLE
*SystemTable
52 EFI_HOB_GUID_TYPE
*GuidHob
;
54 GuidHob
= GetFirstGuidHob(&gEfiStatusCodeRuntimeProtocolGuid
);
55 ASSERT (GuidHob
!= NULL
);
57 mStatusProtocol
.ReportStatusCode
= (EFI_REPORT_STATUS_CODE
) (*(UINTN
*) GET_GUID_HOB_DATA (GuidHob
));
58 ASSERT (mStatusProtocol
.ReportStatusCode
!= NULL
);
61 // Install report status protocol interface so that later DXE phase drivers can retrieve the protocol
62 // interface to report status code.
64 Status
= gBS
->InstallProtocolInterface (
66 &gEfiStatusCodeRuntimeProtocolGuid
,
70 ASSERT_EFI_ERROR (Status
);
76 Reports a status code with full parameters.
78 The function reports a status code. If ExtendedData is NULL and ExtendedDataSize
79 is 0, then an extended data buffer is not reported. If ExtendedData is not
80 NULL and ExtendedDataSize is not 0, then an extended data buffer is allocated.
81 ExtendedData is assumed not have the standard status code header, so this function
82 is responsible for allocating a buffer large enough for the standard header and
83 the extended data passed into this function. The standard header is filled in
84 with a GUID specified by ExtendedDataGuid. If ExtendedDataGuid is NULL, then a
85 GUID of gEfiStatusCodeSpecificDatauid is used. The status code is reported with
86 an instance specified by Instance and a caller ID specified by CallerId. If
87 CallerId is NULL, then a caller ID of gEfiCallerIdGuid is used.
89 ReportStatusCodeEx()must actively prevent recursion. If ReportStatusCodeEx()
90 is called while processing another any other Report Status Code Library function,
91 then ReportStatusCodeEx() must return EFI_DEVICE_ERROR immediately.
93 If ExtendedData is NULL and ExtendedDataSize is not zero, then ASSERT().
94 If ExtendedData is not NULL and ExtendedDataSize is zero, then ASSERT().
96 @param Type Status code type.
97 @param Value Status code value.
98 @param Instance Status code instance number.
99 @param CallerId Pointer to a GUID that identifies the caller of this
100 function. If this parameter is NULL, then a caller
101 ID of gEfiCallerIdGuid is used.
102 @param ExtendedDataGuid Pointer to the GUID for the extended data buffer.
103 If this parameter is NULL, then a the status code
104 standard header is filled in with
105 gEfiStatusCodeSpecificDataGuid.
106 @param ExtendedData Pointer to the extended data buffer. This is an
107 optional parameter that may be NULL.
108 @param ExtendedDataSize The size, in bytes, of the extended data buffer.
110 @retval EFI_SUCCESS The status code was reported.
111 @retval EFI_OUT_OF_RESOURCES There were not enough resources to allocate
112 the extended data section if it was specified.
113 @retval EFI_UNSUPPORTED Report status code is not supported
118 InternalReportStatusCodeEx (
119 IN EFI_STATUS_CODE_TYPE Type
,
120 IN EFI_STATUS_CODE_VALUE Value
,
122 IN CONST EFI_GUID
*CallerId OPTIONAL
,
123 IN CONST EFI_GUID
*ExtendedDataGuid OPTIONAL
,
124 IN CONST VOID
*ExtendedData OPTIONAL
,
125 IN UINTN ExtendedDataSize
129 EFI_STATUS_CODE_DATA
*StatusCodeData
;
131 ASSERT (!((ExtendedData
== NULL
) && (ExtendedDataSize
!= 0)));
132 ASSERT (!((ExtendedData
!= NULL
) && (ExtendedDataSize
== 0)));
135 return EFI_UNSUPPORTED
;
139 // Allocate space for the Status Code Header and its buffer
141 StatusCodeData
= NULL
;
142 gBS
->AllocatePool (EfiBootServicesData
, sizeof (EFI_STATUS_CODE_DATA
) + ExtendedDataSize
, (VOID
**)&StatusCodeData
);
143 if (StatusCodeData
== NULL
) {
144 return EFI_OUT_OF_RESOURCES
;
148 // Fill in the extended data header
150 StatusCodeData
->HeaderSize
= sizeof (EFI_STATUS_CODE_DATA
);
151 StatusCodeData
->Size
= (UINT16
)ExtendedDataSize
;
152 if (ExtendedDataGuid
== NULL
) {
153 ExtendedDataGuid
= &gEfiStatusCodeSpecificDataGuid
;
155 CopyGuid (&StatusCodeData
->Type
, ExtendedDataGuid
);
158 // Fill in the extended data buffer
160 CopyMem (StatusCodeData
+ 1, ExtendedData
, ExtendedDataSize
);
163 // Report the status code
165 if (CallerId
== NULL
) {
166 CallerId
= &gEfiCallerIdGuid
;
168 Status
= InternalReportStatusCode (Type
, Value
, Instance
, CallerId
, StatusCodeData
);
171 // Free the allocated buffer
173 gBS
->FreePool (StatusCodeData
);