All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 00/16] PCI improvements
@ 2019-01-12  7:22 Andrey Smirnov
  2019-01-12  7:22 ` [PATCH v2 01/16] PCI: Switch to using %pa to print memory addresses Andrey Smirnov
                   ` (16 more replies)
  0 siblings, 17 replies; 24+ messages in thread
From: Andrey Smirnov @ 2019-01-12  7:22 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!

Changes since [v1]:

  - Dropped all of the rejected patches

Thanks,
Andrey Smirnov

[v1] http://lists.infradead.org/pipermail/barebox/2019-January/036355.html

Andrey Smirnov (16):
  PCI: Switch to using %pa to print memory addresses
  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: 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                  | 155 +++++++++++------------------
 drivers/pci/pci_iomap.c            |   6 +-
 drivers/pci/pcie-designware-host.c |  10 +-
 include/linux/pci.h                |  12 +--
 7 files changed, 77 insertions(+), 125 deletions(-)

-- 
2.20.1


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

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

* [PATCH v2 01/16] PCI: Switch to using %pa to print memory addresses
  2019-01-12  7:22 [PATCH v2 00/16] PCI improvements Andrey Smirnov
@ 2019-01-12  7:22 ` Andrey Smirnov
  2019-01-12  7:22 ` [PATCH v2 02/16] PCI: Replace magic number in setup_device() Andrey Smirnov
                   ` (15 subsequent siblings)
  16 siblings, 0 replies; 24+ messages in thread
From: Andrey Smirnov @ 2019-01-12  7:22 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 related	[flat|nested] 24+ messages in thread

* [PATCH v2 02/16] PCI: Replace magic number in setup_device()
  2019-01-12  7:22 [PATCH v2 00/16] PCI improvements Andrey Smirnov
  2019-01-12  7:22 ` [PATCH v2 01/16] PCI: Switch to using %pa to print memory addresses Andrey Smirnov
@ 2019-01-12  7:22 ` Andrey Smirnov
  2019-01-12  7:22 ` [PATCH v2 03/16] PCI: Remove superfluous parens " Andrey Smirnov
                   ` (14 subsequent siblings)
  16 siblings, 0 replies; 24+ messages in thread
From: Andrey Smirnov @ 2019-01-12  7:22 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 1f9d360d79..5e67750c39 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -182,7 +182,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 related	[flat|nested] 24+ messages in thread

* [PATCH v2 03/16] PCI: Remove superfluous parens in setup_device()
  2019-01-12  7:22 [PATCH v2 00/16] PCI improvements Andrey Smirnov
  2019-01-12  7:22 ` [PATCH v2 01/16] PCI: Switch to using %pa to print memory addresses Andrey Smirnov
  2019-01-12  7:22 ` [PATCH v2 02/16] PCI: Replace magic number in setup_device() Andrey Smirnov
@ 2019-01-12  7:22 ` Andrey Smirnov
  2019-01-12  7:22 ` [PATCH v2 04/16] PCI: Simplify resource setup code " Andrey Smirnov
                   ` (13 subsequent siblings)
  16 siblings, 0 replies; 24+ messages in thread
From: Andrey Smirnov @ 2019-01-12  7:22 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 5e67750c39..b8089207a4 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -245,7 +245,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 related	[flat|nested] 24+ messages in thread

* [PATCH v2 04/16] PCI: Simplify resource setup code in setup_device()
  2019-01-12  7:22 [PATCH v2 00/16] PCI improvements Andrey Smirnov
                   ` (2 preceding siblings ...)
  2019-01-12  7:22 ` [PATCH v2 03/16] PCI: Remove superfluous parens " Andrey Smirnov
