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
;
33 EFI_SMM_BASE_PROTOCOL
*mSmmBase
;
36 BOOLEAN mHaveExitedBootServices
= FALSE
;
39 Locatet he report status code service.
41 @return EFI_REPORT_STATUS_CODE function point to
44 EFI_REPORT_STATUS_CODE
45 InternalGetReportStatusCode (
49 EFI_STATUS_CODE_PROTOCOL
*StatusCodeProtocol
;
54 mSmmBase
->InSmm (mSmmBase
, &InSmm
);
56 return (EFI_REPORT_STATUS_CODE
) OemHookStatusCodeReport
;
59 if (gRT
->Hdr
.Revision
< 0x20000) {
60 return ((FRAMEWORK_EFI_RUNTIME_SERVICES
*)gRT
)->ReportStatusCode
;
61 } else if (!mHaveExitedBootServices
) {
62 Status
= gBS
->LocateProtocol (&gEfiStatusCodeRuntimeProtocolGuid
, NULL
, (VOID
**)&StatusCodeProtocol
);
63 if (!EFI_ERROR (Status
) && StatusCodeProtocol
!= NULL
) {
64 return StatusCodeProtocol
->ReportStatusCode
;
73 Fixup internal report status code protocol interface.
75 @param[in] Event The Event that is being processed
76 @param[in] Context Event Context
81 ReportStatusCodeLibVirtualAddressChange (
86 if (NULL
!= mReportStatusCode
) {
87 gRT
->ConvertPointer (0, (VOID
**) &mReportStatusCode
);
89 if (NULL
!= mSmmBase
) {
90 gRT
->ConvertPointer (0, (VOID
**) &mSmmBase
);
92 gRT
->ConvertPointer (0, (VOID
**) &mStatusCodeData
);
93 gRT
->ConvertPointer (0, (VOID
**) &gRT
);
97 Updatet the In Runtime Indicator.
99 @param[in] Event The Event that is being processed
100 @param[in] Context Event Context
105 ReportStatusCodeLibExitBootServices (
110 mHaveExitedBootServices
= TRUE
;
114 Intialize Report Status Code Lib.
116 @param[in] ImageHandle The firmware allocated handle for the EFI image.
117 @param[in] SystemTable A pointer to the EFI System Table.
119 @return EFI_STATUS always returns EFI_SUCCESS.
123 ReportStatusCodeLibConstruct (
124 IN EFI_HANDLE ImageHandle
,
125 IN EFI_SYSTEM_TABLE
*SystemTable
132 // SMM driver depends on the SMM BASE protocol.
133 // the SMM driver must be success to locate protocol.
135 ASSERT (gBS
!= NULL
);
136 Status
= gBS
->LocateProtocol (&gEfiSmmBaseProtocolGuid
, NULL
, (VOID
**) &mSmmBase
);
137 if (!EFI_ERROR (Status
)) {
138 mSmmBase
->InSmm (mSmmBase
, &InSmm
);
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 ();
152 gBS
->AllocatePool (EfiRuntimeServicesData
, sizeof (EFI_STATUS_CODE_DATA
) + EFI_STATUS_CODE_DATA_MAX_SIZE
, (VOID
**)&mStatusCodeData
);
153 ASSERT (NULL
!= mStatusCodeData
);
155 // Cache the report status code service
157 mReportStatusCode
= InternalGetReportStatusCode ();
160 // Register the call back of virtual address change
162 Status
= gBS
->CreateEvent (
163 EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE
,
165 ReportStatusCodeLibVirtualAddressChange
,
167 &mVirtualAddressChangeEvent
169 ASSERT_EFI_ERROR (Status
);
173 // Register the call back of virtual address change
175 Status
= gBS
->CreateEvent (
176 EVT_SIGNAL_EXIT_BOOT_SERVICES
,
178 ReportStatusCodeLibExitBootServices
,
180 &mExitBootServicesEvent
182 ASSERT_EFI_ERROR (Status
);
190 ReportStatusCodeLibDestruct (
191 IN EFI_HANDLE ImageHandle
,
192 IN EFI_SYSTEM_TABLE
*SystemTable
198 // Close SetVirtualAddressMap () notify function
200 ASSERT (gBS
!= NULL
);
201 Status
= gBS
->CloseEvent (mVirtualAddressChangeEvent
);
202 ASSERT_EFI_ERROR (Status
);
203 Status
= gBS
->CloseEvent (mExitBootServicesEvent
);
204 ASSERT_EFI_ERROR (Status
);
206 gBS
->FreePool (mStatusCodeData
);
213 Reports a status code with full parameters.
215 The function reports a status code. If ExtendedData is NULL and ExtendedDataSize
216 is 0, then an extended data buffer is not reported. If ExtendedData is not
217 NULL and ExtendedDataSize is not 0, then an extended data buffer is allocated.
218 ExtendedData is assumed not have the standard status code header, so this function
219 is responsible for allocating a buffer large enough for the standard header and
220 the extended data passed into this function. The standard header is filled in
221 with a GUID specified by ExtendedDataGuid. If ExtendedDataGuid is NULL, then a
222 GUID of gEfiStatusCodeSpecificDatauid is used. The status code is reported with
223 an instance specified by Instance and a caller ID specified by CallerId. If
224 CallerId is NULL, then a caller ID of gEfiCallerIdGuid is used.
226 ReportStatusCodeEx()must actively prevent recursion. If ReportStatusCodeEx()
227 is called while processing another any other Report Status Code Library function,
228 then ReportStatusCodeEx() must return EFI_DEVICE_ERROR immediately.
230 If ExtendedData is NULL and ExtendedDataSize is not zero, then ASSERT().
231 If ExtendedData is not NULL and ExtendedDataSize is zero, then ASSERT().
233 @param Type Status code type.
234 @param Value Status code value.
235 @param Instance Status code instance number.
236 @param CallerId Pointer to a GUID that identifies the caller of this
237 function. If this parameter is NULL, then a caller
238 ID of gEfiCallerIdGuid is used.
239 @param ExtendedDataGuid Pointer to the GUID for the extended data buffer.
240 If this parameter is NULL, then a the status code
241 standard header is filled in with
242 gEfiStatusCodeSpecificDataGuid.
243 @param ExtendedData Pointer to the extended data buffer. This is an
244 optional parameter that may be NULL.
245 @param ExtendedDataSize The size, in bytes, of the extended data buffer.
247 @retval EFI_SUCCESS The status code was reported.
248 @retval EFI_OUT_OF_RESOURCES There were not enough resources to allocate
249 the extended data section if it was specified.
250 @retval EFI_UNSUPPORTED Report status code is not supported
255 InternalReportStatusCodeEx (
256 IN EFI_STATUS_CODE_TYPE Type
,
257 IN EFI_STATUS_CODE_VALUE Value
,
259 IN CONST EFI_GUID
*CallerId OPTIONAL
,
260 IN CONST EFI_GUID
*ExtendedDataGuid OPTIONAL
,
261 IN CONST VOID
*ExtendedData OPTIONAL
,
262 IN UINTN ExtendedDataSize
265 ASSERT (!((ExtendedData
== NULL
) && (ExtendedDataSize
!= 0)));
266 ASSERT (!((ExtendedData
!= NULL
) && (ExtendedDataSize
== 0)));
268 if (ExtendedDataSize
> EFI_STATUS_CODE_DATA_MAX_SIZE
) {
269 return EFI_OUT_OF_RESOURCES
;
273 // Fill in the extended data header
275 mStatusCodeData
->HeaderSize
= sizeof (EFI_STATUS_CODE_DATA
);
276 mStatusCodeData
->Size
= (UINT16
)ExtendedDataSize
;
277 if (ExtendedDataGuid
== NULL
) {
278 ExtendedDataGuid
= &gEfiStatusCodeSpecificDataGuid
;
280 CopyGuid (&mStatusCodeData
->Type
, ExtendedDataGuid
);
283 // Fill in the extended data buffer
285 CopyMem (mStatusCodeData
+ 1, ExtendedData
, ExtendedDataSize
);
288 // Report the status code
290 if (CallerId
== NULL
) {
291 CallerId
= &gEfiCallerIdGuid
;
293 return InternalReportStatusCode (Type
, Value
, Instance
, CallerId
, mStatusCodeData
);