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