@ 2019-01-12  7:22 ` Andrey Smirnov
  2019-01-12 11:00   ` Sam Ravnborg
  2019-01-12 11:01   ` Sam Ravnborg
  2019-01-12  7:22 ` [PATCH v2 05/16] PCI: Store and reuse BAR offsets Andrey Smirnov
                   ` (12 subsequent siblings)
  16 siblings, 2 replies; 24+ messages in thread
From: Andrey Smirnov @ 2019-01-12  7:22 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 | 99 ++++++++++++++++++++---------------------------
 1 file changed, 42 insertions(+), 57 deletions(-)

diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index b8089207a4..666b457257 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -169,8 +169,11 @@ 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;
+		resource_size_t *last;
 		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);
@@ -183,67 +186,49 @@ 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_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);
-			dev->resource[bar].flags = IORESOURCE_IO;
-			last_addr = last_io;
-			last_io += size;
+			size  = pci_size(orig, mask, 0xfffffffe);
+			flags = IORESOURCE_IO;
+			kind  = "IO";
+			last  = &last_io;
+			r     = PCI_BUS_RESOURCE_IO;
 		} else if ((mask & PCI_BASE_ADDRESS_MEM_PREFETCH) &&
 		           last_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_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);
-			dev->resource[bar].flags = IORESOURCE_MEM |
-			                           IORESOURCE_PREFETCH;
-			last_addr = last_mem_pref;
-			last_mem_pref += size;
+			size  = pci_size(orig, mask, 0xfffffff0);
+			flags = IORESOURCE_MEM | IORESOURCE_PREFETCH;
+			kind  = "P-MEM";
+			last  = &last_mem_pref;
+			r     = PCI_BUS_RESOURCE_MEM_PREF;
 		} 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_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);
-			dev->resource[bar].flags = IORESOURCE_MEM;
-			last_addr = last_mem;
-			last_mem += size;
+			size  = pci_size(orig, mask, 0xfffffff0);
+			flags = IORESOURCE_MEM;
+			kind  = "NP-MEM";
+			last  = &last_mem;
+			r     = PCI_BUS_RESOURCE_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, size) + size > dev->bus->resource[r]->end) {
+			pr_debug("BAR does not fit within bus %s res\n", kind);
+			return;
+		}
+
+		*last = ALIGN(*last, size);
+		pci_write_config_dword(dev, PCI_BASE_ADDRESS_0 + bar * 4,
+				       *last);
+		dev->resource[bar].flags = flags;
+		dev->resource[bar].start = *last;
+		dev->resource[bar].end = dev->resource[bar].start + size - 1;
+
+		pr_debug("pbar%d: allocated at %pa\n", bar, last);
+
+		*last += 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 related	[flat|nested] 24+ messages in thread

* [PATCH v2 05/16] PCI: Store and reuse BAR offsets
  2019-01-12  7:22 [PATCH v2 00/16] PCI improvements Andrey Smirnov
                   ` (3 preceding siblings ...)
  2019-01-12  7:22 ` [PATCH v2 04/16] PCI: Simplify resource setup code " Andrey Smirnov
@ 2019-01-12  7:22 ` Andrey Smirnov
  2019-01-12  7:22 ` [PATCH v2 06/16] PCI: Remove unused variables/code Andrey Smirnov
                   ` (11 subsequent siblings)
  16 siblings, 0 replies; 24+ messages in thread
From: Andrey Smirnov @ 2019-01-12  7:22 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 666b457257..ee8afa7e87 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -169,16 +169,18 @@ 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;
 		resource_size_t *last;
 		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);
@@ -220,8 +222,7 @@ static void setup_device(struct pci_dev *dev, int max_bar)
 		}
 
 		*last = ALIGN(*last, size);
-		pci_write_config_dword(dev, PCI_BASE_ADDRESS_0 + bar * 4,
-				       *last);
+		pci_write_config_dword(dev, pci_base_address_0, *last);
 		dev->resource[bar].flags = flags;
 		dev->resource[bar].start = *last;
 		dev->resource[bar].end = dev->resource[bar].start + size - 1;
@@ -232,8 +233,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 related	[flat|nested] 24+ messages in thread

* [PATCH v2 06/16] PCI: Remove unused variables/code
  2019-01-12  7:22 [PATCH v2 00/16] PCI improvements Andrey Smirnov
                   ` (4 preceding siblings ...)
  2019-01-12  7:22 ` [PATCH v2 05/16] PCI: Store and reuse BAR offsets Andrey Smirnov
