]>
Commit | Line | Data |
---|---|---|
656419f9 | 1 | /** @file\r |
9fb629ed | 2 | bhyve ACPI Platform Driver\r |
656419f9 RC |
3 | \r |
4 | Copyright (c) 2020, Rebecca Cran <rebecca@bsdio.com>\r | |
5 | Copyright (c) 2008 - 2012, Intel Corporation. All rights reserved.<BR>\r | |
9fb629ed | 6 | \r |
656419f9 RC |
7 | SPDX-License-Identifier: BSD-2-Clause-Patent\r |
8 | \r | |
9 | **/\r | |
10 | \r | |
11 | #include "AcpiPlatform.h"\r | |
12 | \r | |
13 | EFI_STATUS\r | |
14 | EFIAPI\r | |
15 | InstallAcpiTable (\r | |
16 | IN EFI_ACPI_TABLE_PROTOCOL *AcpiProtocol,\r | |
17 | IN VOID *AcpiTableBuffer,\r | |
18 | IN UINTN AcpiTableBufferSize,\r | |
19 | OUT UINTN *TableKey\r | |
20 | )\r | |
21 | {\r | |
22 | return AcpiProtocol->InstallAcpiTable (\r | |
23 | AcpiProtocol,\r | |
24 | AcpiTableBuffer,\r | |
25 | AcpiTableBufferSize,\r | |
26 | TableKey\r | |
27 | );\r | |
28 | }\r | |
29 | \r | |
30 | \r | |
31 | /**\r | |
32 | Locate the first instance of a protocol. If the protocol requested is an\r | |
33 | FV protocol, then it will return the first FV that contains the ACPI table\r | |
34 | storage file.\r | |
35 | \r | |
36 | @param Instance Return pointer to the first instance of the protocol\r | |
37 | \r | |
38 | @return EFI_SUCCESS The function completed successfully.\r | |
39 | @return EFI_NOT_FOUND The protocol could not be located.\r | |
40 | @return EFI_OUT_OF_RESOURCES There are not enough resources to find the protocol.\r | |
41 | \r | |
42 | **/\r | |
43 | EFI_STATUS\r | |
44 | LocateFvInstanceWithTables (\r | |
45 | OUT EFI_FIRMWARE_VOLUME2_PROTOCOL **Instance\r | |
46 | )\r | |
47 | {\r | |
48 | EFI_STATUS Status;\r | |
49 | EFI_HANDLE *HandleBuffer;\r | |
50 | UINTN NumberOfHandles;\r | |
51 | EFI_FV_FILETYPE FileType;\r | |
52 | UINT32 FvStatus;\r | |
53 | EFI_FV_FILE_ATTRIBUTES Attributes;\r | |
54 | UINTN Size;\r | |
55 | UINTN Index;\r | |
56 | EFI_FIRMWARE_VOLUME2_PROTOCOL *FvInstance;\r | |
57 | \r | |
58 | FvStatus = 0;\r | |
59 | \r | |
60 | //\r | |
61 | // Locate protocol.\r | |
62 | //\r | |
63 | Status = gBS->LocateHandleBuffer (\r | |
64 | ByProtocol,\r | |
65 | &gEfiFirmwareVolume2ProtocolGuid,\r | |
66 | NULL,\r | |
67 | &NumberOfHandles,\r | |
68 | &HandleBuffer\r | |
69 | );\r | |
70 | if (EFI_ERROR (Status)) {\r | |
71 | //\r | |
72 | // Defined errors at this time are not found and out of resources.\r | |
73 | //\r | |
74 | return Status;\r | |
75 | }\r | |
76 | \r | |
77 | //\r | |
78 | // Looking for FV with ACPI storage file\r | |
79 | //\r | |
80 | for (Index = 0; Index < NumberOfHandles; Index++) {\r | |
81 | //\r | |
82 | // Get the protocol on this handle\r | |
83 | // This should not fail because of LocateHandleBuffer\r | |
84 | //\r | |
85 | Status = gBS->HandleProtocol (\r | |
86 | HandleBuffer[Index],\r | |
87 | &gEfiFirmwareVolume2ProtocolGuid,\r | |
88 | (VOID**) &FvInstance\r | |
89 | );\r | |
90 | ASSERT_EFI_ERROR (Status);\r | |
91 | \r | |
92 | //\r | |
93 | // See if it has the ACPI storage file\r | |
94 | //\r | |
95 | Status = FvInstance->ReadFile (\r | |
96 | FvInstance,\r | |
97 | (EFI_GUID*)PcdGetPtr (PcdAcpiTableStorageFile),\r | |
98 | NULL,\r | |
99 | &Size,\r | |
100 | &FileType,\r | |
101 | &Attributes,\r | |
102 | &FvStatus\r | |
103 | );\r | |
104 | \r | |
105 | //\r | |
106 | // If we found it, then we are done\r | |
107 | //\r | |
108 | if (Status == EFI_SUCCESS) {\r | |
109 | *Instance = FvInstance;\r | |
110 | break;\r | |
111 | }\r | |
112 | }\r | |
113 | \r | |
114 | //\r | |
115 | // Our exit status is determined by the success of the previous operations\r | |
116 | // If the protocol was found, Instance already points to it.\r | |
117 | //\r | |
118 | \r | |
119 | //\r | |
120 | // Free any allocated buffers\r | |
121 | //\r | |
122 | gBS->FreePool (HandleBuffer);\r | |
123 | \r | |
124 | return Status;\r | |
125 | }\r | |
126 | \r | |
127 | \r | |
128 | /**\r | |
129 | Find ACPI tables in an FV and install them.\r | |
130 | \r | |
131 | This is now a fall-back path. Normally, we will search for tables provided\r | |
132 | by the VMM first.\r | |
133 | \r | |
134 | If that fails, we use this function to load the ACPI tables from an FV. The\r | |
4174c5c7 | 135 | sources for the FV based tables is located under OvmfPkg/Bhyve/AcpiTables.\r |
656419f9 RC |
136 | \r |
137 | @param AcpiTable Protocol instance pointer\r | |
138 | \r | |
139 | **/\r | |
140 | EFI_STATUS\r | |
141 | EFIAPI\r | |
142 | InstallOvmfFvTables (\r | |
143 | IN EFI_ACPI_TABLE_PROTOCOL *AcpiTable\r | |
144 | )\r | |
145 | {\r | |
146 | EFI_STATUS Status;\r | |
147 | EFI_FIRMWARE_VOLUME2_PROTOCOL *FwVol;\r | |
148 | INTN Instance;\r | |
149 | EFI_ACPI_COMMON_HEADER *CurrentTable;\r | |
150 | UINTN TableHandle;\r | |
151 | UINT32 FvStatus;\r | |
152 | UINTN TableSize;\r | |
153 | UINTN Size;\r | |
154 | EFI_ACPI_TABLE_INSTALL_ACPI_TABLE TableInstallFunction;\r | |
155 | \r | |
156 | Instance = 0;\r | |
157 | CurrentTable = NULL;\r | |
158 | TableHandle = 0;\r | |
159 | \r | |
160 | TableInstallFunction = BhyveInstallAcpiTable;\r | |
161 | \r | |
162 | //\r | |
163 | // set FwVol (and use an ASSERT() below) to suppress incorrect\r | |
164 | // compiler/analyzer warnings\r | |
165 | //\r | |
166 | FwVol = NULL;\r | |
167 | //\r | |
168 | // Locate the firmware volume protocol\r | |
169 | //\r | |
170 | Status = LocateFvInstanceWithTables (&FwVol);\r | |
171 | if (EFI_ERROR (Status)) {\r | |
172 | return EFI_ABORTED;\r | |
173 | }\r | |
174 | ASSERT (FwVol != NULL);\r | |
175 | \r | |
176 | //\r | |
177 | // Read tables from the storage file.\r | |
178 | //\r | |
179 | while (Status == EFI_SUCCESS) {\r | |
180 | \r | |
181 | Status = FwVol->ReadSection (\r | |
182 | FwVol,\r | |
183 | (EFI_GUID*)PcdGetPtr (PcdAcpiTableStorageFile),\r | |
184 | EFI_SECTION_RAW,\r | |
185 | Instance,\r | |
186 | (VOID**) &CurrentTable,\r | |
187 | &Size,\r | |
188 | &FvStatus\r | |
189 | );\r | |
190 | if (!EFI_ERROR (Status)) {\r | |
191 | //\r | |
192 | // Add the table\r | |
193 | //\r | |
194 | TableHandle = 0;\r | |
195 | \r | |
196 | TableSize = ((EFI_ACPI_DESCRIPTION_HEADER *) CurrentTable)->Length;\r | |
197 | ASSERT (Size >= TableSize);\r | |
198 | \r | |
199 | //\r | |
200 | // Install ACPI table\r | |
201 | //\r | |
202 | Status = TableInstallFunction (\r | |
203 | AcpiTable,\r | |
204 | CurrentTable,\r | |
205 | TableSize,\r | |
206 | &TableHandle\r | |
207 | );\r | |
208 | \r | |
209 | //\r | |
210 | // Free memory allocated by ReadSection\r | |
211 | //\r | |
212 | gBS->FreePool (CurrentTable);\r | |
213 | \r | |
214 | if (EFI_ERROR (Status)) {\r | |
215 | return EFI_ABORTED;\r | |
216 | }\r | |
217 | \r | |
218 | //\r | |
219 | // Increment the instance\r | |
220 | //\r | |
221 | Instance++;\r | |
222 | CurrentTable = NULL;\r | |
223 | }\r | |
224 | }\r | |
225 | \r | |
226 | return EFI_SUCCESS;\r | |
227 | }\r | |
228 | \r | |
229 | /**\r | |
230 | Effective entrypoint of Acpi Platform driver.\r | |
231 | \r | |
232 | @param ImageHandle\r | |
233 | @param SystemTable\r | |
234 | \r | |
235 | @return EFI_SUCCESS\r | |
236 | @return EFI_LOAD_ERROR\r | |
237 | @return EFI_OUT_OF_RESOURCES\r | |
238 | \r | |
239 | **/\r | |
240 | EFI_STATUS\r | |
241 | EFIAPI\r | |
242 | InstallAcpiTables (\r | |
243 | IN EFI_ACPI_TABLE_PROTOCOL *AcpiTable\r | |
244 | )\r | |
245 | {\r | |
246 | EFI_STATUS Status;\r | |
247 | \r | |
248 | Status = InstallOvmfFvTables (AcpiTable);\r | |
249 | \r | |
250 | return Status;\r | |
251 | }\r | |
252 | \r |