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 byte 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 byte * 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: 64bit%c Queue=%d/%d Enable%c\n",
995 FLAG(cap, PCI_MSI_FLAGS_64BIT),
996 (cap & PCI_MSI_FLAGS_QSIZE) >> 4,
997 (cap & PCI_MSI_FLAGS_QMASK) >> 1,
998 FLAG(cap, PCI_MSI_FLAGS_ENABLE));
1001 is64 = cap & PCI_MSI_FLAGS_64BIT;
1002 if (!config_fetch(d, where + PCI_MSI_ADDRESS_LO, (is64 ? PCI_MSI_DATA_64 : PCI_MSI_DATA_32) + 2 - PCI_MSI_ADDRESS_LO))
1004 printf("\t\tAddress: ");
1007 t = get_conf_long(d, where + PCI_MSI_ADDRESS_HI);
1008 w = get_conf_word(d, where + PCI_MSI_DATA_64);
1012 w = get_conf_word(d, where + PCI_MSI_DATA_32);
1013 t = get_conf_long(d, where + PCI_MSI_ADDRESS_LO);
1014 printf("%08x Data: %04x\n", t, w);
1017 static void show_vendor(void)
1019 printf("Vendor Specific Information\n");
1022 static void show_debug(void)
1024 printf("Debug port\n");
1027 static float power_limit(int value, int scale)
1029 static const float scales[4] = { 1.0, 0.1, 0.01, 0.001 };
1030 return value * scales[scale];
1033 static const char *latency_l0s(int value)
1035 static const char *latencies[] = { "<64ns", "<128ns", "<256ns", "<512ns", "<1us", "<2us", "<4us", "unlimited" };
1036 return latencies[value];
1039 static const char *latency_l1(int value)
1041 static const char *latencies[] = { "<1us", "<2us", "<4us", "<8us", "<16us", "<32us", "<64us", "unlimited" };
1042 return latencies[value];
1045 static void show_express_dev(struct device *d, int where, int type)
1050 t = get_conf_long(d, where + PCI_EXP_DEVCAP);
1051 printf("\t\tDevice: Supported: MaxPayload %d bytes, PhantFunc %d, ExtTag%c\n",
1052 128 << (t & PCI_EXP_DEVCAP_PAYLOAD),
1053 (1 << ((t & PCI_EXP_DEVCAP_PHANTOM) >> 3)) - 1,
1054 FLAG(t, PCI_EXP_DEVCAP_EXT_TAG));
1055 printf("\t\tDevice: Latency L0s %s, L1 %s\n",
1056 latency_l0s((t & PCI_EXP_DEVCAP_L0S) >> 6),
1057 latency_l1((t & PCI_EXP_DEVCAP_L1) >> 9));
1058 if ((type == PCI_EXP_TYPE_ENDPOINT) || (type == PCI_EXP_TYPE_LEG_END) ||
1059 (type == PCI_EXP_TYPE_UPSTREAM) || (type == PCI_EXP_TYPE_PCI_BRIDGE))
1060 printf("\t\tDevice: AtnBtn%c AtnInd%c PwrInd%c\n",
1061 FLAG(t, PCI_EXP_DEVCAP_ATN_BUT),
1062 FLAG(t, PCI_EXP_DEVCAP_ATN_IND), FLAG(t, PCI_EXP_DEVCAP_PWR_IND));
1063 if (type == PCI_EXP_TYPE_UPSTREAM)
1064 printf("\t\tDevice: SlotPowerLimit %f\n",
1065 power_limit((t & PCI_EXP_DEVCAP_PWR_VAL) >> 18,
1066 (t & PCI_EXP_DEVCAP_PWR_SCL) >> 26));
1068 w = get_conf_word(d, where + PCI_EXP_DEVCTL);
1069 printf("\t\tDevice: Errors: Correctable%c Non-Fatal%c Fatal%c Unsupported%c\n",
1070 FLAG(w, PCI_EXP_DEVCTL_CERE),
1071 FLAG(w, PCI_EXP_DEVCTL_NFERE),
1072 FLAG(w, PCI_EXP_DEVCTL_FERE),
1073 FLAG(w, PCI_EXP_DEVCTL_URRE));
1074 printf("\t\tDevice: RlxdOrd%c ExtTag%c PhantFunc%c AuxPwr%c NoSnoop%c\n",
1075 FLAG(w, PCI_EXP_DEVCTL_RELAXED),
1076 FLAG(w, PCI_EXP_DEVCTL_EXT_TAG),
1077 FLAG(w, PCI_EXP_DEVCTL_PHANTOM),
1078 FLAG(w, PCI_EXP_DEVCTL_AUX_PME),
1079 FLAG(w, PCI_EXP_DEVCTL_NOSNOOP));
1080 printf("\t\tDevice: MaxPayload %d bytes, MaxReadReq %d bytes\n",
1081 128 << ((w & PCI_EXP_DEVCTL_PAYLOAD) >> 5),
1082 128 << ((w & PCI_EXP_DEVCTL_READRQ) >> 12));
1085 static char *link_speed(int speed)
1096 static char *aspm_support(int code)
1109 static const char *aspm_enabled(int code)
1111 static const char *desc[] = { "Disabled", "L0s Enabled", "L1 Enabled", "L0s L1 Enabled" };
1115 static void show_express_link(struct device *d, int where, int type)
1120 t = get_conf_long(d, where + PCI_EXP_LNKCAP);
1121 printf("\t\tLink: Supported Speed %s, Width x%d, ASPM %s, Port %d\n",
1122 link_speed(t & PCI_EXP_LNKCAP_SPEED), (t & PCI_EXP_LNKCAP_WIDTH) >> 4,
1123 aspm_support((t & PCI_EXP_LNKCAP_ASPM) >> 10),
1125 printf("\t\tLink: Latency L0s %s, L1 %s\n",
1126 latency_l0s((t & PCI_EXP_LNKCAP_L0S) >> 12),
1127 latency_l1((t & PCI_EXP_LNKCAP_L1) >> 15));
1128 w = get_conf_word(d, where + PCI_EXP_LNKCTL);
1129 printf("\t\tLink: ASPM %s", aspm_enabled(w & PCI_EXP_LNKCTL_ASPM));
1130 if ((type == PCI_EXP_TYPE_ROOT_PORT) || (type == PCI_EXP_TYPE_ENDPOINT) ||
1131 (type == PCI_EXP_TYPE_LEG_END))
1132 printf(" RCB %d bytes", w & PCI_EXP_LNKCTL_RCB ? 128 : 64);
1133 if (w & PCI_EXP_LNKCTL_DISABLE)
1134 printf(" Disabled");
1135 printf(" CommClk%c ExtSynch%c\n", FLAG(w, PCI_EXP_LNKCTL_CLOCK),
1136 FLAG(w, PCI_EXP_LNKCTL_XSYNCH));
1137 w = get_conf_word(d, where + PCI_EXP_LNKSTA);
1138 printf("\t\tLink: Speed %s, Width x%d\n",
1139 link_speed(w & PCI_EXP_LNKSTA_SPEED), (w & PCI_EXP_LNKSTA_WIDTH) >> 4);
1142 static const char *indicator(int code)
1144 static const char *names[] = { "Unknown", "On", "Blink", "Off" };
1148 static void show_express_slot(struct device *d, int where)
1153 t = get_conf_long(d, where + PCI_EXP_SLTCAP);
1154 printf("\t\tSlot: AtnBtn%c PwrCtrl%c MRL%c AtnInd%c PwrInd%c HotPlug%c Surpise%c\n",
1155 FLAG(t, PCI_EXP_SLTCAP_ATNB),
1156 FLAG(t, PCI_EXP_SLTCAP_PWRC),
1157 FLAG(t, PCI_EXP_SLTCAP_MRL),
1158 FLAG(t, PCI_EXP_SLTCAP_ATNI),
1159 FLAG(t, PCI_EXP_SLTCAP_PWRI),
1160 FLAG(t, PCI_EXP_SLTCAP_HPC),
1161 FLAG(t, PCI_EXP_SLTCAP_HPS));
1162 printf("\t\tSlot: Number %d, PowerLimit %f\n", t >> 19,
1163 power_limit((t & PCI_EXP_SLTCAP_PWR_VAL) >> 7,
1164 (t & PCI_EXP_SLTCAP_PWR_SCL) >> 15));
1165 w = get_conf_word(d, where + PCI_EXP_SLTCTL);
1166 printf("\t\tSlot: Enabled AtnBtn%c PwrFlt%c MRL%c PresDet%c CmdCplt%c HPIrq%c\n",
1167 FLAG(w, PCI_EXP_SLTCTL_ATNB),
1168 FLAG(w, PCI_EXP_SLTCTL_PWRF),
1169 FLAG(w, PCI_EXP_SLTCTL_MRLS),
1170 FLAG(w, PCI_EXP_SLTCTL_PRSD),
1171 FLAG(w, PCI_EXP_SLTCTL_CMDC),
1172 FLAG(w, PCI_EXP_SLTCTL_HPIE));
1173 printf("\t\tSlot: AttnInd %s, PwrInd %s, Power%c\n",
1174 indicator((w & PCI_EXP_SLTCTL_ATNI) >> 6),
1175 indicator((w & PCI_EXP_SLTCTL_PWRI) >> 8),
1176 FLAG(w, w & PCI_EXP_SLTCTL_PWRC));
1179 static void show_express_root(struct device *d, int where)
1181 u16 w = get_conf_word(d, where + PCI_EXP_RTCTL);
1182 printf("\t\tRoot: Correctable%c Non-Fatal%c Fatal%c PME%c\n",
1183 FLAG(w, PCI_EXP_RTCTL_SECEE),
1184 FLAG(w, PCI_EXP_RTCTL_SENFEE),
1185 FLAG(w, PCI_EXP_RTCTL_SEFEE),
1186 FLAG(w, PCI_EXP_RTCTL_PMEIE));
1190 show_express(struct device *d, int where, int cap)
1192 int type = (cap & PCI_EXP_FLAGS_TYPE) >> 4;
1199 case PCI_EXP_TYPE_ENDPOINT:
1202 case PCI_EXP_TYPE_LEG_END:
1203 printf("Legacy Endpoint");
1205 case PCI_EXP_TYPE_ROOT_PORT:
1206 slot = cap & PCI_EXP_FLAGS_SLOT;
1207 printf("Root Port (Slot%c)", FLAG(cap, PCI_EXP_FLAGS_SLOT));
1209 case PCI_EXP_TYPE_UPSTREAM:
1210 printf("Upstream Port");
1212 case PCI_EXP_TYPE_DOWNSTREAM:
1213 slot = cap & PCI_EXP_FLAGS_SLOT;
1214 printf("Downstream Port (Slot%c)", FLAG(cap, PCI_EXP_FLAGS_SLOT));
1216 case PCI_EXP_TYPE_PCI_BRIDGE:
1217 printf("PCI/PCI-X Bridge");
1220 printf("Unknown type");
1222 printf(" IRQ %d\n", (cap & PCI_EXP_FLAGS_IRQ) >> 9);
1229 if (type == PCI_EXP_TYPE_ROOT_PORT)
1231 if (!config_fetch(d, where + PCI_EXP_DEVCAP, size))
1234 show_express_dev(d, where, type);
1235 show_express_link(d, where, type);
1237 show_express_slot(d, where);
1238 if (type == PCI_EXP_TYPE_ROOT_PORT)
1239 show_express_root(d, where);
1243 show_msix(struct device *d, int where, int cap)
1247 printf("MSI-X: Enable%c Mask%c TabSize=%d\n",
1248 FLAG(cap, PCI_MSIX_ENABLE),
1249 FLAG(cap, PCI_MSIX_MASK),
1250 (cap & PCI_MSIX_TABSIZE) + 1);
1251 if (verbose < 2 || !config_fetch(d, where + PCI_MSIX_TABLE, 8))
1254 off = get_conf_long(d, where + PCI_MSIX_TABLE);
1255 printf("\t\tVector table: BAR=%d offset=%08x\n",
1256 off & PCI_MSIX_BIR, off & ~PCI_MSIX_BIR);
1257 off = get_conf_long(d, where + PCI_MSIX_PBA);
1258 printf("\t\tPBA: BAR=%d offset=%08x\n",
1259 off & PCI_MSIX_BIR, off & ~PCI_MSIX_BIR);
1263 show_slotid(int cap)
1265 int esr = cap & 0xff;
1268 printf("Slot ID: %d slots, First%c, chassis %02x\n",
1269 esr & PCI_SID_ESR_NSLOTS,
1270 FLAG(esr, PCI_SID_ESR_FIC),
1275 show_aer(struct device *d UNUSED, int where UNUSED)
1277 printf("Advanced Error Reporting\n");
1281 show_vc(struct device *d UNUSED, int where UNUSED)
1283 printf("Virtual Channel\n");
1287 show_dsn(struct device *d, int where)
1290 if (!config_fetch(d, where + 4, 8))
1292 t1 = get_conf_long(d, where + 4);
1293 t2 = get_conf_long(d, where + 8);
1294 printf("Device Serial Number %02x-%02x-%02x-%02x-%02x-%02x-%02x-%02x\n",
1295 t1 & 0xff, (t1 >> 8) & 0xff, (t1 >> 16) & 0xff, t1 >> 24,
1296 t2 & 0xff, (t2 >> 8) & 0xff, (t2 >> 16) & 0xff, t2 >> 24);
1300 show_pb(struct device *d UNUSED, int where UNUSED)
1302 printf("Power Budgeting\n");
1306 show_ext_caps(struct device *d)
1314 if (!config_fetch(d, where, 4))
1316 header = get_conf_long(d, where);
1319 id = header & 0xffff;
1320 printf("\tCapabilities: [%03x] ", where);
1323 case PCI_EXT_CAP_ID_AER:
1326 case PCI_EXT_CAP_ID_VC:
1329 case PCI_EXT_CAP_ID_DSN:
1332 case PCI_EXT_CAP_ID_PB:
1336 printf("Unknown (%d)\n", id);
1339 where = header >> 20;
1344 show_caps(struct device *d)
1346 int can_have_ext_caps = 0;
1348 if (get_conf_word(d, PCI_STATUS) & PCI_STATUS_CAP_LIST)
1350 int where = get_conf_byte(d, PCI_CAPABILITY_LIST) & ~3;
1354 printf("\tCapabilities: ");
1355 if (!config_fetch(d, where, 4))
1357 puts("<access denied>");
1360 id = get_conf_byte(d, where + PCI_CAP_LIST_ID);
1361 next = get_conf_byte(d, where + PCI_CAP_LIST_NEXT) & ~3;
1362 cap = get_conf_word(d, where + PCI_CAP_FLAGS);
1363 printf("[%02x] ", where);
1366 printf("<chain broken>\n");
1372 show_pm(d, where, cap);
1374 case PCI_CAP_ID_AGP:
1375 show_agp(d, where, cap);
1377 case PCI_CAP_ID_VPD:
1378 printf("Vital Product Data\n");
1380 case PCI_CAP_ID_SLOTID:
1383 case PCI_CAP_ID_MSI:
1384 show_msi(d, where, cap);
1386 case PCI_CAP_ID_PCIX:
1387 show_pcix(d, where);
1388 can_have_ext_caps = 1;
1391 show_ht(d, where, cap);
1393 case PCI_CAP_ID_VNDR:
1396 case PCI_CAP_ID_DBG:
1399 case PCI_CAP_ID_EXP:
1400 show_express(d, where, cap);
1401 can_have_ext_caps = 1;
1403 case PCI_CAP_ID_MSIX:
1404 show_msix(d, where, cap);
1407 printf("#%02x [%04x]\n", id, cap);
1412 if (can_have_ext_caps)
1417 show_htype0(struct device *d)
1420 show_rom(d, PCI_ROM_ADDRESS);
1425 show_htype1(struct device *d)
1427 u32 io_base = get_conf_byte(d, PCI_IO_BASE);
1428 u32 io_limit = get_conf_byte(d, PCI_IO_LIMIT);
1429 u32 io_type = io_base & PCI_IO_RANGE_TYPE_MASK;
1430 u32 mem_base = get_conf_word(d, PCI_MEMORY_BASE);
1431 u32 mem_limit = get_conf_word(d, PCI_MEMORY_LIMIT);
1432 u32 mem_type = mem_base & PCI_MEMORY_RANGE_TYPE_MASK;
1433 u32 pref_base = get_conf_word(d, PCI_PREF_MEMORY_BASE);
1434 u32 pref_limit = get_conf_word(d, PCI_PREF_MEMORY_LIMIT);
1435 u32 pref_type = pref_base & PCI_PREF_RANGE_TYPE_MASK;
1436 word sec_stat = get_conf_word(d, PCI_SEC_STATUS);
1437 word brc = get_conf_word(d, PCI_BRIDGE_CONTROL);
1438 int verb = verbose > 2;
1441 printf("\tBus: primary=%02x, secondary=%02x, subordinate=%02x, sec-latency=%d\n",
1442 get_conf_byte(d, PCI_PRIMARY_BUS),
1443 get_conf_byte(d, PCI_SECONDARY_BUS),
1444 get_conf_byte(d, PCI_SUBORDINATE_BUS),
1445 get_conf_byte(d, PCI_SEC_LATENCY_TIMER));
1447 if (io_type != (io_limit & PCI_IO_RANGE_TYPE_MASK) ||
1448 (io_type != PCI_IO_RANGE_TYPE_16 && io_type != PCI_IO_RANGE_TYPE_32))
1449 printf("\t!!! Unknown I/O range types %x/%x\n", io_base, io_limit);
1452 io_base = (io_base & PCI_IO_RANGE_MASK) << 8;
1453 io_limit = (io_limit & PCI_IO_RANGE_MASK) << 8;
1454 if (io_type == PCI_IO_RANGE_TYPE_32)
1456 io_base |= (get_conf_word(d, PCI_IO_BASE_UPPER16) << 16);
1457 io_limit |= (get_conf_word(d, PCI_IO_LIMIT_UPPER16) << 16);
1459 if (io_base <= io_limit || verb)
1460 printf("\tI/O behind bridge: %08x-%08x\n", io_base, io_limit+0xfff);
1463 if (mem_type != (mem_limit & PCI_MEMORY_RANGE_TYPE_MASK) ||
1465 printf("\t!!! Unknown memory range types %x/%x\n", mem_base, mem_limit);
1468 mem_base = (mem_base & PCI_MEMORY_RANGE_MASK) << 16;
1469 mem_limit = (mem_limit & PCI_MEMORY_RANGE_MASK) << 16;
1470 if (mem_base <= mem_limit || verb)
1471 printf("\tMemory behind bridge: %08x-%08x\n", mem_base, mem_limit + 0xfffff);
1474 if (pref_type != (pref_limit & PCI_PREF_RANGE_TYPE_MASK) ||
1475 (pref_type != PCI_PREF_RANGE_TYPE_32 && pref_type != PCI_PREF_RANGE_TYPE_64))
1476 printf("\t!!! Unknown prefetchable memory range types %x/%x\n", pref_base, pref_limit);
1479 pref_base = (pref_base & PCI_PREF_RANGE_MASK) << 16;
1480 pref_limit = (pref_limit & PCI_PREF_RANGE_MASK) << 16;
1481 if (pref_base <= pref_limit || verb)
1483 if (pref_type == PCI_PREF_RANGE_TYPE_32)
1484 printf("\tPrefetchable memory behind bridge: %08x-%08x\n", pref_base, pref_limit + 0xfffff);
1486 printf("\tPrefetchable memory behind bridge: %08x%08x-%08x%08x\n",
1487 get_conf_long(d, PCI_PREF_BASE_UPPER32),
1489 get_conf_long(d, PCI_PREF_LIMIT_UPPER32),
1495 printf("\tSecondary status: 66MHz%c FastB2B%c ParErr%c DEVSEL=%s >TAbort%c <TAbort%c <MAbort%c <SERR%c <PERR%c\n",
1496 FLAG(sec_stat, PCI_STATUS_66MHZ),
1497 FLAG(sec_stat, PCI_STATUS_FAST_BACK),
1498 FLAG(sec_stat, PCI_STATUS_PARITY),
1499 ((sec_stat & PCI_STATUS_DEVSEL_MASK) == PCI_STATUS_DEVSEL_SLOW) ? "slow" :
1500 ((sec_stat & PCI_STATUS_DEVSEL_MASK) == PCI_STATUS_DEVSEL_MEDIUM) ? "medium" :
1501 ((sec_stat & PCI_STATUS_DEVSEL_MASK) == PCI_STATUS_DEVSEL_FAST) ? "fast" : "??",
1502 FLAG(sec_stat, PCI_STATUS_SIG_TARGET_ABORT),
1503 FLAG(sec_stat, PCI_STATUS_REC_TARGET_ABORT),
1504 FLAG(sec_stat, PCI_STATUS_REC_MASTER_ABORT),
1505 FLAG(sec_stat, PCI_STATUS_SIG_SYSTEM_ERROR),
1506 FLAG(sec_stat, PCI_STATUS_DETECTED_PARITY));
1508 show_rom(d, PCI_ROM_ADDRESS1);
1511 printf("\tBridgeCtl: Parity%c SERR%c NoISA%c VGA%c MAbort%c >Reset%c FastB2B%c\n",
1512 FLAG(brc, PCI_BRIDGE_CTL_PARITY),
1513 FLAG(brc, PCI_BRIDGE_CTL_SERR),
1514 FLAG(brc, PCI_BRIDGE_CTL_NO_ISA),
1515 FLAG(brc, PCI_BRIDGE_CTL_VGA),
1516 FLAG(brc, PCI_BRIDGE_CTL_MASTER_ABORT),
1517 FLAG(brc, PCI_BRIDGE_CTL_BUS_RESET),
1518 FLAG(brc, PCI_BRIDGE_CTL_FAST_BACK));
1524 show_htype2(struct device *d)
1527 word cmd = get_conf_word(d, PCI_COMMAND);
1528 word brc = get_conf_word(d, PCI_CB_BRIDGE_CONTROL);
1530 int verb = verbose > 2;
1533 printf("\tBus: primary=%02x, secondary=%02x, subordinate=%02x, sec-latency=%d\n",
1534 get_conf_byte(d, PCI_CB_PRIMARY_BUS),
1535 get_conf_byte(d, PCI_CB_CARD_BUS),
1536 get_conf_byte(d, PCI_CB_SUBORDINATE_BUS),
1537 get_conf_byte(d, PCI_CB_LATENCY_TIMER));
1541 u32 base = get_conf_long(d, PCI_CB_MEMORY_BASE_0 + p);
1542 u32 limit = get_conf_long(d, PCI_CB_MEMORY_LIMIT_0 + p);
1543 if (limit > base || verb)
1544 printf("\tMemory window %d: %08x-%08x%s%s\n", i, base, limit,
1545 (cmd & PCI_COMMAND_MEMORY) ? "" : " [disabled]",
1546 (brc & (PCI_CB_BRIDGE_CTL_PREFETCH_MEM0 << i)) ? " (prefetchable)" : "");
1551 u32 base = get_conf_long(d, PCI_CB_IO_BASE_0 + p);
1552 u32 limit = get_conf_long(d, PCI_CB_IO_LIMIT_0 + p);
1553 if (!(base & PCI_IO_RANGE_TYPE_32))
1558 base &= PCI_CB_IO_RANGE_MASK;
1559 limit = (limit & PCI_CB_IO_RANGE_MASK) + 3;
1560 if (base <= limit || verb)
1561 printf("\tI/O window %d: %08x-%08x%s\n", i, base, limit,
1562 (cmd & PCI_COMMAND_IO) ? "" : " [disabled]");
1565 if (get_conf_word(d, PCI_CB_SEC_STATUS) & PCI_STATUS_SIG_SYSTEM_ERROR)
1566 printf("\tSecondary status: SERR\n");
1568 printf("\tBridgeCtl: Parity%c SERR%c ISA%c VGA%c MAbort%c >Reset%c 16bInt%c PostWrite%c\n",
1569 FLAG(brc, PCI_CB_BRIDGE_CTL_PARITY),
1570 FLAG(brc, PCI_CB_BRIDGE_CTL_SERR),
1571 FLAG(brc, PCI_CB_BRIDGE_CTL_ISA),
1572 FLAG(brc, PCI_CB_BRIDGE_CTL_VGA),
1573 FLAG(brc, PCI_CB_BRIDGE_CTL_MASTER_ABORT),
1574 FLAG(brc, PCI_CB_BRIDGE_CTL_CB_RESET),
1575 FLAG(brc, PCI_CB_BRIDGE_CTL_16BIT_INT),
1576 FLAG(brc, PCI_CB_BRIDGE_CTL_POST_WRITES));
1578 if (d->config_cached < 128)
1580 printf("\t<access denied to the rest>\n");
1584 exca = get_conf_word(d, PCI_CB_LEGACY_MODE_BASE);
1586 printf("\t16-bit legacy interface ports at %04x\n", exca);
1590 show_verbose(struct device *d)
1592 struct pci_dev *p = d->dev;
1593 word status = get_conf_word(d, PCI_STATUS);
1594 word cmd = get_conf_word(d, PCI_COMMAND);
1595 word class = p->device_class;
1596 byte bist = get_conf_byte(d, PCI_BIST);
1597 byte htype = get_conf_byte(d, PCI_HEADER_TYPE) & 0x7f;
1598 byte latency = get_conf_byte(d, PCI_LATENCY_TIMER);
1599 byte cache_line = get_conf_byte(d, PCI_CACHE_LINE_SIZE);
1600 byte max_lat, min_gnt;
1601 byte int_pin = get_conf_byte(d, PCI_INTERRUPT_PIN);
1602 unsigned int irq = p->irq;
1603 word subsys_v = 0, subsys_d = 0;
1604 char ssnamebuf[256];
1610 case PCI_HEADER_TYPE_NORMAL:
1611 if (class == PCI_CLASS_BRIDGE_PCI)
1612 printf("\t!!! Invalid class %04x for header type %02x\n", class, htype);
1613 max_lat = get_conf_byte(d, PCI_MAX_LAT);
1614 min_gnt = get_conf_byte(d, PCI_MIN_GNT);
1615 subsys_v = get_conf_word(d, PCI_SUBSYSTEM_VENDOR_ID);
1616 subsys_d = get_conf_word(d, PCI_SUBSYSTEM_ID);
1618 case PCI_HEADER_TYPE_BRIDGE:
1619 if ((class >> 8) != PCI_BASE_CLASS_BRIDGE)
1620 printf("\t!!! Invalid class %04x for header type %02x\n", class, htype);
1621 irq = int_pin = min_gnt = max_lat = 0;
1623 case PCI_HEADER_TYPE_CARDBUS:
1624 if ((class >> 8) != PCI_BASE_CLASS_BRIDGE)
1625 printf("\t!!! Invalid class %04x for header type %02x\n", class, htype);
1626 min_gnt = max_lat = 0;
1627 if (d->config_cached >= 128)
1629 subsys_v = get_conf_word(d, PCI_CB_SUBSYSTEM_VENDOR_ID);
1630 subsys_d = get_conf_word(d, PCI_CB_SUBSYSTEM_ID);
1634 printf("\t!!! Unknown header type %02x\n", htype);
1638 if (subsys_v && subsys_v != 0xffff)
1639 printf("\tSubsystem: %s\n",
1640 pci_lookup_name(pacc, ssnamebuf, sizeof(ssnamebuf),
1641 PCI_LOOKUP_SUBSYSTEM | PCI_LOOKUP_VENDOR | PCI_LOOKUP_DEVICE,
1642 p->vendor_id, p->device_id, subsys_v, subsys_d));
1646 printf("\tControl: I/O%c Mem%c BusMaster%c SpecCycle%c MemWINV%c VGASnoop%c ParErr%c Stepping%c SERR%c FastB2B%c\n",
1647 FLAG(cmd, PCI_COMMAND_IO),
1648 FLAG(cmd, PCI_COMMAND_MEMORY),
1649 FLAG(cmd, PCI_COMMAND_MASTER),
1650 FLAG(cmd, PCI_COMMAND_SPECIAL),
1651 FLAG(cmd, PCI_COMMAND_INVALIDATE),
1652 FLAG(cmd, PCI_COMMAND_VGA_PALETTE),
1653 FLAG(cmd, PCI_COMMAND_PARITY),
1654 FLAG(cmd, PCI_COMMAND_WAIT),
1655 FLAG(cmd, PCI_COMMAND_SERR),
1656 FLAG(cmd, PCI_COMMAND_FAST_BACK));
1657 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",
1658 FLAG(status, PCI_STATUS_CAP_LIST),
1659 FLAG(status, PCI_STATUS_66MHZ),
1660 FLAG(status, PCI_STATUS_UDF),
1661 FLAG(status, PCI_STATUS_FAST_BACK),
1662 FLAG(status, PCI_STATUS_PARITY),
1663 ((status & PCI_STATUS_DEVSEL_MASK) == PCI_STATUS_DEVSEL_SLOW) ? "slow" :
1664 ((status & PCI_STATUS_DEVSEL_MASK) == PCI_STATUS_DEVSEL_MEDIUM) ? "medium" :
1665 ((status & PCI_STATUS_DEVSEL_MASK) == PCI_STATUS_DEVSEL_FAST) ? "fast" : "??",
1666 FLAG(status, PCI_STATUS_SIG_TARGET_ABORT),
1667 FLAG(status, PCI_STATUS_REC_TARGET_ABORT),
1668 FLAG(status, PCI_STATUS_REC_MASTER_ABORT),
1669 FLAG(status, PCI_STATUS_SIG_SYSTEM_ERROR),
1670 FLAG(status, PCI_STATUS_DETECTED_PARITY));
1671 if (cmd & PCI_COMMAND_MASTER)
1673 printf("\tLatency: %d", latency);
1674 if (min_gnt || max_lat)
1678 printf("%dns min", min_gnt*250);
1679 if (min_gnt && max_lat)
1682 printf("%dns max", max_lat*250);
1686 printf(", Cache Line Size: %d bytes", cache_line * 4);
1690 printf("\tInterrupt: pin %c routed to IRQ " PCIIRQ_FMT "\n",
1691 (int_pin ? 'A' + int_pin - 1 : '?'), irq);
1695 printf("\tFlags: ");
1696 if (cmd & PCI_COMMAND_MASTER)
1697 printf("bus master, ");
1698 if (cmd & PCI_COMMAND_VGA_PALETTE)
1699 printf("VGA palette snoop, ");
1700 if (cmd & PCI_COMMAND_WAIT)
1701 printf("stepping, ");
1702 if (cmd & PCI_COMMAND_FAST_BACK)
1703 printf("fast Back2Back, ");
1704 if (status & PCI_STATUS_66MHZ)
1706 if (status & PCI_STATUS_UDF)
1707 printf("user-definable features, ");
1709 ((status & PCI_STATUS_DEVSEL_MASK) == PCI_STATUS_DEVSEL_SLOW) ? "slow" :
1710 ((status & PCI_STATUS_DEVSEL_MASK) == PCI_STATUS_DEVSEL_MEDIUM) ? "medium" :
1711 ((status & PCI_STATUS_DEVSEL_MASK) == PCI_STATUS_DEVSEL_FAST) ? "fast" : "??");
1712 if (cmd & PCI_COMMAND_MASTER)
1713 printf(", latency %d", latency);
1715 printf(", IRQ " PCIIRQ_FMT, irq);
1719 if (bist & PCI_BIST_CAPABLE)
1721 if (bist & PCI_BIST_START)
1722 printf("\tBIST is running\n");
1724 printf("\tBIST result: %02x\n", bist & PCI_BIST_CODE_MASK);
1729 case PCI_HEADER_TYPE_NORMAL:
1732 case PCI_HEADER_TYPE_BRIDGE:
1735 case PCI_HEADER_TYPE_CARDBUS:
1742 show_hex_dump(struct device *d)
1744 unsigned int i, cnt;
1746 cnt = d->config_cached;
1747 if (show_hex >= 3 && config_fetch(d, cnt, 256-cnt))
1750 if (show_hex >= 4 && config_fetch(d, 256, 4096-256))
1754 for(i=0; i<cnt; i++)
1758 printf(" %02x", get_conf_byte(d, i));
1765 show_machine(struct device *d)
1767 struct pci_dev *p = d->dev;
1769 word sv_id=0, sd_id=0;
1770 char classbuf[128], vendbuf[128], devbuf[128], svbuf[128], sdbuf[128];
1772 switch (get_conf_byte(d, PCI_HEADER_TYPE) & 0x7f)
1774 case PCI_HEADER_TYPE_NORMAL:
1775 sv_id = get_conf_word(d, PCI_SUBSYSTEM_VENDOR_ID);
1776 sd_id = get_conf_word(d, PCI_SUBSYSTEM_ID);
1778 case PCI_HEADER_TYPE_CARDBUS:
1779 if (d->config_cached >= 128)
1781 sv_id = get_conf_word(d, PCI_CB_SUBSYSTEM_VENDOR_ID);
1782 sd_id = get_conf_word(d, PCI_CB_SUBSYSTEM_ID);
1789 printf("Device:\t");
1792 printf("Class:\t%s\n",
1793 pci_lookup_name(pacc, classbuf, sizeof(classbuf), PCI_LOOKUP_CLASS, p->device_class));
1794 printf("Vendor:\t%s\n",
1795 pci_lookup_name(pacc, vendbuf, sizeof(vendbuf), PCI_LOOKUP_VENDOR, p->vendor_id, p->device_id));
1796 printf("Device:\t%s\n",
1797 pci_lookup_name(pacc, devbuf, sizeof(devbuf), PCI_LOOKUP_DEVICE, p->vendor_id, p->device_id));
1798 if (sv_id && sv_id != 0xffff)
1800 printf("SVendor:\t%s\n",
1801 pci_lookup_name(pacc, svbuf, sizeof(svbuf), PCI_LOOKUP_SUBSYSTEM | PCI_LOOKUP_VENDOR, sv_id));
1802 printf("SDevice:\t%s\n",
1803 pci_lookup_name(pacc, sdbuf, sizeof(sdbuf), PCI_LOOKUP_SUBSYSTEM | PCI_LOOKUP_DEVICE, p->vendor_id, p->device_id, sv_id, sd_id));
1805 if (c = get_conf_byte(d, PCI_REVISION_ID))
1806 printf("Rev:\t%02x\n", c);
1807 if (c = get_conf_byte(d, PCI_CLASS_PROG))
1808 printf("ProgIf:\t%02x\n", c);
1813 printf(" \"%s\" \"%s\" \"%s\"",
1814 pci_lookup_name(pacc, classbuf, sizeof(classbuf), PCI_LOOKUP_CLASS,
1816 pci_lookup_name(pacc, vendbuf, sizeof(vendbuf), PCI_LOOKUP_VENDOR,
1817 p->vendor_id, p->device_id),
1818 pci_lookup_name(pacc, devbuf, sizeof(devbuf), PCI_LOOKUP_DEVICE,
1819 p->vendor_id, p->device_id));
1820 if (c = get_conf_byte(d, PCI_REVISION_ID))
1821 printf(" -r%02x", c);
1822 if (c = get_conf_byte(d, PCI_CLASS_PROG))
1823 printf(" -p%02x", c);
1824 if (sv_id && sv_id != 0xffff)
1825 printf(" \"%s\" \"%s\"",
1826 pci_lookup_name(pacc, svbuf, sizeof(svbuf), PCI_LOOKUP_SUBSYSTEM | PCI_LOOKUP_VENDOR, sv_id),
1827 pci_lookup_name(pacc, sdbuf, sizeof(sdbuf), PCI_LOOKUP_SUBSYSTEM | PCI_LOOKUP_DEVICE, p->vendor_id, p->device_id, sv_id, sd_id));
1829 printf(" \"\" \"\"");
1835 show_device(struct device *d)
1837 if (machine_readable)
1845 if (verbose || show_hex)
1854 for(d=first_dev; d; d=d->next)
1861 struct bridge *chain; /* Single-linked list of bridges */
1862 struct bridge *next, *child; /* Tree of bridges */
1863 struct bus *first_bus; /* List of buses connected to this bridge */
1864 unsigned int domain;
1865 unsigned int primary, secondary, subordinate; /* Bus numbers */
1866 struct device *br_dev;
1870 unsigned int domain;
1871 unsigned int number;
1872 struct bus *sibling;
1873 struct device *first_dev, **last_dev;
1876 static struct bridge host_bridge = { NULL, NULL, NULL, NULL, 0, ~0, 0, ~0, NULL };
1879 find_bus(struct bridge *b, unsigned int domain, unsigned int n)
1883 for(bus=b->first_bus; bus; bus=bus->sibling)
1884 if (bus->domain == domain && bus->number == n)
1890 new_bus(struct bridge *b, unsigned int domain, unsigned int n)
1892 struct bus *bus = xmalloc(sizeof(struct bus));
1893 bus->domain = domain;
1895 bus->sibling = b->first_bus;
1896 bus->first_dev = NULL;
1897 bus->last_dev = &bus->first_dev;
1903 insert_dev(struct device *d, struct bridge *b)
1905 struct pci_dev *p = d->dev;
1908 if (! (bus = find_bus(b, p->domain, p->bus)))
1911 for(c=b->child; c; c=c->next)
1912 if (c->domain == p->domain && c->secondary <= p->bus && p->bus <= c->subordinate)
1917 bus = new_bus(b, p->domain, p->bus);
1919 /* Simple insertion at the end _does_ guarantee the correct order as the
1920 * original device list was sorted by (domain, bus, devfn) lexicographically
1921 * and all devices on the new list have the same bus number.
1924 bus->last_dev = &d->next;
1931 struct device *d, *d2;
1932 struct bridge **last_br, *b;
1934 /* Build list of bridges */
1936 last_br = &host_bridge.chain;
1937 for(d=first_dev; d; d=d->next)
1939 word class = d->dev->device_class;
1940 byte ht = get_conf_byte(d, PCI_HEADER_TYPE) & 0x7f;
1941 if (class == PCI_CLASS_BRIDGE_PCI &&
1942 (ht == PCI_HEADER_TYPE_BRIDGE || ht == PCI_HEADER_TYPE_CARDBUS))
1944 b = xmalloc(sizeof(struct bridge));
1945 b->domain = d->dev->domain;
1946 if (ht == PCI_HEADER_TYPE_BRIDGE)
1948 b->primary = get_conf_byte(d, PCI_CB_PRIMARY_BUS);
1949 b->secondary = get_conf_byte(d, PCI_CB_CARD_BUS);
1950 b->subordinate = get_conf_byte(d, PCI_CB_SUBORDINATE_BUS);
1954 b->primary = get_conf_byte(d, PCI_PRIMARY_BUS);
1955 b->secondary = get_conf_byte(d, PCI_SECONDARY_BUS);
1956 b->subordinate = get_conf_byte(d, PCI_SUBORDINATE_BUS);
1959 last_br = &b->chain;
1960 b->next = b->child = NULL;
1961 b->first_bus = NULL;
1967 /* Create a bridge tree */
1969 for(b=&host_bridge; b; b=b->chain)
1971 struct bridge *c, *best;
1973 for(c=&host_bridge; c; c=c->chain)
1974 if (c != b && (c == &host_bridge || b->domain == c->domain) &&
1975 b->primary >= c->secondary && b->primary <= c->subordinate &&
1976 (!best || best->subordinate - best->primary > c->subordinate - c->primary))
1980 b->next = best->child;
1985 /* Insert secondary bus for each bridge */
1987 for(b=&host_bridge; b; b=b->chain)
1988 if (!find_bus(b, b->domain, b->secondary))
1989 new_bus(b, b->domain, b->secondary);
1991 /* Create bus structs and link devices */
1993 for(d=first_dev; d;)
1996 insert_dev(d, &host_bridge);
2002 print_it(byte *line, byte *p)
2006 fputs(line, stdout);
2007 for(p=line; *p; p++)
2008 if (*p == '+' || *p == '|')
2014 static void show_tree_bridge(struct bridge *, byte *, byte *);
2017 show_tree_dev(struct device *d, byte *line, byte *p)
2019 struct pci_dev *q = d->dev;
2023 p += sprintf(p, "%02x.%x", q->dev, q->func);
2024 for(b=&host_bridge; b; b=b->chain)
2027 if (b->secondary == b->subordinate)
2028 p += sprintf(p, "-[%04x:%02x]-", b->domain, b->secondary);
2030 p += sprintf(p, "-[%04x:%02x-%02x]-", b->domain, b->secondary, b->subordinate);
2031 show_tree_bridge(b, line, p);
2035 p += sprintf(p, " %s",
2036 pci_lookup_name(pacc, namebuf, sizeof(namebuf),
2037 PCI_LOOKUP_VENDOR | PCI_LOOKUP_DEVICE,
2038 q->vendor_id, q->device_id));
2043 show_tree_bus(struct bus *b, byte *line, byte *p)
2047 else if (!b->first_dev->next)
2051 show_tree_dev(b->first_dev, line, p);
2055 struct device *d = b->first_dev;
2060 show_tree_dev(d, line, p+2);
2065 show_tree_dev(d, line, p+2);
2070 show_tree_bridge(struct bridge *b, byte *line, byte *p)
2073 if (!b->first_bus->sibling)
2075 if (b == &host_bridge)
2076 p += sprintf(p, "[%04x:%02x]-", b->domain, b->first_bus->number);
2077 show_tree_bus(b->first_bus, line, p);
2081 struct bus *u = b->first_bus;
2086 k = p + sprintf(p, "+-[%04x:%02x]-", u->domain, u->number);
2087 show_tree_bus(u, line, k);
2090 k = p + sprintf(p, "\\-[%04x:%02x]-", u->domain, u->number);
2091 show_tree_bus(u, line, k);
2101 show_tree_bridge(&host_bridge, line, line);
2104 /* Bus mapping mode */
2107 struct bus_bridge *next;
2108 byte this, dev, func, first, last, bug;
2114 struct bus_bridge *bridges, *via;
2117 static struct bus_info *bus_info;
2120 map_bridge(struct bus_info *bi, struct device *d, int np, int ns, int nl)
2122 struct bus_bridge *b = xmalloc(sizeof(struct bus_bridge));
2123 struct pci_dev *p = d->dev;
2125 b->next = bi->bridges;
2127 b->this = get_conf_byte(d, np);
2130 b->first = get_conf_byte(d, ns);
2131 b->last = get_conf_byte(d, nl);
2132 printf("## %02x.%02x:%d is a bridge from %02x to %02x-%02x\n",
2133 p->bus, p->dev, p->func, b->this, b->first, b->last);
2134 if (b->this != p->bus)
2135 printf("!!! Bridge points to invalid primary bus.\n");
2136 if (b->first > b->last)
2138 printf("!!! Bridge points to invalid bus range.\n");
2147 int verbose = pacc->debugging;
2148 struct bus_info *bi = bus_info + bus;
2152 printf("Mapping bus %02x\n", bus);
2153 for(dev = 0; dev < 32; dev++)
2154 if (filter.slot < 0 || filter.slot == dev)
2157 for(func = 0; func < func_limit; func++)
2158 if (filter.func < 0 || filter.func == func)
2160 /* XXX: Bus mapping supports only domain 0 */
2161 struct pci_dev *p = pci_get_dev(pacc, 0, bus, dev, func);
2162 u16 vendor = pci_read_word(p, PCI_VENDOR_ID);
2163 if (vendor && vendor != 0xffff)
2165 if (!func && (pci_read_byte(p, PCI_HEADER_TYPE) & 0x80))
2168 printf("Discovered device %02x:%02x.%d\n", bus, dev, func);
2170 if (d = scan_device(p))
2173 switch (get_conf_byte(d, PCI_HEADER_TYPE) & 0x7f)
2175 case PCI_HEADER_TYPE_BRIDGE:
2176 map_bridge(bi, d, PCI_PRIMARY_BUS, PCI_SECONDARY_BUS, PCI_SUBORDINATE_BUS);
2178 case PCI_HEADER_TYPE_CARDBUS:
2179 map_bridge(bi, d, PCI_CB_PRIMARY_BUS, PCI_CB_CARD_BUS, PCI_CB_SUBORDINATE_BUS);
2185 printf("But it was filtered out.\n");
2193 do_map_bridges(int bus, int min, int max)
2195 struct bus_info *bi = bus_info + bus;
2196 struct bus_bridge *b;
2199 for(b=bi->bridges; b; b=b->next)
2201 if (bus_info[b->first].guestbook)
2203 else if (b->first < min || b->last > max)
2207 bus_info[b->first].via = b;
2208 do_map_bridges(b->first, b->first, b->last);
2218 printf("\nSummary of buses:\n\n");
2219 for(i=0; i<256; i++)
2220 if (bus_info[i].exists && !bus_info[i].guestbook)
2221 do_map_bridges(i, 0, 255);
2222 for(i=0; i<256; i++)
2224 struct bus_info *bi = bus_info + i;
2225 struct bus_bridge *b = bi->via;
2229 printf("%02x: ", i);
2231 printf("Entered via %02x:%02x.%d\n", b->this, b->dev, b->func);
2233 printf("Primary host bus\n");
2235 printf("Secondary host bus (?)\n");
2237 for(b=bi->bridges; b; b=b->next)
2239 printf("\t%02x.%d Bridge to %02x-%02x", b->dev, b->func, b->first, b->last);
2243 printf(" <overlap bug>");
2246 printf(" <crossing bug>");
2257 if (pacc->method == PCI_ACCESS_PROC_BUS_PCI ||
2258 pacc->method == PCI_ACCESS_DUMP)
2259 printf("WARNING: Bus mapping can be reliable only with direct hardware access enabled.\n\n");
2260 bus_info = xmalloc(sizeof(struct bus_info) * 256);
2261 bzero(bus_info, sizeof(struct bus_info) * 256);
2262 if (filter.bus >= 0)
2263 do_map_bus(filter.bus);
2267 for(bus=0; bus<256; bus++)
2276 main(int argc, char **argv)
2281 if (argc == 2 && !strcmp(argv[1], "--version"))
2283 puts("lspci version " PCIUTILS_VERSION);
2289 pci_filter_init(pacc, &filter);
2291 while ((i = getopt(argc, argv, options)) != -1)
2295 pacc->numeric_ids++;
2301 pacc->buscentric = 1;
2302 buscentric_view = 1;
2305 if (msg = pci_filter_parse_slot(&filter, optarg))
2309 if (msg = pci_filter_parse_id(&filter, optarg))
2319 pacc->id_file_name = optarg;
2331 if (parse_generic_option(i, pacc, optarg))
2334 fprintf(stderr, help_msg, pacc->id_file_name);