Linux PCI subsystem development
 help / color / mirror / Atom feed
From: "Pali Rohár" <pali@kernel.org>
To: "Martin Mares" <mj@ucw.cz>, "Bjorn Helgaas" <helgaas@kernel.org>,
	"Krzysztof Wilczyński" <kw@linux.com>,
	"Matthew Wilcox" <willy@infradead.org>,
	linux-pci@vger.kernel.org
Subject: [PATCH v2 pciutils] lspci: Print buses of multibus PCI domain in ascending order
Date: Sun, 26 Dec 2021 23:04:03 +0100	[thread overview]
Message-ID: <20211226220403.18063-1-pali@kernel.org> (raw)
In-Reply-To: <mj+md-20211226.215722.61425.albireo@ucw.cz>

Currently PCI domains are printed in ascending order. Devices on each PCI
bus are also printed in ascending order. PCI buses behind PCI-to-PCI
bridges are also printed in ascending order.

But buses of PCI domain are currently printed in descending order because
function new_bus() puts newly created bus at the beginning of linked list.

In most cases PCI domain contains only one (top level) bus, so in most
cases it is not visible this inconsistency.

Multibus PCI domains (where PCI domain contains more independent top level
PCI buses) are available on ARM devices.

This change fixes print order of multibus PCI domains, so also top level
PCI buses are printed in ascending order, like PCI buses behind PCI-to-PCI
bridges.
---
v2: Initialize bus->sibling to NULL.
---
 ls-tree.c | 11 ++++++++---
 lspci.h   |  2 +-
 2 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/ls-tree.c b/ls-tree.c
index aeb40870865e..ba7873b77649 100644
--- a/ls-tree.c
+++ b/ls-tree.c
@@ -12,7 +12,7 @@
 
 #include "lspci.h"
 
-struct bridge host_bridge = { NULL, NULL, NULL, NULL, 0, ~0, 0, ~0, NULL };
+struct bridge host_bridge = { NULL, NULL, NULL, NULL, NULL, 0, ~0, 0, ~0, NULL };
 
 static struct bus *
 find_bus(struct bridge *b, unsigned int domain, unsigned int n)
@@ -31,11 +31,15 @@ new_bus(struct bridge *b, unsigned int domain, unsigned int n)
   struct bus *bus = xmalloc(sizeof(struct bus));
   bus->domain = domain;
   bus->number = n;
-  bus->sibling = b->first_bus;
+  bus->sibling = NULL;
   bus->first_dev = NULL;
   bus->last_dev = &bus->first_dev;
   bus->parent_bridge = b;
-  b->first_bus = bus;
+  if (b->last_bus)
+    b->last_bus->sibling = bus;
+  b->last_bus = bus;
+  if (!b->first_bus)
+    b->first_bus = bus;
   return bus;
 }
 
@@ -101,6 +105,7 @@ grow_tree(void)
 	  last_br = &b->chain;
 	  b->next = b->child = NULL;
 	  b->first_bus = NULL;
+	  b->last_bus = NULL;
 	  b->br_dev = d;
 	  d->bridge = b;
 	  pacc->debug("Tree: bridge %04x:%02x:%02x.%d: %02x -> %02x-%02x\n",
diff --git a/lspci.h b/lspci.h
index fefee5256423..352177fcce7b 100644
--- a/lspci.h
+++ b/lspci.h
@@ -90,7 +90,7 @@ void show_kernel_cleanup(void);
 struct bridge {
   struct bridge *chain;			/* Single-linked list of bridges */
   struct bridge *next, *child;		/* Tree of bridges */
-  struct bus *first_bus;		/* List of buses connected to this bridge */
+  struct bus *first_bus, *last_bus;	/* List of buses connected to this bridge */
   unsigned int domain;
   unsigned int primary, secondary, subordinate;	/* Bus numbers */
   struct device *br_dev;
-- 
2.20.1


  reply	other threads:[~2021-12-26 22:04 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-20 19:53 [PATCH pciutils] lspci: Print buses of multibus PCI domain in ascending order Pali Rohár
2021-12-26 13:04 ` Pali Rohár
2021-12-26 21:57   ` Martin Mareš
2021-12-26 22:04     ` Pali Rohár [this message]
2021-12-26 22:05       ` [PATCH v2 " Martin Mareš

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211226220403.18063-1-pali@kernel.org \
    --to=pali@kernel.org \
    --cc=helgaas@kernel.org \
    --cc=kw@linux.com \
    --cc=linux-pci@vger.kernel.org \
    --cc=mj@ucw.cz \
    --cc=willy@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox