]> git.proxmox.com Git - mirror_edk2.git/blame - OvmfPkg/AcpiPlatformDxe/AcpiPlatform.c
OvmfPkg/AcpiPlatformDxe: Assert if AcpiTable protocol is not found
[mirror_edk2.git] / OvmfPkg / AcpiPlatformDxe / AcpiPlatform.c
CommitLineData
7d2bd150 1/** @file\r
522203de 2 OVMF ACPI Platform Driver\r
7d2bd150 3\r
522203de 4 Copyright (c) 2008 - 2012, Intel Corporation. All rights reserved.<BR>\r
7d2bd150 5 This program and the accompanying materials\r
6 are licensed and made available under the terms and conditions of the BSD License\r
7 which accompanies this distribution. The full text of the license may be found at\r
8 http://opensource.org/licenses/bsd-license.php\r
9\r
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
522203de 13**/\r
7d2bd150 14\r
522203de 15#include "AcpiPlatform.h"\r
7d2bd150 16\r
522203de 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
7d2bd150 33\r
7d2bd150 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
7d2bd150 81 //\r
82 // Looking for FV with ACPI storage file\r
83 //\r
7d2bd150 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
7d2bd150 132/**\r
377e758c 133 Find ACPI tables in an FV and parses them. This function is useful for QEMU and KVM.\r
7d2bd150 134\r
377e758c 135 @param AcpiTable Protocol instance pointer \r
7d2bd150 136\r
137**/\r
138EFI_STATUS\r
139EFIAPI\r
377e758c 140FindAcpiTablesInFv (\r
141 IN EFI_ACPI_TABLE_PROTOCOL *AcpiTable\r
7d2bd150 142 )\r
143{\r
377e758c 144 EFI_STATUS Status;\r
145 EFI_FIRMWARE_VOLUME2_PROTOCOL *FwVol;\r
146 INTN Instance;\r
147 EFI_ACPI_COMMON_HEADER *CurrentTable;\r
148 UINTN TableHandle;\r
149 UINT32 FvStatus;\r
150 UINTN TableSize;\r
151 UINTN Size;\r
152 EFI_ACPI_TABLE_INSTALL_ACPI_TABLE TableInstallFunction;\r
7d2bd150 153\r
154 Instance = 0;\r
155 CurrentTable = NULL;\r
156 TableHandle = 0;\r
157\r
522203de 158 if (QemuDetected ()) {\r
159 TableInstallFunction = QemuInstallAcpiTable;\r
522203de 160 } else {\r
161 TableInstallFunction = InstallAcpiTable;\r
162 }\r
163\r
7d2bd150 164 //\r
165 // Locate the firmware volume protocol\r
166 //\r
167 Status = LocateFvInstanceWithTables (&FwVol);\r
168 if (EFI_ERROR (Status)) {\r
169 return EFI_ABORTED;\r
170 }\r
171 //\r
172 // Read tables from the storage file.\r
173 //\r
174 while (Status == EFI_SUCCESS) {\r
175\r
176 Status = FwVol->ReadSection (\r
177 FwVol,\r
178 (EFI_GUID*)PcdGetPtr (PcdAcpiTableStorageFile),\r
179 EFI_SECTION_RAW,\r
180 Instance,\r
181 (VOID**) &CurrentTable,\r
182 &Size,\r
183 &FvStatus\r
184 );\r
377e758c 185 if (!EFI_ERROR (Status)) {\r
7d2bd150 186 //\r
187 // Add the table\r
188 //\r
189 TableHandle = 0;\r
190\r
191 TableSize = ((EFI_ACPI_DESCRIPTION_HEADER *) CurrentTable)->Length;\r
192 ASSERT (Size >= TableSize);\r
193\r
7d2bd150 194 //\r
195 // Install ACPI table\r
196 //\r
522203de 197 Status = TableInstallFunction (\r
198 AcpiTable,\r
199 CurrentTable,\r
200 TableSize,\r
201 &TableHandle\r
202 );\r
7d2bd150 203\r
204 //\r
205 // Free memory allocated by ReadSection\r
206 //\r
207 gBS->FreePool (CurrentTable);\r
208\r
522203de 209 if (EFI_ERROR (Status)) {\r
7d2bd150 210 return EFI_ABORTED;\r
211 }\r
212\r
213 //\r
214 // Increment the instance\r
215 //\r
216 Instance++;\r
217 CurrentTable = NULL;\r
218 }\r
219 }\r
220\r
221 return EFI_SUCCESS;\r
222}\r
223\r
377e758c 224/**\r
225 Entrypoint of Acpi Platform driver.\r
226\r
227 @param ImageHandle\r
228 @param SystemTable\r
229\r
230 @return EFI_SUCCESS\r
231 @return EFI_LOAD_ERROR\r
232 @return EFI_OUT_OF_RESOURCES\r
233\r
234**/\r
235EFI_STATUS\r
236EFIAPI\r
237AcpiPlatformEntryPoint (\r
238 IN EFI_HANDLE ImageHandle,\r
239 IN EFI_SYSTEM_TABLE *SystemTable\r
240 )\r
241{\r
242 EFI_STATUS Status;\r
243 EFI_ACPI_TABLE_PROTOCOL *AcpiTable;\r
244\r
245 //\r
246 // Find the AcpiTable protocol\r
247 //\r
248 Status = gBS->LocateProtocol (\r
249 &gEfiAcpiTableProtocolGuid,\r
250 NULL,\r
251 (VOID**)&AcpiTable\r
252 );\r
53596a72 253 ASSERT_EFI_ERROR (Status);\r
377e758c 254\r
255 if (XenDetected ()) {\r
256 Status = InstallXenTables (AcpiTable);\r
377e758c 257 } else {\r
2d1fe950 258 Status = InstallAllQemuLinkedTables (AcpiTable);\r
377e758c 259 }\r
96bbdbc8 260\r
377e758c 261 if (EFI_ERROR (Status)) {\r
96bbdbc8 262 Status = FindAcpiTablesInFv (AcpiTable);\r
377e758c 263 }\r
264\r
96bbdbc8 265 return Status;\r
377e758c 266}\r
267\r