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