1 /** @file 2 This driver will report some MMIO/IO resources to dxe core, extract smbios and acpi 3 tables from coreboot and install. 4 5 Copyright (c) 2014, 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 #include "CbSupportDxe.h" 16 17 UINTN mPmCtrlReg = 0; 18 /** 19 Reserve MMIO/IO resource in GCD 20 21 @param IsMMIO Flag of whether it is mmio resource or io resource. 22 @param GcdType Type of the space. 23 @param BaseAddress Base address of the space. 24 @param Length Length of the space. 25 @param Alignment Align with 2^Alignment 26 @param ImageHandle Handle for the image of this driver. 27 28 @retval EFI_SUCCESS Reserve successful 29 **/ 30 EFI_STATUS 31 CbReserveResourceInGcd ( 32 IN BOOLEAN IsMMIO, 33 IN UINTN GcdType, 34 IN EFI_PHYSICAL_ADDRESS BaseAddress, 35 IN UINT64 Length, 36 IN UINTN Alignment, 37 IN EFI_HANDLE ImageHandle 38 ) 39 { 40 EFI_STATUS Status; 41 42 if (IsMMIO) { 43 Status = gDS->AddMemorySpace ( 44 GcdType, 45 BaseAddress, 46 Length, 47 EFI_MEMORY_UC 48 ); 49 if (EFI_ERROR (Status)) { 50 DEBUG (( 51 EFI_D_ERROR, 52 "Failed to add memory space :0x%lx 0x%lx\n", 53 BaseAddress, 54 Length 55 )); 56 } 57 ASSERT_EFI_ERROR (Status); 58 Status = gDS->AllocateMemorySpace ( 59 EfiGcdAllocateAddress, 60 GcdType, 61 Alignment, 62 Length, 63 &BaseAddress, 64 ImageHandle, 65 NULL 66 ); 67 ASSERT_EFI_ERROR (Status); 68 } else { 69 Status = gDS->AddIoSpace ( 70 GcdType, 71 BaseAddress, 72 Length 73 ); 74 ASSERT_EFI_ERROR (Status); 75 Status = gDS->AllocateIoSpace ( 76 EfiGcdAllocateAddress, 77 GcdType, 78 Alignment, 79 Length, 80 &BaseAddress, 81 ImageHandle, 82 NULL 83 ); 84 ASSERT_EFI_ERROR (Status); 85 } 86 return Status; 87 } 88 89 /** 90 Notification function of EVT_GROUP_READY_TO_BOOT event group. 91 92 This is a notification function registered on EVT_GROUP_READY_TO_BOOT event group. 93 When the Boot Manager is about to load and execute a boot option, it reclaims variable 94 storage if free size is below the threshold. 95 96 @param Event Event whose notification function is being invoked. 97 @param Context Pointer to the notification function's context. 98 99 **/ 100 VOID 101 EFIAPI 102 OnReadyToBoot ( 103 IN EFI_EVENT Event, 104 IN VOID *Context 105 ) 106 { 107 // 108 // Enable SCI 109 // 110 IoOr16 (mPmCtrlReg, BIT0); 111 112 DEBUG ((EFI_D_ERROR, "Enable SCI bit at 0x%lx before boot\n", (UINT64)mPmCtrlReg)); 113 } 114 115 /** 116 Main entry for the Coreboot Support DXE module. 117 118 @param[in] ImageHandle The firmware allocated handle for the EFI image. 119 @param[in] SystemTable A pointer to the EFI System Table. 120 121 @retval EFI_SUCCESS The entry point is executed successfully. 122 @retval other Some error occurs when executing this entry point. 123 124 **/ 125 EFI_STATUS 126 EFIAPI 127 CbDxeEntryPoint ( 128 IN EFI_HANDLE ImageHandle, 129 IN EFI_SYSTEM_TABLE *SystemTable 130 ) 131 { 132 EFI_STATUS Status; 133 EFI_EVENT ReadyToBootEvent; 134 EFI_HOB_GUID_TYPE *GuidHob; 135 SYSTEM_TABLE_INFO *pSystemTableInfo; 136 ACPI_BOARD_INFO *pAcpiBoardInfo; 137 FRAME_BUFFER_INFO *FbInfo; 138 139 Status = EFI_SUCCESS; 140 // 141 // Report MMIO/IO Resources 142 // 143 Status = CbReserveResourceInGcd (TRUE, EfiGcdMemoryTypeMemoryMappedIo, 0xFEE00000, SIZE_1MB, 0, SystemTable); // LAPIC 144 ASSERT_EFI_ERROR (Status); 145 146 Status = CbReserveResourceInGcd (TRUE, EfiGcdMemoryTypeMemoryMappedIo, 0xFEC00000, SIZE_4KB, 0, SystemTable); // IOAPIC 147 ASSERT_EFI_ERROR (Status); 148 149 Status = CbReserveResourceInGcd (TRUE, EfiGcdMemoryTypeMemoryMappedIo, 0xFED00000, SIZE_1KB, 0, SystemTable); // HPET 150 ASSERT_EFI_ERROR (Status); 151 152 // 153 // Find the system table information guid hob 154 // 155 GuidHob = GetFirstGuidHob (&gUefiSystemTableInfoGuid); 156 ASSERT (GuidHob != NULL); 157 pSystemTableInfo = (SYSTEM_TABLE_INFO *)GET_GUID_HOB_DATA (GuidHob); 158 159 // 160 // Install Acpi Table 161 // 162 if (pSystemTableInfo->AcpiTableBase != 0 && pSystemTableInfo->AcpiTableSize != 0) { 163 DEBUG ((EFI_D_ERROR, "Install Acpi Table at 0x%lx, length 0x%x\n", pSystemTableInfo->AcpiTableBase, pSystemTableInfo->AcpiTableSize)); 164 Status = gBS->InstallConfigurationTable (&gEfiAcpiTableGuid, (VOID *)(UINTN)pSystemTableInfo->AcpiTableBase); 165 ASSERT_EFI_ERROR (Status); 166 } 167 168 // 169 // Install Smbios Table 170 // 171 if (pSystemTableInfo->SmbiosTableBase != 0 && pSystemTableInfo->SmbiosTableSize != 0) { 172 DEBUG ((EFI_D_ERROR, "Install Smbios Table at 0x%lx, length 0x%x\n", pSystemTableInfo->SmbiosTableBase, pSystemTableInfo->SmbiosTableSize)); 173 Status = gBS->InstallConfigurationTable (&gEfiSmbiosTableGuid, (VOID *)(UINTN)pSystemTableInfo->SmbiosTableBase); 174 ASSERT_EFI_ERROR (Status); 175 } 176 177 // 178 // Find the acpi board information guid hob 179 // 180 GuidHob = GetFirstGuidHob (&gUefiAcpiBoardInfoGuid); 181 ASSERT (GuidHob != NULL); 182 pAcpiBoardInfo = (ACPI_BOARD_INFO *)GET_GUID_HOB_DATA (GuidHob); 183 184 mPmCtrlReg = (UINTN)pAcpiBoardInfo->PmCtrlRegBase; 185 DEBUG ((EFI_D_ERROR, "PmCtrlReg at 0x%lx\n", (UINT64)mPmCtrlReg)); 186 187 // 188 // Find the frame buffer information and update PCDs 189 // 190 GuidHob = GetFirstGuidHob (&gUefiFrameBufferInfoGuid); 191 if (GuidHob != NULL) { 192 FbInfo = (FRAME_BUFFER_INFO *)GET_GUID_HOB_DATA (GuidHob); 193 Status = PcdSet32S (PcdVideoHorizontalResolution, FbInfo->HorizontalResolution); 194 ASSERT_EFI_ERROR (Status); 195 Status = PcdSet32S (PcdVideoVerticalResolution, FbInfo->VerticalResolution); 196 ASSERT_EFI_ERROR (Status); 197 Status = PcdSet32S (PcdSetupVideoHorizontalResolution, FbInfo->HorizontalResolution); 198 ASSERT_EFI_ERROR (Status); 199 Status = PcdSet32S (PcdSetupVideoVerticalResolution, FbInfo->VerticalResolution); 200 ASSERT_EFI_ERROR (Status); 201 } 202 203 // 204 // Register callback on the ready to boot event 205 // in order to enable SCI 206 // 207 ReadyToBootEvent = NULL; 208 Status = EfiCreateEventReadyToBootEx ( 209 TPL_CALLBACK, 210 OnReadyToBoot, 211 NULL, 212 &ReadyToBootEvent 213 ); 214 ASSERT_EFI_ERROR (Status); 215 216 return EFI_SUCCESS; 217 } 218 219