2 Report Status Code Library for DXE Phase.
4 Copyright (c) 2006 - 2007, Intel Corporation<BR>
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 #include "ReportStatusCodeLibInternal.h"
18 // Resources need by SMM runtime instance
20 #include <Library/OemHookStatusCodeLib.h>
21 #include <Protocol/SmmBase.h>
23 EFI_EVENT mVirtualAddressChangeEvent
;
25 EFI_EVENT mExitBootServicesEvent
;
27 EFI_STATUS_CODE_DATA
*mStatusCodeData
;
31 EFI_SMM_BASE_PROTOCOL
*mSmmBase
;
33 EFI_RUNTIME_SERVICES
*mRT
;
35 BOOLEAN mHaveExitedBootServices
= FALSE
;
38 Locate he report status code service.
40 @return EFI_REPORT_STATUS_CODE function point to
43 EFI_REPORT_STATUS_CODE
44 InternalGetReportStatusCode (
48 EFI_STATUS_CODE_PROTOCOL
*StatusCodeProtocol
;
52 return (EFI_REPORT_STATUS_CODE
) OemHookStatusCodeReport
;
53 } else if (mRT
!= NULL
&& mRT
->Hdr
.Revision
< 0x20000) {
54 return ((FRAMEWORK_EFI_RUNTIME_SERVICES
*)mRT
)->ReportStatusCode
;
55 } else if (!mHaveExitedBootServices
) {
57 // Check gBS just in case. ReportStatusCode is called before gBS is initialized.
60 Status
= gBS
->LocateProtocol (&gEfiStatusCodeRuntimeProtocolGuid
, NULL
, (VOID
**)&StatusCodeProtocol
);
61 if (!EFI_ERROR (Status
) && StatusCodeProtocol
!= NULL
) {
62 return StatusCodeProtocol
->ReportStatusCode
;
72 Fixup internal report status code protocol interface.
74 @param[in] Event The Event that is being processed
75 @param[in] Context Event Context
79 ReportStatusCodeLibVirtualAddressChange (
84 if (NULL
!= mReportStatusCode
) {
85 mRT
->ConvertPointer (0, (VOID
**) &mReportStatusCode
);
87 mRT
->ConvertPointer (0, (VOID
**) &mStatusCodeData
);
88 mRT
->ConvertPointer (0, (VOID
**) &mRT
);
92 Update the In Runtime Indicator.
94 @param[in] Event The Event that is being processed
95 @param[in] Context Event Context
99 ReportStatusCodeLibExitBootServices (
104 mHaveExitedBootServices
= TRUE
;
108 Intialize Report Status Code Lib.
110 @param[in] ImageHandle The firmware allocated handle for the EFI image.
111 @param[in] SystemTable A pointer to the EFI System Table.
113 @return EFI_STATUS always returns EFI_SUCCESS.
117 ReportStatusCodeLibConstruct (
118 IN EFI_HANDLE ImageHandle
,
119 IN EFI_SYSTEM_TABLE
*SystemTable
125 // SMM driver depends on the SMM BASE protocol.
126 // the SMM driver must be success to locate protocol.
128 Status
= gBS
->LocateProtocol (&gEfiSmmBaseProtocolGuid
, NULL
, (VOID
**) &mSmmBase
);
129 if (!EFI_ERROR (Status
)) {
130 mSmmBase
->InSmm (mSmmBase
, &mInSmm
);
132 Status
= mSmmBase
->SmmAllocatePool (
134 EfiRuntimeServicesData
,
135 sizeof (EFI_STATUS_CODE_DATA
) + EFI_STATUS_CODE_DATA_MAX_SIZE
,
136 (VOID
**) &mStatusCodeData
138 ASSERT_EFI_ERROR (Status
);
139 OemHookStatusCodeInitialize ();
145 // Library should not use the gRT directly, since it
146 // may be converted by other library instance.
151 gBS
->AllocatePool (EfiRuntimeServicesData
, sizeof (EFI_STATUS_CODE_DATA
) + EFI_STATUS_CODE_DATA_MAX_SIZE
, (VOID
**)&mStatusCodeData
);
152 ASSERT (NULL
!= mStatusCodeData
);
154 // Cache the report status code service
156 mReportStatusCode
= InternalGetReportStatusCode ();
159 // Register the call back of virtual address change
161 Status
= gBS
->CreateEventEx (
164 ReportStatusCodeLibVirtualAddressChange
,
166 &gEfiEventVirtualAddressChangeGuid
,
167 &mVirtualAddressChangeEvent
169 ASSERT_EFI_ERROR (Status
);
173 // Register the call back of virtual address change
175 Status
= gBS
->CreateEventEx (
178 ReportStatusCodeLibExitBootServices
,
180 &gEfiEventExitBootServicesGuid
,
181 &mExitBootServicesEvent
183 ASSERT_EFI_ERROR (Status
);
189 Desctructor of library will close events.
191 @param ImageHandle callder module's image handle
192 @param SystemTable pointer to EFI system table.
193 @return the status of close event.
197 ReportStatusCodeLibDestruct (
198 IN EFI_HANDLE ImageHandle
,
199 IN EFI_SYSTEM_TABLE
*SystemTable
206 // Close SetVirtualAddressMap () notify function
208 ASSERT (gBS
!= NULL
);
209 Status
= gBS
->CloseEvent (mVirtualAddressChangeEvent
);
210 ASSERT_EFI_ERROR (Status
);
211 Status
= gBS
->CloseEvent (mExitBootServicesEvent
);
212 ASSERT_EFI_ERROR (Status
);
214 gBS
->FreePool (mStatusCodeData
);
216 mSmmBase
->SmmFreePool (mSmmBase
, mStatusCodeData
);
223 Reports a status code with full parameters.
225 The function reports a status code. If ExtendedData is NULL and ExtendedDataSize
226 is 0, then an extended data buffer is not reported. If ExtendedData is not
227 NULL and ExtendedDataSize is not 0, then an extended data buffer is allocated.
228 ExtendedData is assumed not have the standard status code header, so this function
229 is responsible for allocating a buffer large enough for the standard header and
230 the extended data passed into this function. The standard header is filled in
231 with a GUID specified by ExtendedDataGuid. If ExtendedDataGuid is NULL, then a
232 GUID of gEfiStatusCodeSpecificDatauid is used. The status code is reported with
233 an instance specified by Instance and a caller ID specified by CallerId. If
234 CallerId is NULL, then a caller ID of gEfiCallerIdGuid is used.
236 ReportStatusCodeEx()must actively prevent recursion. If ReportStatusCodeEx()
237 is called while processing another any other Report Status Code Library function,
238 then ReportStatusCodeEx() must return EFI_DEVICE_ERROR immediately.
240 If ExtendedData is NULL and ExtendedDataSize is not zero, then ASSERT().
241 If ExtendedData is not NULL and ExtendedDataSize is zero, then ASSERT().
243 @param Type Status code type.
244 @param Value Status code value.
245 @param Instance Status code instance number.
246 @param CallerId Pointer to a GUID that identifies the caller of this
247 function. If this parameter is NULL, then a caller
248 ID of gEfiCallerIdGuid is used.
249 @param ExtendedDataGuid Pointer to the GUID for the extended data buffer.
250 If this parameter is NULL, then a the status code
251 standard header is filled in with
252 gEfiStatusCodeSpecificDataGuid.
253 @param ExtendedData Pointer to the extended data buffer. This is an
254 optional parameter that may be NULL.
255 @param ExtendedDataSize The size, in bytes, of the extended data buffer.
257 @retval EFI_SUCCESS The status code was reported.
258 @retval EFI_OUT_OF_RESOURCES There were not enough resources to allocate
259 the extended data section if it was specified.
260 @retval EFI_UNSUPPORTED Report status code is not supported
265 InternalReportStatusCodeEx (
266 IN EFI_STATUS_CODE_TYPE Type
,
267 IN EFI_STATUS_CODE_VALUE Value
,
269 IN CONST EFI_GUID
*CallerId OPTIONAL
,
270 IN CONST EFI_GUID
*ExtendedDataGuid OPTIONAL
,
271 IN CONST VOID
*ExtendedData OPTIONAL
,
272 IN UINTN ExtendedDataSize
275 ASSERT (!((ExtendedData
== NULL
) && (ExtendedDataSize
!= 0)));
276 ASSERT (!((ExtendedData
!= NULL
) && (ExtendedDataSize
== 0)));
278 if (ExtendedDataSize
> EFI_STATUS_CODE_DATA_MAX_SIZE
) {
279 return EFI_OUT_OF_RESOURCES
;
283 // Fill in the extended data header
285 mStatusCodeData
->HeaderSize
= sizeof (EFI_STATUS_CODE_DATA
);
286 mStatusCodeData
->Size
= (UINT16
)ExtendedDataSize
;
287 if (ExtendedDataGuid
== NULL
) {
288 ExtendedDataGuid
= &gEfiStatusCodeSpecificDataGuid
;
290 CopyGuid (&mStatusCodeData
->Type
, ExtendedDataGuid
);
293 // Fill in the extended data buffer
295 if (ExtendedData
!= NULL
) {
296 CopyMem (mStatusCodeData
+ 1, ExtendedData
, ExtendedDataSize
);
300 // Report the status code
302 if (CallerId
== NULL
) {
303 CallerId
= &gEfiCallerIdGuid
;
305 return InternalReportStatusCode (Type
, Value
, Instance
, CallerId
, mStatusCodeData
);