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 EFI_BOOT_SERVICES
*mBS
;
42 BOOLEAN mHaveExitedBootServices
= FALSE
;
45 Locatet he report status code service.
47 @return EFI_REPORT_STATUS_CODE function point to
50 EFI_REPORT_STATUS_CODE
51 InternalGetReportStatusCode (
55 EFI_STATUS_CODE_PROTOCOL
*StatusCodeProtocol
;
59 return (EFI_REPORT_STATUS_CODE
) OemHookStatusCodeReport
;
60 } else if (mRT
->Hdr
.Revision
< 0x20000) {
61 return ((FRAMEWORK_EFI_RUNTIME_SERVICES
*)mRT
)->ReportStatusCode
;
62 } else if (!mHaveExitedBootServices
) {
63 Status
= mBS
->LocateProtocol (&gEfiStatusCodeRuntimeProtocolGuid
, NULL
, (VOID
**)&StatusCodeProtocol
);
64 if (!EFI_ERROR (Status
) && StatusCodeProtocol
!= NULL
) {
65 return StatusCodeProtocol
->ReportStatusCode
;
74 Fixup internal report status code protocol interface.
76 @param[in] Event The Event that is being processed
77 @param[in] Context Event Context
82 ReportStatusCodeLibVirtualAddressChange (
87 if (NULL
!= mReportStatusCode
) {
88 mRT
->ConvertPointer (0, (VOID
**) &mReportStatusCode
);
90 mRT
->ConvertPointer (0, (VOID
**) &mStatusCodeData
);
91 mRT
->ConvertPointer (0, (VOID
**) &mRT
);
95 Updatet the In Runtime Indicator.
97 @param[in] Event The Event that is being processed
98 @param[in] Context Event Context
103 ReportStatusCodeLibExitBootServices (
108 mHaveExitedBootServices
= TRUE
;
112 Intialize Report Status Code Lib.
114 @param[in] ImageHandle The firmware allocated handle for the EFI image.
115 @param[in] SystemTable A pointer to the EFI System Table.
117 @return EFI_STATUS always returns EFI_SUCCESS.
121 ReportStatusCodeLibConstruct (
122 IN EFI_HANDLE ImageHandle
,
123 IN EFI_SYSTEM_TABLE
*SystemTable
126 EFI_SMM_BASE_PROTOCOL
*SmmBase
;
129 mBS
= SystemTable
->BootServices
;
132 // SMM driver depends on the SMM BASE protocol.
133 // the SMM driver must be success to locate protocol.
135 ASSERT (mBS
!= NULL
);
136 Status
= mBS
->LocateProtocol (&gEfiSmmBaseProtocolGuid
, NULL
, (VOID
**) &SmmBase
);
137 if (!EFI_ERROR (Status
)) {
138 SmmBase
->InSmm (SmmBase
, &mInSmm
);
140 Status
= SmmBase
->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 mBS
->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
= mBS
->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
= mBS
->CreateEvent (
183 EVT_SIGNAL_EXIT_BOOT_SERVICES
,
185 ReportStatusCodeLibExitBootServices
,
187 &mExitBootServicesEvent
189 ASSERT_EFI_ERROR (Status
);
197 ReportStatusCodeLibDestruct (
198 IN EFI_HANDLE ImageHandle
,
199 IN EFI_SYSTEM_TABLE
*SystemTable
205 // Close SetVirtualAddressMap () notify function
207 ASSERT (mBS
!= NULL
);
208 Status
= mBS
->CloseEvent (mVirtualAddressChangeEvent
);
209 ASSERT_EFI_ERROR (Status
);
210 Status
= mBS
->CloseEvent (mExitBootServicesEvent
);
211 ASSERT_EFI_ERROR (Status
);
213 mBS
->FreePool (mStatusCodeData
);
220 Reports a status code with full parameters.
222 The function reports a status code. If ExtendedData is NULL and ExtendedDataSize
223 is 0, then an extended data buffer is not reported. If ExtendedData is not
224 NULL and ExtendedDataSize is not 0, then an extended data buffer is allocated.
225 ExtendedData is assumed not have the standard status code header, so this function
226 is responsible for allocating a buffer large enough for the standard header and
227 the extended data passed into this function. The standard header is filled in
228 with a GUID specified by ExtendedDataGuid. If ExtendedDataGuid is NULL, then a
229 GUID of gEfiStatusCodeSpecificDatauid is used. The status code is reported with
230 an instance specified by Instance and a caller ID specified by CallerId. If
231 CallerId is NULL, then a caller ID of gEfiCallerIdGuid is used.
233 ReportStatusCodeEx()must actively prevent recursion. If ReportStatusCodeEx()
234 is called while processing another any other Report Status Code Library function,
235 then ReportStatusCodeEx() must return EFI_DEVICE_ERROR immediately.
237 If ExtendedData is NULL and ExtendedDataSize is not zero, then ASSERT().
238 If ExtendedData is not NULL and ExtendedDataSize is zero, then ASSERT().
240 @param Type Status code type.
241 @param Value Status code value.
242 @param Instance Status code instance number.
243 @param CallerId Pointer to a GUID that identifies the caller of this
244 function. If this parameter is NULL, then a caller
245 ID of gEfiCallerIdGuid is used.
246 @param ExtendedDataGuid Pointer to the GUID for the extended data buffer.
247 If this parameter is NULL, then a the status code
248 standard header is filled in with
249 gEfiStatusCodeSpecificDataGuid.
250 @param ExtendedData Pointer to the extended data buffer. This is an
251 optional parameter that may be NULL.
252 @param ExtendedDataSize The size, in bytes, of the extended data buffer.
254 @retval EFI_SUCCESS The status code was reported.
255 @retval EFI_OUT_OF_RESOURCES There were not enough resources to allocate
256 the extended data section if it was specified.
257 @retval EFI_UNSUPPORTED Report status code is not supported
262 InternalReportStatusCodeEx (
263 IN EFI_STATUS_CODE_TYPE Type
,
264 IN EFI_STATUS_CODE_VALUE Value
,
266 IN CONST EFI_GUID
*CallerId OPTIONAL
,
267 IN CONST EFI_GUID
*ExtendedDataGuid OPTIONAL
,
268 IN CONST VOID
*ExtendedData OPTIONAL
,
269 IN UINTN ExtendedDataSize
272 ASSERT (!((ExtendedData
== NULL
) && (ExtendedDataSize
!= 0)));
273 ASSERT (!((ExtendedData
!= NULL
) && (ExtendedDataSize
== 0)));
275 if (ExtendedDataSize
> EFI_STATUS_CODE_DATA_MAX_SIZE
) {
276 return EFI_OUT_OF_RESOURCES
;
280 // Fill in the extended data header
282 mStatusCodeData
->HeaderSize
= sizeof (EFI_STATUS_CODE_DATA
);
283 mStatusCodeData
->Size
= (UINT16
)ExtendedDataSize
;
284 if (ExtendedDataGuid
== NULL
) {
285 ExtendedDataGuid
= &gEfiStatusCodeSpecificDataGuid
;
287 CopyGuid (&mStatusCodeData
->Type
, ExtendedDataGuid
);
290 // Fill in the extended data buffer
292 CopyMem (mStatusCodeData
+ 1, ExtendedData
, ExtendedDataSize
);
295 // Report the status code
297 if (CallerId
== NULL
) {
298 CallerId
= &gEfiCallerIdGuid
;
300 return InternalReportStatusCode (Type
, Value
, Instance
, CallerId
, mStatusCodeData
);