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