@ 2019-01-12  7:22 ` Andrey Smirnov
  2019-01-12  7:22 ` [PATCH v2 07/16] PCI: Make pci_scan_bus static Andrey Smirnov
                   ` (10 subsequent siblings)
  16 siblings, 0 replies; 24+ messages in thread
From: Andrey Smirnov @ 2019-01-12  7:22 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 ee8afa7e87..198ec9e995 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 u8 bus_index;
@@ -46,9 +44,6 @@ void register_pci_controller(struct pci_controller *hose)
 {
 	struct pci_bus *bus;
 
-	*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 related	[flat|nested] 24+ messages in thread

* [PATCH v2 07/16] PCI: Make pci_scan_bus static
  2019-01-12  7:22 [PATCH v2 00/16] PCI improvements Andrey Smirnov
                   ` (5 preceding siblings ...)
  2019-01-12  7:22 ` [PATCH v2 06/16] PCI: Remove unused variables/code Andrey Smirnov
@ 2019-01-12  7:22 ` Andrey Smirnov
  2019-01-12 11:04   ` Sam Ravnborg
  2019-01-12  7:22 ` [PATCH v2 08/16] PCI: Drop "slots" from struct pci_bus Andrey Smirnov
                   ` (9 subsequent siblings)
  16 siblings, 1 reply; 24+ messages in thread
From: Andrey Smirnov @ 2019-01-12  7:22 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 198ec9e995..b0f5ac1b15 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 u8 bus_index;
@@ -338,7 +340,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 related	[flat|nested] 24+ messages in thread

* [PATCH v2 08/16] PCI: Drop "slots" from struct pci_bus
  2019-01-12  7:22 [PATCH v2 00/16] PCI improvements Andrey Smirnov
                   ` (6 preceding siblings ...)
  2019-01-12  7:22 ` [PATCH v2 07/16] PCI: Make pci_scan_bus static Andrey Smirnov
@ 2019-01-12  7:22 ` Andrey Smirnov
  2019-01-12  7:22 ` [PATCH v2 09/16] PCI: Drop "resources" " Andrey Smirnov
                   ` (8 subsequent siblings)
  16 siblings, 0 replies; 24+ messages in thread
From: Andrey Smirnov @ 2019-01-12  7:22 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 b0f5ac1b15..683f4e5540 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -22,7 +22,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 related	[flat|nested] 24+ messages in thread

* [PATCH v2 09/16] PCI: Drop "resources" from struct pci_bus
  2019-01-12  7:22 [PATCH v2 00/16] PCI improvements Andrey Smirnov
                   ` (7 preceding siblings ...)
  2019-01-12  7:22 ` [PATCH v2 08/16] PCI: Drop "slots" from struct pci_bus Andrey Smirnov
@ 2019-01-12  7:22 ` Andrey Smirnov
  2019-01-12  7:22 ` [PATCH v2 10/16] PCI: Drop "name" " Andrey Smirnov
                   ` (7 subsequent siblings)
  16 siblings, 0 replies; 24+ messages in thread
From: Andrey Smirnov @ 2019-01-12  7:22 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 683f4e5540..0c5a22fd59 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -22,7 +22,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 related	[flat|nested] 24+ messages in thread

* [PATCH v2 10/16] PCI: Drop "name" from struct pci_bus
  2019-01-12  7:22 [PATCH v2 00/16] PCI improvements Andrey Smirnov
                   ` (8 preceding siblings ...)
  2019-01-12  7:22 ` [PATCH v2 09/16] PCI: Drop "resources" " Andrey Smirnov
@ 2019-01-12  7:22 ` Andrey Smirnov
  2019-01-12  7:22 ` [PATCH v2 11/16] PCI: Drop "ops" " Andrey Smirnov
                   ` (6 subsequent siblings)
  16 siblings, 0 replies; 24+ messages in thread
From: Andrey Smirnov @ 2019-01-12  7:22 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 related	[flat|nested] 24+ messages in thread

