mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 00/21] PCI improvements
@ 2019-01-10  4:57 Andrey Smirnov
  2019-01-10  4:57 ` [PATCH 01/21] PCI: Switch to using %pa to print memory addresses Andrey Smirnov
                   ` (20 more replies)
  0 siblings, 21 replies; 26+ messages in thread
From: Andrey Smirnov @ 2019-01-10  4:57 UTC (permalink / raw)
  To: barebox; +Cc: Andrey Smirnov

Everyone:

This series is a number of various small improvementes (or at least
they seemed so to me) as well as a couple of small fixes for 64-bit
builds. With exception of "PCI: Switch to using %pa to print memory
addresses" and "Convert ->res_start() to return resource_size_t" none
of the patches are fixing problems so all of them are optional and can
be dropped from the series.

Hopefully all of the patches are self-explanatory.

Feedback is welcome!

Thanks,
Andrey Smirnov

Andrey Smirnov (21):
  PCI: Switch to using %pa to print memory addresses
  PCI: Replace last_* variables with an array
  PCI: Consolidate limit/base settting code
  PCI: Convert prescan_setup_bridge() to use a loop
  PCI: Convert postscan_setup_bridge() to use a loop
  PCI: Replace magic number in setup_device()
  PCI: Remove superfluous parens in setup_device()
  PCI: Simplify resource setup code in setup_device()
  PCI: Store and reuse BAR offsets
  PCI: Conver register_pci_controller() to use a loop
  PCI: Remove unused variables/code
  PCI: Make pci_scan_bus static
  PCI: Drop "slots" from struct pci_bus
  PCI: Drop "resources" from struct pci_bus
  PCI: Drop "name" from struct pci_bus
  PCI: Drop "ops" from struct pci_bus
  PCI: Drop "rom_address" from struct pci_dev
  PCI: Simplify alloc_pci_dev()
  PCI: Assume 1:1 mapping if .res_start callback is NULL
  PCI: Convert ->res_start() to return resource_size_t
  PCI: Consify pci_ops in struct pci_controller

 arch/mips/mach-malta/pci.c         |   3 +-
 drivers/pci/pci-mvebu.c            |   8 +-
 drivers/pci/pci-tegra.c            |   8 +-
 drivers/pci/pci.c                  | 281 +++++++++++++----------------
 drivers/pci/pci_iomap.c            |   6 +-
 drivers/pci/pcie-designware-host.c |  10 +-
 include/linux/pci.h                |  12 +-
 7 files changed, 139 insertions(+), 189 deletions(-)

-- 
2.20.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 26+ messages in thread

* [PATCH 01/21] PCI: Switch to using %pa to print memory addresses
  2019-01-10  4:57 [PATCH 00/21] PCI improvements Andrey Smirnov
@ 2019-01-10  4:57 ` Andrey Smirnov
  2019-01-10  4:57 ` [PATCH 02/21] PCI: Replace last_* variables with an array Andrey Smirnov
                   ` (19 subsequent siblings)
  20 siblings, 0 replies; 26+ messages in thread
From: Andrey Smirnov @ 2019-01-10  4:57 UTC (permalink / raw)
  To: barebox; +Cc: Andrey Smirnov

Switch to using %pa to print memory addresses in order to be able to
support both 64 and 32 bit builds.

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
 drivers/pci/pci.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index 7abc7a3439..1f9d360d79 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -195,7 +195,7 @@ static void setup_device(struct pci_dev *dev, int max_bar)
 				return;
 			}
 			last_io = ALIGN(last_io, size);
-			pr_debug("pbar%d: allocated at 0x%08x\n", bar, last_io);
+			pr_debug("pbar%d: allocated at %pa\n", bar, &last_io);
 			pci_write_config_dword(dev, PCI_BASE_ADDRESS_0 + bar * 4, last_io);
 			dev->resource[bar].flags = IORESOURCE_IO;
 			last_addr = last_io;
@@ -215,7 +215,7 @@ static void setup_device(struct pci_dev *dev, int max_bar)
 				return;
 			}
 			last_mem_pref = ALIGN(last_mem_pref, size);
-			pr_debug("pbar%d: allocated at 0x%08x\n", bar, last_mem_pref);
+			pr_debug("pbar%d: allocated at %pa\n", bar, &last_mem_pref);
 			pci_write_config_dword(dev, PCI_BASE_ADDRESS_0 + bar * 4, last_mem_pref);
 			dev->resource[bar].flags = IORESOURCE_MEM |
 			                           IORESOURCE_PREFETCH;
@@ -235,7 +235,7 @@ static void setup_device(struct pci_dev *dev, int max_bar)
 				return;
 			}
 			last_mem = ALIGN(last_mem, size);
-			pr_debug("pbar%d: allocated at 0x%08x\n", bar, last_mem);
+			pr_debug("pbar%d: allocated at %pa\n", bar, &last_mem);
 			pci_write_config_dword(dev, PCI_BASE_ADDRESS_0 + bar * 4, last_mem);
 			dev->resource[bar].flags = IORESOURCE_MEM;
 			last_addr = last_mem;
@@ -311,21 +311,21 @@ static void postscan_setup_bridge(struct pci_dev *dev)
 
 	if (last_mem) {
 		last_mem = ALIGN(last_mem, SZ_1M);
-		pr_debug("bridge NP limit at 0x%08x\n", last_mem);
+		pr_debug("bridge NP limit at %pa\n", &last_mem);
 		pci_write_config_word(dev, PCI_MEMORY_LIMIT,
 				      ((last_mem - 1) & 0xfff00000) >> 16);
 	}
 
 	if (last_mem_pref) {
 		last_mem_pref = ALIGN(last_mem_pref, SZ_1M);
-		pr_debug("bridge P limit at 0x%08x\n", last_mem_pref);
+		pr_debug("bridge P limit at %pa\n", &last_mem_pref);
 		pci_write_config_word(dev, PCI_PREF_MEMORY_LIMIT,
 				      ((last_mem_pref - 1) & 0xfff00000) >> 16);
 	}
 
 	if (last_io) {
 		last_io = ALIGN(last_io, SZ_4K);
-		pr_debug("bridge IO limit at 0x%08x\n", last_io);
+		pr_debug("bridge IO limit at %pa\n", &last_io);
 		pci_write_config_byte(dev, PCI_IO_LIMIT,
 				((last_io - 1) & 0x0000f000) >> 8);
 		pci_write_config_word(dev, PCI_IO_LIMIT_UPPER16,
@@ -366,8 +366,8 @@ unsigned int pci_scan_bus(struct pci_bus *bus)
 	unsigned char cmd, tmp, hdr_type, is_multi = 0;
 
 	pr_debug("pci_scan_bus for bus %d\n", bus->number);
-	pr_debug(" last_io = 0x%08x, last_mem = 0x%08x, last_mem_pref = 0x%08x\n",
-	    last_io, last_mem, last_mem_pref);
+	pr_debug(" last_io = %pa, last_mem = %pa, last_mem_pref = %pa\n",
+	    &last_io, &last_mem, &last_mem_pref);
 
 	max = bus->secondary;
 
-- 
2.20.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 26+ messages in thread

* [PATCH 02/21] PCI: Replace last_* variables with an array
  2019-01-10  4:57 [PATCH 00/21] PCI improvements Andrey Smirnov
  2019-01-10  4:57 ` [PATCH 01/21] PCI: Switch to using %pa to print memory addresses Andrey Smirnov
