]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/StatusCodeHandler/RuntimeDxe/StatusCodeHandlerRuntimeDxe.c
Update the copyright notice format
[mirror_edk2.git] / MdeModulePkg / Universal / StatusCodeHandler / RuntimeDxe / StatusCodeHandlerRuntimeDxe.c
CommitLineData
3af9b388 1/** @file\r
2 Status Code Handler Driver which produces general handlers and hook them\r
3 onto the DXE status code router.\r
4\r
e5eed7d3
HT
5 Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.<BR>\r
6 This program and the accompanying materials\r
3af9b388 7 are licensed and made available under the terms and conditions of the BSD License\r
8 which accompanies this distribution. The full text of the license may be found at\r
9 http://opensource.org/licenses/bsd-license.php\r
10\r
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
13\r
14**/\r
15\r
16#include "StatusCodeHandlerRuntimeDxe.h"\r
17\r
18EFI_EVENT mVirtualAddressChangeEvent = NULL;\r
19EFI_EVENT mExitBootServicesEvent = NULL;\r
20EFI_RSC_HANDLER_PROTOCOL *mRscHandlerProtocol = NULL;\r
21\r
22/**\r
23 Unregister status code callback functions only available at boot time from\r
24 report status code router when exiting boot services.\r
25\r
26 @param Event Event whose notification function is being invoked.\r
27 @param Context Pointer to the notification function's context, which is\r
28 always zero in current implementation.\r
29\r
30**/\r
31VOID\r
32EFIAPI\r
33UnregisterBootTimeHandlers (\r
34 IN EFI_EVENT Event,\r
35 IN VOID *Context\r
36 )\r
37{\r
38 if (FeaturePcdGet (PcdStatusCodeUseSerial)) {\r
39 mRscHandlerProtocol->Unregister (SerialStatusCodeReportWorker);\r
40 }\r
41}\r
42\r
43/**\r
44 Virtual address change notification call back. It converts global pointer\r
45 to virtual address.\r
46\r
47 @param Event Event whose notification function is being invoked.\r
48 @param Context Pointer to the notification function's context, which is\r
49 always zero in current implementation.\r
50\r
51**/\r
52VOID\r
53EFIAPI\r
54VirtualAddressChangeCallBack (\r
55 IN EFI_EVENT Event,\r
56 IN VOID *Context\r
57 )\r
58{\r
59 //\r
60 // Convert memory status code table to virtual address;\r
61 //\r
62 EfiConvertPointer (\r
63 0,\r
64 (VOID **) &mRtMemoryStatusCodeTable\r
65 );\r
66}\r
67\r
68/**\r
69 Dispatch initialization request to sub status code devices based on \r
70 customized feature flags.\r
71 \r
72**/\r
73VOID\r
74InitializationDispatcherWorker (\r
75 VOID\r
76 )\r
77{\r
78 EFI_PEI_HOB_POINTERS Hob;\r
79 EFI_STATUS Status;\r
80 MEMORY_STATUSCODE_PACKET_HEADER *PacketHeader;\r
81 MEMORY_STATUSCODE_RECORD *Record;\r
82 UINTN ExpectedPacketIndex;\r
83 UINTN Index;\r
84 VOID *HobStart;\r
85\r
86 //\r
87 // If enable UseSerial, then initialize serial port.\r
88 // if enable UseRuntimeMemory, then initialize runtime memory status code worker.\r
89 //\r
90 if (FeaturePcdGet (PcdStatusCodeUseSerial)) {\r
91 //\r
92 // Call Serial Port Lib API to initialize serial port.\r
93 //\r
94 Status = SerialPortInitialize ();\r
95 ASSERT_EFI_ERROR (Status);\r
96 }\r
97 if (FeaturePcdGet (PcdStatusCodeUseMemory)) {\r
98 Status = RtMemoryStatusCodeInitializeWorker ();\r
99 ASSERT_EFI_ERROR (Status);\r
100 }\r
101\r
102 //\r
103 // Replay Status code which saved in GUID'ed HOB to all supported devices. \r
104 //\r
105 if (FeaturePcdGet (PcdStatusCodeReplayIn)) {\r
106 // \r
107 // Journal GUID'ed HOBs to find all record entry, if found, \r
108 // then output record to support replay device.\r
109 //\r
110 ExpectedPacketIndex = 0;\r
111 Hob.Raw = GetFirstGuidHob (&gMemoryStatusCodeRecordGuid);\r
112 HobStart = Hob.Raw;\r
113 while (Hob.Raw != NULL) {\r
114 PacketHeader = (MEMORY_STATUSCODE_PACKET_HEADER *) GET_GUID_HOB_DATA (Hob.Guid);\r
115 if (PacketHeader->PacketIndex == ExpectedPacketIndex) {\r
116 Record = (MEMORY_STATUSCODE_RECORD *) (PacketHeader + 1);\r
117 for (Index = 0; Index < PacketHeader->RecordIndex; Index++) {\r
118 //\r
119 // Dispatch records to devices based on feature flag.\r
120 //\r
121 if (FeaturePcdGet (PcdStatusCodeUseSerial)) {\r
122 SerialStatusCodeReportWorker (\r
123 Record[Index].CodeType,\r
124 Record[Index].Value,\r
125 Record[Index].Instance,\r
126 NULL,\r
127 NULL\r
128 );\r
129 }\r
130 if (FeaturePcdGet (PcdStatusCodeUseMemory)) {\r
131 RtMemoryStatusCodeReportWorker (\r
132 Record[Index].CodeType,\r
133 Record[Index].Value,\r
134 Record[Index].Instance,\r
135 NULL,\r
136 NULL\r
137 );\r
138 }\r
139 }\r
140 ExpectedPacketIndex++;\r
141 \r
142 //\r
143 // See whether there is gap of packet or not\r
144 //\r
145 if (HobStart != NULL) {\r
146 HobStart = NULL;\r
147 Hob.Raw = HobStart;\r
148 continue;\r
149 }\r
150 } else if (HobStart != NULL) {\r
151 //\r
152 // Cache the found packet for improve the performance\r
153 //\r
154 HobStart = Hob.Raw;\r
155 }\r
156 \r
157 Hob.Raw = GetNextGuidHob (&gMemoryStatusCodeRecordGuid, Hob.Raw);\r
158 }\r
159 }\r
160}\r
161\r
162/**\r
163 Entry point of DXE Status Code Driver.\r
164\r
165 This function is the entry point of this DXE Status Code Driver.\r
166 It initializes registers status code handlers, and registers event for EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE.\r
167\r
168 @param ImageHandle The firmware allocated handle for the EFI image.\r
169 @param SystemTable A pointer to the EFI System Table.\r
170 \r
171 @retval EFI_SUCCESS The entry point is executed successfully.\r
172\r
173**/\r
174EFI_STATUS\r
175EFIAPI\r
176StatusCodeHandlerRuntimeDxeEntry (\r
177 IN EFI_HANDLE ImageHandle,\r
178 IN EFI_SYSTEM_TABLE *SystemTable\r
179 )\r
180{\r
181 EFI_STATUS Status;\r
182\r
183 Status = gBS->LocateProtocol (\r
184 &gEfiRscHandlerProtocolGuid,\r
185 NULL,\r
186 (VOID **) &mRscHandlerProtocol\r
187 );\r
188 ASSERT_EFI_ERROR (Status);\r
189\r
190 //\r
191 // Dispatch initialization request to supported devices\r
192 //\r
193 InitializationDispatcherWorker ();\r
194\r
195 if (FeaturePcdGet (PcdStatusCodeUseSerial)) {\r
196 mRscHandlerProtocol->Register (SerialStatusCodeReportWorker, TPL_HIGH_LEVEL);\r
197 }\r
198 if (FeaturePcdGet (PcdStatusCodeUseMemory)) {\r
199 mRscHandlerProtocol->Register (RtMemoryStatusCodeReportWorker, TPL_HIGH_LEVEL);\r
200 }\r
201\r
202 Status = gBS->CreateEventEx (\r
203 EVT_NOTIFY_SIGNAL,\r
204 TPL_NOTIFY,\r
205 UnregisterBootTimeHandlers,\r
206 NULL,\r
207 &gEfiEventExitBootServicesGuid,\r
208 &mExitBootServicesEvent\r
209 );\r
210\r
211 Status = gBS->CreateEventEx (\r
212 EVT_NOTIFY_SIGNAL,\r
213 TPL_NOTIFY,\r
214 VirtualAddressChangeCallBack,\r
215 NULL,\r
216 &gEfiEventVirtualAddressChangeGuid,\r
217 &mVirtualAddressChangeEvent\r
218 );\r
219 ASSERT_EFI_ERROR (Status);\r
220\r
221 return EFI_SUCCESS;\r
222}\r