2 Library constructor & destructor, event handlers, and other internal worker functions.
4 Copyright (c) 2006 - 2009, 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"
17 EFI_EVENT mVirtualAddressChangeEvent
;
18 EFI_EVENT mExitBootServicesEvent
;
19 EFI_STATUS_CODE_DATA
*mStatusCodeData
;
21 EFI_SMM_BASE_PROTOCOL
*mSmmBase
;
22 EFI_RUNTIME_SERVICES
*mInternalRT
;
23 BOOLEAN mHaveExitedBootServices
= FALSE
;
24 EFI_REPORT_STATUS_CODE mReportStatusCode
= NULL
;
27 Locate the report status code service.
29 In SMM, it retrieves OemHookStatusCodeReport() from customized OEM Hook Status Code Lib.
30 Otherwise, it first tries to retrieve ReportStatusCode() in Runtime Services Table.
31 If not found, it then tries to retrieve ReportStatusCode() API of Report Status Code Protocol.
33 @return Function pointer to the report status code service.
34 NULL is returned if no status code service is available.
37 EFI_REPORT_STATUS_CODE
38 InternalGetReportStatusCode (
42 EFI_STATUS_CODE_PROTOCOL
*StatusCodeProtocol
;
46 return (EFI_REPORT_STATUS_CODE
) OemHookStatusCodeReport
;
47 } else if (mInternalRT
!= NULL
&& mInternalRT
->Hdr
.Revision
< 0x20000) {
48 return ((FRAMEWORK_EFI_RUNTIME_SERVICES
*)mInternalRT
)->ReportStatusCode
;
49 } else if (!mHaveExitedBootServices
) {
51 // Check gBS just in case. ReportStatusCode is called before gBS is initialized.
54 Status
= gBS
->LocateProtocol (&gEfiStatusCodeRuntimeProtocolGuid
, NULL
, (VOID
**)&StatusCodeProtocol
);
55 if (!EFI_ERROR (Status
) && StatusCodeProtocol
!= NULL
) {
56 return StatusCodeProtocol
->ReportStatusCode
;
65 Internal worker function that reports a status code through the status code service.
67 If status code service is not cached, then this function checks if status code service is
68 available in system. If status code service is not available, then EFI_UNSUPPORTED is
69 returned. If status code service is present, then it is cached in mReportStatusCode.
70 Finally this function reports status code through the status code service.
72 @param Type Status code type.
73 @param Value Status code value.
74 @param Instance Status code instance number.
75 @param CallerId Pointer to a GUID that identifies the caller of this
76 function. This is an optional parameter that may be
78 @param Data Pointer to the extended data buffer. This is an
79 optional parameter that may be NULL.
81 @retval EFI_SUCCESS The status code was reported.
82 @retval EFI_UNSUPPORTED Status code service is not available.
83 @retval EFI_UNSUPPORTED Status code type is not supported.
87 InternalReportStatusCode (
88 IN EFI_STATUS_CODE_TYPE Type
,
89 IN EFI_STATUS_CODE_VALUE Value
,
91 IN CONST EFI_GUID
*CallerId OPTIONAL
,
92 IN EFI_STATUS_CODE_DATA
*Data OPTIONAL
95 if ((ReportProgressCodeEnabled() && ((Type
) & EFI_STATUS_CODE_TYPE_MASK
) == EFI_PROGRESS_CODE
) ||
96 (ReportErrorCodeEnabled() && ((Type
) & EFI_STATUS_CODE_TYPE_MASK
) == EFI_ERROR_CODE
) ||
97 (ReportDebugCodeEnabled() && ((Type
) & EFI_STATUS_CODE_TYPE_MASK
) == EFI_DEBUG_CODE
)) {
99 // If mReportStatusCode is NULL, then check if status code service is available in system.
101 if (mReportStatusCode
== NULL
) {
102 mReportStatusCode
= InternalGetReportStatusCode ();
103 if (mReportStatusCode
== NULL
) {
104 return EFI_UNSUPPORTED
;
109 // A status code service is present in system, so pass in all the parameters to the service.
111 return (*mReportStatusCode
) (Type
, Value
, Instance
, (EFI_GUID
*)CallerId
, Data
);
114 return EFI_UNSUPPORTED
;
118 Notification function of EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE.
120 @param Event Event whose notification function is being invoked.
121 @param Context Pointer to the notification function's context
126 ReportStatusCodeLibVirtualAddressChange (
131 if (mReportStatusCode
!= NULL
) {
132 mInternalRT
->ConvertPointer (0, (VOID
**) &mReportStatusCode
);
134 mInternalRT
->ConvertPointer (0, (VOID
**) &mStatusCodeData
);
135 mInternalRT
->ConvertPointer (0, (VOID
**) &mInternalRT
);
139 Notification function of EVT_SIGNAL_EXIT_BOOT_SERVICES.
141 @param Event Event whose notification function is being invoked.
142 @param Context Pointer to the notification function's context
147 ReportStatusCodeLibExitBootServices (
152 mHaveExitedBootServices
= TRUE
;
156 The constructor function of SMM Runtime DXE Report Status Code Lib.
158 This function allocates memory for extended status code data, caches
159 the report status code service, and registers events.
161 @param ImageHandle The firmware allocated handle for the EFI image.
162 @param SystemTable A pointer to the EFI System Table.
164 @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.
169 ReportStatusCodeLibConstruct (
170 IN EFI_HANDLE ImageHandle
,
171 IN EFI_SYSTEM_TABLE
*SystemTable
177 // If in SMM mode, then allocates memory from SMRAM for extended status code data.
179 Status
= gBS
->LocateProtocol (&gEfiSmmBaseProtocolGuid
, NULL
, (VOID
**) &mSmmBase
);
180 if (!EFI_ERROR (Status
)) {
181 mSmmBase
->InSmm (mSmmBase
, &mInSmm
);
183 Status
= mSmmBase
->SmmAllocatePool (
185 EfiRuntimeServicesData
,
186 sizeof (EFI_STATUS_CODE_DATA
) + EFI_STATUS_CODE_DATA_MAX_SIZE
,
187 (VOID
**) &mStatusCodeData
189 ASSERT_EFI_ERROR (Status
);
190 OemHookStatusCodeInitialize ();
197 // If not in SMM mode, then allocate runtime memory for extended status code data.
199 // Library should not use the gRT directly, for it may be converted by other library instance.
204 mStatusCodeData
= AllocateRuntimePool (sizeof (EFI_STATUS_CODE_DATA
) + EFI_STATUS_CODE_DATA_MAX_SIZE
);
205 ASSERT (mStatusCodeData
!= NULL
);
207 // Cache the report status code service
209 mReportStatusCode
= InternalGetReportStatusCode ();
212 // Register notify function for EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE
214 Status
= gBS
->CreateEventEx (
217 ReportStatusCodeLibVirtualAddressChange
,
219 &gEfiEventVirtualAddressChangeGuid
,
220 &mVirtualAddressChangeEvent
222 ASSERT_EFI_ERROR (Status
);
225 // Register notify function for EVT_SIGNAL_EXIT_BOOT_SERVICES
227 Status
= gBS
->CreateEventEx (
230 ReportStatusCodeLibExitBootServices
,
232 &gEfiEventExitBootServicesGuid
,
233 &mExitBootServicesEvent
235 ASSERT_EFI_ERROR (Status
);
241 The destructor function of SMM Runtime DXE Report Status Code Lib.
243 The destructor function frees memory allocated by constructor, and closes related events.
244 It will ASSERT() if that related operation fails and it will always return EFI_SUCCESS.
246 @param ImageHandle The firmware allocated handle for the EFI image.
247 @param SystemTable A pointer to the EFI System Table.
249 @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.
254 ReportStatusCodeLibDestruct (
255 IN EFI_HANDLE ImageHandle
,
256 IN EFI_SYSTEM_TABLE
*SystemTable
262 ASSERT (gBS
!= NULL
);
263 Status
= gBS
->CloseEvent (mVirtualAddressChangeEvent
);
264 ASSERT_EFI_ERROR (Status
);
265 Status
= gBS
->CloseEvent (mExitBootServicesEvent
);
266 ASSERT_EFI_ERROR (Status
);
268 FreePool (mStatusCodeData
);
270 mSmmBase
->SmmFreePool (mSmmBase
, mStatusCodeData
);