* [PATCH v2 11/16] PCI: Drop "ops" from struct pci_bus
  2019-01-12  7:22 [PATCH v2 00/16] PCI improvements Andrey Smirnov
                   ` (9 preceding siblings ...)
  2019-01-12  7:22 ` [PATCH v2 10/16] PCI: Drop "name" " Andrey Smirnov
@ 2019-01-12  7:22 ` Andrey Smirnov
  2019-01-12  7:22 ` [PATCH v2 12/16] PCI: Drop "rom_address" from struct pci_dev Andrey Smirnov
                   ` (5 subsequent siblings)
  16 siblings, 0 replies; 24+ messages in thread
From: Andrey Smirnov @ 2019-01-12  7:22 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 0c5a22fd59..a94864b0c6 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -48,7 +48,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;
@@ -97,7 +96,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;							\
 }
@@ -108,7 +107,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;							\
 }
 
@@ -420,7 +419,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 related	[flat|nested] 24+ messages in thread

* [PATCH v2 12/16] PCI: Drop "rom_address" from struct pci_dev
  2019-01-12  7:22 [PATCH v2 00/16] PCI improvements Andrey Smirnov
                   ` (10 preceding siblings ...)
  2019-01-12  7:22 ` [PATCH v2 11/16] PCI: Drop "ops" " Andrey Smirnov
@ 2019-01-12  7:22 ` Andrey Smirnov
  2019-01-12  7:22 ` [PATCH v2 13/16] PCI: Simplify alloc_pci_dev() Andrey Smirnov
                   ` (4 subsequent siblings)
  16 siblings, 0 replies; 24+ messages in thread
From: Andrey Smirnov @ 2019-01-12  7:22 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 a94864b0c6..10890d07eb 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -406,13 +406,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 related	[flat|nested] 24+ messages in thread

* [PATCH v2 13/16] PCI: Simplify alloc_pci_dev()
  2019-01-12  7:22 [PATCH v2 00/16] PCI improvements Andrey Smirnov
                   ` (11 preceding siblings ...)
  2019-01-12  7:22 ` [PATCH v2 12/16] PCI: Drop "rom_address" from struct pci_dev Andrey Smirnov
@ 2019-01-12  7:22 ` Andrey Smirnov
  2019-01-12  7:22 ` [PATCH v2 14/16] PCI: Assume 1:1 mapping if .res_start callback is NULL Andrey Smirnov
                   ` (3 subsequent siblings)
  16 siblings, 0 replies; 24+ messages in thread
From: Andrey Smirnov @ 2019-01-12  7:22 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 10890d07eb..64fcb7aea7 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -129,10 +129,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;
@@ -366,9 +363,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 related	[flat|nested] 24+ messages in thread

* [PATCH v2 14/16] PCI: Assume 1:1 mapping if .res_start callback is NULL
  2019-01-12  7:22 [PATCH v2 00/16] PCI improvements Andrey Smirnov
                   ` (12 preceding siblings ...)
  2019-01-12  7:22 ` [PATCH v2 13/16] PCI: Simplify alloc_pci_dev() Andrey Smirnov
@ 2019-01-12  7:22 ` Andrey Smirnov
  2019-01-12  7:22 ` [PATCH v2 15/16] PCI: Convert ->res_start() to return resource_size_t Andrey Smirnov
                   ` (2 subsequent siblings)
  16 siblings, 0 replies; 24+ messages in thread
From: Andrey Smirnov @ 2019-01-12  7:22 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 related	[flat|nested] 24+ messages in thread

* [PATCH v2 15/16] PCI: Convert ->res_start() to return resource_size_t
  2019-01-12  7:22 [PATCH v2 00/16] PCI improvements Andrey Smirnov
                   ` (13 preceding siblings ...)
  2019-01-12  7:22 ` [PATCH v2 14/16] PCI: Assume 1:1 mapping if .res_start callback is NULL Andrey Smirnov
