From a31fcb509684c45d173919d8b980c013df300cb5 Mon Sep 17 00:00:00 2001 From: Laszlo Ersek Date: Wed, 26 May 2021 22:14:15 +0200 Subject: OvmfPkg/AcpiPlatformDxe: remove the "AcpiPlatformDxe.inf" driver MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The "OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf" module is no longer referenced in any platform DSC file; remove it. That orphans the "AcpiPlatform.c", "Qemu.c" and "Xen.c" files in the "OvmfPkg/AcpiPlatformDxe/" directory; remove them. That in turn removes the only definitions of the InstallAcpiTable(), QemuDetected(), QemuInstallAcpiTable(), InstallXenTables() functions in the "OvmfPkg/AcpiPlatformDxe/" directory, so remove their declarations from "AcpiPlatform.h". Remove "OvmfPkg/AcpiPlatformDxe/Xen.c" from the "OvmfPkg: Xen-related modules" section of "Maintainers.txt", as well. Cc: Andrew Fish Cc: Ard Biesheuvel Cc: Jordan Justen Cc: Leif Lindholm Cc: Michael D Kinney Cc: Philippe Mathieu-Daudé Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=2122 Signed-off-by: Laszlo Ersek Message-Id: <20210526201446.12554-13-lersek@redhat.com> Reviewed-by: Ard Biesheuvel Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Leif Lindholm --- Maintainers.txt | 1 - OvmfPkg/AcpiPlatformDxe/AcpiPlatform.c | 267 --------------- OvmfPkg/AcpiPlatformDxe/AcpiPlatform.h | 29 -- OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf | 69 ---- OvmfPkg/AcpiPlatformDxe/Qemu.c | 512 ---------------------------- OvmfPkg/AcpiPlatformDxe/Xen.c | 315 ----------------- 6 files changed, 1193 deletions(-) delete mode 100644 OvmfPkg/AcpiPlatformDxe/AcpiPlatform.c delete mode 100644 OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf delete mode 100644 OvmfPkg/AcpiPlatformDxe/Qemu.c delete mode 100644 OvmfPkg/AcpiPlatformDxe/Xen.c diff --git a/Maintainers.txt b/Maintainers.txt index 23cb66383a..8950ebe14a 100644 --- a/Maintainers.txt +++ b/Maintainers.txt @@ -475,7 +475,6 @@ R: Marc-André Lureau R: Stefan Berger OvmfPkg: Xen-related modules -F: OvmfPkg/AcpiPlatformDxe/Xen.c F: OvmfPkg/Include/Guid/XenBusRootDevice.h F: OvmfPkg/Include/Guid/XenInfo.h F: OvmfPkg/Include/IndustryStandard/Xen/ diff --git a/OvmfPkg/AcpiPlatformDxe/AcpiPlatform.c b/OvmfPkg/AcpiPlatformDxe/AcpiPlatform.c deleted file mode 100644 index efbbfab89d..0000000000 --- a/OvmfPkg/AcpiPlatformDxe/AcpiPlatform.c +++ /dev/null @@ -1,267 +0,0 @@ -/** @file - OVMF ACPI Platform Driver - - Copyright (c) 2008 - 2012, Intel Corporation. All rights reserved.
- SPDX-License-Identifier: BSD-2-Clause-Patent - -**/ - -#include // ASSERT_EFI_ERROR() -#include // gBS -#include // XenDetected() -#include // gEfiFirmwareVolume2Protocol... - -#include "AcpiPlatform.h" - -EFI_STATUS -EFIAPI -InstallAcpiTable ( - IN EFI_ACPI_TABLE_PROTOCOL *AcpiProtocol, - IN VOID *AcpiTableBuffer, - IN UINTN AcpiTableBufferSize, - OUT UINTN *TableKey - ) -{ - return AcpiProtocol->InstallAcpiTable ( - AcpiProtocol, - AcpiTableBuffer, - AcpiTableBufferSize, - TableKey - ); -} - - -/** - Locate the first instance of a protocol. If the protocol requested is an - FV protocol, then it will return the first FV that contains the ACPI table - storage file. - - @param Instance Return pointer to the first instance of the protocol - - @return EFI_SUCCESS The function completed successfully. - @return EFI_NOT_FOUND The protocol could not be located. - @return EFI_OUT_OF_RESOURCES There are not enough resources to find the protocol. - -**/ -EFI_STATUS -LocateFvInstanceWithTables ( - OUT EFI_FIRMWARE_VOLUME2_PROTOCOL **Instance - ) -{ - EFI_STATUS Status; - EFI_HANDLE *HandleBuffer; - UINTN NumberOfHandles; - EFI_FV_FILETYPE FileType; - UINT32 FvStatus; - EFI_FV_FILE_ATTRIBUTES Attributes; - UINTN Size; - UINTN Index; - EFI_FIRMWARE_VOLUME2_PROTOCOL *FvInstance; - - FvStatus = 0; - - // - // Locate protocol. - // - Status = gBS->LocateHandleBuffer ( - ByProtocol, - &gEfiFirmwareVolume2ProtocolGuid, - NULL, - &NumberOfHandles, - &HandleBuffer - ); - if (EFI_ERROR (Status)) { - // - // Defined errors at this time are not found and out of resources. - // - return Status; - } - - // - // Looking for FV with ACPI storage file - // - for (Index = 0; Index < NumberOfHandles; Index++) { - // - // Get the protocol on this handle - // This should not fail because of LocateHandleBuffer - // - Status = gBS->HandleProtocol ( - HandleBuffer[Index], - &gEfiFirmwareVolume2ProtocolGuid, - (VOID**) &FvInstance - ); - ASSERT_EFI_ERROR (Status); - - // - // See if it has the ACPI storage file - // - Status = FvInstance->ReadFile ( - FvInstance, - (EFI_GUID*)PcdGetPtr (PcdAcpiTableStorageFile), - NULL, - &Size, - &FileType, - &Attributes, - &FvStatus - ); - - // - // If we found it, then we are done - // - if (Status == EFI_SUCCESS) { - *Instance = FvInstance; - break; - } - } - - // - // Our exit status is determined by the success of the previous operations - // If the protocol was found, Instance already points to it. - // - - // - // Free any allocated buffers - // - gBS->FreePool (HandleBuffer); - - return Status; -} - - -/** - Find ACPI tables in an FV and install them. - - This is now a fall-back path. Normally, we will search for tables provided - by the VMM first. - - If that fails, we use this function to load the ACPI tables from an FV. The - sources for the FV based tables is located under OvmfPkg/AcpiTables. - - @param AcpiTable Protocol instance pointer - -**/ -EFI_STATUS -EFIAPI -InstallOvmfFvTables ( - IN EFI_ACPI_TABLE_PROTOCOL *AcpiTable - ) -{ - EFI_STATUS Status; - EFI_FIRMWARE_VOLUME2_PROTOCOL *FwVol; - INTN Instance; - EFI_ACPI_COMMON_HEADER *CurrentTable; - UINTN TableHandle; - UINT32 FvStatus; - UINTN TableSize; - UINTN Size; - EFI_ACPI_TABLE_INSTALL_ACPI_TABLE TableInstallFunction; - - Instance = 0; - CurrentTable = NULL; - TableHandle = 0; - - if (QemuDetected ()) { - TableInstallFunction = QemuInstallAcpiTable; - } else { - TableInstallFunction = InstallAcpiTable; - } - - // - // set FwVol (and use an ASSERT() below) to suppress incorrect - // compiler/analyzer warnings - // - FwVol = NULL; - // - // Locate the firmware volume protocol - // - Status = LocateFvInstanceWithTables (&FwVol); - if (EFI_ERROR (Status)) { - return EFI_ABORTED; - } - ASSERT (FwVol != NULL); - - // - // Read tables from the storage file. - // - while (Status == EFI_SUCCESS) { - - Status = FwVol->ReadSection ( - FwVol, - (EFI_GUID*)PcdGetPtr (PcdAcpiTableStorageFile), - EFI_SECTION_RAW, - Instance, - (VOID**) &CurrentTable, - &Size, - &FvStatus - ); - if (!EFI_ERROR (Status)) { - // - // Add the table - // - TableHandle = 0; - - TableSize = ((EFI_ACPI_DESCRIPTION_HEADER *) CurrentTable)->Length; - ASSERT (Size >= TableSize); - - // - // Install ACPI table - // - Status = TableInstallFunction ( - AcpiTable, - CurrentTable, - TableSize, - &TableHandle - ); - - // - // Free memory allocated by ReadSection - // - gBS->FreePool (CurrentTable); - - if (EFI_ERROR (Status)) { - return EFI_ABORTED; - } - - // - // Increment the instance - // - Instance++; - CurrentTable = NULL; - } - } - - return EFI_SUCCESS; -} - -/** - Effective entrypoint of Acpi Platform driver. - - @param ImageHandle - @param SystemTable - - @return EFI_SUCCESS - @return EFI_LOAD_ERROR - @return EFI_OUT_OF_RESOURCES - -**/ -EFI_STATUS -EFIAPI -InstallAcpiTables ( - IN EFI_ACPI_TABLE_PROTOCOL *AcpiTable - ) -{ - EFI_STATUS Status; - - if (XenDetected ()) { - Status = InstallXenTables (AcpiTable); - } else { - Status = InstallQemuFwCfgTables (AcpiTable); - } - - if (EFI_ERROR (Status)) { - Status = InstallOvmfFvTables (AcpiTable); - } - - return Status; -} - diff --git a/OvmfPkg/AcpiPlatformDxe/AcpiPlatform.h b/OvmfPkg/AcpiPlatformDxe/AcpiPlatform.h index d98b79baab..bd4c26f07f 100644 --- a/OvmfPkg/AcpiPlatformDxe/AcpiPlatform.h +++ b/OvmfPkg/AcpiPlatformDxe/AcpiPlatform.h @@ -19,35 +19,6 @@ typedef struct { typedef struct S3_CONTEXT S3_CONTEXT; -EFI_STATUS -EFIAPI -InstallAcpiTable ( - IN EFI_ACPI_TABLE_PROTOCOL *AcpiProtocol, - IN VOID *AcpiTableBuffer, - IN UINTN AcpiTableBufferSize, - OUT UINTN *TableKey - ); - -BOOLEAN -QemuDetected ( - VOID - ); - -EFI_STATUS -EFIAPI -QemuInstallAcpiTable ( - IN EFI_ACPI_TABLE_PROTOCOL *AcpiProtocol, - IN VOID *AcpiTableBuffer, - IN UINTN AcpiTableBufferSize, - OUT UINTN *TableKey - ); - -EFI_STATUS -EFIAPI -InstallXenTables ( - IN EFI_ACPI_TABLE_PROTOCOL *AcpiProtocol - ); - EFI_STATUS EFIAPI InstallQemuFwCfgTables ( diff --git a/OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf b/OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf deleted file mode 100644 index 77607298cb..0000000000 --- a/OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf +++ /dev/null @@ -1,69 +0,0 @@ -## @file -# OVMF ACPI Platform Driver -# -# Copyright (c) 2008 - 2019, Intel Corporation. All rights reserved.
-# SPDX-License-Identifier: BSD-2-Clause-Patent -# -## - -[Defines] - INF_VERSION = 0x00010005 - BASE_NAME = AcpiPlatform - FILE_GUID = 49970331-E3FA-4637-9ABC-3B7868676970 - MODULE_TYPE = DXE_DRIVER - VERSION_STRING = 1.0 - ENTRY_POINT = AcpiPlatformEntryPoint - -# -# The following information is for reference only and not required by the build tools. -# -# VALID_ARCHITECTURES = IA32 X64 EBC -# - -[Sources] - AcpiPlatform.c - AcpiPlatform.h - BootScript.c - EntryPoint.c - PciDecoding.c - Qemu.c - QemuFwCfgAcpi.c - Xen.c - -[Packages] - MdeModulePkg/MdeModulePkg.dec - MdePkg/MdePkg.dec - OvmfPkg/OvmfPkg.dec - UefiCpuPkg/UefiCpuPkg.dec - -[LibraryClasses] - BaseLib - BaseMemoryLib - DebugLib - DxeServicesTableLib - MemoryAllocationLib - OrderedCollectionLib - PcdLib - QemuFwCfgLib - QemuFwCfgS3Lib - UefiBootServicesTableLib - UefiDriverEntryPoint - XenPlatformLib - -[Protocols] - gEfiAcpiTableProtocolGuid # PROTOCOL ALWAYS_CONSUMED - gEfiFirmwareVolume2ProtocolGuid # PROTOCOL SOMETIMES_CONSUMED - gEfiPciIoProtocolGuid # PROTOCOL SOMETIMES_CONSUMED - -[Guids] - gRootBridgesConnectedEventGroupGuid - -[Pcd] - gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiTableStorageFile - gEfiMdeModulePkgTokenSpaceGuid.PcdPciDisableBusEnumeration - gUefiCpuPkgTokenSpaceGuid.PcdCpuLocalApicBaseAddress - gUefiOvmfPkgTokenSpaceGuid.Pcd8259LegacyModeEdgeLevel - gUefiOvmfPkgTokenSpaceGuid.PcdOvmfFdBaseAddress - -[Depex] - gEfiAcpiTableProtocolGuid diff --git a/OvmfPkg/AcpiPlatformDxe/Qemu.c b/OvmfPkg/AcpiPlatformDxe/Qemu.c deleted file mode 100644 index bdcc46b718..0000000000 --- a/OvmfPkg/AcpiPlatformDxe/Qemu.c +++ /dev/null @@ -1,512 +0,0 @@ -/** @file - OVMF ACPI QEMU support - - Copyright (c) 2008 - 2014, Intel Corporation. All rights reserved.
- - Copyright (C) 2012-2014, Red Hat, Inc. - - SPDX-License-Identifier: BSD-2-Clause-Patent - -**/ - -#include // EFI_ACPI_1_0_IO_APIC_STRUCTURE -#include // CopyMem() -#include // DEBUG() -#include // gDS -#include // AllocatePool() -#include // PcdGet16() -#include // QemuFwCfgIsAvailable() - -#include "AcpiPlatform.h" - -BOOLEAN -QemuDetected ( - VOID - ) -{ - if (!QemuFwCfgIsAvailable ()) { - return FALSE; - } - - return TRUE; -} - - -STATIC -UINTN -CountBits16 ( - UINT16 Mask - ) -{ - // - // For all N >= 1, N bits are enough to represent the number of bits set - // among N bits. It's true for N == 1. When adding a new bit (N := N+1), - // the maximum number of possibly set bits increases by one, while the - // representable maximum doubles. - // - Mask = ((Mask & 0xAAAA) >> 1) + (Mask & 0x5555); - Mask = ((Mask & 0xCCCC) >> 2) + (Mask & 0x3333); - Mask = ((Mask & 0xF0F0) >> 4) + (Mask & 0x0F0F); - Mask = ((Mask & 0xFF00) >> 8) + (Mask & 0x00FF); - - return Mask; -} - - -STATIC -EFI_STATUS -EFIAPI -QemuInstallAcpiMadtTable ( - IN EFI_ACPI_TABLE_PROTOCOL *AcpiProtocol, - IN VOID *AcpiTableBuffer, - IN UINTN AcpiTableBufferSize, - OUT UINTN *TableKey - ) -{ - UINTN CpuCount; - UINTN PciLinkIsoCount; - UINTN NewBufferSize; - EFI_ACPI_1_0_MULTIPLE_APIC_DESCRIPTION_TABLE_HEADER *Madt; - EFI_ACPI_1_0_PROCESSOR_LOCAL_APIC_STRUCTURE *LocalApic; - EFI_ACPI_1_0_IO_APIC_STRUCTURE *IoApic; - EFI_ACPI_1_0_INTERRUPT_SOURCE_OVERRIDE_STRUCTURE *Iso; - EFI_ACPI_1_0_LOCAL_APIC_NMI_STRUCTURE *LocalApicNmi; - VOID *Ptr; - UINTN Loop; - EFI_STATUS Status; - - ASSERT (AcpiTableBufferSize >= sizeof (EFI_ACPI_DESCRIPTION_HEADER)); - - QemuFwCfgSelectItem (QemuFwCfgItemSmpCpuCount); - CpuCount = QemuFwCfgRead16 (); - ASSERT (CpuCount >= 1); - - // - // Set Level-tiggered, Active High for these identity mapped IRQs. The bitset - // corresponds to the union of all possible interrupt assignments for the LNKA, - // LNKB, LNKC, LNKD PCI interrupt lines. See the DSDT. - // - PciLinkIsoCount = CountBits16 (PcdGet16 (Pcd8259LegacyModeEdgeLevel)); - - NewBufferSize = 1 * sizeof (*Madt) + - CpuCount * sizeof (*LocalApic) + - 1 * sizeof (*IoApic) + - (1 + PciLinkIsoCount) * sizeof (*Iso) + - 1 * sizeof (*LocalApicNmi); - - Madt = AllocatePool (NewBufferSize); - if (Madt == NULL) { - return EFI_OUT_OF_RESOURCES; - } - - CopyMem (&(Madt->Header), AcpiTableBuffer, sizeof (EFI_ACPI_DESCRIPTION_HEADER)); - Madt->Header.Length = (UINT32) NewBufferSize; - Madt->LocalApicAddress = PcdGet32 (PcdCpuLocalApicBaseAddress); - Madt->Flags = EFI_ACPI_1_0_PCAT_COMPAT; - Ptr = Madt + 1; - - LocalApic = Ptr; - for (Loop = 0; Loop < CpuCount; ++Loop) { - LocalApic->Type = EFI_ACPI_1_0_PROCESSOR_LOCAL_APIC; - LocalApic->Length = sizeof (*LocalApic); - LocalApic->AcpiProcessorId = (UINT8) Loop; - LocalApic->ApicId = (UINT8) Loop; - LocalApic->Flags = 1; // enabled - ++LocalApic; - } - Ptr = LocalApic; - - IoApic = Ptr; - IoApic->Type = EFI_ACPI_1_0_IO_APIC; - IoApic->Length = sizeof (*IoApic); - IoApic->IoApicId = (UINT8) CpuCount; - IoApic->Reserved = EFI_ACPI_RESERVED_BYTE; - IoApic->IoApicAddress = 0xFEC00000; - IoApic->SystemVectorBase = 0x00000000; - Ptr = IoApic + 1; - - // - // IRQ0 (8254 Timer) => IRQ2 (PIC) Interrupt Source Override Structure - // - Iso = Ptr; - Iso->Type = EFI_ACPI_1_0_INTERRUPT_SOURCE_OVERRIDE; - Iso->Length = sizeof (*Iso); - Iso->Bus = 0x00; // ISA - Iso->Source = 0x00; // IRQ0 - Iso->GlobalSystemInterruptVector = 0x00000002; - Iso->Flags = 0x0000; // Conforms to specs of the bus - ++Iso; - - // - // Set Level-triggered, Active High for all possible PCI link targets. - // - for (Loop = 0; Loop < 16; ++Loop) { - if ((PcdGet16 (Pcd8259LegacyModeEdgeLevel) & (1 << Loop)) == 0) { - continue; - } - Iso->Type = EFI_ACPI_1_0_INTERRUPT_SOURCE_OVERRIDE; - Iso->Length = sizeof (*Iso); - Iso->Bus = 0x00; // ISA - Iso->Source = (UINT8) Loop; - Iso->GlobalSystemInterruptVector = (UINT32) Loop; - Iso->Flags = 0x000D; // Level-triggered, Active High - ++Iso; - } - ASSERT ( - (UINTN) (Iso - (EFI_ACPI_1_0_INTERRUPT_SOURCE_OVERRIDE_STRUCTURE *)Ptr) == - 1 + PciLinkIsoCount - ); - Ptr = Iso; - - LocalApicNmi = Ptr; - LocalApicNmi->Type = EFI_ACPI_1_0_LOCAL_APIC_NMI; - LocalApicNmi->Length = sizeof (*LocalApicNmi); - LocalApicNmi->AcpiProcessorId = 0xFF; // applies to all processors - // - // polarity and trigger mode of the APIC I/O input signals conform to the - // specifications of the bus - // - LocalApicNmi->Flags = 0x0000; - // - // Local APIC interrupt input LINTn to which NMI is connected. - // - LocalApicNmi->LocalApicInti = 0x01; - Ptr = LocalApicNmi + 1; - - ASSERT ((UINTN) ((UINT8 *)Ptr - (UINT8 *)Madt) == NewBufferSize); - Status = InstallAcpiTable (AcpiProtocol, Madt, NewBufferSize, TableKey); - - FreePool (Madt); - - return Status; -} - - -#pragma pack(1) - -typedef struct { - UINT64 Base; - UINT64 End; - UINT64 Length; -} PCI_WINDOW; - -typedef struct { - PCI_WINDOW PciWindow32; - PCI_WINDOW PciWindow64; -} FIRMWARE_DATA; - -typedef struct { - UINT8 BytePrefix; - UINT8 ByteValue; -} AML_BYTE; - -typedef struct { - UINT8 NameOp; - UINT8 RootChar; - UINT8 NameChar[4]; - UINT8 PackageOp; - UINT8 PkgLength; - UINT8 NumElements; - AML_BYTE Pm1aCntSlpTyp; - AML_BYTE Pm1bCntSlpTyp; - AML_BYTE Reserved[2]; -} SYSTEM_STATE_PACKAGE; - -#pragma pack() - - -STATIC -EFI_STATUS -EFIAPI -PopulateFwData( - OUT FIRMWARE_DATA *FwData - ) -{ - EFI_STATUS Status; - UINTN NumDesc; - EFI_GCD_MEMORY_SPACE_DESCRIPTOR *AllDesc; - - Status = gDS->GetMemorySpaceMap (&NumDesc, &AllDesc); - if (Status == EFI_SUCCESS) { - UINT64 NonMmio32MaxExclTop; - UINT64 Mmio32MinBase; - UINT64 Mmio32MaxExclTop; - UINTN CurDesc; - - Status = EFI_UNSUPPORTED; - - NonMmio32MaxExclTop = 0; - Mmio32MinBase = BASE_4GB; - Mmio32MaxExclTop = 0; - - for (CurDesc = 0; CurDesc < NumDesc; ++CurDesc) { - CONST EFI_GCD_MEMORY_SPACE_DESCRIPTOR *Desc; - UINT64 ExclTop; - - Desc = &AllDesc[CurDesc]; - ExclTop = Desc->BaseAddress + Desc->Length; - - if (ExclTop <= (UINT64) PcdGet32 (PcdOvmfFdBaseAddress)) { - switch (Desc->GcdMemoryType) { - case EfiGcdMemoryTypeNonExistent: - break; - - case EfiGcdMemoryTypeReserved: - case EfiGcdMemoryTypeSystemMemory: - if (NonMmio32MaxExclTop < ExclTop) { - NonMmio32MaxExclTop = ExclTop; - } - break; - - case EfiGcdMemoryTypeMemoryMappedIo: - if (Mmio32MinBase > Desc->BaseAddress) { - Mmio32MinBase = Desc->BaseAddress; - } - if (Mmio32MaxExclTop < ExclTop) { - Mmio32MaxExclTop = ExclTop; - } - break; - - default: - ASSERT(0); - } - } - } - - if (Mmio32MinBase < NonMmio32MaxExclTop) { - Mmio32MinBase = NonMmio32MaxExclTop; - } - - if (Mmio32MinBase < Mmio32MaxExclTop) { - FwData->PciWindow32.Base = Mmio32MinBase; - FwData->PciWindow32.End = Mmio32MaxExclTop - 1; - FwData->PciWindow32.Length = Mmio32MaxExclTop - Mmio32MinBase; - - FwData->PciWindow64.Base = 0; - FwData->PciWindow64.End = 0; - FwData->PciWindow64.Length = 0; - - Status = EFI_SUCCESS; - } - - FreePool (AllDesc); - } - - DEBUG (( - DEBUG_INFO, - "ACPI PciWindow32: Base=0x%08lx End=0x%08lx Length=0x%08lx\n", - FwData->PciWindow32.Base, - FwData->PciWindow32.End, - FwData->PciWindow32.Length - )); - DEBUG (( - DEBUG_INFO, - "ACPI PciWindow64: Base=0x%08lx End=0x%08lx Length=0x%08lx\n", - FwData->PciWindow64.Base, - FwData->PciWindow64.End, - FwData->PciWindow64.Length - )); - - return Status; -} - - -STATIC -VOID -EFIAPI -GetSuspendStates ( - UINTN *SuspendToRamSize, - SYSTEM_STATE_PACKAGE *SuspendToRam, - UINTN *SuspendToDiskSize, - SYSTEM_STATE_PACKAGE *SuspendToDisk - ) -{ - STATIC CONST SYSTEM_STATE_PACKAGE Template = { - 0x08, // NameOp - '\\', // RootChar - { '_', 'S', 'x', '_' }, // NameChar[4] - 0x12, // PackageOp - 0x0A, // PkgLength - 0x04, // NumElements - { 0x0A, 0x00 }, // Pm1aCntSlpTyp - { 0x0A, 0x00 }, // Pm1bCntSlpTyp -- we don't support it - { // Reserved[2] - { 0x0A, 0x00 }, - { 0x0A, 0x00 } - } - }; - RETURN_STATUS Status; - FIRMWARE_CONFIG_ITEM FwCfgItem; - UINTN FwCfgSize; - UINT8 SystemStates[6]; - - // - // configure defaults - // - *SuspendToRamSize = sizeof Template; - CopyMem (SuspendToRam, &Template, sizeof Template); - SuspendToRam->NameChar[2] = '3'; // S3 - SuspendToRam->Pm1aCntSlpTyp.ByteValue = 1; // PIIX4: STR - - *SuspendToDiskSize = sizeof Template; - CopyMem (SuspendToDisk, &Template, sizeof Template); - SuspendToDisk->NameChar[2] = '4'; // S4 - SuspendToDisk->Pm1aCntSlpTyp.ByteValue = 2; // PIIX4: POSCL - - // - // check for overrides - // - Status = QemuFwCfgFindFile ("etc/system-states", &FwCfgItem, &FwCfgSize); - if (Status != RETURN_SUCCESS || FwCfgSize != sizeof SystemStates) { - DEBUG ((DEBUG_INFO, "ACPI using S3/S4 defaults\n")); - return; - } - QemuFwCfgSelectItem (FwCfgItem); - QemuFwCfgReadBytes (sizeof SystemStates, SystemStates); - - // - // Each byte corresponds to a system state. In each byte, the MSB tells us - // whether the given state is enabled. If so, the three LSBs specify the - // value to be written to the PM control register's SUS_TYP bits. - // - if (SystemStates[3] & BIT7) { - SuspendToRam->Pm1aCntSlpTyp.ByteValue = - SystemStates[3] & (BIT2 | BIT1 | BIT0); - DEBUG ((DEBUG_INFO, "ACPI S3 value: %d\n", - SuspendToRam->Pm1aCntSlpTyp.ByteValue)); - } else { - *SuspendToRamSize = 0; - DEBUG ((DEBUG_INFO, "ACPI S3 disabled\n")); - } - - if (SystemStates[4] & BIT7) { - SuspendToDisk->Pm1aCntSlpTyp.ByteValue = - SystemStates[4] & (BIT2 | BIT1 | BIT0); - DEBUG ((DEBUG_INFO, "ACPI S4 value: %d\n", - SuspendToDisk->Pm1aCntSlpTyp.ByteValue)); - } else { - *SuspendToDiskSize = 0; - DEBUG ((DEBUG_INFO, "ACPI S4 disabled\n")); - } -} - - -STATIC -EFI_STATUS -EFIAPI -QemuInstallAcpiSsdtTable ( - IN EFI_ACPI_TABLE_PROTOCOL *AcpiProtocol, - IN VOID *AcpiTableBuffer, - IN UINTN AcpiTableBufferSize, - OUT UINTN *TableKey - ) -{ - EFI_STATUS Status; - FIRMWARE_DATA *FwData; - - Status = EFI_OUT_OF_RESOURCES; - - FwData = AllocateReservedPool (sizeof (*FwData)); - if (FwData != NULL) { - UINTN SuspendToRamSize; - SYSTEM_STATE_PACKAGE SuspendToRam; - UINTN SuspendToDiskSize; - SYSTEM_STATE_PACKAGE SuspendToDisk; - UINTN SsdtSize; - UINT8 *Ssdt; - - GetSuspendStates (&SuspendToRamSize, &SuspendToRam, - &SuspendToDiskSize, &SuspendToDisk); - SsdtSize = AcpiTableBufferSize + 17 + SuspendToRamSize + SuspendToDiskSize; - Ssdt = AllocatePool (SsdtSize); - - if (Ssdt != NULL) { - Status = PopulateFwData (FwData); - - if (Status == EFI_SUCCESS) { - UINT8 *SsdtPtr; - - SsdtPtr = Ssdt; - - CopyMem (SsdtPtr, AcpiTableBuffer, AcpiTableBufferSize); - SsdtPtr += AcpiTableBufferSize; - - // - // build "OperationRegion(FWDT, SystemMemory, 0x12345678, 0x87654321)" - // - *(SsdtPtr++) = 0x5B; // ExtOpPrefix - *(SsdtPtr++) = 0x80; // OpRegionOp - *(SsdtPtr++) = 'F'; - *(SsdtPtr++) = 'W'; - *(SsdtPtr++) = 'D'; - *(SsdtPtr++) = 'T'; - *(SsdtPtr++) = 0x00; // SystemMemory - *(SsdtPtr++) = 0x0C; // DWordPrefix - - // - // no virtual addressing yet, take the four least significant bytes - // - CopyMem(SsdtPtr, &FwData, 4); - SsdtPtr += 4; - - *(SsdtPtr++) = 0x0C; // DWordPrefix - - *(UINT32*) SsdtPtr = sizeof (*FwData); - SsdtPtr += 4; - - // - // add suspend system states - // - CopyMem (SsdtPtr, &SuspendToRam, SuspendToRamSize); - SsdtPtr += SuspendToRamSize; - CopyMem (SsdtPtr, &SuspendToDisk, SuspendToDiskSize); - SsdtPtr += SuspendToDiskSize; - - ASSERT((UINTN) (SsdtPtr - Ssdt) == SsdtSize); - ((EFI_ACPI_DESCRIPTION_HEADER *) Ssdt)->Length = (UINT32) SsdtSize; - Status = InstallAcpiTable (AcpiProtocol, Ssdt, SsdtSize, TableKey); - } - - FreePool(Ssdt); - } - - if (Status != EFI_SUCCESS) { - FreePool(FwData); - } - } - - return Status; -} - - -EFI_STATUS -EFIAPI -QemuInstallAcpiTable ( - IN EFI_ACPI_TABLE_PROTOCOL *AcpiProtocol, - IN VOID *AcpiTableBuffer, - IN UINTN AcpiTableBufferSize, - OUT UINTN *TableKey - ) -{ - EFI_ACPI_DESCRIPTION_HEADER *Hdr; - EFI_ACPI_TABLE_INSTALL_ACPI_TABLE TableInstallFunction; - - Hdr = (EFI_ACPI_DESCRIPTION_HEADER*) AcpiTableBuffer; - switch (Hdr->Signature) { - case EFI_ACPI_1_0_APIC_SIGNATURE: - TableInstallFunction = QemuInstallAcpiMadtTable; - break; - case EFI_ACPI_1_0_SECONDARY_SYSTEM_DESCRIPTION_TABLE_SIGNATURE: - TableInstallFunction = QemuInstallAcpiSsdtTable; - break; - default: - TableInstallFunction = InstallAcpiTable; - } - - return TableInstallFunction ( - AcpiProtocol, - AcpiTableBuffer, - AcpiTableBufferSize, - TableKey - ); -} diff --git a/OvmfPkg/AcpiPlatformDxe/Xen.c b/OvmfPkg/AcpiPlatformDxe/Xen.c deleted file mode 100644 index be2c5d6958..0000000000 --- a/OvmfPkg/AcpiPlatformDxe/Xen.c +++ /dev/null @@ -1,315 +0,0 @@ -/** @file - OVMF ACPI Xen support - - Copyright (c) 2008 - 2012, Intel Corporation. All rights reserved.
- Copyright (c) 2012, Bei Guan - - SPDX-License-Identifier: BSD-2-Clause-Patent - -**/ - -#include // CpuDeadLoop() -#include // DEBUG() -#include // XenGetInfoHOB() - -#include "AcpiPlatform.h" - -#define XEN_ACPI_PHYSICAL_ADDRESS 0x000EA020 -#define XEN_BIOS_PHYSICAL_END 0x000FFFFF - -EFI_ACPI_2_0_ROOT_SYSTEM_DESCRIPTION_POINTER *XenAcpiRsdpStructurePtr = NULL; - -/** - Get the address of Xen ACPI Root System Description Pointer (RSDP) - structure. - - @param RsdpStructurePtr Return pointer to RSDP structure - - @return EFI_SUCCESS Find Xen RSDP structure successfully. - @return EFI_NOT_FOUND Don't find Xen RSDP structure. - @return EFI_ABORTED Find Xen RSDP structure, but it's not integrated. - -**/ -EFI_STATUS -EFIAPI -GetXenAcpiRsdp ( - OUT EFI_ACPI_2_0_ROOT_SYSTEM_DESCRIPTION_POINTER **RsdpPtr - ) -{ - EFI_ACPI_2_0_ROOT_SYSTEM_DESCRIPTION_POINTER *RsdpStructurePtr; - UINT8 *XenAcpiPtr; - UINT8 Sum; - EFI_XEN_INFO *XenInfo; - - // - // Detect the RSDP structure - // - - // - // First look for PVH one - // - XenInfo = XenGetInfoHOB (); - ASSERT (XenInfo != NULL); - if (XenInfo->RsdpPvh != NULL) { - DEBUG ((DEBUG_INFO, "%a: Use ACPI RSDP table at 0x%p\n", - gEfiCallerBaseName, XenInfo->RsdpPvh)); - *RsdpPtr = XenInfo->RsdpPvh; - return EFI_SUCCESS; - } - - // - // Otherwise, look for the HVM one - // - for (XenAcpiPtr = (UINT8*)(UINTN) XEN_ACPI_PHYSICAL_ADDRESS; - XenAcpiPtr < (UINT8*)(UINTN) XEN_BIOS_PHYSICAL_END; - XenAcpiPtr += 0x10) { - - RsdpStructurePtr = (EFI_ACPI_2_0_ROOT_SYSTEM_DESCRIPTION_POINTER *) - (UINTN) XenAcpiPtr; - - if (!AsciiStrnCmp ((CHAR8 *) &RsdpStructurePtr->Signature, "RSD PTR ", 8)) { - // - // RSDP ACPI 1.0 checksum for 1.0/2.0/3.0 table. - // This is only the first 20 bytes of the structure - // - Sum = CalculateSum8 ( - (CONST UINT8 *)RsdpStructurePtr, - sizeof (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER) - ); - if (Sum != 0) { - return EFI_ABORTED; - } - - if (RsdpStructurePtr->Revision >= 2) { - // - // RSDP ACPI 2.0/3.0 checksum, this is the entire table - // - Sum = CalculateSum8 ( - (CONST UINT8 *)RsdpStructurePtr, - sizeof (EFI_ACPI_2_0_ROOT_SYSTEM_DESCRIPTION_POINTER) - ); - if (Sum != 0) { - return EFI_ABORTED; - } - } - *RsdpPtr = RsdpStructurePtr; - return EFI_SUCCESS; - } - } - - return EFI_NOT_FOUND; -} - -/** - Get Xen Acpi tables from the RSDP structure. And installs Xen ACPI tables - into the RSDT/XSDT using InstallAcpiTable. Some signature of the installed - ACPI tables are: FACP, APIC, HPET, WAET, SSDT, FACS, DSDT. - - @param AcpiProtocol Protocol instance pointer. - - @return EFI_SUCCESS The table was successfully inserted. - @return EFI_INVALID_PARAMETER Either AcpiTableBuffer is NULL, TableHandle is - NULL, or AcpiTableBufferSize and the size - field embedded in the ACPI table pointed to - by AcpiTableBuffer are not in sync. - @return EFI_OUT_OF_RESOURCES Insufficient resources exist to complete the request. - -**/ -EFI_STATUS -EFIAPI -InstallXenTables ( - IN EFI_ACPI_TABLE_PROTOCOL *AcpiProtocol - ) -{ - EFI_STATUS Status; - UINTN TableHandle; - - EFI_ACPI_DESCRIPTION_HEADER *Rsdt; - EFI_ACPI_DESCRIPTION_HEADER *Xsdt; - VOID *CurrentTableEntry; - UINTN CurrentTablePointer; - EFI_ACPI_DESCRIPTION_HEADER *CurrentTable; - UINTN Index; - UINTN NumberOfTableEntries; - EFI_ACPI_2_0_FIXED_ACPI_DESCRIPTION_TABLE *Fadt2Table; - EFI_ACPI_1_0_FIXED_ACPI_DESCRIPTION_TABLE *Fadt1Table; - EFI_ACPI_2_0_FIRMWARE_ACPI_CONTROL_STRUCTURE *Facs2Table; - EFI_ACPI_1_0_FIRMWARE_ACPI_CONTROL_STRUCTURE *Facs1Table; - EFI_ACPI_DESCRIPTION_HEADER *DsdtTable; - - Fadt2Table = NULL; - Fadt1Table = NULL; - Facs2Table = NULL; - Facs1Table = NULL; - DsdtTable = NULL; - TableHandle = 0; - NumberOfTableEntries = 0; - - // - // Try to find Xen ACPI tables - // - Status = GetXenAcpiRsdp (&XenAcpiRsdpStructurePtr); - if (EFI_ERROR (Status)) { - return Status; - } - - // - // If XSDT table is find, just install its tables. - // Otherwise, try to find and install the RSDT tables. - // - if (XenAcpiRsdpStructurePtr->XsdtAddress) { - // - // Retrieve the addresses of XSDT and - // calculate the number of its table entries. - // - Xsdt = (EFI_ACPI_DESCRIPTION_HEADER *) (UINTN) - XenAcpiRsdpStructurePtr->XsdtAddress; - NumberOfTableEntries = (Xsdt->Length - - sizeof (EFI_ACPI_DESCRIPTION_HEADER)) / - sizeof (UINT64); - - // - // Install ACPI tables found in XSDT. - // - for (Index = 0; Index < NumberOfTableEntries; Index++) { - // - // Get the table entry from XSDT - // - CurrentTableEntry = (VOID *) ((UINT8 *) Xsdt + - sizeof (EFI_ACPI_DESCRIPTION_HEADER) + - Index * sizeof (UINT64)); - CurrentTablePointer = (UINTN) *(UINT64 *)CurrentTableEntry; - CurrentTable = (EFI_ACPI_DESCRIPTION_HEADER *) CurrentTablePointer; - - // - // Install the XSDT tables - // - Status = InstallAcpiTable ( - AcpiProtocol, - CurrentTable, - CurrentTable->Length, - &TableHandle - ); - - if (EFI_ERROR (Status)) { - return Status; - } - - // - // Get the FACS and DSDT table address from the table FADT - // - if (!AsciiStrnCmp ((CHAR8 *) &CurrentTable->Signature, "FACP", 4)) { - Fadt2Table = (EFI_ACPI_2_0_FIXED_ACPI_DESCRIPTION_TABLE *) - (UINTN) CurrentTablePointer; - Facs2Table = (EFI_ACPI_2_0_FIRMWARE_ACPI_CONTROL_STRUCTURE *) - (UINTN) Fadt2Table->FirmwareCtrl; - DsdtTable = (EFI_ACPI_DESCRIPTION_HEADER *) (UINTN) Fadt2Table->Dsdt; - } - } - } - else if (XenAcpiRsdpStructurePtr->RsdtAddress) { - // - // Retrieve the addresses of RSDT and - // calculate the number of its table entries. - // - Rsdt = (EFI_ACPI_DESCRIPTION_HEADER *) (UINTN) - XenAcpiRsdpStructurePtr->RsdtAddress; - NumberOfTableEntries = (Rsdt->Length - - sizeof (EFI_ACPI_DESCRIPTION_HEADER)) / - sizeof (UINT32); - - // - // Install ACPI tables found in XSDT. - // - for (Index = 0; Index < NumberOfTableEntries; Index++) { - // - // Get the table entry from RSDT - // - CurrentTableEntry = (UINT32 *) ((UINT8 *) Rsdt + - sizeof (EFI_ACPI_DESCRIPTION_HEADER) + - Index * sizeof (UINT32)); - CurrentTablePointer = *(UINT32 *)CurrentTableEntry; - CurrentTable = (EFI_ACPI_DESCRIPTION_HEADER *) CurrentTablePointer; - - // - // Install the RSDT tables - // - Status = InstallAcpiTable ( - AcpiProtocol, - CurrentTable, - CurrentTable->Length, - &TableHandle - ); - - if (EFI_ERROR (Status)) { - return Status; - } - - // - // Get the FACS and DSDT table address from the table FADT - // - if (!AsciiStrnCmp ((CHAR8 *) &CurrentTable->Signature, "FACP", 4)) { - Fadt1Table = (EFI_ACPI_1_0_FIXED_ACPI_DESCRIPTION_TABLE *) - (UINTN) CurrentTablePointer; - Facs1Table = (EFI_ACPI_1_0_FIRMWARE_ACPI_CONTROL_STRUCTURE *) - (UINTN) Fadt1Table->FirmwareCtrl; - DsdtTable = (EFI_ACPI_DESCRIPTION_HEADER *) (UINTN) Fadt1Table->Dsdt; - } - } - } - - // - // Install the FACS table. - // - if (Fadt2Table) { - // - // FACS 2.0 - // - Status = InstallAcpiTable ( - AcpiProtocol, - Facs2Table, - Facs2Table->Length, - &TableHandle - ); - if (EFI_ERROR (Status)) { - return Status; - } - } - else if (Fadt1Table) { - // - // FACS 1.0 - // - Status = InstallAcpiTable ( - AcpiProtocol, - Facs1Table, - Facs1Table->Length, - &TableHandle - ); - if (EFI_ERROR (Status)) { - return Status; - } - } - - // - // Install DSDT table. If we reached this point without finding the DSDT, - // then we're out of sync with the hypervisor, and cannot continue. - // - if (DsdtTable == NULL) { - DEBUG ((DEBUG_ERROR, "%a: no DSDT found\n", __FUNCTION__)); - ASSERT (FALSE); - CpuDeadLoop (); - } - - Status = InstallAcpiTable ( - AcpiProtocol, - DsdtTable, - DsdtTable->Length, - &TableHandle - ); - if (EFI_ERROR (Status)) { - return Status; - } - - return EFI_SUCCESS; -} - -- cgit v1.2.3