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