@ 2019-01-12  7:22 ` Andrey Smirnov
  2019-01-12  7:22 ` [PATCH v2 16/16] PCI: Consify pci_ops in struct pci_controller Andrey Smirnov
  2019-01-12 11:07 ` [PATCH v2 00/16] PCI improvements Sam Ravnborg
  16 siblings, 0 replies; 24+ messages in thread
From: Andrey Smirnov @ 2019-01-12  7:22 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 related	[flat|nested] 24+ messages in thread

* [PATCH v2 16/16] PCI: Consify pci_ops in struct pci_controller
  2019-01-12  7:22 [PATCH v2 00/16] PCI improvements Andrey Smirnov
                   ` (14 preceding siblings ...)
  2019-01-12  7:22 ` [PATCH v2 15/16] PCI: Convert ->res_start() to return resource_size_t Andrey Smirnov
@ 2019-01-12  7:22 ` Andrey Smirnov
  2019-01-12 11:07 ` [PATCH v2 00/16] PCI improvements Sam Ravnborg
  16 siblings, 0 replies; 24+ messages in thread
From: Andrey Smirnov @ 2019-01-12  7:22 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 related	[flat|nested] 24+ messages in thread

* Re: [PATCH v2 04/16] PCI: Simplify resource setup code in setup_device()
  2019-01-12  7:22 ` [PATCH v2 04/16] PCI: Simplify resource setup code " Andrey Smirnov
@ 2019-01-12 11:00   ` Sam Ravnborg
  2019-01-12 20:49     ` Andrey Smirnov
  2019-01-12 11:01   ` Sam Ravnborg
  1 sibling, 1 reply; 24+ messages in thread
From: Sam Ravnborg @ 2019-01-12 11:00 UTC (permalink / raw)
  To: Andrey Smirnov; +Cc: barebox

Hi Andrey.

> ---
>  drivers/pci/pci.c | 99 ++++++++++++++++++++---------------------------
>  1 file changed, 42 insertions(+), 57 deletions(-)
> 
> diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
> index b8089207a4..666b457257 100644
> --- a/drivers/pci/pci.c
> +++ b/drivers/pci/pci.c
> @@ -169,8 +169,11 @@ 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;
> +		resource_size_t *last;
>  		u32 orig, mask, size;
> +		unsigned long flags;
> +		const char *kind;
> +		int r;
A more descriptine name than "r" would maybe improve readability.

> @@ -183,67 +186,49 @@ static void setup_device(struct pci_dev *dev, int max_bar)
>  		if (mask & PCI_BASE_ADDRESS_SPACE_IO) { /* IO */
> -			last_io = ALIGN(last_io, size);
> -			last_addr = last_io;
>  		} else if ((mask & PCI_BASE_ADDRESS_MEM_PREFETCH) &&
>  		           last_mem_pref) /* prefetchable MEM */ {
> -			last_mem_pref = ALIGN(last_mem_pref, size);
> -			                           IORESOURCE_PREFETCH;
> -			last_addr = last_mem_pref;
>  		} else { /* non-prefetch MEM */
> -			last_mem = ALIGN(last_mem, size);
> -			last_addr = last_mem;
>  		}
>  
> -		dev->resource[bar].end = last_addr + size - 1;
> +		dev->resource[bar].start = *last;
> +		dev->resource[bar].end = dev->resource[bar].start + size - 1;
> +
> +		pr_debug("pbar%d: allocated at %pa\n", bar, last);
> +
> +		*last += size;

I could not see that dev->resource[bar].end was assigned the
same value with the new code.
Maybe I just missed it because I did not follow *last?

I think it is worth to double check it.

	Sam

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

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

* Re: [PATCH v2 04/16] PCI: Simplify resource setup code in setup_device()
  2019-01-12  7:22 ` [PATCH v2 04/16] PCI: Simplify resource setup code " Andrey Smirnov
  2019-01-12 11:00   ` Sam Ravnborg
@ 2019-01-12 11:01   ` Sam Ravnborg
  1 sibling, 0 replies; 24+ messages in thread
From: Sam Ravnborg @ 2019-01-12 11:01 UTC (permalink / raw)
  To: Andrey Smirnov; +Cc: barebox

Hi Andrey.

Forgot to say in my previous mail that the simplification looks
good - the new code looks much simpler.

	Sam


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

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

