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