PCI: Allow BAR movement during hotplug
Subsystems (4)
v3 cover PCI: Allow BAR movement during hotplug
If the firmware or kernel has arranged memory for PCIe devices in a way that doesn't provide enough space for BARs of a new hotplugged device, the kernel can pause the drivers of the "obstructing" devices and move their BARs, so new BARs can fit into the freed spaces.
When a driver is un-paused by the kernel after the PCIe rescan, it should check if its BARs had moved, and ioremap() them if needed.
Drivers indicate their support of the feature by implementing the new rescan_prepare() and rescan_done() hooks in the struct pci_driver. If a driver doesn't yet support the feature, BARs of its devices will be marked as immovable by the IORESOURCE_PCI_FIXED flag.
To re-arrange the BARs and bridge windows this patch releases all of them after a rescan and re-assigns in the same way as during the initial PCIe topology scan at system boot.
Tested on:
- x86_64 with "pci=realloc,assign-busses,use_crs pcie_movable_bars=force"
- ppc64le POWER8 PowerNV (with extra arch-specific patches which will be introduced later) with "pci=realloc pcie_movable_bars=force"
Not so many platforms and test cases were covered, so all who are interested are highly welcome to test on your setups - the more exotic the better!
Changes since v2:
- Fixed double-assignment of bridge windows;
- Fixed assignment of fixed prefetched resources;
- Fixed releasing of fixed resources;
- Fixed a debug message;
- Removed auto-enabling the movable BARs for x86 - let's rely on the "pcie_movable_bars=force" option for now;
- Reordered the patches - bugfixes first.
Changes since v1:
- Add a "pcie_movable_bars={ off | force }" command line argument;
- Handle the IORESOURCE_PCI_FIXED flag properly;
- Don't move BARs of devices which don't support the feature;
- Guarantee that new hotplugged devices will not steal memory from working devices by ignoring the failing new devices with the new PCI_DEV_IGNORE flag;
- Add rescan_prepare()+rescan_done() to the struct pci_driver instead of using the reset_prepare()+reset_done() from struct pci_error_handlers;
- Add a bugfix of a race condition;
- Fixed hotplug in a non-pre-enabled (by BIOS/firmware) bridge;
- Fix the compatibility of the feature with pm_runtime and D3-state;
- Hotplug events from pciehp also can move BARs;
- Add support of the feature to the NVME driver.
This patchset is a part of our work on adding support for hotplugging bridges full of NVME and GPU devices (without special requirement such as Hot-Plug Controller, reservation of bus numbers and memory regions by firmware, etc.). Next patchset will implement the movable bus numbers.
Sergey Miroshnichenko (21):
PCI: Fix writing invalid BARs during pci_restore_state()
PCI: Fix race condition in pci_enable/disable_device()
PCI: Enable bridge's I/O and MEM access for hotplugged devices
PCI: Define PCI-specific version of the release_child_resources()
PCI: hotplug: Add a flag for the movable BARs feature
PCI: Pause the devices with movable BARs during rescan
PCI: Wake up bridges during rescan when movable BARs enabled
nvme-pci: Handle movable BARs
PCI: Mark immovable BARs with PCI_FIXED
PCI: Fix assigning of fixed prefetchable resources
PCI: Release and reassign the root bridge resources during rescan
PCI: Don't allow hotplugged devices to steal resources
PCI: Include fixed BARs into the bus size calculating
PCI: Don't reserve memory for hotplug when enabled movable BARs
PCI: Allow the failed resources to be reassigned later
PCI: Calculate fixed areas of bridge windows based on fixed BARs
PCI: Calculate boundaries for bridge windows
PCI: Make sure bridge windows include their fixed BARs
PCI: Prioritize fixed BAR assigning over the movable ones
PCI: pciehp: Add support for the movable BARs feature powerpc/pci: Fix crash with enabled movable BARs
.../admin-guide/kernel-parameters.txt | 7 + arch/powerpc/platforms/powernv/pci-ioda.c | 3 +- drivers/nvme/host/pci.c | 29 +- drivers/pci/bus.c | 7 +- drivers/pci/hotplug/pciehp_pci.c | 14 +- drivers/pci/pci.c | 60 +++- drivers/pci/pci.h | 26 ++ drivers/pci/probe.c | 271 +++++++++++++++++- drivers/pci/setup-bus.c | 245 ++++++++++++++-- drivers/pci/setup-res.c | 43 ++- include/linux/pci.h | 14 + 11 files changed, 678 insertions(+), 41 deletions(-)
Signature · 1 line
2.20.1
RFC PATCH v3 1/21 PCI: Fix writing invalid BARs during pci_restore_state()
If BAR movement has happened (due to PCIe hotplug) after pci_save_state(), the saved addresses will become outdated. Restore them the most recently calculated values, not the ones stored in an arbitrary moment.
--- drivers/pci/pci.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pci/pci.c +1 -1
@@ -1337,7 +1337,7 @@ static void pci_restore_config_space(struct pci_dev *pdev)if (pdev->hdr_type ==PCI_HEADER_TYPE_NORMAL ) {pci_restore_config_space_range (pdev,10 ,15 ,0 , false);/* Restore BARs before the command register. */ -pci_restore_config_space_range (pdev,4 ,9 ,10 , false); +pci_restore_bars (pdev);pci_restore_config_space_range (pdev,0 ,3 ,0 , false); }else if (pdev->hdr_type ==PCI_HEADER_TYPE_BRIDGE ) {pci_restore_config_space_range (pdev,12 ,15 ,0 , false);
Signature · 1 line
2.20.1
RFC PATCH v3 2/21 PCI: Fix race condition in pci_enable/disable_device()
In reply to Sergey MiroshnichenkoCPU0 CPU1
pci_enable_device_mem() pci_enable_device_mem()
pci_enable_bridge() pci_enable_bridge()
pci_is_enabled()
return false;
atomic_inc_return(enable_cnt)
Start actual enabling the bridge
... pci_is_enabled()
... return true;
... Start memory requests <-- FAIL
...
Set the PCI_COMMAND_MEMORY bit <-- Must wait for this
This patch protects the pci_enable/disable_device() and pci_enable_bridge() with mutexes.
--- drivers/pci/pci.c | 26 ++++++++++++++++++++++---- drivers/pci/probe.c | 1 + include/linux/pci.h | 1 + 3 files changed, 24 insertions(+), 4 deletions(-)
drivers/pci/pci.c +22 -4
@@ -1571,6 +1571,8 @@ static void pci_enable_bridge(struct pci_dev *dev)struct pci_dev *bridge;int retval; +mutex_lock (&dev->enable_mutex); + bridge =pci_upstream_bridge (dev);if (bridge)pci_enable_bridge (bridge);
@@ -1578,6 +1580,7 @@ static void pci_enable_bridge(struct pci_dev *dev)if (pci_is_enabled (dev)) {if (!dev->is_busmaster)pci_set_master (dev); +mutex_unlock (&dev->enable_mutex);return ; }
@@ -1586,11 +1589,14 @@ static void pci_enable_bridge(struct pci_dev *dev)pci_err (dev,"Error enabling bridge (%d), continuing\n" , retval);pci_set_master (dev); +mutex_unlock (&dev->enable_mutex); }static int pci_enable_device_flags (struct pci_dev *dev,unsigned long flags) {struct pci_dev *bridge; +/* Enable-locking of bridges is performed within the pci_enable_bridge() */ +bool need_lock = !dev->subordinate;int err;int i, bars =0 ;
@@ -1606,8 +1612,13 @@ static int pci_enable_device_flags(struct pci_dev *dev, unsigned long flags) dev->current_state = (pmcsr &PCI_PM_CTRL_STATE_MASK ); } -if (atomic_inc_return (&dev->enable_cnt) >1 ) +if (need_lock) +mutex_lock (&dev->enable_mutex); +if (pci_is_enabled (dev)) { +if (need_lock) +mutex_unlock (&dev->enable_mutex);return 0 ;/* already enabled */ + } bridge =pci_upstream_bridge (dev);if (bridge)
@@ -1622,8 +1633,10 @@ static int pci_enable_device_flags(struct pci_dev *dev, unsigned long flags) bars |= (1 << i); err =do_pci_enable_device (dev, bars); -if (err <0 ) -atomic_dec (&dev->enable_cnt); +if (err >=0 ) +atomic_inc (&dev->enable_cnt); +if (need_lock) +mutex_unlock (&dev->enable_mutex);return err; }
@@ -1866,15 +1879,20 @@ void pci_disable_device(struct pci_dev *dev)if (dr) dr->enabled =0 ; +mutex_lock (&dev->enable_mutex);dev_WARN_ONCE (&dev->dev,atomic_read (&dev->enable_cnt) <=0 ,"disabling already-disabled device" ); -if (atomic_dec_return (&dev->enable_cnt) !=0 ) +if (atomic_dec_return (&dev->enable_cnt) !=0 ) { +mutex_unlock (&dev->enable_mutex);return ; + }do_pci_disable_device (dev); dev->is_busmaster =0 ; + +mutex_unlock (&dev->enable_mutex); }EXPORT_SYMBOL (pci_disable_device);
drivers/pci/probe.c +1 -0
@@ -2191,6 +2191,7 @@ struct pci_dev *pci_alloc_dev(struct pci_bus *bus)INIT_LIST_HEAD (&dev->bus_list); dev->dev.type = &pci_dev_type; dev->bus =pci_bus_get (bus); +mutex_init (&dev->enable_mutex);return dev; }
include/linux/pci.h +1 -0
@@ -416,6 +416,7 @@ struct pci_dev { unsigned int no_vf_scan:1; /* Don't scan for VFs after IOV enablement */pci_dev_flags_t dev_flags;atomic_t enable_cnt;/* pci_enable_device has been called */ +struct mutex enable_mutex;u32 saved_config_space[16 ];/* Config space saved at suspend time */ struct hlist_head saved_cap_space;
Signature · 1 line
2.20.1
RFC PATCH v3 3/21 PCI: Enable bridge's I/O and MEM access for hotplugged devices
In reply to Sergey MiroshnichenkoAfter updating the bridge window resources, the PCI_COMMAND_IO and PCI_COMMAND_MEMORY bits of the bridge must be addressed as well.
--- drivers/pci/pci.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/pci/pci.c +8 -0
@@ -1578,6 +1578,14 @@ static void pci_enable_bridge(struct pci_dev *dev)pci_enable_bridge (bridge);if (pci_is_enabled (dev)) { +int i, bars =0 ; + +for (i =PCI_BRIDGE_RESOURCES ; i <DEVICE_COUNT_RESOURCE ; i++) { +if (dev->resource[i].flags & (IORESOURCE_MEM |IORESOURCE_IO )) + bars |= (1 << i); + } +do_pci_enable_device (dev, bars); +if (!dev->is_busmaster)pci_set_master (dev);mutex_unlock (&dev->enable_mutex);
Signature · 1 line
2.20.1
RFC PATCH v3 4/21 PCI: Define PCI-specific version of the release_child_resources()
In reply to Sergey MiroshnichenkoMake the released resources of a bridge valid for later re-assignment:
clear the STARTALIGN flag.
Resources marked with PCI_FIXED must preserve their offset and size.
--- drivers/pci/setup-bus.c | 47 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-)
drivers/pci/setup-bus.c +46 -1
@@ -1520,6 +1520,51 @@ static void __pci_bridge_assign_resources(const struct pci_dev *bridge, (IORESOURCE_IO |IORESOURCE_MEM |IORESOURCE_PREFETCH |\IORESOURCE_MEM_64 ) +/* +* Similar to release_child_resources(), but aware of PCI_FIXED and STARTALIGN flags + */ +static void pci_release_child_resources (struct resource *r) +{ +struct resource *tmp, *p; + +if (!r) +return ; + +if (r->flags &IORESOURCE_PCI_FIXED ) +return ; + + p = r->child; + r->child =NULL ; +while (p) { +resource_size_t size =resource_size (p); + + tmp = p; + p = p->sibling; + + tmp->parent =NULL ; + tmp->sibling =NULL ; +pci_release_child_resources (tmp); + +if (!tmp->flags) +continue ; + +if (tmp->flags &IORESOURCE_PCI_FIXED ) { +pr_debug ("PCI: release fixed %pR (%s), keep its flags, base and size\n" , + tmp, tmp->name); +continue ; + } + +pr_debug ("PCI: release %pR (%s)\n" , tmp, tmp->name); + +/* need to restore size, and keep all the flags but STARTALIGN */ + tmp->start =0 ; + tmp->end = size -1 ; + + tmp->flags &= ~IORESOURCE_STARTALIGN ; + tmp->flags |=IORESOURCE_SIZEALIGN ; + } +} +static void pci_bridge_release_resources (struct pci_bus *bus,unsigned long type) {
@@ -1565,7 +1610,7 @@ static void pci_bridge_release_resources(struct pci_bus *bus,* if there are children under that, we should release them * all */ -release_child_resources (r); +pci_release_child_resources (r);if (!release_resource (r)) { type = old_flags = r->flags &PCI_RES_TYPE_MASK ; pci_printk(KERN_DEBUG, dev, "resource %d %pR released\n",
Signature · 1 line
2.20.1
RFC PATCH v3 5/21 PCI: hotplug: Add a flag for the movable BARs feature
In reply to Sergey MiroshnichenkoIf a new PCIe device has been hot-plugged between the two active ones without big enough gap between their BARs, these BARs should be moved if their drivers support this feature. The drivers should be notified and paused during the procedure:
1) dev 8 (new)
|
v
.. | dev 3 | dev 3 | dev 5 | dev 7 |
.. | BAR 0 | BAR 1 | BAR 0 | BAR 0 |2) dev 8
|
v
.. | dev 3 | dev 3 | --> --> | dev 5 | dev 7 |
.. | BAR 0 | BAR 1 | --> --> | BAR 0 | BAR 0 |3)
.. | dev 3 | dev 3 | dev 8 | dev 8 | dev 5 | dev 7 | .. | BAR 0 | BAR 1 | BAR 0 | BAR 1 | BAR 0 | BAR 0 |
Thus, prior reservation of memory regions by BIOS/bootloader/firmware is not required anymore for the PCIe hotplug.
The PCI_MOVABLE_BARS flag is set by the platform is this feature is supported and tested, but can be overridden by the following command line option:
pcie_movable_bars={ off | force }--- .../admin-guide/kernel-parameters.txt | 7 ++++++ drivers/pci/pci.c | 24 +++++++++++++++++++ include/linux/pci.h | 2 ++ 3 files changed, 33 insertions(+)
Documentation/admin-guide/kernel-parameters.txt +7 -0
@@ -3387,6 +3387,13 @@ nomsi Do not use MSI for native PCIe PME signaling (this makes all PCIe root ports use INTx for all services). + pcie_movable_bars=[PCIE] + Override the movable BARs support detection: + off + Disable even if supported by the platform + force + Enable even if not explicitly declared as supported + pcmv= [HW,PCMCIA] BadgePAD 4 pd_ignore_unused
drivers/pci/pci.c +24 -0
@@ -139,6 +139,30 @@ static int __init pcie_port_pm_setup(char *str) }__setup ("pcie_port_pm=" , pcie_port_pm_setup); +static bool pcie_movable_bars_off; +static bool pcie_movable_bars_force; +static int __init pcie_movable_bars_setup (char *str) +{ +if (!strcmp (str,"off" )) + pcie_movable_bars_off = true; +else if (!strcmp (str,"force" )) + pcie_movable_bars_force = true; +return 1 ; +} +__setup ("pcie_movable_bars=" , pcie_movable_bars_setup); + +bool pci_movable_bars_enabled (void ) +{ +if (pcie_movable_bars_off) +return false; + +if (pcie_movable_bars_force) +return true; + +return pci_has_flag (PCI_MOVABLE_BARS ); +} +EXPORT_SYMBOL (pci_movable_bars_enabled); +/* Time to wait after a reset for device to become responsive */ #define PCIE_RESET_READY_POLL_MS 60000
include/linux/pci.h +2 -0
@@ -863,6 +863,7 @@ enum {PCI_ENABLE_PROC_DOMAINS =0x00000010 ,/* Enable domains in /proc */ PCI_COMPAT_DOMAIN_0 =0x00000020 ,/* ... except domain 0 */ PCI_SCAN_ALL_PCIE_DEVS =0x00000040 ,/* Scan all, not just dev 0 */ + PCI_MOVABLE_BARS = 0x00000080, /* Runtime BAR reassign after hotplug */ };/* These external functions are only available when PCI support is enabled */
@@ -1342,6 +1343,7 @@ unsigned char pci_bus_max_busnr(struct pci_bus *bus);void pci_setup_bridge (struct pci_bus *bus);resource_size_t pcibios_window_alignment (struct pci_bus *bus,unsigned long type); +bool pci_movable_bars_enabled (void );#define PCI_VGA_STATE_CHANGE_BRIDGE (1 << 0)#define PCI_VGA_STATE_CHANGE_DECODES (1 << 1)
Signature · 1 line
2.20.1
RFC PATCH v3 6/21 PCI: Pause the devices with movable BARs during rescan
In reply to Sergey MiroshnichenkoDrivers indicate their support of movable BARs by implementing the new rescan_prepare() and rescan_done() hooks in the struct pci_driver.
All device's activity must be stopped during a rescan, and iounmap() +ioremap() must be applied to every used BAR.
--- drivers/pci/probe.c | 51 +++++++++++++++++++++++++++++++++++++++++++-- include/linux/pci.h | 2 ++ 2 files changed, 51 insertions(+), 2 deletions(-)
drivers/pci/probe.c +49 -2
@@ -3172,6 +3172,38 @@ unsigned int pci_rescan_bus_bridge_resize(struct pci_dev *bridge)return max; } +static void pci_bus_rescan_prepare (struct pci_bus *bus) +{ +struct pci_dev *dev; + +list_for_each_entry (dev, &bus->devices, bus_list) { +struct pci_bus *child = dev->subordinate; + +if (child) { +pci_bus_rescan_prepare (child); + }else if (dev->driver && + dev->driver->rescan_prepare) { + dev->driver->rescan_prepare (dev); + } + } +} + +static void pci_bus_rescan_done (struct pci_bus *bus) +{ +struct pci_dev *dev; + +list_for_each_entry (dev, &bus->devices, bus_list) { +struct pci_bus *child = dev->subordinate; + +if (child) { +pci_bus_rescan_done (child); + }else if (dev->driver && + dev->driver->rescan_done) { + dev->driver->rescan_done (dev); + } + } +} +/** * pci_rescan_bus - Scan a PCI bus for devices * @bus: PCI bus to scan
@@ -3185,8 +3217,23 @@ unsigned int pci_rescan_bus(struct pci_bus *bus) {unsigned int max; - max =pci_scan_child_bus (bus); -pci_assign_unassigned_bus_resources (bus); +if (pci_movable_bars_enabled ()) { +struct pci_bus *root = bus; + +while (!pci_is_root_bus (root)) + root = root->parent; + +pci_bus_rescan_prepare (root); + + max =pci_scan_child_bus (root); +pci_assign_unassigned_root_bus_resources (root); + +pci_bus_rescan_done (root); + }else { + max =pci_scan_child_bus (bus); +pci_assign_unassigned_bus_resources (bus); + } +pci_bus_add_devices (bus);return max;
include/linux/pci.h +2 -0
@@ -777,6 +777,8 @@ struct pci_driver {int (*resume)(struct pci_dev *dev);/* Device woken up */ void (*shutdown)(struct pci_dev *dev);int (*sriov_configure)(struct pci_dev *dev,int num_vfs);/* On PF */ +void (*rescan_prepare)(struct pci_dev *dev); +void (*rescan_done)(struct pci_dev *dev);const struct pci_error_handlers *err_handler;const struct attribute_group **groups;struct device_driver driver;
Signature · 1 line
2.20.1
RFC PATCH v3 7/21 PCI: Wake up bridges during rescan when movable BARs enabled
In reply to Sergey MiroshnichenkoUse the PM runtime methods to wake up the bridges before accessing their config space.
--- drivers/pci/probe.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/pci/probe.c +4 -0
@@ -3176,6 +3176,8 @@ static void pci_bus_rescan_prepare(struct pci_bus *bus) {struct pci_dev *dev; +pm_runtime_get_sync (&bus->dev); +list_for_each_entry (dev, &bus->devices, bus_list) {struct pci_bus *child = dev->subordinate;
@@ -3202,6 +3204,8 @@ static void pci_bus_rescan_done(struct pci_bus *bus) dev->driver->rescan_done (dev); } } + +pm_runtime_put (&bus->dev); }/**
Signature · 1 line
2.20.1
RFC PATCH v3 8/21 nvme-pci: Handle movable BARs
In reply to Sergey MiroshnichenkoHotplugged devices can affect the existing ones by moving their BARs. PCI subsystem will inform the NVME driver about this by invoking reset_prepare()+reset_done(), then iounmap()+ioremap() must be called.
--- drivers/nvme/host/pci.c | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-)
drivers/nvme/host/pci.c +27 -2
@@ -114,6 +114,7 @@ struct nvme_dev {unsigned int num_vecs;int q_depth;u32 db_stride; +resource_size_t current_phys_bar;void __iomem *bar;unsigned long bar_mapped_size;struct work_struct remove_work;
@@ -1678,13 +1679,16 @@ static int nvme_remap_bar(struct nvme_dev *dev, unsigned long size) {struct pci_dev *pdev =to_pci_dev (dev->dev); -if (size <= dev->bar_mapped_size) +if (dev->bar && + dev->current_phys_bar ==pci_resource_start (pdev,0 ) && + size <= dev->bar_mapped_size)return 0 ;if (size >pci_resource_len (pdev,0 ))return -ENOMEM ;if (dev->bar)iounmap (dev->bar); - dev->bar =ioremap (pci_resource_start (pdev,0 ), size); + dev->current_phys_bar =pci_resource_start (pdev,0 ); + dev->bar =ioremap (dev->current_phys_bar, size);if (!dev->bar) { dev->bar_mapped_size =0 ;return -ENOMEM ;
@@ -2550,6 +2554,8 @@ static void nvme_reset_work(struct work_struct *work)if (WARN_ON (dev->ctrl.state !=NVME_CTRL_RESETTING )) goto out; +nvme_remap_bar (dev,db_bar_size (dev,0 )); +/* * If we're called to reset a live controller first shut it down before * moving on.
@@ -2952,6 +2958,23 @@ static void nvme_error_resume(struct pci_dev *pdev)flush_work (&dev->ctrl.reset_work); } +void nvme_rescan_prepare (struct pci_dev *pdev) +{ +struct nvme_dev *dev =pci_get_drvdata (pdev); + +nvme_dev_disable (dev, false); +nvme_dev_unmap (dev); + dev->bar =NULL ; +} + +void nvme_rescan_done (struct pci_dev *pdev) +{ +struct nvme_dev *dev =pci_get_drvdata (pdev); + +nvme_dev_map (dev); +nvme_reset_ctrl_sync (&dev->ctrl); +} +static const struct pci_error_handlers nvme_err_handler = { .error_detected = nvme_error_detected, .slot_reset = nvme_slot_reset,
@@ -3016,6 +3039,8 @@ static struct pci_driver nvme_driver = { }, .sriov_configure = pci_sriov_configure_simple, .err_handler = &nvme_err_handler, + .rescan_prepare = nvme_rescan_prepare, + .rescan_done = nvme_rescan_done, };static int __init nvme_init (void )
Signature · 1 line
2.20.1
RFC PATCH v3 9/21 PCI: Mark immovable BARs with PCI_FIXED
In reply to Sergey MiroshnichenkoIf a PCIe device driver doesn't yet have support for movable BARs, mark device's BARs with IORESOURCE_PCI_FIXED.
--- drivers/pci/probe.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
drivers/pci/probe.c +15 -0
@@ -3186,6 +3186,21 @@ static void pci_bus_rescan_prepare(struct pci_bus *bus) }else if (dev->driver && dev->driver->rescan_prepare) { dev->driver->rescan_prepare (dev); + }else if (dev->driver || ((dev->class >>8 ) ==PCI_CLASS_DISPLAY_VGA )) { +int i; + +for (i =0 ; i <PCI_NUM_RESOURCES ; i++) { +struct resource *r = &dev->resource[i]; + +if (!r->flags || !r->parent || + (r->flags &IORESOURCE_UNSET ) || + (r->flags &IORESOURCE_PCI_FIXED )) +continue ; + + r->flags |=IORESOURCE_PCI_FIXED ; +pci_warn (dev,"%s: no support for movable BARs, mark BAR %d (%pR) as fixed\n" , + __func__, i, r); + } } } }
Signature · 1 line
2.20.1
RFC PATCH v3 10/21 PCI: Fix assigning of fixed prefetchable resources
In reply to Sergey MiroshnichenkoAllow matching them to non-prefetchable windows, as it is done for movable resources.
--- drivers/pci/setup-bus.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
drivers/pci/setup-bus.c +9 -4
@@ -1338,15 +1338,20 @@ static void assign_fixed_resource_on_bus(struct pci_bus *b, struct resource *r) {int i;struct resource *parent_r; -unsigned long mask =IORESOURCE_IO |IORESOURCE_MEM | -IORESOURCE_PREFETCH ; +unsigned long mask =IORESOURCE_TYPE_BITS ;pci_bus_for_each_resource (b, parent_r, i) {if (!parent_r)continue ; -if ((r->flags & mask) == (parent_r->flags & mask) && -resource_contains (parent_r, r)) +if ((r->flags & mask) != (parent_r->flags & mask)) +continue ; + +if (parent_r->flags &IORESOURCE_PREFETCH && + !(r->flags &IORESOURCE_PREFETCH )) +continue ; + +if (resource_contains (parent_r, r))request_resource (parent_r, r); } }
Signature · 1 line
2.20.1
RFC PATCH v3 11/21 PCI: Release and reassign the root bridge resources during rescan
In reply to Sergey MiroshnichenkoWhen the movable BARs feature is enabled, don't rely on the memory gaps reserved by the BIOS/bootloader/firmware, but instead rearrange the BARs and bridge windows starting from the root.
Endpoint device's BARs, after being released, are resorted and written back by the pci_assign_unassigned_root_bus_resources().
The last step of writing the recalculated windows to the bridges is done by the new pci_setup_bridges() function.
--- drivers/pci/pci.h | 1 + drivers/pci/probe.c | 22 ++++++++++++++++++++++ drivers/pci/setup-bus.c | 11 ++++++++++- 3 files changed, 33 insertions(+), 1 deletion(-)
drivers/pci/pci.h +1 -0
@@ -248,6 +248,7 @@ void __pci_bus_assign_resources(const struct pci_bus *bus,struct list_head *realloc_head, struct list_head *fail_head);bool pci_bus_clip_resource (struct pci_dev *dev,int idx); +void pci_bus_release_root_bridge_resources (struct pci_bus *bus);void pci_reassigndev_resource_alignment (struct pci_dev *dev);void pci_disable_bridge_window (struct pci_dev *dev);
drivers/pci/probe.c +22 -0
@@ -3223,6 +3223,25 @@ static void pci_bus_rescan_done(struct pci_bus *bus)pm_runtime_put (&bus->dev); } +static void pci_setup_bridges (struct pci_bus *bus) +{ +struct pci_dev *dev; + +list_for_each_entry (dev, &bus->devices, bus_list) { +struct pci_bus *child; + +if (!pci_dev_is_added (dev) ||pci_dev_is_ignored (dev)) +continue ; + + child = dev->subordinate; +if (child) +pci_setup_bridges (child); + } + +if (bus->self) +pci_setup_bridge (bus); +} +/** * pci_rescan_bus - Scan a PCI bus for devices * @bus: PCI bus to scan
@@ -3245,8 +3264,11 @@ unsigned int pci_rescan_bus(struct pci_bus *bus)pci_bus_rescan_prepare (root); max =pci_scan_child_bus (root); + +pci_bus_release_root_bridge_resources (root);pci_assign_unassigned_root_bus_resources (root); +pci_setup_bridges (root);pci_bus_rescan_done (root); }else { max =pci_scan_child_bus (bus);
drivers/pci/setup-bus.c +10 -1
@@ -1621,7 +1621,7 @@ static void pci_bridge_release_resources(struct pci_bus *bus,pci_printk (KERN_DEBUG , dev,"resource %d %pR released\n" ,PCI_BRIDGE_RESOURCES + idx, r);/* keep the old size */ - r->end =resource_size (r) -1 ; + r->end =pci_movable_bars_enabled () ?0 : (resource_size (r) -1 ); r->start =0 ; r->flags =0 ;
@@ -1674,6 +1674,15 @@ static void pci_bus_release_bridge_resources(struct pci_bus *bus,pci_bridge_release_resources (bus, type); } +void pci_bus_release_root_bridge_resources (struct pci_bus *root_bus) +{ +pci_bus_release_bridge_resources (root_bus,IORESOURCE_IO , whole_subtree); +pci_bus_release_bridge_resources (root_bus,IORESOURCE_MEM , whole_subtree); +pci_bus_release_bridge_resources (root_bus, +IORESOURCE_MEM_64 |IORESOURCE_PREFETCH , + whole_subtree); +} +static void pci_bus_dump_res (struct pci_bus *bus) {struct resource *res;
Signature · 1 line
2.20.1
RFC PATCH v3 12/21 PCI: Don't allow hotplugged devices to steal resources
In reply to Sergey MiroshnichenkoWhen movable BARs are enabled, the PCI subsystem at first releases all the bridge windows and then performs an attempt to assign new requested resources and re-assign the existing ones.
If a hotplugged device gets its resources first, there could be no space left to re-assign resources of already working devices, which is unacceptable. If this happens, this patch marks one of the new devices with the new introduced flag PCI_DEV_IGNORE and retries the resource assignment.
This patch adds a new res_mask bitmask to the struct pci_dev for storing the indices of assigned resources.
--- drivers/pci/bus.c | 5 ++ drivers/pci/pci.h | 11 +++++ drivers/pci/probe.c | 100 +++++++++++++++++++++++++++++++++++++++- drivers/pci/setup-bus.c | 15 ++++++ include/linux/pci.h | 1 + 5 files changed, 130 insertions(+), 2 deletions(-)
drivers/pci/bus.c +5 -0
@@ -311,6 +311,11 @@ void pci_bus_add_device(struct pci_dev *dev) {int retval; +if (pci_dev_is_ignored (dev)) { +pci_warn (dev,"%s: don't enable the ignored device\n" , __func__); +return ; + } +/* * Can not put in pci_device_add yet because resources * are not assigned yet for some devices.
drivers/pci/pci.h +11 -0
@@ -366,6 +366,7 @@ static inline bool pci_dev_is_disconnected(const struct pci_dev *dev)/* pci_dev priv_flags */ #define PCI_DEV_ADDED 0 +#define PCI_DEV_IGNORE 1static inline void pci_dev_assign_added (struct pci_dev *dev,bool added) {
@@ -377,6 +378,16 @@ static inline bool pci_dev_is_added(const struct pci_dev *dev)return test_bit (PCI_DEV_ADDED , &dev->priv_flags); } +static inline void pci_dev_ignore (struct pci_dev *dev,bool ignore) +{ +assign_bit (PCI_DEV_IGNORE , &dev->priv_flags, ignore); +} + +static inline bool pci_dev_is_ignored (const struct pci_dev *dev) +{ +return test_bit (PCI_DEV_IGNORE , &dev->priv_flags); +} +#ifdef CONFIG_PCIEAER #include <linux/aer.h>
drivers/pci/probe.c +98 -2
124 lines not on this page · raw message
drivers/pci/setup-bus.c +15 -0
@@ -131,6 +131,9 @@ static void pdev_sort_resources(struct pci_dev *dev, struct list_head *head) {int i; +if (pci_dev_is_ignored (dev)) +return ; +for (i =0 ; i <PCI_NUM_RESOURCES ; i++) {struct resource *r;struct pci_dev_resource *dev_res, *tmp;
@@ -181,6 +184,9 @@ static void __dev_sort_resources(struct pci_dev *dev, {u16 class = dev->class >>8 ; +if (pci_dev_is_ignored (dev)) +return ; +/* Don't touch classless devices or host bridges or ioapics. */ if (class ==PCI_CLASS_NOT_DEFINED || class ==PCI_CLASS_BRIDGE_HOST )return ;
@@ -284,6 +290,9 @@ static void assign_requested_resources_sorted(struct list_head *head,int idx;list_for_each_entry (dev_res, head, list) { +if (pci_dev_is_ignored (dev_res->dev)) +continue ; + res = dev_res->res; idx = res - &dev_res->dev->resource[0 ]; if (resource_size(res) &&
@@ -1028,6 +1037,9 @@ static int pbus_size_mem(struct pci_bus *bus, unsigned long mask,list_for_each_entry (dev, &bus->devices, bus_list) {int i; +if (pci_dev_is_ignored (dev)) +continue ; +for (i =0 ; i <PCI_NUM_RESOURCES ; i++) {struct resource *r = &dev->resource[i];resource_size_t r_size;
@@ -1390,6 +1402,9 @@ void __pci_bus_assign_resources(const struct pci_bus *bus,pbus_assign_resources_sorted (bus, realloc_head, fail_head);list_for_each_entry (dev, &bus->devices, bus_list) { +if (pci_dev_is_ignored (dev)) +continue ; +pdev_assign_fixed_resources (dev); b = dev->subordinate;
include/linux/pci.h +1 -0
@@ -369,6 +369,7 @@ struct pci_dev {*/ unsigned int irq;struct resource resource[DEVICE_COUNT_RESOURCE ];/* I/O and memory regions + expansion ROMs */ +unsigned int res_mask;/* Bitmask of assigned resources */ bool match_driver;/* Skip attaching driver */
Signature · 1 line
2.20.1
RFC PATCH v3 13/21 PCI: Include fixed BARs into the bus size calculating
In reply to Sergey MiroshnichenkoThe only difference between the fixed and movable BARs is an offset preservation during the release+reassign procedure on PCIe rescan.
When fixed BARs are included into the result of pbus_size_mem(), these BARs can be restricted: assign them to direct parents only.
--- drivers/pci/setup-bus.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)
drivers/pci/setup-bus.c +11 -1
@@ -1044,12 +1044,20 @@ static int pbus_size_mem(struct pci_bus *bus, unsigned long mask,struct resource *r = &dev->resource[i];resource_size_t r_size; -if (r->parent || (r->flags &IORESOURCE_PCI_FIXED ) || +if (r->parent || ((r->flags & mask) != type && (r->flags & mask) != type2 && (r->flags & mask) != type3))continue ; r_size =resource_size (r); + +if (r->flags &IORESOURCE_PCI_FIXED ) { +if (pci_movable_bars_enabled ()) + size += r_size; + +continue ; + } +#ifdef CONFIG_PCI_IOV /* put SRIOV requested res to the optional list */ if (realloc_head && i >= PCI_IOV_RESOURCES &&
@@ -1388,6 +1396,8 @@ static void pdev_assign_fixed_resources(struct pci_dev *dev)while (b && !r->parent) {assign_fixed_resource_on_bus (b, r); b = b->parent; +if (!r->parent &&pci_movable_bars_enabled ()) +break ; } } }
Signature · 1 line
2.20.1
RFC PATCH v3 14/21 PCI: Don't reserve memory for hotplug when enabled movable BARs
In reply to Sergey Miroshnichenkopbus_size_mem() returns a precise amount of memory required to fit all the requested BARs and windows of children bridges.
--- drivers/pci/setup-bus.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pci/setup-bus.c +1 -1
@@ -1266,7 +1266,7 @@ void __pci_bus_size_bridges(struct pci_bus *bus, struct list_head *realloc_head)case PCI_CLASS_BRIDGE_PCI :pci_bridge_check_ranges (bus); -if (bus->self->is_hotplug_bridge) { +if (bus->self->is_hotplug_bridge && !pci_movable_bars_enabled ()) { additional_io_size = pci_hotplug_io_size; additional_mem_size = pci_hotplug_mem_size; }
Signature · 1 line
2.20.1
RFC PATCH v3 15/21 PCI: Allow the failed resources to be reassigned later
In reply to Sergey MiroshnichenkoDon't lose the size of the requested EP's BAR if it can't be fit in a current trial, so this can be retried.
But a failed bridge window must be dropped and recalculated in the next trial.
--- drivers/pci/setup-bus.c | 3 ++- drivers/pci/setup-res.c | 12 ++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-)
drivers/pci/setup-bus.c +2 -1
@@ -309,7 +309,8 @@ static void assign_requested_resources_sorted(struct list_head *head,0 /* don't care */ , 0 /* don't care */); } -reset_resource (res); +if (!pci_movable_bars_enabled ()) +reset_resource (res); } } }
drivers/pci/setup-res.c +12 -0
@@ -298,6 +298,18 @@ static int _pci_assign_resource(struct pci_dev *dev, int resno, bus = dev->bus;while ((ret =__pci_assign_resource (bus, dev, resno, size, min_align))) { +if (pci_movable_bars_enabled ()) { +if (resno >=PCI_BRIDGE_RESOURCES && + resno <=PCI_BRIDGE_RESOURCE_END ) { +struct resource *res = dev->resource + resno; + + res->start =0 ; + res->end =0 ; + res->flags =0 ; + } +break ; + } +if (!bus->parent || !bus->self->transparent)break ; bus = bus->parent;
Signature · 1 line
2.20.1
RFC PATCH v3 16/21 PCI: Calculate fixed areas of bridge windows based on fixed BARs
In reply to Sergey MiroshnichenkoFor every (IO, MEM, MEM64) bridge window, count the fixed resources of its children endpoints and children bridge windows:
| <- BAR -> | | <- child bus fixed_range_hard -> | | <- fixed BAR -> |
| <- bus's fixed_range_hard -> |
| <- bus's bridge window -> |These ranges will be later used to arrange bridge windows in a way which covers every immovable BAR as well as the movable ones during hotplug.
--- drivers/pci/pci.h | 14 +++++++ drivers/pci/probe.c | 82 +++++++++++++++++++++++++++++++++++++++++ drivers/pci/setup-bus.c | 17 +++++++++ include/linux/pci.h | 6 +++ 4 files changed, 119 insertions(+)
drivers/pci/pci.h +14 -0
@@ -364,6 +364,20 @@ static inline bool pci_dev_is_disconnected(const struct pci_dev *dev)return dev->error_state == pci_channel_io_perm_failure; } +static inline int pci_get_bridge_resource_idx (struct resource *r) +{ +int idx =1 ; + +if (r->flags &IORESOURCE_IO ) + idx =0 ; +else if (!(r->flags &IORESOURCE_PREFETCH )) + idx =1 ; +else if (r->flags &IORESOURCE_MEM_64 ) + idx =2 ; + +return idx; +} +/* pci_dev priv_flags */ #define PCI_DEV_ADDED 0#define PCI_DEV_IGNORE 1
drivers/pci/probe.c +82 -0
106 lines not on this page · raw message
drivers/pci/setup-bus.c +17 -0
@@ -916,9 +916,17 @@ static void pbus_size_io(struct pci_bus *bus, resource_size_t min_size,resource_size_t children_add_size =0 ;resource_size_t min_align, align; +resource_size_t fixed_start = bus->fixed_range_hard[0 ].start; +resource_size_t fixed_end = bus->fixed_range_hard[0 ].end; +resource_size_t fixed_size = (fixed_start < fixed_end) ? + (fixed_end - fixed_start +1 ) :0 ; +if (!b_res)return ; +if (min_size < fixed_size) + min_size = fixed_size; + min_align =window_alignment (bus,IORESOURCE_IO );list_for_each_entry (dev, &bus->devices, bus_list) {int i;
@@ -1027,6 +1035,15 @@ static int pbus_size_mem(struct pci_bus *bus, unsigned long mask,resource_size_t children_add_size =0 ;resource_size_t children_add_align =0 ;resource_size_t add_align =0 ; +bool is_mem64 = (mask &IORESOURCE_MEM_64 ); + +resource_size_t fixed_start = bus->fixed_range_hard[is_mem64 ?2 :1 ].start; +resource_size_t fixed_end = bus->fixed_range_hard[is_mem64 ?2 :1 ].end; +resource_size_t fixed_size = (fixed_start < fixed_end) ? + (fixed_end - fixed_start +1 ) :0 ; + +if (min_size < fixed_size) + min_size = fixed_size;if (!b_res)return -ENOSPC ;
include/linux/pci.h +6 -0
@@ -569,6 +569,12 @@ struct pci_bus {struct list_head resources;/* Address space routed to this bus */ struct resource busn_res;/* Bus numbers routed to this bus */ +/* +* If there are fixed resources in the bridge window, the hard range +* contains the lowest and the highest addresses of them. +*/ +struct resource fixed_range_hard[PCI_BRIDGE_RESOURCE_NUM ]; +struct pci_ops *ops;/* Configuration access functions */ struct msi_controller *msi;/* MSI controller */ void *sysdata;/* Hook for sys-specific extension */
Signature · 1 line
2.20.1
RFC PATCH v3 17/21 PCI: Calculate boundaries for bridge windows
In reply to Sergey MiroshnichenkoIf a bridge window contains fixed areas (there are PCIe devices with immovable BARs located on this bus), this window must be allocated within the bound memory area, limited by windows size and by address range of fixed resources, calculated as follows:
| <-- bus's fixed_range_hard --> |
| <-- fixed_range_hard.end - window size --> |
| <-- fixed_range_hard.start + window size --> |
| <-- bus's fixed_range_soft --> |--- drivers/pci/setup-bus.c | 56 +++++++++++++++++++++++++++++++++++++++++ include/linux/pci.h | 4 ++- 2 files changed, 59 insertions(+), 1 deletion(-)
drivers/pci/setup-bus.c +56 -0
@@ -1846,6 +1846,61 @@ static enum enable_type pci_realloc_detect(struct pci_bus *bus, }#endif +static void pci_bus_update_fixed_range_soft (struct pci_bus *bus) +{ +struct pci_dev *dev; +struct pci_bus *parent = bus->parent; +int idx; + +list_for_each_entry (dev, &bus->devices, bus_list) +if (dev->subordinate) +pci_bus_update_fixed_range_soft (dev->subordinate); + +if (!parent || !bus->self) +return ; + +for (idx =0 ; idx <ARRAY_SIZE (bus->fixed_range_hard); ++idx) { +struct resource *r; +resource_size_t soft_start, soft_end; +resource_size_t hard_start = bus->fixed_range_hard[idx].start; +resource_size_t hard_end = bus->fixed_range_hard[idx].end; + +if (hard_start > hard_end) +continue ; + + r = bus->resource[idx]; + + soft_start = hard_end -resource_size (r) +1 ; + soft_end = hard_start +resource_size (r) -1 ; + +if (soft_start > hard_start) + soft_start = hard_start; + +if (soft_end < hard_end) + soft_end = hard_end; + +list_for_each_entry (dev, &parent->devices, bus_list) { +struct pci_bus *sibling = dev->subordinate; +resource_size_t s_start, s_end; + +if (!sibling || sibling == bus) +continue ; + + s_start = sibling->fixed_range_hard[idx].start; + s_end = sibling->fixed_range_hard[idx].end; + +if (s_start > s_end) +continue ; + +if (s_end < hard_start && s_end > soft_start) + soft_start = s_end; + } + + bus->fixed_range_soft[idx].start = soft_start; + bus->fixed_range_soft[idx].end = soft_end; + } +} +/* * first try will not touch pci bridge res * second and later try will clear small leaf bridge res
@@ -1884,6 +1939,7 @@ void pci_assign_unassigned_root_bus_resources(struct pci_bus *bus)/* Depth first, calculate sizes and alignments of all subordinate buses. */ __pci_bus_size_bridges (bus, add_list); +pci_bus_update_fixed_range_soft (bus);/* Depth last, allocate resources and update the hardware. */ __pci_bus_assign_resources (bus, add_list, &fail_head);
include/linux/pci.h +3 -1
@@ -571,9 +571,11 @@ struct pci_bus {/* * If there are fixed resources in the bridge window, the hard range -* contains the lowest and the highest addresses of them. +* contains the lowest and the highest addresses of them, and this +* bridge window must reside within the soft range. */ struct resource fixed_range_hard[PCI_BRIDGE_RESOURCE_NUM ]; +struct resource fixed_range_soft[PCI_BRIDGE_RESOURCE_NUM ];struct pci_ops *ops;/* Configuration access functions */ struct msi_controller *msi;/* MSI controller */
Signature · 1 line
2.20.1
RFC PATCH v3 18/21 PCI: Make sure bridge windows include their fixed BARs
In reply to Sergey MiroshnichenkoConsider previously calculated boundaries when allocating a bridge window, setting the lowest allowed address and checking the result.
--- drivers/pci/bus.c | 2 +- drivers/pci/setup-res.c | 31 +++++++++++++++++++++++++++++-- 2 files changed, 30 insertions(+), 3 deletions(-)
drivers/pci/bus.c +1 -1
@@ -192,7 +192,7 @@ static int pci_bus_alloc_from_region(struct pci_bus *bus, struct resource *res,* this is an already-configured bridge window, its start * overrides "min". */ -if (avail.start) +if (min_used < avail.start) min_used = avail.start; max = avail.end;
drivers/pci/setup-res.c +29 -2
@@ -248,9 +248,22 @@ static int __pci_assign_resource(struct pci_bus *bus, struct pci_dev *dev,struct resource *res = dev->resource + resno;resource_size_t min;int ret; +resource_size_t start = (resource_size_t)-1 ; +resource_size_t end =0 ; min = (res->flags &IORESOURCE_IO ) ?PCIBIOS_MIN_IO :PCIBIOS_MIN_MEM ; +if (dev->subordinate && resno >=PCI_BRIDGE_RESOURCES ) { +struct pci_bus *child_bus = dev->subordinate; +int b_resno = resno -PCI_BRIDGE_RESOURCES ; +resource_size_t soft_start = child_bus->fixed_range_soft[b_resno].start; + + start = child_bus->fixed_range_hard[b_resno].start; + end = child_bus->fixed_range_hard[b_resno].end; +if (start < end) + min = soft_start; + } +/* * First, try exact prefetching match. Even if a 64-bit * prefetchable bridge window is below 4GB, we can't put a 32-bit
@@ -262,7 +275,7 @@ static int __pci_assign_resource(struct pci_bus *bus, struct pci_dev *dev,IORESOURCE_PREFETCH |IORESOURCE_MEM_64 , pcibios_align_resource, dev);if (ret ==0 ) -return 0 ; + goto check_fixed;/* * If the prefetchable window is only 32 bits wide, we can put
@@ -274,7 +287,7 @@ static int __pci_assign_resource(struct pci_bus *bus, struct pci_dev *dev,IORESOURCE_PREFETCH , pcibios_align_resource, dev);if (ret ==0 ) -return 0 ; + goto check_fixed; }/*
@@ -287,6 +300,20 @@ static int __pci_assign_resource(struct pci_bus *bus, struct pci_dev *dev, ret =pci_bus_alloc_resource (bus, res, size, align, min,0 , pcibios_align_resource, dev); +check_fixed: +if (ret ==0 && start < end) { +if (res->start > start || res->end < end) { +dev_err (&bus->dev,"%s: fixed area 0x%llx-0x%llx for %s doesn't fit in the allocated %pR (0x%llx-0x%llx)" , + __func__, + (unsigned long long )start, (unsigned long long )end, +dev_name (&dev->dev), + res, (unsigned long long )res->start, + (unsigned long long )res->end); +release_resource (res); +return -1 ; + } + } +return ret; }
Signature · 1 line
2.20.1
RFC PATCH v3 19/21 PCI: Prioritize fixed BAR assigning over the movable ones
In reply to Sergey MiroshnichenkoThe allocated bridge windows are big enough to house all the children bridges and BARs, but the fixed resources must be assigned first, so the movable ones later divide the rest of the window. That's the assignment order:
1. Bridge windows with fixed areas;
2. Fixed BARs;
3. The rest of BARs and bridge windows.
--- drivers/pci/setup-bus.c | 69 ++++++++++++++++++++++++++++++++--------- 1 file changed, 55 insertions(+), 14 deletions(-)
drivers/pci/setup-bus.c +55 -14
@@ -272,31 +272,54 @@ static void reassign_resources_sorted(struct list_head *realloc_head, } } -/** -* assign_requested_resources_sorted() - satisfy resource requests -* -* @head : head of the list tracking requests for resources -* @fail_head : head of the list tracking requests that could -* not be allocated -* -* Satisfy resource requests of each element in the list. Add -* requests that could not satisfied to the failed_list. -*/ -static void assign_requested_resources_sorted (struct list_head *head, -struct list_head *fail_head) +enum assign_step { + assign_fixed_bridge_windows, + assign_fixed_resources, + assign_float_resources, +}; + +static void _assign_requested_resources_sorted (struct list_head *head, +struct list_head *fail_head, +enum assign_step step) {struct resource *res;struct pci_dev_resource *dev_res;int idx;list_for_each_entry (dev_res, head, list) { +bool is_fixed; +bool is_fixed_bridge; +bool is_bridge; +if (pci_dev_is_ignored (dev_res->dev))continue ; res = dev_res->res; +if (!resource_size (res)) +continue ; + idx = res - &dev_res->dev->resource[0 ]; -if (resource_size (res) && -pci_assign_resource (dev_res->dev, idx)) { + is_fixed = res->flags &IORESOURCE_PCI_FIXED ; + is_bridge = dev_res->dev->subordinate && idx >=PCI_BRIDGE_RESOURCES ; + +if (is_bridge) { +struct pci_bus *child = dev_res->dev->subordinate; +int b_res_idx =pci_get_bridge_resource_idx (res); +struct resource *fixed_res = &child->fixed_range_hard[b_res_idx]; + + is_fixed_bridge = fixed_res->start < fixed_res->end; + }else { + is_fixed_bridge = false; + } + +if (assign_fixed_bridge_windows == step && !is_fixed_bridge) +continue ; +else if (assign_fixed_resources == step && (!is_fixed || is_bridge)) +continue ; +else if (assign_float_resources == step && (is_fixed || is_fixed_bridge)) +continue ; + +if (pci_assign_resource (dev_res->dev, idx)) {if (fail_head) {/* * if the failed res is for ROM BAR, and it will
@@ -315,6 +338,24 @@ static void assign_requested_resources_sorted(struct list_head *head, } } +/** +* assign_requested_resources_sorted() - satisfy resource requests +* +* @head : head of the list tracking requests for resources +* @fail_head : head of the list tracking requests that could +* not be allocated +* +* Satisfy resource requests of each element in the list. Add +* requests that could not satisfied to the failed_list. +*/ +static void assign_requested_resources_sorted (struct list_head *head, +struct list_head *fail_head) +{ +_assign_requested_resources_sorted (head, fail_head, assign_fixed_bridge_windows); +_assign_requested_resources_sorted (head, fail_head, assign_fixed_resources); +_assign_requested_resources_sorted (head, fail_head, assign_float_resources); +} +static unsigned long pci_fail_res_type_mask (struct list_head *fail_head) {struct pci_dev_resource *fail_res;
Signature · 1 line
2.20.1
RFC PATCH v3 20/21 PCI: pciehp: Add support for the movable BARs feature
In reply to Sergey MiroshnichenkoWith movable BARs, adding a hotplugged device may affect all the PCIe domain starting from the root, so use a pci_rescan_bus() function which handles the rearrangement of existing BARs and bridge windows.
--- drivers/pci/hotplug/pciehp_pci.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-)
drivers/pci/hotplug/pciehp_pci.c +9 -5
@@ -56,12 +56,16 @@ int pciehp_configure_device(struct controller *ctrl) goto out; } -for_each_pci_bridge (dev, parent) -pci_hp_add_bridge (dev); +if (pci_movable_bars_enabled ()) { +pci_rescan_bus (parent); + }else { +for_each_pci_bridge (dev, parent) +pci_hp_add_bridge (dev); -pci_assign_unassigned_bridge_resources (bridge); -pcie_bus_configure_settings (parent); -pci_bus_add_devices (parent); +pci_assign_unassigned_bridge_resources (bridge); +pcie_bus_configure_settings (parent); +pci_bus_add_devices (parent); + } out:pci_unlock_rescan_remove ();
Signature · 1 line
2.20.1
RFC PATCH v3 21/21 powerpc/pci: Fix crash with enabled movable BARs
In reply to Sergey MiroshnichenkoCheck a resource for the UNSET flags.
--- arch/powerpc/platforms/powernv/pci-ioda.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
arch/powerpc/platforms/powernv/pci-ioda.c +2 -1
@@ -3038,7 +3038,8 @@ static void pnv_ioda_setup_pe_res(struct pnv_ioda_pe *pe,int index;int64_t rc; -if (!res || !res->flags || res->start > res->end) +if (!res || !res->flags || res->start > res->end || + (res->flags &IORESOURCE_UNSET ))return ;if (res->flags &IORESOURCE_IO ) {
Signature · 1 line
2.20.1