MdePkg: Clarification to the return status of EFI_PEIM_NOTIFY_ENTRY_POINT
[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
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
MM
105 )\r
106{ \r
107 //\r
108 // Enable SCI\r
109 //\r
110 IoOr16 (mPmCtrlReg, BIT0);\r
111 \r
42e548a8 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
117 \r
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
120 \r
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
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
137 \r
138 Status = EFI_SUCCESS;\r
139 //\r
140 // Report MMIO/IO Resources\r
141 //\r
142 Status = CbReserveResourceInGcd (TRUE, EfiGcdMemoryTypeMemoryMappedIo, 0xFEE00000, SIZE_1MB, 0, SystemTable); // LAPIC \r
143 ASSERT_EFI_ERROR (Status);\r
144 \r
145 Status = CbReserveResourceInGcd (TRUE, EfiGcdMemoryTypeMemoryMappedIo, 0xFEC00000, SIZE_4KB, 0, SystemTable); // IOAPIC \r
146 ASSERT_EFI_ERROR (Status);\r
147 \r
148 Status = CbReserveResourceInGcd (TRUE, EfiGcdMemoryTypeMemoryMappedIo, 0xFED00000, SIZE_1KB, 0, SystemTable); // HPET \r
149 ASSERT_EFI_ERROR (Status);\r
150 \r
151 //\r
152 // Find the system table information guid hob\r
153 //\r
154 GuidHob = GetFirstGuidHob (&gUefiSystemTableInfoGuid);\r
155 ASSERT (GuidHob != NULL);\r
156 pSystemTableInfo = (SYSTEM_TABLE_INFO *)GET_GUID_HOB_DATA (GuidHob);\r
157 \r
158 //\r
159 // Install Acpi Table\r
160 //\r
161 if (pSystemTableInfo->AcpiTableBase != 0 && pSystemTableInfo->AcpiTableSize != 0) { \r
42e548a8 162 DEBUG ((EFI_D_ERROR, "Install Acpi Table at 0x%lx, length 0x%x\n", pSystemTableInfo->AcpiTableBase, pSystemTableInfo->AcpiTableSize)); \r
fce4ecd9
MM
163 Status = gBS->InstallConfigurationTable (&gEfiAcpiTableGuid, (VOID *)(UINTN)pSystemTableInfo->AcpiTableBase);\r
164 ASSERT_EFI_ERROR (Status);\r
165 }\r
166 \r
167 //\r
168 // Install Smbios Table\r
169 //\r
170 if (pSystemTableInfo->SmbiosTableBase != 0 && pSystemTableInfo->SmbiosTableSize != 0) { \r
42e548a8 171 DEBUG ((EFI_D_ERROR, "Install Smbios Table at 0x%lx, length 0x%x\n", pSystemTableInfo->SmbiosTableBase, pSystemTableInfo->SmbiosTableSize)); \r
fce4ecd9
MM
172 Status = gBS->InstallConfigurationTable (&gEfiSmbiosTableGuid, (VOID *)(UINTN)pSystemTableInfo->SmbiosTableBase);\r
173 ASSERT_EFI_ERROR (Status);\r
174 }\r
175 \r
176 //\r
177 // Find the acpi board information guid hob\r
178 //\r
179 GuidHob = GetFirstGuidHob (&gUefiAcpiBoardInfoGuid);\r
180 ASSERT (GuidHob != NULL);\r
181 pAcpiBoardInfo = (ACPI_BOARD_INFO *)GET_GUID_HOB_DATA (GuidHob); \r
182 \r
183 mPmCtrlReg = (UINTN)pAcpiBoardInfo->PmCtrlRegBase;\r
42e548a8 184 DEBUG ((EFI_D_ERROR, "PmCtrlReg at 0x%lx\n", (UINT64)mPmCtrlReg)); \r
fce4ecd9
MM
185 \r
186 //\r
187 // Register callback on the ready to boot event \r
188 // in order to enable SCI\r
189 // \r
190 ReadyToBootEvent = NULL;\r
191 Status = EfiCreateEventReadyToBootEx (\r
192 TPL_CALLBACK,\r
193 OnReadyToBoot,\r
194 NULL,\r
195 &ReadyToBootEvent\r
196 );\r
197 ASSERT_EFI_ERROR (Status);\r
198 \r
199 return EFI_SUCCESS;\r
200}\r
201\r