From e2e360e3f8ab90154bbad05ef5d9cb480d841dca Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Wed, 9 Oct 2019 21:28:04 -0600 Subject: [PATCH] Add hotplug_buses to device struct to allow removal of hack --- src/device/pci_device.c | 24 ++++++++++++++++-------- src/drivers/thunderbolt/thunderbolt.c | 19 +++++++++++++++---- src/include/device/device.h | 1 + 3 files changed, 32 insertions(+), 12 deletions(-) diff --git a/src/device/pci_device.c b/src/device/pci_device.c index 861ed4a924..29ef5dd8bd 100644 --- a/src/device/pci_device.c +++ b/src/device/pci_device.c @@ -1217,13 +1217,15 @@ static void pci_bridge_route(struct bus *link, scan_state state) if (state == PCI_ROUTE_SCAN) { link->secondary = parent->subordinate + 1; - link->subordinate = link->secondary; - - if (dev->vendor == 0x8086 && dev->device == 0x15e7 && PCI_SLOT(dev->path.pci.devfn) == 1) { - printk(BIOS_DEBUG, "system76: HACK: add 32 to subordinate\n"); - link->subordinate += 32; - } - printk(BIOS_DEBUG, "system76: pci_bridge_route: assigning link secondary %d subordinate %d\n", link->secondary, link->subordinate); + link->subordinate = link->secondary + dev->hotplug_buses; + printk( + BIOS_DEBUG, + "system76: %s: %s: assigning link secondary %d subordinate %d\n", + __func__, + dev_path(dev), + link->secondary, + link->subordinate + ); } if (state == PCI_ROUTE_CLOSE) { @@ -1259,7 +1261,13 @@ static void pci_bridge_route(struct bus *link, scan_state state) if (state == PCI_ROUTE_FINAL) { pci_write_config16(dev, PCI_COMMAND, link->bridge_cmd); parent->subordinate = link->subordinate; - printk(BIOS_DEBUG, "system76: pci_bridge_route: assigning link subordinate %d\n", link->subordinate); + printk( + BIOS_DEBUG, + "system76: %s: %s: assigning parent subordinate %d\n", + __func__, + dev_path(dev), + parent->subordinate + ); } } diff --git a/src/drivers/thunderbolt/thunderbolt.c b/src/drivers/thunderbolt/thunderbolt.c index c1ef3c7bb3..cb417ec5b8 100644 --- a/src/drivers/thunderbolt/thunderbolt.c +++ b/src/drivers/thunderbolt/thunderbolt.c @@ -52,15 +52,26 @@ static struct device_operations slot_dev_ops = { .read_resources = slot_dev_read_resources, }; +static bool tbt_is_hotplug_bridge(struct device *dev) { + return PCI_SLOT(dev->path.pci.devfn) == 1; +} + static void tbt_pciexp_scan_bridge(struct device *dev) { - printk(BIOS_DEBUG, "tbt_pciexp_scan_bridge %s: scan bridge\n", dev_path(dev)); + printk(BIOS_DEBUG, "%s: %s: scan bridge\n", __func__, dev_path(dev)); + + bool is_hotplug = tbt_is_hotplug_bridge(dev); + if (is_hotplug) { + /* Add hotplug buses, must happen before bus scan */ + printk(BIOS_DEBUG, "%s: %s: add hotplug buses\n", __func__, dev_path(dev)); + dev->hotplug_buses = 32; + } /* Normal PCIe Scan */ pciexp_scan_bridge(dev); - /* Add dummy slot to preserve resources */ - if (PCI_SLOT(dev->path.pci.devfn) == 1) { - printk(BIOS_DEBUG, "tbt_pciexp_scan_bridge %s: add dummy device\n", dev_path(dev)); + if (is_hotplug) { + /* Add dummy slot to preserve resources, must happen after bus scan */ + printk(BIOS_DEBUG, "%s: %s: add dummy device\n", __func__, dev_path(dev)); struct device *slot; struct device_path slot_path = { .type = DEVICE_PATH_NONE }; slot = alloc_dev(dev->link_list, &slot_path); diff --git a/src/include/device/device.h b/src/include/device/device.h index cb37c096e4..f22bed5d58 100644 --- a/src/include/device/device.h +++ b/src/include/device/device.h @@ -129,6 +129,7 @@ struct device { unsigned int disable_pcie_aspm : 1; unsigned int hidden : 1; /* set if we should hide from UI */ u8 command; + uint16_t hotplug_buses; /* hotplug buses to allocate */ /* Base registers for this device. I/O, MEM and Expansion ROM */ DEVTREE_CONST struct resource *resource_list;