mirror of https://github.com/acidanthera/audk.git
OvmfPkg: move PciEncoding into AcpiPlatformLib
Bhyve supports providing ACPI tables by FwCfg. Therefore, InstallQemuFwCfgTables should be moved to AcpiPlatformLib to reuse the code. As first step, move PciEncoding into AcpiPlatformLib. Signed-off-by: Corvin Köhne <corvink@FreeBSD.org> Acked-by: Peter Grehan <grehan@freebsd.org>
This commit is contained in:
parent
f5d851673d
commit
ea88df6b26
|
@ -111,6 +111,7 @@
|
|||
ArmMmuLib|ArmPkg/Library/ArmMmuLib/ArmMmuPeiLib.inf
|
||||
|
||||
[LibraryClasses.common.DXE_DRIVER]
|
||||
AcpiPlatformLib|OvmfPkg/Library/AcpiPlatformLib/DxeAcpiPlatformLib.inf
|
||||
ReportStatusCodeLib|MdeModulePkg/Library/DxeReportStatusCodeLib/DxeReportStatusCodeLib.inf
|
||||
|
||||
!if $(TPM2_ENABLE) == TRUE
|
||||
|
|
|
@ -83,6 +83,7 @@
|
|||
TpmPlatformHierarchyLib|SecurityPkg/Library/PeiDxeTpmPlatformHierarchyLibNull/PeiDxeTpmPlatformHierarchyLib.inf
|
||||
|
||||
[LibraryClasses.common.DXE_DRIVER]
|
||||
AcpiPlatformLib|OvmfPkg/Library/AcpiPlatformLib/DxeAcpiPlatformLib.inf
|
||||
ReportStatusCodeLib|MdeModulePkg/Library/DxeReportStatusCodeLib/DxeReportStatusCodeLib.inf
|
||||
|
||||
[LibraryClasses.common.UEFI_DRIVER]
|
||||
|
|
|
@ -10,12 +10,6 @@
|
|||
#define ACPI_PLATFORM_H_
|
||||
|
||||
#include <Protocol/AcpiTable.h> // EFI_ACPI_TABLE_PROTOCOL
|
||||
#include <Protocol/PciIo.h> // EFI_PCI_IO_PROTOCOL
|
||||
|
||||
typedef struct {
|
||||
EFI_PCI_IO_PROTOCOL *PciIo;
|
||||
UINT64 PciAttributes;
|
||||
} ORIGINAL_ATTRIBUTES;
|
||||
|
||||
typedef struct S3_CONTEXT S3_CONTEXT;
|
||||
|
||||
|
@ -43,18 +37,6 @@ InstallAcpiTables (
|
|||
IN EFI_ACPI_TABLE_PROTOCOL *AcpiTable
|
||||
);
|
||||
|
||||
VOID
|
||||
EnablePciDecoding (
|
||||
OUT ORIGINAL_ATTRIBUTES **OriginalAttributes,
|
||||
OUT UINTN *Count
|
||||
);
|
||||
|
||||
VOID
|
||||
RestorePciDecoding (
|
||||
IN ORIGINAL_ATTRIBUTES *OriginalAttributes,
|
||||
IN UINTN Count
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
AllocateS3Context (
|
||||
OUT S3_CONTEXT **S3Context,
|
||||
|
|
|
@ -26,7 +26,6 @@
|
|||
BootScript.c
|
||||
CloudHvAcpi.c
|
||||
EntryPoint.c
|
||||
PciDecoding.c
|
||||
QemuFwCfgAcpi.c
|
||||
|
||||
[Packages]
|
||||
|
@ -35,15 +34,13 @@
|
|||
OvmfPkg/OvmfPkg.dec
|
||||
|
||||
[LibraryClasses]
|
||||
AcpiPlatformLib
|
||||
BaseLib
|
||||
BaseMemoryLib
|
||||
DebugLib
|
||||
MemoryAllocationLib
|
||||
OrderedCollectionLib
|
||||
PcdLib
|
||||
QemuFwCfgLib
|
||||
QemuFwCfgS3Lib
|
||||
UefiBootServicesTableLib
|
||||
UefiDriverEntryPoint
|
||||
HobLib
|
||||
TpmMeasurementLib
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#include <IndustryStandard/Acpi.h> // EFI_ACPI_DESCRIPTION_HEADER
|
||||
#include <IndustryStandard/QemuLoader.h> // QEMU_LOADER_FNAME_SIZE
|
||||
#include <IndustryStandard/UefiTcgPlatform.h>
|
||||
#include <Library/AcpiPlatformLib.h>
|
||||
#include <Library/BaseLib.h> // AsciiStrCmp()
|
||||
#include <Library/BaseMemoryLib.h> // CopyMem()
|
||||
#include <Library/DebugLib.h> // DEBUG()
|
||||
|
|
|
@ -329,6 +329,7 @@
|
|||
PciLib|OvmfPkg/Library/DxePciLibI440FxQ35/DxePciLibI440FxQ35.inf
|
||||
|
||||
[LibraryClasses.common.DXE_DRIVER]
|
||||
AcpiPlatformLib|OvmfPkg/Library/AcpiPlatformLib/DxeAcpiPlatformLib.inf
|
||||
PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf
|
||||
TimerLib|OvmfPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.inf
|
||||
ResetSystemLib|OvmfPkg/Library/ResetSystemLib/DxeResetSystemLib.inf
|
||||
|
|
|
@ -21,11 +21,6 @@
|
|||
#include <Library/XenPlatformLib.h>
|
||||
#include <IndustryStandard/Acpi.h>
|
||||
|
||||
typedef struct {
|
||||
EFI_PCI_IO_PROTOCOL *PciIo;
|
||||
UINT64 PciAttributes;
|
||||
} ORIGINAL_ATTRIBUTES;
|
||||
|
||||
typedef struct S3_CONTEXT S3_CONTEXT;
|
||||
|
||||
EFI_STATUS
|
||||
|
@ -58,16 +53,4 @@ InstallAcpiTables (
|
|||
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 /* _ACPI_PLATFORM_H_INCLUDED_ */
|
||||
|
|
|
@ -26,7 +26,6 @@
|
|||
AcpiPlatform.h
|
||||
Bhyve.c
|
||||
EntryPoint.c
|
||||
PciDecoding.c
|
||||
|
||||
[Packages]
|
||||
MdePkg/MdePkg.dec
|
||||
|
|
|
@ -1,232 +0,0 @@
|
|||
/** @file
|
||||
Temporarily enable IO and MMIO decoding for all PCI devices while QEMU
|
||||
regenerates the ACPI tables.
|
||||
|
||||
Copyright (C) 2016, Red Hat, Inc.
|
||||
|
||||
SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||
**/
|
||||
|
||||
#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 ((
|
||||
DEBUG_WARN,
|
||||
"%a: LocateHandleBuffer(): %r\n",
|
||||
__func__,
|
||||
Status
|
||||
));
|
||||
return;
|
||||
}
|
||||
|
||||
OrigAttrs = AllocatePool (NoHandles * sizeof *OrigAttrs);
|
||||
if (OrigAttrs == NULL) {
|
||||
DEBUG ((
|
||||
DEBUG_WARN,
|
||||
"%a: AllocatePool(): out of resources\n",
|
||||
__func__
|
||||
));
|
||||
goto FreeHandles;
|
||||
}
|
||||
|
||||
for (Idx = 0; Idx < NoHandles; ++Idx) {
|
||||
EFI_PCI_IO_PROTOCOL *PciIo;
|
||||
UINT64 Attributes;
|
||||
|
||||
//
|
||||
// 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 ((
|
||||
DEBUG_WARN,
|
||||
"%a: EfiPciIoAttributeOperationGet: %r\n",
|
||||
__func__,
|
||||
Status
|
||||
));
|
||||
goto RestoreAttributes;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve supported attributes
|
||||
//
|
||||
Status = PciIo->Attributes (
|
||||
PciIo,
|
||||
EfiPciIoAttributeOperationSupported,
|
||||
0,
|
||||
&Attributes
|
||||
);
|
||||
if (EFI_ERROR (Status)) {
|
||||
DEBUG ((
|
||||
DEBUG_WARN,
|
||||
"%a: EfiPciIoAttributeOperationSupported: %r\n",
|
||||
__func__,
|
||||
Status
|
||||
));
|
||||
goto RestoreAttributes;
|
||||
}
|
||||
|
||||
//
|
||||
// Enable IO and MMIO decoding
|
||||
//
|
||||
Attributes &= EFI_PCI_IO_ATTRIBUTE_IO | EFI_PCI_IO_ATTRIBUTE_MEMORY;
|
||||
Status = PciIo->Attributes (
|
||||
PciIo,
|
||||
EfiPciIoAttributeOperationEnable,
|
||||
Attributes,
|
||||
NULL
|
||||
);
|
||||
if (EFI_ERROR (Status)) {
|
||||
DEBUG ((
|
||||
DEBUG_WARN,
|
||||
"%a: EfiPciIoAttributeOperationEnable: %r\n",
|
||||
__func__,
|
||||
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);
|
||||
}
|
|
@ -366,6 +366,7 @@
|
|||
PciLib|OvmfPkg/Library/DxePciLibI440FxQ35/DxePciLibI440FxQ35.inf
|
||||
|
||||
[LibraryClasses.common.DXE_DRIVER]
|
||||
AcpiPlatformLib|OvmfPkg/Library/AcpiPlatformLib/DxeAcpiPlatformLib.inf
|
||||
PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf
|
||||
TimerLib|OvmfPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.inf
|
||||
ResetSystemLib|OvmfPkg/Library/ResetSystemLib/DxeResetSystemLib.inf
|
||||
|
|
|
@ -8,6 +8,12 @@
|
|||
#define ACPI_PLATFORM_LIB_H_
|
||||
|
||||
#include <Protocol/AcpiTable.h>
|
||||
#include <Protocol/PciIo.h>
|
||||
|
||||
typedef struct {
|
||||
EFI_PCI_IO_PROTOCOL *PciIo;
|
||||
UINT64 PciAttributes;
|
||||
} ORIGINAL_ATTRIBUTES;
|
||||
|
||||
/**
|
||||
Searches and returns the address of the ACPI Root System Description Pointer (RSDP) in system memory.
|
||||
|
@ -51,4 +57,16 @@ InstallAcpiTablesFromRsdp (
|
|||
IN EFI_ACPI_2_0_ROOT_SYSTEM_DESCRIPTION_POINTER *Rsdp
|
||||
);
|
||||
|
||||
VOID
|
||||
EnablePciDecoding (
|
||||
OUT ORIGINAL_ATTRIBUTES **OriginalAttributes,
|
||||
OUT UINTN *Count
|
||||
);
|
||||
|
||||
VOID
|
||||
RestorePciDecoding (
|
||||
IN ORIGINAL_ATTRIBUTES *OriginalAttributes,
|
||||
IN UINTN Count
|
||||
);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -289,6 +289,7 @@
|
|||
PciLib|OvmfPkg/Library/DxePciLibI440FxQ35/DxePciLibI440FxQ35.inf
|
||||
|
||||
[LibraryClasses.common.DXE_DRIVER]
|
||||
AcpiPlatformLib|OvmfPkg/Library/AcpiPlatformLib/DxeAcpiPlatformLib.inf
|
||||
PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf
|
||||
TimerLib|OvmfPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.inf
|
||||
ResetSystemLib|OvmfPkg/Library/ResetSystemLib/DxeResetSystemLib.inf
|
||||
|
|
|
@ -16,11 +16,18 @@
|
|||
|
||||
[Sources]
|
||||
DxeAcpiPlatformLib.c
|
||||
PciDecoding.c
|
||||
|
||||
[Packages]
|
||||
MdeModulePkg/MdeModulePkg.dec
|
||||
MdePkg/MdePkg.dec
|
||||
OvmfPkg/OvmfPkg.dec
|
||||
|
||||
[LibraryClasses]
|
||||
BaseLib
|
||||
DebugLib
|
||||
PcdLib
|
||||
UefiBootServicesTableLib
|
||||
|
||||
[Pcd]
|
||||
gEfiMdeModulePkgTokenSpaceGuid.PcdPciDisableBusEnumeration
|
||||
|
|
|
@ -7,12 +7,11 @@
|
|||
SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||
**/
|
||||
|
||||
#include <Library/AcpiPlatformLib.h>
|
||||
#include <Library/DebugLib.h> // DEBUG()
|
||||
#include <Library/MemoryAllocationLib.h> // AllocatePool()
|
||||
#include <Library/UefiBootServicesTableLib.h> // gBS
|
||||
|
||||
#include "AcpiPlatform.h"
|
||||
|
||||
/**
|
||||
Collect all PciIo protocol instances in the system. Save their original
|
||||
attributes, and enable IO and MMIO decoding for each.
|
|
@ -368,6 +368,7 @@
|
|||
PciExpressLib|OvmfPkg/Library/BaseCachingPciExpressLib/BaseCachingPciExpressLib.inf
|
||||
|
||||
[LibraryClasses.common.DXE_DRIVER]
|
||||
AcpiPlatformLib|OvmfPkg/Library/AcpiPlatformLib/DxeAcpiPlatformLib.inf
|
||||
PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf
|
||||
ResetSystemLib|OvmfPkg/Library/ResetSystemLib/DxeResetSystemLibMicrovm.inf
|
||||
HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf
|
||||
|
|
|
@ -373,6 +373,7 @@
|
|||
PciLib|OvmfPkg/Library/DxePciLibI440FxQ35/DxePciLibI440FxQ35.inf
|
||||
|
||||
[LibraryClasses.common.DXE_DRIVER]
|
||||
AcpiPlatformLib|OvmfPkg/Library/AcpiPlatformLib/DxeAcpiPlatformLib.inf
|
||||
PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf
|
||||
TimerLib|OvmfPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.inf
|
||||
ResetSystemLib|OvmfPkg/Library/ResetSystemLib/DxeResetSystemLib.inf
|
||||
|
|
|
@ -378,6 +378,7 @@
|
|||
PciLib|OvmfPkg/Library/DxePciLibI440FxQ35/DxePciLibI440FxQ35.inf
|
||||
|
||||
[LibraryClasses.common.DXE_DRIVER]
|
||||
AcpiPlatformLib|OvmfPkg/Library/AcpiPlatformLib/DxeAcpiPlatformLib.inf
|
||||
PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf
|
||||
TimerLib|OvmfPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.inf
|
||||
ResetSystemLib|OvmfPkg/Library/ResetSystemLib/DxeResetSystemLib.inf
|
||||
|
|
|
@ -399,6 +399,7 @@
|
|||
PciLib|OvmfPkg/Library/DxePciLibI440FxQ35/DxePciLibI440FxQ35.inf
|
||||
|
||||
[LibraryClasses.common.DXE_DRIVER]
|
||||
AcpiPlatformLib|OvmfPkg/Library/AcpiPlatformLib/DxeAcpiPlatformLib.inf
|
||||
PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf
|
||||
TimerLib|OvmfPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.inf
|
||||
ResetSystemLib|OvmfPkg/Library/ResetSystemLib/DxeResetSystemLib.inf
|
||||
|
|
|
@ -113,6 +113,7 @@
|
|||
!endif
|
||||
|
||||
[LibraryClasses.common.DXE_DRIVER]
|
||||
AcpiPlatformLib|OvmfPkg/Library/AcpiPlatformLib/DxeAcpiPlatformLib.inf
|
||||
ReportStatusCodeLib|MdeModulePkg/Library/DxeReportStatusCodeLib/DxeReportStatusCodeLib.inf
|
||||
PciExpressLib|OvmfPkg/Library/BaseCachingPciExpressLib/BaseCachingPciExpressLib.inf
|
||||
|
||||
|
|
Loading…
Reference in New Issue