Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 14fe5951 authored by Mika Westerberg's avatar Mika Westerberg Committed by Bjorn Helgaas
Browse files

PCI: Move resource distribution for single bridge outside loop



If there is only a single bridge on the bus, we assign all resources to it.
Currently this is done as a part of the resource distribution loop but it
does not have to be there, and moving it outside actually improves
readability because we can then save one indent level in the loop.

While there we can add hotplug_bridges == 1 && normal_bridges == 0 to
the same block because they are dealt the same way.

Suggested-by: default avatarBjorn Helgaas <bhelgaas@google.com>
Signed-off-by: default avatarMika Westerberg <mika.westerberg@linux.intel.com>
Signed-off-by: default avatarBjorn Helgaas <bhelgaas@google.com>
Reviewed-by: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
Reviewed-by: default avatarAndy Shevchenko <andriy.shevchenko@linux.intel.com>
parent 3374c545
Loading
Loading
Loading
Loading
+41 −41
Original line number Diff line number Diff line
@@ -1942,34 +1942,37 @@ static void pci_bus_distribute_available_resources(struct pci_bus *bus,
			remaining_mmio_pref -= resource_size(res);
	}

	/*
	 * There is only one bridge on the bus so it gets all available
	 * resources which it can then distribute to the possible
	 * hotplug bridges below.
	 */
	if (hotplug_bridges + normal_bridges == 1) {
		dev = list_first_entry(&bus->devices, struct pci_dev, bus_list);
		if (dev->subordinate) {
			pci_bus_distribute_available_resources(dev->subordinate,
				add_list, available_io, available_mmio,
				available_mmio_pref);
		}
		return;
	}

	/*
	 * Go over devices on this bus and distribute the remaining
	 * resource space between hotplug bridges.
	 */
	for_each_pci_bridge(dev, bus) {
		resource_size_t align, io, mmio, mmio_pref;
		struct pci_bus *b;

		b = dev->subordinate;
		if (!b)
		if (!b || !dev->is_hotplug_bridge)
			continue;

		if (!hotplug_bridges && normal_bridges == 1) {
			/*
			 * There is only one bridge on the bus (upstream
			 * port) so it gets all available resources
			 * which it can then distribute to the possible
			 * hotplug bridges below.
			 */
			pci_bus_distribute_available_resources(b, add_list,
				available_io, available_mmio,
				available_mmio_pref);
		} else if (dev->is_hotplug_bridge) {
			resource_size_t align, io, mmio, mmio_pref;

		/*
			 * Distribute available extra resources equally
			 * between hotplug-capable downstream ports
			 * taking alignment into account.
		 * Distribute available extra resources equally between
		 * hotplug-capable downstream ports taking alignment into
		 * account.
		 *
		 * Here hotplug_bridges is always != 0.
		 */
@@ -1984,15 +1987,12 @@ static void pci_bus_distribute_available_resources(struct pci_bus *bus,
		remaining_mmio -= mmio;

		align = pci_resource_alignment(bridge, mmio_pref_res);
			mmio_pref = div64_ul(available_mmio_pref,
					     hotplug_bridges);
			mmio_pref = min(ALIGN(mmio_pref, align),
					remaining_mmio_pref);
		mmio_pref = div64_ul(available_mmio_pref, hotplug_bridges);
		mmio_pref = min(ALIGN(mmio_pref, align), remaining_mmio_pref);
		remaining_mmio_pref -= mmio_pref;

			pci_bus_distribute_available_resources(b, add_list, io,
							       mmio, mmio_pref);
		}
		pci_bus_distribute_available_resources(b, add_list, io, mmio,
						       mmio_pref);
	}
}