[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v8 30/46] pci/pcie_port: Add pci_find_port_by_pn()
From: |
Jonathan Cameron |
Subject: |
[PATCH v8 30/46] pci/pcie_port: Add pci_find_port_by_pn() |
Date: |
Fri, 18 Mar 2022 15:06:19 +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>
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
---
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 v8 21/46] hw/cxl/device: Implement get/set Label Storage Area (LSA), (continued)
- [PATCH v8 21/46] hw/cxl/device: Implement get/set Label Storage Area (LSA), Jonathan Cameron, 2022/03/18
- [PATCH v8 22/46] qtests/cxl: Add initial root port and CXL type3 tests, Jonathan Cameron, 2022/03/18
- [PATCH v8 23/46] hw/cxl/component: Implement host bridge MMIO (8.2.5, table 142), Jonathan Cameron, 2022/03/18
- [PATCH v8 24/46] acpi/cxl: Add _OSC implementation (9.14.2), Jonathan Cameron, 2022/03/18
- [PATCH v8 25/46] acpi/cxl: Create the CEDT (9.14.1), Jonathan Cameron, 2022/03/18
- [PATCH v8 26/46] hw/cxl/component: Add utils for interleave parameter encoding/decoding, Jonathan Cameron, 2022/03/18
- [PATCH v8 27/46] hw/cxl/host: Add support for CXL Fixed Memory Windows., Jonathan Cameron, 2022/03/18
- [PATCH v8 28/46] acpi/cxl: Introduce CFMWS structures in CEDT, Jonathan Cameron, 2022/03/18
- [PATCH v8 29/46] hw/pci-host/gpex-acpi: Add support for dsdt construction for pxb-cxl, Jonathan Cameron, 2022/03/18
- [PATCH v8 30/46] pci/pcie_port: Add pci_find_port_by_pn(),
Jonathan Cameron <=
- [PATCH v8 31/46] CXL/cxl_component: Add cxl_get_hb_cstate(), Jonathan Cameron, 2022/03/18
- [PATCH v8 32/46] mem/cxl_type3: Add read and write functions for associated hostmem., Jonathan Cameron, 2022/03/18
- [PATCH v8 33/46] cxl/cxl-host: Add memops for CFMWS region., Jonathan Cameron, 2022/03/18
- [PATCH v8 34/46] hw/cxl/component Add a dumb HDM decoder handler, Jonathan Cameron, 2022/03/18
- [PATCH v8 35/46] i386/pc: Enable CXL fixed memory windows, Jonathan Cameron, 2022/03/18
- [PATCH v8 36/46] tests/acpi: q35: Allow addition of a CXL test., Jonathan Cameron, 2022/03/18
- [PATCH v8 37/46] qtests/bios-tables-test: Add a test for CXL emulation., Jonathan Cameron, 2022/03/18
- [PATCH v8 38/46] tests/acpi: Add tables for CXL emulation., Jonathan Cameron, 2022/03/18