From d3397e3cff67e299d4306f9115b45b65aa2419a3 Mon Sep 17 00:00:00 2001 From: Dima Buzdyk Date: Mon, 17 Jun 2024 07:50:39 +0500 Subject: [PATCH] lspci: print domains Print PCI controller domain (id) for devices with non-zero domains. This usually happens on SOCs with multiple PCIe controllers. Add '-D' flag to force print domains for all devices. --- toys/other/lsusb.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/toys/other/lsusb.c b/toys/other/lsusb.c index 7642b094..cbfc2421 100644 --- a/toys/other/lsusb.c +++ b/toys/other/lsusb.c @@ -4,7 +4,7 @@ * Copyright 2013 Isaac Dunham USE_LSUSB(NEWTOY(lsusb, "i:", TOYFLAG_USR|TOYFLAG_BIN)) -USE_LSPCI(NEWTOY(lspci, "emkn@x@i:", TOYFLAG_USR|TOYFLAG_BIN)) +USE_LSPCI(NEWTOY(lspci, "eD@mkn@x@i:", TOYFLAG_USR|TOYFLAG_BIN)) config LSPCI bool "lspci" @@ -19,6 +19,7 @@ config LSPCI -k Show kernel driver -m Machine readable -n Numeric output (-nn for both) + -D Print domain numbers -x Hex dump of config space (64 bytes; -xxx for 256, -xxxx for 4096) config LSUSB @@ -37,7 +38,7 @@ config LSUSB GLOBALS( char *i; - long x, n; + long x, n, D; void *ids, *class; int count; @@ -192,6 +193,8 @@ static int list_pci(struct dirtree *new) char *driver = 0, buf[16], *ss, *names[3]; int cvd[3] = {0}, ii, revision = 0; off_t len = sizeof(toybuf); + /* skip 0000: part by default */ + char *bus = strchr(new->name, ':') + 1; // Output formats: -n, -nn, -m, -nm, -nnm, -k @@ -214,7 +217,9 @@ static int list_pci(struct dirtree *new) if (!FLAG(e)) cvd[0] >>= 8; // Output line according to flags - printf("%s", new->name+5); + if (TT.D || strncmp(new->name, "0000:", bus-new->name)) + bus=new->name; + printf("%s", bus); for (ii = 0; ii<3; ii++) { sprintf(buf, "%0*x", 6-2*(ii||!FLAG(e)), cvd[ii]); if (!TT.n) printf(FLAG(m) ? " \"%s\"" : ": %s"+(ii!=1), names[ii] ? : buf); -- 2.39.2