2 * The PCI Utilities -- List All PCI Devices
4 * Copyright (c) 1997--2007 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
61 #if defined (__FreeBSD__) || defined (__NetBSD__) || defined (__OpenBSD__) || defined (__DragonFly__)
62 /* alloca() is defined in stdlib.h */
63 #elif defined(__GNUC__) && !defined(PCI_OS_WINDOWS)
67 #define alloca xmalloc
70 /* Our view of the PCI bus */
75 unsigned int config_cached, config_bufsize;
76 byte *config; /* Cached configuration space data */
77 byte *present; /* Maps which configuration bytes are present */
80 static struct device *first_dev;
81 static int seen_errors;
84 config_fetch(struct device *d, unsigned int pos, unsigned int len)
86 unsigned int end = pos+len;
89 while (pos < d->config_bufsize && len && d->present[pos])
91 while (pos+len <= d->config_bufsize && len && d->present[pos+len-1])
96 if (end > d->config_bufsize)
98 int orig_size = d->config_bufsize;
99 while (end > d->config_bufsize)
100 d->config_bufsize *= 2;
101 d->config = xrealloc(d->config, d->config_bufsize);
102 d->present = xrealloc(d->present, d->config_bufsize);
103 memset(d->present + orig_size, 0, d->config_bufsize - orig_size);
105 result = pci_read_block(d->dev, pos, d->config + pos, len);
107 memset(d->present + pos, 1, len);
111 static struct device *
112 scan_device(struct pci_dev *p)
116 if (p->domain && !show_domains)
118 if (!pci_filter_match(&filter, p))
120 d = xmalloc(sizeof(struct device));
121 memset(d, 0, sizeof(*d));
123 d->config_cached = d->config_bufsize = 64;
124 d->config = xmalloc(64);
125 d->present = xmalloc(64);
126 memset(d->present, 1, 64);
127 if (!pci_read_block(p, 0, d->config, 64))
129 fprintf(stderr, "lspci: Unable to read the standard configuration space header of device %04x:%02x:%02x.%d\n",
130 p->domain, p->bus, p->dev, p->func);
134 if ((d->config[PCI_HEADER_TYPE] & 0x7f) == PCI_HEADER_TYPE_CARDBUS)
136 /* For cardbus bridges, we need to fetch 64 bytes more to get the
137 * full standard header... */
138 if (config_fetch(d, 64, 64))
139 d->config_cached += 64;
141 pci_setup_cache(p, d->config, d->config_cached);
142 pci_fill_info(p, PCI_FILL_IDENT | PCI_FILL_CLASS | PCI_FILL_IRQ | PCI_FILL_BASES | PCI_FILL_ROM_BASE | PCI_FILL_SIZES);
153 for(p=pacc->devices; p; p=p->next)
154 if (d = scan_device(p))
161 /* Config space accesses */
164 check_conf_range(struct device *d, unsigned int pos, unsigned int len)
167 if (!d->present[pos])
168 die("Internal bug: Accessing non-read configuration byte at position %x", pos);
174 get_conf_byte(struct device *d, unsigned int pos)
176 check_conf_range(d, pos, 1);
177 return d->config[pos];
181 get_conf_word(struct device *d, unsigned int pos)
183 check_conf_range(d, pos, 2);
184 return d->config[pos] | (d->config[pos+1] << 8);
188 get_conf_long(struct device *d, unsigned int pos)
190 check_conf_range(d, pos, 4);
191 return d->config[pos] |
192 (d->config[pos+1] << 8) |
193 (d->config[pos+2] << 16) |
194 (d->config[pos+3] << 24);
200 compare_them(const void *A, const void *B)
202 const struct pci_dev *a = (*(const struct device **)A)->dev;
203 const struct pci_dev *b = (*(const struct device **)B)->dev;
205 if (a->domain < b->domain)
207 if (a->domain > b->domain)
217 if (a->func < b->func)
219 if (a->func > b->func)
227 struct device **index, **h, **last_dev;
232 for(d=first_dev; d; d=d->next)
234 h = index = alloca(sizeof(struct device *) * cnt);
235 for(d=first_dev; d; d=d->next)
237 qsort(index, cnt, sizeof(struct device *), compare_them);
238 last_dev = &first_dev;
243 last_dev = &(*h)->next;
251 #define FLAG(x,y) ((x & y) ? '+' : '-')
254 show_slot_name(struct device *d)
256 struct pci_dev *p = d->dev;
258 if (!machine_readable ? show_domains : (p->domain || show_domains >= 2))
259 printf("%04x:", p->domain);
260 printf("%02x:%02x.%d", p->bus, p->dev, p->func);
264 show_terse(struct device *d)
267 struct pci_dev *p = d->dev;
268 char classbuf[128], devbuf[128];
272 pci_lookup_name(pacc, classbuf, sizeof(classbuf),
275 pci_lookup_name(pacc, devbuf, sizeof(devbuf),
276 PCI_LOOKUP_VENDOR | PCI_LOOKUP_DEVICE,
277 p->vendor_id, p->device_id));
278 if (c = get_conf_byte(d, PCI_REVISION_ID))
279 printf(" (rev %02x)", c);
283 c = get_conf_byte(d, PCI_CLASS_PROG);
284 x = pci_lookup_name(pacc, devbuf, sizeof(devbuf),
285 PCI_LOOKUP_PROGIF | PCI_LOOKUP_NO_NUMBERS,
289 printf(" (prog-if %02x", c);
299 show_size(pciaddr_t x)
305 printf("%d", (int) x);
306 else if (x < 1048576)
307 printf("%dK", (int)(x / 1024));
308 else if (x < 0x80000000)
309 printf("%dM", (int)(x / 1048576));
311 printf(PCIADDR_T_FMT, x);
316 show_bases(struct device *d, int cnt)
318 struct pci_dev *p = d->dev;
319 word cmd = get_conf_word(d, PCI_COMMAND);
324 pciaddr_t pos = p->base_addr[i];
325 pciaddr_t len = (p->known_fields & PCI_FILL_SIZES) ? p->size[i] : 0;
326 u32 flg = get_conf_long(d, PCI_BASE_ADDRESS_0 + 4*i);
327 if (flg == 0xffffffff)
329 if (!pos && !flg && !len)
332 printf("\tRegion %d: ", i);
335 if (pos && !flg) /* Reported by the OS, but not by the device */
337 printf("[virtual] ");
340 if (flg & PCI_BASE_ADDRESS_SPACE_IO)
342 pciaddr_t a = pos & PCI_BASE_ADDRESS_IO_MASK;
343 printf("I/O ports at ");
345 printf(PCIADDR_PORT_FMT, a);
346 else if (flg & PCI_BASE_ADDRESS_IO_MASK)
349 printf("<unassigned>");
350 if (!(cmd & PCI_COMMAND_IO))
351 printf(" [disabled]");
355 int t = flg & PCI_BASE_ADDRESS_MEM_TYPE_MASK;
356 pciaddr_t a = pos & PCI_ADDR_MEM_MASK;
360 printf("Memory at ");
361 if (t == PCI_BASE_ADDRESS_MEM_TYPE_64)
365 printf("<invalid-64bit-slot>");
371 z = get_conf_long(d, PCI_BASE_ADDRESS_0 + 4*i);
374 u32 y = a & 0xffffffff;
376 printf("%08x%08x", z, y);
378 printf("<unassigned>");
386 printf(PCIADDR_T_FMT, a);
388 printf(((flg & PCI_BASE_ADDRESS_MEM_MASK) || z) ? "<ignored>" : "<unassigned>");
390 printf(" (%s, %sprefetchable)",
391 (t == PCI_BASE_ADDRESS_MEM_TYPE_32) ? "32-bit" :
392 (t == PCI_BASE_ADDRESS_MEM_TYPE_64) ? "64-bit" :
393 (t == PCI_BASE_ADDRESS_MEM_TYPE_1M) ? "low-1M" : "type 3",
394 (flg & PCI_BASE_ADDRESS_MEM_PREFETCH) ? "" : "non-");
395 if (!(cmd & PCI_COMMAND_MEMORY))
396 printf(" [disabled]");
404 show_pm(struct device *d, int where, int cap)
407 static int pm_aux_current[8] = { 0, 55, 100, 160, 220, 270, 320, 375 };
409 printf("Power Management version %d\n", cap & PCI_PM_CAP_VER_MASK);
412 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",
413 FLAG(cap, PCI_PM_CAP_PME_CLOCK),
414 FLAG(cap, PCI_PM_CAP_DSI),
415 FLAG(cap, PCI_PM_CAP_D1),
416 FLAG(cap, PCI_PM_CAP_D2),
417 pm_aux_current[(cap >> 6) & 7],
418 FLAG(cap, PCI_PM_CAP_PME_D0),
419 FLAG(cap, PCI_PM_CAP_PME_D1),
420 FLAG(cap, PCI_PM_CAP_PME_D2),
421 FLAG(cap, PCI_PM_CAP_PME_D3_HOT),
422 FLAG(cap, PCI_PM_CAP_PME_D3_COLD));
423 if (!config_fetch(d, where + PCI_PM_CTRL, PCI_PM_SIZEOF - PCI_PM_CTRL))
425 t = get_conf_word(d, where + PCI_PM_CTRL);
426 printf("\t\tStatus: D%d PME-Enable%c DSel=%d DScale=%d PME%c\n",
427 t & PCI_PM_CTRL_STATE_MASK,
428 FLAG(t, PCI_PM_CTRL_PME_ENABLE),
429 (t & PCI_PM_CTRL_DATA_SEL_MASK) >> 9,
430 (t & PCI_PM_CTRL_DATA_SCALE_MASK) >> 13,
431 FLAG(t, PCI_PM_CTRL_PME_STATUS));
432 b = get_conf_byte(d, where + PCI_PM_PPB_EXTENSIONS);
434 printf("\t\tBridge: PM%c B3%c\n",
435 FLAG(t, PCI_PM_BPCC_ENABLE),
436 FLAG(~t, PCI_PM_PPB_B2_B3));
440 format_agp_rate(int rate, char *buf, int agp3)
450 c += sprintf(c, "x%d", 1 << (i + 2*agp3));
455 strcpy(buf, "<none>");
459 show_agp(struct device *d, int where, int cap)
466 ver = (cap >> 4) & 0x0f;
468 printf("AGP version %x.%x\n", ver, rev);
471 if (!config_fetch(d, where + PCI_AGP_STATUS, PCI_AGP_SIZEOF - PCI_AGP_STATUS))
473 t = get_conf_long(d, where + PCI_AGP_STATUS);
474 if (ver >= 3 && (t & PCI_AGP_STATUS_AGP3))
476 format_agp_rate(t & 7, rate, agp3);
477 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",
478 ((t & PCI_AGP_STATUS_RQ_MASK) >> 24U) + 1,
479 FLAG(t, PCI_AGP_STATUS_ISOCH),
480 ((t & PCI_AGP_STATUS_ARQSZ_MASK) >> 13),
481 ((t & PCI_AGP_STATUS_CAL_MASK) >> 10),
482 FLAG(t, PCI_AGP_STATUS_SBA),
483 FLAG(t, PCI_AGP_STATUS_ITA_COH),
484 FLAG(t, PCI_AGP_STATUS_GART64),
485 FLAG(t, PCI_AGP_STATUS_HTRANS),
486 FLAG(t, PCI_AGP_STATUS_64BIT),
487 FLAG(t, PCI_AGP_STATUS_FW),
488 FLAG(t, PCI_AGP_STATUS_AGP3),
490 t = get_conf_long(d, where + PCI_AGP_COMMAND);
491 format_agp_rate(t & 7, rate, agp3);
492 printf("\t\tCommand: RQ=%d ArqSz=%d Cal=%d SBA%c AGP%c GART64%c 64bit%c FW%c Rate=%s\n",
493 ((t & PCI_AGP_COMMAND_RQ_MASK) >> 24U) + 1,
494 ((t & PCI_AGP_COMMAND_ARQSZ_MASK) >> 13),
495 ((t & PCI_AGP_COMMAND_CAL_MASK) >> 10),
496 FLAG(t, PCI_AGP_COMMAND_SBA),
497 FLAG(t, PCI_AGP_COMMAND_AGP),
498 FLAG(t, PCI_AGP_COMMAND_GART64),
499 FLAG(t, PCI_AGP_COMMAND_64BIT),
500 FLAG(t, PCI_AGP_COMMAND_FW),
505 show_pcix_nobridge(struct device *d, int where)
509 static const byte max_outstanding[8] = { 1, 2, 3, 4, 8, 12, 16, 32 };
511 printf("PCI-X non-bridge device\n");
516 if (!config_fetch(d, where + PCI_PCIX_STATUS, 4))
519 command = get_conf_word(d, where + PCI_PCIX_COMMAND);
520 status = get_conf_long(d, where + PCI_PCIX_STATUS);
521 printf("\t\tCommand: DPERE%c ERO%c RBC=%d OST=%d\n",
522 FLAG(command, PCI_PCIX_COMMAND_DPERE),
523 FLAG(command, PCI_PCIX_COMMAND_ERO),
524 1 << (9 + ((command & PCI_PCIX_COMMAND_MAX_MEM_READ_BYTE_COUNT) >> 2U)),
525 max_outstanding[(command & PCI_PCIX_COMMAND_MAX_OUTSTANDING_SPLIT_TRANS) >> 4U]);
526 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",
527 ((status >> 8) & 0xff),
528 ((status >> 3) & 0x1f),
529 (status & PCI_PCIX_STATUS_FUNCTION),
530 FLAG(status, PCI_PCIX_STATUS_64BIT),
531 FLAG(status, PCI_PCIX_STATUS_133MHZ),
532 FLAG(status, PCI_PCIX_STATUS_SC_DISCARDED),
533 FLAG(status, PCI_PCIX_STATUS_UNEXPECTED_SC),
534 ((status & PCI_PCIX_STATUS_DEVICE_COMPLEXITY) ? "bridge" : "simple"),
535 1 << (9 + ((status >> 21) & 3U)),
536 max_outstanding[(status >> 23) & 7U],
537 1 << (3 + ((status >> 26) & 7U)),
538 FLAG(status, PCI_PCIX_STATUS_RCVD_SC_ERR_MESS),
539 FLAG(status, PCI_PCIX_STATUS_266MHZ),
540 FLAG(status, PCI_PCIX_STATUS_533MHZ));
544 show_pcix_bridge(struct device *d, int where)
546 static const char * const sec_clock_freq[8] = { "conv", "66MHz", "100MHz", "133MHz", "?4", "?5", "?6", "?7" };
548 u32 status, upstcr, downstcr;
550 printf("PCI-X bridge device\n");
555 if (!config_fetch(d, where + PCI_PCIX_BRIDGE_STATUS, 12))
558 secstatus = get_conf_word(d, where + PCI_PCIX_BRIDGE_SEC_STATUS);
559 printf("\t\tSecondary Status: 64bit%c 133MHz%c SCD%c USC%c SCO%c SRD%c Freq=%s\n",
560 FLAG(secstatus, PCI_PCIX_BRIDGE_SEC_STATUS_64BIT),
561 FLAG(secstatus, PCI_PCIX_BRIDGE_SEC_STATUS_133MHZ),
562 FLAG(secstatus, PCI_PCIX_BRIDGE_SEC_STATUS_SC_DISCARDED),
563 FLAG(secstatus, PCI_PCIX_BRIDGE_SEC_STATUS_UNEXPECTED_SC),
564 FLAG(secstatus, PCI_PCIX_BRIDGE_SEC_STATUS_SC_OVERRUN),
565 FLAG(secstatus, PCI_PCIX_BRIDGE_SEC_STATUS_SPLIT_REQUEST_DELAYED),
566 sec_clock_freq[(secstatus >> 6) & 7]);
567 status = get_conf_long(d, where + PCI_PCIX_BRIDGE_STATUS);
568 printf("\t\tStatus: Dev=%02x:%02x.%d 64bit%c 133MHz%c SCD%c USC%c SCO%c SRD%c\n",
569 ((status >> 8) & 0xff),
570 ((status >> 3) & 0x1f),
571 (status & PCI_PCIX_BRIDGE_STATUS_FUNCTION),
572 FLAG(status, PCI_PCIX_BRIDGE_STATUS_64BIT),
573 FLAG(status, PCI_PCIX_BRIDGE_STATUS_133MHZ),
574 FLAG(status, PCI_PCIX_BRIDGE_STATUS_SC_DISCARDED),
575 FLAG(status, PCI_PCIX_BRIDGE_STATUS_UNEXPECTED_SC),
576 FLAG(status, PCI_PCIX_BRIDGE_STATUS_SC_OVERRUN),
577 FLAG(status, PCI_PCIX_BRIDGE_STATUS_SPLIT_REQUEST_DELAYED));
578 upstcr = get_conf_long(d, where + PCI_PCIX_BRIDGE_UPSTREAM_SPLIT_TRANS_CTRL);
579 printf("\t\tUpstream: Capacity=%u CommitmentLimit=%u\n",
580 (upstcr & PCI_PCIX_BRIDGE_STR_CAPACITY),
581 (upstcr >> 16) & 0xffff);
582 downstcr = get_conf_long(d, where + PCI_PCIX_BRIDGE_DOWNSTREAM_SPLIT_TRANS_CTRL);
583 printf("\t\tDownstream: Capacity=%u CommitmentLimit=%u\n",
584 (downstcr & PCI_PCIX_BRIDGE_STR_CAPACITY),
585 (downstcr >> 16) & 0xffff);
589 show_pcix(struct device *d, int where)
591 switch (get_conf_byte(d, PCI_HEADER_TYPE) & 0x7f)
593 case PCI_HEADER_TYPE_NORMAL:
594 show_pcix_nobridge(d, where);
596 case PCI_HEADER_TYPE_BRIDGE:
597 show_pcix_bridge(d, where);
603 ht_link_width(unsigned width)
605 static char * const widths[8] = { "8bit", "16bit", "[2]", "32bit", "2bit", "4bit", "[6]", "N/C" };
606 return widths[width];
610 ht_link_freq(unsigned freq)
612 static char * const freqs[16] = { "200MHz", "300MHz", "400MHz", "500MHz", "600MHz", "800MHz", "1.0GHz", "1.2GHz",
613 "1.4GHz", "1.6GHz", "[a]", "[b]", "[c]", "[d]", "[e]", "Vend" };
618 show_ht_pri(struct device *d, int where, int cmd)
620 u16 lctr0, lcnf0, lctr1, lcnf1, eh;
621 u8 rid, lfrer0, lfcap0, ftr, lfrer1, lfcap1, mbu, mlu, bn;
624 printf("HyperTransport: Slave or Primary Interface\n");
628 if (!config_fetch(d, where + PCI_HT_PRI_LCTR0, PCI_HT_PRI_SIZEOF - PCI_HT_PRI_LCTR0))
630 rid = get_conf_byte(d, where + PCI_HT_PRI_RID);
631 if (rid < 0x23 && rid > 0x11)
632 printf("\t\t!!! Possibly incomplete decoding\n");
635 fmt = "\t\tCommand: BaseUnitID=%u UnitCnt=%u MastHost%c DefDir%c DUL%c\n";
637 fmt = "\t\tCommand: BaseUnitID=%u UnitCnt=%u MastHost%c DefDir%c\n";
639 (cmd & PCI_HT_PRI_CMD_BUID),
640 (cmd & PCI_HT_PRI_CMD_UC) >> 5,
641 FLAG(cmd, PCI_HT_PRI_CMD_MH),
642 FLAG(cmd, PCI_HT_PRI_CMD_DD),
643 FLAG(cmd, PCI_HT_PRI_CMD_DUL));
644 lctr0 = get_conf_word(d, where + PCI_HT_PRI_LCTR0);
646 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";
648 fmt = "\t\tLink Control 0: CFlE%c CST%c CFE%c <LkFail%c Init%c EOC%c TXO%c <CRCErr=%x\n";
650 FLAG(lctr0, PCI_HT_LCTR_CFLE),
651 FLAG(lctr0, PCI_HT_LCTR_CST),
652 FLAG(lctr0, PCI_HT_LCTR_CFE),
653 FLAG(lctr0, PCI_HT_LCTR_LKFAIL),
654 FLAG(lctr0, PCI_HT_LCTR_INIT),
655 FLAG(lctr0, PCI_HT_LCTR_EOC),
656 FLAG(lctr0, PCI_HT_LCTR_TXO),
657 (lctr0 & PCI_HT_LCTR_CRCERR) >> 8,
658 FLAG(lctr0, PCI_HT_LCTR_ISOCEN),
659 FLAG(lctr0, PCI_HT_LCTR_LSEN),
660 FLAG(lctr0, PCI_HT_LCTR_EXTCTL),
661 FLAG(lctr0, PCI_HT_LCTR_64B));
662 lcnf0 = get_conf_word(d, where + PCI_HT_PRI_LCNF0);
664 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";
666 fmt = "\t\tLink Config 0: MLWI=%s MLWO=%s LWI=%s LWO=%s\n";
668 ht_link_width(lcnf0 & PCI_HT_LCNF_MLWI),
669 ht_link_width((lcnf0 & PCI_HT_LCNF_MLWO) >> 4),
670 ht_link_width((lcnf0 & PCI_HT_LCNF_LWI) >> 8),
671 ht_link_width((lcnf0 & PCI_HT_LCNF_LWO) >> 12),
672 FLAG(lcnf0, PCI_HT_LCNF_DFI),
673 FLAG(lcnf0, PCI_HT_LCNF_DFO),
674 FLAG(lcnf0, PCI_HT_LCNF_DFIE),
675 FLAG(lcnf0, PCI_HT_LCNF_DFOE));
676 lctr1 = get_conf_word(d, where + PCI_HT_PRI_LCTR1);
678 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";
680 fmt = "\t\tLink Control 1: CFlE%c CST%c CFE%c <LkFail%c Init%c EOC%c TXO%c <CRCErr=%x\n";
682 FLAG(lctr1, PCI_HT_LCTR_CFLE),
683 FLAG(lctr1, PCI_HT_LCTR_CST),
684 FLAG(lctr1, PCI_HT_LCTR_CFE),
685 FLAG(lctr1, PCI_HT_LCTR_LKFAIL),
686 FLAG(lctr1, PCI_HT_LCTR_INIT),
687 FLAG(lctr1, PCI_HT_LCTR_EOC),
688 FLAG(lctr1, PCI_HT_LCTR_TXO),
689 (lctr1 & PCI_HT_LCTR_CRCERR) >> 8,
690 FLAG(lctr1, PCI_HT_LCTR_ISOCEN),
691 FLAG(lctr1, PCI_HT_LCTR_LSEN),
692 FLAG(lctr1, PCI_HT_LCTR_EXTCTL),
693 FLAG(lctr1, PCI_HT_LCTR_64B));
694 lcnf1 = get_conf_word(d, where + PCI_HT_PRI_LCNF1);
696 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";
698 fmt = "\t\tLink Config 1: MLWI=%s MLWO=%s LWI=%s LWO=%s\n";
700 ht_link_width(lcnf1 & PCI_HT_LCNF_MLWI),
701 ht_link_width((lcnf1 & PCI_HT_LCNF_MLWO) >> 4),
702 ht_link_width((lcnf1 & PCI_HT_LCNF_LWI) >> 8),
703 ht_link_width((lcnf1 & PCI_HT_LCNF_LWO) >> 12),
704 FLAG(lcnf1, PCI_HT_LCNF_DFI),
705 FLAG(lcnf1, PCI_HT_LCNF_DFO),
706 FLAG(lcnf1, PCI_HT_LCNF_DFIE),
707 FLAG(lcnf1, PCI_HT_LCNF_DFOE));
708 printf("\t\tRevision ID: %u.%02u\n",
709 (rid & PCI_HT_RID_MAJ) >> 5, (rid & PCI_HT_RID_MIN));
712 lfrer0 = get_conf_byte(d, where + PCI_HT_PRI_LFRER0);
713 printf("\t\tLink Frequency 0: %s\n", ht_link_freq(lfrer0 & PCI_HT_LFRER_FREQ));
714 printf("\t\tLink Error 0: <Prot%c <Ovfl%c <EOC%c CTLTm%c\n",
715 FLAG(lfrer0, PCI_HT_LFRER_PROT),
716 FLAG(lfrer0, PCI_HT_LFRER_OV),
717 FLAG(lfrer0, PCI_HT_LFRER_EOC),
718 FLAG(lfrer0, PCI_HT_LFRER_CTLT));
719 lfcap0 = get_conf_byte(d, where + PCI_HT_PRI_LFCAP0);
720 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",
721 FLAG(lfcap0, PCI_HT_LFCAP_200),
722 FLAG(lfcap0, PCI_HT_LFCAP_300),
723 FLAG(lfcap0, PCI_HT_LFCAP_400),
724 FLAG(lfcap0, PCI_HT_LFCAP_500),
725 FLAG(lfcap0, PCI_HT_LFCAP_600),
726 FLAG(lfcap0, PCI_HT_LFCAP_800),
727 FLAG(lfcap0, PCI_HT_LFCAP_1000),
728 FLAG(lfcap0, PCI_HT_LFCAP_1200),
729 FLAG(lfcap0, PCI_HT_LFCAP_1400),
730 FLAG(lfcap0, PCI_HT_LFCAP_1600),
731 FLAG(lfcap0, PCI_HT_LFCAP_VEND));
732 ftr = get_conf_byte(d, where + PCI_HT_PRI_FTR);
733 printf("\t\tFeature Capability: IsocFC%c LDTSTOP%c CRCTM%c ECTLT%c 64bA%c UIDRD%c\n",
734 FLAG(ftr, PCI_HT_FTR_ISOCFC),
735 FLAG(ftr, PCI_HT_FTR_LDTSTOP),
736 FLAG(ftr, PCI_HT_FTR_CRCTM),
737 FLAG(ftr, PCI_HT_FTR_ECTLT),
738 FLAG(ftr, PCI_HT_FTR_64BA),
739 FLAG(ftr, PCI_HT_FTR_UIDRD));
740 lfrer1 = get_conf_byte(d, where + PCI_HT_PRI_LFRER1);
741 printf("\t\tLink Frequency 1: %s\n", ht_link_freq(lfrer1 & PCI_HT_LFRER_FREQ));
742 printf("\t\tLink Error 1: <Prot%c <Ovfl%c <EOC%c CTLTm%c\n",
743 FLAG(lfrer1, PCI_HT_LFRER_PROT),
744 FLAG(lfrer1, PCI_HT_LFRER_OV),
745 FLAG(lfrer1, PCI_HT_LFRER_EOC),
746 FLAG(lfrer1, PCI_HT_LFRER_CTLT));
747 lfcap1 = get_conf_byte(d, where + PCI_HT_PRI_LFCAP1);
748 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",
749 FLAG(lfcap1, PCI_HT_LFCAP_200),
750 FLAG(lfcap1, PCI_HT_LFCAP_300),
751 FLAG(lfcap1, PCI_HT_LFCAP_400),
752 FLAG(lfcap1, PCI_HT_LFCAP_500),
753 FLAG(lfcap1, PCI_HT_LFCAP_600),
754 FLAG(lfcap1, PCI_HT_LFCAP_800),
755 FLAG(lfcap1, PCI_HT_LFCAP_1000),
756 FLAG(lfcap1, PCI_HT_LFCAP_1200),
757 FLAG(lfcap1, PCI_HT_LFCAP_1400),
758 FLAG(lfcap1, PCI_HT_LFCAP_1600),
759 FLAG(lfcap1, PCI_HT_LFCAP_VEND));
760 eh = get_conf_word(d, where + PCI_HT_PRI_EH);
761 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",
762 FLAG(eh, PCI_HT_EH_PFLE),
763 FLAG(eh, PCI_HT_EH_OFLE),
764 FLAG(eh, PCI_HT_EH_PFE),
765 FLAG(eh, PCI_HT_EH_OFE),
766 FLAG(eh, PCI_HT_EH_EOCFE),
767 FLAG(eh, PCI_HT_EH_RFE),
768 FLAG(eh, PCI_HT_EH_CRCFE),
769 FLAG(eh, PCI_HT_EH_SERRFE),
770 FLAG(eh, PCI_HT_EH_CF),
771 FLAG(eh, PCI_HT_EH_RE),
772 FLAG(eh, PCI_HT_EH_PNFE),
773 FLAG(eh, PCI_HT_EH_ONFE),
774 FLAG(eh, PCI_HT_EH_EOCNFE),
775 FLAG(eh, PCI_HT_EH_RNFE),
776 FLAG(eh, PCI_HT_EH_CRCNFE),
777 FLAG(eh, PCI_HT_EH_SERRNFE));
778 mbu = get_conf_byte(d, where + PCI_HT_PRI_MBU);
779 mlu = get_conf_byte(d, where + PCI_HT_PRI_MLU);
780 printf("\t\tPrefetchable memory behind bridge Upper: %02x-%02x\n", mbu, mlu);
781 bn = get_conf_byte(d, where + PCI_HT_PRI_BN);
782 printf("\t\tBus Number: %02x\n", bn);
786 show_ht_sec(struct device *d, int where, int cmd)
788 u16 lctr, lcnf, ftr, eh;
789 u8 rid, lfrer, lfcap, mbu, mlu;
792 printf("HyperTransport: Host or Secondary Interface\n");
796 if (!config_fetch(d, where + PCI_HT_SEC_LCTR, PCI_HT_SEC_SIZEOF - PCI_HT_SEC_LCTR))
798 rid = get_conf_byte(d, where + PCI_HT_SEC_RID);
799 if (rid < 0x23 && rid > 0x11)
800 printf("\t\t!!! Possibly incomplete decoding\n");
803 fmt = "\t\tCommand: WarmRst%c DblEnd%c DevNum=%u ChainSide%c HostHide%c Slave%c <EOCErr%c DUL%c\n";
805 fmt = "\t\tCommand: WarmRst%c DblEnd%c\n";
807 FLAG(cmd, PCI_HT_SEC_CMD_WR),
808 FLAG(cmd, PCI_HT_SEC_CMD_DE),
809 (cmd & PCI_HT_SEC_CMD_DN) >> 2,
810 FLAG(cmd, PCI_HT_SEC_CMD_CS),
811 FLAG(cmd, PCI_HT_SEC_CMD_HH),
812 FLAG(cmd, PCI_HT_SEC_CMD_AS),
813 FLAG(cmd, PCI_HT_SEC_CMD_HIECE),
814 FLAG(cmd, PCI_HT_SEC_CMD_DUL));
815 lctr = get_conf_word(d, where + PCI_HT_SEC_LCTR);
817 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";
819 fmt = "\t\tLink Control: CFlE%c CST%c CFE%c <LkFail%c Init%c EOC%c TXO%c <CRCErr=%x\n";
821 FLAG(lctr, PCI_HT_LCTR_CFLE),
822 FLAG(lctr, PCI_HT_LCTR_CST),
823 FLAG(lctr, PCI_HT_LCTR_CFE),
824 FLAG(lctr, PCI_HT_LCTR_LKFAIL),
825 FLAG(lctr, PCI_HT_LCTR_INIT),
826 FLAG(lctr, PCI_HT_LCTR_EOC),
827 FLAG(lctr, PCI_HT_LCTR_TXO),
828 (lctr & PCI_HT_LCTR_CRCERR) >> 8,
829 FLAG(lctr, PCI_HT_LCTR_ISOCEN),
830 FLAG(lctr, PCI_HT_LCTR_LSEN),
831 FLAG(lctr, PCI_HT_LCTR_EXTCTL),
832 FLAG(lctr, PCI_HT_LCTR_64B));
833 lcnf = get_conf_word(d, where + PCI_HT_SEC_LCNF);
835 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";
837 fmt = "\t\tLink Config: MLWI=%s MLWO=%s LWI=%s LWO=%s\n";
839 ht_link_width(lcnf & PCI_HT_LCNF_MLWI),
840 ht_link_width((lcnf & PCI_HT_LCNF_MLWO) >> 4),
841 ht_link_width((lcnf & PCI_HT_LCNF_LWI) >> 8),
842 ht_link_width((lcnf & PCI_HT_LCNF_LWO) >> 12),
843 FLAG(lcnf, PCI_HT_LCNF_DFI),
844 FLAG(lcnf, PCI_HT_LCNF_DFO),
845 FLAG(lcnf, PCI_HT_LCNF_DFIE),
846 FLAG(lcnf, PCI_HT_LCNF_DFOE));
847 printf("\t\tRevision ID: %u.%02u\n",
848 (rid & PCI_HT_RID_MAJ) >> 5, (rid & PCI_HT_RID_MIN));
851 lfrer = get_conf_byte(d, where + PCI_HT_SEC_LFRER);
852 printf("\t\tLink Frequency: %s\n", ht_link_freq(lfrer & PCI_HT_LFRER_FREQ));
853 printf("\t\tLink Error: <Prot%c <Ovfl%c <EOC%c CTLTm%c\n",
854 FLAG(lfrer, PCI_HT_LFRER_PROT),
855 FLAG(lfrer, PCI_HT_LFRER_OV),
856 FLAG(lfrer, PCI_HT_LFRER_EOC),
857 FLAG(lfrer, PCI_HT_LFRER_CTLT));
858 lfcap = get_conf_byte(d, where + PCI_HT_SEC_LFCAP);
859 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",
860 FLAG(lfcap, PCI_HT_LFCAP_200),
861 FLAG(lfcap, PCI_HT_LFCAP_300),
862 FLAG(lfcap, PCI_HT_LFCAP_400),
863 FLAG(lfcap, PCI_HT_LFCAP_500),
864 FLAG(lfcap, PCI_HT_LFCAP_600),
865 FLAG(lfcap, PCI_HT_LFCAP_800),
866 FLAG(lfcap, PCI_HT_LFCAP_1000),
867 FLAG(lfcap, PCI_HT_LFCAP_1200),
868 FLAG(lfcap, PCI_HT_LFCAP_1400),
869 FLAG(lfcap, PCI_HT_LFCAP_1600),
870 FLAG(lfcap, PCI_HT_LFCAP_VEND));
871 ftr = get_conf_word(d, where + PCI_HT_SEC_FTR);
872 printf("\t\tFeature Capability: IsocFC%c LDTSTOP%c CRCTM%c ECTLT%c 64bA%c UIDRD%c ExtRS%c UCnfE%c\n",
873 FLAG(ftr, PCI_HT_FTR_ISOCFC),
874 FLAG(ftr, PCI_HT_FTR_LDTSTOP),
875 FLAG(ftr, PCI_HT_FTR_CRCTM),
876 FLAG(ftr, PCI_HT_FTR_ECTLT),
877 FLAG(ftr, PCI_HT_FTR_64BA),
878 FLAG(ftr, PCI_HT_FTR_UIDRD),
879 FLAG(ftr, PCI_HT_SEC_FTR_EXTRS),
880 FLAG(ftr, PCI_HT_SEC_FTR_UCNFE));
881 if (ftr & PCI_HT_SEC_FTR_EXTRS)
883 eh = get_conf_word(d, where + PCI_HT_SEC_EH);
884 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",
885 FLAG(eh, PCI_HT_EH_PFLE),
886 FLAG(eh, PCI_HT_EH_OFLE),
887 FLAG(eh, PCI_HT_EH_PFE),
888 FLAG(eh, PCI_HT_EH_OFE),
889 FLAG(eh, PCI_HT_EH_EOCFE),
890 FLAG(eh, PCI_HT_EH_RFE),
891 FLAG(eh, PCI_HT_EH_CRCFE),
892 FLAG(eh, PCI_HT_EH_SERRFE),
893 FLAG(eh, PCI_HT_EH_CF),
894 FLAG(eh, PCI_HT_EH_RE),
895 FLAG(eh, PCI_HT_EH_PNFE),
896 FLAG(eh, PCI_HT_EH_ONFE),
897 FLAG(eh, PCI_HT_EH_EOCNFE),
898 FLAG(eh, PCI_HT_EH_RNFE),
899 FLAG(eh, PCI_HT_EH_CRCNFE),
900 FLAG(eh, PCI_HT_EH_SERRNFE));
901 mbu = get_conf_byte(d, where + PCI_HT_SEC_MBU);
902 mlu = get_conf_byte(d, where + PCI_HT_SEC_MLU);
903 printf("\t\tPrefetchable memory behind bridge Upper: %02x-%02x\n", mbu, mlu);
908 show_ht(struct device *d, int where, int cmd)
912 switch (cmd & PCI_HT_CMD_TYP_HI)
914 case PCI_HT_CMD_TYP_HI_PRI:
915 show_ht_pri(d, where, cmd);
917 case PCI_HT_CMD_TYP_HI_SEC:
918 show_ht_sec(d, where, cmd);
922 type = cmd & PCI_HT_CMD_TYP;
925 case PCI_HT_CMD_TYP_SW:
926 printf("HyperTransport: Switch\n");
928 case PCI_HT_CMD_TYP_IDC:
929 printf("HyperTransport: Interrupt Discovery and Configuration\n");
931 case PCI_HT_CMD_TYP_RID:
932 printf("HyperTransport: Revision ID: %u.%02u\n",
933 (cmd & PCI_HT_RID_MAJ) >> 5, (cmd & PCI_HT_RID_MIN));
935 case PCI_HT_CMD_TYP_UIDC:
936 printf("HyperTransport: UnitID Clumping\n");
938 case PCI_HT_CMD_TYP_ECSA:
939 printf("HyperTransport: Extended Configuration Space Access\n");
941 case PCI_HT_CMD_TYP_AM:
942 printf("HyperTransport: Address Mapping\n");
944 case PCI_HT_CMD_TYP_MSIM:
945 printf("HyperTransport: MSI Mapping Enable%c Fixed%c\n",
946 FLAG(cmd, PCI_HT_MSIM_CMD_EN),
947 FLAG(cmd, PCI_HT_MSIM_CMD_FIXD));
948 if (verbose >= 2 && !(cmd & PCI_HT_MSIM_CMD_FIXD))
951 if (!config_fetch(d, where + PCI_HT_MSIM_ADDR_LO, 8))
953 offl = get_conf_long(d, where + PCI_HT_MSIM_ADDR_LO);
954 offh = get_conf_long(d, where + PCI_HT_MSIM_ADDR_HI);
955 printf("\t\tMapping Address Base: %016llx\n", ((unsigned long long)offh << 32) | (offl & ~0xfffff));
958 case PCI_HT_CMD_TYP_DR:
959 printf("HyperTransport: DirectRoute\n");
961 case PCI_HT_CMD_TYP_VCS:
962 printf("HyperTransport: VCSet\n");
964 case PCI_HT_CMD_TYP_RM:
965 printf("HyperTransport: Retry Mode\n");
967 case PCI_HT_CMD_TYP_X86:
968 printf("HyperTransport: X86 (reserved)\n");
971 printf("HyperTransport: #%02x\n", type >> 11);
976 show_rom(struct device *d, int reg)
978 struct pci_dev *p = d->dev;
979 pciaddr_t rom = p->rom_base_addr;
980 pciaddr_t len = (p->known_fields & PCI_FILL_SIZES) ? p->rom_size : 0;
981 u32 flg = get_conf_long(d, reg);
982 word cmd = get_conf_word(d, PCI_COMMAND);
984 if (!rom && !flg && !len)
987 if ((rom & PCI_ROM_ADDRESS_MASK) && !(flg & PCI_ROM_ADDRESS_MASK))
989 printf("[virtual] ");
992 printf("Expansion ROM at ");
993 if (rom & PCI_ROM_ADDRESS_MASK)
994 printf(PCIADDR_T_FMT, rom & PCI_ROM_ADDRESS_MASK);
995 else if (flg & PCI_ROM_ADDRESS_MASK)
998 printf("<unassigned>");
999 if (!(flg & PCI_ROM_ADDRESS_ENABLE))
1000 printf(" [disabled]");
1001 else if (!(cmd & PCI_COMMAND_MEMORY))
1002 printf(" [disabled by cmd]");
1008 show_msi(struct device *d, int where, int cap)
1014 printf("Message Signalled Interrupts: Mask%c 64bit%c Queue=%d/%d Enable%c\n",
1015 FLAG(cap, PCI_MSI_FLAGS_MASK_BIT),
1016 FLAG(cap, PCI_MSI_FLAGS_64BIT),
1017 (cap & PCI_MSI_FLAGS_QSIZE) >> 4,
1018 (cap & PCI_MSI_FLAGS_QMASK) >> 1,
1019 FLAG(cap, PCI_MSI_FLAGS_ENABLE));
1022 is64 = cap & PCI_MSI_FLAGS_64BIT;
1023 if (!config_fetch(d, where + PCI_MSI_ADDRESS_LO, (is64 ? PCI_MSI_DATA_64 : PCI_MSI_DATA_32) + 2 - PCI_MSI_ADDRESS_LO))
1025 printf("\t\tAddress: ");
1028 t = get_conf_long(d, where + PCI_MSI_ADDRESS_HI);
1029 w = get_conf_word(d, where + PCI_MSI_DATA_64);
1033 w = get_conf_word(d, where + PCI_MSI_DATA_32);
1034 t = get_conf_long(d, where + PCI_MSI_ADDRESS_LO);
1035 printf("%08x Data: %04x\n", t, w);
1036 if (cap & PCI_MSI_FLAGS_MASK_BIT)
1042 if (!config_fetch(d, where + PCI_MSI_MASK_BIT_64, 8))
1044 mask = get_conf_long(d, where + PCI_MSI_MASK_BIT_64);
1045 pending = get_conf_long(d, where + PCI_MSI_PENDING_64);
1049 if (!config_fetch(d, where + PCI_MSI_MASK_BIT_32, 8))
1051 mask = get_conf_long(d, where + PCI_MSI_MASK_BIT_32);
1052 pending = get_conf_long(d, where + PCI_MSI_PENDING_32);
1054 printf("\t\tMasking: %08x Pending: %08x\n", mask, pending);
1058 static void show_vendor(void)
1060 printf("Vendor Specific Information\n");
1063 static void show_debug(void)
1065 printf("Debug port\n");
1068 static float power_limit(int value, int scale)
1070 static const float scales[4] = { 1.0, 0.1, 0.01, 0.001 };
1071 return value * scales[scale];
1074 static const char *latency_l0s(int value)
1076 static const char *latencies[] = { "<64ns", "<128ns", "<256ns", "<512ns", "<1us", "<2us", "<4us", "unlimited" };
1077 return latencies[value];
1080 static const char *latency_l1(int value)
1082 static const char *latencies[] = { "<1us", "<2us", "<4us", "<8us", "<16us", "<32us", "<64us", "unlimited" };
1083 return latencies[value];
1086 static void show_express_dev(struct device *d, int where, int type)
1091 t = get_conf_long(d, where + PCI_EXP_DEVCAP);
1092 printf("\t\tDevice: Supported: MaxPayload %d bytes, PhantFunc %d, ExtTag%c\n",
1093 128 << (t & PCI_EXP_DEVCAP_PAYLOAD),
1094 (1 << ((t & PCI_EXP_DEVCAP_PHANTOM) >> 3)) - 1,
1095 FLAG(t, PCI_EXP_DEVCAP_EXT_TAG));
1096 printf("\t\tDevice: Latency L0s %s, L1 %s\n",
1097 latency_l0s((t & PCI_EXP_DEVCAP_L0S) >> 6),
1098 latency_l1((t & PCI_EXP_DEVCAP_L1) >> 9));
1099 if ((type == PCI_EXP_TYPE_ENDPOINT) || (type == PCI_EXP_TYPE_LEG_END) ||
1100 (type == PCI_EXP_TYPE_UPSTREAM) || (type == PCI_EXP_TYPE_PCI_BRIDGE))
1101 printf("\t\tDevice: AtnBtn%c AtnInd%c PwrInd%c\n",
1102 FLAG(t, PCI_EXP_DEVCAP_ATN_BUT),
1103 FLAG(t, PCI_EXP_DEVCAP_ATN_IND), FLAG(t, PCI_EXP_DEVCAP_PWR_IND));
1104 if (type == PCI_EXP_TYPE_UPSTREAM)
1105 printf("\t\tDevice: SlotPowerLimit %f\n",
1106 power_limit((t & PCI_EXP_DEVCAP_PWR_VAL) >> 18,
1107 (t & PCI_EXP_DEVCAP_PWR_SCL) >> 26));
1109 w = get_conf_word(d, where + PCI_EXP_DEVCTL);
1110 printf("\t\tDevice: Errors: Correctable%c Non-Fatal%c Fatal%c Unsupported%c\n",
1111 FLAG(w, PCI_EXP_DEVCTL_CERE),
1112 FLAG(w, PCI_EXP_DEVCTL_NFERE),
1113 FLAG(w, PCI_EXP_DEVCTL_FERE),
1114 FLAG(w, PCI_EXP_DEVCTL_URRE));
1115 printf("\t\tDevice: RlxdOrd%c ExtTag%c PhantFunc%c AuxPwr%c NoSnoop%c\n",
1116 FLAG(w, PCI_EXP_DEVCTL_RELAXED),
1117 FLAG(w, PCI_EXP_DEVCTL_EXT_TAG),
1118 FLAG(w, PCI_EXP_DEVCTL_PHANTOM),
1119 FLAG(w, PCI_EXP_DEVCTL_AUX_PME),
1120 FLAG(w, PCI_EXP_DEVCTL_NOSNOOP));
1121 printf("\t\tDevice: MaxPayload %d bytes, MaxReadReq %d bytes\n",
1122 128 << ((w & PCI_EXP_DEVCTL_PAYLOAD) >> 5),
1123 128 << ((w & PCI_EXP_DEVCTL_READRQ) >> 12));
1126 static char *link_speed(int speed)
1137 static char *aspm_support(int code)
1150 static const char *aspm_enabled(int code)
1152 static const char *desc[] = { "Disabled", "L0s Enabled", "L1 Enabled", "L0s L1 Enabled" };
1156 static void show_express_link(struct device *d, int where, int type)
1161 t = get_conf_long(d, where + PCI_EXP_LNKCAP);
1162 printf("\t\tLink: Supported Speed %s, Width x%d, ASPM %s, Port %d\n",
1163 link_speed(t & PCI_EXP_LNKCAP_SPEED), (t & PCI_EXP_LNKCAP_WIDTH) >> 4,
1164 aspm_support((t & PCI_EXP_LNKCAP_ASPM) >> 10),
1166 printf("\t\tLink: Latency L0s %s, L1 %s\n",
1167 latency_l0s((t & PCI_EXP_LNKCAP_L0S) >> 12),
1168 latency_l1((t & PCI_EXP_LNKCAP_L1) >> 15));
1169 w = get_conf_word(d, where + PCI_EXP_LNKCTL);
1170 printf("\t\tLink: ASPM %s", aspm_enabled(w & PCI_EXP_LNKCTL_ASPM));
1171 if ((type == PCI_EXP_TYPE_ROOT_PORT) || (type == PCI_EXP_TYPE_ENDPOINT) ||
1172 (type == PCI_EXP_TYPE_LEG_END))
1173 printf(" RCB %d bytes", w & PCI_EXP_LNKCTL_RCB ? 128 : 64);
1174 if (w & PCI_EXP_LNKCTL_DISABLE)
1175 printf(" Disabled");
1176 printf(" CommClk%c ExtSynch%c\n", FLAG(w, PCI_EXP_LNKCTL_CLOCK),
1177 FLAG(w, PCI_EXP_LNKCTL_XSYNCH));
1178 w = get_conf_word(d, where + PCI_EXP_LNKSTA);
1179 printf("\t\tLink: Speed %s, Width x%d\n",
1180 link_speed(w & PCI_EXP_LNKSTA_SPEED), (w & PCI_EXP_LNKSTA_WIDTH) >> 4);
1183 static const char *indicator(int code)
1185 static const char *names[] = { "Unknown", "On", "Blink", "Off" };
1189 static void show_express_slot(struct device *d, int where)
1194 t = get_conf_long(d, where + PCI_EXP_SLTCAP);
1195 printf("\t\tSlot: AtnBtn%c PwrCtrl%c MRL%c AtnInd%c PwrInd%c HotPlug%c Surpise%c\n",
1196 FLAG(t, PCI_EXP_SLTCAP_ATNB),
1197 FLAG(t, PCI_EXP_SLTCAP_PWRC),
1198 FLAG(t, PCI_EXP_SLTCAP_MRL),
1199 FLAG(t, PCI_EXP_SLTCAP_ATNI),
1200 FLAG(t, PCI_EXP_SLTCAP_PWRI),
1201 FLAG(t, PCI_EXP_SLTCAP_HPC),
1202 FLAG(t, PCI_EXP_SLTCAP_HPS));
1203 printf("\t\tSlot: Number %d, PowerLimit %f\n", t >> 19,
1204 power_limit((t & PCI_EXP_SLTCAP_PWR_VAL) >> 7,
1205 (t & PCI_EXP_SLTCAP_PWR_SCL) >> 15));
1206 w = get_conf_word(d, where + PCI_EXP_SLTCTL);
1207 printf("\t\tSlot: Enabled AtnBtn%c PwrFlt%c MRL%c PresDet%c CmdCplt%c HPIrq%c\n",
1208 FLAG(w, PCI_EXP_SLTCTL_ATNB),
1209 FLAG(w, PCI_EXP_SLTCTL_PWRF),
1210 FLAG(w, PCI_EXP_SLTCTL_MRLS),
1211 FLAG(w, PCI_EXP_SLTCTL_PRSD),
1212 FLAG(w, PCI_EXP_SLTCTL_CMDC),
1213 FLAG(w, PCI_EXP_SLTCTL_HPIE));
1214 printf("\t\tSlot: AttnInd %s, PwrInd %s, Power%c\n",
1215 indicator((w & PCI_EXP_SLTCTL_ATNI) >> 6),
1216 indicator((w & PCI_EXP_SLTCTL_PWRI) >> 8),
1217 FLAG(w, w & PCI_EXP_SLTCTL_PWRC));
1220 static void show_express_root(struct device *d, int where)
1222 u16 w = get_conf_word(d, where + PCI_EXP_RTCTL);
1223 printf("\t\tRoot: Correctable%c Non-Fatal%c Fatal%c PME%c\n",
1224 FLAG(w, PCI_EXP_RTCTL_SECEE),
1225 FLAG(w, PCI_EXP_RTCTL_SENFEE),
1226 FLAG(w, PCI_EXP_RTCTL_SEFEE),
1227 FLAG(w, PCI_EXP_RTCTL_PMEIE));
1231 show_express(struct device *d, int where, int cap)
1233 int type = (cap & PCI_EXP_FLAGS_TYPE) >> 4;
1239 printf("(v%d) ", cap & PCI_EXP_FLAGS_VERS);
1242 case PCI_EXP_TYPE_ENDPOINT:
1245 case PCI_EXP_TYPE_LEG_END:
1246 printf("Legacy Endpoint");
1248 case PCI_EXP_TYPE_ROOT_PORT:
1249 slot = cap & PCI_EXP_FLAGS_SLOT;
1250 printf("Root Port (Slot%c)", FLAG(cap, PCI_EXP_FLAGS_SLOT));
1252 case PCI_EXP_TYPE_UPSTREAM:
1253 printf("Upstream Port");
1255 case PCI_EXP_TYPE_DOWNSTREAM:
1256 slot = cap & PCI_EXP_FLAGS_SLOT;
1257 printf("Downstream Port (Slot%c)", FLAG(cap, PCI_EXP_FLAGS_SLOT));
1259 case PCI_EXP_TYPE_PCI_BRIDGE:
1260 printf("PCI/PCI-X Bridge");
1262 case PCI_EXP_TYPE_PCIE_BRIDGE:
1263 printf("PCI/PCI-X to PCI-Express Bridge");
1265 case PCI_EXP_TYPE_ROOT_INT_EP:
1266 printf("Root Complex Integrated Endpoint");
1268 case PCI_EXP_TYPE_ROOT_EC:
1269 printf("Root Complex Event Collector");
1272 printf("Unknown type %d", type);
1274 printf(" IRQ %d\n", (cap & PCI_EXP_FLAGS_IRQ) >> 9);
1281 if (type == PCI_EXP_TYPE_ROOT_PORT)
1283 if (!config_fetch(d, where + PCI_EXP_DEVCAP, size))
1286 show_express_dev(d, where, type);
1287 show_express_link(d, where, type);
1289 show_express_slot(d, where);
1290 if (type == PCI_EXP_TYPE_ROOT_PORT)
1291 show_express_root(d, where);
1295 show_msix(struct device *d, int where, int cap)
1299 printf("MSI-X: Enable%c Mask%c TabSize=%d\n",
1300 FLAG(cap, PCI_MSIX_ENABLE),
1301 FLAG(cap, PCI_MSIX_MASK),
1302 (cap & PCI_MSIX_TABSIZE) + 1);
1303 if (verbose < 2 || !config_fetch(d, where + PCI_MSIX_TABLE, 8))
1306 off = get_conf_long(d, where + PCI_MSIX_TABLE);
1307 printf("\t\tVector table: BAR=%d offset=%08x\n",
1308 off & PCI_MSIX_BIR, off & ~PCI_MSIX_BIR);
1309 off = get_conf_long(d, where + PCI_MSIX_PBA);
1310 printf("\t\tPBA: BAR=%d offset=%08x\n",
1311 off & PCI_MSIX_BIR, off & ~PCI_MSIX_BIR);
1315 show_slotid(int cap)
1317 int esr = cap & 0xff;
1320 printf("Slot ID: %d slots, First%c, chassis %02x\n",
1321 esr & PCI_SID_ESR_NSLOTS,
1322 FLAG(esr, PCI_SID_ESR_FIC),
1327 show_ssvid(struct device *d, int where)
1329 u16 subsys_v, subsys_d;
1330 char ssnamebuf[256];
1332 if (!config_fetch(d, where, 8))
1334 subsys_v = get_conf_word(d, where + PCI_SSVID_VENDOR);
1335 subsys_d = get_conf_word(d, where + PCI_SSVID_DEVICE);
1336 printf("Subsystem: %s\n",
1337 pci_lookup_name(pacc, ssnamebuf, sizeof(ssnamebuf),
1338 PCI_LOOKUP_SUBSYSTEM | PCI_LOOKUP_VENDOR | PCI_LOOKUP_DEVICE,
1339 d->dev->vendor_id, d->dev->device_id, subsys_v, subsys_d));
1343 show_aer(struct device *d UNUSED, int where UNUSED)
1345 printf("Advanced Error Reporting\n");
1349 show_vc(struct device *d UNUSED, int where UNUSED)
1351 printf("Virtual Channel\n");
1355 show_dsn(struct device *d, int where)
1358 if (!config_fetch(d, where + 4, 8))
1360 t1 = get_conf_long(d, where + 4);
1361 t2 = get_conf_long(d, where + 8);
1362 printf("Device Serial Number %02x-%02x-%02x-%02x-%02x-%02x-%02x-%02x\n",
1363 t1 & 0xff, (t1 >> 8) & 0xff, (t1 >> 16) & 0xff, t1 >> 24,
1364 t2 & 0xff, (t2 >> 8) & 0xff, (t2 >> 16) & 0xff, t2 >> 24);
1368 show_pb(struct device *d UNUSED, int where UNUSED)
1370 printf("Power Budgeting\n");
1374 show_ext_caps(struct device *d)
1377 char been_there[0x1000];
1378 memset(been_there, 0, 0x1000);
1384 if (!config_fetch(d, where, 4))
1386 header = get_conf_long(d, where);
1389 id = header & 0xffff;
1390 printf("\tCapabilities: [%03x] ", where);
1391 if (been_there[where++])
1393 printf("<chain looped>\n");
1398 case PCI_EXT_CAP_ID_AER:
1401 case PCI_EXT_CAP_ID_VC:
1404 case PCI_EXT_CAP_ID_DSN:
1407 case PCI_EXT_CAP_ID_PB:
1411 printf("Unknown (%d)\n", id);
1414 where = header >> 20;
1419 show_caps(struct device *d)
1421 int can_have_ext_caps = 0;
1423 if (get_conf_word(d, PCI_STATUS) & PCI_STATUS_CAP_LIST)
1425 int where = get_conf_byte(d, PCI_CAPABILITY_LIST) & ~3;
1426 byte been_there[256];
1427 memset(been_there, 0, 256);
1431 printf("\tCapabilities: ");
1432 if (!config_fetch(d, where, 4))
1434 puts("<access denied>");
1437 id = get_conf_byte(d, where + PCI_CAP_LIST_ID);
1438 next = get_conf_byte(d, where + PCI_CAP_LIST_NEXT) & ~3;
1439 cap = get_conf_word(d, where + PCI_CAP_FLAGS);
1440 printf("[%02x] ", where);
1441 if (been_there[where]++)
1443 printf("<chain looped>\n");
1448 printf("<chain broken>\n");
1454 show_pm(d, where, cap);
1456 case PCI_CAP_ID_AGP:
1457 show_agp(d, where, cap);
1459 case PCI_CAP_ID_VPD:
1460 printf("Vital Product Data\n");
1462 case PCI_CAP_ID_SLOTID:
1465 case PCI_CAP_ID_MSI:
1466 show_msi(d, where, cap);
1468 case PCI_CAP_ID_PCIX:
1469 show_pcix(d, where);
1470 can_have_ext_caps = 1;
1473 show_ht(d, where, cap);
1475 case PCI_CAP_ID_VNDR:
1478 case PCI_CAP_ID_DBG:
1481 case PCI_CAP_ID_SSVID:
1482 show_ssvid(d, where);
1484 case PCI_CAP_ID_EXP:
1485 show_express(d, where, cap);
1486 can_have_ext_caps = 1;
1488 case PCI_CAP_ID_MSIX:
1489 show_msix(d, where, cap);
1492 printf("#%02x [%04x]\n", id, cap);
1497 if (can_have_ext_caps)
1502 show_htype0(struct device *d)
1505 show_rom(d, PCI_ROM_ADDRESS);
1510 show_htype1(struct device *d)
1512 u32 io_base = get_conf_byte(d, PCI_IO_BASE);
1513 u32 io_limit = get_conf_byte(d, PCI_IO_LIMIT);
1514 u32 io_type = io_base & PCI_IO_RANGE_TYPE_MASK;
1515 u32 mem_base = get_conf_word(d, PCI_MEMORY_BASE);
1516 u32 mem_limit = get_conf_word(d, PCI_MEMORY_LIMIT);
1517 u32 mem_type = mem_base & PCI_MEMORY_RANGE_TYPE_MASK;
1518 u32 pref_base = get_conf_word(d, PCI_PREF_MEMORY_BASE);
1519 u32 pref_limit = get_conf_word(d, PCI_PREF_MEMORY_LIMIT);
1520 u32 pref_type = pref_base & PCI_PREF_RANGE_TYPE_MASK;
1521 word sec_stat = get_conf_word(d, PCI_SEC_STATUS);
1522 word brc = get_conf_word(d, PCI_BRIDGE_CONTROL);
1523 int verb = verbose > 2;
1526 printf("\tBus: primary=%02x, secondary=%02x, subordinate=%02x, sec-latency=%d\n",
1527 get_conf_byte(d, PCI_PRIMARY_BUS),
1528 get_conf_byte(d, PCI_SECONDARY_BUS),
1529 get_conf_byte(d, PCI_SUBORDINATE_BUS),
1530 get_conf_byte(d, PCI_SEC_LATENCY_TIMER));
1532 if (io_type != (io_limit & PCI_IO_RANGE_TYPE_MASK) ||
1533 (io_type != PCI_IO_RANGE_TYPE_16 && io_type != PCI_IO_RANGE_TYPE_32))
1534 printf("\t!!! Unknown I/O range types %x/%x\n", io_base, io_limit);
1537 io_base = (io_base & PCI_IO_RANGE_MASK) << 8;
1538 io_limit = (io_limit & PCI_IO_RANGE_MASK) << 8;
1539 if (io_type == PCI_IO_RANGE_TYPE_32)
1541 io_base |= (get_conf_word(d, PCI_IO_BASE_UPPER16) << 16);
1542 io_limit |= (get_conf_word(d, PCI_IO_LIMIT_UPPER16) << 16);
1544 if (io_base <= io_limit || verb)
1545 printf("\tI/O behind bridge: %08x-%08x\n", io_base, io_limit+0xfff);
1548 if (mem_type != (mem_limit & PCI_MEMORY_RANGE_TYPE_MASK) ||
1550 printf("\t!!! Unknown memory range types %x/%x\n", mem_base, mem_limit);
1553 mem_base = (mem_base & PCI_MEMORY_RANGE_MASK) << 16;
1554 mem_limit = (mem_limit & PCI_MEMORY_RANGE_MASK) << 16;
1555 if (mem_base <= mem_limit || verb)
1556 printf("\tMemory behind bridge: %08x-%08x\n", mem_base, mem_limit + 0xfffff);
1559 if (pref_type != (pref_limit & PCI_PREF_RANGE_TYPE_MASK) ||
1560 (pref_type != PCI_PREF_RANGE_TYPE_32 && pref_type != PCI_PREF_RANGE_TYPE_64))
1561 printf("\t!!! Unknown prefetchable memory range types %x/%x\n", pref_base, pref_limit);
1564 pref_base = (pref_base & PCI_PREF_RANGE_MASK) << 16;
1565 pref_limit = (pref_limit & PCI_PREF_RANGE_MASK) << 16;
1566 if (pref_base <= pref_limit || verb)
1568 if (pref_type == PCI_PREF_RANGE_TYPE_32)
1569 printf("\tPrefetchable memory behind bridge: %08x-%08x\n", pref_base, pref_limit + 0xfffff);
1571 printf("\tPrefetchable memory behind bridge: %08x%08x-%08x%08x\n",
1572 get_conf_long(d, PCI_PREF_BASE_UPPER32),
1574 get_conf_long(d, PCI_PREF_LIMIT_UPPER32),
1575 pref_limit + 0xfffff);
1580 printf("\tSecondary status: 66MHz%c FastB2B%c ParErr%c DEVSEL=%s >TAbort%c <TAbort%c <MAbort%c <SERR%c <PERR%c\n",
1581 FLAG(sec_stat, PCI_STATUS_66MHZ),
1582 FLAG(sec_stat, PCI_STATUS_FAST_BACK),
1583 FLAG(sec_stat, PCI_STATUS_PARITY),
1584 ((sec_stat & PCI_STATUS_DEVSEL_MASK) == PCI_STATUS_DEVSEL_SLOW) ? "slow" :
1585 ((sec_stat & PCI_STATUS_DEVSEL_MASK) == PCI_STATUS_DEVSEL_MEDIUM) ? "medium" :
1586 ((sec_stat & PCI_STATUS_DEVSEL_MASK) == PCI_STATUS_DEVSEL_FAST) ? "fast" : "??",
1587 FLAG(sec_stat, PCI_STATUS_SIG_TARGET_ABORT),
1588 FLAG(sec_stat, PCI_STATUS_REC_TARGET_ABORT),
1589 FLAG(sec_stat, PCI_STATUS_REC_MASTER_ABORT),
1590 FLAG(sec_stat, PCI_STATUS_SIG_SYSTEM_ERROR),
1591 FLAG(sec_stat, PCI_STATUS_DETECTED_PARITY));
1593 show_rom(d, PCI_ROM_ADDRESS1);
1596 printf("\tBridgeCtl: Parity%c SERR%c NoISA%c VGA%c MAbort%c >Reset%c FastB2B%c\n",
1597 FLAG(brc, PCI_BRIDGE_CTL_PARITY),
1598 FLAG(brc, PCI_BRIDGE_CTL_SERR),
1599 FLAG(brc, PCI_BRIDGE_CTL_NO_ISA),
1600 FLAG(brc, PCI_BRIDGE_CTL_VGA),
1601 FLAG(brc, PCI_BRIDGE_CTL_MASTER_ABORT),
1602 FLAG(brc, PCI_BRIDGE_CTL_BUS_RESET),
1603 FLAG(brc, PCI_BRIDGE_CTL_FAST_BACK));
1609 show_htype2(struct device *d)
1612 word cmd = get_conf_word(d, PCI_COMMAND);
1613 word brc = get_conf_word(d, PCI_CB_BRIDGE_CONTROL);
1615 int verb = verbose > 2;
1618 printf("\tBus: primary=%02x, secondary=%02x, subordinate=%02x, sec-latency=%d\n",
1619 get_conf_byte(d, PCI_CB_PRIMARY_BUS),
1620 get_conf_byte(d, PCI_CB_CARD_BUS),
1621 get_conf_byte(d, PCI_CB_SUBORDINATE_BUS),
1622 get_conf_byte(d, PCI_CB_LATENCY_TIMER));
1626 u32 base = get_conf_long(d, PCI_CB_MEMORY_BASE_0 + p);
1627 u32 limit = get_conf_long(d, PCI_CB_MEMORY_LIMIT_0 + p);
1628 if (limit > base || verb)
1629 printf("\tMemory window %d: %08x-%08x%s%s\n", i, base, limit,
1630 (cmd & PCI_COMMAND_MEMORY) ? "" : " [disabled]",
1631 (brc & (PCI_CB_BRIDGE_CTL_PREFETCH_MEM0 << i)) ? " (prefetchable)" : "");
1636 u32 base = get_conf_long(d, PCI_CB_IO_BASE_0 + p);
1637 u32 limit = get_conf_long(d, PCI_CB_IO_LIMIT_0 + p);
1638 if (!(base & PCI_IO_RANGE_TYPE_32))
1643 base &= PCI_CB_IO_RANGE_MASK;
1644 limit = (limit & PCI_CB_IO_RANGE_MASK) + 3;
1645 if (base <= limit || verb)
1646 printf("\tI/O window %d: %08x-%08x%s\n", i, base, limit,
1647 (cmd & PCI_COMMAND_IO) ? "" : " [disabled]");
1650 if (get_conf_word(d, PCI_CB_SEC_STATUS) & PCI_STATUS_SIG_SYSTEM_ERROR)
1651 printf("\tSecondary status: SERR\n");
1653 printf("\tBridgeCtl: Parity%c SERR%c ISA%c VGA%c MAbort%c >Reset%c 16bInt%c PostWrite%c\n",
1654 FLAG(brc, PCI_CB_BRIDGE_CTL_PARITY),
1655 FLAG(brc, PCI_CB_BRIDGE_CTL_SERR),
1656 FLAG(brc, PCI_CB_BRIDGE_CTL_ISA),
1657 FLAG(brc, PCI_CB_BRIDGE_CTL_VGA),
1658 FLAG(brc, PCI_CB_BRIDGE_CTL_MASTER_ABORT),
1659 FLAG(brc, PCI_CB_BRIDGE_CTL_CB_RESET),
1660 FLAG(brc, PCI_CB_BRIDGE_CTL_16BIT_INT),
1661 FLAG(brc, PCI_CB_BRIDGE_CTL_POST_WRITES));
1663 if (d->config_cached < 128)
1665 printf("\t<access denied to the rest>\n");
1669 exca = get_conf_word(d, PCI_CB_LEGACY_MODE_BASE);
1671 printf("\t16-bit legacy interface ports at %04x\n", exca);
1675 show_verbose(struct device *d)
1677 struct pci_dev *p = d->dev;
1678 word status = get_conf_word(d, PCI_STATUS);
1679 word cmd = get_conf_word(d, PCI_COMMAND);
1680 word class = p->device_class;
1681 byte bist = get_conf_byte(d, PCI_BIST);
1682 byte htype = get_conf_byte(d, PCI_HEADER_TYPE) & 0x7f;
1683 byte latency = get_conf_byte(d, PCI_LATENCY_TIMER);
1684 byte cache_line = get_conf_byte(d, PCI_CACHE_LINE_SIZE);
1685 byte max_lat, min_gnt;
1686 byte int_pin = get_conf_byte(d, PCI_INTERRUPT_PIN);
1687 unsigned int irq = p->irq;
1688 word subsys_v = 0, subsys_d = 0;
1689 char ssnamebuf[256];
1695 case PCI_HEADER_TYPE_NORMAL:
1696 if (class == PCI_CLASS_BRIDGE_PCI)
1697 printf("\t!!! Invalid class %04x for header type %02x\n", class, htype);
1698 max_lat = get_conf_byte(d, PCI_MAX_LAT);
1699 min_gnt = get_conf_byte(d, PCI_MIN_GNT);
1700 subsys_v = get_conf_word(d, PCI_SUBSYSTEM_VENDOR_ID);
1701 subsys_d = get_conf_word(d, PCI_SUBSYSTEM_ID);
1703 case PCI_HEADER_TYPE_BRIDGE:
1704 if ((class >> 8) != PCI_BASE_CLASS_BRIDGE)
1705 printf("\t!!! Invalid class %04x for header type %02x\n", class, htype);
1706 irq = int_pin = min_gnt = max_lat = 0;
1708 case PCI_HEADER_TYPE_CARDBUS:
1709 if ((class >> 8) != PCI_BASE_CLASS_BRIDGE)
1710 printf("\t!!! Invalid class %04x for header type %02x\n", class, htype);
1711 min_gnt = max_lat = 0;
1712 if (d->config_cached >= 128)
1714 subsys_v = get_conf_word(d, PCI_CB_SUBSYSTEM_VENDOR_ID);
1715 subsys_d = get_conf_word(d, PCI_CB_SUBSYSTEM_ID);
1719 printf("\t!!! Unknown header type %02x\n", htype);
1723 if (subsys_v && subsys_v != 0xffff)
1724 printf("\tSubsystem: %s\n",
1725 pci_lookup_name(pacc, ssnamebuf, sizeof(ssnamebuf),
1726 PCI_LOOKUP_SUBSYSTEM | PCI_LOOKUP_VENDOR | PCI_LOOKUP_DEVICE,
1727 p->vendor_id, p->device_id, subsys_v, subsys_d));
1731 printf("\tControl: I/O%c Mem%c BusMaster%c SpecCycle%c MemWINV%c VGASnoop%c ParErr%c Stepping%c SERR%c FastB2B%c\n",
1732 FLAG(cmd, PCI_COMMAND_IO),
1733 FLAG(cmd, PCI_COMMAND_MEMORY),
1734 FLAG(cmd, PCI_COMMAND_MASTER),
1735 FLAG(cmd, PCI_COMMAND_SPECIAL),
1736 FLAG(cmd, PCI_COMMAND_INVALIDATE),
1737 FLAG(cmd, PCI_COMMAND_VGA_PALETTE),
1738 FLAG(cmd, PCI_COMMAND_PARITY),
1739 FLAG(cmd, PCI_COMMAND_WAIT),
1740 FLAG(cmd, PCI_COMMAND_SERR),
1741 FLAG(cmd, PCI_COMMAND_FAST_BACK));
1742 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",
1743 FLAG(status, PCI_STATUS_CAP_LIST),
1744 FLAG(status, PCI_STATUS_66MHZ),
1745 FLAG(status, PCI_STATUS_UDF),
1746 FLAG(status, PCI_STATUS_FAST_BACK),
1747 FLAG(status, PCI_STATUS_PARITY),
1748 ((status & PCI_STATUS_DEVSEL_MASK) == PCI_STATUS_DEVSEL_SLOW) ? "slow" :
1749 ((status & PCI_STATUS_DEVSEL_MASK) == PCI_STATUS_DEVSEL_MEDIUM) ? "medium" :
1750 ((status & PCI_STATUS_DEVSEL_MASK) == PCI_STATUS_DEVSEL_FAST) ? "fast" : "??",
1751 FLAG(status, PCI_STATUS_SIG_TARGET_ABORT),
1752 FLAG(status, PCI_STATUS_REC_TARGET_ABORT),
1753 FLAG(status, PCI_STATUS_REC_MASTER_ABORT),
1754 FLAG(status, PCI_STATUS_SIG_SYSTEM_ERROR),
1755 FLAG(status, PCI_STATUS_DETECTED_PARITY));
1756 if (cmd & PCI_COMMAND_MASTER)
1758 printf("\tLatency: %d", latency);
1759 if (min_gnt || max_lat)
1763 printf("%dns min", min_gnt*250);
1764 if (min_gnt && max_lat)
1767 printf("%dns max", max_lat*250);
1771 printf(", Cache Line Size: %d bytes", cache_line * 4);
1775 printf("\tInterrupt: pin %c routed to IRQ " PCIIRQ_FMT "\n",
1776 (int_pin ? 'A' + int_pin - 1 : '?'), irq);
1780 printf("\tFlags: ");
1781 if (cmd & PCI_COMMAND_MASTER)
1782 printf("bus master, ");
1783 if (cmd & PCI_COMMAND_VGA_PALETTE)
1784 printf("VGA palette snoop, ");
1785 if (cmd & PCI_COMMAND_WAIT)
1786 printf("stepping, ");
1787 if (cmd & PCI_COMMAND_FAST_BACK)
1788 printf("fast Back2Back, ");
1789 if (status & PCI_STATUS_66MHZ)
1791 if (status & PCI_STATUS_UDF)
1792 printf("user-definable features, ");
1794 ((status & PCI_STATUS_DEVSEL_MASK) == PCI_STATUS_DEVSEL_SLOW) ? "slow" :
1795 ((status & PCI_STATUS_DEVSEL_MASK) == PCI_STATUS_DEVSEL_MEDIUM) ? "medium" :
1796 ((status & PCI_STATUS_DEVSEL_MASK) == PCI_STATUS_DEVSEL_FAST) ? "fast" : "??");
1797 if (cmd & PCI_COMMAND_MASTER)
1798 printf(", latency %d", latency);
1800 printf(", IRQ " PCIIRQ_FMT, irq);
1804 if (bist & PCI_BIST_CAPABLE)
1806 if (bist & PCI_BIST_START)
1807 printf("\tBIST is running\n");
1809 printf("\tBIST result: %02x\n", bist & PCI_BIST_CODE_MASK);
1814 case PCI_HEADER_TYPE_NORMAL:
1817 case PCI_HEADER_TYPE_BRIDGE:
1820 case PCI_HEADER_TYPE_CARDBUS:
1827 show_hex_dump(struct device *d)
1829 unsigned int i, cnt;
1831 cnt = d->config_cached;
1832 if (show_hex >= 3 && config_fetch(d, cnt, 256-cnt))
1835 if (show_hex >= 4 && config_fetch(d, 256, 4096-256))
1839 for(i=0; i<cnt; i++)
1843 printf(" %02x", get_conf_byte(d, i));
1850 print_shell_escaped(char *c)
1855 if (*c == '"' || *c == '\\')
1863 show_machine(struct device *d)
1865 struct pci_dev *p = d->dev;
1867 word sv_id=0, sd_id=0;
1868 char classbuf[128], vendbuf[128], devbuf[128], svbuf[128], sdbuf[128];
1870 switch (get_conf_byte(d, PCI_HEADER_TYPE) & 0x7f)
1872 case PCI_HEADER_TYPE_NORMAL:
1873 sv_id = get_conf_word(d, PCI_SUBSYSTEM_VENDOR_ID);
1874 sd_id = get_conf_word(d, PCI_SUBSYSTEM_ID);
1876 case PCI_HEADER_TYPE_CARDBUS:
1877 if (d->config_cached >= 128)
1879 sv_id = get_conf_word(d, PCI_CB_SUBSYSTEM_VENDOR_ID);
1880 sd_id = get_conf_word(d, PCI_CB_SUBSYSTEM_ID);
1887 printf((machine_readable >= 2) ? "Slot:\t" : "Device:\t");
1890 printf("Class:\t%s\n",
1891 pci_lookup_name(pacc, classbuf, sizeof(classbuf), PCI_LOOKUP_CLASS, p->device_class));
1892 printf("Vendor:\t%s\n",
1893 pci_lookup_name(pacc, vendbuf, sizeof(vendbuf), PCI_LOOKUP_VENDOR, p->vendor_id, p->device_id));
1894 printf("Device:\t%s\n",
1895 pci_lookup_name(pacc, devbuf, sizeof(devbuf), PCI_LOOKUP_DEVICE, p->vendor_id, p->device_id));
1896 if (sv_id && sv_id != 0xffff)
1898 printf("SVendor:\t%s\n",
1899 pci_lookup_name(pacc, svbuf, sizeof(svbuf), PCI_LOOKUP_SUBSYSTEM | PCI_LOOKUP_VENDOR, sv_id));
1900 printf("SDevice:\t%s\n",
1901 pci_lookup_name(pacc, sdbuf, sizeof(sdbuf), PCI_LOOKUP_SUBSYSTEM | PCI_LOOKUP_DEVICE, p->vendor_id, p->device_id, sv_id, sd_id));
1903 if (c = get_conf_byte(d, PCI_REVISION_ID))
1904 printf("Rev:\t%02x\n", c);
1905 if (c = get_conf_byte(d, PCI_CLASS_PROG))
1906 printf("ProgIf:\t%02x\n", c);
1911 print_shell_escaped(pci_lookup_name(pacc, classbuf, sizeof(classbuf), PCI_LOOKUP_CLASS, p->device_class));
1912 print_shell_escaped(pci_lookup_name(pacc, vendbuf, sizeof(vendbuf), PCI_LOOKUP_VENDOR, p->vendor_id, p->device_id));
1913 print_shell_escaped(pci_lookup_name(pacc, devbuf, sizeof(devbuf), PCI_LOOKUP_DEVICE, p->vendor_id, p->device_id));
1914 if (c = get_conf_byte(d, PCI_REVISION_ID))
1915 printf(" -r%02x", c);
1916 if (c = get_conf_byte(d, PCI_CLASS_PROG))
1917 printf(" -p%02x", c);
1918 if (sv_id && sv_id != 0xffff)
1920 print_shell_escaped(pci_lookup_name(pacc, svbuf, sizeof(svbuf), PCI_LOOKUP_SUBSYSTEM | PCI_LOOKUP_VENDOR, sv_id));
1921 print_shell_escaped(pci_lookup_name(pacc, sdbuf, sizeof(sdbuf), PCI_LOOKUP_SUBSYSTEM | PCI_LOOKUP_DEVICE, p->vendor_id, p->device_id, sv_id, sd_id));
1924 printf(" \"\" \"\"");
1930 show_device(struct device *d)
1932 if (machine_readable)
1940 if (verbose || show_hex)
1949 for(d=first_dev; d; d=d->next)
1956 struct bridge *chain; /* Single-linked list of bridges */
1957 struct bridge *next, *child; /* Tree of bridges */
1958 struct bus *first_bus; /* List of buses connected to this bridge */
1959 unsigned int domain;
1960 unsigned int primary, secondary, subordinate; /* Bus numbers */
1961 struct device *br_dev;
1965 unsigned int domain;
1966 unsigned int number;
1967 struct bus *sibling;
1968 struct device *first_dev, **last_dev;
1971 static struct bridge host_bridge = { NULL, NULL, NULL, NULL, 0, ~0, 0, ~0, NULL };
1974 find_bus(struct bridge *b, unsigned int domain, unsigned int n)
1978 for(bus=b->first_bus; bus; bus=bus->sibling)
1979 if (bus->domain == domain && bus->number == n)
1985 new_bus(struct bridge *b, unsigned int domain, unsigned int n)
1987 struct bus *bus = xmalloc(sizeof(struct bus));
1988 bus->domain = domain;
1990 bus->sibling = b->first_bus;
1991 bus->first_dev = NULL;
1992 bus->last_dev = &bus->first_dev;
1998 insert_dev(struct device *d, struct bridge *b)
2000 struct pci_dev *p = d->dev;
2003 if (! (bus = find_bus(b, p->domain, p->bus)))
2006 for(c=b->child; c; c=c->next)
2007 if (c->domain == p->domain && c->secondary <= p->bus && p->bus <= c->subordinate)
2012 bus = new_bus(b, p->domain, p->bus);
2014 /* Simple insertion at the end _does_ guarantee the correct order as the
2015 * original device list was sorted by (domain, bus, devfn) lexicographically
2016 * and all devices on the new list have the same bus number.
2019 bus->last_dev = &d->next;
2026 struct device *d, *d2;
2027 struct bridge **last_br, *b;
2029 /* Build list of bridges */
2031 last_br = &host_bridge.chain;
2032 for(d=first_dev; d; d=d->next)
2034 word class = d->dev->device_class;
2035 byte ht = get_conf_byte(d, PCI_HEADER_TYPE) & 0x7f;
2036 if (class == PCI_CLASS_BRIDGE_PCI &&
2037 (ht == PCI_HEADER_TYPE_BRIDGE || ht == PCI_HEADER_TYPE_CARDBUS))
2039 b = xmalloc(sizeof(struct bridge));
2040 b->domain = d->dev->domain;
2041 if (ht == PCI_HEADER_TYPE_BRIDGE)
2043 b->primary = get_conf_byte(d, PCI_PRIMARY_BUS);
2044 b->secondary = get_conf_byte(d, PCI_SECONDARY_BUS);
2045 b->subordinate = get_conf_byte(d, PCI_SUBORDINATE_BUS);
2049 b->primary = get_conf_byte(d, PCI_CB_PRIMARY_BUS);
2050 b->secondary = get_conf_byte(d, PCI_CB_CARD_BUS);
2051 b->subordinate = get_conf_byte(d, PCI_CB_SUBORDINATE_BUS);
2054 last_br = &b->chain;
2055 b->next = b->child = NULL;
2056 b->first_bus = NULL;
2062 /* Create a bridge tree */
2064 for(b=&host_bridge; b; b=b->chain)
2066 struct bridge *c, *best;
2068 for(c=&host_bridge; c; c=c->chain)
2069 if (c != b && (c == &host_bridge || b->domain == c->domain) &&
2070 b->primary >= c->secondary && b->primary <= c->subordinate &&
2071 (!best || best->subordinate - best->primary > c->subordinate - c->primary))
2075 b->next = best->child;
2080 /* Insert secondary bus for each bridge */
2082 for(b=&host_bridge; b; b=b->chain)
2083 if (!find_bus(b, b->domain, b->secondary))
2084 new_bus(b, b->domain, b->secondary);
2086 /* Create bus structs and link devices */
2088 for(d=first_dev; d;)
2091 insert_dev(d, &host_bridge);
2097 print_it(char *line, char *p)
2101 fputs(line, stdout);
2102 for(p=line; *p; p++)
2103 if (*p == '+' || *p == '|')
2109 static void show_tree_bridge(struct bridge *, char *, char *);
2112 show_tree_dev(struct device *d, char *line, char *p)
2114 struct pci_dev *q = d->dev;
2118 p += sprintf(p, "%02x.%x", q->dev, q->func);
2119 for(b=&host_bridge; b; b=b->chain)
2122 if (b->secondary == b->subordinate)
2123 p += sprintf(p, "-[%04x:%02x]-", b->domain, b->secondary);
2125 p += sprintf(p, "-[%04x:%02x-%02x]-", b->domain, b->secondary, b->subordinate);
2126 show_tree_bridge(b, line, p);
2130 p += sprintf(p, " %s",
2131 pci_lookup_name(pacc, namebuf, sizeof(namebuf),
2132 PCI_LOOKUP_VENDOR | PCI_LOOKUP_DEVICE,
2133 q->vendor_id, q->device_id));
2138 show_tree_bus(struct bus *b, char *line, char *p)
2142 else if (!b->first_dev->next)
2146 show_tree_dev(b->first_dev, line, p);
2150 struct device *d = b->first_dev;
2155 show_tree_dev(d, line, p+2);
2160 show_tree_dev(d, line, p+2);
2165 show_tree_bridge(struct bridge *b, char *line, char *p)
2168 if (!b->first_bus->sibling)
2170 if (b == &host_bridge)
2171 p += sprintf(p, "[%04x:%02x]-", b->domain, b->first_bus->number);
2172 show_tree_bus(b->first_bus, line, p);
2176 struct bus *u = b->first_bus;
2181 k = p + sprintf(p, "+-[%04x:%02x]-", u->domain, u->number);
2182 show_tree_bus(u, line, k);
2185 k = p + sprintf(p, "\\-[%04x:%02x]-", u->domain, u->number);
2186 show_tree_bus(u, line, k);
2196 show_tree_bridge(&host_bridge, line, line);
2199 /* Bus mapping mode */
2202 struct bus_bridge *next;
2203 byte this, dev, func, first, last, bug;
2209 struct bus_bridge *bridges, *via;
2212 static struct bus_info *bus_info;
2215 map_bridge(struct bus_info *bi, struct device *d, int np, int ns, int nl)
2217 struct bus_bridge *b = xmalloc(sizeof(struct bus_bridge));
2218 struct pci_dev *p = d->dev;
2220 b->next = bi->bridges;
2222 b->this = get_conf_byte(d, np);
2225 b->first = get_conf_byte(d, ns);
2226 b->last = get_conf_byte(d, nl);
2227 printf("## %02x.%02x:%d is a bridge from %02x to %02x-%02x\n",
2228 p->bus, p->dev, p->func, b->this, b->first, b->last);
2229 if (b->this != p->bus)
2230 printf("!!! Bridge points to invalid primary bus.\n");
2231 if (b->first > b->last)
2233 printf("!!! Bridge points to invalid bus range.\n");
2242 int verbose = pacc->debugging;
2243 struct bus_info *bi = bus_info + bus;
2247 printf("Mapping bus %02x\n", bus);
2248 for(dev = 0; dev < 32; dev++)
2249 if (filter.slot < 0 || filter.slot == dev)
2252 for(func = 0; func < func_limit; func++)
2253 if (filter.func < 0 || filter.func == func)
2255 /* XXX: Bus mapping supports only domain 0 */
2256 struct pci_dev *p = pci_get_dev(pacc, 0, bus, dev, func);
2257 u16 vendor = pci_read_word(p, PCI_VENDOR_ID);
2258 if (vendor && vendor != 0xffff)
2260 if (!func && (pci_read_byte(p, PCI_HEADER_TYPE) & 0x80))
2263 printf("Discovered device %02x:%02x.%d\n", bus, dev, func);
2265 if (d = scan_device(p))
2268 switch (get_conf_byte(d, PCI_HEADER_TYPE) & 0x7f)
2270 case PCI_HEADER_TYPE_BRIDGE:
2271 map_bridge(bi, d, PCI_PRIMARY_BUS, PCI_SECONDARY_BUS, PCI_SUBORDINATE_BUS);
2273 case PCI_HEADER_TYPE_CARDBUS:
2274 map_bridge(bi, d, PCI_CB_PRIMARY_BUS, PCI_CB_CARD_BUS, PCI_CB_SUBORDINATE_BUS);
2280 printf("But it was filtered out.\n");
2288 do_map_bridges(int bus, int min, int max)
2290 struct bus_info *bi = bus_info + bus;
2291 struct bus_bridge *b;
2294 for(b=bi->bridges; b; b=b->next)
2296 if (bus_info[b->first].guestbook)
2298 else if (b->first < min || b->last > max)
2302 bus_info[b->first].via = b;
2303 do_map_bridges(b->first, b->first, b->last);
2313 printf("\nSummary of buses:\n\n");
2314 for(i=0; i<256; i++)
2315 if (bus_info[i].exists && !bus_info[i].guestbook)
2316 do_map_bridges(i, 0, 255);
2317 for(i=0; i<256; i++)
2319 struct bus_info *bi = bus_info + i;
2320 struct bus_bridge *b = bi->via;
2324 printf("%02x: ", i);
2326 printf("Entered via %02x:%02x.%d\n", b->this, b->dev, b->func);
2328 printf("Primary host bus\n");
2330 printf("Secondary host bus (?)\n");
2332 for(b=bi->bridges; b; b=b->next)
2334 printf("\t%02x.%d Bridge to %02x-%02x", b->dev, b->func, b->first, b->last);
2338 printf(" <overlap bug>");
2341 printf(" <crossing bug>");
2352 if (pacc->method == PCI_ACCESS_PROC_BUS_PCI ||
2353 pacc->method == PCI_ACCESS_DUMP)
2354 printf("WARNING: Bus mapping can be reliable only with direct hardware access enabled.\n\n");
2355 bus_info = xmalloc(sizeof(struct bus_info) * 256);
2356 memset(bus_info, 0, sizeof(struct bus_info) * 256);
2357 if (filter.bus >= 0)
2358 do_map_bus(filter.bus);
2362 for(bus=0; bus<256; bus++)
2371 main(int argc, char **argv)
2376 if (argc == 2 && !strcmp(argv[1], "--version"))
2378 puts("lspci version " PCIUTILS_VERSION);
2384 pci_filter_init(pacc, &filter);
2386 while ((i = getopt(argc, argv, options)) != -1)
2390 pacc->numeric_ids++;
2396 pacc->buscentric = 1;
2397 buscentric_view = 1;
2400 if (msg = pci_filter_parse_slot(&filter, optarg))
2404 if (msg = pci_filter_parse_id(&filter, optarg))
2414 pci_set_name_list_path(pacc, optarg, 0);
2426 if (parse_generic_option(i, pacc, optarg))
2429 fprintf(stderr, help_msg, pacc->id_file_name);
2449 return (seen_errors ? 2 : 0);