1 /** @file
2 This driver will report some MMIO/IO resources to dxe core, extract smbios and acpi
3 tables from bootloader.
4
5 Copyright (c) 2014 - 2020, Intel Corporation. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
7
8 **/
9 #include "BlSupportDxe.h"
10
11 /**
12 Reserve MMIO/IO resource in GCD
13
14 @param IsMMIO Flag of whether it is mmio resource or io resource.
15 @param GcdType Type of the space.
16 @param BaseAddress Base address of the space.
17 @param Length Length of the space.
18 @param Alignment Align with 2^Alignment
19 @param ImageHandle Handle for the image of this driver.
20
21 @retval EFI_SUCCESS Reserve successful
22 **/
23 EFI_STATUS
ReserveResourceInGcd(IN BOOLEAN IsMMIO,IN UINTN GcdType,IN EFI_PHYSICAL_ADDRESS BaseAddress,IN UINT64 Length,IN UINTN Alignment,IN EFI_HANDLE ImageHandle)24 ReserveResourceInGcd (
25 IN BOOLEAN IsMMIO,
26 IN UINTN GcdType,
27 IN EFI_PHYSICAL_ADDRESS BaseAddress,
28 IN UINT64 Length,
29 IN UINTN Alignment,
30 IN EFI_HANDLE ImageHandle
31 )
32 {
33 EFI_STATUS Status;
34
35 if (IsMMIO) {
36 Status = gDS->AddMemorySpace (
37 GcdType,
38 BaseAddress,
39 Length,
40 EFI_MEMORY_UC
41 );
42 if (EFI_ERROR (Status)) {
43 DEBUG ((
44 DEBUG_ERROR,
45 "Failed to add memory space :0x%lx 0x%lx\n",
46 BaseAddress,
47 Length
48 ));
49 }
50 ASSERT_EFI_ERROR (Status);
51 Status = gDS->AllocateMemorySpace (
52 EfiGcdAllocateAddress,
53 GcdType,
54 Alignment,
55 Length,
56 &BaseAddress,
57 ImageHandle,
58 NULL
59 );
60 ASSERT_EFI_ERROR (Status);
61 } else {
62 Status = gDS->AddIoSpace (
63 GcdType,
64 BaseAddress,
65 Length
66 );
67 ASSERT_EFI_ERROR (Status);
68 Status = gDS->AllocateIoSpace (
69 EfiGcdAllocateAddress,
70 GcdType,
71 Alignment,
72 Length,
73 &BaseAddress,
74 ImageHandle,
75 NULL
76 );
77 ASSERT_EFI_ERROR (Status);
78 }
79 return Status;
80 }
81
82
83 /**
84 Main entry for the bootloader support DXE module.
85
86 @param[in] ImageHandle The firmware allocated handle for the EFI image.
87 @param[in] SystemTable A pointer to the EFI System Table.
88
89 @retval EFI_SUCCESS The entry point is executed successfully.
90 @retval other Some error occurs when executing this entry point.
91
92 **/
93 EFI_STATUS
94 EFIAPI
BlDxeEntryPoint(IN EFI_HANDLE ImageHandle,IN EFI_SYSTEM_TABLE * SystemTable)95 BlDxeEntryPoint (
96 IN EFI_HANDLE ImageHandle,
97 IN EFI_SYSTEM_TABLE *SystemTable
98 )
99 {
100 EFI_STATUS Status;
101 EFI_HOB_GUID_TYPE *GuidHob;
102 SYSTEM_TABLE_INFO *SystemTableInfo;
103 EFI_PEI_GRAPHICS_INFO_HOB *GfxInfo;
104 ACPI_BOARD_INFO *AcpiBoardInfo;
105
106 Status = EFI_SUCCESS;
107 //
108 // Report MMIO/IO Resources
109 //
110 Status = ReserveResourceInGcd (TRUE, EfiGcdMemoryTypeMemoryMappedIo, 0xFEC00000, SIZE_4KB, 0, ImageHandle); // IOAPIC
111 ASSERT_EFI_ERROR (Status);
112
113 Status = ReserveResourceInGcd (TRUE, EfiGcdMemoryTypeMemoryMappedIo, 0xFED00000, SIZE_1KB, 0, ImageHandle); // HPET
114 ASSERT_EFI_ERROR (Status);
115
116 //
117 // Find the system table information guid hob
118 //
119 GuidHob = GetFirstGuidHob (&gUefiSystemTableInfoGuid);
120 ASSERT (GuidHob != NULL);
121 SystemTableInfo = (SYSTEM_TABLE_INFO *)GET_GUID_HOB_DATA (GuidHob);
122
123 //
124 // Install Acpi Table
125 //
126 if (SystemTableInfo->AcpiTableBase != 0 && SystemTableInfo->AcpiTableSize != 0) {
127 DEBUG ((DEBUG_ERROR, "Install Acpi Table at 0x%lx, length 0x%x\n", SystemTableInfo->AcpiTableBase, SystemTableInfo->AcpiTableSize));
128 Status = gBS->InstallConfigurationTable (&gEfiAcpiTableGuid, (VOID *)(UINTN)SystemTableInfo->AcpiTableBase);
129 ASSERT_EFI_ERROR (Status);
130 }
131
132 //
133 // Install Smbios Table
134 //
135 if (SystemTableInfo->SmbiosTableBase != 0 && SystemTableInfo->SmbiosTableSize != 0) {
136 DEBUG ((DEBUG_ERROR, "Install Smbios Table at 0x%lx, length 0x%x\n", SystemTableInfo->SmbiosTableBase, SystemTableInfo->SmbiosTableSize));
137 Status = gBS->InstallConfigurationTable (&gEfiSmbiosTableGuid, (VOID *)(UINTN)SystemTableInfo->SmbiosTableBase);
138 ASSERT_EFI_ERROR (Status);
139 }
140
141 //
142 // Find the frame buffer information and update PCDs
143 //
144 GuidHob = GetFirstGuidHob (&gEfiGraphicsInfoHobGuid);
145 if (GuidHob != NULL) {
146 GfxInfo = (EFI_PEI_GRAPHICS_INFO_HOB *)GET_GUID_HOB_DATA (GuidHob);
147 Status = PcdSet32S (PcdVideoHorizontalResolution, GfxInfo->GraphicsMode.HorizontalResolution);
148 ASSERT_EFI_ERROR (Status);
149 Status = PcdSet32S (PcdVideoVerticalResolution, GfxInfo->GraphicsMode.VerticalResolution);
150 ASSERT_EFI_ERROR (Status);
151 Status = PcdSet32S (PcdSetupVideoHorizontalResolution, GfxInfo->GraphicsMode.HorizontalResolution);
152 ASSERT_EFI_ERROR (Status);
153 Status = PcdSet32S (PcdSetupVideoVerticalResolution, GfxInfo->GraphicsMode.VerticalResolution);
154 ASSERT_EFI_ERROR (Status);
155 }
156
157 //
158 // Set PcdPciExpressBaseAddress and PcdPciExpressBaseSize by HOB info
159 //
160 GuidHob = GetFirstGuidHob (&gUefiAcpiBoardInfoGuid);
161 if (GuidHob != NULL) {
162 AcpiBoardInfo = (ACPI_BOARD_INFO *)GET_GUID_HOB_DATA (GuidHob);
163 Status = PcdSet64S (PcdPciExpressBaseAddress, AcpiBoardInfo->PcieBaseAddress);
164 ASSERT_EFI_ERROR (Status);
165 Status = PcdSet64S (PcdPciExpressBaseSize, AcpiBoardInfo->PcieBaseSize);
166 ASSERT_EFI_ERROR (Status);
167 }
168
169 return EFI_SUCCESS;
170 }
171
172