2016-01-25 20:33:32 +01:00
|
|
|
/** @file
|
|
|
|
OVMF's instance of the PCI Host Bridge Library.
|
|
|
|
|
|
|
|
Copyright (C) 2016, Red Hat, Inc.
|
|
|
|
Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>
|
|
|
|
|
2019-04-04 01:06:33 +02:00
|
|
|
SPDX-License-Identifier: BSD-2-Clause-Patent
|
2016-01-25 20:33:32 +01:00
|
|
|
|
|
|
|
**/
|
2021-05-26 22:14:31 +02:00
|
|
|
#include <IndustryStandard/Pci.h> // PCI_MAX_BUS
|
|
|
|
#include <IndustryStandard/Q35MchIch9.h> // INTEL_Q35_MCH_DEVIC...
|
|
|
|
#include <Library/BaseMemoryLib.h> // ZeroMem()
|
|
|
|
#include <Library/PcdLib.h> // PcdGet64()
|
|
|
|
#include <Library/PciHostBridgeLib.h> // PCI_ROOT_BRIDGE_APE...
|
|
|
|
#include <Library/PciHostBridgeUtilityLib.h> // PciHostBridgeUtilit...
|
|
|
|
#include <Protocol/PciHostBridgeResourceAllocation.h> // EFI_PCI_HOST_BRIDGE...
|
|
|
|
#include <Protocol/PciRootBridgeIo.h> // EFI_PCI_ATTRIBUTE_I...
|
OvmfPkg: PciHostBridgeLib: convert main loop from PciHostBridgeDxe
In this patch we import the scan for extra root buses from the
InitializePciHostBridge() function, in file
"OvmfPkg/PciHostBridgeDxe/PciHostBridge.c".
For the time being, the InitRootBridge() and UninitRootBridge() functions
are just placeholders.
The PciHostBridgeGetRootBridges() API expects us to return the
PCI_ROOT_BRIDGE structures in a contiguous array, instead of a linked
list. Therefore the following bits have to be converted manually:
(1) The array is allocated in advance, in a single step.
(2) The calculation of the array size depends on an explicit
multiplication, which we must check against overflow. Since more than
255 extra root bridges make no sense anyway, we use (1 + 255) as the
limit on the main plus all extra root bridges. This also ensures that
the UINTN multiplication doesn't overflow.
(3) The PciHostBridgeDxe code decrements "ExtraRootBridgesLeft" to
terminate the scanning early. Here we need track the increasing count
of used array elements as well, so we employ "ExtraRootBridges" as a
constant limit, and increment the new local variable "Initialized".
(4) The prototypes of InitRootBridge() and UninitRootBridge() reflect that
the PCI_ROOT_BRIDGE structure is allocated by the caller; only
in-place initialization is necessary.
Additionally, macros are employed for standard PCI quantities, from
"MdePkg/Include/IndustryStandard/Pci22.h":
- MAX_PCI_DEVICE_NUMBER (31) is replaced with PCI_MAX_DEVICE (same),
- the constant 255 is replaced with PCI_MAX_BUS,
- the (RootBridgeNumber < 256) condition is replaced with
(RootBridgeNumber <= PCI_MAX_BUS).
Cc: Jordan Justen <jordan.l.justen@intel.com>
Cc: Ruiyu Ni <ruiyu.ni@intel.com>
Cc: Marcel Apfelbaum <marcel@redhat.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>
2016-01-25 22:47:00 +01:00
|
|
|
|
2016-05-09 08:03:57 +02:00
|
|
|
STATIC PCI_ROOT_BRIDGE_APERTURE mNonExistAperture = { MAX_UINT64, 0 };
|
OvmfPkg: PciHostBridgeLib: convert main loop from PciHostBridgeDxe
In this patch we import the scan for extra root buses from the
InitializePciHostBridge() function, in file
"OvmfPkg/PciHostBridgeDxe/PciHostBridge.c".
For the time being, the InitRootBridge() and UninitRootBridge() functions
are just placeholders.
The PciHostBridgeGetRootBridges() API expects us to return the
PCI_ROOT_BRIDGE structures in a contiguous array, instead of a linked
list. Therefore the following bits have to be converted manually:
(1) The array is allocated in advance, in a single step.
(2) The calculation of the array size depends on an explicit
multiplication, which we must check against overflow. Since more than
255 extra root bridges make no sense anyway, we use (1 + 255) as the
limit on the main plus all extra root bridges. This also ensures that
the UINTN multiplication doesn't overflow.
(3) The PciHostBridgeDxe code decrements "ExtraRootBridgesLeft" to
terminate the scanning early. Here we need track the increasing count
of used array elements as well, so we employ "ExtraRootBridges" as a
constant limit, and increment the new local variable "Initialized".
(4) The prototypes of InitRootBridge() and UninitRootBridge() reflect that
the PCI_ROOT_BRIDGE structure is allocated by the caller; only
in-place initialization is necessary.
Additionally, macros are employed for standard PCI quantities, from
"MdePkg/Include/IndustryStandard/Pci22.h":
- MAX_PCI_DEVICE_NUMBER (31) is replaced with PCI_MAX_DEVICE (same),
- the constant 255 is replaced with PCI_MAX_BUS,
- the (RootBridgeNumber < 256) condition is replaced with
(RootBridgeNumber <= PCI_MAX_BUS).
Cc: Jordan Justen <jordan.l.justen@intel.com>
Cc: Ruiyu Ni <ruiyu.ni@intel.com>
Cc: Marcel Apfelbaum <marcel@redhat.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>
2016-01-25 22:47:00 +01:00
|
|
|
|
2016-01-25 20:33:32 +01:00
|
|
|
/**
|
|
|
|
Return all the root bridge instances in an array.
|
|
|
|
|
|
|
|
@param Count Return the count of root bridge instances.
|
|
|
|
|
|
|
|
@return All the root bridge instances in an array.
|
|
|
|
The array should be passed into PciHostBridgeFreeRootBridges()
|
|
|
|
when it's not used.
|
|
|
|
**/
|
|
|
|
PCI_ROOT_BRIDGE *
|
|
|
|
EFIAPI
|
|
|
|
PciHostBridgeGetRootBridges (
|
|
|
|
UINTN *Count
|
|
|
|
)
|
|
|
|
{
|
2016-05-09 08:03:57 +02:00
|
|
|
UINT64 Attributes;
|
|
|
|
UINT64 AllocationAttributes;
|
|
|
|
PCI_ROOT_BRIDGE_APERTURE Io;
|
|
|
|
PCI_ROOT_BRIDGE_APERTURE Mem;
|
|
|
|
PCI_ROOT_BRIDGE_APERTURE MemAbove4G;
|
|
|
|
|
2018-02-28 03:19:28 +01:00
|
|
|
ZeroMem (&Io, sizeof (Io));
|
|
|
|
ZeroMem (&Mem, sizeof (Mem));
|
|
|
|
ZeroMem (&MemAbove4G, sizeof (MemAbove4G));
|
|
|
|
|
2016-05-09 08:03:57 +02:00
|
|
|
Attributes = EFI_PCI_ATTRIBUTE_IDE_PRIMARY_IO |
|
|
|
|
EFI_PCI_ATTRIBUTE_IDE_SECONDARY_IO |
|
|
|
|
EFI_PCI_ATTRIBUTE_ISA_IO_16 |
|
|
|
|
EFI_PCI_ATTRIBUTE_ISA_MOTHERBOARD_IO |
|
|
|
|
EFI_PCI_ATTRIBUTE_VGA_MEMORY |
|
|
|
|
EFI_PCI_ATTRIBUTE_VGA_IO_16 |
|
|
|
|
EFI_PCI_ATTRIBUTE_VGA_PALETTE_IO_16;
|
|
|
|
|
|
|
|
AllocationAttributes = EFI_PCI_HOST_BRIDGE_COMBINE_MEM_PMEM;
|
|
|
|
if (PcdGet64 (PcdPciMmio64Size) > 0) {
|
|
|
|
AllocationAttributes |= EFI_PCI_HOST_BRIDGE_MEM64_DECODE;
|
|
|
|
MemAbove4G.Base = PcdGet64 (PcdPciMmio64Base);
|
|
|
|
MemAbove4G.Limit = PcdGet64 (PcdPciMmio64Base) +
|
|
|
|
PcdGet64 (PcdPciMmio64Size) - 1;
|
|
|
|
} else {
|
|
|
|
CopyMem (&MemAbove4G, &mNonExistAperture, sizeof (mNonExistAperture));
|
|
|
|
}
|
|
|
|
|
|
|
|
Io.Base = PcdGet64 (PcdPciIoBase);
|
|
|
|
Io.Limit = PcdGet64 (PcdPciIoBase) + (PcdGet64 (PcdPciIoSize) - 1);
|
|
|
|
Mem.Base = PcdGet64 (PcdPciMmio32Base);
|
|
|
|
Mem.Limit = PcdGet64 (PcdPciMmio32Base) + (PcdGet64 (PcdPciMmio32Size) - 1);
|
OvmfPkg: PciHostBridgeLib: convert main loop from PciHostBridgeDxe
In this patch we import the scan for extra root buses from the
InitializePciHostBridge() function, in file
"OvmfPkg/PciHostBridgeDxe/PciHostBridge.c".
For the time being, the InitRootBridge() and UninitRootBridge() functions
are just placeholders.
The PciHostBridgeGetRootBridges() API expects us to return the
PCI_ROOT_BRIDGE structures in a contiguous array, instead of a linked
list. Therefore the following bits have to be converted manually:
(1) The array is allocated in advance, in a single step.
(2) The calculation of the array size depends on an explicit
multiplication, which we must check against overflow. Since more than
255 extra root bridges make no sense anyway, we use (1 + 255) as the
limit on the main plus all extra root bridges. This also ensures that
the UINTN multiplication doesn't overflow.
(3) The PciHostBridgeDxe code decrements "ExtraRootBridgesLeft" to
terminate the scanning early. Here we need track the increasing count
of used array elements as well, so we employ "ExtraRootBridges" as a
constant limit, and increment the new local variable "Initialized".
(4) The prototypes of InitRootBridge() and UninitRootBridge() reflect that
the PCI_ROOT_BRIDGE structure is allocated by the caller; only
in-place initialization is necessary.
Additionally, macros are employed for standard PCI quantities, from
"MdePkg/Include/IndustryStandard/Pci22.h":
- MAX_PCI_DEVICE_NUMBER (31) is replaced with PCI_MAX_DEVICE (same),
- the constant 255 is replaced with PCI_MAX_BUS,
- the (RootBridgeNumber < 256) condition is replaced with
(RootBridgeNumber <= PCI_MAX_BUS).
Cc: Jordan Justen <jordan.l.justen@intel.com>
Cc: Ruiyu Ni <ruiyu.ni@intel.com>
Cc: Marcel Apfelbaum <marcel@redhat.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>
2016-01-25 22:47:00 +01:00
|
|
|
|
2021-01-19 02:12:58 +01:00
|
|
|
return PciHostBridgeUtilityGetRootBridges (
|
|
|
|
Count,
|
2016-05-09 08:03:57 +02:00
|
|
|
Attributes,
|
|
|
|
AllocationAttributes,
|
2021-01-19 02:12:59 +01:00
|
|
|
FALSE,
|
|
|
|
PcdGet16 (PcdOvmfHostBridgePciDevId) != INTEL_Q35_MCH_DEVICE_ID,
|
2021-01-19 02:13:00 +01:00
|
|
|
0,
|
|
|
|
PCI_MAX_BUS,
|
2016-05-09 08:03:57 +02:00
|
|
|
&Io,
|
|
|
|
&Mem,
|
|
|
|
&MemAbove4G,
|
|
|
|
&mNonExistAperture,
|
2021-01-19 02:12:58 +01:00
|
|
|
&mNonExistAperture
|
2016-05-09 08:03:57 +02:00
|
|
|
);
|
2016-01-25 20:33:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Free the root bridge instances array returned from
|
|
|
|
PciHostBridgeGetRootBridges().
|
|
|
|
|
|
|
|
@param The root bridge instances array.
|
|
|
|
@param The count of the array.
|
|
|
|
**/
|
|
|
|
VOID
|
|
|
|
EFIAPI
|
|
|
|
PciHostBridgeFreeRootBridges (
|
|
|
|
PCI_ROOT_BRIDGE *Bridges,
|
|
|
|
UINTN Count
|
|
|
|
)
|
|
|
|
{
|
2021-01-19 02:12:58 +01:00
|
|
|
PciHostBridgeUtilityFreeRootBridges (Bridges, Count);
|
2016-01-25 20:33:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Inform the platform that the resource conflict happens.
|
|
|
|
|
|
|
|
@param HostBridgeHandle Handle of the Host Bridge.
|
|
|
|
@param Configuration Pointer to PCI I/O and PCI memory resource
|
|
|
|
descriptors. The Configuration contains the resources
|
|
|
|
for all the root bridges. The resource for each root
|
|
|
|
bridge is terminated with END descriptor and an
|
|
|
|
additional END is appended indicating the end of the
|
|
|
|
entire resources. The resource descriptor field
|
|
|
|
values follow the description in
|
|
|
|
EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL
|
|
|
|
.SubmitResources().
|
|
|
|
**/
|
|
|
|
VOID
|
|
|
|
EFIAPI
|
|
|
|
PciHostBridgeResourceConflict (
|
|
|
|
EFI_HANDLE HostBridgeHandle,
|
|
|
|
VOID *Configuration
|
|
|
|
)
|
|
|
|
{
|
2021-01-19 02:12:52 +01:00
|
|
|
PciHostBridgeUtilityResourceConflict (Configuration);
|
2016-01-25 20:33:32 +01:00
|
|
|
}
|