summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIlpo Järvinen <ilpo.jarvinen@linux.intel.com>2024-06-14 13:06:06 +0300
committerBjorn Helgaas <bhelgaas@google.com>2024-10-10 17:47:08 -0500
commite3bdd2dd3f618d0bb9f500aae17df2b4f726dca1 (patch)
treedc6019767bac220825d18a645993165e021a78a8
parent9d3faf229c06d953999e2aa6b6dbb57afd252f26 (diff)
PCI: Add ALIGN_DOWN_IF_NONZERO() helper
pci_bus_distribute_available_resources() performs alignment in case of non-zero alignment requirement on three occasions. Add ALIGN_DOWN_IF_NONZERO() helper to avoid coding the non-zero check three times. Suggested-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Link: https://lore.kernel.org/r/20240614100606.15830-5-ilpo.jarvinen@linux.intel.com Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com> Signed-off-by: Bjorn Helgaas <bhelgaas@google.com> Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
-rw-r--r--drivers/pci/setup-bus.c13
1 files changed, 7 insertions, 6 deletions
diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c
index 7293958ab234..27da27c59e89 100644
--- a/drivers/pci/setup-bus.c
+++ b/drivers/pci/setup-bus.c
@@ -1894,6 +1894,9 @@ static void remove_dev_resources(struct pci_dev *dev, struct resource *io,
}
}
+#define ALIGN_DOWN_IF_NONZERO(addr, align) \
+ ((align) ? ALIGN_DOWN((addr), (align)) : (addr))
+
/*
* io, mmio and mmio_pref contain the total amount of bridge window space
* available. This includes the minimal space needed to cover all the
@@ -2005,8 +2008,7 @@ static void pci_bus_distribute_available_resources(struct pci_bus *bus,
* what is available).
*/
align = pci_resource_alignment(dev, res);
- resource_set_size(&io, align ? ALIGN_DOWN(io_per_b, align)
- : io_per_b);
+ resource_set_size(&io, ALIGN_DOWN_IF_NONZERO(io_per_b, align));
/*
* The x_per_b holds the extra resource space that can be
@@ -2018,15 +2020,14 @@ static void pci_bus_distribute_available_resources(struct pci_bus *bus,
res = &dev->resource[PCI_BRIDGE_MEM_WINDOW];
align = pci_resource_alignment(dev, res);
- resource_set_size(&mmio, align ? ALIGN_DOWN(mmio_per_b, align)
- : mmio_per_b);
+ resource_set_size(&mmio,
+ ALIGN_DOWN_IF_NONZERO(mmio_per_b,align));
mmio.start -= resource_size(res);
res = &dev->resource[PCI_BRIDGE_PREF_MEM_WINDOW];
align = pci_resource_alignment(dev, res);
resource_set_size(&mmio_pref,
- align ? ALIGN_DOWN(mmio_pref_per_b, align)
- : mmio_pref_per_b);
+ ALIGN_DOWN_IF_NONZERO(mmio_pref_per_b, align));
mmio_pref.start -= resource_size(res);
pci_bus_distribute_available_resources(b, add_list, io, mmio,