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
66 #define alloca xmalloc
69 /* Our view of the PCI bus */
74 unsigned int config_cached, config_bufsize;
75 byte *config; /* Cached configuration space data */
76 byte *present; /* Maps which configuration bytes are present */
79 static struct device *first_dev;
80 static int seen_errors;
83 config_fetch(struct device *d, unsigned int pos, unsigned int len)
85 unsigned int end = pos+len;
88 while (pos < d->config_bufsize && len && d->present[pos])
90 while (pos+len <= d->config_bufsize && len && d->present[pos+len-1])
95 if (end > d->config_bufsize)
97 int orig_size = d->config_bufsize;
98 while (end > d->config_bufsize)
99 d->config_bufsize *= 2;
100 d->config = xrealloc(d->config, d->config_bufsize);
101 d->present = xrealloc(d->present, d->config_bufsize);
102 memset(d->present + orig_size, 0, d->config_bufsize - orig_size);
104 result = pci_read_block(d->dev, pos, d->config + pos, len);
106 memset(d->present + pos, 1, len);
110 static struct device *
111 scan_device(struct pci_dev *p)
115 if (p->domain && !show_domains)
117 if (!pci_filter_match(&filter, p))
119 d = xmalloc(sizeof(struct device));
120 memset(d, 0, sizeof(*d));
122 d->config_cached = d->config_bufsize = 64;
123 d->config = xmalloc(64);
124 d->present = xmalloc(64);
125 memset(d->present, 1, 64);
126 if (!pci_read_block(p, 0, d->config, 64))
128 fprintf(stderr, "lspci: Unable to read the standard configuration space header of device %04x:%02x:%02x.%d\n",
129 p->domain, p->bus, p->dev, p->func);
133 if ((d->config[PCI_HEADER_TYPE] & 0x7f) == PCI_HEADER_TYPE_CARDBUS)
135 /* For cardbus bridges, we need to fetch 64 bytes more to get the
136 * full standard header... */
137 if (config_fetch(d, 64, 64))
138 d->config_cached += 64;
140 pci_setup_cache(p, d->config, d->config_cached);
141 pci_fill_info(p, PCI_FILL_IDENT | PCI_FILL_CLASS | PCI_FILL_IRQ | PCI_FILL_BASES | PCI_FILL_ROM_BASE | PCI_FILL_SIZES);
152 for(p=pacc->devices; p; p=p->next)
153 if (d = scan_device(p))
160 /* Config space accesses */
163 check_conf_range(struct device *d, unsigned int pos, unsigned int len)
166 if (!d->present[pos])
167 die("Internal bug: Accessing non-read configuration byte at position %x", pos);
173 get_conf_byte(struct device *d, unsigned int pos)
175 check_conf_range(d, pos, 1);
176 return d->config[pos];
180 get_conf_word(struct device *d, unsigned int pos)
182 check_conf_range(d, pos, 2);
183 return d->config[pos] | (d->config[pos+1] << 8);
187 get_conf_long(struct device *d, unsigned int pos)
189 check_conf_range(d, pos, 4);
190 return d->config[pos] |
191 (d->config[pos+1] << 8) |
192 (d->config[pos+2] << 16) |
193 (d->config[pos+3] << 24);
199 compare_them(const void *A, const void *B)
201 const struct pci_dev *a = (*(const struct device **)A)->dev;
202 const struct pci_dev *b = (*(const struct device **)B)->dev;
204 if (a->domain < b->domain)
206 if (a->domain > b->domain)
216 if (a->func < b->func)
218 if (a->func > b->func)
226 struct device **index, **h, **last_dev;
231 for(d=first_dev; d; d=d->next)
233 h = index = alloca(sizeof(struct device *) * cnt);
234 for(d=first_dev; d; d=d->next)
236 qsort(index, cnt, sizeof(struct device *), compare_them);
237 last_dev = &first_dev;
242 last_dev = &(*h)->next;
250 #define FLAG(x,y) ((x & y) ? '+' : '-')
253 show_slot_name(struct device *d)
255 struct pci_dev *p = d->dev;
257 if (!machine_readable ? show_domains : (p->domain || show_domains >= 2))
258 printf("%04x:", p->domain);
259 printf("%02x:%02x.%d", p->bus, p->dev, p->func);
263 show_terse(struct device *d)
266 struct pci_dev *p = d->dev;
267 char classbuf[128], devbuf[128];
271 pci_lookup_name(pacc, classbuf, sizeof(classbuf),
274 pci_lookup_name(pacc, devbuf, sizeof(devbuf),
275 PCI_LOOKUP_VENDOR | PCI_LOOKUP_DEVICE,
276 p->vendor_id, p->device_id));
277 if (c = get_conf_byte(d, PCI_REVISION_ID))
278 printf(" (rev %02x)", c);
282 c = get_conf_byte(d, PCI_CLASS_PROG);
283 x = pci_lookup_name(pacc, devbuf, sizeof(devbuf),
284 PCI_LOOKUP_PROGIF | PCI_LOOKUP_NO_NUMBERS,
288 printf(" (prog-if %02x", c);
298 show_size(pciaddr_t x)
304 printf("%d", (int) x);
305 else if (x < 1048576)
306 printf("%dK", (int)(x / 1024));
307 else if (x < 0x80000000)
308 printf("%dM", (int)(x / 1048576));
310 printf(PCIADDR_T_FMT, x);
315 show_bases(struct device *d, int cnt)
317 struct pci_dev *p = d->dev;
318 word cmd = get_conf_word(d, PCI_COMMAND);
323 pciaddr_t pos = p->base_addr[i];
324 pciaddr_t len = (p->known_fields & PCI_FILL_SIZES) ? p->size[i] : 0;
325 u32 flg = get_conf_long(d, PCI_BASE_ADDRESS_0 + 4*i);
326 if (flg == 0xffffffff)
328 if (!pos && !flg && !len)
331 printf("\tRegion %d: ", i);
334 if (pos && !flg) /* Reported by the OS, but not by the device */
336 printf("[virtual] ");
339 if (flg & PCI_BASE_ADDRESS_SPACE_IO)
341 pciaddr_t a = pos & PCI_BASE_ADDRESS_IO_MASK;
342 printf("I/O ports at ");
344 printf(PCIADDR_PORT_FMT, a);
345 else if (flg & PCI_BASE_ADDRESS_IO_MASK)
348 printf("<unassigned>");
349 if (!(cmd & PCI_COMMAND_IO))
350 printf(" [disabled]");
354 int t = flg & PCI_BASE_ADDRESS_MEM_TYPE_MASK;
355 pciaddr_t a = pos & PCI_ADDR_MEM_MASK;
359 printf("Memory at ");
360 if (t == PCI_BASE_ADDRESS_MEM_TYPE_64)
364 printf("<invalid-64bit-slot>");
370 z = get_conf_long(d, PCI_BASE_ADDRESS_0 + 4*i);
373 u32 y = a & 0xffffffff;
375 printf("%08x%08x", z, y);
377 printf("<unassigned>");
385 printf(PCIADDR_T_FMT, a);
387 printf(((flg & PCI_BASE_ADDRESS_MEM_MASK) || z) ? "<ignored>" : "<unassigned>");
389 printf(" (%s, %sprefetchable)",
390 (t == PCI_BASE_ADDRESS_MEM_TYPE_32) ? "32-bit" :
391 (t == PCI_BASE_ADDRESS_MEM_TYPE_64) ? "64-bit" :
392 (t == PCI_BASE_ADDRESS_MEM_TYPE_1M) ? "low-1M" : "type 3",
393 (flg & PCI_BASE_ADDRESS_MEM_PREFETCH) ? "" : "non-");
394 if (!(cmd & PCI_COMMAND_MEMORY))
395 printf(" [disabled]");
403 show_pm(struct device *d, int where, int cap)
406 static int pm_aux_current[8] = { 0, 55, 100, 160, 220, 270, 320, 375 };
408 printf("Power Management version %d\n", cap & PCI_PM_CAP_VER_MASK);
411 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",
412 FLAG(cap, PCI_PM_CAP_PME_CLOCK),
413 FLAG(cap, PCI_PM_CAP_DSI),
414 FLAG(cap, PCI_PM_CAP_D1),
415 FLAG(cap, PCI_PM_CAP_D2),
416 pm_aux_current[(cap >> 6) & 7],
417 FLAG(cap, PCI_PM_CAP_PME_D0),
418 FLAG(cap, PCI_PM_CAP_PME_D1),
419 FLAG(cap, PCI_PM_CAP_PME_D2),
420 FLAG(cap, PCI_PM_CAP_PME_D3_HOT),
421 FLAG(cap, PCI_PM_CAP_PME_D3_COLD));
422 if (!config_fetch(d, where + PCI_PM_CTRL, PCI_PM_SIZEOF - PCI_PM_CTRL))
424 t = get_conf_word(d, where + PCI_PM_CTRL);
425 printf("\t\tStatus: D%d PME-Enable%c DSel=%d DScale=%d PME%c\n",
426 t & PCI_PM_CTRL_STATE_MASK,
427 FLAG(t, PCI_PM_CTRL_PME_ENABLE),
428 (t & PCI_PM_CTRL_DATA_SEL_MASK) >> 9,
429 (t & PCI_PM_CTRL_DATA_SCALE_MASK) >> 13,
430 FLAG(t, PCI_PM_CTRL_PME_STATUS));
431 b = get_conf_byte(d, where + PCI_PM_PPB_EXTENSIONS);
433 printf("\t\tBridge: PM%c B3%c\n",
434 FLAG(t, PCI_PM_BPCC_ENABLE),
435 FLAG(~t, PCI_PM_PPB_B2_B3));
439 format_agp_rate(int rate, char *buf, int agp3)
449 c += sprintf(c, "x%d", 1 << (i + 2*agp3));
454 strcpy(buf, "<none>");
458 show_agp(struct device *d, int where, int cap)
465 ver = (cap >> 4) & 0x0f;
467 printf("AGP version %x.%x\n", ver, rev);
470 if (!config_fetch(d, where + PCI_AGP_STATUS, PCI_AGP_SIZEOF - PCI_AGP_STATUS))
472 t = get_conf_long(d, where + PCI_AGP_STATUS);
473 if (ver >= 3 && (t & PCI_AGP_STATUS_AGP3))
475 format_agp_rate(t & 7, rate, agp3);
476 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",
477 ((t & PCI_AGP_STATUS_RQ_MASK) >> 24U) + 1,
478 FLAG(t, PCI_AGP_STATUS_ISOCH),
479 ((t & PCI_AGP_STATUS_ARQSZ_MASK) >> 13),
480 ((t & PCI_AGP_STATUS_CAL_MASK) >> 10),
481 FLAG(t, PCI_AGP_STATUS_SBA),
482 FLAG(t, PCI_AGP_STATUS_ITA_COH),
483 FLAG(t, PCI_AGP_STATUS_GART64),
484 FLAG(t, PCI_AGP_STATUS_HTRANS),
485 FLAG(t, PCI_AGP_STATUS_64BIT),
486 FLAG(t, PCI_AGP_STATUS_FW),
487 FLAG(t, PCI_AGP_STATUS_AGP3),
489 t = get_conf_long(d, where + PCI_AGP_COMMAND);
490 format_agp_rate(t & 7, rate, agp3);
491 printf("\t\tCommand: RQ=%d ArqSz=%d Cal=%d SBA%c AGP%c GART64%c 64bit%c FW%c Rate=%s\n",
492 ((t & PCI_AGP_COMMAND_RQ_MASK) >> 24U) + 1,
493 ((t & PCI_AGP_COMMAND_ARQSZ_MASK) >> 13),
494 ((t & PCI_AGP_COMMAND_CAL_MASK) >> 10),
495 FLAG(t, PCI_AGP_COMMAND_SBA),
496 FLAG(t, PCI_AGP_COMMAND_AGP),
497 FLAG(t, PCI_AGP_COMMAND_GART64),
498 FLAG(t, PCI_AGP_COMMAND_64BIT),
499 FLAG(t, PCI_AGP_COMMAND_FW),
504 show_pcix_nobridge(struct device *d, int where)
508 static const byte max_outstanding[8] = { 1, 2, 3, 4, 8, 12, 16, 32 };
510 printf("PCI-X non-bridge device\n");
515 if (!config_fetch(d, where + PCI_PCIX_STATUS, 4))
518 command = get_conf_word(d, where + PCI_PCIX_COMMAND);
519 status = get_conf_long(d, where + PCI_PCIX_STATUS);
520 printf("\t\tCommand: DPERE%c ERO%c RBC=%d OST=%d\n",
521 FLAG(command, PCI_PCIX_COMMAND_DPERE),
522 FLAG(command, PCI_PCIX_COMMAND_ERO),
523 1 << (9 + ((command & PCI_PCIX_COMMAND_MAX_MEM_READ_BYTE_COUNT) >> 2U)),
524 max_outstanding[(command & PCI_PCIX_COMMAND_MAX_OUTSTANDING_SPLIT_TRANS) >> 4U]);
525 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",
526 ((status >> 8) & 0xff),
527 ((status >> 3) & 0x1f),
528 (status & PCI_PCIX_STATUS_FUNCTION),
529 FLAG(status, PCI_PCIX_STATUS_64BIT),
530 FLAG(status, PCI_PCIX_STATUS_133MHZ),
531 FLAG(status, PCI_PCIX_STATUS_SC_DISCARDED),
532 FLAG(status, PCI_PCIX_STATUS_UNEXPECTED_SC),
533 ((status & PCI_PCIX_STATUS_DEVICE_COMPLEXITY) ? "bridge" : "simple"),
534 1 << (9 + ((status >> 21) & 3U)),
535 max_outstanding[(status >> 23) & 7U],
536 1 << (3 + ((status >> 26) & 7U)),
537 FLAG(status, PCI_PCIX_STATUS_RCVD_SC_ERR_MESS),
538 FLAG(status, PCI_PCIX_STATUS_266MHZ),
539 FLAG(status, PCI_PCIX_STATUS_533MHZ));
543 show_pcix_bridge(struct device *d, int where)
545 static const char * const sec_clock_freq[8] = { "conv", "66MHz", "100MHz", "133MHz", "?4", "?5", "?6", "?7" };
547 u32 status, upstcr, downstcr;
549 printf("PCI-X bridge device\n");
554 if (!config_fetch(d, where + PCI_PCIX_BRIDGE_STATUS, 12))
557 secstatus = get_conf_word(d, where + PCI_PCIX_BRIDGE_SEC_STATUS);
558 printf("\t\tSecondary Status: 64bit%c 133MHz%c SCD%c USC%c SCO%c SRD%c Freq=%s\n",
559 FLAG(secstatus, PCI_PCIX_BRIDGE_SEC_STATUS_64BIT),
560 FLAG(secstatus, PCI_PCIX_BRIDGE_SEC_STATUS_133MHZ),
561 FLAG(secstatus, PCI_PCIX_BRIDGE_SEC_STATUS_SC_DISCARDED),
562 FLAG(secstatus, PCI_PCIX_BRIDGE_SEC_STATUS_UNEXPECTED_SC),
563 FLAG(secstatus, PCI_PCIX_BRIDGE_SEC_STATUS_SC_OVERRUN),
564 FLAG(secstatus, PCI_PCIX_BRIDGE_SEC_STATUS_SPLIT_REQUEST_DELAYED),
565 sec_clock_freq[(secstatus >> 6) & 7]);
566 status = get_conf_long(d, where + PCI_PCIX_BRIDGE_STATUS);
567 printf("\t\tStatus: Dev=%02x:%02x.%d 64bit%c 133MHz%c SCD%c USC%c SCO%c SRD%c\n",
568 ((status >> 8) & 0xff),
569 ((status >> 3) & 0x1f),
570 (status & PCI_PCIX_BRIDGE_STATUS_FUNCTION),
571 FLAG(status, PCI_PCIX_BRIDGE_STATUS_64BIT),
572 FLAG(status, PCI_PCIX_BRIDGE_STATUS_133MHZ),
573 FLAG(status, PCI_PCIX_BRIDGE_STATUS_SC_DISCARDED),
574 FLAG(status, PCI_PCIX_BRIDGE_STATUS_UNEXPECTED_SC),
575 FLAG(status, PCI_PCIX_BRIDGE_STATUS_SC_OVERRUN),
576 FLAG(status, PCI_PCIX_BRIDGE_STATUS_SPLIT_REQUEST_DELAYED));
577 upstcr = get_conf_long(d, where + PCI_PCIX_BRIDGE_UPSTREAM_SPLIT_TRANS_CTRL);
578 printf("\t\tUpstream: Capacity=%u CommitmentLimit=%u\n",
579 (upstcr & PCI_PCIX_BRIDGE_STR_CAPACITY),
580 (upstcr >> 16) & 0xffff);
581 downstcr = get_conf_long(d, where + PCI_PCIX_BRIDGE_DOWNSTREAM_SPLIT_TRANS_CTRL);
582 printf("\t\tDownstream: Capacity=%u CommitmentLimit=%u\n",
583 (downstcr & PCI_PCIX_BRIDGE_STR_CAPACITY),
584 (downstcr >> 16) & 0xffff);
588 show_pcix(struct device *d, int where)
590 switch (get_conf_byte(d, PCI_HEADER_TYPE) & 0x7f)
592 case PCI_HEADER_TYPE_NORMAL:
593 show_pcix_nobridge(d, where);
595 case PCI_HEADER_TYPE_BRIDGE:
596 show_pcix_bridge(d, where);
602 ht_link_width(unsigned width)
604 static char * const widths[8] = { "8bit", "16bit", "[2]", "32bit", "2bit", "4bit", "[6]", "N/C" };
605 return widths[width];
609 ht_link_freq(unsigned freq)
611 static char * const freqs[16] = { "200MHz", "300MHz", "400MHz", "500MHz", "600MHz", "800MHz", "1.0GHz", "1.2GHz",
612 "1.4GHz", "1.6GHz", "[a]", "[b]", "[c]", "[d]", "[e]", "Vend" };
617 show_ht_pri(struct device *d, int where, int cmd)
619 u16 lctr0, lcnf0, lctr1, lcnf1, eh;
620 u8 rid, lfrer0, lfcap0, ftr, lfrer1, lfcap1, mbu, mlu, bn;
623 printf("HyperTransport: Slave or Primary Interface\n");
627 if (!config_fetch(d, where + PCI_HT_PRI_LCTR0, PCI_HT_PRI_SIZEOF - PCI_HT_PRI_LCTR0))
629 rid = get_conf_byte(d, where + PCI_HT_PRI_RID);
630 if (rid < 0x23 && rid > 0x11)
631 printf("\t\t!!! Possibly incomplete decoding\n");
634 fmt = "\t\tCommand: BaseUnitID=%u UnitCnt=%u MastHost%c DefDir%c DUL%c\n";
636 fmt = "\t\tCommand: BaseUnitID=%u UnitCnt=%u MastHost%c DefDir%c\n";
638 (cmd & PCI_HT_PRI_CMD_BUID),
639 (cmd & PCI_HT_PRI_CMD_UC) >> 5,
640 FLAG(cmd, PCI_HT_PRI_CMD_MH),
641 FLAG(cmd, PCI_HT_PRI_CMD_DD),
642 FLAG(cmd, PCI_HT_PRI_CMD_DUL));
643 lctr0 = get_conf_word(d, where + PCI_HT_PRI_LCTR0);
645 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";
647 fmt = "\t\tLink Control 0: CFlE%c CST%c CFE%c <LkFail%c Init%c EOC%c TXO%c <CRCErr=%x\n";
649 FLAG(lctr0, PCI_HT_LCTR_CFLE),
650 FLAG(lctr0, PCI_HT_LCTR_CST),
651 FLAG(lctr0, PCI_HT_LCTR_CFE),
652 FLAG(lctr0, PCI_HT_LCTR_LKFAIL),
653 FLAG(lctr0, PCI_HT_LCTR_INIT),
654 FLAG(lctr0, PCI_HT_LCTR_EOC),
655 FLAG(lctr0, PCI_HT_LCTR_TXO),
656 (lctr0 & PCI_HT_LCTR_CRCERR) >> 8,
657 FLAG(lctr0, PCI_HT_LCTR_ISOCEN),
658 FLAG(lctr0, PCI_HT_LCTR_LSEN),
659 FLAG(lctr0, PCI_HT_LCTR_EXTCTL),
660 FLAG(lctr0, PCI_HT_LCTR_64B));
661 lcnf0 = get_conf_word(d, where + PCI_HT_PRI_LCNF0);
663 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";
665 fmt = "\t\tLink Config 0: MLWI=%s MLWO=%s LWI=%s LWO=%s\n";
667 ht_link_width(lcnf0 & PCI_HT_LCNF_MLWI),
668 ht_link_width((lcnf0 & PCI_HT_LCNF_MLWO) >> 4),
669 ht_link_width((lcnf0 & PCI_HT_LCNF_LWI) >> 8),
670 ht_link_width((lcnf0 & PCI_HT_LCNF_LWO) >> 12),
671 FLAG(lcnf0, PCI_HT_LCNF_DFI),
672 FLAG(lcnf0, PCI_HT_LCNF_DFO),
673 FLAG(lcnf0, PCI_HT_LCNF_DFIE),
674 FLAG(lcnf0, PCI_HT_LCNF_DFOE));
675 lctr1 = get_conf_word(d, where + PCI_HT_PRI_LCTR1);
677 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";
679 fmt = "\t\tLink Control 1: CFlE%c CST%c CFE%c <LkFail%c Init%c EOC%c TXO%c <CRCErr=%x\n";
681 FLAG(lctr1, PCI_HT_LCTR_CFLE),
682 FLAG(lctr1, PCI_HT_LCTR_CST),
683 FLAG(lctr1, PCI_HT_LCTR_CFE),
684 FLAG(lctr1, PCI_HT_LCTR_LKFAIL),
685 FLAG(lctr1, PCI_HT_LCTR_INIT),
686 FLAG(lctr1, PCI_HT_LCTR_EOC),
687 FLAG(lctr1, PCI_HT_LCTR_TXO),
688 (lctr1 & PCI_HT_LCTR_CRCERR) >> 8,
689 FLAG(lctr1, PCI_HT_LCTR_ISOCEN),
690 FLAG(lctr1, PCI_HT_LCTR_LSEN),
691 FLAG(lctr1, PCI_HT_LCTR_EXTCTL),
692 FLAG(lctr1, PCI_HT_LCTR_64B));
693 lcnf1 = get_conf_word(d, where + PCI_HT_PRI_LCNF1);
695 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";
697 fmt = "\t\tLink Config 1: MLWI=%s MLWO=%s LWI=%s LWO=%s\n";
699 ht_link_width(lcnf1 & PCI_HT_LCNF_MLWI),
700 ht_link_width((lcnf1 & PCI_HT_LCNF_MLWO) >> 4),
701 ht_link_width((lcnf1 & PCI_HT_LCNF_LWI) >> 8),
702 ht_link_width((lcnf1 & PCI_HT_LCNF_LWO) >> 12),
703 FLAG(lcnf1, PCI_HT_LCNF_DFI),
704 FLAG(lcnf1, PCI_HT_LCNF_DFO),
705 FLAG(lcnf1, PCI_HT_LCNF_DFIE),
706 FLAG(lcnf1, PCI_HT_LCNF_DFOE));
707 printf("\t\tRevision ID: %u.%02u\n",
708 (rid & PCI_HT_RID_MAJ) >> 5, (rid & PCI_HT_RID_MIN));
711 lfrer0 = get_conf_byte(d, where + PCI_HT_PRI_LFRER0);
712 printf("\t\tLink Frequency 0: %s\n", ht_link_freq(lfrer0 & PCI_HT_LFRER_FREQ));
713 printf("\t\tLink Error 0: <Prot%c <Ovfl%c <EOC%c CTLTm%c\n",
714 FLAG(lfrer0, PCI_HT_LFRER_PROT),
715 FLAG(lfrer0, PCI_HT_LFRER_OV),
716 FLAG(lfrer0, PCI_HT_LFRER_EOC),
717 FLAG(lfrer0, PCI_HT_LFRER_CTLT));
718 lfcap0 = get_conf_byte(d, where + PCI_HT_PRI_LFCAP0);
719 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",
720 FLAG(lfcap0, PCI_HT_LFCAP_200),
721 FLAG(lfcap0, PCI_HT_LFCAP_300),
722 FLAG(lfcap0, PCI_HT_LFCAP_400),
723 FLAG(lfcap0, PCI_HT_LFCAP_500),
724 FLAG(lfcap0, PCI_HT_LFCAP_600),
725 FLAG(lfcap0, PCI_HT_LFCAP_800),
726 FLAG(lfcap0, PCI_HT_LFCAP_1000),
727 FLAG(lfcap0, PCI_HT_LFCAP_1200),
728 FLAG(lfcap0, PCI_HT_LFCAP_1400),
729 FLAG(lfcap0, PCI_HT_LFCAP_1600),
730 FLAG(lfcap0, PCI_HT_LFCAP_VEND));
731 ftr = get_conf_byte(d, where + PCI_HT_PRI_FTR);
732 printf("\t\tFeature Capability: IsocFC%c LDTSTOP%c CRCTM%c ECTLT%c 64bA%c UIDRD%c\n",
733 FLAG(ftr, PCI_HT_FTR_ISOCFC),
734 FLAG(ftr, PCI_HT_FTR_LDTSTOP),
735 FLAG(ftr, PCI_HT_FTR_CRCTM),
736 FLAG(ftr, PCI_HT_FTR_ECTLT),
737 FLAG(ftr, PCI_HT_FTR_64BA),
738 FLAG(ftr, PCI_HT_FTR_UIDRD));
739 lfrer1 = get_conf_byte(d, where + PCI_HT_PRI_LFRER1);
740 printf("\t\tLink Frequency 1: %s\n", ht_link_freq(lfrer1 & PCI_HT_LFRER_FREQ));
741 printf("\t\tLink Error 1: <Prot%c <Ovfl%c <EOC%c CTLTm%c\n",
742 FLAG(lfrer1, PCI_HT_LFRER_PROT),
743 FLAG(lfrer1, PCI_HT_LFRER_OV),
744 FLAG(lfrer1, PCI_HT_LFRER_EOC),
745 FLAG(lfrer1, PCI_HT_LFRER_CTLT));
746 lfcap1 = get_conf_byte(d, where + PCI_HT_PRI_LFCAP1);
747 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",
748 FLAG(lfcap1, PCI_HT_LFCAP_200),
749 FLAG(lfcap1, PCI_HT_LFCAP_300),
750 FLAG(lfcap1, PCI_HT_LFCAP_400),
751 FLAG(lfcap1, PCI_HT_LFCAP_500),
752 FLAG(lfcap1, PCI_HT_LFCAP_600),
753 FLAG(lfcap1, PCI_HT_LFCAP_800),
754 FLAG(lfcap1, PCI_HT_LFCAP_1000),
755 FLAG(lfcap1, PCI_HT_LFCAP_1200),
756 FLAG(lfcap1, PCI_HT_LFCAP_1400),
757 FLAG(lfcap1, PCI_HT_LFCAP_1600),
758 FLAG(lfcap1, PCI_HT_LFCAP_VEND));
759 eh = get_conf_word(d, where + PCI_HT_PRI_EH);
760 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",
761 FLAG(eh, PCI_HT_EH_PFLE),
762 FLAG(eh, PCI_HT_EH_OFLE),
763 FLAG(eh, PCI_HT_EH_PFE),
764 FLAG(eh, PCI_HT_EH_OFE),
765 FLAG(eh, PCI_HT_EH_EOCFE),
766 FLAG(eh, PCI_HT_EH_RFE),
767 FLAG(eh, PCI_HT_EH_CRCFE),
768 FLAG(eh, PCI_HT_EH_SERRFE),
769 FLAG(eh, PCI_HT_EH_CF),
770 FLAG(eh, PCI_HT_EH_RE),
771 FLAG(eh, PCI_HT_EH_PNFE),
772 FLAG(eh, PCI_HT_EH_ONFE),
773 FLAG(eh, PCI_HT_EH_EOCNFE),
774 FLAG(eh, PCI_HT_EH_RNFE),
775 FLAG(eh, PCI_HT_EH_CRCNFE),
776 FLAG(eh, PCI_HT_EH_SERRNFE));
777 mbu = get_conf_byte(d, where + PCI_HT_PRI_MBU);
778 mlu = get_conf_byte(d, where + PCI_HT_PRI_MLU);
779 printf("\t\tPrefetchable memory behind bridge Upper: %02x-%02x\n", mbu, mlu);
780 bn = get_conf_byte(d, where + PCI_HT_PRI_BN);
781 printf("\t\tBus Number: %02x\n", bn);
785 show_ht_sec(struct device *d, int where, int cmd)
787 u16 lctr, lcnf, ftr, eh;
788 u8 rid, lfrer, lfcap, mbu, mlu;
791 printf("HyperTransport: Host or Secondary Interface\n");
795 if (!config_fetch(d, where + PCI_HT_SEC_LCTR, PCI_HT_SEC_SIZEOF - PCI_HT_SEC_LCTR))
797 rid = get_conf_byte(d, where + PCI_HT_SEC_RID);
798 if (rid < 0x23 && rid > 0x11)
799 printf("\t\t!!! Possibly incomplete decoding\n");
802 fmt = "\t\tCommand: WarmRst%c DblEnd%c DevNum=%u ChainSide%c HostHide%c Slave%c <EOCErr%c DUL%c\n";
804 fmt = "\t\tCommand: WarmRst%c DblEnd%c\n";
806 FLAG(cmd, PCI_HT_SEC_CMD_WR),
807 FLAG(cmd, PCI_HT_SEC_CMD_DE),
808 (cmd & PCI_HT_SEC_CMD_DN) >> 2,
809 FLAG(cmd, PCI_HT_SEC_CMD_CS),
810 FLAG(cmd, PCI_HT_SEC_CMD_HH),
811 FLAG(cmd, PCI_HT_SEC_CMD_AS),
812 FLAG(cmd, PCI_HT_SEC_CMD_HIECE),
813 FLAG(cmd, PCI_HT_SEC_CMD_DUL));
814 lctr = get_conf_word(d, where + PCI_HT_SEC_LCTR);
816 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";
818 fmt = "\t\tLink Control: CFlE%c CST%c CFE%c <LkFail%c Init%c EOC%c TXO%c <CRCErr=%x\n";
820 FLAG(lctr, PCI_HT_LCTR_CFLE),
821 FLAG(lctr, PCI_HT_LCTR_CST),
822 FLAG(lctr, PCI_HT_LCTR_CFE),
823 FLAG(lctr, PCI_HT_LCTR_LKFAIL),
824 FLAG(lctr, PCI_HT_LCTR_INIT),
825 FLAG(lctr, PCI_HT_LCTR_EOC),
826 FLAG(lctr, PCI_HT_LCTR_TXO),
827 (lctr & PCI_HT_LCTR_CRCERR) >> 8,
828 FLAG(lctr, PCI_HT_LCTR_ISOCEN),
829 FLAG(lctr, PCI_HT_LCTR_LSEN),
830 FLAG(lctr, PCI_HT_LCTR_EXTCTL),
831 FLAG(lctr, PCI_HT_LCTR_64B));
832 lcnf = get_conf_word(d, where + PCI_HT_SEC_LCNF);
834 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";
836 fmt = "\t\tLink Config: MLWI=%s MLWO=%s LWI=%s LWO=%s\n";
838 ht_link_width(lcnf & PCI_HT_LCNF_MLWI),
839 ht_link_width((lcnf & PCI_HT_LCNF_MLWO) >> 4),
840 ht_link_width((lcnf & PCI_HT_LCNF_LWI) >> 8),
841 ht_link_width((lcnf & PCI_HT_LCNF_LWO) >> 12),
842 FLAG(lcnf, PCI_HT_LCNF_DFI),
843 FLAG(lcnf, PCI_HT_LCNF_DFO),
844 FLAG(lcnf, PCI_HT_LCNF_DFIE),
845 FLAG(lcnf, PCI_HT_LCNF_DFOE));
846 printf("\t\tRevision ID: %u.%02u\n",
847 (rid & PCI_HT_RID_MAJ) >> 5, (rid & PCI_HT_RID_MIN));
850 lfrer = get_conf_byte(d, where + PCI_HT_SEC_LFRER);
851 printf("\t\tLink Frequency: %s\n", ht_link_freq(lfrer & PCI_HT_LFRER_FREQ));
852 printf("\t\tLink Error: <Prot%c <Ovfl%c <EOC%c CTLTm%c\n",
853 FLAG(lfrer, PCI_HT_LFRER_PROT),
854 FLAG(lfrer, PCI_HT_LFRER_OV),
855 FLAG(lfrer, PCI_HT_LFRER_EOC),
856 FLAG(lfrer, PCI_HT_LFRER_CTLT));
857 lfcap = get_conf_byte(d, where + PCI_HT_SEC_LFCAP);
858 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",
859 FLAG(lfcap, PCI_HT_LFCAP_200),
860 FLAG(lfcap, PCI_HT_LFCAP_300),
861 FLAG(lfcap, PCI_HT_LFCAP_400),
862 FLAG(lfcap, PCI_HT_LFCAP_500),
863 FLAG(lfcap, PCI_HT_LFCAP_600),
864 FLAG(lfcap, PCI_HT_LFCAP_800),
865 FLAG(lfcap, PCI_HT_LFCAP_1000),
866 FLAG(lfcap, PCI_HT_LFCAP_1200),
867 FLAG(lfcap, PCI_HT_LFCAP_1400),
868 FLAG(lfcap, PCI_HT_LFCAP_1600),
869 FLAG(lfcap, PCI_HT_LFCAP_VEND));
870 ftr = get_conf_word(d, where + PCI_HT_SEC_FTR);
871 printf("\t\tFeature Capability: IsocFC%c LDTSTOP%c CRCTM%c ECTLT%c 64bA%c UIDRD%c ExtRS%c UCnfE%c\n",
872 FLAG(ftr, PCI_HT_FTR_ISOCFC),
873 FLAG(ftr, PCI_HT_FTR_LDTSTOP),
874 FLAG(ftr, PCI_HT_FTR_CRCTM),
875 FLAG(ftr, PCI_HT_FTR_ECTLT),
876 FLAG(ftr, PCI_HT_FTR_64BA),
877 FLAG(ftr, PCI_HT_FTR_UIDRD),
878 FLAG(ftr, PCI_HT_SEC_FTR_EXTRS),
879 FLAG(ftr, PCI_HT_SEC_FTR_UCNFE));
880 if (ftr & PCI_HT_SEC_FTR_EXTRS)
882 eh = get_conf_word(d, where + PCI_HT_SEC_EH);
883 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",
884 FLAG(eh, PCI_HT_EH_PFLE),
885 FLAG(eh, PCI_HT_EH_OFLE),
886 FLAG(eh, PCI_HT_EH_PFE),
887 FLAG(eh, PCI_HT_EH_OFE),
888 FLAG(eh, PCI_HT_EH_EOCFE),
889 FLAG(eh, PCI_HT_EH_RFE),
890 FLAG(eh, PCI_HT_EH_CRCFE),
891 FLAG(eh, PCI_HT_EH_SERRFE),
892 FLAG(eh, PCI_HT_EH_CF),
893 FLAG(eh, PCI_HT_EH_RE),
894 FLAG(eh, PCI_HT_EH_PNFE),
895 FLAG(eh, PCI_HT_EH_ONFE),
896 FLAG(eh, PCI_HT_EH_EOCNFE),
897 FLAG(eh, PCI_HT_EH_RNFE),
898 FLAG(eh, PCI_HT_EH_CRCNFE),
899 FLAG(eh, PCI_HT_EH_SERRNFE));
900 mbu = get_conf_byte(d, where + PCI_HT_SEC_MBU);
901 mlu = get_conf_byte(d, where + PCI_HT_SEC_MLU);
902 printf("\t\tPrefetchable memory behind bridge Upper: %02x-%02x\n", mbu, mlu);
907 show_ht(struct device *d, int where, int cmd)
911 switch (cmd & PCI_HT_CMD_TYP_HI)
913 case PCI_HT_CMD_TYP_HI_PRI:
914 show_ht_pri(d, where, cmd);
916 case PCI_HT_CMD_TYP_HI_SEC:
917 show_ht_sec(d, where, cmd);
921 type = cmd & PCI_HT_CMD_TYP;
924 case PCI_HT_CMD_TYP_SW:
925 printf("HyperTransport: Switch\n");
927 case PCI_HT_CMD_TYP_IDC:
928 printf("HyperTransport: Interrupt Discovery and Configuration\n");
930 case PCI_HT_CMD_TYP_RID:
931 printf("HyperTransport: Revision ID: %u.%02u\n",
932 (cmd & PCI_HT_RID_MAJ) >> 5, (cmd & PCI_HT_RID_MIN));
934 case PCI_HT_CMD_TYP_UIDC:
935 printf("HyperTransport: UnitID Clumping\n");
937 case PCI_HT_CMD_TYP_ECSA:
938 printf("HyperTransport: Extended Configuration Space Access\n");
940 case PCI_HT_CMD_TYP_AM:
941 printf("HyperTransport: Address Mapping\n");
943 case PCI_HT_CMD_TYP_MSIM:
944 printf("HyperTransport: MSI Mapping\n");
946 case PCI_HT_CMD_TYP_DR:
947 printf("HyperTransport: DirectRoute\n");
949 case PCI_HT_CMD_TYP_VCS:
950 printf("HyperTransport: VCSet\n");
952 case PCI_HT_CMD_TYP_RM:
953 printf("HyperTransport: Retry Mode\n");
955 case PCI_HT_CMD_TYP_X86:
956 printf("HyperTransport: X86 (reserved)\n");
959 printf("HyperTransport: #%02x\n", type >> 11);
964 show_rom(struct device *d, int reg)
966 struct pci_dev *p = d->dev;
967 pciaddr_t rom = p->rom_base_addr;
968 pciaddr_t len = (p->known_fields & PCI_FILL_SIZES) ? p->rom_size : 0;
969 u32 flg = get_conf_long(d, reg);
970 word cmd = get_conf_word(d, PCI_COMMAND);
972 if (!rom && !flg && !len)
975 if ((rom & PCI_ROM_ADDRESS_MASK) && !(flg & PCI_ROM_ADDRESS_MASK))
977 printf("[virtual] ");
980 printf("Expansion ROM at ");
981 if (rom & PCI_ROM_ADDRESS_MASK)
982 printf(PCIADDR_T_FMT, rom & PCI_ROM_ADDRESS_MASK);
983 else if (flg & PCI_ROM_ADDRESS_MASK)
986 printf("<unassigned>");
987 if (!(flg & PCI_ROM_ADDRESS_ENABLE))
988 printf(" [disabled]");
989 else if (!(cmd & PCI_COMMAND_MEMORY))
990 printf(" [disabled by cmd]");
996 show_msi(struct device *d, int where, int cap)
1002 printf("Message Signalled Interrupts: Mask%c 64bit%c Queue=%d/%d Enable%c\n",
1003 FLAG(cap, PCI_MSI_FLAGS_MASK_BIT),
1004 FLAG(cap, PCI_MSI_FLAGS_64BIT),
1005 (cap & PCI_MSI_FLAGS_QSIZE) >> 4,
1006 (cap & PCI_MSI_FLAGS_QMASK) >> 1,
1007 FLAG(cap, PCI_MSI_FLAGS_ENABLE));
1010 is64 = cap & PCI_MSI_FLAGS_64BIT;
1011 if (!config_fetch(d, where + PCI_MSI_ADDRESS_LO, (is64 ? PCI_MSI_DATA_64 : PCI_MSI_DATA_32) + 2 - PCI_MSI_ADDRESS_LO))
1013 printf("\t\tAddress: ");
1016 t = get_conf_long(d, where + PCI_MSI_ADDRESS_HI);
1017 w = get_conf_word(d, where + PCI_MSI_DATA_64);
1021 w = get_conf_word(d, where + PCI_MSI_DATA_32);
1022 t = get_conf_long(d, where + PCI_MSI_ADDRESS_LO);
1023 printf("%08x Data: %04x\n", t, w);
1024 if (cap & PCI_MSI_FLAGS_MASK_BIT)
1030 if (!config_fetch(d, where + PCI_MSI_MASK_BIT_64, 8))
1032 mask = get_conf_long(d, where + PCI_MSI_MASK_BIT_64);
1033 pending = get_conf_long(d, where + PCI_MSI_PENDING_64);
1037 if (!config_fetch(d, where + PCI_MSI_MASK_BIT_32, 8))
1039 mask = get_conf_long(d, where + PCI_MSI_MASK_BIT_32);
1040 pending = get_conf_long(d, where + PCI_MSI_PENDING_32);
1042 printf("\t\tMasking: %08x Pending: %08x\n", mask, pending);
1046 static void show_vendor(void)
1048 printf("Vendor Specific Information\n");
1051 static void show_debug(void)
1053 printf("Debug port\n");
1056 static float power_limit(int value, int scale)
1058 static const float scales[4] = { 1.0, 0.1, 0.01, 0.001 };
1059 return value * scales[scale];
1062 static const char *latency_l0s(int value)
1064 static const char *latencies[] = { "<64ns", "<128ns", "<256ns", "<512ns", "<1us", "<2us", "<4us", "unlimited" };
1065 return latencies[value];
1068 static const char *latency_l1(int value)
1070 static const char *latencies[] = { "<1us", "<2us", "<4us", "<8us", "<16us", "<32us", "<64us", "unlimited" };
1071 return latencies[value];
1074 static void show_express_dev(struct device *d, int where, int type)
1079 t = get_conf_long(d, where + PCI_EXP_DEVCAP);
1080 printf("\t\tDevice: Supported: MaxPayload %d bytes, PhantFunc %d, ExtTag%c\n",
1081 128 << (t & PCI_EXP_DEVCAP_PAYLOAD),
1082 (1 << ((t & PCI_EXP_DEVCAP_PHANTOM) >> 3)) - 1,
1083 FLAG(t, PCI_EXP_DEVCAP_EXT_TAG));
1084 printf("\t\tDevice: Latency L0s %s, L1 %s\n",
1085 latency_l0s((t & PCI_EXP_DEVCAP_L0S) >> 6),
1086 latency_l1((t & PCI_EXP_DEVCAP_L1) >> 9));
1087 if ((type == PCI_EXP_TYPE_ENDPOINT) || (type == PCI_EXP_TYPE_LEG_END) ||
1088 (type == PCI_EXP_TYPE_UPSTREAM) || (type == PCI_EXP_TYPE_PCI_BRIDGE))
1089 printf("\t\tDevice: AtnBtn%c AtnInd%c PwrInd%c\n",
1090 FLAG(t, PCI_EXP_DEVCAP_ATN_BUT),
1091 FLAG(t, PCI_EXP_DEVCAP_ATN_IND), FLAG(t, PCI_EXP_DEVCAP_PWR_IND));
1092 if (type == PCI_EXP_TYPE_UPSTREAM)
1093 printf("\t\tDevice: SlotPowerLimit %f\n",
1094 power_limit((t & PCI_EXP_DEVCAP_PWR_VAL) >> 18,
1095 (t & PCI_EXP_DEVCAP_PWR_SCL) >> 26));
1097 w = get_conf_word(d, where + PCI_EXP_DEVCTL);
1098 printf("\t\tDevice: Errors: Correctable%c Non-Fatal%c Fatal%c Unsupported%c\n",
1099 FLAG(w, PCI_EXP_DEVCTL_CERE),
1100 FLAG(w, PCI_EXP_DEVCTL_NFERE),
1101 FLAG(w, PCI_EXP_DEVCTL_FERE),
1102 FLAG(w, PCI_EXP_DEVCTL_URRE));
1103 printf("\t\tDevice: RlxdOrd%c ExtTag%c PhantFunc%c AuxPwr%c NoSnoop%c\n",
1104 FLAG(w, PCI_EXP_DEVCTL_RELAXED),
1105 FLAG(w, PCI_EXP_DEVCTL_EXT_TAG),
1106 FLAG(w, PCI_EXP_DEVCTL_PHANTOM),
1107 FLAG(w, PCI_EXP_DEVCTL_AUX_PME),
1108 FLAG(w, PCI_EXP_DEVCTL_NOSNOOP));
1109 printf("\t\tDevice: MaxPayload %d bytes, MaxReadReq %d bytes\n",
1110 128 << ((w & PCI_EXP_DEVCTL_PAYLOAD) >> 5),
1111 128 << ((w & PCI_EXP_DEVCTL_READRQ) >> 12));
1114 static char *link_speed(int speed)
1125 static char *aspm_support(int code)
1138 static const char *aspm_enabled(int code)
1140 static const char *desc[] = { "Disabled", "L0s Enabled", "L1 Enabled", "L0s L1 Enabled" };
1144 static void show_express_link(struct device *d, int where, int type)
1149 t = get_conf_long(d, where + PCI_EXP_LNKCAP);
1150 printf("\t\tLink: Supported Speed %s, Width x%d, ASPM %s, Port %d\n",
1151 link_speed(t & PCI_EXP_LNKCAP_SPEED), (t & PCI_EXP_LNKCAP_WIDTH) >> 4,
1152 aspm_support((t & PCI_EXP_LNKCAP_ASPM) >> 10),
1154 printf("\t\tLink: Latency L0s %s, L1 %s\n",
1155 latency_l0s((t & PCI_EXP_LNKCAP_L0S) >> 12),
1156 latency_l1((t & PCI_EXP_LNKCAP_L1) >> 15));
1157 w = get_conf_word(d, where + PCI_EXP_LNKCTL);
1158 printf("\t\tLink: ASPM %s", aspm_enabled(w & PCI_EXP_LNKCTL_ASPM));
1159 if ((type == PCI_EXP_TYPE_ROOT_PORT) || (type == PCI_EXP_TYPE_ENDPOINT) ||
1160 (type == PCI_EXP_TYPE_LEG_END))
1161 printf(" RCB %d bytes", w & PCI_EXP_LNKCTL_RCB ? 128 : 64);
1162 if (w & PCI_EXP_LNKCTL_DISABLE)
1163 printf(" Disabled");
1164 printf(" CommClk%c ExtSynch%c\n", FLAG(w, PCI_EXP_LNKCTL_CLOCK),
1165 FLAG(w, PCI_EXP_LNKCTL_XSYNCH));
1166 w = get_conf_word(d, where + PCI_EXP_LNKSTA);
1167 printf("\t\tLink: Speed %s, Width x%d\n",
1168 link_speed(w & PCI_EXP_LNKSTA_SPEED), (w & PCI_EXP_LNKSTA_WIDTH) >> 4);
1171 static const char *indicator(int code)
1173 static const char *names[] = { "Unknown", "On", "Blink", "Off" };
1177 static void show_express_slot(struct device *d, int where)
1182 t = get_conf_long(d, where + PCI_EXP_SLTCAP);
1183 printf("\t\tSlot: AtnBtn%c PwrCtrl%c MRL%c AtnInd%c PwrInd%c HotPlug%c Surpise%c\n",
1184 FLAG(t, PCI_EXP_SLTCAP_ATNB),
1185 FLAG(t, PCI_EXP_SLTCAP_PWRC),
1186 FLAG(t, PCI_EXP_SLTCAP_MRL),
1187 FLAG(t, PCI_EXP_SLTCAP_ATNI),
1188 FLAG(t, PCI_EXP_SLTCAP_PWRI),
1189 FLAG(t, PCI_EXP_SLTCAP_HPC),
1190 FLAG(t, PCI_EXP_SLTCAP_HPS));
1191 printf("\t\tSlot: Number %d, PowerLimit %f\n", t >> 19,
1192 power_limit((t & PCI_EXP_SLTCAP_PWR_VAL) >> 7,
1193 (t & PCI_EXP_SLTCAP_PWR_SCL) >> 15));
1194 w = get_conf_word(d, where + PCI_EXP_SLTCTL);
1195 printf("\t\tSlot: Enabled AtnBtn%c PwrFlt%c MRL%c PresDet%c CmdCplt%c HPIrq%c\n",
1196 FLAG(w, PCI_EXP_SLTCTL_ATNB),
1197 FLAG(w, PCI_EXP_SLTCTL_PWRF),
1198 FLAG(w, PCI_EXP_SLTCTL_MRLS),
1199 FLAG(w, PCI_EXP_SLTCTL_PRSD),
1200 FLAG(w, PCI_EXP_SLTCTL_CMDC),
1201 FLAG(w, PCI_EXP_SLTCTL_HPIE));
1202 printf("\t\tSlot: AttnInd %s, PwrInd %s, Power%c\n",
1203 indicator((w & PCI_EXP_SLTCTL_ATNI) >> 6),
1204 indicator((w & PCI_EXP_SLTCTL_PWRI) >> 8),
1205 FLAG(w, w & PCI_EXP_SLTCTL_PWRC));
1208 static void show_express_root(struct device *d, int where)
1210 u16 w = get_conf_word(d, where + PCI_EXP_RTCTL);
1211 printf("\t\tRoot: Correctable%c Non-Fatal%c Fatal%c PME%c\n",
1212 FLAG(w, PCI_EXP_RTCTL_SECEE),
1213 FLAG(w, PCI_EXP_RTCTL_SENFEE),
1214 FLAG(w, PCI_EXP_RTCTL_SEFEE),
1215 FLAG(w, PCI_EXP_RTCTL_PMEIE));
1219 show_express(struct device *d, int where, int cap)
1221 int type = (cap & PCI_EXP_FLAGS_TYPE) >> 4;
1228 case PCI_EXP_TYPE_ENDPOINT:
1231 case PCI_EXP_TYPE_LEG_END:
1232 printf("Legacy Endpoint");
1234 case PCI_EXP_TYPE_ROOT_PORT:
1235 slot = cap & PCI_EXP_FLAGS_SLOT;
1236 printf("Root Port (Slot%c)", FLAG(cap, PCI_EXP_FLAGS_SLOT));
1238 case PCI_EXP_TYPE_UPSTREAM:
1239 printf("Upstream Port");
1241 case PCI_EXP_TYPE_DOWNSTREAM:
1242 slot = cap & PCI_EXP_FLAGS_SLOT;
1243 printf("Downstream Port (Slot%c)", FLAG(cap, PCI_EXP_FLAGS_SLOT));
1245 case PCI_EXP_TYPE_PCI_BRIDGE:
1246 printf("PCI/PCI-X Bridge");
1249 printf("Unknown type");
1251 printf(" IRQ %d\n", (cap & PCI_EXP_FLAGS_IRQ) >> 9);
1258 if (type == PCI_EXP_TYPE_ROOT_PORT)
1260 if (!config_fetch(d, where + PCI_EXP_DEVCAP, size))
1263 show_express_dev(d, where, type);
1264 show_express_link(d, where, type);
1266 show_express_slot(d, where);
1267 if (type == PCI_EXP_TYPE_ROOT_PORT)
1268 show_express_root(d, where);
1272 show_msix(struct device *d, int where, int cap)
1276 printf("MSI-X: Enable%c Mask%c TabSize=%d\n",
1277 FLAG(cap, PCI_MSIX_ENABLE),
1278 FLAG(cap, PCI_MSIX_MASK),
1279 (cap & PCI_MSIX_TABSIZE) + 1);
1280 if (verbose < 2 || !config_fetch(d, where + PCI_MSIX_TABLE, 8))
1283 off = get_conf_long(d, where + PCI_MSIX_TABLE);
1284 printf("\t\tVector table: BAR=%d offset=%08x\n",
1285 off & PCI_MSIX_BIR, off & ~PCI_MSIX_BIR);
1286 off = get_conf_long(d, where + PCI_MSIX_PBA);
1287 printf("\t\tPBA: BAR=%d offset=%08x\n",
1288 off & PCI_MSIX_BIR, off & ~PCI_MSIX_BIR);
1292 show_slotid(int cap)
1294 int esr = cap & 0xff;
1297 printf("Slot ID: %d slots, First%c, chassis %02x\n",
1298 esr & PCI_SID_ESR_NSLOTS,
1299 FLAG(esr, PCI_SID_ESR_FIC),
1304 show_ssvid(struct device *d, int where)
1306 u16 subsys_v, subsys_d;
1307 char ssnamebuf[256];
1309 if (!config_fetch(d, where, 8))
1311 subsys_v = get_conf_word(d, where + PCI_SSVID_VENDOR);
1312 subsys_d = get_conf_word(d, where + PCI_SSVID_DEVICE);
1313 printf("Subsystem: %s\n",
1314 pci_lookup_name(pacc, ssnamebuf, sizeof(ssnamebuf),
1315 PCI_LOOKUP_SUBSYSTEM | PCI_LOOKUP_VENDOR | PCI_LOOKUP_DEVICE,
1316 d->dev->vendor_id, d->dev->device_id, subsys_v, subsys_d));
1320 show_aer(struct device *d UNUSED, int where UNUSED)
1322 printf("Advanced Error Reporting\n");
1326 show_vc(struct device *d UNUSED, int where UNUSED)
1328 printf("Virtual Channel\n");
1332 show_dsn(struct device *d, int where)
1335 if (!config_fetch(d, where + 4, 8))
1337 t1 = get_conf_long(d, where + 4);
1338 t2 = get_conf_long(d, where + 8);
1339 printf("Device Serial Number %02x-%02x-%02x-%02x-%02x-%02x-%02x-%02x\n",
1340 t1 & 0xff, (t1 >> 8) & 0xff, (t1 >> 16) & 0xff, t1 >> 24,
1341 t2 & 0xff, (t2 >> 8) & 0xff, (t2 >> 16) & 0xff, t2 >> 24);
1345 show_pb(struct device *d UNUSED, int where UNUSED)
1347 printf("Power Budgeting\n");
1351 show_ext_caps(struct device *d)
1359 if (!config_fetch(d, where, 4))
1361 header = get_conf_long(d, where);
1364 id = header & 0xffff;
1365 printf("\tCapabilities: [%03x] ", where);
1368 case PCI_EXT_CAP_ID_AER:
1371 case PCI_EXT_CAP_ID_VC:
1374 case PCI_EXT_CAP_ID_DSN:
1377 case PCI_EXT_CAP_ID_PB:
1381 printf("Unknown (%d)\n", id);
1384 where = header >> 20;
1389 show_caps(struct device *d)
1391 int can_have_ext_caps = 0;
1393 if (get_conf_word(d, PCI_STATUS) & PCI_STATUS_CAP_LIST)
1395 int where = get_conf_byte(d, PCI_CAPABILITY_LIST) & ~3;
1399 printf("\tCapabilities: ");
1400 if (!config_fetch(d, where, 4))
1402 puts("<access denied>");
1405 id = get_conf_byte(d, where + PCI_CAP_LIST_ID);
1406 next = get_conf_byte(d, where + PCI_CAP_LIST_NEXT) & ~3;
1407 cap = get_conf_word(d, where + PCI_CAP_FLAGS);
1408 printf("[%02x] ", where);
1411 printf("<chain broken>\n");
1417 show_pm(d, where, cap);
1419 case PCI_CAP_ID_AGP:
1420 show_agp(d, where, cap);
1422 case PCI_CAP_ID_VPD:
1423 printf("Vital Product Data\n");
1425 case PCI_CAP_ID_SLOTID:
1428 case PCI_CAP_ID_MSI:
1429 show_msi(d, where, cap);
1431 case PCI_CAP_ID_PCIX:
1432 show_pcix(d, where);
1433 can_have_ext_caps = 1;
1436 show_ht(d, where, cap);
1438 case PCI_CAP_ID_VNDR:
1441 case PCI_CAP_ID_DBG:
1444 case PCI_CAP_ID_SSVID:
1445 show_ssvid(d, where);
1447 case PCI_CAP_ID_EXP:
1448 show_express(d, where, cap);
1449 can_have_ext_caps = 1;
1451 case PCI_CAP_ID_MSIX:
1452 show_msix(d, where, cap);
1455 printf("#%02x [%04x]\n", id, cap);
1460 if (can_have_ext_caps)
1465 show_htype0(struct device *d)
1468 show_rom(d, PCI_ROM_ADDRESS);
1473 show_htype1(struct device *d)
1475 u32 io_base = get_conf_byte(d, PCI_IO_BASE);
1476 u32 io_limit = get_conf_byte(d, PCI_IO_LIMIT);
1477 u32 io_type = io_base & PCI_IO_RANGE_TYPE_MASK;
1478 u32 mem_base = get_conf_word(d, PCI_MEMORY_BASE);
1479 u32 mem_limit = get_conf_word(d, PCI_MEMORY_LIMIT);
1480 u32 mem_type = mem_base & PCI_MEMORY_RANGE_TYPE_MASK;
1481 u32 pref_base = get_conf_word(d, PCI_PREF_MEMORY_BASE);
1482 u32 pref_limit = get_conf_word(d, PCI_PREF_MEMORY_LIMIT);
1483 u32 pref_type = pref_base & PCI_PREF_RANGE_TYPE_MASK;
1484 word sec_stat = get_conf_word(d, PCI_SEC_STATUS);
1485 word brc = get_conf_word(d, PCI_BRIDGE_CONTROL);
1486 int verb = verbose > 2;
1489 printf("\tBus: primary=%02x, secondary=%02x, subordinate=%02x, sec-latency=%d\n",
1490 get_conf_byte(d, PCI_PRIMARY_BUS),
1491 get_conf_byte(d, PCI_SECONDARY_BUS),
1492 get_conf_byte(d, PCI_SUBORDINATE_BUS),
1493 get_conf_byte(d, PCI_SEC_LATENCY_TIMER));
1495 if (io_type != (io_limit & PCI_IO_RANGE_TYPE_MASK) ||
1496 (io_type != PCI_IO_RANGE_TYPE_16 && io_type != PCI_IO_RANGE_TYPE_32))
1497 printf("\t!!! Unknown I/O range types %x/%x\n", io_base, io_limit);
1500 io_base = (io_base & PCI_IO_RANGE_MASK) << 8;
1501 io_limit = (io_limit & PCI_IO_RANGE_MASK) << 8;
1502 if (io_type == PCI_IO_RANGE_TYPE_32)
1504 io_base |= (get_conf_word(d, PCI_IO_BASE_UPPER16) << 16);
1505 io_limit |= (get_conf_word(d, PCI_IO_LIMIT_UPPER16) << 16);
1507 if (io_base <= io_limit || verb)
1508 printf("\tI/O behind bridge: %08x-%08x\n", io_base, io_limit+0xfff);
1511 if (mem_type != (mem_limit & PCI_MEMORY_RANGE_TYPE_MASK) ||
1513 printf("\t!!! Unknown memory range types %x/%x\n", mem_base, mem_limit);
1516 mem_base = (mem_base & PCI_MEMORY_RANGE_MASK) << 16;
1517 mem_limit = (mem_limit & PCI_MEMORY_RANGE_MASK) << 16;
1518 if (mem_base <= mem_limit || verb)
1519 printf("\tMemory behind bridge: %08x-%08x\n", mem_base, mem_limit + 0xfffff);
1522 if (pref_type != (pref_limit & PCI_PREF_RANGE_TYPE_MASK) ||
1523 (pref_type != PCI_PREF_RANGE_TYPE_32 && pref_type != PCI_PREF_RANGE_TYPE_64))
1524 printf("\t!!! Unknown prefetchable memory range types %x/%x\n", pref_base, pref_limit);
1527 pref_base = (pref_base & PCI_PREF_RANGE_MASK) << 16;
1528 pref_limit = (pref_limit & PCI_PREF_RANGE_MASK) << 16;
1529 if (pref_base <= pref_limit || verb)
1531 if (pref_type == PCI_PREF_RANGE_TYPE_32)
1532 printf("\tPrefetchable memory behind bridge: %08x-%08x\n", pref_base, pref_limit + 0xfffff);
1534 printf("\tPrefetchable memory behind bridge: %08x%08x-%08x%08x\n",
1535 get_conf_long(d, PCI_PREF_BASE_UPPER32),
1537 get_conf_long(d, PCI_PREF_LIMIT_UPPER32),
1538 pref_limit + 0xfffff);
1543 printf("\tSecondary status: 66MHz%c FastB2B%c ParErr%c DEVSEL=%s >TAbort%c <TAbort%c <MAbort%c <SERR%c <PERR%c\n",
1544 FLAG(sec_stat, PCI_STATUS_66MHZ),
1545 FLAG(sec_stat, PCI_STATUS_FAST_BACK),
1546 FLAG(sec_stat, PCI_STATUS_PARITY),
1547 ((sec_stat & PCI_STATUS_DEVSEL_MASK) == PCI_STATUS_DEVSEL_SLOW) ? "slow" :
1548 ((sec_stat & PCI_STATUS_DEVSEL_MASK) == PCI_STATUS_DEVSEL_MEDIUM) ? "medium" :
1549 ((sec_stat & PCI_STATUS_DEVSEL_MASK) == PCI_STATUS_DEVSEL_FAST) ? "fast" : "??",
1550 FLAG(sec_stat, PCI_STATUS_SIG_TARGET_ABORT),
1551 FLAG(sec_stat, PCI_STATUS_REC_TARGET_ABORT),
1552 FLAG(sec_stat, PCI_STATUS_REC_MASTER_ABORT),
1553 FLAG(sec_stat, PCI_STATUS_SIG_SYSTEM_ERROR),
1554 FLAG(sec_stat, PCI_STATUS_DETECTED_PARITY));
1556 show_rom(d, PCI_ROM_ADDRESS1);
1559 printf("\tBridgeCtl: Parity%c SERR%c NoISA%c VGA%c MAbort%c >Reset%c FastB2B%c\n",
1560 FLAG(brc, PCI_BRIDGE_CTL_PARITY),
1561 FLAG(brc, PCI_BRIDGE_CTL_SERR),
1562 FLAG(brc, PCI_BRIDGE_CTL_NO_ISA),
1563 FLAG(brc, PCI_BRIDGE_CTL_VGA),
1564 FLAG(brc, PCI_BRIDGE_CTL_MASTER_ABORT),
1565 FLAG(brc, PCI_BRIDGE_CTL_BUS_RESET),
1566 FLAG(brc, PCI_BRIDGE_CTL_FAST_BACK));
1572 show_htype2(struct device *d)
1575 word cmd = get_conf_word(d, PCI_COMMAND);
1576 word brc = get_conf_word(d, PCI_CB_BRIDGE_CONTROL);
1578 int verb = verbose > 2;
1581 printf("\tBus: primary=%02x, secondary=%02x, subordinate=%02x, sec-latency=%d\n",
1582 get_conf_byte(d, PCI_CB_PRIMARY_BUS),
1583 get_conf_byte(d, PCI_CB_CARD_BUS),
1584 get_conf_byte(d, PCI_CB_SUBORDINATE_BUS),
1585 get_conf_byte(d, PCI_CB_LATENCY_TIMER));
1589 u32 base = get_conf_long(d, PCI_CB_MEMORY_BASE_0 + p);
1590 u32 limit = get_conf_long(d, PCI_CB_MEMORY_LIMIT_0 + p);
1591 if (limit > base || verb)
1592 printf("\tMemory window %d: %08x-%08x%s%s\n", i, base, limit,
1593 (cmd & PCI_COMMAND_MEMORY) ? "" : " [disabled]",
1594 (brc & (PCI_CB_BRIDGE_CTL_PREFETCH_MEM0 << i)) ? " (prefetchable)" : "");
1599 u32 base = get_conf_long(d, PCI_CB_IO_BASE_0 + p);
1600 u32 limit = get_conf_long(d, PCI_CB_IO_LIMIT_0 + p);
1601 if (!(base & PCI_IO_RANGE_TYPE_32))
1606 base &= PCI_CB_IO_RANGE_MASK;
1607 limit = (limit & PCI_CB_IO_RANGE_MASK) + 3;
1608 if (base <= limit || verb)
1609 printf("\tI/O window %d: %08x-%08x%s\n", i, base, limit,
1610 (cmd & PCI_COMMAND_IO) ? "" : " [disabled]");
1613 if (get_conf_word(d, PCI_CB_SEC_STATUS) & PCI_STATUS_SIG_SYSTEM_ERROR)
1614 printf("\tSecondary status: SERR\n");
1616 printf("\tBridgeCtl: Parity%c SERR%c ISA%c VGA%c MAbort%c >Reset%c 16bInt%c PostWrite%c\n",
1617 FLAG(brc, PCI_CB_BRIDGE_CTL_PARITY),
1618 FLAG(brc, PCI_CB_BRIDGE_CTL_SERR),
1619 FLAG(brc, PCI_CB_BRIDGE_CTL_ISA),
1620 FLAG(brc, PCI_CB_BRIDGE_CTL_VGA),
1621 FLAG(brc, PCI_CB_BRIDGE_CTL_MASTER_ABORT),
1622 FLAG(brc, PCI_CB_BRIDGE_CTL_CB_RESET),
1623 FLAG(brc, PCI_CB_BRIDGE_CTL_16BIT_INT),
1624 FLAG(brc, PCI_CB_BRIDGE_CTL_POST_WRITES));
1626 if (d->config_cached < 128)
1628 printf("\t<access denied to the rest>\n");
1632 exca = get_conf_word(d, PCI_CB_LEGACY_MODE_BASE);
1634 printf("\t16-bit legacy interface ports at %04x\n", exca);
1638 show_verbose(struct device *d)
1640 struct pci_dev *p = d->dev;
1641 word status = get_conf_word(d, PCI_STATUS);
1642 word cmd = get_conf_word(d, PCI_COMMAND);
1643 word class = p->device_class;
1644 byte bist = get_conf_byte(d, PCI_BIST);
1645 byte htype = get_conf_byte(d, PCI_HEADER_TYPE) & 0x7f;
1646 byte latency = get_conf_byte(d, PCI_LATENCY_TIMER);
1647 byte cache_line = get_conf_byte(d, PCI_CACHE_LINE_SIZE);
1648 byte max_lat, min_gnt;
1649 byte int_pin = get_conf_byte(d, PCI_INTERRUPT_PIN);
1650 unsigned int irq = p->irq;
1651 word subsys_v = 0, subsys_d = 0;
1652 char ssnamebuf[256];
1658 case PCI_HEADER_TYPE_NORMAL:
1659 if (class == PCI_CLASS_BRIDGE_PCI)
1660 printf("\t!!! Invalid class %04x for header type %02x\n", class, htype);
1661 max_lat = get_conf_byte(d, PCI_MAX_LAT);
1662 min_gnt = get_conf_byte(d, PCI_MIN_GNT);
1663 subsys_v = get_conf_word(d, PCI_SUBSYSTEM_VENDOR_ID);
1664 subsys_d = get_conf_word(d, PCI_SUBSYSTEM_ID);
1666 case PCI_HEADER_TYPE_BRIDGE:
1667 if ((class >> 8) != PCI_BASE_CLASS_BRIDGE)
1668 printf("\t!!! Invalid class %04x for header type %02x\n", class, htype);
1669 irq = int_pin = min_gnt = max_lat = 0;
1671 case PCI_HEADER_TYPE_CARDBUS:
1672 if ((class >> 8) != PCI_BASE_CLASS_BRIDGE)
1673 printf("\t!!! Invalid class %04x for header type %02x\n", class, htype);
1674 min_gnt = max_lat = 0;
1675 if (d->config_cached >= 128)
1677 subsys_v = get_conf_word(d, PCI_CB_SUBSYSTEM_VENDOR_ID);
1678 subsys_d = get_conf_word(d, PCI_CB_SUBSYSTEM_ID);
1682 printf("\t!!! Unknown header type %02x\n", htype);
1686 if (subsys_v && subsys_v != 0xffff)
1687 printf("\tSubsystem: %s\n",
1688 pci_lookup_name(pacc, ssnamebuf, sizeof(ssnamebuf),
1689 PCI_LOOKUP_SUBSYSTEM | PCI_LOOKUP_VENDOR | PCI_LOOKUP_DEVICE,
1690 p->vendor_id, p->device_id, subsys_v, subsys_d));
1694 printf("\tControl: I/O%c Mem%c BusMaster%c SpecCycle%c MemWINV%c VGASnoop%c ParErr%c Stepping%c SERR%c FastB2B%c\n",
1695 FLAG(cmd, PCI_COMMAND_IO),
1696 FLAG(cmd, PCI_COMMAND_MEMORY),
1697 FLAG(cmd, PCI_COMMAND_MASTER),
1698 FLAG(cmd, PCI_COMMAND_SPECIAL),
1699 FLAG(cmd, PCI_COMMAND_INVALIDATE),
1700 FLAG(cmd, PCI_COMMAND_VGA_PALETTE),
1701 FLAG(cmd, PCI_COMMAND_PARITY),
1702 FLAG(cmd, PCI_COMMAND_WAIT),
1703 FLAG(cmd, PCI_COMMAND_SERR),
1704 FLAG(cmd, PCI_COMMAND_FAST_BACK));
1705 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",
1706 FLAG(status, PCI_STATUS_CAP_LIST),
1707 FLAG(status, PCI_STATUS_66MHZ),
1708 FLAG(status, PCI_STATUS_UDF),
1709 FLAG(status, PCI_STATUS_FAST_BACK),
1710 FLAG(status, PCI_STATUS_PARITY),
1711 ((status & PCI_STATUS_DEVSEL_MASK) == PCI_STATUS_DEVSEL_SLOW) ? "slow" :
1712 ((status & PCI_STATUS_DEVSEL_MASK) == PCI_STATUS_DEVSEL_MEDIUM) ? "medium" :
1713 ((status & PCI_STATUS_DEVSEL_MASK) == PCI_STATUS_DEVSEL_FAST) ? "fast" : "??",
1714 FLAG(status, PCI_STATUS_SIG_TARGET_ABORT),
1715 FLAG(status, PCI_STATUS_REC_TARGET_ABORT),
1716 FLAG(status, PCI_STATUS_REC_MASTER_ABORT),
1717 FLAG(status, PCI_STATUS_SIG_SYSTEM_ERROR),
1718 FLAG(status, PCI_STATUS_DETECTED_PARITY));
1719 if (cmd & PCI_COMMAND_MASTER)
1721 printf("\tLatency: %d", latency);
1722 if (min_gnt || max_lat)
1726 printf("%dns min", min_gnt*250);
1727 if (min_gnt && max_lat)
1730 printf("%dns max", max_lat*250);
1734 printf(", Cache Line Size: %d bytes", cache_line * 4);
1738 printf("\tInterrupt: pin %c routed to IRQ " PCIIRQ_FMT "\n",
1739 (int_pin ? 'A' + int_pin - 1 : '?'), irq);
1743 printf("\tFlags: ");
1744 if (cmd & PCI_COMMAND_MASTER)
1745 printf("bus master, ");
1746 if (cmd & PCI_COMMAND_VGA_PALETTE)
1747 printf("VGA palette snoop, ");
1748 if (cmd & PCI_COMMAND_WAIT)
1749 printf("stepping, ");
1750 if (cmd & PCI_COMMAND_FAST_BACK)
1751 printf("fast Back2Back, ");
1752 if (status & PCI_STATUS_66MHZ)
1754 if (status & PCI_STATUS_UDF)
1755 printf("user-definable features, ");
1757 ((status & PCI_STATUS_DEVSEL_MASK) == PCI_STATUS_DEVSEL_SLOW) ? "slow" :
1758 ((status & PCI_STATUS_DEVSEL_MASK) == PCI_STATUS_DEVSEL_MEDIUM) ? "medium" :
1759 ((status & PCI_STATUS_DEVSEL_MASK) == PCI_STATUS_DEVSEL_FAST) ? "fast" : "??");
1760 if (cmd & PCI_COMMAND_MASTER)
1761 printf(", latency %d", latency);
1763 printf(", IRQ " PCIIRQ_FMT, irq);
1767 if (bist & PCI_BIST_CAPABLE)
1769 if (bist & PCI_BIST_START)
1770 printf("\tBIST is running\n");
1772 printf("\tBIST result: %02x\n", bist & PCI_BIST_CODE_MASK);
1777 case PCI_HEADER_TYPE_NORMAL:
1780 case PCI_HEADER_TYPE_BRIDGE:
1783 case PCI_HEADER_TYPE_CARDBUS:
1790 show_hex_dump(struct device *d)
1792 unsigned int i, cnt;
1794 cnt = d->config_cached;
1795 if (show_hex >= 3 && config_fetch(d, cnt, 256-cnt))
1798 if (show_hex >= 4 && config_fetch(d, 256, 4096-256))
1802 for(i=0; i<cnt; i++)
1806 printf(" %02x", get_conf_byte(d, i));
1813 print_shell_escaped(char *c)
1818 if (*c == '"' || *c == '\\')
1826 show_machine(struct device *d)
1828 struct pci_dev *p = d->dev;
1830 word sv_id=0, sd_id=0;
1831 char classbuf[128], vendbuf[128], devbuf[128], svbuf[128], sdbuf[128];
1833 switch (get_conf_byte(d, PCI_HEADER_TYPE) & 0x7f)
1835 case PCI_HEADER_TYPE_NORMAL:
1836 sv_id = get_conf_word(d, PCI_SUBSYSTEM_VENDOR_ID);
1837 sd_id = get_conf_word(d, PCI_SUBSYSTEM_ID);
1839 case PCI_HEADER_TYPE_CARDBUS:
1840 if (d->config_cached >= 128)
1842 sv_id = get_conf_word(d, PCI_CB_SUBSYSTEM_VENDOR_ID);
1843 sd_id = get_conf_word(d, PCI_CB_SUBSYSTEM_ID);
1850 printf((machine_readable >= 2) ? "Slot:\t" : "Device:\t");
1853 printf("Class:\t%s\n",
1854 pci_lookup_name(pacc, classbuf, sizeof(classbuf), PCI_LOOKUP_CLASS, p->device_class));
1855 printf("Vendor:\t%s\n",
1856 pci_lookup_name(pacc, vendbuf, sizeof(vendbuf), PCI_LOOKUP_VENDOR, p->vendor_id, p->device_id));
1857 printf("Device:\t%s\n",
1858 pci_lookup_name(pacc, devbuf, sizeof(devbuf), PCI_LOOKUP_DEVICE, p->vendor_id, p->device_id));
1859 if (sv_id && sv_id != 0xffff)
1861 printf("SVendor:\t%s\n",
1862 pci_lookup_name(pacc, svbuf, sizeof(svbuf), PCI_LOOKUP_SUBSYSTEM | PCI_LOOKUP_VENDOR, sv_id));
1863 printf("SDevice:\t%s\n",
1864 pci_lookup_name(pacc, sdbuf, sizeof(sdbuf), PCI_LOOKUP_SUBSYSTEM | PCI_LOOKUP_DEVICE, p->vendor_id, p->device_id, sv_id, sd_id));
1866 if (c = get_conf_byte(d, PCI_REVISION_ID))
1867 printf("Rev:\t%02x\n", c);
1868 if (c = get_conf_byte(d, PCI_CLASS_PROG))
1869 printf("ProgIf:\t%02x\n", c);
1874 print_shell_escaped(pci_lookup_name(pacc, classbuf, sizeof(classbuf), PCI_LOOKUP_CLASS, p->device_class));
1875 print_shell_escaped(pci_lookup_name(pacc, vendbuf, sizeof(vendbuf), PCI_LOOKUP_VENDOR, p->vendor_id, p->device_id));
1876 print_shell_escaped(pci_lookup_name(pacc, devbuf, sizeof(devbuf), PCI_LOOKUP_DEVICE, p->vendor_id, p->device_id));
1877 if (c = get_conf_byte(d, PCI_REVISION_ID))
1878 printf(" -r%02x", c);
1879 if (c = get_conf_byte(d, PCI_CLASS_PROG))
1880 printf(" -p%02x", c);
1881 if (sv_id && sv_id != 0xffff)
1883 print_shell_escaped(pci_lookup_name(pacc, svbuf, sizeof(svbuf), PCI_LOOKUP_SUBSYSTEM | PCI_LOOKUP_VENDOR, sv_id));
1884 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));
1887 printf(" \"\" \"\"");
1893 show_device(struct device *d)
1895 if (machine_readable)
1903 if (verbose || show_hex)
1912 for(d=first_dev; d; d=d->next)
1919 struct bridge *chain; /* Single-linked list of bridges */
1920 struct bridge *next, *child; /* Tree of bridges */
1921 struct bus *first_bus; /* List of buses connected to this bridge */
1922 unsigned int domain;
1923 unsigned int primary, secondary, subordinate; /* Bus numbers */
1924 struct device *br_dev;
1928 unsigned int domain;
1929 unsigned int number;
1930 struct bus *sibling;
1931 struct device *first_dev, **last_dev;
1934 static struct bridge host_bridge = { NULL, NULL, NULL, NULL, 0, ~0, 0, ~0, NULL };
1937 find_bus(struct bridge *b, unsigned int domain, unsigned int n)
1941 for(bus=b->first_bus; bus; bus=bus->sibling)
1942 if (bus->domain == domain && bus->number == n)
1948 new_bus(struct bridge *b, unsigned int domain, unsigned int n)
1950 struct bus *bus = xmalloc(sizeof(struct bus));
1951 bus->domain = domain;
1953 bus->sibling = b->first_bus;
1954 bus->first_dev = NULL;
1955 bus->last_dev = &bus->first_dev;
1961 insert_dev(struct device *d, struct bridge *b)
1963 struct pci_dev *p = d->dev;
1966 if (! (bus = find_bus(b, p->domain, p->bus)))
1969 for(c=b->child; c; c=c->next)
1970 if (c->domain == p->domain && c->secondary <= p->bus && p->bus <= c->subordinate)
1975 bus = new_bus(b, p->domain, p->bus);
1977 /* Simple insertion at the end _does_ guarantee the correct order as the
1978 * original device list was sorted by (domain, bus, devfn) lexicographically
1979 * and all devices on the new list have the same bus number.
1982 bus->last_dev = &d->next;
1989 struct device *d, *d2;
1990 struct bridge **last_br, *b;
1992 /* Build list of bridges */
1994 last_br = &host_bridge.chain;
1995 for(d=first_dev; d; d=d->next)
1997 word class = d->dev->device_class;
1998 byte ht = get_conf_byte(d, PCI_HEADER_TYPE) & 0x7f;
1999 if (class == PCI_CLASS_BRIDGE_PCI &&
2000 (ht == PCI_HEADER_TYPE_BRIDGE || ht == PCI_HEADER_TYPE_CARDBUS))
2002 b = xmalloc(sizeof(struct bridge));
2003 b->domain = d->dev->domain;
2004 if (ht == PCI_HEADER_TYPE_BRIDGE)
2006 b->primary = get_conf_byte(d, PCI_CB_PRIMARY_BUS);
2007 b->secondary = get_conf_byte(d, PCI_CB_CARD_BUS);
2008 b->subordinate = get_conf_byte(d, PCI_CB_SUBORDINATE_BUS);
2012 b->primary = get_conf_byte(d, PCI_PRIMARY_BUS);
2013 b->secondary = get_conf_byte(d, PCI_SECONDARY_BUS);
2014 b->subordinate = get_conf_byte(d, PCI_SUBORDINATE_BUS);
2017 last_br = &b->chain;
2018 b->next = b->child = NULL;
2019 b->first_bus = NULL;
2025 /* Create a bridge tree */
2027 for(b=&host_bridge; b; b=b->chain)
2029 struct bridge *c, *best;
2031 for(c=&host_bridge; c; c=c->chain)
2032 if (c != b && (c == &host_bridge || b->domain == c->domain) &&
2033 b->primary >= c->secondary && b->primary <= c->subordinate &&
2034 (!best || best->subordinate - best->primary > c->subordinate - c->primary))
2038 b->next = best->child;
2043 /* Insert secondary bus for each bridge */
2045 for(b=&host_bridge; b; b=b->chain)
2046 if (!find_bus(b, b->domain, b->secondary))
2047 new_bus(b, b->domain, b->secondary);
2049 /* Create bus structs and link devices */
2051 for(d=first_dev; d;)
2054 insert_dev(d, &host_bridge);
2060 print_it(char *line, char *p)
2064 fputs(line, stdout);
2065 for(p=line; *p; p++)
2066 if (*p == '+' || *p == '|')
2072 static void show_tree_bridge(struct bridge *, char *, char *);
2075 show_tree_dev(struct device *d, char *line, char *p)
2077 struct pci_dev *q = d->dev;
2081 p += sprintf(p, "%02x.%x", q->dev, q->func);
2082 for(b=&host_bridge; b; b=b->chain)
2085 if (b->secondary == b->subordinate)
2086 p += sprintf(p, "-[%04x:%02x]-", b->domain, b->secondary);
2088 p += sprintf(p, "-[%04x:%02x-%02x]-", b->domain, b->secondary, b->subordinate);
2089 show_tree_bridge(b, line, p);
2093 p += sprintf(p, " %s",
2094 pci_lookup_name(pacc, namebuf, sizeof(namebuf),
2095 PCI_LOOKUP_VENDOR | PCI_LOOKUP_DEVICE,
2096 q->vendor_id, q->device_id));
2101 show_tree_bus(struct bus *b, char *line, char *p)
2105 else if (!b->first_dev->next)
2109 show_tree_dev(b->first_dev, line, p);
2113 struct device *d = b->first_dev;
2118 show_tree_dev(d, line, p+2);
2123 show_tree_dev(d, line, p+2);
2128 show_tree_bridge(struct bridge *b, char *line, char *p)
2131 if (!b->first_bus->sibling)
2133 if (b == &host_bridge)
2134 p += sprintf(p, "[%04x:%02x]-", b->domain, b->first_bus->number);
2135 show_tree_bus(b->first_bus, line, p);
2139 struct bus *u = b->first_bus;
2144 k = p + sprintf(p, "+-[%04x:%02x]-", u->domain, u->number);
2145 show_tree_bus(u, line, k);
2148 k = p + sprintf(p, "\\-[%04x:%02x]-", u->domain, u->number);
2149 show_tree_bus(u, line, k);
2159 show_tree_bridge(&host_bridge, line, line);
2162 /* Bus mapping mode */
2165 struct bus_bridge *next;
2166 byte this, dev, func, first, last, bug;
2172 struct bus_bridge *bridges, *via;
2175 static struct bus_info *bus_info;
2178 map_bridge(struct bus_info *bi, struct device *d, int np, int ns, int nl)
2180 struct bus_bridge *b = xmalloc(sizeof(struct bus_bridge));
2181 struct pci_dev *p = d->dev;
2183 b->next = bi->bridges;
2185 b->this = get_conf_byte(d, np);
2188 b->first = get_conf_byte(d, ns);
2189 b->last = get_conf_byte(d, nl);
2190 printf("## %02x.%02x:%d is a bridge from %02x to %02x-%02x\n",
2191 p->bus, p->dev, p->func, b->this, b->first, b->last);
2192 if (b->this != p->bus)
2193 printf("!!! Bridge points to invalid primary bus.\n");
2194 if (b->first > b->last)
2196 printf("!!! Bridge points to invalid bus range.\n");
2205 int verbose = pacc->debugging;
2206 struct bus_info *bi = bus_info + bus;
2210 printf("Mapping bus %02x\n", bus);
2211 for(dev = 0; dev < 32; dev++)
2212 if (filter.slot < 0 || filter.slot == dev)
2215 for(func = 0; func < func_limit; func++)
2216 if (filter.func < 0 || filter.func == func)
2218 /* XXX: Bus mapping supports only domain 0 */
2219 struct pci_dev *p = pci_get_dev(pacc, 0, bus, dev, func);
2220 u16 vendor = pci_read_word(p, PCI_VENDOR_ID);
2221 if (vendor && vendor != 0xffff)
2223 if (!func && (pci_read_byte(p, PCI_HEADER_TYPE) & 0x80))
2226 printf("Discovered device %02x:%02x.%d\n", bus, dev, func);
2228 if (d = scan_device(p))
2231 switch (get_conf_byte(d, PCI_HEADER_TYPE) & 0x7f)
2233 case PCI_HEADER_TYPE_BRIDGE:
2234 map_bridge(bi, d, PCI_PRIMARY_BUS, PCI_SECONDARY_BUS, PCI_SUBORDINATE_BUS);
2236 case PCI_HEADER_TYPE_CARDBUS:
2237 map_bridge(bi, d, PCI_CB_PRIMARY_BUS, PCI_CB_CARD_BUS, PCI_CB_SUBORDINATE_BUS);
2243 printf("But it was filtered out.\n");
2251 do_map_bridges(int bus, int min, int max)
2253 struct bus_info *bi = bus_info + bus;
2254 struct bus_bridge *b;
2257 for(b=bi->bridges; b; b=b->next)
2259 if (bus_info[b->first].guestbook)
2261 else if (b->first < min || b->last > max)
2265 bus_info[b->first].via = b;
2266 do_map_bridges(b->first, b->first, b->last);
2276 printf("\nSummary of buses:\n\n");
2277 for(i=0; i<256; i++)
2278 if (bus_info[i].exists && !bus_info[i].guestbook)
2279 do_map_bridges(i, 0, 255);
2280 for(i=0; i<256; i++)
2282 struct bus_info *bi = bus_info + i;
2283 struct bus_bridge *b = bi->via;
2287 printf("%02x: ", i);
2289 printf("Entered via %02x:%02x.%d\n", b->this, b->dev, b->func);
2291 printf("Primary host bus\n");
2293 printf("Secondary host bus (?)\n");
2295 for(b=bi->bridges; b; b=b->next)
2297 printf("\t%02x.%d Bridge to %02x-%02x", b->dev, b->func, b->first, b->last);
2301 printf(" <overlap bug>");
2304 printf(" <crossing bug>");
2315 if (pacc->method == PCI_ACCESS_PROC_BUS_PCI ||
2316 pacc->method == PCI_ACCESS_DUMP)
2317 printf("WARNING: Bus mapping can be reliable only with direct hardware access enabled.\n\n");
2318 bus_info = xmalloc(sizeof(struct bus_info) * 256);
2319 memset(bus_info, 0, sizeof(struct bus_info) * 256);
2320 if (filter.bus >= 0)
2321 do_map_bus(filter.bus);
2325 for(bus=0; bus<256; bus++)
2334 main(int argc, char **argv)
2339 if (argc == 2 && !strcmp(argv[1], "--version"))
2341 puts("lspci version " PCIUTILS_VERSION);
2347 pci_filter_init(pacc, &filter);
2349 while ((i = getopt(argc, argv, options)) != -1)
2353 pacc->numeric_ids++;
2359 pacc->buscentric = 1;
2360 buscentric_view = 1;
2363 if (msg = pci_filter_parse_slot(&filter, optarg))
2367 if (msg = pci_filter_parse_id(&filter, optarg))
2377 pci_set_name_list_path(pacc, optarg, 0);
2389 if (parse_generic_option(i, pacc, optarg))
2392 fprintf(stderr, help_msg, pacc->id_file_name);
2412 return (seen_errors ? 2 : 0);