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