]>
Commit | Line | Data |
---|---|---|
e5516b49 | 1 | /** @file\r |
2 | Report Status Code Library for DXE Phase.\r | |
3 | \r | |
4 | Copyright (c) 2006 - 2007, 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 | //\r | |
18 | // Resources need by SMM runtime instance\r | |
19 | // \r | |
20 | #include <Library/OemHookStatusCodeLib.h>\r | |
21 | #include <Protocol/SmmBase.h>\r | |
22 | \r | |
23 | STATIC \r | |
24 | EFI_EVENT mVirtualAddressChangeEvent;\r | |
25 | \r | |
26 | STATIC \r | |
27 | EFI_EVENT mExitBootServicesEvent;\r | |
28 | \r | |
29 | STATIC\r | |
30 | EFI_STATUS_CODE_DATA *mStatusCodeData;\r | |
31 | \r | |
32 | STATIC\r | |
404d4e5c | 33 | BOOLEAN mInSmm;\r |
e5516b49 | 34 | \r |
b13b4473 | 35 | STATIC\r |
36 | EFI_RUNTIME_SERVICES *mRT;\r | |
37 | \r | |
e12848a3 | 38 | STATIC\r |
39 | EFI_BOOT_SERVICES *mBS;\r | |
40 | \r | |
e5516b49 | 41 | STATIC\r |
42 | BOOLEAN mHaveExitedBootServices = FALSE;\r | |
43 | \r | |
44 | /**\r | |
ed7752ec | 45 | Locate he report status code service.\r |
e5516b49 | 46 | \r |
47 | @return EFI_REPORT_STATUS_CODE function point to\r | |
48 | ReportStatusCode.\r | |
49 | **/\r | |
50 | EFI_REPORT_STATUS_CODE\r | |
51 | InternalGetReportStatusCode (\r | |
52 | VOID\r | |
53 | )\r | |
54 | {\r | |
55 | EFI_STATUS_CODE_PROTOCOL *StatusCodeProtocol;\r | |
e5516b49 | 56 | EFI_STATUS Status;\r |
57 | \r | |
404d4e5c | 58 | if (mInSmm) {\r |
59 | return (EFI_REPORT_STATUS_CODE) OemHookStatusCodeReport;\r | |
60 | } else if (mRT->Hdr.Revision < 0x20000) {\r | |
b13b4473 | 61 | return ((FRAMEWORK_EFI_RUNTIME_SERVICES*)mRT)->ReportStatusCode;\r |
e5516b49 | 62 | } else if (!mHaveExitedBootServices) {\r |
e12848a3 | 63 | Status = mBS->LocateProtocol (&gEfiStatusCodeRuntimeProtocolGuid, NULL, (VOID**)&StatusCodeProtocol);\r |
e5516b49 | 64 | if (!EFI_ERROR (Status) && StatusCodeProtocol != NULL) {\r |
65 | return StatusCodeProtocol->ReportStatusCode;\r | |
66 | }\r | |
67 | }\r | |
68 | \r | |
69 | return NULL;\r | |
70 | }\r | |
71 | \r | |
72 | \r | |
73 | /**\r | |
74 | Fixup internal report status code protocol interface.\r | |
75 | \r | |
76 | @param[in] Event The Event that is being processed\r | |
77 | @param[in] Context Event Context\r | |
78 | **/\r | |
79 | STATIC\r | |
80 | VOID\r | |
81 | EFIAPI\r | |
82 | ReportStatusCodeLibVirtualAddressChange (\r | |
83 | IN EFI_EVENT Event,\r | |
84 | IN VOID *Context\r | |
85 | )\r | |
86 | {\r | |
87 | if (NULL != mReportStatusCode) {\r | |
b13b4473 | 88 | mRT->ConvertPointer (0, (VOID **) &mReportStatusCode);\r |
e5516b49 | 89 | }\r |
b13b4473 | 90 | mRT->ConvertPointer (0, (VOID **) &mStatusCodeData);\r |
91 | mRT->ConvertPointer (0, (VOID **) &mRT);\r | |
e5516b49 | 92 | }\r |
93 | \r | |
94 | /**\r | |
ed7752ec | 95 | Update the In Runtime Indicator.\r |
e5516b49 | 96 | \r |
97 | @param[in] Event The Event that is being processed\r | |
98 | @param[in] Context Event Context\r | |
99 | **/\r | |
100 | STATIC\r | |
101 | VOID\r | |
102 | EFIAPI\r | |
103 | ReportStatusCodeLibExitBootServices (\r | |
104 | IN EFI_EVENT Event,\r | |
105 | IN VOID *Context\r | |
106 | )\r | |
107 | {\r | |
108 | mHaveExitedBootServices = TRUE;\r | |
109 | }\r | |
110 | \r | |
111 | /**\r | |
112 | Intialize Report Status Code Lib.\r | |
113 | \r | |
114 | @param[in] ImageHandle The firmware allocated handle for the EFI image.\r | |
115 | @param[in] SystemTable A pointer to the EFI System Table.\r | |
116 | \r | |
117 | @return EFI_STATUS always returns EFI_SUCCESS.\r | |
118 | **/\r | |
119 | EFI_STATUS\r | |
120 | EFIAPI\r | |
121 | ReportStatusCodeLibConstruct (\r | |
122 | IN EFI_HANDLE ImageHandle,\r | |
123 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
124 | )\r | |
125 | {\r | |
404d4e5c | 126 | EFI_SMM_BASE_PROTOCOL *SmmBase;\r |
127 | EFI_STATUS Status;\r | |
e5516b49 | 128 | \r |
e12848a3 | 129 | mBS = SystemTable->BootServices;\r |
130 | \r | |
e5516b49 | 131 | //\r |
132 | // SMM driver depends on the SMM BASE protocol.\r | |
133 | // the SMM driver must be success to locate protocol.\r | |
134 | // \r | |
e12848a3 | 135 | ASSERT (mBS != NULL);\r |
136 | Status = mBS->LocateProtocol (&gEfiSmmBaseProtocolGuid, NULL, (VOID **) &SmmBase);\r | |
e5516b49 | 137 | if (!EFI_ERROR (Status)) {\r |
404d4e5c | 138 | SmmBase->InSmm (SmmBase, &mInSmm);\r |
139 | if (mInSmm) {\r | |
140 | Status = SmmBase->SmmAllocatePool (\r | |
141 | SmmBase,\r | |
e5516b49 | 142 | EfiRuntimeServicesData, \r |
143 | sizeof (EFI_STATUS_CODE_DATA) + EFI_STATUS_CODE_DATA_MAX_SIZE, \r | |
144 | (VOID **) &mStatusCodeData\r | |
145 | );\r | |
146 | ASSERT_EFI_ERROR (Status);\r | |
147 | OemHookStatusCodeInitialize ();\r | |
148 | return EFI_SUCCESS;\r | |
149 | }\r | |
150 | }\r | |
151 | \r | |
b13b4473 | 152 | //\r |
153 | // Library should not use the gRT directly, since it\r | |
154 | // may be converted by other library instance.\r | |
155 | // \r | |
404d4e5c | 156 | mRT = gRT;\r |
157 | mInSmm = FALSE;\r | |
b13b4473 | 158 | \r |
e12848a3 | 159 | mBS->AllocatePool (EfiRuntimeServicesData, sizeof (EFI_STATUS_CODE_DATA) + EFI_STATUS_CODE_DATA_MAX_SIZE, (VOID **)&mStatusCodeData);\r |
e5516b49 | 160 | ASSERT (NULL != mStatusCodeData);\r |
161 | //\r | |
162 | // Cache the report status code service\r | |
163 | // \r | |
164 | mReportStatusCode = InternalGetReportStatusCode ();\r | |
165 | \r | |
166 | //\r | |
167 | // Register the call back of virtual address change\r | |
168 | // \r | |
e12848a3 | 169 | Status = mBS->CreateEvent (\r |
e5516b49 | 170 | EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE,\r |
171 | TPL_NOTIFY,\r | |
172 | ReportStatusCodeLibVirtualAddressChange,\r | |
173 | NULL,\r | |
174 | &mVirtualAddressChangeEvent\r | |
175 | );\r | |
176 | ASSERT_EFI_ERROR (Status);\r | |
177 | \r | |
178 | \r | |
179 | //\r | |
180 | // Register the call back of virtual address change\r | |
181 | // \r | |
e12848a3 | 182 | Status = mBS->CreateEvent (\r |
e5516b49 | 183 | EVT_SIGNAL_EXIT_BOOT_SERVICES,\r |
184 | TPL_NOTIFY,\r | |
185 | ReportStatusCodeLibExitBootServices,\r | |
186 | NULL,\r | |
187 | &mExitBootServicesEvent\r | |
188 | );\r | |
189 | ASSERT_EFI_ERROR (Status);\r | |
190 | \r | |
191 | return Status;\r | |
192 | }\r | |
193 | \r | |
ed7752ec | 194 | /**\r |
195 | Desctructor of library will close events.\r | |
196 | \r | |
197 | @param ImageHandle callder module's image handle\r | |
198 | @param SystemTable pointer to EFI system table.\r | |
199 | @return the status of close event.\r | |
200 | **/\r | |
e5516b49 | 201 | EFI_STATUS\r |
202 | EFIAPI\r | |
203 | ReportStatusCodeLibDestruct (\r | |
204 | IN EFI_HANDLE ImageHandle,\r | |
205 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
206 | )\r | |
207 | {\r | |
208 | EFI_STATUS Status;\r | |
209 | \r | |
210 | //\r | |
211 | // Close SetVirtualAddressMap () notify function\r | |
212 | //\r | |
e12848a3 | 213 | ASSERT (mBS != NULL);\r |
214 | Status = mBS->CloseEvent (mVirtualAddressChangeEvent);\r | |
e5516b49 | 215 | ASSERT_EFI_ERROR (Status);\r |
e12848a3 | 216 | Status = mBS->CloseEvent (mExitBootServicesEvent);\r |
e5516b49 | 217 | ASSERT_EFI_ERROR (Status);\r |
218 | \r | |
e12848a3 | 219 | mBS->FreePool (mStatusCodeData);\r |
e5516b49 | 220 | \r |
221 | return Status;\r | |
222 | }\r | |
223 | \r | |
e5516b49 | 224 | /**\r |
225 | Reports a status code with full parameters.\r | |
226 | \r | |
227 | The function reports a status code. If ExtendedData is NULL and ExtendedDataSize\r | |
228 | is 0, then an extended data buffer is not reported. If ExtendedData is not\r | |
229 | NULL and ExtendedDataSize is not 0, then an extended data buffer is allocated.\r | |
230 | ExtendedData is assumed not have the standard status code header, so this function\r | |
231 | is responsible for allocating a buffer large enough for the standard header and\r | |
232 | the extended data passed into this function. The standard header is filled in\r | |
233 | with a GUID specified by ExtendedDataGuid. If ExtendedDataGuid is NULL, then a\r | |
234 | GUID of gEfiStatusCodeSpecificDatauid is used. The status code is reported with\r | |
235 | an instance specified by Instance and a caller ID specified by CallerId. If\r | |
236 | CallerId is NULL, then a caller ID of gEfiCallerIdGuid is used.\r | |
237 | \r | |
238 | ReportStatusCodeEx()must actively prevent recursion. If ReportStatusCodeEx()\r | |
239 | is called while processing another any other Report Status Code Library function,\r | |
240 | then ReportStatusCodeEx() must return EFI_DEVICE_ERROR immediately.\r | |
241 | \r | |
242 | If ExtendedData is NULL and ExtendedDataSize is not zero, then ASSERT().\r | |
243 | If ExtendedData is not NULL and ExtendedDataSize is zero, then ASSERT().\r | |
244 | \r | |
245 | @param Type Status code type.\r | |
246 | @param Value Status code value.\r | |
247 | @param Instance Status code instance number.\r | |
248 | @param CallerId Pointer to a GUID that identifies the caller of this\r | |
249 | function. If this parameter is NULL, then a caller\r | |
250 | ID of gEfiCallerIdGuid is used.\r | |
251 | @param ExtendedDataGuid Pointer to the GUID for the extended data buffer.\r | |
252 | If this parameter is NULL, then a the status code\r | |
253 | standard header is filled in with\r | |
254 | gEfiStatusCodeSpecificDataGuid.\r | |
255 | @param ExtendedData Pointer to the extended data buffer. This is an\r | |
256 | optional parameter that may be NULL.\r | |
257 | @param ExtendedDataSize The size, in bytes, of the extended data buffer.\r | |
258 | \r | |
259 | @retval EFI_SUCCESS The status code was reported.\r | |
260 | @retval EFI_OUT_OF_RESOURCES There were not enough resources to allocate\r | |
261 | the extended data section if it was specified.\r | |
262 | @retval EFI_UNSUPPORTED Report status code is not supported\r | |
263 | \r | |
264 | **/\r | |
265 | EFI_STATUS\r | |
266 | EFIAPI\r | |
267 | InternalReportStatusCodeEx (\r | |
268 | IN EFI_STATUS_CODE_TYPE Type,\r | |
269 | IN EFI_STATUS_CODE_VALUE Value,\r | |
270 | IN UINT32 Instance,\r | |
271 | IN CONST EFI_GUID *CallerId OPTIONAL,\r | |
272 | IN CONST EFI_GUID *ExtendedDataGuid OPTIONAL,\r | |
273 | IN CONST VOID *ExtendedData OPTIONAL,\r | |
274 | IN UINTN ExtendedDataSize\r | |
275 | )\r | |
276 | {\r | |
277 | ASSERT (!((ExtendedData == NULL) && (ExtendedDataSize != 0)));\r | |
278 | ASSERT (!((ExtendedData != NULL) && (ExtendedDataSize == 0)));\r | |
279 | \r | |
280 | if (ExtendedDataSize > EFI_STATUS_CODE_DATA_MAX_SIZE) {\r | |
281 | return EFI_OUT_OF_RESOURCES;\r | |
282 | }\r | |
283 | \r | |
284 | //\r | |
285 | // Fill in the extended data header\r | |
286 | //\r | |
287 | mStatusCodeData->HeaderSize = sizeof (EFI_STATUS_CODE_DATA);\r | |
288 | mStatusCodeData->Size = (UINT16)ExtendedDataSize;\r | |
289 | if (ExtendedDataGuid == NULL) {\r | |
290 | ExtendedDataGuid = &gEfiStatusCodeSpecificDataGuid;\r | |
291 | }\r | |
292 | CopyGuid (&mStatusCodeData->Type, ExtendedDataGuid);\r | |
293 | \r | |
294 | //\r | |
295 | // Fill in the extended data buffer\r | |
296 | //\r | |
297 | CopyMem (mStatusCodeData + 1, ExtendedData, ExtendedDataSize);\r | |
298 | \r | |
299 | //\r | |
300 | // Report the status code\r | |
301 | //\r | |
302 | if (CallerId == NULL) {\r | |
303 | CallerId = &gEfiCallerIdGuid;\r | |
304 | }\r | |
305 | return InternalReportStatusCode (Type, Value, Instance, CallerId, mStatusCodeData);\r | |
306 | }\r | |
ed7752ec | 307 | \r |