2 * The PCI Utilities -- List All PCI Devices
4 * Copyright (c) 1997--2008 Martin Mares <mj@ucw.cz>
6 * Can be freely distributed and used under the terms of the GNU GPL.
19 int verbose; /* Show detailed information */
20 static int opt_hex; /* Show contents of config space as hexadecimal numbers */
21 struct pci_filter filter; /* Device filter */
22 static int opt_tree; /* Show bus tree */
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:ti: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"
53 "Resolving of device ID's to names:\n"
54 "-n\t\tShow numeric ID's\n"
55 "-nn\t\tShow both textual and numeric ID's (names & numbers)\n"
57 "-q\t\tQuery the PCI ID database for unknown ID's via DNS\n"
58 "-qq\t\tAs above, but re-query locally cached entries\n"
59 "-Q\t\tQuery the PCI ID database for all ID's via DNS\n"
62 "Selection of devices:\n"
63 "-s [[[[<domain>]:]<bus>]:][<slot>][.[<func>]]\tShow only devices in selected slots\n"
64 "-d [<vendor>]:[<device>]\t\t\tShow only devices with specified ID's\n"
67 "-i <file>\tUse specified ID database instead of %s\n"
69 "-p <file>\tLook up kernel modules in a given file instead of default modules.pcimap\n"
71 "-M\t\tEnable `bus mapping' mode (dangerous; root only)\n"
73 "PCI access options:\n"
77 /*** Our view of the PCI bus ***/
79 struct pci_access *pacc;
80 struct device *first_dev;
81 static int seen_errors;
84 config_fetch(struct device *d, unsigned int pos, unsigned int len)
86 unsigned int end = pos+len;
89 while (pos < d->config_bufsize && len && d->present[pos])
91 while (pos+len <= d->config_bufsize && len && d->present[pos+len-1])
96 if (end > d->config_bufsize)
98 int orig_size = d->config_bufsize;
99 while (end > d->config_bufsize)
100 d->config_bufsize *= 2;
101 d->config = xrealloc(d->config, d->config_bufsize);
102 d->present = xrealloc(d->present, d->config_bufsize);
103 memset(d->present + orig_size, 0, d->config_bufsize - orig_size);
105 result = pci_read_block(d->dev, pos, d->config + pos, len);
107 memset(d->present + pos, 1, len);
112 scan_device(struct pci_dev *p)
116 if (p->domain && !opt_domains)
118 if (!pci_filter_match(&filter, p))
120 d = xmalloc(sizeof(struct device));
121 memset(d, 0, sizeof(*d));
123 d->config_cached = d->config_bufsize = 64;
124 d->config = xmalloc(64);
125 d->present = xmalloc(64);
126 memset(d->present, 1, 64);
127 if (!pci_read_block(p, 0, d->config, 64))
129 fprintf(stderr, "lspci: Unable to read the standard configuration space header of device %04x:%02x:%02x.%d\n",
130 p->domain, p->bus, p->dev, p->func);
134 if ((d->config[PCI_HEADER_TYPE] & 0x7f) == PCI_HEADER_TYPE_CARDBUS)
136 /* For cardbus bridges, we need to fetch 64 bytes more to get the
137 * full standard header... */
138 if (config_fetch(d, 64, 64))
139 d->config_cached += 64;
141 pci_setup_cache(p, d->config, d->config_cached);
142 pci_fill_info(p, PCI_FILL_IDENT | PCI_FILL_CLASS | PCI_FILL_IRQ | PCI_FILL_BASES | PCI_FILL_ROM_BASE | PCI_FILL_SIZES | PCI_FILL_PHYS_SLOT);
153 for (p=pacc->devices; p; p=p->next)
154 if (d = scan_device(p))
161 /*** Config space accesses ***/
164 check_conf_range(struct device *d, unsigned int pos, unsigned int len)
167 if (!d->present[pos])
168 die("Internal bug: Accessing non-read configuration byte at position %x", pos);
174 get_conf_byte(struct device *d, unsigned int pos)
176 check_conf_range(d, pos, 1);
177 return d->config[pos];
181 get_conf_word(struct device *d, unsigned int pos)
183 check_conf_range(d, pos, 2);
184 return d->config[pos] | (d->config[pos+1] << 8);
188 get_conf_long(struct device *d, unsigned int pos)
190 check_conf_range(d, pos, 4);
191 return d->config[pos] |
192 (d->config[pos+1] << 8) |
193 (d->config[pos+2] << 16) |
194 (d->config[pos+3] << 24);
200 compare_them(const void *A, const void *B)
202 const struct pci_dev *a = (*(const struct device **)A)->dev;
203 const struct pci_dev *b = (*(const struct device **)B)->dev;
205 if (a->domain < b->domain)
207 if (a->domain > b->domain)
217 if (a->func < b->func)
219 if (a->func > b->func)
227 struct device **index, **h, **last_dev;
232 for (d=first_dev; d; d=d->next)
234 h = index = alloca(sizeof(struct device *) * cnt);
235 for (d=first_dev; d; d=d->next)
237 qsort(index, cnt, sizeof(struct device *), compare_them);
238 last_dev = &first_dev;
243 last_dev = &(*h)->next;
249 /*** Normal output ***/
252 show_slot_name(struct device *d)
254 struct pci_dev *p = d->dev;
256 if (!opt_machine ? opt_domains : (p->domain || opt_domains >= 2))
257 printf("%04x:", p->domain);
258 printf("%02x:%02x.%d", p->bus, p->dev, p->func);
262 get_subid(struct device *d, word *subvp, word *subdp)
264 byte htype = get_conf_byte(d, PCI_HEADER_TYPE) & 0x7f;
266 if (htype == PCI_HEADER_TYPE_NORMAL)
268 *subvp = get_conf_word(d, PCI_SUBSYSTEM_VENDOR_ID);
269 *subdp = get_conf_word(d, PCI_SUBSYSTEM_ID);
271 else if (htype == PCI_HEADER_TYPE_CARDBUS && d->config_cached >= 128)
273 *subvp = get_conf_word(d, PCI_CB_SUBSYSTEM_VENDOR_ID);
274 *subdp = get_conf_word(d, PCI_CB_SUBSYSTEM_ID);
277 *subvp = *subdp = 0xffff;
281 show_terse(struct device *d)
284 struct pci_dev *p = d->dev;
285 char classbuf[128], devbuf[128];
289 pci_lookup_name(pacc, classbuf, sizeof(classbuf),
292 pci_lookup_name(pacc, devbuf, sizeof(devbuf),
293 PCI_LOOKUP_VENDOR | PCI_LOOKUP_DEVICE,
294 p->vendor_id, p->device_id));
295 if (c = get_conf_byte(d, PCI_REVISION_ID))
296 printf(" (rev %02x)", c);
300 c = get_conf_byte(d, PCI_CLASS_PROG);
301 x = pci_lookup_name(pacc, devbuf, sizeof(devbuf),
302 PCI_LOOKUP_PROGIF | PCI_LOOKUP_NO_NUMBERS,
306 printf(" (prog-if %02x", c);
314 if (verbose || opt_kernel)
316 word subsys_v, subsys_d;
319 get_subid(d, &subsys_v, &subsys_d);
320 if (subsys_v && subsys_v != 0xffff)
321 printf("\tSubsystem: %s\n",
322 pci_lookup_name(pacc, ssnamebuf, sizeof(ssnamebuf),
323 PCI_LOOKUP_SUBSYSTEM | PCI_LOOKUP_VENDOR | PCI_LOOKUP_DEVICE,
324 p->vendor_id, p->device_id, subsys_v, subsys_d));
328 /*** Verbose output ***/
331 show_size(pciaddr_t x)
337 printf("%d", (int) x);
338 else if (x < 1048576)
339 printf("%dK", (int)(x / 1024));
340 else if (x < 0x80000000)
341 printf("%dM", (int)(x / 1048576));
343 printf(PCIADDR_T_FMT, x);
348 show_bases(struct device *d, int cnt)
350 struct pci_dev *p = d->dev;
351 word cmd = get_conf_word(d, PCI_COMMAND);
355 for (i=0; i<cnt; i++)
357 pciaddr_t pos = p->base_addr[i];
358 pciaddr_t len = (p->known_fields & PCI_FILL_SIZES) ? p->size[i] : 0;
359 u32 flg = get_conf_long(d, PCI_BASE_ADDRESS_0 + 4*i);
360 if (flg == 0xffffffff)
362 if (!pos && !flg && !len)
365 printf("\tRegion %d: ", i);
368 if (pos && !flg) /* Reported by the OS, but not by the device */
370 printf("[virtual] ");
374 if (flg & PCI_BASE_ADDRESS_SPACE_IO)
376 pciaddr_t a = pos & PCI_BASE_ADDRESS_IO_MASK;
377 printf("I/O ports at ");
379 printf(PCIADDR_PORT_FMT, a);
380 else if (flg & PCI_BASE_ADDRESS_IO_MASK)
383 printf("<unassigned>");
384 if (!virtual && !(cmd & PCI_COMMAND_IO))
385 printf(" [disabled]");
389 int t = flg & PCI_BASE_ADDRESS_MEM_TYPE_MASK;
390 pciaddr_t a = pos & PCI_ADDR_MEM_MASK;
394 printf("Memory at ");
395 if (t == PCI_BASE_ADDRESS_MEM_TYPE_64)
399 printf("<invalid-64bit-slot>");
405 z = get_conf_long(d, PCI_BASE_ADDRESS_0 + 4*i);
411 printf(PCIADDR_T_FMT, a);
413 printf(((flg & PCI_BASE_ADDRESS_MEM_MASK) || z) ? "<ignored>" : "<unassigned>");
415 printf(" (%s, %sprefetchable)",
416 (t == PCI_BASE_ADDRESS_MEM_TYPE_32) ? "32-bit" :
417 (t == PCI_BASE_ADDRESS_MEM_TYPE_64) ? "64-bit" :
418 (t == PCI_BASE_ADDRESS_MEM_TYPE_1M) ? "low-1M" : "type 3",
419 (flg & PCI_BASE_ADDRESS_MEM_PREFETCH) ? "" : "non-");
420 if (!virtual && !(cmd & PCI_COMMAND_MEMORY))
421 printf(" [disabled]");
429 show_rom(struct device *d, int reg)
431 struct pci_dev *p = d->dev;
432 pciaddr_t rom = p->rom_base_addr;
433 pciaddr_t len = (p->known_fields & PCI_FILL_SIZES) ? p->rom_size : 0;
434 u32 flg = get_conf_long(d, reg);
435 word cmd = get_conf_word(d, PCI_COMMAND);
438 if (!rom && !flg && !len)
441 if ((rom & PCI_ROM_ADDRESS_MASK) && !(flg & PCI_ROM_ADDRESS_MASK))
443 printf("[virtual] ");
447 printf("Expansion ROM at ");
448 if (rom & PCI_ROM_ADDRESS_MASK)
449 printf(PCIADDR_T_FMT, rom & PCI_ROM_ADDRESS_MASK);
450 else if (flg & PCI_ROM_ADDRESS_MASK)
453 printf("<unassigned>");
454 if (!(flg & PCI_ROM_ADDRESS_ENABLE))
455 printf(" [disabled]");
456 else if (!virtual && !(cmd & PCI_COMMAND_MEMORY))
457 printf(" [disabled by cmd]");
463 show_htype0(struct device *d)
466 show_rom(d, PCI_ROM_ADDRESS);
471 show_htype1(struct device *d)
473 u32 io_base = get_conf_byte(d, PCI_IO_BASE);
474 u32 io_limit = get_conf_byte(d, PCI_IO_LIMIT);
475 u32 io_type = io_base & PCI_IO_RANGE_TYPE_MASK;
476 u32 mem_base = get_conf_word(d, PCI_MEMORY_BASE);
477 u32 mem_limit = get_conf_word(d, PCI_MEMORY_LIMIT);
478 u32 mem_type = mem_base & PCI_MEMORY_RANGE_TYPE_MASK;
479 u32 pref_base = get_conf_word(d, PCI_PREF_MEMORY_BASE);
480 u32 pref_limit = get_conf_word(d, PCI_PREF_MEMORY_LIMIT);
481 u32 pref_type = pref_base & PCI_PREF_RANGE_TYPE_MASK;
482 word sec_stat = get_conf_word(d, PCI_SEC_STATUS);
483 word brc = get_conf_word(d, PCI_BRIDGE_CONTROL);
484 int verb = verbose > 2;
487 printf("\tBus: primary=%02x, secondary=%02x, subordinate=%02x, sec-latency=%d\n",
488 get_conf_byte(d, PCI_PRIMARY_BUS),
489 get_conf_byte(d, PCI_SECONDARY_BUS),
490 get_conf_byte(d, PCI_SUBORDINATE_BUS),
491 get_conf_byte(d, PCI_SEC_LATENCY_TIMER));
493 if (io_type != (io_limit & PCI_IO_RANGE_TYPE_MASK) ||
494 (io_type != PCI_IO_RANGE_TYPE_16 && io_type != PCI_IO_RANGE_TYPE_32))
495 printf("\t!!! Unknown I/O range types %x/%x\n", io_base, io_limit);
498 io_base = (io_base & PCI_IO_RANGE_MASK) << 8;
499 io_limit = (io_limit & PCI_IO_RANGE_MASK) << 8;
500 if (io_type == PCI_IO_RANGE_TYPE_32)
502 io_base |= (get_conf_word(d, PCI_IO_BASE_UPPER16) << 16);
503 io_limit |= (get_conf_word(d, PCI_IO_LIMIT_UPPER16) << 16);
505 if (io_base <= io_limit || verb)
506 printf("\tI/O behind bridge: %08x-%08x\n", io_base, io_limit+0xfff);
509 if (mem_type != (mem_limit & PCI_MEMORY_RANGE_TYPE_MASK) ||
511 printf("\t!!! Unknown memory range types %x/%x\n", mem_base, mem_limit);
514 mem_base = (mem_base & PCI_MEMORY_RANGE_MASK) << 16;
515 mem_limit = (mem_limit & PCI_MEMORY_RANGE_MASK) << 16;
516 if (mem_base <= mem_limit || verb)
517 printf("\tMemory behind bridge: %08x-%08x\n", mem_base, mem_limit + 0xfffff);
520 if (pref_type != (pref_limit & PCI_PREF_RANGE_TYPE_MASK) ||
521 (pref_type != PCI_PREF_RANGE_TYPE_32 && pref_type != PCI_PREF_RANGE_TYPE_64))
522 printf("\t!!! Unknown prefetchable memory range types %x/%x\n", pref_base, pref_limit);
525 pref_base = (pref_base & PCI_PREF_RANGE_MASK) << 16;
526 pref_limit = (pref_limit & PCI_PREF_RANGE_MASK) << 16;
527 if (pref_base <= pref_limit || verb)
529 if (pref_type == PCI_PREF_RANGE_TYPE_32)
530 printf("\tPrefetchable memory behind bridge: %08x-%08x\n", pref_base, pref_limit + 0xfffff);
532 printf("\tPrefetchable memory behind bridge: %08x%08x-%08x%08x\n",
533 get_conf_long(d, PCI_PREF_BASE_UPPER32),
535 get_conf_long(d, PCI_PREF_LIMIT_UPPER32),
536 pref_limit + 0xfffff);
541 printf("\tSecondary status: 66MHz%c FastB2B%c ParErr%c DEVSEL=%s >TAbort%c <TAbort%c <MAbort%c <SERR%c <PERR%c\n",
542 FLAG(sec_stat, PCI_STATUS_66MHZ),
543 FLAG(sec_stat, PCI_STATUS_FAST_BACK),
544 FLAG(sec_stat, PCI_STATUS_PARITY),
545 ((sec_stat & PCI_STATUS_DEVSEL_MASK) == PCI_STATUS_DEVSEL_SLOW) ? "slow" :
546 ((sec_stat & PCI_STATUS_DEVSEL_MASK) == PCI_STATUS_DEVSEL_MEDIUM) ? "medium" :
547 ((sec_stat & PCI_STATUS_DEVSEL_MASK) == PCI_STATUS_DEVSEL_FAST) ? "fast" : "??",
548 FLAG(sec_stat, PCI_STATUS_SIG_TARGET_ABORT),
549 FLAG(sec_stat, PCI_STATUS_REC_TARGET_ABORT),
550 FLAG(sec_stat, PCI_STATUS_REC_MASTER_ABORT),
551 FLAG(sec_stat, PCI_STATUS_SIG_SYSTEM_ERROR),
552 FLAG(sec_stat, PCI_STATUS_DETECTED_PARITY));
554 show_rom(d, PCI_ROM_ADDRESS1);
558 printf("\tBridgeCtl: Parity%c SERR%c NoISA%c VGA%c MAbort%c >Reset%c FastB2B%c\n",
559 FLAG(brc, PCI_BRIDGE_CTL_PARITY),
560 FLAG(brc, PCI_BRIDGE_CTL_SERR),
561 FLAG(brc, PCI_BRIDGE_CTL_NO_ISA),
562 FLAG(brc, PCI_BRIDGE_CTL_VGA),
563 FLAG(brc, PCI_BRIDGE_CTL_MASTER_ABORT),
564 FLAG(brc, PCI_BRIDGE_CTL_BUS_RESET),
565 FLAG(brc, PCI_BRIDGE_CTL_FAST_BACK));
566 printf("\t\tPriDiscTmr%c SecDiscTmr%c DiscTmrStat%c DiscTmrSERREn%c\n",
567 FLAG(brc, PCI_BRIDGE_CTL_PRI_DISCARD_TIMER),
568 FLAG(brc, PCI_BRIDGE_CTL_SEC_DISCARD_TIMER),
569 FLAG(brc, PCI_BRIDGE_CTL_DISCARD_TIMER_STATUS),
570 FLAG(brc, PCI_BRIDGE_CTL_DISCARD_TIMER_SERR_EN));
577 show_htype2(struct device *d)
580 word cmd = get_conf_word(d, PCI_COMMAND);
581 word brc = get_conf_word(d, PCI_CB_BRIDGE_CONTROL);
583 int verb = verbose > 2;
586 printf("\tBus: primary=%02x, secondary=%02x, subordinate=%02x, sec-latency=%d\n",
587 get_conf_byte(d, PCI_CB_PRIMARY_BUS),
588 get_conf_byte(d, PCI_CB_CARD_BUS),
589 get_conf_byte(d, PCI_CB_SUBORDINATE_BUS),
590 get_conf_byte(d, PCI_CB_LATENCY_TIMER));
594 u32 base = get_conf_long(d, PCI_CB_MEMORY_BASE_0 + p);
595 u32 limit = get_conf_long(d, PCI_CB_MEMORY_LIMIT_0 + p);
596 if (limit > base || verb)
597 printf("\tMemory window %d: %08x-%08x%s%s\n", i, base, limit,
598 (cmd & PCI_COMMAND_MEMORY) ? "" : " [disabled]",
599 (brc & (PCI_CB_BRIDGE_CTL_PREFETCH_MEM0 << i)) ? " (prefetchable)" : "");
604 u32 base = get_conf_long(d, PCI_CB_IO_BASE_0 + p);
605 u32 limit = get_conf_long(d, PCI_CB_IO_LIMIT_0 + p);
606 if (!(base & PCI_IO_RANGE_TYPE_32))
611 base &= PCI_CB_IO_RANGE_MASK;
612 limit = (limit & PCI_CB_IO_RANGE_MASK) + 3;
613 if (base <= limit || verb)
614 printf("\tI/O window %d: %08x-%08x%s\n", i, base, limit,
615 (cmd & PCI_COMMAND_IO) ? "" : " [disabled]");
618 if (get_conf_word(d, PCI_CB_SEC_STATUS) & PCI_STATUS_SIG_SYSTEM_ERROR)
619 printf("\tSecondary status: SERR\n");
621 printf("\tBridgeCtl: Parity%c SERR%c ISA%c VGA%c MAbort%c >Reset%c 16bInt%c PostWrite%c\n",
622 FLAG(brc, PCI_CB_BRIDGE_CTL_PARITY),
623 FLAG(brc, PCI_CB_BRIDGE_CTL_SERR),
624 FLAG(brc, PCI_CB_BRIDGE_CTL_ISA),
625 FLAG(brc, PCI_CB_BRIDGE_CTL_VGA),
626 FLAG(brc, PCI_CB_BRIDGE_CTL_MASTER_ABORT),
627 FLAG(brc, PCI_CB_BRIDGE_CTL_CB_RESET),
628 FLAG(brc, PCI_CB_BRIDGE_CTL_16BIT_INT),
629 FLAG(brc, PCI_CB_BRIDGE_CTL_POST_WRITES));
631 if (d->config_cached < 128)
633 printf("\t<access denied to the rest>\n");
637 exca = get_conf_word(d, PCI_CB_LEGACY_MODE_BASE);
639 printf("\t16-bit legacy interface ports at %04x\n", exca);
643 show_verbose(struct device *d)
645 struct pci_dev *p = d->dev;
646 word status = get_conf_word(d, PCI_STATUS);
647 word cmd = get_conf_word(d, PCI_COMMAND);
648 word class = p->device_class;
649 byte bist = get_conf_byte(d, PCI_BIST);
650 byte htype = get_conf_byte(d, PCI_HEADER_TYPE) & 0x7f;
651 byte latency = get_conf_byte(d, PCI_LATENCY_TIMER);
652 byte cache_line = get_conf_byte(d, PCI_CACHE_LINE_SIZE);
653 byte max_lat, min_gnt;
654 byte int_pin = get_conf_byte(d, PCI_INTERRUPT_PIN);
655 unsigned int irq = p->irq;
661 case PCI_HEADER_TYPE_NORMAL:
662 if (class == PCI_CLASS_BRIDGE_PCI)
663 printf("\t!!! Invalid class %04x for header type %02x\n", class, htype);
664 max_lat = get_conf_byte(d, PCI_MAX_LAT);
665 min_gnt = get_conf_byte(d, PCI_MIN_GNT);
667 case PCI_HEADER_TYPE_BRIDGE:
668 if ((class >> 8) != PCI_BASE_CLASS_BRIDGE)
669 printf("\t!!! Invalid class %04x for header type %02x\n", class, htype);
670 irq = int_pin = min_gnt = max_lat = 0;
672 case PCI_HEADER_TYPE_CARDBUS:
673 if ((class >> 8) != PCI_BASE_CLASS_BRIDGE)
674 printf("\t!!! Invalid class %04x for header type %02x\n", class, htype);
675 min_gnt = max_lat = 0;
678 printf("\t!!! Unknown header type %02x\n", htype);
683 printf("\tPhysical Slot: %s\n", p->phy_slot);
687 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",
688 FLAG(cmd, PCI_COMMAND_IO),
689 FLAG(cmd, PCI_COMMAND_MEMORY),
690 FLAG(cmd, PCI_COMMAND_MASTER),
691 FLAG(cmd, PCI_COMMAND_SPECIAL),
692 FLAG(cmd, PCI_COMMAND_INVALIDATE),
693 FLAG(cmd, PCI_COMMAND_VGA_PALETTE),
694 FLAG(cmd, PCI_COMMAND_PARITY),
695 FLAG(cmd, PCI_COMMAND_WAIT),
696 FLAG(cmd, PCI_COMMAND_SERR),
697 FLAG(cmd, PCI_COMMAND_FAST_BACK),
698 FLAG(cmd, PCI_COMMAND_DISABLE_INTx));
699 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",
700 FLAG(status, PCI_STATUS_CAP_LIST),
701 FLAG(status, PCI_STATUS_66MHZ),
702 FLAG(status, PCI_STATUS_UDF),
703 FLAG(status, PCI_STATUS_FAST_BACK),
704 FLAG(status, PCI_STATUS_PARITY),
705 ((status & PCI_STATUS_DEVSEL_MASK) == PCI_STATUS_DEVSEL_SLOW) ? "slow" :
706 ((status & PCI_STATUS_DEVSEL_MASK) == PCI_STATUS_DEVSEL_MEDIUM) ? "medium" :
707 ((status & PCI_STATUS_DEVSEL_MASK) == PCI_STATUS_DEVSEL_FAST) ? "fast" : "??",
708 FLAG(status, PCI_STATUS_SIG_TARGET_ABORT),
709 FLAG(status, PCI_STATUS_REC_TARGET_ABORT),
710 FLAG(status, PCI_STATUS_REC_MASTER_ABORT),
711 FLAG(status, PCI_STATUS_SIG_SYSTEM_ERROR),
712 FLAG(status, PCI_STATUS_DETECTED_PARITY),
713 FLAG(status, PCI_STATUS_INTx));
714 if (cmd & PCI_COMMAND_MASTER)
716 printf("\tLatency: %d", latency);
717 if (min_gnt || max_lat)
721 printf("%dns min", min_gnt*250);
722 if (min_gnt && max_lat)
725 printf("%dns max", max_lat*250);
729 printf(", Cache Line Size: %d bytes", cache_line * 4);
733 printf("\tInterrupt: pin %c routed to IRQ " PCIIRQ_FMT "\n",
734 (int_pin ? 'A' + int_pin - 1 : '?'), irq);
739 if (cmd & PCI_COMMAND_MASTER)
740 printf("bus master, ");
741 if (cmd & PCI_COMMAND_VGA_PALETTE)
742 printf("VGA palette snoop, ");
743 if (cmd & PCI_COMMAND_WAIT)
744 printf("stepping, ");
745 if (cmd & PCI_COMMAND_FAST_BACK)
746 printf("fast Back2Back, ");
747 if (status & PCI_STATUS_66MHZ)
749 if (status & PCI_STATUS_UDF)
750 printf("user-definable features, ");
752 ((status & PCI_STATUS_DEVSEL_MASK) == PCI_STATUS_DEVSEL_SLOW) ? "slow" :
753 ((status & PCI_STATUS_DEVSEL_MASK) == PCI_STATUS_DEVSEL_MEDIUM) ? "medium" :
754 ((status & PCI_STATUS_DEVSEL_MASK) == PCI_STATUS_DEVSEL_FAST) ? "fast" : "??");
755 if (cmd & PCI_COMMAND_MASTER)
756 printf(", latency %d", latency);
758 printf(", IRQ " PCIIRQ_FMT, irq);
762 if (bist & PCI_BIST_CAPABLE)
764 if (bist & PCI_BIST_START)
765 printf("\tBIST is running\n");
767 printf("\tBIST result: %02x\n", bist & PCI_BIST_CODE_MASK);
772 case PCI_HEADER_TYPE_NORMAL:
775 case PCI_HEADER_TYPE_BRIDGE:
778 case PCI_HEADER_TYPE_CARDBUS:
784 /*** Machine-readable dumps ***/
787 show_hex_dump(struct device *d)
791 cnt = d->config_cached;
792 if (opt_hex >= 3 && config_fetch(d, cnt, 256-cnt))
795 if (opt_hex >= 4 && config_fetch(d, 256, 4096-256))
799 for (i=0; i<cnt; i++)
803 printf(" %02x", get_conf_byte(d, i));
810 print_shell_escaped(char *c)
815 if (*c == '"' || *c == '\\')
823 show_machine(struct device *d)
825 struct pci_dev *p = d->dev;
828 char classbuf[128], vendbuf[128], devbuf[128], svbuf[128], sdbuf[128];
830 get_subid(d, &sv_id, &sd_id);
834 printf((opt_machine >= 2) ? "Slot:\t" : "Device:\t");
837 printf("Class:\t%s\n",
838 pci_lookup_name(pacc, classbuf, sizeof(classbuf), PCI_LOOKUP_CLASS, p->device_class));
839 printf("Vendor:\t%s\n",
840 pci_lookup_name(pacc, vendbuf, sizeof(vendbuf), PCI_LOOKUP_VENDOR, p->vendor_id, p->device_id));
841 printf("Device:\t%s\n",
842 pci_lookup_name(pacc, devbuf, sizeof(devbuf), PCI_LOOKUP_DEVICE, p->vendor_id, p->device_id));
843 if (sv_id && sv_id != 0xffff)
845 printf("SVendor:\t%s\n",
846 pci_lookup_name(pacc, svbuf, sizeof(svbuf), PCI_LOOKUP_SUBSYSTEM | PCI_LOOKUP_VENDOR, sv_id));
847 printf("SDevice:\t%s\n",
848 pci_lookup_name(pacc, sdbuf, sizeof(sdbuf), PCI_LOOKUP_SUBSYSTEM | PCI_LOOKUP_DEVICE, p->vendor_id, p->device_id, sv_id, sd_id));
851 printf("PhySlot:\t%s\n", p->phy_slot);
852 if (c = get_conf_byte(d, PCI_REVISION_ID))
853 printf("Rev:\t%02x\n", c);
854 if (c = get_conf_byte(d, PCI_CLASS_PROG))
855 printf("ProgIf:\t%02x\n", c);
857 show_kernel_machine(d);
862 print_shell_escaped(pci_lookup_name(pacc, classbuf, sizeof(classbuf), PCI_LOOKUP_CLASS, p->device_class));
863 print_shell_escaped(pci_lookup_name(pacc, vendbuf, sizeof(vendbuf), PCI_LOOKUP_VENDOR, p->vendor_id, p->device_id));
864 print_shell_escaped(pci_lookup_name(pacc, devbuf, sizeof(devbuf), PCI_LOOKUP_DEVICE, p->vendor_id, p->device_id));
865 if (c = get_conf_byte(d, PCI_REVISION_ID))
866 printf(" -r%02x", c);
867 if (c = get_conf_byte(d, PCI_CLASS_PROG))
868 printf(" -p%02x", c);
869 if (sv_id && sv_id != 0xffff)
871 print_shell_escaped(pci_lookup_name(pacc, svbuf, sizeof(svbuf), PCI_LOOKUP_SUBSYSTEM | PCI_LOOKUP_VENDOR, sv_id));
872 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));
875 printf(" \"\" \"\"");
880 /*** Main show function ***/
883 show_device(struct device *d)
893 if (opt_kernel || verbose)
898 if (verbose || opt_hex)
907 for (d=first_dev; d; d=d->next)
914 main(int argc, char **argv)
919 if (argc == 2 && !strcmp(argv[1], "--version"))
921 puts("lspci version " PCIUTILS_VERSION);
927 pci_filter_init(pacc, &filter);
929 while ((i = getopt(argc, argv, options)) != -1)
939 pacc->buscentric = 1;
942 if (msg = pci_filter_parse_slot(&filter, optarg))
946 if (msg = pci_filter_parse_id(&filter, optarg))
956 pci_set_name_list_path(pacc, optarg, 0);
985 die("DNS queries are not available in this version");
988 if (parse_generic_option(i, pacc, optarg))
991 fprintf(stderr, help_msg, pacc->id_file_name);
999 pacc->id_lookup_mode |= PCI_LOOKUP_NETWORK;
1000 if (opt_query_dns > 1)
1001 pacc->id_lookup_mode |= PCI_LOOKUP_REFRESH_CACHE;
1004 pacc->id_lookup_mode |= PCI_LOOKUP_NETWORK | PCI_LOOKUP_SKIP_LOCAL;
1020 return (seen_errors ? 2 : 0);