/** @file\r
OVMF ACPI Platform Driver\r
\r
- Copyright (c) 2008 - 2012, Intel Corporation. All rights reserved.<BR>\r
- This program and the accompanying materials\r
- are licensed and made available under the terms and conditions of the BSD License\r
- which accompanies this distribution. The full text of the license may be found at\r
- http://opensource.org/licenses/bsd-license.php\r
-\r
- THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+ Copyright (C) 2015, Red Hat, Inc.\r
+ Copyright (c) 2008 - 2014, Intel Corporation. All rights reserved.<BR>\r
\r
+ SPDX-License-Identifier: BSD-2-Clause-Patent\r
**/\r
\r
+#include <OvmfPlatforms.h> // CLOUDHV_DEVICE_ID\r
+#include <ConfidentialComputingGuestAttr.h>\r
#include "AcpiPlatform.h"\r
\r
-EFI_STATUS\r
-EFIAPI\r
-InstallAcpiTable (\r
- IN EFI_ACPI_TABLE_PROTOCOL *AcpiProtocol,\r
- IN VOID *AcpiTableBuffer,\r
- IN UINTN AcpiTableBufferSize,\r
- OUT UINTN *TableKey\r
- )\r
-{\r
- return AcpiProtocol->InstallAcpiTable (\r
- AcpiProtocol,\r
- AcpiTableBuffer,\r
- AcpiTableBufferSize,\r
- TableKey\r
- );\r
-}\r
-\r
-\r
-/**\r
- Locate the first instance of a protocol. If the protocol requested is an\r
- FV protocol, then it will return the first FV that contains the ACPI table\r
- storage file.\r
-\r
- @param Instance Return pointer to the first instance of the protocol\r
-\r
- @return EFI_SUCCESS The function completed successfully.\r
- @return EFI_NOT_FOUND The protocol could not be located.\r
- @return EFI_OUT_OF_RESOURCES There are not enough resources to find the protocol.\r
-\r
-**/\r
-EFI_STATUS\r
-LocateFvInstanceWithTables (\r
- OUT EFI_FIRMWARE_VOLUME2_PROTOCOL **Instance\r
- )\r
-{\r
- EFI_STATUS Status;\r
- EFI_HANDLE *HandleBuffer;\r
- UINTN NumberOfHandles;\r
- EFI_FV_FILETYPE FileType;\r
- UINT32 FvStatus;\r
- EFI_FV_FILE_ATTRIBUTES Attributes;\r
- UINTN Size;\r
- UINTN Index;\r
- EFI_FIRMWARE_VOLUME2_PROTOCOL *FvInstance;\r
-\r
- FvStatus = 0;\r
-\r
- //\r
- // Locate protocol.\r
- //\r
- Status = gBS->LocateHandleBuffer (\r
- ByProtocol,\r
- &gEfiFirmwareVolume2ProtocolGuid,\r
- NULL,\r
- &NumberOfHandles,\r
- &HandleBuffer\r
- );\r
- if (EFI_ERROR (Status)) {\r
- //\r
- // Defined errors at this time are not found and out of resources.\r
- //\r
- return Status;\r
- }\r
-\r
- //\r
- // Looking for FV with ACPI storage file\r
- //\r
- for (Index = 0; Index < NumberOfHandles; Index++) {\r
- //\r
- // Get the protocol on this handle\r
- // This should not fail because of LocateHandleBuffer\r
- //\r
- Status = gBS->HandleProtocol (\r
- HandleBuffer[Index],\r
- &gEfiFirmwareVolume2ProtocolGuid,\r
- (VOID**) &FvInstance\r
- );\r
- ASSERT_EFI_ERROR (Status);\r
-\r
- //\r
- // See if it has the ACPI storage file\r
- //\r
- Status = FvInstance->ReadFile (\r
- FvInstance,\r
- (EFI_GUID*)PcdGetPtr (PcdAcpiTableStorageFile),\r
- NULL,\r
- &Size,\r
- &FileType,\r
- &Attributes,\r
- &FvStatus\r
- );\r
-\r
- //\r
- // If we found it, then we are done\r
- //\r
- if (Status == EFI_SUCCESS) {\r
- *Instance = FvInstance;\r
- break;\r
- }\r
- }\r
-\r
- //\r
- // Our exit status is determined by the success of the previous operations\r
- // If the protocol was found, Instance already points to it.\r
- //\r
-\r
- //\r
- // Free any allocated buffers\r
- //\r
- gBS->FreePool (HandleBuffer);\r
-\r
- return Status;\r
-}\r
-\r
-\r
-/**\r
- Find ACPI tables in an FV and install them. \r
-\r
- This is now a fall-back path. Normally, we will search for tables provided\r
- by the VMM first.\r
-\r
- If that fails, we use this function to load the ACPI tables from an FV. The\r
- sources for the FV based tables is located under OvmfPkg/AcpiTables.\r
-\r
- @param AcpiTable Protocol instance pointer \r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-InstallOvmfFvTables (\r
- IN EFI_ACPI_TABLE_PROTOCOL *AcpiTable\r
- )\r
-{\r
- EFI_STATUS Status;\r
- EFI_FIRMWARE_VOLUME2_PROTOCOL *FwVol;\r
- INTN Instance;\r
- EFI_ACPI_COMMON_HEADER *CurrentTable;\r
- UINTN TableHandle;\r
- UINT32 FvStatus;\r
- UINTN TableSize;\r
- UINTN Size;\r
- EFI_ACPI_TABLE_INSTALL_ACPI_TABLE TableInstallFunction;\r
-\r
- Instance = 0;\r
- CurrentTable = NULL;\r
- TableHandle = 0;\r
-\r
- if (QemuDetected ()) {\r
- TableInstallFunction = QemuInstallAcpiTable;\r
- } else {\r
- TableInstallFunction = InstallAcpiTable;\r
- }\r
-\r
- //\r
- // Locate the firmware volume protocol\r
- //\r
- Status = LocateFvInstanceWithTables (&FwVol);\r
- if (EFI_ERROR (Status)) {\r
- return EFI_ABORTED;\r
- }\r
- //\r
- // Read tables from the storage file.\r
- //\r
- while (Status == EFI_SUCCESS) {\r
-\r
- Status = FwVol->ReadSection (\r
- FwVol,\r
- (EFI_GUID*)PcdGetPtr (PcdAcpiTableStorageFile),\r
- EFI_SECTION_RAW,\r
- Instance,\r
- (VOID**) &CurrentTable,\r
- &Size,\r
- &FvStatus\r
- );\r
- if (!EFI_ERROR (Status)) {\r
- //\r
- // Add the table\r
- //\r
- TableHandle = 0;\r
-\r
- TableSize = ((EFI_ACPI_DESCRIPTION_HEADER *) CurrentTable)->Length;\r
- ASSERT (Size >= TableSize);\r
-\r
- //\r
- // Install ACPI table\r
- //\r
- Status = TableInstallFunction (\r
- AcpiTable,\r
- CurrentTable,\r
- TableSize,\r
- &TableHandle\r
- );\r
-\r
- //\r
- // Free memory allocated by ReadSection\r
- //\r
- gBS->FreePool (CurrentTable);\r
-\r
- if (EFI_ERROR (Status)) {\r
- return EFI_ABORTED;\r
- }\r
-\r
- //\r
- // Increment the instance\r
- //\r
- Instance++;\r
- CurrentTable = NULL;\r
- }\r
- }\r
-\r
- return EFI_SUCCESS;\r
-}\r
-\r
/**\r
Effective entrypoint of Acpi Platform driver.\r
\r
EFI_STATUS\r
EFIAPI\r
InstallAcpiTables (\r
- IN EFI_ACPI_TABLE_PROTOCOL *AcpiTable\r
+ IN EFI_ACPI_TABLE_PROTOCOL *AcpiTable\r
)\r
{\r
- EFI_STATUS Status;\r
-\r
- if (XenDetected ()) {\r
- Status = InstallXenTables (AcpiTable);\r
+ EFI_STATUS Status;\r
+ UINT16 HostBridgeDevId;\r
+\r
+ HostBridgeDevId = PcdGet16 (PcdOvmfHostBridgePciDevId);\r
+ if (HostBridgeDevId == CLOUDHV_DEVICE_ID) {\r
+ if (CC_GUEST_IS_TDX (PcdGet64 (PcdConfidentialComputingGuestAttr))) {\r
+ Status = InstallCloudHvTablesTdx (AcpiTable);\r
+ } else {\r
+ Status = InstallCloudHvTables (AcpiTable);\r
+ }\r
} else {\r
Status = InstallQemuFwCfgTables (AcpiTable);\r
}\r
\r
- if (EFI_ERROR (Status)) {\r
- Status = InstallOvmfFvTables (AcpiTable);\r
- }\r
-\r
return Status;\r
}\r
-\r