[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v4 32/42] pci/pcie_port: Add pci_find_port_by_pn()
|
From: |
Jonathan Cameron |
|
Subject: |
[PATCH v4 32/42] pci/pcie_port: Add pci_find_port_by_pn() |
|
Date: |
Mon, 24 Jan 2022 17:16:55 +0000 |
From: Jonathan Cameron <jonathan.cameron@huawei.com>
Simple function to search a PCIBus to find a port by
it's port number.
CXL interleave decoding uses the port number as a target
so it is necessary to locate the port when doing interleave
decoding.
Signed-off-by: Jonathan Cameron <jonathan.cameron@huawei.com>
---
hw/pci/pcie_port.c | 25 +++++++++++++++++++++++++
include/hw/pci/pcie_port.h | 2 ++
2 files changed, 27 insertions(+)
diff --git a/hw/pci/pcie_port.c b/hw/pci/pcie_port.c
index e95c1e5519..687e4e763a 100644
--- a/hw/pci/pcie_port.c
+++ b/hw/pci/pcie_port.c
@@ -136,6 +136,31 @@ static void pcie_port_class_init(ObjectClass *oc, void
*data)
device_class_set_props(dc, pcie_port_props);
}
+PCIDevice *pcie_find_port_by_pn(PCIBus *bus, uint8_t pn)
+{
+ int devfn;
+
+ for (devfn = 0; devfn < ARRAY_SIZE(bus->devices); devfn++) {
+ PCIDevice *d = bus->devices[devfn];
+ PCIEPort *port;
+
+ if (!d || !pci_is_express(d) || !d->exp.exp_cap) {
+ continue;
+ }
+
+ if (!object_dynamic_cast(OBJECT(d), TYPE_PCIE_PORT)) {
+ continue;
+ }
+
+ port = PCIE_PORT(d);
+ if (port->port == pn) {
+ return d;
+ }
+ }
+
+ return NULL;
+}
+
static const TypeInfo pcie_port_type_info = {
.name = TYPE_PCIE_PORT,
.parent = TYPE_PCI_BRIDGE,
diff --git a/include/hw/pci/pcie_port.h b/include/hw/pci/pcie_port.h
index e25b289ce8..7b8193061a 100644
--- a/include/hw/pci/pcie_port.h
+++ b/include/hw/pci/pcie_port.h
@@ -39,6 +39,8 @@ struct PCIEPort {
void pcie_port_init_reg(PCIDevice *d);
+PCIDevice *pcie_find_port_by_pn(PCIBus *bus, uint8_t pn);
+
#define TYPE_PCIE_SLOT "pcie-slot"
OBJECT_DECLARE_SIMPLE_TYPE(PCIESlot, PCIE_SLOT)
--
2.32.0
[PATCH v4 32/42] pci/pcie_port: Add pci_find_port_by_pn(),
Jonathan Cameron <=
[PATCH v4 33/42] CXL/cxl_component: Add cxl_get_hb_cstate(), Jonathan Cameron, 2022/01/24
[PATCH v4 34/42] mem/cxl_type3: Add read and write functions for associated hostmem., Jonathan Cameron, 2022/01/24
[PATCH v4 35/42] cxl/cxl-host: Add memops for CFMWS region., Jonathan Cameron, 2022/01/24
[PATCH v4 36/42] arm/virt: Allow virt/CEDT creation, Jonathan Cameron, 2022/01/24
[PATCH v4 38/42] RFC: softmmu/memory: Add ops to memory_region_ram_init_from_file, Jonathan Cameron, 2022/01/24
[PATCH v4 37/42] hw/arm/virt: Basic CXL enablement on pci_expander_bridge instances pxb-cxl, Jonathan Cameron, 2022/01/24
[PATCH v4 39/42] hw/cxl/component Add a dumb HDM decoder handler, Jonathan Cameron, 2022/01/24
[PATCH v4 40/42] i386/pc: Enable CXL fixed memory windows, Jonathan Cameron, 2022/01/24
[PATCH v4 41/42] qtest/acpi: Add reference CEDT tables., Jonathan Cameron, 2022/01/24
[PATCH v4 42/42] qtest/cxl: Add very basic sanity tests, Jonathan Cameron, 2022/01/24