]> git.proxmox.com Git - mirror_edk2.git/blame - CorebootModulePkg/CbSupportDxe/CbSupportDxe.c
MdeModulePkg: Put report status code at the end of RuntimeDriverSetVirtualAddressMap.
[mirror_edk2.git] / CorebootModulePkg / CbSupportDxe / CbSupportDxe.c
CommitLineData
fce4ecd9
MM
1/** @file\r
2 This driver will report some MMIO/IO resources to dxe core, extract smbios and acpi \r
3 tables from coreboot and install.\r
4 \r
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
40 EFI_STATUS Status;\r
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
52 "Failed to add memory space :0x%x 0x%x\n",\r
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
101OnReadyToBoot (\r
102 EFI_EVENT Event,\r
103 VOID *Context\r
104 )\r
105{ \r
106 //\r
107 // Enable SCI\r
108 //\r
109 IoOr16 (mPmCtrlReg, BIT0);\r
110 \r
111 DEBUG ((EFI_D_ERROR, "Enable SCI bit at 0x%x before boot\n", mPmCtrlReg)); \r
112}\r
113\r
114/**\r
115 Main entry for the Coreboot Support DXE module.\r
116 \r
117 @param[in] ImageHandle The firmware allocated handle for the EFI image.\r
118 @param[in] SystemTable A pointer to the EFI System Table.\r
119 \r
120 @retval EFI_SUCCESS The entry point is executed successfully.\r
121 @retval other Some error occurs when executing this entry point.\r
122\r
123**/\r
124EFI_STATUS\r
125CbDxeEntryPoint (\r
126 IN EFI_HANDLE ImageHandle,\r
127 IN EFI_SYSTEM_TABLE *SystemTable\r
128 )\r
129{ \r
130 EFI_STATUS Status;\r
131 EFI_EVENT ReadyToBootEvent;\r
132 EFI_HOB_GUID_TYPE *GuidHob;\r
133 SYSTEM_TABLE_INFO *pSystemTableInfo;\r
134 ACPI_BOARD_INFO *pAcpiBoardInfo;\r
135 \r
136 Status = EFI_SUCCESS;\r
137 //\r
138 // Report MMIO/IO Resources\r
139 //\r
140 Status = CbReserveResourceInGcd (TRUE, EfiGcdMemoryTypeMemoryMappedIo, 0xFEE00000, SIZE_1MB, 0, SystemTable); // LAPIC \r
141 ASSERT_EFI_ERROR (Status);\r
142 \r
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
154 pSystemTableInfo = (SYSTEM_TABLE_INFO *)GET_GUID_HOB_DATA (GuidHob);\r
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%x, length 0x%x\n", (UINTN)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%x, length 0x%x\n", (UINTN)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
181 mPmCtrlReg = (UINTN)pAcpiBoardInfo->PmCtrlRegBase;\r
182 DEBUG ((EFI_D_ERROR, "PmCtrlReg at 0x%x\n", mPmCtrlReg)); \r
183 \r
184 //\r
185 // Register callback on the ready to boot event \r
186 // in order to enable SCI\r
187 // \r
188 ReadyToBootEvent = NULL;\r
189 Status = EfiCreateEventReadyToBootEx (\r
190 TPL_CALLBACK,\r
191 OnReadyToBoot,\r
192 NULL,\r
193 &ReadyToBootEvent\r
194 );\r
195 ASSERT_EFI_ERROR (Status);\r
196 \r
197 return EFI_SUCCESS;\r
198}\r
199\r