]> git.proxmox.com Git - mirror_edk2.git/blame - IntelFrameworkModulePkg/Universal/StatusCode/RuntimeDxe/StatusCodeRuntimeDxe.c
roll back last check-in.
[mirror_edk2.git] / IntelFrameworkModulePkg / Universal / StatusCode / RuntimeDxe / StatusCodeRuntimeDxe.c
CommitLineData
c8126ad9 1/** @file\r
2 Status code driver for IA32/X64/EBC architecture.\r
3\r
180a5a35
HT
4 Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.<BR>\r
5 This program and the accompanying materials\r
ececc2eb 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
c8126ad9 12\r
c8126ad9 13**/\r
14\r
20e7a774 15#include "StatusCodeRuntimeDxe.h"\r
c8126ad9 16\r
a8cbf345 17EFI_EVENT mVirtualAddressChangeEvent = NULL;\r
18EFI_HANDLE mHandle = NULL;\r
c8126ad9 19\r
20//\r
21// Declaration of status code protocol.\r
22//\r
c8126ad9 23EFI_STATUS_CODE_PROTOCOL mEfiStatusCodeProtocol = {\r
24 ReportDispatcher\r
25};\r
26\r
27//\r
a8cbf345 28// Report operation nest status.\r
29// If it is set, then the report operation has nested.\r
c8126ad9 30//\r
a8cbf345 31UINT32 mStatusCodeNestStatus = 0;\r
c8126ad9 32\r
33/**\r
a8cbf345 34 Entry point of DXE Status Code Driver.\r
c8126ad9 35\r
a8cbf345 36 This function is the entry point of this DXE Status Code Driver.\r
37 It installs Status Code Runtime Protocol, and registers event for EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE.\r
ececc2eb 38\r
a8cbf345 39 @param ImageHandle The firmware allocated handle for the EFI image.\r
40 @param SystemTable A pointer to the EFI System Table.\r
41 \r
42 @retval EFI_SUCCESS The entry point is executed successfully.\r
c8126ad9 43\r
44**/\r
45EFI_STATUS\r
6ba0bc7c 46EFIAPI\r
20e7a774 47StatusCodeRuntimeDxeEntry (\r
c8126ad9 48 IN EFI_HANDLE ImageHandle,\r
49 IN EFI_SYSTEM_TABLE *SystemTable\r
50 )\r
51{\r
c8126ad9 52 EFI_STATUS Status;\r
53\r
54 //\r
55 // Dispatch initialization request to supported devices\r
56 //\r
57 InitializationDispatcherWorker ();\r
58\r
59 //\r
a8cbf345 60 // Install Status Code Runtime Protocol implementation as defined in PI Specification.\r
c8126ad9 61 //\r
62 Status = gBS->InstallMultipleProtocolInterfaces (\r
a8cbf345 63 &mHandle,\r
c8126ad9 64 &gEfiStatusCodeRuntimeProtocolGuid,\r
65 &mEfiStatusCodeProtocol,\r
66 NULL\r
67 );\r
68 ASSERT_EFI_ERROR (Status);\r
69\r
6a27a4eb 70 Status = gBS->CreateEventEx (\r
71 EVT_NOTIFY_SIGNAL,\r
ececc2eb 72 TPL_NOTIFY,\r
73 VirtualAddressChangeCallBack,\r
74 NULL,\r
a8cbf345 75 &gEfiEventVirtualAddressChangeGuid,\r
76 &mVirtualAddressChangeEvent\r
ececc2eb 77 );\r
78 ASSERT_EFI_ERROR (Status);\r
79\r
a8cbf345 80 return EFI_SUCCESS;\r
c8126ad9 81}\r
82\r
83/**\r
ececc2eb 84 Report status code to all supported device.\r
a8cbf345 85\r
86 This function implements EFI_STATUS_CODE_PROTOCOL.ReportStatusCode().\r
87 It calls into the workers which dispatches the platform specific listeners.\r
88\r
9484bb62 89 @param CodeType Indicates the type of status code being reported.\r
a8cbf345 90 @param Value Describes the current status of a hardware or software entity.\r
91 This included information about the class and subclass that is used to\r
92 classify the entity as well as an operation.\r
93 @param Instance The enumeration of a hardware or software entity within\r
94 the system. Valid instance numbers start with 1.\r
95 @param CallerId This optional parameter may be used to identify the caller.\r
96 This parameter allows the status code driver to apply different rules to\r
97 different callers.\r
98 @param Data This optional parameter may be used to pass additional data.\r
99\r
100 @retval EFI_SUCCESS The function completed successfully\r
101 @retval EFI_DEVICE_ERROR The function should not be completed due to a device error.\r
c8126ad9 102\r
103**/\r
ececc2eb 104EFI_STATUS\r
c8126ad9 105EFIAPI\r
106ReportDispatcher (\r
107 IN EFI_STATUS_CODE_TYPE CodeType,\r
108 IN EFI_STATUS_CODE_VALUE Value,\r
109 IN UINT32 Instance,\r
110 IN EFI_GUID *CallerId OPTIONAL,\r
111 IN EFI_STATUS_CODE_DATA *Data OPTIONAL\r
112 )\r
113{\r
114 //\r
115 // Use atom operation to avoid the reentant of report.\r
116 // If current status is not zero, then the function is reentrancy.\r
117 //\r
a8cbf345 118 if (InterlockedCompareExchange32 (&mStatusCodeNestStatus, 0, 1) == 1) {\r
c8126ad9 119 return EFI_DEVICE_ERROR;\r
120 }\r
121\r
d2c315e6 122 if (FeaturePcdGet (PcdStatusCodeUseSerial)) {\r
c8126ad9 123 SerialStatusCodeReportWorker (\r
124 CodeType,\r
125 Value,\r
126 Instance,\r
127 CallerId,\r
128 Data\r
129 );\r
130 }\r
d2c315e6 131 if (FeaturePcdGet (PcdStatusCodeUseMemory)) {\r
c8126ad9 132 RtMemoryStatusCodeReportWorker (\r
c8126ad9 133 CodeType,\r
134 Value,\r
135 Instance\r
136 );\r
137 }\r
138 if (FeaturePcdGet (PcdStatusCodeUseDataHub)) {\r
139 DataHubStatusCodeReportWorker (\r
140 CodeType,\r
141 Value,\r
142 Instance,\r
143 CallerId,\r
144 Data\r
145 );\r
146 }\r
147 if (FeaturePcdGet (PcdStatusCodeUseOEM)) {\r
a8cbf345 148 //\r
149 // Call OEM hook status code library API to report status code to OEM device\r
150 //\r
c8126ad9 151 OemHookStatusCodeReport (\r
152 CodeType,\r
153 Value,\r
154 Instance,\r
155 CallerId,\r
156 Data\r
157 );\r
158 }\r
159\r
160 //\r
161 // Restore the nest status of report\r
162 //\r
a8cbf345 163 InterlockedCompareExchange32 (&mStatusCodeNestStatus, 1, 0);\r
c8126ad9 164\r
165 return EFI_SUCCESS;\r
166}\r
167\r
168\r
169/**\r
ececc2eb 170 Virtual address change notification call back. It converts global pointer\r
c8126ad9 171 to virtual address.\r
172\r
173 @param Event Event whose notification function is being invoked.\r
174 @param Context Pointer to the notification function's context, which is\r
175 always zero in current implementation.\r
176\r
177**/\r
178VOID\r
179EFIAPI\r
180VirtualAddressChangeCallBack (\r
181 IN EFI_EVENT Event,\r
182 IN VOID *Context\r
183 )\r
184{\r
185 //\r
186 // Convert memory status code table to virtual address;\r
187 //\r
188 EfiConvertPointer (\r
ececc2eb 189 0,\r
a8cbf345 190 (VOID **) &mRtMemoryStatusCodeTable\r
c8126ad9 191 );\r
192}\r
193\r
20e7a774 194/**\r
195 Dispatch initialization request to sub status code devices based on \r
196 customized feature flags.\r
197 \r
198**/\r
199VOID\r
200InitializationDispatcherWorker (\r
201 VOID\r
202 )\r
203{\r
204 EFI_PEI_HOB_POINTERS Hob;\r
205 EFI_STATUS Status;\r
206 MEMORY_STATUSCODE_PACKET_HEADER *PacketHeader;\r
207 MEMORY_STATUSCODE_RECORD *Record;\r
208 UINTN ExpectedPacketIndex;\r
209 UINTN Index;\r
210 VOID *HobStart;\r
211\r
212 //\r
213 // If enable UseSerial, then initialize serial port.\r
214 // if enable UseRuntimeMemory, then initialize runtime memory status code worker.\r
215 // if enable UseDataHub, then initialize data hub status code worker.\r
216 //\r
d2c315e6 217 if (FeaturePcdGet (PcdStatusCodeUseSerial)) {\r
20e7a774 218 //\r
219 // Call Serial Port Lib API to initialize serial port.\r
220 //\r
221 Status = SerialPortInitialize ();\r
222 ASSERT_EFI_ERROR (Status);\r
223 }\r
d2c315e6 224 if (FeaturePcdGet (PcdStatusCodeUseMemory)) {\r
20e7a774 225 Status = RtMemoryStatusCodeInitializeWorker ();\r
226 ASSERT_EFI_ERROR (Status);\r
227 }\r
228 if (FeaturePcdGet (PcdStatusCodeUseDataHub)) {\r
445b3570 229 Status = DataHubStatusCodeInitializeWorker ();\r
230 ASSERT_EFI_ERROR (Status);\r
20e7a774 231 }\r
232 if (FeaturePcdGet (PcdStatusCodeUseOEM)) {\r
233 //\r
234 // Call OEM hook status code library API to initialize OEM device for status code.\r
235 //\r
236 Status = OemHookStatusCodeInitialize ();\r
237 ASSERT_EFI_ERROR (Status);\r
238 }\r
239\r
240 //\r
241 // Replay Status code which saved in GUID'ed HOB to all supported devices. \r
242 //\r
d2c315e6
LG
243 if (FeaturePcdGet (PcdStatusCodeReplayIn)) {\r
244 // \r
245 // Journal GUID'ed HOBs to find all record entry, if found, \r
246 // then output record to support replay device.\r
247 //\r
248 ExpectedPacketIndex = 0;\r
249 Hob.Raw = GetFirstGuidHob (&gMemoryStatusCodeRecordGuid);\r
250 HobStart = Hob.Raw;\r
251 while (Hob.Raw != NULL) {\r
252 PacketHeader = (MEMORY_STATUSCODE_PACKET_HEADER *) GET_GUID_HOB_DATA (Hob.Guid);\r
253 if (PacketHeader->PacketIndex == ExpectedPacketIndex) {\r
254 Record = (MEMORY_STATUSCODE_RECORD *) (PacketHeader + 1);\r
255 for (Index = 0; Index < PacketHeader->RecordIndex; Index++) {\r
20e7a774 256 //\r
d2c315e6 257 // Dispatch records to devices based on feature flag.\r
20e7a774 258 //\r
d2c315e6
LG
259 if (FeaturePcdGet (PcdStatusCodeUseSerial)) {\r
260 SerialStatusCodeReportWorker (\r
261 Record[Index].CodeType,\r
262 Record[Index].Value,\r
263 Record[Index].Instance,\r
264 NULL,\r
265 NULL\r
266 );\r
267 }\r
268 if (FeaturePcdGet (PcdStatusCodeUseMemory)) {\r
269 RtMemoryStatusCodeReportWorker (\r
270 Record[Index].CodeType,\r
271 Record[Index].Value,\r
272 Record[Index].Instance\r
273 );\r
274 }\r
275 if (FeaturePcdGet (PcdStatusCodeUseDataHub)) {\r
276 DataHubStatusCodeReportWorker (\r
277 Record[Index].CodeType,\r
278 Record[Index].Value,\r
279 Record[Index].Instance,\r
280 NULL,\r
281 NULL\r
282 );\r
283 }\r
284 if (FeaturePcdGet (PcdStatusCodeUseOEM)) {\r
285 //\r
286 // Call OEM hook status code library API to report status code to OEM device\r
287 //\r
288 OemHookStatusCodeReport (\r
289 Record[Index].CodeType,\r
290 Record[Index].Value,\r
291 Record[Index].Instance,\r
292 NULL,\r
293 NULL\r
294 );\r
295 }\r
20e7a774 296 }\r
d2c315e6
LG
297 ExpectedPacketIndex++;\r
298 \r
299 //\r
300 // See whether there is gap of packet or not\r
301 //\r
302 if (HobStart != NULL) {\r
303 HobStart = NULL;\r
304 Hob.Raw = HobStart;\r
305 continue;\r
306 }\r
307 } else if (HobStart != NULL) {\r
308 //\r
309 // Cache the found packet for improve the performance\r
310 //\r
311 HobStart = Hob.Raw;\r
20e7a774 312 }\r
d2c315e6
LG
313 \r
314 Hob.Raw = GetNextGuidHob (&gMemoryStatusCodeRecordGuid, Hob.Raw);\r
20e7a774 315 }\r
20e7a774 316 }\r
317}\r