mirror of https://github.com/acidanthera/audk.git
OvmfPkg: AcpiPlatformDxe: enable PCI IO and MMIO while fetching QEMU tables
Now that the previous patches ensure that we can access all PCI devices in AcpiPlatformDxe, we can enable IO and MMIO decoding for all of them while we contact QEMU for the ACPI tables. See more details in the patch titled: OvmfPkg: introduce gRootBridgesConnectedEventGroupGuid In particular, this patch will prevent the bug when the 64-bit MMIO aperture is completely missing from QEMU's _CRS, and consequently Linux rejects 64-bit BARs with the error message pci 0000:00:03.0: can't claim BAR 4 [mem 0x800000000-0x8007fffff 64bit pref]: no compatible bridge window Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org> Cc: Jordan Justen <jordan.l.justen@intel.com> Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Laszlo Ersek <lersek@redhat.com> Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>
This commit is contained in:
parent
b6bc800d5a
commit
8f35eb92c4
|
@ -19,6 +19,7 @@
|
||||||
|
|
||||||
#include <Protocol/AcpiTable.h>
|
#include <Protocol/AcpiTable.h>
|
||||||
#include <Protocol/FirmwareVolume2.h>
|
#include <Protocol/FirmwareVolume2.h>
|
||||||
|
#include <Protocol/PciIo.h>
|
||||||
|
|
||||||
#include <Library/BaseLib.h>
|
#include <Library/BaseLib.h>
|
||||||
#include <Library/UefiBootServicesTableLib.h>
|
#include <Library/UefiBootServicesTableLib.h>
|
||||||
|
@ -27,6 +28,11 @@
|
||||||
|
|
||||||
#include <IndustryStandard/Acpi.h>
|
#include <IndustryStandard/Acpi.h>
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
EFI_PCI_IO_PROTOCOL *PciIo;
|
||||||
|
UINT64 PciAttributes;
|
||||||
|
} ORIGINAL_ATTRIBUTES;
|
||||||
|
|
||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
EFIAPI
|
EFIAPI
|
||||||
InstallAcpiTable (
|
InstallAcpiTable (
|
||||||
|
@ -73,5 +79,17 @@ InstallAcpiTables (
|
||||||
IN EFI_ACPI_TABLE_PROTOCOL *AcpiTable
|
IN EFI_ACPI_TABLE_PROTOCOL *AcpiTable
|
||||||
);
|
);
|
||||||
|
|
||||||
|
VOID
|
||||||
|
EnablePciDecoding (
|
||||||
|
OUT ORIGINAL_ATTRIBUTES **OriginalAttributes,
|
||||||
|
OUT UINTN *Count
|
||||||
|
);
|
||||||
|
|
||||||
|
VOID
|
||||||
|
RestorePciDecoding (
|
||||||
|
IN ORIGINAL_ATTRIBUTES *OriginalAttributes,
|
||||||
|
IN UINTN Count
|
||||||
|
);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -32,6 +32,7 @@
|
||||||
QemuFwCfgAcpi.c
|
QemuFwCfgAcpi.c
|
||||||
Xen.c
|
Xen.c
|
||||||
EntryPoint.c
|
EntryPoint.c
|
||||||
|
PciDecoding.c
|
||||||
|
|
||||||
[Packages]
|
[Packages]
|
||||||
MdePkg/MdePkg.dec
|
MdePkg/MdePkg.dec
|
||||||
|
@ -57,6 +58,7 @@
|
||||||
|
|
||||||
[Protocols]
|
[Protocols]
|
||||||
gEfiAcpiTableProtocolGuid # PROTOCOL ALWAYS_CONSUMED
|
gEfiAcpiTableProtocolGuid # PROTOCOL ALWAYS_CONSUMED
|
||||||
|
gEfiPciIoProtocolGuid # PROTOCOL SOMETIMES_CONSUMED
|
||||||
|
|
||||||
[Guids]
|
[Guids]
|
||||||
gEfiXenInfoGuid
|
gEfiXenInfoGuid
|
||||||
|
|
|
@ -0,0 +1,186 @@
|
||||||
|
/** @file
|
||||||
|
Temporarily enable IO and MMIO decoding for all PCI devices while QEMU
|
||||||
|
regenerates the ACPI tables.
|
||||||
|
|
||||||
|
Copyright (C) 2016, Red Hat, Inc.
|
||||||
|
|
||||||
|
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.
|
||||||
|
**/
|
||||||
|
|
||||||
|
#include <Library/MemoryAllocationLib.h>
|
||||||
|
|
||||||
|
#include "AcpiPlatform.h"
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
Collect all PciIo protocol instances in the system. Save their original
|
||||||
|
attributes, and enable IO and MMIO decoding for each.
|
||||||
|
|
||||||
|
This is a best effort function; it doesn't return status codes. Its
|
||||||
|
caller is supposed to proceed even if this function fails.
|
||||||
|
|
||||||
|
@param[out] OriginalAttributes On output, a dynamically allocated array of
|
||||||
|
ORIGINAL_ATTRIBUTES elements. The array lists
|
||||||
|
the PciIo protocol instances found in the
|
||||||
|
system at the time of the call, plus the
|
||||||
|
original PCI attributes for each.
|
||||||
|
|
||||||
|
Before returning, the function enables IO and
|
||||||
|
MMIO decoding for each PciIo instance it
|
||||||
|
finds.
|
||||||
|
|
||||||
|
On error, or when no such instances are
|
||||||
|
found, OriginalAttributes is set to NULL.
|
||||||
|
|
||||||
|
@param[out] Count On output, the number of elements in
|
||||||
|
OriginalAttributes. On error it is set to
|
||||||
|
zero.
|
||||||
|
**/
|
||||||
|
VOID
|
||||||
|
EnablePciDecoding (
|
||||||
|
OUT ORIGINAL_ATTRIBUTES **OriginalAttributes,
|
||||||
|
OUT UINTN *Count
|
||||||
|
)
|
||||||
|
{
|
||||||
|
EFI_STATUS Status;
|
||||||
|
UINTN NoHandles;
|
||||||
|
EFI_HANDLE *Handles;
|
||||||
|
ORIGINAL_ATTRIBUTES *OrigAttrs;
|
||||||
|
UINTN Idx;
|
||||||
|
|
||||||
|
*OriginalAttributes = NULL;
|
||||||
|
*Count = 0;
|
||||||
|
|
||||||
|
if (PcdGetBool (PcdPciDisableBusEnumeration)) {
|
||||||
|
//
|
||||||
|
// The platform downloads ACPI tables from QEMU in general, but there are
|
||||||
|
// no root bridges in this execution. We're done.
|
||||||
|
//
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Status = gBS->LocateHandleBuffer (ByProtocol, &gEfiPciIoProtocolGuid,
|
||||||
|
NULL /* SearchKey */, &NoHandles, &Handles);
|
||||||
|
if (Status == EFI_NOT_FOUND) {
|
||||||
|
//
|
||||||
|
// No PCI devices were found on either of the root bridges. We're done.
|
||||||
|
//
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (EFI_ERROR (Status)) {
|
||||||
|
DEBUG ((EFI_D_WARN, "%a: LocateHandleBuffer(): %r\n", __FUNCTION__,
|
||||||
|
Status));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
OrigAttrs = AllocatePool (NoHandles * sizeof *OrigAttrs);
|
||||||
|
if (OrigAttrs == NULL) {
|
||||||
|
DEBUG ((EFI_D_WARN, "%a: AllocatePool(): out of resources\n",
|
||||||
|
__FUNCTION__));
|
||||||
|
goto FreeHandles;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Idx = 0; Idx < NoHandles; ++Idx) {
|
||||||
|
EFI_PCI_IO_PROTOCOL *PciIo;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Look up PciIo on the handle and stash it
|
||||||
|
//
|
||||||
|
Status = gBS->HandleProtocol (Handles[Idx], &gEfiPciIoProtocolGuid,
|
||||||
|
(VOID**)&PciIo);
|
||||||
|
ASSERT_EFI_ERROR (Status);
|
||||||
|
OrigAttrs[Idx].PciIo = PciIo;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Stash the current attributes
|
||||||
|
//
|
||||||
|
Status = PciIo->Attributes (PciIo, EfiPciIoAttributeOperationGet, 0,
|
||||||
|
&OrigAttrs[Idx].PciAttributes);
|
||||||
|
if (EFI_ERROR (Status)) {
|
||||||
|
DEBUG ((EFI_D_WARN, "%a: EfiPciIoAttributeOperationGet: %r\n",
|
||||||
|
__FUNCTION__, Status));
|
||||||
|
goto RestoreAttributes;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Enable IO and MMIO decoding
|
||||||
|
//
|
||||||
|
Status = PciIo->Attributes (PciIo, EfiPciIoAttributeOperationEnable,
|
||||||
|
EFI_PCI_IO_ATTRIBUTE_IO | EFI_PCI_IO_ATTRIBUTE_MEMORY,
|
||||||
|
NULL);
|
||||||
|
if (EFI_ERROR (Status)) {
|
||||||
|
DEBUG ((EFI_D_WARN, "%a: EfiPciIoAttributeOperationEnable: %r\n",
|
||||||
|
__FUNCTION__, Status));
|
||||||
|
goto RestoreAttributes;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Success
|
||||||
|
//
|
||||||
|
FreePool (Handles);
|
||||||
|
*OriginalAttributes = OrigAttrs;
|
||||||
|
*Count = NoHandles;
|
||||||
|
return;
|
||||||
|
|
||||||
|
RestoreAttributes:
|
||||||
|
while (Idx > 0) {
|
||||||
|
--Idx;
|
||||||
|
OrigAttrs[Idx].PciIo->Attributes (OrigAttrs[Idx].PciIo,
|
||||||
|
EfiPciIoAttributeOperationSet,
|
||||||
|
OrigAttrs[Idx].PciAttributes,
|
||||||
|
NULL
|
||||||
|
);
|
||||||
|
}
|
||||||
|
FreePool (OrigAttrs);
|
||||||
|
|
||||||
|
FreeHandles:
|
||||||
|
FreePool (Handles);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
Restore the original PCI attributes saved with EnablePciDecoding().
|
||||||
|
|
||||||
|
@param[in] OriginalAttributes The array allocated and populated by
|
||||||
|
EnablePciDecoding(). This parameter may be
|
||||||
|
NULL. If OriginalAttributes is NULL, then the
|
||||||
|
function is a no-op; otherwise the PciIo
|
||||||
|
attributes will be restored, and the
|
||||||
|
OriginalAttributes array will be freed.
|
||||||
|
|
||||||
|
@param[in] Count The Count value stored by EnablePciDecoding(),
|
||||||
|
the number of elements in OriginalAttributes.
|
||||||
|
Count may be zero if and only if
|
||||||
|
OriginalAttributes is NULL.
|
||||||
|
**/
|
||||||
|
VOID
|
||||||
|
RestorePciDecoding (
|
||||||
|
IN ORIGINAL_ATTRIBUTES *OriginalAttributes,
|
||||||
|
IN UINTN Count
|
||||||
|
)
|
||||||
|
{
|
||||||
|
UINTN Idx;
|
||||||
|
|
||||||
|
ASSERT ((OriginalAttributes == NULL) == (Count == 0));
|
||||||
|
if (OriginalAttributes == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Idx = 0; Idx < Count; ++Idx) {
|
||||||
|
OriginalAttributes[Idx].PciIo->Attributes (
|
||||||
|
OriginalAttributes[Idx].PciIo,
|
||||||
|
EfiPciIoAttributeOperationSet,
|
||||||
|
OriginalAttributes[Idx].PciAttributes,
|
||||||
|
NULL
|
||||||
|
);
|
||||||
|
}
|
||||||
|
FreePool (OriginalAttributes);
|
||||||
|
}
|
|
@ -561,6 +561,8 @@ InstallQemuFwCfgTables (
|
||||||
UINTN FwCfgSize;
|
UINTN FwCfgSize;
|
||||||
QEMU_LOADER_ENTRY *LoaderStart;
|
QEMU_LOADER_ENTRY *LoaderStart;
|
||||||
CONST QEMU_LOADER_ENTRY *LoaderEntry, *LoaderEnd;
|
CONST QEMU_LOADER_ENTRY *LoaderEntry, *LoaderEnd;
|
||||||
|
ORIGINAL_ATTRIBUTES *OriginalPciAttributes;
|
||||||
|
UINTN OriginalPciAttributesCount;
|
||||||
ORDERED_COLLECTION *Tracker;
|
ORDERED_COLLECTION *Tracker;
|
||||||
UINTN *InstalledKey;
|
UINTN *InstalledKey;
|
||||||
INT32 Installed;
|
INT32 Installed;
|
||||||
|
@ -580,8 +582,10 @@ InstallQemuFwCfgTables (
|
||||||
if (LoaderStart == NULL) {
|
if (LoaderStart == NULL) {
|
||||||
return EFI_OUT_OF_RESOURCES;
|
return EFI_OUT_OF_RESOURCES;
|
||||||
}
|
}
|
||||||
|
EnablePciDecoding (&OriginalPciAttributes, &OriginalPciAttributesCount);
|
||||||
QemuFwCfgSelectItem (FwCfgItem);
|
QemuFwCfgSelectItem (FwCfgItem);
|
||||||
QemuFwCfgReadBytes (FwCfgSize, LoaderStart);
|
QemuFwCfgReadBytes (FwCfgSize, LoaderStart);
|
||||||
|
RestorePciDecoding (OriginalPciAttributes, OriginalPciAttributesCount);
|
||||||
LoaderEnd = LoaderStart + FwCfgSize / sizeof *LoaderEntry;
|
LoaderEnd = LoaderStart + FwCfgSize / sizeof *LoaderEntry;
|
||||||
|
|
||||||
Tracker = OrderedCollectionInit (BlobCompare, BlobKeyCompare);
|
Tracker = OrderedCollectionInit (BlobCompare, BlobKeyCompare);
|
||||||
|
|
|
@ -30,6 +30,7 @@
|
||||||
QemuFwCfgAcpiPlatform.c
|
QemuFwCfgAcpiPlatform.c
|
||||||
QemuFwCfgAcpi.c
|
QemuFwCfgAcpi.c
|
||||||
EntryPoint.c
|
EntryPoint.c
|
||||||
|
PciDecoding.c
|
||||||
|
|
||||||
[Packages]
|
[Packages]
|
||||||
MdePkg/MdePkg.dec
|
MdePkg/MdePkg.dec
|
||||||
|
@ -47,6 +48,7 @@
|
||||||
|
|
||||||
[Protocols]
|
[Protocols]
|
||||||
gEfiAcpiTableProtocolGuid # PROTOCOL ALWAYS_CONSUMED
|
gEfiAcpiTableProtocolGuid # PROTOCOL ALWAYS_CONSUMED
|
||||||
|
gEfiPciIoProtocolGuid # PROTOCOL SOMETIMES_CONSUMED
|
||||||
|
|
||||||
[Guids]
|
[Guids]
|
||||||
gRootBridgesConnectedEventGroupGuid
|
gRootBridgesConnectedEventGroupGuid
|
||||||
|
|
Loading…
Reference in New Issue