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_filter; /* Any filter was given */
22 static int opt_tree; /* Show bus tree */
23 static int opt_path; /* Show bridge path */
24 static int opt_machine; /* Generate machine-readable output */
25 static int opt_map_mode; /* Bus mapping mode enabled */
26 static int opt_domains; /* Show domain numbers (0=disabled, 1=auto-detected, 2=requested) */
27 static int opt_kernel; /* Show kernel drivers */
28 static int opt_query_dns; /* Query the DNS (0=disabled, 1=enabled, 2=refresh cache) */
29 static int opt_query_all; /* Query the DNS for all entries */
30 char *opt_pcimap; /* Override path to Linux modules.pcimap */
32 const char program_name[] = "lspci";
34 static char options[] = "nvbxs:d:tPi:mgp:qkMDQ" GENERIC_OPTIONS ;
36 static char help_msg[] =
37 "Usage: lspci [<switches>]\n"
39 "Basic display modes:\n"
40 "-mm\t\tProduce machine-readable output (single -m for an obsolete format)\n"
41 "-t\t\tShow bus tree\n"
44 "-v\t\tBe verbose (-vv or -vvv for higher verbosity)\n"
46 "-k\t\tShow kernel drivers handling each device\n"
48 "-x\t\tShow hex-dump of the standard part of the config space\n"
49 "-xxx\t\tShow hex-dump of the whole config space (dangerous; root only)\n"
50 "-xxxx\t\tShow hex-dump of the 4096-byte extended config space (root only)\n"
51 "-b\t\tBus-centric view (addresses and IRQ's as seen by the bus)\n"
52 "-D\t\tAlways show domain numbers\n"
53 "-P\t\tDisplay bridge path in addition to bus and device number\n"
54 "-PP\t\tDisplay bus path in addition to bus and device number\n"
56 "Resolving of device ID's to names:\n"
57 "-n\t\tShow numeric ID's\n"
58 "-nn\t\tShow both textual and numeric ID's (names & numbers)\n"
60 "-q\t\tQuery the PCI ID database for unknown ID's via DNS\n"
61 "-qq\t\tAs above, but re-query locally cached entries\n"
62 "-Q\t\tQuery the PCI ID database for all ID's via DNS\n"
65 "Selection of devices:\n"
66 "-s [[[[<domain>]:]<bus>]:][<slot>][.[<func>]]\tShow only devices in selected slots\n"
67 "-d [<vendor>]:[<device>][:<class>]\t\tShow only devices with specified ID's\n"
70 "-i <file>\tUse specified ID database instead of %s\n"
72 "-p <file>\tLook up kernel modules in a given file instead of default modules.pcimap\n"
74 "-M\t\tEnable `bus mapping' mode (dangerous; root only)\n"
76 "PCI access options:\n"
80 /*** Our view of the PCI bus ***/
82 struct pci_access *pacc;
83 struct device *first_dev;
84 static int seen_errors;
85 static int need_topology;
88 config_fetch(struct device *d, unsigned int pos, unsigned int len)
90 unsigned int end = pos+len;
93 while (pos < d->config_bufsize && len && d->present[pos])
95 while (pos+len <= d->config_bufsize && len && d->present[pos+len-1])
100 if (end > d->config_bufsize)
102 int orig_size = d->config_bufsize;
103 while (end > d->config_bufsize)
104 d->config_bufsize *= 2;
105 d->config = xrealloc(d->config, d->config_bufsize);
106 d->present = xrealloc(d->present, d->config_bufsize);
107 memset(d->present + orig_size, 0, d->config_bufsize - orig_size);
109 result = pci_read_block(d->dev, pos, d->config + pos, len);
111 memset(d->present + pos, 1, len);
116 scan_device(struct pci_dev *p)
120 if (p->domain && !opt_domains)
122 if (!pci_filter_match(&filter, p) && !need_topology)
124 d = xmalloc(sizeof(struct device));
125 memset(d, 0, sizeof(*d));
127 d->config_cached = d->config_bufsize = 64;
128 d->config = xmalloc(64);
129 d->present = xmalloc(64);
130 memset(d->present, 1, 64);
131 if (!pci_read_block(p, 0, d->config, 64))
133 fprintf(stderr, "lspci: Unable to read the standard configuration space header of device %04x:%02x:%02x.%d\n",
134 p->domain, p->bus, p->dev, p->func);
138 if ((d->config[PCI_HEADER_TYPE] & 0x7f) == PCI_HEADER_TYPE_CARDBUS)
140 /* For cardbus bridges, we need to fetch 64 bytes more to get the
141 * full standard header... */
142 if (config_fetch(d, 64, 64))
143 d->config_cached += 64;
145 pci_setup_cache(p, d->config, d->config_cached);
146 pci_fill_info(p, PCI_FILL_IDENT | PCI_FILL_CLASS);
157 for (p=pacc->devices; p; p=p->next)
158 if (d = scan_device(p))
165 /*** Config space accesses ***/
168 check_conf_range(struct device *d, unsigned int pos, unsigned int len)
171 if (!d->present[pos])
172 die("Internal bug: Accessing non-read configuration byte at position %x", pos);
178 get_conf_byte(struct device *d, unsigned int pos)
180 check_conf_range(d, pos, 1);
181 return d->config[pos];
185 get_conf_word(struct device *d, unsigned int pos)
187 check_conf_range(d, pos, 2);
188 return d->config[pos] | (d->config[pos+1] << 8);
192 get_conf_long(struct device *d, unsigned int pos)
194 check_conf_range(d, pos, 4);
195 return d->config[pos] |
196 (d->config[pos+1] << 8) |
197 (d->config[pos+2] << 16) |
198 (d->config[pos+3] << 24);
204 compare_them(const void *A, const void *B)
206 const struct pci_dev *a = (*(const struct device **)A)->dev;
207 const struct pci_dev *b = (*(const struct device **)B)->dev;
209 if (a->domain < b->domain)
211 if (a->domain > b->domain)
221 if (a->func < b->func)
223 if (a->func > b->func)
231 struct device **index, **h, **last_dev;
236 for (d=first_dev; d; d=d->next)
238 h = index = alloca(sizeof(struct device *) * cnt);
239 for (d=first_dev; d; d=d->next)
241 qsort(index, cnt, sizeof(struct device *), compare_them);
242 last_dev = &first_dev;
247 last_dev = &(*h)->next;
253 /*** Normal output ***/
256 show_slot_path(struct device *d)
258 struct pci_dev *p = d->dev;
262 struct bus *bus = d->parent_bus;
263 struct bridge *br = bus->parent_bridge;
265 if (br && br->br_dev)
267 show_slot_path(br->br_dev);
269 printf("/%02x:%02x.%d", p->bus, p->dev, p->func);
271 printf("/%02x.%d", p->dev, p->func);
275 printf("%02x:%02x.%d", p->bus, p->dev, p->func);
279 show_slot_name(struct device *d)
281 struct pci_dev *p = d->dev;
283 if (!opt_machine ? opt_domains : (p->domain || opt_domains >= 2))
284 printf("%04x:", p->domain);
289 get_subid(struct device *d, word *subvp, word *subdp)
291 byte htype = get_conf_byte(d, PCI_HEADER_TYPE) & 0x7f;
293 if (htype == PCI_HEADER_TYPE_NORMAL)
295 *subvp = get_conf_word(d, PCI_SUBSYSTEM_VENDOR_ID);
296 *subdp = get_conf_word(d, PCI_SUBSYSTEM_ID);
298 else if (htype == PCI_HEADER_TYPE_CARDBUS && d->config_cached >= 128)
300 *subvp = get_conf_word(d, PCI_CB_SUBSYSTEM_VENDOR_ID);
301 *subdp = get_conf_word(d, PCI_CB_SUBSYSTEM_ID);
304 *subvp = *subdp = 0xffff;
308 show_terse(struct device *d)
311 struct pci_dev *p = d->dev;
312 char classbuf[128], devbuf[128];
316 pci_lookup_name(pacc, classbuf, sizeof(classbuf),
319 pci_lookup_name(pacc, devbuf, sizeof(devbuf),
320 PCI_LOOKUP_VENDOR | PCI_LOOKUP_DEVICE,
321 p->vendor_id, p->device_id));
322 if (c = get_conf_byte(d, PCI_REVISION_ID))
323 printf(" (rev %02x)", c);
327 c = get_conf_byte(d, PCI_CLASS_PROG);
328 x = pci_lookup_name(pacc, devbuf, sizeof(devbuf),
329 PCI_LOOKUP_PROGIF | PCI_LOOKUP_NO_NUMBERS,
333 printf(" (prog-if %02x", c);
341 if (verbose || opt_kernel)
343 word subsys_v, subsys_d;
346 pci_fill_info(p, PCI_FILL_LABEL);
349 printf("\tDeviceName: %s", p->label);
350 get_subid(d, &subsys_v, &subsys_d);
351 if (subsys_v && subsys_v != 0xffff)
352 printf("\tSubsystem: %s\n",
353 pci_lookup_name(pacc, ssnamebuf, sizeof(ssnamebuf),
354 PCI_LOOKUP_SUBSYSTEM | PCI_LOOKUP_VENDOR | PCI_LOOKUP_DEVICE,
355 p->vendor_id, p->device_id, subsys_v, subsys_d));
359 /*** Verbose output ***/
364 static const char suffix[][2] = { "", "K", "M", "G", "T" };
368 for (i = 0; i < (sizeof(suffix) / sizeof(*suffix) - 1); i++) {
373 printf(" [size=%u%s]", (unsigned)x, suffix[i]);
377 show_range(char *prefix, u64 base, u64 limit, int is_64bit)
379 if (base > limit && verbose < 3)
381 printf("%s: None\n", prefix);
384 printf("%s: ", prefix);
386 printf("%016" PCI_U64_FMT_X "-%016" PCI_U64_FMT_X, base, limit);
388 printf("%08x-%08x", (unsigned) base, (unsigned) limit);
390 show_size(limit - base + 1);
397 show_bases(struct device *d, int cnt)
399 struct pci_dev *p = d->dev;
400 word cmd = get_conf_word(d, PCI_COMMAND);
404 for (i=0; i<cnt; i++)
406 pciaddr_t pos = p->base_addr[i];
407 pciaddr_t len = (p->known_fields & PCI_FILL_SIZES) ? p->size[i] : 0;
408 pciaddr_t ioflg = (p->known_fields & PCI_FILL_IO_FLAGS) ? p->flags[i] : 0;
409 u32 flg = get_conf_long(d, PCI_BASE_ADDRESS_0 + 4*i);
410 if (flg == 0xffffffff)
412 if (!pos && !flg && !len)
415 printf("\tRegion %d: ", i);
418 if (ioflg & PCI_IORESOURCE_PCI_EA_BEI)
419 printf("[enhanced] ");
420 else if (pos && !(flg & ((flg & PCI_BASE_ADDRESS_SPACE_IO) ? PCI_BASE_ADDRESS_IO_MASK : PCI_BASE_ADDRESS_MEM_MASK)))
422 /* Reported by the OS, but not by the device */
423 printf("[virtual] ");
427 if (flg & PCI_BASE_ADDRESS_SPACE_IO)
429 pciaddr_t a = pos & PCI_BASE_ADDRESS_IO_MASK;
430 printf("I/O ports at ");
431 if (a || (cmd & PCI_COMMAND_IO))
432 printf(PCIADDR_PORT_FMT, a);
433 else if (flg & PCI_BASE_ADDRESS_IO_MASK)
436 printf("<unassigned>");
437 if (!virtual && !(cmd & PCI_COMMAND_IO))
438 printf(" [disabled]");
442 int t = flg & PCI_BASE_ADDRESS_MEM_TYPE_MASK;
443 pciaddr_t a = pos & PCI_ADDR_MEM_MASK;
447 printf("Memory at ");
448 if (t == PCI_BASE_ADDRESS_MEM_TYPE_64)
452 printf("<invalid-64bit-slot>");
458 z = get_conf_long(d, PCI_BASE_ADDRESS_0 + 4*i);
464 printf(PCIADDR_T_FMT, a);
466 printf(((flg & PCI_BASE_ADDRESS_MEM_MASK) || z) ? "<ignored>" : "<unassigned>");
468 printf(" (%s, %sprefetchable)",
469 (t == PCI_BASE_ADDRESS_MEM_TYPE_32) ? "32-bit" :
470 (t == PCI_BASE_ADDRESS_MEM_TYPE_64) ? "64-bit" :
471 (t == PCI_BASE_ADDRESS_MEM_TYPE_1M) ? "low-1M" : "type 3",
472 (flg & PCI_BASE_ADDRESS_MEM_PREFETCH) ? "" : "non-");
473 if (!virtual && !(cmd & PCI_COMMAND_MEMORY))
474 printf(" [disabled]");
482 show_rom(struct device *d, int reg)
484 struct pci_dev *p = d->dev;
485 pciaddr_t rom = p->rom_base_addr;
486 pciaddr_t len = (p->known_fields & PCI_FILL_SIZES) ? p->rom_size : 0;
487 pciaddr_t ioflg = (p->known_fields & PCI_FILL_IO_FLAGS) ? p->rom_flags : 0;
488 u32 flg = get_conf_long(d, reg);
489 word cmd = get_conf_word(d, PCI_COMMAND);
492 if (!rom && !flg && !len)
495 if (ioflg & PCI_IORESOURCE_PCI_EA_BEI)
496 printf("[enhanced] ");
497 else if ((rom & PCI_ROM_ADDRESS_MASK) && !(flg & PCI_ROM_ADDRESS_MASK))
499 printf("[virtual] ");
503 printf("Expansion ROM at ");
504 if (rom & PCI_ROM_ADDRESS_MASK)
505 printf(PCIADDR_T_FMT, rom & PCI_ROM_ADDRESS_MASK);
506 else if (flg & PCI_ROM_ADDRESS_MASK)
509 printf("<unassigned>");
510 if (!(flg & PCI_ROM_ADDRESS_ENABLE))
511 printf(" [disabled]");
512 else if (!virtual && !(cmd & PCI_COMMAND_MEMORY))
513 printf(" [disabled by cmd]");
519 show_htype0(struct device *d)
522 show_rom(d, PCI_ROM_ADDRESS);
523 show_caps(d, PCI_CAPABILITY_LIST);
527 show_htype1(struct device *d)
529 u32 io_base = get_conf_byte(d, PCI_IO_BASE);
530 u32 io_limit = get_conf_byte(d, PCI_IO_LIMIT);
531 u32 io_type = io_base & PCI_IO_RANGE_TYPE_MASK;
532 u32 mem_base = get_conf_word(d, PCI_MEMORY_BASE);
533 u32 mem_limit = get_conf_word(d, PCI_MEMORY_LIMIT);
534 u32 mem_type = mem_base & PCI_MEMORY_RANGE_TYPE_MASK;
535 u32 pref_base = get_conf_word(d, PCI_PREF_MEMORY_BASE);
536 u32 pref_limit = get_conf_word(d, PCI_PREF_MEMORY_LIMIT);
537 u32 pref_type = pref_base & PCI_PREF_RANGE_TYPE_MASK;
538 word sec_stat = get_conf_word(d, PCI_SEC_STATUS);
539 word brc = get_conf_word(d, PCI_BRIDGE_CONTROL);
542 printf("\tBus: primary=%02x, secondary=%02x, subordinate=%02x, sec-latency=%d\n",
543 get_conf_byte(d, PCI_PRIMARY_BUS),
544 get_conf_byte(d, PCI_SECONDARY_BUS),
545 get_conf_byte(d, PCI_SUBORDINATE_BUS),
546 get_conf_byte(d, PCI_SEC_LATENCY_TIMER));
548 if (io_type != (io_limit & PCI_IO_RANGE_TYPE_MASK) ||
549 (io_type != PCI_IO_RANGE_TYPE_16 && io_type != PCI_IO_RANGE_TYPE_32))
550 printf("\t!!! Unknown I/O range types %x/%x\n", io_base, io_limit);
553 io_base = (io_base & PCI_IO_RANGE_MASK) << 8;
554 io_limit = (io_limit & PCI_IO_RANGE_MASK) << 8;
555 if (io_type == PCI_IO_RANGE_TYPE_32)
557 io_base |= (get_conf_word(d, PCI_IO_BASE_UPPER16) << 16);
558 io_limit |= (get_conf_word(d, PCI_IO_LIMIT_UPPER16) << 16);
560 show_range("\tI/O behind bridge", io_base, io_limit+0xfff, 0);
563 if (mem_type != (mem_limit & PCI_MEMORY_RANGE_TYPE_MASK) ||
565 printf("\t!!! Unknown memory range types %x/%x\n", mem_base, mem_limit);
568 mem_base = (mem_base & PCI_MEMORY_RANGE_MASK) << 16;
569 mem_limit = (mem_limit & PCI_MEMORY_RANGE_MASK) << 16;
570 show_range("\tMemory behind bridge", mem_base, mem_limit + 0xfffff, 0);
573 if (pref_type != (pref_limit & PCI_PREF_RANGE_TYPE_MASK) ||
574 (pref_type != PCI_PREF_RANGE_TYPE_32 && pref_type != PCI_PREF_RANGE_TYPE_64))
575 printf("\t!!! Unknown prefetchable memory range types %x/%x\n", pref_base, pref_limit);
578 u64 pref_base_64 = (pref_base & PCI_PREF_RANGE_MASK) << 16;
579 u64 pref_limit_64 = (pref_limit & PCI_PREF_RANGE_MASK) << 16;
580 if (pref_type == PCI_PREF_RANGE_TYPE_64)
582 pref_base_64 |= (u64) get_conf_long(d, PCI_PREF_BASE_UPPER32) << 32;
583 pref_limit_64 |= (u64) get_conf_long(d, PCI_PREF_LIMIT_UPPER32) << 32;
585 show_range("\tPrefetchable memory behind bridge", pref_base_64, pref_limit_64 + 0xfffff, (pref_type == PCI_PREF_RANGE_TYPE_64));
589 printf("\tSecondary status: 66MHz%c FastB2B%c ParErr%c DEVSEL=%s >TAbort%c <TAbort%c <MAbort%c <SERR%c <PERR%c\n",
590 FLAG(sec_stat, PCI_STATUS_66MHZ),
591 FLAG(sec_stat, PCI_STATUS_FAST_BACK),
592 FLAG(sec_stat, PCI_STATUS_PARITY),
593 ((sec_stat & PCI_STATUS_DEVSEL_MASK) == PCI_STATUS_DEVSEL_SLOW) ? "slow" :
594 ((sec_stat & PCI_STATUS_DEVSEL_MASK) == PCI_STATUS_DEVSEL_MEDIUM) ? "medium" :
595 ((sec_stat & PCI_STATUS_DEVSEL_MASK) == PCI_STATUS_DEVSEL_FAST) ? "fast" : "??",
596 FLAG(sec_stat, PCI_STATUS_SIG_TARGET_ABORT),
597 FLAG(sec_stat, PCI_STATUS_REC_TARGET_ABORT),
598 FLAG(sec_stat, PCI_STATUS_REC_MASTER_ABORT),
599 FLAG(sec_stat, PCI_STATUS_SIG_SYSTEM_ERROR),
600 FLAG(sec_stat, PCI_STATUS_DETECTED_PARITY));
602 show_rom(d, PCI_ROM_ADDRESS1);
606 printf("\tBridgeCtl: Parity%c SERR%c NoISA%c VGA%c VGA16%c MAbort%c >Reset%c FastB2B%c\n",
607 FLAG(brc, PCI_BRIDGE_CTL_PARITY),
608 FLAG(brc, PCI_BRIDGE_CTL_SERR),
609 FLAG(brc, PCI_BRIDGE_CTL_NO_ISA),
610 FLAG(brc, PCI_BRIDGE_CTL_VGA),
611 FLAG(brc, PCI_BRIDGE_CTL_VGA_16BIT),
612 FLAG(brc, PCI_BRIDGE_CTL_MASTER_ABORT),
613 FLAG(brc, PCI_BRIDGE_CTL_BUS_RESET),
614 FLAG(brc, PCI_BRIDGE_CTL_FAST_BACK));
615 printf("\t\tPriDiscTmr%c SecDiscTmr%c DiscTmrStat%c DiscTmrSERREn%c\n",
616 FLAG(brc, PCI_BRIDGE_CTL_PRI_DISCARD_TIMER),
617 FLAG(brc, PCI_BRIDGE_CTL_SEC_DISCARD_TIMER),
618 FLAG(brc, PCI_BRIDGE_CTL_DISCARD_TIMER_STATUS),
619 FLAG(brc, PCI_BRIDGE_CTL_DISCARD_TIMER_SERR_EN));
622 show_caps(d, PCI_CAPABILITY_LIST);
626 show_htype2(struct device *d)
629 word cmd = get_conf_word(d, PCI_COMMAND);
630 word brc = get_conf_word(d, PCI_CB_BRIDGE_CONTROL);
632 int verb = verbose > 2;
635 printf("\tBus: primary=%02x, secondary=%02x, subordinate=%02x, sec-latency=%d\n",
636 get_conf_byte(d, PCI_CB_PRIMARY_BUS),
637 get_conf_byte(d, PCI_CB_CARD_BUS),
638 get_conf_byte(d, PCI_CB_SUBORDINATE_BUS),
639 get_conf_byte(d, PCI_CB_LATENCY_TIMER));
643 u32 base = get_conf_long(d, PCI_CB_MEMORY_BASE_0 + p);
644 u32 limit = get_conf_long(d, PCI_CB_MEMORY_LIMIT_0 + p);
645 limit = limit + 0xfff;
646 if (base <= limit || verb)
647 printf("\tMemory window %d: %08x-%08x%s%s\n", i, base, limit,
648 (cmd & PCI_COMMAND_MEMORY) ? "" : " [disabled]",
649 (brc & (PCI_CB_BRIDGE_CTL_PREFETCH_MEM0 << i)) ? " (prefetchable)" : "");
654 u32 base = get_conf_long(d, PCI_CB_IO_BASE_0 + p);
655 u32 limit = get_conf_long(d, PCI_CB_IO_LIMIT_0 + p);
656 if (!(base & PCI_IO_RANGE_TYPE_32))
661 base &= PCI_CB_IO_RANGE_MASK;
662 limit = (limit & PCI_CB_IO_RANGE_MASK) + 3;
663 if (base <= limit || verb)
664 printf("\tI/O window %d: %08x-%08x%s\n", i, base, limit,
665 (cmd & PCI_COMMAND_IO) ? "" : " [disabled]");
668 if (get_conf_word(d, PCI_CB_SEC_STATUS) & PCI_STATUS_SIG_SYSTEM_ERROR)
669 printf("\tSecondary status: SERR\n");
671 printf("\tBridgeCtl: Parity%c SERR%c ISA%c VGA%c MAbort%c >Reset%c 16bInt%c PostWrite%c\n",
672 FLAG(brc, PCI_CB_BRIDGE_CTL_PARITY),
673 FLAG(brc, PCI_CB_BRIDGE_CTL_SERR),
674 FLAG(brc, PCI_CB_BRIDGE_CTL_ISA),
675 FLAG(brc, PCI_CB_BRIDGE_CTL_VGA),
676 FLAG(brc, PCI_CB_BRIDGE_CTL_MASTER_ABORT),
677 FLAG(brc, PCI_CB_BRIDGE_CTL_CB_RESET),
678 FLAG(brc, PCI_CB_BRIDGE_CTL_16BIT_INT),
679 FLAG(brc, PCI_CB_BRIDGE_CTL_POST_WRITES));
681 if (d->config_cached < 128)
683 printf("\t<access denied to the rest>\n");
687 exca = get_conf_word(d, PCI_CB_LEGACY_MODE_BASE);
689 printf("\t16-bit legacy interface ports at %04x\n", exca);
690 show_caps(d, PCI_CB_CAPABILITY_LIST);
694 show_verbose(struct device *d)
696 struct pci_dev *p = d->dev;
697 word status = get_conf_word(d, PCI_STATUS);
698 word cmd = get_conf_word(d, PCI_COMMAND);
699 word class = p->device_class;
700 byte bist = get_conf_byte(d, PCI_BIST);
701 byte htype = get_conf_byte(d, PCI_HEADER_TYPE) & 0x7f;
702 byte latency = get_conf_byte(d, PCI_LATENCY_TIMER);
703 byte cache_line = get_conf_byte(d, PCI_CACHE_LINE_SIZE);
704 byte max_lat, min_gnt;
705 byte int_pin = get_conf_byte(d, PCI_INTERRUPT_PIN);
711 pci_fill_info(p, PCI_FILL_IRQ | PCI_FILL_BASES | PCI_FILL_ROM_BASE | PCI_FILL_SIZES |
712 PCI_FILL_PHYS_SLOT | PCI_FILL_NUMA_NODE | PCI_FILL_DT_NODE);
717 case PCI_HEADER_TYPE_NORMAL:
718 if (class == PCI_CLASS_BRIDGE_PCI)
719 printf("\t!!! Invalid class %04x for header type %02x\n", class, htype);
720 max_lat = get_conf_byte(d, PCI_MAX_LAT);
721 min_gnt = get_conf_byte(d, PCI_MIN_GNT);
723 case PCI_HEADER_TYPE_BRIDGE:
724 if ((class >> 8) != PCI_BASE_CLASS_BRIDGE)
725 printf("\t!!! Invalid class %04x for header type %02x\n", class, htype);
726 min_gnt = max_lat = 0;
728 case PCI_HEADER_TYPE_CARDBUS:
729 if ((class >> 8) != PCI_BASE_CLASS_BRIDGE)
730 printf("\t!!! Invalid class %04x for header type %02x\n", class, htype);
731 min_gnt = max_lat = 0;
734 printf("\t!!! Unknown header type %02x\n", htype);
739 printf("\tPhysical Slot: %s\n", p->phy_slot);
741 if (dt_node = pci_get_string_property(p, PCI_FILL_DT_NODE))
742 printf("\tDevice tree node: %s\n", dt_node);
746 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",
747 FLAG(cmd, PCI_COMMAND_IO),
748 FLAG(cmd, PCI_COMMAND_MEMORY),
749 FLAG(cmd, PCI_COMMAND_MASTER),
750 FLAG(cmd, PCI_COMMAND_SPECIAL),
751 FLAG(cmd, PCI_COMMAND_INVALIDATE),
752 FLAG(cmd, PCI_COMMAND_VGA_PALETTE),
753 FLAG(cmd, PCI_COMMAND_PARITY),
754 FLAG(cmd, PCI_COMMAND_WAIT),
755 FLAG(cmd, PCI_COMMAND_SERR),
756 FLAG(cmd, PCI_COMMAND_FAST_BACK),
757 FLAG(cmd, PCI_COMMAND_DISABLE_INTx));
758 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",
759 FLAG(status, PCI_STATUS_CAP_LIST),
760 FLAG(status, PCI_STATUS_66MHZ),
761 FLAG(status, PCI_STATUS_UDF),
762 FLAG(status, PCI_STATUS_FAST_BACK),
763 FLAG(status, PCI_STATUS_PARITY),
764 ((status & PCI_STATUS_DEVSEL_MASK) == PCI_STATUS_DEVSEL_SLOW) ? "slow" :
765 ((status & PCI_STATUS_DEVSEL_MASK) == PCI_STATUS_DEVSEL_MEDIUM) ? "medium" :
766 ((status & PCI_STATUS_DEVSEL_MASK) == PCI_STATUS_DEVSEL_FAST) ? "fast" : "??",
767 FLAG(status, PCI_STATUS_SIG_TARGET_ABORT),
768 FLAG(status, PCI_STATUS_REC_TARGET_ABORT),
769 FLAG(status, PCI_STATUS_REC_MASTER_ABORT),
770 FLAG(status, PCI_STATUS_SIG_SYSTEM_ERROR),
771 FLAG(status, PCI_STATUS_DETECTED_PARITY),
772 FLAG(status, PCI_STATUS_INTx));
773 if (cmd & PCI_COMMAND_MASTER)
775 printf("\tLatency: %d", latency);
776 if (min_gnt || max_lat)
780 printf("%dns min", min_gnt*250);
781 if (min_gnt && max_lat)
784 printf("%dns max", max_lat*250);
788 printf(", Cache Line Size: %d bytes", cache_line * 4);
792 printf("\tInterrupt: pin %c routed to IRQ " PCIIRQ_FMT "\n",
793 (int_pin ? 'A' + int_pin - 1 : '?'), irq);
794 if (p->numa_node != -1)
795 printf("\tNUMA node: %d\n", p->numa_node);
800 if (cmd & PCI_COMMAND_MASTER)
801 printf("bus master, ");
802 if (cmd & PCI_COMMAND_VGA_PALETTE)
803 printf("VGA palette snoop, ");
804 if (cmd & PCI_COMMAND_WAIT)
805 printf("stepping, ");
806 if (cmd & PCI_COMMAND_FAST_BACK)
807 printf("fast Back2Back, ");
808 if (status & PCI_STATUS_66MHZ)
810 if (status & PCI_STATUS_UDF)
811 printf("user-definable features, ");
813 ((status & PCI_STATUS_DEVSEL_MASK) == PCI_STATUS_DEVSEL_SLOW) ? "slow" :
814 ((status & PCI_STATUS_DEVSEL_MASK) == PCI_STATUS_DEVSEL_MEDIUM) ? "medium" :
815 ((status & PCI_STATUS_DEVSEL_MASK) == PCI_STATUS_DEVSEL_FAST) ? "fast" : "??");
816 if (cmd & PCI_COMMAND_MASTER)
817 printf(", latency %d", latency);
819 printf(", IRQ " PCIIRQ_FMT, irq);
820 if (p->numa_node != -1)
821 printf(", NUMA node %d", p->numa_node);
825 if (bist & PCI_BIST_CAPABLE)
827 if (bist & PCI_BIST_START)
828 printf("\tBIST is running\n");
830 printf("\tBIST result: %02x\n", bist & PCI_BIST_CODE_MASK);
835 case PCI_HEADER_TYPE_NORMAL:
838 case PCI_HEADER_TYPE_BRIDGE:
841 case PCI_HEADER_TYPE_CARDBUS:
847 /*** Machine-readable dumps ***/
850 show_hex_dump(struct device *d)
854 cnt = d->config_cached;
855 if (opt_hex >= 3 && config_fetch(d, cnt, 256-cnt))
858 if (opt_hex >= 4 && config_fetch(d, 256, 4096-256))
862 for (i=0; i<cnt; i++)
866 printf(" %02x", get_conf_byte(d, i));
873 print_shell_escaped(char *c)
878 if (*c == '"' || *c == '\\')
886 show_machine(struct device *d)
888 struct pci_dev *p = d->dev;
891 char classbuf[128], vendbuf[128], devbuf[128], svbuf[128], sdbuf[128];
894 get_subid(d, &sv_id, &sd_id);
898 pci_fill_info(p, PCI_FILL_PHYS_SLOT | PCI_FILL_NUMA_NODE | PCI_FILL_DT_NODE);
899 printf((opt_machine >= 2) ? "Slot:\t" : "Device:\t");
902 printf("Class:\t%s\n",
903 pci_lookup_name(pacc, classbuf, sizeof(classbuf), PCI_LOOKUP_CLASS, p->device_class));
904 printf("Vendor:\t%s\n",
905 pci_lookup_name(pacc, vendbuf, sizeof(vendbuf), PCI_LOOKUP_VENDOR, p->vendor_id, p->device_id));
906 printf("Device:\t%s\n",
907 pci_lookup_name(pacc, devbuf, sizeof(devbuf), PCI_LOOKUP_DEVICE, p->vendor_id, p->device_id));
908 if (sv_id && sv_id != 0xffff)
910 printf("SVendor:\t%s\n",
911 pci_lookup_name(pacc, svbuf, sizeof(svbuf), PCI_LOOKUP_SUBSYSTEM | PCI_LOOKUP_VENDOR, sv_id));
912 printf("SDevice:\t%s\n",
913 pci_lookup_name(pacc, sdbuf, sizeof(sdbuf), PCI_LOOKUP_SUBSYSTEM | PCI_LOOKUP_DEVICE, p->vendor_id, p->device_id, sv_id, sd_id));
916 printf("PhySlot:\t%s\n", p->phy_slot);
917 if (c = get_conf_byte(d, PCI_REVISION_ID))
918 printf("Rev:\t%02x\n", c);
919 if (c = get_conf_byte(d, PCI_CLASS_PROG))
920 printf("ProgIf:\t%02x\n", c);
922 show_kernel_machine(d);
923 if (p->numa_node != -1)
924 printf("NUMANode:\t%d\n", p->numa_node);
925 if (dt_node = pci_get_string_property(p, PCI_FILL_DT_NODE))
926 printf("DTNode:\t%s\n", dt_node);
931 print_shell_escaped(pci_lookup_name(pacc, classbuf, sizeof(classbuf), PCI_LOOKUP_CLASS, p->device_class));
932 print_shell_escaped(pci_lookup_name(pacc, vendbuf, sizeof(vendbuf), PCI_LOOKUP_VENDOR, p->vendor_id, p->device_id));
933 print_shell_escaped(pci_lookup_name(pacc, devbuf, sizeof(devbuf), PCI_LOOKUP_DEVICE, p->vendor_id, p->device_id));
934 if (c = get_conf_byte(d, PCI_REVISION_ID))
935 printf(" -r%02x", c);
936 if (c = get_conf_byte(d, PCI_CLASS_PROG))
937 printf(" -p%02x", c);
938 if (sv_id && sv_id != 0xffff)
940 print_shell_escaped(pci_lookup_name(pacc, svbuf, sizeof(svbuf), PCI_LOOKUP_SUBSYSTEM | PCI_LOOKUP_VENDOR, sv_id));
941 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));
944 printf(" \"\" \"\"");
949 /*** Main show function ***/
952 show_device(struct device *d)
962 if (opt_kernel || verbose)
967 if (verbose || opt_hex)
976 for (d=first_dev; d; d=d->next)
977 if (pci_filter_match(&filter, d->dev))
984 main(int argc, char **argv)
989 if (argc == 2 && !strcmp(argv[1], "--version"))
991 puts("lspci version " PCIUTILS_VERSION);
997 pci_filter_init(pacc, &filter);
999 while ((i = getopt(argc, argv, options)) != -1)
1003 pacc->numeric_ids++;
1009 pacc->buscentric = 1;
1012 if (msg = pci_filter_parse_slot(&filter, optarg))
1017 if (msg = pci_filter_parse_id(&filter, optarg))
1033 pci_set_name_list_path(pacc, optarg, 0);
1039 opt_pcimap = optarg;
1062 die("DNS queries are not available in this version");
1065 if (parse_generic_option(i, pacc, optarg))
1068 fprintf(stderr, help_msg, pacc->id_file_name);
1076 pacc->id_lookup_mode |= PCI_LOOKUP_NETWORK;
1077 if (opt_query_dns > 1)
1078 pacc->id_lookup_mode |= PCI_LOOKUP_REFRESH_CACHE;
1081 pacc->id_lookup_mode |= PCI_LOOKUP_NETWORK | PCI_LOOKUP_SKIP_LOCAL;
1087 die("Bus mapping mode does not recognize bus topology");
1097 show_forest(opt_filter ? &filter : NULL);
1101 show_kernel_cleanup();
1104 return (seen_errors ? 2 : 0);