CorebootPayloadPkg/PlatformBootManagerLib: Fix Linux build
[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
143 Status = CbReserveResourceInGcd (TRUE, EfiGcdMemoryTypeMemoryMappedIo, 0xFEE00000, SIZE_1MB, 0, SystemTable); // LAPIC\r
144 ASSERT_EFI_ERROR (Status);\r
145\r
146 Status = CbReserveResourceInGcd (TRUE, EfiGcdMemoryTypeMemoryMappedIo, 0xFEC00000, SIZE_4KB, 0, SystemTable); // IOAPIC\r
147 ASSERT_EFI_ERROR (Status);\r
148\r
149 Status = CbReserveResourceInGcd (TRUE, EfiGcdMemoryTypeMemoryMappedIo, 0xFED00000, SIZE_1KB, 0, SystemTable); // HPET\r
150 ASSERT_EFI_ERROR (Status);\r
151\r
152 //\r
153 // Find the system table information guid hob\r
154 //\r
155 GuidHob = GetFirstGuidHob (&gUefiSystemTableInfoGuid);\r
156 ASSERT (GuidHob != NULL);\r
fce4ecd9 157 pSystemTableInfo = (SYSTEM_TABLE_INFO *)GET_GUID_HOB_DATA (GuidHob);\r
f3a90fbf
MM
158\r
159 //\r
160 // Install Acpi Table\r
161 //\r
162 if (pSystemTableInfo->AcpiTableBase != 0 && pSystemTableInfo->AcpiTableSize != 0) {\r
163 DEBUG ((EFI_D_ERROR, "Install Acpi Table at 0x%lx, length 0x%x\n", pSystemTableInfo->AcpiTableBase, pSystemTableInfo->AcpiTableSize));\r
164 Status = gBS->InstallConfigurationTable (&gEfiAcpiTableGuid, (VOID *)(UINTN)pSystemTableInfo->AcpiTableBase);\r
165 ASSERT_EFI_ERROR (Status);\r
166 }\r
167\r
168 //\r
169 // Install Smbios Table\r
170 //\r
171 if (pSystemTableInfo->SmbiosTableBase != 0 && pSystemTableInfo->SmbiosTableSize != 0) {\r
172 DEBUG ((EFI_D_ERROR, "Install Smbios Table at 0x%lx, length 0x%x\n", pSystemTableInfo->SmbiosTableBase, pSystemTableInfo->SmbiosTableSize));\r
173 Status = gBS->InstallConfigurationTable (&gEfiSmbiosTableGuid, (VOID *)(UINTN)pSystemTableInfo->SmbiosTableBase);\r
174 ASSERT_EFI_ERROR (Status);\r
175 }\r
176\r
177 //\r
178 // Find the acpi board information guid hob\r
179 //\r
180 GuidHob = GetFirstGuidHob (&gUefiAcpiBoardInfoGuid);\r
181 ASSERT (GuidHob != NULL);\r
182 pAcpiBoardInfo = (ACPI_BOARD_INFO *)GET_GUID_HOB_DATA (GuidHob);\r
183\r
fce4ecd9 184 mPmCtrlReg = (UINTN)pAcpiBoardInfo->PmCtrlRegBase;\r
f3a90fbf
MM
185 DEBUG ((EFI_D_ERROR, "PmCtrlReg at 0x%lx\n", (UINT64)mPmCtrlReg));\r
186\r
3aa86568
MM
187 //\r
188 // Find the frame buffer information and update PCDs\r
189 //\r
190 GuidHob = GetFirstGuidHob (&gUefiFrameBufferInfoGuid);\r
191 ASSERT (GuidHob != NULL);\r
192 FbInfo = (FRAME_BUFFER_INFO *)GET_GUID_HOB_DATA (GuidHob);\r
193 Status = PcdSet32S (PcdVideoHorizontalResolution, FbInfo->HorizontalResolution);\r
194 ASSERT_EFI_ERROR (Status);\r
195 Status = PcdSet32S (PcdVideoVerticalResolution, FbInfo->VerticalResolution);\r
196 ASSERT_EFI_ERROR (Status);\r
197 Status = PcdSet32S (PcdSetupVideoHorizontalResolution, FbInfo->HorizontalResolution);\r
198 ASSERT_EFI_ERROR (Status);\r
199 Status = PcdSet32S (PcdSetupVideoVerticalResolution, FbInfo->VerticalResolution);\r
200 ASSERT_EFI_ERROR (Status);\r
201\r
f3a90fbf
MM
202 //\r
203 // Register callback on the ready to boot event\r
204 // in order to enable SCI\r
205 //\r
206 ReadyToBootEvent = NULL;\r
fce4ecd9
MM
207 Status = EfiCreateEventReadyToBootEx (\r
208 TPL_CALLBACK,\r
209 OnReadyToBoot,\r
210 NULL,\r
211 &ReadyToBootEvent\r
212 );\r
213 ASSERT_EFI_ERROR (Status);\r
f3a90fbf 214\r
fce4ecd9
MM
215 return EFI_SUCCESS;\r
216}\r
217\r