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.
15 #define PCIUTILS_LSPCI
20 static int verbose; /* Show detailed information */
21 static int opt_buscentric; /* Show bus addresses/IRQ's instead of CPU-visible ones */
22 static int opt_hex; /* Show contents of config space as hexadecimal numbers */
23 static struct pci_filter filter; /* Device filter */
24 static int opt_tree; /* Show bus tree */
25 static int opt_machine; /* Generate machine-readable output */
26 static int opt_map_mode; /* Bus mapping mode enabled */
27 static int opt_domains; /* Show domain numbers (0=disabled, 1=auto-detected, 2=requested) */
28 static int opt_kernel; /* Show kernel drivers */
29 static int opt_query_dns; /* Query the DNS (0=disabled, 1=enabled, 2=refresh cache) */
30 static int opt_query_all; /* Query the DNS for all entries */
31 static char *opt_pcimap; /* Override path to Linux modules.pcimap */
33 const char program_name[] = "lspci";
35 static char options[] = "nvbxs:d:ti:mgp:qkMDQ" GENERIC_OPTIONS ;
37 static char help_msg[] =
38 "Usage: lspci [<switches>]\n"
40 "Basic display modes:\n"
41 "-mm\t\tProduce machine-readable output (single -m for an obsolete format)\n"
42 "-t\t\tShow bus tree\n"
45 "-v\t\tBe verbose (-vv for very verbose)\n"
47 "-k\t\tShow kernel drivers handling each device\n"
49 "-x\t\tShow hex-dump of the standard part of the config space\n"
50 "-xxx\t\tShow hex-dump of the whole config space (dangerous; root only)\n"
51 "-xxxx\t\tShow hex-dump of the 4096-byte extended config space (root only)\n"
52 "-b\t\tBus-centric view (addresses and IRQ's as seen by the bus)\n"
53 "-D\t\tAlways show domain numbers\n"
55 "Resolving of device ID's to names:\n"
56 "-n\t\tShow numeric ID's\n"
57 "-nn\t\tShow both textual and numeric ID's (names & numbers)\n"
59 "-q\t\tQuery the PCI ID database for unknown ID's via DNS\n"
60 "-qq\t\tAs above, but re-query locally cached entries\n"
61 "-Q\t\tQuery the PCI ID database for all ID's via DNS\n"
64 "Selection of devices:\n"
65 "-s [[[[<domain>]:]<bus>]:][<slot>][.[<func>]]\tShow only devices in selected slots\n"
66 "-d [<vendor>]:[<device>]\t\t\tShow only devices with specified ID's\n"
69 "-i <file>\tUse specified ID database instead of %s\n"
71 "-p <file>\tLook up kernel modules in a given file instead of default modules.pcimap\n"
73 "-M\t\tEnable `bus mapping' mode (dangerous; root only)\n"
75 "PCI access options:\n"
79 /*** Communication with libpci ***/
81 static struct pci_access *pacc;
84 * If we aren't being compiled by GCC, use xmalloc() instead of alloca().
85 * This increases our memory footprint, but only slightly since we don't
88 #if defined (__FreeBSD__) || defined (__NetBSD__) || defined (__OpenBSD__) || defined (__DragonFly__)
89 /* alloca() is defined in stdlib.h */
90 #elif defined(__GNUC__) && !defined(PCI_OS_WINDOWS)
94 #define alloca xmalloc
97 /*** Our view of the PCI bus ***/
102 unsigned int config_cached, config_bufsize;
103 byte *config; /* Cached configuration space data */
104 byte *present; /* Maps which configuration bytes are present */
107 static struct device *first_dev;
108 static int seen_errors;
111 config_fetch(struct device *d, unsigned int pos, unsigned int len)
113 unsigned int end = pos+len;
116 while (pos < d->config_bufsize && len && d->present[pos])
118 while (pos+len <= d->config_bufsize && len && d->present[pos+len-1])
123 if (end > d->config_bufsize)
125 int orig_size = d->config_bufsize;
126 while (end > d->config_bufsize)
127 d->config_bufsize *= 2;
128 d->config = xrealloc(d->config, d->config_bufsize);
129 d->present = xrealloc(d->present, d->config_bufsize);
130 memset(d->present + orig_size, 0, d->config_bufsize - orig_size);
132 result = pci_read_block(d->dev, pos, d->config + pos, len);
134 memset(d->present + pos, 1, len);
138 static struct device *
139 scan_device(struct pci_dev *p)
143 if (p->domain && !opt_domains)
145 if (!pci_filter_match(&filter, p))
147 d = xmalloc(sizeof(struct device));
148 memset(d, 0, sizeof(*d));
150 d->config_cached = d->config_bufsize = 64;
151 d->config = xmalloc(64);
152 d->present = xmalloc(64);
153 memset(d->present, 1, 64);
154 if (!pci_read_block(p, 0, d->config, 64))
156 fprintf(stderr, "lspci: Unable to read the standard configuration space header of device %04x:%02x:%02x.%d\n",
157 p->domain, p->bus, p->dev, p->func);
161 if ((d->config[PCI_HEADER_TYPE] & 0x7f) == PCI_HEADER_TYPE_CARDBUS)
163 /* For cardbus bridges, we need to fetch 64 bytes more to get the
164 * full standard header... */
165 if (config_fetch(d, 64, 64))
166 d->config_cached += 64;
168 pci_setup_cache(p, d->config, d->config_cached);
169 pci_fill_info(p, PCI_FILL_IDENT | PCI_FILL_CLASS | PCI_FILL_IRQ | PCI_FILL_BASES | PCI_FILL_ROM_BASE | PCI_FILL_SIZES);
180 for(p=pacc->devices; p; p=p->next)
181 if (d = scan_device(p))
188 /*** Config space accesses ***/
191 check_conf_range(struct device *d, unsigned int pos, unsigned int len)
194 if (!d->present[pos])
195 die("Internal bug: Accessing non-read configuration byte at position %x", pos);
201 get_conf_byte(struct device *d, unsigned int pos)
203 check_conf_range(d, pos, 1);
204 return d->config[pos];
208 get_conf_word(struct device *d, unsigned int pos)
210 check_conf_range(d, pos, 2);
211 return d->config[pos] | (d->config[pos+1] << 8);
215 get_conf_long(struct device *d, unsigned int pos)
217 check_conf_range(d, pos, 4);
218 return d->config[pos] |
219 (d->config[pos+1] << 8) |
220 (d->config[pos+2] << 16) |
221 (d->config[pos+3] << 24);
227 compare_them(const void *A, const void *B)
229 const struct pci_dev *a = (*(const struct device **)A)->dev;
230 const struct pci_dev *b = (*(const struct device **)B)->dev;
232 if (a->domain < b->domain)
234 if (a->domain > b->domain)
244 if (a->func < b->func)
246 if (a->func > b->func)
254 struct device **index, **h, **last_dev;
259 for(d=first_dev; d; d=d->next)
261 h = index = alloca(sizeof(struct device *) * cnt);
262 for(d=first_dev; d; d=d->next)
264 qsort(index, cnt, sizeof(struct device *), compare_them);
265 last_dev = &first_dev;
270 last_dev = &(*h)->next;
276 /*** Normal output ***/
278 #define FLAG(x,y) ((x & y) ? '+' : '-')
281 show_slot_name(struct device *d)
283 struct pci_dev *p = d->dev;
285 if (!opt_machine ? opt_domains : (p->domain || opt_domains >= 2))
286 printf("%04x:", p->domain);
287 printf("%02x:%02x.%d", p->bus, p->dev, p->func);
291 show_terse(struct device *d)
294 struct pci_dev *p = d->dev;
295 char classbuf[128], devbuf[128];
299 pci_lookup_name(pacc, classbuf, sizeof(classbuf),
302 pci_lookup_name(pacc, devbuf, sizeof(devbuf),
303 PCI_LOOKUP_VENDOR | PCI_LOOKUP_DEVICE,
304 p->vendor_id, p->device_id));
305 if (c = get_conf_byte(d, PCI_REVISION_ID))
306 printf(" (rev %02x)", c);
310 c = get_conf_byte(d, PCI_CLASS_PROG);
311 x = pci_lookup_name(pacc, devbuf, sizeof(devbuf),
312 PCI_LOOKUP_PROGIF | PCI_LOOKUP_NO_NUMBERS,
316 printf(" (prog-if %02x", c);
326 get_subid(struct device *d, word *subvp, word *subdp)
328 byte htype = get_conf_byte(d, PCI_HEADER_TYPE) & 0x7f;
330 if (htype == PCI_HEADER_TYPE_NORMAL)
332 *subvp = get_conf_word(d, PCI_SUBSYSTEM_VENDOR_ID);
333 *subdp = get_conf_word(d, PCI_SUBSYSTEM_ID);
335 else if (htype == PCI_HEADER_TYPE_CARDBUS && d->config_cached >= 128)
337 *subvp = get_conf_word(d, PCI_CB_SUBSYSTEM_VENDOR_ID);
338 *subdp = get_conf_word(d, PCI_CB_SUBSYSTEM_ID);
341 *subvp = *subdp = 0xffff;
344 /*** Capabilities ***/
347 cap_pm(struct device *d, int where, int cap)
350 static int pm_aux_current[8] = { 0, 55, 100, 160, 220, 270, 320, 375 };
352 printf("Power Management version %d\n", cap & PCI_PM_CAP_VER_MASK);
355 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",
356 FLAG(cap, PCI_PM_CAP_PME_CLOCK),
357 FLAG(cap, PCI_PM_CAP_DSI),
358 FLAG(cap, PCI_PM_CAP_D1),
359 FLAG(cap, PCI_PM_CAP_D2),
360 pm_aux_current[(cap >> 6) & 7],
361 FLAG(cap, PCI_PM_CAP_PME_D0),
362 FLAG(cap, PCI_PM_CAP_PME_D1),
363 FLAG(cap, PCI_PM_CAP_PME_D2),
364 FLAG(cap, PCI_PM_CAP_PME_D3_HOT),
365 FLAG(cap, PCI_PM_CAP_PME_D3_COLD));
366 if (!config_fetch(d, where + PCI_PM_CTRL, PCI_PM_SIZEOF - PCI_PM_CTRL))
368 t = get_conf_word(d, where + PCI_PM_CTRL);
369 printf("\t\tStatus: D%d PME-Enable%c DSel=%d DScale=%d PME%c\n",
370 t & PCI_PM_CTRL_STATE_MASK,
371 FLAG(t, PCI_PM_CTRL_PME_ENABLE),
372 (t & PCI_PM_CTRL_DATA_SEL_MASK) >> 9,
373 (t & PCI_PM_CTRL_DATA_SCALE_MASK) >> 13,
374 FLAG(t, PCI_PM_CTRL_PME_STATUS));
375 b = get_conf_byte(d, where + PCI_PM_PPB_EXTENSIONS);
377 printf("\t\tBridge: PM%c B3%c\n",
378 FLAG(t, PCI_PM_BPCC_ENABLE),
379 FLAG(~t, PCI_PM_PPB_B2_B3));
383 format_agp_rate(int rate, char *buf, int agp3)
393 c += sprintf(c, "x%d", 1 << (i + 2*agp3));
398 strcpy(buf, "<none>");
402 cap_agp(struct device *d, int where, int cap)
409 ver = (cap >> 4) & 0x0f;
411 printf("AGP version %x.%x\n", ver, rev);
414 if (!config_fetch(d, where + PCI_AGP_STATUS, PCI_AGP_SIZEOF - PCI_AGP_STATUS))
416 t = get_conf_long(d, where + PCI_AGP_STATUS);
417 if (ver >= 3 && (t & PCI_AGP_STATUS_AGP3))
419 format_agp_rate(t & 7, rate, agp3);
420 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",
421 ((t & PCI_AGP_STATUS_RQ_MASK) >> 24U) + 1,
422 FLAG(t, PCI_AGP_STATUS_ISOCH),
423 ((t & PCI_AGP_STATUS_ARQSZ_MASK) >> 13),
424 ((t & PCI_AGP_STATUS_CAL_MASK) >> 10),
425 FLAG(t, PCI_AGP_STATUS_SBA),
426 FLAG(t, PCI_AGP_STATUS_ITA_COH),
427 FLAG(t, PCI_AGP_STATUS_GART64),
428 FLAG(t, PCI_AGP_STATUS_HTRANS),
429 FLAG(t, PCI_AGP_STATUS_64BIT),
430 FLAG(t, PCI_AGP_STATUS_FW),
431 FLAG(t, PCI_AGP_STATUS_AGP3),
433 t = get_conf_long(d, where + PCI_AGP_COMMAND);
434 format_agp_rate(t & 7, rate, agp3);
435 printf("\t\tCommand: RQ=%d ArqSz=%d Cal=%d SBA%c AGP%c GART64%c 64bit%c FW%c Rate=%s\n",
436 ((t & PCI_AGP_COMMAND_RQ_MASK) >> 24U) + 1,
437 ((t & PCI_AGP_COMMAND_ARQSZ_MASK) >> 13),
438 ((t & PCI_AGP_COMMAND_CAL_MASK) >> 10),
439 FLAG(t, PCI_AGP_COMMAND_SBA),
440 FLAG(t, PCI_AGP_COMMAND_AGP),
441 FLAG(t, PCI_AGP_COMMAND_GART64),
442 FLAG(t, PCI_AGP_COMMAND_64BIT),
443 FLAG(t, PCI_AGP_COMMAND_FW),
448 cap_pcix_nobridge(struct device *d, int where)
452 static const byte max_outstanding[8] = { 1, 2, 3, 4, 8, 12, 16, 32 };
454 printf("PCI-X non-bridge device\n");
459 if (!config_fetch(d, where + PCI_PCIX_STATUS, 4))
462 command = get_conf_word(d, where + PCI_PCIX_COMMAND);
463 status = get_conf_long(d, where + PCI_PCIX_STATUS);
464 printf("\t\tCommand: DPERE%c ERO%c RBC=%d OST=%d\n",
465 FLAG(command, PCI_PCIX_COMMAND_DPERE),
466 FLAG(command, PCI_PCIX_COMMAND_ERO),
467 1 << (9 + ((command & PCI_PCIX_COMMAND_MAX_MEM_READ_BYTE_COUNT) >> 2U)),
468 max_outstanding[(command & PCI_PCIX_COMMAND_MAX_OUTSTANDING_SPLIT_TRANS) >> 4U]);
469 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",
470 ((status >> 8) & 0xff),
471 ((status >> 3) & 0x1f),
472 (status & PCI_PCIX_STATUS_FUNCTION),
473 FLAG(status, PCI_PCIX_STATUS_64BIT),
474 FLAG(status, PCI_PCIX_STATUS_133MHZ),
475 FLAG(status, PCI_PCIX_STATUS_SC_DISCARDED),
476 FLAG(status, PCI_PCIX_STATUS_UNEXPECTED_SC),
477 ((status & PCI_PCIX_STATUS_DEVICE_COMPLEXITY) ? "bridge" : "simple"),
478 1 << (9 + ((status >> 21) & 3U)),
479 max_outstanding[(status >> 23) & 7U],
480 1 << (3 + ((status >> 26) & 7U)),
481 FLAG(status, PCI_PCIX_STATUS_RCVD_SC_ERR_MESS),
482 FLAG(status, PCI_PCIX_STATUS_266MHZ),
483 FLAG(status, PCI_PCIX_STATUS_533MHZ));
487 cap_pcix_bridge(struct device *d, int where)
489 static const char * const sec_clock_freq[8] = { "conv", "66MHz", "100MHz", "133MHz", "?4", "?5", "?6", "?7" };
491 u32 status, upstcr, downstcr;
493 printf("PCI-X bridge device\n");
498 if (!config_fetch(d, where + PCI_PCIX_BRIDGE_STATUS, 12))
501 secstatus = get_conf_word(d, where + PCI_PCIX_BRIDGE_SEC_STATUS);
502 printf("\t\tSecondary Status: 64bit%c 133MHz%c SCD%c USC%c SCO%c SRD%c Freq=%s\n",
503 FLAG(secstatus, PCI_PCIX_BRIDGE_SEC_STATUS_64BIT),
504 FLAG(secstatus, PCI_PCIX_BRIDGE_SEC_STATUS_133MHZ),
505 FLAG(secstatus, PCI_PCIX_BRIDGE_SEC_STATUS_SC_DISCARDED),
506 FLAG(secstatus, PCI_PCIX_BRIDGE_SEC_STATUS_UNEXPECTED_SC),
507 FLAG(secstatus, PCI_PCIX_BRIDGE_SEC_STATUS_SC_OVERRUN),
508 FLAG(secstatus, PCI_PCIX_BRIDGE_SEC_STATUS_SPLIT_REQUEST_DELAYED),
509 sec_clock_freq[(secstatus >> 6) & 7]);
510 status = get_conf_long(d, where + PCI_PCIX_BRIDGE_STATUS);
511 printf("\t\tStatus: Dev=%02x:%02x.%d 64bit%c 133MHz%c SCD%c USC%c SCO%c SRD%c\n",
512 ((status >> 8) & 0xff),
513 ((status >> 3) & 0x1f),
514 (status & PCI_PCIX_BRIDGE_STATUS_FUNCTION),
515 FLAG(status, PCI_PCIX_BRIDGE_STATUS_64BIT),
516 FLAG(status, PCI_PCIX_BRIDGE_STATUS_133MHZ),
517 FLAG(status, PCI_PCIX_BRIDGE_STATUS_SC_DISCARDED),
518 FLAG(status, PCI_PCIX_BRIDGE_STATUS_UNEXPECTED_SC),
519 FLAG(status, PCI_PCIX_BRIDGE_STATUS_SC_OVERRUN),
520 FLAG(status, PCI_PCIX_BRIDGE_STATUS_SPLIT_REQUEST_DELAYED));
521 upstcr = get_conf_long(d, where + PCI_PCIX_BRIDGE_UPSTREAM_SPLIT_TRANS_CTRL);
522 printf("\t\tUpstream: Capacity=%u CommitmentLimit=%u\n",
523 (upstcr & PCI_PCIX_BRIDGE_STR_CAPACITY),
524 (upstcr >> 16) & 0xffff);
525 downstcr = get_conf_long(d, where + PCI_PCIX_BRIDGE_DOWNSTREAM_SPLIT_TRANS_CTRL);
526 printf("\t\tDownstream: Capacity=%u CommitmentLimit=%u\n",
527 (downstcr & PCI_PCIX_BRIDGE_STR_CAPACITY),
528 (downstcr >> 16) & 0xffff);
532 cap_pcix(struct device *d, int where)
534 switch (get_conf_byte(d, PCI_HEADER_TYPE) & 0x7f)
536 case PCI_HEADER_TYPE_NORMAL:
537 cap_pcix_nobridge(d, where);
539 case PCI_HEADER_TYPE_BRIDGE:
540 cap_pcix_bridge(d, where);
546 ht_link_width(unsigned width)
548 static char * const widths[8] = { "8bit", "16bit", "[2]", "32bit", "2bit", "4bit", "[6]", "N/C" };
549 return widths[width];
553 ht_link_freq(unsigned freq)
555 static char * const freqs[16] = { "200MHz", "300MHz", "400MHz", "500MHz", "600MHz", "800MHz", "1.0GHz", "1.2GHz",
556 "1.4GHz", "1.6GHz", "[a]", "[b]", "[c]", "[d]", "[e]", "Vend" };
561 cap_ht_pri(struct device *d, int where, int cmd)
563 u16 lctr0, lcnf0, lctr1, lcnf1, eh;
564 u8 rid, lfrer0, lfcap0, ftr, lfrer1, lfcap1, mbu, mlu, bn;
567 printf("HyperTransport: Slave or Primary Interface\n");
571 if (!config_fetch(d, where + PCI_HT_PRI_LCTR0, PCI_HT_PRI_SIZEOF - PCI_HT_PRI_LCTR0))
573 rid = get_conf_byte(d, where + PCI_HT_PRI_RID);
574 if (rid < 0x23 && rid > 0x11)
575 printf("\t\t!!! Possibly incomplete decoding\n");
578 fmt = "\t\tCommand: BaseUnitID=%u UnitCnt=%u MastHost%c DefDir%c DUL%c\n";
580 fmt = "\t\tCommand: BaseUnitID=%u UnitCnt=%u MastHost%c DefDir%c\n";
582 (cmd & PCI_HT_PRI_CMD_BUID),
583 (cmd & PCI_HT_PRI_CMD_UC) >> 5,
584 FLAG(cmd, PCI_HT_PRI_CMD_MH),
585 FLAG(cmd, PCI_HT_PRI_CMD_DD),
586 FLAG(cmd, PCI_HT_PRI_CMD_DUL));
587 lctr0 = get_conf_word(d, where + PCI_HT_PRI_LCTR0);
589 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";
591 fmt = "\t\tLink Control 0: CFlE%c CST%c CFE%c <LkFail%c Init%c EOC%c TXO%c <CRCErr=%x\n";
593 FLAG(lctr0, PCI_HT_LCTR_CFLE),
594 FLAG(lctr0, PCI_HT_LCTR_CST),
595 FLAG(lctr0, PCI_HT_LCTR_CFE),
596 FLAG(lctr0, PCI_HT_LCTR_LKFAIL),
597 FLAG(lctr0, PCI_HT_LCTR_INIT),
598 FLAG(lctr0, PCI_HT_LCTR_EOC),
599 FLAG(lctr0, PCI_HT_LCTR_TXO),
600 (lctr0 & PCI_HT_LCTR_CRCERR) >> 8,
601 FLAG(lctr0, PCI_HT_LCTR_ISOCEN),
602 FLAG(lctr0, PCI_HT_LCTR_LSEN),
603 FLAG(lctr0, PCI_HT_LCTR_EXTCTL),
604 FLAG(lctr0, PCI_HT_LCTR_64B));
605 lcnf0 = get_conf_word(d, where + PCI_HT_PRI_LCNF0);
607 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";
609 fmt = "\t\tLink Config 0: MLWI=%s MLWO=%s LWI=%s LWO=%s\n";
611 ht_link_width(lcnf0 & PCI_HT_LCNF_MLWI),
612 ht_link_width((lcnf0 & PCI_HT_LCNF_MLWO) >> 4),
613 ht_link_width((lcnf0 & PCI_HT_LCNF_LWI) >> 8),
614 ht_link_width((lcnf0 & PCI_HT_LCNF_LWO) >> 12),
615 FLAG(lcnf0, PCI_HT_LCNF_DFI),
616 FLAG(lcnf0, PCI_HT_LCNF_DFO),
617 FLAG(lcnf0, PCI_HT_LCNF_DFIE),
618 FLAG(lcnf0, PCI_HT_LCNF_DFOE));
619 lctr1 = get_conf_word(d, where + PCI_HT_PRI_LCTR1);
621 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";
623 fmt = "\t\tLink Control 1: CFlE%c CST%c CFE%c <LkFail%c Init%c EOC%c TXO%c <CRCErr=%x\n";
625 FLAG(lctr1, PCI_HT_LCTR_CFLE),
626 FLAG(lctr1, PCI_HT_LCTR_CST),
627 FLAG(lctr1, PCI_HT_LCTR_CFE),
628 FLAG(lctr1, PCI_HT_LCTR_LKFAIL),
629 FLAG(lctr1, PCI_HT_LCTR_INIT),
630 FLAG(lctr1, PCI_HT_LCTR_EOC),
631 FLAG(lctr1, PCI_HT_LCTR_TXO),
632 (lctr1 & PCI_HT_LCTR_CRCERR) >> 8,
633 FLAG(lctr1, PCI_HT_LCTR_ISOCEN),
634 FLAG(lctr1, PCI_HT_LCTR_LSEN),
635 FLAG(lctr1, PCI_HT_LCTR_EXTCTL),
636 FLAG(lctr1, PCI_HT_LCTR_64B));
637 lcnf1 = get_conf_word(d, where + PCI_HT_PRI_LCNF1);
639 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";
641 fmt = "\t\tLink Config 1: MLWI=%s MLWO=%s LWI=%s LWO=%s\n";
643 ht_link_width(lcnf1 & PCI_HT_LCNF_MLWI),
644 ht_link_width((lcnf1 & PCI_HT_LCNF_MLWO) >> 4),
645 ht_link_width((lcnf1 & PCI_HT_LCNF_LWI) >> 8),
646 ht_link_width((lcnf1 & PCI_HT_LCNF_LWO) >> 12),
647 FLAG(lcnf1, PCI_HT_LCNF_DFI),
648 FLAG(lcnf1, PCI_HT_LCNF_DFO),
649 FLAG(lcnf1, PCI_HT_LCNF_DFIE),
650 FLAG(lcnf1, PCI_HT_LCNF_DFOE));
651 printf("\t\tRevision ID: %u.%02u\n",
652 (rid & PCI_HT_RID_MAJ) >> 5, (rid & PCI_HT_RID_MIN));
655 lfrer0 = get_conf_byte(d, where + PCI_HT_PRI_LFRER0);
656 printf("\t\tLink Frequency 0: %s\n", ht_link_freq(lfrer0 & PCI_HT_LFRER_FREQ));
657 printf("\t\tLink Error 0: <Prot%c <Ovfl%c <EOC%c CTLTm%c\n",
658 FLAG(lfrer0, PCI_HT_LFRER_PROT),
659 FLAG(lfrer0, PCI_HT_LFRER_OV),
660 FLAG(lfrer0, PCI_HT_LFRER_EOC),
661 FLAG(lfrer0, PCI_HT_LFRER_CTLT));
662 lfcap0 = get_conf_byte(d, where + PCI_HT_PRI_LFCAP0);
663 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",
664 FLAG(lfcap0, PCI_HT_LFCAP_200),
665 FLAG(lfcap0, PCI_HT_LFCAP_300),
666 FLAG(lfcap0, PCI_HT_LFCAP_400),
667 FLAG(lfcap0, PCI_HT_LFCAP_500),
668 FLAG(lfcap0, PCI_HT_LFCAP_600),
669 FLAG(lfcap0, PCI_HT_LFCAP_800),
670 FLAG(lfcap0, PCI_HT_LFCAP_1000),
671 FLAG(lfcap0, PCI_HT_LFCAP_1200),
672 FLAG(lfcap0, PCI_HT_LFCAP_1400),
673 FLAG(lfcap0, PCI_HT_LFCAP_1600),
674 FLAG(lfcap0, PCI_HT_LFCAP_VEND));
675 ftr = get_conf_byte(d, where + PCI_HT_PRI_FTR);
676 printf("\t\tFeature Capability: IsocFC%c LDTSTOP%c CRCTM%c ECTLT%c 64bA%c UIDRD%c\n",
677 FLAG(ftr, PCI_HT_FTR_ISOCFC),
678 FLAG(ftr, PCI_HT_FTR_LDTSTOP),
679 FLAG(ftr, PCI_HT_FTR_CRCTM),
680 FLAG(ftr, PCI_HT_FTR_ECTLT),
681 FLAG(ftr, PCI_HT_FTR_64BA),
682 FLAG(ftr, PCI_HT_FTR_UIDRD));
683 lfrer1 = get_conf_byte(d, where + PCI_HT_PRI_LFRER1);
684 printf("\t\tLink Frequency 1: %s\n", ht_link_freq(lfrer1 & PCI_HT_LFRER_FREQ));
685 printf("\t\tLink Error 1: <Prot%c <Ovfl%c <EOC%c CTLTm%c\n",
686 FLAG(lfrer1, PCI_HT_LFRER_PROT),
687 FLAG(lfrer1, PCI_HT_LFRER_OV),
688 FLAG(lfrer1, PCI_HT_LFRER_EOC),
689 FLAG(lfrer1, PCI_HT_LFRER_CTLT));
690 lfcap1 = get_conf_byte(d, where + PCI_HT_PRI_LFCAP1);
691 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",
692 FLAG(lfcap1, PCI_HT_LFCAP_200),
693 FLAG(lfcap1, PCI_HT_LFCAP_300),
694 FLAG(lfcap1, PCI_HT_LFCAP_400),
695 FLAG(lfcap1, PCI_HT_LFCAP_500),
696 FLAG(lfcap1, PCI_HT_LFCAP_600),
697 FLAG(lfcap1, PCI_HT_LFCAP_800),
698 FLAG(lfcap1, PCI_HT_LFCAP_1000),
699 FLAG(lfcap1, PCI_HT_LFCAP_1200),
700 FLAG(lfcap1, PCI_HT_LFCAP_1400),
701 FLAG(lfcap1, PCI_HT_LFCAP_1600),
702 FLAG(lfcap1, PCI_HT_LFCAP_VEND));
703 eh = get_conf_word(d, where + PCI_HT_PRI_EH);
704 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",
705 FLAG(eh, PCI_HT_EH_PFLE),
706 FLAG(eh, PCI_HT_EH_OFLE),
707 FLAG(eh, PCI_HT_EH_PFE),
708 FLAG(eh, PCI_HT_EH_OFE),
709 FLAG(eh, PCI_HT_EH_EOCFE),
710 FLAG(eh, PCI_HT_EH_RFE),
711 FLAG(eh, PCI_HT_EH_CRCFE),
712 FLAG(eh, PCI_HT_EH_SERRFE),
713 FLAG(eh, PCI_HT_EH_CF),
714 FLAG(eh, PCI_HT_EH_RE),
715 FLAG(eh, PCI_HT_EH_PNFE),
716 FLAG(eh, PCI_HT_EH_ONFE),
717 FLAG(eh, PCI_HT_EH_EOCNFE),
718 FLAG(eh, PCI_HT_EH_RNFE),
719 FLAG(eh, PCI_HT_EH_CRCNFE),
720 FLAG(eh, PCI_HT_EH_SERRNFE));
721 mbu = get_conf_byte(d, where + PCI_HT_PRI_MBU);
722 mlu = get_conf_byte(d, where + PCI_HT_PRI_MLU);
723 printf("\t\tPrefetchable memory behind bridge Upper: %02x-%02x\n", mbu, mlu);
724 bn = get_conf_byte(d, where + PCI_HT_PRI_BN);
725 printf("\t\tBus Number: %02x\n", bn);
729 cap_ht_sec(struct device *d, int where, int cmd)
731 u16 lctr, lcnf, ftr, eh;
732 u8 rid, lfrer, lfcap, mbu, mlu;
735 printf("HyperTransport: Host or Secondary Interface\n");
739 if (!config_fetch(d, where + PCI_HT_SEC_LCTR, PCI_HT_SEC_SIZEOF - PCI_HT_SEC_LCTR))
741 rid = get_conf_byte(d, where + PCI_HT_SEC_RID);
742 if (rid < 0x23 && rid > 0x11)
743 printf("\t\t!!! Possibly incomplete decoding\n");
746 fmt = "\t\tCommand: WarmRst%c DblEnd%c DevNum=%u ChainSide%c HostHide%c Slave%c <EOCErr%c DUL%c\n";
748 fmt = "\t\tCommand: WarmRst%c DblEnd%c\n";
750 FLAG(cmd, PCI_HT_SEC_CMD_WR),
751 FLAG(cmd, PCI_HT_SEC_CMD_DE),
752 (cmd & PCI_HT_SEC_CMD_DN) >> 2,
753 FLAG(cmd, PCI_HT_SEC_CMD_CS),
754 FLAG(cmd, PCI_HT_SEC_CMD_HH),
755 FLAG(cmd, PCI_HT_SEC_CMD_AS),
756 FLAG(cmd, PCI_HT_SEC_CMD_HIECE),
757 FLAG(cmd, PCI_HT_SEC_CMD_DUL));
758 lctr = get_conf_word(d, where + PCI_HT_SEC_LCTR);
760 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";
762 fmt = "\t\tLink Control: CFlE%c CST%c CFE%c <LkFail%c Init%c EOC%c TXO%c <CRCErr=%x\n";
764 FLAG(lctr, PCI_HT_LCTR_CFLE),
765 FLAG(lctr, PCI_HT_LCTR_CST),
766 FLAG(lctr, PCI_HT_LCTR_CFE),
767 FLAG(lctr, PCI_HT_LCTR_LKFAIL),
768 FLAG(lctr, PCI_HT_LCTR_INIT),
769 FLAG(lctr, PCI_HT_LCTR_EOC),
770 FLAG(lctr, PCI_HT_LCTR_TXO),
771 (lctr & PCI_HT_LCTR_CRCERR) >> 8,
772 FLAG(lctr, PCI_HT_LCTR_ISOCEN),
773 FLAG(lctr, PCI_HT_LCTR_LSEN),
774 FLAG(lctr, PCI_HT_LCTR_EXTCTL),
775 FLAG(lctr, PCI_HT_LCTR_64B));
776 lcnf = get_conf_word(d, where + PCI_HT_SEC_LCNF);
778 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";
780 fmt = "\t\tLink Config: MLWI=%s MLWO=%s LWI=%s LWO=%s\n";
782 ht_link_width(lcnf & PCI_HT_LCNF_MLWI),
783 ht_link_width((lcnf & PCI_HT_LCNF_MLWO) >> 4),
784 ht_link_width((lcnf & PCI_HT_LCNF_LWI) >> 8),
785 ht_link_width((lcnf & PCI_HT_LCNF_LWO) >> 12),
786 FLAG(lcnf, PCI_HT_LCNF_DFI),
787 FLAG(lcnf, PCI_HT_LCNF_DFO),
788 FLAG(lcnf, PCI_HT_LCNF_DFIE),
789 FLAG(lcnf, PCI_HT_LCNF_DFOE));
790 printf("\t\tRevision ID: %u.%02u\n",
791 (rid & PCI_HT_RID_MAJ) >> 5, (rid & PCI_HT_RID_MIN));
794 lfrer = get_conf_byte(d, where + PCI_HT_SEC_LFRER);
795 printf("\t\tLink Frequency: %s\n", ht_link_freq(lfrer & PCI_HT_LFRER_FREQ));
796 printf("\t\tLink Error: <Prot%c <Ovfl%c <EOC%c CTLTm%c\n",
797 FLAG(lfrer, PCI_HT_LFRER_PROT),
798 FLAG(lfrer, PCI_HT_LFRER_OV),
799 FLAG(lfrer, PCI_HT_LFRER_EOC),
800 FLAG(lfrer, PCI_HT_LFRER_CTLT));
801 lfcap = get_conf_byte(d, where + PCI_HT_SEC_LFCAP);
802 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",
803 FLAG(lfcap, PCI_HT_LFCAP_200),
804 FLAG(lfcap, PCI_HT_LFCAP_300),
805 FLAG(lfcap, PCI_HT_LFCAP_400),
806 FLAG(lfcap, PCI_HT_LFCAP_500),
807 FLAG(lfcap, PCI_HT_LFCAP_600),
808 FLAG(lfcap, PCI_HT_LFCAP_800),
809 FLAG(lfcap, PCI_HT_LFCAP_1000),
810 FLAG(lfcap, PCI_HT_LFCAP_1200),
811 FLAG(lfcap, PCI_HT_LFCAP_1400),
812 FLAG(lfcap, PCI_HT_LFCAP_1600),
813 FLAG(lfcap, PCI_HT_LFCAP_VEND));
814 ftr = get_conf_word(d, where + PCI_HT_SEC_FTR);
815 printf("\t\tFeature Capability: IsocFC%c LDTSTOP%c CRCTM%c ECTLT%c 64bA%c UIDRD%c ExtRS%c UCnfE%c\n",
816 FLAG(ftr, PCI_HT_FTR_ISOCFC),
817 FLAG(ftr, PCI_HT_FTR_LDTSTOP),
818 FLAG(ftr, PCI_HT_FTR_CRCTM),
819 FLAG(ftr, PCI_HT_FTR_ECTLT),
820 FLAG(ftr, PCI_HT_FTR_64BA),
821 FLAG(ftr, PCI_HT_FTR_UIDRD),
822 FLAG(ftr, PCI_HT_SEC_FTR_EXTRS),
823 FLAG(ftr, PCI_HT_SEC_FTR_UCNFE));
824 if (ftr & PCI_HT_SEC_FTR_EXTRS)
826 eh = get_conf_word(d, where + PCI_HT_SEC_EH);
827 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",
828 FLAG(eh, PCI_HT_EH_PFLE),
829 FLAG(eh, PCI_HT_EH_OFLE),
830 FLAG(eh, PCI_HT_EH_PFE),
831 FLAG(eh, PCI_HT_EH_OFE),
832 FLAG(eh, PCI_HT_EH_EOCFE),
833 FLAG(eh, PCI_HT_EH_RFE),
834 FLAG(eh, PCI_HT_EH_CRCFE),
835 FLAG(eh, PCI_HT_EH_SERRFE),
836 FLAG(eh, PCI_HT_EH_CF),
837 FLAG(eh, PCI_HT_EH_RE),
838 FLAG(eh, PCI_HT_EH_PNFE),
839 FLAG(eh, PCI_HT_EH_ONFE),
840 FLAG(eh, PCI_HT_EH_EOCNFE),
841 FLAG(eh, PCI_HT_EH_RNFE),
842 FLAG(eh, PCI_HT_EH_CRCNFE),
843 FLAG(eh, PCI_HT_EH_SERRNFE));
844 mbu = get_conf_byte(d, where + PCI_HT_SEC_MBU);
845 mlu = get_conf_byte(d, where + PCI_HT_SEC_MLU);
846 printf("\t\tPrefetchable memory behind bridge Upper: %02x-%02x\n", mbu, mlu);
851 cap_ht(struct device *d, int where, int cmd)
855 switch (cmd & PCI_HT_CMD_TYP_HI)
857 case PCI_HT_CMD_TYP_HI_PRI:
858 cap_ht_pri(d, where, cmd);
860 case PCI_HT_CMD_TYP_HI_SEC:
861 cap_ht_sec(d, where, cmd);
865 type = cmd & PCI_HT_CMD_TYP;
868 case PCI_HT_CMD_TYP_SW:
869 printf("HyperTransport: Switch\n");
871 case PCI_HT_CMD_TYP_IDC:
872 printf("HyperTransport: Interrupt Discovery and Configuration\n");
874 case PCI_HT_CMD_TYP_RID:
875 printf("HyperTransport: Revision ID: %u.%02u\n",
876 (cmd & PCI_HT_RID_MAJ) >> 5, (cmd & PCI_HT_RID_MIN));
878 case PCI_HT_CMD_TYP_UIDC:
879 printf("HyperTransport: UnitID Clumping\n");
881 case PCI_HT_CMD_TYP_ECSA:
882 printf("HyperTransport: Extended Configuration Space Access\n");
884 case PCI_HT_CMD_TYP_AM:
885 printf("HyperTransport: Address Mapping\n");
887 case PCI_HT_CMD_TYP_MSIM:
888 printf("HyperTransport: MSI Mapping Enable%c Fixed%c\n",
889 FLAG(cmd, PCI_HT_MSIM_CMD_EN),
890 FLAG(cmd, PCI_HT_MSIM_CMD_FIXD));
891 if (verbose >= 2 && !(cmd & PCI_HT_MSIM_CMD_FIXD))
894 if (!config_fetch(d, where + PCI_HT_MSIM_ADDR_LO, 8))
896 offl = get_conf_long(d, where + PCI_HT_MSIM_ADDR_LO);
897 offh = get_conf_long(d, where + PCI_HT_MSIM_ADDR_HI);
898 printf("\t\tMapping Address Base: %016llx\n", ((unsigned long long)offh << 32) | (offl & ~0xfffff));
901 case PCI_HT_CMD_TYP_DR:
902 printf("HyperTransport: DirectRoute\n");
904 case PCI_HT_CMD_TYP_VCS:
905 printf("HyperTransport: VCSet\n");
907 case PCI_HT_CMD_TYP_RM:
908 printf("HyperTransport: Retry Mode\n");
910 case PCI_HT_CMD_TYP_X86:
911 printf("HyperTransport: X86 (reserved)\n");
914 printf("HyperTransport: #%02x\n", type >> 11);
919 cap_msi(struct device *d, int where, int cap)
925 printf("Message Signalled Interrupts: Mask%c 64bit%c Queue=%d/%d Enable%c\n",
926 FLAG(cap, PCI_MSI_FLAGS_MASK_BIT),
927 FLAG(cap, PCI_MSI_FLAGS_64BIT),
928 (cap & PCI_MSI_FLAGS_QSIZE) >> 4,
929 (cap & PCI_MSI_FLAGS_QMASK) >> 1,
930 FLAG(cap, PCI_MSI_FLAGS_ENABLE));
933 is64 = cap & PCI_MSI_FLAGS_64BIT;
934 if (!config_fetch(d, where + PCI_MSI_ADDRESS_LO, (is64 ? PCI_MSI_DATA_64 : PCI_MSI_DATA_32) + 2 - PCI_MSI_ADDRESS_LO))
936 printf("\t\tAddress: ");
939 t = get_conf_long(d, where + PCI_MSI_ADDRESS_HI);
940 w = get_conf_word(d, where + PCI_MSI_DATA_64);
944 w = get_conf_word(d, where + PCI_MSI_DATA_32);
945 t = get_conf_long(d, where + PCI_MSI_ADDRESS_LO);
946 printf("%08x Data: %04x\n", t, w);
947 if (cap & PCI_MSI_FLAGS_MASK_BIT)
953 if (!config_fetch(d, where + PCI_MSI_MASK_BIT_64, 8))
955 mask = get_conf_long(d, where + PCI_MSI_MASK_BIT_64);
956 pending = get_conf_long(d, where + PCI_MSI_PENDING_64);
960 if (!config_fetch(d, where + PCI_MSI_MASK_BIT_32, 8))
962 mask = get_conf_long(d, where + PCI_MSI_MASK_BIT_32);
963 pending = get_conf_long(d, where + PCI_MSI_PENDING_32);
965 printf("\t\tMasking: %08x Pending: %08x\n", mask, pending);
969 static float power_limit(int value, int scale)
971 static const float scales[4] = { 1.0, 0.1, 0.01, 0.001 };
972 return value * scales[scale];
975 static const char *latency_l0s(int value)
977 static const char *latencies[] = { "<64ns", "<128ns", "<256ns", "<512ns", "<1us", "<2us", "<4us", "unlimited" };
978 return latencies[value];
981 static const char *latency_l1(int value)
983 static const char *latencies[] = { "<1us", "<2us", "<4us", "<8us", "<16us", "<32us", "<64us", "unlimited" };
984 return latencies[value];
987 static void cap_express_dev(struct device *d, int where, int type)
992 t = get_conf_long(d, where + PCI_EXP_DEVCAP);
993 printf("\t\tDevCap:\tMaxPayload %d bytes, PhantFunc %d, Latency L0s %s, L1 %s\n",
994 128 << (t & PCI_EXP_DEVCAP_PAYLOAD),
995 (1 << ((t & PCI_EXP_DEVCAP_PHANTOM) >> 3)) - 1,
996 latency_l0s((t & PCI_EXP_DEVCAP_L0S) >> 6),
997 latency_l1((t & PCI_EXP_DEVCAP_L1) >> 9));
998 printf("\t\t\tExtTag%c", FLAG(t, PCI_EXP_DEVCAP_EXT_TAG));
999 if ((type == PCI_EXP_TYPE_ENDPOINT) || (type == PCI_EXP_TYPE_LEG_END) ||
1000 (type == PCI_EXP_TYPE_UPSTREAM) || (type == PCI_EXP_TYPE_PCI_BRIDGE))
1001 printf(" AttnBtn%c AttnInd%c PwrInd%c",
1002 FLAG(t, PCI_EXP_DEVCAP_ATN_BUT),
1003 FLAG(t, PCI_EXP_DEVCAP_ATN_IND), FLAG(t, PCI_EXP_DEVCAP_PWR_IND));
1004 printf(" RBE%c FLReset%c",
1005 FLAG(t, PCI_EXP_DEVCAP_RBE),
1006 FLAG(t, PCI_EXP_DEVCAP_FLRESET));
1007 if (type == PCI_EXP_TYPE_UPSTREAM)
1008 printf("SlotPowerLimit %fW",
1009 power_limit((t & PCI_EXP_DEVCAP_PWR_VAL) >> 18,
1010 (t & PCI_EXP_DEVCAP_PWR_SCL) >> 26));
1013 w = get_conf_word(d, where + PCI_EXP_DEVCTL);
1014 printf("\t\tDevCtl:\tReport errors: Correctable%c Non-Fatal%c Fatal%c Unsupported%c\n",
1015 FLAG(w, PCI_EXP_DEVCTL_CERE),
1016 FLAG(w, PCI_EXP_DEVCTL_NFERE),
1017 FLAG(w, PCI_EXP_DEVCTL_FERE),
1018 FLAG(w, PCI_EXP_DEVCTL_URRE));
1019 printf("\t\t\tRlxdOrd%c ExtTag%c PhantFunc%c AuxPwr%c NoSnoop%c",
1020 FLAG(w, PCI_EXP_DEVCTL_RELAXED),
1021 FLAG(w, PCI_EXP_DEVCTL_EXT_TAG),
1022 FLAG(w, PCI_EXP_DEVCTL_PHANTOM),
1023 FLAG(w, PCI_EXP_DEVCTL_AUX_PME),
1024 FLAG(w, PCI_EXP_DEVCTL_NOSNOOP));
1025 if (type == PCI_EXP_TYPE_PCI_BRIDGE || type == PCI_EXP_TYPE_PCIE_BRIDGE)
1026 printf(" BrConfRtry%c", FLAG(w, PCI_EXP_DEVCTL_BCRE));
1027 if (type == PCI_EXP_TYPE_ENDPOINT && (t & PCI_EXP_DEVCAP_FLRESET))
1028 printf(" FLReset%c", FLAG(w, PCI_EXP_DEVCTL_FLRESET));
1029 printf("\n\t\t\tMaxPayload %d bytes, MaxReadReq %d bytes\n",
1030 128 << ((w & PCI_EXP_DEVCTL_PAYLOAD) >> 5),
1031 128 << ((w & PCI_EXP_DEVCTL_READRQ) >> 12));
1033 w = get_conf_word(d, where + PCI_EXP_DEVSTA);
1034 printf("\t\tDevSta:\tCorrErr%c UncorrErr%c FatalErr%c UnsuppReq%c AuxPwr%c TransPend%c\n",
1035 FLAG(w, PCI_EXP_DEVSTA_CED),
1036 FLAG(w, PCI_EXP_DEVSTA_NFED),
1037 FLAG(w, PCI_EXP_DEVSTA_FED),
1038 FLAG(w, PCI_EXP_DEVSTA_URD),
1039 FLAG(w, PCI_EXP_DEVSTA_AUXPD),
1040 FLAG(w, PCI_EXP_DEVSTA_TRPND));
1042 /* FIXME: Second set of control/status registers is not supported yet. */
1045 static char *link_speed(int speed)
1058 static char *aspm_support(int code)
1071 static const char *aspm_enabled(int code)
1073 static const char *desc[] = { "Disabled", "L0s Enabled", "L1 Enabled", "L0s L1 Enabled" };
1077 static void cap_express_link(struct device *d, int where, int type)
1082 t = get_conf_long(d, where + PCI_EXP_LNKCAP);
1083 printf("\t\tLnkCap:\tPort #%d, Speed %s, Width x%d, ASPM %s, Latency L0 %s, L1 %s\n",
1085 link_speed(t & PCI_EXP_LNKCAP_SPEED), (t & PCI_EXP_LNKCAP_WIDTH) >> 4,
1086 aspm_support((t & PCI_EXP_LNKCAP_ASPM) >> 10),
1087 latency_l0s((t & PCI_EXP_LNKCAP_L0S) >> 12),
1088 latency_l1((t & PCI_EXP_LNKCAP_L1) >> 15));
1089 printf("\t\t\tClockPM%c Suprise%c LLActRep%c BwNot%c\n",
1090 FLAG(t, PCI_EXP_LNKCAP_CLOCKPM),
1091 FLAG(t, PCI_EXP_LNKCAP_SURPRISE),
1092 FLAG(t, PCI_EXP_LNKCAP_DLLA),
1093 FLAG(t, PCI_EXP_LNKCAP_LBNC));
1095 w = get_conf_word(d, where + PCI_EXP_LNKCTL);
1096 printf("\t\tLnkCtl:\tASPM %s;", aspm_enabled(w & PCI_EXP_LNKCTL_ASPM));
1097 if ((type == PCI_EXP_TYPE_ROOT_PORT) || (type == PCI_EXP_TYPE_ENDPOINT) ||
1098 (type == PCI_EXP_TYPE_LEG_END))
1099 printf(" RCB %d bytes", w & PCI_EXP_LNKCTL_RCB ? 128 : 64);
1100 printf(" Disabled%c Retrain%c CommClk%c\n\t\t\tExtSynch%c ClockPM%c AutWidDis%c BWInt%c AutBWInt%c\n",
1101 FLAG(w, PCI_EXP_LNKCTL_DISABLE),
1102 FLAG(w, PCI_EXP_LNKCTL_RETRAIN),
1103 FLAG(w, PCI_EXP_LNKCTL_CLOCK),
1104 FLAG(w, PCI_EXP_LNKCTL_XSYNCH),
1105 FLAG(w, PCI_EXP_LNKCTL_CLOCKPM),
1106 FLAG(w, PCI_EXP_LNKCTL_HWAUTWD),
1107 FLAG(w, PCI_EXP_LNKCTL_BWMIE),
1108 FLAG(w, PCI_EXP_LNKCTL_AUTBWIE));
1110 w = get_conf_word(d, where + PCI_EXP_LNKSTA);
1111 printf("\t\tLnkSta:\tSpeed %s, Width x%d, TrErr%c Train%c SlotClk%c DLActive%c BWMgmt%c ABWMgmt%c\n",
1112 link_speed(w & PCI_EXP_LNKSTA_SPEED),
1113 (w & PCI_EXP_LNKSTA_WIDTH) >> 4,
1114 FLAG(w, PCI_EXP_LNKSTA_TR_ERR),
1115 FLAG(w, PCI_EXP_LNKSTA_TRAIN),
1116 FLAG(w, PCI_EXP_LNKSTA_SL_CLK),
1117 FLAG(w, PCI_EXP_LNKSTA_DL_ACT),
1118 FLAG(w, PCI_EXP_LNKSTA_BWMGMT),
1119 FLAG(w, PCI_EXP_LNKSTA_AUTBW));
1122 static const char *indicator(int code)
1124 static const char *names[] = { "Unknown", "On", "Blink", "Off" };
1128 static void cap_express_slot(struct device *d, int where)
1133 t = get_conf_long(d, where + PCI_EXP_SLTCAP);
1134 printf("\t\tSltCap:\tAttnBtn%c PwrCtrl%c MRL%c AttnInd%c PwrInd%c HotPlug%c Surpise%c\n",
1135 FLAG(t, PCI_EXP_SLTCAP_ATNB),
1136 FLAG(t, PCI_EXP_SLTCAP_PWRC),
1137 FLAG(t, PCI_EXP_SLTCAP_MRL),
1138 FLAG(t, PCI_EXP_SLTCAP_ATNI),
1139 FLAG(t, PCI_EXP_SLTCAP_PWRI),
1140 FLAG(t, PCI_EXP_SLTCAP_HPC),
1141 FLAG(t, PCI_EXP_SLTCAP_HPS));
1142 printf("\t\t\tSlot #%3x, PowerLimit %f; Interlock%c NoCompl%c\n",
1144 power_limit((t & PCI_EXP_SLTCAP_PWR_VAL) >> 7, (t & PCI_EXP_SLTCAP_PWR_SCL) >> 15),
1145 FLAG(t, PCI_EXP_SLTCAP_INTERLOCK),
1146 FLAG(t, PCI_EXP_SLTCAP_NOCMDCOMP));
1148 w = get_conf_word(d, where + PCI_EXP_SLTCTL);
1149 printf("\t\tSltCtl:\tEnable: AttnBtn%c PwrFlt%c MRL%c PresDet%c CmdCplt%c HPIrq%c LinkChg%c\n",
1150 FLAG(w, PCI_EXP_SLTCTL_ATNB),
1151 FLAG(w, PCI_EXP_SLTCTL_PWRF),
1152 FLAG(w, PCI_EXP_SLTCTL_MRLS),
1153 FLAG(w, PCI_EXP_SLTCTL_PRSD),
1154 FLAG(w, PCI_EXP_SLTCTL_CMDC),
1155 FLAG(w, PCI_EXP_SLTCTL_HPIE),
1156 FLAG(w, PCI_EXP_SLTCTL_LLCHG));
1157 printf("\t\t\tControl: AttnInd %s, PwrInd %s, Power%c Interlock%c\n",
1158 indicator((w & PCI_EXP_SLTCTL_ATNI) >> 6),
1159 indicator((w & PCI_EXP_SLTCTL_PWRI) >> 8),
1160 FLAG(w, PCI_EXP_SLTCTL_PWRC),
1161 FLAG(w, PCI_EXP_SLTCTL_INTERLOCK));
1163 w = get_conf_word(d, where + PCI_EXP_SLTSTA);
1164 printf("\t\tSltSta:\tStatus: AttnBtn%c PowerFlt%c MRL%c CmdCplt%c PresDet%c Interlock%c\n",
1165 FLAG(w, PCI_EXP_SLTSTA_ATNB),
1166 FLAG(w, PCI_EXP_SLTSTA_PWRF),
1167 FLAG(w, PCI_EXP_SLTSTA_MRL_ST),
1168 FLAG(w, PCI_EXP_SLTSTA_CMDC),
1169 FLAG(w, PCI_EXP_SLTSTA_PRES),
1170 FLAG(w, PCI_EXP_SLTSTA_INTERLOCK));
1171 printf("\t\t\tChanged: MRL%c PresDet%c LinkState%c\n",
1172 FLAG(w, PCI_EXP_SLTSTA_MRLS),
1173 FLAG(w, PCI_EXP_SLTSTA_PRSD),
1174 FLAG(w, PCI_EXP_SLTSTA_LLCHG));
1177 static void cap_express_root(struct device *d, int where)
1179 u32 w = get_conf_word(d, where + PCI_EXP_RTCTL);
1180 printf("\t\tRootCtl: ErrCorrectable%c ErrNon-Fatal%c ErrFatal%c PMEIntEna%c CRSVisible%c\n",
1181 FLAG(w, PCI_EXP_RTCTL_SECEE),
1182 FLAG(w, PCI_EXP_RTCTL_SENFEE),
1183 FLAG(w, PCI_EXP_RTCTL_SEFEE),
1184 FLAG(w, PCI_EXP_RTCTL_PMEIE),
1185 FLAG(w, PCI_EXP_RTCTL_CRSVIS));
1187 w = get_conf_word(d, where + PCI_EXP_RTCAP);
1188 printf("\t\tRootCap: CRSVisible%c\n",
1189 FLAG(w, PCI_EXP_RTCAP_CRSVIS));
1191 w = get_conf_word(d, where + PCI_EXP_RTSTA);
1192 printf("\t\tRootSta: PME ReqID %04x, PMEStatus%c PMEPending%c\n",
1193 w & PCI_EXP_RTSTA_PME_REQID,
1194 FLAG(w, PCI_EXP_RTSTA_PME_STATUS),
1195 FLAG(w, PCI_EXP_RTSTA_PME_PENDING));
1199 cap_express(struct device *d, int where, int cap)
1201 int type = (cap & PCI_EXP_FLAGS_TYPE) >> 4;
1207 printf("(v%d) ", cap & PCI_EXP_FLAGS_VERS);
1210 case PCI_EXP_TYPE_ENDPOINT:
1213 case PCI_EXP_TYPE_LEG_END:
1214 printf("Legacy Endpoint");
1216 case PCI_EXP_TYPE_ROOT_PORT:
1217 slot = cap & PCI_EXP_FLAGS_SLOT;
1218 printf("Root Port (Slot%c)", FLAG(cap, PCI_EXP_FLAGS_SLOT));
1220 case PCI_EXP_TYPE_UPSTREAM:
1221 printf("Upstream Port");
1223 case PCI_EXP_TYPE_DOWNSTREAM:
1224 slot = cap & PCI_EXP_FLAGS_SLOT;
1225 printf("Downstream Port (Slot%c)", FLAG(cap, PCI_EXP_FLAGS_SLOT));
1227 case PCI_EXP_TYPE_PCI_BRIDGE:
1228 printf("PCI/PCI-X Bridge");
1230 case PCI_EXP_TYPE_PCIE_BRIDGE:
1231 printf("PCI/PCI-X to PCI-Express Bridge");
1233 case PCI_EXP_TYPE_ROOT_INT_EP:
1234 printf("Root Complex Integrated Endpoint");
1236 case PCI_EXP_TYPE_ROOT_EC:
1237 printf("Root Complex Event Collector");
1240 printf("Unknown type %d", type);
1242 printf(", MSI %02x\n", (cap & PCI_EXP_FLAGS_IRQ) >> 9);
1249 if (type == PCI_EXP_TYPE_ROOT_PORT)
1251 if (!config_fetch(d, where + PCI_EXP_DEVCAP, size))
1254 cap_express_dev(d, where, type);
1255 cap_express_link(d, where, type);
1257 cap_express_slot(d, where);
1258 if (type == PCI_EXP_TYPE_ROOT_PORT)
1259 cap_express_root(d, where);
1263 cap_msix(struct device *d, int where, int cap)
1267 printf("MSI-X: Enable%c Mask%c TabSize=%d\n",
1268 FLAG(cap, PCI_MSIX_ENABLE),
1269 FLAG(cap, PCI_MSIX_MASK),
1270 (cap & PCI_MSIX_TABSIZE) + 1);
1271 if (verbose < 2 || !config_fetch(d, where + PCI_MSIX_TABLE, 8))
1274 off = get_conf_long(d, where + PCI_MSIX_TABLE);
1275 printf("\t\tVector table: BAR=%d offset=%08x\n",
1276 off & PCI_MSIX_BIR, off & ~PCI_MSIX_BIR);
1277 off = get_conf_long(d, where + PCI_MSIX_PBA);
1278 printf("\t\tPBA: BAR=%d offset=%08x\n",
1279 off & PCI_MSIX_BIR, off & ~PCI_MSIX_BIR);
1285 int esr = cap & 0xff;
1288 printf("Slot ID: %d slots, First%c, chassis %02x\n",
1289 esr & PCI_SID_ESR_NSLOTS,
1290 FLAG(esr, PCI_SID_ESR_FIC),
1295 cap_ssvid(struct device *d, int where)
1297 u16 subsys_v, subsys_d;
1298 char ssnamebuf[256];
1300 if (!config_fetch(d, where, 8))
1302 subsys_v = get_conf_word(d, where + PCI_SSVID_VENDOR);
1303 subsys_d = get_conf_word(d, where + PCI_SSVID_DEVICE);
1304 printf("Subsystem: %s\n",
1305 pci_lookup_name(pacc, ssnamebuf, sizeof(ssnamebuf),
1306 PCI_LOOKUP_SUBSYSTEM | PCI_LOOKUP_VENDOR | PCI_LOOKUP_DEVICE,
1307 d->dev->vendor_id, d->dev->device_id, subsys_v, subsys_d));
1311 cap_dsn(struct device *d, int where)
1314 if (!config_fetch(d, where + 4, 8))
1316 t1 = get_conf_long(d, where + 4);
1317 t2 = get_conf_long(d, where + 8);
1318 printf("Device Serial Number %02x-%02x-%02x-%02x-%02x-%02x-%02x-%02x\n",
1319 t1 & 0xff, (t1 >> 8) & 0xff, (t1 >> 16) & 0xff, t1 >> 24,
1320 t2 & 0xff, (t2 >> 8) & 0xff, (t2 >> 16) & 0xff, t2 >> 24);
1324 cap_debug_port(int cap)
1326 int bar = cap >> 13;
1327 int pos = cap & 0x1fff;
1328 printf("Debug port: BAR=%d offset=%04x\n", bar, pos);
1332 show_ext_caps(struct device *d)
1335 char been_there[0x1000];
1336 memset(been_there, 0, 0x1000);
1342 if (!config_fetch(d, where, 4))
1344 header = get_conf_long(d, where);
1347 id = header & 0xffff;
1348 printf("\tCapabilities: [%03x] ", where);
1349 if (been_there[where]++)
1351 printf("<chain looped>\n");
1356 case PCI_EXT_CAP_ID_AER:
1357 printf("Advanced Error Reporting <?>\n");
1359 case PCI_EXT_CAP_ID_VC:
1360 printf("Virtual Channel <?>\n");
1362 case PCI_EXT_CAP_ID_DSN:
1365 case PCI_EXT_CAP_ID_PB:
1366 printf("Power Budgeting <?>\n");
1368 case PCI_EXT_CAP_ID_RCLINK:
1369 printf("Root Complex Link <?>\n");
1371 case PCI_EXT_CAP_ID_RCILINK:
1372 printf("Root Complex Internal Link <?>\n");
1374 case PCI_EXT_CAP_ID_RCECOLL:
1375 printf("Root Complex Event Collector <?>\n");
1377 case PCI_EXT_CAP_ID_MFVC:
1378 printf("Multi-Function Virtual Channel <?>\n");
1380 case PCI_EXT_CAP_ID_RBCB:
1381 printf("Root Bridge Control Block <?>\n");
1383 case PCI_EXT_CAP_ID_VNDR:
1384 printf("Vendor Specific Information <?>\n");
1386 case PCI_EXT_CAP_ID_ACS:
1387 printf("Access Controls <?>\n");
1390 printf("#%02x\n", id);
1393 where = header >> 20;
1398 show_caps(struct device *d)
1400 int can_have_ext_caps = 0;
1402 if (get_conf_word(d, PCI_STATUS) & PCI_STATUS_CAP_LIST)
1404 int where = get_conf_byte(d, PCI_CAPABILITY_LIST) & ~3;
1405 byte been_there[256];
1406 memset(been_there, 0, 256);
1410 printf("\tCapabilities: ");
1411 if (!config_fetch(d, where, 4))
1413 puts("<access denied>");
1416 id = get_conf_byte(d, where + PCI_CAP_LIST_ID);
1417 next = get_conf_byte(d, where + PCI_CAP_LIST_NEXT) & ~3;
1418 cap = get_conf_word(d, where + PCI_CAP_FLAGS);
1419 printf("[%02x] ", where);
1420 if (been_there[where]++)
1422 printf("<chain looped>\n");
1427 printf("<chain broken>\n");
1433 cap_pm(d, where, cap);
1435 case PCI_CAP_ID_AGP:
1436 cap_agp(d, where, cap);
1438 case PCI_CAP_ID_VPD:
1439 printf("Vital Product Data <?>\n");
1441 case PCI_CAP_ID_SLOTID:
1444 case PCI_CAP_ID_MSI:
1445 cap_msi(d, where, cap);
1447 case PCI_CAP_ID_CHSWP:
1448 printf("CompactPCI hot-swap <?>\n");
1450 case PCI_CAP_ID_PCIX:
1452 can_have_ext_caps = 1;
1455 cap_ht(d, where, cap);
1457 case PCI_CAP_ID_VNDR:
1458 printf("Vendor Specific Information <?>\n");
1460 case PCI_CAP_ID_DBG:
1461 cap_debug_port(cap);
1463 case PCI_CAP_ID_CCRC:
1464 printf("CompactPCI central resource control <?>\n");
1466 case PCI_CAP_ID_HOTPLUG:
1467 printf("Hot-plug capable\n");
1469 case PCI_CAP_ID_SSVID:
1470 cap_ssvid(d, where);
1472 case PCI_CAP_ID_AGP3:
1473 printf("AGP3 <?>\n");
1475 case PCI_CAP_ID_SECURE:
1476 printf("Secure device <?>\n");
1478 case PCI_CAP_ID_EXP:
1479 cap_express(d, where, cap);
1480 can_have_ext_caps = 1;
1482 case PCI_CAP_ID_MSIX:
1483 cap_msix(d, where, cap);
1485 case PCI_CAP_ID_SATA:
1486 printf("SATA HBA <?>\n");
1489 printf("PCIe advanced features <?>\n");
1492 printf("#%02x [%04x]\n", id, cap);
1497 if (can_have_ext_caps)
1501 /*** Kernel drivers ***/
1505 #include <sys/utsname.h>
1507 struct pcimap_entry {
1508 struct pcimap_entry *next;
1509 unsigned int vendor, device;
1510 unsigned int subvendor, subdevice;
1511 unsigned int class, class_mask;
1515 static struct pcimap_entry *pcimap_head;
1520 static int tried_pcimap;
1522 char *name, line[1024];
1529 if (name = opt_pcimap)
1531 f = fopen(name, "r");
1533 die("Cannot open pcimap file %s: %m", name);
1537 if (uname(&uts) < 0)
1538 die("uname() failed: %m");
1539 name = alloca(64 + strlen(uts.release));
1540 sprintf(name, "/lib/modules/%s/modules.pcimap", uts.release);
1541 f = fopen(name, "r");
1546 while (fgets(line, sizeof(line), f))
1548 char *c = strchr(line, '\n');
1549 struct pcimap_entry *e;
1552 die("Unterminated or too long line in %s", name);
1554 if (!line[0] || line[0] == '#')
1558 while (*c && *c != ' ' && *c != '\t')
1561 continue; /* FIXME: Emit warnings! */
1564 e = xmalloc(sizeof(*e) + strlen(line));
1565 if (sscanf(c, "%i%i%i%i%i%i",
1566 &e->vendor, &e->device,
1567 &e->subvendor, &e->subdevice,
1568 &e->class, &e->class_mask) != 6)
1570 e->next = pcimap_head;
1572 strcpy(e->module, line);
1578 match_pcimap(struct device *d, struct pcimap_entry *e)
1580 struct pci_dev *dev = d->dev;
1581 unsigned int class = get_conf_long(d, PCI_REVISION_ID) >> 8;
1584 #define MATCH(x, y) ((y) > 0xffff || (x) == (y))
1585 get_subid(d, &subv, &subd);
1587 MATCH(dev->vendor_id, e->vendor) &&
1588 MATCH(dev->device_id, e->device) &&
1589 MATCH(subv, e->subvendor) &&
1590 MATCH(subd, e->subdevice) &&
1591 (class & e->class_mask) == e->class;
1595 #define DRIVER_BUF_SIZE 1024
1598 find_driver(struct device *d, char *buf)
1600 struct pci_dev *dev = d->dev;
1601 char name[1024], *drv, *base;
1604 if (dev->access->method != PCI_ACCESS_SYS_BUS_PCI)
1607 base = pci_get_param(dev->access, "sysfs.path");
1608 if (!base || !base[0])
1611 n = snprintf(name, sizeof(name), "%s/devices/%04x:%02x:%02x.%d/driver",
1612 base, dev->domain, dev->bus, dev->dev, dev->func);
1613 if (n < 0 || n >= (int)sizeof(name))
1614 die("show_driver: sysfs device name too long, why?");
1616 n = readlink(name, buf, DRIVER_BUF_SIZE);
1619 if (n >= DRIVER_BUF_SIZE)
1620 return "<name-too-long>";
1623 if (drv = strrchr(buf, '/'))
1630 show_kernel(struct device *d)
1632 char buf[DRIVER_BUF_SIZE];
1634 struct pcimap_entry *e, *last = NULL;
1636 if (driver = find_driver(d, buf))
1637 printf("\tKernel driver in use: %s\n", driver);
1640 for (e=pcimap_head; e; e=e->next)
1641 if (match_pcimap(d, e) && (!last || strcmp(last->module, e->module)))
1643 printf("%s %s", (last ? "," : "\tKernel modules:"), e->module);
1651 show_kernel_machine(struct device *d)
1653 char buf[DRIVER_BUF_SIZE];
1655 struct pcimap_entry *e, *last = NULL;
1657 if (driver = find_driver(d, buf))
1658 printf("Driver:\t%s\n", driver);
1661 for (e=pcimap_head; e; e=e->next)
1662 if (match_pcimap(d, e) && (!last || strcmp(last->module, e->module)))
1664 printf("Module:\t%s\n", e->module);
1672 show_kernel(struct device *d UNUSED)
1677 show_kernel_machine(struct device *d UNUSED)
1683 /*** Verbose output ***/
1686 show_size(pciaddr_t x)
1692 printf("%d", (int) x);
1693 else if (x < 1048576)
1694 printf("%dK", (int)(x / 1024));
1695 else if (x < 0x80000000)
1696 printf("%dM", (int)(x / 1048576));
1698 printf(PCIADDR_T_FMT, x);
1703 show_bases(struct device *d, int cnt)
1705 struct pci_dev *p = d->dev;
1706 word cmd = get_conf_word(d, PCI_COMMAND);
1709 for(i=0; i<cnt; i++)
1711 pciaddr_t pos = p->base_addr[i];
1712 pciaddr_t len = (p->known_fields & PCI_FILL_SIZES) ? p->size[i] : 0;
1713 u32 flg = get_conf_long(d, PCI_BASE_ADDRESS_0 + 4*i);
1714 if (flg == 0xffffffff)
1716 if (!pos && !flg && !len)
1719 printf("\tRegion %d: ", i);
1722 if (pos && !flg) /* Reported by the OS, but not by the device */
1724 printf("[virtual] ");
1727 if (flg & PCI_BASE_ADDRESS_SPACE_IO)
1729 pciaddr_t a = pos & PCI_BASE_ADDRESS_IO_MASK;
1730 printf("I/O ports at ");
1732 printf(PCIADDR_PORT_FMT, a);
1733 else if (flg & PCI_BASE_ADDRESS_IO_MASK)
1734 printf("<ignored>");
1736 printf("<unassigned>");
1737 if (!(cmd & PCI_COMMAND_IO))
1738 printf(" [disabled]");
1742 int t = flg & PCI_BASE_ADDRESS_MEM_TYPE_MASK;
1743 pciaddr_t a = pos & PCI_ADDR_MEM_MASK;
1747 printf("Memory at ");
1748 if (t == PCI_BASE_ADDRESS_MEM_TYPE_64)
1752 printf("<invalid-64bit-slot>");
1758 z = get_conf_long(d, PCI_BASE_ADDRESS_0 + 4*i);
1761 u32 y = a & 0xffffffff;
1763 printf("%08x%08x", z, y);
1765 printf("<unassigned>");
1773 printf(PCIADDR_T_FMT, a);
1775 printf(((flg & PCI_BASE_ADDRESS_MEM_MASK) || z) ? "<ignored>" : "<unassigned>");
1777 printf(" (%s, %sprefetchable)",
1778 (t == PCI_BASE_ADDRESS_MEM_TYPE_32) ? "32-bit" :
1779 (t == PCI_BASE_ADDRESS_MEM_TYPE_64) ? "64-bit" :
1780 (t == PCI_BASE_ADDRESS_MEM_TYPE_1M) ? "low-1M" : "type 3",
1781 (flg & PCI_BASE_ADDRESS_MEM_PREFETCH) ? "" : "non-");
1782 if (!(cmd & PCI_COMMAND_MEMORY))
1783 printf(" [disabled]");
1791 show_rom(struct device *d, int reg)
1793 struct pci_dev *p = d->dev;
1794 pciaddr_t rom = p->rom_base_addr;
1795 pciaddr_t len = (p->known_fields & PCI_FILL_SIZES) ? p->rom_size : 0;
1796 u32 flg = get_conf_long(d, reg);
1797 word cmd = get_conf_word(d, PCI_COMMAND);
1799 if (!rom && !flg && !len)
1802 if ((rom & PCI_ROM_ADDRESS_MASK) && !(flg & PCI_ROM_ADDRESS_MASK))
1804 printf("[virtual] ");
1807 printf("Expansion ROM at ");
1808 if (rom & PCI_ROM_ADDRESS_MASK)
1809 printf(PCIADDR_T_FMT, rom & PCI_ROM_ADDRESS_MASK);
1810 else if (flg & PCI_ROM_ADDRESS_MASK)
1811 printf("<ignored>");
1813 printf("<unassigned>");
1814 if (!(flg & PCI_ROM_ADDRESS_ENABLE))
1815 printf(" [disabled]");
1816 else if (!(cmd & PCI_COMMAND_MEMORY))
1817 printf(" [disabled by cmd]");
1823 show_htype0(struct device *d)
1826 show_rom(d, PCI_ROM_ADDRESS);
1831 show_htype1(struct device *d)
1833 u32 io_base = get_conf_byte(d, PCI_IO_BASE);
1834 u32 io_limit = get_conf_byte(d, PCI_IO_LIMIT);
1835 u32 io_type = io_base & PCI_IO_RANGE_TYPE_MASK;
1836 u32 mem_base = get_conf_word(d, PCI_MEMORY_BASE);
1837 u32 mem_limit = get_conf_word(d, PCI_MEMORY_LIMIT);
1838 u32 mem_type = mem_base & PCI_MEMORY_RANGE_TYPE_MASK;
1839 u32 pref_base = get_conf_word(d, PCI_PREF_MEMORY_BASE);
1840 u32 pref_limit = get_conf_word(d, PCI_PREF_MEMORY_LIMIT);
1841 u32 pref_type = pref_base & PCI_PREF_RANGE_TYPE_MASK;
1842 word sec_stat = get_conf_word(d, PCI_SEC_STATUS);
1843 word brc = get_conf_word(d, PCI_BRIDGE_CONTROL);
1844 int verb = verbose > 2;
1847 printf("\tBus: primary=%02x, secondary=%02x, subordinate=%02x, sec-latency=%d\n",
1848 get_conf_byte(d, PCI_PRIMARY_BUS),
1849 get_conf_byte(d, PCI_SECONDARY_BUS),
1850 get_conf_byte(d, PCI_SUBORDINATE_BUS),
1851 get_conf_byte(d, PCI_SEC_LATENCY_TIMER));
1853 if (io_type != (io_limit & PCI_IO_RANGE_TYPE_MASK) ||
1854 (io_type != PCI_IO_RANGE_TYPE_16 && io_type != PCI_IO_RANGE_TYPE_32))
1855 printf("\t!!! Unknown I/O range types %x/%x\n", io_base, io_limit);
1858 io_base = (io_base & PCI_IO_RANGE_MASK) << 8;
1859 io_limit = (io_limit & PCI_IO_RANGE_MASK) << 8;
1860 if (io_type == PCI_IO_RANGE_TYPE_32)
1862 io_base |= (get_conf_word(d, PCI_IO_BASE_UPPER16) << 16);
1863 io_limit |= (get_conf_word(d, PCI_IO_LIMIT_UPPER16) << 16);
1865 if (io_base <= io_limit || verb)
1866 printf("\tI/O behind bridge: %08x-%08x\n", io_base, io_limit+0xfff);
1869 if (mem_type != (mem_limit & PCI_MEMORY_RANGE_TYPE_MASK) ||
1871 printf("\t!!! Unknown memory range types %x/%x\n", mem_base, mem_limit);
1874 mem_base = (mem_base & PCI_MEMORY_RANGE_MASK) << 16;
1875 mem_limit = (mem_limit & PCI_MEMORY_RANGE_MASK) << 16;
1876 if (mem_base <= mem_limit || verb)
1877 printf("\tMemory behind bridge: %08x-%08x\n", mem_base, mem_limit + 0xfffff);
1880 if (pref_type != (pref_limit & PCI_PREF_RANGE_TYPE_MASK) ||
1881 (pref_type != PCI_PREF_RANGE_TYPE_32 && pref_type != PCI_PREF_RANGE_TYPE_64))
1882 printf("\t!!! Unknown prefetchable memory range types %x/%x\n", pref_base, pref_limit);
1885 pref_base = (pref_base & PCI_PREF_RANGE_MASK) << 16;
1886 pref_limit = (pref_limit & PCI_PREF_RANGE_MASK) << 16;
1887 if (pref_base <= pref_limit || verb)
1889 if (pref_type == PCI_PREF_RANGE_TYPE_32)
1890 printf("\tPrefetchable memory behind bridge: %08x-%08x\n", pref_base, pref_limit + 0xfffff);
1892 printf("\tPrefetchable memory behind bridge: %08x%08x-%08x%08x\n",
1893 get_conf_long(d, PCI_PREF_BASE_UPPER32),
1895 get_conf_long(d, PCI_PREF_LIMIT_UPPER32),
1896 pref_limit + 0xfffff);
1901 printf("\tSecondary status: 66MHz%c FastB2B%c ParErr%c DEVSEL=%s >TAbort%c <TAbort%c <MAbort%c <SERR%c <PERR%c\n",
1902 FLAG(sec_stat, PCI_STATUS_66MHZ),
1903 FLAG(sec_stat, PCI_STATUS_FAST_BACK),
1904 FLAG(sec_stat, PCI_STATUS_PARITY),
1905 ((sec_stat & PCI_STATUS_DEVSEL_MASK) == PCI_STATUS_DEVSEL_SLOW) ? "slow" :
1906 ((sec_stat & PCI_STATUS_DEVSEL_MASK) == PCI_STATUS_DEVSEL_MEDIUM) ? "medium" :
1907 ((sec_stat & PCI_STATUS_DEVSEL_MASK) == PCI_STATUS_DEVSEL_FAST) ? "fast" : "??",
1908 FLAG(sec_stat, PCI_STATUS_SIG_TARGET_ABORT),
1909 FLAG(sec_stat, PCI_STATUS_REC_TARGET_ABORT),
1910 FLAG(sec_stat, PCI_STATUS_REC_MASTER_ABORT),
1911 FLAG(sec_stat, PCI_STATUS_SIG_SYSTEM_ERROR),
1912 FLAG(sec_stat, PCI_STATUS_DETECTED_PARITY));
1914 show_rom(d, PCI_ROM_ADDRESS1);
1918 printf("\tBridgeCtl: Parity%c SERR%c NoISA%c VGA%c MAbort%c >Reset%c FastB2B%c\n",
1919 FLAG(brc, PCI_BRIDGE_CTL_PARITY),
1920 FLAG(brc, PCI_BRIDGE_CTL_SERR),
1921 FLAG(brc, PCI_BRIDGE_CTL_NO_ISA),
1922 FLAG(brc, PCI_BRIDGE_CTL_VGA),
1923 FLAG(brc, PCI_BRIDGE_CTL_MASTER_ABORT),
1924 FLAG(brc, PCI_BRIDGE_CTL_BUS_RESET),
1925 FLAG(brc, PCI_BRIDGE_CTL_FAST_BACK));
1926 printf("\t\tPriDiscTmr%c SecDiscTmr%c DiscTmrStat%c DiscTmrSERREn%c\n",
1927 FLAG(brc, PCI_BRIDGE_CTL_PRI_DISCARD_TIMER),
1928 FLAG(brc, PCI_BRIDGE_CTL_SEC_DISCARD_TIMER),
1929 FLAG(brc, PCI_BRIDGE_CTL_DISCARD_TIMER_STATUS),
1930 FLAG(brc, PCI_BRIDGE_CTL_DISCARD_TIMER_SERR_EN));
1937 show_htype2(struct device *d)
1940 word cmd = get_conf_word(d, PCI_COMMAND);
1941 word brc = get_conf_word(d, PCI_CB_BRIDGE_CONTROL);
1943 int verb = verbose > 2;
1946 printf("\tBus: primary=%02x, secondary=%02x, subordinate=%02x, sec-latency=%d\n",
1947 get_conf_byte(d, PCI_CB_PRIMARY_BUS),
1948 get_conf_byte(d, PCI_CB_CARD_BUS),
1949 get_conf_byte(d, PCI_CB_SUBORDINATE_BUS),
1950 get_conf_byte(d, PCI_CB_LATENCY_TIMER));
1954 u32 base = get_conf_long(d, PCI_CB_MEMORY_BASE_0 + p);
1955 u32 limit = get_conf_long(d, PCI_CB_MEMORY_LIMIT_0 + p);
1956 if (limit > base || verb)
1957 printf("\tMemory window %d: %08x-%08x%s%s\n", i, base, limit,
1958 (cmd & PCI_COMMAND_MEMORY) ? "" : " [disabled]",
1959 (brc & (PCI_CB_BRIDGE_CTL_PREFETCH_MEM0 << i)) ? " (prefetchable)" : "");
1964 u32 base = get_conf_long(d, PCI_CB_IO_BASE_0 + p);
1965 u32 limit = get_conf_long(d, PCI_CB_IO_LIMIT_0 + p);
1966 if (!(base & PCI_IO_RANGE_TYPE_32))
1971 base &= PCI_CB_IO_RANGE_MASK;
1972 limit = (limit & PCI_CB_IO_RANGE_MASK) + 3;
1973 if (base <= limit || verb)
1974 printf("\tI/O window %d: %08x-%08x%s\n", i, base, limit,
1975 (cmd & PCI_COMMAND_IO) ? "" : " [disabled]");
1978 if (get_conf_word(d, PCI_CB_SEC_STATUS) & PCI_STATUS_SIG_SYSTEM_ERROR)
1979 printf("\tSecondary status: SERR\n");
1981 printf("\tBridgeCtl: Parity%c SERR%c ISA%c VGA%c MAbort%c >Reset%c 16bInt%c PostWrite%c\n",
1982 FLAG(brc, PCI_CB_BRIDGE_CTL_PARITY),
1983 FLAG(brc, PCI_CB_BRIDGE_CTL_SERR),
1984 FLAG(brc, PCI_CB_BRIDGE_CTL_ISA),
1985 FLAG(brc, PCI_CB_BRIDGE_CTL_VGA),
1986 FLAG(brc, PCI_CB_BRIDGE_CTL_MASTER_ABORT),
1987 FLAG(brc, PCI_CB_BRIDGE_CTL_CB_RESET),
1988 FLAG(brc, PCI_CB_BRIDGE_CTL_16BIT_INT),
1989 FLAG(brc, PCI_CB_BRIDGE_CTL_POST_WRITES));
1991 if (d->config_cached < 128)
1993 printf("\t<access denied to the rest>\n");
1997 exca = get_conf_word(d, PCI_CB_LEGACY_MODE_BASE);
1999 printf("\t16-bit legacy interface ports at %04x\n", exca);
2003 show_verbose(struct device *d)
2005 struct pci_dev *p = d->dev;
2006 word status = get_conf_word(d, PCI_STATUS);
2007 word cmd = get_conf_word(d, PCI_COMMAND);
2008 word class = p->device_class;
2009 byte bist = get_conf_byte(d, PCI_BIST);
2010 byte htype = get_conf_byte(d, PCI_HEADER_TYPE) & 0x7f;
2011 byte latency = get_conf_byte(d, PCI_LATENCY_TIMER);
2012 byte cache_line = get_conf_byte(d, PCI_CACHE_LINE_SIZE);
2013 byte max_lat, min_gnt;
2014 byte int_pin = get_conf_byte(d, PCI_INTERRUPT_PIN);
2015 unsigned int irq = p->irq;
2016 word subsys_v, subsys_d;
2017 char ssnamebuf[256];
2023 case PCI_HEADER_TYPE_NORMAL:
2024 if (class == PCI_CLASS_BRIDGE_PCI)
2025 printf("\t!!! Invalid class %04x for header type %02x\n", class, htype);
2026 max_lat = get_conf_byte(d, PCI_MAX_LAT);
2027 min_gnt = get_conf_byte(d, PCI_MIN_GNT);
2029 case PCI_HEADER_TYPE_BRIDGE:
2030 if ((class >> 8) != PCI_BASE_CLASS_BRIDGE)
2031 printf("\t!!! Invalid class %04x for header type %02x\n", class, htype);
2032 irq = int_pin = min_gnt = max_lat = 0;
2034 case PCI_HEADER_TYPE_CARDBUS:
2035 if ((class >> 8) != PCI_BASE_CLASS_BRIDGE)
2036 printf("\t!!! Invalid class %04x for header type %02x\n", class, htype);
2037 min_gnt = max_lat = 0;
2040 printf("\t!!! Unknown header type %02x\n", htype);
2044 get_subid(d, &subsys_v, &subsys_d);
2045 if (subsys_v && subsys_v != 0xffff)
2046 printf("\tSubsystem: %s\n",
2047 pci_lookup_name(pacc, ssnamebuf, sizeof(ssnamebuf),
2048 PCI_LOOKUP_SUBSYSTEM | PCI_LOOKUP_VENDOR | PCI_LOOKUP_DEVICE,
2049 p->vendor_id, p->device_id, subsys_v, subsys_d));
2053 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",
2054 FLAG(cmd, PCI_COMMAND_IO),
2055 FLAG(cmd, PCI_COMMAND_MEMORY),
2056 FLAG(cmd, PCI_COMMAND_MASTER),
2057 FLAG(cmd, PCI_COMMAND_SPECIAL),
2058 FLAG(cmd, PCI_COMMAND_INVALIDATE),
2059 FLAG(cmd, PCI_COMMAND_VGA_PALETTE),
2060 FLAG(cmd, PCI_COMMAND_PARITY),
2061 FLAG(cmd, PCI_COMMAND_WAIT),
2062 FLAG(cmd, PCI_COMMAND_SERR),
2063 FLAG(cmd, PCI_COMMAND_FAST_BACK),
2064 FLAG(cmd, PCI_COMMAND_DISABLE_INTx));
2065 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",
2066 FLAG(status, PCI_STATUS_CAP_LIST),
2067 FLAG(status, PCI_STATUS_66MHZ),
2068 FLAG(status, PCI_STATUS_UDF),
2069 FLAG(status, PCI_STATUS_FAST_BACK),
2070 FLAG(status, PCI_STATUS_PARITY),
2071 ((status & PCI_STATUS_DEVSEL_MASK) == PCI_STATUS_DEVSEL_SLOW) ? "slow" :
2072 ((status & PCI_STATUS_DEVSEL_MASK) == PCI_STATUS_DEVSEL_MEDIUM) ? "medium" :
2073 ((status & PCI_STATUS_DEVSEL_MASK) == PCI_STATUS_DEVSEL_FAST) ? "fast" : "??",
2074 FLAG(status, PCI_STATUS_SIG_TARGET_ABORT),
2075 FLAG(status, PCI_STATUS_REC_TARGET_ABORT),
2076 FLAG(status, PCI_STATUS_REC_MASTER_ABORT),
2077 FLAG(status, PCI_STATUS_SIG_SYSTEM_ERROR),
2078 FLAG(status, PCI_STATUS_DETECTED_PARITY),
2079 FLAG(status, PCI_STATUS_INTx));
2080 if (cmd & PCI_COMMAND_MASTER)
2082 printf("\tLatency: %d", latency);
2083 if (min_gnt || max_lat)
2087 printf("%dns min", min_gnt*250);
2088 if (min_gnt && max_lat)
2091 printf("%dns max", max_lat*250);
2095 printf(", Cache Line Size: %d bytes", cache_line * 4);
2099 printf("\tInterrupt: pin %c routed to IRQ " PCIIRQ_FMT "\n",
2100 (int_pin ? 'A' + int_pin - 1 : '?'), irq);
2104 printf("\tFlags: ");
2105 if (cmd & PCI_COMMAND_MASTER)
2106 printf("bus master, ");
2107 if (cmd & PCI_COMMAND_VGA_PALETTE)
2108 printf("VGA palette snoop, ");
2109 if (cmd & PCI_COMMAND_WAIT)
2110 printf("stepping, ");
2111 if (cmd & PCI_COMMAND_FAST_BACK)
2112 printf("fast Back2Back, ");
2113 if (status & PCI_STATUS_66MHZ)
2115 if (status & PCI_STATUS_UDF)
2116 printf("user-definable features, ");
2118 ((status & PCI_STATUS_DEVSEL_MASK) == PCI_STATUS_DEVSEL_SLOW) ? "slow" :
2119 ((status & PCI_STATUS_DEVSEL_MASK) == PCI_STATUS_DEVSEL_MEDIUM) ? "medium" :
2120 ((status & PCI_STATUS_DEVSEL_MASK) == PCI_STATUS_DEVSEL_FAST) ? "fast" : "??");
2121 if (cmd & PCI_COMMAND_MASTER)
2122 printf(", latency %d", latency);
2124 printf(", IRQ " PCIIRQ_FMT, irq);
2128 if (bist & PCI_BIST_CAPABLE)
2130 if (bist & PCI_BIST_START)
2131 printf("\tBIST is running\n");
2133 printf("\tBIST result: %02x\n", bist & PCI_BIST_CODE_MASK);
2138 case PCI_HEADER_TYPE_NORMAL:
2141 case PCI_HEADER_TYPE_BRIDGE:
2144 case PCI_HEADER_TYPE_CARDBUS:
2150 /*** Machine-readable dumps ***/
2153 show_hex_dump(struct device *d)
2155 unsigned int i, cnt;
2157 cnt = d->config_cached;
2158 if (opt_hex >= 3 && config_fetch(d, cnt, 256-cnt))
2161 if (opt_hex >= 4 && config_fetch(d, 256, 4096-256))
2165 for(i=0; i<cnt; i++)
2169 printf(" %02x", get_conf_byte(d, i));
2176 print_shell_escaped(char *c)
2181 if (*c == '"' || *c == '\\')
2189 show_machine(struct device *d)
2191 struct pci_dev *p = d->dev;
2194 char classbuf[128], vendbuf[128], devbuf[128], svbuf[128], sdbuf[128];
2196 get_subid(d, &sv_id, &sd_id);
2200 printf((opt_machine >= 2) ? "Slot:\t" : "Device:\t");
2203 printf("Class:\t%s\n",
2204 pci_lookup_name(pacc, classbuf, sizeof(classbuf), PCI_LOOKUP_CLASS, p->device_class));
2205 printf("Vendor:\t%s\n",
2206 pci_lookup_name(pacc, vendbuf, sizeof(vendbuf), PCI_LOOKUP_VENDOR, p->vendor_id, p->device_id));
2207 printf("Device:\t%s\n",
2208 pci_lookup_name(pacc, devbuf, sizeof(devbuf), PCI_LOOKUP_DEVICE, p->vendor_id, p->device_id));
2209 if (sv_id && sv_id != 0xffff)
2211 printf("SVendor:\t%s\n",
2212 pci_lookup_name(pacc, svbuf, sizeof(svbuf), PCI_LOOKUP_SUBSYSTEM | PCI_LOOKUP_VENDOR, sv_id));
2213 printf("SDevice:\t%s\n",
2214 pci_lookup_name(pacc, sdbuf, sizeof(sdbuf), PCI_LOOKUP_SUBSYSTEM | PCI_LOOKUP_DEVICE, p->vendor_id, p->device_id, sv_id, sd_id));
2216 if (c = get_conf_byte(d, PCI_REVISION_ID))
2217 printf("Rev:\t%02x\n", c);
2218 if (c = get_conf_byte(d, PCI_CLASS_PROG))
2219 printf("ProgIf:\t%02x\n", c);
2221 show_kernel_machine(d);
2226 print_shell_escaped(pci_lookup_name(pacc, classbuf, sizeof(classbuf), PCI_LOOKUP_CLASS, p->device_class));
2227 print_shell_escaped(pci_lookup_name(pacc, vendbuf, sizeof(vendbuf), PCI_LOOKUP_VENDOR, p->vendor_id, p->device_id));
2228 print_shell_escaped(pci_lookup_name(pacc, devbuf, sizeof(devbuf), PCI_LOOKUP_DEVICE, p->vendor_id, p->device_id));
2229 if (c = get_conf_byte(d, PCI_REVISION_ID))
2230 printf(" -r%02x", c);
2231 if (c = get_conf_byte(d, PCI_CLASS_PROG))
2232 printf(" -p%02x", c);
2233 if (sv_id && sv_id != 0xffff)
2235 print_shell_escaped(pci_lookup_name(pacc, svbuf, sizeof(svbuf), PCI_LOOKUP_SUBSYSTEM | PCI_LOOKUP_VENDOR, sv_id));
2236 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));
2239 printf(" \"\" \"\"");
2244 /*** Main show function ***/
2247 show_device(struct device *d)
2257 if (opt_kernel || verbose)
2262 if (verbose || opt_hex)
2271 for(d=first_dev; d; d=d->next)
2275 /*** Tree output ***/
2278 struct bridge *chain; /* Single-linked list of bridges */
2279 struct bridge *next, *child; /* Tree of bridges */
2280 struct bus *first_bus; /* List of buses connected to this bridge */
2281 unsigned int domain;
2282 unsigned int primary, secondary, subordinate; /* Bus numbers */
2283 struct device *br_dev;
2287 unsigned int domain;
2288 unsigned int number;
2289 struct bus *sibling;
2290 struct device *first_dev, **last_dev;
2293 static struct bridge host_bridge = { NULL, NULL, NULL, NULL, 0, ~0, 0, ~0, NULL };
2296 find_bus(struct bridge *b, unsigned int domain, unsigned int n)
2300 for(bus=b->first_bus; bus; bus=bus->sibling)
2301 if (bus->domain == domain && bus->number == n)
2307 new_bus(struct bridge *b, unsigned int domain, unsigned int n)
2309 struct bus *bus = xmalloc(sizeof(struct bus));
2310 bus->domain = domain;
2312 bus->sibling = b->first_bus;
2313 bus->first_dev = NULL;
2314 bus->last_dev = &bus->first_dev;
2320 insert_dev(struct device *d, struct bridge *b)
2322 struct pci_dev *p = d->dev;
2325 if (! (bus = find_bus(b, p->domain, p->bus)))
2328 for(c=b->child; c; c=c->next)
2329 if (c->domain == p->domain && c->secondary <= p->bus && p->bus <= c->subordinate)
2334 bus = new_bus(b, p->domain, p->bus);
2336 /* Simple insertion at the end _does_ guarantee the correct order as the
2337 * original device list was sorted by (domain, bus, devfn) lexicographically
2338 * and all devices on the new list have the same bus number.
2341 bus->last_dev = &d->next;
2348 struct device *d, *d2;
2349 struct bridge **last_br, *b;
2351 /* Build list of bridges */
2353 last_br = &host_bridge.chain;
2354 for(d=first_dev; d; d=d->next)
2356 word class = d->dev->device_class;
2357 byte ht = get_conf_byte(d, PCI_HEADER_TYPE) & 0x7f;
2358 if (class == PCI_CLASS_BRIDGE_PCI &&
2359 (ht == PCI_HEADER_TYPE_BRIDGE || ht == PCI_HEADER_TYPE_CARDBUS))
2361 b = xmalloc(sizeof(struct bridge));
2362 b->domain = d->dev->domain;
2363 if (ht == PCI_HEADER_TYPE_BRIDGE)
2365 b->primary = get_conf_byte(d, PCI_PRIMARY_BUS);
2366 b->secondary = get_conf_byte(d, PCI_SECONDARY_BUS);
2367 b->subordinate = get_conf_byte(d, PCI_SUBORDINATE_BUS);
2371 b->primary = get_conf_byte(d, PCI_CB_PRIMARY_BUS);
2372 b->secondary = get_conf_byte(d, PCI_CB_CARD_BUS);
2373 b->subordinate = get_conf_byte(d, PCI_CB_SUBORDINATE_BUS);
2376 last_br = &b->chain;
2377 b->next = b->child = NULL;
2378 b->first_bus = NULL;
2384 /* Create a bridge tree */
2386 for(b=&host_bridge; b; b=b->chain)
2388 struct bridge *c, *best;
2390 for(c=&host_bridge; c; c=c->chain)
2391 if (c != b && (c == &host_bridge || b->domain == c->domain) &&
2392 b->primary >= c->secondary && b->primary <= c->subordinate &&
2393 (!best || best->subordinate - best->primary > c->subordinate - c->primary))
2397 b->next = best->child;
2402 /* Insert secondary bus for each bridge */
2404 for(b=&host_bridge; b; b=b->chain)
2405 if (!find_bus(b, b->domain, b->secondary))
2406 new_bus(b, b->domain, b->secondary);
2408 /* Create bus structs and link devices */
2410 for(d=first_dev; d;)
2413 insert_dev(d, &host_bridge);
2419 print_it(char *line, char *p)
2423 fputs(line, stdout);
2424 for(p=line; *p; p++)
2425 if (*p == '+' || *p == '|')
2431 static void show_tree_bridge(struct bridge *, char *, char *);
2434 show_tree_dev(struct device *d, char *line, char *p)
2436 struct pci_dev *q = d->dev;
2440 p += sprintf(p, "%02x.%x", q->dev, q->func);
2441 for(b=&host_bridge; b; b=b->chain)
2444 if (b->secondary == b->subordinate)
2445 p += sprintf(p, "-[%04x:%02x]-", b->domain, b->secondary);
2447 p += sprintf(p, "-[%04x:%02x-%02x]-", b->domain, b->secondary, b->subordinate);
2448 show_tree_bridge(b, line, p);
2452 p += sprintf(p, " %s",
2453 pci_lookup_name(pacc, namebuf, sizeof(namebuf),
2454 PCI_LOOKUP_VENDOR | PCI_LOOKUP_DEVICE,
2455 q->vendor_id, q->device_id));
2460 show_tree_bus(struct bus *b, char *line, char *p)
2464 else if (!b->first_dev->next)
2468 show_tree_dev(b->first_dev, line, p);
2472 struct device *d = b->first_dev;
2477 show_tree_dev(d, line, p+2);
2482 show_tree_dev(d, line, p+2);
2487 show_tree_bridge(struct bridge *b, char *line, char *p)
2490 if (!b->first_bus->sibling)
2492 if (b == &host_bridge)
2493 p += sprintf(p, "[%04x:%02x]-", b->domain, b->first_bus->number);
2494 show_tree_bus(b->first_bus, line, p);
2498 struct bus *u = b->first_bus;
2503 k = p + sprintf(p, "+-[%04x:%02x]-", u->domain, u->number);
2504 show_tree_bus(u, line, k);
2507 k = p + sprintf(p, "\\-[%04x:%02x]-", u->domain, u->number);
2508 show_tree_bus(u, line, k);
2518 show_tree_bridge(&host_bridge, line, line);
2521 /*** Bus mapping mode ***/
2524 struct bus_bridge *next;
2525 byte this, dev, func, first, last, bug;
2531 struct bus_bridge *bridges, *via;
2534 static struct bus_info *bus_info;
2537 map_bridge(struct bus_info *bi, struct device *d, int np, int ns, int nl)
2539 struct bus_bridge *b = xmalloc(sizeof(struct bus_bridge));
2540 struct pci_dev *p = d->dev;
2542 b->next = bi->bridges;
2544 b->this = get_conf_byte(d, np);
2547 b->first = get_conf_byte(d, ns);
2548 b->last = get_conf_byte(d, nl);
2549 printf("## %02x.%02x:%d is a bridge from %02x to %02x-%02x\n",
2550 p->bus, p->dev, p->func, b->this, b->first, b->last);
2551 if (b->this != p->bus)
2552 printf("!!! Bridge points to invalid primary bus.\n");
2553 if (b->first > b->last)
2555 printf("!!! Bridge points to invalid bus range.\n");
2564 int verbose = pacc->debugging;
2565 struct bus_info *bi = bus_info + bus;
2569 printf("Mapping bus %02x\n", bus);
2570 for(dev = 0; dev < 32; dev++)
2571 if (filter.slot < 0 || filter.slot == dev)
2574 for(func = 0; func < func_limit; func++)
2575 if (filter.func < 0 || filter.func == func)
2577 /* XXX: Bus mapping supports only domain 0 */
2578 struct pci_dev *p = pci_get_dev(pacc, 0, bus, dev, func);
2579 u16 vendor = pci_read_word(p, PCI_VENDOR_ID);
2580 if (vendor && vendor != 0xffff)
2582 if (!func && (pci_read_byte(p, PCI_HEADER_TYPE) & 0x80))
2585 printf("Discovered device %02x:%02x.%d\n", bus, dev, func);
2587 if (d = scan_device(p))
2590 switch (get_conf_byte(d, PCI_HEADER_TYPE) & 0x7f)
2592 case PCI_HEADER_TYPE_BRIDGE:
2593 map_bridge(bi, d, PCI_PRIMARY_BUS, PCI_SECONDARY_BUS, PCI_SUBORDINATE_BUS);
2595 case PCI_HEADER_TYPE_CARDBUS:
2596 map_bridge(bi, d, PCI_CB_PRIMARY_BUS, PCI_CB_CARD_BUS, PCI_CB_SUBORDINATE_BUS);
2602 printf("But it was filtered out.\n");
2610 do_map_bridges(int bus, int min, int max)
2612 struct bus_info *bi = bus_info + bus;
2613 struct bus_bridge *b;
2616 for(b=bi->bridges; b; b=b->next)
2618 if (bus_info[b->first].guestbook)
2620 else if (b->first < min || b->last > max)
2624 bus_info[b->first].via = b;
2625 do_map_bridges(b->first, b->first, b->last);
2635 printf("\nSummary of buses:\n\n");
2636 for(i=0; i<256; i++)
2637 if (bus_info[i].exists && !bus_info[i].guestbook)
2638 do_map_bridges(i, 0, 255);
2639 for(i=0; i<256; i++)
2641 struct bus_info *bi = bus_info + i;
2642 struct bus_bridge *b = bi->via;
2646 printf("%02x: ", i);
2648 printf("Entered via %02x:%02x.%d\n", b->this, b->dev, b->func);
2650 printf("Primary host bus\n");
2652 printf("Secondary host bus (?)\n");
2654 for(b=bi->bridges; b; b=b->next)
2656 printf("\t%02x.%d Bridge to %02x-%02x", b->dev, b->func, b->first, b->last);
2660 printf(" <overlap bug>");
2663 printf(" <crossing bug>");
2674 if (pacc->method == PCI_ACCESS_PROC_BUS_PCI ||
2675 pacc->method == PCI_ACCESS_DUMP)
2676 printf("WARNING: Bus mapping can be reliable only with direct hardware access enabled.\n\n");
2677 bus_info = xmalloc(sizeof(struct bus_info) * 256);
2678 memset(bus_info, 0, sizeof(struct bus_info) * 256);
2679 if (filter.bus >= 0)
2680 do_map_bus(filter.bus);
2684 for(bus=0; bus<256; bus++)
2693 main(int argc, char **argv)
2698 if (argc == 2 && !strcmp(argv[1], "--version"))
2700 puts("lspci version " PCIUTILS_VERSION);
2706 pci_filter_init(pacc, &filter);
2708 while ((i = getopt(argc, argv, options)) != -1)
2712 pacc->numeric_ids++;
2718 pacc->buscentric = 1;
2722 if (msg = pci_filter_parse_slot(&filter, optarg))
2726 if (msg = pci_filter_parse_id(&filter, optarg))
2736 pci_set_name_list_path(pacc, optarg, 0);
2742 opt_pcimap = optarg;
2765 die("DNS queries are not available in this version");
2768 if (parse_generic_option(i, pacc, optarg))
2771 fprintf(stderr, help_msg, pacc->id_file_name);
2779 pacc->id_lookup_mode |= PCI_LOOKUP_NETWORK;
2780 if (opt_query_dns > 1)
2781 pacc->id_lookup_mode |= PCI_LOOKUP_REFRESH_CACHE;
2784 pacc->id_lookup_mode |= PCI_LOOKUP_NETWORK | PCI_LOOKUP_SKIP_LOCAL;
2800 return (seen_errors ? 2 : 0);