2012-05-31 01:15:27 +02:00
|
|
|
/** @file
|
|
|
|
OVMF ACPI QEMU support
|
|
|
|
|
|
|
|
Copyright (c) 2008 - 2012, Intel Corporation. All rights reserved.<BR>
|
2012-12-17 03:13:14 +01:00
|
|
|
|
|
|
|
Copyright (C) 2012, Red Hat, Inc.
|
|
|
|
|
2012-05-31 01:15:27 +02:00
|
|
|
This program and the accompanying materials
|
|
|
|
are licensed and made available under the terms and conditions of the BSD License
|
|
|
|
which accompanies this distribution. The full text of the license may be found at
|
|
|
|
http://opensource.org/licenses/bsd-license.php
|
|
|
|
|
|
|
|
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
|
|
|
|
2012-07-31 20:17:51 +02:00
|
|
|
**/
|
2012-05-31 01:15:27 +02:00
|
|
|
|
|
|
|
#include "AcpiPlatform.h"
|
2012-05-31 01:15:59 +02:00
|
|
|
#include <Library/BaseMemoryLib.h>
|
|
|
|
#include <Library/MemoryAllocationLib.h>
|
2012-05-31 01:15:27 +02:00
|
|
|
#include <Library/QemuFwCfgLib.h>
|
2012-07-31 20:18:01 +02:00
|
|
|
#include <Library/DxeServicesTableLib.h>
|
2012-08-13 17:42:07 +02:00
|
|
|
#include <Library/PcdLib.h>
|
|
|
|
#include <IndustryStandard/Acpi.h>
|
2012-05-31 01:15:27 +02:00
|
|
|
|
|
|
|
BOOLEAN
|
|
|
|
QemuDetected (
|
|
|
|
VOID
|
|
|
|
)
|
|
|
|
{
|
|
|
|
if (!QemuFwCfgIsAvailable ()) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-08-13 17:42:07 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-05-31 01:15:59 +02:00
|
|
|
STATIC
|
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
QemuInstallAcpiMadtTable (
|
|
|
|
IN EFI_ACPI_TABLE_PROTOCOL *AcpiProtocol,
|
|
|
|
IN VOID *AcpiTableBuffer,
|
|
|
|
IN UINTN AcpiTableBufferSize,
|
|
|
|
OUT UINTN *TableKey
|
|
|
|
)
|
|
|
|
{
|
2012-08-13 17:42:07 +02:00
|
|
|
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));
|
2012-05-31 01:15:59 +02:00
|
|
|
|
|
|
|
QemuFwCfgSelectItem (QemuFwCfgItemSmpCpuCount);
|
2012-08-13 17:42:07 +02:00
|
|
|
CpuCount = QemuFwCfgRead16 ();
|
|
|
|
ASSERT (CpuCount >= 1);
|
2012-05-31 01:15:59 +02:00
|
|
|
|
|
|
|
//
|
2012-08-13 17:42:07 +02:00
|
|
|
// 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.
|
2012-05-31 01:15:59 +02:00
|
|
|
//
|
2012-08-13 17:42:07 +02:00
|
|
|
PciLinkIsoCount = CountBits16 (PcdGet16 (Pcd8259LegacyModeEdgeLevel));
|
2012-05-31 01:15:59 +02:00
|
|
|
|
2012-08-13 17:42:07 +02:00
|
|
|
NewBufferSize = 1 * sizeof (*Madt) +
|
|
|
|
CpuCount * sizeof (*LocalApic) +
|
|
|
|
1 * sizeof (*IoApic) +
|
|
|
|
(1 + PciLinkIsoCount) * sizeof (*Iso) +
|
|
|
|
1 * sizeof (*LocalApicNmi);
|
2012-05-31 01:15:59 +02:00
|
|
|
|
2012-08-13 17:42:07 +02:00
|
|
|
Madt = AllocatePool (NewBufferSize);
|
|
|
|
if (Madt == NULL) {
|
|
|
|
return EFI_OUT_OF_RESOURCES;
|
|
|
|
}
|
|
|
|
|
2012-08-15 02:03:35 +02:00
|
|
|
CopyMem (&(Madt->Header), AcpiTableBuffer, sizeof (EFI_ACPI_DESCRIPTION_HEADER));
|
|
|
|
Madt->Header.Length = (UINT32) NewBufferSize;
|
2012-08-13 17:42:07 +02:00
|
|
|
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);
|
2012-08-15 02:03:35 +02:00
|
|
|
LocalApic->AcpiProcessorId = (UINT8) Loop;
|
|
|
|
LocalApic->ApicId = (UINT8) Loop;
|
2012-08-13 17:42:07 +02:00
|
|
|
LocalApic->Flags = 1; // enabled
|
|
|
|
++LocalApic;
|
|
|
|
}
|
|
|
|
Ptr = LocalApic;
|
|
|
|
|
|
|
|
IoApic = Ptr;
|
|
|
|
IoApic->Type = EFI_ACPI_1_0_IO_APIC;
|
|
|
|
IoApic->Length = sizeof (*IoApic);
|
2012-08-15 02:03:35 +02:00
|
|
|
IoApic->IoApicId = (UINT8) CpuCount;
|
2012-08-13 17:42:07 +02:00
|
|
|
IoApic->Reserved = EFI_ACPI_RESERVED_BYTE;
|
|
|
|
IoApic->IoApicAddress = 0xFEC00000;
|
|
|
|
IoApic->SystemVectorBase = 0x00000000;
|
|
|
|
Ptr = IoApic + 1;
|
2012-05-31 01:15:59 +02:00
|
|
|
|
|
|
|
//
|
2012-08-13 17:42:07 +02:00
|
|
|
// IRQ0 (8254 Timer) => IRQ2 (PIC) Interrupt Source Override Structure
|
2012-05-31 01:15:59 +02:00
|
|
|
//
|
2012-08-13 17:42:07 +02:00
|
|
|
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;
|
2012-05-31 01:15:59 +02:00
|
|
|
|
2012-08-13 17:42:07 +02:00
|
|
|
//
|
|
|
|
// Set Level-tiggered, 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
|
2012-08-15 02:03:35 +02:00
|
|
|
Iso->Source = (UINT8) Loop;
|
|
|
|
Iso->GlobalSystemInterruptVector = (UINT32) Loop;
|
2012-08-13 17:42:07 +02:00
|
|
|
Iso->Flags = 0x000D; // Level-tiggered, Active High
|
|
|
|
++Iso;
|
|
|
|
}
|
|
|
|
ASSERT (
|
2012-08-15 02:03:35 +02:00
|
|
|
(UINTN) (Iso - (EFI_ACPI_1_0_INTERRUPT_SOURCE_OVERRIDE_STRUCTURE *)Ptr) ==
|
2012-08-13 17:42:07 +02:00
|
|
|
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;
|
2012-05-31 01:15:59 +02:00
|
|
|
|
2012-08-15 02:03:35 +02:00
|
|
|
ASSERT ((UINTN) ((UINT8 *)Ptr - (UINT8 *)Madt) == NewBufferSize);
|
2012-08-13 17:42:07 +02:00
|
|
|
Status = InstallAcpiTable (AcpiProtocol, Madt, NewBufferSize, TableKey);
|
2012-05-31 01:15:59 +02:00
|
|
|
|
2012-08-13 17:42:07 +02:00
|
|
|
FreePool (Madt);
|
2012-05-31 01:15:59 +02:00
|
|
|
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-07-31 20:17:51 +02:00
|
|
|
#pragma pack(1)
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
UINT64 Base;
|
|
|
|
UINT64 End;
|
|
|
|
UINT64 Length;
|
|
|
|
} PCI_WINDOW;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
PCI_WINDOW PciWindow32;
|
|
|
|
PCI_WINDOW PciWindow64;
|
|
|
|
} FIRMWARE_DATA;
|
|
|
|
|
2012-12-17 03:13:14 +01:00
|
|
|
typedef struct {
|
2013-02-14 20:20:57 +01:00
|
|
|
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];
|
2012-12-17 03:13:14 +01:00
|
|
|
} SYSTEM_STATE_PACKAGE;
|
|
|
|
|
2012-07-31 20:17:51 +02:00
|
|
|
#pragma pack()
|
|
|
|
|
|
|
|
|
|
|
|
STATIC
|
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
PopulateFwData(
|
|
|
|
OUT FIRMWARE_DATA *FwData
|
|
|
|
)
|
|
|
|
{
|
2012-07-31 20:18:01 +02:00
|
|
|
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;
|
|
|
|
|
2013-11-12 19:34:36 +01:00
|
|
|
if (ExclTop <= (UINT64) PcdGet32 (PcdOvmfFdBaseAddress)) {
|
2012-07-31 20:18:01 +02:00
|
|
|
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;
|
2012-07-31 20:17:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-12-17 03:13:14 +01:00
|
|
|
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
|
2013-02-14 20:20:57 +01:00
|
|
|
0x0A, // PkgLength
|
|
|
|
0x04, // NumElements
|
|
|
|
{ 0x0A, 0x00 }, // Pm1aCntSlpTyp
|
|
|
|
{ 0x0A, 0x00 }, // Pm1bCntSlpTyp -- we don't support it
|
|
|
|
{ // Reserved[2]
|
|
|
|
{ 0x0A, 0x00 },
|
|
|
|
{ 0x0A, 0x00 }
|
|
|
|
}
|
2012-12-17 03:13:14 +01:00
|
|
|
};
|
|
|
|
RETURN_STATUS Status;
|
|
|
|
FIRMWARE_CONFIG_ITEM FwCfgItem;
|
|
|
|
UINTN FwCfgSize;
|
|
|
|
UINT8 SystemStates[6];
|
|
|
|
|
|
|
|
//
|
|
|
|
// configure defaults
|
|
|
|
//
|
|
|
|
*SuspendToRamSize = sizeof Template;
|
|
|
|
CopyMem (SuspendToRam, &Template, sizeof Template);
|
2013-02-14 20:20:57 +01:00
|
|
|
SuspendToRam->NameChar[2] = '3'; // S3
|
|
|
|
SuspendToRam->Pm1aCntSlpTyp.ByteValue = 1; // PIIX4: STR
|
2012-12-17 03:13:14 +01:00
|
|
|
|
|
|
|
*SuspendToDiskSize = sizeof Template;
|
|
|
|
CopyMem (SuspendToDisk, &Template, sizeof Template);
|
2013-02-14 20:20:57 +01:00
|
|
|
SuspendToDisk->NameChar[2] = '4'; // S4
|
|
|
|
SuspendToDisk->Pm1aCntSlpTyp.ByteValue = 2; // PIIX4: POSCL
|
2012-12-17 03:13:14 +01:00
|
|
|
|
|
|
|
//
|
|
|
|
// 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) {
|
2013-02-14 20:20:57 +01:00
|
|
|
SuspendToRam->Pm1aCntSlpTyp.ByteValue =
|
|
|
|
SystemStates[3] & (BIT2 | BIT1 | BIT0);
|
|
|
|
DEBUG ((DEBUG_INFO, "ACPI S3 value: %d\n",
|
|
|
|
SuspendToRam->Pm1aCntSlpTyp.ByteValue));
|
2012-12-17 03:13:14 +01:00
|
|
|
} else {
|
|
|
|
*SuspendToRamSize = 0;
|
|
|
|
DEBUG ((DEBUG_INFO, "ACPI S3 disabled\n"));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (SystemStates[4] & BIT7) {
|
2013-02-14 20:20:57 +01:00
|
|
|
SuspendToDisk->Pm1aCntSlpTyp.ByteValue =
|
|
|
|
SystemStates[4] & (BIT2 | BIT1 | BIT0);
|
|
|
|
DEBUG ((DEBUG_INFO, "ACPI S4 value: %d\n",
|
|
|
|
SuspendToDisk->Pm1aCntSlpTyp.ByteValue));
|
2012-12-17 03:13:14 +01:00
|
|
|
} else {
|
|
|
|
*SuspendToDiskSize = 0;
|
|
|
|
DEBUG ((DEBUG_INFO, "ACPI S4 disabled\n"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-07-31 20:17:51 +02:00
|
|
|
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) {
|
2012-12-17 03:13:14 +01:00
|
|
|
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;
|
2012-07-31 20:17:51 +02:00
|
|
|
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;
|
|
|
|
|
2012-12-17 03:13:14 +01:00
|
|
|
//
|
|
|
|
// add suspend system states
|
|
|
|
//
|
|
|
|
CopyMem (SsdtPtr, &SuspendToRam, SuspendToRamSize);
|
|
|
|
SsdtPtr += SuspendToRamSize;
|
|
|
|
CopyMem (SsdtPtr, &SuspendToDisk, SuspendToDiskSize);
|
|
|
|
SsdtPtr += SuspendToDiskSize;
|
|
|
|
|
2012-08-10 01:27:05 +02:00
|
|
|
ASSERT((UINTN) (SsdtPtr - Ssdt) == SsdtSize);
|
|
|
|
((EFI_ACPI_DESCRIPTION_HEADER *) Ssdt)->Length = (UINT32) SsdtSize;
|
2012-07-31 20:17:51 +02:00
|
|
|
Status = InstallAcpiTable (AcpiProtocol, Ssdt, SsdtSize, TableKey);
|
|
|
|
}
|
|
|
|
|
|
|
|
FreePool(Ssdt);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Status != EFI_SUCCESS) {
|
|
|
|
FreePool(FwData);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-05-31 01:15:27 +02:00
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
QemuInstallAcpiTable (
|
|
|
|
IN EFI_ACPI_TABLE_PROTOCOL *AcpiProtocol,
|
|
|
|
IN VOID *AcpiTableBuffer,
|
|
|
|
IN UINTN AcpiTableBufferSize,
|
|
|
|
OUT UINTN *TableKey
|
|
|
|
)
|
|
|
|
{
|
2012-05-31 01:15:59 +02:00
|
|
|
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;
|
2012-07-31 20:17:51 +02:00
|
|
|
case EFI_ACPI_1_0_SECONDARY_SYSTEM_DESCRIPTION_TABLE_SIGNATURE:
|
|
|
|
TableInstallFunction = QemuInstallAcpiSsdtTable;
|
|
|
|
break;
|
2012-05-31 01:15:59 +02:00
|
|
|
default:
|
|
|
|
TableInstallFunction = InstallAcpiTable;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TableInstallFunction (
|
2012-05-31 01:15:27 +02:00
|
|
|
AcpiProtocol,
|
|
|
|
AcpiTableBuffer,
|
|
|
|
AcpiTableBufferSize,
|
|
|
|
TableKey
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
OvmfPkg: AcpiPlatformDxe: download ACPI tables from QEMU
Recent qemu versions compose all ACPI tables on the host side, according
to the target hardware configuration, and make the tables available to any
guest firmware over fw_cfg.
See version compatibility information below.
The feature moves the burden of keeping ACPI tables up-to-date from boot
firmware to qemu (which is the source of hardware configuration anyway).
This patch adds client code for this feature. Benefits of the
qemu-provided ACPI tables include PCI hotplug for example.
Qemu provides the following three fw_cfg files:
- etc/acpi/rsdp
- etc/acpi/tables
- etc/table-loader
"etc/acpi/rsdp" and "etc/acpi/tables" are similar, they are only kept
separate because they have different allocation requirements in SeaBIOS.
Both of these fw_cfg files contain preformatted ACPI payload.
"etc/acpi/rsdp" contains only the RSDP table, while "etc/acpi/tables"
contains all other tables, concatenated.
The tables in these two fw_cfg files are filled in by qemu, but two kinds
of fields are left incomplete in each table: pointers to other tables, and
checksums (which depend on the pointers).
Qemu initializes each pointer with a relative offset into the fw_cfg file
that contains the pointed-to ACPI table. The final pointer values depend
on where the fw_cfg files, holding the pointed-to ACPI tables, will be
placed in memory by the guest. That is, the pointer fields need to be
"relocated" (incremented) by the base addresses of where "/etc/acpi/rsdp"
and "/etc/acpi/tables" will be placed in guest memory.
This is where the third file, "/etc/table-loader" comes in the picture. It
is a linker/loader script that has several command types:
One command type instructs the guest to download the other two files.
Another command type instructs the guest to increment ("absolutize") a
pointer field (having a relative initial value) in the pointing ACPI
table, present in some fw_cfg file, with the dynamic base address of the
same (or another) fw_cfg file, holding the pointed-to ACPI table.
The third command type instructs the guest to compute checksums over
ranges and to store them.
In edk2, EFI_ACPI_TABLE_PROTOCOL knows about table relationships -- it
handles linkage automatically when a table is installed. The protocol
takes care of checksumming too. RSDP is installed automatically. Hence we
only need to care about the "etc/acpi/tables" fw_cfg file, determining the
boundaries of each ACPI table inside it, and installing those tables.
Qemu compatibility information:
--------------+---------------------+-------------------------------------
qemu version | qemu machine type | effects of the patch
--------------+---------------------+-------------------------------------
up to 1.6.x | any pc-i440fx | None. OVMF's built-in ACPI tables
| | are used.
--------------+---------------------+-------------------------------------
any | up to pc-i440fx-1.6 | None. OVMF's built-in ACPI tables
| | are used.
--------------+---------------------+-------------------------------------
1.7.0 | pc-i440fx-1.7 | Potential guest OS crash, dependent
| (default for 1.7.0) | on guest RAM size.
| |
| | DO NOT RUN OVMF on the (1.7.0,
| | pc-i440fx-1.7) qemu / machine type
| | combination.
--------------+---------------------+-------------------------------------
1.7.1 | pc-i440fx-1.7 | OVMF downloads valid ACPI tables
| (default for 1.7.1) | from qemu and passes them to the
| | guest OS.
--------------+---------------------+-------------------------------------
2.0.0-rc0 | pc-i440fx-1.7 or | OVMF downloads valid ACPI tables
| later | from qemu and passes them to the
| | guest OS.
-------------+---------------------+-------------------------------------
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@15420 6f19259b-4bc3-4df7-8a09-765794883524
2014-03-31 22:36:06 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
Download the ACPI table data file from QEMU and interpret it.
|
|
|
|
|
|
|
|
@param[in] AcpiProtocol The ACPI table protocol used to install tables.
|
|
|
|
|
|
|
|
@retval EFI_UNSUPPORTED Firmware configuration is unavailable.
|
|
|
|
|
|
|
|
@retval EFI_NOT_FOUND The host doesn't export the required fw_cfg
|
|
|
|
files.
|
|
|
|
|
|
|
|
@retval EFI_OUT_OF_RESOURCES Memory allocation failed.
|
|
|
|
|
|
|
|
@retval EFI_PROTOCOL_ERROR Found truncated or invalid ACPI table header
|
|
|
|
in the fw_cfg contents.
|
|
|
|
|
|
|
|
@return Status codes returned by
|
|
|
|
AcpiProtocol->InstallAcpiTable().
|
|
|
|
|
|
|
|
**/
|
|
|
|
|
|
|
|
//
|
|
|
|
// We'll be saving the keys of installed tables so that we can roll them back
|
|
|
|
// in case of failure. 128 tables should be enough for anyone (TM).
|
|
|
|
//
|
|
|
|
#define INSTALLED_TABLES_MAX 128
|
|
|
|
|
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
InstallQemuLinkedTables (
|
|
|
|
IN EFI_ACPI_TABLE_PROTOCOL *AcpiProtocol
|
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
|
|
|
FIRMWARE_CONFIG_ITEM TablesFile;
|
|
|
|
UINTN TablesFileSize;
|
|
|
|
UINT8 *Tables;
|
|
|
|
UINTN *InstalledKey;
|
|
|
|
UINTN Processed;
|
|
|
|
INT32 Installed;
|
|
|
|
|
|
|
|
Status = QemuFwCfgFindFile ("etc/acpi/tables", &TablesFile, &TablesFileSize);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
DEBUG ((EFI_D_INFO, "%a: \"etc/acpi/tables\" interface unavailable: %r\n",
|
|
|
|
__FUNCTION__, Status));
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
Tables = AllocatePool (TablesFileSize);
|
|
|
|
if (Tables == NULL) {
|
|
|
|
return EFI_OUT_OF_RESOURCES;
|
|
|
|
}
|
|
|
|
|
|
|
|
QemuFwCfgSelectItem (TablesFile);
|
|
|
|
QemuFwCfgReadBytes (TablesFileSize, Tables);
|
|
|
|
|
|
|
|
InstalledKey = AllocatePool (INSTALLED_TABLES_MAX * sizeof *InstalledKey);
|
|
|
|
if (InstalledKey == NULL) {
|
|
|
|
Status = EFI_OUT_OF_RESOURCES;
|
|
|
|
goto FreeTables;
|
|
|
|
}
|
|
|
|
|
|
|
|
Processed = 0;
|
|
|
|
Installed = 0;
|
|
|
|
while (Processed < TablesFileSize) {
|
|
|
|
UINTN Remaining;
|
|
|
|
EFI_ACPI_DESCRIPTION_HEADER *Probe;
|
|
|
|
|
|
|
|
Remaining = TablesFileSize - Processed;
|
|
|
|
if (Remaining < sizeof *Probe) {
|
|
|
|
Status = EFI_PROTOCOL_ERROR;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
Probe = (EFI_ACPI_DESCRIPTION_HEADER *) (Tables + Processed);
|
|
|
|
if (Remaining < Probe->Length || Probe->Length < sizeof *Probe) {
|
|
|
|
Status = EFI_PROTOCOL_ERROR;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
DEBUG ((EFI_D_VERBOSE, "%a: offset 0x%016Lx:"
|
|
|
|
" Signature=\"%-4.4a\" Length=0x%08x\n",
|
|
|
|
__FUNCTION__, (UINT64) Processed,
|
|
|
|
(CONST CHAR8 *) &Probe->Signature, Probe->Length));
|
|
|
|
|
|
|
|
//
|
|
|
|
// skip automatically handled "root" tables: RSDT, XSDT
|
|
|
|
//
|
|
|
|
if (Probe->Signature !=
|
|
|
|
EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_TABLE_SIGNATURE &&
|
|
|
|
Probe->Signature !=
|
|
|
|
EFI_ACPI_2_0_EXTENDED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE) {
|
|
|
|
if (Installed == INSTALLED_TABLES_MAX) {
|
|
|
|
DEBUG ((EFI_D_ERROR, "%a: can't install more than %d tables\n",
|
|
|
|
__FUNCTION__, INSTALLED_TABLES_MAX));
|
|
|
|
Status = EFI_OUT_OF_RESOURCES;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
Status = AcpiProtocol->InstallAcpiTable (AcpiProtocol, Probe,
|
|
|
|
Probe->Length, &InstalledKey[Installed]);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
DEBUG ((EFI_D_ERROR,
|
|
|
|
"%a: failed to install table \"%-4.4a\" at offset 0x%Lx: %r\n",
|
|
|
|
__FUNCTION__, (CONST CHAR8 *) &Probe->Signature, (UINT64) Processed,
|
|
|
|
Status));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
++Installed;
|
|
|
|
}
|
|
|
|
|
|
|
|
Processed += Probe->Length;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// NUL-padding at the end is accepted
|
|
|
|
//
|
|
|
|
if (Status == EFI_PROTOCOL_ERROR) {
|
|
|
|
UINTN ErrorLocation;
|
|
|
|
|
|
|
|
ErrorLocation = Processed;
|
|
|
|
while (Processed < TablesFileSize && Tables[Processed] == '\0') {
|
|
|
|
++Processed;
|
|
|
|
}
|
|
|
|
if (Processed < TablesFileSize) {
|
|
|
|
DEBUG ((EFI_D_ERROR, "%a: truncated or invalid ACPI table header at "
|
|
|
|
"offset 0x%Lx\n", __FUNCTION__, (UINT64) ErrorLocation));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Processed == TablesFileSize) {
|
|
|
|
DEBUG ((EFI_D_INFO, "%a: installed %d tables\n", __FUNCTION__, Installed));
|
|
|
|
Status = EFI_SUCCESS;
|
|
|
|
} else {
|
|
|
|
ASSERT (EFI_ERROR (Status));
|
|
|
|
|
|
|
|
//
|
|
|
|
// Roll back partial installation.
|
|
|
|
//
|
|
|
|
while (Installed > 0) {
|
|
|
|
--Installed;
|
|
|
|
AcpiProtocol->UninstallAcpiTable (AcpiProtocol, InstalledKey[Installed]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
FreePool (InstalledKey);
|
|
|
|
|
|
|
|
FreeTables:
|
|
|
|
FreePool (Tables);
|
|
|
|
|
|
|
|
return Status;
|
|
|
|
}
|