2 * The PCI Utilities -- List All PCI Devices
4 * Copyright (c) 1997--2018 Martin Mares <mj@ucw.cz>
6 * Can be freely distributed and used under the terms of the GNU GPL.
18 int verbose; /* Show detailed information */
19 static int opt_hex; /* Show contents of config space as hexadecimal numbers */
20 struct pci_filter filter; /* Device filter */
21 static int opt_tree; /* Show bus tree */
22 static int opt_path; /* Show bridge path */
23 static int opt_machine; /* Generate machine-readable output */
24 static int opt_map_mode; /* Bus mapping mode enabled */
25 static int opt_domains; /* Show domain numbers (0=disabled, 1=auto-detected, 2=requested) */
26 static int opt_kernel; /* Show kernel drivers */
27 static int opt_query_dns; /* Query the DNS (0=disabled, 1=enabled, 2=refresh cache) */
28 static int opt_query_all; /* Query the DNS for all entries */
29 char *opt_pcimap; /* Override path to Linux modules.pcimap */
31 const char program_name[] = "lspci";
33 static char options[] = "nvbxs:d:tPi:mgp:qkMDQ" GENERIC_OPTIONS ;
35 static char help_msg[] =
36 "Usage: lspci [<switches>]\n"
38 "Basic display modes:\n"
39 "-mm\t\tProduce machine-readable output (single -m for an obsolete format)\n"
40 "-t\t\tShow bus tree\n"
43 "-v\t\tBe verbose (-vv for very verbose)\n"
45 "-k\t\tShow kernel drivers handling each device\n"
47 "-x\t\tShow hex-dump of the standard part of the config space\n"
48 "-xxx\t\tShow hex-dump of the whole config space (dangerous; root only)\n"
49 "-xxxx\t\tShow hex-dump of the 4096-byte extended config space (root only)\n"
50 "-b\t\tBus-centric view (addresses and IRQ's as seen by the bus)\n"
51 "-D\t\tAlways show domain numbers\n"
52 "-P\t\tDisplay bridge path in addition to bus and device number\n"
53 "-PP\t\tDisplay bus path in addition to bus and device number\n"
55 "Resolving of device ID's to names:\n"
56 "-n\t\tShow numeric ID's\n"
57 "-nn\t\tShow both textual and numeric ID's (names & numbers)\n"
59 "-q\t\tQuery the PCI ID database for unknown ID's via DNS\n"
60 "-qq\t\tAs above, but re-query locally cached entries\n"
61 "-Q\t\tQuery the PCI ID database for all ID's via DNS\n"
64 "Selection of devices:\n"
65 "-s [[[[<domain>]:]<bus>]:][<slot>][.[<func>]]\tShow only devices in selected slots\n"
66 "-d [<vendor>]:[<device>][:<class>]\t\tShow only devices with specified ID's\n"
69 "-i <file>\tUse specified ID database instead of %s\n"
71 "-p <file>\tLook up kernel modules in a given file instead of default modules.pcimap\n"
73 "-M\t\tEnable `bus mapping' mode (dangerous; root only)\n"
75 "PCI access options:\n"
79 /*** Our view of the PCI bus ***/
81 struct pci_access *pacc;
82 struct device *first_dev;
83 static int seen_errors;
86 config_fetch(struct device *d, unsigned int pos, unsigned int len)
88 unsigned int end = pos+len;
91 while (pos < d->config_bufsize && len && d->present[pos])
93 while (pos+len <= d->config_bufsize && len && d->present[pos+len-1])
98 if (end > d->config_bufsize)
100 int orig_size = d->config_bufsize;
101 while (end > d->config_bufsize)
102 d->config_bufsize *= 2;
103 d->config = xrealloc(d->config, d->config_bufsize);
104 d->present = xrealloc(d->present, d->config_bufsize);
105 memset(d->present + orig_size, 0, d->config_bufsize - orig_size);
107 result = pci_read_block(d->dev, pos, d->config + pos, len);
109 memset(d->present + pos, 1, len);
114 scan_device(struct pci_dev *p)
118 if (p->domain && !opt_domains)
120 if (!pci_filter_match(&filter, p))
122 d = xmalloc(sizeof(struct device));
123 memset(d, 0, sizeof(*d));
125 d->config_cached = d->config_bufsize = 64;
126 d->config = xmalloc(64);
127 d->present = xmalloc(64);
128 memset(d->present, 1, 64);
129 if (!pci_read_block(p, 0, d->config, 64))
131 fprintf(stderr, "lspci: Unable to read the standard configuration space header of device %04x:%02x:%02x.%d\n",
132 p->domain, p->bus, p->dev, p->func);
136 if ((d->config[PCI_HEADER_TYPE] & 0x7f) == PCI_HEADER_TYPE_CARDBUS)
138 /* For cardbus bridges, we need to fetch 64 bytes more to get the
139 * full standard header... */
140 if (config_fetch(d, 64, 64))
141 d->config_cached += 64;
143 pci_setup_cache(p, d->config, d->config_cached);
144 pci_fill_info(p, PCI_FILL_IDENT | PCI_FILL_CLASS);
155 for (p=pacc->devices; p; p=p->next)
156 if (d = scan_device(p))
163 /*** Config space accesses ***/
166 check_conf_range(struct device *d, unsigned int pos, unsigned int len)
169 if (!d->present[pos])
170 die("Internal bug: Accessing non-read configuration byte at position %x", pos);
176 get_conf_byte(struct device *d, unsigned int pos)
178 check_conf_range(d, pos, 1);
179 return d->config[pos];
183 get_conf_word(struct device *d, unsigned int pos)
185 check_conf_range(d, pos, 2);
186 return d->config[pos] | (d->config[pos+1] << 8);
190 get_conf_long(struct device *d, unsigned int pos)
192 check_conf_range(d, pos, 4);
193 return d->config[pos] |
194 (d->config[pos+1] << 8) |
195 (d->config[pos+2] << 16) |
196 (d->config[pos+3] << 24);
202 compare_them(const void *A, const void *B)
204 const struct pci_dev *a = (*(const struct device **)A)->dev;
205 const struct pci_dev *b = (*(const struct device **)B)->dev;
207 if (a->domain < b->domain)
209 if (a->domain > b->domain)
219 if (a->func < b->func)
221 if (a->func > b->func)
229 struct device **index, **h, **last_dev;
234 for (d=first_dev; d; d=d->next)
236 h = index = alloca(sizeof(struct device *) * cnt);
237 for (d=first_dev; d; d=d->next)
239 qsort(index, cnt, sizeof(struct device *), compare_them);
240 last_dev = &first_dev;
245 last_dev = &(*h)->next;
251 /*** Normal output ***/
254 show_slot_path(struct device *d)
256 struct pci_dev *p = d->dev;
260 struct bus *bus = d->parent_bus;
261 struct bridge *br = bus->parent_bridge;
263 if (br && br->br_dev)
265 show_slot_path(br->br_dev);
267 printf("/%02x:%02x.%d", p->bus, p->dev, p->func);
269 printf("/%02x.%d", p->dev, p->func);
273 printf("%02x:%02x.%d", p->bus, p->dev, p->func);
277 show_slot_name(struct device *d)
279 struct pci_dev *p = d->dev;
281 if (!opt_machine ? opt_domains : (p->domain || opt_domains >= 2))
282 printf("%04x:", p->domain);
287 get_subid(struct device *d, word *subvp, word *subdp)
289 byte htype = get_conf_byte(d, PCI_HEADER_TYPE) & 0x7f;
291 if (htype == PCI_HEADER_TYPE_NORMAL)
293 *subvp = get_conf_word(d, PCI_SUBSYSTEM_VENDOR_ID);
294 *subdp = get_conf_word(d, PCI_SUBSYSTEM_ID);
296 else if (htype == PCI_HEADER_TYPE_CARDBUS && d->config_cached >= 128)
298 *subvp = get_conf_word(d, PCI_CB_SUBSYSTEM_VENDOR_ID);
299 *subdp = get_conf_word(d, PCI_CB_SUBSYSTEM_ID);
302 *subvp = *subdp = 0xffff;
306 show_terse(struct device *d)
309 struct pci_dev *p = d->dev;
310 char classbuf[128], devbuf[128];
314 pci_lookup_name(pacc, classbuf, sizeof(classbuf),
317 pci_lookup_name(pacc, devbuf, sizeof(devbuf),
318 PCI_LOOKUP_VENDOR | PCI_LOOKUP_DEVICE,
319 p->vendor_id, p->device_id));
320 if (c = get_conf_byte(d, PCI_REVISION_ID))
321 printf(" (rev %02x)", c);
325 c = get_conf_byte(d, PCI_CLASS_PROG);
326 x = pci_lookup_name(pacc, devbuf, sizeof(devbuf),
327 PCI_LOOKUP_PROGIF | PCI_LOOKUP_NO_NUMBERS,
331 printf(" (prog-if %02x", c);
339 if (verbose || opt_kernel)
341 word subsys_v, subsys_d;
344 pci_fill_info(p, PCI_FILL_LABEL);
347 printf("\tDeviceName: %s", p->label);
348 get_subid(d, &subsys_v, &subsys_d);
349 if (subsys_v && subsys_v != 0xffff)
350 printf("\tSubsystem: %s\n",
351 pci_lookup_name(pacc, ssnamebuf, sizeof(ssnamebuf),
352 PCI_LOOKUP_SUBSYSTEM | PCI_LOOKUP_VENDOR | PCI_LOOKUP_DEVICE,
353 p->vendor_id, p->device_id, subsys_v, subsys_d));
357 /*** Verbose output ***/
362 static const char suffix[][2] = { "", "K", "M", "G", "T" };
366 for (i = 0; i < (sizeof(suffix) / sizeof(*suffix) - 1); i++) {
371 printf(" [size=%u%s]", (unsigned)x, suffix[i]);
375 show_range(char *prefix, u64 base, u64 limit, int is_64bit)
381 else if (verbose < 3)
383 printf("%s: None\n", prefix);
388 printf("%s: ", prefix);
390 printf("%016" PCI_U64_FMT_X "-%016" PCI_U64_FMT_X, base, limit);
392 printf("%08x-%08x", (unsigned) base, (unsigned) limit);
394 show_size(limit - base + 1);
401 show_bases(struct device *d, int cnt)
403 struct pci_dev *p = d->dev;
404 word cmd = get_conf_word(d, PCI_COMMAND);
408 for (i=0; i<cnt; i++)
410 pciaddr_t pos = p->base_addr[i];
411 pciaddr_t len = (p->known_fields & PCI_FILL_SIZES) ? p->size[i] : 0;
412 pciaddr_t ioflg = (p->known_fields & PCI_FILL_IO_FLAGS) ? p->flags[i] : 0;
413 u32 flg = get_conf_long(d, PCI_BASE_ADDRESS_0 + 4*i);
414 if (flg == 0xffffffff)
416 if (!pos && !flg && !len)
419 printf("\tRegion %d: ", i);
422 if (ioflg & PCI_IORESOURCE_PCI_EA_BEI)
423 printf("[enhanced] ");
424 else if (pos && !(flg & ((flg & PCI_BASE_ADDRESS_SPACE_IO) ? PCI_BASE_ADDRESS_IO_MASK : PCI_BASE_ADDRESS_MEM_MASK)))
426 /* Reported by the OS, but not by the device */
427 printf("[virtual] ");
431 if (flg & PCI_BASE_ADDRESS_SPACE_IO)
433 pciaddr_t a = pos & PCI_BASE_ADDRESS_IO_MASK;
434 printf("I/O ports at ");
435 if (a || (cmd & PCI_COMMAND_IO))
436 printf(PCIADDR_PORT_FMT, a);
437 else if (flg & PCI_BASE_ADDRESS_IO_MASK)
440 printf("<unassigned>");
441 if (!virtual && !(cmd & PCI_COMMAND_IO))
442 printf(" [disabled]");
446 int t = flg & PCI_BASE_ADDRESS_MEM_TYPE_MASK;
447 pciaddr_t a = pos & PCI_ADDR_MEM_MASK;
451 printf("Memory at ");
452 if (t == PCI_BASE_ADDRESS_MEM_TYPE_64)
456 printf("<invalid-64bit-slot>");
462 z = get_conf_long(d, PCI_BASE_ADDRESS_0 + 4*i);
468 printf(PCIADDR_T_FMT, a);
470 printf(((flg & PCI_BASE_ADDRESS_MEM_MASK) || z) ? "<ignored>" : "<unassigned>");
472 printf(" (%s, %sprefetchable)",
473 (t == PCI_BASE_ADDRESS_MEM_TYPE_32) ? "32-bit" :
474 (t == PCI_BASE_ADDRESS_MEM_TYPE_64) ? "64-bit" :
475 (t == PCI_BASE_ADDRESS_MEM_TYPE_1M) ? "low-1M" : "type 3",
476 (flg & PCI_BASE_ADDRESS_MEM_PREFETCH) ? "" : "non-");
477 if (!virtual && !(cmd & PCI_COMMAND_MEMORY))
478 printf(" [disabled]");
486 show_rom(struct device *d, int reg)
488 struct pci_dev *p = d->dev;
489 pciaddr_t rom = p->rom_base_addr;
490 pciaddr_t len = (p->known_fields & PCI_FILL_SIZES) ? p->rom_size : 0;
491 pciaddr_t ioflg = (p->known_fields & PCI_FILL_IO_FLAGS) ? p->rom_flags : 0;
492 u32 flg = get_conf_long(d, reg);
493 word cmd = get_conf_word(d, PCI_COMMAND);
496 if (!rom && !flg && !len)
499 if (ioflg & PCI_IORESOURCE_PCI_EA_BEI)
500 printf("[enhanced] ");
501 else if ((rom & PCI_ROM_ADDRESS_MASK) && !(flg & PCI_ROM_ADDRESS_MASK))
503 printf("[virtual] ");
507 printf("Expansion ROM at ");
508 if (rom & PCI_ROM_ADDRESS_MASK)
509 printf(PCIADDR_T_FMT, rom & PCI_ROM_ADDRESS_MASK);
510 else if (flg & PCI_ROM_ADDRESS_MASK)
513 printf("<unassigned>");
514 if (!(flg & PCI_ROM_ADDRESS_ENABLE))
515 printf(" [disabled]");
516 else if (!virtual && !(cmd & PCI_COMMAND_MEMORY))
517 printf(" [disabled by cmd]");
523 show_htype0(struct device *d)
526 show_rom(d, PCI_ROM_ADDRESS);
527 show_caps(d, PCI_CAPABILITY_LIST);
531 show_htype1(struct device *d)
533 u32 io_base = get_conf_byte(d, PCI_IO_BASE);
534 u32 io_limit = get_conf_byte(d, PCI_IO_LIMIT);
535 u32 io_type = io_base & PCI_IO_RANGE_TYPE_MASK;
536 u32 mem_base = get_conf_word(d, PCI_MEMORY_BASE);
537 u32 mem_limit = get_conf_word(d, PCI_MEMORY_LIMIT);
538 u32 mem_type = mem_base & PCI_MEMORY_RANGE_TYPE_MASK;
539 u32 pref_base = get_conf_word(d, PCI_PREF_MEMORY_BASE);
540 u32 pref_limit = get_conf_word(d, PCI_PREF_MEMORY_LIMIT);
541 u32 pref_type = pref_base & PCI_PREF_RANGE_TYPE_MASK;
542 word sec_stat = get_conf_word(d, PCI_SEC_STATUS);
543 word brc = get_conf_word(d, PCI_BRIDGE_CONTROL);
546 printf("\tBus: primary=%02x, secondary=%02x, subordinate=%02x, sec-latency=%d\n",
547 get_conf_byte(d, PCI_PRIMARY_BUS),
548 get_conf_byte(d, PCI_SECONDARY_BUS),
549 get_conf_byte(d, PCI_SUBORDINATE_BUS),
550 get_conf_byte(d, PCI_SEC_LATENCY_TIMER));
552 if (io_type != (io_limit & PCI_IO_RANGE_TYPE_MASK) ||
553 (io_type != PCI_IO_RANGE_TYPE_16 && io_type != PCI_IO_RANGE_TYPE_32))
554 printf("\t!!! Unknown I/O range types %x/%x\n", io_base, io_limit);
557 io_base = (io_base & PCI_IO_RANGE_MASK) << 8;
558 io_limit = (io_limit & PCI_IO_RANGE_MASK) << 8;
559 if (io_type == PCI_IO_RANGE_TYPE_32)
561 io_base |= (get_conf_word(d, PCI_IO_BASE_UPPER16) << 16);
562 io_limit |= (get_conf_word(d, PCI_IO_LIMIT_UPPER16) << 16);
564 show_range("\tI/O behind bridge", io_base, io_limit+0xfff, 0);
567 if (mem_type != (mem_limit & PCI_MEMORY_RANGE_TYPE_MASK) ||
569 printf("\t!!! Unknown memory range types %x/%x\n", mem_base, mem_limit);
572 mem_base = (mem_base & PCI_MEMORY_RANGE_MASK) << 16;
573 mem_limit = (mem_limit & PCI_MEMORY_RANGE_MASK) << 16;
574 show_range("\tMemory behind bridge", mem_base, mem_limit + 0xfffff, 0);
577 if (pref_type != (pref_limit & PCI_PREF_RANGE_TYPE_MASK) ||
578 (pref_type != PCI_PREF_RANGE_TYPE_32 && pref_type != PCI_PREF_RANGE_TYPE_64))
579 printf("\t!!! Unknown prefetchable memory range types %x/%x\n", pref_base, pref_limit);
582 u64 pref_base_64 = (pref_base & PCI_PREF_RANGE_MASK) << 16;
583 u64 pref_limit_64 = (pref_limit & PCI_PREF_RANGE_MASK) << 16;
584 if (pref_type == PCI_PREF_RANGE_TYPE_64)
586 pref_base_64 |= (u64) get_conf_long(d, PCI_PREF_BASE_UPPER32) << 32;
587 pref_limit_64 |= (u64) get_conf_long(d, PCI_PREF_LIMIT_UPPER32) << 32;
589 show_range("\tPrefetchable memory behind bridge", pref_base_64, pref_limit_64 + 0xfffff, (pref_type == PCI_PREF_RANGE_TYPE_64));
593 printf("\tSecondary status: 66MHz%c FastB2B%c ParErr%c DEVSEL=%s >TAbort%c <TAbort%c <MAbort%c <SERR%c <PERR%c\n",
594 FLAG(sec_stat, PCI_STATUS_66MHZ),
595 FLAG(sec_stat, PCI_STATUS_FAST_BACK),
596 FLAG(sec_stat, PCI_STATUS_PARITY),
597 ((sec_stat & PCI_STATUS_DEVSEL_MASK) == PCI_STATUS_DEVSEL_SLOW) ? "slow" :
598 ((sec_stat & PCI_STATUS_DEVSEL_MASK) == PCI_STATUS_DEVSEL_MEDIUM) ? "medium" :
599 ((sec_stat & PCI_STATUS_DEVSEL_MASK) == PCI_STATUS_DEVSEL_FAST) ? "fast" : "??",
600 FLAG(sec_stat, PCI_STATUS_SIG_TARGET_ABORT),
601 FLAG(sec_stat, PCI_STATUS_REC_TARGET_ABORT),
602 FLAG(sec_stat, PCI_STATUS_REC_MASTER_ABORT),
603 FLAG(sec_stat, PCI_STATUS_SIG_SYSTEM_ERROR),
604 FLAG(sec_stat, PCI_STATUS_DETECTED_PARITY));
606 show_rom(d, PCI_ROM_ADDRESS1);
610 printf("\tBridgeCtl: Parity%c SERR%c NoISA%c VGA%c VGA16%c MAbort%c >Reset%c FastB2B%c\n",
611 FLAG(brc, PCI_BRIDGE_CTL_PARITY),
612 FLAG(brc, PCI_BRIDGE_CTL_SERR),
613 FLAG(brc, PCI_BRIDGE_CTL_NO_ISA),
614 FLAG(brc, PCI_BRIDGE_CTL_VGA),
615 FLAG(brc, PCI_BRIDGE_CTL_VGA_16BIT),
616 FLAG(brc, PCI_BRIDGE_CTL_MASTER_ABORT),
617 FLAG(brc, PCI_BRIDGE_CTL_BUS_RESET),
618 FLAG(brc, PCI_BRIDGE_CTL_FAST_BACK));
619 printf("\t\tPriDiscTmr%c SecDiscTmr%c DiscTmrStat%c DiscTmrSERREn%c\n",
620 FLAG(brc, PCI_BRIDGE_CTL_PRI_DISCARD_TIMER),
621 FLAG(brc, PCI_BRIDGE_CTL_SEC_DISCARD_TIMER),
622 FLAG(brc, PCI_BRIDGE_CTL_DISCARD_TIMER_STATUS),
623 FLAG(brc, PCI_BRIDGE_CTL_DISCARD_TIMER_SERR_EN));
626 show_caps(d, PCI_CAPABILITY_LIST);
630 show_htype2(struct device *d)
633 word cmd = get_conf_word(d, PCI_COMMAND);
634 word brc = get_conf_word(d, PCI_CB_BRIDGE_CONTROL);
636 int verb = verbose > 2;
639 printf("\tBus: primary=%02x, secondary=%02x, subordinate=%02x, sec-latency=%d\n",
640 get_conf_byte(d, PCI_CB_PRIMARY_BUS),
641 get_conf_byte(d, PCI_CB_CARD_BUS),
642 get_conf_byte(d, PCI_CB_SUBORDINATE_BUS),
643 get_conf_byte(d, PCI_CB_LATENCY_TIMER));
647 u32 base = get_conf_long(d, PCI_CB_MEMORY_BASE_0 + p);
648 u32 limit = get_conf_long(d, PCI_CB_MEMORY_LIMIT_0 + p);
649 limit = limit + 0xfff;
650 if (base <= limit || verb)
651 printf("\tMemory window %d: %08x-%08x%s%s\n", i, base, limit,
652 (cmd & PCI_COMMAND_MEMORY) ? "" : " [disabled]",
653 (brc & (PCI_CB_BRIDGE_CTL_PREFETCH_MEM0 << i)) ? " (prefetchable)" : "");
658 u32 base = get_conf_long(d, PCI_CB_IO_BASE_0 + p);
659 u32 limit = get_conf_long(d, PCI_CB_IO_LIMIT_0 + p);
660 if (!(base & PCI_IO_RANGE_TYPE_32))
665 base &= PCI_CB_IO_RANGE_MASK;
666 limit = (limit & PCI_CB_IO_RANGE_MASK) + 3;
667 if (base <= limit || verb)
668 printf("\tI/O window %d: %08x-%08x%s\n", i, base, limit,
669 (cmd & PCI_COMMAND_IO) ? "" : " [disabled]");
672 if (get_conf_word(d, PCI_CB_SEC_STATUS) & PCI_STATUS_SIG_SYSTEM_ERROR)
673 printf("\tSecondary status: SERR\n");
675 printf("\tBridgeCtl: Parity%c SERR%c ISA%c VGA%c MAbort%c >Reset%c 16bInt%c PostWrite%c\n",
676 FLAG(brc, PCI_CB_BRIDGE_CTL_PARITY),
677 FLAG(brc, PCI_CB_BRIDGE_CTL_SERR),
678 FLAG(brc, PCI_CB_BRIDGE_CTL_ISA),
679 FLAG(brc, PCI_CB_BRIDGE_CTL_VGA),
680 FLAG(brc, PCI_CB_BRIDGE_CTL_MASTER_ABORT),
681 FLAG(brc, PCI_CB_BRIDGE_CTL_CB_RESET),
682 FLAG(brc, PCI_CB_BRIDGE_CTL_16BIT_INT),
683 FLAG(brc, PCI_CB_BRIDGE_CTL_POST_WRITES));
685 if (d->config_cached < 128)
687 printf("\t<access denied to the rest>\n");
691 exca = get_conf_word(d, PCI_CB_LEGACY_MODE_BASE);
693 printf("\t16-bit legacy interface ports at %04x\n", exca);
694 show_caps(d, PCI_CB_CAPABILITY_LIST);
698 show_verbose(struct device *d)
700 struct pci_dev *p = d->dev;
701 word status = get_conf_word(d, PCI_STATUS);
702 word cmd = get_conf_word(d, PCI_COMMAND);
703 word class = p->device_class;
704 byte bist = get_conf_byte(d, PCI_BIST);
705 byte htype = get_conf_byte(d, PCI_HEADER_TYPE) & 0x7f;
706 byte latency = get_conf_byte(d, PCI_LATENCY_TIMER);
707 byte cache_line = get_conf_byte(d, PCI_CACHE_LINE_SIZE);
708 byte max_lat, min_gnt;
709 byte int_pin = get_conf_byte(d, PCI_INTERRUPT_PIN);
715 pci_fill_info(p, PCI_FILL_IRQ | PCI_FILL_BASES | PCI_FILL_ROM_BASE | PCI_FILL_SIZES |
716 PCI_FILL_PHYS_SLOT | PCI_FILL_NUMA_NODE | PCI_FILL_DT_NODE);
721 case PCI_HEADER_TYPE_NORMAL:
722 if (class == PCI_CLASS_BRIDGE_PCI)
723 printf("\t!!! Invalid class %04x for header type %02x\n", class, htype);
724 max_lat = get_conf_byte(d, PCI_MAX_LAT);
725 min_gnt = get_conf_byte(d, PCI_MIN_GNT);
727 case PCI_HEADER_TYPE_BRIDGE:
728 if ((class >> 8) != PCI_BASE_CLASS_BRIDGE)
729 printf("\t!!! Invalid class %04x for header type %02x\n", class, htype);
730 min_gnt = max_lat = 0;
732 case PCI_HEADER_TYPE_CARDBUS:
733 if ((class >> 8) != PCI_BASE_CLASS_BRIDGE)
734 printf("\t!!! Invalid class %04x for header type %02x\n", class, htype);
735 min_gnt = max_lat = 0;
738 printf("\t!!! Unknown header type %02x\n", htype);
743 printf("\tPhysical Slot: %s\n", p->phy_slot);
745 if (dt_node = pci_get_string_property(p, PCI_FILL_DT_NODE))
746 printf("\tDevice tree node: %s\n", dt_node);
750 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",
751 FLAG(cmd, PCI_COMMAND_IO),
752 FLAG(cmd, PCI_COMMAND_MEMORY),
753 FLAG(cmd, PCI_COMMAND_MASTER),
754 FLAG(cmd, PCI_COMMAND_SPECIAL),
755 FLAG(cmd, PCI_COMMAND_INVALIDATE),
756 FLAG(cmd, PCI_COMMAND_VGA_PALETTE),
757 FLAG(cmd, PCI_COMMAND_PARITY),
758 FLAG(cmd, PCI_COMMAND_WAIT),
759 FLAG(cmd, PCI_COMMAND_SERR),
760 FLAG(cmd, PCI_COMMAND_FAST_BACK),
761 FLAG(cmd, PCI_COMMAND_DISABLE_INTx));
762 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",
763 FLAG(status, PCI_STATUS_CAP_LIST),
764 FLAG(status, PCI_STATUS_66MHZ),
765 FLAG(status, PCI_STATUS_UDF),
766 FLAG(status, PCI_STATUS_FAST_BACK),
767 FLAG(status, PCI_STATUS_PARITY),
768 ((status & PCI_STATUS_DEVSEL_MASK) == PCI_STATUS_DEVSEL_SLOW) ? "slow" :
769 ((status & PCI_STATUS_DEVSEL_MASK) == PCI_STATUS_DEVSEL_MEDIUM) ? "medium" :
770 ((status & PCI_STATUS_DEVSEL_MASK) == PCI_STATUS_DEVSEL_FAST) ? "fast" : "??",
771 FLAG(status, PCI_STATUS_SIG_TARGET_ABORT),
772 FLAG(status, PCI_STATUS_REC_TARGET_ABORT),
773 FLAG(status, PCI_STATUS_REC_MASTER_ABORT),
774 FLAG(status, PCI_STATUS_SIG_SYSTEM_ERROR),
775 FLAG(status, PCI_STATUS_DETECTED_PARITY),
776 FLAG(status, PCI_STATUS_INTx));
777 if (cmd & PCI_COMMAND_MASTER)
779 printf("\tLatency: %d", latency);
780 if (min_gnt || max_lat)
784 printf("%dns min", min_gnt*250);
785 if (min_gnt && max_lat)
788 printf("%dns max", max_lat*250);
792 printf(", Cache Line Size: %d bytes", cache_line * 4);
796 printf("\tInterrupt: pin %c routed to IRQ " PCIIRQ_FMT "\n",
797 (int_pin ? 'A' + int_pin - 1 : '?'), irq);
798 if (p->numa_node != -1)
799 printf("\tNUMA node: %d\n", p->numa_node);
804 if (cmd & PCI_COMMAND_MASTER)
805 printf("bus master, ");
806 if (cmd & PCI_COMMAND_VGA_PALETTE)
807 printf("VGA palette snoop, ");
808 if (cmd & PCI_COMMAND_WAIT)
809 printf("stepping, ");
810 if (cmd & PCI_COMMAND_FAST_BACK)
811 printf("fast Back2Back, ");
812 if (status & PCI_STATUS_66MHZ)
814 if (status & PCI_STATUS_UDF)
815 printf("user-definable features, ");
817 ((status & PCI_STATUS_DEVSEL_MASK) == PCI_STATUS_DEVSEL_SLOW) ? "slow" :
818 ((status & PCI_STATUS_DEVSEL_MASK) == PCI_STATUS_DEVSEL_MEDIUM) ? "medium" :
819 ((status & PCI_STATUS_DEVSEL_MASK) == PCI_STATUS_DEVSEL_FAST) ? "fast" : "??");
820 if (cmd & PCI_COMMAND_MASTER)
821 printf(", latency %d", latency);
823 printf(", IRQ " PCIIRQ_FMT, irq);
824 if (p->numa_node != -1)
825 printf(", NUMA node %d", p->numa_node);
829 if (bist & PCI_BIST_CAPABLE)
831 if (bist & PCI_BIST_START)
832 printf("\tBIST is running\n");
834 printf("\tBIST result: %02x\n", bist & PCI_BIST_CODE_MASK);
839 case PCI_HEADER_TYPE_NORMAL:
842 case PCI_HEADER_TYPE_BRIDGE:
845 case PCI_HEADER_TYPE_CARDBUS:
851 /*** Machine-readable dumps ***/
854 show_hex_dump(struct device *d)
858 cnt = d->config_cached;
859 if (opt_hex >= 3 && config_fetch(d, cnt, 256-cnt))
862 if (opt_hex >= 4 && config_fetch(d, 256, 4096-256))
866 for (i=0; i<cnt; i++)
870 printf(" %02x", get_conf_byte(d, i));
877 print_shell_escaped(char *c)
882 if (*c == '"' || *c == '\\')
890 show_machine(struct device *d)
892 struct pci_dev *p = d->dev;
895 char classbuf[128], vendbuf[128], devbuf[128], svbuf[128], sdbuf[128];
898 get_subid(d, &sv_id, &sd_id);
902 pci_fill_info(p, PCI_FILL_PHYS_SLOT | PCI_FILL_NUMA_NODE | PCI_FILL_DT_NODE);
903 printf((opt_machine >= 2) ? "Slot:\t" : "Device:\t");
906 printf("Class:\t%s\n",
907 pci_lookup_name(pacc, classbuf, sizeof(classbuf), PCI_LOOKUP_CLASS, p->device_class));
908 printf("Vendor:\t%s\n",
909 pci_lookup_name(pacc, vendbuf, sizeof(vendbuf), PCI_LOOKUP_VENDOR, p->vendor_id, p->device_id));
910 printf("Device:\t%s\n",
911 pci_lookup_name(pacc, devbuf, sizeof(devbuf), PCI_LOOKUP_DEVICE, p->vendor_id, p->device_id));
912 if (sv_id && sv_id != 0xffff)
914 printf("SVendor:\t%s\n",
915 pci_lookup_name(pacc, svbuf, sizeof(svbuf), PCI_LOOKUP_SUBSYSTEM | PCI_LOOKUP_VENDOR, sv_id));
916 printf("SDevice:\t%s\n",
917 pci_lookup_name(pacc, sdbuf, sizeof(sdbuf), PCI_LOOKUP_SUBSYSTEM | PCI_LOOKUP_DEVICE, p->vendor_id, p->device_id, sv_id, sd_id));
920 printf("PhySlot:\t%s\n", p->phy_slot);
921 if (c = get_conf_byte(d, PCI_REVISION_ID))
922 printf("Rev:\t%02x\n", c);
923 if (c = get_conf_byte(d, PCI_CLASS_PROG))
924 printf("ProgIf:\t%02x\n", c);
926 show_kernel_machine(d);
927 if (p->numa_node != -1)
928 printf("NUMANode:\t%d\n", p->numa_node);
929 if (dt_node = pci_get_string_property(p, PCI_FILL_DT_NODE))
930 printf("DTNode:\t%s\n", dt_node);
935 print_shell_escaped(pci_lookup_name(pacc, classbuf, sizeof(classbuf), PCI_LOOKUP_CLASS, p->device_class));
936 print_shell_escaped(pci_lookup_name(pacc, vendbuf, sizeof(vendbuf), PCI_LOOKUP_VENDOR, p->vendor_id, p->device_id));
937 print_shell_escaped(pci_lookup_name(pacc, devbuf, sizeof(devbuf), PCI_LOOKUP_DEVICE, p->vendor_id, p->device_id));
938 if (c = get_conf_byte(d, PCI_REVISION_ID))
939 printf(" -r%02x", c);
940 if (c = get_conf_byte(d, PCI_CLASS_PROG))
941 printf(" -p%02x", c);
942 if (sv_id && sv_id != 0xffff)
944 print_shell_escaped(pci_lookup_name(pacc, svbuf, sizeof(svbuf), PCI_LOOKUP_SUBSYSTEM | PCI_LOOKUP_VENDOR, sv_id));
945 print_shell_escaped(pci_lookup_name(pacc, sdbuf, sizeof(sdbuf), PCI_LOOKUP_SUBSYSTEM | PCI_LOOKUP_DEVICE, p->vendor_id, p->device_id, sv_id, sd_id));
948 printf(" \"\" \"\"");
953 /*** Main show function ***/
956 show_device(struct device *d)
966 if (opt_kernel || verbose)
971 if (verbose || opt_hex)
982 for (d=first_dev; d; d=d->next)
989 main(int argc, char **argv)
994 if (argc == 2 && !strcmp(argv[1], "--version"))
996 puts("lspci version " PCIUTILS_VERSION);
1002 pci_filter_init(pacc, &filter);
1004 while ((i = getopt(argc, argv, options)) != -1)
1008 pacc->numeric_ids++;
1014 pacc->buscentric = 1;
1017 if (msg = pci_filter_parse_slot(&filter, optarg))
1021 if (msg = pci_filter_parse_id(&filter, optarg))
1034 pci_set_name_list_path(pacc, optarg, 0);
1040 opt_pcimap = optarg;
1063 die("DNS queries are not available in this version");
1066 if (parse_generic_option(i, pacc, optarg))
1069 fprintf(stderr, help_msg, pacc->id_file_name);
1077 pacc->id_lookup_mode |= PCI_LOOKUP_NETWORK;
1078 if (opt_query_dns > 1)
1079 pacc->id_lookup_mode |= PCI_LOOKUP_REFRESH_CACHE;
1082 pacc->id_lookup_mode |= PCI_LOOKUP_NETWORK | PCI_LOOKUP_SKIP_LOCAL;
1088 die("Bus paths cannot be shown in bus mapping mode");
1100 show_kernel_cleanup();
1103 return (seen_errors ? 2 : 0);