lspci: Print buses of multibus PCI domain in ascending order
PATCH 1/1 lspci: Print buses of multibus PCI domain in ascending order
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.
--- ls-tree.c | 10 +++++++--- lspci.h | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-)
ls-tree.c +7 -3
@@ -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,14 @@ 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->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 +104,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",
lspci.h +1 -1
@@ -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;
Signature · 1 line
2.20.1
Quoted 35 lines · On Monday 20 December 2021 20:53:49 Pali Rohár wrote:
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.
--- ls-tree.c | 10 +++++++--- lspci.h | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-)ls-tree.c +1
-1@@ -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)
ls-tree.c new_bus(struct bridge *b, unsigned int domain, unsigned int n) · line 34
Quoted 4 lines
ls-tree.c +0
-1@@ -31,11 +31,14 @@ 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;
Oops, this is a mistake. Default value for bus->sibling needs to be explicitly set because xmalloc() wrapper does not return zero initialized memory. So correct change for above line should be:
- bus->sibling = b->first_bus;
+ bus->sibling = NULL;
Quoted 36 lines
ls-tree.c +6
-1bus->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 +104,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",lspci.h +1
-1@@ -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;Signature · 1 line
2.20.1
Hi!
Quoted 3 lines
Oops, this is a mistake. Default value for
bus->siblingneeds to be explicitly set becausexmalloc()wrapper does not return zero initialized memory. So correct change for above line should be:
Fine, could you please re-submit the whole patch.
Martin
PATCH v2 1/1 lspci: Print buses of multibus PCI domain in ascending order
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(-)
ls-tree.c +8 -3
@@ -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",
lspci.h +1 -1
@@ -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;
Signature · 1 line
2.20.1
Martin Mareš
AppliedHi!
Quoted 10 lines
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.
Quoted 6 lines
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.
Thanks, applied.
Martin