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_buscentric; /* Show bus addresses/IRQ's instead of CPU-visible ones */
21 static int opt_hex; /* Show contents of config space as hexadecimal numbers */
22 struct pci_filter filter; /* Device filter */
23 static int opt_tree; /* Show bus tree */
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:ti: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 for very verbose)\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"
54 "Resolving of device ID's to names:\n"
55 "-n\t\tShow numeric ID's\n"
56 "-nn\t\tShow both textual and numeric ID's (names & numbers)\n"
58 "-q\t\tQuery the PCI ID database for unknown ID's via DNS\n"
59 "-qq\t\tAs above, but re-query locally cached entries\n"
60 "-Q\t\tQuery the PCI ID database for all ID's via DNS\n"
63 "Selection of devices:\n"
64 "-s [[[[<domain>]:]<bus>]:][<slot>][.[<func>]]\tShow only devices in selected slots\n"
65 "-d [<vendor>]:[<device>]\t\t\tShow only devices with specified ID's\n"
68 "-i <file>\tUse specified ID database instead of %s\n"
70 "-p <file>\tLook up kernel modules in a given file instead of default modules.pcimap\n"
72 "-M\t\tEnable `bus mapping' mode (dangerous; root only)\n"
74 "PCI access options:\n"
78 /*** Our view of the PCI bus ***/
80 struct pci_access *pacc;
81 struct device *first_dev;
82 static int seen_errors;
85 config_fetch(struct device *d, unsigned int pos, unsigned int len)
87 unsigned int end = pos+len;
90 while (pos < d->config_bufsize && len && d->present[pos])
92 while (pos+len <= d->config_bufsize && len && d->present[pos+len-1])
97 if (end > d->config_bufsize)
99 int orig_size = d->config_bufsize;
100 while (end > d->config_bufsize)
101 d->config_bufsize *= 2;
102 d->config = xrealloc(d->config, d->config_bufsize);
103 d->present = xrealloc(d->present, d->config_bufsize);
104 memset(d->present + orig_size, 0, d->config_bufsize - orig_size);
106 result = pci_read_block(d->dev, pos, d->config + pos, len);
108 memset(d->present + pos, 1, len);
113 scan_device(struct pci_dev *p)
117 if (p->domain && !opt_domains)
119 if (!pci_filter_match(&filter, p))
121 d = xmalloc(sizeof(struct device));
122 memset(d, 0, sizeof(*d));
124 d->config_cached = d->config_bufsize = 64;
125 d->config = xmalloc(64);
126 d->present = xmalloc(64);
127 memset(d->present, 1, 64);
128 if (!pci_read_block(p, 0, d->config, 64))
130 fprintf(stderr, "lspci: Unable to read the standard configuration space header of device %04x:%02x:%02x.%d\n",
131 p->domain, p->bus, p->dev, p->func);
135 if ((d->config[PCI_HEADER_TYPE] & 0x7f) == PCI_HEADER_TYPE_CARDBUS)
137 /* For cardbus bridges, we need to fetch 64 bytes more to get the
138 * full standard header... */
139 if (config_fetch(d, 64, 64))
140 d->config_cached += 64;
142 pci_setup_cache(p, d->config, d->config_cached);
143 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);
154 for (p=pacc->devices; p; p=p->next)
155 if (d = scan_device(p))
162 /*** Config space accesses ***/
165 check_conf_range(struct device *d, unsigned int pos, unsigned int len)
168 if (!d->present[pos])
169 die("Internal bug: Accessing non-read configuration byte at position %x", pos);
175 get_conf_byte(struct device *d, unsigned int pos)
177 check_conf_range(d, pos, 1);
178 return d->config[pos];
182 get_conf_word(struct device *d, unsigned int pos)
184 check_conf_range(d, pos, 2);
185 return d->config[pos] | (d->config[pos+1] << 8);
189 get_conf_long(struct device *d, unsigned int pos)
191 check_conf_range(d, pos, 4);
192 return d->config[pos] |
193 (d->config[pos+1] << 8) |
194 (d->config[pos+2] << 16) |
195 (d->config[pos+3] << 24);
201 compare_them(const void *A, const void *B)
203 const struct pci_dev *a = (*(const struct device **)A)->dev;
204 const struct pci_dev *b = (*(const struct device **)B)->dev;
206 if (a->domain < b->domain)
208 if (a->domain > b->domain)
218 if (a->func < b->func)
220 if (a->func > b->func)
228 struct device **index, **h, **last_dev;
233 for (d=first_dev; d; d=d->next)
235 h = index = alloca(sizeof(struct device *) * cnt);
236 for (d=first_dev; d; d=d->next)
238 qsort(index, cnt, sizeof(struct device *), compare_them);
239 last_dev = &first_dev;
244 last_dev = &(*h)->next;
250 /*** Normal output ***/
253 show_slot_name(struct device *d)
255 struct pci_dev *p = d->dev;
257 if (!opt_machine ? opt_domains : (p->domain || opt_domains >= 2))
258 printf("%04x:", p->domain);
259 printf("%02x:%02x.%d", p->bus, p->dev, p->func);
263 get_subid(struct device *d, word *subvp, word *subdp)
265 byte htype = get_conf_byte(d, PCI_HEADER_TYPE) & 0x7f;
267 if (htype == PCI_HEADER_TYPE_NORMAL)
269 *subvp = get_conf_word(d, PCI_SUBSYSTEM_VENDOR_ID);
270 *subdp = get_conf_word(d, PCI_SUBSYSTEM_ID);
272 else if (htype == PCI_HEADER_TYPE_CARDBUS && d->config_cached >= 128)
274 *subvp = get_conf_word(d, PCI_CB_SUBSYSTEM_VENDOR_ID);
275 *subdp = get_conf_word(d, PCI_CB_SUBSYSTEM_ID);
278 *subvp = *subdp = 0xffff;
282 show_terse(struct device *d)
285 struct pci_dev *p = d->dev;
286 char classbuf[128], devbuf[128];
290 pci_lookup_name(pacc, classbuf, sizeof(classbuf),
293 pci_lookup_name(pacc, devbuf, sizeof(devbuf),
294 PCI_LOOKUP_VENDOR | PCI_LOOKUP_DEVICE,
295 p->vendor_id, p->device_id));
296 if (c = get_conf_byte(d, PCI_REVISION_ID))
297 printf(" (rev %02x)", c);
301 c = get_conf_byte(d, PCI_CLASS_PROG);
302 x = pci_lookup_name(pacc, devbuf, sizeof(devbuf),
303 PCI_LOOKUP_PROGIF | PCI_LOOKUP_NO_NUMBERS,
307 printf(" (prog-if %02x", c);
315 if (verbose || opt_kernel)
317 word subsys_v, subsys_d;
320 get_subid(d, &subsys_v, &subsys_d);
321 if (subsys_v && subsys_v != 0xffff)
322 printf("\tSubsystem: %s\n",
323 pci_lookup_name(pacc, ssnamebuf, sizeof(ssnamebuf),
324 PCI_LOOKUP_SUBSYSTEM | PCI_LOOKUP_VENDOR | PCI_LOOKUP_DEVICE,
325 p->vendor_id, p->device_id, subsys_v, subsys_d));
329 /*** Verbose output ***/
332 show_size(pciaddr_t x)
338 printf("%d", (int) x);
339 else if (x < 1048576)
340 printf("%dK", (int)(x / 1024));
341 else if (x < 0x80000000)
342 printf("%dM", (int)(x / 1048576));
344 printf(PCIADDR_T_FMT, x);
349 show_bases(struct device *d, int cnt)
351 struct pci_dev *p = d->dev;
352 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] ");
373 if (flg & PCI_BASE_ADDRESS_SPACE_IO)
375 pciaddr_t a = pos & PCI_BASE_ADDRESS_IO_MASK;
376 printf("I/O ports at ");
378 printf(PCIADDR_PORT_FMT, a);
379 else if (flg & PCI_BASE_ADDRESS_IO_MASK)
382 printf("<unassigned>");
383 if (!(cmd & PCI_COMMAND_IO))
384 printf(" [disabled]");
388 int t = flg & PCI_BASE_ADDRESS_MEM_TYPE_MASK;
389 pciaddr_t a = pos & PCI_ADDR_MEM_MASK;
393 printf("Memory at ");
394 if (t == PCI_BASE_ADDRESS_MEM_TYPE_64)
398 printf("<invalid-64bit-slot>");
404 z = get_conf_long(d, PCI_BASE_ADDRESS_0 + 4*i);
407 u32 y = a & 0xffffffff;
409 printf("%08x%08x", z, y);
411 printf("<unassigned>");
419 printf(PCIADDR_T_FMT, a);
421 printf(((flg & PCI_BASE_ADDRESS_MEM_MASK) || z) ? "<ignored>" : "<unassigned>");
423 printf(" (%s, %sprefetchable)",
424 (t == PCI_BASE_ADDRESS_MEM_TYPE_32) ? "32-bit" :
425 (t == PCI_BASE_ADDRESS_MEM_TYPE_64) ? "64-bit" :
426 (t == PCI_BASE_ADDRESS_MEM_TYPE_1M) ? "low-1M" : "type 3",
427 (flg & PCI_BASE_ADDRESS_MEM_PREFETCH) ? "" : "non-");
428 if (!(cmd & PCI_COMMAND_MEMORY))
429 printf(" [disabled]");
437 show_rom(struct device *d, int reg)
439 struct pci_dev *p = d->dev;
440 pciaddr_t rom = p->rom_base_addr;
441 pciaddr_t len = (p->known_fields & PCI_FILL_SIZES) ? p->rom_size : 0;
442 u32 flg = get_conf_long(d, reg);
443 word cmd = get_conf_word(d, PCI_COMMAND);
445 if (!rom && !flg && !len)
448 if ((rom & PCI_ROM_ADDRESS_MASK) && !(flg & PCI_ROM_ADDRESS_MASK))
450 printf("[virtual] ");
453 printf("Expansion ROM at ");
454 if (rom & PCI_ROM_ADDRESS_MASK)
455 printf(PCIADDR_T_FMT, rom & PCI_ROM_ADDRESS_MASK);
456 else if (flg & PCI_ROM_ADDRESS_MASK)
459 printf("<unassigned>");
460 if (!(flg & PCI_ROM_ADDRESS_ENABLE))
461 printf(" [disabled]");
462 else if (!(cmd & PCI_COMMAND_MEMORY))
463 printf(" [disabled by cmd]");
469 show_htype0(struct device *d)
472 show_rom(d, PCI_ROM_ADDRESS);
477 show_htype1(struct device *d)
479 u32 io_base = get_conf_byte(d, PCI_IO_BASE);
480 u32 io_limit = get_conf_byte(d, PCI_IO_LIMIT);
481 u32 io_type = io_base & PCI_IO_RANGE_TYPE_MASK;
482 u32 mem_base = get_conf_word(d, PCI_MEMORY_BASE);
483 u32 mem_limit = get_conf_word(d, PCI_MEMORY_LIMIT);
484 u32 mem_type = mem_base & PCI_MEMORY_RANGE_TYPE_MASK;
485 u32 pref_base = get_conf_word(d, PCI_PREF_MEMORY_BASE);
486 u32 pref_limit = get_conf_word(d, PCI_PREF_MEMORY_LIMIT);
487 u32 pref_type = pref_base & PCI_PREF_RANGE_TYPE_MASK;
488 word sec_stat = get_conf_word(d, PCI_SEC_STATUS);
489 word brc = get_conf_word(d, PCI_BRIDGE_CONTROL);
490 int verb = verbose > 2;
493 printf("\tBus: primary=%02x, secondary=%02x, subordinate=%02x, sec-latency=%d\n",
494 get_conf_byte(d, PCI_PRIMARY_BUS),
495 get_conf_byte(d, PCI_SECONDARY_BUS),
496 get_conf_byte(d, PCI_SUBORDINATE_BUS),
497 get_conf_byte(d, PCI_SEC_LATENCY_TIMER));
499 if (io_type != (io_limit & PCI_IO_RANGE_TYPE_MASK) ||
500 (io_type != PCI_IO_RANGE_TYPE_16 && io_type != PCI_IO_RANGE_TYPE_32))
501 printf("\t!!! Unknown I/O range types %x/%x\n", io_base, io_limit);
504 io_base = (io_base & PCI_IO_RANGE_MASK) << 8;
505 io_limit = (io_limit & PCI_IO_RANGE_MASK) << 8;
506 if (io_type == PCI_IO_RANGE_TYPE_32)
508 io_base |= (get_conf_word(d, PCI_IO_BASE_UPPER16) << 16);
509 io_limit |= (get_conf_word(d, PCI_IO_LIMIT_UPPER16) << 16);
511 if (io_base <= io_limit || verb)
512 printf("\tI/O behind bridge: %08x-%08x\n", io_base, io_limit+0xfff);
515 if (mem_type != (mem_limit & PCI_MEMORY_RANGE_TYPE_MASK) ||
517 printf("\t!!! Unknown memory range types %x/%x\n", mem_base, mem_limit);
520 mem_base = (mem_base & PCI_MEMORY_RANGE_MASK) << 16;
521 mem_limit = (mem_limit & PCI_MEMORY_RANGE_MASK) << 16;
522 if (mem_base <= mem_limit || verb)
523 printf("\tMemory behind bridge: %08x-%08x\n", mem_base, mem_limit + 0xfffff);
526 if (pref_type != (pref_limit & PCI_PREF_RANGE_TYPE_MASK) ||
527 (pref_type != PCI_PREF_RANGE_TYPE_32 && pref_type != PCI_PREF_RANGE_TYPE_64))
528 printf("\t!!! Unknown prefetchable memory range types %x/%x\n", pref_base, pref_limit);
531 pref_base = (pref_base & PCI_PREF_RANGE_MASK) << 16;
532 pref_limit = (pref_limit & PCI_PREF_RANGE_MASK) << 16;
533 if (pref_base <= pref_limit || verb)
535 if (pref_type == PCI_PREF_RANGE_TYPE_32)
536 printf("\tPrefetchable memory behind bridge: %08x-%08x\n", pref_base, pref_limit + 0xfffff);
538 printf("\tPrefetchable memory behind bridge: %08x%08x-%08x%08x\n",
539 get_conf_long(d, PCI_PREF_BASE_UPPER32),
541 get_conf_long(d, PCI_PREF_LIMIT_UPPER32),
542 pref_limit + 0xfffff);
547 printf("\tSecondary status: 66MHz%c FastB2B%c ParErr%c DEVSEL=%s >TAbort%c <TAbort%c <MAbort%c <SERR%c <PERR%c\n",
548 FLAG(sec_stat, PCI_STATUS_66MHZ),
549 FLAG(sec_stat, PCI_STATUS_FAST_BACK),
550 FLAG(sec_stat, PCI_STATUS_PARITY),
551 ((sec_stat & PCI_STATUS_DEVSEL_MASK) == PCI_STATUS_DEVSEL_SLOW) ? "slow" :
552 ((sec_stat & PCI_STATUS_DEVSEL_MASK) == PCI_STATUS_DEVSEL_MEDIUM) ? "medium" :
553 ((sec_stat & PCI_STATUS_DEVSEL_MASK) == PCI_STATUS_DEVSEL_FAST) ? "fast" : "??",
554 FLAG(sec_stat, PCI_STATUS_SIG_TARGET_ABORT),
555 FLAG(sec_stat, PCI_STATUS_REC_TARGET_ABORT),
556 FLAG(sec_stat, PCI_STATUS_REC_MASTER_ABORT),
557 FLAG(sec_stat, PCI_STATUS_SIG_SYSTEM_ERROR),
558 FLAG(sec_stat, PCI_STATUS_DETECTED_PARITY));
560 show_rom(d, PCI_ROM_ADDRESS1);
564 printf("\tBridgeCtl: Parity%c SERR%c NoISA%c VGA%c MAbort%c >Reset%c FastB2B%c\n",
565 FLAG(brc, PCI_BRIDGE_CTL_PARITY),
566 FLAG(brc, PCI_BRIDGE_CTL_SERR),
567 FLAG(brc, PCI_BRIDGE_CTL_NO_ISA),
568 FLAG(brc, PCI_BRIDGE_CTL_VGA),
569 FLAG(brc, PCI_BRIDGE_CTL_MASTER_ABORT),
570 FLAG(brc, PCI_BRIDGE_CTL_BUS_RESET),
571 FLAG(brc, PCI_BRIDGE_CTL_FAST_BACK));
572 printf("\t\tPriDiscTmr%c SecDiscTmr%c DiscTmrStat%c DiscTmrSERREn%c\n",
573 FLAG(brc, PCI_BRIDGE_CTL_PRI_DISCARD_TIMER),
574 FLAG(brc, PCI_BRIDGE_CTL_SEC_DISCARD_TIMER),
575 FLAG(brc, PCI_BRIDGE_CTL_DISCARD_TIMER_STATUS),
576 FLAG(brc, PCI_BRIDGE_CTL_DISCARD_TIMER_SERR_EN));
583 show_htype2(struct device *d)
586 word cmd = get_conf_word(d, PCI_COMMAND);
587 word brc = get_conf_word(d, PCI_CB_BRIDGE_CONTROL);
589 int verb = verbose > 2;
592 printf("\tBus: primary=%02x, secondary=%02x, subordinate=%02x, sec-latency=%d\n",
593 get_conf_byte(d, PCI_CB_PRIMARY_BUS),
594 get_conf_byte(d, PCI_CB_CARD_BUS),
595 get_conf_byte(d, PCI_CB_SUBORDINATE_BUS),
596 get_conf_byte(d, PCI_CB_LATENCY_TIMER));
600 u32 base = get_conf_long(d, PCI_CB_MEMORY_BASE_0 + p);
601 u32 limit = get_conf_long(d, PCI_CB_MEMORY_LIMIT_0 + p);
602 if (limit > base || verb)
603 printf("\tMemory window %d: %08x-%08x%s%s\n", i, base, limit,
604 (cmd & PCI_COMMAND_MEMORY) ? "" : " [disabled]",
605 (brc & (PCI_CB_BRIDGE_CTL_PREFETCH_MEM0 << i)) ? " (prefetchable)" : "");
610 u32 base = get_conf_long(d, PCI_CB_IO_BASE_0 + p);
611 u32 limit = get_conf_long(d, PCI_CB_IO_LIMIT_0 + p);
612 if (!(base & PCI_IO_RANGE_TYPE_32))
617 base &= PCI_CB_IO_RANGE_MASK;
618 limit = (limit & PCI_CB_IO_RANGE_MASK) + 3;
619 if (base <= limit || verb)
620 printf("\tI/O window %d: %08x-%08x%s\n", i, base, limit,
621 (cmd & PCI_COMMAND_IO) ? "" : " [disabled]");
624 if (get_conf_word(d, PCI_CB_SEC_STATUS) & PCI_STATUS_SIG_SYSTEM_ERROR)
625 printf("\tSecondary status: SERR\n");
627 printf("\tBridgeCtl: Parity%c SERR%c ISA%c VGA%c MAbort%c >Reset%c 16bInt%c PostWrite%c\n",
628 FLAG(brc, PCI_CB_BRIDGE_CTL_PARITY),
629 FLAG(brc, PCI_CB_BRIDGE_CTL_SERR),
630 FLAG(brc, PCI_CB_BRIDGE_CTL_ISA),
631 FLAG(brc, PCI_CB_BRIDGE_CTL_VGA),
632 FLAG(brc, PCI_CB_BRIDGE_CTL_MASTER_ABORT),
633 FLAG(brc, PCI_CB_BRIDGE_CTL_CB_RESET),
634 FLAG(brc, PCI_CB_BRIDGE_CTL_16BIT_INT),
635 FLAG(brc, PCI_CB_BRIDGE_CTL_POST_WRITES));
637 if (d->config_cached < 128)
639 printf("\t<access denied to the rest>\n");
643 exca = get_conf_word(d, PCI_CB_LEGACY_MODE_BASE);
645 printf("\t16-bit legacy interface ports at %04x\n", exca);
649 show_verbose(struct device *d)
651 struct pci_dev *p = d->dev;
652 word status = get_conf_word(d, PCI_STATUS);
653 word cmd = get_conf_word(d, PCI_COMMAND);
654 word class = p->device_class;
655 byte bist = get_conf_byte(d, PCI_BIST);
656 byte htype = get_conf_byte(d, PCI_HEADER_TYPE) & 0x7f;
657 byte latency = get_conf_byte(d, PCI_LATENCY_TIMER);
658 byte cache_line = get_conf_byte(d, PCI_CACHE_LINE_SIZE);
659 byte max_lat, min_gnt;
660 byte int_pin = get_conf_byte(d, PCI_INTERRUPT_PIN);
661 unsigned int irq = p->irq;
667 case PCI_HEADER_TYPE_NORMAL:
668 if (class == PCI_CLASS_BRIDGE_PCI)
669 printf("\t!!! Invalid class %04x for header type %02x\n", class, htype);
670 max_lat = get_conf_byte(d, PCI_MAX_LAT);
671 min_gnt = get_conf_byte(d, PCI_MIN_GNT);
673 case PCI_HEADER_TYPE_BRIDGE:
674 if ((class >> 8) != PCI_BASE_CLASS_BRIDGE)
675 printf("\t!!! Invalid class %04x for header type %02x\n", class, htype);
676 irq = int_pin = min_gnt = max_lat = 0;
678 case PCI_HEADER_TYPE_CARDBUS:
679 if ((class >> 8) != PCI_BASE_CLASS_BRIDGE)
680 printf("\t!!! Invalid class %04x for header type %02x\n", class, htype);
681 min_gnt = max_lat = 0;
684 printf("\t!!! Unknown header type %02x\n", htype);
689 printf("\tPhysical Slot: %s\n", p->phy_slot);
693 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",
694 FLAG(cmd, PCI_COMMAND_IO),
695 FLAG(cmd, PCI_COMMAND_MEMORY),
696 FLAG(cmd, PCI_COMMAND_MASTER),
697 FLAG(cmd, PCI_COMMAND_SPECIAL),
698 FLAG(cmd, PCI_COMMAND_INVALIDATE),
699 FLAG(cmd, PCI_COMMAND_VGA_PALETTE),
700 FLAG(cmd, PCI_COMMAND_PARITY),
701 FLAG(cmd, PCI_COMMAND_WAIT),
702 FLAG(cmd, PCI_COMMAND_SERR),
703 FLAG(cmd, PCI_COMMAND_FAST_BACK),
704 FLAG(cmd, PCI_COMMAND_DISABLE_INTx));
705 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",
706 FLAG(status, PCI_STATUS_CAP_LIST),
707 FLAG(status, PCI_STATUS_66MHZ),
708 FLAG(status, PCI_STATUS_UDF),
709 FLAG(status, PCI_STATUS_FAST_BACK),
710 FLAG(status, PCI_STATUS_PARITY),
711 ((status & PCI_STATUS_DEVSEL_MASK) == PCI_STATUS_DEVSEL_SLOW) ? "slow" :
712 ((status & PCI_STATUS_DEVSEL_MASK) == PCI_STATUS_DEVSEL_MEDIUM) ? "medium" :
713 ((status & PCI_STATUS_DEVSEL_MASK) == PCI_STATUS_DEVSEL_FAST) ? "fast" : "??",
714 FLAG(status, PCI_STATUS_SIG_TARGET_ABORT),
715 FLAG(status, PCI_STATUS_REC_TARGET_ABORT),
716 FLAG(status, PCI_STATUS_REC_MASTER_ABORT),
717 FLAG(status, PCI_STATUS_SIG_SYSTEM_ERROR),
718 FLAG(status, PCI_STATUS_DETECTED_PARITY),
719 FLAG(status, PCI_STATUS_INTx));
720 if (cmd & PCI_COMMAND_MASTER)
722 printf("\tLatency: %d", latency);
723 if (min_gnt || max_lat)
727 printf("%dns min", min_gnt*250);
728 if (min_gnt && max_lat)
731 printf("%dns max", max_lat*250);
735 printf(", Cache Line Size: %d bytes", cache_line * 4);
739 printf("\tInterrupt: pin %c routed to IRQ " PCIIRQ_FMT "\n",
740 (int_pin ? 'A' + int_pin - 1 : '?'), irq);
745 if (cmd & PCI_COMMAND_MASTER)
746 printf("bus master, ");
747 if (cmd & PCI_COMMAND_VGA_PALETTE)
748 printf("VGA palette snoop, ");
749 if (cmd & PCI_COMMAND_WAIT)
750 printf("stepping, ");
751 if (cmd & PCI_COMMAND_FAST_BACK)
752 printf("fast Back2Back, ");
753 if (status & PCI_STATUS_66MHZ)
755 if (status & PCI_STATUS_UDF)
756 printf("user-definable features, ");
758 ((status & PCI_STATUS_DEVSEL_MASK) == PCI_STATUS_DEVSEL_SLOW) ? "slow" :
759 ((status & PCI_STATUS_DEVSEL_MASK) == PCI_STATUS_DEVSEL_MEDIUM) ? "medium" :
760 ((status & PCI_STATUS_DEVSEL_MASK) == PCI_STATUS_DEVSEL_FAST) ? "fast" : "??");
761 if (cmd & PCI_COMMAND_MASTER)
762 printf(", latency %d", latency);
764 printf(", IRQ " PCIIRQ_FMT, irq);
768 if (bist & PCI_BIST_CAPABLE)
770 if (bist & PCI_BIST_START)
771 printf("\tBIST is running\n");
773 printf("\tBIST result: %02x\n", bist & PCI_BIST_CODE_MASK);
778 case PCI_HEADER_TYPE_NORMAL:
781 case PCI_HEADER_TYPE_BRIDGE:
784 case PCI_HEADER_TYPE_CARDBUS:
790 /*** Machine-readable dumps ***/
793 show_hex_dump(struct device *d)
797 cnt = d->config_cached;
798 if (opt_hex >= 3 && config_fetch(d, cnt, 256-cnt))
801 if (opt_hex >= 4 && config_fetch(d, 256, 4096-256))
805 for (i=0; i<cnt; i++)
809 printf(" %02x", get_conf_byte(d, i));
816 print_shell_escaped(char *c)
821 if (*c == '"' || *c == '\\')
829 show_machine(struct device *d)
831 struct pci_dev *p = d->dev;
834 char classbuf[128], vendbuf[128], devbuf[128], svbuf[128], sdbuf[128];
836 get_subid(d, &sv_id, &sd_id);
840 printf((opt_machine >= 2) ? "Slot:\t" : "Device:\t");
843 printf("Class:\t%s\n",
844 pci_lookup_name(pacc, classbuf, sizeof(classbuf), PCI_LOOKUP_CLASS, p->device_class));
845 printf("Vendor:\t%s\n",
846 pci_lookup_name(pacc, vendbuf, sizeof(vendbuf), PCI_LOOKUP_VENDOR, p->vendor_id, p->device_id));
847 printf("Device:\t%s\n",
848 pci_lookup_name(pacc, devbuf, sizeof(devbuf), PCI_LOOKUP_DEVICE, p->vendor_id, p->device_id));
849 if (sv_id && sv_id != 0xffff)
851 printf("SVendor:\t%s\n",
852 pci_lookup_name(pacc, svbuf, sizeof(svbuf), PCI_LOOKUP_SUBSYSTEM | PCI_LOOKUP_VENDOR, sv_id));
853 printf("SDevice:\t%s\n",
854 pci_lookup_name(pacc, sdbuf, sizeof(sdbuf), PCI_LOOKUP_SUBSYSTEM | PCI_LOOKUP_DEVICE, p->vendor_id, p->device_id, sv_id, sd_id));
857 printf("PhySlot:\t%s\n", p->phy_slot);
858 if (c = get_conf_byte(d, PCI_REVISION_ID))
859 printf("Rev:\t%02x\n", c);
860 if (c = get_conf_byte(d, PCI_CLASS_PROG))
861 printf("ProgIf:\t%02x\n", c);
863 show_kernel_machine(d);
868 print_shell_escaped(pci_lookup_name(pacc, classbuf, sizeof(classbuf), PCI_LOOKUP_CLASS, p->device_class));
869 print_shell_escaped(pci_lookup_name(pacc, vendbuf, sizeof(vendbuf), PCI_LOOKUP_VENDOR, p->vendor_id, p->device_id));
870 print_shell_escaped(pci_lookup_name(pacc, devbuf, sizeof(devbuf), PCI_LOOKUP_DEVICE, p->vendor_id, p->device_id));
871 if (c = get_conf_byte(d, PCI_REVISION_ID))
872 printf(" -r%02x", c);
873 if (c = get_conf_byte(d, PCI_CLASS_PROG))
874 printf(" -p%02x", c);
875 if (sv_id && sv_id != 0xffff)
877 print_shell_escaped(pci_lookup_name(pacc, svbuf, sizeof(svbuf), PCI_LOOKUP_SUBSYSTEM | PCI_LOOKUP_VENDOR, sv_id));
878 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));
881 printf(" \"\" \"\"");
886 /*** Main show function ***/
889 show_device(struct device *d)
899 if (opt_kernel || verbose)
904 if (verbose || opt_hex)
913 for (d=first_dev; d; d=d->next)
920 main(int argc, char **argv)
925 if (argc == 2 && !strcmp(argv[1], "--version"))
927 puts("lspci version " PCIUTILS_VERSION);
933 pci_filter_init(pacc, &filter);
935 while ((i = getopt(argc, argv, options)) != -1)
945 pacc->buscentric = 1;
949 if (msg = pci_filter_parse_slot(&filter, optarg))
953 if (msg = pci_filter_parse_id(&filter, optarg))
963 pci_set_name_list_path(pacc, optarg, 0);
992 die("DNS queries are not available in this version");
995 if (parse_generic_option(i, pacc, optarg))
998 fprintf(stderr, help_msg, pacc->id_file_name);
1006 pacc->id_lookup_mode |= PCI_LOOKUP_NETWORK;
1007 if (opt_query_dns > 1)
1008 pacc->id_lookup_mode |= PCI_LOOKUP_REFRESH_CACHE;
1011 pacc->id_lookup_mode |= PCI_LOOKUP_NETWORK | PCI_LOOKUP_SKIP_LOCAL;
1027 return (seen_errors ? 2 : 0);