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 Index; 83 UINTN MaxRecordNumber; 84 85 // 86 // If enable UseSerial, then initialize serial port. 87 // if enable UseRuntimeMemory, then initialize runtime memory status code worker. 88 // 89 if (FeaturePcdGet (PcdStatusCodeUseSerial)) { 90 // 91 // Call Serial Port Lib API to initialize serial port. 92 // 93 Status = SerialPortInitialize (); 94 ASSERT_EFI_ERROR (Status); 95 } 96 if (FeaturePcdGet (PcdStatusCodeUseMemory)) { 97 Status = RtMemoryStatusCodeInitializeWorker (); 98 ASSERT_EFI_ERROR (Status); 99 } 100 101 // 102 // Replay Status code which saved in GUID'ed HOB to all supported devices. 103 // 104 if (FeaturePcdGet (PcdStatusCodeReplayIn)) { 105 // 106 // Journal GUID'ed HOBs to find all record entry, if found, 107 // then output record to support replay device. 108 // 109 Hob.Raw = GetFirstGuidHob (&gMemoryStatusCodeRecordGuid); 110 if (Hob.Raw != NULL) { 111 PacketHeader = (MEMORY_STATUSCODE_PACKET_HEADER *) GET_GUID_HOB_DATA (Hob.Guid); 112 Record = (MEMORY_STATUSCODE_RECORD *) (PacketHeader + 1); 113 MaxRecordNumber = (UINTN) PacketHeader->RecordIndex; 114 if (PacketHeader->PacketIndex > 0) { 115 // 116 // Record has been wrapped around. So, record number has arrived at max number. 117 // 118 MaxRecordNumber = (UINTN) PacketHeader->MaxRecordsNumber; 119 } 120 for (Index = 0; Index < MaxRecordNumber; Index++) { 121 // 122 // Dispatch records to devices based on feature flag. 123 // 124 if (FeaturePcdGet (PcdStatusCodeUseSerial)) { 125 SerialStatusCodeReportWorker ( 126 Record[Index].CodeType, 127 Record[Index].Value, 128 Record[Index].Instance, 129 NULL, 130 NULL 131 ); 132 } 133 if (FeaturePcdGet (PcdStatusCodeUseMemory)) { 134 RtMemoryStatusCodeReportWorker ( 135 Record[Index].CodeType, 136 Record[Index].Value, 137 Record[Index].Instance, 138 NULL, 139 NULL 140 ); 141 } 142 } 143 } 144 } 145 } 146 147 /** 148 Entry point of DXE Status Code Driver. 149 150 This function is the entry point of this DXE Status Code Driver. 151 It initializes registers status code handlers, and registers event for EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE. 152 153 @param ImageHandle The firmware allocated handle for the EFI image. 154 @param SystemTable A pointer to the EFI System Table. 155 156 @retval EFI_SUCCESS The entry point is executed successfully. 157 158 **/ 159 EFI_STATUS 160 EFIAPI 161 StatusCodeHandlerRuntimeDxeEntry ( 162 IN EFI_HANDLE ImageHandle, 163 IN EFI_SYSTEM_TABLE *SystemTable 164 ) 165 { 166 EFI_STATUS Status; 167 168 Status = gBS->LocateProtocol ( 169 &gEfiRscHandlerProtocolGuid, 170 NULL, 171 (VOID **) &mRscHandlerProtocol 172 ); 173 ASSERT_EFI_ERROR (Status); 174 175 // 176 // Dispatch initialization request to supported devices 177 // 178 InitializationDispatcherWorker (); 179 180 if (FeaturePcdGet (PcdStatusCodeUseSerial)) { 181 mRscHandlerProtocol->Register (SerialStatusCodeReportWorker, TPL_HIGH_LEVEL); 182 } 183 if (FeaturePcdGet (PcdStatusCodeUseMemory)) { 184 mRscHandlerProtocol->Register (RtMemoryStatusCodeReportWorker, TPL_HIGH_LEVEL); 185 } 186 187 Status = gBS->CreateEventEx ( 188 EVT_NOTIFY_SIGNAL, 189 TPL_NOTIFY, 190 UnregisterBootTimeHandlers, 191 NULL, 192 &gEfiEventExitBootServicesGuid, 193 &mExitBootServicesEvent 194 ); 195 196 Status = gBS->CreateEventEx ( 197 EVT_NOTIFY_SIGNAL, 198 TPL_NOTIFY, 199 VirtualAddressChangeCallBack, 200 NULL, 201 &gEfiEventVirtualAddressChangeGuid, 202 &mVirtualAddressChangeEvent 203 ); 204 ASSERT_EFI_ERROR (Status); 205 206 return EFI_SUCCESS; 207 } 208