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
;
36 EFI_RUNTIME_SERVICES
*mRT
;
39 BOOLEAN mHaveExitedBootServices
= FALSE
;
42 Locatet he report status code service.
44 @return EFI_REPORT_STATUS_CODE function point to
47 EFI_REPORT_STATUS_CODE
48 InternalGetReportStatusCode (
52 EFI_STATUS_CODE_PROTOCOL
*StatusCodeProtocol
;
56 return (EFI_REPORT_STATUS_CODE
) OemHookStatusCodeReport
;
57 } else if (mRT
->Hdr
.Revision
< 0x20000) {
58 return ((FRAMEWORK_EFI_RUNTIME_SERVICES
*)mRT
)->ReportStatusCode
;
59 } else if (!mHaveExitedBootServices
) {
60 Status
= gBS
->LocateProtocol (&gEfiStatusCodeRuntimeProtocolGuid
, NULL
, (VOID
**)&StatusCodeProtocol
);
61 if (!EFI_ERROR (Status
) && StatusCodeProtocol
!= NULL
) {
62 return StatusCodeProtocol
->ReportStatusCode
;
71 Fixup internal report status code protocol interface.
73 @param[in] Event The Event that is being processed
74 @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 Updatet the In Runtime Indicator.
94 @param[in] Event The Event that is being processed
95 @param[in] Context Event Context
100 ReportStatusCodeLibExitBootServices (
105 mHaveExitedBootServices
= TRUE
;
109 Intialize Report Status Code Lib.
111 @param[in] ImageHandle The firmware allocated handle for the EFI image.
112 @param[in] SystemTable A pointer to the EFI System Table.
114 @return EFI_STATUS always returns EFI_SUCCESS.
118 ReportStatusCodeLibConstruct (
119 IN EFI_HANDLE ImageHandle
,
120 IN EFI_SYSTEM_TABLE
*SystemTable
123 EFI_SMM_BASE_PROTOCOL
*SmmBase
;
127 // SMM driver depends on the SMM BASE protocol.
128 // the SMM driver must be success to locate protocol.
130 ASSERT (gBS
!= NULL
);
131 Status
= gBS
->LocateProtocol (&gEfiSmmBaseProtocolGuid
, NULL
, (VOID
**) &SmmBase
);
132 if (!EFI_ERROR (Status
)) {
133 SmmBase
->InSmm (SmmBase
, &mInSmm
);
135 Status
= SmmBase
->SmmAllocatePool (
137 EfiRuntimeServicesData
,
138 sizeof (EFI_STATUS_CODE_DATA
) + EFI_STATUS_CODE_DATA_MAX_SIZE
,
139 (VOID
**) &mStatusCodeData
141 ASSERT_EFI_ERROR (Status
);
142 OemHookStatusCodeInitialize ();
148 // Library should not use the gRT directly, since it
149 // may be converted by other library instance.
154 gBS
->AllocatePool (EfiRuntimeServicesData
, sizeof (EFI_STATUS_CODE_DATA
) + EFI_STATUS_CODE_DATA_MAX_SIZE
, (VOID
**)&mStatusCodeData
);
155 ASSERT (NULL
!= mStatusCodeData
);
157 // Cache the report status code service
159 mReportStatusCode
= InternalGetReportStatusCode ();
162 // Register the call back of virtual address change
164 Status
= gBS
->CreateEvent (
165 EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE
,
167 ReportStatusCodeLibVirtualAddressChange
,
169 &mVirtualAddressChangeEvent
171 ASSERT_EFI_ERROR (Status
);
175 // Register the call back of virtual address change
177 Status
= gBS
->CreateEvent (
178 EVT_SIGNAL_EXIT_BOOT_SERVICES
,
180 ReportStatusCodeLibExitBootServices
,
182 &mExitBootServicesEvent
184 ASSERT_EFI_ERROR (Status
);
192 ReportStatusCodeLibDestruct (
193 IN EFI_HANDLE ImageHandle
,
194 IN EFI_SYSTEM_TABLE
*SystemTable
200 // Close SetVirtualAddressMap () notify function
202 ASSERT (gBS
!= NULL
);
203 Status
= gBS
->CloseEvent (mVirtualAddressChangeEvent
);
204 ASSERT_EFI_ERROR (Status
);
205 Status
= gBS
->CloseEvent (mExitBootServicesEvent
);
206 ASSERT_EFI_ERROR (Status
);
208 gBS
->FreePool (mStatusCodeData
);
215 Reports a status code with full parameters.
217 The function reports a status code. If ExtendedData is NULL and ExtendedDataSize
218 is 0, then an extended data buffer is not reported. If ExtendedData is not
219 NULL and ExtendedDataSize is not 0, then an extended data buffer is allocated.
220 ExtendedData is assumed not have the standard status code header, so this function
221 is responsible for allocating a buffer large enough for the standard header and
222 the extended data passed into this function. The standard header is filled in
223 with a GUID specified by ExtendedDataGuid. If ExtendedDataGuid is NULL, then a
224 GUID of gEfiStatusCodeSpecificDatauid is used. The status code is reported with
225 an instance specified by Instance and a caller ID specified by CallerId. If
226 CallerId is NULL, then a caller ID of gEfiCallerIdGuid is used.
228 ReportStatusCodeEx()must actively prevent recursion. If ReportStatusCodeEx()
229 is called while processing another any other Report Status Code Library function,
230 then ReportStatusCodeEx() must return EFI_DEVICE_ERROR immediately.
232 If ExtendedData is NULL and ExtendedDataSize is not zero, then ASSERT().
233 If ExtendedData is not NULL and ExtendedDataSize is zero, then ASSERT().
235 @param Type Status code type.
236 @param Value Status code value.
237 @param Instance Status code instance number.
238 @param CallerId Pointer to a GUID that identifies the caller of this
239 function. If this parameter is NULL, then a caller
240 ID of gEfiCallerIdGuid is used.
241 @param ExtendedDataGuid Pointer to the GUID for the extended data buffer.
242 If this parameter is NULL, then a the status code
243 standard header is filled in with
244 gEfiStatusCodeSpecificDataGuid.
245 @param ExtendedData Pointer to the extended data buffer. This is an
246 optional parameter that may be NULL.
247 @param ExtendedDataSize The size, in bytes, of the extended data buffer.
249 @retval EFI_SUCCESS The status code was reported.
250 @retval EFI_OUT_OF_RESOURCES There were not enough resources to allocate
251 the extended data section if it was specified.
252 @retval EFI_UNSUPPORTED Report status code is not supported
257 InternalReportStatusCodeEx (
258 IN EFI_STATUS_CODE_TYPE Type
,
259 IN EFI_STATUS_CODE_VALUE Value
,
261 IN CONST EFI_GUID
*CallerId OPTIONAL
,
262 IN CONST EFI_GUID
*ExtendedDataGuid OPTIONAL
,
263 IN CONST VOID
*ExtendedData OPTIONAL
,
264 IN UINTN ExtendedDataSize
267 ASSERT (!((ExtendedData
== NULL
) && (ExtendedDataSize
!= 0)));
268 ASSERT (!((ExtendedData
!= NULL
) && (ExtendedDataSize
== 0)));
270 if (ExtendedDataSize
> EFI_STATUS_CODE_DATA_MAX_SIZE
) {
271 return EFI_OUT_OF_RESOURCES
;
275 // Fill in the extended data header
277 mStatusCodeData
->HeaderSize
= sizeof (EFI_STATUS_CODE_DATA
);
278 mStatusCodeData
->Size
= (UINT16
)ExtendedDataSize
;
279 if (ExtendedDataGuid
== NULL
) {
280 ExtendedDataGuid
= &gEfiStatusCodeSpecificDataGuid
;
282 CopyGuid (&mStatusCodeData
->Type
, ExtendedDataGuid
);
285 // Fill in the extended data buffer
287 CopyMem (mStatusCodeData
+ 1, ExtendedData
, ExtendedDataSize
);
290 // Report the status code
292 if (CallerId
== NULL
) {
293 CallerId
= &gEfiCallerIdGuid
;
295 return InternalReportStatusCode (Type
, Value
, Instance
, CallerId
, mStatusCodeData
);