* Re: [PATCH v2 07/16] PCI: Make pci_scan_bus static
  2019-01-12  7:22 ` [PATCH v2 07/16] PCI: Make pci_scan_bus static Andrey Smirnov
@ 2019-01-12 11:04   ` Sam Ravnborg
  2019-01-12 19:52     ` Andrey Smirnov
  0 siblings, 1 reply; 24+ messages in thread
From: Sam Ravnborg @ 2019-01-12 11:04 UTC (permalink / raw)
  To: Andrey Smirnov; +Cc: barebox

On Fri, Jan 11, 2019 at 11:22:25PM -0800, Andrey Smirnov wrote:
> 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 198ec9e995..b0f5ac1b15 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);

Move function to avoid this forward?

	Sam

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

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

* Re: [PATCH v2 00/16] PCI improvements
  2019-01-12  7:22 [PATCH v2 00/16] PCI improvements Andrey Smirnov
                   ` (15 preceding siblings ...)
  2019-01-12  7:22 ` [PATCH v2 16/16] PCI: Consify pci_ops in struct pci_controller Andrey Smirnov
@ 2019-01-12 11:07 ` Sam Ravnborg
  16 siblings, 0 replies; 24+ messages in thread
From: Sam Ravnborg @ 2019-01-12 11:07 UTC (permalink / raw)
  To: Andrey Smirnov; +Cc: barebox

Hi Andrey.

> Hopefully all of the patches are self-explanatory.
Everything looks good (to me) except one patch where I could
not follow the conversion.

	Sam

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

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

* Re: [PATCH v2 07/16] PCI: Make pci_scan_bus static
  2019-01-12 11:04   ` Sam Ravnborg
@ 2019-01-12 19:52     ` Andrey Smirnov
  0 siblings, 0 replies; 24+ messages in thread
From: Andrey Smirnov @ 2019-01-12 19:52 UTC (permalink / raw)
  To: Sam Ravnborg; +Cc: Barebox List

On Sat, Jan 12, 2019 at 3:04 AM Sam Ravnborg <sam@ravnborg.org> wrote:
>
> On Fri, Jan 11, 2019 at 11:22:25PM -0800, Andrey Smirnov wrote:
> > 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 198ec9e995..b0f5ac1b15 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);
>
> Move function to avoid this forward?
>

I'd rather keep the diff to a minimum, I'll leave it up to Sascha if
he wants to do what you suggest instead.

Thanks,
Andrey Smirnov

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

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

* Re: [PATCH v2 04/16] PCI: Simplify resource setup code in setup_device()
  2019-01-12 11:00   ` Sam Ravnborg
@ 2019-01-12 20:49     ` Andrey Smirnov
  2019-01-12 21:35       ` Sam Ravnborg
  0 siblings, 1 reply; 24+ messages in thread
From: Andrey Smirnov @ 2019-01-12 20:49 UTC (permalink / raw)
  To: Sam Ravnborg; +Cc: Barebox List

On Sat, Jan 12, 2019 at 3:00 AM Sam Ravnborg <sam@ravnborg.org> wrote:
>
> Hi Andrey.
>
> > ---
> >  drivers/pci/pci.c | 99 ++++++++++++++++++++---------------------------
> >  1 file changed, 42 insertions(+), 57 deletions(-)
> >
> > diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
> > index b8089207a4..666b457257 100644
> > --- a/drivers/pci/pci.c
> > +++ b/drivers/pci/pci.c
> > @@ -169,8 +169,11 @@ 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;
> > +             resource_size_t *last;
> >               u32 orig, mask, size;
> > +             unsigned long flags;
> > +             const char *kind;
> > +             int r;
> A more descriptine name than "r" would maybe improve readability.
>

It's just an index of an array, so single letter name seemed
reasonable. However, if you give me concrete suggestions, I am more
than happy to change it.

> > @@ -183,67 +186,49 @@ static void setup_device(struct pci_dev *dev, int max_bar)
> >               if (mask & PCI_BASE_ADDRESS_SPACE_IO) { /* IO */
> > -                     last_io = ALIGN(last_io, size);
> > -                     last_addr = last_io;
> >               } else if ((mask & PCI_BASE_ADDRESS_MEM_PREFETCH) &&
> >                          last_mem_pref) /* prefetchable MEM */ {
> > -                     last_mem_pref = ALIGN(last_mem_pref, size);
> > -                                                IORESOURCE_PREFETCH;
> > -                     last_addr = last_mem_pref;
> >               } else { /* non-prefetch MEM */
> > -                     last_mem = ALIGN(last_mem, size);
> > -                     last_addr = last_mem;
> >               }
> >

You omitted

-               dev->resource[bar].start = last_addr;

here, which would make things a bit more clear since it make easier to
see that "dev->resource[bar].start" and "last_addr" are
interchangeable.

> > -             dev->resource[bar].end = last_addr + size - 1;
> > +             dev->resource[bar].start = *last;
> > +             dev->resource[bar].end = dev->resource[bar].start + size - 1;
> > +
> > +             pr_debug("pbar%d: allocated at %pa\n", bar, last);
> > +
> > +             *last += size;
>
> I could not see that dev->resource[bar].end was assigned the
> same value with the new code.
> Maybe I just missed it because I did not follow *last?
>

Yes, "*last" should have the same value as "last_addr" (I probably
should've kept the name). Also

dev->resource[bar].end = dev->resource[bar].start + size - 1;

should always be true, just by definition, so as long as
dev->resource[bar].start is the same (and it is) the value of .end
should be OK.

> I think it is worth to double check it.
>

I did compare debug outputs before/after when I was writing the patch,
and AFAICT they matched.

Thanks,
Andrey Smirnov

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

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

* Re: [PATCH v2 04/16] PCI: Simplify resource setup code in setup_device()
  2019-01-12 20:49     ` Andrey Smirnov
@ 2019-01-12 21:35       ` Sam Ravnborg
  0 siblings, 0 replies; 24+ messages in thread
From: Sam Ravnborg @ 2019-01-12 21:35 UTC (permalink / raw)
  To: Andrey Smirnov; +Cc: Barebox List

Hi Andrey.

On Sat, Jan 12, 2019 at 12:49:17PM -0800, Andrey Smirnov wrote:
> On Sat, Jan 12, 2019 at 3:00 AM Sam Ravnborg <sam@ravnborg.org> wrote:
> >
> > Hi Andrey.
> >
> > > ---
> > >  drivers/pci/pci.c | 99 ++++++++++++++++++++---------------------------
> > >  1 file changed, 42 insertions(+), 57 deletions(-)
> > >
> > > diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
> > > index b8089207a4..666b457257 100644
> > > --- a/drivers/pci/pci.c
> > > +++ b/drivers/pci/pci.c
> > > @@ -169,8 +169,11 @@ 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;
> > > +             resource_size_t *last;
> > >               u32 orig, mask, size;
> > > +             unsigned long flags;
> > > +             const char *kind;
> > > +             int r;
> > A more descriptine name than "r" would maybe improve readability.
> >
> 
> It's just an index of an array, so single letter name seemed
> reasonable. However, if you give me concrete suggestions, I am more
> than happy to change it.
busres - is this is the type of bus resource we deal with?

> 
> > > @@ -183,67 +186,49 @@ static void setup_device(struct pci_dev *dev, int max_bar)
> > >               if (mask & PCI_BASE_ADDRESS_SPACE_IO) { /* IO */
> > > -                     last_io = ALIGN(last_io, size);
> > > -                     last_addr = last_io;
> > >               } else if ((mask & PCI_BASE_ADDRESS_MEM_PREFETCH) &&
> > >                          last_mem_pref) /* prefetchable MEM */ {
> > > -                     last_mem_pref = ALIGN(last_mem_pref, size);
> > > -                                                IORESOURCE_PREFETCH;
> > > -                     last_addr = last_mem_pref;
> > >               } else { /* non-prefetch MEM */
> > > -                     last_mem = ALIGN(last_mem, size);
> > > -                     last_addr = last_mem;
> > >               }
> > >
> 
> You omitted
> 
> -               dev->resource[bar].start = last_addr;
> 
> here, which would make things a bit more clear since it make easier to
> see that "dev->resource[bar].start" and "last_addr" are
> interchangeable.

Missed that - thanks.

> 
> > > -             dev->resource[bar].end = last_addr + size - 1;
> > > +             dev->resource[bar].start = *last;
> > > +             dev->resource[bar].end = dev->resource[bar].start + size - 1;
> > > +
> > > +             pr_debug("pbar%d: allocated at %pa\n", bar, last);
> > > +
> > > +             *last += size;
> >
> > I could not see that dev->resource[bar].end was assigned the
> > same value with the new code.
> > Maybe I just missed it because I did not follow *last?
> >
> 
> Yes, "*last" should have the same value as "last_addr" (I probably
> should've kept the name). Also
> 
> dev->resource[bar].end = dev->resource[bar].start + size - 1;
> 
> should always be true, just by definition, so as long as
> dev->resource[bar].start is the same (and it is) the value of .end
> should be OK.
> 
> > I think it is worth to double check it.
> >
> 
> I did compare debug outputs before/after when I was writing the patch,
> and AFAICT they matched.
Good!

You can add my:

Reviewed-by: Sam Ravnborg <sam@ravnborg.org>

if you spin a new version.

	Sam

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

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

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

Thread overview: 24+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-01-12  7:22 [PATCH v2 00/16] PCI improvements Andrey Smirnov
2019-01-12  7:22 ` [PATCH v2 01/16] PCI: Switch to using %pa to print memory addresses Andrey Smirnov
2019-01-12  7:22 ` [PATCH v2 02/16] PCI: Replace magic number in setup_device() Andrey Smirnov
2019-01-12  7:22 ` [PATCH v2 03/16] PCI: Remove superfluous parens " Andrey Smirnov
2019-01-12  7:22 ` [PATCH v2 04/16] PCI: Simplify resource setup code " Andrey Smirnov
2019-01-12 11:00   ` Sam Ravnborg
2019-01-12 20:49     ` Andrey Smirnov
2019-01-12 21:35       ` Sam Ravnborg
2019-01-12 11:01   ` Sam Ravnborg
2019-01-12  7:22 ` [PATCH v2 05/16] PCI: Store and reuse BAR offsets Andrey Smirnov
2019-01-12  7:22 ` [PATCH v2 06/16] PCI: Remove unused variables/code Andrey Smirnov
2019-01-12  7:22 ` [PATCH v2 07/16] PCI: Make pci_scan_bus static Andrey Smirnov
2019-01-12 11:04   ` Sam Ravnborg
2019-01-12 19:52     ` Andrey Smirnov
2019-01-12  7:22 ` [PATCH v2 08/16] PCI: Drop "slots" from struct pci_bus Andrey Smirnov
2019-01-12  7:22 ` [PATCH v2 09/16] PCI: Drop "resources" " Andrey Smirnov
2019-01-12  7:22 ` [PATCH v2 10/16] PCI: Drop "name" " Andrey Smirnov
2019-01-12  7:22 ` [PATCH v2 11/16] PCI: Drop "ops" " Andrey Smirnov
2019-01-12  7:22 ` [PATCH v2 12/16] PCI: Drop "rom_address" from struct pci_dev Andrey Smirnov
2019-01-12  7:22 ` [PATCH v2 13/16] PCI: Simplify alloc_pci_dev() Andrey Smirnov
2019-01-12  7:22 ` [PATCH v2 14/16] PCI: Assume 1:1 mapping if .res_start callback is NULL Andrey Smirnov
2019-01-12  7:22 ` [PATCH v2 15/16] PCI: Convert ->res_start() to return resource_size_t Andrey Smirnov
2019-01-12  7:22 ` [PATCH v2 16/16] PCI: Consify pci_ops in struct pci_controller Andrey Smirnov
2019-01-12 11:07 ` [PATCH v2 00/16] PCI improvements Sam Ravnborg

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.