@ 2019-01-10  4:57 ` Andrey Smirnov
  2019-01-10  4:57 ` [PATCH 03/21] PCI: Consolidate limit/base settting code Andrey Smirnov
                   ` (18 subsequent siblings)
  20 siblings, 0 replies; 26+ messages in thread
From: Andrey Smirnov @ 2019-01-10  4:57 UTC (permalink / raw)
  To: barebox; +Cc: Andrey Smirnov

A number of codepaths in pci.c perform almost exactly the same
operations on variables with different names. In order to replace
those paths with loops, replace last_mem, last_mem_perf, last_io,
bus_index with a single last[] array indexed with PCI_BUS_RESOURCE_*
constants. No functional change intended.

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
 drivers/pci/pci.c | 115 +++++++++++++++++++++++-----------------------
 1 file changed, 58 insertions(+), 57 deletions(-)

diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index 1f9d360d79..6a327c6f88 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -8,10 +8,7 @@ static struct pci_controller *hose_head, **hose_tail = &hose_head;
 
 LIST_HEAD(pci_root_buses);
 EXPORT_SYMBOL(pci_root_buses);
-static u8 bus_index;
-static resource_size_t last_mem;
-static resource_size_t last_mem_pref;
-static resource_size_t last_io;
+static resource_size_t last[PCI_BRIDGE_RESOURCE_NUM];
 
 static struct pci_bus *pci_alloc_bus(void)
 {
@@ -57,25 +54,25 @@ void register_pci_controller(struct pci_controller *hose)
 	bus->resource[PCI_BUS_RESOURCE_MEM] = hose->mem_resource;
 	bus->resource[PCI_BUS_RESOURCE_MEM_PREF] = hose->mem_pref_resource;
 	bus->resource[PCI_BUS_RESOURCE_IO] = hose->io_resource;
-	bus->number = bus_index++;
+	bus->number = last[PCI_BUS_RESOURCE_BUSN]++;
 
 	if (hose->set_busno)
 		hose->set_busno(hose, bus->number);
 
 	if (bus->resource[PCI_BUS_RESOURCE_MEM])
-		last_mem = bus->resource[PCI_BUS_RESOURCE_MEM]->start;
+		last[PCI_BUS_RESOURCE_MEM] = bus->resource[PCI_BUS_RESOURCE_MEM]->start;
 	else
-		last_mem = 0;
+		last[PCI_BUS_RESOURCE_MEM] = 0;
 
 	if (bus->resource[PCI_BUS_RESOURCE_MEM_PREF])
-		last_mem_pref = bus->resource[PCI_BUS_RESOURCE_MEM_PREF]->start;
+		last[PCI_BUS_RESOURCE_MEM_PREF] = bus->resource[PCI_BUS_RESOURCE_MEM_PREF]->start;
 	else
-		last_mem_pref = 0;
+		last[PCI_BUS_RESOURCE_MEM_PREF] = 0;
 
 	if (bus->resource[PCI_BUS_RESOURCE_IO])
-		last_io = bus->resource[PCI_BUS_RESOURCE_IO]->start;
+		last[PCI_BUS_RESOURCE_IO] = bus->resource[PCI_BUS_RESOURCE_IO]->start;
 	else
-		last_io = 0;
+		last[PCI_BUS_RESOURCE_IO] = 0;
 
 	pci_scan_bus(bus);
 	pci_bus_register_devices(bus);
@@ -189,19 +186,19 @@ static void setup_device(struct pci_dev *dev, int max_bar)
 				continue;
 			}
 			pr_debug("pbar%d: mask=%08x io %d bytes\n", bar, mask, size);
-			if (ALIGN(last_io, size) + size >
+			if (ALIGN(last[PCI_BUS_RESOURCE_IO], size) + size >
 			    dev->bus->resource[PCI_BUS_RESOURCE_IO]->end) {
 				pr_debug("BAR does not fit within bus IO res\n");
 				return;
 			}
-			last_io = ALIGN(last_io, size);
-			pr_debug("pbar%d: allocated at %pa\n", bar, &last_io);
-			pci_write_config_dword(dev, PCI_BASE_ADDRESS_0 + bar * 4, last_io);
+			last[PCI_BUS_RESOURCE_IO] = ALIGN(last[PCI_BUS_RESOURCE_IO], size);
+			pr_debug("pbar%d: allocated at %pa\n", bar, &last[PCI_BUS_RESOURCE_IO]);
+			pci_write_config_dword(dev, PCI_BASE_ADDRESS_0 + bar * 4, last[PCI_BUS_RESOURCE_IO]);
 			dev->resource[bar].flags = IORESOURCE_IO;
-			last_addr = last_io;
-			last_io += size;
+			last_addr = last[PCI_BUS_RESOURCE_IO];
+			last[PCI_BUS_RESOURCE_IO] += size;
 		} else if ((mask & PCI_BASE_ADDRESS_MEM_PREFETCH) &&
-		           last_mem_pref) /* prefetchable MEM */ {
+		           last[PCI_BUS_RESOURCE_MEM_PREF]) /* prefetchable MEM */ {
 			size = pci_size(orig, mask, 0xfffffff0);
 			if (!size) {
 				pr_debug("pbar%d bad P-MEM mask\n", bar);
@@ -209,18 +206,18 @@ static void setup_device(struct pci_dev *dev, int max_bar)
 			}
 			pr_debug("pbar%d: mask=%08x P memory %d bytes\n",
 			    bar, mask, size);
-			if (ALIGN(last_mem_pref, size) + size >
+			if (ALIGN(last[PCI_BUS_RESOURCE_MEM_PREF], size) + size >
 			    dev->bus->resource[PCI_BUS_RESOURCE_MEM_PREF]->end) {
 				pr_debug("BAR does not fit within bus p-mem res\n");
 				return;
 			}
-			last_mem_pref = ALIGN(last_mem_pref, size);
-			pr_debug("pbar%d: allocated at %pa\n", bar, &last_mem_pref);
-			pci_write_config_dword(dev, PCI_BASE_ADDRESS_0 + bar * 4, last_mem_pref);
+			last[PCI_BUS_RESOURCE_MEM_PREF] = ALIGN(last[PCI_BUS_RESOURCE_MEM_PREF], size);
+			pr_debug("pbar%d: allocated at %pa\n", bar, &last[PCI_BUS_RESOURCE_MEM_PREF]);
+			pci_write_config_dword(dev, PCI_BASE_ADDRESS_0 + bar * 4, last[PCI_BUS_RESOURCE_MEM_PREF]);
 			dev->resource[bar].flags = IORESOURCE_MEM |
 			                           IORESOURCE_PREFETCH;
-			last_addr = last_mem_pref;
-			last_mem_pref += size;
+			last_addr = last[PCI_BUS_RESOURCE_MEM_PREF];
+			last[PCI_BUS_RESOURCE_MEM_PREF] += size;
 		} else { /* non-prefetch MEM */
 			size = pci_size(orig, mask, 0xfffffff0);
 			if (!size) {
@@ -229,17 +226,17 @@ static void setup_device(struct pci_dev *dev, int max_bar)
 			}
 			pr_debug("pbar%d: mask=%08x NP memory %d bytes\n",
 			    bar, mask, size);
-			if (ALIGN(last_mem, size) + size >
+			if (ALIGN(last[PCI_BUS_RESOURCE_MEM], size) + size >
 			    dev->bus->resource[PCI_BUS_RESOURCE_MEM]->end) {
 				pr_debug("BAR does not fit within bus np-mem res\n");
 				return;
 			}
-			last_mem = ALIGN(last_mem, size);
-			pr_debug("pbar%d: allocated at %pa\n", bar, &last_mem);
-			pci_write_config_dword(dev, PCI_BASE_ADDRESS_0 + bar * 4, last_mem);
+			last[PCI_BUS_RESOURCE_MEM] = ALIGN(last[PCI_BUS_RESOURCE_MEM], size);
+			pr_debug("pbar%d: allocated at %pa\n", bar, &last[PCI_BUS_RESOURCE_MEM]);
+			pci_write_config_dword(dev, PCI_BASE_ADDRESS_0 + bar * 4, last[PCI_BUS_RESOURCE_MEM]);
 			dev->resource[bar].flags = IORESOURCE_MEM;
-			last_addr = last_mem;
-			last_mem += size;
+			last_addr = last[PCI_BUS_RESOURCE_MEM];
+			last[PCI_BUS_RESOURCE_MEM] += size;
 		}
 
 		dev->resource[bar].start = last_addr;
@@ -270,19 +267,21 @@ static void prescan_setup_bridge(struct pci_dev *dev)
 	pci_write_config_byte(dev, PCI_SECONDARY_BUS, dev->subordinate->number);
 	pci_write_config_byte(dev, PCI_SUBORDINATE_BUS, 0xff);
 
-	if (last_mem) {
+	if (last[PCI_BUS_RESOURCE_MEM]) {
 		/* Set up memory and I/O filter limits, assume 32-bit I/O space */
-		last_mem = ALIGN(last_mem, SZ_1M);
+		last[PCI_BUS_RESOURCE_MEM] = ALIGN(last[PCI_BUS_RESOURCE_MEM], SZ_1M);
 		pci_write_config_word(dev, PCI_MEMORY_BASE,
-				      (last_mem & 0xfff00000) >> 16);
+				      (last[PCI_BUS_RESOURCE_MEM] & 0xfff00000) >> 16);
 		cmdstat |= PCI_COMMAND_MEMORY;
 	}
 
-	if (last_mem_pref) {
+	if (last[PCI_BUS_RESOURCE_MEM_PREF]) {
 		/* Set up memory and I/O filter limits, assume 32-bit I/O space */
-		last_mem_pref = ALIGN(last_mem_pref, SZ_1M);
+		last[PCI_BUS_RESOURCE_MEM_PREF] =
+			ALIGN(last[PCI_BUS_RESOURCE_MEM_PREF],
+			      SZ_1M);
 		pci_write_config_word(dev, PCI_PREF_MEMORY_BASE,
-				      (last_mem_pref & 0xfff00000) >> 16);
+				      (last[PCI_BUS_RESOURCE_MEM_PREF] & 0xfff00000) >> 16);
 		cmdstat |= PCI_COMMAND_MEMORY;
 	} else {
 
@@ -291,12 +290,12 @@ static void prescan_setup_bridge(struct pci_dev *dev)
 		pci_write_config_word(dev, PCI_PREF_MEMORY_LIMIT, 0x0);
 	}
 
-	if (last_io) {
-		last_io = ALIGN(last_io, SZ_4K);
+	if (last[PCI_BUS_RESOURCE_IO]) {
+		last[PCI_BUS_RESOURCE_IO] = ALIGN(last[PCI_BUS_RESOURCE_IO], SZ_4K);
 		pci_write_config_byte(dev, PCI_IO_BASE,
-				      (last_io & 0x0000f000) >> 8);
+				      (last[PCI_BUS_RESOURCE_IO] & 0x0000f000) >> 8);
 		pci_write_config_word(dev, PCI_IO_BASE_UPPER16,
-				      (last_io & 0xffff0000) >> 16);
+				      (last[PCI_BUS_RESOURCE_IO] & 0xffff0000) >> 16);
 		cmdstat |= PCI_COMMAND_IO;
 	}
 
@@ -307,29 +306,29 @@ static void prescan_setup_bridge(struct pci_dev *dev)
 static void postscan_setup_bridge(struct pci_dev *dev)
 {
 	/* limit subordinate to last used bus number */
-	pci_write_config_byte(dev, PCI_SUBORDINATE_BUS, bus_index - 1);
+	pci_write_config_byte(dev, PCI_SUBORDINATE_BUS, last[PCI_BUS_RESOURCE_BUSN] - 1);
 
-	if (last_mem) {
-		last_mem = ALIGN(last_mem, SZ_1M);
-		pr_debug("bridge NP limit at %pa\n", &last_mem);
+	if (last[PCI_BUS_RESOURCE_MEM]) {
+		last[PCI_BUS_RESOURCE_MEM] = ALIGN(last[PCI_BUS_RESOURCE_MEM], SZ_1M);
+		pr_debug("bridge NP limit at %pa\n", &last[PCI_BUS_RESOURCE_MEM]);
 		pci_write_config_word(dev, PCI_MEMORY_LIMIT,
-				      ((last_mem - 1) & 0xfff00000) >> 16);
+				      ((last[PCI_BUS_RESOURCE_MEM] - 1) & 0xfff00000) >> 16);
 	}
 
-	if (last_mem_pref) {
-		last_mem_pref = ALIGN(last_mem_pref, SZ_1M);
-		pr_debug("bridge P limit at %pa\n", &last_mem_pref);
+	if (last[PCI_BUS_RESOURCE_MEM_PREF]) {
+		last[PCI_BUS_RESOURCE_MEM_PREF] = ALIGN(last[PCI_BUS_RESOURCE_MEM_PREF], SZ_1M);
+		pr_debug("bridge P limit at %pa\n", &last[PCI_BUS_RESOURCE_MEM_PREF]);
 		pci_write_config_word(dev, PCI_PREF_MEMORY_LIMIT,
-				      ((last_mem_pref - 1) & 0xfff00000) >> 16);
+				      ((last[PCI_BUS_RESOURCE_MEM_PREF] - 1) & 0xfff00000) >> 16);
 	}
 
-	if (last_io) {
-		last_io = ALIGN(last_io, SZ_4K);
-		pr_debug("bridge IO limit at %pa\n", &last_io);
+	if (last[PCI_BUS_RESOURCE_IO]) {
+		last[PCI_BUS_RESOURCE_IO] = ALIGN(last[PCI_BUS_RESOURCE_IO], SZ_4K);
+		pr_debug("bridge IO limit at %pa\n", &last[PCI_BUS_RESOURCE_IO]);
 		pci_write_config_byte(dev, PCI_IO_LIMIT,
-				((last_io - 1) & 0x0000f000) >> 8);
+				((last[PCI_BUS_RESOURCE_IO] - 1) & 0x0000f000) >> 8);
 		pci_write_config_word(dev, PCI_IO_LIMIT_UPPER16,
-				((last_io - 1) & 0xffff0000) >> 16);
+				((last[PCI_BUS_RESOURCE_IO] - 1) & 0xffff0000) >> 16);
 	}
 }
 
@@ -367,7 +366,9 @@ unsigned int pci_scan_bus(struct pci_bus *bus)
 
 	pr_debug("pci_scan_bus for bus %d\n", bus->number);
 	pr_debug(" last_io = %pa, last_mem = %pa, last_mem_pref = %pa\n",
-	    &last_io, &last_mem, &last_mem_pref);
+		 &last[PCI_BUS_RESOURCE_IO],
+		 &last[PCI_BUS_RESOURCE_MEM],
+		 &last[PCI_BUS_RESOURCE_MEM_PREF]);
 
 	max = bus->secondary;
 
@@ -450,7 +451,7 @@ unsigned int pci_scan_bus(struct pci_bus *bus)
 				bus->resource[PCI_BUS_RESOURCE_IO];
 
 			child_bus->parent = &dev->dev;
-			child_bus->number = bus_index++;
+			child_bus->number = last[PCI_BUS_RESOURCE_BUSN]++;
 			child_bus->primary = bus->number;
 			list_add_tail(&child_bus->node, &bus->children);
 			dev->subordinate = child_bus;
@@ -477,7 +478,7 @@ unsigned int pci_scan_bus(struct pci_bus *bus)
 	 *
 	 * Return how far we've got finding sub-buses.
 	 */
-	max = bus_index;
+	max = last[PCI_BUS_RESOURCE_BUSN];
 	pr_debug("pci_scan_bus returning with max=%02x\n", max);
 
 	return max;
-- 
2.20.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 26+ messages in thread

* [PATCH 03/21] PCI: Consolidate limit/base settting code
  2019-01-10  4:57 [PATCH 00/21] PCI improvements Andrey Smirnov
  2019-01-10  4:57 ` [PATCH 01/21] PCI: Switch to using %pa to print memory addresses Andrey Smirnov
  2019-01-10  4:57 ` [PATCH 02/21] PCI: Replace last_* variables with an array Andrey Smirnov
@ 2019-01-10  4:57 ` Andrey Smirnov
  2019-01-10  4:57 ` [PATCH 04/21] PCI: Convert prescan_setup_bridge() to use a loop Andrey Smirnov
                   ` (17 subsequent siblings)
  20 siblings, 0 replies; 26+ messages in thread
From: Andrey Smirnov @ 2019-01-10  4:57 UTC (permalink / raw)
  To: barebox; +Cc: Andrey Smirnov

Move limit/base settting code into a dedicated function order to avoid
repeating address masking code. No functional change intended.

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
 drivers/pci/pci.c | 64 +++++++++++++++++++++++++++++++++++------------
 1 file changed, 48 insertions(+), 16 deletions(-)

diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index 6a327c6f88..11f84934f5 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -256,6 +256,42 @@ static void setup_device(struct pci_dev *dev, int max_bar)
 	list_add_tail(&dev->bus_list, &dev->bus->devices);
 }
 
