]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - IntelFrameworkModulePkg/Library/SmmRuntimeDxeReportStatusCodeLibFramework/SmmRuntimeDxeSupport.c
1) Replace mBS with gBS from UefiBootServicesTablePointer Lib to avoid library instan...
[mirror_edk2.git] / IntelFrameworkModulePkg / Library / SmmRuntimeDxeReportStatusCodeLibFramework / SmmRuntimeDxeSupport.c
... / ...
CommitLineData
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
23STATIC \r
24EFI_EVENT mVirtualAddressChangeEvent;\r
25\r
26STATIC \r
27EFI_EVENT mExitBootServicesEvent;\r
28\r
29STATIC\r
30EFI_STATUS_CODE_DATA *mStatusCodeData;\r
31\r
32STATIC\r
33BOOLEAN mInSmm;\r
34\r
35EFI_SMM_BASE_PROTOCOL *mSmmBase;\r
36\r
37STATIC\r
38EFI_RUNTIME_SERVICES *mRT;\r
39\r
40STATIC\r
41BOOLEAN mHaveExitedBootServices = FALSE;\r
42\r
43/**\r
44 Locate he report status code service.\r
45\r
46 @return EFI_REPORT_STATUS_CODE function point to\r
47 ReportStatusCode.\r
48**/\r
49EFI_REPORT_STATUS_CODE\r
50InternalGetReportStatusCode (\r
51 VOID\r
52 )\r
53{\r
54 EFI_STATUS_CODE_PROTOCOL *StatusCodeProtocol;\r
55 EFI_STATUS Status;\r
56\r
57 if (mInSmm) {\r
58 return (EFI_REPORT_STATUS_CODE) OemHookStatusCodeReport;\r
59 } else if (mRT != NULL && mRT->Hdr.Revision < 0x20000) {\r
60 return ((FRAMEWORK_EFI_RUNTIME_SERVICES*)mRT)->ReportStatusCode;\r
61 } else if (!mHaveExitedBootServices) {\r
62 //\r
63 // Check gBS just in case. ReportStatusCode is called before gBS is initialized.\r
64 //\r
65 if (gBS != NULL) {\r
66 Status = gBS->LocateProtocol (&gEfiStatusCodeRuntimeProtocolGuid, NULL, (VOID**)&StatusCodeProtocol);\r
67 if (!EFI_ERROR (Status) && StatusCodeProtocol != NULL) {\r
68 return StatusCodeProtocol->ReportStatusCode;\r
69 }\r
70 }\r
71 }\r
72\r
73 return NULL;\r
74}\r
75\r
76\r
77/**\r
78 Fixup internal report status code protocol interface.\r
79\r
80 @param[in] Event The Event that is being processed\r
81 @param[in] Context Event Context\r
82**/\r
83STATIC\r
84VOID\r
85EFIAPI\r
86ReportStatusCodeLibVirtualAddressChange (\r
87 IN EFI_EVENT Event,\r
88 IN VOID *Context\r
89 )\r
90{\r
91 if (NULL != mReportStatusCode) {\r
92 mRT->ConvertPointer (0, (VOID **) &mReportStatusCode);\r
93 }\r
94 mRT->ConvertPointer (0, (VOID **) &mStatusCodeData);\r
95 mRT->ConvertPointer (0, (VOID **) &mRT);\r
96}\r
97\r
98/**\r
99 Update the In Runtime Indicator.\r
100\r
101 @param[in] Event The Event that is being processed\r
102 @param[in] Context Event Context\r
103**/\r
104STATIC\r
105VOID\r
106EFIAPI\r
107ReportStatusCodeLibExitBootServices (\r
108 IN EFI_EVENT Event,\r
109 IN VOID *Context\r
110 )\r
111{\r
112 mHaveExitedBootServices = TRUE;\r
113}\r
114\r
115/**\r
116 Intialize Report Status Code Lib.\r
117\r
118 @param[in] ImageHandle The firmware allocated handle for the EFI image.\r
119 @param[in] SystemTable A pointer to the EFI System Table.\r
120\r
121 @return EFI_STATUS always returns EFI_SUCCESS.\r
122**/\r
123EFI_STATUS\r
124EFIAPI\r
125ReportStatusCodeLibConstruct (\r
126 IN EFI_HANDLE ImageHandle,\r
127 IN EFI_SYSTEM_TABLE *SystemTable\r
128 )\r
129{\r
130 EFI_STATUS Status;\r
131\r
132 //\r
133 // SMM driver depends on the SMM BASE protocol.\r
134 // the SMM driver must be success to locate protocol.\r
135 // \r
136 Status = gBS->LocateProtocol (&gEfiSmmBaseProtocolGuid, NULL, (VOID **) &mSmmBase);\r
137 if (!EFI_ERROR (Status)) {\r
138 mSmmBase->InSmm (mSmmBase, &mInSmm);\r
139 if (mInSmm) {\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 //\r
153 // Library should not use the gRT directly, since it\r
154 // may be converted by other library instance.\r
155 // \r
156 mRT = gRT;\r
157 mInSmm = FALSE;\r
158\r
159 gBS->AllocatePool (EfiRuntimeServicesData, sizeof (EFI_STATUS_CODE_DATA) + EFI_STATUS_CODE_DATA_MAX_SIZE, (VOID **)&mStatusCodeData);\r
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
169 Status = gBS->CreateEvent (\r
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
182 Status = gBS->CreateEvent (\r
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
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
201EFI_STATUS\r
202EFIAPI\r
203ReportStatusCodeLibDestruct (\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 if (!mInSmm) {\r
211 //\r
212 // Close SetVirtualAddressMap () notify function\r
213 //\r
214 ASSERT (gBS != NULL);\r
215 Status = gBS->CloseEvent (mVirtualAddressChangeEvent);\r
216 ASSERT_EFI_ERROR (Status);\r
217 Status = gBS->CloseEvent (mExitBootServicesEvent);\r
218 ASSERT_EFI_ERROR (Status);\r
219\r
220 gBS->FreePool (mStatusCodeData);\r
221 } else {\r
222 mSmmBase->SmmFreePool (mSmmBase, mStatusCodeData);\r
223 }\r
224\r
225 return EFI_SUCCESS;\r
226}\r
227\r
228/**\r
229 Reports a status code with full parameters.\r
230\r
231 The function reports a status code. If ExtendedData is NULL and ExtendedDataSize\r
232 is 0, then an extended data buffer is not reported. If ExtendedData is not\r
233 NULL and ExtendedDataSize is not 0, then an extended data buffer is allocated.\r
234 ExtendedData is assumed not have the standard status code header, so this function\r
235 is responsible for allocating a buffer large enough for the standard header and\r
236 the extended data passed into this function. The standard header is filled in\r
237 with a GUID specified by ExtendedDataGuid. If ExtendedDataGuid is NULL, then a\r
238 GUID of gEfiStatusCodeSpecificDatauid is used. The status code is reported with\r
239 an instance specified by Instance and a caller ID specified by CallerId. If\r
240 CallerId is NULL, then a caller ID of gEfiCallerIdGuid is used.\r
241\r
242 ReportStatusCodeEx()must actively prevent recursion. If ReportStatusCodeEx()\r
243 is called while processing another any other Report Status Code Library function,\r
244 then ReportStatusCodeEx() must return EFI_DEVICE_ERROR immediately.\r
245\r
246 If ExtendedData is NULL and ExtendedDataSize is not zero, then ASSERT().\r
247 If ExtendedData is not NULL and ExtendedDataSize is zero, then ASSERT().\r
248\r
249 @param Type Status code type.\r
250 @param Value Status code value.\r
251 @param Instance Status code instance number.\r
252 @param CallerId Pointer to a GUID that identifies the caller of this\r
253 function. If this parameter is NULL, then a caller\r
254 ID of gEfiCallerIdGuid is used.\r
255 @param ExtendedDataGuid Pointer to the GUID for the extended data buffer.\r
256 If this parameter is NULL, then a the status code\r
257 standard header is filled in with\r
258 gEfiStatusCodeSpecificDataGuid.\r
259 @param ExtendedData Pointer to the extended data buffer. This is an\r
260 optional parameter that may be NULL.\r
261 @param ExtendedDataSize The size, in bytes, of the extended data buffer.\r
262\r
263 @retval EFI_SUCCESS The status code was reported.\r
264 @retval EFI_OUT_OF_RESOURCES There were not enough resources to allocate\r
265 the extended data section if it was specified.\r
266 @retval EFI_UNSUPPORTED Report status code is not supported\r
267\r
268**/\r
269EFI_STATUS\r
270EFIAPI\r
271InternalReportStatusCodeEx (\r
272 IN EFI_STATUS_CODE_TYPE Type,\r
273 IN EFI_STATUS_CODE_VALUE Value,\r
274 IN UINT32 Instance,\r
275 IN CONST EFI_GUID *CallerId OPTIONAL,\r
276 IN CONST EFI_GUID *ExtendedDataGuid OPTIONAL,\r
277 IN CONST VOID *ExtendedData OPTIONAL,\r
278 IN UINTN ExtendedDataSize\r
279 )\r
280{\r
281 ASSERT (!((ExtendedData == NULL) && (ExtendedDataSize != 0)));\r
282 ASSERT (!((ExtendedData != NULL) && (ExtendedDataSize == 0)));\r
283\r
284 if (ExtendedDataSize > EFI_STATUS_CODE_DATA_MAX_SIZE) {\r
285 return EFI_OUT_OF_RESOURCES;\r
286 }\r
287\r
288 //\r
289 // Fill in the extended data header\r
290 //\r
291 mStatusCodeData->HeaderSize = sizeof (EFI_STATUS_CODE_DATA);\r
292 mStatusCodeData->Size = (UINT16)ExtendedDataSize;\r
293 if (ExtendedDataGuid == NULL) {\r
294 ExtendedDataGuid = &gEfiStatusCodeSpecificDataGuid;\r
295 }\r
296 CopyGuid (&mStatusCodeData->Type, ExtendedDataGuid);\r
297\r
298 //\r
299 // Fill in the extended data buffer\r
300 //\r
301 CopyMem (mStatusCodeData + 1, ExtendedData, ExtendedDataSize);\r
302\r
303 //\r
304 // Report the status code\r
305 //\r
306 if (CallerId == NULL) {\r
307 CallerId = &gEfiCallerIdGuid;\r
308 }\r
309 return InternalReportStatusCode (Type, Value, Instance, CallerId, mStatusCodeData);\r
310}\r
311\r