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