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