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