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>
24 EFI_EVENT mVirtualAddressChangeEvent
;
27 EFI_EVENT mExitBootServicesEvent
;
30 EFI_STATUS_CODE_DATA
*mStatusCodeData
;
35 EFI_SMM_BASE_PROTOCOL
*mSmmBase
;
38 EFI_RUNTIME_SERVICES
*mRT
;
41 BOOLEAN mHaveExitedBootServices
= FALSE
;
44 Locate he report status code service.
46 @return EFI_REPORT_STATUS_CODE function point to
49 EFI_REPORT_STATUS_CODE
50 InternalGetReportStatusCode (
54 EFI_STATUS_CODE_PROTOCOL
*StatusCodeProtocol
;
58 return (EFI_REPORT_STATUS_CODE
) OemHookStatusCodeReport
;
59 } else if (mRT
!= NULL
&& mRT
->Hdr
.Revision
< 0x20000) {
60 return ((FRAMEWORK_EFI_RUNTIME_SERVICES
*)mRT
)->ReportStatusCode
;
61 } else if (!mHaveExitedBootServices
) {
63 // Check gBS just in case. ReportStatusCode is called before gBS is initialized.
66 Status
= gBS
->LocateProtocol (&gEfiStatusCodeRuntimeProtocolGuid
, NULL
, (VOID
**)&StatusCodeProtocol
);
67 if (!EFI_ERROR (Status
) && StatusCodeProtocol
!= NULL
) {
68 return StatusCodeProtocol
->ReportStatusCode
;
78 Fixup internal report status code protocol interface.
80 @param[in] Event The Event that is being processed
81 @param[in] Context Event Context
86 ReportStatusCodeLibVirtualAddressChange (
91 if (NULL
!= mReportStatusCode
) {
92 mRT
->ConvertPointer (0, (VOID
**) &mReportStatusCode
);
94 mRT
->ConvertPointer (0, (VOID
**) &mStatusCodeData
);
95 mRT
->ConvertPointer (0, (VOID
**) &mRT
);
99 Update the In Runtime Indicator.
101 @param[in] Event The Event that is being processed
102 @param[in] Context Event Context
107 ReportStatusCodeLibExitBootServices (
112 mHaveExitedBootServices
= TRUE
;
116 Intialize Report Status Code Lib.
118 @param[in] ImageHandle The firmware allocated handle for the EFI image.
119 @param[in] SystemTable A pointer to the EFI System Table.
121 @return EFI_STATUS always returns EFI_SUCCESS.
125 ReportStatusCodeLibConstruct (
126 IN EFI_HANDLE ImageHandle
,
127 IN EFI_SYSTEM_TABLE
*SystemTable
133 // SMM driver depends on the SMM BASE protocol.
134 // the SMM driver must be success to locate protocol.
136 Status
= gBS
->LocateProtocol (&gEfiSmmBaseProtocolGuid
, NULL
, (VOID
**) &mSmmBase
);
137 if (!EFI_ERROR (Status
)) {
138 mSmmBase
->InSmm (mSmmBase
, &mInSmm
);
140 Status
= mSmmBase
->SmmAllocatePool (
142 EfiRuntimeServicesData
,
143 sizeof (EFI_STATUS_CODE_DATA
) + EFI_STATUS_CODE_DATA_MAX_SIZE
,
144 (VOID
**) &mStatusCodeData
146 ASSERT_EFI_ERROR (Status
);
147 OemHookStatusCodeInitialize ();
153 // Library should not use the gRT directly, since it
154 // may be converted by other library instance.
159 gBS
->AllocatePool (EfiRuntimeServicesData
, sizeof (EFI_STATUS_CODE_DATA
) + EFI_STATUS_CODE_DATA_MAX_SIZE
, (VOID
**)&mStatusCodeData
);
160 ASSERT (NULL
!= mStatusCodeData
);
162 // Cache the report status code service
164 mReportStatusCode
= InternalGetReportStatusCode ();
167 // Register the call back of virtual address change
169 Status
= gBS
->CreateEvent (
170 EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE
,
172 ReportStatusCodeLibVirtualAddressChange
,
174 &mVirtualAddressChangeEvent
176 ASSERT_EFI_ERROR (Status
);
180 // Register the call back of virtual address change
182 Status
= gBS
->CreateEvent (
183 EVT_SIGNAL_EXIT_BOOT_SERVICES
,
185 ReportStatusCodeLibExitBootServices
,
187 &mExitBootServicesEvent
189 ASSERT_EFI_ERROR (Status
);
195 Desctructor of library will close events.
197 @param ImageHandle callder module's image handle
198 @param SystemTable pointer to EFI system table.
199 @return the status of close event.
203 ReportStatusCodeLibDestruct (
204 IN EFI_HANDLE ImageHandle
,
205 IN EFI_SYSTEM_TABLE
*SystemTable
212 // Close SetVirtualAddressMap () notify function
214 ASSERT (gBS
!= NULL
);
215 Status
= gBS
->CloseEvent (mVirtualAddressChangeEvent
);
216 ASSERT_EFI_ERROR (Status
);
217 Status
= gBS
->CloseEvent (mExitBootServicesEvent
);
218 ASSERT_EFI_ERROR (Status
);
220 gBS
->FreePool (mStatusCodeData
);
222 mSmmBase
->SmmFreePool (mSmmBase
, mStatusCodeData
);
229 Reports a status code with full parameters.
231 The function reports a status code. If ExtendedData is NULL and ExtendedDataSize
232 is 0, then an extended data buffer is not reported. If ExtendedData is not
233 NULL and ExtendedDataSize is not 0, then an extended data buffer is allocated.
234 ExtendedData is assumed not have the standard status code header, so this function
235 is responsible for allocating a buffer large enough for the standard header and
236 the extended data passed into this function. The standard header is filled in
237 with a GUID specified by ExtendedDataGuid. If ExtendedDataGuid is NULL, then a
238 GUID of gEfiStatusCodeSpecificDatauid is used. The status code is reported with
239 an instance specified by Instance and a caller ID specified by CallerId. If
240 CallerId is NULL, then a caller ID of gEfiCallerIdGuid is used.
242 ReportStatusCodeEx()must actively prevent recursion. If ReportStatusCodeEx()
243 is called while processing another any other Report Status Code Library function,
244 then ReportStatusCodeEx() must return EFI_DEVICE_ERROR immediately.
246 If ExtendedData is NULL and ExtendedDataSize is not zero, then ASSERT().
247 If ExtendedData is not NULL and ExtendedDataSize is zero, then ASSERT().
249 @param Type Status code type.
250 @param Value Status code value.
251 @param Instance Status code instance number.
252 @param CallerId Pointer to a GUID that identifies the caller of this
253 function. If this parameter is NULL, then a caller
254 ID of gEfiCallerIdGuid is used.
255 @param ExtendedDataGuid Pointer to the GUID for the extended data buffer.
256 If this parameter is NULL, then a the status code
257 standard header is filled in with
258 gEfiStatusCodeSpecificDataGuid.
259 @param ExtendedData Pointer to the extended data buffer. This is an
260 optional parameter that may be NULL.
261 @param ExtendedDataSize The size, in bytes, of the extended data buffer.
263 @retval EFI_SUCCESS The status code was reported.
264 @retval EFI_OUT_OF_RESOURCES There were not enough resources to allocate
265 the extended data section if it was specified.
266 @retval EFI_UNSUPPORTED Report status code is not supported
271 InternalReportStatusCodeEx (
272 IN EFI_STATUS_CODE_TYPE Type
,
273 IN EFI_STATUS_CODE_VALUE Value
,
275 IN CONST EFI_GUID
*CallerId OPTIONAL
,
276 IN CONST EFI_GUID
*ExtendedDataGuid OPTIONAL
,
277 IN CONST VOID
*ExtendedData OPTIONAL
,
278 IN UINTN ExtendedDataSize
281 ASSERT (!((ExtendedData
== NULL
) && (ExtendedDataSize
!= 0)));
282 ASSERT (!((ExtendedData
!= NULL
) && (ExtendedDataSize
== 0)));
284 if (ExtendedDataSize
> EFI_STATUS_CODE_DATA_MAX_SIZE
) {
285 return EFI_OUT_OF_RESOURCES
;
289 // Fill in the extended data header
291 mStatusCodeData
->HeaderSize
= sizeof (EFI_STATUS_CODE_DATA
);
292 mStatusCodeData
->Size
= (UINT16
)ExtendedDataSize
;
293 if (ExtendedDataGuid
== NULL
) {
294 ExtendedDataGuid
= &gEfiStatusCodeSpecificDataGuid
;
296 CopyGuid (&mStatusCodeData
->Type
, ExtendedDataGuid
);
299 // Fill in the extended data buffer
301 CopyMem (mStatusCodeData
+ 1, ExtendedData
, ExtendedDataSize
);
304 // Report the status code
306 if (CallerId
== NULL
) {
307 CallerId
= &gEfiCallerIdGuid
;
309 return InternalReportStatusCode (Type
, Value
, Instance
, CallerId
, mStatusCodeData
);