2 * The PCI Utilities -- List All PCI Devices
4 * Copyright (c) 1997--2008 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 opt_buscentric; /* Show bus addresses/IRQ's instead of CPU-visible ones */
21 static int opt_hex; /* Show contents of config space as hexadecimal numbers */
22 static struct pci_filter filter; /* Device filter */
23 static int opt_tree; /* Show bus tree */
24 static int opt_machine; /* Generate machine-readable output */
25 static int opt_map_mode; /* Bus mapping mode enabled */
26 static int opt_domains; /* Show domain numbers (0=disabled, 1=auto-detected, 2=requested) */
27 static int opt_kernel; /* Show kernel drivers */
28 static int opt_query_dns; /* Query the DNS (0=disabled, 1=enabled, 2=refresh cache) */
29 static int opt_query_all; /* Query the DNS for all entries */
30 static char *opt_pcimap; /* Override path to Linux modules.pcimap */
32 const char program_name[] = "lspci";
34 static char options[] = "nvbxs:d:ti:mgp:qkMDQ" GENERIC_OPTIONS ;
36 static char help_msg[] =
37 "Usage: lspci [<switches>]\n"
40 "-n\t\tShow numeric ID's\n"
41 "-nn\t\tShow both textual and numeric ID's (names & numbers)\n"
43 "-q\t\tQuery the PCI ID database for unknown ID's via DNS\n"
44 "-qq\t\tAs above, but re-query locally cached entries\n"
45 "-Q\t\tQuery the PCI ID database for all ID's via DNS\n"
47 "-b\t\tBus-centric view (PCI addresses and IRQ's instead of those seen by the CPU)\n"
48 "-x\t\tShow hex-dump of the standard portion of config space\n"
49 "-xxx\t\tShow hex-dump of the whole config space (dangerous; root only)\n"
50 "-xxxx\t\tShow hex-dump of the 4096-byte extended config space (root only)\n"
51 "-s [[[[<domain>]:]<bus>]:][<slot>][.[<func>]]\tShow only devices in selected slots\n"
52 "-d [<vendor>]:[<device>]\tShow only selected devices\n"
53 "-t\t\tShow bus tree\n"
54 "-m\t\tProduce machine-readable output\n"
55 "-i <file>\tUse specified ID database instead of %s\n"
57 "-k\t\tShow kernel drivers handling each device\n"
58 "-p <file>\tLook up kernel modules in a given file instead of default modules.pcimap\n"
60 "-D\t\tAlways show domain numbers\n"
61 "-M\t\tEnable `bus mapping' mode (dangerous; root only)\n"
65 /*** Communication with libpci ***/
67 static struct pci_access *pacc;
70 * If we aren't being compiled by GCC, use xmalloc() instead of alloca().
71 * This increases our memory footprint, but only slightly since we don't
74 #if defined (__FreeBSD__) || defined (__NetBSD__) || defined (__OpenBSD__) || defined (__DragonFly__)
75 /* alloca() is defined in stdlib.h */
76 #elif defined(__GNUC__) && !defined(PCI_OS_WINDOWS)
80 #define alloca xmalloc
83 /*** Our view of the PCI bus ***/
88 unsigned int config_cached, config_bufsize;
89 byte *config; /* Cached configuration space data */
90 byte *present; /* Maps which configuration bytes are present */
93 static struct device *first_dev;
94 static int seen_errors;
97 config_fetch(struct device *d, unsigned int pos, unsigned int len)
99 unsigned int end = pos+len;
102 while (pos < d->config_bufsize && len && d->present[pos])
104 while (pos+len <= d->config_bufsize && len && d->present[pos+len-1])
109 if (end > d->config_bufsize)
111 int orig_size = d->config_bufsize;
112 while (end > d->config_bufsize)
113 d->config_bufsize *= 2;
114 d->config = xrealloc(d->config, d->config_bufsize);
115 d->present = xrealloc(d->present, d->config_bufsize);
116 memset(d->present + orig_size, 0, d->config_bufsize - orig_size);
118 result = pci_read_block(d->dev, pos, d->config + pos, len);
120 memset(d->present + pos, 1, len);
124 static struct device *
125 scan_device(struct pci_dev *p)
129 if (p->domain && !opt_domains)
131 if (!pci_filter_match(&filter, p))
133 d = xmalloc(sizeof(struct device));
134 memset(d, 0, sizeof(*d));
136 d->config_cached = d->config_bufsize = 64;
137 d->config = xmalloc(64);
138 d->present = xmalloc(64);
139 memset(d->present, 1, 64);
140 if (!pci_read_block(p, 0, d->config, 64))
142 fprintf(stderr, "lspci: Unable to read the standard configuration space header of device %04x:%02x:%02x.%d\n",
143 p->domain, p->bus, p->dev, p->func);
147 if ((d->config[PCI_HEADER_TYPE] & 0x7f) == PCI_HEADER_TYPE_CARDBUS)
149 /* For cardbus bridges, we need to fetch 64 bytes more to get the
150 * full standard header... */
151 if (config_fetch(d, 64, 64))
152 d->config_cached += 64;
154 pci_setup_cache(p, d->config, d->config_cached);
155 pci_fill_info(p, PCI_FILL_IDENT | PCI_FILL_CLASS | PCI_FILL_IRQ | PCI_FILL_BASES | PCI_FILL_ROM_BASE | PCI_FILL_SIZES);
166 for(p=pacc->devices; p; p=p->next)
167 if (d = scan_device(p))
174 /*** Config space accesses ***/
177 check_conf_range(struct device *d, unsigned int pos, unsigned int len)
180 if (!d->present[pos])
181 die("Internal bug: Accessing non-read configuration byte at position %x", pos);
187 get_conf_byte(struct device *d, unsigned int pos)
189 check_conf_range(d, pos, 1);
190 return d->config[pos];
194 get_conf_word(struct device *d, unsigned int pos)
196 check_conf_range(d, pos, 2);
197 return d->config[pos] | (d->config[pos+1] << 8);
201 get_conf_long(struct device *d, unsigned int pos)
203 check_conf_range(d, pos, 4);
204 return d->config[pos] |
205 (d->config[pos+1] << 8) |
206 (d->config[pos+2] << 16) |
207 (d->config[pos+3] << 24);
213 compare_them(const void *A, const void *B)
215 const struct pci_dev *a = (*(const struct device **)A)->dev;
216 const struct pci_dev *b = (*(const struct device **)B)->dev;
218 if (a->domain < b->domain)
220 if (a->domain > b->domain)
230 if (a->func < b->func)
232 if (a->func > b->func)
240 struct device **index, **h, **last_dev;
245 for(d=first_dev; d; d=d->next)
247 h = index = alloca(sizeof(struct device *) * cnt);
248 for(d=first_dev; d; d=d->next)
250 qsort(index, cnt, sizeof(struct device *), compare_them);
251 last_dev = &first_dev;
256 last_dev = &(*h)->next;
262 /*** Normal output ***/
264 #define FLAG(x,y) ((x & y) ? '+' : '-')
267 show_slot_name(struct device *d)
269 struct pci_dev *p = d->dev;
271 if (!opt_machine ? opt_domains : (p->domain || opt_domains >= 2))
272 printf("%04x:", p->domain);
273 printf("%02x:%02x.%d", p->bus, p->dev, p->func);
277 show_terse(struct device *d)
280 struct pci_dev *p = d->dev;
281 char classbuf[128], devbuf[128];
285 pci_lookup_name(pacc, classbuf, sizeof(classbuf),
288 pci_lookup_name(pacc, devbuf, sizeof(devbuf),
289 PCI_LOOKUP_VENDOR | PCI_LOOKUP_DEVICE,
290 p->vendor_id, p->device_id));
291 if (c = get_conf_byte(d, PCI_REVISION_ID))
292 printf(" (rev %02x)", c);
296 c = get_conf_byte(d, PCI_CLASS_PROG);
297 x = pci_lookup_name(pacc, devbuf, sizeof(devbuf),
298 PCI_LOOKUP_PROGIF | PCI_LOOKUP_NO_NUMBERS,
302 printf(" (prog-if %02x", c);
312 get_subid(struct device *d, word *subvp, word *subdp)
314 byte htype = get_conf_byte(d, PCI_HEADER_TYPE) & 0x7f;
316 if (htype == PCI_HEADER_TYPE_NORMAL)
318 *subvp = get_conf_word(d, PCI_SUBSYSTEM_VENDOR_ID);
319 *subdp = get_conf_word(d, PCI_SUBSYSTEM_ID);
321 else if (htype == PCI_HEADER_TYPE_CARDBUS && d->config_cached >= 128)
323 *subvp = get_conf_word(d, PCI_CB_SUBSYSTEM_VENDOR_ID);
324 *subdp = get_conf_word(d, PCI_CB_SUBSYSTEM_ID);
327 *subvp = *subdp = 0xffff;
330 /*** Capabilities ***/
333 cap_pm(struct device *d, int where, int cap)
336 static int pm_aux_current[8] = { 0, 55, 100, 160, 220, 270, 320, 375 };
338 printf("Power Management version %d\n", cap & PCI_PM_CAP_VER_MASK);
341 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",
342 FLAG(cap, PCI_PM_CAP_PME_CLOCK),
343 FLAG(cap, PCI_PM_CAP_DSI),
344 FLAG(cap, PCI_PM_CAP_D1),
345 FLAG(cap, PCI_PM_CAP_D2),
346 pm_aux_current[(cap >> 6) & 7],
347 FLAG(cap, PCI_PM_CAP_PME_D0),
348 FLAG(cap, PCI_PM_CAP_PME_D1),
349 FLAG(cap, PCI_PM_CAP_PME_D2),
350 FLAG(cap, PCI_PM_CAP_PME_D3_HOT),
351 FLAG(cap, PCI_PM_CAP_PME_D3_COLD));
352 if (!config_fetch(d, where + PCI_PM_CTRL, PCI_PM_SIZEOF - PCI_PM_CTRL))
354 t = get_conf_word(d, where + PCI_PM_CTRL);
355 printf("\t\tStatus: D%d PME-Enable%c DSel=%d DScale=%d PME%c\n",
356 t & PCI_PM_CTRL_STATE_MASK,
357 FLAG(t, PCI_PM_CTRL_PME_ENABLE),
358 (t & PCI_PM_CTRL_DATA_SEL_MASK) >> 9,
359 (t & PCI_PM_CTRL_DATA_SCALE_MASK) >> 13,
360 FLAG(t, PCI_PM_CTRL_PME_STATUS));
361 b = get_conf_byte(d, where + PCI_PM_PPB_EXTENSIONS);
363 printf("\t\tBridge: PM%c B3%c\n",
364 FLAG(t, PCI_PM_BPCC_ENABLE),
365 FLAG(~t, PCI_PM_PPB_B2_B3));
369 format_agp_rate(int rate, char *buf, int agp3)
379 c += sprintf(c, "x%d", 1 << (i + 2*agp3));
384 strcpy(buf, "<none>");
388 cap_agp(struct device *d, int where, int cap)
395 ver = (cap >> 4) & 0x0f;
397 printf("AGP version %x.%x\n", ver, rev);
400 if (!config_fetch(d, where + PCI_AGP_STATUS, PCI_AGP_SIZEOF - PCI_AGP_STATUS))
402 t = get_conf_long(d, where + PCI_AGP_STATUS);
403 if (ver >= 3 && (t & PCI_AGP_STATUS_AGP3))
405 format_agp_rate(t & 7, rate, agp3);
406 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",
407 ((t & PCI_AGP_STATUS_RQ_MASK) >> 24U) + 1,
408 FLAG(t, PCI_AGP_STATUS_ISOCH),
409 ((t & PCI_AGP_STATUS_ARQSZ_MASK) >> 13),
410 ((t & PCI_AGP_STATUS_CAL_MASK) >> 10),
411 FLAG(t, PCI_AGP_STATUS_SBA),
412 FLAG(t, PCI_AGP_STATUS_ITA_COH),
413 FLAG(t, PCI_AGP_STATUS_GART64),
414 FLAG(t, PCI_AGP_STATUS_HTRANS),
415 FLAG(t, PCI_AGP_STATUS_64BIT),
416 FLAG(t, PCI_AGP_STATUS_FW),
417 FLAG(t, PCI_AGP_STATUS_AGP3),
419 t = get_conf_long(d, where + PCI_AGP_COMMAND);
420 format_agp_rate(t & 7, rate, agp3);
421 printf("\t\tCommand: RQ=%d ArqSz=%d Cal=%d SBA%c AGP%c GART64%c 64bit%c FW%c Rate=%s\n",
422 ((t & PCI_AGP_COMMAND_RQ_MASK) >> 24U) + 1,
423 ((t & PCI_AGP_COMMAND_ARQSZ_MASK) >> 13),
424 ((t & PCI_AGP_COMMAND_CAL_MASK) >> 10),
425 FLAG(t, PCI_AGP_COMMAND_SBA),
426 FLAG(t, PCI_AGP_COMMAND_AGP),
427 FLAG(t, PCI_AGP_COMMAND_GART64),
428 FLAG(t, PCI_AGP_COMMAND_64BIT),
429 FLAG(t, PCI_AGP_COMMAND_FW),
434 cap_pcix_nobridge(struct device *d, int where)
438 static const byte max_outstanding[8] = { 1, 2, 3, 4, 8, 12, 16, 32 };
440 printf("PCI-X non-bridge device\n");
445 if (!config_fetch(d, where + PCI_PCIX_STATUS, 4))
448 command = get_conf_word(d, where + PCI_PCIX_COMMAND);
449 status = get_conf_long(d, where + PCI_PCIX_STATUS);
450 printf("\t\tCommand: DPERE%c ERO%c RBC=%d OST=%d\n",
451 FLAG(command, PCI_PCIX_COMMAND_DPERE),
452 FLAG(command, PCI_PCIX_COMMAND_ERO),
453 1 << (9 + ((command & PCI_PCIX_COMMAND_MAX_MEM_READ_BYTE_COUNT) >> 2U)),
454 max_outstanding[(command & PCI_PCIX_COMMAND_MAX_OUTSTANDING_SPLIT_TRANS) >> 4U]);
455 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",
456 ((status >> 8) & 0xff),
457 ((status >> 3) & 0x1f),
458 (status & PCI_PCIX_STATUS_FUNCTION),
459 FLAG(status, PCI_PCIX_STATUS_64BIT),
460 FLAG(status, PCI_PCIX_STATUS_133MHZ),
461 FLAG(status, PCI_PCIX_STATUS_SC_DISCARDED),
462 FLAG(status, PCI_PCIX_STATUS_UNEXPECTED_SC),
463 ((status & PCI_PCIX_STATUS_DEVICE_COMPLEXITY) ? "bridge" : "simple"),
464 1 << (9 + ((status >> 21) & 3U)),
465 max_outstanding[(status >> 23) & 7U],
466 1 << (3 + ((status >> 26) & 7U)),
467 FLAG(status, PCI_PCIX_STATUS_RCVD_SC_ERR_MESS),
468 FLAG(status, PCI_PCIX_STATUS_266MHZ),
469 FLAG(status, PCI_PCIX_STATUS_533MHZ));
473 cap_pcix_bridge(struct device *d, int where)
475 static const char * const sec_clock_freq[8] = { "conv", "66MHz", "100MHz", "133MHz", "?4", "?5", "?6", "?7" };
477 u32 status, upstcr, downstcr;
479 printf("PCI-X bridge device\n");
484 if (!config_fetch(d, where + PCI_PCIX_BRIDGE_STATUS, 12))
487 secstatus = get_conf_word(d, where + PCI_PCIX_BRIDGE_SEC_STATUS);
488 printf("\t\tSecondary Status: 64bit%c 133MHz%c SCD%c USC%c SCO%c SRD%c Freq=%s\n",
489 FLAG(secstatus, PCI_PCIX_BRIDGE_SEC_STATUS_64BIT),
490 FLAG(secstatus, PCI_PCIX_BRIDGE_SEC_STATUS_133MHZ),
491 FLAG(secstatus, PCI_PCIX_BRIDGE_SEC_STATUS_SC_DISCARDED),
492 FLAG(secstatus, PCI_PCIX_BRIDGE_SEC_STATUS_UNEXPECTED_SC),
493 FLAG(secstatus, PCI_PCIX_BRIDGE_SEC_STATUS_SC_OVERRUN),
494 FLAG(secstatus, PCI_PCIX_BRIDGE_SEC_STATUS_SPLIT_REQUEST_DELAYED),
495 sec_clock_freq[(secstatus >> 6) & 7]);
496 status = get_conf_long(d, where + PCI_PCIX_BRIDGE_STATUS);
497 printf("\t\tStatus: Dev=%02x:%02x.%d 64bit%c 133MHz%c SCD%c USC%c SCO%c SRD%c\n",
498 ((status >> 8) & 0xff),
499 ((status >> 3) & 0x1f),
500 (status & PCI_PCIX_BRIDGE_STATUS_FUNCTION),
501 FLAG(status, PCI_PCIX_BRIDGE_STATUS_64BIT),
502 FLAG(status, PCI_PCIX_BRIDGE_STATUS_133MHZ),
503 FLAG(status, PCI_PCIX_BRIDGE_STATUS_SC_DISCARDED),
504 FLAG(status, PCI_PCIX_BRIDGE_STATUS_UNEXPECTED_SC),
505 FLAG(status, PCI_PCIX_BRIDGE_STATUS_SC_OVERRUN),
506 FLAG(status, PCI_PCIX_BRIDGE_STATUS_SPLIT_REQUEST_DELAYED));
507 upstcr = get_conf_long(d, where + PCI_PCIX_BRIDGE_UPSTREAM_SPLIT_TRANS_CTRL);
508 printf("\t\tUpstream: Capacity=%u CommitmentLimit=%u\n",
509 (upstcr & PCI_PCIX_BRIDGE_STR_CAPACITY),
510 (upstcr >> 16) & 0xffff);
511 downstcr = get_conf_long(d, where + PCI_PCIX_BRIDGE_DOWNSTREAM_SPLIT_TRANS_CTRL);
512 printf("\t\tDownstream: Capacity=%u CommitmentLimit=%u\n",
513 (downstcr & PCI_PCIX_BRIDGE_STR_CAPACITY),
514 (downstcr >> 16) & 0xffff);
518 cap_pcix(struct device *d, int where)
520 switch (get_conf_byte(d, PCI_HEADER_TYPE) & 0x7f)
522 case PCI_HEADER_TYPE_NORMAL:
523 cap_pcix_nobridge(d, where);
525 case PCI_HEADER_TYPE_BRIDGE:
526 cap_pcix_bridge(d, where);
532 ht_link_width(unsigned width)
534 static char * const widths[8] = { "8bit", "16bit", "[2]", "32bit", "2bit", "4bit", "[6]", "N/C" };
535 return widths[width];
539 ht_link_freq(unsigned freq)
541 static char * const freqs[16] = { "200MHz", "300MHz", "400MHz", "500MHz", "600MHz", "800MHz", "1.0GHz", "1.2GHz",
542 "1.4GHz", "1.6GHz", "[a]", "[b]", "[c]", "[d]", "[e]", "Vend" };
547 cap_ht_pri(struct device *d, int where, int cmd)
549 u16 lctr0, lcnf0, lctr1, lcnf1, eh;
550 u8 rid, lfrer0, lfcap0, ftr, lfrer1, lfcap1, mbu, mlu, bn;
553 printf("HyperTransport: Slave or Primary Interface\n");
557 if (!config_fetch(d, where + PCI_HT_PRI_LCTR0, PCI_HT_PRI_SIZEOF - PCI_HT_PRI_LCTR0))
559 rid = get_conf_byte(d, where + PCI_HT_PRI_RID);
560 if (rid < 0x23 && rid > 0x11)
561 printf("\t\t!!! Possibly incomplete decoding\n");
564 fmt = "\t\tCommand: BaseUnitID=%u UnitCnt=%u MastHost%c DefDir%c DUL%c\n";
566 fmt = "\t\tCommand: BaseUnitID=%u UnitCnt=%u MastHost%c DefDir%c\n";
568 (cmd & PCI_HT_PRI_CMD_BUID),
569 (cmd & PCI_HT_PRI_CMD_UC) >> 5,
570 FLAG(cmd, PCI_HT_PRI_CMD_MH),
571 FLAG(cmd, PCI_HT_PRI_CMD_DD),
572 FLAG(cmd, PCI_HT_PRI_CMD_DUL));
573 lctr0 = get_conf_word(d, where + PCI_HT_PRI_LCTR0);
575 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";
577 fmt = "\t\tLink Control 0: CFlE%c CST%c CFE%c <LkFail%c Init%c EOC%c TXO%c <CRCErr=%x\n";
579 FLAG(lctr0, PCI_HT_LCTR_CFLE),
580 FLAG(lctr0, PCI_HT_LCTR_CST),
581 FLAG(lctr0, PCI_HT_LCTR_CFE),
582 FLAG(lctr0, PCI_HT_LCTR_LKFAIL),
583 FLAG(lctr0, PCI_HT_LCTR_INIT),
584 FLAG(lctr0, PCI_HT_LCTR_EOC),
585 FLAG(lctr0, PCI_HT_LCTR_TXO),
586 (lctr0 & PCI_HT_LCTR_CRCERR) >> 8,
587 FLAG(lctr0, PCI_HT_LCTR_ISOCEN),
588 FLAG(lctr0, PCI_HT_LCTR_LSEN),
589 FLAG(lctr0, PCI_HT_LCTR_EXTCTL),
590 FLAG(lctr0, PCI_HT_LCTR_64B));
591 lcnf0 = get_conf_word(d, where + PCI_HT_PRI_LCNF0);
593 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";
595 fmt = "\t\tLink Config 0: MLWI=%s MLWO=%s LWI=%s LWO=%s\n";
597 ht_link_width(lcnf0 & PCI_HT_LCNF_MLWI),
598 ht_link_width((lcnf0 & PCI_HT_LCNF_MLWO) >> 4),
599 ht_link_width((lcnf0 & PCI_HT_LCNF_LWI) >> 8),
600 ht_link_width((lcnf0 & PCI_HT_LCNF_LWO) >> 12),
601 FLAG(lcnf0, PCI_HT_LCNF_DFI),
602 FLAG(lcnf0, PCI_HT_LCNF_DFO),
603 FLAG(lcnf0, PCI_HT_LCNF_DFIE),
604 FLAG(lcnf0, PCI_HT_LCNF_DFOE));
605 lctr1 = get_conf_word(d, where + PCI_HT_PRI_LCTR1);
607 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";
609 fmt = "\t\tLink Control 1: CFlE%c CST%c CFE%c <LkFail%c Init%c EOC%c TXO%c <CRCErr=%x\n";
611 FLAG(lctr1, PCI_HT_LCTR_CFLE),
612 FLAG(lctr1, PCI_HT_LCTR_CST),
613 FLAG(lctr1, PCI_HT_LCTR_CFE),
614 FLAG(lctr1, PCI_HT_LCTR_LKFAIL),
615 FLAG(lctr1, PCI_HT_LCTR_INIT),
616 FLAG(lctr1, PCI_HT_LCTR_EOC),
617 FLAG(lctr1, PCI_HT_LCTR_TXO),
618 (lctr1 & PCI_HT_LCTR_CRCERR) >> 8,
619 FLAG(lctr1, PCI_HT_LCTR_ISOCEN),
620 FLAG(lctr1, PCI_HT_LCTR_LSEN),
621 FLAG(lctr1, PCI_HT_LCTR_EXTCTL),
622 FLAG(lctr1, PCI_HT_LCTR_64B));
623 lcnf1 = get_conf_word(d, where + PCI_HT_PRI_LCNF1);
625 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";
627 fmt = "\t\tLink Config 1: MLWI=%s MLWO=%s LWI=%s LWO=%s\n";
629 ht_link_width(lcnf1 & PCI_HT_LCNF_MLWI),
630 ht_link_width((lcnf1 & PCI_HT_LCNF_MLWO) >> 4),
631 ht_link_width((lcnf1 & PCI_HT_LCNF_LWI) >> 8),
632 ht_link_width((lcnf1 & PCI_HT_LCNF_LWO) >> 12),
633 FLAG(lcnf1, PCI_HT_LCNF_DFI),
634 FLAG(lcnf1, PCI_HT_LCNF_DFO),
635 FLAG(lcnf1, PCI_HT_LCNF_DFIE),
636 FLAG(lcnf1, PCI_HT_LCNF_DFOE));
637 printf("\t\tRevision ID: %u.%02u\n",
638 (rid & PCI_HT_RID_MAJ) >> 5, (rid & PCI_HT_RID_MIN));
641 lfrer0 = get_conf_byte(d, where + PCI_HT_PRI_LFRER0);
642 printf("\t\tLink Frequency 0: %s\n", ht_link_freq(lfrer0 & PCI_HT_LFRER_FREQ));
643 printf("\t\tLink Error 0: <Prot%c <Ovfl%c <EOC%c CTLTm%c\n",
644 FLAG(lfrer0, PCI_HT_LFRER_PROT),
645 FLAG(lfrer0, PCI_HT_LFRER_OV),
646 FLAG(lfrer0, PCI_HT_LFRER_EOC),
647 FLAG(lfrer0, PCI_HT_LFRER_CTLT));
648 lfcap0 = get_conf_byte(d, where + PCI_HT_PRI_LFCAP0);
649 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",
650 FLAG(lfcap0, PCI_HT_LFCAP_200),
651 FLAG(lfcap0, PCI_HT_LFCAP_300),
652 FLAG(lfcap0, PCI_HT_LFCAP_400),
653 FLAG(lfcap0, PCI_HT_LFCAP_500),
654 FLAG(lfcap0, PCI_HT_LFCAP_600),
655 FLAG(lfcap0, PCI_HT_LFCAP_800),
656 FLAG(lfcap0, PCI_HT_LFCAP_1000),
657 FLAG(lfcap0, PCI_HT_LFCAP_1200),
658 FLAG(lfcap0, PCI_HT_LFCAP_1400),
659 FLAG(lfcap0, PCI_HT_LFCAP_1600),
660 FLAG(lfcap0, PCI_HT_LFCAP_VEND));
661 ftr = get_conf_byte(d, where + PCI_HT_PRI_FTR);
662 printf("\t\tFeature Capability: IsocFC%c LDTSTOP%c CRCTM%c ECTLT%c 64bA%c UIDRD%c\n",
663 FLAG(ftr, PCI_HT_FTR_ISOCFC),
664 FLAG(ftr, PCI_HT_FTR_LDTSTOP),
665 FLAG(ftr, PCI_HT_FTR_CRCTM),
666 FLAG(ftr, PCI_HT_FTR_ECTLT),
667 FLAG(ftr, PCI_HT_FTR_64BA),
668 FLAG(ftr, PCI_HT_FTR_UIDRD));
669 lfrer1 = get_conf_byte(d, where + PCI_HT_PRI_LFRER1);
670 printf("\t\tLink Frequency 1: %s\n", ht_link_freq(lfrer1 & PCI_HT_LFRER_FREQ));
671 printf("\t\tLink Error 1: <Prot%c <Ovfl%c <EOC%c CTLTm%c\n",
672 FLAG(lfrer1, PCI_HT_LFRER_PROT),
673 FLAG(lfrer1, PCI_HT_LFRER_OV),
674 FLAG(lfrer1, PCI_HT_LFRER_EOC),
675 FLAG(lfrer1, PCI_HT_LFRER_CTLT));
676 lfcap1 = get_conf_byte(d, where + PCI_HT_PRI_LFCAP1);
677 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",
678 FLAG(lfcap1, PCI_HT_LFCAP_200),
679 FLAG(lfcap1, PCI_HT_LFCAP_300),
680 FLAG(lfcap1, PCI_HT_LFCAP_400),
681 FLAG(lfcap1, PCI_HT_LFCAP_500),
682 FLAG(lfcap1, PCI_HT_LFCAP_600),
683 FLAG(lfcap1, PCI_HT_LFCAP_800),
684 FLAG(lfcap1, PCI_HT_LFCAP_1000),
685 FLAG(lfcap1, PCI_HT_LFCAP_1200),
686 FLAG(lfcap1, PCI_HT_LFCAP_1400),
687 FLAG(lfcap1, PCI_HT_LFCAP_1600),
688 FLAG(lfcap1, PCI_HT_LFCAP_VEND));
689 eh = get_conf_word(d, where + PCI_HT_PRI_EH);
690 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",
691 FLAG(eh, PCI_HT_EH_PFLE),
692 FLAG(eh, PCI_HT_EH_OFLE),
693 FLAG(eh, PCI_HT_EH_PFE),
694 FLAG(eh, PCI_HT_EH_OFE),
695 FLAG(eh, PCI_HT_EH_EOCFE),
696 FLAG(eh, PCI_HT_EH_RFE),
697 FLAG(eh, PCI_HT_EH_CRCFE),
698 FLAG(eh, PCI_HT_EH_SERRFE),
699 FLAG(eh, PCI_HT_EH_CF),
700 FLAG(eh, PCI_HT_EH_RE),
701 FLAG(eh, PCI_HT_EH_PNFE),
702 FLAG(eh, PCI_HT_EH_ONFE),
703 FLAG(eh, PCI_HT_EH_EOCNFE),
704 FLAG(eh, PCI_HT_EH_RNFE),
705 FLAG(eh, PCI_HT_EH_CRCNFE),
706 FLAG(eh, PCI_HT_EH_SERRNFE));
707 mbu = get_conf_byte(d, where + PCI_HT_PRI_MBU);
708 mlu = get_conf_byte(d, where + PCI_HT_PRI_MLU);
709 printf("\t\tPrefetchable memory behind bridge Upper: %02x-%02x\n", mbu, mlu);
710 bn = get_conf_byte(d, where + PCI_HT_PRI_BN);
711 printf("\t\tBus Number: %02x\n", bn);
715 cap_ht_sec(struct device *d, int where, int cmd)
717 u16 lctr, lcnf, ftr, eh;
718 u8 rid, lfrer, lfcap, mbu, mlu;
721 printf("HyperTransport: Host or Secondary Interface\n");
725 if (!config_fetch(d, where + PCI_HT_SEC_LCTR, PCI_HT_SEC_SIZEOF - PCI_HT_SEC_LCTR))
727 rid = get_conf_byte(d, where + PCI_HT_SEC_RID);
728 if (rid < 0x23 && rid > 0x11)
729 printf("\t\t!!! Possibly incomplete decoding\n");
732 fmt = "\t\tCommand: WarmRst%c DblEnd%c DevNum=%u ChainSide%c HostHide%c Slave%c <EOCErr%c DUL%c\n";
734 fmt = "\t\tCommand: WarmRst%c DblEnd%c\n";
736 FLAG(cmd, PCI_HT_SEC_CMD_WR),
737 FLAG(cmd, PCI_HT_SEC_CMD_DE),
738 (cmd & PCI_HT_SEC_CMD_DN) >> 2,
739 FLAG(cmd, PCI_HT_SEC_CMD_CS),
740 FLAG(cmd, PCI_HT_SEC_CMD_HH),
741 FLAG(cmd, PCI_HT_SEC_CMD_AS),
742 FLAG(cmd, PCI_HT_SEC_CMD_HIECE),
743 FLAG(cmd, PCI_HT_SEC_CMD_DUL));
744 lctr = get_conf_word(d, where + PCI_HT_SEC_LCTR);
746 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";
748 fmt = "\t\tLink Control: CFlE%c CST%c CFE%c <LkFail%c Init%c EOC%c TXO%c <CRCErr=%x\n";
750 FLAG(lctr, PCI_HT_LCTR_CFLE),
751 FLAG(lctr, PCI_HT_LCTR_CST),
752 FLAG(lctr, PCI_HT_LCTR_CFE),
753 FLAG(lctr, PCI_HT_LCTR_LKFAIL),
754 FLAG(lctr, PCI_HT_LCTR_INIT),
755 FLAG(lctr, PCI_HT_LCTR_EOC),
756 FLAG(lctr, PCI_HT_LCTR_TXO),
757 (lctr & PCI_HT_LCTR_CRCERR) >> 8,
758 FLAG(lctr, PCI_HT_LCTR_ISOCEN),
759 FLAG(lctr, PCI_HT_LCTR_LSEN),
760 FLAG(lctr, PCI_HT_LCTR_EXTCTL),
761 FLAG(lctr, PCI_HT_LCTR_64B));
762 lcnf = get_conf_word(d, where + PCI_HT_SEC_LCNF);
764 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";
766 fmt = "\t\tLink Config: MLWI=%s MLWO=%s LWI=%s LWO=%s\n";
768 ht_link_width(lcnf & PCI_HT_LCNF_MLWI),
769 ht_link_width((lcnf & PCI_HT_LCNF_MLWO) >> 4),
770 ht_link_width((lcnf & PCI_HT_LCNF_LWI) >> 8),
771 ht_link_width((lcnf & PCI_HT_LCNF_LWO) >> 12),
772 FLAG(lcnf, PCI_HT_LCNF_DFI),
773 FLAG(lcnf, PCI_HT_LCNF_DFO),
774 FLAG(lcnf, PCI_HT_LCNF_DFIE),
775 FLAG(lcnf, PCI_HT_LCNF_DFOE));
776 printf("\t\tRevision ID: %u.%02u\n",
777 (rid & PCI_HT_RID_MAJ) >> 5, (rid & PCI_HT_RID_MIN));
780 lfrer = get_conf_byte(d, where + PCI_HT_SEC_LFRER);
781 printf("\t\tLink Frequency: %s\n", ht_link_freq(lfrer & PCI_HT_LFRER_FREQ));
782 printf("\t\tLink Error: <Prot%c <Ovfl%c <EOC%c CTLTm%c\n",
783 FLAG(lfrer, PCI_HT_LFRER_PROT),
784 FLAG(lfrer, PCI_HT_LFRER_OV),
785 FLAG(lfrer, PCI_HT_LFRER_EOC),
786 FLAG(lfrer, PCI_HT_LFRER_CTLT));
787 lfcap = get_conf_byte(d, where + PCI_HT_SEC_LFCAP);
788 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",
789 FLAG(lfcap, PCI_HT_LFCAP_200),
790 FLAG(lfcap, PCI_HT_LFCAP_300),
791 FLAG(lfcap, PCI_HT_LFCAP_400),
792 FLAG(lfcap, PCI_HT_LFCAP_500),
793 FLAG(lfcap, PCI_HT_LFCAP_600),
794 FLAG(lfcap, PCI_HT_LFCAP_800),
795 FLAG(lfcap, PCI_HT_LFCAP_1000),
796 FLAG(lfcap, PCI_HT_LFCAP_1200),
797 FLAG(lfcap, PCI_HT_LFCAP_1400),
798 FLAG(lfcap, PCI_HT_LFCAP_1600),
799 FLAG(lfcap, PCI_HT_LFCAP_VEND));
800 ftr = get_conf_word(d, where + PCI_HT_SEC_FTR);
801 printf("\t\tFeature Capability: IsocFC%c LDTSTOP%c CRCTM%c ECTLT%c 64bA%c UIDRD%c ExtRS%c UCnfE%c\n",
802 FLAG(ftr, PCI_HT_FTR_ISOCFC),
803 FLAG(ftr, PCI_HT_FTR_LDTSTOP),
804 FLAG(ftr, PCI_HT_FTR_CRCTM),
805 FLAG(ftr, PCI_HT_FTR_ECTLT),
806 FLAG(ftr, PCI_HT_FTR_64BA),
807 FLAG(ftr, PCI_HT_FTR_UIDRD),
808 FLAG(ftr, PCI_HT_SEC_FTR_EXTRS),
809 FLAG(ftr, PCI_HT_SEC_FTR_UCNFE));
810 if (ftr & PCI_HT_SEC_FTR_EXTRS)
812 eh = get_conf_word(d, where + PCI_HT_SEC_EH);
813 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",
814 FLAG(eh, PCI_HT_EH_PFLE),
815 FLAG(eh, PCI_HT_EH_OFLE),
816 FLAG(eh, PCI_HT_EH_PFE),
817 FLAG(eh, PCI_HT_EH_OFE),
818 FLAG(eh, PCI_HT_EH_EOCFE),
819 FLAG(eh, PCI_HT_EH_RFE),
820 FLAG(eh, PCI_HT_EH_CRCFE),
821 FLAG(eh, PCI_HT_EH_SERRFE),
822 FLAG(eh, PCI_HT_EH_CF),
823 FLAG(eh, PCI_HT_EH_RE),
824 FLAG(eh, PCI_HT_EH_PNFE),
825 FLAG(eh, PCI_HT_EH_ONFE),
826 FLAG(eh, PCI_HT_EH_EOCNFE),
827 FLAG(eh, PCI_HT_EH_RNFE),
828 FLAG(eh, PCI_HT_EH_CRCNFE),
829 FLAG(eh, PCI_HT_EH_SERRNFE));
830 mbu = get_conf_byte(d, where + PCI_HT_SEC_MBU);
831 mlu = get_conf_byte(d, where + PCI_HT_SEC_MLU);
832 printf("\t\tPrefetchable memory behind bridge Upper: %02x-%02x\n", mbu, mlu);
837 cap_ht(struct device *d, int where, int cmd)
841 switch (cmd & PCI_HT_CMD_TYP_HI)
843 case PCI_HT_CMD_TYP_HI_PRI:
844 cap_ht_pri(d, where, cmd);
846 case PCI_HT_CMD_TYP_HI_SEC:
847 cap_ht_sec(d, where, cmd);
851 type = cmd & PCI_HT_CMD_TYP;
854 case PCI_HT_CMD_TYP_SW:
855 printf("HyperTransport: Switch\n");
857 case PCI_HT_CMD_TYP_IDC:
858 printf("HyperTransport: Interrupt Discovery and Configuration\n");
860 case PCI_HT_CMD_TYP_RID:
861 printf("HyperTransport: Revision ID: %u.%02u\n",
862 (cmd & PCI_HT_RID_MAJ) >> 5, (cmd & PCI_HT_RID_MIN));
864 case PCI_HT_CMD_TYP_UIDC:
865 printf("HyperTransport: UnitID Clumping\n");
867 case PCI_HT_CMD_TYP_ECSA:
868 printf("HyperTransport: Extended Configuration Space Access\n");
870 case PCI_HT_CMD_TYP_AM:
871 printf("HyperTransport: Address Mapping\n");
873 case PCI_HT_CMD_TYP_MSIM:
874 printf("HyperTransport: MSI Mapping Enable%c Fixed%c\n",
875 FLAG(cmd, PCI_HT_MSIM_CMD_EN),
876 FLAG(cmd, PCI_HT_MSIM_CMD_FIXD));
877 if (verbose >= 2 && !(cmd & PCI_HT_MSIM_CMD_FIXD))
880 if (!config_fetch(d, where + PCI_HT_MSIM_ADDR_LO, 8))
882 offl = get_conf_long(d, where + PCI_HT_MSIM_ADDR_LO);
883 offh = get_conf_long(d, where + PCI_HT_MSIM_ADDR_HI);
884 printf("\t\tMapping Address Base: %016llx\n", ((unsigned long long)offh << 32) | (offl & ~0xfffff));
887 case PCI_HT_CMD_TYP_DR:
888 printf("HyperTransport: DirectRoute\n");
890 case PCI_HT_CMD_TYP_VCS:
891 printf("HyperTransport: VCSet\n");
893 case PCI_HT_CMD_TYP_RM:
894 printf("HyperTransport: Retry Mode\n");
896 case PCI_HT_CMD_TYP_X86:
897 printf("HyperTransport: X86 (reserved)\n");
900 printf("HyperTransport: #%02x\n", type >> 11);
905 cap_msi(struct device *d, int where, int cap)
911 printf("Message Signalled Interrupts: Mask%c 64bit%c Queue=%d/%d Enable%c\n",
912 FLAG(cap, PCI_MSI_FLAGS_MASK_BIT),
913 FLAG(cap, PCI_MSI_FLAGS_64BIT),
914 (cap & PCI_MSI_FLAGS_QSIZE) >> 4,
915 (cap & PCI_MSI_FLAGS_QMASK) >> 1,
916 FLAG(cap, PCI_MSI_FLAGS_ENABLE));
919 is64 = cap & PCI_MSI_FLAGS_64BIT;
920 if (!config_fetch(d, where + PCI_MSI_ADDRESS_LO, (is64 ? PCI_MSI_DATA_64 : PCI_MSI_DATA_32) + 2 - PCI_MSI_ADDRESS_LO))
922 printf("\t\tAddress: ");
925 t = get_conf_long(d, where + PCI_MSI_ADDRESS_HI);
926 w = get_conf_word(d, where + PCI_MSI_DATA_64);
930 w = get_conf_word(d, where + PCI_MSI_DATA_32);
931 t = get_conf_long(d, where + PCI_MSI_ADDRESS_LO);
932 printf("%08x Data: %04x\n", t, w);
933 if (cap & PCI_MSI_FLAGS_MASK_BIT)
939 if (!config_fetch(d, where + PCI_MSI_MASK_BIT_64, 8))
941 mask = get_conf_long(d, where + PCI_MSI_MASK_BIT_64);
942 pending = get_conf_long(d, where + PCI_MSI_PENDING_64);
946 if (!config_fetch(d, where + PCI_MSI_MASK_BIT_32, 8))
948 mask = get_conf_long(d, where + PCI_MSI_MASK_BIT_32);
949 pending = get_conf_long(d, where + PCI_MSI_PENDING_32);
951 printf("\t\tMasking: %08x Pending: %08x\n", mask, pending);
955 static float power_limit(int value, int scale)
957 static const float scales[4] = { 1.0, 0.1, 0.01, 0.001 };
958 return value * scales[scale];
961 static const char *latency_l0s(int value)
963 static const char *latencies[] = { "<64ns", "<128ns", "<256ns", "<512ns", "<1us", "<2us", "<4us", "unlimited" };
964 return latencies[value];
967 static const char *latency_l1(int value)
969 static const char *latencies[] = { "<1us", "<2us", "<4us", "<8us", "<16us", "<32us", "<64us", "unlimited" };
970 return latencies[value];
973 static void cap_express_dev(struct device *d, int where, int type)
978 t = get_conf_long(d, where + PCI_EXP_DEVCAP);
979 printf("\t\tDevCap:\tMaxPayload %d bytes, PhantFunc %d, Latency L0s %s, L1 %s\n",
980 128 << (t & PCI_EXP_DEVCAP_PAYLOAD),
981 (1 << ((t & PCI_EXP_DEVCAP_PHANTOM) >> 3)) - 1,
982 latency_l0s((t & PCI_EXP_DEVCAP_L0S) >> 6),
983 latency_l1((t & PCI_EXP_DEVCAP_L1) >> 9));
984 printf("\t\t\tExtTag%c", FLAG(t, PCI_EXP_DEVCAP_EXT_TAG));
985 if ((type == PCI_EXP_TYPE_ENDPOINT) || (type == PCI_EXP_TYPE_LEG_END) ||
986 (type == PCI_EXP_TYPE_UPSTREAM) || (type == PCI_EXP_TYPE_PCI_BRIDGE))
987 printf(" AttnBtn%c AttnInd%c PwrInd%c",
988 FLAG(t, PCI_EXP_DEVCAP_ATN_BUT),
989 FLAG(t, PCI_EXP_DEVCAP_ATN_IND), FLAG(t, PCI_EXP_DEVCAP_PWR_IND));
990 printf(" RBE%c FLReset%c",
991 FLAG(t, PCI_EXP_DEVCAP_RBE),
992 FLAG(t, PCI_EXP_DEVCAP_FLRESET));
993 if (type == PCI_EXP_TYPE_UPSTREAM)
994 printf("SlotPowerLimit %fW",
995 power_limit((t & PCI_EXP_DEVCAP_PWR_VAL) >> 18,
996 (t & PCI_EXP_DEVCAP_PWR_SCL) >> 26));
999 w = get_conf_word(d, where + PCI_EXP_DEVCTL);
1000 printf("\t\tDevCtl:\tReport errors: Correctable%c Non-Fatal%c Fatal%c Unsupported%c\n",
1001 FLAG(w, PCI_EXP_DEVCTL_CERE),
1002 FLAG(w, PCI_EXP_DEVCTL_NFERE),
1003 FLAG(w, PCI_EXP_DEVCTL_FERE),
1004 FLAG(w, PCI_EXP_DEVCTL_URRE));
1005 printf("\t\t\tRlxdOrd%c ExtTag%c PhantFunc%c AuxPwr%c NoSnoop%c",
1006 FLAG(w, PCI_EXP_DEVCTL_RELAXED),
1007 FLAG(w, PCI_EXP_DEVCTL_EXT_TAG),
1008 FLAG(w, PCI_EXP_DEVCTL_PHANTOM),
1009 FLAG(w, PCI_EXP_DEVCTL_AUX_PME),
1010 FLAG(w, PCI_EXP_DEVCTL_NOSNOOP));
1011 if (type == PCI_EXP_TYPE_PCI_BRIDGE || type == PCI_EXP_TYPE_PCIE_BRIDGE)
1012 printf(" BrConfRtry%c", FLAG(w, PCI_EXP_DEVCTL_BCRE));
1013 if (type == PCI_EXP_TYPE_ENDPOINT && (t & PCI_EXP_DEVCAP_FLRESET))
1014 printf(" FLReset%c", FLAG(w, PCI_EXP_DEVCTL_FLRESET));
1015 printf("\n\t\t\tMaxPayload %d bytes, MaxReadReq %d bytes\n",
1016 128 << ((w & PCI_EXP_DEVCTL_PAYLOAD) >> 5),
1017 128 << ((w & PCI_EXP_DEVCTL_READRQ) >> 12));
1019 w = get_conf_word(d, where + PCI_EXP_DEVSTA);
1020 printf("\t\tDevSta:\tCorrErr%c UncorrErr%c FatalErr%c UnsuppReq%c AuxPwr%c TransPend%c\n",
1021 FLAG(w, PCI_EXP_DEVSTA_CED),
1022 FLAG(w, PCI_EXP_DEVSTA_NFED),
1023 FLAG(w, PCI_EXP_DEVSTA_FED),
1024 FLAG(w, PCI_EXP_DEVSTA_URD),
1025 FLAG(w, PCI_EXP_DEVSTA_AUXPD),
1026 FLAG(w, PCI_EXP_DEVSTA_TRPND));
1028 /* FIXME: Second set of control/status registers is not supported yet. */
1031 static char *link_speed(int speed)
1044 static char *aspm_support(int code)
1057 static const char *aspm_enabled(int code)
1059 static const char *desc[] = { "Disabled", "L0s Enabled", "L1 Enabled", "L0s L1 Enabled" };
1063 static void cap_express_link(struct device *d, int where, int type)
1068 t = get_conf_long(d, where + PCI_EXP_LNKCAP);
1069 printf("\t\tLnkCap:\tPort #%d, Speed %s, Width x%d, ASPM %s, Latency L0 %s, L1 %s\n",
1071 link_speed(t & PCI_EXP_LNKCAP_SPEED), (t & PCI_EXP_LNKCAP_WIDTH) >> 4,
1072 aspm_support((t & PCI_EXP_LNKCAP_ASPM) >> 10),
1073 latency_l0s((t & PCI_EXP_LNKCAP_L0S) >> 12),
1074 latency_l1((t & PCI_EXP_LNKCAP_L1) >> 15));
1075 printf("\t\t\tClockPM%c Suprise%c LLActRep%c BwNot%c\n",
1076 FLAG(t, PCI_EXP_LNKCAP_CLOCKPM),
1077 FLAG(t, PCI_EXP_LNKCAP_SURPRISE),
1078 FLAG(t, PCI_EXP_LNKCAP_DLLA),
1079 FLAG(t, PCI_EXP_LNKCAP_LBNC));
1081 w = get_conf_word(d, where + PCI_EXP_LNKCTL);
1082 printf("\t\tLnkCtl:\tASPM %s;", aspm_enabled(w & PCI_EXP_LNKCTL_ASPM));
1083 if ((type == PCI_EXP_TYPE_ROOT_PORT) || (type == PCI_EXP_TYPE_ENDPOINT) ||
1084 (type == PCI_EXP_TYPE_LEG_END))
1085 printf(" RCB %d bytes", w & PCI_EXP_LNKCTL_RCB ? 128 : 64);
1086 printf(" Disabled%c Retrain%c CommClk%c\n\t\t\tExtSynch%c ClockPM%c AutWidDis%c BWInt%c AutBWInt%c\n",
1087 FLAG(w, PCI_EXP_LNKCTL_DISABLE),
1088 FLAG(w, PCI_EXP_LNKCTL_RETRAIN),
1089 FLAG(w, PCI_EXP_LNKCTL_CLOCK),
1090 FLAG(w, PCI_EXP_LNKCTL_XSYNCH),
1091 FLAG(w, PCI_EXP_LNKCTL_CLOCKPM),
1092 FLAG(w, PCI_EXP_LNKCTL_HWAUTWD),
1093 FLAG(w, PCI_EXP_LNKCTL_BWMIE),
1094 FLAG(w, PCI_EXP_LNKCTL_AUTBWIE));
1096 w = get_conf_word(d, where + PCI_EXP_LNKSTA);
1097 printf("\t\tLnkSta:\tSpeed %s, Width x%d, TrErr%c Train%c SlotClk%c DLActive%c BWMgmt%c ABWMgmt%c\n",
1098 link_speed(w & PCI_EXP_LNKSTA_SPEED),
1099 (w & PCI_EXP_LNKSTA_WIDTH) >> 4,
1100 FLAG(w, PCI_EXP_LNKSTA_TR_ERR),
1101 FLAG(w, PCI_EXP_LNKSTA_TRAIN),
1102 FLAG(w, PCI_EXP_LNKSTA_SL_CLK),
1103 FLAG(w, PCI_EXP_LNKSTA_DL_ACT),
1104 FLAG(w, PCI_EXP_LNKSTA_BWMGMT),
1105 FLAG(w, PCI_EXP_LNKSTA_AUTBW));
1108 static const char *indicator(int code)
1110 static const char *names[] = { "Unknown", "On", "Blink", "Off" };
1114 static void cap_express_slot(struct device *d, int where)
1119 t = get_conf_long(d, where + PCI_EXP_SLTCAP);
1120 printf("\t\tSltCap:\tAttnBtn%c PwrCtrl%c MRL%c AttnInd%c PwrInd%c HotPlug%c Surpise%c\n",
1121 FLAG(t, PCI_EXP_SLTCAP_ATNB),
1122 FLAG(t, PCI_EXP_SLTCAP_PWRC),
1123 FLAG(t, PCI_EXP_SLTCAP_MRL),
1124 FLAG(t, PCI_EXP_SLTCAP_ATNI),
1125 FLAG(t, PCI_EXP_SLTCAP_PWRI),
1126 FLAG(t, PCI_EXP_SLTCAP_HPC),
1127 FLAG(t, PCI_EXP_SLTCAP_HPS));
1128 printf("\t\t\tSlot #%3x, PowerLimit %f; Interlock%c NoCompl%c\n",
1130 power_limit((t & PCI_EXP_SLTCAP_PWR_VAL) >> 7, (t & PCI_EXP_SLTCAP_PWR_SCL) >> 15),
1131 FLAG(t, PCI_EXP_SLTCAP_INTERLOCK),
1132 FLAG(t, PCI_EXP_SLTCAP_NOCMDCOMP));
1134 w = get_conf_word(d, where + PCI_EXP_SLTCTL);
1135 printf("\t\tSltCtl:\tEnable: AttnBtn%c PwrFlt%c MRL%c PresDet%c CmdCplt%c HPIrq%c LinkChg%c\n",
1136 FLAG(w, PCI_EXP_SLTCTL_ATNB),
1137 FLAG(w, PCI_EXP_SLTCTL_PWRF),
1138 FLAG(w, PCI_EXP_SLTCTL_MRLS),
1139 FLAG(w, PCI_EXP_SLTCTL_PRSD),
1140 FLAG(w, PCI_EXP_SLTCTL_CMDC),
1141 FLAG(w, PCI_EXP_SLTCTL_HPIE),
1142 FLAG(w, PCI_EXP_SLTCTL_LLCHG));
1143 printf("\t\t\tControl: AttnInd %s, PwrInd %s, Power%c Interlock%c\n",
1144 indicator((w & PCI_EXP_SLTCTL_ATNI) >> 6),
1145 indicator((w & PCI_EXP_SLTCTL_PWRI) >> 8),
1146 FLAG(w, PCI_EXP_SLTCTL_PWRC),
1147 FLAG(w, PCI_EXP_SLTCTL_INTERLOCK));
1149 w = get_conf_word(d, where + PCI_EXP_SLTSTA);
1150 printf("\t\tSltSta:\tStatus: AttnBtn%c PowerFlt%c MRL%c CmdCplt%c PresDet%c Interlock%c\n",
1151 FLAG(w, PCI_EXP_SLTSTA_ATNB),
1152 FLAG(w, PCI_EXP_SLTSTA_PWRF),
1153 FLAG(w, PCI_EXP_SLTSTA_MRL_ST),
1154 FLAG(w, PCI_EXP_SLTSTA_CMDC),
1155 FLAG(w, PCI_EXP_SLTSTA_PRES),
1156 FLAG(w, PCI_EXP_SLTSTA_INTERLOCK));
1157 printf("\t\t\tChanged: MRL%c PresDet%c LinkState%c\n",
1158 FLAG(w, PCI_EXP_SLTSTA_MRLS),
1159 FLAG(w, PCI_EXP_SLTSTA_PRSD),
1160 FLAG(w, PCI_EXP_SLTSTA_LLCHG));
1163 static void cap_express_root(struct device *d, int where)
1165 u32 w = get_conf_word(d, where + PCI_EXP_RTCTL);
1166 printf("\t\tRootCtl: ErrCorrectable%c ErrNon-Fatal%c ErrFatal%c PMEIntEna%c CRSVisible%c\n",
1167 FLAG(w, PCI_EXP_RTCTL_SECEE),
1168 FLAG(w, PCI_EXP_RTCTL_SENFEE),
1169 FLAG(w, PCI_EXP_RTCTL_SEFEE),
1170 FLAG(w, PCI_EXP_RTCTL_PMEIE),
1171 FLAG(w, PCI_EXP_RTCTL_CRSVIS));
1173 w = get_conf_word(d, where + PCI_EXP_RTCAP);
1174 printf("\t\tRootCap: CRSVisible%c\n",
1175 FLAG(w, PCI_EXP_RTCAP_CRSVIS));
1177 w = get_conf_word(d, where + PCI_EXP_RTSTA);
1178 printf("\t\tRootSta: PME ReqID %04x, PMEStatus%c PMEPending%c\n",
1179 w & PCI_EXP_RTSTA_PME_REQID,
1180 FLAG(w, PCI_EXP_RTSTA_PME_STATUS),
1181 FLAG(w, PCI_EXP_RTSTA_PME_PENDING));
1185 cap_express(struct device *d, int where, int cap)
1187 int type = (cap & PCI_EXP_FLAGS_TYPE) >> 4;
1193 printf("(v%d) ", cap & PCI_EXP_FLAGS_VERS);
1196 case PCI_EXP_TYPE_ENDPOINT:
1199 case PCI_EXP_TYPE_LEG_END:
1200 printf("Legacy Endpoint");
1202 case PCI_EXP_TYPE_ROOT_PORT:
1203 slot = cap & PCI_EXP_FLAGS_SLOT;
1204 printf("Root Port (Slot%c)", FLAG(cap, PCI_EXP_FLAGS_SLOT));
1206 case PCI_EXP_TYPE_UPSTREAM:
1207 printf("Upstream Port");
1209 case PCI_EXP_TYPE_DOWNSTREAM:
1210 slot = cap & PCI_EXP_FLAGS_SLOT;
1211 printf("Downstream Port (Slot%c)", FLAG(cap, PCI_EXP_FLAGS_SLOT));
1213 case PCI_EXP_TYPE_PCI_BRIDGE:
1214 printf("PCI/PCI-X Bridge");
1216 case PCI_EXP_TYPE_PCIE_BRIDGE:
1217 printf("PCI/PCI-X to PCI-Express Bridge");
1219 case PCI_EXP_TYPE_ROOT_INT_EP:
1220 printf("Root Complex Integrated Endpoint");
1222 case PCI_EXP_TYPE_ROOT_EC:
1223 printf("Root Complex Event Collector");
1226 printf("Unknown type %d", type);
1228 printf(", MSI %02x\n", (cap & PCI_EXP_FLAGS_IRQ) >> 9);
1235 if (type == PCI_EXP_TYPE_ROOT_PORT)
1237 if (!config_fetch(d, where + PCI_EXP_DEVCAP, size))
1240 cap_express_dev(d, where, type);
1241 cap_express_link(d, where, type);
1243 cap_express_slot(d, where);
1244 if (type == PCI_EXP_TYPE_ROOT_PORT)
1245 cap_express_root(d, where);
1249 cap_msix(struct device *d, int where, int cap)
1253 printf("MSI-X: Enable%c Mask%c TabSize=%d\n",
1254 FLAG(cap, PCI_MSIX_ENABLE),
1255 FLAG(cap, PCI_MSIX_MASK),
1256 (cap & PCI_MSIX_TABSIZE) + 1);
1257 if (verbose < 2 || !config_fetch(d, where + PCI_MSIX_TABLE, 8))
1260 off = get_conf_long(d, where + PCI_MSIX_TABLE);
1261 printf("\t\tVector table: BAR=%d offset=%08x\n",
1262 off & PCI_MSIX_BIR, off & ~PCI_MSIX_BIR);
1263 off = get_conf_long(d, where + PCI_MSIX_PBA);
1264 printf("\t\tPBA: BAR=%d offset=%08x\n",
1265 off & PCI_MSIX_BIR, off & ~PCI_MSIX_BIR);
1271 int esr = cap & 0xff;
1274 printf("Slot ID: %d slots, First%c, chassis %02x\n",
1275 esr & PCI_SID_ESR_NSLOTS,
1276 FLAG(esr, PCI_SID_ESR_FIC),
1281 cap_ssvid(struct device *d, int where)
1283 u16 subsys_v, subsys_d;
1284 char ssnamebuf[256];
1286 if (!config_fetch(d, where, 8))
1288 subsys_v = get_conf_word(d, where + PCI_SSVID_VENDOR);
1289 subsys_d = get_conf_word(d, where + PCI_SSVID_DEVICE);
1290 printf("Subsystem: %s\n",
1291 pci_lookup_name(pacc, ssnamebuf, sizeof(ssnamebuf),
1292 PCI_LOOKUP_SUBSYSTEM | PCI_LOOKUP_VENDOR | PCI_LOOKUP_DEVICE,
1293 d->dev->vendor_id, d->dev->device_id, subsys_v, subsys_d));
1297 cap_dsn(struct device *d, int where)
1300 if (!config_fetch(d, where + 4, 8))
1302 t1 = get_conf_long(d, where + 4);
1303 t2 = get_conf_long(d, where + 8);
1304 printf("Device Serial Number %02x-%02x-%02x-%02x-%02x-%02x-%02x-%02x\n",
1305 t1 & 0xff, (t1 >> 8) & 0xff, (t1 >> 16) & 0xff, t1 >> 24,
1306 t2 & 0xff, (t2 >> 8) & 0xff, (t2 >> 16) & 0xff, t2 >> 24);
1310 cap_debug_port(int cap)
1312 int bar = cap >> 13;
1313 int pos = cap & 0x1fff;
1314 printf("Debug port: BAR=%d offset=%04x\n", bar, pos);
1318 show_ext_caps(struct device *d)
1321 char been_there[0x1000];
1322 memset(been_there, 0, 0x1000);
1328 if (!config_fetch(d, where, 4))
1330 header = get_conf_long(d, where);
1333 id = header & 0xffff;
1334 printf("\tCapabilities: [%03x] ", where);
1335 if (been_there[where]++)
1337 printf("<chain looped>\n");
1342 case PCI_EXT_CAP_ID_AER:
1343 printf("Advanced Error Reporting <?>\n");
1345 case PCI_EXT_CAP_ID_VC:
1346 printf("Virtual Channel <?>\n");
1348 case PCI_EXT_CAP_ID_DSN:
1351 case PCI_EXT_CAP_ID_PB:
1352 printf("Power Budgeting <?>\n");
1354 case PCI_EXT_CAP_ID_RCLINK:
1355 printf("Root Complex Link <?>\n");
1357 case PCI_EXT_CAP_ID_RCILINK:
1358 printf("Root Complex Internal Link <?>\n");
1360 case PCI_EXT_CAP_ID_RCECOLL:
1361 printf("Root Complex Event Collector <?>\n");
1363 case PCI_EXT_CAP_ID_MFVC:
1364 printf("Multi-Function Virtual Channel <?>\n");
1366 case PCI_EXT_CAP_ID_RBCB:
1367 printf("Root Bridge Control Block <?>\n");
1369 case PCI_EXT_CAP_ID_VNDR:
1370 printf("Vendor Specific Information <?>\n");
1372 case PCI_EXT_CAP_ID_ACS:
1373 printf("Access Controls <?>\n");
1376 printf("#%02x\n", id);
1379 where = header >> 20;
1384 show_caps(struct device *d)
1386 int can_have_ext_caps = 0;
1388 if (get_conf_word(d, PCI_STATUS) & PCI_STATUS_CAP_LIST)
1390 int where = get_conf_byte(d, PCI_CAPABILITY_LIST) & ~3;
1391 byte been_there[256];
1392 memset(been_there, 0, 256);
1396 printf("\tCapabilities: ");
1397 if (!config_fetch(d, where, 4))
1399 puts("<access denied>");
1402 id = get_conf_byte(d, where + PCI_CAP_LIST_ID);
1403 next = get_conf_byte(d, where + PCI_CAP_LIST_NEXT) & ~3;
1404 cap = get_conf_word(d, where + PCI_CAP_FLAGS);
1405 printf("[%02x] ", where);
1406 if (been_there[where]++)
1408 printf("<chain looped>\n");
1413 printf("<chain broken>\n");
1419 cap_pm(d, where, cap);
1421 case PCI_CAP_ID_AGP:
1422 cap_agp(d, where, cap);
1424 case PCI_CAP_ID_VPD:
1425 printf("Vital Product Data <?>\n");
1427 case PCI_CAP_ID_SLOTID:
1430 case PCI_CAP_ID_MSI:
1431 cap_msi(d, where, cap);
1433 case PCI_CAP_ID_CHSWP:
1434 printf("CompactPCI hot-swap <?>\n");
1436 case PCI_CAP_ID_PCIX:
1438 can_have_ext_caps = 1;
1441 cap_ht(d, where, cap);
1443 case PCI_CAP_ID_VNDR:
1444 printf("Vendor Specific Information <?>\n");
1446 case PCI_CAP_ID_DBG:
1447 cap_debug_port(cap);
1449 case PCI_CAP_ID_CCRC:
1450 printf("CompactPCI central resource control <?>\n");
1452 case PCI_CAP_ID_HOTPLUG:
1453 printf("Hot-plug capable\n");
1455 case PCI_CAP_ID_SSVID:
1456 cap_ssvid(d, where);
1458 case PCI_CAP_ID_AGP3:
1459 printf("AGP3 <?>\n");
1461 case PCI_CAP_ID_SECURE:
1462 printf("Secure device <?>\n");
1464 case PCI_CAP_ID_EXP:
1465 cap_express(d, where, cap);
1466 can_have_ext_caps = 1;
1468 case PCI_CAP_ID_MSIX:
1469 cap_msix(d, where, cap);
1471 case PCI_CAP_ID_SATA:
1472 printf("SATA HBA <?>\n");
1475 printf("PCIe advanced features <?>\n");
1478 printf("#%02x [%04x]\n", id, cap);
1483 if (can_have_ext_caps)
1487 /*** Kernel drivers ***/
1491 #include <sys/utsname.h>
1493 struct pcimap_entry {
1494 struct pcimap_entry *next;
1495 unsigned int vendor, device;
1496 unsigned int subvendor, subdevice;
1497 unsigned int class, class_mask;
1501 static struct pcimap_entry *pcimap_head;
1506 static int tried_pcimap;
1508 char *name, line[1024];
1515 if (name = opt_pcimap)
1517 f = fopen(name, "r");
1519 die("Cannot open pcimap file %s: %m", name);
1523 if (uname(&uts) < 0)
1524 die("uname() failed: %m");
1525 name = alloca(64 + strlen(uts.release));
1526 sprintf(name, "/lib/modules/%s/modules.pcimap", uts.release);
1527 f = fopen(name, "r");
1532 while (fgets(line, sizeof(line), f))
1534 char *c = strchr(line, '\n');
1535 struct pcimap_entry *e;
1538 die("Unterminated or too long line in %s", name);
1540 if (!line[0] || line[0] == '#')
1544 while (*c && *c != ' ' && *c != '\t')
1547 continue; /* FIXME: Emit warnings! */
1550 e = xmalloc(sizeof(*e) + strlen(line));
1551 if (sscanf(c, "%i%i%i%i%i%i",
1552 &e->vendor, &e->device,
1553 &e->subvendor, &e->subdevice,
1554 &e->class, &e->class_mask) != 6)
1556 e->next = pcimap_head;
1558 strcpy(e->module, line);
1564 match_pcimap(struct device *d, struct pcimap_entry *e)
1566 struct pci_dev *dev = d->dev;
1567 unsigned int class = get_conf_long(d, PCI_REVISION_ID) >> 8;
1570 #define MATCH(x, y) ((y) > 0xffff || (x) == (y))
1571 get_subid(d, &subv, &subd);
1573 MATCH(dev->vendor_id, e->vendor) &&
1574 MATCH(dev->device_id, e->device) &&
1575 MATCH(subv, e->subvendor) &&
1576 MATCH(subd, e->subdevice) &&
1577 (class & e->class_mask) == e->class;
1581 #define DRIVER_BUF_SIZE 1024
1584 find_driver(struct device *d, char *buf)
1586 struct pci_dev *dev = d->dev;
1587 char *base = dev->access->method_params[PCI_ACCESS_SYS_BUS_PCI];
1588 char name[1024], *drv;
1591 if (dev->access->method != PCI_ACCESS_SYS_BUS_PCI)
1594 n = snprintf(name, sizeof(name), "%s/devices/%04x:%02x:%02x.%d/driver",
1595 base, dev->domain, dev->bus, dev->dev, dev->func);
1596 if (n < 0 || n >= (int)sizeof(name))
1597 die("show_driver: sysfs device name too long, why?");
1599 n = readlink(name, buf, DRIVER_BUF_SIZE);
1602 if (n >= DRIVER_BUF_SIZE)
1603 return "<name-too-long>";
1606 if (drv = strrchr(buf, '/'))
1613 show_kernel(struct device *d)
1615 char buf[DRIVER_BUF_SIZE];
1617 struct pcimap_entry *e, *last = NULL;
1619 if (driver = find_driver(d, buf))
1620 printf("\tKernel driver in use: %s\n", driver);
1623 for (e=pcimap_head; e; e=e->next)
1624 if (match_pcimap(d, e) && (!last || strcmp(last->module, e->module)))
1626 printf("%s %s", (last ? "," : "\tKernel modules:"), e->module);
1634 show_kernel_machine(struct device *d)
1636 char buf[DRIVER_BUF_SIZE];
1638 struct pcimap_entry *e, *last = NULL;
1640 if (driver = find_driver(d, buf))
1641 printf("Driver:\t%s\n", driver);
1644 for (e=pcimap_head; e; e=e->next)
1645 if (match_pcimap(d, e) && (!last || strcmp(last->module, e->module)))
1647 printf("Module:\t%s\n", e->module);
1655 show_kernel(struct device *d UNUSED)
1660 show_kernel_machine(struct device *d UNUSED)
1666 /*** Verbose output ***/
1669 show_size(pciaddr_t x)
1675 printf("%d", (int) x);
1676 else if (x < 1048576)
1677 printf("%dK", (int)(x / 1024));
1678 else if (x < 0x80000000)
1679 printf("%dM", (int)(x / 1048576));
1681 printf(PCIADDR_T_FMT, x);
1686 show_bases(struct device *d, int cnt)
1688 struct pci_dev *p = d->dev;
1689 word cmd = get_conf_word(d, PCI_COMMAND);
1692 for(i=0; i<cnt; i++)
1694 pciaddr_t pos = p->base_addr[i];
1695 pciaddr_t len = (p->known_fields & PCI_FILL_SIZES) ? p->size[i] : 0;
1696 u32 flg = get_conf_long(d, PCI_BASE_ADDRESS_0 + 4*i);
1697 if (flg == 0xffffffff)
1699 if (!pos && !flg && !len)
1702 printf("\tRegion %d: ", i);
1705 if (pos && !flg) /* Reported by the OS, but not by the device */
1707 printf("[virtual] ");
1710 if (flg & PCI_BASE_ADDRESS_SPACE_IO)
1712 pciaddr_t a = pos & PCI_BASE_ADDRESS_IO_MASK;
1713 printf("I/O ports at ");
1715 printf(PCIADDR_PORT_FMT, a);
1716 else if (flg & PCI_BASE_ADDRESS_IO_MASK)
1717 printf("<ignored>");
1719 printf("<unassigned>");
1720 if (!(cmd & PCI_COMMAND_IO))
1721 printf(" [disabled]");
1725 int t = flg & PCI_BASE_ADDRESS_MEM_TYPE_MASK;
1726 pciaddr_t a = pos & PCI_ADDR_MEM_MASK;
1730 printf("Memory at ");
1731 if (t == PCI_BASE_ADDRESS_MEM_TYPE_64)
1735 printf("<invalid-64bit-slot>");
1741 z = get_conf_long(d, PCI_BASE_ADDRESS_0 + 4*i);
1744 u32 y = a & 0xffffffff;
1746 printf("%08x%08x", z, y);
1748 printf("<unassigned>");
1756 printf(PCIADDR_T_FMT, a);
1758 printf(((flg & PCI_BASE_ADDRESS_MEM_MASK) || z) ? "<ignored>" : "<unassigned>");
1760 printf(" (%s, %sprefetchable)",
1761 (t == PCI_BASE_ADDRESS_MEM_TYPE_32) ? "32-bit" :
1762 (t == PCI_BASE_ADDRESS_MEM_TYPE_64) ? "64-bit" :
1763 (t == PCI_BASE_ADDRESS_MEM_TYPE_1M) ? "low-1M" : "type 3",
1764 (flg & PCI_BASE_ADDRESS_MEM_PREFETCH) ? "" : "non-");
1765 if (!(cmd & PCI_COMMAND_MEMORY))
1766 printf(" [disabled]");
1774 show_rom(struct device *d, int reg)
1776 struct pci_dev *p = d->dev;
1777 pciaddr_t rom = p->rom_base_addr;
1778 pciaddr_t len = (p->known_fields & PCI_FILL_SIZES) ? p->rom_size : 0;
1779 u32 flg = get_conf_long(d, reg);
1780 word cmd = get_conf_word(d, PCI_COMMAND);
1782 if (!rom && !flg && !len)
1785 if ((rom & PCI_ROM_ADDRESS_MASK) && !(flg & PCI_ROM_ADDRESS_MASK))
1787 printf("[virtual] ");
1790 printf("Expansion ROM at ");
1791 if (rom & PCI_ROM_ADDRESS_MASK)
1792 printf(PCIADDR_T_FMT, rom & PCI_ROM_ADDRESS_MASK);
1793 else if (flg & PCI_ROM_ADDRESS_MASK)
1794 printf("<ignored>");
1796 printf("<unassigned>");
1797 if (!(flg & PCI_ROM_ADDRESS_ENABLE))
1798 printf(" [disabled]");
1799 else if (!(cmd & PCI_COMMAND_MEMORY))
1800 printf(" [disabled by cmd]");
1806 show_htype0(struct device *d)
1809 show_rom(d, PCI_ROM_ADDRESS);
1814 show_htype1(struct device *d)
1816 u32 io_base = get_conf_byte(d, PCI_IO_BASE);
1817 u32 io_limit = get_conf_byte(d, PCI_IO_LIMIT);
1818 u32 io_type = io_base & PCI_IO_RANGE_TYPE_MASK;
1819 u32 mem_base = get_conf_word(d, PCI_MEMORY_BASE);
1820 u32 mem_limit = get_conf_word(d, PCI_MEMORY_LIMIT);
1821 u32 mem_type = mem_base & PCI_MEMORY_RANGE_TYPE_MASK;
1822 u32 pref_base = get_conf_word(d, PCI_PREF_MEMORY_BASE);
1823 u32 pref_limit = get_conf_word(d, PCI_PREF_MEMORY_LIMIT);
1824 u32 pref_type = pref_base & PCI_PREF_RANGE_TYPE_MASK;
1825 word sec_stat = get_conf_word(d, PCI_SEC_STATUS);
1826 word brc = get_conf_word(d, PCI_BRIDGE_CONTROL);
1827 int verb = verbose > 2;
1830 printf("\tBus: primary=%02x, secondary=%02x, subordinate=%02x, sec-latency=%d\n",
1831 get_conf_byte(d, PCI_PRIMARY_BUS),
1832 get_conf_byte(d, PCI_SECONDARY_BUS),
1833 get_conf_byte(d, PCI_SUBORDINATE_BUS),
1834 get_conf_byte(d, PCI_SEC_LATENCY_TIMER));
1836 if (io_type != (io_limit & PCI_IO_RANGE_TYPE_MASK) ||
1837 (io_type != PCI_IO_RANGE_TYPE_16 && io_type != PCI_IO_RANGE_TYPE_32))
1838 printf("\t!!! Unknown I/O range types %x/%x\n", io_base, io_limit);
1841 io_base = (io_base & PCI_IO_RANGE_MASK) << 8;
1842 io_limit = (io_limit & PCI_IO_RANGE_MASK) << 8;
1843 if (io_type == PCI_IO_RANGE_TYPE_32)
1845 io_base |= (get_conf_word(d, PCI_IO_BASE_UPPER16) << 16);
1846 io_limit |= (get_conf_word(d, PCI_IO_LIMIT_UPPER16) << 16);
1848 if (io_base <= io_limit || verb)
1849 printf("\tI/O behind bridge: %08x-%08x\n", io_base, io_limit+0xfff);
1852 if (mem_type != (mem_limit & PCI_MEMORY_RANGE_TYPE_MASK) ||
1854 printf("\t!!! Unknown memory range types %x/%x\n", mem_base, mem_limit);
1857 mem_base = (mem_base & PCI_MEMORY_RANGE_MASK) << 16;
1858 mem_limit = (mem_limit & PCI_MEMORY_RANGE_MASK) << 16;
1859 if (mem_base <= mem_limit || verb)
1860 printf("\tMemory behind bridge: %08x-%08x\n", mem_base, mem_limit + 0xfffff);
1863 if (pref_type != (pref_limit & PCI_PREF_RANGE_TYPE_MASK) ||
1864 (pref_type != PCI_PREF_RANGE_TYPE_32 && pref_type != PCI_PREF_RANGE_TYPE_64))
1865 printf("\t!!! Unknown prefetchable memory range types %x/%x\n", pref_base, pref_limit);
1868 pref_base = (pref_base & PCI_PREF_RANGE_MASK) << 16;
1869 pref_limit = (pref_limit & PCI_PREF_RANGE_MASK) << 16;
1870 if (pref_base <= pref_limit || verb)
1872 if (pref_type == PCI_PREF_RANGE_TYPE_32)
1873 printf("\tPrefetchable memory behind bridge: %08x-%08x\n", pref_base, pref_limit + 0xfffff);
1875 printf("\tPrefetchable memory behind bridge: %08x%08x-%08x%08x\n",
1876 get_conf_long(d, PCI_PREF_BASE_UPPER32),
1878 get_conf_long(d, PCI_PREF_LIMIT_UPPER32),
1879 pref_limit + 0xfffff);
1884 printf("\tSecondary status: 66MHz%c FastB2B%c ParErr%c DEVSEL=%s >TAbort%c <TAbort%c <MAbort%c <SERR%c <PERR%c\n",
1885 FLAG(sec_stat, PCI_STATUS_66MHZ),
1886 FLAG(sec_stat, PCI_STATUS_FAST_BACK),
1887 FLAG(sec_stat, PCI_STATUS_PARITY),
1888 ((sec_stat & PCI_STATUS_DEVSEL_MASK) == PCI_STATUS_DEVSEL_SLOW) ? "slow" :
1889 ((sec_stat & PCI_STATUS_DEVSEL_MASK) == PCI_STATUS_DEVSEL_MEDIUM) ? "medium" :
1890 ((sec_stat & PCI_STATUS_DEVSEL_MASK) == PCI_STATUS_DEVSEL_FAST) ? "fast" : "??",
1891 FLAG(sec_stat, PCI_STATUS_SIG_TARGET_ABORT),
1892 FLAG(sec_stat, PCI_STATUS_REC_TARGET_ABORT),
1893 FLAG(sec_stat, PCI_STATUS_REC_MASTER_ABORT),
1894 FLAG(sec_stat, PCI_STATUS_SIG_SYSTEM_ERROR),
1895 FLAG(sec_stat, PCI_STATUS_DETECTED_PARITY));
1897 show_rom(d, PCI_ROM_ADDRESS1);
1901 printf("\tBridgeCtl: Parity%c SERR%c NoISA%c VGA%c MAbort%c >Reset%c FastB2B%c\n",
1902 FLAG(brc, PCI_BRIDGE_CTL_PARITY),
1903 FLAG(brc, PCI_BRIDGE_CTL_SERR),
1904 FLAG(brc, PCI_BRIDGE_CTL_NO_ISA),
1905 FLAG(brc, PCI_BRIDGE_CTL_VGA),
1906 FLAG(brc, PCI_BRIDGE_CTL_MASTER_ABORT),
1907 FLAG(brc, PCI_BRIDGE_CTL_BUS_RESET),
1908 FLAG(brc, PCI_BRIDGE_CTL_FAST_BACK));
1909 printf("\t\tPriDiscTmr%c SecDiscTmr%c DiscTmrStat%c DiscTmrSERREn%c\n",
1910 FLAG(brc, PCI_BRIDGE_CTL_PRI_DISCARD_TIMER),
1911 FLAG(brc, PCI_BRIDGE_CTL_SEC_DISCARD_TIMER),
1912 FLAG(brc, PCI_BRIDGE_CTL_DISCARD_TIMER_STATUS),
1913 FLAG(brc, PCI_BRIDGE_CTL_DISCARD_TIMER_SERR_EN));
1920 show_htype2(struct device *d)
1923 word cmd = get_conf_word(d, PCI_COMMAND);
1924 word brc = get_conf_word(d, PCI_CB_BRIDGE_CONTROL);
1926 int verb = verbose > 2;
1929 printf("\tBus: primary=%02x, secondary=%02x, subordinate=%02x, sec-latency=%d\n",
1930 get_conf_byte(d, PCI_CB_PRIMARY_BUS),
1931 get_conf_byte(d, PCI_CB_CARD_BUS),
1932 get_conf_byte(d, PCI_CB_SUBORDINATE_BUS),
1933 get_conf_byte(d, PCI_CB_LATENCY_TIMER));
1937 u32 base = get_conf_long(d, PCI_CB_MEMORY_BASE_0 + p);
1938 u32 limit = get_conf_long(d, PCI_CB_MEMORY_LIMIT_0 + p);
1939 if (limit > base || verb)
1940 printf("\tMemory window %d: %08x-%08x%s%s\n", i, base, limit,
1941 (cmd & PCI_COMMAND_MEMORY) ? "" : " [disabled]",
1942 (brc & (PCI_CB_BRIDGE_CTL_PREFETCH_MEM0 << i)) ? " (prefetchable)" : "");
1947 u32 base = get_conf_long(d, PCI_CB_IO_BASE_0 + p);
1948 u32 limit = get_conf_long(d, PCI_CB_IO_LIMIT_0 + p);
1949 if (!(base & PCI_IO_RANGE_TYPE_32))
1954 base &= PCI_CB_IO_RANGE_MASK;
1955 limit = (limit & PCI_CB_IO_RANGE_MASK) + 3;
1956 if (base <= limit || verb)
1957 printf("\tI/O window %d: %08x-%08x%s\n", i, base, limit,
1958 (cmd & PCI_COMMAND_IO) ? "" : " [disabled]");
1961 if (get_conf_word(d, PCI_CB_SEC_STATUS) & PCI_STATUS_SIG_SYSTEM_ERROR)
1962 printf("\tSecondary status: SERR\n");
1964 printf("\tBridgeCtl: Parity%c SERR%c ISA%c VGA%c MAbort%c >Reset%c 16bInt%c PostWrite%c\n",
1965 FLAG(brc, PCI_CB_BRIDGE_CTL_PARITY),
1966 FLAG(brc, PCI_CB_BRIDGE_CTL_SERR),
1967 FLAG(brc, PCI_CB_BRIDGE_CTL_ISA),
1968 FLAG(brc, PCI_CB_BRIDGE_CTL_VGA),
1969 FLAG(brc, PCI_CB_BRIDGE_CTL_MASTER_ABORT),
1970 FLAG(brc, PCI_CB_BRIDGE_CTL_CB_RESET),
1971 FLAG(brc, PCI_CB_BRIDGE_CTL_16BIT_INT),
1972 FLAG(brc, PCI_CB_BRIDGE_CTL_POST_WRITES));
1974 if (d->config_cached < 128)
1976 printf("\t<access denied to the rest>\n");
1980 exca = get_conf_word(d, PCI_CB_LEGACY_MODE_BASE);
1982 printf("\t16-bit legacy interface ports at %04x\n", exca);
1986 show_verbose(struct device *d)
1988 struct pci_dev *p = d->dev;
1989 word status = get_conf_word(d, PCI_STATUS);
1990 word cmd = get_conf_word(d, PCI_COMMAND);
1991 word class = p->device_class;
1992 byte bist = get_conf_byte(d, PCI_BIST);
1993 byte htype = get_conf_byte(d, PCI_HEADER_TYPE) & 0x7f;
1994 byte latency = get_conf_byte(d, PCI_LATENCY_TIMER);
1995 byte cache_line = get_conf_byte(d, PCI_CACHE_LINE_SIZE);
1996 byte max_lat, min_gnt;
1997 byte int_pin = get_conf_byte(d, PCI_INTERRUPT_PIN);
1998 unsigned int irq = p->irq;
1999 word subsys_v, subsys_d;
2000 char ssnamebuf[256];
2006 case PCI_HEADER_TYPE_NORMAL:
2007 if (class == PCI_CLASS_BRIDGE_PCI)
2008 printf("\t!!! Invalid class %04x for header type %02x\n", class, htype);
2009 max_lat = get_conf_byte(d, PCI_MAX_LAT);
2010 min_gnt = get_conf_byte(d, PCI_MIN_GNT);
2012 case PCI_HEADER_TYPE_BRIDGE:
2013 if ((class >> 8) != PCI_BASE_CLASS_BRIDGE)
2014 printf("\t!!! Invalid class %04x for header type %02x\n", class, htype);
2015 irq = int_pin = min_gnt = max_lat = 0;
2017 case PCI_HEADER_TYPE_CARDBUS:
2018 if ((class >> 8) != PCI_BASE_CLASS_BRIDGE)
2019 printf("\t!!! Invalid class %04x for header type %02x\n", class, htype);
2020 min_gnt = max_lat = 0;
2023 printf("\t!!! Unknown header type %02x\n", htype);
2027 get_subid(d, &subsys_v, &subsys_d);
2028 if (subsys_v && subsys_v != 0xffff)
2029 printf("\tSubsystem: %s\n",
2030 pci_lookup_name(pacc, ssnamebuf, sizeof(ssnamebuf),
2031 PCI_LOOKUP_SUBSYSTEM | PCI_LOOKUP_VENDOR | PCI_LOOKUP_DEVICE,
2032 p->vendor_id, p->device_id, subsys_v, subsys_d));
2036 printf("\tControl: I/O%c Mem%c BusMaster%c SpecCycle%c MemWINV%c VGASnoop%c ParErr%c Stepping%c SERR%c FastB2B%c DisINTx%c\n",
2037 FLAG(cmd, PCI_COMMAND_IO),
2038 FLAG(cmd, PCI_COMMAND_MEMORY),
2039 FLAG(cmd, PCI_COMMAND_MASTER),
2040 FLAG(cmd, PCI_COMMAND_SPECIAL),
2041 FLAG(cmd, PCI_COMMAND_INVALIDATE),
2042 FLAG(cmd, PCI_COMMAND_VGA_PALETTE),
2043 FLAG(cmd, PCI_COMMAND_PARITY),
2044 FLAG(cmd, PCI_COMMAND_WAIT),
2045 FLAG(cmd, PCI_COMMAND_SERR),
2046 FLAG(cmd, PCI_COMMAND_FAST_BACK),
2047 FLAG(cmd, PCI_COMMAND_DISABLE_INTx));
2048 printf("\tStatus: Cap%c 66MHz%c UDF%c FastB2B%c ParErr%c DEVSEL=%s >TAbort%c <TAbort%c <MAbort%c >SERR%c <PERR%c INTx%c\n",
2049 FLAG(status, PCI_STATUS_CAP_LIST),
2050 FLAG(status, PCI_STATUS_66MHZ),
2051 FLAG(status, PCI_STATUS_UDF),
2052 FLAG(status, PCI_STATUS_FAST_BACK),
2053 FLAG(status, PCI_STATUS_PARITY),
2054 ((status & PCI_STATUS_DEVSEL_MASK) == PCI_STATUS_DEVSEL_SLOW) ? "slow" :
2055 ((status & PCI_STATUS_DEVSEL_MASK) == PCI_STATUS_DEVSEL_MEDIUM) ? "medium" :
2056 ((status & PCI_STATUS_DEVSEL_MASK) == PCI_STATUS_DEVSEL_FAST) ? "fast" : "??",
2057 FLAG(status, PCI_STATUS_SIG_TARGET_ABORT),
2058 FLAG(status, PCI_STATUS_REC_TARGET_ABORT),
2059 FLAG(status, PCI_STATUS_REC_MASTER_ABORT),
2060 FLAG(status, PCI_STATUS_SIG_SYSTEM_ERROR),
2061 FLAG(status, PCI_STATUS_DETECTED_PARITY),
2062 FLAG(status, PCI_STATUS_INTx));
2063 if (cmd & PCI_COMMAND_MASTER)
2065 printf("\tLatency: %d", latency);
2066 if (min_gnt || max_lat)
2070 printf("%dns min", min_gnt*250);
2071 if (min_gnt && max_lat)
2074 printf("%dns max", max_lat*250);
2078 printf(", Cache Line Size: %d bytes", cache_line * 4);
2082 printf("\tInterrupt: pin %c routed to IRQ " PCIIRQ_FMT "\n",
2083 (int_pin ? 'A' + int_pin - 1 : '?'), irq);
2087 printf("\tFlags: ");
2088 if (cmd & PCI_COMMAND_MASTER)
2089 printf("bus master, ");
2090 if (cmd & PCI_COMMAND_VGA_PALETTE)
2091 printf("VGA palette snoop, ");
2092 if (cmd & PCI_COMMAND_WAIT)
2093 printf("stepping, ");
2094 if (cmd & PCI_COMMAND_FAST_BACK)
2095 printf("fast Back2Back, ");
2096 if (status & PCI_STATUS_66MHZ)
2098 if (status & PCI_STATUS_UDF)
2099 printf("user-definable features, ");
2101 ((status & PCI_STATUS_DEVSEL_MASK) == PCI_STATUS_DEVSEL_SLOW) ? "slow" :
2102 ((status & PCI_STATUS_DEVSEL_MASK) == PCI_STATUS_DEVSEL_MEDIUM) ? "medium" :
2103 ((status & PCI_STATUS_DEVSEL_MASK) == PCI_STATUS_DEVSEL_FAST) ? "fast" : "??");
2104 if (cmd & PCI_COMMAND_MASTER)
2105 printf(", latency %d", latency);
2107 printf(", IRQ " PCIIRQ_FMT, irq);
2111 if (bist & PCI_BIST_CAPABLE)
2113 if (bist & PCI_BIST_START)
2114 printf("\tBIST is running\n");
2116 printf("\tBIST result: %02x\n", bist & PCI_BIST_CODE_MASK);
2121 case PCI_HEADER_TYPE_NORMAL:
2124 case PCI_HEADER_TYPE_BRIDGE:
2127 case PCI_HEADER_TYPE_CARDBUS:
2133 /*** Machine-readable dumps ***/
2136 show_hex_dump(struct device *d)
2138 unsigned int i, cnt;
2140 cnt = d->config_cached;
2141 if (opt_hex >= 3 && config_fetch(d, cnt, 256-cnt))
2144 if (opt_hex >= 4 && config_fetch(d, 256, 4096-256))
2148 for(i=0; i<cnt; i++)
2152 printf(" %02x", get_conf_byte(d, i));
2159 print_shell_escaped(char *c)
2164 if (*c == '"' || *c == '\\')
2172 show_machine(struct device *d)
2174 struct pci_dev *p = d->dev;
2177 char classbuf[128], vendbuf[128], devbuf[128], svbuf[128], sdbuf[128];
2179 get_subid(d, &sv_id, &sd_id);
2183 printf((opt_machine >= 2) ? "Slot:\t" : "Device:\t");
2186 printf("Class:\t%s\n",
2187 pci_lookup_name(pacc, classbuf, sizeof(classbuf), PCI_LOOKUP_CLASS, p->device_class));
2188 printf("Vendor:\t%s\n",
2189 pci_lookup_name(pacc, vendbuf, sizeof(vendbuf), PCI_LOOKUP_VENDOR, p->vendor_id, p->device_id));
2190 printf("Device:\t%s\n",
2191 pci_lookup_name(pacc, devbuf, sizeof(devbuf), PCI_LOOKUP_DEVICE, p->vendor_id, p->device_id));
2192 if (sv_id && sv_id != 0xffff)
2194 printf("SVendor:\t%s\n",
2195 pci_lookup_name(pacc, svbuf, sizeof(svbuf), PCI_LOOKUP_SUBSYSTEM | PCI_LOOKUP_VENDOR, sv_id));
2196 printf("SDevice:\t%s\n",
2197 pci_lookup_name(pacc, sdbuf, sizeof(sdbuf), PCI_LOOKUP_SUBSYSTEM | PCI_LOOKUP_DEVICE, p->vendor_id, p->device_id, sv_id, sd_id));
2199 if (c = get_conf_byte(d, PCI_REVISION_ID))
2200 printf("Rev:\t%02x\n", c);
2201 if (c = get_conf_byte(d, PCI_CLASS_PROG))
2202 printf("ProgIf:\t%02x\n", c);
2204 show_kernel_machine(d);
2209 print_shell_escaped(pci_lookup_name(pacc, classbuf, sizeof(classbuf), PCI_LOOKUP_CLASS, p->device_class));
2210 print_shell_escaped(pci_lookup_name(pacc, vendbuf, sizeof(vendbuf), PCI_LOOKUP_VENDOR, p->vendor_id, p->device_id));
2211 print_shell_escaped(pci_lookup_name(pacc, devbuf, sizeof(devbuf), PCI_LOOKUP_DEVICE, p->vendor_id, p->device_id));
2212 if (c = get_conf_byte(d, PCI_REVISION_ID))
2213 printf(" -r%02x", c);
2214 if (c = get_conf_byte(d, PCI_CLASS_PROG))
2215 printf(" -p%02x", c);
2216 if (sv_id && sv_id != 0xffff)
2218 print_shell_escaped(pci_lookup_name(pacc, svbuf, sizeof(svbuf), PCI_LOOKUP_SUBSYSTEM | PCI_LOOKUP_VENDOR, sv_id));
2219 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));
2222 printf(" \"\" \"\"");
2227 /*** Main show function ***/
2230 show_device(struct device *d)
2240 if (opt_kernel || verbose)
2245 if (verbose || opt_hex)
2254 for(d=first_dev; d; d=d->next)
2258 /*** Tree output ***/
2261 struct bridge *chain; /* Single-linked list of bridges */
2262 struct bridge *next, *child; /* Tree of bridges */
2263 struct bus *first_bus; /* List of buses connected to this bridge */
2264 unsigned int domain;
2265 unsigned int primary, secondary, subordinate; /* Bus numbers */
2266 struct device *br_dev;
2270 unsigned int domain;
2271 unsigned int number;
2272 struct bus *sibling;
2273 struct device *first_dev, **last_dev;
2276 static struct bridge host_bridge = { NULL, NULL, NULL, NULL, 0, ~0, 0, ~0, NULL };
2279 find_bus(struct bridge *b, unsigned int domain, unsigned int n)
2283 for(bus=b->first_bus; bus; bus=bus->sibling)
2284 if (bus->domain == domain && bus->number == n)
2290 new_bus(struct bridge *b, unsigned int domain, unsigned int n)
2292 struct bus *bus = xmalloc(sizeof(struct bus));
2293 bus->domain = domain;
2295 bus->sibling = b->first_bus;
2296 bus->first_dev = NULL;
2297 bus->last_dev = &bus->first_dev;
2303 insert_dev(struct device *d, struct bridge *b)
2305 struct pci_dev *p = d->dev;
2308 if (! (bus = find_bus(b, p->domain, p->bus)))
2311 for(c=b->child; c; c=c->next)
2312 if (c->domain == p->domain && c->secondary <= p->bus && p->bus <= c->subordinate)
2317 bus = new_bus(b, p->domain, p->bus);
2319 /* Simple insertion at the end _does_ guarantee the correct order as the
2320 * original device list was sorted by (domain, bus, devfn) lexicographically
2321 * and all devices on the new list have the same bus number.
2324 bus->last_dev = &d->next;
2331 struct device *d, *d2;
2332 struct bridge **last_br, *b;
2334 /* Build list of bridges */
2336 last_br = &host_bridge.chain;
2337 for(d=first_dev; d; d=d->next)
2339 word class = d->dev->device_class;
2340 byte ht = get_conf_byte(d, PCI_HEADER_TYPE) & 0x7f;
2341 if (class == PCI_CLASS_BRIDGE_PCI &&
2342 (ht == PCI_HEADER_TYPE_BRIDGE || ht == PCI_HEADER_TYPE_CARDBUS))
2344 b = xmalloc(sizeof(struct bridge));
2345 b->domain = d->dev->domain;
2346 if (ht == PCI_HEADER_TYPE_BRIDGE)
2348 b->primary = get_conf_byte(d, PCI_PRIMARY_BUS);
2349 b->secondary = get_conf_byte(d, PCI_SECONDARY_BUS);
2350 b->subordinate = get_conf_byte(d, PCI_SUBORDINATE_BUS);
2354 b->primary = get_conf_byte(d, PCI_CB_PRIMARY_BUS);
2355 b->secondary = get_conf_byte(d, PCI_CB_CARD_BUS);
2356 b->subordinate = get_conf_byte(d, PCI_CB_SUBORDINATE_BUS);
2359 last_br = &b->chain;
2360 b->next = b->child = NULL;
2361 b->first_bus = NULL;
2367 /* Create a bridge tree */
2369 for(b=&host_bridge; b; b=b->chain)
2371 struct bridge *c, *best;
2373 for(c=&host_bridge; c; c=c->chain)
2374 if (c != b && (c == &host_bridge || b->domain == c->domain) &&
2375 b->primary >= c->secondary && b->primary <= c->subordinate &&
2376 (!best || best->subordinate - best->primary > c->subordinate - c->primary))
2380 b->next = best->child;
2385 /* Insert secondary bus for each bridge */
2387 for(b=&host_bridge; b; b=b->chain)
2388 if (!find_bus(b, b->domain, b->secondary))
2389 new_bus(b, b->domain, b->secondary);
2391 /* Create bus structs and link devices */
2393 for(d=first_dev; d;)
2396 insert_dev(d, &host_bridge);
2402 print_it(char *line, char *p)
2406 fputs(line, stdout);
2407 for(p=line; *p; p++)
2408 if (*p == '+' || *p == '|')
2414 static void show_tree_bridge(struct bridge *, char *, char *);
2417 show_tree_dev(struct device *d, char *line, char *p)
2419 struct pci_dev *q = d->dev;
2423 p += sprintf(p, "%02x.%x", q->dev, q->func);
2424 for(b=&host_bridge; b; b=b->chain)
2427 if (b->secondary == b->subordinate)
2428 p += sprintf(p, "-[%04x:%02x]-", b->domain, b->secondary);
2430 p += sprintf(p, "-[%04x:%02x-%02x]-", b->domain, b->secondary, b->subordinate);
2431 show_tree_bridge(b, line, p);
2435 p += sprintf(p, " %s",
2436 pci_lookup_name(pacc, namebuf, sizeof(namebuf),
2437 PCI_LOOKUP_VENDOR | PCI_LOOKUP_DEVICE,
2438 q->vendor_id, q->device_id));
2443 show_tree_bus(struct bus *b, char *line, char *p)
2447 else if (!b->first_dev->next)
2451 show_tree_dev(b->first_dev, line, p);
2455 struct device *d = b->first_dev;
2460 show_tree_dev(d, line, p+2);
2465 show_tree_dev(d, line, p+2);
2470 show_tree_bridge(struct bridge *b, char *line, char *p)
2473 if (!b->first_bus->sibling)
2475 if (b == &host_bridge)
2476 p += sprintf(p, "[%04x:%02x]-", b->domain, b->first_bus->number);
2477 show_tree_bus(b->first_bus, line, p);
2481 struct bus *u = b->first_bus;
2486 k = p + sprintf(p, "+-[%04x:%02x]-", u->domain, u->number);
2487 show_tree_bus(u, line, k);
2490 k = p + sprintf(p, "\\-[%04x:%02x]-", u->domain, u->number);
2491 show_tree_bus(u, line, k);
2501 show_tree_bridge(&host_bridge, line, line);
2504 /*** Bus mapping mode ***/
2507 struct bus_bridge *next;
2508 byte this, dev, func, first, last, bug;
2514 struct bus_bridge *bridges, *via;
2517 static struct bus_info *bus_info;
2520 map_bridge(struct bus_info *bi, struct device *d, int np, int ns, int nl)
2522 struct bus_bridge *b = xmalloc(sizeof(struct bus_bridge));
2523 struct pci_dev *p = d->dev;
2525 b->next = bi->bridges;
2527 b->this = get_conf_byte(d, np);
2530 b->first = get_conf_byte(d, ns);
2531 b->last = get_conf_byte(d, nl);
2532 printf("## %02x.%02x:%d is a bridge from %02x to %02x-%02x\n",
2533 p->bus, p->dev, p->func, b->this, b->first, b->last);
2534 if (b->this != p->bus)
2535 printf("!!! Bridge points to invalid primary bus.\n");
2536 if (b->first > b->last)
2538 printf("!!! Bridge points to invalid bus range.\n");
2547 int verbose = pacc->debugging;
2548 struct bus_info *bi = bus_info + bus;
2552 printf("Mapping bus %02x\n", bus);
2553 for(dev = 0; dev < 32; dev++)
2554 if (filter.slot < 0 || filter.slot == dev)
2557 for(func = 0; func < func_limit; func++)
2558 if (filter.func < 0 || filter.func == func)
2560 /* XXX: Bus mapping supports only domain 0 */
2561 struct pci_dev *p = pci_get_dev(pacc, 0, bus, dev, func);
2562 u16 vendor = pci_read_word(p, PCI_VENDOR_ID);
2563 if (vendor && vendor != 0xffff)
2565 if (!func && (pci_read_byte(p, PCI_HEADER_TYPE) & 0x80))
2568 printf("Discovered device %02x:%02x.%d\n", bus, dev, func);
2570 if (d = scan_device(p))
2573 switch (get_conf_byte(d, PCI_HEADER_TYPE) & 0x7f)
2575 case PCI_HEADER_TYPE_BRIDGE:
2576 map_bridge(bi, d, PCI_PRIMARY_BUS, PCI_SECONDARY_BUS, PCI_SUBORDINATE_BUS);
2578 case PCI_HEADER_TYPE_CARDBUS:
2579 map_bridge(bi, d, PCI_CB_PRIMARY_BUS, PCI_CB_CARD_BUS, PCI_CB_SUBORDINATE_BUS);
2585 printf("But it was filtered out.\n");
2593 do_map_bridges(int bus, int min, int max)
2595 struct bus_info *bi = bus_info + bus;
2596 struct bus_bridge *b;
2599 for(b=bi->bridges; b; b=b->next)
2601 if (bus_info[b->first].guestbook)
2603 else if (b->first < min || b->last > max)
2607 bus_info[b->first].via = b;
2608 do_map_bridges(b->first, b->first, b->last);
2618 printf("\nSummary of buses:\n\n");
2619 for(i=0; i<256; i++)
2620 if (bus_info[i].exists && !bus_info[i].guestbook)
2621 do_map_bridges(i, 0, 255);
2622 for(i=0; i<256; i++)
2624 struct bus_info *bi = bus_info + i;
2625 struct bus_bridge *b = bi->via;
2629 printf("%02x: ", i);
2631 printf("Entered via %02x:%02x.%d\n", b->this, b->dev, b->func);
2633 printf("Primary host bus\n");
2635 printf("Secondary host bus (?)\n");
2637 for(b=bi->bridges; b; b=b->next)
2639 printf("\t%02x.%d Bridge to %02x-%02x", b->dev, b->func, b->first, b->last);
2643 printf(" <overlap bug>");
2646 printf(" <crossing bug>");
2657 if (pacc->method == PCI_ACCESS_PROC_BUS_PCI ||
2658 pacc->method == PCI_ACCESS_DUMP)
2659 printf("WARNING: Bus mapping can be reliable only with direct hardware access enabled.\n\n");
2660 bus_info = xmalloc(sizeof(struct bus_info) * 256);
2661 memset(bus_info, 0, sizeof(struct bus_info) * 256);
2662 if (filter.bus >= 0)
2663 do_map_bus(filter.bus);
2667 for(bus=0; bus<256; bus++)
2676 main(int argc, char **argv)
2681 if (argc == 2 && !strcmp(argv[1], "--version"))
2683 puts("lspci version " PCIUTILS_VERSION);
2689 pci_filter_init(pacc, &filter);
2691 while ((i = getopt(argc, argv, options)) != -1)
2695 pacc->numeric_ids++;
2701 pacc->buscentric = 1;
2705 if (msg = pci_filter_parse_slot(&filter, optarg))
2709 if (msg = pci_filter_parse_id(&filter, optarg))
2719 pci_set_name_list_path(pacc, optarg, 0);
2725 opt_pcimap = optarg;
2746 die("DNS queries are not available in this version");
2749 if (parse_generic_option(i, pacc, optarg))
2752 fprintf(stderr, help_msg, pacc->id_file_name);
2760 pacc->id_lookup_mode |= PCI_LOOKUP_NETWORK;
2761 if (opt_query_dns > 1)
2762 pacc->id_lookup_mode |= PCI_LOOKUP_REFRESH_CACHE;
2765 pacc->id_lookup_mode |= PCI_LOOKUP_NETWORK | PCI_LOOKUP_SKIP_LOCAL;
2781 return (seen_errors ? 2 : 0);