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