audk/OvmfPkg/AcpiPlatformDxe/AcpiPlatform.c

263 lines
6.5 KiB
C
Raw Normal View History

/** @file
OVMF ACPI Platform Driver
Copyright (c) 2008 - 2012, Intel Corporation. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#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;
}
OvmfPkg/AcpiPlatformDxe: suppress invalid "deref of undef pointer" warning RH covscan emits the following false positive: > Error: CLANG_WARNING: > edk2-89910a39dcfd/OvmfPkg/AcpiPlatformDxe/AcpiPlatform.c:182:14: > warning: Dereference of undefined pointer value > # Status = FwVol->ReadSection ( > # ^~~~~~~~~~~~~~~~~~ > edk2-89910a39dcfd/OvmfPkg/AcpiPlatformDxe/AcpiPlatform.c:164:7: note: > Assuming the condition is false > # if (QemuDetected ()) { > # ^~~~~~~~~~~~~~~ > edk2-89910a39dcfd/OvmfPkg/AcpiPlatformDxe/AcpiPlatform.c:164:3: note: > Taking false branch > # if (QemuDetected ()) { > # ^ > edk2-89910a39dcfd/OvmfPkg/AcpiPlatformDxe/AcpiPlatform.c:174:3: note: > Taking false branch > # if (EFI_ERROR (Status)) { > # ^ > edk2-89910a39dcfd/OvmfPkg/AcpiPlatformDxe/AcpiPlatform.c:180:10: note: > Assuming 'Status' is equal to EFI_SUCCESS > # while (Status == EFI_SUCCESS) { > # ^~~~~~~~~~~~~~~~~~~~~ > edk2-89910a39dcfd/OvmfPkg/AcpiPlatformDxe/AcpiPlatform.c:180:3: note: > Loop condition is true. Entering loop body > # while (Status == EFI_SUCCESS) { > # ^ > edk2-89910a39dcfd/OvmfPkg/AcpiPlatformDxe/AcpiPlatform.c:182:14: note: > Dereference of undefined pointer value > # Status = FwVol->ReadSection ( > # ^~~~~~~~~~~~~~~~~~ > # 180| while (Status == EFI_SUCCESS) { > # 181| > # 182|-> Status = FwVol->ReadSection ( > # 183| FwVol, > # 184| (EFI_GUID*)PcdGetPtr (PcdAcpiTableStorageFile), This is invalid because LocateFvInstanceWithTables() sets FwVol on success. Suppress the message by: - assigning FwVol NULL first (this would replace the original report with "nullptr deref"), - asserting that FwVol is no longer NULL, on success. What's important here is that ASSERT() ends with ANALYZER_UNREACHABLE() on failure. Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org> Cc: Jordan Justen <jordan.l.justen@intel.com> Bugzilla: https://bugzilla.tianocore.org/show_bug.cgi?id=1710 Issue: scan-0991.txt Signed-off-by: Laszlo Ersek <lersek@redhat.com> Reviewed-by: Philippe Mathieu-Daude <philmd@redhat.com> Acked-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
2019-04-12 16:45:58 +02:00
//
// 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;
}
OvmfPkg/AcpiPlatformDxe: suppress invalid "deref of undef pointer" warning RH covscan emits the following false positive: > Error: CLANG_WARNING: > edk2-89910a39dcfd/OvmfPkg/AcpiPlatformDxe/AcpiPlatform.c:182:14: > warning: Dereference of undefined pointer value > # Status = FwVol->ReadSection ( > # ^~~~~~~~~~~~~~~~~~ > edk2-89910a39dcfd/OvmfPkg/AcpiPlatformDxe/AcpiPlatform.c:164:7: note: > Assuming the condition is false > # if (QemuDetected ()) { > # ^~~~~~~~~~~~~~~ > edk2-89910a39dcfd/OvmfPkg/AcpiPlatformDxe/AcpiPlatform.c:164:3: note: > Taking false branch > # if (QemuDetected ()) { > # ^ > edk2-89910a39dcfd/OvmfPkg/AcpiPlatformDxe/AcpiPlatform.c:174:3: note: > Taking false branch > # if (EFI_ERROR (Status)) { > # ^ > edk2-89910a39dcfd/OvmfPkg/AcpiPlatformDxe/AcpiPlatform.c:180:10: note: > Assuming 'Status' is equal to EFI_SUCCESS > # while (Status == EFI_SUCCESS) { > # ^~~~~~~~~~~~~~~~~~~~~ > edk2-89910a39dcfd/OvmfPkg/AcpiPlatformDxe/AcpiPlatform.c:180:3: note: > Loop condition is true. Entering loop body > # while (Status == EFI_SUCCESS) { > # ^ > edk2-89910a39dcfd/OvmfPkg/AcpiPlatformDxe/AcpiPlatform.c:182:14: note: > Dereference of undefined pointer value > # Status = FwVol->ReadSection ( > # ^~~~~~~~~~~~~~~~~~ > # 180| while (Status == EFI_SUCCESS) { > # 181| > # 182|-> Status = FwVol->ReadSection ( > # 183| FwVol, > # 184| (EFI_GUID*)PcdGetPtr (PcdAcpiTableStorageFile), This is invalid because LocateFvInstanceWithTables() sets FwVol on success. Suppress the message by: - assigning FwVol NULL first (this would replace the original report with "nullptr deref"), - asserting that FwVol is no longer NULL, on success. What's important here is that ASSERT() ends with ANALYZER_UNREACHABLE() on failure. Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org> Cc: Jordan Justen <jordan.l.justen@intel.com> Bugzilla: https://bugzilla.tianocore.org/show_bug.cgi?id=1710 Issue: scan-0991.txt Signed-off-by: Laszlo Ersek <lersek@redhat.com> Reviewed-by: Philippe Mathieu-Daude <philmd@redhat.com> Acked-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
2019-04-12 16:45:58 +02:00
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);
}
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
if (EFI_ERROR (Status)) {
Status = InstallOvmfFvTables (AcpiTable);
}
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
return Status;
}