]>
Commit | Line | Data |
---|---|---|
e5516b49 | 1 | /** @file\r |
29f766e4 | 2 | Library constructor & destructor, event handlers, and other internal worker functions.\r |
e5516b49 | 3 | \r |
3c28a728 | 4 | Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>\r |
180a5a35 | 5 | This program and the accompanying materials\r |
e5516b49 | 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 | |
19796be3 | 17 | EFI_EVENT mVirtualAddressChangeEvent;\r |
18 | EFI_EVENT mExitBootServicesEvent;\r | |
19 | EFI_STATUS_CODE_DATA *mStatusCodeData;\r | |
20 | BOOLEAN mInSmm;\r | |
21 | EFI_SMM_BASE_PROTOCOL *mSmmBase;\r | |
22 | EFI_RUNTIME_SERVICES *mInternalRT;\r | |
23 | BOOLEAN mHaveExitedBootServices = FALSE;\r | |
24 | EFI_REPORT_STATUS_CODE mReportStatusCode = NULL;\r | |
25 | EFI_SMM_STATUS_CODE_PROTOCOL *mSmmStatusCodeProtocol;\r | |
26 | \r | |
27 | /**\r | |
28 | Locates and caches SMM Status Code Protocol.\r | |
29 | \r | |
30 | **/\r | |
31 | VOID\r | |
32 | SmmStatusCodeInitialize (\r | |
33 | VOID\r | |
34 | )\r | |
35 | {\r | |
36 | EFI_STATUS Status;\r | |
37 | \r | |
38 | Status = gBS->LocateProtocol (&gEfiSmmStatusCodeProtocolGuid, NULL, (VOID **) &mSmmStatusCodeProtocol);\r | |
39 | if (EFI_ERROR (Status)) {\r | |
40 | mSmmStatusCodeProtocol = NULL;\r | |
41 | }\r | |
42 | }\r | |
43 | \r | |
44 | /**\r | |
45 | Report status code via SMM Status Code Protocol.\r | |
46 | \r | |
47 | @param Type Indicates the type of status code being reported.\r | |
48 | @param Value Describes the current status of a hardware or software entity. \r | |
49 | This included information about the class and subclass that is used to classify the entity \r | |
50 | as well as an operation. For progress codes, the operation is the current activity. \r | |
51 | For error codes, it is the exception. For debug codes, it is not defined at this time. \r | |
52 | @param Instance The enumeration of a hardware or software entity within the system. \r | |
53 | A system may contain multiple entities that match a class/subclass pairing. \r | |
54 | The instance differentiates between them. An instance of 0 indicates that instance information is unavailable, \r | |
55 | not meaningful, or not relevant. Valid instance numbers start with 1.\r | |
56 | @param CallerId This optional parameter may be used to identify the caller. \r | |
57 | This parameter allows the status code driver to apply different rules to different callers. \r | |
58 | @param Data This optional parameter may be used to pass additional data\r | |
59 | \r | |
60 | @retval EFI_SUCCESS Always return EFI_SUCCESS.\r | |
61 | \r | |
62 | **/\r | |
63 | EFI_STATUS\r | |
64 | SmmStatusCodeReport (\r | |
65 | IN EFI_STATUS_CODE_TYPE Type,\r | |
66 | IN EFI_STATUS_CODE_VALUE Value,\r | |
67 | IN UINT32 Instance,\r | |
68 | IN EFI_GUID *CallerId OPTIONAL,\r | |
69 | IN EFI_STATUS_CODE_DATA *Data OPTIONAL\r | |
70 | )\r | |
71 | {\r | |
72 | if (mSmmStatusCodeProtocol != NULL) {\r | |
73 | (mSmmStatusCodeProtocol->ReportStatusCode) (mSmmStatusCodeProtocol, Type, Value, Instance, CallerId, Data);\r | |
74 | }\r | |
75 | return EFI_SUCCESS;\r | |
76 | }\r | |
e5516b49 | 77 | \r |
29f766e4 | 78 | /**\r |
79 | Locate the report status code service.\r | |
b13b4473 | 80 | \r |
19796be3 | 81 | In SMM, it tries to retrieve SMM Status Code Protocol.\r |
29f766e4 | 82 | Otherwise, it first tries to retrieve ReportStatusCode() in Runtime Services Table.\r |
83 | If not found, it then tries to retrieve ReportStatusCode() API of Report Status Code Protocol.\r | |
e5516b49 | 84 | \r |
29f766e4 | 85 | @return Function pointer to the report status code service.\r |
86 | NULL is returned if no status code service is available.\r | |
e5516b49 | 87 | \r |
e5516b49 | 88 | **/\r |
89 | EFI_REPORT_STATUS_CODE\r | |
90 | InternalGetReportStatusCode (\r | |
91 | VOID\r | |
92 | )\r | |
93 | {\r | |
94 | EFI_STATUS_CODE_PROTOCOL *StatusCodeProtocol;\r | |
e5516b49 | 95 | EFI_STATUS Status;\r |
96 | \r | |
404d4e5c | 97 | if (mInSmm) {\r |
19796be3 | 98 | return (EFI_REPORT_STATUS_CODE) SmmStatusCodeReport;\r |
29f766e4 | 99 | } else if (mInternalRT != NULL && mInternalRT->Hdr.Revision < 0x20000) {\r |
100 | return ((FRAMEWORK_EFI_RUNTIME_SERVICES*)mInternalRT)->ReportStatusCode;\r | |
e5516b49 | 101 | } else if (!mHaveExitedBootServices) {\r |
9556741c | 102 | //\r |
103 | // Check gBS just in case. ReportStatusCode is called before gBS is initialized.\r | |
104 | //\r | |
105 | if (gBS != NULL) {\r | |
106 | Status = gBS->LocateProtocol (&gEfiStatusCodeRuntimeProtocolGuid, NULL, (VOID**)&StatusCodeProtocol);\r | |
107 | if (!EFI_ERROR (Status) && StatusCodeProtocol != NULL) {\r | |
108 | return StatusCodeProtocol->ReportStatusCode;\r | |
109 | }\r | |
e5516b49 | 110 | }\r |
111 | }\r | |
112 | \r | |
113 | return NULL;\r | |
114 | }\r | |
115 | \r | |
29f766e4 | 116 | /**\r |
117 | Internal worker function that reports a status code through the status code service.\r | |
118 | \r | |
119 | If status code service is not cached, then this function checks if status code service is\r | |
120 | available in system. If status code service is not available, then EFI_UNSUPPORTED is\r | |
121 | returned. If status code service is present, then it is cached in mReportStatusCode.\r | |
122 | Finally this function reports status code through the status code service.\r | |
123 | \r | |
124 | @param Type Status code type.\r | |
125 | @param Value Status code value.\r | |
126 | @param Instance Status code instance number.\r | |
127 | @param CallerId Pointer to a GUID that identifies the caller of this\r | |
128 | function. This is an optional parameter that may be\r | |
129 | NULL.\r | |
130 | @param Data Pointer to the extended data buffer. This is an\r | |
131 | optional parameter that may be NULL.\r | |
132 | \r | |
133 | @retval EFI_SUCCESS The status code was reported.\r | |
134 | @retval EFI_UNSUPPORTED Status code service is not available.\r | |
135 | @retval EFI_UNSUPPORTED Status code type is not supported.\r | |
136 | \r | |
137 | **/\r | |
138 | EFI_STATUS\r | |
139 | InternalReportStatusCode (\r | |
140 | IN EFI_STATUS_CODE_TYPE Type,\r | |
141 | IN EFI_STATUS_CODE_VALUE Value,\r | |
142 | IN UINT32 Instance,\r | |
143 | IN CONST EFI_GUID *CallerId OPTIONAL,\r | |
144 | IN EFI_STATUS_CODE_DATA *Data OPTIONAL\r | |
145 | )\r | |
146 | {\r | |
147 | if ((ReportProgressCodeEnabled() && ((Type) & EFI_STATUS_CODE_TYPE_MASK) == EFI_PROGRESS_CODE) ||\r | |
148 | (ReportErrorCodeEnabled() && ((Type) & EFI_STATUS_CODE_TYPE_MASK) == EFI_ERROR_CODE) ||\r | |
149 | (ReportDebugCodeEnabled() && ((Type) & EFI_STATUS_CODE_TYPE_MASK) == EFI_DEBUG_CODE)) {\r | |
150 | //\r | |
151 | // If mReportStatusCode is NULL, then check if status code service is available in system.\r | |
152 | //\r | |
153 | if (mReportStatusCode == NULL) {\r | |
154 | mReportStatusCode = InternalGetReportStatusCode ();\r | |
155 | if (mReportStatusCode == NULL) {\r | |
156 | return EFI_UNSUPPORTED;\r | |
157 | }\r | |
158 | }\r | |
159 | \r | |
160 | //\r | |
161 | // A status code service is present in system, so pass in all the parameters to the service.\r | |
162 | //\r | |
163 | return (*mReportStatusCode) (Type, Value, Instance, (EFI_GUID *)CallerId, Data);\r | |
164 | }\r | |
165 | \r | |
166 | return EFI_UNSUPPORTED;\r | |
167 | }\r | |
e5516b49 | 168 | \r |
169 | /**\r | |
29f766e4 | 170 | Notification function of EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE.\r |
171 | \r | |
172 | @param Event Event whose notification function is being invoked.\r | |
173 | @param Context Pointer to the notification function's context\r | |
e5516b49 | 174 | \r |
e5516b49 | 175 | **/\r |
e5516b49 | 176 | VOID\r |
177 | EFIAPI\r | |
178 | ReportStatusCodeLibVirtualAddressChange (\r | |
179 | IN EFI_EVENT Event,\r | |
180 | IN VOID *Context\r | |
181 | )\r | |
182 | {\r | |
29f766e4 | 183 | if (mReportStatusCode != NULL) {\r |
184 | mInternalRT->ConvertPointer (0, (VOID **) &mReportStatusCode);\r | |
e5516b49 | 185 | }\r |
29f766e4 | 186 | mInternalRT->ConvertPointer (0, (VOID **) &mStatusCodeData);\r |
187 | mInternalRT->ConvertPointer (0, (VOID **) &mInternalRT);\r | |
e5516b49 | 188 | }\r |
189 | \r | |
190 | /**\r | |
29f766e4 | 191 | Notification function of EVT_SIGNAL_EXIT_BOOT_SERVICES.\r |
192 | \r | |
193 | @param Event Event whose notification function is being invoked.\r | |
194 | @param Context Pointer to the notification function's context\r | |
e5516b49 | 195 | \r |
e5516b49 | 196 | **/\r |
e5516b49 | 197 | VOID\r |
198 | EFIAPI\r | |
199 | ReportStatusCodeLibExitBootServices (\r | |
200 | IN EFI_EVENT Event,\r | |
201 | IN VOID *Context\r | |
202 | )\r | |
203 | {\r | |
3c28a728 LG |
204 | //\r |
205 | // If mReportStatusCode is NULL, then see if a Status Code Protocol instance is present\r | |
206 | // in the handle database.\r | |
207 | //\r | |
208 | if (mReportStatusCode == NULL) {\r | |
209 | mReportStatusCode = InternalGetReportStatusCode ();\r | |
210 | }\r | |
211 | \r | |
e5516b49 | 212 | mHaveExitedBootServices = TRUE;\r |
213 | }\r | |
214 | \r | |
215 | /**\r | |
29f766e4 | 216 | The constructor function of SMM Runtime DXE Report Status Code Lib.\r |
e5516b49 | 217 | \r |
29f766e4 | 218 | This function allocates memory for extended status code data, caches\r |
219 | the report status code service, and registers events.\r | |
220 | \r | |
221 | @param ImageHandle The firmware allocated handle for the EFI image.\r | |
222 | @param SystemTable A pointer to the EFI System Table.\r | |
223 | \r | |
224 | @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.\r | |
e5516b49 | 225 | \r |
e5516b49 | 226 | **/\r |
227 | EFI_STATUS\r | |
228 | EFIAPI\r | |
229 | ReportStatusCodeLibConstruct (\r | |
230 | IN EFI_HANDLE ImageHandle,\r | |
231 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
232 | )\r | |
233 | {\r | |
29f766e4 | 234 | EFI_STATUS Status;\r |
e5516b49 | 235 | \r |
236 | //\r | |
29f766e4 | 237 | // If in SMM mode, then allocates memory from SMRAM for extended status code data.\r |
238 | //\r | |
9556741c | 239 | Status = gBS->LocateProtocol (&gEfiSmmBaseProtocolGuid, NULL, (VOID **) &mSmmBase);\r |
e5516b49 | 240 | if (!EFI_ERROR (Status)) {\r |
c0522bd7 | 241 | mSmmBase->InSmm (mSmmBase, &mInSmm);\r |
404d4e5c | 242 | if (mInSmm) {\r |
c0522bd7 | 243 | Status = mSmmBase->SmmAllocatePool (\r |
244 | mSmmBase,\r | |
e5516b49 | 245 | EfiRuntimeServicesData, \r |
246 | sizeof (EFI_STATUS_CODE_DATA) + EFI_STATUS_CODE_DATA_MAX_SIZE, \r | |
247 | (VOID **) &mStatusCodeData\r | |
248 | );\r | |
249 | ASSERT_EFI_ERROR (Status);\r | |
19796be3 | 250 | SmmStatusCodeInitialize ();\r |
e5516b49 | 251 | return EFI_SUCCESS;\r |
252 | }\r | |
253 | }\r | |
254 | \r | |
29f766e4 | 255 | \r |
b13b4473 | 256 | //\r |
29f766e4 | 257 | // If not in SMM mode, then allocate runtime memory for extended status code data.\r |
258 | //\r | |
259 | // Library should not use the gRT directly, for it may be converted by other library instance.\r | |
b13b4473 | 260 | // \r |
29f766e4 | 261 | mInternalRT = gRT;\r |
262 | mInSmm = FALSE;\r | |
b13b4473 | 263 | \r |
29f766e4 | 264 | mStatusCodeData = AllocateRuntimePool (sizeof (EFI_STATUS_CODE_DATA) + EFI_STATUS_CODE_DATA_MAX_SIZE);\r |
265 | ASSERT (mStatusCodeData != NULL);\r | |
e5516b49 | 266 | //\r |
267 | // Cache the report status code service\r | |
268 | // \r | |
269 | mReportStatusCode = InternalGetReportStatusCode ();\r | |
270 | \r | |
271 | //\r | |
29f766e4 | 272 | // Register notify function for EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE\r |
e5516b49 | 273 | // \r |
6a27a4eb | 274 | Status = gBS->CreateEventEx (\r |
275 | EVT_NOTIFY_SIGNAL,\r | |
e5516b49 | 276 | TPL_NOTIFY,\r |
277 | ReportStatusCodeLibVirtualAddressChange,\r | |
278 | NULL,\r | |
6a27a4eb | 279 | &gEfiEventVirtualAddressChangeGuid,\r |
e5516b49 | 280 | &mVirtualAddressChangeEvent\r |
281 | );\r | |
282 | ASSERT_EFI_ERROR (Status);\r | |
283 | \r | |
e5516b49 | 284 | //\r |
29f766e4 | 285 | // Register notify function for EVT_SIGNAL_EXIT_BOOT_SERVICES\r |
e5516b49 | 286 | // \r |
6a27a4eb | 287 | Status = gBS->CreateEventEx (\r |
288 | EVT_NOTIFY_SIGNAL,\r | |
e5516b49 | 289 | TPL_NOTIFY,\r |
290 | ReportStatusCodeLibExitBootServices,\r | |
291 | NULL,\r | |
6a27a4eb | 292 | &gEfiEventExitBootServicesGuid,\r |
e5516b49 | 293 | &mExitBootServicesEvent\r |
294 | );\r | |
295 | ASSERT_EFI_ERROR (Status);\r | |
296 | \r | |
29f766e4 | 297 | return EFI_SUCCESS;\r |
e5516b49 | 298 | }\r |
299 | \r | |
ed7752ec | 300 | /**\r |
29f766e4 | 301 | The destructor function of SMM Runtime DXE Report Status Code Lib.\r |
302 | \r | |
303 | The destructor function frees memory allocated by constructor, and closes related events.\r | |
304 | It will ASSERT() if that related operation fails and it will always return EFI_SUCCESS. \r | |
305 | \r | |
306 | @param ImageHandle The firmware allocated handle for the EFI image.\r | |
307 | @param SystemTable A pointer to the EFI System Table.\r | |
ed7752ec | 308 | \r |
29f766e4 | 309 | @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.\r |
310 | \r | |
ed7752ec | 311 | **/\r |
e5516b49 | 312 | EFI_STATUS\r |
313 | EFIAPI\r | |
314 | ReportStatusCodeLibDestruct (\r | |
315 | IN EFI_HANDLE ImageHandle,\r | |
316 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
317 | )\r | |
318 | {\r | |
319 | EFI_STATUS Status;\r | |
320 | \r | |
c0522bd7 | 321 | if (!mInSmm) {\r |
9556741c | 322 | ASSERT (gBS != NULL);\r |
323 | Status = gBS->CloseEvent (mVirtualAddressChangeEvent);\r | |
c0522bd7 | 324 | ASSERT_EFI_ERROR (Status);\r |
9556741c | 325 | Status = gBS->CloseEvent (mExitBootServicesEvent);\r |
c0522bd7 | 326 | ASSERT_EFI_ERROR (Status);\r |
327 | \r | |
29f766e4 | 328 | FreePool (mStatusCodeData);\r |
c0522bd7 | 329 | } else {\r |
330 | mSmmBase->SmmFreePool (mSmmBase, mStatusCodeData);\r | |
331 | }\r | |
e5516b49 | 332 | \r |
c0522bd7 | 333 | return EFI_SUCCESS;\r |
e5516b49 | 334 | }\r |
335 | \r |