]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/StatusCodeHandler/RuntimeDxe/StatusCodeHandlerRuntimeDxe.c
MdeModulePkg: Replace BSD License with BSD+Patent License
[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 - 2018, Intel Corporation. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
7
8 **/
9
10 #include "StatusCodeHandlerRuntimeDxe.h"
11
12 EFI_EVENT mVirtualAddressChangeEvent = NULL;
13 EFI_EVENT mExitBootServicesEvent = NULL;
14 EFI_RSC_HANDLER_PROTOCOL *mRscHandlerProtocol = NULL;
15
16 /**
17 Unregister status code callback functions only available at boot time from
18 report status code router when exiting boot services.
19
20 @param Event Event whose notification function is being invoked.
21 @param Context Pointer to the notification function's context, which is
22 always zero in current implementation.
23
24 **/
25 VOID
26 EFIAPI
27 UnregisterBootTimeHandlers (
28 IN EFI_EVENT Event,
29 IN VOID *Context
30 )
31 {
32 if (FeaturePcdGet (PcdStatusCodeUseSerial)) {
33 mRscHandlerProtocol->Unregister (SerialStatusCodeReportWorker);
34 }
35 }
36
37 /**
38 Virtual address change notification call back. It converts global pointer
39 to virtual address.
40
41 @param Event Event whose notification function is being invoked.
42 @param Context Pointer to the notification function's context, which is
43 always zero in current implementation.
44
45 **/
46 VOID
47 EFIAPI
48 VirtualAddressChangeCallBack (
49 IN EFI_EVENT Event,
50 IN VOID *Context
51 )
52 {
53 //
54 // Convert memory status code table to virtual address;
55 //
56 EfiConvertPointer (
57 0,
58 (VOID **) &mRtMemoryStatusCodeTable
59 );
60 }
61
62 /**
63 Dispatch initialization request to sub status code devices based on
64 customized feature flags.
65
66 **/
67 VOID
68 InitializationDispatcherWorker (
69 VOID
70 )
71 {
72 EFI_PEI_HOB_POINTERS Hob;
73 EFI_STATUS Status;
74 MEMORY_STATUSCODE_PACKET_HEADER *PacketHeader;
75 MEMORY_STATUSCODE_RECORD *Record;
76 UINTN Index;
77 UINTN MaxRecordNumber;
78
79 //
80 // If enable UseSerial, then initialize serial port.
81 // if enable UseRuntimeMemory, then initialize runtime memory status code worker.
82 //
83 if (FeaturePcdGet (PcdStatusCodeUseSerial)) {
84 //
85 // Call Serial Port Lib API to initialize serial port.
86 //
87 Status = SerialPortInitialize ();
88 ASSERT_EFI_ERROR (Status);
89 }
90 if (FeaturePcdGet (PcdStatusCodeUseMemory)) {
91 Status = RtMemoryStatusCodeInitializeWorker ();
92 ASSERT_EFI_ERROR (Status);
93 }
94
95 //
96 // Replay Status code which saved in GUID'ed HOB to all supported devices.
97 //
98 if (FeaturePcdGet (PcdStatusCodeReplayIn)) {
99 //
100 // Journal GUID'ed HOBs to find all record entry, if found,
101 // then output record to support replay device.
102 //
103 Hob.Raw = GetFirstGuidHob (&gMemoryStatusCodeRecordGuid);
104 if (Hob.Raw != NULL) {
105 PacketHeader = (MEMORY_STATUSCODE_PACKET_HEADER *) GET_GUID_HOB_DATA (Hob.Guid);
106 Record = (MEMORY_STATUSCODE_RECORD *) (PacketHeader + 1);
107 MaxRecordNumber = (UINTN) PacketHeader->RecordIndex;
108 if (PacketHeader->PacketIndex > 0) {
109 //
110 // Record has been wrapped around. So, record number has arrived at max number.
111 //
112 MaxRecordNumber = (UINTN) PacketHeader->MaxRecordsNumber;
113 }
114 for (Index = 0; Index < MaxRecordNumber; Index++) {
115 //
116 // Dispatch records to devices based on feature flag.
117 //
118 if (FeaturePcdGet (PcdStatusCodeUseSerial)) {
119 SerialStatusCodeReportWorker (
120 Record[Index].CodeType,
121 Record[Index].Value,
122 Record[Index].Instance,
123 NULL,
124 NULL
125 );
126 }
127 if (FeaturePcdGet (PcdStatusCodeUseMemory)) {
128 RtMemoryStatusCodeReportWorker (
129 Record[Index].CodeType,
130 Record[Index].Value,
131 Record[Index].Instance,
132 NULL,
133 NULL
134 );
135 }
136 }
137 }
138 }
139 }
140
141 /**
142 Entry point of DXE Status Code Driver.
143
144 This function is the entry point of this DXE Status Code Driver.
145 It initializes registers status code handlers, and registers event for EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE.
146
147 @param ImageHandle The firmware allocated handle for the EFI image.
148 @param SystemTable A pointer to the EFI System Table.
149
150 @retval EFI_SUCCESS The entry point is executed successfully.
151
152 **/
153 EFI_STATUS
154 EFIAPI
155 StatusCodeHandlerRuntimeDxeEntry (
156 IN EFI_HANDLE ImageHandle,
157 IN EFI_SYSTEM_TABLE *SystemTable
158 )
159 {
160 EFI_STATUS Status;
161
162 Status = gBS->LocateProtocol (
163 &gEfiRscHandlerProtocolGuid,
164 NULL,
165 (VOID **) &mRscHandlerProtocol
166 );
167 ASSERT_EFI_ERROR (Status);
168
169 //
170 // Dispatch initialization request to supported devices
171 //
172 InitializationDispatcherWorker ();
173
174 if (FeaturePcdGet (PcdStatusCodeUseSerial)) {
175 mRscHandlerProtocol->Register (SerialStatusCodeReportWorker, TPL_HIGH_LEVEL);
176 }
177 if (FeaturePcdGet (PcdStatusCodeUseMemory)) {
178 mRscHandlerProtocol->Register (RtMemoryStatusCodeReportWorker, TPL_HIGH_LEVEL);
179 }
180
181 Status = gBS->CreateEventEx (
182 EVT_NOTIFY_SIGNAL,
183 TPL_NOTIFY,
184 UnregisterBootTimeHandlers,
185 NULL,
186 &gEfiEventExitBootServicesGuid,
187 &mExitBootServicesEvent
188 );
189
190 Status = gBS->CreateEventEx (
191 EVT_NOTIFY_SIGNAL,
192 TPL_NOTIFY,
193 VirtualAddressChangeCallBack,
194 NULL,
195 &gEfiEventVirtualAddressChangeGuid,
196 &mVirtualAddressChangeEvent
197 );
198 ASSERT_EFI_ERROR (Status);
199
200 return EFI_SUCCESS;
201 }