+static void __pci_set_base_or_limit(struct pci_dev *dev, int r,
+				    resource_size_t addr, bool limit)
+{
+	int upper, where;
+
+	switch (r) {
+	case PCI_BUS_RESOURCE_IO:
+		where = limit ? PCI_IO_LIMIT : PCI_IO_BASE;
+		upper = limit ? PCI_IO_LIMIT_UPPER16 : PCI_IO_BASE_UPPER16;
+
+		pci_write_config_byte(dev, where, (addr & 0x0000f000) >> 8);
+		pci_write_config_word(dev, upper, (addr & 0xffff0000) >> 16);
+		return;
+	case PCI_BUS_RESOURCE_MEM:
+		where = limit ? PCI_MEMORY_LIMIT : PCI_MEMORY_BASE;
+		break;
+	case PCI_BUS_RESOURCE_MEM_PREF:
+		where = limit ? PCI_PREF_MEMORY_LIMIT : PCI_PREF_MEMORY_BASE;
+		break;
+	default:
+		BUG();
+	}
+
+	pci_write_config_word(dev, where, (addr & 0xfff00000) >> 16);
+}
+
+static void pci_set_limit(struct pci_dev *dev, int r, resource_size_t addr)
+{
+	__pci_set_base_or_limit(dev, r, addr, true);
+}
+
+static void pci_set_base(struct pci_dev *dev, int r, resource_size_t addr)
+{
+	__pci_set_base_or_limit(dev, r, addr, false);
+}
+
 static void prescan_setup_bridge(struct pci_dev *dev)
 {
 	u16 cmdstat;
@@ -270,8 +306,8 @@ static void prescan_setup_bridge(struct pci_dev *dev)
 	if (last[PCI_BUS_RESOURCE_MEM]) {
 		/* Set up memory and I/O filter limits, assume 32-bit I/O space */
 		last[PCI_BUS_RESOURCE_MEM] = ALIGN(last[PCI_BUS_RESOURCE_MEM], SZ_1M);
-		pci_write_config_word(dev, PCI_MEMORY_BASE,
-				      (last[PCI_BUS_RESOURCE_MEM] & 0xfff00000) >> 16);
+		pci_set_base(dev, PCI_BUS_RESOURCE_MEM,
+			     last[PCI_BUS_RESOURCE_MEM]);
 		cmdstat |= PCI_COMMAND_MEMORY;
 	}
 
@@ -280,8 +316,8 @@ static void prescan_setup_bridge(struct pci_dev *dev)
 		last[PCI_BUS_RESOURCE_MEM_PREF] =
 			ALIGN(last[PCI_BUS_RESOURCE_MEM_PREF],
 			      SZ_1M);
-		pci_write_config_word(dev, PCI_PREF_MEMORY_BASE,
-				      (last[PCI_BUS_RESOURCE_MEM_PREF] & 0xfff00000) >> 16);
+		pci_set_base(dev, PCI_BUS_RESOURCE_MEM_PREF,
+			     last[PCI_BUS_RESOURCE_MEM_PREF]);
 		cmdstat |= PCI_COMMAND_MEMORY;
 	} else {
 
@@ -292,10 +328,8 @@ static void prescan_setup_bridge(struct pci_dev *dev)
 
 	if (last[PCI_BUS_RESOURCE_IO]) {
 		last[PCI_BUS_RESOURCE_IO] = ALIGN(last[PCI_BUS_RESOURCE_IO], SZ_4K);
-		pci_write_config_byte(dev, PCI_IO_BASE,
-				      (last[PCI_BUS_RESOURCE_IO] & 0x0000f000) >> 8);
-		pci_write_config_word(dev, PCI_IO_BASE_UPPER16,
-				      (last[PCI_BUS_RESOURCE_IO] & 0xffff0000) >> 16);
+		pci_set_base(dev, PCI_BUS_RESOURCE_IO,
+			     last[PCI_BUS_RESOURCE_IO]);
 		cmdstat |= PCI_COMMAND_IO;
 	}
 
@@ -311,24 +345,22 @@ static void postscan_setup_bridge(struct pci_dev *dev)
 	if (last[PCI_BUS_RESOURCE_MEM]) {
 		last[PCI_BUS_RESOURCE_MEM] = ALIGN(last[PCI_BUS_RESOURCE_MEM], SZ_1M);
 		pr_debug("bridge NP limit at %pa\n", &last[PCI_BUS_RESOURCE_MEM]);
-		pci_write_config_word(dev, PCI_MEMORY_LIMIT,
-				      ((last[PCI_BUS_RESOURCE_MEM] - 1) & 0xfff00000) >> 16);
+		pci_set_limit(dev, PCI_BUS_RESOURCE_MEM,
+			      last[PCI_BUS_RESOURCE_MEM] - 1);
 	}
 
 	if (last[PCI_BUS_RESOURCE_MEM_PREF]) {
 		last[PCI_BUS_RESOURCE_MEM_PREF] = ALIGN(last[PCI_BUS_RESOURCE_MEM_PREF], SZ_1M);
 		pr_debug("bridge P limit at %pa\n", &last[PCI_BUS_RESOURCE_MEM_PREF]);
-		pci_write_config_word(dev, PCI_PREF_MEMORY_LIMIT,
-				      ((last[PCI_BUS_RESOURCE_MEM_PREF] - 1) & 0xfff00000) >> 16);
+		pci_set_limit(dev, PCI_BUS_RESOURCE_MEM_PREF,
+			      last[PCI_BUS_RESOURCE_MEM_PREF] - 1);
 	}
 
 	if (last[PCI_BUS_RESOURCE_IO]) {
 		last[PCI_BUS_RESOURCE_IO] = ALIGN(last[PCI_BUS_RESOURCE_IO], SZ_4K);
 		pr_debug("bridge IO limit at %pa\n", &last[PCI_BUS_RESOURCE_IO]);
-		pci_write_config_byte(dev, PCI_IO_LIMIT,
-				((last[PCI_BUS_RESOURCE_IO] - 1) & 0x0000f000) >> 8);
-		pci_write_config_word(dev, PCI_IO_LIMIT_UPPER16,
-				((last[PCI_BUS_RESOURCE_IO] - 1) & 0xffff0000) >> 16);
+		pci_set_limit(dev, PCI_BUS_RESOURCE_IO,
+			      last[PCI_BUS_RESOURCE_IO] - 1);
 	}
 }
 
-- 
2.20.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 26+ messages in thread

* [PATCH 04/21] PCI: Convert prescan_setup_bridge() to use a loop
  2019-01-10  4:57 [PATCH 00/21] PCI improvements Andrey Smirnov
                   ` (2 preceding siblings ...)
  2019-01-10  4:57 ` [PATCH 03/21] PCI: Consolidate limit/base settting code Andrey Smirnov
@ 2019-01-10  4:57 ` Andrey Smirnov
  2019-01-10  4:57 ` [PATCH 05/21] PCI: Convert postscan_setup_bridge() " Andrey Smirnov
                   ` (16 subsequent siblings)
  20 siblings, 0 replies; 26+ messages in thread
From: Andrey Smirnov @ 2019-01-10  4:57 UTC (permalink / raw)
  To: barebox; +Cc: Andrey Smirnov

Simplify prescan_setup_bridge() by folding base setup code into a
loop. No functional change intended.

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
 drivers/pci/pci.c | 37 ++++++++++++++-----------------------
 1 file changed, 14 insertions(+), 23 deletions(-)

diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index 11f84934f5..02b7f091f7 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -256,6 +256,11 @@ static void setup_device(struct pci_dev *dev, int max_bar)
 	list_add_tail(&dev->bus_list, &dev->bus->devices);
 }
 
+static size_t pci_resource_to_alignment(int r)
+{
+	return (r == PCI_BUS_RESOURCE_IO) ? SZ_4K : SZ_1M;
+}
+
 static void __pci_set_base_or_limit(struct pci_dev *dev, int r,
 				    resource_size_t addr, bool limit)
 {
@@ -295,6 +300,7 @@ static void pci_set_base(struct pci_dev *dev, int r, resource_size_t addr)
 static void prescan_setup_bridge(struct pci_dev *dev)
 {
 	u16 cmdstat;
+	int r;
 
 	pci_read_config_word(dev, PCI_COMMAND, &cmdstat);
 
@@ -303,36 +309,21 @@ static void prescan_setup_bridge(struct pci_dev *dev)
 	pci_write_config_byte(dev, PCI_SECONDARY_BUS, dev->subordinate->number);
 	pci_write_config_byte(dev, PCI_SUBORDINATE_BUS, 0xff);
 
-	if (last[PCI_BUS_RESOURCE_MEM]) {
-		/* Set up memory and I/O filter limits, assume 32-bit I/O space */
-		last[PCI_BUS_RESOURCE_MEM] = ALIGN(last[PCI_BUS_RESOURCE_MEM], SZ_1M);
-		pci_set_base(dev, PCI_BUS_RESOURCE_MEM,
-			     last[PCI_BUS_RESOURCE_MEM]);
-		cmdstat |= PCI_COMMAND_MEMORY;
+	for (r = PCI_BUS_RESOURCE_IO; r <= PCI_BUS_RESOURCE_MEM_PREF; r++) {
+		if (last[r]) {
+			cmdstat |= (r == PCI_BUS_RESOURCE_IO) ?
+				PCI_COMMAND_IO : PCI_COMMAND_MEMORY;
+			last[r] = ALIGN(last[r], pci_resource_to_alignment(r));
+			pci_set_base(dev, r, last[r]);
+		}
 	}
 
-	if (last[PCI_BUS_RESOURCE_MEM_PREF]) {
-		/* Set up memory and I/O filter limits, assume 32-bit I/O space */
-		last[PCI_BUS_RESOURCE_MEM_PREF] =
-			ALIGN(last[PCI_BUS_RESOURCE_MEM_PREF],
-			      SZ_1M);
-		pci_set_base(dev, PCI_BUS_RESOURCE_MEM_PREF,
-			     last[PCI_BUS_RESOURCE_MEM_PREF]);
-		cmdstat |= PCI_COMMAND_MEMORY;
-	} else {
-
+	if (!last[PCI_BUS_RESOURCE_MEM_PREF]) {
 		/* We don't support prefetchable memory for now, so disable */
 		pci_write_config_word(dev, PCI_PREF_MEMORY_BASE, 0x1000);
 		pci_write_config_word(dev, PCI_PREF_MEMORY_LIMIT, 0x0);
 	}
 
-	if (last[PCI_BUS_RESOURCE_IO]) {
-		last[PCI_BUS_RESOURCE_IO] = ALIGN(last[PCI_BUS_RESOURCE_IO], SZ_4K);
-		pci_set_base(dev, PCI_BUS_RESOURCE_IO,
-			     last[PCI_BUS_RESOURCE_IO]);
-		cmdstat |= PCI_COMMAND_IO;
-	}
-
 	/* Enable memory and I/O accesses, enable bus master */
 	pci_write_config_word(dev, PCI_COMMAND, cmdstat | PCI_COMMAND_MASTER);
 }
-- 
2.20.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 26+ messages in thread

* [PATCH 05/21] PCI: Convert postscan_setup_bridge() to use a loop
  2019-01-10  4:57 [PATCH 00/21] PCI improvements Andrey Smirnov
                   ` (3 preceding siblings ...)
  2019-01-10  4:57 ` [PATCH 04/21] PCI: Convert prescan_setup_bridge() to use a loop Andrey Smirnov
@ 2019-01-10  4:57 ` Andrey Smirnov
  2019-01-10 10:09   ` Sascha Hauer
  2019-01-10  4:57 ` [PATCH 06/21] PCI: Replace magic number in setup_device() Andrey Smirnov
                   ` (15 subsequent siblings)
  20 siblings, 1 reply; 26+ messages in thread
From: Andrey Smirnov @ 2019-01-10  4:57 UTC (permalink / raw)
  To: barebox; +Cc: Andrey Smirnov

Simplify postscan_setup_bridge() by folding limit setting code into a
loop. No functional change intended.

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
 drivers/pci/pci.c | 26 +++++++-------------------
 1 file changed, 7 insertions(+), 19 deletions(-)

diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index 02b7f091f7..b5e13e5dbc 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -330,28 +330,16 @@ static void prescan_setup_bridge(struct pci_dev *dev)
 
 static void postscan_setup_bridge(struct pci_dev *dev)
 {
+	int r;
+
 	/* limit subordinate to last used bus number */
 	pci_write_config_byte(dev, PCI_SUBORDINATE_BUS, last[PCI_BUS_RESOURCE_BUSN] - 1);
 
-	if (last[PCI_BUS_RESOURCE_MEM]) {
-		last[PCI_BUS_RESOURCE_MEM] = ALIGN(last[PCI_BUS_RESOURCE_MEM], SZ_1M);
-		pr_debug("bridge NP limit at %pa\n", &last[PCI_BUS_RESOURCE_MEM]);
-		pci_set_limit(dev, PCI_BUS_RESOURCE_MEM,
-			      last[PCI_BUS_RESOURCE_MEM] - 1);
-	}
-
-	if (last[PCI_BUS_RESOURCE_MEM_PREF]) {
-		last[PCI_BUS_RESOURCE_MEM_PREF] = ALIGN(last[PCI_BUS_RESOURCE_MEM_PREF], SZ_1M);
-		pr_debug("bridge P limit at %pa\n", &last[PCI_BUS_RESOURCE_MEM_PREF]);
-		pci_set_limit(dev, PCI_BUS_RESOURCE_MEM_PREF,
-			      last[PCI_BUS_RESOURCE_MEM_PREF] - 1);
-	}
-
-	if (last[PCI_BUS_RESOURCE_IO]) {
-		last[PCI_BUS_RESOURCE_IO] = ALIGN(last[PCI_BUS_RESOURCE_IO], SZ_4K);
-		pr_debug("bridge IO limit at %pa\n", &last[PCI_BUS_RESOURCE_IO]);
-		pci_set_limit(dev, PCI_BUS_RESOURCE_IO,
-			      last[PCI_BUS_RESOURCE_IO] - 1);
+	for (r = PCI_BUS_RESOURCE_IO; r <= PCI_BUS_RESOURCE_MEM_PREF; r++) {
+		if (last[r]) {
+			last[r] = ALIGN(last[r], pci_resource_to_alignment(r));
+			pci_set_limit(dev, r, last[r] - 1);
+		}
 	}
 }
 
-- 
2.20.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 26+ messages in thread

* [PATCH 06/21] PCI: Replace magic number in setup_device()
  2019-01-10  4:57 [PATCH 00/21] PCI improvements Andrey Smirnov
                   ` (4 preceding siblings ...)
  2019-01-10  4:57 ` [PATCH 05/21] PCI: Convert postscan_setup_bridge() " Andrey Smirnov
@ 2019-01-10  4:57 ` Andrey Smirnov
  2019-01-10  4:57 ` [PATCH 07/21] PCI: Remove superfluous parens " Andrey Smirnov
                   ` (14 subsequent siblings)
  20 siblings, 0 replies; 26+ messages in thread
