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