]> git.proxmox.com Git - mirror_edk2.git/blame - IntelFrameworkModulePkg/Library/SmmRuntimeDxeReportStatusCodeLibFramework/SmmRuntimeDxeSupport.c
Fixed a typo in variable name
[mirror_edk2.git] / IntelFrameworkModulePkg / Library / SmmRuntimeDxeReportStatusCodeLibFramework / SmmRuntimeDxeSupport.c
CommitLineData
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
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
404d4e5c 33BOOLEAN mInSmm;\r
e5516b49 34\r
b13b4473 35STATIC\r
36EFI_RUNTIME_SERVICES *mRT;\r
37\r
e12848a3 38STATIC\r
39EFI_BOOT_SERVICES *mBS;\r
40\r
e5516b49 41STATIC\r
42BOOLEAN mHaveExitedBootServices = FALSE;\r
43\r
44/**\r
45 Locatet he report status code service.\r
46\r
47 @return EFI_REPORT_STATUS_CODE function point to\r
48 ReportStatusCode.\r
49**/\r
50EFI_REPORT_STATUS_CODE\r
51InternalGetReportStatusCode (\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
79STATIC\r
80VOID\r
81EFIAPI\r
82ReportStatusCodeLibVirtualAddressChange (\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
95 Updatet the In Runtime Indicator.\r
96\r
97 @param[in] Event The Event that is being processed\r
98 @param[in] Context Event Context\r
99**/\r
100STATIC\r
101VOID\r
102EFIAPI\r
103ReportStatusCodeLibExitBootServices (\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
119EFI_STATUS\r
120EFIAPI\r
121ReportStatusCodeLibConstruct (\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
194\r
195EFI_STATUS\r
196EFIAPI\r
197ReportStatusCodeLibDestruct (\r
198 IN EFI_HANDLE ImageHandle,\r
199 IN EFI_SYSTEM_TABLE *SystemTable\r
200 )\r
201{\r
202 EFI_STATUS Status;\r
203\r
204 //\r
205 // Close SetVirtualAddressMap () notify function\r
206 //\r
e12848a3 207 ASSERT (mBS != NULL);\r
208 Status = mBS->CloseEvent (mVirtualAddressChangeEvent);\r
e5516b49 209 ASSERT_EFI_ERROR (Status);\r
e12848a3 210 Status = mBS->CloseEvent (mExitBootServicesEvent);\r
e5516b49 211 ASSERT_EFI_ERROR (Status);\r
212\r
e12848a3 213 mBS->FreePool (mStatusCodeData);\r
e5516b49 214\r
215 return Status;\r
216}\r
217\r
218\r
219/**\r
220 Reports a status code with full parameters.\r
221\r
222 The function reports a status code. If ExtendedData is NULL and ExtendedDataSize\r
223 is 0, then an extended data buffer is not reported. If ExtendedData is not\r
224 NULL and ExtendedDataSize is not 0, then an extended data buffer is allocated.\r
225 ExtendedData is assumed not have the standard status code header, so this function\r
226 is responsible for allocating a buffer large enough for the standard header and\r
227 the extended data passed into this function. The standard header is filled in\r
228 with a GUID specified by ExtendedDataGuid. If ExtendedDataGuid is NULL, then a\r
229 GUID of gEfiStatusCodeSpecificDatauid is used. The status code is reported with\r
230 an instance specified by Instance and a caller ID specified by CallerId. If\r
231 CallerId is NULL, then a caller ID of gEfiCallerIdGuid is used.\r
232\r
233 ReportStatusCodeEx()must actively prevent recursion. If ReportStatusCodeEx()\r
234 is called while processing another any other Report Status Code Library function,\r
235 then ReportStatusCodeEx() must return EFI_DEVICE_ERROR immediately.\r
236\r
237 If ExtendedData is NULL and ExtendedDataSize is not zero, then ASSERT().\r
238 If ExtendedData is not NULL and ExtendedDataSize is zero, then ASSERT().\r
239\r
240 @param Type Status code type.\r
241 @param Value Status code value.\r
242 @param Instance Status code instance number.\r
243 @param CallerId Pointer to a GUID that identifies the caller of this\r
244 function. If this parameter is NULL, then a caller\r
245 ID of gEfiCallerIdGuid is used.\r
246 @param ExtendedDataGuid Pointer to the GUID for the extended data buffer.\r
247 If this parameter is NULL, then a the status code\r
248 standard header is filled in with\r
249 gEfiStatusCodeSpecificDataGuid.\r
250 @param ExtendedData Pointer to the extended data buffer. This is an\r
251 optional parameter that may be NULL.\r
252 @param ExtendedDataSize The size, in bytes, of the extended data buffer.\r
253\r
254 @retval EFI_SUCCESS The status code was reported.\r
255 @retval EFI_OUT_OF_RESOURCES There were not enough resources to allocate\r
256 the extended data section if it was specified.\r
257 @retval EFI_UNSUPPORTED Report status code is not supported\r
258\r
259**/\r
260EFI_STATUS\r
261EFIAPI\r
262InternalReportStatusCodeEx (\r
263 IN EFI_STATUS_CODE_TYPE Type,\r
264 IN EFI_STATUS_CODE_VALUE Value,\r
265 IN UINT32 Instance,\r
266 IN CONST EFI_GUID *CallerId OPTIONAL,\r
267 IN CONST EFI_GUID *ExtendedDataGuid OPTIONAL,\r
268 IN CONST VOID *ExtendedData OPTIONAL,\r
269 IN UINTN ExtendedDataSize\r
270 )\r
271{\r
272 ASSERT (!((ExtendedData == NULL) && (ExtendedDataSize != 0)));\r
273 ASSERT (!((ExtendedData != NULL) && (ExtendedDataSize == 0)));\r
274\r
275 if (ExtendedDataSize > EFI_STATUS_CODE_DATA_MAX_SIZE) {\r
276 return EFI_OUT_OF_RESOURCES;\r
277 }\r
278\r
279 //\r
280 // Fill in the extended data header\r
281 //\r
282 mStatusCodeData->HeaderSize = sizeof (EFI_STATUS_CODE_DATA);\r
283 mStatusCodeData->Size = (UINT16)ExtendedDataSize;\r
284 if (ExtendedDataGuid == NULL) {\r
285 ExtendedDataGuid = &gEfiStatusCodeSpecificDataGuid;\r
286 }\r
287 CopyGuid (&mStatusCodeData->Type, ExtendedDataGuid);\r
288\r
289 //\r
290 // Fill in the extended data buffer\r
291 //\r
292 CopyMem (mStatusCodeData + 1, ExtendedData, ExtendedDataSize);\r
293\r
294 //\r
295 // Report the status code\r
296 //\r
297 if (CallerId == NULL) {\r
298 CallerId = &gEfiCallerIdGuid;\r
299 }\r
300 return InternalReportStatusCode (Type, Value, Instance, CallerId, mStatusCodeData);\r
301}\r