From: Andrey Smirnov @ 2019-01-10  4:57 UTC (permalink / raw)
  To: barebox; +Cc: Andrey Smirnov

User PCI_BASE_ADDRESS_SPACE_IO instead of explicit magic number. No
functional change intended.

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
 drivers/pci/pci.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index b5e13e5dbc..341af5212f 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -179,7 +179,7 @@ static void setup_device(struct pci_dev *dev, int max_bar)
 			continue;
 		}
 
-		if (mask & 0x01) { /* IO */
+		if (mask & PCI_BASE_ADDRESS_SPACE_IO) { /* IO */
 			size = pci_size(orig, mask, 0xfffffffe);
 			if (!size) {
 				pr_debug("pbar%d bad IO mask\n", bar);
-- 
2.20.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 26+ messages in thread

* [PATCH 07/21] PCI: Remove superfluous parens in setup_device()
  2019-01-10  4:57 [PATCH 00/21] PCI improvements Andrey Smirnov
                   ` (5 preceding siblings ...)
  2019-01-10  4:57 ` [PATCH 06/21] PCI: Replace magic number in setup_device() Andrey Smirnov
@ 2019-01-10  4:57 ` Andrey Smirnov
  2019-01-10  4:57 ` [PATCH 08/21] PCI: Simplify resource setup code " Andrey Smirnov
                   ` (13 subsequent siblings)
  20 siblings, 0 replies; 26+ messages in thread
From: Andrey Smirnov @ 2019-01-10  4:57 UTC (permalink / raw)
  To: barebox; +Cc: Andrey Smirnov

Remove superfluous parens in setup_device(). No functional change
intended.

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
 drivers/pci/pci.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index 341af5212f..c9b6e840b2 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -242,7 +242,7 @@ static void setup_device(struct pci_dev *dev, int max_bar)
 		dev->resource[bar].start = last_addr;
 		dev->resource[bar].end = last_addr + size - 1;
 
-		if ((mask & PCI_BASE_ADDRESS_MEM_TYPE_64)) {
+		if (mask & PCI_BASE_ADDRESS_MEM_TYPE_64) {
 			dev->resource[bar].flags |= IORESOURCE_MEM_64;
 			pci_write_config_dword(dev,
 			       PCI_BASE_ADDRESS_1 + bar * 4, 0);
-- 
2.20.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 26+ messages in thread

* [PATCH 08/21] PCI: Simplify resource setup code in setup_device()
  2019-01-10  4:57 [PATCH 00/21] PCI improvements Andrey Smirnov
                   ` (6 preceding siblings ...)
  2019-01-10  4:57 ` [PATCH 07/21] PCI: Remove superfluous parens " Andrey Smirnov
@ 2019-01-10  4:57 ` Andrey Smirnov
  2019-01-10  4:57 ` [PATCH 09/21] PCI: Store and reuse BAR offsets Andrey Smirnov
                   ` (12 subsequent siblings)
  20 siblings, 0 replies; 26+ messages in thread
From: Andrey Smirnov @ 2019-01-10  4:57 UTC (permalink / raw)
  To: barebox; +Cc: Andrey Smirnov

Simplify resource setup code in setup_device() by factoring out all of
the common code and moving it outside the if main if statement. No
functional change intended.

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
 drivers/pci/pci.c | 98 +++++++++++++++++++----------------------------
 1 file changed, 40 insertions(+), 58 deletions(-)

diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index c9b6e840b2..e57cc32c76 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -166,8 +166,10 @@ static void setup_device(struct pci_dev *dev, int max_bar)
 			      cmd & ~(PCI_COMMAND_IO | PCI_COMMAND_MEMORY));
 
 	for (bar = 0; bar < max_bar; bar++) {
-		resource_size_t last_addr;
 		u32 orig, mask, size;
+		unsigned long flags;
+		const char *kind;
+		int r;
 
 		pci_read_config_dword(dev, PCI_BASE_ADDRESS_0 + bar * 4, &orig);
 		pci_write_config_dword(dev, PCI_BASE_ADDRESS_0 + bar * 4, 0xfffffffe);
@@ -180,67 +182,47 @@ static void setup_device(struct pci_dev *dev, int max_bar)
 		}
 
 		if (mask & PCI_BASE_ADDRESS_SPACE_IO) { /* IO */
-			size = pci_size(orig, mask, 0xfffffffe);
-			if (!size) {
-				pr_debug("pbar%d bad IO mask\n", bar);
-				continue;
-			}
-			pr_debug("pbar%d: mask=%08x io %d bytes\n", bar, mask, size);
-			if (ALIGN(last[PCI_BUS_RESOURCE_IO], size) + size >
-			    dev->bus->resource[PCI_BUS_RESOURCE_IO]->end) {
-				pr_debug("BAR does not fit within bus IO res\n");
-				return;
-			}
-			last[PCI_BUS_RESOURCE_IO] = ALIGN(last[PCI_BUS_RESOURCE_IO], size);
-			pr_debug("pbar%d: allocated at %pa\n", bar, &last[PCI_BUS_RESOURCE_IO]);
-			pci_write_config_dword(dev, PCI_BASE_ADDRESS_0 + bar * 4, last[PCI_BUS_RESOURCE_IO]);
-			dev->resource[bar].flags = IORESOURCE_IO;
-			last_addr = last[PCI_BUS_RESOURCE_IO];
-			last[PCI_BUS_RESOURCE_IO] += size;
+			r     = PCI_BUS_RESOURCE_IO;
+			size  = pci_size(orig, mask, 0xfffffffe);
+			flags = IORESOURCE_IO;
+			kind  = "IO";
 		} else if ((mask & PCI_BASE_ADDRESS_MEM_PREFETCH) &&
-		           last[PCI_BUS_RESOURCE_MEM_PREF]) /* prefetchable MEM */ {
-			size = pci_size(orig, mask, 0xfffffff0);
-			if (!size) {
-				pr_debug("pbar%d bad P-MEM mask\n", bar);
-				continue;
-			}
-			pr_debug("pbar%d: mask=%08x P memory %d bytes\n",
-			    bar, mask, size);
-			if (ALIGN(last[PCI_BUS_RESOURCE_MEM_PREF], size) + size >
-			    dev->bus->resource[PCI_BUS_RESOURCE_MEM_PREF]->end) {
-				pr_debug("BAR does not fit within bus p-mem res\n");
-				return;
-			}
-			last[PCI_BUS_RESOURCE_MEM_PREF] = ALIGN(last[PCI_BUS_RESOURCE_MEM_PREF], size);
-			pr_debug("pbar%d: allocated at %pa\n", bar, &last[PCI_BUS_RESOURCE_MEM_PREF]);
-			pci_write_config_dword(dev, PCI_BASE_ADDRESS_0 + bar * 4, last[PCI_BUS_RESOURCE_MEM_PREF]);
-			dev->resource[bar].flags = IORESOURCE_MEM |
-			                           IORESOURCE_PREFETCH;
-			last_addr = last[PCI_BUS_RESOURCE_MEM_PREF];
-			last[PCI_BUS_RESOURCE_MEM_PREF] += size;
+		           last[PCI_BUS_RESOURCE_MEM_PREF]) {
+			/* prefetchable MEM */
+			r     = PCI_BUS_RESOURCE_MEM_PREF;
+			size  = pci_size(orig, mask, 0xfffffff0);
+			flags = IORESOURCE_MEM | IORESOURCE_PREFETCH;
+			kind  = "P-MEM";
 		} else { /* non-prefetch MEM */
-			size = pci_size(orig, mask, 0xfffffff0);
-			if (!size) {
-				pr_debug("pbar%d bad NP-MEM mask\n", bar);
-				continue;
-			}
-			pr_debug("pbar%d: mask=%08x NP memory %d bytes\n",
-			    bar, mask, size);
-			if (ALIGN(last[PCI_BUS_RESOURCE_MEM], size) + size >
-			    dev->bus->resource[PCI_BUS_RESOURCE_MEM]->end) {
-				pr_debug("BAR does not fit within bus np-mem res\n");
-				return;
-			}
-			last[PCI_BUS_RESOURCE_MEM] = ALIGN(last[PCI_BUS_RESOURCE_MEM], size);
-			pr_debug("pbar%d: allocated at %pa\n", bar, &last[PCI_BUS_RESOURCE_MEM]);
-			pci_write_config_dword(dev, PCI_BASE_ADDRESS_0 + bar * 4, last[PCI_BUS_RESOURCE_MEM]);
-			dev->resource[bar].flags = IORESOURCE_MEM;
-			last_addr = last[PCI_BUS_RESOURCE_MEM];
-			last[PCI_BUS_RESOURCE_MEM] += size;
+			r     = PCI_BUS_RESOURCE_MEM;
+			size  = pci_size(orig, mask, 0xfffffff0);
+			flags = IORESOURCE_MEM;
+			kind  = "NP-MEM";
 		}
 
-		dev->resource[bar].start = last_addr;
-		dev->resource[bar].end = last_addr + size - 1;
+		if (!size) {
+			pr_debug("pbar%d bad %s mask\n", bar, kind);
+			continue;
+		}
+
+		pr_debug("pbar%d: mask=%08x %s %d bytes\n", bar, mask, kind,
+			 size);
+
+		if (ALIGN(last[r], size) + size > dev->bus->resource[r]->end) {
+			pr_debug("BAR does not fit within bus %s res\n", kind);
+			return;
+		}
+
+		last[r] = ALIGN(last[r], size);
+		pci_write_config_dword(dev, PCI_BASE_ADDRESS_0 + bar * 4,
+				       last[r]);
+		dev->resource[bar].flags = flags;
+		dev->resource[bar].start = last[r];
+		dev->resource[bar].end = dev->resource[bar].start + size - 1;
+
+		pr_debug("pbar%d: allocated at %pa\n", bar, &last[r]);
+
+		last[r] += size;
 
 		if (mask & PCI_BASE_ADDRESS_MEM_TYPE_64) {
 			dev->resource[bar].flags |= IORESOURCE_MEM_64;
-- 
2.20.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 26+ messages in thread

* [PATCH 09/21] PCI: Store and reuse BAR offsets
  2019-01-10  4:57 [PATCH 00/21] PCI improvements Andrey Smirnov
                   ` (7 preceding siblings ...)
  2019-01-10  4:57 ` [PATCH 08/21] PCI: Simplify resource setup code " Andrey Smirnov
@ 2019-01-10  4:57 ` Andrey Smirnov
  2019-01-10  4:57 ` [PATCH 10/21] PCI: Conver register_pci_controller() to use a loop Andrey Smirnov
                   ` (11 subsequent siblings)
  20 siblings, 0 replies; 26+ messages in thread
From: Andrey Smirnov @ 2019-01-10  4:57 UTC (permalink / raw)
  To: barebox; +Cc: Andrey Smirnov

Save and reuse BAR offsets in dedicated constants instead of repeating
the same expression multiple times. No functional change intended.

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
 drivers/pci/pci.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index e57cc32c76..3e249abe4f 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -166,15 +166,17 @@ static void setup_device(struct pci_dev *dev, int max_bar)
 			      cmd & ~(PCI_COMMAND_IO | PCI_COMMAND_MEMORY));
 
 	for (bar = 0; bar < max_bar; bar++) {
+		const int pci_base_address_0 = PCI_BASE_ADDRESS_0 + bar * 4;
+		const int pci_base_address_1 = PCI_BASE_ADDRESS_1 + bar * 4;
 		u32 orig, mask, size;
 		unsigned long flags;
 		const char *kind;
 		int r;
 
-		pci_read_config_dword(dev, PCI_BASE_ADDRESS_0 + bar * 4, &orig);
-		pci_write_config_dword(dev, PCI_BASE_ADDRESS_0 + bar * 4, 0xfffffffe);
-		pci_read_config_dword(dev, PCI_BASE_ADDRESS_0 + bar * 4, &mask);
-		pci_write_config_dword(dev, PCI_BASE_ADDRESS_0 + bar * 4, orig);
+		pci_read_config_dword(dev, pci_base_address_0, &orig);
+		pci_write_config_dword(dev, pci_base_address_0, 0xfffffffe);
+		pci_read_config_dword(dev, pci_base_address_0, &mask);
+		pci_write_config_dword(dev, pci_base_address_0, orig);
 
 		if (mask == 0 || mask == 0xffffffff) {
 			pr_debug("pbar%d set bad mask\n", bar);
@@ -214,8 +216,7 @@ static void setup_device(struct pci_dev *dev, int max_bar)
 		}
 
 		last[r] = ALIGN(last[r], size);
-		pci_write_config_dword(dev, PCI_BASE_ADDRESS_0 + bar * 4,
-				       last[r]);
+		pci_write_config_dword(dev, pci_base_address_0, last[r]);
 		dev->resource[bar].flags = flags;
 		dev->resource[bar].start = last[r];
 		dev->resource[bar].end = dev->resource[bar].start + size - 1;
@@ -226,8 +227,7 @@ static void setup_device(struct pci_dev *dev, int max_bar)
 
 		if (mask & PCI_BASE_ADDRESS_MEM_TYPE_64) {
 			dev->resource[bar].flags |= IORESOURCE_MEM_64;
-			pci_write_config_dword(dev,
-			       PCI_BASE_ADDRESS_1 + bar * 4, 0);
+			pci_write_config_dword(dev, pci_base_address_1, 0);
 			bar++;
 		}
 	}
-- 
2.20.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 26+ messages in thread

* [PATCH 10/21] PCI: Conver register_pci_controller() to use a loop
  2019-01-10  4:57 [PATCH 00/21] PCI improvements Andrey Smirnov
                   ` (8 preceding siblings ...)
  2019-01-10  4:57 ` [PATCH 09/21] PCI: Store and reuse BAR offsets Andrey Smirnov
@ 2019-01-10  4:57 ` Andrey Smirnov
  2019-01-10  4:57 ` [PATCH 11/21] PCI: Remove unused variables/code Andrey Smirnov
                   ` (10 subsequent siblings)
  20 siblings, 0 replies; 26+ messages in thread
From: Andrey Smirnov @ 2019-01-10  4:57 UTC (permalink / raw)
  To: barebox; +Cc: Andrey Smirnov

Conver register_pci_controller() to use a loop. No functional change
intended.

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
 drivers/pci/pci.c | 17 +++--------------
 1 file changed, 3 insertions(+), 14 deletions(-)

diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index 3e249abe4f..e1c059f2a9 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -42,6 +42,7 @@ static void pci_bus_register_devices(struct pci_bus *bus)
 void register_pci_controller(struct pci_controller *hose)
 {
 	struct pci_bus *bus;
+	int r;
 
 	*hose_tail = hose;
 	hose_tail = &hose->next;
@@ -59,20 +60,8 @@ void register_pci_controller(struct pci_controller *hose)
 	if (hose->set_busno)
 		hose->set_busno(hose, bus->number);
 
-	if (bus->resource[PCI_BUS_RESOURCE_MEM])
-		last[PCI_BUS_RESOURCE_MEM] = bus->resource[PCI_BUS_RESOURCE_MEM]->start;
-	else
-		last[PCI_BUS_RESOURCE_MEM] = 0;
-
-	if (bus->resource[PCI_BUS_RESOURCE_MEM_PREF])
-		last[PCI_BUS_RESOURCE_MEM_PREF] = bus->resource[PCI_BUS_RESOURCE_MEM_PREF]->start;
-	else
-		last[PCI_BUS_RESOURCE_MEM_PREF] = 0;
-
-	if (bus->resource[PCI_BUS_RESOURCE_IO])
-		last[PCI_BUS_RESOURCE_IO] = bus->resource[PCI_BUS_RESOURCE_IO]->start;
-	else
-		last[PCI_BUS_RESOURCE_IO] = 0;
+	for (r = PCI_BUS_RESOURCE_IO; r <= PCI_BUS_RESOURCE_MEM_PREF; r++)
+		last[r] = bus->resource[r] ? bus->resource[r]->start : 0;
 
 	pci_scan_bus(bus);
 	pci_bus_register_devices(bus);
-- 
2.20.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 26+ messages in thread

* [PATCH 11/21] PCI: Remove unused variables/code
  2019-01-10  4:57 [PATCH 00/21] PCI improvements Andrey Smirnov
                   ` (9 preceding siblings ...)
  2019-01-10  4:57 ` [PATCH 10/21] PCI: Conver register_pci_controller() to use a loop Andrey Smirnov
@ 2019-01-10  4:57 ` Andrey Smirnov
  2019-01-10  4:57 ` [PATCH 12/21] PCI: Make pci_scan_bus static Andrey Smirnov
                   ` (9 subsequent siblings)
  20 siblings, 0 replies; 26+ messages in thread
From: Andrey Smirnov @ 2019-01-10  4:57 UTC (permalink / raw)
  To: barebox; +Cc: Andrey Smirnov

Both host_head and host_tail are not used anywhere in the codebase and
look like a leftover. Remove them.

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
 drivers/pci/pci.c | 5 -----
 1 file changed, 5 deletions(-)

diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index e1c059f2a9..9bfa54d054 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -4,8 +4,6 @@
 #include <linux/sizes.h>
 #include <linux/pci.h>
 
-static struct pci_controller *hose_head, **hose_tail = &hose_head;
-
 LIST_HEAD(pci_root_buses);
 EXPORT_SYMBOL(pci_root_buses);
 static resource_size_t last[PCI_BRIDGE_RESOURCE_NUM];
@@ -44,9 +42,6 @@ void register_pci_controller(struct pci_controller *hose)
 	struct pci_bus *bus;
 	int r;
 
-	*hose_tail = hose;
-	hose_tail = &hose->next;
-
 	bus = pci_alloc_bus();
 	hose->bus = bus;
 	bus->parent = hose->parent;
-- 
2.20.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 26+ messages in thread

* [PATCH 12/21] PCI: Make pci_scan_bus static
  2019-01-10  4:57 [PATCH 00/21] PCI improvements Andrey Smirnov
                   ` (10 preceding siblings ...)
  2019-01-10  4:57 ` [PATCH 11/21] PCI: Remove unused variables/code Andrey Smirnov
@ 2019-01-10  4:57 ` Andrey Smirnov
  2019-01-10  4:57 ` [PATCH 13/21] PCI: Drop "slots" from struct pci_bus Andrey Smirnov
                   ` (8 subsequent siblings)
  20 siblings, 0 replies; 26+ messages in thread
From: Andrey Smirnov @ 2019-01-10  4:57 UTC (permalink / raw)
  To: barebox; +Cc: Andrey Smirnov

Pci_scan_bus is not used anyhwere outside pci.c. Mark in static to
reflect that. No functional change intended.

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
 drivers/pci/pci.c   | 4 +++-
 include/linux/pci.h | 1 -
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index 9bfa54d054..23306be506 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -4,6 +4,8 @@
 #include <linux/sizes.h>
 #include <linux/pci.h>
 
+static unsigned int pci_scan_bus(struct pci_bus *bus);
+
 LIST_HEAD(pci_root_buses);
 EXPORT_SYMBOL(pci_root_buses);
 static resource_size_t last[PCI_BRIDGE_RESOURCE_NUM];
@@ -334,7 +336,7 @@ pci_of_match_device(struct device_d *parent, unsigned int devfn)
 	return NULL;
 }
 
-unsigned int pci_scan_bus(struct pci_bus *bus)
+static unsigned int pci_scan_bus(struct pci_bus *bus)
 {
 	struct pci_dev *dev;
 	struct pci_bus *child_bus;
diff --git a/include/linux/pci.h b/include/linux/pci.h
index 82f27f21b2..c8f91cdd96 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -251,7 +251,6 @@ int pci_register_device(struct pci_dev *pdev);
 
 extern struct list_head pci_root_buses; /* list of all known PCI buses */
 
-extern unsigned int pci_scan_bus(struct pci_bus *bus);
 extern void register_pci_controller(struct pci_controller *hose);
 
 int pci_bus_read_config_byte(struct pci_bus *bus, unsigned int devfn,
-- 
2.20.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 26+ messages in thread

* [PATCH 13/21] PCI: Drop "slots" from struct pci_bus
  2019-01-10  4:57 [PATCH 00/21] PCI improvements Andrey Smirnov
                   ` (11 preceding siblings ...)
  2019-01-10  4:57 ` [PATCH 12/21] PCI: Make pci_scan_bus static Andrey Smirnov
@ 2019-01-10  4:57 ` Andrey Smirnov
  2019-01-10  4:57 ` [PATCH 14/21] PCI: Drop "resources" " Andrey Smirnov
                   ` (7 subsequent siblings)
  20 siblings, 0 replies; 26+ messages in thread
From: Andrey Smirnov @ 2019-01-10  4:57 UTC (permalink / raw)
  To: barebox; +Cc: Andrey Smirnov

This field is not used by Barebox. Remove it. No functional change
intended.

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
 drivers/pci/pci.c   | 1 -
 include/linux/pci.h | 1 -
 2 files changed, 2 deletions(-)

diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index 23306be506..c8521ddcd2 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -19,7 +19,6 @@ static struct pci_bus *pci_alloc_bus(void)
 	INIT_LIST_HEAD(&b->node);
 	INIT_LIST_HEAD(&b->children);
 	INIT_LIST_HEAD(&b->devices);
-	INIT_LIST_HEAD(&b->slots);
 	INIT_LIST_HEAD(&b->resources);
 
 	return b;
diff --git a/include/linux/pci.h b/include/linux/pci.h
index c8f91cdd96..28aa56343b 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -129,7 +129,6 @@ struct pci_bus {
 	struct list_head node;		/* node in list of buses */
 	struct list_head children;	/* list of child buses */
 	struct list_head devices;	/* list of devices on this bus */
-	struct list_head slots;		/* list of slots on this bus */
 	struct resource *resource[PCI_BRIDGE_RESOURCE_NUM];
 	struct list_head resources;	/* address space routed to this bus */
 
-- 
2.20.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 26+ messages in thread

* [PATCH 14/21] PCI: Drop "resources" from struct pci_bus
  2019-01-10  4:57 [PATCH 00/21] PCI improvements Andrey Smirnov
                   ` (12 preceding siblings ...)
  2019-01-10  4:57 ` [PATCH 13/21] PCI: Drop "slots" from struct pci_bus Andrey Smirnov
@ 2019-01-10  4:57 ` Andrey Smirnov
  2019-01-10  4:57 ` [PATCH 15/21] PCI: Drop "name" " Andrey Smirnov
                   ` (6 subsequent siblings)
  20 siblings, 0 replies; 26+ messages in thread
From: Andrey Smirnov @ 2019-01-10  4:57 UTC (permalink / raw)
  To: barebox; +Cc: Andrey Smirnov

This field is not used by Barebox. Remove it. No functional change
intended.

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
 drivers/pci/pci.c   | 1 -
 include/linux/pci.h | 1 -
 2 files changed, 2 deletions(-)

diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index c8521ddcd2..78c0daffcd 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -19,7 +19,6 @@ static struct pci_bus *pci_alloc_bus(void)
 	INIT_LIST_HEAD(&b->node);
 	INIT_LIST_HEAD(&b->children);
 	INIT_LIST_HEAD(&b->devices);
-	INIT_LIST_HEAD(&b->resources);
 
 	return b;
 }
diff --git a/include/linux/pci.h b/include/linux/pci.h
index 28aa56343b..d7a0e2babc 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -130,7 +130,6 @@ struct pci_bus {
 	struct list_head children;	/* list of child buses */
 	struct list_head devices;	/* list of devices on this bus */
 	struct resource *resource[PCI_BRIDGE_RESOURCE_NUM];
-	struct list_head resources;	/* address space routed to this bus */
 
 	struct pci_ops	*ops;		/* configuration access functions */
 
-- 
2.20.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 26+ messages in thread

* [PATCH 15/21] PCI: Drop "name" from struct pci_bus
  2019-01-10  4:57 [PATCH 00/21] PCI improvements Andrey Smirnov
                   ` (13 preceding siblings ...)
  2019-01-10  4:57 ` [PATCH 14/21] PCI: Drop "resources" " Andrey Smirnov
@ 2019-01-10  4:57 ` Andrey Smirnov
  2019-01-10  4:57 ` [PATCH 16/21] PCI: Drop "ops" " Andrey Smirnov
                   ` (5 subsequent siblings)
  20 siblings, 0 replies; 26+ messages in thread
From: Andrey Smirnov @ 2019-01-10  4:57 UTC (permalink / raw)
  To: barebox; +Cc: Andrey Smirnov

This field is not used by Barebox. Remove it. No functional change
intended.

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
 include/linux/pci.h | 2 --
 1 file changed, 2 deletions(-)

diff --git a/include/linux/pci.h b/include/linux/pci.h
index d7a0e2babc..a519a9dc81 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -137,8 +137,6 @@ struct pci_bus {
 	unsigned char	primary;	/* number of primary bridge */
 	unsigned char	secondary;	/* number of secondary bridge */
 	unsigned char	subordinate;	/* max number of subordinate buses */
-
-	char		name[48];
 };
 
 /* Low-level architecture-dependent routines */
-- 
2.20.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 26+ messages in thread

* [PATCH 16/21] PCI: Drop "ops" from struct pci_bus
  2019-01-10  4:57 [PATCH 00/21] PCI improvements Andrey Smirnov
                   ` (14 preceding siblings ...)
  2019-01-10  4:57 ` [PATCH 15/21] PCI: Drop "name" " Andrey Smirnov
@ 2019-01-10  4:57 ` Andrey Smirnov
  2019-01-10  4:57 ` [PATCH 17/21] PCI: Drop "rom_address" from struct pci_dev Andrey Smirnov
                   ` (4 subsequent siblings)
  20 siblings, 0 replies; 26+ messages in thread
From: Andrey Smirnov @ 2019-01-10  4:57 UTC (permalink / raw)
  To: barebox; +Cc: Andrey Smirnov

Drop "ops" from struct pci_bus, since the same struct can be accessed
via host->pci_ops. No functional change intended.

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
 drivers/pci/pci.c       | 6 ++----
 drivers/pci/pci_iomap.c | 2 +-
 include/linux/pci.h     | 2 --
 3 files changed, 3 insertions(+), 7 deletions(-)

diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index 78c0daffcd..c34b918453 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -46,7 +46,6 @@ void register_pci_controller(struct pci_controller *hose)
 	hose->bus = bus;
 	bus->parent = hose->parent;
 	bus->host = hose;
-	bus->ops = hose->pci_ops;
 	bus->resource[PCI_BUS_RESOURCE_MEM] = hose->mem_resource;
 	bus->resource[PCI_BUS_RESOURCE_MEM_PREF] = hose->mem_pref_resource;
 	bus->resource[PCI_BUS_RESOURCE_IO] = hose->io_resource;
@@ -83,7 +82,7 @@ int pci_bus_read_config_##size \
 	int res;							\
 	u32 data = 0;							\
 	if (PCI_##size##_BAD) return PCIBIOS_BAD_REGISTER_NUMBER;	\
-	res = bus->ops->read(bus, devfn, pos, len, &data);		\
+	res = bus->host->pci_ops->read(bus, devfn, pos, len, &data);	\
 	*value = (type)data;						\
 	return res;							\
 }
@@ -94,7 +93,7 @@ int pci_bus_write_config_##size \
 {									\
 	int res;							\
 	if (PCI_##size##_BAD) return PCIBIOS_BAD_REGISTER_NUMBER;	\
-	res = bus->ops->write(bus, devfn, pos, len, value);		\
+	res = bus->host->pci_ops->write(bus, devfn, pos, len, value);	\
 	return res;							\
 }
 
@@ -418,7 +417,6 @@ static unsigned int pci_scan_bus(struct pci_bus *bus)
 			child_bus = pci_alloc_bus();
 			/* inherit parent properties */
 			child_bus->host = bus->host;
-			child_bus->ops = bus->host->pci_ops;
 			child_bus->parent_bus = bus;
 			child_bus->resource[PCI_BUS_RESOURCE_MEM] =
 				bus->resource[PCI_BUS_RESOURCE_MEM];
diff --git a/drivers/pci/pci_iomap.c b/drivers/pci/pci_iomap.c
index a56f61dc1a..2c58c0c0f9 100644
--- a/drivers/pci/pci_iomap.c
+++ b/drivers/pci/pci_iomap.c
@@ -24,6 +24,6 @@ void __iomem *pci_iomap(struct pci_dev *dev, int bar)
 	struct pci_bus *bus = dev->bus;
 	resource_size_t start = pci_resource_start(dev, bar);
 
-	return (void *)bus->ops->res_start(bus, start);
+	return (void *)bus->host->pci_ops->res_start(bus, start);
 }
 EXPORT_SYMBOL(pci_iomap);
diff --git a/include/linux/pci.h b/include/linux/pci.h
index a519a9dc81..b609a1330b 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -131,8 +131,6 @@ struct pci_bus {
 	struct list_head devices;	/* list of devices on this bus */
 	struct resource *resource[PCI_BRIDGE_RESOURCE_NUM];
 
-	struct pci_ops	*ops;		/* configuration access functions */
-
 	unsigned char	number;		/* bus number */
 	unsigned char	primary;	/* number of primary bridge */
 	unsigned char	secondary;	/* number of secondary bridge */
-- 
2.20.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 26+ messages in thread

* [PATCH 17/21] PCI: Drop "rom_address" from struct pci_dev
  2019-01-10  4:57 [PATCH 00/21] PCI improvements Andrey Smirnov
                   ` (15 preceding siblings ...)
  2019-01-10  4:57 ` [PATCH 16/21] PCI: Drop "ops" " Andrey Smirnov
@ 2019-01-10  4:57 ` Andrey Smirnov
  2019-01-10  4:57 ` [PATCH 18/21] PCI: Simplify alloc_pci_dev() Andrey Smirnov
                   ` (3 subsequent siblings)
  20 siblings, 0 replies; 26+ messages in thread
From: Andrey Smirnov @ 2019-01-10  4:57 UTC (permalink / raw)
  To: barebox; +Cc: Andrey Smirnov

This field is not being used in Barebox. Drop it.

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
 drivers/pci/pci.c   | 7 -------
 include/linux/pci.h | 1 -
 2 files changed, 8 deletions(-)

diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index c34b918453..12f438d3ff 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -404,13 +404,6 @@ static unsigned int pci_scan_bus(struct pci_bus *bus)
 			if (class == PCI_CLASS_BRIDGE_PCI)
 				goto bad;
 
-			/*
-			 * read base address registers, again pcibios_fixup() can
-			 * tweak these
-			 */
-			pci_read_config_dword(dev, PCI_ROM_ADDRESS, &l);
-			dev->rom_address = (l == 0xffffffff) ? 0 : l;
-
 			setup_device(dev, 6);
 			break;
 		case PCI_HEADER_TYPE_BRIDGE:
diff --git a/include/linux/pci.h b/include/linux/pci.h
index b609a1330b..2c7acbdda9 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -112,7 +112,6 @@ struct pci_dev {
 	 * pcibios_fixup() as necessary.
 	 */
 	unsigned long	base_address[6];
-	unsigned long	rom_address;
 };
 #define	to_pci_dev(dev) container_of(dev, struct pci_dev, dev)
 
-- 
2.20.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 26+ messages in thread

* [PATCH 18/21] PCI: Simplify alloc_pci_dev()
  2019-01-10  4:57 [PATCH 00/21] PCI improvements Andrey Smirnov
                   ` (16 preceding siblings ...)
  2019-01-10  4:57 ` [PATCH 17/21] PCI: Drop "rom_address" from struct pci_dev Andrey Smirnov
@ 2019-01-10  4:57 ` Andrey Smirnov
  2019-01-10  4:57 ` [PATCH 19/21] PCI: Assume 1:1 mapping if .res_start callback is NULL Andrey Smirnov
                   ` (2 subsequent siblings)
  20 siblings, 0 replies; 26+ messages in thread
From: Andrey Smirnov @ 2019-01-10  4:57 UTC (permalink / raw)
  To: barebox; +Cc: Andrey Smirnov

Use xzalloc() to allocate PCI device and drop OOM checking code.

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
 drivers/pci/pci.c | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)

diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index 12f438d3ff..8a0d7fb03b 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -115,10 +115,7 @@ static struct pci_dev *alloc_pci_dev(void)
 {
 	struct pci_dev *dev;
 
-	dev = kzalloc(sizeof(struct pci_dev), GFP_KERNEL);
-	if (!dev)
-		return NULL;
-
+	dev = xzalloc(sizeof(struct pci_dev));
 	INIT_LIST_HEAD(&dev->bus_list);
 
 	return dev;
@@ -364,9 +361,6 @@ static unsigned int pci_scan_bus(struct pci_bus *bus)
 			continue;
 
 		dev = alloc_pci_dev();
-		if (!dev)
-			return 0;
-
 		dev->bus = bus;
 		dev->devfn = devfn;
 		dev->vendor = l & 0xffff;
-- 
2.20.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 26+ messages in thread

* [PATCH 19/21] PCI: Assume 1:1 mapping if .res_start callback is NULL
  2019-01-10  4:57 [PATCH 00/21] PCI improvements Andrey Smirnov
                   ` (17 preceding siblings ...)
  2019-01-10  4:57 ` [PATCH 18/21] PCI: Simplify alloc_pci_dev() Andrey Smirnov
@ 2019-01-10  4:57 ` Andrey Smirnov
  2019-01-10  4:57 ` [PATCH 20/21] PCI: Convert ->res_start() to return resource_size_t Andrey Smirnov
  2019-01-10  4:57 ` [PATCH 21/21] PCI: Consify pci_ops in struct pci_controller Andrey Smirnov
  20 siblings, 0 replies; 26+ messages in thread
From: Andrey Smirnov @ 2019-01-10  4:57 UTC (permalink / raw)
  To: barebox; +Cc: Andrey Smirnov

Save a bit of no-op boilerplate by converting pci_iomap() to treat
absense of .res_start callback as an indicator that 1:1 mapping is
being used.

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
 drivers/pci/pci-tegra.c            | 6 ------
 drivers/pci/pci_iomap.c            | 6 +++++-
 drivers/pci/pcie-designware-host.c | 6 ------
 3 files changed, 5 insertions(+), 13 deletions(-)

diff --git a/drivers/pci/pci-tegra.c b/drivers/pci/pci-tegra.c
index b6ccf8e5b5..7c9dd80c00 100644
--- a/drivers/pci/pci-tegra.c
+++ b/drivers/pci/pci-tegra.c
@@ -366,15 +366,9 @@ static int tegra_pcie_write_conf(struct pci_bus *bus, unsigned int devfn,
 	return PCIBIOS_SUCCESSFUL;
 }
 
-static int tegra_pcie_res_start(struct pci_bus *bus, resource_size_t res_addr)
-{
-	return res_addr;
-}
-
 static struct pci_ops tegra_pcie_ops = {
 	.read = tegra_pcie_read_conf,
 	.write = tegra_pcie_write_conf,
-	.res_start = tegra_pcie_res_start,
 };
 
 static unsigned long tegra_pcie_port_get_pex_ctrl(struct tegra_pcie_port *port)
diff --git a/drivers/pci/pci_iomap.c b/drivers/pci/pci_iomap.c
index 2c58c0c0f9..2f06e60e38 100644
--- a/drivers/pci/pci_iomap.c
+++ b/drivers/pci/pci_iomap.c
@@ -3,6 +3,7 @@
  *
  * (C) Copyright 2004 Linus Torvalds
  */
+#include <common.h>
 #include <linux/pci.h>
 #include <io.h>
 
@@ -24,6 +25,9 @@ void __iomem *pci_iomap(struct pci_dev *dev, int bar)
 	struct pci_bus *bus = dev->bus;
 	resource_size_t start = pci_resource_start(dev, bar);
 
-	return (void *)bus->host->pci_ops->res_start(bus, start);
+	if (bus->host->pci_ops->res_start)
+		start = bus->host->pci_ops->res_start(bus, start);
+
+	return IOMEM(start);
 }
 EXPORT_SYMBOL(pci_iomap);
diff --git a/drivers/pci/pcie-designware-host.c b/drivers/pci/pcie-designware-host.c
index 6cc4b93a31..af37a502d8 100644
--- a/drivers/pci/pcie-designware-host.c
+++ b/drivers/pci/pcie-designware-host.c
@@ -335,15 +335,9 @@ static int dw_pcie_wr_conf(struct pci_bus *bus, u32 devfn,
 	return ret;
 }
 
-static int dw_pcie_res_start(struct pci_bus *bus, resource_size_t res_addr)
-{
-	return res_addr;
-}
-
 static struct pci_ops dw_pcie_ops = {
 	.read = dw_pcie_rd_conf,
 	.write = dw_pcie_wr_conf,
-	.res_start = dw_pcie_res_start,
 };
 
 static u8 dw_pcie_iatu_unroll_enabled(struct dw_pcie *pci)
-- 
2.20.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 26+ messages in thread

* [PATCH 20/21] PCI: Convert ->res_start() to return resource_size_t
  2019-01-10  4:57 [PATCH 00/21] PCI improvements Andrey Smirnov
                   ` (18 preceding siblings ...)
  2019-01-10  4:57 ` [PATCH 19/21] PCI: Assume 1:1 mapping if .res_start callback is NULL Andrey Smirnov
@ 2019-01-10  4:57 ` Andrey Smirnov
  2019-01-10  4:57 ` [PATCH 21/21] PCI: Consify pci_ops in struct pci_controller Andrey Smirnov
  20 siblings, 0 replies; 26+ messages in thread
From: Andrey Smirnov @ 2019-01-10  4:57 UTC (permalink / raw)
  To: barebox; +Cc: Andrey Smirnov

On 64-bit machines int doesn't cover full address space, so convert
.res_start to both accept resource_size_t as a parameter and return it
as result.

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
 arch/mips/mach-malta/pci.c | 3 ++-
 drivers/pci/pci-mvebu.c    | 6 ++++--
 include/linux/pci.h        | 2 +-
 3 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/arch/mips/mach-malta/pci.c b/arch/mips/mach-malta/pci.c
index 47c0e228a7..4561123d22 100644
--- a/arch/mips/mach-malta/pci.c
+++ b/arch/mips/mach-malta/pci.c
@@ -131,7 +131,8 @@ static int gt64xxx_pci0_pcibios_write(struct pci_bus *bus, unsigned int devfn,
 }
 
 /* function returns memory address for begin of pci resource */
-static int gt64xxx_res_start(struct pci_bus *bus, resource_size_t res_addr)
+static resource_size_t gt64xxx_res_start(struct pci_bus *bus,
+					 resource_size_t res_addr)
 {
 	return KSEG0ADDR(res_addr);
 }
diff --git a/drivers/pci/pci-mvebu.c b/drivers/pci/pci-mvebu.c
index 1c20f91544..c17ef3898b 100644
--- a/drivers/pci/pci-mvebu.c
+++ b/drivers/pci/pci-mvebu.c
@@ -145,11 +145,13 @@ static int mvebu_pcie_indirect_wr_conf(struct pci_bus *bus,
 	return PCIBIOS_SUCCESSFUL;
 }
 
-static int mvebu_pcie_res_start(struct pci_bus *bus, resource_size_t res_addr)
+static resource_size_t mvebu_pcie_res_start(struct pci_bus *bus,
+					    resource_size_t res_addr)
 {
 	struct mvebu_pcie *pcie = to_pcie(bus->host);
 
-	return (int)pcie->membase + (res_addr & (resource_size(&pcie->mem)-1));
+	return (resource_size_t)pcie->membase +
+		(res_addr & (resource_size(&pcie->mem) - 1));
 }
 
 static struct pci_ops mvebu_pcie_indirect_ops = {
diff --git a/include/linux/pci.h b/include/linux/pci.h
index 2c7acbdda9..c00a866a48 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -143,7 +143,7 @@ struct pci_ops {
 	int (*write)(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 val);
 
 	/* return memory address for pci resource */
-	int (*res_start)(struct pci_bus *bus, resource_size_t res_addr);
+	resource_size_t (*res_start)(struct pci_bus *bus, resource_size_t res_addr);
 };
 
 extern struct pci_ops *pci_ops;
-- 
2.20.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 26+ messages in thread

* [PATCH 21/21] PCI: Consify pci_ops in struct pci_controller
  2019-01-10  4:57 [PATCH 00/21] PCI improvements Andrey Smirnov
                   ` (19 preceding siblings ...)
  2019-01-10  4:57 ` [PATCH 20/21] PCI: Convert ->res_start() to return resource_size_t Andrey Smirnov
@ 2019-01-10  4:57 ` Andrey Smirnov
  20 siblings, 0 replies; 26+ messages in thread
From: Andrey Smirnov @ 2019-01-10  4:57 UTC (permalink / raw)
  To: barebox; +Cc: Andrey Smirnov

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
 drivers/pci/pci-mvebu.c            | 2 +-
 drivers/pci/pci-tegra.c            | 2 +-
 drivers/pci/pcie-designware-host.c | 4 ++--
 include/linux/pci.h                | 2 +-
 4 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/pci/pci-mvebu.c b/drivers/pci/pci-mvebu.c
index c17ef3898b..ae2e83dacd 100644
--- a/drivers/pci/pci-mvebu.c
+++ b/drivers/pci/pci-mvebu.c
@@ -154,7 +154,7 @@ static resource_size_t mvebu_pcie_res_start(struct pci_bus *bus,
 		(res_addr & (resource_size(&pcie->mem) - 1));
 }
 
-static struct pci_ops mvebu_pcie_indirect_ops = {
+static const struct pci_ops mvebu_pcie_indirect_ops = {
 	.read = mvebu_pcie_indirect_rd_conf,
 	.write = mvebu_pcie_indirect_wr_conf,
 	.res_start = mvebu_pcie_res_start,
diff --git a/drivers/pci/pci-tegra.c b/drivers/pci/pci-tegra.c
index 7c9dd80c00..7f10b7af2e 100644
--- a/drivers/pci/pci-tegra.c
+++ b/drivers/pci/pci-tegra.c
@@ -366,7 +366,7 @@ static int tegra_pcie_write_conf(struct pci_bus *bus, unsigned int devfn,
 	return PCIBIOS_SUCCESSFUL;
 }
 
-static struct pci_ops tegra_pcie_ops = {
+static const struct pci_ops tegra_pcie_ops = {
 	.read = tegra_pcie_read_conf,
 	.write = tegra_pcie_write_conf,
 };
diff --git a/drivers/pci/pcie-designware-host.c b/drivers/pci/pcie-designware-host.c
index af37a502d8..0c6ace0928 100644
--- a/drivers/pci/pcie-designware-host.c
+++ b/drivers/pci/pcie-designware-host.c
@@ -29,7 +29,7 @@
 
 #include <abort.h>
 
-static struct pci_ops dw_pcie_ops;
+static const struct pci_ops dw_pcie_ops;
 static unsigned long global_io_offset;
 
 static int dw_pcie_rd_own_conf(struct pcie_port *pp, int where, int size,
@@ -335,7 +335,7 @@ static int dw_pcie_wr_conf(struct pci_bus *bus, u32 devfn,
 	return ret;
 }
 
-static struct pci_ops dw_pcie_ops = {
+static const struct pci_ops dw_pcie_ops = {
 	.read = dw_pcie_rd_conf,
 	.write = dw_pcie_wr_conf,
 };
diff --git a/include/linux/pci.h b/include/linux/pci.h
index c00a866a48..478f10207a 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -158,7 +158,7 @@ struct pci_controller {
 	struct device_d *parent;
 	struct pci_bus *bus;
 
-	struct pci_ops *pci_ops;
+	const struct pci_ops *pci_ops;
 	struct resource *mem_resource;
 	struct resource *mem_pref_resource;
 	unsigned long mem_offset;
-- 
2.20.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH 05/21] PCI: Convert postscan_setup_bridge() to use a loop
  2019-01-10  4:57 ` [PATCH 05/21] PCI: Convert postscan_setup_bridge() " Andrey Smirnov
@ 2019-01-10 10:09   ` Sascha Hauer
  2019-01-10 19:16     ` Andrey Smirnov
  0 siblings, 1 reply; 26+ messages in thread
From: Sascha Hauer @ 2019-01-10 10:09 UTC (permalink / raw)
  To: Andrey Smirnov; +Cc: barebox

Hi Andrey,

On Wed, Jan 09, 2019 at 08:57:23PM -0800, Andrey Smirnov wrote:
> Simplify postscan_setup_bridge() by folding limit setting code into a
> loop. No functional change intended.
> 
> Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
> ---
>  drivers/pci/pci.c | 26 +++++++-------------------
>  1 file changed, 7 insertions(+), 19 deletions(-)
> 
> diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
> index 02b7f091f7..b5e13e5dbc 100644
> --- a/drivers/pci/pci.c
> +++ b/drivers/pci/pci.c
> @@ -330,28 +330,16 @@ static void prescan_setup_bridge(struct pci_dev *dev)
>  
>  static void postscan_setup_bridge(struct pci_dev *dev)
>  {
> +	int r;
> +
>  	/* limit subordinate to last used bus number */
>  	pci_write_config_byte(dev, PCI_SUBORDINATE_BUS, last[PCI_BUS_RESOURCE_BUSN] - 1);
>  
> -	if (last[PCI_BUS_RESOURCE_MEM]) {
> -		last[PCI_BUS_RESOURCE_MEM] = ALIGN(last[PCI_BUS_RESOURCE_MEM], SZ_1M);
> -		pr_debug("bridge NP limit at %pa\n", &last[PCI_BUS_RESOURCE_MEM]);
> -		pci_set_limit(dev, PCI_BUS_RESOURCE_MEM,
> -			      last[PCI_BUS_RESOURCE_MEM] - 1);
> -	}
> -
> -	if (last[PCI_BUS_RESOURCE_MEM_PREF]) {
> -		last[PCI_BUS_RESOURCE_MEM_PREF] = ALIGN(last[PCI_BUS_RESOURCE_MEM_PREF], SZ_1M);
> -		pr_debug("bridge P limit at %pa\n", &last[PCI_BUS_RESOURCE_MEM_PREF]);
> -		pci_set_limit(dev, PCI_BUS_RESOURCE_MEM_PREF,
> -			      last[PCI_BUS_RESOURCE_MEM_PREF] - 1);
> -	}
> -
> -	if (last[PCI_BUS_RESOURCE_IO]) {
> -		last[PCI_BUS_RESOURCE_IO] = ALIGN(last[PCI_BUS_RESOURCE_IO], SZ_4K);
> -		pr_debug("bridge IO limit at %pa\n", &last[PCI_BUS_RESOURCE_IO]);
> -		pci_set_limit(dev, PCI_BUS_RESOURCE_IO,
> -			      last[PCI_BUS_RESOURCE_IO] - 1);
> +	for (r = PCI_BUS_RESOURCE_IO; r <= PCI_BUS_RESOURCE_MEM_PREF; r++) {
> +		if (last[r]) {
> +			last[r] = ALIGN(last[r], pci_resource_to_alignment(r));
> +			pci_set_limit(dev, r, last[r] - 1);
> +		}

Indeed postscan_setup_bridge() gets simpler, but the code as a whole doesn't
get easier to read. Yes, the commonalities are merged into this loop, but
with the price of having to dispatch the differences in a switch/case
later. This often works but here I don't think this is an improvement.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH 05/21] PCI: Convert postscan_setup_bridge() to use a loop
  2019-01-10 10:09   ` Sascha Hauer
@ 2019-01-10 19:16     ` Andrey Smirnov
  2019-01-11 10:47       ` Sascha Hauer
  0 siblings, 1 reply; 26+ messages in thread
From: Andrey Smirnov @ 2019-01-10 19:16 UTC (permalink / raw)
  To: Sascha Hauer; +Cc: Barebox List

On Thu, Jan 10, 2019 at 2:09 AM Sascha Hauer <s.hauer@pengutronix.de> wrote:
>
> Hi Andrey,
>
> On Wed, Jan 09, 2019 at 08:57:23PM -0800, Andrey Smirnov wrote:
> > Simplify postscan_setup_bridge() by folding limit setting code into a
> > loop. No functional change intended.
> >
> > Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
> > ---
> >  drivers/pci/pci.c | 26 +++++++-------------------
> >  1 file changed, 7 insertions(+), 19 deletions(-)
> >
> > diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
> > index 02b7f091f7..b5e13e5dbc 100644
> > --- a/drivers/pci/pci.c
> > +++ b/drivers/pci/pci.c
> > @@ -330,28 +330,16 @@ static void prescan_setup_bridge(struct pci_dev *dev)
> >
> >  static void postscan_setup_bridge(struct pci_dev *dev)
> >  {
> > +     int r;
> > +
> >       /* limit subordinate to last used bus number */
> >       pci_write_config_byte(dev, PCI_SUBORDINATE_BUS, last[PCI_BUS_RESOURCE_BUSN] - 1);
> >
> > -     if (last[PCI_BUS_RESOURCE_MEM]) {
> > -             last[PCI_BUS_RESOURCE_MEM] = ALIGN(last[PCI_BUS_RESOURCE_MEM], SZ_1M);
> > -             pr_debug("bridge NP limit at %pa\n", &last[PCI_BUS_RESOURCE_MEM]);
> > -             pci_set_limit(dev, PCI_BUS_RESOURCE_MEM,
> > -                           last[PCI_BUS_RESOURCE_MEM] - 1);
> > -     }
> > -
> > -     if (last[PCI_BUS_RESOURCE_MEM_PREF]) {
> > -             last[PCI_BUS_RESOURCE_MEM_PREF] = ALIGN(last[PCI_BUS_RESOURCE_MEM_PREF], SZ_1M);
> > -             pr_debug("bridge P limit at %pa\n", &last[PCI_BUS_RESOURCE_MEM_PREF]);
> > -             pci_set_limit(dev, PCI_BUS_RESOURCE_MEM_PREF,
> > -                           last[PCI_BUS_RESOURCE_MEM_PREF] - 1);
> > -     }
> > -
> > -     if (last[PCI_BUS_RESOURCE_IO]) {
> > -             last[PCI_BUS_RESOURCE_IO] = ALIGN(last[PCI_BUS_RESOURCE_IO], SZ_4K);
> > -             pr_debug("bridge IO limit at %pa\n", &last[PCI_BUS_RESOURCE_IO]);
> > -             pci_set_limit(dev, PCI_BUS_RESOURCE_IO,
> > -                           last[PCI_BUS_RESOURCE_IO] - 1);
> > +     for (r = PCI_BUS_RESOURCE_IO; r <= PCI_BUS_RESOURCE_MEM_PREF; r++) {
> > +             if (last[r]) {
> > +                     last[r] = ALIGN(last[r], pci_resource_to_alignment(r));
> > +                     pci_set_limit(dev, r, last[r] - 1);
> > +             }
>
> Indeed postscan_setup_bridge() gets simpler, but the code as a whole doesn't
> get easier to read. Yes, the commonalities are merged into this loop, but
> with the price of having to dispatch the differences in a switch/case
> later. This often works but here I don't think this is an improvement.
>

I am confused, is this a comment for this specific patch or more than
that, since you mention a switch statement? Can you drop:

PCI: Convert postscan_setup_bridge() to use a loop
PCI: Convert prescan_setup_bridge() to use a loop
PCI: Consolidate limit/base settting code

and apply the rest?

Thanks,
Andrey Smirnov

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH 05/21] PCI: Convert postscan_setup_bridge() to use a loop
  2019-01-10 19:16     ` Andrey Smirnov
@ 2019-01-11 10:47       ` Sascha Hauer
  2019-01-12  2:34         ` Andrey Smirnov
  0 siblings, 1 reply; 26+ messages in thread
From: Sascha Hauer @ 2019-01-11 10:47 UTC (permalink / raw)
  To: Andrey Smirnov; +Cc: Barebox List

On Thu, Jan 10, 2019 at 11:16:07AM -0800, Andrey Smirnov wrote:
> On Thu, Jan 10, 2019 at 2:09 AM Sascha Hauer <s.hauer@pengutronix.de> wrote:
> >
> > Hi Andrey,
> >
> > with the price of having to dispatch the differences in a switch/case
> > later. This often works but here I don't think this is an improvement.
> >
> 
> I am confused, is this a comment for this specific patch or more than
> that, since you mention a switch statement? Can you drop:

The comment was specific to these patches:
> 
> PCI: Convert postscan_setup_bridge() to use a loop
> PCI: Convert prescan_setup_bridge() to use a loop
> PCI: Consolidate limit/base settting code

and this one:

PCI: Replace last_* variables with an array

> 
> and apply the rest?

I tried, it didn't apply. Could you respin the remaining patches?

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH 05/21] PCI: Convert postscan_setup_bridge() to use a loop
  2019-01-11 10:47       ` Sascha Hauer
@ 2019-01-12  2:34         ` Andrey Smirnov
  0 siblings, 0 replies; 26+ messages in thread
From: Andrey Smirnov @ 2019-01-12  2:34 UTC (permalink / raw)
  To: Sascha Hauer; +Cc: Barebox List

On Fri, Jan 11, 2019 at 2:47 AM Sascha Hauer <s.hauer@pengutronix.de> wrote:
>
> On Thu, Jan 10, 2019 at 11:16:07AM -0800, Andrey Smirnov wrote:
> > On Thu, Jan 10, 2019 at 2:09 AM Sascha Hauer <s.hauer@pengutronix.de> wrote:
> > >
> > > Hi Andrey,
> > >
> > > with the price of having to dispatch the differences in a switch/case
> > > later. This often works but here I don't think this is an improvement.
> > >
> >
> > I am confused, is this a comment for this specific patch or more than
> > that, since you mention a switch statement? Can you drop:
>
> The comment was specific to these patches:
> >
> > PCI: Convert postscan_setup_bridge() to use a loop
> > PCI: Convert prescan_setup_bridge() to use a loop
> > PCI: Consolidate limit/base settting code
>
> and this one:
>
> PCI: Replace last_* variables with an array
>
> >
> > and apply the rest?
>
> I tried, it didn't apply.

Yeah, dropping "PCI: Replace last_* variables with an array" will
require some rework.

>Could you respin the remaining patches?

Sure, will do in v2.

Thanks,
Andrey Smirnov

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 26+ messages in thread

end of thread, other threads:[~2019-01-12  2:34 UTC | newest]

Thread overview: 26+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-10  4:57 [PATCH 00/21] PCI improvements Andrey Smirnov
2019-01-10  4:57 ` [PATCH 01/21] PCI: Switch to using %pa to print memory addresses Andrey Smirnov
2019-01-10  4:57 ` [PATCH 02/21] PCI: Replace last_* variables with an array Andrey Smirnov
2019-01-10  4:57 ` [PATCH 03/21] PCI: Consolidate limit/base settting code Andrey Smirnov
2019-01-10  4:57 ` [PATCH 04/21] PCI: Convert prescan_setup_bridge() to use a loop Andrey Smirnov
2019-01-10  4:57 ` [PATCH 05/21] PCI: Convert postscan_setup_bridge() " Andrey Smirnov
2019-01-10 10:09   ` Sascha Hauer
2019-01-10 19:16     ` Andrey Smirnov
2019-01-11 10:47       ` Sascha Hauer
2019-01-12  2:34         ` Andrey Smirnov
2019-01-10  4:57 ` [PATCH 06/21] PCI: Replace magic number in setup_device() Andrey Smirnov
2019-01-10  4:57 ` [PATCH 07/21] PCI: Remove superfluous parens " Andrey Smirnov
2019-01-10  4:57 ` [PATCH 08/21] PCI: Simplify resource setup code " Andrey Smirnov
2019-01-10  4:57 ` [PATCH 09/21] PCI: Store and reuse BAR offsets Andrey Smirnov
2019-01-10  4:57 ` [PATCH 10/21] PCI: Conver register_pci_controller() to use a loop Andrey Smirnov
2019-01-10  4:57 ` [PATCH 11/21] PCI: Remove unused variables/code Andrey Smirnov
2019-01-10  4:57 ` [PATCH 12/21] PCI: Make pci_scan_bus static Andrey Smirnov
2019-01-10  4:57 ` [PATCH 13/21] PCI: Drop "slots" from struct pci_bus Andrey Smirnov
2019-01-10  4:57 ` [PATCH 14/21] PCI: Drop "resources" " Andrey Smirnov
2019-01-10  4:57 ` [PATCH 15/21] PCI: Drop "name" " Andrey Smirnov
2019-01-10  4:57 ` [PATCH 16/21] PCI: Drop "ops" " Andrey Smirnov
2019-01-10  4:57 ` [PATCH 17/21] PCI: Drop "rom_address" from struct pci_dev Andrey Smirnov
2019-01-10  4:57 ` [PATCH 18/21] PCI: Simplify alloc_pci_dev() Andrey Smirnov
2019-01-10  4:57 ` [PATCH 19/21] PCI: Assume 1:1 mapping if .res_start callback is NULL Andrey Smirnov
2019-01-10  4:57 ` [PATCH 20/21] PCI: Convert ->res_start() to return resource_size_t Andrey Smirnov
2019-01-10  4:57 ` [PATCH 21/21] PCI: Consify pci_ops in struct pci_controller Andrey Smirnov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox