diff mbox series

PCI: of: Restore alignment/indentation in host bridge window table

Message ID 20191119191505.25286-1-geert+renesas@glider.be (mailing list archive)
State Accepted, archived
Delegated to: Lorenzo Pieralisi
Headers show
Series PCI: of: Restore alignment/indentation in host bridge window table | expand

Commit Message

Geert Uytterhoeven Nov. 19, 2019, 7:15 p.m. UTC
Since the printing of the inbound resources was added, alignment and
indentation of the host bridge window table is broken because of two
reasons:
  1. The "IB MEM" row header is longer than the other headers,
  2. Inbound ranges typically extend beyond 32-bit address space, and thus
     don't fit in "#010llx".

Fix this by extending the row header field to 6 characters, and the
format string to 40-bit addresses.

Use "%6s" to handle field size and right-alignment, instead of manual
preparation using error-prone snprintf() calls.  Use the exact same
format string for both cases, to allow sharing.

Impact on kernel boot log on r8a7791/koelsch:

     rcar-pcie fe000000.pcie: host bridge /soc/pcie@fe000000 ranges:
    -rcar-pcie fe000000.pcie:    IO 0xfe100000..0xfe1fffff -> 0x00000000
    -rcar-pcie fe000000.pcie:   MEM 0xfe200000..0xfe3fffff -> 0xfe200000
    -rcar-pcie fe000000.pcie:   MEM 0x30000000..0x37ffffff -> 0x30000000
    -rcar-pcie fe000000.pcie:   MEM 0x38000000..0x3fffffff -> 0x38000000
    -rcar-pcie fe000000.pcie: IB MEM 0x40000000..0xbfffffff -> 0x40000000
    -rcar-pcie fe000000.pcie: IB MEM 0x200000000..0x2ffffffff -> 0x200000000
    +rcar-pcie fe000000.pcie:       IO 0x00fe100000..0x00fe1fffff -> 0x0000000000
    +rcar-pcie fe000000.pcie:      MEM 0x00fe200000..0x00fe3fffff -> 0x00fe200000
    +rcar-pcie fe000000.pcie:      MEM 0x0030000000..0x0037ffffff -> 0x0030000000
    +rcar-pcie fe000000.pcie:      MEM 0x0038000000..0x003fffffff -> 0x0038000000
    +rcar-pcie fe000000.pcie:   IB MEM 0x0040000000..0x00bfffffff -> 0x0040000000
    +rcar-pcie fe000000.pcie:   IB MEM 0x0200000000..0x02ffffffff -> 0x0200000000

Fixes: 52ac576f88f9f701 ("PCI: of: Add inbound resource parsing to helpers")
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
 drivers/pci/of.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

Comments

Bjorn Helgaas Nov. 19, 2019, 7:48 p.m. UTC | #1
On Tue, Nov 19, 2019 at 08:15:05PM +0100, Geert Uytterhoeven wrote:
> Since the printing of the inbound resources was added, alignment and
> indentation of the host bridge window table is broken because of two
> reasons:
>   1. The "IB MEM" row header is longer than the other headers,
>   2. Inbound ranges typically extend beyond 32-bit address space, and thus
>      don't fit in "#010llx".
> 
> Fix this by extending the row header field to 6 characters, and the
> format string to 40-bit addresses.
> 
> Use "%6s" to handle field size and right-alignment, instead of manual
> preparation using error-prone snprintf() calls.  Use the exact same
> format string for both cases, to allow sharing.
> 
> Impact on kernel boot log on r8a7791/koelsch:
> 
>      rcar-pcie fe000000.pcie: host bridge /soc/pcie@fe000000 ranges:
>     -rcar-pcie fe000000.pcie:    IO 0xfe100000..0xfe1fffff -> 0x00000000
>     -rcar-pcie fe000000.pcie:   MEM 0xfe200000..0xfe3fffff -> 0xfe200000
>     -rcar-pcie fe000000.pcie:   MEM 0x30000000..0x37ffffff -> 0x30000000
>     -rcar-pcie fe000000.pcie:   MEM 0x38000000..0x3fffffff -> 0x38000000
>     -rcar-pcie fe000000.pcie: IB MEM 0x40000000..0xbfffffff -> 0x40000000
>     -rcar-pcie fe000000.pcie: IB MEM 0x200000000..0x2ffffffff -> 0x200000000
>     +rcar-pcie fe000000.pcie:       IO 0x00fe100000..0x00fe1fffff -> 0x0000000000
>     +rcar-pcie fe000000.pcie:      MEM 0x00fe200000..0x00fe3fffff -> 0x00fe200000
>     +rcar-pcie fe000000.pcie:      MEM 0x0030000000..0x0037ffffff -> 0x0030000000
>     +rcar-pcie fe000000.pcie:      MEM 0x0038000000..0x003fffffff -> 0x0038000000
>     +rcar-pcie fe000000.pcie:   IB MEM 0x0040000000..0x00bfffffff -> 0x0040000000
>     +rcar-pcie fe000000.pcie:   IB MEM 0x0200000000..0x02ffffffff -> 0x0200000000
> 
> Fixes: 52ac576f88f9f701 ("PCI: of: Add inbound resource parsing to helpers")
> Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>

This is fine with me, and since it applies on top of 52ac576f88f9f701
(longer than the usual 12-char SHA1, BTW), which is on Lorenzo's
pci/mmio-dma-ranges branch, I assume Lorenzo will be the one to take
care of this.

pci_register_host_bridge() prints some of this info like this:

  pci_bus 0000:00: root bus resource [io  0x0000-0x0cf7 window]
  pci_bus 0000:00: root bus resource [io  0x0d00-0xffff window]
  pci_bus 0000:00: root bus resource [mem 0x000a0000-0x000bffff window]
  pci_bus 0000:00: root bus resource [mem 0xdc800000-0xfebfffff window]

Is there any opportunity for consolidating these or at least making
the format the same?

I assume we're currently printing most of that info twice, once
in devm_of_pci_get_host_bridge_resources() and again in
pci_register_host_bridge()?

> ---
>  drivers/pci/of.c | 14 +++++++-------
>  1 file changed, 7 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/pci/of.c b/drivers/pci/of.c
> index e7e12adcff3a3836..81ceeaa6f1d5a2c5 100644
> --- a/drivers/pci/of.c
> +++ b/drivers/pci/of.c
> @@ -265,7 +265,7 @@ static int devm_of_pci_get_host_bridge_resources(struct device *dev,
>  	struct resource *bus_range;
>  	struct of_pci_range range;
>  	struct of_pci_range_parser parser;
> -	char range_type[4];
> +	const char *range_type;
>  	int err;
>  
>  	if (io_base)
> @@ -299,12 +299,12 @@ static int devm_of_pci_get_host_bridge_resources(struct device *dev,
>  	for_each_of_pci_range(&parser, &range) {
>  		/* Read next ranges element */
>  		if ((range.flags & IORESOURCE_TYPE_BITS) == IORESOURCE_IO)
> -			snprintf(range_type, 4, " IO");
> +			range_type = "IO";
>  		else if ((range.flags & IORESOURCE_TYPE_BITS) == IORESOURCE_MEM)
> -			snprintf(range_type, 4, "MEM");
> +			range_type = "MEM";
>  		else
> -			snprintf(range_type, 4, "err");
> -		dev_info(dev, "  %s %#010llx..%#010llx -> %#010llx\n",
> +			range_type = "err";
> +		dev_info(dev, "  %6s %#012llx..%#012llx -> %#012llx\n",
>  			 range_type, range.cpu_addr,
>  			 range.cpu_addr + range.size - 1, range.pci_addr);
>  
> @@ -359,8 +359,8 @@ static int devm_of_pci_get_host_bridge_resources(struct device *dev,
>  		    range.cpu_addr == OF_BAD_ADDR || range.size == 0)
>  			continue;
>  
> -		dev_info(dev, "IB MEM %#010llx..%#010llx -> %#010llx\n",
> -			 range.cpu_addr,
> +		dev_info(dev, "  %6s %#012llx..%#012llx -> %#012llx\n",
> +			 "IB MEM", range.cpu_addr,
>  			 range.cpu_addr + range.size - 1, range.pci_addr);
>  
>  
> -- 
> 2.17.1
>
Geert Uytterhoeven Nov. 20, 2019, 8:49 a.m. UTC | #2
Hi Bjorn,

On Tue, Nov 19, 2019 at 8:48 PM Bjorn Helgaas <helgaas@kernel.org> wrote:
> On Tue, Nov 19, 2019 at 08:15:05PM +0100, Geert Uytterhoeven wrote:
> > Since the printing of the inbound resources was added, alignment and
> > indentation of the host bridge window table is broken because of two
> > reasons:
> >   1. The "IB MEM" row header is longer than the other headers,
> >   2. Inbound ranges typically extend beyond 32-bit address space, and thus
> >      don't fit in "#010llx".
> >
> > Fix this by extending the row header field to 6 characters, and the
> > format string to 40-bit addresses.
> >
> > Use "%6s" to handle field size and right-alignment, instead of manual
> > preparation using error-prone snprintf() calls.  Use the exact same
> > format string for both cases, to allow sharing.
> >
> > Impact on kernel boot log on r8a7791/koelsch:
> >
> >      rcar-pcie fe000000.pcie: host bridge /soc/pcie@fe000000 ranges:
> >     -rcar-pcie fe000000.pcie:    IO 0xfe100000..0xfe1fffff -> 0x00000000
> >     -rcar-pcie fe000000.pcie:   MEM 0xfe200000..0xfe3fffff -> 0xfe200000
> >     -rcar-pcie fe000000.pcie:   MEM 0x30000000..0x37ffffff -> 0x30000000
> >     -rcar-pcie fe000000.pcie:   MEM 0x38000000..0x3fffffff -> 0x38000000
> >     -rcar-pcie fe000000.pcie: IB MEM 0x40000000..0xbfffffff -> 0x40000000
> >     -rcar-pcie fe000000.pcie: IB MEM 0x200000000..0x2ffffffff -> 0x200000000
> >     +rcar-pcie fe000000.pcie:       IO 0x00fe100000..0x00fe1fffff -> 0x0000000000
> >     +rcar-pcie fe000000.pcie:      MEM 0x00fe200000..0x00fe3fffff -> 0x00fe200000
> >     +rcar-pcie fe000000.pcie:      MEM 0x0030000000..0x0037ffffff -> 0x0030000000
> >     +rcar-pcie fe000000.pcie:      MEM 0x0038000000..0x003fffffff -> 0x0038000000
> >     +rcar-pcie fe000000.pcie:   IB MEM 0x0040000000..0x00bfffffff -> 0x0040000000
> >     +rcar-pcie fe000000.pcie:   IB MEM 0x0200000000..0x02ffffffff -> 0x0200000000
> >
> > Fixes: 52ac576f88f9f701 ("PCI: of: Add inbound resource parsing to helpers")
> > Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
>
> This is fine with me, and since it applies on top of 52ac576f88f9f701
> (longer than the usual 12-char SHA1, BTW), which is on Lorenzo's
> pci/mmio-dma-ranges branch, I assume Lorenzo will be the one to take
> care of this.
>
> pci_register_host_bridge() prints some of this info like this:
>
>   pci_bus 0000:00: root bus resource [io  0x0000-0x0cf7 window]
>   pci_bus 0000:00: root bus resource [io  0x0d00-0xffff window]
>   pci_bus 0000:00: root bus resource [mem 0x000a0000-0x000bffff window]
>   pci_bus 0000:00: root bus resource [mem 0xdc800000-0xfebfffff window]
>
> Is there any opportunity for consolidating these or at least making
> the format the same?
>
> I assume we're currently printing most of that info twice, once
> in devm_of_pci_get_host_bridge_resources() and again in
> pci_register_host_bridge()?

(after ignoring PCIe link down, as I don't have a spare PCIe card to plug in)

  rcar-pcie fe000000.pcie: host bridge /soc/pcie@fe000000 ranges:
  rcar-pcie fe000000.pcie:       IO 0x00fe100000..0x00fe1fffff -> 0x0000000000
  rcar-pcie fe000000.pcie:      MEM 0x00fe200000..0x00fe3fffff -> 0x00fe200000
  rcar-pcie fe000000.pcie:      MEM 0x0030000000..0x0037ffffff -> 0x0030000000
  rcar-pcie fe000000.pcie:      MEM 0x0038000000..0x003fffffff -> 0x0038000000
  rcar-pcie fe000000.pcie:   IB MEM 0x0040000000..0x00bfffffff -> 0x0040000000
  rcar-pcie fe000000.pcie:   IB MEM 0x0200000000..0x02ffffffff -> 0x0200000000
  rcar-pcie fe000000.pcie: PCIe link down (ignored)
  rcar-pcie fe000000.pcie: PCIe x4: link up
  rcar-pcie fe000000.pcie: PCI host bridge to bus 0002:00
  pci_bus 0002:00: root bus resource [bus 00-ff]
  pci_bus 0002:00: root bus resource [io  0x0000-0xfffff]
  pci_bus 0002:00: root bus resource [mem 0xfe200000-0xfe3fffff]
  pci_bus 0002:00: root bus resource [mem 0x30000000-0x37ffffff]
  pci_bus 0002:00: root bus resource [mem 0x38000000-0x3fffffff pref]
  pci 0002:00:00.0: [1912:001f] type 01 class 0x060400
  pci 0002:00:00.0: enabling Extended Tags
  pci 0002:00:00.0: PME# supported from D0 D3hot D3cold
  PCI: bus0: Fast back to back transfers disabled

So some, but not all, info is indeed duplicated.

Gr{oetje,eeting}s,

                        Geert
Lorenzo Pieralisi Nov. 20, 2019, 4:27 p.m. UTC | #3
On Tue, Nov 19, 2019 at 08:15:05PM +0100, Geert Uytterhoeven wrote:
> Since the printing of the inbound resources was added, alignment and
> indentation of the host bridge window table is broken because of two
> reasons:
>   1. The "IB MEM" row header is longer than the other headers,
>   2. Inbound ranges typically extend beyond 32-bit address space, and thus
>      don't fit in "#010llx".
> 
> Fix this by extending the row header field to 6 characters, and the
> format string to 40-bit addresses.
> 
> Use "%6s" to handle field size and right-alignment, instead of manual
> preparation using error-prone snprintf() calls.  Use the exact same
> format string for both cases, to allow sharing.
> 
> Impact on kernel boot log on r8a7791/koelsch:
> 
>      rcar-pcie fe000000.pcie: host bridge /soc/pcie@fe000000 ranges:
>     -rcar-pcie fe000000.pcie:    IO 0xfe100000..0xfe1fffff -> 0x00000000
>     -rcar-pcie fe000000.pcie:   MEM 0xfe200000..0xfe3fffff -> 0xfe200000
>     -rcar-pcie fe000000.pcie:   MEM 0x30000000..0x37ffffff -> 0x30000000
>     -rcar-pcie fe000000.pcie:   MEM 0x38000000..0x3fffffff -> 0x38000000
>     -rcar-pcie fe000000.pcie: IB MEM 0x40000000..0xbfffffff -> 0x40000000
>     -rcar-pcie fe000000.pcie: IB MEM 0x200000000..0x2ffffffff -> 0x200000000
>     +rcar-pcie fe000000.pcie:       IO 0x00fe100000..0x00fe1fffff -> 0x0000000000
>     +rcar-pcie fe000000.pcie:      MEM 0x00fe200000..0x00fe3fffff -> 0x00fe200000
>     +rcar-pcie fe000000.pcie:      MEM 0x0030000000..0x0037ffffff -> 0x0030000000
>     +rcar-pcie fe000000.pcie:      MEM 0x0038000000..0x003fffffff -> 0x0038000000
>     +rcar-pcie fe000000.pcie:   IB MEM 0x0040000000..0x00bfffffff -> 0x0040000000
>     +rcar-pcie fe000000.pcie:   IB MEM 0x0200000000..0x02ffffffff -> 0x0200000000
> 
> Fixes: 52ac576f88f9f701 ("PCI: of: Add inbound resource parsing to helpers")
> Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
> ---
>  drivers/pci/of.c | 14 +++++++-------
>  1 file changed, 7 insertions(+), 7 deletions(-)

Hi Rob,

do you mind if I squash this patch in the Fixes: above ?

Thanks,
Lorenzo

> diff --git a/drivers/pci/of.c b/drivers/pci/of.c
> index e7e12adcff3a3836..81ceeaa6f1d5a2c5 100644
> --- a/drivers/pci/of.c
> +++ b/drivers/pci/of.c
> @@ -265,7 +265,7 @@ static int devm_of_pci_get_host_bridge_resources(struct device *dev,
>  	struct resource *bus_range;
>  	struct of_pci_range range;
>  	struct of_pci_range_parser parser;
> -	char range_type[4];
> +	const char *range_type;
>  	int err;
>  
>  	if (io_base)
> @@ -299,12 +299,12 @@ static int devm_of_pci_get_host_bridge_resources(struct device *dev,
>  	for_each_of_pci_range(&parser, &range) {
>  		/* Read next ranges element */
>  		if ((range.flags & IORESOURCE_TYPE_BITS) == IORESOURCE_IO)
> -			snprintf(range_type, 4, " IO");
> +			range_type = "IO";
>  		else if ((range.flags & IORESOURCE_TYPE_BITS) == IORESOURCE_MEM)
> -			snprintf(range_type, 4, "MEM");
> +			range_type = "MEM";
>  		else
> -			snprintf(range_type, 4, "err");
> -		dev_info(dev, "  %s %#010llx..%#010llx -> %#010llx\n",
> +			range_type = "err";
> +		dev_info(dev, "  %6s %#012llx..%#012llx -> %#012llx\n",
>  			 range_type, range.cpu_addr,
>  			 range.cpu_addr + range.size - 1, range.pci_addr);
>  
> @@ -359,8 +359,8 @@ static int devm_of_pci_get_host_bridge_resources(struct device *dev,
>  		    range.cpu_addr == OF_BAD_ADDR || range.size == 0)
>  			continue;
>  
> -		dev_info(dev, "IB MEM %#010llx..%#010llx -> %#010llx\n",
> -			 range.cpu_addr,
> +		dev_info(dev, "  %6s %#012llx..%#012llx -> %#012llx\n",
> +			 "IB MEM", range.cpu_addr,
>  			 range.cpu_addr + range.size - 1, range.pci_addr);
>  
>  
> -- 
> 2.17.1
>
Rob Herring (Arm) Nov. 20, 2019, 4:45 p.m. UTC | #4
On Wed, Nov 20, 2019 at 10:27 AM Lorenzo Pieralisi
<lorenzo.pieralisi@arm.com> wrote:
>
> On Tue, Nov 19, 2019 at 08:15:05PM +0100, Geert Uytterhoeven wrote:
> > Since the printing of the inbound resources was added, alignment and
> > indentation of the host bridge window table is broken because of two
> > reasons:
> >   1. The "IB MEM" row header is longer than the other headers,
> >   2. Inbound ranges typically extend beyond 32-bit address space, and thus
> >      don't fit in "#010llx".
> >
> > Fix this by extending the row header field to 6 characters, and the
> > format string to 40-bit addresses.
> >
> > Use "%6s" to handle field size and right-alignment, instead of manual
> > preparation using error-prone snprintf() calls.  Use the exact same
> > format string for both cases, to allow sharing.
> >
> > Impact on kernel boot log on r8a7791/koelsch:
> >
> >      rcar-pcie fe000000.pcie: host bridge /soc/pcie@fe000000 ranges:
> >     -rcar-pcie fe000000.pcie:    IO 0xfe100000..0xfe1fffff -> 0x00000000
> >     -rcar-pcie fe000000.pcie:   MEM 0xfe200000..0xfe3fffff -> 0xfe200000
> >     -rcar-pcie fe000000.pcie:   MEM 0x30000000..0x37ffffff -> 0x30000000
> >     -rcar-pcie fe000000.pcie:   MEM 0x38000000..0x3fffffff -> 0x38000000
> >     -rcar-pcie fe000000.pcie: IB MEM 0x40000000..0xbfffffff -> 0x40000000
> >     -rcar-pcie fe000000.pcie: IB MEM 0x200000000..0x2ffffffff -> 0x200000000
> >     +rcar-pcie fe000000.pcie:       IO 0x00fe100000..0x00fe1fffff -> 0x0000000000
> >     +rcar-pcie fe000000.pcie:      MEM 0x00fe200000..0x00fe3fffff -> 0x00fe200000
> >     +rcar-pcie fe000000.pcie:      MEM 0x0030000000..0x0037ffffff -> 0x0030000000
> >     +rcar-pcie fe000000.pcie:      MEM 0x0038000000..0x003fffffff -> 0x0038000000
> >     +rcar-pcie fe000000.pcie:   IB MEM 0x0040000000..0x00bfffffff -> 0x0040000000
> >     +rcar-pcie fe000000.pcie:   IB MEM 0x0200000000..0x02ffffffff -> 0x0200000000
> >
> > Fixes: 52ac576f88f9f701 ("PCI: of: Add inbound resource parsing to helpers")
> > Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
> > ---
> >  drivers/pci/of.c | 14 +++++++-------
> >  1 file changed, 7 insertions(+), 7 deletions(-)
>
> Hi Rob,
>
> do you mind if I squash this patch in the Fixes: above ?

No, LGTM.

Rob
diff mbox series

Patch

diff --git a/drivers/pci/of.c b/drivers/pci/of.c
index e7e12adcff3a3836..81ceeaa6f1d5a2c5 100644
--- a/drivers/pci/of.c
+++ b/drivers/pci/of.c
@@ -265,7 +265,7 @@  static int devm_of_pci_get_host_bridge_resources(struct device *dev,
 	struct resource *bus_range;
 	struct of_pci_range range;
 	struct of_pci_range_parser parser;
-	char range_type[4];
+	const char *range_type;
 	int err;
 
 	if (io_base)
@@ -299,12 +299,12 @@  static int devm_of_pci_get_host_bridge_resources(struct device *dev,
 	for_each_of_pci_range(&parser, &range) {
 		/* Read next ranges element */
 		if ((range.flags & IORESOURCE_TYPE_BITS) == IORESOURCE_IO)
-			snprintf(range_type, 4, " IO");
+			range_type = "IO";
 		else if ((range.flags & IORESOURCE_TYPE_BITS) == IORESOURCE_MEM)
-			snprintf(range_type, 4, "MEM");
+			range_type = "MEM";
 		else
-			snprintf(range_type, 4, "err");
-		dev_info(dev, "  %s %#010llx..%#010llx -> %#010llx\n",
+			range_type = "err";
+		dev_info(dev, "  %6s %#012llx..%#012llx -> %#012llx\n",
 			 range_type, range.cpu_addr,
 			 range.cpu_addr + range.size - 1, range.pci_addr);
 
@@ -359,8 +359,8 @@  static int devm_of_pci_get_host_bridge_resources(struct device *dev,
 		    range.cpu_addr == OF_BAD_ADDR || range.size == 0)
 			continue;
 
-		dev_info(dev, "IB MEM %#010llx..%#010llx -> %#010llx\n",
-			 range.cpu_addr,
+		dev_info(dev, "  %6s %#012llx..%#012llx -> %#012llx\n",
+			 "IB MEM", range.cpu_addr,
 			 range.cpu_addr + range.size - 1, range.pci_addr);