From 1f7c91ccc8a51398e91834a75a6ac08dde68550b Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Sat, 27 Dec 2003 22:16:56 +0000 Subject: [PATCH] Support for PCI domains finished git-archimport-id: mj@ucw.cz--public/pciutils--main--2.2--patch-35 --- ChangeLog | 7 ++++++- TODO | 6 ------ lib/dump.c | 11 +++++++---- lspci.c | 38 ++++++++++++++++++++++---------------- lspci.man | 33 +++++++++++++++++---------------- setpci.man | 18 ++++++++++-------- 6 files changed, 62 insertions(+), 51 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3b77271..69d3a27 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,7 +1,12 @@ 2003-12-27 Martin Mares + * lspci.man, setpci.man: Document domains and correct spelling. + + * lib/dump.c (dump_init): Added ability to read domain numbers. + * lspci.c: Devices in domains different from 0 have their slot number - printed as "::.". + printed as "::.". Tree view supports domains + as well. * lib/filter.c: Slot filters understand domains. diff --git a/TODO b/TODO index 9e39125..f25f99b 100644 --- a/TODO +++ b/TODO @@ -4,9 +4,3 @@ - pci.ids: "Unknown mass storage controller" -> "Mass storage controller". - names.c: rewrite - -- support for domains: - - filters: doc and helps - - reading of dumps - - tree view - - map mode diff --git a/lib/dump.c b/lib/dump.c index d3b154f..4baeae4 100644 --- a/lib/dump.c +++ b/lib/dump.c @@ -26,7 +26,7 @@ dump_init(struct pci_access *a) FILE *f; char buf[256]; struct pci_dev *dev = NULL; - int len, bn, dn, fn, i, j; + int len, mn, bn, dn, fn, i, j; if (!a) a->error("dump: File name not given."); @@ -41,10 +41,13 @@ dump_init(struct pci_access *a) if (z >= buf && *z == '\r') *z-- = 0; len = z - buf + 1; - if (len >= 8 && buf[2] == ':' && buf[5] == '.' && buf[7] == ' ' && - sscanf(buf, "%x:%x.%d ", &bn, &dn, &fn) == 3) + mn = 0; + if ((len >= 8 && buf[2] == ':' && buf[5] == '.' && buf[7] == ' ' && + sscanf(buf, "%x:%x.%d ", &bn, &dn, &fn) == 3) || + (len >= 13 && buf[4] == ':' && buf[7] == ':' && buf[10] == '.' && buf[12] == ' ' && + sscanf(buf, "%x:%x:%x.%d", &mn, &bn, &dn, &fn) == 4)) { - dev = pci_get_dev(a, 0, bn, dn, fn); + dev = pci_get_dev(a, mn, bn, dn, fn); dev->aux = pci_malloc(a, 256); memset(dev->aux, 0xff, 256); pci_link_dev(a, dev); diff --git a/lspci.c b/lspci.c index 2368ceb..3fde622 100644 --- a/lspci.c +++ b/lspci.c @@ -1083,35 +1083,38 @@ struct bridge { struct bridge *chain; /* Single-linked list of bridges */ struct bridge *next, *child; /* Tree of bridges */ struct bus *first_bus; /* List of busses connected to this bridge */ + unsigned int domain; unsigned int primary, secondary, subordinate; /* Bus numbers */ struct device *br_dev; }; struct bus { + unsigned int domain; unsigned int number; struct bus *sibling; struct device *first_dev, **last_dev; }; -static struct bridge host_bridge = { NULL, NULL, NULL, NULL, ~0, 0, ~0, NULL }; +static struct bridge host_bridge = { NULL, NULL, NULL, NULL, 0, ~0, 0, ~0, NULL }; static struct bus * -find_bus(struct bridge *b, unsigned int n) +find_bus(struct bridge *b, unsigned int domain, unsigned int n) { struct bus *bus; for(bus=b->first_bus; bus; bus=bus->sibling) - if (bus->number == n) + if (bus->domain == domain && bus->number == n) break; return bus; } static struct bus * -new_bus(struct bridge *b, unsigned int n) +new_bus(struct bridge *b, unsigned int domain, unsigned int n) { struct bus *bus = xmalloc(sizeof(struct bus)); bus = xmalloc(sizeof(struct bus)); + bus->domain = domain; bus->number = n; bus->sibling = b->first_bus; bus->first_dev = NULL; @@ -1126,19 +1129,19 @@ insert_dev(struct device *d, struct bridge *b) struct pci_dev *p = d->dev; struct bus *bus; - if (! (bus = find_bus(b, p->bus))) + if (! (bus = find_bus(b, p->domain, p->bus))) { struct bridge *c; for(c=b->child; c; c=c->next) - if (c->secondary <= p->bus && p->bus <= c->subordinate) + if (c->domain == p->domain && c->secondary <= p->bus && p->bus <= c->subordinate) { insert_dev(d, c); return; } - bus = new_bus(b, p->bus); + bus = new_bus(b, p->domain, p->bus); } /* Simple insertion at the end _does_ guarantee the correct order as the - * original device list was sorted by (bus, devfn) lexicographically + * original device list was sorted by (domain, bus, devfn) lexicographically * and all devices on the new list have the same bus number. */ *bus->last_dev = d; @@ -1163,6 +1166,7 @@ grow_tree(void) (ht == PCI_HEADER_TYPE_BRIDGE || ht == PCI_HEADER_TYPE_CARDBUS)) { b = xmalloc(sizeof(struct bridge)); + b->domain = d->dev->domain; if (ht == PCI_HEADER_TYPE_BRIDGE) { b->primary = get_conf_byte(d, PCI_CB_PRIMARY_BUS); @@ -1191,7 +1195,8 @@ grow_tree(void) struct bridge *c, *best; best = NULL; for(c=&host_bridge; c; c=c->chain) - if (c != b && b->primary >= c->secondary && b->primary <= c->subordinate && + if (c != b && (c == &host_bridge || b->domain == c->domain) && + b->primary >= c->secondary && b->primary <= c->subordinate && (!best || best->subordinate - best->primary > c->subordinate - c->primary)) best = c; if (best) @@ -1204,8 +1209,8 @@ grow_tree(void) /* Insert secondary bus for each bridge */ for(b=&host_bridge; b; b=b->chain) - if (!find_bus(b, b->secondary)) - new_bus(b, b->secondary); + if (!find_bus(b, b->domain, b->secondary)) + new_bus(b, b->domain, b->secondary); /* Create bus structs and link devices */ @@ -1244,9 +1249,9 @@ show_tree_dev(struct device *d, byte *line, byte *p) if (b->br_dev == d) { if (b->secondary == b->subordinate) - p += sprintf(p, "-[%02x]-", b->secondary); + p += sprintf(p, "-[%04x:%02x]-", b->domain, b->secondary); else - p += sprintf(p, "-[%02x-%02x]-", b->secondary, b->subordinate); + p += sprintf(p, "-[%04x:%02x-%02x]-", b->domain, b->secondary, b->subordinate); show_tree_bridge(b, line, p); return; } @@ -1292,7 +1297,7 @@ show_tree_bridge(struct bridge *b, byte *line, byte *p) if (!b->first_bus->sibling) { if (b == &host_bridge) - p += sprintf(p, "[%02x]-", b->first_bus->number); + p += sprintf(p, "[%04x:%02x]-", b->domain, b->first_bus->number); show_tree_bus(b->first_bus, line, p); } else @@ -1302,11 +1307,11 @@ show_tree_bridge(struct bridge *b, byte *line, byte *p) while (u->sibling) { - k = p + sprintf(p, "+-[%02x]-", u->number); + k = p + sprintf(p, "+-[%04x:%02x]-", u->domain, u->number); show_tree_bus(u, line, k); u = u->sibling; } - k = p + sprintf(p, "\\-[%02x]-", u->number); + k = p + sprintf(p, "\\-[%04x:%02x]-", u->domain, u->number); show_tree_bus(u, line, k); } } @@ -1376,6 +1381,7 @@ do_map_bus(int bus) for(func = 0; func < func_limit; func++) if (filter.func < 0 || filter.func == func) { + /* XXX: Bus mapping supports only domain 0 */ struct pci_dev *p = pci_get_dev(pacc, 0, bus, dev, func); u16 vendor = pci_read_word(p, PCI_VENDOR_ID); if (vendor && vendor != 0xffff) diff --git a/lspci.man b/lspci.man index c4e0fe2..58cfbd7 100644 --- a/lspci.man +++ b/lspci.man @@ -44,7 +44,7 @@ itself. Show hexadecimal dump of whole PCI configuration space. Available only for root as several PCI devices .B crash -when you try to read undefined portions of the config space (this behaviour probably +when you try to read undefined portions of the config space (this behavior probably doesn't violate the PCI standard, but it's at least very stupid). .TP .B -b @@ -55,16 +55,18 @@ PCI bus instead of as seen by the kernel. Show a tree-like diagram containing all buses, bridges, devices and connections between them. .TP -.B -s [[]:][][.[]] -Show only devices in specified bus, slot and function. Each component of the device -address can be omitted or set as "*" meaning "any value". All numbers are +.B -s [[[[]:]]:][][.[]] +Show only devices in the specified domain (in case your machine has several host bridges, +they can either share a common bus number space or each of them can address a PCI domain +of its own; domains are numbered from 0 to ffff), bus (0 to ff), slot (0 to 1f) and function (0 to 7). +Each component of the device address can be omitted or set to "*", both meaning "any value". All numbers are hexadecimal. E.g., "0:" means all devices on bus 0, "0" means all functions of device 0 on any bus, "0.3" selects third function of device 0 on all buses and ".4" shows only -fourth function of each device. +the fourth function of each device. .TP .B -d []:[] Show only devices with specified vendor and device ID. Both ID's are given in -hexadecimal and may be omitted or given as "*" meaning "any value". +hexadecimal and may be omitted or given as "*", both meaning "any value". .TP .B -i Use @@ -82,18 +84,16 @@ Dump PCI device data in machine readable form (both normal and verbose format su for easy parsing by scripts. .TP .B -M -Invoke bus mapping mode which scans the bus extensively to find all devices including -those behind misconfigured bridges etc. Please note that this is intended only for -debugging and as it can crash the machine (only in case of buggy devices, but -unfortunately these happen to exist), it's available only to root. Also using --M on PCI access methods which don't directly touch the hardware has no -sense since the results are (modulo bugs in lspci) identical to normal listing -modes. +Invoke bus mapping mode which performs a thorough scan of all PCI devices, including +those behind misconfigured bridges etc. This option is available only to root and it +gives meaningful results only if combined with direct hardware access mode (otherwise +the results are identical to normal listing modes, modulo bugs in lspci). Please note +that the bus mapper doesn't support PCI domains and scans only domain 0. .TP .B --version Shows .I lspci -version. This option should be used standalone. +version. This option should be used stand-alone. .SH PCILIB OPTIONS The PCI utilities use PCILIB (a portable library providing platform-independent @@ -115,7 +115,7 @@ Use direct hardware access via Intel configuration mechanism 1. (i386 and compat .B -H2 Use direct hardware access via Intel configuration mechanism 2. Warning: This method is able to address only first 16 devices on any bus and it seems to be very -unrealiable in many cases. (i386 and compatible only) +unreliable in many cases. (i386 and compatible only) .TP .B -F Extract all information from given file containing output of lspci -x. This is very @@ -138,7 +138,8 @@ kernels. Contains per-bus subdirectories with per-card config space files and a file containing a list of all PCI devices. .SH SEE ALSO -.BR setpci (8), update-pciids (8) +.BR setpci (8), +.BR update-pciids (8) .SH AUTHOR The PCI Utilities are maintained by Martin Mares . diff --git a/setpci.man b/setpci.man index 3c03536..5dda248 100644 --- a/setpci.man +++ b/setpci.man @@ -41,7 +41,7 @@ operations does before you actually execute it. .B --version Shows .I setpci -version. This option should be used standalone. +version. This option should be used stand-alone. .SH DEVICE SELECTION @@ -49,16 +49,18 @@ version. This option should be used standalone. Before each sequence of operations you need to select which devices you wish that operation to affect. .TP -.B -s [[]:][][.[]] -Select devices in specified bus, slot and function. Each component of the device -address can be omitted or set as "*" meaning "any value". All numbers are +.B -s [[[[]:]]:][][.[]] +Show only devices in the specified domain (in case your machine has several host bridges, +they can either share a common bus number space or each of them can address a PCI domain +of its own; domains are numbered from 0 to ffff), bus (0 to ff), slot (0 to 1f) and function (0 to 7). +Each component of the device address can be omitted or set to "*", both meaning "any value". All numbers are hexadecimal. E.g., "0:" means all devices on bus 0, "0" means all functions of device 0 -on any bus, "0.3" selects third function of device 0 on all busses and ".4" selects only -fourth function of each device. +on any bus, "0.3" selects third function of device 0 on all buses and ".4" shows only +the fourth function of each device. .TP .B -d []:[] Select devices with specified vendor and device ID. Both ID's are given in -hexadecimal and may be omitted or given as "*" meaning "any value". +hexadecimal and may be omitted or given as "*", both meaning "any value". .SH OPERATIONS .PP @@ -180,7 +182,7 @@ Use direct hardware access via Intel configuration mechanism 1. (i386 and compat .B -H2 Use direct hardware access via Intel configuration mechanism 2. Warning: This method is able to address only first 16 devices on any bus and it seems to be very -unrealiable in many cases. (i386 and compatible only) +unreliable in many cases. (i386 and compatible only) .TP .B -F Extract all information from given file containing output of lspci -x. This is very -- 2.39.2