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
;
20 EFI_RUNTIME_SERVICES
*mInternalRT
;
21 BOOLEAN mHaveExitedBootServices
= FALSE
;
22 EFI_REPORT_STATUS_CODE mReportStatusCode
= NULL
;
25 Locate the report status code service.
27 It first tries to retrieve ReportStatusCode() in Runtime Services Table.
28 If not found, it then tries to retrieve ReportStatusCode() API of Report Status Code Protocol.
30 @return Function pointer to the report status code service.
31 NULL is returned if no status code service is available.
34 EFI_REPORT_STATUS_CODE
35 InternalGetReportStatusCode (
39 EFI_STATUS_CODE_PROTOCOL
*StatusCodeProtocol
;
42 if (!mHaveExitedBootServices
) {
44 // Check gBS just in case. ReportStatusCode is called before gBS is initialized.
47 Status
= gBS
->LocateProtocol (&gEfiStatusCodeRuntimeProtocolGuid
, NULL
, (VOID
**) &StatusCodeProtocol
);
48 if (!EFI_ERROR (Status
) && StatusCodeProtocol
!= NULL
) {
49 return StatusCodeProtocol
->ReportStatusCode
;
58 Internal worker function that reports a status code through the status code service.
60 If status code service is not cached, then this function checks if status code service is
61 available in system. If status code service is not available, then EFI_UNSUPPORTED is
62 returned. If status code service is present, then it is cached in mReportStatusCode.
63 Finally this function reports status code through the status code service.
65 @param Type Status code type.
66 @param Value Status code value.
67 @param Instance Status code instance number.
68 @param CallerId Pointer to a GUID that identifies the caller of this
69 function. This is an optional parameter that may be
71 @param Data Pointer to the extended data buffer. This is an
72 optional parameter that may be NULL.
74 @retval EFI_SUCCESS The status code was reported.
75 @retval EFI_UNSUPPORTED Status code service is not available.
76 @retval EFI_UNSUPPORTED Status code type is not supported.
80 InternalReportStatusCode (
81 IN EFI_STATUS_CODE_TYPE Type
,
82 IN EFI_STATUS_CODE_VALUE Value
,
84 IN CONST EFI_GUID
*CallerId OPTIONAL
,
85 IN EFI_STATUS_CODE_DATA
*Data OPTIONAL
88 if ((ReportProgressCodeEnabled() && ((Type
) & EFI_STATUS_CODE_TYPE_MASK
) == EFI_PROGRESS_CODE
) ||
89 (ReportErrorCodeEnabled() && ((Type
) & EFI_STATUS_CODE_TYPE_MASK
) == EFI_ERROR_CODE
) ||
90 (ReportDebugCodeEnabled() && ((Type
) & EFI_STATUS_CODE_TYPE_MASK
) == EFI_DEBUG_CODE
)) {
92 // If mReportStatusCode is NULL, then check if status code service is available in system.
94 if (mReportStatusCode
== NULL
) {
95 mReportStatusCode
= InternalGetReportStatusCode ();
96 if (mReportStatusCode
== NULL
) {
97 return EFI_UNSUPPORTED
;
102 // A status code service is present in system, so pass in all the parameters to the service.
104 return (*mReportStatusCode
) (Type
, Value
, Instance
, (EFI_GUID
*)CallerId
, Data
);
107 return EFI_UNSUPPORTED
;
111 Notification function of EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE.
113 @param Event Event whose notification function is being invoked.
114 @param Context Pointer to the notification function's context
119 ReportStatusCodeLibVirtualAddressChange (
124 if (mReportStatusCode
!= NULL
) {
125 mInternalRT
->ConvertPointer (0, (VOID
**) &mReportStatusCode
);
127 mInternalRT
->ConvertPointer (0, (VOID
**) &mStatusCodeData
);
128 mInternalRT
->ConvertPointer (0, (VOID
**) &mInternalRT
);
132 Notification function of EVT_SIGNAL_EXIT_BOOT_SERVICES.
134 @param Event Event whose notification function is being invoked.
135 @param Context Pointer to the notification function's context
140 ReportStatusCodeLibExitBootServices (
145 mHaveExitedBootServices
= TRUE
;
149 The constructor function of Runtime DXE Report Status Code Lib.
151 This function allocates memory for extended status code data, caches
152 the report status code service, and registers events.
154 @param ImageHandle The firmware allocated handle for the EFI image.
155 @param SystemTable A pointer to the EFI System Table.
157 @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.
162 ReportStatusCodeLibConstruct (
163 IN EFI_HANDLE ImageHandle
,
164 IN EFI_SYSTEM_TABLE
*SystemTable
170 // Library should not use the gRT directly, for it may be converted by other library instance.
174 mStatusCodeData
= AllocateRuntimePool (sizeof (EFI_STATUS_CODE_DATA
) + EFI_STATUS_CODE_DATA_MAX_SIZE
);
175 ASSERT (mStatusCodeData
!= NULL
);
177 // Cache the report status code service
179 mReportStatusCode
= InternalGetReportStatusCode ();
182 // Register notify function for EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE
184 Status
= gBS
->CreateEventEx (
187 ReportStatusCodeLibVirtualAddressChange
,
189 &gEfiEventVirtualAddressChangeGuid
,
190 &mVirtualAddressChangeEvent
192 ASSERT_EFI_ERROR (Status
);
195 // Register notify function for EVT_SIGNAL_EXIT_BOOT_SERVICES
197 Status
= gBS
->CreateEventEx (
200 ReportStatusCodeLibExitBootServices
,
202 &gEfiEventExitBootServicesGuid
,
203 &mExitBootServicesEvent
205 ASSERT_EFI_ERROR (Status
);
211 The destructor function of Runtime DXE Report Status Code Lib.
213 The destructor function frees memory allocated by constructor, and closes related events.
214 It will ASSERT() if that related operation fails and it will always return EFI_SUCCESS.
216 @param ImageHandle The firmware allocated handle for the EFI image.
217 @param SystemTable A pointer to the EFI System Table.
219 @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.
224 ReportStatusCodeLibDestruct (
225 IN EFI_HANDLE ImageHandle
,
226 IN EFI_SYSTEM_TABLE
*SystemTable
231 ASSERT (gBS
!= NULL
);
232 Status
= gBS
->CloseEvent (mVirtualAddressChangeEvent
);
233 ASSERT_EFI_ERROR (Status
);
234 Status
= gBS
->CloseEvent (mExitBootServicesEvent
);
235 ASSERT_EFI_ERROR (Status
);
237 FreePool (mStatusCodeData
);