2 * The PCI Utilities -- List All PCI Devices
4 * Copyright (c) 1997--2020 Martin Mares <mj@ucw.cz>
6 * Can be freely distributed and used under the terms of the GNU GPL v2+.
8 * SPDX-License-Identifier: GPL-2.0-or-later
20 int verbose; /* Show detailed information */
21 static int opt_hex; /* Show contents of config space as hexadecimal numbers */
22 struct pci_filter filter; /* Device filter */
23 static int opt_filter; /* Any filter was given */
24 static int opt_tree; /* Show bus tree */
25 static int opt_path; /* Show bridge path */
26 static int opt_machine; /* Generate machine-readable output */
27 static int opt_map_mode; /* Bus mapping mode enabled */
28 static int opt_domains; /* Show domain numbers (0=disabled, 1=auto-detected, 2=requested) */
29 static int opt_kernel; /* Show kernel drivers */
30 static int opt_query_dns; /* Query the DNS (0=disabled, 1=enabled, 2=refresh cache) */
31 static int opt_query_all; /* Query the DNS for all entries */
32 char *opt_pcimap; /* Override path to Linux modules.pcimap */
34 const char program_name[] = "lspci";
36 static char options[] = "nvbxs:d:tPi:mgp:qkMDQ" GENERIC_OPTIONS ;
38 static char help_msg[] =
39 "Usage: lspci [<switches>]\n"
41 "Basic display modes:\n"
42 "-mm\t\tProduce machine-readable output (single -m for an obsolete format)\n"
43 "-t\t\tShow bus tree\n"
46 "-v\t\tBe verbose (-vv or -vvv for higher verbosity)\n"
48 "-k\t\tShow kernel drivers handling each device\n"
50 "-x\t\tShow hex-dump of the standard part of the config space\n"
51 "-xxx\t\tShow hex-dump of the whole config space (dangerous; root only)\n"
52 "-xxxx\t\tShow hex-dump of the 4096-byte extended config space (root only)\n"
53 "-b\t\tBus-centric view (addresses and IRQ's as seen by the bus)\n"
54 "-D\t\tAlways show domain numbers\n"
55 "-P\t\tDisplay bridge path in addition to bus and device number\n"
56 "-PP\t\tDisplay bus path in addition to bus and device number\n"
58 "Resolving of device ID's to names:\n"
59 "-n\t\tShow numeric ID's\n"
60 "-nn\t\tShow both textual and numeric ID's (names & numbers)\n"
62 "-q\t\tQuery the PCI ID database for unknown ID's via DNS\n"
63 "-qq\t\tAs above, but re-query locally cached entries\n"
64 "-Q\t\tQuery the PCI ID database for all ID's via DNS\n"
67 "Selection of devices:\n"
68 "-s [[[[<domain>]:]<bus>]:][<slot>][.[<func>]]\tShow only devices in selected slots\n"
69 "-d [<vendor>]:[<device>][:<class>]\t\tShow only devices with specified ID's\n"
72 "-i <file>\tUse specified ID database instead of %s\n"
74 "-p <file>\tLook up kernel modules in a given file instead of default modules.pcimap\n"
76 "-M\t\tEnable `bus mapping' mode (dangerous; root only)\n"
78 "PCI access options:\n"
82 /*** Our view of the PCI bus ***/
84 struct pci_access *pacc;
85 struct device *first_dev;
86 static int seen_errors;
87 static int need_topology;
90 config_fetch(struct device *d, unsigned int pos, unsigned int len)
92 unsigned int end = pos+len;
95 while (pos < d->config_bufsize && len && d->present[pos])
97 while (pos+len <= d->config_bufsize && len && d->present[pos+len-1])
102 if (end > d->config_bufsize)
104 int orig_size = d->config_bufsize;
105 while (end > d->config_bufsize)
106 d->config_bufsize *= 2;
107 d->config = xrealloc(d->config, d->config_bufsize);
108 d->present = xrealloc(d->present, d->config_bufsize);
109 memset(d->present + orig_size, 0, d->config_bufsize - orig_size);
111 result = pci_read_block(d->dev, pos, d->config + pos, len);
113 memset(d->present + pos, 1, len);
118 scan_device(struct pci_dev *p)
122 if (p->domain && !opt_domains)
124 if (!pci_filter_match(&filter, p) && !need_topology)
126 d = xmalloc(sizeof(struct device));
127 memset(d, 0, sizeof(*d));
129 d->no_config_access = p->no_config_access;
130 d->config_cached = d->config_bufsize = 64;
131 d->config = xmalloc(64);
132 d->present = xmalloc(64);
133 memset(d->present, 1, 64);
134 if (!d->no_config_access && !pci_read_block(p, 0, d->config, 64))
136 d->no_config_access = 1;
137 d->config_cached = d->config_bufsize = 0;
138 memset(d->present, 0, 64);
140 if (!d->no_config_access && (d->config[PCI_HEADER_TYPE] & 0x7f) == PCI_HEADER_TYPE_CARDBUS)
142 /* For cardbus bridges, we need to fetch 64 bytes more to get the
143 * full standard header... */
144 if (config_fetch(d, 64, 64))
145 d->config_cached += 64;
147 pci_setup_cache(p, d->config, d->config_cached);
148 pci_fill_info(p, PCI_FILL_IDENT | PCI_FILL_CLASS | PCI_FILL_CLASS_EXT | PCI_FILL_SUBSYS | (need_topology ? PCI_FILL_PARENT : 0));
159 for (p=pacc->devices; p; p=p->next)
160 if (d = scan_device(p))
167 /*** Config space accesses ***/
170 check_conf_range(struct device *d, unsigned int pos, unsigned int len)
173 if (!d->present[pos])
174 die("Internal bug: Accessing non-read configuration byte at position %x", pos);
180 get_conf_byte(struct device *d, unsigned int pos)
182 check_conf_range(d, pos, 1);
183 return d->config[pos];
187 get_conf_word(struct device *d, unsigned int pos)
189 check_conf_range(d, pos, 2);
190 return d->config[pos] | (d->config[pos+1] << 8);
194 get_conf_long(struct device *d, unsigned int pos)
196 check_conf_range(d, pos, 4);
197 return d->config[pos] |
198 (d->config[pos+1] << 8) |
199 (d->config[pos+2] << 16) |
200 (d->config[pos+3] << 24);
206 compare_them(const void *A, const void *B)
208 const struct pci_dev *a = (*(const struct device **)A)->dev;
209 const struct pci_dev *b = (*(const struct device **)B)->dev;
211 if (a->domain < b->domain)
213 if (a->domain > b->domain)
223 if (a->func < b->func)
225 if (a->func > b->func)
233 struct device **index, **h, **last_dev;
238 for (d=first_dev; d; d=d->next)
240 h = index = alloca(sizeof(struct device *) * cnt);
241 for (d=first_dev; d; d=d->next)
243 qsort(index, cnt, sizeof(struct device *), compare_them);
244 last_dev = &first_dev;
249 last_dev = &(*h)->next;
255 /*** Normal output ***/
258 show_slot_path(struct device *d)
260 struct pci_dev *p = d->dev;
264 struct bus *bus = d->parent_bus;
265 struct bridge *br = bus->parent_bridge;
267 if (br && br->br_dev)
269 show_slot_path(br->br_dev);
271 printf("/%02x:%02x.%d", p->bus, p->dev, p->func);
273 printf("/%02x.%d", p->dev, p->func);
277 printf("%02x:%02x.%d", p->bus, p->dev, p->func);
281 show_slot_name(struct device *d)
283 struct pci_dev *p = d->dev;
285 if (!opt_machine ? opt_domains : (p->domain || opt_domains >= 2))
286 printf("%04x:", p->domain);
291 show_terse(struct device *d)
294 struct pci_dev *p = d->dev;
295 char classbuf[256], devbuf[256];
299 pci_lookup_name(pacc, classbuf, sizeof(classbuf),
302 pci_lookup_name(pacc, devbuf, sizeof(devbuf),
303 PCI_LOOKUP_VENDOR | PCI_LOOKUP_DEVICE,
304 p->vendor_id, p->device_id));
305 if ((p->known_fields & PCI_FILL_CLASS_EXT) && p->rev_id)
306 printf(" (rev %02x)", p->rev_id);
310 c = (p->known_fields & PCI_FILL_CLASS_EXT) ? p->prog_if : 0;
311 x = pci_lookup_name(pacc, devbuf, sizeof(devbuf),
312 PCI_LOOKUP_PROGIF | PCI_LOOKUP_NO_NUMBERS,
316 printf(" (prog-if %02x", c);
324 if (verbose || opt_kernel)
328 pci_fill_info(p, PCI_FILL_LABEL);
331 printf("\tDeviceName: %s", p->label);
332 if ((p->known_fields & PCI_FILL_SUBSYS) &&
333 p->subsys_vendor_id && p->subsys_vendor_id != 0xffff)
334 printf("\tSubsystem: %s\n",
335 pci_lookup_name(pacc, ssnamebuf, sizeof(ssnamebuf),
336 PCI_LOOKUP_SUBSYSTEM | PCI_LOOKUP_VENDOR | PCI_LOOKUP_DEVICE,
337 p->vendor_id, p->device_id, p->subsys_vendor_id, p->subsys_id));
341 /*** Verbose output ***/
346 static const char suffix[][2] = { "", "K", "M", "G", "T" };
350 for (i = 0; i < (sizeof(suffix) / sizeof(*suffix) - 1); i++) {
355 printf(" [size=%u%s]", (unsigned)x, suffix[i]);
359 show_range(const char *prefix, u64 base, u64 limit, int bits, int disabled)
361 printf("%s:", prefix);
362 if (base <= limit || verbose > 2)
363 printf(" %0*" PCI_U64_FMT_X "-%0*" PCI_U64_FMT_X, (bits+3)/4, base, (bits+3)/4, limit);
364 if (!disabled && base <= limit)
365 show_size(limit - base + 1);
367 printf(" [disabled]");
369 printf(" [%d-bit]", bits);
374 ioflg_to_pciflg(pciaddr_t ioflg)
378 if (ioflg & PCI_IORESOURCE_IO)
379 flg = PCI_BASE_ADDRESS_SPACE_IO;
380 else if (!(ioflg & PCI_IORESOURCE_MEM))
384 flg = PCI_BASE_ADDRESS_SPACE_MEMORY;
385 if (ioflg & PCI_IORESOURCE_MEM_64)
386 flg |= PCI_BASE_ADDRESS_MEM_TYPE_64;
388 flg |= PCI_BASE_ADDRESS_MEM_TYPE_32;
389 if (ioflg & PCI_IORESOURCE_PREFETCH)
390 flg |= PCI_BASE_ADDRESS_MEM_PREFETCH;
397 show_bases(struct device *d, int cnt, int without_config_data)
399 struct pci_dev *p = d->dev;
400 word cmd = without_config_data ? (PCI_COMMAND_IO | PCI_COMMAND_MEMORY) : get_conf_word(d, PCI_COMMAND);
403 for (i=0; i<cnt; i++)
405 pciaddr_t pos = p->base_addr[i];
406 pciaddr_t len = (p->known_fields & PCI_FILL_SIZES) ? p->size[i] : 0;
407 pciaddr_t ioflg = (p->known_fields & PCI_FILL_IO_FLAGS) ? p->flags[i] : 0;
408 u32 flg = (p->known_fields & PCI_FILL_IO_FLAGS) ? ioflg_to_pciflg(ioflg) : without_config_data ? 0 : get_conf_long(d, PCI_BASE_ADDRESS_0 + 4*i);
414 if (flg == 0xffffffff)
416 if (!pos && !flg && !len)
420 printf("\tRegion %d: ", i);
424 /* Detect virtual regions, which are reported by the OS, but unassigned in the device */
425 if ((p->known_fields & PCI_FILL_IO_FLAGS) && !without_config_data)
427 /* Read address as seen by the hardware */
428 hw_lower = get_conf_long(d, PCI_BASE_ADDRESS_0 + 4*i);
429 if ((hw_lower & PCI_BASE_ADDRESS_SPACE) == (ioflg_to_pciflg(ioflg) & PCI_BASE_ADDRESS_SPACE))
431 if ((ioflg & PCI_IORESOURCE_TYPE_BITS) == PCI_IORESOURCE_MEM &&
432 (hw_lower & PCI_BASE_ADDRESS_MEM_TYPE_MASK) == PCI_BASE_ADDRESS_MEM_TYPE_64)
437 hw_upper = get_conf_long(d, PCI_BASE_ADDRESS_0 + 4*i + 1);
439 if (pos && !hw_lower && !hw_upper && !(ioflg & PCI_IORESOURCE_PCI_EA_BEI))
444 /* Print base address */
445 if (flg & PCI_BASE_ADDRESS_SPACE_IO)
447 pciaddr_t a = pos & PCI_BASE_ADDRESS_IO_MASK;
448 printf("I/O ports at ");
449 if (a || (cmd & PCI_COMMAND_IO))
450 printf(PCIADDR_PORT_FMT, a);
454 printf("<unassigned>");
456 printf(" [virtual]");
457 else if (!(cmd & PCI_COMMAND_IO))
458 printf(" [disabled]");
462 int t = flg & PCI_BASE_ADDRESS_MEM_TYPE_MASK;
463 pciaddr_t a = pos & PCI_ADDR_MEM_MASK;
465 printf("Memory at ");
467 printf("<broken-64-bit-slot>");
469 printf(PCIADDR_T_FMT, a);
470 else if (hw_lower || hw_upper)
473 printf("<unassigned>");
474 printf(" (%s, %sprefetchable)",
475 (t == PCI_BASE_ADDRESS_MEM_TYPE_32) ? "32-bit" :
476 (t == PCI_BASE_ADDRESS_MEM_TYPE_64) ? "64-bit" :
477 (t == PCI_BASE_ADDRESS_MEM_TYPE_1M) ? "low-1M" : "type 3",
478 (flg & PCI_BASE_ADDRESS_MEM_PREFETCH) ? "" : "non-");
480 printf(" [virtual]");
481 else if (!(cmd & PCI_COMMAND_MEMORY))
482 printf(" [disabled]");
485 if (ioflg & PCI_IORESOURCE_PCI_EA_BEI)
486 printf(" [enhanced]");
494 show_rom(struct device *d, int reg)
496 struct pci_dev *p = d->dev;
497 pciaddr_t rom = p->rom_base_addr;
498 pciaddr_t len = (p->known_fields & PCI_FILL_SIZES) ? p->rom_size : 0;
499 pciaddr_t ioflg = (p->known_fields & PCI_FILL_IO_FLAGS) ? p->rom_flags : 0;
500 u32 flg = reg >= 0 ? get_conf_long(d, reg) : ioflg_to_pciflg(ioflg);
501 word cmd = reg >= 0 ? get_conf_word(d, PCI_COMMAND) : PCI_COMMAND_MEMORY;
504 if (!rom && !flg && !len)
507 if (reg >= 0 && (rom & PCI_ROM_ADDRESS_MASK) && !(flg & PCI_ROM_ADDRESS_MASK) && !(ioflg & PCI_IORESOURCE_PCI_EA_BEI))
513 printf("\tExpansion ROM at ");
514 if (rom & PCI_ROM_ADDRESS_MASK)
515 printf(PCIADDR_T_FMT, rom & PCI_ROM_ADDRESS_MASK);
516 else if (flg & PCI_ROM_ADDRESS_MASK)
519 printf("<unassigned>");
522 printf(" [virtual]");
524 if (!(flg & PCI_ROM_ADDRESS_ENABLE))
525 printf(" [disabled]");
526 else if (!virtual && !(cmd & PCI_COMMAND_MEMORY))
527 printf(" [disabled by cmd]");
529 if (ioflg & PCI_IORESOURCE_PCI_EA_BEI)
530 printf(" [enhanced]");
537 show_htype0(struct device *d)
540 show_rom(d, PCI_ROM_ADDRESS);
541 show_caps(d, PCI_CAPABILITY_LIST);
545 show_htype1(struct device *d)
547 struct pci_dev *p = d->dev;
548 u32 io_base = get_conf_byte(d, PCI_IO_BASE);
549 u32 io_limit = get_conf_byte(d, PCI_IO_LIMIT);
550 u32 io_type = io_base & PCI_IO_RANGE_TYPE_MASK;
551 u32 mem_base = get_conf_word(d, PCI_MEMORY_BASE);
552 u32 mem_limit = get_conf_word(d, PCI_MEMORY_LIMIT);
553 u32 mem_type = mem_base & PCI_MEMORY_RANGE_TYPE_MASK;
554 u32 pref_base = get_conf_word(d, PCI_PREF_MEMORY_BASE);
555 u32 pref_limit = get_conf_word(d, PCI_PREF_MEMORY_LIMIT);
556 u32 pref_type = pref_base & PCI_PREF_RANGE_TYPE_MASK;
557 word sec_stat = get_conf_word(d, PCI_SEC_STATUS);
558 word brc = get_conf_word(d, PCI_BRIDGE_CONTROL);
559 int io_disabled = (p->known_fields & PCI_FILL_BRIDGE_BASES) && !p->bridge_size[0];
560 int mem_disabled = (p->known_fields & PCI_FILL_BRIDGE_BASES) && !p->bridge_size[1];
561 int pref_disabled = (p->known_fields & PCI_FILL_BRIDGE_BASES) && !p->bridge_size[2];
562 int io_bits, pref_bits;
565 printf("\tBus: primary=%02x, secondary=%02x, subordinate=%02x, sec-latency=%d\n",
566 get_conf_byte(d, PCI_PRIMARY_BUS),
567 get_conf_byte(d, PCI_SECONDARY_BUS),
568 get_conf_byte(d, PCI_SUBORDINATE_BUS),
569 get_conf_byte(d, PCI_SEC_LATENCY_TIMER));
571 if ((p->known_fields & PCI_FILL_BRIDGE_BASES) && !io_disabled)
573 io_base = p->bridge_base_addr[0] & PCI_IO_RANGE_MASK;
574 io_limit = io_base + p->bridge_size[0] - 1;
575 io_type = p->bridge_base_addr[0] & PCI_IO_RANGE_TYPE_MASK;
576 io_bits = (io_type == PCI_IO_RANGE_TYPE_32) ? 32 : 16;
577 show_range("\tI/O behind bridge", io_base, io_limit, io_bits, io_disabled);
579 else if (io_type != (io_limit & PCI_IO_RANGE_TYPE_MASK) ||
580 (io_type != PCI_IO_RANGE_TYPE_16 && io_type != PCI_IO_RANGE_TYPE_32))
581 printf("\t!!! Unknown I/O range types %x/%x\n", io_base, io_limit);
584 io_base = (io_base & PCI_IO_RANGE_MASK) << 8;
585 io_limit = (io_limit & PCI_IO_RANGE_MASK) << 8;
586 if (io_type == PCI_IO_RANGE_TYPE_32)
588 io_base |= (get_conf_word(d, PCI_IO_BASE_UPPER16) << 16);
589 io_limit |= (get_conf_word(d, PCI_IO_LIMIT_UPPER16) << 16);
591 /* I/O is unsupported if both base and limit are zeros and resource is disabled */
592 if (!(io_base == 0x0 && io_limit == 0x0 && io_disabled))
595 io_bits = (io_type == PCI_IO_RANGE_TYPE_32) ? 32 : 16;
596 show_range("\tI/O behind bridge", io_base, io_limit, io_bits, io_disabled);
600 if ((p->known_fields & PCI_FILL_BRIDGE_BASES) && !mem_disabled)
602 mem_base = p->bridge_base_addr[1] & PCI_MEMORY_RANGE_MASK;
603 mem_limit = mem_base + p->bridge_size[1] - 1;
604 show_range("\tMemory behind bridge", mem_base, mem_limit, 32, mem_disabled);
606 else if (mem_type != (mem_limit & PCI_MEMORY_RANGE_TYPE_MASK) ||
608 printf("\t!!! Unknown memory range types %x/%x\n", mem_base, mem_limit);
611 mem_base = (mem_base & PCI_MEMORY_RANGE_MASK) << 16;
612 mem_limit = (mem_limit & PCI_MEMORY_RANGE_MASK) << 16;
613 show_range("\tMemory behind bridge", mem_base, mem_limit + 0xfffff, 32, mem_disabled);
616 if ((p->known_fields & PCI_FILL_BRIDGE_BASES) && !pref_disabled)
618 u64 pref_base_64 = p->bridge_base_addr[2] & PCI_MEMORY_RANGE_MASK;
619 u64 pref_limit_64 = pref_base_64 + p->bridge_size[2] - 1;
620 pref_type = p->bridge_base_addr[2] & PCI_MEMORY_RANGE_TYPE_MASK;
621 pref_bits = (pref_type == PCI_PREF_RANGE_TYPE_64) ? 64 : 32;
622 show_range("\tPrefetchable memory behind bridge", pref_base_64, pref_limit_64, pref_bits, pref_disabled);
624 else if (pref_type != (pref_limit & PCI_PREF_RANGE_TYPE_MASK) ||
625 (pref_type != PCI_PREF_RANGE_TYPE_32 && pref_type != PCI_PREF_RANGE_TYPE_64))
626 printf("\t!!! Unknown prefetchable memory range types %x/%x\n", pref_base, pref_limit);
629 u64 pref_base_64 = (pref_base & PCI_PREF_RANGE_MASK) << 16;
630 u64 pref_limit_64 = (pref_limit & PCI_PREF_RANGE_MASK) << 16;
631 if (pref_type == PCI_PREF_RANGE_TYPE_64)
633 pref_base_64 |= (u64) get_conf_long(d, PCI_PREF_BASE_UPPER32) << 32;
634 pref_limit_64 |= (u64) get_conf_long(d, PCI_PREF_LIMIT_UPPER32) << 32;
636 /* Prefetchable memory is unsupported if both base and limit are zeros and resource is disabled */
637 if (!(pref_base_64 == 0x0 && pref_limit_64 == 0x0 && pref_disabled))
639 pref_limit_64 += 0xfffff;
640 pref_bits = (pref_type == PCI_PREF_RANGE_TYPE_64) ? 64 : 32;
641 show_range("\tPrefetchable memory behind bridge", pref_base_64, pref_limit_64, pref_bits, pref_disabled);
646 printf("\tSecondary status: 66MHz%c FastB2B%c ParErr%c DEVSEL=%s >TAbort%c <TAbort%c <MAbort%c <SERR%c <PERR%c\n",
647 FLAG(sec_stat, PCI_STATUS_66MHZ),
648 FLAG(sec_stat, PCI_STATUS_FAST_BACK),
649 FLAG(sec_stat, PCI_STATUS_PARITY),
650 ((sec_stat & PCI_STATUS_DEVSEL_MASK) == PCI_STATUS_DEVSEL_SLOW) ? "slow" :
651 ((sec_stat & PCI_STATUS_DEVSEL_MASK) == PCI_STATUS_DEVSEL_MEDIUM) ? "medium" :
652 ((sec_stat & PCI_STATUS_DEVSEL_MASK) == PCI_STATUS_DEVSEL_FAST) ? "fast" : "??",
653 FLAG(sec_stat, PCI_STATUS_SIG_TARGET_ABORT),
654 FLAG(sec_stat, PCI_STATUS_REC_TARGET_ABORT),
655 FLAG(sec_stat, PCI_STATUS_REC_MASTER_ABORT),
656 FLAG(sec_stat, PCI_STATUS_SIG_SYSTEM_ERROR),
657 FLAG(sec_stat, PCI_STATUS_DETECTED_PARITY));
659 show_rom(d, PCI_ROM_ADDRESS1);
663 printf("\tBridgeCtl: Parity%c SERR%c NoISA%c VGA%c VGA16%c MAbort%c >Reset%c FastB2B%c\n",
664 FLAG(brc, PCI_BRIDGE_CTL_PARITY),
665 FLAG(brc, PCI_BRIDGE_CTL_SERR),
666 FLAG(brc, PCI_BRIDGE_CTL_NO_ISA),
667 FLAG(brc, PCI_BRIDGE_CTL_VGA),
668 FLAG(brc, PCI_BRIDGE_CTL_VGA_16BIT),
669 FLAG(brc, PCI_BRIDGE_CTL_MASTER_ABORT),
670 FLAG(brc, PCI_BRIDGE_CTL_BUS_RESET),
671 FLAG(brc, PCI_BRIDGE_CTL_FAST_BACK));
672 printf("\t\tPriDiscTmr%c SecDiscTmr%c DiscTmrStat%c DiscTmrSERREn%c\n",
673 FLAG(brc, PCI_BRIDGE_CTL_PRI_DISCARD_TIMER),
674 FLAG(brc, PCI_BRIDGE_CTL_SEC_DISCARD_TIMER),
675 FLAG(brc, PCI_BRIDGE_CTL_DISCARD_TIMER_STATUS),
676 FLAG(brc, PCI_BRIDGE_CTL_DISCARD_TIMER_SERR_EN));
679 show_caps(d, PCI_CAPABILITY_LIST);
683 show_htype2(struct device *d)
686 word cmd = get_conf_word(d, PCI_COMMAND);
687 word brc = get_conf_word(d, PCI_CB_BRIDGE_CONTROL);
689 int verb = verbose > 2;
692 printf("\tBus: primary=%02x, secondary=%02x, subordinate=%02x, sec-latency=%d\n",
693 get_conf_byte(d, PCI_CB_PRIMARY_BUS),
694 get_conf_byte(d, PCI_CB_CARD_BUS),
695 get_conf_byte(d, PCI_CB_SUBORDINATE_BUS),
696 get_conf_byte(d, PCI_CB_LATENCY_TIMER));
700 u32 base = get_conf_long(d, PCI_CB_MEMORY_BASE_0 + p);
701 u32 limit = get_conf_long(d, PCI_CB_MEMORY_LIMIT_0 + p);
702 limit = limit + 0xfff;
703 if (base <= limit || verb)
704 printf("\tMemory window %d: %08x-%08x%s%s\n", i, base, limit,
705 (cmd & PCI_COMMAND_MEMORY) ? "" : " [disabled]",
706 (brc & (PCI_CB_BRIDGE_CTL_PREFETCH_MEM0 << i)) ? " (prefetchable)" : "");
711 u32 base = get_conf_long(d, PCI_CB_IO_BASE_0 + p);
712 u32 limit = get_conf_long(d, PCI_CB_IO_LIMIT_0 + p);
713 if (!(base & PCI_IO_RANGE_TYPE_32))
718 base &= PCI_CB_IO_RANGE_MASK;
719 limit = (limit & PCI_CB_IO_RANGE_MASK) + 3;
720 if (base <= limit || verb)
721 printf("\tI/O window %d: %08x-%08x%s\n", i, base, limit,
722 (cmd & PCI_COMMAND_IO) ? "" : " [disabled]");
725 if (get_conf_word(d, PCI_CB_SEC_STATUS) & PCI_STATUS_SIG_SYSTEM_ERROR)
726 printf("\tSecondary status: SERR\n");
728 printf("\tBridgeCtl: Parity%c SERR%c ISA%c VGA%c MAbort%c >Reset%c 16bInt%c PostWrite%c\n",
729 FLAG(brc, PCI_CB_BRIDGE_CTL_PARITY),
730 FLAG(brc, PCI_CB_BRIDGE_CTL_SERR),
731 FLAG(brc, PCI_CB_BRIDGE_CTL_ISA),
732 FLAG(brc, PCI_CB_BRIDGE_CTL_VGA),
733 FLAG(brc, PCI_CB_BRIDGE_CTL_MASTER_ABORT),
734 FLAG(brc, PCI_CB_BRIDGE_CTL_CB_RESET),
735 FLAG(brc, PCI_CB_BRIDGE_CTL_16BIT_INT),
736 FLAG(brc, PCI_CB_BRIDGE_CTL_POST_WRITES));
738 if (d->config_cached < 128)
740 printf("\t<access denied to the rest>\n");
744 exca = get_conf_word(d, PCI_CB_LEGACY_MODE_BASE);
746 printf("\t16-bit legacy interface ports at %04x\n", exca);
747 show_caps(d, PCI_CB_CAPABILITY_LIST);
751 show_htype_unknown(struct device *d)
753 struct pci_dev *p = d->dev;
754 u64 base, limit, flags;
758 if (pacc->buscentric)
762 for (i = 0; i < 4; i++)
764 if (!p->bridge_base_addr[i])
766 base = p->bridge_base_addr[i];
767 limit = base + p->bridge_size[i] - 1;
768 flags = p->bridge_flags[i];
769 if (flags & PCI_IORESOURCE_IO)
771 bits = (flags & PCI_IORESOURCE_IO_16BIT_ADDR) ? 16 : 32;
772 str = "\tI/O behind bridge";
774 else if (flags & PCI_IORESOURCE_MEM)
776 bits = (flags & PCI_IORESOURCE_MEM_64) ? 64 : 32;
777 if (flags & PCI_IORESOURCE_PREFETCH)
778 str = "\tPrefetchable memory behind bridge";
780 str = "\tMemory behind bridge";
785 str = "\tUnknown resource behind bridge";
787 show_range(str, base, limit, bits, 0);
793 show_verbose(struct device *d)
795 struct pci_dev *p = d->dev;
796 int unknown_config_data = 0;
797 word class = p->device_class;
798 byte htype = d->no_config_access ? -1 : (get_conf_byte(d, PCI_HEADER_TYPE) & 0x7f);
800 byte max_lat, min_gnt;
801 char *dt_node, *iommu_group;
805 pci_fill_info(p, PCI_FILL_IRQ | PCI_FILL_BASES | PCI_FILL_ROM_BASE | PCI_FILL_SIZES |
806 PCI_FILL_PHYS_SLOT | PCI_FILL_NUMA_NODE | PCI_FILL_DT_NODE | PCI_FILL_IOMMU_GROUP |
807 PCI_FILL_BRIDGE_BASES | PCI_FILL_CLASS_EXT | PCI_FILL_SUBSYS);
811 case PCI_HEADER_TYPE_NORMAL:
812 if (class == PCI_CLASS_BRIDGE_PCI)
813 printf("\t!!! Invalid class %04x for header type %02x\n", class, htype);
814 bist = get_conf_byte(d, PCI_BIST);
815 max_lat = get_conf_byte(d, PCI_MAX_LAT);
816 min_gnt = get_conf_byte(d, PCI_MIN_GNT);
818 case PCI_HEADER_TYPE_BRIDGE:
819 if ((class >> 8) != PCI_BASE_CLASS_BRIDGE)
820 printf("\t!!! Invalid class %04x for header type %02x\n", class, htype);
821 bist = get_conf_byte(d, PCI_BIST);
822 min_gnt = max_lat = 0;
824 case PCI_HEADER_TYPE_CARDBUS:
825 if ((class >> 8) != PCI_BASE_CLASS_BRIDGE)
826 printf("\t!!! Invalid class %04x for header type %02x\n", class, htype);
827 bist = get_conf_byte(d, PCI_BIST);
828 min_gnt = max_lat = 0;
831 if (!d->no_config_access)
832 printf("\t!!! Unknown header type %02x\n", htype);
834 min_gnt = max_lat = 0;
835 unknown_config_data = 1;
839 printf("\tPhysical Slot: %s\n", p->phy_slot);
841 if (dt_node = pci_get_string_property(p, PCI_FILL_DT_NODE))
842 printf("\tDevice tree node: %s\n", dt_node);
844 if (!unknown_config_data && verbose > 1)
846 word cmd = get_conf_word(d, PCI_COMMAND);
847 word status = get_conf_word(d, PCI_STATUS);
848 printf("\tControl: I/O%c Mem%c BusMaster%c SpecCycle%c MemWINV%c VGASnoop%c ParErr%c Stepping%c SERR%c FastB2B%c DisINTx%c\n",
849 FLAG(cmd, PCI_COMMAND_IO),
850 FLAG(cmd, PCI_COMMAND_MEMORY),
851 FLAG(cmd, PCI_COMMAND_MASTER),
852 FLAG(cmd, PCI_COMMAND_SPECIAL),
853 FLAG(cmd, PCI_COMMAND_INVALIDATE),
854 FLAG(cmd, PCI_COMMAND_VGA_PALETTE),
855 FLAG(cmd, PCI_COMMAND_PARITY),
856 FLAG(cmd, PCI_COMMAND_WAIT),
857 FLAG(cmd, PCI_COMMAND_SERR),
858 FLAG(cmd, PCI_COMMAND_FAST_BACK),
859 FLAG(cmd, PCI_COMMAND_DISABLE_INTx));
860 printf("\tStatus: Cap%c 66MHz%c UDF%c FastB2B%c ParErr%c DEVSEL=%s >TAbort%c <TAbort%c <MAbort%c >SERR%c <PERR%c INTx%c\n",
861 FLAG(status, PCI_STATUS_CAP_LIST),
862 FLAG(status, PCI_STATUS_66MHZ),
863 FLAG(status, PCI_STATUS_UDF),
864 FLAG(status, PCI_STATUS_FAST_BACK),
865 FLAG(status, PCI_STATUS_PARITY),
866 ((status & PCI_STATUS_DEVSEL_MASK) == PCI_STATUS_DEVSEL_SLOW) ? "slow" :
867 ((status & PCI_STATUS_DEVSEL_MASK) == PCI_STATUS_DEVSEL_MEDIUM) ? "medium" :
868 ((status & PCI_STATUS_DEVSEL_MASK) == PCI_STATUS_DEVSEL_FAST) ? "fast" : "??",
869 FLAG(status, PCI_STATUS_SIG_TARGET_ABORT),
870 FLAG(status, PCI_STATUS_REC_TARGET_ABORT),
871 FLAG(status, PCI_STATUS_REC_MASTER_ABORT),
872 FLAG(status, PCI_STATUS_SIG_SYSTEM_ERROR),
873 FLAG(status, PCI_STATUS_DETECTED_PARITY),
874 FLAG(status, PCI_STATUS_INTx));
875 if (cmd & PCI_COMMAND_MASTER)
877 byte latency = get_conf_byte(d, PCI_LATENCY_TIMER);
878 byte cache_line = get_conf_byte(d, PCI_CACHE_LINE_SIZE);
879 printf("\tLatency: %d", latency);
880 if (min_gnt || max_lat)
884 printf("%dns min", min_gnt*250);
885 if (min_gnt && max_lat)
888 printf("%dns max", max_lat*250);
892 printf(", Cache Line Size: %d bytes", cache_line * 4);
899 byte int_pin = unknown_config_data ? 0 : get_conf_byte(d, PCI_INTERRUPT_PIN);
900 if (int_pin || p->irq)
901 printf("\tInterrupt: pin %c routed to IRQ " PCIIRQ_FMT "\n",
902 (int_pin ? 'A' + int_pin - 1 : '?'), p->irq);
903 if (p->numa_node != -1)
904 printf("\tNUMA node: %d\n", p->numa_node);
905 if (iommu_group = pci_get_string_property(p, PCI_FILL_IOMMU_GROUP))
906 printf("\tIOMMU group: %s\n", iommu_group);
909 if (!unknown_config_data && verbose <= 1)
911 word cmd = get_conf_word(d, PCI_COMMAND);
912 word status = get_conf_word(d, PCI_STATUS);
913 byte latency = get_conf_byte(d, PCI_LATENCY_TIMER);
915 if (cmd & PCI_COMMAND_MASTER)
916 printf("bus master, ");
917 if (cmd & PCI_COMMAND_VGA_PALETTE)
918 printf("VGA palette snoop, ");
919 if (cmd & PCI_COMMAND_WAIT)
920 printf("stepping, ");
921 if (cmd & PCI_COMMAND_FAST_BACK)
922 printf("fast Back2Back, ");
923 if (status & PCI_STATUS_66MHZ)
925 if (status & PCI_STATUS_UDF)
926 printf("user-definable features, ");
928 ((status & PCI_STATUS_DEVSEL_MASK) == PCI_STATUS_DEVSEL_SLOW) ? "slow" :
929 ((status & PCI_STATUS_DEVSEL_MASK) == PCI_STATUS_DEVSEL_MEDIUM) ? "medium" :
930 ((status & PCI_STATUS_DEVSEL_MASK) == PCI_STATUS_DEVSEL_FAST) ? "fast" : "??");
931 if (cmd & PCI_COMMAND_MASTER)
932 printf(", latency %d", latency);
934 printf(", IRQ " PCIIRQ_FMT, p->irq);
935 if (p->numa_node != -1)
936 printf(", NUMA node %d", p->numa_node);
937 if (iommu_group = pci_get_string_property(p, PCI_FILL_IOMMU_GROUP))
938 printf(", IOMMU group %s", iommu_group);
942 if (bist & PCI_BIST_CAPABLE)
944 if (bist & PCI_BIST_START)
945 printf("\tBIST is running\n");
947 printf("\tBIST result: %02x\n", bist & PCI_BIST_CODE_MASK);
952 case PCI_HEADER_TYPE_NORMAL:
955 case PCI_HEADER_TYPE_BRIDGE:
958 case PCI_HEADER_TYPE_CARDBUS:
962 show_htype_unknown(d);
966 /*** Machine-readable dumps ***/
969 show_hex_dump(struct device *d)
973 if (d->no_config_access)
975 printf("WARNING: Cannot show hex-dump of the config space\n");
979 cnt = d->config_cached;
980 if (opt_hex >= 3 && config_fetch(d, cnt, 256-cnt))
983 if (opt_hex >= 4 && config_fetch(d, 256, 4096-256))
987 for (i=0; i<cnt; i++)
991 printf(" %02x", get_conf_byte(d, i));
998 print_shell_escaped(char *c)
1003 if (*c == '"' || *c == '\\')
1011 show_machine(struct device *d)
1013 struct pci_dev *p = d->dev;
1014 char classbuf[256], vendbuf[256], devbuf[256], svbuf[256], sdbuf[256];
1015 char *dt_node, *iommu_group;
1019 pci_fill_info(p, PCI_FILL_PHYS_SLOT | PCI_FILL_NUMA_NODE | PCI_FILL_DT_NODE | PCI_FILL_IOMMU_GROUP);
1020 printf((opt_machine >= 2) ? "Slot:\t" : "Device:\t");
1023 printf("Class:\t%s\n",
1024 pci_lookup_name(pacc, classbuf, sizeof(classbuf), PCI_LOOKUP_CLASS, p->device_class));
1025 printf("Vendor:\t%s\n",
1026 pci_lookup_name(pacc, vendbuf, sizeof(vendbuf), PCI_LOOKUP_VENDOR, p->vendor_id, p->device_id));
1027 printf("Device:\t%s\n",
1028 pci_lookup_name(pacc, devbuf, sizeof(devbuf), PCI_LOOKUP_DEVICE, p->vendor_id, p->device_id));
1029 if ((p->known_fields & PCI_FILL_SUBSYS) &&
1030 p->subsys_vendor_id && p->subsys_vendor_id != 0xffff)
1032 printf("SVendor:\t%s\n",
1033 pci_lookup_name(pacc, svbuf, sizeof(svbuf), PCI_LOOKUP_SUBSYSTEM | PCI_LOOKUP_VENDOR, p->subsys_vendor_id));
1034 printf("SDevice:\t%s\n",
1035 pci_lookup_name(pacc, sdbuf, sizeof(sdbuf), PCI_LOOKUP_SUBSYSTEM | PCI_LOOKUP_DEVICE, p->vendor_id, p->device_id, p->subsys_vendor_id, p->subsys_id));
1038 printf("PhySlot:\t%s\n", p->phy_slot);
1039 if ((p->known_fields & PCI_FILL_CLASS_EXT) && p->rev_id)
1040 printf("Rev:\t%02x\n", p->rev_id);
1041 if (p->known_fields & PCI_FILL_CLASS_EXT)
1042 printf("ProgIf:\t%02x\n", p->prog_if);
1044 show_kernel_machine(d);
1045 if (p->numa_node != -1)
1046 printf("NUMANode:\t%d\n", p->numa_node);
1047 if (dt_node = pci_get_string_property(p, PCI_FILL_DT_NODE))
1048 printf("DTNode:\t%s\n", dt_node);
1049 if (iommu_group = pci_get_string_property(p, PCI_FILL_IOMMU_GROUP))
1050 printf("IOMMUGroup:\t%s\n", iommu_group);
1055 print_shell_escaped(pci_lookup_name(pacc, classbuf, sizeof(classbuf), PCI_LOOKUP_CLASS, p->device_class));
1056 print_shell_escaped(pci_lookup_name(pacc, vendbuf, sizeof(vendbuf), PCI_LOOKUP_VENDOR, p->vendor_id, p->device_id));
1057 print_shell_escaped(pci_lookup_name(pacc, devbuf, sizeof(devbuf), PCI_LOOKUP_DEVICE, p->vendor_id, p->device_id));
1058 if ((p->known_fields & PCI_FILL_CLASS_EXT) && p->rev_id)
1059 printf(" -r%02x", p->rev_id);
1060 if (p->known_fields & PCI_FILL_CLASS_EXT)
1061 printf(" -p%02x", p->prog_if);
1062 if ((p->known_fields & PCI_FILL_SUBSYS) &&
1063 p->subsys_vendor_id && p->subsys_vendor_id != 0xffff)
1065 print_shell_escaped(pci_lookup_name(pacc, svbuf, sizeof(svbuf), PCI_LOOKUP_SUBSYSTEM | PCI_LOOKUP_VENDOR, p->subsys_vendor_id));
1066 print_shell_escaped(pci_lookup_name(pacc, sdbuf, sizeof(sdbuf), PCI_LOOKUP_SUBSYSTEM | PCI_LOOKUP_DEVICE, p->vendor_id, p->device_id, p->subsys_vendor_id, p->subsys_id));
1069 printf(" \"\" \"\"");
1074 /*** Main show function ***/
1077 show_device(struct device *d)
1087 if (opt_kernel || verbose)
1092 if (verbose || opt_hex)
1101 for (d=first_dev; d; d=d->next)
1102 if (pci_filter_match(&filter, d->dev))
1109 main(int argc, char **argv)
1114 if (argc == 2 && !strcmp(argv[1], "--version"))
1116 puts("lspci version " PCIUTILS_VERSION);
1122 pci_filter_init(pacc, &filter);
1124 while ((i = getopt(argc, argv, options)) != -1)
1128 pacc->numeric_ids++;
1134 pacc->buscentric = 1;
1137 if (msg = pci_filter_parse_slot(&filter, optarg))
1142 if (msg = pci_filter_parse_id(&filter, optarg))
1158 pci_set_name_list_path(pacc, optarg, 0);
1164 opt_pcimap = optarg;
1187 die("DNS queries are not available in this version");
1190 if (parse_generic_option(i, pacc, optarg))
1193 fprintf(stderr, help_msg, pacc->id_file_name);
1201 pacc->id_lookup_mode |= PCI_LOOKUP_NETWORK;
1202 if (opt_query_dns > 1)
1203 pacc->id_lookup_mode |= PCI_LOOKUP_REFRESH_CACHE;
1206 pacc->id_lookup_mode |= PCI_LOOKUP_NETWORK | PCI_LOOKUP_SKIP_LOCAL;
1212 die("Bus mapping mode does not recognize bus topology");
1222 show_forest(opt_filter ? &filter : NULL);
1226 show_kernel_cleanup();
1229 return (seen_errors ? 2 : 0);