2 * The PCI Utilities -- List All PCI Devices
4 * Copyright (c) 1997--2006 Martin Mares <mj@ucw.cz>
6 * Can be freely distributed and used under the terms of the GNU GPL.
19 static int verbose; /* Show detailed information */
20 static int buscentric_view; /* Show bus addresses/IRQ's instead of CPU-visible ones */
21 static int show_hex; /* Show contents of config space as hexadecimal numbers */
22 static struct pci_filter filter; /* Device filter */
23 static int show_tree; /* Show bus tree */
24 static int machine_readable; /* Generate machine-readable output */
25 static int map_mode; /* Bus mapping mode enabled */
26 static int show_domains; /* Show domain numbers (0=disabled, 1=auto-detected, 2=requested) */
28 const char program_name[] = "lspci";
30 static char options[] = "nvbxs:d:ti:mgMD" GENERIC_OPTIONS ;
32 static char help_msg[] = "\
33 Usage: lspci [<switches>]\n\
36 -n\t\tShow numeric ID's\n\
37 -nn\t\tShow both textual and numeric ID's (names & numbers)\n\
38 -b\t\tBus-centric view (PCI addresses and IRQ's instead of those seen by the CPU)\n\
39 -x\t\tShow hex-dump of the standard portion of config space\n\
40 -xxx\t\tShow hex-dump of the whole config space (dangerous; root only)\n\
41 -xxxx\t\tShow hex-dump of the 4096-byte extended config space (root only)\n\
42 -s [[[[<domain>]:]<bus>]:][<slot>][.[<func>]]\tShow only devices in selected slots\n\
43 -d [<vendor>]:[<device>]\tShow only selected devices\n\
44 -t\t\tShow bus tree\n\
45 -m\t\tProduce machine-readable output\n\
46 -i <file>\tUse specified ID database instead of %s\n\
47 -D\t\tAlways show domain numbers\n\
48 -M\t\tEnable `bus mapping' mode (dangerous; root only)\n"
52 /* Communication with libpci */
54 static struct pci_access *pacc;
57 * If we aren't being compiled by GCC, use xmalloc() instead of alloca().
58 * This increases our memory footprint, but only slightly since we don't
64 #define alloca xmalloc
67 /* Our view of the PCI bus */
72 unsigned int config_cached, config_bufsize;
73 byte *config; /* Cached configuration space data */
74 byte *present; /* Maps which configuration bytes are present */
77 static struct device *first_dev;
80 config_fetch(struct device *d, unsigned int pos, unsigned int len)
82 unsigned int end = pos+len;
85 while (pos < d->config_bufsize && len && d->present[pos])
87 while (pos+len <= d->config_bufsize && len && d->present[pos+len-1])
92 if (end > d->config_bufsize)
94 int orig_size = d->config_bufsize;
95 while (end > d->config_bufsize)
96 d->config_bufsize *= 2;
97 d->config = xrealloc(d->config, d->config_bufsize);
98 d->present = xrealloc(d->present, d->config_bufsize);
99 bzero(d->present + orig_size, d->config_bufsize - orig_size);
101 result = pci_read_block(d->dev, pos, d->config + pos, len);
103 memset(d->present + pos, 1, len);
107 static struct device *
108 scan_device(struct pci_dev *p)
112 if (p->domain && !show_domains)
114 if (!pci_filter_match(&filter, p))
116 d = xmalloc(sizeof(struct device));
117 bzero(d, sizeof(*d));
119 d->config_cached = d->config_bufsize = 64;
120 d->config = xmalloc(64);
121 d->present = xmalloc(64);
122 memset(d->present, 1, 64);
123 if (!pci_read_block(p, 0, d->config, 64))
124 die("Unable to read the standard configuration space header");
125 if ((d->config[PCI_HEADER_TYPE] & 0x7f) == PCI_HEADER_TYPE_CARDBUS)
127 /* For cardbus bridges, we need to fetch 64 bytes more to get the
128 * full standard header... */
129 if (config_fetch(d, 64, 64))
130 d->config_cached += 64;
132 pci_setup_cache(p, d->config, d->config_cached);
133 pci_fill_info(p, PCI_FILL_IDENT | PCI_FILL_CLASS | PCI_FILL_IRQ | PCI_FILL_BASES | PCI_FILL_ROM_BASE | PCI_FILL_SIZES);
144 for(p=pacc->devices; p; p=p->next)
145 if (d = scan_device(p))
152 /* Config space accesses */
155 check_conf_range(struct device *d, unsigned int pos, unsigned int len)
158 if (!d->present[pos])
159 die("Internal bug: Accessing non-read configuration byte at position %x", pos);
165 get_conf_byte(struct device *d, unsigned int pos)
167 check_conf_range(d, pos, 1);
168 return d->config[pos];
172 get_conf_word(struct device *d, unsigned int pos)
174 check_conf_range(d, pos, 2);
175 return d->config[pos] | (d->config[pos+1] << 8);
179 get_conf_long(struct device *d, unsigned int pos)
181 check_conf_range(d, pos, 4);
182 return d->config[pos] |
183 (d->config[pos+1] << 8) |
184 (d->config[pos+2] << 16) |
185 (d->config[pos+3] << 24);
191 compare_them(const void *A, const void *B)
193 const struct pci_dev *a = (*(const struct device **)A)->dev;
194 const struct pci_dev *b = (*(const struct device **)B)->dev;
196 if (a->domain < b->domain)
198 if (a->domain > b->domain)
208 if (a->func < b->func)
210 if (a->func > b->func)
218 struct device **index, **h, **last_dev;
223 for(d=first_dev; d; d=d->next)
225 h = index = alloca(sizeof(struct device *) * cnt);
226 for(d=first_dev; d; d=d->next)
228 qsort(index, cnt, sizeof(struct device *), compare_them);
229 last_dev = &first_dev;
234 last_dev = &(*h)->next;
242 #define FLAG(x,y) ((x & y) ? '+' : '-')
245 show_slot_name(struct device *d)
247 struct pci_dev *p = d->dev;
249 if (!machine_readable ? show_domains : (p->domain || show_domains >= 2))
250 printf("%04x:", p->domain);
251 printf("%02x:%02x.%d", p->bus, p->dev, p->func);
255 show_terse(struct device *d)
258 struct pci_dev *p = d->dev;
259 char classbuf[128], devbuf[128];
263 pci_lookup_name(pacc, classbuf, sizeof(classbuf),
266 pci_lookup_name(pacc, devbuf, sizeof(devbuf),
267 PCI_LOOKUP_VENDOR | PCI_LOOKUP_DEVICE,
268 p->vendor_id, p->device_id));
269 if (c = get_conf_byte(d, PCI_REVISION_ID))
270 printf(" (rev %02x)", c);
274 c = get_conf_byte(d, PCI_CLASS_PROG);
275 x = pci_lookup_name(pacc, devbuf, sizeof(devbuf),
276 PCI_LOOKUP_PROGIF | PCI_LOOKUP_NO_NUMBERS,
280 printf(" (prog-if %02x", c);
290 show_size(pciaddr_t x)
296 printf("%d", (int) x);
297 else if (x < 1048576)
298 printf("%dK", (int)(x / 1024));
299 else if (x < 0x80000000)
300 printf("%dM", (int)(x / 1048576));
302 printf(PCIADDR_T_FMT, x);
307 show_bases(struct device *d, int cnt)
309 struct pci_dev *p = d->dev;
310 word cmd = get_conf_word(d, PCI_COMMAND);
315 pciaddr_t pos = p->base_addr[i];
316 pciaddr_t len = (p->known_fields & PCI_FILL_SIZES) ? p->size[i] : 0;
317 u32 flg = get_conf_long(d, PCI_BASE_ADDRESS_0 + 4*i);
318 if (flg == 0xffffffff)
320 if (!pos && !flg && !len)
323 printf("\tRegion %d: ", i);
326 if (pos && !flg) /* Reported by the OS, but not by the device */
328 printf("[virtual] ");
331 if (flg & PCI_BASE_ADDRESS_SPACE_IO)
333 pciaddr_t a = pos & PCI_BASE_ADDRESS_IO_MASK;
334 printf("I/O ports at ");
336 printf(PCIADDR_PORT_FMT, a);
337 else if (flg & PCI_BASE_ADDRESS_IO_MASK)
340 printf("<unassigned>");
341 if (!(cmd & PCI_COMMAND_IO))
342 printf(" [disabled]");
346 int t = flg & PCI_BASE_ADDRESS_MEM_TYPE_MASK;
347 pciaddr_t a = pos & PCI_ADDR_MEM_MASK;
351 printf("Memory at ");
352 if (t == PCI_BASE_ADDRESS_MEM_TYPE_64)
356 printf("<invalid-64bit-slot>");
362 z = get_conf_long(d, PCI_BASE_ADDRESS_0 + 4*i);
365 u32 y = a & 0xffffffff;
367 printf("%08x%08x", z, y);
369 printf("<unassigned>");
377 printf(PCIADDR_T_FMT, a);
379 printf(((flg & PCI_BASE_ADDRESS_MEM_MASK) || z) ? "<ignored>" : "<unassigned>");
381 printf(" (%s, %sprefetchable)",
382 (t == PCI_BASE_ADDRESS_MEM_TYPE_32) ? "32-bit" :
383 (t == PCI_BASE_ADDRESS_MEM_TYPE_64) ? "64-bit" :
384 (t == PCI_BASE_ADDRESS_MEM_TYPE_1M) ? "low-1M" : "type 3",
385 (flg & PCI_BASE_ADDRESS_MEM_PREFETCH) ? "" : "non-");
386 if (!(cmd & PCI_COMMAND_MEMORY))
387 printf(" [disabled]");
395 show_pm(struct device *d, int where, int cap)
398 static int pm_aux_current[8] = { 0, 55, 100, 160, 220, 270, 320, 375 };
400 printf("Power Management version %d\n", cap & PCI_PM_CAP_VER_MASK);
403 printf("\t\tFlags: PMEClk%c DSI%c D1%c D2%c AuxCurrent=%dmA PME(D0%c,D1%c,D2%c,D3hot%c,D3cold%c)\n",
404 FLAG(cap, PCI_PM_CAP_PME_CLOCK),
405 FLAG(cap, PCI_PM_CAP_DSI),
406 FLAG(cap, PCI_PM_CAP_D1),
407 FLAG(cap, PCI_PM_CAP_D2),
408 pm_aux_current[(cap >> 6) & 7],
409 FLAG(cap, PCI_PM_CAP_PME_D0),
410 FLAG(cap, PCI_PM_CAP_PME_D1),
411 FLAG(cap, PCI_PM_CAP_PME_D2),
412 FLAG(cap, PCI_PM_CAP_PME_D3_HOT),
413 FLAG(cap, PCI_PM_CAP_PME_D3_COLD));
414 if (!config_fetch(d, where + PCI_PM_CTRL, PCI_PM_SIZEOF - PCI_PM_CTRL))
416 t = get_conf_word(d, where + PCI_PM_CTRL);
417 printf("\t\tStatus: D%d PME-Enable%c DSel=%d DScale=%d PME%c\n",
418 t & PCI_PM_CTRL_STATE_MASK,
419 FLAG(t, PCI_PM_CTRL_PME_ENABLE),
420 (t & PCI_PM_CTRL_DATA_SEL_MASK) >> 9,
421 (t & PCI_PM_CTRL_DATA_SCALE_MASK) >> 13,
422 FLAG(t, PCI_PM_CTRL_PME_STATUS));
423 b = get_conf_byte(d, where + PCI_PM_PPB_EXTENSIONS);
425 printf("\t\tBridge: PM%c B3%c\n",
426 FLAG(t, PCI_PM_BPCC_ENABLE),
427 FLAG(~t, PCI_PM_PPB_B2_B3));
431 format_agp_rate(int rate, char *buf, int agp3)
441 c += sprintf(c, "x%d", 1 << (i + 2*agp3));
446 strcpy(buf, "<none>");
450 show_agp(struct device *d, int where, int cap)
457 ver = (cap >> 4) & 0x0f;
459 printf("AGP version %x.%x\n", ver, rev);
462 if (!config_fetch(d, where + PCI_AGP_STATUS, PCI_AGP_SIZEOF - PCI_AGP_STATUS))
464 t = get_conf_long(d, where + PCI_AGP_STATUS);
465 if (ver >= 3 && (t & PCI_AGP_STATUS_AGP3))
467 format_agp_rate(t & 7, rate, agp3);
468 printf("\t\tStatus: RQ=%d Iso%c ArqSz=%d Cal=%d SBA%c ITACoh%c GART64%c HTrans%c 64bit%c FW%c AGP3%c Rate=%s\n",
469 ((t & PCI_AGP_STATUS_RQ_MASK) >> 24U) + 1,
470 FLAG(t, PCI_AGP_STATUS_ISOCH),
471 ((t & PCI_AGP_STATUS_ARQSZ_MASK) >> 13),
472 ((t & PCI_AGP_STATUS_CAL_MASK) >> 10),
473 FLAG(t, PCI_AGP_STATUS_SBA),
474 FLAG(t, PCI_AGP_STATUS_ITA_COH),
475 FLAG(t, PCI_AGP_STATUS_GART64),
476 FLAG(t, PCI_AGP_STATUS_HTRANS),
477 FLAG(t, PCI_AGP_STATUS_64BIT),
478 FLAG(t, PCI_AGP_STATUS_FW),
479 FLAG(t, PCI_AGP_STATUS_AGP3),
481 t = get_conf_long(d, where + PCI_AGP_COMMAND);
482 format_agp_rate(t & 7, rate, agp3);
483 printf("\t\tCommand: RQ=%d ArqSz=%d Cal=%d SBA%c AGP%c GART64%c 64bit%c FW%c Rate=%s\n",
484 ((t & PCI_AGP_COMMAND_RQ_MASK) >> 24U) + 1,
485 ((t & PCI_AGP_COMMAND_ARQSZ_MASK) >> 13),
486 ((t & PCI_AGP_COMMAND_CAL_MASK) >> 10),
487 FLAG(t, PCI_AGP_COMMAND_SBA),
488 FLAG(t, PCI_AGP_COMMAND_AGP),
489 FLAG(t, PCI_AGP_COMMAND_GART64),
490 FLAG(t, PCI_AGP_COMMAND_64BIT),
491 FLAG(t, PCI_AGP_COMMAND_FW),
496 show_pcix_nobridge(struct device *d, int where)
500 static const byte max_outstanding[8] = { 1, 2, 3, 4, 8, 12, 16, 32 };
502 printf("PCI-X non-bridge device\n");
507 if (!config_fetch(d, where + PCI_PCIX_STATUS, 4))
510 command = get_conf_word(d, where + PCI_PCIX_COMMAND);
511 status = get_conf_long(d, where + PCI_PCIX_STATUS);
512 printf("\t\tCommand: DPERE%c ERO%c RBC=%d OST=%d\n",
513 FLAG(command, PCI_PCIX_COMMAND_DPERE),
514 FLAG(command, PCI_PCIX_COMMAND_ERO),
515 1 << (9 + ((command & PCI_PCIX_COMMAND_MAX_MEM_READ_BYTE_COUNT) >> 2U)),
516 max_outstanding[(command & PCI_PCIX_COMMAND_MAX_OUTSTANDING_SPLIT_TRANS) >> 4U]);
517 printf("\t\tStatus: Dev=%02x:%02x.%d 64bit%c 133MHz%c SCD%c USC%c DC=%s DMMRBC=%u DMOST=%u DMCRS=%u RSCEM%c 266MHz%c 533MHz%c\n",
518 ((status >> 8) & 0xff),
519 ((status >> 3) & 0x1f),
520 (status & PCI_PCIX_STATUS_FUNCTION),
521 FLAG(status, PCI_PCIX_STATUS_64BIT),
522 FLAG(status, PCI_PCIX_STATUS_133MHZ),
523 FLAG(status, PCI_PCIX_STATUS_SC_DISCARDED),
524 FLAG(status, PCI_PCIX_STATUS_UNEXPECTED_SC),
525 ((status & PCI_PCIX_STATUS_DEVICE_COMPLEXITY) ? "bridge" : "simple"),
526 1 << (9 + ((status >> 21) & 3U)),
527 max_outstanding[(status >> 23) & 7U],
528 1 << (3 + ((status >> 26) & 7U)),
529 FLAG(status, PCI_PCIX_STATUS_RCVD_SC_ERR_MESS),
530 FLAG(status, PCI_PCIX_STATUS_266MHZ),
531 FLAG(status, PCI_PCIX_STATUS_533MHZ));
535 show_pcix_bridge(struct device *d, int where)
537 static const char * const sec_clock_freq[8] = { "conv", "66MHz", "100MHz", "133MHz", "?4", "?5", "?6", "?7" };
539 u32 status, upstcr, downstcr;
541 printf("PCI-X bridge device\n");
546 if (!config_fetch(d, where + PCI_PCIX_BRIDGE_STATUS, 12))
549 secstatus = get_conf_word(d, where + PCI_PCIX_BRIDGE_SEC_STATUS);
550 printf("\t\tSecondary Status: 64bit%c 133MHz%c SCD%c USC%c SCO%c SRD%c Freq=%s\n",
551 FLAG(secstatus, PCI_PCIX_BRIDGE_SEC_STATUS_64BIT),
552 FLAG(secstatus, PCI_PCIX_BRIDGE_SEC_STATUS_133MHZ),
553 FLAG(secstatus, PCI_PCIX_BRIDGE_SEC_STATUS_SC_DISCARDED),
554 FLAG(secstatus, PCI_PCIX_BRIDGE_SEC_STATUS_UNEXPECTED_SC),
555 FLAG(secstatus, PCI_PCIX_BRIDGE_SEC_STATUS_SC_OVERRUN),
556 FLAG(secstatus, PCI_PCIX_BRIDGE_SEC_STATUS_SPLIT_REQUEST_DELAYED),
557 sec_clock_freq[(secstatus >> 6) & 7]);
558 status = get_conf_long(d, where + PCI_PCIX_BRIDGE_STATUS);
559 printf("\t\tStatus: Dev=%02x:%02x.%d 64bit%c 133MHz%c SCD%c USC%c SCO%c SRD%c\n",
560 ((status >> 8) & 0xff),
561 ((status >> 3) & 0x1f),
562 (status & PCI_PCIX_BRIDGE_STATUS_FUNCTION),
563 FLAG(status, PCI_PCIX_BRIDGE_STATUS_64BIT),
564 FLAG(status, PCI_PCIX_BRIDGE_STATUS_133MHZ),
565 FLAG(status, PCI_PCIX_BRIDGE_STATUS_SC_DISCARDED),
566 FLAG(status, PCI_PCIX_BRIDGE_STATUS_UNEXPECTED_SC),
567 FLAG(status, PCI_PCIX_BRIDGE_STATUS_SC_OVERRUN),
568 FLAG(status, PCI_PCIX_BRIDGE_STATUS_SPLIT_REQUEST_DELAYED));
569 upstcr = get_conf_long(d, where + PCI_PCIX_BRIDGE_UPSTREAM_SPLIT_TRANS_CTRL);
570 printf("\t\tUpstream: Capacity=%u CommitmentLimit=%u\n",
571 (upstcr & PCI_PCIX_BRIDGE_STR_CAPACITY),
572 (upstcr >> 16) & 0xffff);
573 downstcr = get_conf_long(d, where + PCI_PCIX_BRIDGE_DOWNSTREAM_SPLIT_TRANS_CTRL);
574 printf("\t\tDownstream: Capacity=%u CommitmentLimit=%u\n",
575 (downstcr & PCI_PCIX_BRIDGE_STR_CAPACITY),
576 (downstcr >> 16) & 0xffff);
580 show_pcix(struct device *d, int where)
582 switch (get_conf_byte(d, PCI_HEADER_TYPE) & 0x7f)
584 case PCI_HEADER_TYPE_NORMAL:
585 show_pcix_nobridge(d, where);
587 case PCI_HEADER_TYPE_BRIDGE:
588 show_pcix_bridge(d, where);
594 ht_link_width(unsigned width)
596 static char * const widths[8] = { "8bit", "16bit", "[2]", "32bit", "2bit", "4bit", "[6]", "N/C" };
597 return widths[width];
601 ht_link_freq(unsigned freq)
603 static char * const freqs[16] = { "200MHz", "300MHz", "400MHz", "500MHz", "600MHz", "800MHz", "1.0GHz", "1.2GHz",
604 "1.4GHz", "1.6GHz", "[a]", "[b]", "[c]", "[d]", "[e]", "Vend" };
609 show_ht_pri(struct device *d, int where, int cmd)
611 u16 lctr0, lcnf0, lctr1, lcnf1, eh;
612 u8 rid, lfrer0, lfcap0, ftr, lfrer1, lfcap1, mbu, mlu, bn;
615 printf("HyperTransport: Slave or Primary Interface\n");
619 if (!config_fetch(d, where + PCI_HT_PRI_LCTR0, PCI_HT_PRI_SIZEOF - PCI_HT_PRI_LCTR0))
621 rid = get_conf_byte(d, where + PCI_HT_PRI_RID);
622 if (rid < 0x23 && rid > 0x11)
623 printf("\t\t!!! Possibly incomplete decoding\n");
626 fmt = "\t\tCommand: BaseUnitID=%u UnitCnt=%u MastHost%c DefDir%c DUL%c\n";
628 fmt = "\t\tCommand: BaseUnitID=%u UnitCnt=%u MastHost%c DefDir%c\n";
630 (cmd & PCI_HT_PRI_CMD_BUID),
631 (cmd & PCI_HT_PRI_CMD_UC) >> 5,
632 FLAG(cmd, PCI_HT_PRI_CMD_MH),
633 FLAG(cmd, PCI_HT_PRI_CMD_DD),
634 FLAG(cmd, PCI_HT_PRI_CMD_DUL));
635 lctr0 = get_conf_word(d, where + PCI_HT_PRI_LCTR0);
637 fmt = "\t\tLink Control 0: CFlE%c CST%c CFE%c <LkFail%c Init%c EOC%c TXO%c <CRCErr=%x IsocEn%c LSEn%c ExtCTL%c 64b%c\n";
639 fmt = "\t\tLink Control 0: CFlE%c CST%c CFE%c <LkFail%c Init%c EOC%c TXO%c <CRCErr=%x\n";
641 FLAG(lctr0, PCI_HT_LCTR_CFLE),
642 FLAG(lctr0, PCI_HT_LCTR_CST),
643 FLAG(lctr0, PCI_HT_LCTR_CFE),
644 FLAG(lctr0, PCI_HT_LCTR_LKFAIL),
645 FLAG(lctr0, PCI_HT_LCTR_INIT),
646 FLAG(lctr0, PCI_HT_LCTR_EOC),
647 FLAG(lctr0, PCI_HT_LCTR_TXO),
648 (lctr0 & PCI_HT_LCTR_CRCERR) >> 8,
649 FLAG(lctr0, PCI_HT_LCTR_ISOCEN),
650 FLAG(lctr0, PCI_HT_LCTR_LSEN),
651 FLAG(lctr0, PCI_HT_LCTR_EXTCTL),
652 FLAG(lctr0, PCI_HT_LCTR_64B));
653 lcnf0 = get_conf_word(d, where + PCI_HT_PRI_LCNF0);
655 fmt = "\t\tLink Config 0: MLWI=%1$s DwFcIn%5$c MLWO=%2$s DwFcOut%6$c LWI=%3$s DwFcInEn%7$c LWO=%4$s DwFcOutEn%8$c\n";
657 fmt = "\t\tLink Config 0: MLWI=%s MLWO=%s LWI=%s LWO=%s\n";
659 ht_link_width(lcnf0 & PCI_HT_LCNF_MLWI),
660 ht_link_width((lcnf0 & PCI_HT_LCNF_MLWO) >> 4),
661 ht_link_width((lcnf0 & PCI_HT_LCNF_LWI) >> 8),
662 ht_link_width((lcnf0 & PCI_HT_LCNF_LWO) >> 12),
663 FLAG(lcnf0, PCI_HT_LCNF_DFI),
664 FLAG(lcnf0, PCI_HT_LCNF_DFO),
665 FLAG(lcnf0, PCI_HT_LCNF_DFIE),
666 FLAG(lcnf0, PCI_HT_LCNF_DFOE));
667 lctr1 = get_conf_word(d, where + PCI_HT_PRI_LCTR1);
669 fmt = "\t\tLink Control 1: CFlE%c CST%c CFE%c <LkFail%c Init%c EOC%c TXO%c <CRCErr=%x IsocEn%c LSEn%c ExtCTL%c 64b%c\n";
671 fmt = "\t\tLink Control 1: CFlE%c CST%c CFE%c <LkFail%c Init%c EOC%c TXO%c <CRCErr=%x\n";
673 FLAG(lctr1, PCI_HT_LCTR_CFLE),
674 FLAG(lctr1, PCI_HT_LCTR_CST),
675 FLAG(lctr1, PCI_HT_LCTR_CFE),
676 FLAG(lctr1, PCI_HT_LCTR_LKFAIL),
677 FLAG(lctr1, PCI_HT_LCTR_INIT),
678 FLAG(lctr1, PCI_HT_LCTR_EOC),
679 FLAG(lctr1, PCI_HT_LCTR_TXO),
680 (lctr1 & PCI_HT_LCTR_CRCERR) >> 8,
681 FLAG(lctr1, PCI_HT_LCTR_ISOCEN),
682 FLAG(lctr1, PCI_HT_LCTR_LSEN),
683 FLAG(lctr1, PCI_HT_LCTR_EXTCTL),
684 FLAG(lctr1, PCI_HT_LCTR_64B));
685 lcnf1 = get_conf_word(d, where + PCI_HT_PRI_LCNF1);
687 fmt = "\t\tLink Config 1: MLWI=%1$s DwFcIn%5$c MLWO=%2$s DwFcOut%6$c LWI=%3$s DwFcInEn%7$c LWO=%4$s DwFcOutEn%8$c\n";
689 fmt = "\t\tLink Config 1: MLWI=%s MLWO=%s LWI=%s LWO=%s\n";
691 ht_link_width(lcnf1 & PCI_HT_LCNF_MLWI),
692 ht_link_width((lcnf1 & PCI_HT_LCNF_MLWO) >> 4),
693 ht_link_width((lcnf1 & PCI_HT_LCNF_LWI) >> 8),
694 ht_link_width((lcnf1 & PCI_HT_LCNF_LWO) >> 12),
695 FLAG(lcnf1, PCI_HT_LCNF_DFI),
696 FLAG(lcnf1, PCI_HT_LCNF_DFO),
697 FLAG(lcnf1, PCI_HT_LCNF_DFIE),
698 FLAG(lcnf1, PCI_HT_LCNF_DFOE));
699 printf("\t\tRevision ID: %u.%02u\n",
700 (rid & PCI_HT_RID_MAJ) >> 5, (rid & PCI_HT_RID_MIN));
703 lfrer0 = get_conf_byte(d, where + PCI_HT_PRI_LFRER0);
704 printf("\t\tLink Frequency 0: %s\n", ht_link_freq(lfrer0 & PCI_HT_LFRER_FREQ));
705 printf("\t\tLink Error 0: <Prot%c <Ovfl%c <EOC%c CTLTm%c\n",
706 FLAG(lfrer0, PCI_HT_LFRER_PROT),
707 FLAG(lfrer0, PCI_HT_LFRER_OV),
708 FLAG(lfrer0, PCI_HT_LFRER_EOC),
709 FLAG(lfrer0, PCI_HT_LFRER_CTLT));
710 lfcap0 = get_conf_byte(d, where + PCI_HT_PRI_LFCAP0);
711 printf("\t\tLink Frequency Capability 0: 200MHz%c 300MHz%c 400MHz%c 500MHz%c 600MHz%c 800MHz%c 1.0GHz%c 1.2GHz%c 1.4GHz%c 1.6GHz%c Vend%c\n",
712 FLAG(lfcap0, PCI_HT_LFCAP_200),
713 FLAG(lfcap0, PCI_HT_LFCAP_300),
714 FLAG(lfcap0, PCI_HT_LFCAP_400),
715 FLAG(lfcap0, PCI_HT_LFCAP_500),
716 FLAG(lfcap0, PCI_HT_LFCAP_600),
717 FLAG(lfcap0, PCI_HT_LFCAP_800),
718 FLAG(lfcap0, PCI_HT_LFCAP_1000),
719 FLAG(lfcap0, PCI_HT_LFCAP_1200),
720 FLAG(lfcap0, PCI_HT_LFCAP_1400),
721 FLAG(lfcap0, PCI_HT_LFCAP_1600),
722 FLAG(lfcap0, PCI_HT_LFCAP_VEND));
723 ftr = get_conf_byte(d, where + PCI_HT_PRI_FTR);
724 printf("\t\tFeature Capability: IsocFC%c LDTSTOP%c CRCTM%c ECTLT%c 64bA%c UIDRD%c\n",
725 FLAG(ftr, PCI_HT_FTR_ISOCFC),
726 FLAG(ftr, PCI_HT_FTR_LDTSTOP),
727 FLAG(ftr, PCI_HT_FTR_CRCTM),
728 FLAG(ftr, PCI_HT_FTR_ECTLT),
729 FLAG(ftr, PCI_HT_FTR_64BA),
730 FLAG(ftr, PCI_HT_FTR_UIDRD));
731 lfrer1 = get_conf_byte(d, where + PCI_HT_PRI_LFRER1);
732 printf("\t\tLink Frequency 1: %s\n", ht_link_freq(lfrer1 & PCI_HT_LFRER_FREQ));
733 printf("\t\tLink Error 1: <Prot%c <Ovfl%c <EOC%c CTLTm%c\n",
734 FLAG(lfrer1, PCI_HT_LFRER_PROT),
735 FLAG(lfrer1, PCI_HT_LFRER_OV),
736 FLAG(lfrer1, PCI_HT_LFRER_EOC),
737 FLAG(lfrer1, PCI_HT_LFRER_CTLT));
738 lfcap1 = get_conf_byte(d, where + PCI_HT_PRI_LFCAP1);
739 printf("\t\tLink Frequency Capability 1: 200MHz%c 300MHz%c 400MHz%c 500MHz%c 600MHz%c 800MHz%c 1.0GHz%c 1.2GHz%c 1.4GHz%c 1.6GHz%c Vend%c\n",
740 FLAG(lfcap1, PCI_HT_LFCAP_200),
741 FLAG(lfcap1, PCI_HT_LFCAP_300),
742 FLAG(lfcap1, PCI_HT_LFCAP_400),
743 FLAG(lfcap1, PCI_HT_LFCAP_500),
744 FLAG(lfcap1, PCI_HT_LFCAP_600),
745 FLAG(lfcap1, PCI_HT_LFCAP_800),
746 FLAG(lfcap1, PCI_HT_LFCAP_1000),
747 FLAG(lfcap1, PCI_HT_LFCAP_1200),
748 FLAG(lfcap1, PCI_HT_LFCAP_1400),
749 FLAG(lfcap1, PCI_HT_LFCAP_1600),
750 FLAG(lfcap1, PCI_HT_LFCAP_VEND));
751 eh = get_conf_word(d, where + PCI_HT_PRI_EH);
752 printf("\t\tError Handling: PFlE%c OFlE%c PFE%c OFE%c EOCFE%c RFE%c CRCFE%c SERRFE%c CF%c RE%c PNFE%c ONFE%c EOCNFE%c RNFE%c CRCNFE%c SERRNFE%c\n",
753 FLAG(eh, PCI_HT_EH_PFLE),
754 FLAG(eh, PCI_HT_EH_OFLE),
755 FLAG(eh, PCI_HT_EH_PFE),
756 FLAG(eh, PCI_HT_EH_OFE),
757 FLAG(eh, PCI_HT_EH_EOCFE),
758 FLAG(eh, PCI_HT_EH_RFE),
759 FLAG(eh, PCI_HT_EH_CRCFE),
760 FLAG(eh, PCI_HT_EH_SERRFE),
761 FLAG(eh, PCI_HT_EH_CF),
762 FLAG(eh, PCI_HT_EH_RE),
763 FLAG(eh, PCI_HT_EH_PNFE),
764 FLAG(eh, PCI_HT_EH_ONFE),
765 FLAG(eh, PCI_HT_EH_EOCNFE),
766 FLAG(eh, PCI_HT_EH_RNFE),
767 FLAG(eh, PCI_HT_EH_CRCNFE),
768 FLAG(eh, PCI_HT_EH_SERRNFE));
769 mbu = get_conf_byte(d, where + PCI_HT_PRI_MBU);
770 mlu = get_conf_byte(d, where + PCI_HT_PRI_MLU);
771 printf("\t\tPrefetchable memory behind bridge Upper: %02x-%02x\n", mbu, mlu);
772 bn = get_conf_byte(d, where + PCI_HT_PRI_BN);
773 printf("\t\tBus Number: %02x\n", bn);
777 show_ht_sec(struct device *d, int where, int cmd)
779 u16 lctr, lcnf, ftr, eh;
780 u8 rid, lfrer, lfcap, mbu, mlu;
783 printf("HyperTransport: Host or Secondary Interface\n");
787 if (!config_fetch(d, where + PCI_HT_SEC_LCTR, PCI_HT_SEC_SIZEOF - PCI_HT_SEC_LCTR))
789 rid = get_conf_byte(d, where + PCI_HT_SEC_RID);
790 if (rid < 0x23 && rid > 0x11)
791 printf("\t\t!!! Possibly incomplete decoding\n");
794 fmt = "\t\tCommand: WarmRst%c DblEnd%c DevNum=%u ChainSide%c HostHide%c Slave%c <EOCErr%c DUL%c\n";
796 fmt = "\t\tCommand: WarmRst%c DblEnd%c\n";
798 FLAG(cmd, PCI_HT_SEC_CMD_WR),
799 FLAG(cmd, PCI_HT_SEC_CMD_DE),
800 (cmd & PCI_HT_SEC_CMD_DN) >> 2,
801 FLAG(cmd, PCI_HT_SEC_CMD_CS),
802 FLAG(cmd, PCI_HT_SEC_CMD_HH),
803 FLAG(cmd, PCI_HT_SEC_CMD_AS),
804 FLAG(cmd, PCI_HT_SEC_CMD_HIECE),
805 FLAG(cmd, PCI_HT_SEC_CMD_DUL));
806 lctr = get_conf_word(d, where + PCI_HT_SEC_LCTR);
808 fmt = "\t\tLink Control: CFlE%c CST%c CFE%c <LkFail%c Init%c EOC%c TXO%c <CRCErr=%x IsocEn%c LSEn%c ExtCTL%c 64b%c\n";
810 fmt = "\t\tLink Control: CFlE%c CST%c CFE%c <LkFail%c Init%c EOC%c TXO%c <CRCErr=%x\n";
812 FLAG(lctr, PCI_HT_LCTR_CFLE),
813 FLAG(lctr, PCI_HT_LCTR_CST),
814 FLAG(lctr, PCI_HT_LCTR_CFE),
815 FLAG(lctr, PCI_HT_LCTR_LKFAIL),
816 FLAG(lctr, PCI_HT_LCTR_INIT),
817 FLAG(lctr, PCI_HT_LCTR_EOC),
818 FLAG(lctr, PCI_HT_LCTR_TXO),
819 (lctr & PCI_HT_LCTR_CRCERR) >> 8,
820 FLAG(lctr, PCI_HT_LCTR_ISOCEN),
821 FLAG(lctr, PCI_HT_LCTR_LSEN),
822 FLAG(lctr, PCI_HT_LCTR_EXTCTL),
823 FLAG(lctr, PCI_HT_LCTR_64B));
824 lcnf = get_conf_word(d, where + PCI_HT_SEC_LCNF);
826 fmt = "\t\tLink Config: MLWI=%1$s DwFcIn%5$c MLWO=%2$s DwFcOut%6$c LWI=%3$s DwFcInEn%7$c LWO=%4$s DwFcOutEn%8$c\n";
828 fmt = "\t\tLink Config: MLWI=%s MLWO=%s LWI=%s LWO=%s\n";
830 ht_link_width(lcnf & PCI_HT_LCNF_MLWI),
831 ht_link_width((lcnf & PCI_HT_LCNF_MLWO) >> 4),
832 ht_link_width((lcnf & PCI_HT_LCNF_LWI) >> 8),
833 ht_link_width((lcnf & PCI_HT_LCNF_LWO) >> 12),
834 FLAG(lcnf, PCI_HT_LCNF_DFI),
835 FLAG(lcnf, PCI_HT_LCNF_DFO),
836 FLAG(lcnf, PCI_HT_LCNF_DFIE),
837 FLAG(lcnf, PCI_HT_LCNF_DFOE));
838 printf("\t\tRevision ID: %u.%02u\n",
839 (rid & PCI_HT_RID_MAJ) >> 5, (rid & PCI_HT_RID_MIN));
842 lfrer = get_conf_byte(d, where + PCI_HT_SEC_LFRER);
843 printf("\t\tLink Frequency: %s\n", ht_link_freq(lfrer & PCI_HT_LFRER_FREQ));
844 printf("\t\tLink Error: <Prot%c <Ovfl%c <EOC%c CTLTm%c\n",
845 FLAG(lfrer, PCI_HT_LFRER_PROT),
846 FLAG(lfrer, PCI_HT_LFRER_OV),
847 FLAG(lfrer, PCI_HT_LFRER_EOC),
848 FLAG(lfrer, PCI_HT_LFRER_CTLT));
849 lfcap = get_conf_byte(d, where + PCI_HT_SEC_LFCAP);
850 printf("\t\tLink Frequency Capability: 200MHz%c 300MHz%c 400MHz%c 500MHz%c 600MHz%c 800MHz%c 1.0GHz%c 1.2GHz%c 1.4GHz%c 1.6GHz%c Vend%c\n",
851 FLAG(lfcap, PCI_HT_LFCAP_200),
852 FLAG(lfcap, PCI_HT_LFCAP_300),
853 FLAG(lfcap, PCI_HT_LFCAP_400),
854 FLAG(lfcap, PCI_HT_LFCAP_500),
855 FLAG(lfcap, PCI_HT_LFCAP_600),
856 FLAG(lfcap, PCI_HT_LFCAP_800),
857 FLAG(lfcap, PCI_HT_LFCAP_1000),
858 FLAG(lfcap, PCI_HT_LFCAP_1200),
859 FLAG(lfcap, PCI_HT_LFCAP_1400),
860 FLAG(lfcap, PCI_HT_LFCAP_1600),
861 FLAG(lfcap, PCI_HT_LFCAP_VEND));
862 ftr = get_conf_word(d, where + PCI_HT_SEC_FTR);
863 printf("\t\tFeature Capability: IsocFC%c LDTSTOP%c CRCTM%c ECTLT%c 64bA%c UIDRD%c ExtRS%c UCnfE%c\n",
864 FLAG(ftr, PCI_HT_FTR_ISOCFC),
865 FLAG(ftr, PCI_HT_FTR_LDTSTOP),
866 FLAG(ftr, PCI_HT_FTR_CRCTM),
867 FLAG(ftr, PCI_HT_FTR_ECTLT),
868 FLAG(ftr, PCI_HT_FTR_64BA),
869 FLAG(ftr, PCI_HT_FTR_UIDRD),
870 FLAG(ftr, PCI_HT_SEC_FTR_EXTRS),
871 FLAG(ftr, PCI_HT_SEC_FTR_UCNFE));
872 if (ftr & PCI_HT_SEC_FTR_EXTRS)
874 eh = get_conf_word(d, where + PCI_HT_SEC_EH);
875 printf("\t\tError Handling: PFlE%c OFlE%c PFE%c OFE%c EOCFE%c RFE%c CRCFE%c SERRFE%c CF%c RE%c PNFE%c ONFE%c EOCNFE%c RNFE%c CRCNFE%c SERRNFE%c\n",
876 FLAG(eh, PCI_HT_EH_PFLE),
877 FLAG(eh, PCI_HT_EH_OFLE),
878 FLAG(eh, PCI_HT_EH_PFE),
879 FLAG(eh, PCI_HT_EH_OFE),
880 FLAG(eh, PCI_HT_EH_EOCFE),
881 FLAG(eh, PCI_HT_EH_RFE),
882 FLAG(eh, PCI_HT_EH_CRCFE),
883 FLAG(eh, PCI_HT_EH_SERRFE),
884 FLAG(eh, PCI_HT_EH_CF),
885 FLAG(eh, PCI_HT_EH_RE),
886 FLAG(eh, PCI_HT_EH_PNFE),
887 FLAG(eh, PCI_HT_EH_ONFE),
888 FLAG(eh, PCI_HT_EH_EOCNFE),
889 FLAG(eh, PCI_HT_EH_RNFE),
890 FLAG(eh, PCI_HT_EH_CRCNFE),
891 FLAG(eh, PCI_HT_EH_SERRNFE));
892 mbu = get_conf_byte(d, where + PCI_HT_SEC_MBU);
893 mlu = get_conf_byte(d, where + PCI_HT_SEC_MLU);
894 printf("\t\tPrefetchable memory behind bridge Upper: %02x-%02x\n", mbu, mlu);
899 show_ht(struct device *d, int where, int cmd)
903 switch (cmd & PCI_HT_CMD_TYP_HI)
905 case PCI_HT_CMD_TYP_HI_PRI:
906 show_ht_pri(d, where, cmd);
908 case PCI_HT_CMD_TYP_HI_SEC:
909 show_ht_sec(d, where, cmd);
913 type = cmd & PCI_HT_CMD_TYP;
916 case PCI_HT_CMD_TYP_SW:
917 printf("HyperTransport: Switch\n");
919 case PCI_HT_CMD_TYP_IDC:
920 printf("HyperTransport: Interrupt Discovery and Configuration\n");
922 case PCI_HT_CMD_TYP_RID:
923 printf("HyperTransport: Revision ID: %u.%02u\n",
924 (cmd & PCI_HT_RID_MAJ) >> 5, (cmd & PCI_HT_RID_MIN));
926 case PCI_HT_CMD_TYP_UIDC:
927 printf("HyperTransport: UnitID Clumping\n");
929 case PCI_HT_CMD_TYP_ECSA:
930 printf("HyperTransport: Extended Configuration Space Access\n");
932 case PCI_HT_CMD_TYP_AM:
933 printf("HyperTransport: Address Mapping\n");
935 case PCI_HT_CMD_TYP_MSIM:
936 printf("HyperTransport: MSI Mapping\n");
938 case PCI_HT_CMD_TYP_DR:
939 printf("HyperTransport: DirectRoute\n");
941 case PCI_HT_CMD_TYP_VCS:
942 printf("HyperTransport: VCSet\n");
944 case PCI_HT_CMD_TYP_RM:
945 printf("HyperTransport: Retry Mode\n");
947 case PCI_HT_CMD_TYP_X86:
948 printf("HyperTransport: X86 (reserved)\n");
951 printf("HyperTransport: #%02x\n", type >> 11);
956 show_rom(struct device *d, int reg)
958 struct pci_dev *p = d->dev;
959 pciaddr_t rom = p->rom_base_addr;
960 pciaddr_t len = (p->known_fields & PCI_FILL_SIZES) ? p->rom_size : 0;
961 u32 flg = get_conf_long(d, reg);
962 word cmd = get_conf_word(d, PCI_COMMAND);
964 if (!rom && !flg && !len)
967 if ((rom & PCI_ROM_ADDRESS_MASK) && !(flg & PCI_ROM_ADDRESS_MASK))
969 printf("[virtual] ");
972 printf("Expansion ROM at ");
973 if (rom & PCI_ROM_ADDRESS_MASK)
974 printf(PCIADDR_T_FMT, rom & PCI_ROM_ADDRESS_MASK);
975 else if (flg & PCI_ROM_ADDRESS_MASK)
978 printf("<unassigned>");
979 if (!(flg & PCI_ROM_ADDRESS_ENABLE))
980 printf(" [disabled]");
981 else if (!(cmd & PCI_COMMAND_MEMORY))
982 printf(" [disabled by cmd]");
988 show_msi(struct device *d, int where, int cap)
994 printf("Message Signalled Interrupts: Mask%c 64bit%c Queue=%d/%d Enable%c\n",
995 FLAG(cap, PCI_MSI_FLAGS_MASK_BIT),
996 FLAG(cap, PCI_MSI_FLAGS_64BIT),
997 (cap & PCI_MSI_FLAGS_QSIZE) >> 4,
998 (cap & PCI_MSI_FLAGS_QMASK) >> 1,
999 FLAG(cap, PCI_MSI_FLAGS_ENABLE));
1002 is64 = cap & PCI_MSI_FLAGS_64BIT;
1003 if (!config_fetch(d, where + PCI_MSI_ADDRESS_LO, (is64 ? PCI_MSI_DATA_64 : PCI_MSI_DATA_32) + 2 - PCI_MSI_ADDRESS_LO))
1005 printf("\t\tAddress: ");
1008 t = get_conf_long(d, where + PCI_MSI_ADDRESS_HI);
1009 w = get_conf_word(d, where + PCI_MSI_DATA_64);
1013 w = get_conf_word(d, where + PCI_MSI_DATA_32);
1014 t = get_conf_long(d, where + PCI_MSI_ADDRESS_LO);
1015 printf("%08x Data: %04x\n", t, w);
1016 if (cap & PCI_MSI_FLAGS_MASK_BIT)
1022 if (!config_fetch(d, where + PCI_MSI_MASK_BIT_64, 8))
1024 mask = get_conf_long(d, where + PCI_MSI_MASK_BIT_64);
1025 pending = get_conf_long(d, where + PCI_MSI_PENDING_64);
1029 if (!config_fetch(d, where + PCI_MSI_MASK_BIT_32, 8))
1031 mask = get_conf_long(d, where + PCI_MSI_MASK_BIT_32);
1032 pending = get_conf_long(d, where + PCI_MSI_PENDING_32);
1034 printf("\t\tMasking: %08x Pending: %08x\n", mask, pending);
1038 static void show_vendor(void)
1040 printf("Vendor Specific Information\n");
1043 static void show_debug(void)
1045 printf("Debug port\n");
1048 static float power_limit(int value, int scale)
1050 static const float scales[4] = { 1.0, 0.1, 0.01, 0.001 };
1051 return value * scales[scale];
1054 static const char *latency_l0s(int value)
1056 static const char *latencies[] = { "<64ns", "<128ns", "<256ns", "<512ns", "<1us", "<2us", "<4us", "unlimited" };
1057 return latencies[value];
1060 static const char *latency_l1(int value)
1062 static const char *latencies[] = { "<1us", "<2us", "<4us", "<8us", "<16us", "<32us", "<64us", "unlimited" };
1063 return latencies[value];
1066 static void show_express_dev(struct device *d, int where, int type)
1071 t = get_conf_long(d, where + PCI_EXP_DEVCAP);
1072 printf("\t\tDevice: Supported: MaxPayload %d bytes, PhantFunc %d, ExtTag%c\n",
1073 128 << (t & PCI_EXP_DEVCAP_PAYLOAD),
1074 (1 << ((t & PCI_EXP_DEVCAP_PHANTOM) >> 3)) - 1,
1075 FLAG(t, PCI_EXP_DEVCAP_EXT_TAG));
1076 printf("\t\tDevice: Latency L0s %s, L1 %s\n",
1077 latency_l0s((t & PCI_EXP_DEVCAP_L0S) >> 6),
1078 latency_l1((t & PCI_EXP_DEVCAP_L1) >> 9));
1079 if ((type == PCI_EXP_TYPE_ENDPOINT) || (type == PCI_EXP_TYPE_LEG_END) ||
1080 (type == PCI_EXP_TYPE_UPSTREAM) || (type == PCI_EXP_TYPE_PCI_BRIDGE))
1081 printf("\t\tDevice: AtnBtn%c AtnInd%c PwrInd%c\n",
1082 FLAG(t, PCI_EXP_DEVCAP_ATN_BUT),
1083 FLAG(t, PCI_EXP_DEVCAP_ATN_IND), FLAG(t, PCI_EXP_DEVCAP_PWR_IND));
1084 if (type == PCI_EXP_TYPE_UPSTREAM)
1085 printf("\t\tDevice: SlotPowerLimit %f\n",
1086 power_limit((t & PCI_EXP_DEVCAP_PWR_VAL) >> 18,
1087 (t & PCI_EXP_DEVCAP_PWR_SCL) >> 26));
1089 w = get_conf_word(d, where + PCI_EXP_DEVCTL);
1090 printf("\t\tDevice: Errors: Correctable%c Non-Fatal%c Fatal%c Unsupported%c\n",
1091 FLAG(w, PCI_EXP_DEVCTL_CERE),
1092 FLAG(w, PCI_EXP_DEVCTL_NFERE),
1093 FLAG(w, PCI_EXP_DEVCTL_FERE),
1094 FLAG(w, PCI_EXP_DEVCTL_URRE));
1095 printf("\t\tDevice: RlxdOrd%c ExtTag%c PhantFunc%c AuxPwr%c NoSnoop%c\n",
1096 FLAG(w, PCI_EXP_DEVCTL_RELAXED),
1097 FLAG(w, PCI_EXP_DEVCTL_EXT_TAG),
1098 FLAG(w, PCI_EXP_DEVCTL_PHANTOM),
1099 FLAG(w, PCI_EXP_DEVCTL_AUX_PME),
1100 FLAG(w, PCI_EXP_DEVCTL_NOSNOOP));
1101 printf("\t\tDevice: MaxPayload %d bytes, MaxReadReq %d bytes\n",
1102 128 << ((w & PCI_EXP_DEVCTL_PAYLOAD) >> 5),
1103 128 << ((w & PCI_EXP_DEVCTL_READRQ) >> 12));
1106 static char *link_speed(int speed)
1117 static char *aspm_support(int code)
1130 static const char *aspm_enabled(int code)
1132 static const char *desc[] = { "Disabled", "L0s Enabled", "L1 Enabled", "L0s L1 Enabled" };
1136 static void show_express_link(struct device *d, int where, int type)
1141 t = get_conf_long(d, where + PCI_EXP_LNKCAP);
1142 printf("\t\tLink: Supported Speed %s, Width x%d, ASPM %s, Port %d\n",
1143 link_speed(t & PCI_EXP_LNKCAP_SPEED), (t & PCI_EXP_LNKCAP_WIDTH) >> 4,
1144 aspm_support((t & PCI_EXP_LNKCAP_ASPM) >> 10),
1146 printf("\t\tLink: Latency L0s %s, L1 %s\n",
1147 latency_l0s((t & PCI_EXP_LNKCAP_L0S) >> 12),
1148 latency_l1((t & PCI_EXP_LNKCAP_L1) >> 15));
1149 w = get_conf_word(d, where + PCI_EXP_LNKCTL);
1150 printf("\t\tLink: ASPM %s", aspm_enabled(w & PCI_EXP_LNKCTL_ASPM));
1151 if ((type == PCI_EXP_TYPE_ROOT_PORT) || (type == PCI_EXP_TYPE_ENDPOINT) ||
1152 (type == PCI_EXP_TYPE_LEG_END))
1153 printf(" RCB %d bytes", w & PCI_EXP_LNKCTL_RCB ? 128 : 64);
1154 if (w & PCI_EXP_LNKCTL_DISABLE)
1155 printf(" Disabled");
1156 printf(" CommClk%c ExtSynch%c\n", FLAG(w, PCI_EXP_LNKCTL_CLOCK),
1157 FLAG(w, PCI_EXP_LNKCTL_XSYNCH));
1158 w = get_conf_word(d, where + PCI_EXP_LNKSTA);
1159 printf("\t\tLink: Speed %s, Width x%d\n",
1160 link_speed(w & PCI_EXP_LNKSTA_SPEED), (w & PCI_EXP_LNKSTA_WIDTH) >> 4);
1163 static const char *indicator(int code)
1165 static const char *names[] = { "Unknown", "On", "Blink", "Off" };
1169 static void show_express_slot(struct device *d, int where)
1174 t = get_conf_long(d, where + PCI_EXP_SLTCAP);
1175 printf("\t\tSlot: AtnBtn%c PwrCtrl%c MRL%c AtnInd%c PwrInd%c HotPlug%c Surpise%c\n",
1176 FLAG(t, PCI_EXP_SLTCAP_ATNB),
1177 FLAG(t, PCI_EXP_SLTCAP_PWRC),
1178 FLAG(t, PCI_EXP_SLTCAP_MRL),
1179 FLAG(t, PCI_EXP_SLTCAP_ATNI),
1180 FLAG(t, PCI_EXP_SLTCAP_PWRI),
1181 FLAG(t, PCI_EXP_SLTCAP_HPC),
1182 FLAG(t, PCI_EXP_SLTCAP_HPS));
1183 printf("\t\tSlot: Number %d, PowerLimit %f\n", t >> 19,
1184 power_limit((t & PCI_EXP_SLTCAP_PWR_VAL) >> 7,
1185 (t & PCI_EXP_SLTCAP_PWR_SCL) >> 15));
1186 w = get_conf_word(d, where + PCI_EXP_SLTCTL);
1187 printf("\t\tSlot: Enabled AtnBtn%c PwrFlt%c MRL%c PresDet%c CmdCplt%c HPIrq%c\n",
1188 FLAG(w, PCI_EXP_SLTCTL_ATNB),
1189 FLAG(w, PCI_EXP_SLTCTL_PWRF),
1190 FLAG(w, PCI_EXP_SLTCTL_MRLS),
1191 FLAG(w, PCI_EXP_SLTCTL_PRSD),
1192 FLAG(w, PCI_EXP_SLTCTL_CMDC),
1193 FLAG(w, PCI_EXP_SLTCTL_HPIE));
1194 printf("\t\tSlot: AttnInd %s, PwrInd %s, Power%c\n",
1195 indicator((w & PCI_EXP_SLTCTL_ATNI) >> 6),
1196 indicator((w & PCI_EXP_SLTCTL_PWRI) >> 8),
1197 FLAG(w, w & PCI_EXP_SLTCTL_PWRC));
1200 static void show_express_root(struct device *d, int where)
1202 u16 w = get_conf_word(d, where + PCI_EXP_RTCTL);
1203 printf("\t\tRoot: Correctable%c Non-Fatal%c Fatal%c PME%c\n",
1204 FLAG(w, PCI_EXP_RTCTL_SECEE),
1205 FLAG(w, PCI_EXP_RTCTL_SENFEE),
1206 FLAG(w, PCI_EXP_RTCTL_SEFEE),
1207 FLAG(w, PCI_EXP_RTCTL_PMEIE));
1211 show_express(struct device *d, int where, int cap)
1213 int type = (cap & PCI_EXP_FLAGS_TYPE) >> 4;
1220 case PCI_EXP_TYPE_ENDPOINT:
1223 case PCI_EXP_TYPE_LEG_END:
1224 printf("Legacy Endpoint");
1226 case PCI_EXP_TYPE_ROOT_PORT:
1227 slot = cap & PCI_EXP_FLAGS_SLOT;
1228 printf("Root Port (Slot%c)", FLAG(cap, PCI_EXP_FLAGS_SLOT));
1230 case PCI_EXP_TYPE_UPSTREAM:
1231 printf("Upstream Port");
1233 case PCI_EXP_TYPE_DOWNSTREAM:
1234 slot = cap & PCI_EXP_FLAGS_SLOT;
1235 printf("Downstream Port (Slot%c)", FLAG(cap, PCI_EXP_FLAGS_SLOT));
1237 case PCI_EXP_TYPE_PCI_BRIDGE:
1238 printf("PCI/PCI-X Bridge");
1241 printf("Unknown type");
1243 printf(" IRQ %d\n", (cap & PCI_EXP_FLAGS_IRQ) >> 9);
1250 if (type == PCI_EXP_TYPE_ROOT_PORT)
1252 if (!config_fetch(d, where + PCI_EXP_DEVCAP, size))
1255 show_express_dev(d, where, type);
1256 show_express_link(d, where, type);
1258 show_express_slot(d, where);
1259 if (type == PCI_EXP_TYPE_ROOT_PORT)
1260 show_express_root(d, where);
1264 show_msix(struct device *d, int where, int cap)
1268 printf("MSI-X: Enable%c Mask%c TabSize=%d\n",
1269 FLAG(cap, PCI_MSIX_ENABLE),
1270 FLAG(cap, PCI_MSIX_MASK),
1271 (cap & PCI_MSIX_TABSIZE) + 1);
1272 if (verbose < 2 || !config_fetch(d, where + PCI_MSIX_TABLE, 8))
1275 off = get_conf_long(d, where + PCI_MSIX_TABLE);
1276 printf("\t\tVector table: BAR=%d offset=%08x\n",
1277 off & PCI_MSIX_BIR, off & ~PCI_MSIX_BIR);
1278 off = get_conf_long(d, where + PCI_MSIX_PBA);
1279 printf("\t\tPBA: BAR=%d offset=%08x\n",
1280 off & PCI_MSIX_BIR, off & ~PCI_MSIX_BIR);
1284 show_slotid(int cap)
1286 int esr = cap & 0xff;
1289 printf("Slot ID: %d slots, First%c, chassis %02x\n",
1290 esr & PCI_SID_ESR_NSLOTS,
1291 FLAG(esr, PCI_SID_ESR_FIC),
1296 show_ssvid(struct device *d, int where)
1298 u16 subsys_v, subsys_d;
1299 char ssnamebuf[256];
1301 if (!config_fetch(d, where, 8))
1303 subsys_v = get_conf_word(d, where + PCI_SSVID_VENDOR);
1304 subsys_d = get_conf_word(d, where + PCI_SSVID_DEVICE);
1305 printf("Subsystem: %s\n",
1306 pci_lookup_name(pacc, ssnamebuf, sizeof(ssnamebuf),
1307 PCI_LOOKUP_SUBSYSTEM | PCI_LOOKUP_VENDOR | PCI_LOOKUP_DEVICE,
1308 d->dev->vendor_id, d->dev->device_id, subsys_v, subsys_d));
1312 show_aer(struct device *d UNUSED, int where UNUSED)
1314 printf("Advanced Error Reporting\n");
1318 show_vc(struct device *d UNUSED, int where UNUSED)
1320 printf("Virtual Channel\n");
1324 show_dsn(struct device *d, int where)
1327 if (!config_fetch(d, where + 4, 8))
1329 t1 = get_conf_long(d, where + 4);
1330 t2 = get_conf_long(d, where + 8);
1331 printf("Device Serial Number %02x-%02x-%02x-%02x-%02x-%02x-%02x-%02x\n",
1332 t1 & 0xff, (t1 >> 8) & 0xff, (t1 >> 16) & 0xff, t1 >> 24,
1333 t2 & 0xff, (t2 >> 8) & 0xff, (t2 >> 16) & 0xff, t2 >> 24);
1337 show_pb(struct device *d UNUSED, int where UNUSED)
1339 printf("Power Budgeting\n");
1343 show_ext_caps(struct device *d)
1351 if (!config_fetch(d, where, 4))
1353 header = get_conf_long(d, where);
1356 id = header & 0xffff;
1357 printf("\tCapabilities: [%03x] ", where);
1360 case PCI_EXT_CAP_ID_AER:
1363 case PCI_EXT_CAP_ID_VC:
1366 case PCI_EXT_CAP_ID_DSN:
1369 case PCI_EXT_CAP_ID_PB:
1373 printf("Unknown (%d)\n", id);
1376 where = header >> 20;
1381 show_caps(struct device *d)
1383 int can_have_ext_caps = 0;
1385 if (get_conf_word(d, PCI_STATUS) & PCI_STATUS_CAP_LIST)
1387 int where = get_conf_byte(d, PCI_CAPABILITY_LIST) & ~3;
1391 printf("\tCapabilities: ");
1392 if (!config_fetch(d, where, 4))
1394 puts("<access denied>");
1397 id = get_conf_byte(d, where + PCI_CAP_LIST_ID);
1398 next = get_conf_byte(d, where + PCI_CAP_LIST_NEXT) & ~3;
1399 cap = get_conf_word(d, where + PCI_CAP_FLAGS);
1400 printf("[%02x] ", where);
1403 printf("<chain broken>\n");
1409 show_pm(d, where, cap);
1411 case PCI_CAP_ID_AGP:
1412 show_agp(d, where, cap);
1414 case PCI_CAP_ID_VPD:
1415 printf("Vital Product Data\n");
1417 case PCI_CAP_ID_SLOTID:
1420 case PCI_CAP_ID_MSI:
1421 show_msi(d, where, cap);
1423 case PCI_CAP_ID_PCIX:
1424 show_pcix(d, where);
1425 can_have_ext_caps = 1;
1428 show_ht(d, where, cap);
1430 case PCI_CAP_ID_VNDR:
1433 case PCI_CAP_ID_DBG:
1436 case PCI_CAP_ID_SSVID:
1437 show_ssvid(d, where);
1439 case PCI_CAP_ID_EXP:
1440 show_express(d, where, cap);
1441 can_have_ext_caps = 1;
1443 case PCI_CAP_ID_MSIX:
1444 show_msix(d, where, cap);
1447 printf("#%02x [%04x]\n", id, cap);
1452 if (can_have_ext_caps)
1457 show_htype0(struct device *d)
1460 show_rom(d, PCI_ROM_ADDRESS);
1465 show_htype1(struct device *d)
1467 u32 io_base = get_conf_byte(d, PCI_IO_BASE);
1468 u32 io_limit = get_conf_byte(d, PCI_IO_LIMIT);
1469 u32 io_type = io_base & PCI_IO_RANGE_TYPE_MASK;
1470 u32 mem_base = get_conf_word(d, PCI_MEMORY_BASE);
1471 u32 mem_limit = get_conf_word(d, PCI_MEMORY_LIMIT);
1472 u32 mem_type = mem_base & PCI_MEMORY_RANGE_TYPE_MASK;
1473 u32 pref_base = get_conf_word(d, PCI_PREF_MEMORY_BASE);
1474 u32 pref_limit = get_conf_word(d, PCI_PREF_MEMORY_LIMIT);
1475 u32 pref_type = pref_base & PCI_PREF_RANGE_TYPE_MASK;
1476 word sec_stat = get_conf_word(d, PCI_SEC_STATUS);
1477 word brc = get_conf_word(d, PCI_BRIDGE_CONTROL);
1478 int verb = verbose > 2;
1481 printf("\tBus: primary=%02x, secondary=%02x, subordinate=%02x, sec-latency=%d\n",
1482 get_conf_byte(d, PCI_PRIMARY_BUS),
1483 get_conf_byte(d, PCI_SECONDARY_BUS),
1484 get_conf_byte(d, PCI_SUBORDINATE_BUS),
1485 get_conf_byte(d, PCI_SEC_LATENCY_TIMER));
1487 if (io_type != (io_limit & PCI_IO_RANGE_TYPE_MASK) ||
1488 (io_type != PCI_IO_RANGE_TYPE_16 && io_type != PCI_IO_RANGE_TYPE_32))
1489 printf("\t!!! Unknown I/O range types %x/%x\n", io_base, io_limit);
1492 io_base = (io_base & PCI_IO_RANGE_MASK) << 8;
1493 io_limit = (io_limit & PCI_IO_RANGE_MASK) << 8;
1494 if (io_type == PCI_IO_RANGE_TYPE_32)
1496 io_base |= (get_conf_word(d, PCI_IO_BASE_UPPER16) << 16);
1497 io_limit |= (get_conf_word(d, PCI_IO_LIMIT_UPPER16) << 16);
1499 if (io_base <= io_limit || verb)
1500 printf("\tI/O behind bridge: %08x-%08x\n", io_base, io_limit+0xfff);
1503 if (mem_type != (mem_limit & PCI_MEMORY_RANGE_TYPE_MASK) ||
1505 printf("\t!!! Unknown memory range types %x/%x\n", mem_base, mem_limit);
1508 mem_base = (mem_base & PCI_MEMORY_RANGE_MASK) << 16;
1509 mem_limit = (mem_limit & PCI_MEMORY_RANGE_MASK) << 16;
1510 if (mem_base <= mem_limit || verb)
1511 printf("\tMemory behind bridge: %08x-%08x\n", mem_base, mem_limit + 0xfffff);
1514 if (pref_type != (pref_limit & PCI_PREF_RANGE_TYPE_MASK) ||
1515 (pref_type != PCI_PREF_RANGE_TYPE_32 && pref_type != PCI_PREF_RANGE_TYPE_64))
1516 printf("\t!!! Unknown prefetchable memory range types %x/%x\n", pref_base, pref_limit);
1519 pref_base = (pref_base & PCI_PREF_RANGE_MASK) << 16;
1520 pref_limit = (pref_limit & PCI_PREF_RANGE_MASK) << 16;
1521 if (pref_base <= pref_limit || verb)
1523 if (pref_type == PCI_PREF_RANGE_TYPE_32)
1524 printf("\tPrefetchable memory behind bridge: %08x-%08x\n", pref_base, pref_limit + 0xfffff);
1526 printf("\tPrefetchable memory behind bridge: %08x%08x-%08x%08x\n",
1527 get_conf_long(d, PCI_PREF_BASE_UPPER32),
1529 get_conf_long(d, PCI_PREF_LIMIT_UPPER32),
1530 pref_limit + 0xfffff);
1535 printf("\tSecondary status: 66MHz%c FastB2B%c ParErr%c DEVSEL=%s >TAbort%c <TAbort%c <MAbort%c <SERR%c <PERR%c\n",
1536 FLAG(sec_stat, PCI_STATUS_66MHZ),
1537 FLAG(sec_stat, PCI_STATUS_FAST_BACK),
1538 FLAG(sec_stat, PCI_STATUS_PARITY),
1539 ((sec_stat & PCI_STATUS_DEVSEL_MASK) == PCI_STATUS_DEVSEL_SLOW) ? "slow" :
1540 ((sec_stat & PCI_STATUS_DEVSEL_MASK) == PCI_STATUS_DEVSEL_MEDIUM) ? "medium" :
1541 ((sec_stat & PCI_STATUS_DEVSEL_MASK) == PCI_STATUS_DEVSEL_FAST) ? "fast" : "??",
1542 FLAG(sec_stat, PCI_STATUS_SIG_TARGET_ABORT),
1543 FLAG(sec_stat, PCI_STATUS_REC_TARGET_ABORT),
1544 FLAG(sec_stat, PCI_STATUS_REC_MASTER_ABORT),
1545 FLAG(sec_stat, PCI_STATUS_SIG_SYSTEM_ERROR),
1546 FLAG(sec_stat, PCI_STATUS_DETECTED_PARITY));
1548 show_rom(d, PCI_ROM_ADDRESS1);
1551 printf("\tBridgeCtl: Parity%c SERR%c NoISA%c VGA%c MAbort%c >Reset%c FastB2B%c\n",
1552 FLAG(brc, PCI_BRIDGE_CTL_PARITY),
1553 FLAG(brc, PCI_BRIDGE_CTL_SERR),
1554 FLAG(brc, PCI_BRIDGE_CTL_NO_ISA),
1555 FLAG(brc, PCI_BRIDGE_CTL_VGA),
1556 FLAG(brc, PCI_BRIDGE_CTL_MASTER_ABORT),
1557 FLAG(brc, PCI_BRIDGE_CTL_BUS_RESET),
1558 FLAG(brc, PCI_BRIDGE_CTL_FAST_BACK));
1564 show_htype2(struct device *d)
1567 word cmd = get_conf_word(d, PCI_COMMAND);
1568 word brc = get_conf_word(d, PCI_CB_BRIDGE_CONTROL);
1570 int verb = verbose > 2;
1573 printf("\tBus: primary=%02x, secondary=%02x, subordinate=%02x, sec-latency=%d\n",
1574 get_conf_byte(d, PCI_CB_PRIMARY_BUS),
1575 get_conf_byte(d, PCI_CB_CARD_BUS),
1576 get_conf_byte(d, PCI_CB_SUBORDINATE_BUS),
1577 get_conf_byte(d, PCI_CB_LATENCY_TIMER));
1581 u32 base = get_conf_long(d, PCI_CB_MEMORY_BASE_0 + p);
1582 u32 limit = get_conf_long(d, PCI_CB_MEMORY_LIMIT_0 + p);
1583 if (limit > base || verb)
1584 printf("\tMemory window %d: %08x-%08x%s%s\n", i, base, limit,
1585 (cmd & PCI_COMMAND_MEMORY) ? "" : " [disabled]",
1586 (brc & (PCI_CB_BRIDGE_CTL_PREFETCH_MEM0 << i)) ? " (prefetchable)" : "");
1591 u32 base = get_conf_long(d, PCI_CB_IO_BASE_0 + p);
1592 u32 limit = get_conf_long(d, PCI_CB_IO_LIMIT_0 + p);
1593 if (!(base & PCI_IO_RANGE_TYPE_32))
1598 base &= PCI_CB_IO_RANGE_MASK;
1599 limit = (limit & PCI_CB_IO_RANGE_MASK) + 3;
1600 if (base <= limit || verb)
1601 printf("\tI/O window %d: %08x-%08x%s\n", i, base, limit,
1602 (cmd & PCI_COMMAND_IO) ? "" : " [disabled]");
1605 if (get_conf_word(d, PCI_CB_SEC_STATUS) & PCI_STATUS_SIG_SYSTEM_ERROR)
1606 printf("\tSecondary status: SERR\n");
1608 printf("\tBridgeCtl: Parity%c SERR%c ISA%c VGA%c MAbort%c >Reset%c 16bInt%c PostWrite%c\n",
1609 FLAG(brc, PCI_CB_BRIDGE_CTL_PARITY),
1610 FLAG(brc, PCI_CB_BRIDGE_CTL_SERR),
1611 FLAG(brc, PCI_CB_BRIDGE_CTL_ISA),
1612 FLAG(brc, PCI_CB_BRIDGE_CTL_VGA),
1613 FLAG(brc, PCI_CB_BRIDGE_CTL_MASTER_ABORT),
1614 FLAG(brc, PCI_CB_BRIDGE_CTL_CB_RESET),
1615 FLAG(brc, PCI_CB_BRIDGE_CTL_16BIT_INT),
1616 FLAG(brc, PCI_CB_BRIDGE_CTL_POST_WRITES));
1618 if (d->config_cached < 128)
1620 printf("\t<access denied to the rest>\n");
1624 exca = get_conf_word(d, PCI_CB_LEGACY_MODE_BASE);
1626 printf("\t16-bit legacy interface ports at %04x\n", exca);
1630 show_verbose(struct device *d)
1632 struct pci_dev *p = d->dev;
1633 word status = get_conf_word(d, PCI_STATUS);
1634 word cmd = get_conf_word(d, PCI_COMMAND);
1635 word class = p->device_class;
1636 byte bist = get_conf_byte(d, PCI_BIST);
1637 byte htype = get_conf_byte(d, PCI_HEADER_TYPE) & 0x7f;
1638 byte latency = get_conf_byte(d, PCI_LATENCY_TIMER);
1639 byte cache_line = get_conf_byte(d, PCI_CACHE_LINE_SIZE);
1640 byte max_lat, min_gnt;
1641 byte int_pin = get_conf_byte(d, PCI_INTERRUPT_PIN);
1642 unsigned int irq = p->irq;
1643 word subsys_v = 0, subsys_d = 0;
1644 char ssnamebuf[256];
1650 case PCI_HEADER_TYPE_NORMAL:
1651 if (class == PCI_CLASS_BRIDGE_PCI)
1652 printf("\t!!! Invalid class %04x for header type %02x\n", class, htype);
1653 max_lat = get_conf_byte(d, PCI_MAX_LAT);
1654 min_gnt = get_conf_byte(d, PCI_MIN_GNT);
1655 subsys_v = get_conf_word(d, PCI_SUBSYSTEM_VENDOR_ID);
1656 subsys_d = get_conf_word(d, PCI_SUBSYSTEM_ID);
1658 case PCI_HEADER_TYPE_BRIDGE:
1659 if ((class >> 8) != PCI_BASE_CLASS_BRIDGE)
1660 printf("\t!!! Invalid class %04x for header type %02x\n", class, htype);
1661 irq = int_pin = min_gnt = max_lat = 0;
1663 case PCI_HEADER_TYPE_CARDBUS:
1664 if ((class >> 8) != PCI_BASE_CLASS_BRIDGE)
1665 printf("\t!!! Invalid class %04x for header type %02x\n", class, htype);
1666 min_gnt = max_lat = 0;
1667 if (d->config_cached >= 128)
1669 subsys_v = get_conf_word(d, PCI_CB_SUBSYSTEM_VENDOR_ID);
1670 subsys_d = get_conf_word(d, PCI_CB_SUBSYSTEM_ID);
1674 printf("\t!!! Unknown header type %02x\n", htype);
1678 if (subsys_v && subsys_v != 0xffff)
1679 printf("\tSubsystem: %s\n",
1680 pci_lookup_name(pacc, ssnamebuf, sizeof(ssnamebuf),
1681 PCI_LOOKUP_SUBSYSTEM | PCI_LOOKUP_VENDOR | PCI_LOOKUP_DEVICE,
1682 p->vendor_id, p->device_id, subsys_v, subsys_d));
1686 printf("\tControl: I/O%c Mem%c BusMaster%c SpecCycle%c MemWINV%c VGASnoop%c ParErr%c Stepping%c SERR%c FastB2B%c\n",
1687 FLAG(cmd, PCI_COMMAND_IO),
1688 FLAG(cmd, PCI_COMMAND_MEMORY),
1689 FLAG(cmd, PCI_COMMAND_MASTER),
1690 FLAG(cmd, PCI_COMMAND_SPECIAL),
1691 FLAG(cmd, PCI_COMMAND_INVALIDATE),
1692 FLAG(cmd, PCI_COMMAND_VGA_PALETTE),
1693 FLAG(cmd, PCI_COMMAND_PARITY),
1694 FLAG(cmd, PCI_COMMAND_WAIT),
1695 FLAG(cmd, PCI_COMMAND_SERR),
1696 FLAG(cmd, PCI_COMMAND_FAST_BACK));
1697 printf("\tStatus: Cap%c 66MHz%c UDF%c FastB2B%c ParErr%c DEVSEL=%s >TAbort%c <TAbort%c <MAbort%c >SERR%c <PERR%c\n",
1698 FLAG(status, PCI_STATUS_CAP_LIST),
1699 FLAG(status, PCI_STATUS_66MHZ),
1700 FLAG(status, PCI_STATUS_UDF),
1701 FLAG(status, PCI_STATUS_FAST_BACK),
1702 FLAG(status, PCI_STATUS_PARITY),
1703 ((status & PCI_STATUS_DEVSEL_MASK) == PCI_STATUS_DEVSEL_SLOW) ? "slow" :
1704 ((status & PCI_STATUS_DEVSEL_MASK) == PCI_STATUS_DEVSEL_MEDIUM) ? "medium" :
1705 ((status & PCI_STATUS_DEVSEL_MASK) == PCI_STATUS_DEVSEL_FAST) ? "fast" : "??",
1706 FLAG(status, PCI_STATUS_SIG_TARGET_ABORT),
1707 FLAG(status, PCI_STATUS_REC_TARGET_ABORT),
1708 FLAG(status, PCI_STATUS_REC_MASTER_ABORT),
1709 FLAG(status, PCI_STATUS_SIG_SYSTEM_ERROR),
1710 FLAG(status, PCI_STATUS_DETECTED_PARITY));
1711 if (cmd & PCI_COMMAND_MASTER)
1713 printf("\tLatency: %d", latency);
1714 if (min_gnt || max_lat)
1718 printf("%dns min", min_gnt*250);
1719 if (min_gnt && max_lat)
1722 printf("%dns max", max_lat*250);
1726 printf(", Cache Line Size: %d bytes", cache_line * 4);
1730 printf("\tInterrupt: pin %c routed to IRQ " PCIIRQ_FMT "\n",
1731 (int_pin ? 'A' + int_pin - 1 : '?'), irq);
1735 printf("\tFlags: ");
1736 if (cmd & PCI_COMMAND_MASTER)
1737 printf("bus master, ");
1738 if (cmd & PCI_COMMAND_VGA_PALETTE)
1739 printf("VGA palette snoop, ");
1740 if (cmd & PCI_COMMAND_WAIT)
1741 printf("stepping, ");
1742 if (cmd & PCI_COMMAND_FAST_BACK)
1743 printf("fast Back2Back, ");
1744 if (status & PCI_STATUS_66MHZ)
1746 if (status & PCI_STATUS_UDF)
1747 printf("user-definable features, ");
1749 ((status & PCI_STATUS_DEVSEL_MASK) == PCI_STATUS_DEVSEL_SLOW) ? "slow" :
1750 ((status & PCI_STATUS_DEVSEL_MASK) == PCI_STATUS_DEVSEL_MEDIUM) ? "medium" :
1751 ((status & PCI_STATUS_DEVSEL_MASK) == PCI_STATUS_DEVSEL_FAST) ? "fast" : "??");
1752 if (cmd & PCI_COMMAND_MASTER)
1753 printf(", latency %d", latency);
1755 printf(", IRQ " PCIIRQ_FMT, irq);
1759 if (bist & PCI_BIST_CAPABLE)
1761 if (bist & PCI_BIST_START)
1762 printf("\tBIST is running\n");
1764 printf("\tBIST result: %02x\n", bist & PCI_BIST_CODE_MASK);
1769 case PCI_HEADER_TYPE_NORMAL:
1772 case PCI_HEADER_TYPE_BRIDGE:
1775 case PCI_HEADER_TYPE_CARDBUS:
1782 show_hex_dump(struct device *d)
1784 unsigned int i, cnt;
1786 cnt = d->config_cached;
1787 if (show_hex >= 3 && config_fetch(d, cnt, 256-cnt))
1790 if (show_hex >= 4 && config_fetch(d, 256, 4096-256))
1794 for(i=0; i<cnt; i++)
1798 printf(" %02x", get_conf_byte(d, i));
1805 show_machine(struct device *d)
1807 struct pci_dev *p = d->dev;
1809 word sv_id=0, sd_id=0;
1810 char classbuf[128], vendbuf[128], devbuf[128], svbuf[128], sdbuf[128];
1812 switch (get_conf_byte(d, PCI_HEADER_TYPE) & 0x7f)
1814 case PCI_HEADER_TYPE_NORMAL:
1815 sv_id = get_conf_word(d, PCI_SUBSYSTEM_VENDOR_ID);
1816 sd_id = get_conf_word(d, PCI_SUBSYSTEM_ID);
1818 case PCI_HEADER_TYPE_CARDBUS:
1819 if (d->config_cached >= 128)
1821 sv_id = get_conf_word(d, PCI_CB_SUBSYSTEM_VENDOR_ID);
1822 sd_id = get_conf_word(d, PCI_CB_SUBSYSTEM_ID);
1829 printf((machine_readable >= 2) ? "Slot:\t" : "Device:\t");
1832 printf("Class:\t%s\n",
1833 pci_lookup_name(pacc, classbuf, sizeof(classbuf), PCI_LOOKUP_CLASS, p->device_class));
1834 printf("Vendor:\t%s\n",
1835 pci_lookup_name(pacc, vendbuf, sizeof(vendbuf), PCI_LOOKUP_VENDOR, p->vendor_id, p->device_id));
1836 printf("Device:\t%s\n",
1837 pci_lookup_name(pacc, devbuf, sizeof(devbuf), PCI_LOOKUP_DEVICE, p->vendor_id, p->device_id));
1838 if (sv_id && sv_id != 0xffff)
1840 printf("SVendor:\t%s\n",
1841 pci_lookup_name(pacc, svbuf, sizeof(svbuf), PCI_LOOKUP_SUBSYSTEM | PCI_LOOKUP_VENDOR, sv_id));
1842 printf("SDevice:\t%s\n",
1843 pci_lookup_name(pacc, sdbuf, sizeof(sdbuf), PCI_LOOKUP_SUBSYSTEM | PCI_LOOKUP_DEVICE, p->vendor_id, p->device_id, sv_id, sd_id));
1845 if (c = get_conf_byte(d, PCI_REVISION_ID))
1846 printf("Rev:\t%02x\n", c);
1847 if (c = get_conf_byte(d, PCI_CLASS_PROG))
1848 printf("ProgIf:\t%02x\n", c);
1853 printf(" \"%s\" \"%s\" \"%s\"",
1854 pci_lookup_name(pacc, classbuf, sizeof(classbuf), PCI_LOOKUP_CLASS,
1856 pci_lookup_name(pacc, vendbuf, sizeof(vendbuf), PCI_LOOKUP_VENDOR,
1857 p->vendor_id, p->device_id),
1858 pci_lookup_name(pacc, devbuf, sizeof(devbuf), PCI_LOOKUP_DEVICE,
1859 p->vendor_id, p->device_id));
1860 if (c = get_conf_byte(d, PCI_REVISION_ID))
1861 printf(" -r%02x", c);
1862 if (c = get_conf_byte(d, PCI_CLASS_PROG))
1863 printf(" -p%02x", c);
1864 if (sv_id && sv_id != 0xffff)
1865 printf(" \"%s\" \"%s\"",
1866 pci_lookup_name(pacc, svbuf, sizeof(svbuf), PCI_LOOKUP_SUBSYSTEM | PCI_LOOKUP_VENDOR, sv_id),
1867 pci_lookup_name(pacc, sdbuf, sizeof(sdbuf), PCI_LOOKUP_SUBSYSTEM | PCI_LOOKUP_DEVICE, p->vendor_id, p->device_id, sv_id, sd_id));
1869 printf(" \"\" \"\"");
1875 show_device(struct device *d)
1877 if (machine_readable)
1885 if (verbose || show_hex)
1894 for(d=first_dev; d; d=d->next)
1901 struct bridge *chain; /* Single-linked list of bridges */
1902 struct bridge *next, *child; /* Tree of bridges */
1903 struct bus *first_bus; /* List of buses connected to this bridge */
1904 unsigned int domain;
1905 unsigned int primary, secondary, subordinate; /* Bus numbers */
1906 struct device *br_dev;
1910 unsigned int domain;
1911 unsigned int number;
1912 struct bus *sibling;
1913 struct device *first_dev, **last_dev;
1916 static struct bridge host_bridge = { NULL, NULL, NULL, NULL, 0, ~0, 0, ~0, NULL };
1919 find_bus(struct bridge *b, unsigned int domain, unsigned int n)
1923 for(bus=b->first_bus; bus; bus=bus->sibling)
1924 if (bus->domain == domain && bus->number == n)
1930 new_bus(struct bridge *b, unsigned int domain, unsigned int n)
1932 struct bus *bus = xmalloc(sizeof(struct bus));
1933 bus->domain = domain;
1935 bus->sibling = b->first_bus;
1936 bus->first_dev = NULL;
1937 bus->last_dev = &bus->first_dev;
1943 insert_dev(struct device *d, struct bridge *b)
1945 struct pci_dev *p = d->dev;
1948 if (! (bus = find_bus(b, p->domain, p->bus)))
1951 for(c=b->child; c; c=c->next)
1952 if (c->domain == p->domain && c->secondary <= p->bus && p->bus <= c->subordinate)
1957 bus = new_bus(b, p->domain, p->bus);
1959 /* Simple insertion at the end _does_ guarantee the correct order as the
1960 * original device list was sorted by (domain, bus, devfn) lexicographically
1961 * and all devices on the new list have the same bus number.
1964 bus->last_dev = &d->next;
1971 struct device *d, *d2;
1972 struct bridge **last_br, *b;
1974 /* Build list of bridges */
1976 last_br = &host_bridge.chain;
1977 for(d=first_dev; d; d=d->next)
1979 word class = d->dev->device_class;
1980 byte ht = get_conf_byte(d, PCI_HEADER_TYPE) & 0x7f;
1981 if (class == PCI_CLASS_BRIDGE_PCI &&
1982 (ht == PCI_HEADER_TYPE_BRIDGE || ht == PCI_HEADER_TYPE_CARDBUS))
1984 b = xmalloc(sizeof(struct bridge));
1985 b->domain = d->dev->domain;
1986 if (ht == PCI_HEADER_TYPE_BRIDGE)
1988 b->primary = get_conf_byte(d, PCI_CB_PRIMARY_BUS);
1989 b->secondary = get_conf_byte(d, PCI_CB_CARD_BUS);
1990 b->subordinate = get_conf_byte(d, PCI_CB_SUBORDINATE_BUS);
1994 b->primary = get_conf_byte(d, PCI_PRIMARY_BUS);
1995 b->secondary = get_conf_byte(d, PCI_SECONDARY_BUS);
1996 b->subordinate = get_conf_byte(d, PCI_SUBORDINATE_BUS);
1999 last_br = &b->chain;
2000 b->next = b->child = NULL;
2001 b->first_bus = NULL;
2007 /* Create a bridge tree */
2009 for(b=&host_bridge; b; b=b->chain)
2011 struct bridge *c, *best;
2013 for(c=&host_bridge; c; c=c->chain)
2014 if (c != b && (c == &host_bridge || b->domain == c->domain) &&
2015 b->primary >= c->secondary && b->primary <= c->subordinate &&
2016 (!best || best->subordinate - best->primary > c->subordinate - c->primary))
2020 b->next = best->child;
2025 /* Insert secondary bus for each bridge */
2027 for(b=&host_bridge; b; b=b->chain)
2028 if (!find_bus(b, b->domain, b->secondary))
2029 new_bus(b, b->domain, b->secondary);
2031 /* Create bus structs and link devices */
2033 for(d=first_dev; d;)
2036 insert_dev(d, &host_bridge);
2042 print_it(char *line, char *p)
2046 fputs(line, stdout);
2047 for(p=line; *p; p++)
2048 if (*p == '+' || *p == '|')
2054 static void show_tree_bridge(struct bridge *, char *, char *);
2057 show_tree_dev(struct device *d, char *line, char *p)
2059 struct pci_dev *q = d->dev;
2063 p += sprintf(p, "%02x.%x", q->dev, q->func);
2064 for(b=&host_bridge; b; b=b->chain)
2067 if (b->secondary == b->subordinate)
2068 p += sprintf(p, "-[%04x:%02x]-", b->domain, b->secondary);
2070 p += sprintf(p, "-[%04x:%02x-%02x]-", b->domain, b->secondary, b->subordinate);
2071 show_tree_bridge(b, line, p);
2075 p += sprintf(p, " %s",
2076 pci_lookup_name(pacc, namebuf, sizeof(namebuf),
2077 PCI_LOOKUP_VENDOR | PCI_LOOKUP_DEVICE,
2078 q->vendor_id, q->device_id));
2083 show_tree_bus(struct bus *b, char*line, char *p)
2087 else if (!b->first_dev->next)
2091 show_tree_dev(b->first_dev, line, p);
2095 struct device *d = b->first_dev;
2100 show_tree_dev(d, line, p+2);
2105 show_tree_dev(d, line, p+2);
2110 show_tree_bridge(struct bridge *b, char *line, char *p)
2113 if (!b->first_bus->sibling)
2115 if (b == &host_bridge)
2116 p += sprintf(p, "[%04x:%02x]-", b->domain, b->first_bus->number);
2117 show_tree_bus(b->first_bus, line, p);
2121 struct bus *u = b->first_bus;
2126 k = p + sprintf(p, "+-[%04x:%02x]-", u->domain, u->number);
2127 show_tree_bus(u, line, k);
2130 k = p + sprintf(p, "\\-[%04x:%02x]-", u->domain, u->number);
2131 show_tree_bus(u, line, k);
2141 show_tree_bridge(&host_bridge, line, line);
2144 /* Bus mapping mode */
2147 struct bus_bridge *next;
2148 byte this, dev, func, first, last, bug;
2154 struct bus_bridge *bridges, *via;
2157 static struct bus_info *bus_info;
2160 map_bridge(struct bus_info *bi, struct device *d, int np, int ns, int nl)
2162 struct bus_bridge *b = xmalloc(sizeof(struct bus_bridge));
2163 struct pci_dev *p = d->dev;
2165 b->next = bi->bridges;
2167 b->this = get_conf_byte(d, np);
2170 b->first = get_conf_byte(d, ns);
2171 b->last = get_conf_byte(d, nl);
2172 printf("## %02x.%02x:%d is a bridge from %02x to %02x-%02x\n",
2173 p->bus, p->dev, p->func, b->this, b->first, b->last);
2174 if (b->this != p->bus)
2175 printf("!!! Bridge points to invalid primary bus.\n");
2176 if (b->first > b->last)
2178 printf("!!! Bridge points to invalid bus range.\n");
2187 int verbose = pacc->debugging;
2188 struct bus_info *bi = bus_info + bus;
2192 printf("Mapping bus %02x\n", bus);
2193 for(dev = 0; dev < 32; dev++)
2194 if (filter.slot < 0 || filter.slot == dev)
2197 for(func = 0; func < func_limit; func++)
2198 if (filter.func < 0 || filter.func == func)
2200 /* XXX: Bus mapping supports only domain 0 */
2201 struct pci_dev *p = pci_get_dev(pacc, 0, bus, dev, func);
2202 u16 vendor = pci_read_word(p, PCI_VENDOR_ID);
2203 if (vendor && vendor != 0xffff)
2205 if (!func && (pci_read_byte(p, PCI_HEADER_TYPE) & 0x80))
2208 printf("Discovered device %02x:%02x.%d\n", bus, dev, func);
2210 if (d = scan_device(p))
2213 switch (get_conf_byte(d, PCI_HEADER_TYPE) & 0x7f)
2215 case PCI_HEADER_TYPE_BRIDGE:
2216 map_bridge(bi, d, PCI_PRIMARY_BUS, PCI_SECONDARY_BUS, PCI_SUBORDINATE_BUS);
2218 case PCI_HEADER_TYPE_CARDBUS:
2219 map_bridge(bi, d, PCI_CB_PRIMARY_BUS, PCI_CB_CARD_BUS, PCI_CB_SUBORDINATE_BUS);
2225 printf("But it was filtered out.\n");
2233 do_map_bridges(int bus, int min, int max)
2235 struct bus_info *bi = bus_info + bus;
2236 struct bus_bridge *b;
2239 for(b=bi->bridges; b; b=b->next)
2241 if (bus_info[b->first].guestbook)
2243 else if (b->first < min || b->last > max)
2247 bus_info[b->first].via = b;
2248 do_map_bridges(b->first, b->first, b->last);
2258 printf("\nSummary of buses:\n\n");
2259 for(i=0; i<256; i++)
2260 if (bus_info[i].exists && !bus_info[i].guestbook)
2261 do_map_bridges(i, 0, 255);
2262 for(i=0; i<256; i++)
2264 struct bus_info *bi = bus_info + i;
2265 struct bus_bridge *b = bi->via;
2269 printf("%02x: ", i);
2271 printf("Entered via %02x:%02x.%d\n", b->this, b->dev, b->func);
2273 printf("Primary host bus\n");
2275 printf("Secondary host bus (?)\n");
2277 for(b=bi->bridges; b; b=b->next)
2279 printf("\t%02x.%d Bridge to %02x-%02x", b->dev, b->func, b->first, b->last);
2283 printf(" <overlap bug>");
2286 printf(" <crossing bug>");
2297 if (pacc->method == PCI_ACCESS_PROC_BUS_PCI ||
2298 pacc->method == PCI_ACCESS_DUMP)
2299 printf("WARNING: Bus mapping can be reliable only with direct hardware access enabled.\n\n");
2300 bus_info = xmalloc(sizeof(struct bus_info) * 256);
2301 bzero(bus_info, sizeof(struct bus_info) * 256);
2302 if (filter.bus >= 0)
2303 do_map_bus(filter.bus);
2307 for(bus=0; bus<256; bus++)
2316 main(int argc, char **argv)
2321 if (argc == 2 && !strcmp(argv[1], "--version"))
2323 puts("lspci version " PCIUTILS_VERSION);
2329 pci_filter_init(pacc, &filter);
2331 while ((i = getopt(argc, argv, options)) != -1)
2335 pacc->numeric_ids++;
2341 pacc->buscentric = 1;
2342 buscentric_view = 1;
2345 if (msg = pci_filter_parse_slot(&filter, optarg))
2349 if (msg = pci_filter_parse_id(&filter, optarg))
2359 pci_set_name_list_path(pacc, optarg, 0);
2371 if (parse_generic_option(i, pacc, optarg))
2374 fprintf(stderr, help_msg, pacc->id_file_name);