]>
Commit | Line | Data |
---|---|---|
30c8ee5c | 1 | /** @file\r |
2 | Library constructor & destructor, event handlers, and other internal worker functions.\r | |
3 | \r | |
4 | Copyright (c) 2006 - 2009, Intel Corporation<BR>\r | |
5 | All rights reserved. This program and the accompanying materials\r | |
6 | are licensed and made available under the terms and conditions of the BSD License\r | |
7 | which accompanies this distribution. The full text of the license may be found at\r | |
8 | http://opensource.org/licenses/bsd-license.php\r | |
9 | \r | |
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
12 | \r | |
13 | **/\r | |
14 | \r | |
15 | #include "ReportStatusCodeLibInternal.h"\r | |
16 | \r | |
17 | EFI_EVENT mVirtualAddressChangeEvent;\r | |
18 | EFI_EVENT mExitBootServicesEvent;\r | |
19 | EFI_STATUS_CODE_DATA *mStatusCodeData;\r | |
20 | EFI_RUNTIME_SERVICES *mInternalRT;\r | |
21 | BOOLEAN mHaveExitedBootServices = FALSE;\r | |
22 | EFI_REPORT_STATUS_CODE mReportStatusCode = NULL;\r | |
23 | \r | |
24 | /**\r | |
25 | Locate the report status code service.\r | |
26 | \r | |
27 | It first tries to retrieve ReportStatusCode() in Runtime Services Table.\r | |
28 | If not found, it then tries to retrieve ReportStatusCode() API of Report Status Code Protocol.\r | |
29 | \r | |
30 | @return Function pointer to the report status code service.\r | |
31 | NULL is returned if no status code service is available.\r | |
32 | \r | |
33 | **/\r | |
34 | EFI_REPORT_STATUS_CODE\r | |
35 | InternalGetReportStatusCode (\r | |
36 | VOID\r | |
37 | )\r | |
38 | {\r | |
39 | EFI_STATUS_CODE_PROTOCOL *StatusCodeProtocol;\r | |
40 | EFI_STATUS Status;\r | |
41 | \r | |
42 | if (!mHaveExitedBootServices) {\r | |
43 | //\r | |
44 | // Check gBS just in case. ReportStatusCode is called before gBS is initialized.\r | |
45 | //\r | |
46 | if (gBS != NULL) {\r | |
47 | Status = gBS->LocateProtocol (&gEfiStatusCodeRuntimeProtocolGuid, NULL, (VOID**) &StatusCodeProtocol);\r | |
48 | if (!EFI_ERROR (Status) && StatusCodeProtocol != NULL) {\r | |
49 | return StatusCodeProtocol->ReportStatusCode;\r | |
50 | }\r | |
51 | }\r | |
52 | }\r | |
53 | \r | |
54 | return NULL;\r | |
55 | }\r | |
56 | \r | |
57 | /**\r | |
58 | Internal worker function that reports a status code through the status code service.\r | |
59 | \r | |
60 | If status code service is not cached, then this function checks if status code service is\r | |
61 | available in system. If status code service is not available, then EFI_UNSUPPORTED is\r | |
62 | returned. If status code service is present, then it is cached in mReportStatusCode.\r | |
63 | Finally this function reports status code through the status code service.\r | |
64 | \r | |
65 | @param Type Status code type.\r | |
66 | @param Value Status code value.\r | |
67 | @param Instance Status code instance number.\r | |
68 | @param CallerId Pointer to a GUID that identifies the caller of this\r | |
69 | function. This is an optional parameter that may be\r | |
70 | NULL.\r | |
71 | @param Data Pointer to the extended data buffer. This is an\r | |
72 | optional parameter that may be NULL.\r | |
73 | \r | |
74 | @retval EFI_SUCCESS The status code was reported.\r | |
75 | @retval EFI_UNSUPPORTED Status code service is not available.\r | |
76 | @retval EFI_UNSUPPORTED Status code type is not supported.\r | |
77 | \r | |
78 | **/\r | |
79 | EFI_STATUS\r | |
80 | InternalReportStatusCode (\r | |
81 | IN EFI_STATUS_CODE_TYPE Type,\r | |
82 | IN EFI_STATUS_CODE_VALUE Value,\r | |
83 | IN UINT32 Instance,\r | |
84 | IN CONST EFI_GUID *CallerId OPTIONAL,\r | |
85 | IN EFI_STATUS_CODE_DATA *Data OPTIONAL\r | |
86 | )\r | |
87 | {\r | |
88 | if ((ReportProgressCodeEnabled() && ((Type) & EFI_STATUS_CODE_TYPE_MASK) == EFI_PROGRESS_CODE) ||\r | |
89 | (ReportErrorCodeEnabled() && ((Type) & EFI_STATUS_CODE_TYPE_MASK) == EFI_ERROR_CODE) ||\r | |
90 | (ReportDebugCodeEnabled() && ((Type) & EFI_STATUS_CODE_TYPE_MASK) == EFI_DEBUG_CODE)) {\r | |
91 | //\r | |
92 | // If mReportStatusCode is NULL, then check if status code service is available in system.\r | |
93 | //\r | |
94 | if (mReportStatusCode == NULL) {\r | |
95 | mReportStatusCode = InternalGetReportStatusCode ();\r | |
96 | if (mReportStatusCode == NULL) {\r | |
97 | return EFI_UNSUPPORTED;\r | |
98 | }\r | |
99 | }\r | |
100 | \r | |
101 | //\r | |
102 | // A status code service is present in system, so pass in all the parameters to the service.\r | |
103 | //\r | |
104 | return (*mReportStatusCode) (Type, Value, Instance, (EFI_GUID *)CallerId, Data);\r | |
105 | }\r | |
106 | \r | |
107 | return EFI_UNSUPPORTED;\r | |
108 | }\r | |
109 | \r | |
110 | /**\r | |
111 | Notification function of EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE.\r | |
112 | \r | |
113 | @param Event Event whose notification function is being invoked.\r | |
114 | @param Context Pointer to the notification function's context\r | |
115 | \r | |
116 | **/\r | |
117 | VOID\r | |
118 | EFIAPI\r | |
119 | ReportStatusCodeLibVirtualAddressChange (\r | |
120 | IN EFI_EVENT Event,\r | |
121 | IN VOID *Context\r | |
122 | )\r | |
123 | {\r | |
124 | if (mReportStatusCode != NULL) {\r | |
125 | mInternalRT->ConvertPointer (0, (VOID **) &mReportStatusCode);\r | |
126 | }\r | |
127 | mInternalRT->ConvertPointer (0, (VOID **) &mStatusCodeData);\r | |
128 | mInternalRT->ConvertPointer (0, (VOID **) &mInternalRT);\r | |
129 | }\r | |
130 | \r | |
131 | /**\r | |
132 | Notification function of EVT_SIGNAL_EXIT_BOOT_SERVICES.\r | |
133 | \r | |
134 | @param Event Event whose notification function is being invoked.\r | |
135 | @param Context Pointer to the notification function's context\r | |
136 | \r | |
137 | **/\r | |
138 | VOID\r | |
139 | EFIAPI\r | |
140 | ReportStatusCodeLibExitBootServices (\r | |
141 | IN EFI_EVENT Event,\r | |
142 | IN VOID *Context\r | |
143 | )\r | |
144 | {\r | |
145 | mHaveExitedBootServices = TRUE;\r | |
146 | }\r | |
147 | \r | |
148 | /**\r | |
149 | The constructor function of Runtime DXE Report Status Code Lib.\r | |
150 | \r | |
151 | This function allocates memory for extended status code data, caches\r | |
152 | the report status code service, and registers events.\r | |
153 | \r | |
154 | @param ImageHandle The firmware allocated handle for the EFI image.\r | |
155 | @param SystemTable A pointer to the EFI System Table.\r | |
156 | \r | |
157 | @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.\r | |
158 | \r | |
159 | **/\r | |
160 | EFI_STATUS\r | |
161 | EFIAPI\r | |
162 | ReportStatusCodeLibConstruct (\r | |
163 | IN EFI_HANDLE ImageHandle,\r | |
164 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
165 | )\r | |
166 | {\r | |
167 | EFI_STATUS Status;\r | |
168 | \r | |
169 | //\r | |
170 | // Library should not use the gRT directly, for it may be converted by other library instance.\r | |
171 | // \r | |
172 | mInternalRT = gRT;\r | |
173 | \r | |
174 | mStatusCodeData = AllocateRuntimePool (sizeof (EFI_STATUS_CODE_DATA) + EFI_STATUS_CODE_DATA_MAX_SIZE);\r | |
175 | ASSERT (mStatusCodeData != NULL);\r | |
176 | //\r | |
177 | // Cache the report status code service\r | |
178 | // \r | |
179 | mReportStatusCode = InternalGetReportStatusCode ();\r | |
180 | \r | |
181 | //\r | |
182 | // Register notify function for EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE\r | |
183 | // \r | |
184 | Status = gBS->CreateEventEx (\r | |
185 | EVT_NOTIFY_SIGNAL,\r | |
186 | TPL_NOTIFY,\r | |
187 | ReportStatusCodeLibVirtualAddressChange,\r | |
188 | NULL,\r | |
189 | &gEfiEventVirtualAddressChangeGuid,\r | |
190 | &mVirtualAddressChangeEvent\r | |
191 | );\r | |
192 | ASSERT_EFI_ERROR (Status);\r | |
193 | \r | |
194 | //\r | |
195 | // Register notify function for EVT_SIGNAL_EXIT_BOOT_SERVICES\r | |
196 | // \r | |
197 | Status = gBS->CreateEventEx (\r | |
198 | EVT_NOTIFY_SIGNAL,\r | |
199 | TPL_NOTIFY,\r | |
200 | ReportStatusCodeLibExitBootServices,\r | |
201 | NULL,\r | |
202 | &gEfiEventExitBootServicesGuid,\r | |
203 | &mExitBootServicesEvent\r | |
204 | );\r | |
205 | ASSERT_EFI_ERROR (Status);\r | |
206 | \r | |
207 | return EFI_SUCCESS;\r | |
208 | }\r | |
209 | \r | |
210 | /**\r | |
211 | The destructor function of Runtime DXE Report Status Code Lib.\r | |
212 | \r | |
213 | The destructor function frees memory allocated by constructor, and closes related events.\r | |
214 | It will ASSERT() if that related operation fails and it will always return EFI_SUCCESS. \r | |
215 | \r | |
216 | @param ImageHandle The firmware allocated handle for the EFI image.\r | |
217 | @param SystemTable A pointer to the EFI System Table.\r | |
218 | \r | |
219 | @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.\r | |
220 | \r | |
221 | **/\r | |
222 | EFI_STATUS\r | |
223 | EFIAPI\r | |
224 | ReportStatusCodeLibDestruct (\r | |
225 | IN EFI_HANDLE ImageHandle,\r | |
226 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
227 | )\r | |
228 | {\r | |
229 | EFI_STATUS Status;\r | |
230 | \r | |
231 | ASSERT (gBS != NULL);\r | |
232 | Status = gBS->CloseEvent (mVirtualAddressChangeEvent);\r | |
233 | ASSERT_EFI_ERROR (Status);\r | |
234 | Status = gBS->CloseEvent (mExitBootServicesEvent);\r | |
235 | ASSERT_EFI_ERROR (Status);\r | |
236 | \r | |
237 | FreePool (mStatusCodeData);\r | |
238 | \r | |
239 | return EFI_SUCCESS;\r | |
240 | }\r | |
241 | \r |