2 * The PCI Utilities -- List All PCI Devices
4 * Copyright (c) 1997--2005 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 */
27 static char options[] = "nvbxs:d:ti:mgM" GENERIC_OPTIONS ;
29 static char help_msg[] = "\
30 Usage: lspci [<switches>]\n\
33 -n\t\tShow numeric ID's\n\
34 -b\t\tBus-centric view (PCI addresses and IRQ's instead of those seen by the CPU)\n\
35 -x\t\tShow hex-dump of the standard portion of config space\n\
36 -xxx\t\tShow hex-dump of the whole config space (dangerous; root only)\n\
37 -xxxx\t\tShow hex-dump of the 4096-byte extended config space (root only)\n\
38 -s [[[[<domain>]:]<bus>]:][<slot>][.[<func>]]\tShow only devices in selected slots\n\
39 -d [<vendor>]:[<device>]\tShow only selected devices\n\
40 -t\t\tShow bus tree\n\
41 -m\t\tProduce machine-readable output\n\
42 -i <file>\tUse specified ID database instead of %s\n\
43 -M\t\tEnable `bus mapping' mode (dangerous; root only)\n"
47 /* Communication with libpci */
49 static struct pci_access *pacc;
52 * If we aren't being compiled by GCC, use xmalloc() instead of alloca().
53 * This increases our memory footprint, but only slightly since we don't
59 #define alloca xmalloc
62 /* Our view of the PCI bus */
67 unsigned int config_cached, config_bufsize;
68 byte *config; /* Cached configuration space data */
69 byte *present; /* Maps which configuration bytes are present */
72 static struct device *first_dev;
75 config_fetch(struct device *d, unsigned int pos, unsigned int len)
77 unsigned int end = pos+len;
80 while (pos < d->config_bufsize && len && d->present[pos])
82 while (pos+len <= d->config_bufsize && len && d->present[pos+len-1])
87 if (end > d->config_bufsize)
89 int orig_size = d->config_bufsize;
90 while (end > d->config_bufsize)
91 d->config_bufsize *= 2;
92 d->config = xrealloc(d->config, d->config_bufsize);
93 d->present = xrealloc(d->present, d->config_bufsize);
94 bzero(d->present + orig_size, d->config_bufsize - orig_size);
96 result = pci_read_block(d->dev, pos, d->config + pos, len);
98 memset(d->present + pos, 1, len);
102 static struct device *
103 scan_device(struct pci_dev *p)
107 if (!pci_filter_match(&filter, p))
109 d = xmalloc(sizeof(struct device));
110 bzero(d, sizeof(*d));
112 d->config_cached = d->config_bufsize = 64;
113 d->config = xmalloc(64);
114 d->present = xmalloc(64);
115 memset(d->present, 1, 64);
116 if (!pci_read_block(p, 0, d->config, 64))
117 die("Unable to read the standard configuration space header");
118 if ((d->config[PCI_HEADER_TYPE] & 0x7f) == PCI_HEADER_TYPE_CARDBUS)
120 /* For cardbus bridges, we need to fetch 64 bytes more to get the
121 * full standard header... */
122 if (config_fetch(d, 64, 64))
123 d->config_cached += 64;
125 pci_setup_cache(p, d->config, d->config_cached);
126 pci_fill_info(p, PCI_FILL_IDENT | PCI_FILL_IRQ | PCI_FILL_BASES | PCI_FILL_ROM_BASE | PCI_FILL_SIZES);
137 for(p=pacc->devices; p; p=p->next)
138 if (d = scan_device(p))
145 /* Config space accesses */
148 check_conf_range(struct device *d, unsigned int pos, unsigned int len)
151 if (!d->present[pos])
152 die("Internal bug: Accessing non-read configuration byte at position %x", pos);
158 get_conf_byte(struct device *d, unsigned int pos)
160 check_conf_range(d, pos, 1);
161 return d->config[pos];
165 get_conf_word(struct device *d, unsigned int pos)
167 check_conf_range(d, pos, 2);
168 return d->config[pos] | (d->config[pos+1] << 8);
172 get_conf_long(struct device *d, unsigned int pos)
174 check_conf_range(d, pos, 4);
175 return d->config[pos] |
176 (d->config[pos+1] << 8) |
177 (d->config[pos+2] << 16) |
178 (d->config[pos+3] << 24);
184 compare_them(const void *A, const void *B)
186 const struct pci_dev *a = (*(const struct device **)A)->dev;
187 const struct pci_dev *b = (*(const struct device **)B)->dev;
189 if (a->domain < b->domain)
191 if (a->domain > b->domain)
201 if (a->func < b->func)
203 if (a->func > b->func)
211 struct device **index, **h, **last_dev;
216 for(d=first_dev; d; d=d->next)
218 h = index = alloca(sizeof(struct device *) * cnt);
219 for(d=first_dev; d; d=d->next)
221 qsort(index, cnt, sizeof(struct device *), compare_them);
222 last_dev = &first_dev;
227 last_dev = &(*h)->next;
235 #define FLAG(x,y) ((x & y) ? '+' : '-')
238 show_slot_name(struct device *d)
240 struct pci_dev *p = d->dev;
243 printf("%04x:", p->domain);
244 printf("%02x:%02x.%d", p->bus, p->dev, p->func);
248 show_terse(struct device *d)
251 struct pci_dev *p = d->dev;
252 byte classbuf[128], devbuf[128];
256 pci_lookup_name(pacc, classbuf, sizeof(classbuf),
258 get_conf_word(d, PCI_CLASS_DEVICE)),
259 pci_lookup_name(pacc, devbuf, sizeof(devbuf),
260 PCI_LOOKUP_VENDOR | PCI_LOOKUP_DEVICE,
261 p->vendor_id, p->device_id));
262 if (c = get_conf_byte(d, PCI_REVISION_ID))
263 printf(" (rev %02x)", c);
267 c = get_conf_byte(d, PCI_CLASS_PROG);
268 x = pci_lookup_name(pacc, devbuf, sizeof(devbuf),
269 PCI_LOOKUP_PROGIF | PCI_LOOKUP_NO_NUMBERS,
270 get_conf_word(d, PCI_CLASS_DEVICE), c);
273 printf(" (prog-if %02x", c);
283 show_size(pciaddr_t x)
289 printf("%d", (int) x);
290 else if (x < 1048576)
291 printf("%dK", (int)(x / 1024));
292 else if (x < 0x80000000)
293 printf("%dM", (int)(x / 1048576));
295 printf(PCIADDR_T_FMT, x);
300 show_bases(struct device *d, int cnt)
302 struct pci_dev *p = d->dev;
303 word cmd = get_conf_word(d, PCI_COMMAND);
308 pciaddr_t pos = p->base_addr[i];
309 pciaddr_t len = (p->known_fields & PCI_FILL_SIZES) ? p->size[i] : 0;
310 u32 flg = get_conf_long(d, PCI_BASE_ADDRESS_0 + 4*i);
311 if (flg == 0xffffffff)
313 if (!pos && !flg && !len)
316 printf("\tRegion %d: ", i);
319 if (pos && !flg) /* Reported by the OS, but not by the device */
321 printf("[virtual] ");
324 if (flg & PCI_BASE_ADDRESS_SPACE_IO)
326 pciaddr_t a = pos & PCI_BASE_ADDRESS_IO_MASK;
327 printf("I/O ports at ");
329 printf(PCIADDR_PORT_FMT, a);
330 else if (flg & PCI_BASE_ADDRESS_IO_MASK)
333 printf("<unassigned>");
334 if (!(cmd & PCI_COMMAND_IO))
335 printf(" [disabled]");
339 int t = flg & PCI_BASE_ADDRESS_MEM_TYPE_MASK;
340 pciaddr_t a = pos & PCI_ADDR_MEM_MASK;
344 printf("Memory at ");
345 if (t == PCI_BASE_ADDRESS_MEM_TYPE_64)
349 printf("<invalid-64bit-slot>");
355 z = get_conf_long(d, PCI_BASE_ADDRESS_0 + 4*i);
358 u32 y = a & 0xffffffff;
360 printf("%08x%08x", z, y);
362 printf("<unassigned>");
370 printf(PCIADDR_T_FMT, a);
372 printf(((flg & PCI_BASE_ADDRESS_MEM_MASK) || z) ? "<ignored>" : "<unassigned>");
374 printf(" (%s, %sprefetchable)",
375 (t == PCI_BASE_ADDRESS_MEM_TYPE_32) ? "32-bit" :
376 (t == PCI_BASE_ADDRESS_MEM_TYPE_64) ? "64-bit" :
377 (t == PCI_BASE_ADDRESS_MEM_TYPE_1M) ? "low-1M" : "type 3",
378 (flg & PCI_BASE_ADDRESS_MEM_PREFETCH) ? "" : "non-");
379 if (!(cmd & PCI_COMMAND_MEMORY))
380 printf(" [disabled]");
388 show_pm(struct device *d, int where, int cap)
391 static int pm_aux_current[8] = { 0, 55, 100, 160, 220, 270, 320, 375 };
393 printf("Power Management version %d\n", cap & PCI_PM_CAP_VER_MASK);
396 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",
397 FLAG(cap, PCI_PM_CAP_PME_CLOCK),
398 FLAG(cap, PCI_PM_CAP_DSI),
399 FLAG(cap, PCI_PM_CAP_D1),
400 FLAG(cap, PCI_PM_CAP_D2),
401 pm_aux_current[(cap >> 6) & 7],
402 FLAG(cap, PCI_PM_CAP_PME_D0),
403 FLAG(cap, PCI_PM_CAP_PME_D1),
404 FLAG(cap, PCI_PM_CAP_PME_D2),
405 FLAG(cap, PCI_PM_CAP_PME_D3_HOT),
406 FLAG(cap, PCI_PM_CAP_PME_D3_COLD));
407 if (!config_fetch(d, where + PCI_PM_CTRL, PCI_PM_SIZEOF - PCI_PM_CTRL))
409 t = get_conf_word(d, where + PCI_PM_CTRL);
410 printf("\t\tStatus: D%d PME-Enable%c DSel=%d DScale=%d PME%c\n",
411 t & PCI_PM_CTRL_STATE_MASK,
412 FLAG(t, PCI_PM_CTRL_PME_ENABLE),
413 (t & PCI_PM_CTRL_DATA_SEL_MASK) >> 9,
414 (t & PCI_PM_CTRL_DATA_SCALE_MASK) >> 13,
415 FLAG(t, PCI_PM_CTRL_PME_STATUS));
416 b = get_conf_byte(d, where + PCI_PM_PPB_EXTENSIONS);
418 printf("\t\tBridge: PM%c B3%c\n",
419 FLAG(t, PCI_PM_BPCC_ENABLE),
420 FLAG(~t, PCI_PM_PPB_B2_B3));
424 format_agp_rate(int rate, char *buf, int agp3)
434 c += sprintf(c, "x%d", 1 << (i + 2*agp3));
439 strcpy(buf, "<none>");
443 show_agp(struct device *d, int where, int cap)
450 ver = (cap >> 4) & 0x0f;
452 printf("AGP version %x.%x\n", ver, rev);
455 if (!config_fetch(d, where + PCI_AGP_STATUS, PCI_AGP_SIZEOF - PCI_AGP_STATUS))
457 t = get_conf_long(d, where + PCI_AGP_STATUS);
458 if (ver >= 3 && (t & PCI_AGP_STATUS_AGP3))
460 format_agp_rate(t & 7, rate, agp3);
461 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",
462 ((t & PCI_AGP_STATUS_RQ_MASK) >> 24U) + 1,
463 FLAG(t, PCI_AGP_STATUS_ISOCH),
464 ((t & PCI_AGP_STATUS_ARQSZ_MASK) >> 13),
465 ((t & PCI_AGP_STATUS_CAL_MASK) >> 10),
466 FLAG(t, PCI_AGP_STATUS_SBA),
467 FLAG(t, PCI_AGP_STATUS_ITA_COH),
468 FLAG(t, PCI_AGP_STATUS_GART64),
469 FLAG(t, PCI_AGP_STATUS_HTRANS),
470 FLAG(t, PCI_AGP_STATUS_64BIT),
471 FLAG(t, PCI_AGP_STATUS_FW),
472 FLAG(t, PCI_AGP_STATUS_AGP3),
474 t = get_conf_long(d, where + PCI_AGP_COMMAND);
475 format_agp_rate(t & 7, rate, agp3);
476 printf("\t\tCommand: RQ=%d ArqSz=%d Cal=%d SBA%c AGP%c GART64%c 64bit%c FW%c Rate=%s\n",
477 ((t & PCI_AGP_COMMAND_RQ_MASK) >> 24U) + 1,
478 ((t & PCI_AGP_COMMAND_ARQSZ_MASK) >> 13),
479 ((t & PCI_AGP_COMMAND_CAL_MASK) >> 10),
480 FLAG(t, PCI_AGP_COMMAND_SBA),
481 FLAG(t, PCI_AGP_COMMAND_AGP),
482 FLAG(t, PCI_AGP_COMMAND_GART64),
483 FLAG(t, PCI_AGP_COMMAND_64BIT),
484 FLAG(t, PCI_AGP_COMMAND_FW),
489 show_pcix_nobridge(struct device *d, int where)
493 static const byte max_outstanding[8] = { 1, 2, 3, 4, 8, 12, 16, 32 };
495 printf("PCI-X non-bridge device\n");
500 if (!config_fetch(d, where + PCI_PCIX_STATUS, 4))
503 command = get_conf_word(d, where + PCI_PCIX_COMMAND);
504 status = get_conf_long(d, where + PCI_PCIX_STATUS);
505 printf("\t\tCommand: DPERE%c ERO%c RBC=%d OST=%d\n",
506 FLAG(command, PCI_PCIX_COMMAND_DPERE),
507 FLAG(command, PCI_PCIX_COMMAND_ERO),
508 1 << (9 + ((command & PCI_PCIX_COMMAND_MAX_MEM_READ_BYTE_COUNT) >> 2U)),
509 max_outstanding[(command & PCI_PCIX_COMMAND_MAX_OUTSTANDING_SPLIT_TRANS) >> 4U]);
510 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",
511 ((status >> 8) & 0xff),
512 ((status >> 3) & 0x1f),
513 (status & PCI_PCIX_STATUS_FUNCTION),
514 FLAG(status, PCI_PCIX_STATUS_64BIT),
515 FLAG(status, PCI_PCIX_STATUS_133MHZ),
516 FLAG(status, PCI_PCIX_STATUS_SC_DISCARDED),
517 FLAG(status, PCI_PCIX_STATUS_UNEXPECTED_SC),
518 ((status & PCI_PCIX_STATUS_DEVICE_COMPLEXITY) ? "bridge" : "simple"),
519 1 << (9 + ((status >> 21) & 3U)),
520 max_outstanding[(status >> 23) & 7U],
521 1 << (3 + ((status >> 26) & 7U)),
522 FLAG(status, PCI_PCIX_STATUS_RCVD_SC_ERR_MESS),
523 FLAG(status, PCI_PCIX_STATUS_266MHZ),
524 FLAG(status, PCI_PCIX_STATUS_533MHZ));
528 show_pcix_bridge(struct device *d, int where)
530 static const byte * const sec_clock_freq[8] = { "conv", "66MHz", "100MHz", "133MHz", "?4", "?5", "?6", "?7" };
532 u32 status, upstcr, downstcr;
534 printf("PCI-X bridge device\n");
539 if (!config_fetch(d, where + PCI_PCIX_BRIDGE_STATUS, 12))
542 secstatus = get_conf_word(d, where + PCI_PCIX_BRIDGE_SEC_STATUS);
543 printf("\t\tSecondary Status: 64bit%c 133MHz%c SCD%c USC%c SCO%c SRD%c Freq=%s\n",
544 FLAG(secstatus, PCI_PCIX_BRIDGE_SEC_STATUS_64BIT),
545 FLAG(secstatus, PCI_PCIX_BRIDGE_SEC_STATUS_133MHZ),
546 FLAG(secstatus, PCI_PCIX_BRIDGE_SEC_STATUS_SC_DISCARDED),
547 FLAG(secstatus, PCI_PCIX_BRIDGE_SEC_STATUS_UNEXPECTED_SC),
548 FLAG(secstatus, PCI_PCIX_BRIDGE_SEC_STATUS_SC_OVERRUN),
549 FLAG(secstatus, PCI_PCIX_BRIDGE_SEC_STATUS_SPLIT_REQUEST_DELAYED),
550 sec_clock_freq[(secstatus >> 6) & 7]);
551 status = get_conf_long(d, where + PCI_PCIX_BRIDGE_STATUS);
552 printf("\t\tStatus: Dev=%02x:%02x.%d 64bit%c 133MHz%c SCD%c USC%c SCO%c SRD%c\n",
553 ((status >> 8) & 0xff),
554 ((status >> 3) & 0x1f),
555 (status & PCI_PCIX_BRIDGE_STATUS_FUNCTION),
556 FLAG(status, PCI_PCIX_BRIDGE_STATUS_64BIT),
557 FLAG(status, PCI_PCIX_BRIDGE_STATUS_133MHZ),
558 FLAG(status, PCI_PCIX_BRIDGE_STATUS_SC_DISCARDED),
559 FLAG(status, PCI_PCIX_BRIDGE_STATUS_UNEXPECTED_SC),
560 FLAG(status, PCI_PCIX_BRIDGE_STATUS_SC_OVERRUN),
561 FLAG(status, PCI_PCIX_BRIDGE_STATUS_SPLIT_REQUEST_DELAYED));
562 upstcr = get_conf_long(d, where + PCI_PCIX_BRIDGE_UPSTREAM_SPLIT_TRANS_CTRL);
563 printf("\t\tUpstream: Capacity=%u CommitmentLimit=%u\n",
564 (upstcr & PCI_PCIX_BRIDGE_STR_CAPACITY),
565 (upstcr >> 16) & 0xffff);
566 downstcr = get_conf_long(d, where + PCI_PCIX_BRIDGE_DOWNSTREAM_SPLIT_TRANS_CTRL);
567 printf("\t\tDownstream: Capacity=%u CommitmentLimit=%u\n",
568 (downstcr & PCI_PCIX_BRIDGE_STR_CAPACITY),
569 (downstcr >> 16) & 0xffff);
573 show_pcix(struct device *d, int where)
575 switch (get_conf_byte(d, PCI_HEADER_TYPE) & 0x7f)
577 case PCI_HEADER_TYPE_NORMAL:
578 show_pcix_nobridge(d, where);
580 case PCI_HEADER_TYPE_BRIDGE:
581 show_pcix_bridge(d, where);
587 ht_link_width(unsigned width)
589 static char * const widths[8] = { "8bit", "16bit", "[2]", "32bit", "2bit", "4bit", "[6]", "N/C" };
590 return widths[width];
594 ht_link_freq(unsigned freq)
596 static char * const freqs[16] = { "200MHz", "300MHz", "400MHz", "500MHz", "600MHz", "800MHz", "1.0GHz", "1.2GHz",
597 "1.4GHz", "1.6GHz", "[a]", "[b]", "[c]", "[d]", "[e]", "Vend" };
602 show_ht_pri(struct device *d, int where, int cmd)
604 u16 lctr0, lcnf0, lctr1, lcnf1, eh;
605 u8 rid, lfrer0, lfcap0, ftr, lfrer1, lfcap1, mbu, mlu, bn;
608 printf("HyperTransport: Slave or Primary Interface\n");
612 if (!config_fetch(d, where + PCI_HT_PRI_LCTR0, PCI_HT_PRI_SIZEOF - PCI_HT_PRI_LCTR0))
614 rid = get_conf_byte(d, where + PCI_HT_PRI_RID);
615 if (rid < 0x23 && rid > 0x11)
616 printf("\t\t!!! Possibly incomplete decoding\n");
619 fmt = "\t\tCommand: BaseUnitID=%u UnitCnt=%u MastHost%c DefDir%c DUL%c\n";
621 fmt = "\t\tCommand: BaseUnitID=%u UnitCnt=%u MastHost%c DefDir%c\n";
623 (cmd & PCI_HT_PRI_CMD_BUID),
624 (cmd & PCI_HT_PRI_CMD_UC) >> 5,
625 FLAG(cmd, PCI_HT_PRI_CMD_MH),
626 FLAG(cmd, PCI_HT_PRI_CMD_DD),
627 FLAG(cmd, PCI_HT_PRI_CMD_DUL));
628 lctr0 = get_conf_word(d, where + PCI_HT_PRI_LCTR0);
630 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";
632 fmt = "\t\tLink Control 0: CFlE%c CST%c CFE%c <LkFail%c Init%c EOC%c TXO%c <CRCErr=%x\n";
634 FLAG(lctr0, PCI_HT_LCTR_CFLE),
635 FLAG(lctr0, PCI_HT_LCTR_CST),
636 FLAG(lctr0, PCI_HT_LCTR_CFE),
637 FLAG(lctr0, PCI_HT_LCTR_LKFAIL),
638 FLAG(lctr0, PCI_HT_LCTR_INIT),
639 FLAG(lctr0, PCI_HT_LCTR_EOC),
640 FLAG(lctr0, PCI_HT_LCTR_TXO),
641 (lctr0 & PCI_HT_LCTR_CRCERR) >> 8,
642 FLAG(lctr0, PCI_HT_LCTR_ISOCEN),
643 FLAG(lctr0, PCI_HT_LCTR_LSEN),
644 FLAG(lctr0, PCI_HT_LCTR_EXTCTL),
645 FLAG(lctr0, PCI_HT_LCTR_64B));
646 lcnf0 = get_conf_word(d, where + PCI_HT_PRI_LCNF0);
648 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";
650 fmt = "\t\tLink Config 0: MLWI=%s MLWO=%s LWI=%s LWO=%s\n";
652 ht_link_width(lcnf0 & PCI_HT_LCNF_MLWI),
653 ht_link_width((lcnf0 & PCI_HT_LCNF_MLWO) >> 4),
654 ht_link_width((lcnf0 & PCI_HT_LCNF_LWI) >> 8),
655 ht_link_width((lcnf0 & PCI_HT_LCNF_LWO) >> 12),
656 FLAG(lcnf0, PCI_HT_LCNF_DFI),
657 FLAG(lcnf0, PCI_HT_LCNF_DFO),
658 FLAG(lcnf0, PCI_HT_LCNF_DFIE),
659 FLAG(lcnf0, PCI_HT_LCNF_DFOE));
660 lctr1 = get_conf_word(d, where + PCI_HT_PRI_LCTR1);
662 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";
664 fmt = "\t\tLink Control 1: CFlE%c CST%c CFE%c <LkFail%c Init%c EOC%c TXO%c <CRCErr=%x\n";
666 FLAG(lctr1, PCI_HT_LCTR_CFLE),
667 FLAG(lctr1, PCI_HT_LCTR_CST),
668 FLAG(lctr1, PCI_HT_LCTR_CFE),
669 FLAG(lctr1, PCI_HT_LCTR_LKFAIL),
670 FLAG(lctr1, PCI_HT_LCTR_INIT),
671 FLAG(lctr1, PCI_HT_LCTR_EOC),
672 FLAG(lctr1, PCI_HT_LCTR_TXO),
673 (lctr1 & PCI_HT_LCTR_CRCERR) >> 8,
674 FLAG(lctr1, PCI_HT_LCTR_ISOCEN),
675 FLAG(lctr1, PCI_HT_LCTR_LSEN),
676 FLAG(lctr1, PCI_HT_LCTR_EXTCTL),
677 FLAG(lctr1, PCI_HT_LCTR_64B));
678 lcnf1 = get_conf_word(d, where + PCI_HT_PRI_LCNF1);
680 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";
682 fmt = "\t\tLink Config 1: MLWI=%s MLWO=%s LWI=%s LWO=%s\n";
684 ht_link_width(lcnf1 & PCI_HT_LCNF_MLWI),
685 ht_link_width((lcnf1 & PCI_HT_LCNF_MLWO) >> 4),
686 ht_link_width((lcnf1 & PCI_HT_LCNF_LWI) >> 8),
687 ht_link_width((lcnf1 & PCI_HT_LCNF_LWO) >> 12),
688 FLAG(lcnf1, PCI_HT_LCNF_DFI),
689 FLAG(lcnf1, PCI_HT_LCNF_DFO),
690 FLAG(lcnf1, PCI_HT_LCNF_DFIE),
691 FLAG(lcnf1, PCI_HT_LCNF_DFOE));
692 printf("\t\tRevision ID: %u.%02u\n",
693 (rid & PCI_HT_RID_MAJ) >> 5, (rid & PCI_HT_RID_MIN));
696 lfrer0 = get_conf_byte(d, where + PCI_HT_PRI_LFRER0);
697 printf("\t\tLink Frequency 0: %s\n", ht_link_freq(lfrer0 & PCI_HT_LFRER_FREQ));
698 printf("\t\tLink Error 0: <Prot%c <Ovfl%c <EOC%c CTLTm%c\n",
699 FLAG(lfrer0, PCI_HT_LFRER_PROT),
700 FLAG(lfrer0, PCI_HT_LFRER_OV),
701 FLAG(lfrer0, PCI_HT_LFRER_EOC),
702 FLAG(lfrer0, PCI_HT_LFRER_CTLT));
703 lfcap0 = get_conf_byte(d, where + PCI_HT_PRI_LFCAP0);
704 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",
705 FLAG(lfcap0, PCI_HT_LFCAP_200),
706 FLAG(lfcap0, PCI_HT_LFCAP_300),
707 FLAG(lfcap0, PCI_HT_LFCAP_400),
708 FLAG(lfcap0, PCI_HT_LFCAP_500),
709 FLAG(lfcap0, PCI_HT_LFCAP_600),
710 FLAG(lfcap0, PCI_HT_LFCAP_800),
711 FLAG(lfcap0, PCI_HT_LFCAP_1000),
712 FLAG(lfcap0, PCI_HT_LFCAP_1200),
713 FLAG(lfcap0, PCI_HT_LFCAP_1400),
714 FLAG(lfcap0, PCI_HT_LFCAP_1600),
715 FLAG(lfcap0, PCI_HT_LFCAP_VEND));
716 ftr = get_conf_byte(d, where + PCI_HT_PRI_FTR);
717 printf("\t\tFeature Capability: IsocFC%c LDTSTOP%c CRCTM%c ECTLT%c 64bA%c UIDRD%c\n",
718 FLAG(ftr, PCI_HT_FTR_ISOCFC),
719 FLAG(ftr, PCI_HT_FTR_LDTSTOP),
720 FLAG(ftr, PCI_HT_FTR_CRCTM),
721 FLAG(ftr, PCI_HT_FTR_ECTLT),
722 FLAG(ftr, PCI_HT_FTR_64BA),
723 FLAG(ftr, PCI_HT_FTR_UIDRD));
724 lfrer1 = get_conf_byte(d, where + PCI_HT_PRI_LFRER1);
725 printf("\t\tLink Frequency 1: %s\n", ht_link_freq(lfrer1 & PCI_HT_LFRER_FREQ));
726 printf("\t\tLink Error 1: <Prot%c <Ovfl%c <EOC%c CTLTm%c\n",
727 FLAG(lfrer1, PCI_HT_LFRER_PROT),
728 FLAG(lfrer1, PCI_HT_LFRER_OV),
729 FLAG(lfrer1, PCI_HT_LFRER_EOC),
730 FLAG(lfrer1, PCI_HT_LFRER_CTLT));
731 lfcap1 = get_conf_byte(d, where + PCI_HT_PRI_LFCAP1);
732 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",
733 FLAG(lfcap1, PCI_HT_LFCAP_200),
734 FLAG(lfcap1, PCI_HT_LFCAP_300),
735 FLAG(lfcap1, PCI_HT_LFCAP_400),
736 FLAG(lfcap1, PCI_HT_LFCAP_500),
737 FLAG(lfcap1, PCI_HT_LFCAP_600),
738 FLAG(lfcap1, PCI_HT_LFCAP_800),
739 FLAG(lfcap1, PCI_HT_LFCAP_1000),
740 FLAG(lfcap1, PCI_HT_LFCAP_1200),
741 FLAG(lfcap1, PCI_HT_LFCAP_1400),
742 FLAG(lfcap1, PCI_HT_LFCAP_1600),
743 FLAG(lfcap1, PCI_HT_LFCAP_VEND));
744 eh = get_conf_word(d, where + PCI_HT_PRI_EH);
745 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",
746 FLAG(eh, PCI_HT_EH_PFLE),
747 FLAG(eh, PCI_HT_EH_OFLE),
748 FLAG(eh, PCI_HT_EH_PFE),
749 FLAG(eh, PCI_HT_EH_OFE),
750 FLAG(eh, PCI_HT_EH_EOCFE),
751 FLAG(eh, PCI_HT_EH_RFE),
752 FLAG(eh, PCI_HT_EH_CRCFE),
753 FLAG(eh, PCI_HT_EH_SERRFE),
754 FLAG(eh, PCI_HT_EH_CF),
755 FLAG(eh, PCI_HT_EH_RE),
756 FLAG(eh, PCI_HT_EH_PNFE),
757 FLAG(eh, PCI_HT_EH_ONFE),
758 FLAG(eh, PCI_HT_EH_EOCNFE),
759 FLAG(eh, PCI_HT_EH_RNFE),
760 FLAG(eh, PCI_HT_EH_CRCNFE),
761 FLAG(eh, PCI_HT_EH_SERRNFE));
762 mbu = get_conf_byte(d, where + PCI_HT_PRI_MBU);
763 mlu = get_conf_byte(d, where + PCI_HT_PRI_MLU);
764 printf("\t\tPrefetchable memory behind bridge Upper: %02x-%02x\n", mbu, mlu);
765 bn = get_conf_byte(d, where + PCI_HT_PRI_BN);
766 printf("\t\tBus Number: %02x\n", bn);
770 show_ht_sec(struct device *d, int where, int cmd)
772 u16 lctr, lcnf, ftr, eh;
773 u8 rid, lfrer, lfcap, mbu, mlu;
776 printf("HyperTransport: Host or Secondary Interface\n");
780 if (!config_fetch(d, where + PCI_HT_SEC_LCTR, PCI_HT_SEC_SIZEOF - PCI_HT_SEC_LCTR))
782 rid = get_conf_byte(d, where + PCI_HT_SEC_RID);
783 if (rid < 0x23 && rid > 0x11)
784 printf("\t\t!!! Possibly incomplete decoding\n");
787 fmt = "\t\tCommand: WarmRst%c DblEnd%c DevNum=%u ChainSide%c HostHide%c Slave%c <EOCErr%c DUL%c\n";
789 fmt = "\t\tCommand: WarmRst%c DblEnd%c\n";
791 FLAG(cmd, PCI_HT_SEC_CMD_WR),
792 FLAG(cmd, PCI_HT_SEC_CMD_DE),
793 (cmd & PCI_HT_SEC_CMD_DN) >> 2,
794 FLAG(cmd, PCI_HT_SEC_CMD_CS),
795 FLAG(cmd, PCI_HT_SEC_CMD_HH),
796 FLAG(cmd, PCI_HT_SEC_CMD_AS),
797 FLAG(cmd, PCI_HT_SEC_CMD_HIECE),
798 FLAG(cmd, PCI_HT_SEC_CMD_DUL));
799 lctr = get_conf_word(d, where + PCI_HT_SEC_LCTR);
801 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";
803 fmt = "\t\tLink Control: CFlE%c CST%c CFE%c <LkFail%c Init%c EOC%c TXO%c <CRCErr=%x\n";
805 FLAG(lctr, PCI_HT_LCTR_CFLE),
806 FLAG(lctr, PCI_HT_LCTR_CST),
807 FLAG(lctr, PCI_HT_LCTR_CFE),
808 FLAG(lctr, PCI_HT_LCTR_LKFAIL),
809 FLAG(lctr, PCI_HT_LCTR_INIT),
810 FLAG(lctr, PCI_HT_LCTR_EOC),
811 FLAG(lctr, PCI_HT_LCTR_TXO),
812 (lctr & PCI_HT_LCTR_CRCERR) >> 8,
813 FLAG(lctr, PCI_HT_LCTR_ISOCEN),
814 FLAG(lctr, PCI_HT_LCTR_LSEN),
815 FLAG(lctr, PCI_HT_LCTR_EXTCTL),
816 FLAG(lctr, PCI_HT_LCTR_64B));
817 lcnf = get_conf_word(d, where + PCI_HT_SEC_LCNF);
819 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";
821 fmt = "\t\tLink Config: MLWI=%s MLWO=%s LWI=%s LWO=%s\n";
823 ht_link_width(lcnf & PCI_HT_LCNF_MLWI),
824 ht_link_width((lcnf & PCI_HT_LCNF_MLWO) >> 4),
825 ht_link_width((lcnf & PCI_HT_LCNF_LWI) >> 8),
826 ht_link_width((lcnf & PCI_HT_LCNF_LWO) >> 12),
827 FLAG(lcnf, PCI_HT_LCNF_DFI),
828 FLAG(lcnf, PCI_HT_LCNF_DFO),
829 FLAG(lcnf, PCI_HT_LCNF_DFIE),
830 FLAG(lcnf, PCI_HT_LCNF_DFOE));
831 printf("\t\tRevision ID: %u.%02u\n",
832 (rid & PCI_HT_RID_MAJ) >> 5, (rid & PCI_HT_RID_MIN));
835 lfrer = get_conf_byte(d, where + PCI_HT_SEC_LFRER);
836 printf("\t\tLink Frequency: %s\n", ht_link_freq(lfrer & PCI_HT_LFRER_FREQ));
837 printf("\t\tLink Error: <Prot%c <Ovfl%c <EOC%c CTLTm%c\n",
838 FLAG(lfrer, PCI_HT_LFRER_PROT),
839 FLAG(lfrer, PCI_HT_LFRER_OV),
840 FLAG(lfrer, PCI_HT_LFRER_EOC),
841 FLAG(lfrer, PCI_HT_LFRER_CTLT));
842 lfcap = get_conf_byte(d, where + PCI_HT_SEC_LFCAP);
843 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",
844 FLAG(lfcap, PCI_HT_LFCAP_200),
845 FLAG(lfcap, PCI_HT_LFCAP_300),
846 FLAG(lfcap, PCI_HT_LFCAP_400),
847 FLAG(lfcap, PCI_HT_LFCAP_500),
848 FLAG(lfcap, PCI_HT_LFCAP_600),
849 FLAG(lfcap, PCI_HT_LFCAP_800),
850 FLAG(lfcap, PCI_HT_LFCAP_1000),
851 FLAG(lfcap, PCI_HT_LFCAP_1200),
852 FLAG(lfcap, PCI_HT_LFCAP_1400),
853 FLAG(lfcap, PCI_HT_LFCAP_1600),
854 FLAG(lfcap, PCI_HT_LFCAP_VEND));
855 ftr = get_conf_word(d, where + PCI_HT_SEC_FTR);
856 printf("\t\tFeature Capability: IsocFC%c LDTSTOP%c CRCTM%c ECTLT%c 64bA%c UIDRD%c ExtRS%c UCnfE%c\n",
857 FLAG(ftr, PCI_HT_FTR_ISOCFC),
858 FLAG(ftr, PCI_HT_FTR_LDTSTOP),
859 FLAG(ftr, PCI_HT_FTR_CRCTM),
860 FLAG(ftr, PCI_HT_FTR_ECTLT),
861 FLAG(ftr, PCI_HT_FTR_64BA),
862 FLAG(ftr, PCI_HT_FTR_UIDRD),
863 FLAG(ftr, PCI_HT_SEC_FTR_EXTRS),
864 FLAG(ftr, PCI_HT_SEC_FTR_UCNFE));
865 if (ftr & PCI_HT_SEC_FTR_EXTRS)
867 eh = get_conf_word(d, where + PCI_HT_SEC_EH);
868 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",
869 FLAG(eh, PCI_HT_EH_PFLE),
870 FLAG(eh, PCI_HT_EH_OFLE),
871 FLAG(eh, PCI_HT_EH_PFE),
872 FLAG(eh, PCI_HT_EH_OFE),
873 FLAG(eh, PCI_HT_EH_EOCFE),
874 FLAG(eh, PCI_HT_EH_RFE),
875 FLAG(eh, PCI_HT_EH_CRCFE),
876 FLAG(eh, PCI_HT_EH_SERRFE),
877 FLAG(eh, PCI_HT_EH_CF),
878 FLAG(eh, PCI_HT_EH_RE),
879 FLAG(eh, PCI_HT_EH_PNFE),
880 FLAG(eh, PCI_HT_EH_ONFE),
881 FLAG(eh, PCI_HT_EH_EOCNFE),
882 FLAG(eh, PCI_HT_EH_RNFE),
883 FLAG(eh, PCI_HT_EH_CRCNFE),
884 FLAG(eh, PCI_HT_EH_SERRNFE));
885 mbu = get_conf_byte(d, where + PCI_HT_SEC_MBU);
886 mlu = get_conf_byte(d, where + PCI_HT_SEC_MLU);
887 printf("\t\tPrefetchable memory behind bridge Upper: %02x-%02x\n", mbu, mlu);
892 show_ht(struct device *d, int where, int cmd)
896 switch (cmd & PCI_HT_CMD_TYP_HI)
898 case PCI_HT_CMD_TYP_HI_PRI:
899 show_ht_pri(d, where, cmd);
901 case PCI_HT_CMD_TYP_HI_SEC:
902 show_ht_sec(d, where, cmd);
906 type = cmd & PCI_HT_CMD_TYP;
909 case PCI_HT_CMD_TYP_SW:
910 printf("HyperTransport: Switch\n");
912 case PCI_HT_CMD_TYP_IDC:
913 printf("HyperTransport: Interrupt Discovery and Configuration\n");
915 case PCI_HT_CMD_TYP_RID:
916 printf("HyperTransport: Revision ID: %u.%02u\n",
917 (cmd & PCI_HT_RID_MAJ) >> 5, (cmd & PCI_HT_RID_MIN));
919 case PCI_HT_CMD_TYP_UIDC:
920 printf("HyperTransport: UnitID Clumping\n");
922 case PCI_HT_CMD_TYP_ECSA:
923 printf("HyperTransport: Extended Configuration Space Access\n");
925 case PCI_HT_CMD_TYP_AM:
926 printf("HyperTransport: Address Mapping\n");
928 case PCI_HT_CMD_TYP_MSIM:
929 printf("HyperTransport: MSI Mapping\n");
931 case PCI_HT_CMD_TYP_DR:
932 printf("HyperTransport: DirectRoute\n");
934 case PCI_HT_CMD_TYP_VCS:
935 printf("HyperTransport: VCSet\n");
937 case PCI_HT_CMD_TYP_RM:
938 printf("HyperTransport: Retry Mode\n");
940 case PCI_HT_CMD_TYP_X86:
941 printf("HyperTransport: X86 (reserved)\n");
944 printf("HyperTransport: #%02x\n", type >> 11);
949 show_rom(struct device *d, int reg)
951 struct pci_dev *p = d->dev;
952 pciaddr_t rom = p->rom_base_addr;
953 pciaddr_t len = (p->known_fields & PCI_FILL_SIZES) ? p->rom_size : 0;
954 u32 flg = get_conf_long(d, reg);
955 word cmd = get_conf_word(d, PCI_COMMAND);
957 if (!rom && !flg && !len)
960 if ((rom & PCI_ROM_ADDRESS_MASK) && !(flg & PCI_ROM_ADDRESS_MASK))
962 printf("[virtual] ");
965 printf("Expansion ROM at ");
966 if (rom & PCI_ROM_ADDRESS_MASK)
967 printf(PCIADDR_T_FMT, rom & PCI_ROM_ADDRESS_MASK);
968 else if (flg & PCI_ROM_ADDRESS_MASK)
971 printf("<unassigned>");
972 if (!(flg & PCI_ROM_ADDRESS_ENABLE))
973 printf(" [disabled]");
974 else if (!(cmd & PCI_COMMAND_MEMORY))
975 printf(" [disabled by cmd]");
981 show_msi(struct device *d, int where, int cap)
987 printf("Message Signalled Interrupts: 64bit%c Queue=%d/%d Enable%c\n",
988 FLAG(cap, PCI_MSI_FLAGS_64BIT),
989 (cap & PCI_MSI_FLAGS_QSIZE) >> 4,
990 (cap & PCI_MSI_FLAGS_QMASK) >> 1,
991 FLAG(cap, PCI_MSI_FLAGS_ENABLE));
994 is64 = cap & PCI_MSI_FLAGS_64BIT;
995 if (!config_fetch(d, where + PCI_MSI_ADDRESS_LO, (is64 ? PCI_MSI_DATA_64 : PCI_MSI_DATA_32) + 2 - PCI_MSI_ADDRESS_LO))
997 printf("\t\tAddress: ");
1000 t = get_conf_long(d, where + PCI_MSI_ADDRESS_HI);
1001 w = get_conf_word(d, where + PCI_MSI_DATA_64);
1005 w = get_conf_word(d, where + PCI_MSI_DATA_32);
1006 t = get_conf_long(d, where + PCI_MSI_ADDRESS_LO);
1007 printf("%08x Data: %04x\n", t, w);
1010 static void show_vendor(void)
1012 printf("Vendor Specific Information\n");
1015 static void show_debug(void)
1017 printf("Debug port\n");
1020 static float power_limit(int value, int scale)
1022 static const float scales[4] = { 1.0, 0.1, 0.01, 0.001 };
1023 return value * scales[scale];
1026 static const char *latency_l0s(int value)
1028 static const char *latencies[] = { "<64ns", "<128ns", "<256ns", "<512ns", "<1us", "<2us", "<4us", "unlimited" };
1029 return latencies[value];
1032 static const char *latency_l1(int value)
1034 static const char *latencies[] = { "<1us", "<2us", "<4us", "<8us", "<16us", "<32us", "<64us", "unlimited" };
1035 return latencies[value];
1038 static void show_express_dev(struct device *d, int where, int type)
1043 t = get_conf_long(d, where + PCI_EXP_DEVCAP);
1044 printf("\t\tDevice: Supported: MaxPayload %d bytes, PhantFunc %d, ExtTag%c\n",
1045 128 << (t & PCI_EXP_DEVCAP_PAYLOAD),
1046 (1 << ((t & PCI_EXP_DEVCAP_PHANTOM) >> 3)) - 1,
1047 FLAG(t, PCI_EXP_DEVCAP_EXT_TAG));
1048 printf("\t\tDevice: Latency L0s %s, L1 %s\n",
1049 latency_l0s((t & PCI_EXP_DEVCAP_L0S) >> 6),
1050 latency_l1((t & PCI_EXP_DEVCAP_L1) >> 9));
1051 if ((type == PCI_EXP_TYPE_ENDPOINT) || (type == PCI_EXP_TYPE_LEG_END) ||
1052 (type == PCI_EXP_TYPE_UPSTREAM) || (type == PCI_EXP_TYPE_PCI_BRIDGE))
1053 printf("\t\tDevice: AtnBtn%c AtnInd%c PwrInd%c\n",
1054 FLAG(t, PCI_EXP_DEVCAP_ATN_BUT),
1055 FLAG(t, PCI_EXP_DEVCAP_ATN_IND), FLAG(t, PCI_EXP_DEVCAP_PWR_IND));
1056 if (type == PCI_EXP_TYPE_UPSTREAM)
1057 printf("\t\tDevice: SlotPowerLimit %f\n",
1058 power_limit((t & PCI_EXP_DEVCAP_PWR_VAL) >> 18,
1059 (t & PCI_EXP_DEVCAP_PWR_SCL) >> 26));
1061 w = get_conf_word(d, where + PCI_EXP_DEVCTL);
1062 printf("\t\tDevice: Errors: Correctable%c Non-Fatal%c Fatal%c Unsupported%c\n",
1063 FLAG(w, PCI_EXP_DEVCTL_CERE),
1064 FLAG(w, PCI_EXP_DEVCTL_NFERE),
1065 FLAG(w, PCI_EXP_DEVCTL_FERE),
1066 FLAG(w, PCI_EXP_DEVCTL_URRE));
1067 printf("\t\tDevice: RlxdOrd%c ExtTag%c PhantFunc%c AuxPwr%c NoSnoop%c\n",
1068 FLAG(w, PCI_EXP_DEVCTL_RELAXED),
1069 FLAG(w, PCI_EXP_DEVCTL_EXT_TAG),
1070 FLAG(w, PCI_EXP_DEVCTL_PHANTOM),
1071 FLAG(w, PCI_EXP_DEVCTL_AUX_PME),
1072 FLAG(w, PCI_EXP_DEVCTL_NOSNOOP));
1073 printf("\t\tDevice: MaxPayload %d bytes, MaxReadReq %d bytes\n",
1074 128 << ((w & PCI_EXP_DEVCTL_PAYLOAD) >> 5),
1075 128 << ((w & PCI_EXP_DEVCTL_READRQ) >> 12));
1078 static char *link_speed(int speed)
1089 static char *aspm_support(int code)
1102 static const char *aspm_enabled(int code)
1104 static const char *desc[] = { "Disabled", "L0s Enabled", "L1 Enabled", "L0s L1 Enabled" };
1108 static void show_express_link(struct device *d, int where, int type)
1113 t = get_conf_long(d, where + PCI_EXP_LNKCAP);
1114 printf("\t\tLink: Supported Speed %s, Width x%d, ASPM %s, Port %d\n",
1115 link_speed(t & PCI_EXP_LNKCAP_SPEED), (t & PCI_EXP_LNKCAP_WIDTH) >> 4,
1116 aspm_support((t & PCI_EXP_LNKCAP_ASPM) >> 10),
1118 printf("\t\tLink: Latency L0s %s, L1 %s\n",
1119 latency_l0s((t & PCI_EXP_LNKCAP_L0S) >> 12),
1120 latency_l1((t & PCI_EXP_LNKCAP_L1) >> 15));
1121 w = get_conf_word(d, where + PCI_EXP_LNKCTL);
1122 printf("\t\tLink: ASPM %s", aspm_enabled(w & PCI_EXP_LNKCTL_ASPM));
1123 if ((type == PCI_EXP_TYPE_ROOT_PORT) || (type == PCI_EXP_TYPE_ENDPOINT) ||
1124 (type == PCI_EXP_TYPE_LEG_END))
1125 printf(" RCB %d bytes", w & PCI_EXP_LNKCTL_RCB ? 128 : 64);
1126 if (w & PCI_EXP_LNKCTL_DISABLE)
1127 printf(" Disabled");
1128 printf(" CommClk%c ExtSynch%c\n", FLAG(w, PCI_EXP_LNKCTL_CLOCK),
1129 FLAG(w, PCI_EXP_LNKCTL_XSYNCH));
1130 w = get_conf_word(d, where + PCI_EXP_LNKSTA);
1131 printf("\t\tLink: Speed %s, Width x%d\n",
1132 link_speed(t & PCI_EXP_LNKSTA_SPEED), (t & PCI_EXP_LNKSTA_WIDTH) >> 4);
1135 static const char *indicator(int code)
1137 static const char *names[] = { "Unknown", "On", "Blink", "Off" };
1141 static void show_express_slot(struct device *d, int where)
1146 t = get_conf_long(d, where + PCI_EXP_SLTCAP);
1147 printf("\t\tSlot: AtnBtn%c PwrCtrl%c MRL%c AtnInd%c PwrInd%c HotPlug%c Surpise%c\n",
1148 FLAG(t, PCI_EXP_SLTCAP_ATNB),
1149 FLAG(t, PCI_EXP_SLTCAP_PWRC),
1150 FLAG(t, PCI_EXP_SLTCAP_MRL),
1151 FLAG(t, PCI_EXP_SLTCAP_ATNI),
1152 FLAG(t, PCI_EXP_SLTCAP_PWRI),
1153 FLAG(t, PCI_EXP_SLTCAP_HPC),
1154 FLAG(t, PCI_EXP_SLTCAP_HPS));
1155 printf("\t\tSlot: Number %d, PowerLimit %f\n", t >> 19,
1156 power_limit((t & PCI_EXP_SLTCAP_PWR_VAL) >> 7,
1157 (t & PCI_EXP_SLTCAP_PWR_SCL) >> 15));
1158 w = get_conf_word(d, where + PCI_EXP_SLTCTL);
1159 printf("\t\tSlot: Enabled AtnBtn%c PwrFlt%c MRL%c PresDet%c CmdCplt%c HPIrq%c\n",
1160 FLAG(w, PCI_EXP_SLTCTL_ATNB),
1161 FLAG(w, PCI_EXP_SLTCTL_PWRF),
1162 FLAG(w, PCI_EXP_SLTCTL_MRLS),
1163 FLAG(w, PCI_EXP_SLTCTL_PRSD),
1164 FLAG(w, PCI_EXP_SLTCTL_CMDC),
1165 FLAG(w, PCI_EXP_SLTCTL_HPIE));
1166 printf("\t\tSlot: AttnInd %s, PwrInd %s, Power%c\n",
1167 indicator((w & PCI_EXP_SLTCTL_ATNI) >> 6),
1168 indicator((w & PCI_EXP_SLTCTL_PWRI) >> 8),
1169 FLAG(w, w & PCI_EXP_SLTCTL_PWRC));
1172 static void show_express_root(struct device *d, int where)
1174 u16 w = get_conf_word(d, where + PCI_EXP_RTCTL);
1175 printf("\t\tRoot: Correctable%c Non-Fatal%c Fatal%c PME%c\n",
1176 FLAG(w, PCI_EXP_RTCTL_SECEE),
1177 FLAG(w, PCI_EXP_RTCTL_SENFEE),
1178 FLAG(w, PCI_EXP_RTCTL_SEFEE),
1179 FLAG(w, PCI_EXP_RTCTL_PMEIE));
1183 show_express(struct device *d, int where, int cap)
1185 int type = (cap & PCI_EXP_FLAGS_TYPE) >> 4;
1192 case PCI_EXP_TYPE_ENDPOINT:
1195 case PCI_EXP_TYPE_LEG_END:
1196 printf("Legacy Endpoint");
1198 case PCI_EXP_TYPE_ROOT_PORT:
1199 slot = cap & PCI_EXP_FLAGS_SLOT;
1200 printf("Root Port (Slot%c)", FLAG(cap, PCI_EXP_FLAGS_SLOT));
1202 case PCI_EXP_TYPE_UPSTREAM:
1203 printf("Upstream Port");
1205 case PCI_EXP_TYPE_DOWNSTREAM:
1206 slot = cap & PCI_EXP_FLAGS_SLOT;
1207 printf("Downstream Port (Slot%c)", FLAG(cap, PCI_EXP_FLAGS_SLOT));
1209 case PCI_EXP_TYPE_PCI_BRIDGE:
1210 printf("PCI/PCI-X Bridge");
1213 printf("Unknown type");
1215 printf(" IRQ %d\n", (cap & PCI_EXP_FLAGS_IRQ) >> 9);
1222 if (type == PCI_EXP_TYPE_ROOT_PORT)
1224 if (!config_fetch(d, where + PCI_EXP_DEVCAP, size))
1227 show_express_dev(d, where, type);
1228 show_express_link(d, where, type);
1230 show_express_slot(d, where);
1231 if (type == PCI_EXP_TYPE_ROOT_PORT)
1232 show_express_root(d, where);
1236 show_msix(struct device *d, int where, int cap)
1240 printf("MSI-X: Enable%c Mask%c TabSize=%d\n",
1241 FLAG(cap, PCI_MSIX_ENABLE),
1242 FLAG(cap, PCI_MSIX_MASK),
1243 (cap & PCI_MSIX_TABSIZE) + 1);
1244 if (verbose < 2 || !config_fetch(d, where + PCI_MSIX_TABLE, 8))
1247 off = get_conf_long(d, where + PCI_MSIX_TABLE);
1248 printf("\t\tVector table: BAR=%d offset=%08x\n",
1249 off & PCI_MSIX_BIR, off & ~PCI_MSIX_BIR);
1250 off = get_conf_long(d, where + PCI_MSIX_PBA);
1251 printf("\t\tPBA: BAR=%d offset=%08x\n",
1252 off & PCI_MSIX_BIR, off & ~PCI_MSIX_BIR);
1256 show_slotid(int cap)
1258 int esr = cap & 0xff;
1261 printf("Slot ID: %d slots, First%c, chassis %02x\n",
1262 esr & PCI_SID_ESR_NSLOTS,
1263 FLAG(esr, PCI_SID_ESR_FIC),
1268 show_aer(struct device *d UNUSED, int where UNUSED)
1270 printf("Advanced Error Reporting\n");
1274 show_vc(struct device *d UNUSED, int where UNUSED)
1276 printf("Virtual Channel\n");
1280 show_dsn(struct device *d, int where)
1283 if (!config_fetch(d, where + 4, 8))
1285 t1 = get_conf_long(d, where + 4);
1286 t2 = get_conf_long(d, where + 8);
1287 printf("Device Serial Number %02x-%02x-%02x-%02x-%02x-%02x-%02x-%02x\n",
1288 t1 & 0xff, (t1 >> 8) & 0xff, (t1 >> 16) & 0xff, t1 >> 24,
1289 t2 & 0xff, (t2 >> 8) & 0xff, (t2 >> 16) & 0xff, t2 >> 24);
1293 show_pb(struct device *d UNUSED, int where UNUSED)
1295 printf("Power Budgeting\n");
1299 show_ext_caps(struct device *d)
1307 if (!config_fetch(d, where, 4))
1309 header = get_conf_long(d, where);
1312 id = header & 0xffff;
1313 printf("\tCapabilities: [%03x] ", where);
1316 case PCI_EXT_CAP_ID_AER:
1319 case PCI_EXT_CAP_ID_VC:
1322 case PCI_EXT_CAP_ID_DSN:
1325 case PCI_EXT_CAP_ID_PB:
1329 printf("Unknown (%d)\n", id);
1332 where = header >> 20;
1337 show_caps(struct device *d)
1339 int can_have_ext_caps = 0;
1341 if (get_conf_word(d, PCI_STATUS) & PCI_STATUS_CAP_LIST)
1343 int where = get_conf_byte(d, PCI_CAPABILITY_LIST) & ~3;
1347 printf("\tCapabilities: ");
1348 if (!config_fetch(d, where, 4))
1350 puts("<access denied>");
1353 id = get_conf_byte(d, where + PCI_CAP_LIST_ID);
1354 next = get_conf_byte(d, where + PCI_CAP_LIST_NEXT) & ~3;
1355 cap = get_conf_word(d, where + PCI_CAP_FLAGS);
1356 printf("[%02x] ", where);
1359 printf("<chain broken>\n");
1365 show_pm(d, where, cap);
1367 case PCI_CAP_ID_AGP:
1368 show_agp(d, where, cap);
1370 case PCI_CAP_ID_VPD:
1371 printf("Vital Product Data\n");
1373 case PCI_CAP_ID_SLOTID:
1376 case PCI_CAP_ID_MSI:
1377 show_msi(d, where, cap);
1379 case PCI_CAP_ID_PCIX:
1380 show_pcix(d, where);
1381 can_have_ext_caps = 1;
1384 show_ht(d, where, cap);
1386 case PCI_CAP_ID_VNDR:
1389 case PCI_CAP_ID_DBG:
1392 case PCI_CAP_ID_EXP:
1393 show_express(d, where, cap);
1394 can_have_ext_caps = 1;
1396 case PCI_CAP_ID_MSIX:
1397 show_msix(d, where, cap);
1400 printf("#%02x [%04x]\n", id, cap);
1405 if (can_have_ext_caps)
1410 show_htype0(struct device *d)
1413 show_rom(d, PCI_ROM_ADDRESS);
1418 show_htype1(struct device *d)
1420 u32 io_base = get_conf_byte(d, PCI_IO_BASE);
1421 u32 io_limit = get_conf_byte(d, PCI_IO_LIMIT);
1422 u32 io_type = io_base & PCI_IO_RANGE_TYPE_MASK;
1423 u32 mem_base = get_conf_word(d, PCI_MEMORY_BASE);
1424 u32 mem_limit = get_conf_word(d, PCI_MEMORY_LIMIT);
1425 u32 mem_type = mem_base & PCI_MEMORY_RANGE_TYPE_MASK;
1426 u32 pref_base = get_conf_word(d, PCI_PREF_MEMORY_BASE);
1427 u32 pref_limit = get_conf_word(d, PCI_PREF_MEMORY_LIMIT);
1428 u32 pref_type = pref_base & PCI_PREF_RANGE_TYPE_MASK;
1429 word sec_stat = get_conf_word(d, PCI_SEC_STATUS);
1430 word brc = get_conf_word(d, PCI_BRIDGE_CONTROL);
1431 int verb = verbose > 2;
1434 printf("\tBus: primary=%02x, secondary=%02x, subordinate=%02x, sec-latency=%d\n",
1435 get_conf_byte(d, PCI_PRIMARY_BUS),
1436 get_conf_byte(d, PCI_SECONDARY_BUS),
1437 get_conf_byte(d, PCI_SUBORDINATE_BUS),
1438 get_conf_byte(d, PCI_SEC_LATENCY_TIMER));
1440 if (io_type != (io_limit & PCI_IO_RANGE_TYPE_MASK) ||
1441 (io_type != PCI_IO_RANGE_TYPE_16 && io_type != PCI_IO_RANGE_TYPE_32))
1442 printf("\t!!! Unknown I/O range types %x/%x\n", io_base, io_limit);
1445 io_base = (io_base & PCI_IO_RANGE_MASK) << 8;
1446 io_limit = (io_limit & PCI_IO_RANGE_MASK) << 8;
1447 if (io_type == PCI_IO_RANGE_TYPE_32)
1449 io_base |= (get_conf_word(d, PCI_IO_BASE_UPPER16) << 16);
1450 io_limit |= (get_conf_word(d, PCI_IO_LIMIT_UPPER16) << 16);
1452 if (io_base <= io_limit || verb)
1453 printf("\tI/O behind bridge: %08x-%08x\n", io_base, io_limit+0xfff);
1456 if (mem_type != (mem_limit & PCI_MEMORY_RANGE_TYPE_MASK) ||
1458 printf("\t!!! Unknown memory range types %x/%x\n", mem_base, mem_limit);
1461 mem_base = (mem_base & PCI_MEMORY_RANGE_MASK) << 16;
1462 mem_limit = (mem_limit & PCI_MEMORY_RANGE_MASK) << 16;
1463 if (mem_base <= mem_limit || verb)
1464 printf("\tMemory behind bridge: %08x-%08x\n", mem_base, mem_limit + 0xfffff);
1467 if (pref_type != (pref_limit & PCI_PREF_RANGE_TYPE_MASK) ||
1468 (pref_type != PCI_PREF_RANGE_TYPE_32 && pref_type != PCI_PREF_RANGE_TYPE_64))
1469 printf("\t!!! Unknown prefetchable memory range types %x/%x\n", pref_base, pref_limit);
1472 pref_base = (pref_base & PCI_PREF_RANGE_MASK) << 16;
1473 pref_limit = (pref_limit & PCI_PREF_RANGE_MASK) << 16;
1474 if (pref_base <= pref_limit || verb)
1476 if (pref_type == PCI_PREF_RANGE_TYPE_32)
1477 printf("\tPrefetchable memory behind bridge: %08x-%08x\n", pref_base, pref_limit + 0xfffff);
1479 printf("\tPrefetchable memory behind bridge: %08x%08x-%08x%08x\n",
1480 get_conf_long(d, PCI_PREF_BASE_UPPER32),
1482 get_conf_long(d, PCI_PREF_LIMIT_UPPER32),
1488 printf("\tSecondary status: 66MHz%c FastB2B%c ParErr%c DEVSEL=%s >TAbort%c <TAbort%c <MAbort%c <SERR%c <PERR%c\n",
1489 FLAG(sec_stat, PCI_STATUS_66MHZ),
1490 FLAG(sec_stat, PCI_STATUS_FAST_BACK),
1491 FLAG(sec_stat, PCI_STATUS_PARITY),
1492 ((sec_stat & PCI_STATUS_DEVSEL_MASK) == PCI_STATUS_DEVSEL_SLOW) ? "slow" :
1493 ((sec_stat & PCI_STATUS_DEVSEL_MASK) == PCI_STATUS_DEVSEL_MEDIUM) ? "medium" :
1494 ((sec_stat & PCI_STATUS_DEVSEL_MASK) == PCI_STATUS_DEVSEL_FAST) ? "fast" : "??",
1495 FLAG(sec_stat, PCI_STATUS_SIG_TARGET_ABORT),
1496 FLAG(sec_stat, PCI_STATUS_REC_TARGET_ABORT),
1497 FLAG(sec_stat, PCI_STATUS_REC_MASTER_ABORT),
1498 FLAG(sec_stat, PCI_STATUS_SIG_SYSTEM_ERROR),
1499 FLAG(sec_stat, PCI_STATUS_DETECTED_PARITY));
1501 show_rom(d, PCI_ROM_ADDRESS1);
1504 printf("\tBridgeCtl: Parity%c SERR%c NoISA%c VGA%c MAbort%c >Reset%c FastB2B%c\n",
1505 FLAG(brc, PCI_BRIDGE_CTL_PARITY),
1506 FLAG(brc, PCI_BRIDGE_CTL_SERR),
1507 FLAG(brc, PCI_BRIDGE_CTL_NO_ISA),
1508 FLAG(brc, PCI_BRIDGE_CTL_VGA),
1509 FLAG(brc, PCI_BRIDGE_CTL_MASTER_ABORT),
1510 FLAG(brc, PCI_BRIDGE_CTL_BUS_RESET),
1511 FLAG(brc, PCI_BRIDGE_CTL_FAST_BACK));
1517 show_htype2(struct device *d)
1520 word cmd = get_conf_word(d, PCI_COMMAND);
1521 word brc = get_conf_word(d, PCI_CB_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_CB_PRIMARY_BUS),
1528 get_conf_byte(d, PCI_CB_CARD_BUS),
1529 get_conf_byte(d, PCI_CB_SUBORDINATE_BUS),
1530 get_conf_byte(d, PCI_CB_LATENCY_TIMER));
1534 u32 base = get_conf_long(d, PCI_CB_MEMORY_BASE_0 + p);
1535 u32 limit = get_conf_long(d, PCI_CB_MEMORY_LIMIT_0 + p);
1536 if (limit > base || verb)
1537 printf("\tMemory window %d: %08x-%08x%s%s\n", i, base, limit,
1538 (cmd & PCI_COMMAND_MEMORY) ? "" : " [disabled]",
1539 (brc & (PCI_CB_BRIDGE_CTL_PREFETCH_MEM0 << i)) ? " (prefetchable)" : "");
1544 u32 base = get_conf_long(d, PCI_CB_IO_BASE_0 + p);
1545 u32 limit = get_conf_long(d, PCI_CB_IO_LIMIT_0 + p);
1546 if (!(base & PCI_IO_RANGE_TYPE_32))
1551 base &= PCI_CB_IO_RANGE_MASK;
1552 limit = (limit & PCI_CB_IO_RANGE_MASK) + 3;
1553 if (base <= limit || verb)
1554 printf("\tI/O window %d: %08x-%08x%s\n", i, base, limit,
1555 (cmd & PCI_COMMAND_IO) ? "" : " [disabled]");
1558 if (get_conf_word(d, PCI_CB_SEC_STATUS) & PCI_STATUS_SIG_SYSTEM_ERROR)
1559 printf("\tSecondary status: SERR\n");
1561 printf("\tBridgeCtl: Parity%c SERR%c ISA%c VGA%c MAbort%c >Reset%c 16bInt%c PostWrite%c\n",
1562 FLAG(brc, PCI_CB_BRIDGE_CTL_PARITY),
1563 FLAG(brc, PCI_CB_BRIDGE_CTL_SERR),
1564 FLAG(brc, PCI_CB_BRIDGE_CTL_ISA),
1565 FLAG(brc, PCI_CB_BRIDGE_CTL_VGA),
1566 FLAG(brc, PCI_CB_BRIDGE_CTL_MASTER_ABORT),
1567 FLAG(brc, PCI_CB_BRIDGE_CTL_CB_RESET),
1568 FLAG(brc, PCI_CB_BRIDGE_CTL_16BIT_INT),
1569 FLAG(brc, PCI_CB_BRIDGE_CTL_POST_WRITES));
1571 if (d->config_cached < 128)
1573 printf("\t<access denied to the rest>\n");
1577 exca = get_conf_word(d, PCI_CB_LEGACY_MODE_BASE);
1579 printf("\t16-bit legacy interface ports at %04x\n", exca);
1583 show_verbose(struct device *d)
1585 struct pci_dev *p = d->dev;
1586 word status = get_conf_word(d, PCI_STATUS);
1587 word cmd = get_conf_word(d, PCI_COMMAND);
1588 word class = get_conf_word(d, PCI_CLASS_DEVICE);
1589 byte bist = get_conf_byte(d, PCI_BIST);
1590 byte htype = get_conf_byte(d, PCI_HEADER_TYPE) & 0x7f;
1591 byte latency = get_conf_byte(d, PCI_LATENCY_TIMER);
1592 byte cache_line = get_conf_byte(d, PCI_CACHE_LINE_SIZE);
1593 byte max_lat, min_gnt;
1594 byte int_pin = get_conf_byte(d, PCI_INTERRUPT_PIN);
1595 unsigned int irq = p->irq;
1596 word subsys_v = 0, subsys_d = 0;
1597 char ssnamebuf[256];
1603 case PCI_HEADER_TYPE_NORMAL:
1604 if (class == PCI_CLASS_BRIDGE_PCI)
1605 printf("\t!!! Invalid class %04x for header type %02x\n", class, htype);
1606 max_lat = get_conf_byte(d, PCI_MAX_LAT);
1607 min_gnt = get_conf_byte(d, PCI_MIN_GNT);
1608 subsys_v = get_conf_word(d, PCI_SUBSYSTEM_VENDOR_ID);
1609 subsys_d = get_conf_word(d, PCI_SUBSYSTEM_ID);
1611 case PCI_HEADER_TYPE_BRIDGE:
1612 if ((class >> 8) != PCI_BASE_CLASS_BRIDGE)
1613 printf("\t!!! Invalid class %04x for header type %02x\n", class, htype);
1614 irq = int_pin = min_gnt = max_lat = 0;
1616 case PCI_HEADER_TYPE_CARDBUS:
1617 if ((class >> 8) != PCI_BASE_CLASS_BRIDGE)
1618 printf("\t!!! Invalid class %04x for header type %02x\n", class, htype);
1619 min_gnt = max_lat = 0;
1620 if (d->config_cached >= 128)
1622 subsys_v = get_conf_word(d, PCI_CB_SUBSYSTEM_VENDOR_ID);
1623 subsys_d = get_conf_word(d, PCI_CB_SUBSYSTEM_ID);
1627 printf("\t!!! Unknown header type %02x\n", htype);
1631 if (subsys_v && subsys_v != 0xffff)
1632 printf("\tSubsystem: %s\n",
1633 pci_lookup_name(pacc, ssnamebuf, sizeof(ssnamebuf),
1634 PCI_LOOKUP_SUBSYSTEM | PCI_LOOKUP_VENDOR | PCI_LOOKUP_DEVICE,
1635 p->vendor_id, p->device_id, subsys_v, subsys_d));
1639 printf("\tControl: I/O%c Mem%c BusMaster%c SpecCycle%c MemWINV%c VGASnoop%c ParErr%c Stepping%c SERR%c FastB2B%c\n",
1640 FLAG(cmd, PCI_COMMAND_IO),
1641 FLAG(cmd, PCI_COMMAND_MEMORY),
1642 FLAG(cmd, PCI_COMMAND_MASTER),
1643 FLAG(cmd, PCI_COMMAND_SPECIAL),
1644 FLAG(cmd, PCI_COMMAND_INVALIDATE),
1645 FLAG(cmd, PCI_COMMAND_VGA_PALETTE),
1646 FLAG(cmd, PCI_COMMAND_PARITY),
1647 FLAG(cmd, PCI_COMMAND_WAIT),
1648 FLAG(cmd, PCI_COMMAND_SERR),
1649 FLAG(cmd, PCI_COMMAND_FAST_BACK));
1650 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",
1651 FLAG(status, PCI_STATUS_CAP_LIST),
1652 FLAG(status, PCI_STATUS_66MHZ),
1653 FLAG(status, PCI_STATUS_UDF),
1654 FLAG(status, PCI_STATUS_FAST_BACK),
1655 FLAG(status, PCI_STATUS_PARITY),
1656 ((status & PCI_STATUS_DEVSEL_MASK) == PCI_STATUS_DEVSEL_SLOW) ? "slow" :
1657 ((status & PCI_STATUS_DEVSEL_MASK) == PCI_STATUS_DEVSEL_MEDIUM) ? "medium" :
1658 ((status & PCI_STATUS_DEVSEL_MASK) == PCI_STATUS_DEVSEL_FAST) ? "fast" : "??",
1659 FLAG(status, PCI_STATUS_SIG_TARGET_ABORT),
1660 FLAG(status, PCI_STATUS_REC_TARGET_ABORT),
1661 FLAG(status, PCI_STATUS_REC_MASTER_ABORT),
1662 FLAG(status, PCI_STATUS_SIG_SYSTEM_ERROR),
1663 FLAG(status, PCI_STATUS_DETECTED_PARITY));
1664 if (cmd & PCI_COMMAND_MASTER)
1666 printf("\tLatency: %d", latency);
1667 if (min_gnt || max_lat)
1671 printf("%dns min", min_gnt*250);
1672 if (min_gnt && max_lat)
1675 printf("%dns max", max_lat*250);
1679 printf(", Cache Line Size %02x", cache_line);
1683 printf("\tInterrupt: pin %c routed to IRQ " PCIIRQ_FMT "\n",
1684 (int_pin ? 'A' + int_pin - 1 : '?'), irq);
1688 printf("\tFlags: ");
1689 if (cmd & PCI_COMMAND_MASTER)
1690 printf("bus master, ");
1691 if (cmd & PCI_COMMAND_VGA_PALETTE)
1692 printf("VGA palette snoop, ");
1693 if (cmd & PCI_COMMAND_WAIT)
1694 printf("stepping, ");
1695 if (cmd & PCI_COMMAND_FAST_BACK)
1696 printf("fast Back2Back, ");
1697 if (status & PCI_STATUS_66MHZ)
1699 if (status & PCI_STATUS_UDF)
1700 printf("user-definable features, ");
1702 ((status & PCI_STATUS_DEVSEL_MASK) == PCI_STATUS_DEVSEL_SLOW) ? "slow" :
1703 ((status & PCI_STATUS_DEVSEL_MASK) == PCI_STATUS_DEVSEL_MEDIUM) ? "medium" :
1704 ((status & PCI_STATUS_DEVSEL_MASK) == PCI_STATUS_DEVSEL_FAST) ? "fast" : "??");
1705 if (cmd & PCI_COMMAND_MASTER)
1706 printf(", latency %d", latency);
1708 printf(", IRQ " PCIIRQ_FMT, irq);
1712 if (bist & PCI_BIST_CAPABLE)
1714 if (bist & PCI_BIST_START)
1715 printf("\tBIST is running\n");
1717 printf("\tBIST result: %02x\n", bist & PCI_BIST_CODE_MASK);
1722 case PCI_HEADER_TYPE_NORMAL:
1725 case PCI_HEADER_TYPE_BRIDGE:
1728 case PCI_HEADER_TYPE_CARDBUS:
1735 show_hex_dump(struct device *d)
1737 unsigned int i, cnt;
1739 cnt = d->config_cached;
1740 if (show_hex >= 3 && config_fetch(d, cnt, 256-cnt))
1743 if (show_hex >= 4 && config_fetch(d, 256, 4096-256))
1747 for(i=0; i<cnt; i++)
1751 printf(" %02x", get_conf_byte(d, i));
1758 show_machine(struct device *d)
1760 struct pci_dev *p = d->dev;
1762 word sv_id=0, sd_id=0;
1763 char classbuf[128], vendbuf[128], devbuf[128], svbuf[128], sdbuf[128];
1765 switch (get_conf_byte(d, PCI_HEADER_TYPE) & 0x7f)
1767 case PCI_HEADER_TYPE_NORMAL:
1768 sv_id = get_conf_word(d, PCI_SUBSYSTEM_VENDOR_ID);
1769 sd_id = get_conf_word(d, PCI_SUBSYSTEM_ID);
1771 case PCI_HEADER_TYPE_CARDBUS:
1772 if (d->config_cached >= 128)
1774 sv_id = get_conf_word(d, PCI_CB_SUBSYSTEM_VENDOR_ID);
1775 sd_id = get_conf_word(d, PCI_CB_SUBSYSTEM_ID);
1782 printf("Device:\t");
1785 printf("Class:\t%s\n",
1786 pci_lookup_name(pacc, classbuf, sizeof(classbuf), PCI_LOOKUP_CLASS, get_conf_word(d, PCI_CLASS_DEVICE)));
1787 printf("Vendor:\t%s\n",
1788 pci_lookup_name(pacc, vendbuf, sizeof(vendbuf), PCI_LOOKUP_VENDOR, p->vendor_id, p->device_id));
1789 printf("Device:\t%s\n",
1790 pci_lookup_name(pacc, devbuf, sizeof(devbuf), PCI_LOOKUP_DEVICE, p->vendor_id, p->device_id));
1791 if (sv_id && sv_id != 0xffff)
1793 printf("SVendor:\t%s\n",
1794 pci_lookup_name(pacc, svbuf, sizeof(svbuf), PCI_LOOKUP_SUBSYSTEM | PCI_LOOKUP_VENDOR, p->vendor_id, p->device_id, sv_id, sd_id));
1795 printf("SDevice:\t%s\n",
1796 pci_lookup_name(pacc, sdbuf, sizeof(sdbuf), PCI_LOOKUP_SUBSYSTEM | PCI_LOOKUP_DEVICE, p->vendor_id, p->device_id, sv_id, sd_id));
1798 if (c = get_conf_byte(d, PCI_REVISION_ID))
1799 printf("Rev:\t%02x\n", c);
1800 if (c = get_conf_byte(d, PCI_CLASS_PROG))
1801 printf("ProgIf:\t%02x\n", c);
1806 printf(" \"%s\" \"%s\" \"%s\"",
1807 pci_lookup_name(pacc, classbuf, sizeof(classbuf), PCI_LOOKUP_CLASS,
1808 get_conf_word(d, PCI_CLASS_DEVICE)),
1809 pci_lookup_name(pacc, vendbuf, sizeof(vendbuf), PCI_LOOKUP_VENDOR,
1810 p->vendor_id, p->device_id),
1811 pci_lookup_name(pacc, devbuf, sizeof(devbuf), PCI_LOOKUP_DEVICE,
1812 p->vendor_id, p->device_id));
1813 if (c = get_conf_byte(d, PCI_REVISION_ID))
1814 printf(" -r%02x", c);
1815 if (c = get_conf_byte(d, PCI_CLASS_PROG))
1816 printf(" -p%02x", c);
1817 if (sv_id && sv_id != 0xffff)
1818 printf(" \"%s\" \"%s\"",
1819 pci_lookup_name(pacc, svbuf, sizeof(svbuf), PCI_LOOKUP_SUBSYSTEM | PCI_LOOKUP_VENDOR, p->vendor_id, p->device_id, sv_id, sd_id),
1820 pci_lookup_name(pacc, sdbuf, sizeof(sdbuf), PCI_LOOKUP_SUBSYSTEM | PCI_LOOKUP_DEVICE, p->vendor_id, p->device_id, sv_id, sd_id));
1822 printf(" \"\" \"\"");
1828 show_device(struct device *d)
1830 if (machine_readable)
1838 if (verbose || show_hex)
1847 for(d=first_dev; d; d=d->next)
1854 struct bridge *chain; /* Single-linked list of bridges */
1855 struct bridge *next, *child; /* Tree of bridges */
1856 struct bus *first_bus; /* List of buses connected to this bridge */
1857 unsigned int domain;
1858 unsigned int primary, secondary, subordinate; /* Bus numbers */
1859 struct device *br_dev;
1863 unsigned int domain;
1864 unsigned int number;
1865 struct bus *sibling;
1866 struct device *first_dev, **last_dev;
1869 static struct bridge host_bridge = { NULL, NULL, NULL, NULL, 0, ~0, 0, ~0, NULL };
1872 find_bus(struct bridge *b, unsigned int domain, unsigned int n)
1876 for(bus=b->first_bus; bus; bus=bus->sibling)
1877 if (bus->domain == domain && bus->number == n)
1883 new_bus(struct bridge *b, unsigned int domain, unsigned int n)
1885 struct bus *bus = xmalloc(sizeof(struct bus));
1887 bus = xmalloc(sizeof(struct bus));
1888 bus->domain = domain;
1890 bus->sibling = b->first_bus;
1891 bus->first_dev = NULL;
1892 bus->last_dev = &bus->first_dev;
1898 insert_dev(struct device *d, struct bridge *b)
1900 struct pci_dev *p = d->dev;
1903 if (! (bus = find_bus(b, p->domain, p->bus)))
1906 for(c=b->child; c; c=c->next)
1907 if (c->domain == p->domain && c->secondary <= p->bus && p->bus <= c->subordinate)
1912 bus = new_bus(b, p->domain, p->bus);
1914 /* Simple insertion at the end _does_ guarantee the correct order as the
1915 * original device list was sorted by (domain, bus, devfn) lexicographically
1916 * and all devices on the new list have the same bus number.
1919 bus->last_dev = &d->next;
1926 struct device *d, *d2;
1927 struct bridge **last_br, *b;
1929 /* Build list of bridges */
1931 last_br = &host_bridge.chain;
1932 for(d=first_dev; d; d=d->next)
1934 word class = get_conf_word(d, PCI_CLASS_DEVICE);
1935 byte ht = get_conf_byte(d, PCI_HEADER_TYPE) & 0x7f;
1936 if (class == PCI_CLASS_BRIDGE_PCI &&
1937 (ht == PCI_HEADER_TYPE_BRIDGE || ht == PCI_HEADER_TYPE_CARDBUS))
1939 b = xmalloc(sizeof(struct bridge));
1940 b->domain = d->dev->domain;
1941 if (ht == PCI_HEADER_TYPE_BRIDGE)
1943 b->primary = get_conf_byte(d, PCI_CB_PRIMARY_BUS);
1944 b->secondary = get_conf_byte(d, PCI_CB_CARD_BUS);
1945 b->subordinate = get_conf_byte(d, PCI_CB_SUBORDINATE_BUS);
1949 b->primary = get_conf_byte(d, PCI_PRIMARY_BUS);
1950 b->secondary = get_conf_byte(d, PCI_SECONDARY_BUS);
1951 b->subordinate = get_conf_byte(d, PCI_SUBORDINATE_BUS);
1954 last_br = &b->chain;
1955 b->next = b->child = NULL;
1956 b->first_bus = NULL;
1962 /* Create a bridge tree */
1964 for(b=&host_bridge; b; b=b->chain)
1966 struct bridge *c, *best;
1968 for(c=&host_bridge; c; c=c->chain)
1969 if (c != b && (c == &host_bridge || b->domain == c->domain) &&
1970 b->primary >= c->secondary && b->primary <= c->subordinate &&
1971 (!best || best->subordinate - best->primary > c->subordinate - c->primary))
1975 b->next = best->child;
1980 /* Insert secondary bus for each bridge */
1982 for(b=&host_bridge; b; b=b->chain)
1983 if (!find_bus(b, b->domain, b->secondary))
1984 new_bus(b, b->domain, b->secondary);
1986 /* Create bus structs and link devices */
1988 for(d=first_dev; d;)
1991 insert_dev(d, &host_bridge);
1997 print_it(byte *line, byte *p)
2001 fputs(line, stdout);
2002 for(p=line; *p; p++)
2003 if (*p == '+' || *p == '|')
2009 static void show_tree_bridge(struct bridge *, byte *, byte *);
2012 show_tree_dev(struct device *d, byte *line, byte *p)
2014 struct pci_dev *q = d->dev;
2018 p += sprintf(p, "%02x.%x", q->dev, q->func);
2019 for(b=&host_bridge; b; b=b->chain)
2022 if (b->secondary == b->subordinate)
2023 p += sprintf(p, "-[%04x:%02x]-", b->domain, b->secondary);
2025 p += sprintf(p, "-[%04x:%02x-%02x]-", b->domain, b->secondary, b->subordinate);
2026 show_tree_bridge(b, line, p);
2030 p += sprintf(p, " %s",
2031 pci_lookup_name(pacc, namebuf, sizeof(namebuf),
2032 PCI_LOOKUP_VENDOR | PCI_LOOKUP_DEVICE,
2033 q->vendor_id, q->device_id));
2038 show_tree_bus(struct bus *b, byte *line, byte *p)
2042 else if (!b->first_dev->next)
2046 show_tree_dev(b->first_dev, line, p);
2050 struct device *d = b->first_dev;
2055 show_tree_dev(d, line, p+2);
2060 show_tree_dev(d, line, p+2);
2065 show_tree_bridge(struct bridge *b, byte *line, byte *p)
2068 if (!b->first_bus->sibling)
2070 if (b == &host_bridge)
2071 p += sprintf(p, "[%04x:%02x]-", b->domain, b->first_bus->number);
2072 show_tree_bus(b->first_bus, line, p);
2076 struct bus *u = b->first_bus;
2081 k = p + sprintf(p, "+-[%04x:%02x]-", u->domain, u->number);
2082 show_tree_bus(u, line, k);
2085 k = p + sprintf(p, "\\-[%04x:%02x]-", u->domain, u->number);
2086 show_tree_bus(u, line, k);
2096 show_tree_bridge(&host_bridge, line, line);
2099 /* Bus mapping mode */
2102 struct bus_bridge *next;
2103 byte this, dev, func, first, last, bug;
2109 struct bus_bridge *bridges, *via;
2112 static struct bus_info *bus_info;
2115 map_bridge(struct bus_info *bi, struct device *d, int np, int ns, int nl)
2117 struct bus_bridge *b = xmalloc(sizeof(struct bus_bridge));
2118 struct pci_dev *p = d->dev;
2120 b->next = bi->bridges;
2122 b->this = get_conf_byte(d, np);
2125 b->first = get_conf_byte(d, ns);
2126 b->last = get_conf_byte(d, nl);
2127 printf("## %02x.%02x:%d is a bridge from %02x to %02x-%02x\n",
2128 p->bus, p->dev, p->func, b->this, b->first, b->last);
2129 if (b->this != p->bus)
2130 printf("!!! Bridge points to invalid primary bus.\n");
2131 if (b->first > b->last)
2133 printf("!!! Bridge points to invalid bus range.\n");
2142 int verbose = pacc->debugging;
2143 struct bus_info *bi = bus_info + bus;
2147 printf("Mapping bus %02x\n", bus);
2148 for(dev = 0; dev < 32; dev++)
2149 if (filter.slot < 0 || filter.slot == dev)
2152 for(func = 0; func < func_limit; func++)
2153 if (filter.func < 0 || filter.func == func)
2155 /* XXX: Bus mapping supports only domain 0 */
2156 struct pci_dev *p = pci_get_dev(pacc, 0, bus, dev, func);
2157 u16 vendor = pci_read_word(p, PCI_VENDOR_ID);
2158 if (vendor && vendor != 0xffff)
2160 if (!func && (pci_read_byte(p, PCI_HEADER_TYPE) & 0x80))
2163 printf("Discovered device %02x:%02x.%d\n", bus, dev, func);
2165 if (d = scan_device(p))
2168 switch (get_conf_byte(d, PCI_HEADER_TYPE) & 0x7f)
2170 case PCI_HEADER_TYPE_BRIDGE:
2171 map_bridge(bi, d, PCI_PRIMARY_BUS, PCI_SECONDARY_BUS, PCI_SUBORDINATE_BUS);
2173 case PCI_HEADER_TYPE_CARDBUS:
2174 map_bridge(bi, d, PCI_CB_PRIMARY_BUS, PCI_CB_CARD_BUS, PCI_CB_SUBORDINATE_BUS);
2180 printf("But it was filtered out.\n");
2188 do_map_bridges(int bus, int min, int max)
2190 struct bus_info *bi = bus_info + bus;
2191 struct bus_bridge *b;
2194 for(b=bi->bridges; b; b=b->next)
2196 if (bus_info[b->first].guestbook)
2198 else if (b->first < min || b->last > max)
2202 bus_info[b->first].via = b;
2203 do_map_bridges(b->first, b->first, b->last);
2213 printf("\nSummary of buses:\n\n");
2214 for(i=0; i<256; i++)
2215 if (bus_info[i].exists && !bus_info[i].guestbook)
2216 do_map_bridges(i, 0, 255);
2217 for(i=0; i<256; i++)
2219 struct bus_info *bi = bus_info + i;
2220 struct bus_bridge *b = bi->via;
2224 printf("%02x: ", i);
2226 printf("Entered via %02x:%02x.%d\n", b->this, b->dev, b->func);
2228 printf("Primary host bus\n");
2230 printf("Secondary host bus (?)\n");
2232 for(b=bi->bridges; b; b=b->next)
2234 printf("\t%02x.%d Bridge to %02x-%02x", b->dev, b->func, b->first, b->last);
2238 printf(" <overlap bug>");
2241 printf(" <crossing bug>");
2252 if (pacc->method == PCI_ACCESS_PROC_BUS_PCI ||
2253 pacc->method == PCI_ACCESS_DUMP)
2254 printf("WARNING: Bus mapping can be reliable only with direct hardware access enabled.\n\n");
2255 bus_info = xmalloc(sizeof(struct bus_info) * 256);
2256 bzero(bus_info, sizeof(struct bus_info) * 256);
2257 if (filter.bus >= 0)
2258 do_map_bus(filter.bus);
2262 for(bus=0; bus<256; bus++)
2271 main(int argc, char **argv)
2276 if (argc == 2 && !strcmp(argv[1], "--version"))
2278 puts("lspci version " PCIUTILS_VERSION);
2284 pci_filter_init(pacc, &filter);
2286 while ((i = getopt(argc, argv, options)) != -1)
2290 pacc->numeric_ids = 1;
2296 pacc->buscentric = 1;
2297 buscentric_view = 1;
2300 if (msg = pci_filter_parse_slot(&filter, optarg))
2304 if (msg = pci_filter_parse_id(&filter, optarg))
2314 pacc->id_file_name = optarg;
2323 if (parse_generic_option(i, pacc, optarg))
2326 fprintf(stderr, help_msg, pacc->id_file_name);