2 * The PCI Utilities -- List All PCI Devices
4 * Copyright (c) 1997--2004 Martin Mares <mj@ucw.cz>
6 * Can be freely distributed and used under the terms of the GNU GPL.
19 static int verbose; /* Show detailed information */
20 static int buscentric_view; /* Show bus addresses/IRQ's instead of CPU-visible ones */
21 static int show_hex; /* Show contents of config space as hexadecimal numbers */
22 static struct pci_filter filter; /* Device filter */
23 static int show_tree; /* Show bus tree */
24 static int machine_readable; /* Generate machine-readable output */
25 static int map_mode; /* Bus mapping mode enabled */
27 static char options[] = "nvbxs:d:ti:mgM" GENERIC_OPTIONS ;
29 static char help_msg[] = "\
30 Usage: lspci [<switches>]\n\
33 -n\t\tShow numeric ID's\n\
34 -b\t\tBus-centric view (PCI addresses and IRQ's instead of those seen by the CPU)\n\
35 -x\t\tShow hex-dump of the standard portion of config space\n\
36 -xxx\t\tShow hex-dump of the whole config space (dangerous; root only)\n\
37 -xxxx\t\tShow hex-dump of the 4096-byte extended config space (root only)\n\
38 -s [[[[<domain>]:]<bus>]:][<slot>][.[<func>]]\tShow only devices in selected slots\n\
39 -d [<vendor>]:[<device>]\tShow only selected devices\n\
40 -t\t\tShow bus tree\n\
41 -m\t\tProduce machine-readable output\n\
42 -i <file>\tUse specified ID database instead of %s\n\
43 -M\t\tEnable `bus mapping' mode (dangerous; root only)\n"
47 /* Communication with libpci */
49 static struct pci_access *pacc;
52 * If we aren't being compiled by GCC, use malloc() instead of alloca().
53 * This increases our memory footprint, but only slightly since we don't
61 /* Our view of the PCI bus */
66 unsigned int config_cnt;
70 static struct device *first_dev;
72 static struct device *
73 scan_device(struct pci_dev *p)
77 if (!pci_filter_match(&filter, p))
79 d = xmalloc(sizeof(struct device));
83 if (!pci_read_block(p, 0, d->config, 64))
84 die("Unable to read the configuration space header.");
85 if ((d->config[PCI_HEADER_TYPE] & 0x7f) == PCI_HEADER_TYPE_CARDBUS)
87 /* For cardbus bridges, we need to fetch 64 bytes more to get the full standard header... */
88 if (!pci_read_block(p, 64, d->config+64, 64))
89 die("Unable to read cardbus bridge extension data.");
92 pci_setup_cache(p, d->config, d->config_cnt);
93 pci_fill_info(p, PCI_FILL_IDENT | PCI_FILL_IRQ | PCI_FILL_BASES | PCI_FILL_ROM_BASE | PCI_FILL_SIZES);
104 for(p=pacc->devices; p; p=p->next)
105 if (d = scan_device(p))
113 config_fetch(struct device *d, unsigned int pos, unsigned int len)
115 if (pos + len < d->config_cnt)
117 return pci_read_block(d->dev, pos, d->config + pos, len);
120 /* Config space accesses */
123 get_conf_byte(struct device *d, unsigned int pos)
125 return d->config[pos];
129 get_conf_word(struct device *d, unsigned int pos)
131 return d->config[pos] | (d->config[pos+1] << 8);
135 get_conf_long(struct device *d, unsigned int pos)
137 return d->config[pos] |
138 (d->config[pos+1] << 8) |
139 (d->config[pos+2] << 16) |
140 (d->config[pos+3] << 24);
146 compare_them(const void *A, const void *B)
148 const struct pci_dev *a = (*(const struct device **)A)->dev;
149 const struct pci_dev *b = (*(const struct device **)B)->dev;
151 if (a->domain < b->domain)
153 if (a->domain > b->domain)
163 if (a->func < b->func)
165 if (a->func > b->func)
173 struct device **index, **h, **last_dev;
178 for(d=first_dev; d; d=d->next)
180 h = index = alloca(sizeof(struct device *) * cnt);
181 for(d=first_dev; d; d=d->next)
183 qsort(index, cnt, sizeof(struct device *), compare_them);
184 last_dev = &first_dev;
189 last_dev = &(*h)->next;
197 #define FLAG(x,y) ((x & y) ? '+' : '-')
200 show_slot_name(struct device *d)
202 struct pci_dev *p = d->dev;
205 printf("%04x:", p->domain);
206 printf("%02x:%02x.%d", p->bus, p->dev, p->func);
210 show_terse(struct device *d)
213 struct pci_dev *p = d->dev;
214 byte classbuf[128], devbuf[128];
218 pci_lookup_name(pacc, classbuf, sizeof(classbuf),
220 get_conf_word(d, PCI_CLASS_DEVICE), 0, 0, 0),
221 pci_lookup_name(pacc, devbuf, sizeof(devbuf),
222 PCI_LOOKUP_VENDOR | PCI_LOOKUP_DEVICE,
223 p->vendor_id, p->device_id, 0, 0));
224 if (c = get_conf_byte(d, PCI_REVISION_ID))
225 printf(" (rev %02x)", c);
229 c = get_conf_byte(d, PCI_CLASS_PROG);
230 x = pci_lookup_name(pacc, devbuf, sizeof(devbuf),
232 get_conf_word(d, PCI_CLASS_DEVICE), c, 0, 0);
235 printf(" (prog-if %02x", c);
245 show_size(pciaddr_t x)
251 printf("%d", (int) x);
252 else if (x < 1048576)
253 printf("%dK", (int)(x / 1024));
254 else if (x < 0x80000000)
255 printf("%dM", (int)(x / 1048576));
257 printf(PCIADDR_T_FMT, x);
262 show_bases(struct device *d, int cnt)
264 struct pci_dev *p = d->dev;
265 word cmd = get_conf_word(d, PCI_COMMAND);
270 pciaddr_t pos = p->base_addr[i];
271 pciaddr_t len = (p->known_fields & PCI_FILL_SIZES) ? p->size[i] : 0;
272 u32 flg = get_conf_long(d, PCI_BASE_ADDRESS_0 + 4*i);
273 if (flg == 0xffffffff)
275 if (!pos && !flg && !len)
278 printf("\tRegion %d: ", i);
281 if (pos && !flg) /* Reported by the OS, but not by the device */
283 printf("[virtual] ");
286 if (flg & PCI_BASE_ADDRESS_SPACE_IO)
288 pciaddr_t a = pos & PCI_BASE_ADDRESS_IO_MASK;
289 printf("I/O ports at ");
291 printf(PCIADDR_PORT_FMT, a);
292 else if (flg & PCI_BASE_ADDRESS_IO_MASK)
295 printf("<unassigned>");
296 if (!(cmd & PCI_COMMAND_IO))
297 printf(" [disabled]");
301 int t = flg & PCI_BASE_ADDRESS_MEM_TYPE_MASK;
302 pciaddr_t a = pos & PCI_ADDR_MEM_MASK;
306 printf("Memory at ");
307 if (t == PCI_BASE_ADDRESS_MEM_TYPE_64)
311 printf("<invalid-64bit-slot>");
317 z = get_conf_long(d, PCI_BASE_ADDRESS_0 + 4*i);
321 printf("%08x" PCIADDR_T_FMT, z, a);
323 printf("<unassigned>");
331 printf(PCIADDR_T_FMT, a);
333 printf(((flg & PCI_BASE_ADDRESS_MEM_MASK) || z) ? "<ignored>" : "<unassigned>");
335 printf(" (%s, %sprefetchable)",
336 (t == PCI_BASE_ADDRESS_MEM_TYPE_32) ? "32-bit" :
337 (t == PCI_BASE_ADDRESS_MEM_TYPE_64) ? "64-bit" :
338 (t == PCI_BASE_ADDRESS_MEM_TYPE_1M) ? "low-1M" : "type 3",
339 (flg & PCI_BASE_ADDRESS_MEM_PREFETCH) ? "" : "non-");
340 if (!(cmd & PCI_COMMAND_MEMORY))
341 printf(" [disabled]");
349 show_pm(struct device *d, int where, int cap)
352 static int pm_aux_current[8] = { 0, 55, 100, 160, 220, 270, 320, 375 };
354 printf("Power Management version %d\n", cap & PCI_PM_CAP_VER_MASK);
357 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",
358 FLAG(cap, PCI_PM_CAP_PME_CLOCK),
359 FLAG(cap, PCI_PM_CAP_DSI),
360 FLAG(cap, PCI_PM_CAP_D1),
361 FLAG(cap, PCI_PM_CAP_D2),
362 pm_aux_current[(cap >> 6) & 7],
363 FLAG(cap, PCI_PM_CAP_PME_D0),
364 FLAG(cap, PCI_PM_CAP_PME_D1),
365 FLAG(cap, PCI_PM_CAP_PME_D2),
366 FLAG(cap, PCI_PM_CAP_PME_D3_HOT),
367 FLAG(cap, PCI_PM_CAP_PME_D3_COLD));
368 if (!config_fetch(d, where + PCI_PM_CTRL, PCI_PM_SIZEOF - PCI_PM_CTRL))
370 t = get_conf_word(d, where + PCI_PM_CTRL);
371 printf("\t\tStatus: D%d PME-Enable%c DSel=%d DScale=%d PME%c\n",
372 t & PCI_PM_CTRL_STATE_MASK,
373 FLAG(t, PCI_PM_CTRL_PME_ENABLE),
374 (t & PCI_PM_CTRL_DATA_SEL_MASK) >> 9,
375 (t & PCI_PM_CTRL_DATA_SCALE_MASK) >> 13,
376 FLAG(t, PCI_PM_CTRL_PME_STATUS));
377 b = get_conf_byte(d, where + PCI_PM_PPB_EXTENSIONS);
379 printf("\t\tBridge: PM%c B3%c\n",
380 FLAG(t, PCI_PM_BPCC_ENABLE),
381 FLAG(~t, PCI_PM_PPB_B2_B3));
385 format_agp_rate(int rate, char *buf, int agp3)
395 c += sprintf(c, "x%d", 1 << (i + 2*agp3));
400 strcpy(buf, "<none>");
404 show_agp(struct device *d, int where, int cap)
411 ver = (cap >> 4) & 0x0f;
413 printf("AGP version %x.%x\n", ver, rev);
416 if (!config_fetch(d, where + PCI_AGP_STATUS, PCI_AGP_SIZEOF - PCI_AGP_STATUS))
418 t = get_conf_long(d, where + PCI_AGP_STATUS);
419 if (ver >= 3 && (t & PCI_AGP_STATUS_AGP3))
421 format_agp_rate(t & 7, rate, agp3);
422 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",
423 ((t & PCI_AGP_STATUS_RQ_MASK) >> 24U) + 1,
424 FLAG(t, PCI_AGP_STATUS_ISOCH),
425 ((t & PCI_AGP_STATUS_ARQSZ_MASK) >> 13),
426 ((t & PCI_AGP_STATUS_CAL_MASK) >> 10),
427 FLAG(t, PCI_AGP_STATUS_SBA),
428 FLAG(t, PCI_AGP_STATUS_ITA_COH),
429 FLAG(t, PCI_AGP_STATUS_GART64),
430 FLAG(t, PCI_AGP_STATUS_HTRANS),
431 FLAG(t, PCI_AGP_STATUS_64BIT),
432 FLAG(t, PCI_AGP_STATUS_FW),
433 FLAG(t, PCI_AGP_STATUS_AGP3),
435 t = get_conf_long(d, where + PCI_AGP_COMMAND);
436 format_agp_rate(t & 7, rate, agp3);
437 printf("\t\tCommand: RQ=%d ArqSz=%d Cal=%d SBA%c AGP%c GART64%c 64bit%c FW%c Rate=%s\n",
438 ((t & PCI_AGP_COMMAND_RQ_MASK) >> 24U) + 1,
439 ((t & PCI_AGP_COMMAND_ARQSZ_MASK) >> 13),
440 ((t & PCI_AGP_COMMAND_CAL_MASK) >> 10),
441 FLAG(t, PCI_AGP_COMMAND_SBA),
442 FLAG(t, PCI_AGP_COMMAND_AGP),
443 FLAG(t, PCI_AGP_COMMAND_GART64),
444 FLAG(t, PCI_AGP_COMMAND_64BIT),
445 FLAG(t, PCI_AGP_COMMAND_FW),
450 show_pcix_nobridge(struct device *d, int where)
455 printf("PCI-X non-bridge device.\n");
460 if (!config_fetch(d, where + PCI_PCIX_STATUS, 4))
463 command = get_conf_word(d, where + PCI_PCIX_COMMAND);
464 status = get_conf_long(d, where + PCI_PCIX_STATUS);
465 printf("\t\tCommand: DPERE%c ERO%c RBC=%d OST=%d\n",
466 FLAG(command, PCI_PCIX_COMMAND_DPERE),
467 FLAG(command, PCI_PCIX_COMMAND_ERO),
468 ((command & PCI_PCIX_COMMAND_MAX_MEM_READ_BYTE_COUNT) >> 2U),
469 ((command & PCI_PCIX_COMMAND_MAX_OUTSTANDING_SPLIT_TRANS) >> 4U));
470 printf("\t\tStatus: Bus=%u Dev=%u Func=%u 64bit%c 133MHz%c SCD%c USC%c, DC=%s, DMMRBC=%u, DMOST=%u, DMCRS=%u, RSCEM%c\n",
471 ((status >> 8) & 0xffU), // bus
472 ((status >> 3) & 0x1fU), // dev
473 (status & PCI_PCIX_STATUS_FUNCTION), // function
474 FLAG(status, PCI_PCIX_STATUS_64BIT),
475 FLAG(status, PCI_PCIX_STATUS_133MHZ),
476 FLAG(status, PCI_PCIX_STATUS_SC_DISCARDED),
477 FLAG(status, PCI_PCIX_STATUS_UNEXPECTED_SC),
478 ((status & PCI_PCIX_STATUS_DEVICE_COMPLEXITY) ? "bridge" : "simple"),
479 ((status >> 21) & 3U),
480 ((status >> 23) & 7U),
481 ((status >> 26) & 7U),
482 FLAG(status, PCI_PCIX_STATUS_RCVD_SC_ERR_MESS));
486 show_pcix_bridge(struct device *d, int where)
490 u32 status, upstcr, downstcr;
492 printf("PCI-X bridge device.\n");
497 if (!config_fetch(d, where + PCI_PCIX_BRIDGE_STATUS, 12))
500 secstatus = get_conf_word(d, where + PCI_PCIX_BRIDGE_SEC_STATUS);
501 printf("\t\tSecondary Status: 64bit%c, 133MHz%c, SCD%c, USC%c, SCO%c, SRD%c Freq=%d\n",
502 FLAG(secstatus, PCI_PCIX_BRIDGE_SEC_STATUS_64BIT),
503 FLAG(secstatus, PCI_PCIX_BRIDGE_SEC_STATUS_133MHZ),
504 FLAG(secstatus, PCI_PCIX_BRIDGE_SEC_STATUS_SC_DISCARDED),
505 FLAG(secstatus, PCI_PCIX_BRIDGE_SEC_STATUS_UNEXPECTED_SC),
506 FLAG(secstatus, PCI_PCIX_BRIDGE_SEC_STATUS_SC_OVERRUN),
507 FLAG(secstatus, PCI_PCIX_BRIDGE_SEC_STATUS_SPLIT_REQUEST_DELAYED),
508 ((secstatus >> 6) & 7));
509 status = get_conf_long(d, where + PCI_PCIX_BRIDGE_STATUS);
510 printf("\t\tStatus: Bus=%u Dev=%u Func=%u 64bit%c 133MHz%c SCD%c USC%c, SCO%c, SRD%c\n",
511 ((status >> 8) & 0xff), // bus
512 ((status >> 3) & 0x1f), // dev
513 (status & PCI_PCIX_BRIDGE_STATUS_FUNCTION), // function
514 FLAG(status, PCI_PCIX_BRIDGE_STATUS_64BIT),
515 FLAG(status, PCI_PCIX_BRIDGE_STATUS_133MHZ),
516 FLAG(status, PCI_PCIX_BRIDGE_STATUS_SC_DISCARDED),
517 FLAG(status, PCI_PCIX_BRIDGE_STATUS_UNEXPECTED_SC),
518 FLAG(status, PCI_PCIX_BRIDGE_STATUS_SC_OVERRUN),
519 FLAG(status, PCI_PCIX_BRIDGE_STATUS_SPLIT_REQUEST_DELAYED));
520 upstcr = get_conf_long(d, where + PCI_PCIX_BRIDGE_UPSTREAM_SPLIT_TRANS_CTRL);
521 printf("\t\t: Upstream: Capacity=%u, Commitment Limit=%u\n",
522 (upstcr & PCI_PCIX_BRIDGE_STR_CAPACITY),
523 (upstcr >> 16) & 0xffff);
524 downstcr = get_conf_long(d, where + PCI_PCIX_BRIDGE_DOWNSTREAM_SPLIT_TRANS_CTRL);
525 printf("\t\t: Downstream: Capacity=%u, Commitment Limit=%u\n",
526 (downstcr & PCI_PCIX_BRIDGE_STR_CAPACITY),
527 (downstcr >> 16) & 0xffff);
531 show_pcix(struct device *d, int where)
533 switch (get_conf_byte(d, PCI_HEADER_TYPE) & 0x7f)
535 case PCI_HEADER_TYPE_NORMAL:
536 show_pcix_nobridge(d, where);
538 case PCI_HEADER_TYPE_BRIDGE:
539 show_pcix_bridge(d, where);
545 ht_link_width(unsigned width)
547 static char * const widths[8] = { "8bit", "16bit", "[2]", "32bit", "2bit", "4bit", "[6]", "N/C" };
548 return widths[width];
552 ht_link_freq(unsigned freq)
554 static char * const freqs[16] = { "200MHz", "300MHz", "400MHz", "500MHz", "600MHz", "800MHz", "1.0GHz", "1.2GHz",
555 "1.4GHz", "1.6GHz", "[a]", "[b]", "[c]", "[d]", "[e]", "Vend" };
560 show_ht_pri(struct device *d, int where, int cmd)
562 u16 lctr0, lcnf0, lctr1, lcnf1, eh;
563 u8 rid, lfrer0, lfcap0, ftr, lfrer1, lfcap1, mbu, mlu, bn;
565 printf("HyperTransport: Slave or Primary Interface\n");
569 printf("\t\tCommand: BaseUnitID=%u UnitCnt=%u MastHost%c DefDir%c DUL%c\n",
570 (cmd & PCI_HT_PRI_CMD_BUID),
571 (cmd & PCI_HT_PRI_CMD_UC) >> 5,
572 FLAG(cmd, PCI_HT_PRI_CMD_MH),
573 FLAG(cmd, PCI_HT_PRI_CMD_DD),
574 FLAG(cmd, PCI_HT_PRI_CMD_DUL));
575 config_fetch(d, where + PCI_HT_PRI_LCTR0, PCI_HT_PRI_SIZEOF - PCI_HT_PRI_LCTR0);
576 lctr0 = get_conf_word(d, where + PCI_HT_PRI_LCTR0);
577 printf("\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",
578 FLAG(lctr0, PCI_HT_LCTR_CFLE),
579 FLAG(lctr0, PCI_HT_LCTR_CST),
580 FLAG(lctr0, PCI_HT_LCTR_CFE),
581 FLAG(lctr0, PCI_HT_LCTR_LKFAIL),
582 FLAG(lctr0, PCI_HT_LCTR_INIT),
583 FLAG(lctr0, PCI_HT_LCTR_EOC),
584 FLAG(lctr0, PCI_HT_LCTR_TXO),
585 (lctr0 & PCI_HT_LCTR_CRCERR) >> 8,
586 FLAG(lctr0, PCI_HT_LCTR_ISOCEN),
587 FLAG(lctr0, PCI_HT_LCTR_LSEN),
588 FLAG(lctr0, PCI_HT_LCTR_EXTCTL),
589 FLAG(lctr0, PCI_HT_LCTR_64B));
590 lcnf0 = get_conf_word(d, where + PCI_HT_PRI_LCNF0);
591 printf("\t\tLink Config 0: MLWI=%s DwFcIn%c MLWO=%s DwFcOut%c LWI=%s DwFcInEn%c LWO=%s DwFcOutEn%c\n",
592 ht_link_width(lcnf0 & PCI_HT_LCNF_MLWI),
593 FLAG(lcnf0, PCI_HT_LCNF_DFI),
594 ht_link_width((lcnf0 & PCI_HT_LCNF_MLWO) >> 4),
595 FLAG(lcnf0, PCI_HT_LCNF_DFO),
596 ht_link_width((lcnf0 & PCI_HT_LCNF_LWI) >> 8),
597 FLAG(lcnf0, PCI_HT_LCNF_DFIE),
598 ht_link_width((lcnf0 & PCI_HT_LCNF_LWO) >> 12),
599 FLAG(lcnf0, PCI_HT_LCNF_DFOE));
600 lctr1 = get_conf_word(d, where + PCI_HT_PRI_LCTR1);
601 printf("\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",
602 FLAG(lctr1, PCI_HT_LCTR_CFLE),
603 FLAG(lctr1, PCI_HT_LCTR_CST),
604 FLAG(lctr1, PCI_HT_LCTR_CFE),
605 FLAG(lctr1, PCI_HT_LCTR_LKFAIL),
606 FLAG(lctr1, PCI_HT_LCTR_INIT),
607 FLAG(lctr1, PCI_HT_LCTR_EOC),
608 FLAG(lctr1, PCI_HT_LCTR_TXO),
609 (lctr1 & PCI_HT_LCTR_CRCERR) >> 8,
610 FLAG(lctr1, PCI_HT_LCTR_ISOCEN),
611 FLAG(lctr1, PCI_HT_LCTR_LSEN),
612 FLAG(lctr1, PCI_HT_LCTR_EXTCTL),
613 FLAG(lctr1, PCI_HT_LCTR_64B));
614 lcnf1 = get_conf_word(d, where + PCI_HT_PRI_LCNF1);
615 printf("\t\tLink Config 1: MLWI=%s DwFcIn%c MLWO=%s DwFcOut%c LWI=%s DwFcInEn%c LWO=%s DwFcOutEn%c\n",
616 ht_link_width(lcnf1 & PCI_HT_LCNF_MLWI),
617 FLAG(lcnf1, PCI_HT_LCNF_DFI),
618 ht_link_width((lcnf1 & PCI_HT_LCNF_MLWO) >> 4),
619 FLAG(lcnf1, PCI_HT_LCNF_DFO),
620 ht_link_width((lcnf1 & PCI_HT_LCNF_LWI) >> 8),
621 FLAG(lcnf1, PCI_HT_LCNF_DFIE),
622 ht_link_width((lcnf1 & PCI_HT_LCNF_LWO) >> 12),
623 FLAG(lcnf1, PCI_HT_LCNF_DFOE));
624 rid = get_conf_byte(d, where + PCI_HT_PRI_RID);
625 printf("\t\tRevision ID: %u.%02u\n",
626 (rid & PCI_HT_RID_MAJ) >> 5, (rid & PCI_HT_RID_MIN));
627 lfrer0 = get_conf_byte(d, where + PCI_HT_PRI_LFRER0);
628 printf("\t\tLink Frequency 0: %s\n", ht_link_freq(lfrer0 & PCI_HT_LFRER_FREQ));
629 printf("\t\tLink Error 0: <Prot%c <Ovfl%c <EOC%c CTLTm%c\n",
630 FLAG(lfrer0, PCI_HT_LFRER_PROT),
631 FLAG(lfrer0, PCI_HT_LFRER_OV),
632 FLAG(lfrer0, PCI_HT_LFRER_EOC),
633 FLAG(lfrer0, PCI_HT_LFRER_CTLT));
634 lfcap0 = get_conf_byte(d, where + PCI_HT_PRI_LFCAP0);
635 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",
636 FLAG(lfcap0, PCI_HT_LFCAP_200),
637 FLAG(lfcap0, PCI_HT_LFCAP_300),
638 FLAG(lfcap0, PCI_HT_LFCAP_400),
639 FLAG(lfcap0, PCI_HT_LFCAP_500),
640 FLAG(lfcap0, PCI_HT_LFCAP_600),
641 FLAG(lfcap0, PCI_HT_LFCAP_800),
642 FLAG(lfcap0, PCI_HT_LFCAP_1000),
643 FLAG(lfcap0, PCI_HT_LFCAP_1200),
644 FLAG(lfcap0, PCI_HT_LFCAP_1400),
645 FLAG(lfcap0, PCI_HT_LFCAP_1600),
646 FLAG(lfcap0, PCI_HT_LFCAP_VEND));
647 ftr = get_conf_byte(d, where + PCI_HT_PRI_FTR);
648 printf("\t\tFeature Capability: IsocFC%c LDTSTOP%c CRCTM%c ECTLT%c 64bA%c UIDRD%c\n",
649 FLAG(ftr, PCI_HT_FTR_ISOCFC),
650 FLAG(ftr, PCI_HT_FTR_LDTSTOP),
651 FLAG(ftr, PCI_HT_FTR_CRCTM),
652 FLAG(ftr, PCI_HT_FTR_ECTLT),
653 FLAG(ftr, PCI_HT_FTR_64BA),
654 FLAG(ftr, PCI_HT_FTR_UIDRD));
655 lfrer1 = get_conf_byte(d, where + PCI_HT_PRI_LFRER1);
656 printf("\t\tLink Frequency 1: %s\n", ht_link_freq(lfrer1 & PCI_HT_LFRER_FREQ));
657 printf("\t\tLink Error 1: <Prot%c <Ovfl%c <EOC%c CTLTm%c\n",
658 FLAG(lfrer1, PCI_HT_LFRER_PROT),
659 FLAG(lfrer1, PCI_HT_LFRER_OV),
660 FLAG(lfrer1, PCI_HT_LFRER_EOC),
661 FLAG(lfrer1, PCI_HT_LFRER_CTLT));
662 lfcap1 = get_conf_byte(d, where + PCI_HT_PRI_LFCAP1);
663 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",
664 FLAG(lfcap1, PCI_HT_LFCAP_200),
665 FLAG(lfcap1, PCI_HT_LFCAP_300),
666 FLAG(lfcap1, PCI_HT_LFCAP_400),
667 FLAG(lfcap1, PCI_HT_LFCAP_500),
668 FLAG(lfcap1, PCI_HT_LFCAP_600),
669 FLAG(lfcap1, PCI_HT_LFCAP_800),
670 FLAG(lfcap1, PCI_HT_LFCAP_1000),
671 FLAG(lfcap1, PCI_HT_LFCAP_1200),
672 FLAG(lfcap1, PCI_HT_LFCAP_1400),
673 FLAG(lfcap1, PCI_HT_LFCAP_1600),
674 FLAG(lfcap1, PCI_HT_LFCAP_VEND));
675 eh = get_conf_word(d, where + PCI_HT_PRI_EH);
676 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",
677 FLAG(eh, PCI_HT_EH_PFLE),
678 FLAG(eh, PCI_HT_EH_OFLE),
679 FLAG(eh, PCI_HT_EH_PFE),
680 FLAG(eh, PCI_HT_EH_OFE),
681 FLAG(eh, PCI_HT_EH_EOCFE),
682 FLAG(eh, PCI_HT_EH_RFE),
683 FLAG(eh, PCI_HT_EH_CRCFE),
684 FLAG(eh, PCI_HT_EH_SERRFE),
685 FLAG(eh, PCI_HT_EH_CF),
686 FLAG(eh, PCI_HT_EH_RE),
687 FLAG(eh, PCI_HT_EH_PNFE),
688 FLAG(eh, PCI_HT_EH_ONFE),
689 FLAG(eh, PCI_HT_EH_EOCNFE),
690 FLAG(eh, PCI_HT_EH_RNFE),
691 FLAG(eh, PCI_HT_EH_CRCNFE),
692 FLAG(eh, PCI_HT_EH_SERRNFE));
693 mbu = get_conf_byte(d, where + PCI_HT_PRI_MBU);
694 mlu = get_conf_byte(d, where + PCI_HT_PRI_MLU);
695 printf("\t\tPrefetchable memory behind bridge Upper: %02x-%02x\n", mbu, mlu);
696 bn = get_conf_byte(d, where + PCI_HT_PRI_BN);
697 printf("\t\tBus Number: %02x\n", bn);
701 show_ht_sec(struct device *d, int where, int cmd)
703 u16 lctr, lcnf, ftr, eh;
704 u8 rid, lfrer, lfcap, mbu, mlu;
706 printf("HyperTransport: Host or Secondary Interface\n");
710 printf("\t\tCommand: WarmRst%c DblEnd%c DevNum=%u ChainSide%c HostHide%c Slave%c <EOCErr%c DUL%c\n",
711 FLAG(cmd, PCI_HT_SEC_CMD_WR),
712 FLAG(cmd, PCI_HT_SEC_CMD_DE),
713 (cmd & PCI_HT_SEC_CMD_DN) >> 2,
714 FLAG(cmd, PCI_HT_SEC_CMD_CS),
715 FLAG(cmd, PCI_HT_SEC_CMD_HH),
716 FLAG(cmd, PCI_HT_SEC_CMD_AS),
717 FLAG(cmd, PCI_HT_SEC_CMD_HIECE),
718 FLAG(cmd, PCI_HT_SEC_CMD_DUL));
719 config_fetch(d, where + PCI_HT_SEC_LCTR, PCI_HT_SEC_SIZEOF - PCI_HT_SEC_LCTR);
720 lctr = get_conf_word(d, where + PCI_HT_SEC_LCTR);
721 printf("\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",
722 FLAG(lctr, PCI_HT_LCTR_CFLE),
723 FLAG(lctr, PCI_HT_LCTR_CST),
724 FLAG(lctr, PCI_HT_LCTR_CFE),
725 FLAG(lctr, PCI_HT_LCTR_LKFAIL),
726 FLAG(lctr, PCI_HT_LCTR_INIT),
727 FLAG(lctr, PCI_HT_LCTR_EOC),
728 FLAG(lctr, PCI_HT_LCTR_TXO),
729 (lctr & PCI_HT_LCTR_CRCERR) >> 8,
730 FLAG(lctr, PCI_HT_LCTR_ISOCEN),
731 FLAG(lctr, PCI_HT_LCTR_LSEN),
732 FLAG(lctr, PCI_HT_LCTR_EXTCTL),
733 FLAG(lctr, PCI_HT_LCTR_64B));
734 lcnf = get_conf_word(d, where + PCI_HT_SEC_LCNF);
735 printf("\t\tLink Config: MLWI=%s DwFcIn%c MLWO=%s DwFcOut%c LWI=%s DwFcInEn%c LWO=%s DwFcOutEn%c\n",
736 ht_link_width(lcnf & PCI_HT_LCNF_MLWI),
737 FLAG(lcnf, PCI_HT_LCNF_DFI),
738 ht_link_width((lcnf & PCI_HT_LCNF_MLWO) >> 4),
739 FLAG(lcnf, PCI_HT_LCNF_DFO),
740 ht_link_width((lcnf & PCI_HT_LCNF_LWI) >> 8),
741 FLAG(lcnf, PCI_HT_LCNF_DFIE),
742 ht_link_width((lcnf & PCI_HT_LCNF_LWO) >> 12),
743 FLAG(lcnf, PCI_HT_LCNF_DFOE));
744 rid = get_conf_byte(d, where + PCI_HT_SEC_RID);
745 printf("\t\tRevision ID: %u.%02u\n",
746 (rid & PCI_HT_RID_MAJ) >> 5, (rid & PCI_HT_RID_MIN));
747 lfrer = get_conf_byte(d, where + PCI_HT_SEC_LFRER);
748 printf("\t\tLink Frequency: %s\n", ht_link_freq(lfrer & PCI_HT_LFRER_FREQ));
749 printf("\t\tLink Error: <Prot%c <Ovfl%c <EOC%c CTLTm%c\n",
750 FLAG(lfrer, PCI_HT_LFRER_PROT),
751 FLAG(lfrer, PCI_HT_LFRER_OV),
752 FLAG(lfrer, PCI_HT_LFRER_EOC),
753 FLAG(lfrer, PCI_HT_LFRER_CTLT));
754 lfcap = get_conf_byte(d, where + PCI_HT_SEC_LFCAP);
755 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",
756 FLAG(lfcap, PCI_HT_LFCAP_200),
757 FLAG(lfcap, PCI_HT_LFCAP_300),
758 FLAG(lfcap, PCI_HT_LFCAP_400),
759 FLAG(lfcap, PCI_HT_LFCAP_500),
760 FLAG(lfcap, PCI_HT_LFCAP_600),
761 FLAG(lfcap, PCI_HT_LFCAP_800),
762 FLAG(lfcap, PCI_HT_LFCAP_1000),
763 FLAG(lfcap, PCI_HT_LFCAP_1200),
764 FLAG(lfcap, PCI_HT_LFCAP_1400),
765 FLAG(lfcap, PCI_HT_LFCAP_1600),
766 FLAG(lfcap, PCI_HT_LFCAP_VEND));
767 ftr = get_conf_word(d, where + PCI_HT_SEC_FTR);
768 printf("\t\tFeature Capability: IsocFC%c LDTSTOP%c CRCTM%c ECTLT%c 64bA%c UIDRD%c ExtRS%c UCnfE%c\n",
769 FLAG(ftr, PCI_HT_FTR_ISOCFC),
770 FLAG(ftr, PCI_HT_FTR_LDTSTOP),
771 FLAG(ftr, PCI_HT_FTR_CRCTM),
772 FLAG(ftr, PCI_HT_FTR_ECTLT),
773 FLAG(ftr, PCI_HT_FTR_64BA),
774 FLAG(ftr, PCI_HT_FTR_UIDRD),
775 FLAG(ftr, PCI_HT_SEC_FTR_EXTRS),
776 FLAG(ftr, PCI_HT_SEC_FTR_UCNFE));
777 if (ftr & PCI_HT_SEC_FTR_EXTRS)
779 eh = get_conf_word(d, where + PCI_HT_SEC_EH);
780 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",
781 FLAG(eh, PCI_HT_EH_PFLE),
782 FLAG(eh, PCI_HT_EH_OFLE),
783 FLAG(eh, PCI_HT_EH_PFE),
784 FLAG(eh, PCI_HT_EH_OFE),
785 FLAG(eh, PCI_HT_EH_EOCFE),
786 FLAG(eh, PCI_HT_EH_RFE),
787 FLAG(eh, PCI_HT_EH_CRCFE),
788 FLAG(eh, PCI_HT_EH_SERRFE),
789 FLAG(eh, PCI_HT_EH_CF),
790 FLAG(eh, PCI_HT_EH_RE),
791 FLAG(eh, PCI_HT_EH_PNFE),
792 FLAG(eh, PCI_HT_EH_ONFE),
793 FLAG(eh, PCI_HT_EH_EOCNFE),
794 FLAG(eh, PCI_HT_EH_RNFE),
795 FLAG(eh, PCI_HT_EH_CRCNFE),
796 FLAG(eh, PCI_HT_EH_SERRNFE));
797 mbu = get_conf_byte(d, where + PCI_HT_SEC_MBU);
798 mlu = get_conf_byte(d, where + PCI_HT_SEC_MLU);
799 printf("\t\tPrefetchable memory behind bridge Upper: %02x-%02x\n", mbu, mlu);
804 show_ht(struct device *d, int where, int cmd)
808 switch (cmd & PCI_HT_CMD_TYP_HI)
810 case PCI_HT_CMD_TYP_HI_PRI:
811 show_ht_pri(d, where, cmd);
813 case PCI_HT_CMD_TYP_HI_SEC:
814 show_ht_sec(d, where, cmd);
818 type = cmd & PCI_HT_CMD_TYP;
821 case PCI_HT_CMD_TYP_SW:
822 printf("HyperTransport: Switch\n");
824 case PCI_HT_CMD_TYP_IDC:
825 printf("HyperTransport: Interrupt Discovery and Configuration\n");
827 case PCI_HT_CMD_TYP_RID:
828 printf("HyperTransport: Revision ID: %u.%02u\n",
829 (cmd & PCI_HT_RID_MAJ) >> 5, (cmd & PCI_HT_RID_MIN));
831 case PCI_HT_CMD_TYP_UIDC:
832 printf("HyperTransport: UnitID Clumping\n");
834 case PCI_HT_CMD_TYP_ECSA:
835 printf("HyperTransport: Extended Configuration Space Access\n");
837 case PCI_HT_CMD_TYP_AM:
838 printf("HyperTransport: Address Mapping\n");
840 case PCI_HT_CMD_TYP_MSIM:
841 printf("HyperTransport: MSI Mapping\n");
843 case PCI_HT_CMD_TYP_DR:
844 printf("HyperTransport: DirectRoute\n");
846 case PCI_HT_CMD_TYP_VCS:
847 printf("HyperTransport: VCSet\n");
849 case PCI_HT_CMD_TYP_RM:
850 printf("HyperTransport: Retry Mode\n");
852 case PCI_HT_CMD_TYP_X86:
853 printf("HyperTransport: X86 (reserved)\n");
856 printf("HyperTransport: #%02x\n", type >> 11);
861 show_rom(struct device *d)
863 struct pci_dev *p = d->dev;
864 pciaddr_t rom = p->rom_base_addr;
865 pciaddr_t len = (p->known_fields & PCI_FILL_SIZES) ? p->rom_size : 0;
869 printf("\tExpansion ROM at ");
870 if (rom & PCI_ROM_ADDRESS_MASK)
871 printf(PCIADDR_T_FMT, rom & PCI_ROM_ADDRESS_MASK);
873 printf("<unassigned>");
874 if (!(rom & PCI_ROM_ADDRESS_ENABLE))
875 printf(" [disabled]");
881 show_msi(struct device *d, int where, int cap)
887 printf("Message Signalled Interrupts: 64bit%c Queue=%d/%d Enable%c\n",
888 FLAG(cap, PCI_MSI_FLAGS_64BIT),
889 (cap & PCI_MSI_FLAGS_QSIZE) >> 4,
890 (cap & PCI_MSI_FLAGS_QMASK) >> 1,
891 FLAG(cap, PCI_MSI_FLAGS_ENABLE));
894 is64 = cap & PCI_MSI_FLAGS_64BIT;
895 if (!config_fetch(d, where + PCI_MSI_ADDRESS_LO, (is64 ? PCI_MSI_DATA_64 : PCI_MSI_DATA_32) + 2 - PCI_MSI_ADDRESS_LO))
897 printf("\t\tAddress: ");
900 t = get_conf_long(d, where + PCI_MSI_ADDRESS_HI);
901 w = get_conf_word(d, where + PCI_MSI_DATA_64);
905 w = get_conf_word(d, where + PCI_MSI_DATA_32);
906 t = get_conf_long(d, where + PCI_MSI_ADDRESS_LO);
907 printf("%08x Data: %04x\n", t, w);
913 int esr = cap & 0xff;
916 printf("Slot ID: %d slots, First%c, chassis %02x\n",
917 esr & PCI_SID_ESR_NSLOTS,
918 FLAG(esr, PCI_SID_ESR_FIC),
923 show_caps(struct device *d)
925 if (get_conf_word(d, PCI_STATUS) & PCI_STATUS_CAP_LIST)
927 int where = get_conf_byte(d, PCI_CAPABILITY_LIST) & ~3;
931 printf("\tCapabilities: ");
932 if (!config_fetch(d, where, 4))
934 puts("<available only to root>");
937 id = get_conf_byte(d, where + PCI_CAP_LIST_ID);
938 next = get_conf_byte(d, where + PCI_CAP_LIST_NEXT) & ~3;
939 cap = get_conf_word(d, where + PCI_CAP_FLAGS);
940 printf("[%02x] ", where);
943 printf("<chain broken>\n");
949 show_pm(d, where, cap);
952 show_agp(d, where, cap);
955 printf("Vital Product Data\n");
957 case PCI_CAP_ID_SLOTID:
961 show_msi(d, where, cap);
963 case PCI_CAP_ID_PCIX:
967 show_ht(d, where, cap);
970 printf("#%02x [%04x]\n", id, cap);
978 show_htype0(struct device *d)
986 show_htype1(struct device *d)
988 u32 io_base = get_conf_byte(d, PCI_IO_BASE);
989 u32 io_limit = get_conf_byte(d, PCI_IO_LIMIT);
990 u32 io_type = io_base & PCI_IO_RANGE_TYPE_MASK;
991 u32 mem_base = get_conf_word(d, PCI_MEMORY_BASE);
992 u32 mem_limit = get_conf_word(d, PCI_MEMORY_LIMIT);
993 u32 mem_type = mem_base & PCI_MEMORY_RANGE_TYPE_MASK;
994 u32 pref_base = get_conf_word(d, PCI_PREF_MEMORY_BASE);
995 u32 pref_limit = get_conf_word(d, PCI_PREF_MEMORY_LIMIT);
996 u32 pref_type = pref_base & PCI_PREF_RANGE_TYPE_MASK;
997 word sec_stat = get_conf_word(d, PCI_SEC_STATUS);
998 word brc = get_conf_word(d, PCI_BRIDGE_CONTROL);
999 int verb = verbose > 2;
1002 printf("\tBus: primary=%02x, secondary=%02x, subordinate=%02x, sec-latency=%d\n",
1003 get_conf_byte(d, PCI_PRIMARY_BUS),
1004 get_conf_byte(d, PCI_SECONDARY_BUS),
1005 get_conf_byte(d, PCI_SUBORDINATE_BUS),
1006 get_conf_byte(d, PCI_SEC_LATENCY_TIMER));
1008 if (io_type != (io_limit & PCI_IO_RANGE_TYPE_MASK) ||
1009 (io_type != PCI_IO_RANGE_TYPE_16 && io_type != PCI_IO_RANGE_TYPE_32))
1010 printf("\t!!! Unknown I/O range types %x/%x\n", io_base, io_limit);
1013 io_base = (io_base & PCI_IO_RANGE_MASK) << 8;
1014 io_limit = (io_limit & PCI_IO_RANGE_MASK) << 8;
1015 if (io_type == PCI_IO_RANGE_TYPE_32)
1017 io_base |= (get_conf_word(d, PCI_IO_BASE_UPPER16) << 16);
1018 io_limit |= (get_conf_word(d, PCI_IO_LIMIT_UPPER16) << 16);
1020 if (io_base <= io_limit || verb)
1021 printf("\tI/O behind bridge: %08x-%08x\n", io_base, io_limit+0xfff);
1024 if (mem_type != (mem_limit & PCI_MEMORY_RANGE_TYPE_MASK) ||
1026 printf("\t!!! Unknown memory range types %x/%x\n", mem_base, mem_limit);
1029 mem_base = (mem_base & PCI_MEMORY_RANGE_MASK) << 16;
1030 mem_limit = (mem_limit & PCI_MEMORY_RANGE_MASK) << 16;
1031 if (mem_base <= mem_limit || verb)
1032 printf("\tMemory behind bridge: %08x-%08x\n", mem_base, mem_limit + 0xfffff);
1035 if (pref_type != (pref_limit & PCI_PREF_RANGE_TYPE_MASK) ||
1036 (pref_type != PCI_PREF_RANGE_TYPE_32 && pref_type != PCI_PREF_RANGE_TYPE_64))
1037 printf("\t!!! Unknown prefetchable memory range types %x/%x\n", pref_base, pref_limit);
1040 pref_base = (pref_base & PCI_PREF_RANGE_MASK) << 16;
1041 pref_limit = (pref_limit & PCI_PREF_RANGE_MASK) << 16;
1042 if (pref_base <= pref_limit || verb)
1044 if (pref_type == PCI_PREF_RANGE_TYPE_32)
1045 printf("\tPrefetchable memory behind bridge: %08x-%08x\n", pref_base, pref_limit + 0xfffff);
1047 printf("\tPrefetchable memory behind bridge: %08x%08x-%08x%08x\n",
1048 get_conf_long(d, PCI_PREF_BASE_UPPER32),
1050 get_conf_long(d, PCI_PREF_LIMIT_UPPER32),
1056 printf("\tSecondary status: 66Mhz%c FastB2B%c ParErr%c DEVSEL=%s >TAbort%c <TAbort%c <MAbort%c <SERR%c <PERR%c\n",
1057 FLAG(sec_stat, PCI_STATUS_66MHZ),
1058 FLAG(sec_stat, PCI_STATUS_FAST_BACK),
1059 FLAG(sec_stat, PCI_STATUS_PARITY),
1060 ((sec_stat & PCI_STATUS_DEVSEL_MASK) == PCI_STATUS_DEVSEL_SLOW) ? "slow" :
1061 ((sec_stat & PCI_STATUS_DEVSEL_MASK) == PCI_STATUS_DEVSEL_MEDIUM) ? "medium" :
1062 ((sec_stat & PCI_STATUS_DEVSEL_MASK) == PCI_STATUS_DEVSEL_FAST) ? "fast" : "??",
1063 FLAG(sec_stat, PCI_STATUS_SIG_TARGET_ABORT),
1064 FLAG(sec_stat, PCI_STATUS_REC_TARGET_ABORT),
1065 FLAG(sec_stat, PCI_STATUS_REC_MASTER_ABORT),
1066 FLAG(sec_stat, PCI_STATUS_SIG_SYSTEM_ERROR),
1067 FLAG(sec_stat, PCI_STATUS_DETECTED_PARITY));
1072 printf("\tBridgeCtl: Parity%c SERR%c NoISA%c VGA%c MAbort%c >Reset%c FastB2B%c\n",
1073 FLAG(brc, PCI_BRIDGE_CTL_PARITY),
1074 FLAG(brc, PCI_BRIDGE_CTL_SERR),
1075 FLAG(brc, PCI_BRIDGE_CTL_NO_ISA),
1076 FLAG(brc, PCI_BRIDGE_CTL_VGA),
1077 FLAG(brc, PCI_BRIDGE_CTL_MASTER_ABORT),
1078 FLAG(brc, PCI_BRIDGE_CTL_BUS_RESET),
1079 FLAG(brc, PCI_BRIDGE_CTL_FAST_BACK));
1085 show_htype2(struct device *d)
1088 word cmd = get_conf_word(d, PCI_COMMAND);
1089 word brc = get_conf_word(d, PCI_CB_BRIDGE_CONTROL);
1090 word exca = get_conf_word(d, PCI_CB_LEGACY_MODE_BASE);
1091 int verb = verbose > 2;
1094 printf("\tBus: primary=%02x, secondary=%02x, subordinate=%02x, sec-latency=%d\n",
1095 get_conf_byte(d, PCI_CB_PRIMARY_BUS),
1096 get_conf_byte(d, PCI_CB_CARD_BUS),
1097 get_conf_byte(d, PCI_CB_SUBORDINATE_BUS),
1098 get_conf_byte(d, PCI_CB_LATENCY_TIMER));
1102 u32 base = get_conf_long(d, PCI_CB_MEMORY_BASE_0 + p);
1103 u32 limit = get_conf_long(d, PCI_CB_MEMORY_LIMIT_0 + p);
1104 if (limit > base || verb)
1105 printf("\tMemory window %d: %08x-%08x%s%s\n", i, base, limit,
1106 (cmd & PCI_COMMAND_MEMORY) ? "" : " [disabled]",
1107 (brc & (PCI_CB_BRIDGE_CTL_PREFETCH_MEM0 << i)) ? " (prefetchable)" : "");
1112 u32 base = get_conf_long(d, PCI_CB_IO_BASE_0 + p);
1113 u32 limit = get_conf_long(d, PCI_CB_IO_LIMIT_0 + p);
1114 if (!(base & PCI_IO_RANGE_TYPE_32))
1119 base &= PCI_CB_IO_RANGE_MASK;
1120 limit = (limit & PCI_CB_IO_RANGE_MASK) + 3;
1121 if (base <= limit || verb)
1122 printf("\tI/O window %d: %08x-%08x%s\n", i, base, limit,
1123 (cmd & PCI_COMMAND_IO) ? "" : " [disabled]");
1126 if (get_conf_word(d, PCI_CB_SEC_STATUS) & PCI_STATUS_SIG_SYSTEM_ERROR)
1127 printf("\tSecondary status: SERR\n");
1129 printf("\tBridgeCtl: Parity%c SERR%c ISA%c VGA%c MAbort%c >Reset%c 16bInt%c PostWrite%c\n",
1130 FLAG(brc, PCI_CB_BRIDGE_CTL_PARITY),
1131 FLAG(brc, PCI_CB_BRIDGE_CTL_SERR),
1132 FLAG(brc, PCI_CB_BRIDGE_CTL_ISA),
1133 FLAG(brc, PCI_CB_BRIDGE_CTL_VGA),
1134 FLAG(brc, PCI_CB_BRIDGE_CTL_MASTER_ABORT),
1135 FLAG(brc, PCI_CB_BRIDGE_CTL_CB_RESET),
1136 FLAG(brc, PCI_CB_BRIDGE_CTL_16BIT_INT),
1137 FLAG(brc, PCI_CB_BRIDGE_CTL_POST_WRITES));
1139 printf("\t16-bit legacy interface ports at %04x\n", exca);
1143 show_verbose(struct device *d)
1145 struct pci_dev *p = d->dev;
1146 word status = get_conf_word(d, PCI_STATUS);
1147 word cmd = get_conf_word(d, PCI_COMMAND);
1148 word class = get_conf_word(d, PCI_CLASS_DEVICE);
1149 byte bist = get_conf_byte(d, PCI_BIST);
1150 byte htype = get_conf_byte(d, PCI_HEADER_TYPE) & 0x7f;
1151 byte latency = get_conf_byte(d, PCI_LATENCY_TIMER);
1152 byte cache_line = get_conf_byte(d, PCI_CACHE_LINE_SIZE);
1153 byte max_lat, min_gnt;
1154 byte int_pin = get_conf_byte(d, PCI_INTERRUPT_PIN);
1155 unsigned int irq = p->irq;
1156 word subsys_v, subsys_d;
1157 char ssnamebuf[256];
1163 case PCI_HEADER_TYPE_NORMAL:
1164 if (class == PCI_CLASS_BRIDGE_PCI)
1165 printf("\t!!! Invalid class %04x for header type %02x\n", class, htype);
1166 max_lat = get_conf_byte(d, PCI_MAX_LAT);
1167 min_gnt = get_conf_byte(d, PCI_MIN_GNT);
1168 subsys_v = get_conf_word(d, PCI_SUBSYSTEM_VENDOR_ID);
1169 subsys_d = get_conf_word(d, PCI_SUBSYSTEM_ID);
1171 case PCI_HEADER_TYPE_BRIDGE:
1172 if ((class >> 8) != PCI_BASE_CLASS_BRIDGE)
1173 printf("\t!!! Invalid class %04x for header type %02x\n", class, htype);
1174 irq = int_pin = min_gnt = max_lat = 0;
1175 subsys_v = subsys_d = 0;
1177 case PCI_HEADER_TYPE_CARDBUS:
1178 if ((class >> 8) != PCI_BASE_CLASS_BRIDGE)
1179 printf("\t!!! Invalid class %04x for header type %02x\n", class, htype);
1180 min_gnt = max_lat = 0;
1181 subsys_v = get_conf_word(d, PCI_CB_SUBSYSTEM_VENDOR_ID);
1182 subsys_d = get_conf_word(d, PCI_CB_SUBSYSTEM_ID);
1185 printf("\t!!! Unknown header type %02x\n", htype);
1189 if (subsys_v && subsys_v != 0xffff)
1190 printf("\tSubsystem: %s\n",
1191 pci_lookup_name(pacc, ssnamebuf, sizeof(ssnamebuf),
1192 PCI_LOOKUP_SUBSYSTEM | PCI_LOOKUP_VENDOR | PCI_LOOKUP_DEVICE,
1193 p->vendor_id, p->device_id, subsys_v, subsys_d));
1197 printf("\tControl: I/O%c Mem%c BusMaster%c SpecCycle%c MemWINV%c VGASnoop%c ParErr%c Stepping%c SERR%c FastB2B%c\n",
1198 FLAG(cmd, PCI_COMMAND_IO),
1199 FLAG(cmd, PCI_COMMAND_MEMORY),
1200 FLAG(cmd, PCI_COMMAND_MASTER),
1201 FLAG(cmd, PCI_COMMAND_SPECIAL),
1202 FLAG(cmd, PCI_COMMAND_INVALIDATE),
1203 FLAG(cmd, PCI_COMMAND_VGA_PALETTE),
1204 FLAG(cmd, PCI_COMMAND_PARITY),
1205 FLAG(cmd, PCI_COMMAND_WAIT),
1206 FLAG(cmd, PCI_COMMAND_SERR),
1207 FLAG(cmd, PCI_COMMAND_FAST_BACK));
1208 printf("\tStatus: Cap%c 66Mhz%c UDF%c FastB2B%c ParErr%c DEVSEL=%s >TAbort%c <TAbort%c <MAbort%c >SERR%c <PERR%c\n",
1209 FLAG(status, PCI_STATUS_CAP_LIST),
1210 FLAG(status, PCI_STATUS_66MHZ),
1211 FLAG(status, PCI_STATUS_UDF),
1212 FLAG(status, PCI_STATUS_FAST_BACK),
1213 FLAG(status, PCI_STATUS_PARITY),
1214 ((status & PCI_STATUS_DEVSEL_MASK) == PCI_STATUS_DEVSEL_SLOW) ? "slow" :
1215 ((status & PCI_STATUS_DEVSEL_MASK) == PCI_STATUS_DEVSEL_MEDIUM) ? "medium" :
1216 ((status & PCI_STATUS_DEVSEL_MASK) == PCI_STATUS_DEVSEL_FAST) ? "fast" : "??",
1217 FLAG(status, PCI_STATUS_SIG_TARGET_ABORT),
1218 FLAG(status, PCI_STATUS_REC_TARGET_ABORT),
1219 FLAG(status, PCI_STATUS_REC_MASTER_ABORT),
1220 FLAG(status, PCI_STATUS_SIG_SYSTEM_ERROR),
1221 FLAG(status, PCI_STATUS_DETECTED_PARITY));
1222 if (cmd & PCI_COMMAND_MASTER)
1224 printf("\tLatency: %d", latency);
1225 if (min_gnt || max_lat)
1229 printf("%dns min", min_gnt*250);
1230 if (min_gnt && max_lat)
1233 printf("%dns max", max_lat*250);
1237 printf(", Cache Line Size %02x", cache_line);
1241 printf("\tInterrupt: pin %c routed to IRQ " PCIIRQ_FMT "\n",
1242 (int_pin ? 'A' + int_pin - 1 : '?'), irq);
1246 printf("\tFlags: ");
1247 if (cmd & PCI_COMMAND_MASTER)
1248 printf("bus master, ");
1249 if (cmd & PCI_COMMAND_VGA_PALETTE)
1250 printf("VGA palette snoop, ");
1251 if (cmd & PCI_COMMAND_WAIT)
1252 printf("stepping, ");
1253 if (cmd & PCI_COMMAND_FAST_BACK)
1254 printf("fast Back2Back, ");
1255 if (status & PCI_STATUS_66MHZ)
1257 if (status & PCI_STATUS_UDF)
1258 printf("user-definable features, ");
1260 ((status & PCI_STATUS_DEVSEL_MASK) == PCI_STATUS_DEVSEL_SLOW) ? "slow" :
1261 ((status & PCI_STATUS_DEVSEL_MASK) == PCI_STATUS_DEVSEL_MEDIUM) ? "medium" :
1262 ((status & PCI_STATUS_DEVSEL_MASK) == PCI_STATUS_DEVSEL_FAST) ? "fast" : "??");
1263 if (cmd & PCI_COMMAND_MASTER)
1264 printf(", latency %d", latency);
1266 printf(", IRQ " PCIIRQ_FMT, irq);
1270 if (bist & PCI_BIST_CAPABLE)
1272 if (bist & PCI_BIST_START)
1273 printf("\tBIST is running\n");
1275 printf("\tBIST result: %02x\n", bist & PCI_BIST_CODE_MASK);
1280 case PCI_HEADER_TYPE_NORMAL:
1283 case PCI_HEADER_TYPE_BRIDGE:
1286 case PCI_HEADER_TYPE_CARDBUS:
1293 show_hex_dump(struct device *d)
1295 unsigned int i, cnt;
1297 cnt = d->config_cnt;
1298 if (show_hex >= 3 && config_fetch(d, cnt, 256-cnt))
1301 if (show_hex >= 4 && config_fetch(d, 256, 4096-256))
1305 for(i=0; i<cnt; i++)
1309 printf(" %02x", get_conf_byte(d, i));
1316 show_machine(struct device *d)
1318 struct pci_dev *p = d->dev;
1320 word sv_id=0, sd_id=0;
1321 char classbuf[128], vendbuf[128], devbuf[128], svbuf[128], sdbuf[128];
1323 switch (get_conf_byte(d, PCI_HEADER_TYPE) & 0x7f)
1325 case PCI_HEADER_TYPE_NORMAL:
1326 sv_id = get_conf_word(d, PCI_SUBSYSTEM_VENDOR_ID);
1327 sd_id = get_conf_word(d, PCI_SUBSYSTEM_ID);
1329 case PCI_HEADER_TYPE_CARDBUS:
1330 sv_id = get_conf_word(d, PCI_CB_SUBSYSTEM_VENDOR_ID);
1331 sd_id = get_conf_word(d, PCI_CB_SUBSYSTEM_ID);
1337 printf("Device:\t");
1340 printf("Class:\t%s\n",
1341 pci_lookup_name(pacc, classbuf, sizeof(classbuf), PCI_LOOKUP_CLASS, get_conf_word(d, PCI_CLASS_DEVICE), 0, 0, 0));
1342 printf("Vendor:\t%s\n",
1343 pci_lookup_name(pacc, vendbuf, sizeof(vendbuf), PCI_LOOKUP_VENDOR, p->vendor_id, p->device_id, 0, 0));
1344 printf("Device:\t%s\n",
1345 pci_lookup_name(pacc, devbuf, sizeof(devbuf), PCI_LOOKUP_DEVICE, p->vendor_id, p->device_id, 0, 0));
1346 if (sv_id && sv_id != 0xffff)
1348 printf("SVendor:\t%s\n",
1349 pci_lookup_name(pacc, svbuf, sizeof(svbuf), PCI_LOOKUP_SUBSYSTEM | PCI_LOOKUP_VENDOR, p->vendor_id, p->device_id, sv_id, sd_id));
1350 printf("SDevice:\t%s\n",
1351 pci_lookup_name(pacc, sdbuf, sizeof(sdbuf), PCI_LOOKUP_SUBSYSTEM | PCI_LOOKUP_DEVICE, p->vendor_id, p->device_id, sv_id, sd_id));
1353 if (c = get_conf_byte(d, PCI_REVISION_ID))
1354 printf("Rev:\t%02x\n", c);
1355 if (c = get_conf_byte(d, PCI_CLASS_PROG))
1356 printf("ProgIf:\t%02x\n", c);
1361 printf(" \"%s\" \"%s\" \"%s\"",
1362 pci_lookup_name(pacc, classbuf, sizeof(classbuf), PCI_LOOKUP_CLASS,
1363 get_conf_word(d, PCI_CLASS_DEVICE), 0, 0, 0),
1364 pci_lookup_name(pacc, vendbuf, sizeof(vendbuf), PCI_LOOKUP_VENDOR,
1365 p->vendor_id, p->device_id, 0, 0),
1366 pci_lookup_name(pacc, devbuf, sizeof(devbuf), PCI_LOOKUP_DEVICE,
1367 p->vendor_id, p->device_id, 0, 0));
1368 if (c = get_conf_byte(d, PCI_REVISION_ID))
1369 printf(" -r%02x", c);
1370 if (c = get_conf_byte(d, PCI_CLASS_PROG))
1371 printf(" -p%02x", c);
1372 if (sv_id && sv_id != 0xffff)
1373 printf(" \"%s\" \"%s\"",
1374 pci_lookup_name(pacc, svbuf, sizeof(svbuf), PCI_LOOKUP_SUBSYSTEM | PCI_LOOKUP_VENDOR, p->vendor_id, p->device_id, sv_id, sd_id),
1375 pci_lookup_name(pacc, sdbuf, sizeof(sdbuf), PCI_LOOKUP_SUBSYSTEM | PCI_LOOKUP_DEVICE, p->vendor_id, p->device_id, sv_id, sd_id));
1377 printf(" \"\" \"\"");
1383 show_device(struct device *d)
1385 if (machine_readable)
1393 if (verbose || show_hex)
1402 for(d=first_dev; d; d=d->next)
1409 struct bridge *chain; /* Single-linked list of bridges */
1410 struct bridge *next, *child; /* Tree of bridges */
1411 struct bus *first_bus; /* List of busses connected to this bridge */
1412 unsigned int domain;
1413 unsigned int primary, secondary, subordinate; /* Bus numbers */
1414 struct device *br_dev;
1418 unsigned int domain;
1419 unsigned int number;
1420 struct bus *sibling;
1421 struct device *first_dev, **last_dev;
1424 static struct bridge host_bridge = { NULL, NULL, NULL, NULL, 0, ~0, 0, ~0, NULL };
1427 find_bus(struct bridge *b, unsigned int domain, unsigned int n)
1431 for(bus=b->first_bus; bus; bus=bus->sibling)
1432 if (bus->domain == domain && bus->number == n)
1438 new_bus(struct bridge *b, unsigned int domain, unsigned int n)
1440 struct bus *bus = xmalloc(sizeof(struct bus));
1442 bus = xmalloc(sizeof(struct bus));
1443 bus->domain = domain;
1445 bus->sibling = b->first_bus;
1446 bus->first_dev = NULL;
1447 bus->last_dev = &bus->first_dev;
1453 insert_dev(struct device *d, struct bridge *b)
1455 struct pci_dev *p = d->dev;
1458 if (! (bus = find_bus(b, p->domain, p->bus)))
1461 for(c=b->child; c; c=c->next)
1462 if (c->domain == p->domain && c->secondary <= p->bus && p->bus <= c->subordinate)
1467 bus = new_bus(b, p->domain, p->bus);
1469 /* Simple insertion at the end _does_ guarantee the correct order as the
1470 * original device list was sorted by (domain, bus, devfn) lexicographically
1471 * and all devices on the new list have the same bus number.
1474 bus->last_dev = &d->next;
1481 struct device *d, *d2;
1482 struct bridge **last_br, *b;
1484 /* Build list of bridges */
1486 last_br = &host_bridge.chain;
1487 for(d=first_dev; d; d=d->next)
1489 word class = get_conf_word(d, PCI_CLASS_DEVICE);
1490 byte ht = get_conf_byte(d, PCI_HEADER_TYPE) & 0x7f;
1491 if (class == PCI_CLASS_BRIDGE_PCI &&
1492 (ht == PCI_HEADER_TYPE_BRIDGE || ht == PCI_HEADER_TYPE_CARDBUS))
1494 b = xmalloc(sizeof(struct bridge));
1495 b->domain = d->dev->domain;
1496 if (ht == PCI_HEADER_TYPE_BRIDGE)
1498 b->primary = get_conf_byte(d, PCI_CB_PRIMARY_BUS);
1499 b->secondary = get_conf_byte(d, PCI_CB_CARD_BUS);
1500 b->subordinate = get_conf_byte(d, PCI_CB_SUBORDINATE_BUS);
1504 b->primary = get_conf_byte(d, PCI_PRIMARY_BUS);
1505 b->secondary = get_conf_byte(d, PCI_SECONDARY_BUS);
1506 b->subordinate = get_conf_byte(d, PCI_SUBORDINATE_BUS);
1509 last_br = &b->chain;
1510 b->next = b->child = NULL;
1511 b->first_bus = NULL;
1517 /* Create a bridge tree */
1519 for(b=&host_bridge; b; b=b->chain)
1521 struct bridge *c, *best;
1523 for(c=&host_bridge; c; c=c->chain)
1524 if (c != b && (c == &host_bridge || b->domain == c->domain) &&
1525 b->primary >= c->secondary && b->primary <= c->subordinate &&
1526 (!best || best->subordinate - best->primary > c->subordinate - c->primary))
1530 b->next = best->child;
1535 /* Insert secondary bus for each bridge */
1537 for(b=&host_bridge; b; b=b->chain)
1538 if (!find_bus(b, b->domain, b->secondary))
1539 new_bus(b, b->domain, b->secondary);
1541 /* Create bus structs and link devices */
1543 for(d=first_dev; d;)
1546 insert_dev(d, &host_bridge);
1552 print_it(byte *line, byte *p)
1556 fputs(line, stdout);
1557 for(p=line; *p; p++)
1558 if (*p == '+' || *p == '|')
1564 static void show_tree_bridge(struct bridge *, byte *, byte *);
1567 show_tree_dev(struct device *d, byte *line, byte *p)
1569 struct pci_dev *q = d->dev;
1573 p += sprintf(p, "%02x.%x", q->dev, q->func);
1574 for(b=&host_bridge; b; b=b->chain)
1577 if (b->secondary == b->subordinate)
1578 p += sprintf(p, "-[%04x:%02x]-", b->domain, b->secondary);
1580 p += sprintf(p, "-[%04x:%02x-%02x]-", b->domain, b->secondary, b->subordinate);
1581 show_tree_bridge(b, line, p);
1585 p += sprintf(p, " %s",
1586 pci_lookup_name(pacc, namebuf, sizeof(namebuf),
1587 PCI_LOOKUP_VENDOR | PCI_LOOKUP_DEVICE,
1588 q->vendor_id, q->device_id, 0, 0));
1593 show_tree_bus(struct bus *b, byte *line, byte *p)
1597 else if (!b->first_dev->next)
1601 show_tree_dev(b->first_dev, line, p);
1605 struct device *d = b->first_dev;
1610 show_tree_dev(d, line, p+2);
1615 show_tree_dev(d, line, p+2);
1620 show_tree_bridge(struct bridge *b, byte *line, byte *p)
1623 if (!b->first_bus->sibling)
1625 if (b == &host_bridge)
1626 p += sprintf(p, "[%04x:%02x]-", b->domain, b->first_bus->number);
1627 show_tree_bus(b->first_bus, line, p);
1631 struct bus *u = b->first_bus;
1636 k = p + sprintf(p, "+-[%04x:%02x]-", u->domain, u->number);
1637 show_tree_bus(u, line, k);
1640 k = p + sprintf(p, "\\-[%04x:%02x]-", u->domain, u->number);
1641 show_tree_bus(u, line, k);
1651 show_tree_bridge(&host_bridge, line, line);
1654 /* Bus mapping mode */
1657 struct bus_bridge *next;
1658 byte this, dev, func, first, last, bug;
1664 struct bus_bridge *bridges, *via;
1667 static struct bus_info *bus_info;
1670 map_bridge(struct bus_info *bi, struct device *d, int np, int ns, int nl)
1672 struct bus_bridge *b = xmalloc(sizeof(struct bus_bridge));
1673 struct pci_dev *p = d->dev;
1675 b->next = bi->bridges;
1677 b->this = get_conf_byte(d, np);
1680 b->first = get_conf_byte(d, ns);
1681 b->last = get_conf_byte(d, nl);
1682 printf("## %02x.%02x:%d is a bridge from %02x to %02x-%02x\n",
1683 p->bus, p->dev, p->func, b->this, b->first, b->last);
1684 if (b->this != p->bus)
1685 printf("!!! Bridge points to invalid primary bus.\n");
1686 if (b->first > b->last)
1688 printf("!!! Bridge points to invalid bus range.\n");
1697 int verbose = pacc->debugging;
1698 struct bus_info *bi = bus_info + bus;
1702 printf("Mapping bus %02x\n", bus);
1703 for(dev = 0; dev < 32; dev++)
1704 if (filter.slot < 0 || filter.slot == dev)
1707 for(func = 0; func < func_limit; func++)
1708 if (filter.func < 0 || filter.func == func)
1710 /* XXX: Bus mapping supports only domain 0 */
1711 struct pci_dev *p = pci_get_dev(pacc, 0, bus, dev, func);
1712 u16 vendor = pci_read_word(p, PCI_VENDOR_ID);
1713 if (vendor && vendor != 0xffff)
1715 if (!func && (pci_read_byte(p, PCI_HEADER_TYPE) & 0x80))
1718 printf("Discovered device %02x:%02x.%d\n", bus, dev, func);
1720 if (d = scan_device(p))
1723 switch (get_conf_byte(d, PCI_HEADER_TYPE) & 0x7f)
1725 case PCI_HEADER_TYPE_BRIDGE:
1726 map_bridge(bi, d, PCI_PRIMARY_BUS, PCI_SECONDARY_BUS, PCI_SUBORDINATE_BUS);
1728 case PCI_HEADER_TYPE_CARDBUS:
1729 map_bridge(bi, d, PCI_CB_PRIMARY_BUS, PCI_CB_CARD_BUS, PCI_CB_SUBORDINATE_BUS);
1735 printf("But it was filtered out.\n");
1743 do_map_bridges(int bus, int min, int max)
1745 struct bus_info *bi = bus_info + bus;
1746 struct bus_bridge *b;
1749 for(b=bi->bridges; b; b=b->next)
1751 if (bus_info[b->first].guestbook)
1753 else if (b->first < min || b->last > max)
1757 bus_info[b->first].via = b;
1758 do_map_bridges(b->first, b->first, b->last);
1768 printf("\nSummary of buses:\n\n");
1769 for(i=0; i<256; i++)
1770 if (bus_info[i].exists && !bus_info[i].guestbook)
1771 do_map_bridges(i, 0, 255);
1772 for(i=0; i<256; i++)
1774 struct bus_info *bi = bus_info + i;
1775 struct bus_bridge *b = bi->via;
1779 printf("%02x: ", i);
1781 printf("Entered via %02x:%02x.%d\n", b->this, b->dev, b->func);
1783 printf("Primary host bus\n");
1785 printf("Secondary host bus (?)\n");
1787 for(b=bi->bridges; b; b=b->next)
1789 printf("\t%02x.%d Bridge to %02x-%02x", b->dev, b->func, b->first, b->last);
1793 printf(" <overlap bug>");
1796 printf(" <crossing bug>");
1807 if (pacc->method == PCI_ACCESS_PROC_BUS_PCI ||
1808 pacc->method == PCI_ACCESS_DUMP)
1809 printf("WARNING: Bus mapping can be reliable only with direct hardware access enabled.\n\n");
1810 bus_info = xmalloc(sizeof(struct bus_info) * 256);
1811 bzero(bus_info, sizeof(struct bus_info) * 256);
1812 if (filter.bus >= 0)
1813 do_map_bus(filter.bus);
1817 for(bus=0; bus<256; bus++)
1826 main(int argc, char **argv)
1831 if (argc == 2 && !strcmp(argv[1], "--version"))
1833 puts("lspci version " PCIUTILS_VERSION);
1839 pci_filter_init(pacc, &filter);
1841 while ((i = getopt(argc, argv, options)) != -1)
1845 pacc->numeric_ids = 1;
1851 pacc->buscentric = 1;
1852 buscentric_view = 1;
1855 if (msg = pci_filter_parse_slot(&filter, optarg))
1859 if (msg = pci_filter_parse_id(&filter, optarg))
1869 pacc->id_file_name = optarg;
1878 if (parse_generic_option(i, pacc, optarg))
1881 fprintf(stderr, help_msg, pacc->id_file_name);