2 * The PCI Utilities -- List All PCI Devices
4 * Copyright (c) 1997--2020 Martin Mares <mj@ucw.cz>
6 * Can be freely distributed and used under the terms of the GNU GPL v2+.
8 * SPDX-License-Identifier: GPL-2.0-or-later
20 int verbose
; /* Show detailed information */
21 static int opt_hex
; /* Show contents of config space as hexadecimal numbers */
22 struct pci_filter filter
; /* Device filter */
23 static int opt_filter
; /* Any filter was given */
24 static int opt_tree
; /* Show bus tree */
25 static int opt_path
; /* Show bridge path */
26 static int opt_machine
; /* Generate machine-readable output */
27 static int opt_map_mode
; /* Bus mapping mode enabled */
28 static int opt_domains
; /* Show domain numbers (0=disabled, 1=auto-detected, 2=requested) */
29 static int opt_kernel
; /* Show kernel drivers */
30 static int opt_query_dns
; /* Query the DNS (0=disabled, 1=enabled, 2=refresh cache) */
31 static int opt_query_all
; /* Query the DNS for all entries */
32 char *opt_pcimap
; /* Override path to Linux modules.pcimap */
34 const char program_name
[] = "lspci";
36 static char options
[] = "nvbxs:d:tPi:mgp:qkMDQ" GENERIC_OPTIONS
;
38 static char help_msg
[] =
39 "Usage: lspci [<switches>]\n"
41 "Basic display modes:\n"
42 "-mm\t\tProduce machine-readable output (single -m for an obsolete format)\n"
43 "-t\t\tShow bus tree\n"
46 "-v\t\tBe verbose (-vv or -vvv for higher verbosity)\n"
48 "-k\t\tShow kernel drivers handling each device\n"
50 "-x\t\tShow hex-dump of the standard part of the config space\n"
51 "-xxx\t\tShow hex-dump of the whole config space (dangerous; root only)\n"
52 "-xxxx\t\tShow hex-dump of the 4096-byte extended config space (root only)\n"
53 "-b\t\tBus-centric view (addresses and IRQ's as seen by the bus)\n"
54 "-D\t\tAlways show domain numbers\n"
55 "-P\t\tDisplay bridge path in addition to bus and device number\n"
56 "-PP\t\tDisplay bus path in addition to bus and device number\n"
58 "Resolving of device ID's to names:\n"
59 "-n\t\tShow numeric ID's\n"
60 "-nn\t\tShow both textual and numeric ID's (names & numbers)\n"
62 "-q\t\tQuery the PCI ID database for unknown ID's via DNS\n"
63 "-qq\t\tAs above, but re-query locally cached entries\n"
64 "-Q\t\tQuery the PCI ID database for all ID's via DNS\n"
67 "Selection of devices:\n"
68 "-s [[[[<domain>]:]<bus>]:][<slot>][.[<func>]]\tShow only devices in selected slots\n"
69 "-d [<vendor>]:[<device>][:<class>]\t\tShow only devices with specified ID's\n"
72 "-i <file>\tUse specified ID database instead of %s\n"
74 "-p <file>\tLook up kernel modules in a given file instead of default modules.pcimap\n"
76 "-M\t\tEnable `bus mapping' mode (dangerous; root only)\n"
78 "PCI access options:\n"
82 /*** Our view of the PCI bus ***/
84 struct pci_access
*pacc
;
85 struct device
*first_dev
;
86 static int seen_errors
;
87 static int need_topology
;
90 config_fetch(struct device
*d
, unsigned int pos
, unsigned int len
)
92 unsigned int end
= pos
+len
;
95 while (pos
< d
->config_bufsize
&& len
&& d
->present
[pos
])
97 while (pos
+len
<= d
->config_bufsize
&& len
&& d
->present
[pos
+len
-1])
102 if (end
> d
->config_bufsize
)
104 int orig_size
= d
->config_bufsize
;
105 while (end
> d
->config_bufsize
)
106 d
->config_bufsize
*= 2;
107 d
->config
= xrealloc(d
->config
, d
->config_bufsize
);
108 d
->present
= xrealloc(d
->present
, d
->config_bufsize
);
109 memset(d
->present
+ orig_size
, 0, d
->config_bufsize
- orig_size
);
110 pci_setup_cache(d
->dev
, d
->config
, d
->dev
->cache_len
);
112 result
= pci_read_block(d
->dev
, pos
, d
->config
+ pos
, len
);
114 memset(d
->present
+ pos
, 1, len
);
119 scan_device(struct pci_dev
*p
)
123 if (p
->domain
&& !opt_domains
)
125 if (!pci_filter_match(&filter
, p
) && !need_topology
)
127 d
= xmalloc(sizeof(struct device
));
128 memset(d
, 0, sizeof(*d
));
130 d
->no_config_access
= p
->no_config_access
;
131 d
->config_cached
= d
->config_bufsize
= 64;
132 d
->config
= xmalloc(64);
133 d
->present
= xmalloc(64);
134 memset(d
->present
, 1, 64);
135 if (!d
->no_config_access
&& !pci_read_block(p
, 0, d
->config
, 64))
137 d
->no_config_access
= 1;
138 d
->config_cached
= d
->config_bufsize
= 0;
139 memset(d
->present
, 0, 64);
141 if (!d
->no_config_access
&& (d
->config
[PCI_HEADER_TYPE
] & 0x7f) == PCI_HEADER_TYPE_CARDBUS
)
143 /* For cardbus bridges, we need to fetch 64 bytes more to get the
144 * full standard header... */
145 if (config_fetch(d
, 64, 64))
146 d
->config_cached
+= 64;
148 pci_setup_cache(p
, d
->config
, d
->config_cached
);
149 pci_fill_info(p
, PCI_FILL_IDENT
| PCI_FILL_CLASS
| PCI_FILL_CLASS_EXT
| PCI_FILL_SUBSYS
| (need_topology
? PCI_FILL_PARENT
: 0));
160 for (p
=pacc
->devices
; p
; p
=p
->next
)
161 if (d
= scan_device(p
))
168 /*** Config space accesses ***/
171 check_conf_range(struct device
*d
, unsigned int pos
, unsigned int len
)
174 if (!d
->present
[pos
])
175 die("Internal bug: Accessing non-read configuration byte at position %x", pos
);
181 get_conf_byte(struct device
*d
, unsigned int pos
)
183 check_conf_range(d
, pos
, 1);
184 return d
->config
[pos
];
188 get_conf_word(struct device
*d
, unsigned int pos
)
190 check_conf_range(d
, pos
, 2);
191 return d
->config
[pos
] | (d
->config
[pos
+1] << 8);
195 get_conf_long(struct device
*d
, unsigned int pos
)
197 check_conf_range(d
, pos
, 4);
198 return d
->config
[pos
] |
199 (d
->config
[pos
+1] << 8) |
200 (d
->config
[pos
+2] << 16) |
201 (d
->config
[pos
+3] << 24);
207 compare_them(const void *A
, const void *B
)
209 const struct pci_dev
*a
= (*(const struct device
**)A
)->dev
;
210 const struct pci_dev
*b
= (*(const struct device
**)B
)->dev
;
212 if (a
->domain
< b
->domain
)
214 if (a
->domain
> b
->domain
)
224 if (a
->func
< b
->func
)
226 if (a
->func
> b
->func
)
234 struct device
**index
, **h
, **last_dev
;
239 for (d
=first_dev
; d
; d
=d
->next
)
241 h
= index
= alloca(sizeof(struct device
*) * cnt
);
242 for (d
=first_dev
; d
; d
=d
->next
)
244 qsort(index
, cnt
, sizeof(struct device
*), compare_them
);
245 last_dev
= &first_dev
;
250 last_dev
= &(*h
)->next
;
256 /*** Normal output ***/
259 show_slot_path(struct device
*d
)
261 struct pci_dev
*p
= d
->dev
;
265 struct bus
*bus
= d
->parent_bus
;
266 struct bridge
*br
= bus
->parent_bridge
;
268 if (br
&& br
->br_dev
)
270 show_slot_path(br
->br_dev
);
272 printf("/%02x:%02x.%d", p
->bus
, p
->dev
, p
->func
);
274 printf("/%02x.%d", p
->dev
, p
->func
);
278 printf("%02x:%02x.%d", p
->bus
, p
->dev
, p
->func
);
282 show_slot_name(struct device
*d
)
284 struct pci_dev
*p
= d
->dev
;
286 if (!opt_machine
? opt_domains
: (p
->domain
|| opt_domains
>= 2))
287 printf("%04x:", p
->domain
);
292 show_terse(struct device
*d
)
295 struct pci_dev
*p
= d
->dev
;
296 char classbuf
[256], devbuf
[256];
300 pci_lookup_name(pacc
, classbuf
, sizeof(classbuf
),
303 pci_lookup_name(pacc
, devbuf
, sizeof(devbuf
),
304 PCI_LOOKUP_VENDOR
| PCI_LOOKUP_DEVICE
,
305 p
->vendor_id
, p
->device_id
));
306 if ((p
->known_fields
& PCI_FILL_CLASS_EXT
) && p
->rev_id
)
307 printf(" (rev %02x)", p
->rev_id
);
311 c
= (p
->known_fields
& PCI_FILL_CLASS_EXT
) ? p
->prog_if
: 0;
312 x
= pci_lookup_name(pacc
, devbuf
, sizeof(devbuf
),
313 PCI_LOOKUP_PROGIF
| PCI_LOOKUP_NO_NUMBERS
,
317 printf(" (prog-if %02x", c
);
325 if (verbose
|| opt_kernel
)
329 pci_fill_info(p
, PCI_FILL_LABEL
);
332 printf("\tDeviceName: %s", p
->label
);
333 if ((p
->known_fields
& PCI_FILL_SUBSYS
) &&
334 p
->subsys_vendor_id
&& p
->subsys_vendor_id
!= 0xffff)
335 printf("\tSubsystem: %s\n",
336 pci_lookup_name(pacc
, ssnamebuf
, sizeof(ssnamebuf
),
337 PCI_LOOKUP_SUBSYSTEM
| PCI_LOOKUP_VENDOR
| PCI_LOOKUP_DEVICE
,
338 p
->vendor_id
, p
->device_id
, p
->subsys_vendor_id
, p
->subsys_id
));
342 /*** Verbose output ***/
347 static const char suffix
[][2] = { "", "K", "M", "G", "T" };
351 for (i
= 0; i
< (sizeof(suffix
) / sizeof(*suffix
) - 1); i
++) {
356 printf(" [size=%u%s]", (unsigned)x
, suffix
[i
]);
360 show_range(const char *prefix
, u64 base
, u64 limit
, int bits
, int disabled
)
362 printf("%s:", prefix
);
363 if (base
<= limit
|| verbose
> 2)
364 printf(" %0*" PCI_U64_FMT_X
"-%0*" PCI_U64_FMT_X
, (bits
+3)/4, base
, (bits
+3)/4, limit
);
365 if (!disabled
&& base
<= limit
)
366 show_size(limit
- base
+ 1);
368 printf(" [disabled]");
370 printf(" [%d-bit]", bits
);
375 ioflg_to_pciflg(pciaddr_t ioflg
)
379 if (ioflg
& PCI_IORESOURCE_IO
)
380 flg
= PCI_BASE_ADDRESS_SPACE_IO
;
381 else if (!(ioflg
& PCI_IORESOURCE_MEM
))
385 flg
= PCI_BASE_ADDRESS_SPACE_MEMORY
;
386 if (ioflg
& PCI_IORESOURCE_MEM_64
)
387 flg
|= PCI_BASE_ADDRESS_MEM_TYPE_64
;
389 flg
|= PCI_BASE_ADDRESS_MEM_TYPE_32
;
390 if (ioflg
& PCI_IORESOURCE_PREFETCH
)
391 flg
|= PCI_BASE_ADDRESS_MEM_PREFETCH
;
398 show_bases(struct device
*d
, int cnt
, int without_config_data
)
400 struct pci_dev
*p
= d
->dev
;
401 word cmd
= without_config_data
? (PCI_COMMAND_IO
| PCI_COMMAND_MEMORY
) : get_conf_word(d
, PCI_COMMAND
);
404 for (i
=0; i
<cnt
; i
++)
406 pciaddr_t pos
= p
->base_addr
[i
];
407 pciaddr_t len
= (p
->known_fields
& PCI_FILL_SIZES
) ? p
->size
[i
] : 0;
408 pciaddr_t ioflg
= (p
->known_fields
& PCI_FILL_IO_FLAGS
) ? p
->flags
[i
] : 0;
409 u32 flg
= (p
->known_fields
& PCI_FILL_IO_FLAGS
) ? ioflg_to_pciflg(ioflg
) : without_config_data
? 0 : get_conf_long(d
, PCI_BASE_ADDRESS_0
+ 4*i
);
415 if (flg
== 0xffffffff)
417 if (!pos
&& !flg
&& !len
)
421 printf("\tRegion %d: ", i
);
425 /* Detect virtual regions, which are reported by the OS, but unassigned in the device */
426 if ((p
->known_fields
& PCI_FILL_IO_FLAGS
) && !without_config_data
)
428 /* Read address as seen by the hardware */
429 hw_lower
= get_conf_long(d
, PCI_BASE_ADDRESS_0
+ 4*i
);
430 if ((hw_lower
& PCI_BASE_ADDRESS_SPACE
) == (ioflg_to_pciflg(ioflg
) & PCI_BASE_ADDRESS_SPACE
))
432 if ((ioflg
& PCI_IORESOURCE_TYPE_BITS
) == PCI_IORESOURCE_MEM
&&
433 (hw_lower
& PCI_BASE_ADDRESS_MEM_TYPE_MASK
) == PCI_BASE_ADDRESS_MEM_TYPE_64
)
438 hw_upper
= get_conf_long(d
, PCI_BASE_ADDRESS_0
+ 4*i
+ 1);
440 if (pos
&& !hw_lower
&& !hw_upper
&& !(ioflg
& PCI_IORESOURCE_PCI_EA_BEI
))
445 /* Print base address */
446 if (flg
& PCI_BASE_ADDRESS_SPACE_IO
)
448 pciaddr_t a
= pos
& PCI_BASE_ADDRESS_IO_MASK
;
449 printf("I/O ports at ");
450 if (a
|| (cmd
& PCI_COMMAND_IO
))
451 printf(PCIADDR_PORT_FMT
, a
);
455 printf("<unassigned>");
457 printf(" [virtual]");
458 else if (!(cmd
& PCI_COMMAND_IO
))
459 printf(" [disabled]");
463 int t
= flg
& PCI_BASE_ADDRESS_MEM_TYPE_MASK
;
464 pciaddr_t a
= pos
& PCI_ADDR_MEM_MASK
;
466 printf("Memory at ");
468 printf("<broken-64-bit-slot>");
470 printf(PCIADDR_T_FMT
, a
);
471 else if (hw_lower
|| hw_upper
)
474 printf("<unassigned>");
475 printf(" (%s, %sprefetchable)",
476 (t
== PCI_BASE_ADDRESS_MEM_TYPE_32
) ? "32-bit" :
477 (t
== PCI_BASE_ADDRESS_MEM_TYPE_64
) ? "64-bit" :
478 (t
== PCI_BASE_ADDRESS_MEM_TYPE_1M
) ? "low-1M" : "type 3",
479 (flg
& PCI_BASE_ADDRESS_MEM_PREFETCH
) ? "" : "non-");
481 printf(" [virtual]");
482 else if (!(cmd
& PCI_COMMAND_MEMORY
))
483 printf(" [disabled]");
486 if (ioflg
& PCI_IORESOURCE_PCI_EA_BEI
)
487 printf(" [enhanced]");
495 show_rom(struct device
*d
, int reg
)
497 struct pci_dev
*p
= d
->dev
;
498 pciaddr_t rom
= p
->rom_base_addr
;
499 pciaddr_t len
= (p
->known_fields
& PCI_FILL_SIZES
) ? p
->rom_size
: 0;
500 pciaddr_t ioflg
= (p
->known_fields
& PCI_FILL_IO_FLAGS
) ? p
->rom_flags
: 0;
501 u32 flg
= reg
>= 0 ? get_conf_long(d
, reg
) : ioflg_to_pciflg(ioflg
);
502 word cmd
= reg
>= 0 ? get_conf_word(d
, PCI_COMMAND
) : PCI_COMMAND_MEMORY
;
505 if (!rom
&& !flg
&& !len
)
508 if (reg
>= 0 && (rom
& PCI_ROM_ADDRESS_MASK
) && !(flg
& PCI_ROM_ADDRESS_MASK
) && !(ioflg
& PCI_IORESOURCE_PCI_EA_BEI
))
514 printf("\tExpansion ROM at ");
515 if (rom
& PCI_ROM_ADDRESS_MASK
)
516 printf(PCIADDR_T_FMT
, rom
& PCI_ROM_ADDRESS_MASK
);
517 else if (flg
& PCI_ROM_ADDRESS_MASK
)
520 printf("<unassigned>");
523 printf(" [virtual]");
525 if (!(flg
& PCI_ROM_ADDRESS_ENABLE
))
526 printf(" [disabled]");
527 else if (!virtual && !(cmd
& PCI_COMMAND_MEMORY
))
528 printf(" [disabled by cmd]");
530 if (ioflg
& PCI_IORESOURCE_PCI_EA_BEI
)
531 printf(" [enhanced]");
538 show_htype0(struct device
*d
)
541 show_rom(d
, PCI_ROM_ADDRESS
);
542 show_caps(d
, PCI_CAPABILITY_LIST
);
546 show_htype1(struct device
*d
)
548 struct pci_dev
*p
= d
->dev
;
549 u32 io_base
= get_conf_byte(d
, PCI_IO_BASE
);
550 u32 io_limit
= get_conf_byte(d
, PCI_IO_LIMIT
);
551 u32 io_type
= io_base
& PCI_IO_RANGE_TYPE_MASK
;
552 u32 mem_base
= get_conf_word(d
, PCI_MEMORY_BASE
);
553 u32 mem_limit
= get_conf_word(d
, PCI_MEMORY_LIMIT
);
554 u32 mem_type
= mem_base
& PCI_MEMORY_RANGE_TYPE_MASK
;
555 u32 pref_base
= get_conf_word(d
, PCI_PREF_MEMORY_BASE
);
556 u32 pref_limit
= get_conf_word(d
, PCI_PREF_MEMORY_LIMIT
);
557 u32 pref_type
= pref_base
& PCI_PREF_RANGE_TYPE_MASK
;
558 word sec_stat
= get_conf_word(d
, PCI_SEC_STATUS
);
559 word brc
= get_conf_word(d
, PCI_BRIDGE_CONTROL
);
560 int io_disabled
= (p
->known_fields
& PCI_FILL_BRIDGE_BASES
) && !p
->bridge_size
[0];
561 int mem_disabled
= (p
->known_fields
& PCI_FILL_BRIDGE_BASES
) && !p
->bridge_size
[1];
562 int pref_disabled
= (p
->known_fields
& PCI_FILL_BRIDGE_BASES
) && !p
->bridge_size
[2];
563 int io_bits
, pref_bits
;
566 printf("\tBus: primary=%02x, secondary=%02x, subordinate=%02x, sec-latency=%d\n",
567 get_conf_byte(d
, PCI_PRIMARY_BUS
),
568 get_conf_byte(d
, PCI_SECONDARY_BUS
),
569 get_conf_byte(d
, PCI_SUBORDINATE_BUS
),
570 get_conf_byte(d
, PCI_SEC_LATENCY_TIMER
));
572 if ((p
->known_fields
& PCI_FILL_BRIDGE_BASES
) && !io_disabled
)
574 io_base
= p
->bridge_base_addr
[0] & PCI_IO_RANGE_MASK
;
575 io_limit
= io_base
+ p
->bridge_size
[0] - 1;
576 io_type
= p
->bridge_base_addr
[0] & PCI_IO_RANGE_TYPE_MASK
;
577 io_bits
= (io_type
== PCI_IO_RANGE_TYPE_32
) ? 32 : 16;
578 show_range("\tI/O behind bridge", io_base
, io_limit
, io_bits
, io_disabled
);
580 else if (io_type
!= (io_limit
& PCI_IO_RANGE_TYPE_MASK
) ||
581 (io_type
!= PCI_IO_RANGE_TYPE_16
&& io_type
!= PCI_IO_RANGE_TYPE_32
))
582 printf("\t!!! Unknown I/O range types %x/%x\n", io_base
, io_limit
);
585 io_base
= (io_base
& PCI_IO_RANGE_MASK
) << 8;
586 io_limit
= (io_limit
& PCI_IO_RANGE_MASK
) << 8;
587 if (io_type
== PCI_IO_RANGE_TYPE_32
)
589 io_base
|= (get_conf_word(d
, PCI_IO_BASE_UPPER16
) << 16);
590 io_limit
|= (get_conf_word(d
, PCI_IO_LIMIT_UPPER16
) << 16);
592 /* I/O is unsupported if both base and limit are zeros and resource is disabled */
593 if (!(io_base
== 0x0 && io_limit
== 0x0 && io_disabled
))
596 io_bits
= (io_type
== PCI_IO_RANGE_TYPE_32
) ? 32 : 16;
597 show_range("\tI/O behind bridge", io_base
, io_limit
, io_bits
, io_disabled
);
601 if ((p
->known_fields
& PCI_FILL_BRIDGE_BASES
) && !mem_disabled
)
603 mem_base
= p
->bridge_base_addr
[1] & PCI_MEMORY_RANGE_MASK
;
604 mem_limit
= mem_base
+ p
->bridge_size
[1] - 1;
605 show_range("\tMemory behind bridge", mem_base
, mem_limit
, 32, mem_disabled
);
607 else if (mem_type
!= (mem_limit
& PCI_MEMORY_RANGE_TYPE_MASK
) ||
609 printf("\t!!! Unknown memory range types %x/%x\n", mem_base
, mem_limit
);
612 mem_base
= (mem_base
& PCI_MEMORY_RANGE_MASK
) << 16;
613 mem_limit
= (mem_limit
& PCI_MEMORY_RANGE_MASK
) << 16;
614 show_range("\tMemory behind bridge", mem_base
, mem_limit
+ 0xfffff, 32, mem_disabled
);
617 if ((p
->known_fields
& PCI_FILL_BRIDGE_BASES
) && !pref_disabled
)
619 u64 pref_base_64
= p
->bridge_base_addr
[2] & PCI_MEMORY_RANGE_MASK
;
620 u64 pref_limit_64
= pref_base_64
+ p
->bridge_size
[2] - 1;
621 pref_type
= p
->bridge_base_addr
[2] & PCI_MEMORY_RANGE_TYPE_MASK
;
622 pref_bits
= (pref_type
== PCI_PREF_RANGE_TYPE_64
) ? 64 : 32;
623 show_range("\tPrefetchable memory behind bridge", pref_base_64
, pref_limit_64
, pref_bits
, pref_disabled
);
625 else if (pref_type
!= (pref_limit
& PCI_PREF_RANGE_TYPE_MASK
) ||
626 (pref_type
!= PCI_PREF_RANGE_TYPE_32
&& pref_type
!= PCI_PREF_RANGE_TYPE_64
))
627 printf("\t!!! Unknown prefetchable memory range types %x/%x\n", pref_base
, pref_limit
);
630 u64 pref_base_64
= (pref_base
& PCI_PREF_RANGE_MASK
) << 16;
631 u64 pref_limit_64
= (pref_limit
& PCI_PREF_RANGE_MASK
) << 16;
632 if (pref_type
== PCI_PREF_RANGE_TYPE_64
)
634 pref_base_64
|= (u64
) get_conf_long(d
, PCI_PREF_BASE_UPPER32
) << 32;
635 pref_limit_64
|= (u64
) get_conf_long(d
, PCI_PREF_LIMIT_UPPER32
) << 32;
637 /* Prefetchable memory is unsupported if both base and limit are zeros and resource is disabled */
638 if (!(pref_base_64
== 0x0 && pref_limit_64
== 0x0 && pref_disabled
))
640 pref_limit_64
+= 0xfffff;
641 pref_bits
= (pref_type
== PCI_PREF_RANGE_TYPE_64
) ? 64 : 32;
642 show_range("\tPrefetchable memory behind bridge", pref_base_64
, pref_limit_64
, pref_bits
, pref_disabled
);
647 printf("\tSecondary status: 66MHz%c FastB2B%c ParErr%c DEVSEL=%s >TAbort%c <TAbort%c <MAbort%c <SERR%c <PERR%c\n",
648 FLAG(sec_stat
, PCI_STATUS_66MHZ
),
649 FLAG(sec_stat
, PCI_STATUS_FAST_BACK
),
650 FLAG(sec_stat
, PCI_STATUS_PARITY
),
651 ((sec_stat
& PCI_STATUS_DEVSEL_MASK
) == PCI_STATUS_DEVSEL_SLOW
) ? "slow" :
652 ((sec_stat
& PCI_STATUS_DEVSEL_MASK
) == PCI_STATUS_DEVSEL_MEDIUM
) ? "medium" :
653 ((sec_stat
& PCI_STATUS_DEVSEL_MASK
) == PCI_STATUS_DEVSEL_FAST
) ? "fast" : "??",
654 FLAG(sec_stat
, PCI_STATUS_SIG_TARGET_ABORT
),
655 FLAG(sec_stat
, PCI_STATUS_REC_TARGET_ABORT
),
656 FLAG(sec_stat
, PCI_STATUS_REC_MASTER_ABORT
),
657 FLAG(sec_stat
, PCI_STATUS_SIG_SYSTEM_ERROR
),
658 FLAG(sec_stat
, PCI_STATUS_DETECTED_PARITY
));
660 show_rom(d
, PCI_ROM_ADDRESS1
);
664 printf("\tBridgeCtl: Parity%c SERR%c NoISA%c VGA%c VGA16%c MAbort%c >Reset%c FastB2B%c\n",
665 FLAG(brc
, PCI_BRIDGE_CTL_PARITY
),
666 FLAG(brc
, PCI_BRIDGE_CTL_SERR
),
667 FLAG(brc
, PCI_BRIDGE_CTL_NO_ISA
),
668 FLAG(brc
, PCI_BRIDGE_CTL_VGA
),
669 FLAG(brc
, PCI_BRIDGE_CTL_VGA_16BIT
),
670 FLAG(brc
, PCI_BRIDGE_CTL_MASTER_ABORT
),
671 FLAG(brc
, PCI_BRIDGE_CTL_BUS_RESET
),
672 FLAG(brc
, PCI_BRIDGE_CTL_FAST_BACK
));
673 printf("\t\tPriDiscTmr%c SecDiscTmr%c DiscTmrStat%c DiscTmrSERREn%c\n",
674 FLAG(brc
, PCI_BRIDGE_CTL_PRI_DISCARD_TIMER
),
675 FLAG(brc
, PCI_BRIDGE_CTL_SEC_DISCARD_TIMER
),
676 FLAG(brc
, PCI_BRIDGE_CTL_DISCARD_TIMER_STATUS
),
677 FLAG(brc
, PCI_BRIDGE_CTL_DISCARD_TIMER_SERR_EN
));
680 show_caps(d
, PCI_CAPABILITY_LIST
);
684 show_htype2(struct device
*d
)
687 word cmd
= get_conf_word(d
, PCI_COMMAND
);
688 word brc
= get_conf_word(d
, PCI_CB_BRIDGE_CONTROL
);
690 int verb
= verbose
> 2;
693 printf("\tBus: primary=%02x, secondary=%02x, subordinate=%02x, sec-latency=%d\n",
694 get_conf_byte(d
, PCI_CB_PRIMARY_BUS
),
695 get_conf_byte(d
, PCI_CB_CARD_BUS
),
696 get_conf_byte(d
, PCI_CB_SUBORDINATE_BUS
),
697 get_conf_byte(d
, PCI_CB_LATENCY_TIMER
));
701 u32 base
= get_conf_long(d
, PCI_CB_MEMORY_BASE_0
+ p
);
702 u32 limit
= get_conf_long(d
, PCI_CB_MEMORY_LIMIT_0
+ p
);
703 limit
= limit
+ 0xfff;
704 if (base
<= limit
|| verb
)
705 printf("\tMemory window %d: %08x-%08x%s%s\n", i
, base
, limit
,
706 (cmd
& PCI_COMMAND_MEMORY
) ? "" : " [disabled]",
707 (brc
& (PCI_CB_BRIDGE_CTL_PREFETCH_MEM0
<< i
)) ? " (prefetchable)" : "");
712 u32 base
= get_conf_long(d
, PCI_CB_IO_BASE_0
+ p
);
713 u32 limit
= get_conf_long(d
, PCI_CB_IO_LIMIT_0
+ p
);
714 if (!(base
& PCI_IO_RANGE_TYPE_32
))
719 base
&= PCI_CB_IO_RANGE_MASK
;
720 limit
= (limit
& PCI_CB_IO_RANGE_MASK
) + 3;
721 if (base
<= limit
|| verb
)
722 printf("\tI/O window %d: %08x-%08x%s\n", i
, base
, limit
,
723 (cmd
& PCI_COMMAND_IO
) ? "" : " [disabled]");
726 if (get_conf_word(d
, PCI_CB_SEC_STATUS
) & PCI_STATUS_SIG_SYSTEM_ERROR
)
727 printf("\tSecondary status: SERR\n");
729 printf("\tBridgeCtl: Parity%c SERR%c ISA%c VGA%c MAbort%c >Reset%c 16bInt%c PostWrite%c\n",
730 FLAG(brc
, PCI_CB_BRIDGE_CTL_PARITY
),
731 FLAG(brc
, PCI_CB_BRIDGE_CTL_SERR
),
732 FLAG(brc
, PCI_CB_BRIDGE_CTL_ISA
),
733 FLAG(brc
, PCI_CB_BRIDGE_CTL_VGA
),
734 FLAG(brc
, PCI_CB_BRIDGE_CTL_MASTER_ABORT
),
735 FLAG(brc
, PCI_CB_BRIDGE_CTL_CB_RESET
),
736 FLAG(brc
, PCI_CB_BRIDGE_CTL_16BIT_INT
),
737 FLAG(brc
, PCI_CB_BRIDGE_CTL_POST_WRITES
));
739 if (d
->config_cached
< 128)
741 printf("\t<access denied to the rest>\n");
745 exca
= get_conf_word(d
, PCI_CB_LEGACY_MODE_BASE
);
747 printf("\t16-bit legacy interface ports at %04x\n", exca
);
748 show_caps(d
, PCI_CB_CAPABILITY_LIST
);
752 show_htype_unknown(struct device
*d
)
754 struct pci_dev
*p
= d
->dev
;
755 u64 base
, limit
, flags
;
759 if (pacc
->buscentric
)
763 for (i
= 0; i
< 4; i
++)
765 if (!p
->bridge_base_addr
[i
])
767 base
= p
->bridge_base_addr
[i
];
768 limit
= base
+ p
->bridge_size
[i
] - 1;
769 flags
= p
->bridge_flags
[i
];
770 if (flags
& PCI_IORESOURCE_IO
)
772 bits
= (flags
& PCI_IORESOURCE_IO_16BIT_ADDR
) ? 16 : 32;
773 str
= "\tI/O behind bridge";
775 else if (flags
& PCI_IORESOURCE_MEM
)
777 bits
= (flags
& PCI_IORESOURCE_MEM_64
) ? 64 : 32;
778 if (flags
& PCI_IORESOURCE_PREFETCH
)
779 str
= "\tPrefetchable memory behind bridge";
781 str
= "\tMemory behind bridge";
786 str
= "\tUnknown resource behind bridge";
788 show_range(str
, base
, limit
, bits
, 0);
794 show_verbose(struct device
*d
)
796 struct pci_dev
*p
= d
->dev
;
797 int unknown_config_data
= 0;
798 word
class = p
->device_class
;
799 byte htype
= d
->no_config_access
? -1 : (get_conf_byte(d
, PCI_HEADER_TYPE
) & 0x7f);
801 byte max_lat
, min_gnt
;
802 char *dt_node
, *iommu_group
;
806 pci_fill_info(p
, PCI_FILL_IRQ
| PCI_FILL_BASES
| PCI_FILL_ROM_BASE
| PCI_FILL_SIZES
|
807 PCI_FILL_PHYS_SLOT
| PCI_FILL_NUMA_NODE
| PCI_FILL_DT_NODE
| PCI_FILL_IOMMU_GROUP
|
808 PCI_FILL_BRIDGE_BASES
| PCI_FILL_CLASS_EXT
| PCI_FILL_SUBSYS
);
812 case PCI_HEADER_TYPE_NORMAL
:
813 if (class == PCI_CLASS_BRIDGE_PCI
)
814 printf("\t!!! Invalid class %04x for header type %02x\n", class, htype
);
815 bist
= get_conf_byte(d
, PCI_BIST
);
816 max_lat
= get_conf_byte(d
, PCI_MAX_LAT
);
817 min_gnt
= get_conf_byte(d
, PCI_MIN_GNT
);
819 case PCI_HEADER_TYPE_BRIDGE
:
820 if ((class >> 8) != PCI_BASE_CLASS_BRIDGE
)
821 printf("\t!!! Invalid class %04x for header type %02x\n", class, htype
);
822 bist
= get_conf_byte(d
, PCI_BIST
);
823 min_gnt
= max_lat
= 0;
825 case PCI_HEADER_TYPE_CARDBUS
:
826 if ((class >> 8) != PCI_BASE_CLASS_BRIDGE
)
827 printf("\t!!! Invalid class %04x for header type %02x\n", class, htype
);
828 bist
= get_conf_byte(d
, PCI_BIST
);
829 min_gnt
= max_lat
= 0;
832 if (!d
->no_config_access
)
833 printf("\t!!! Unknown header type %02x\n", htype
);
835 min_gnt
= max_lat
= 0;
836 unknown_config_data
= 1;
840 printf("\tPhysical Slot: %s\n", p
->phy_slot
);
842 if (dt_node
= pci_get_string_property(p
, PCI_FILL_DT_NODE
))
843 printf("\tDevice tree node: %s\n", dt_node
);
845 if (!unknown_config_data
&& verbose
> 1)
847 word cmd
= get_conf_word(d
, PCI_COMMAND
);
848 word status
= get_conf_word(d
, PCI_STATUS
);
849 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",
850 FLAG(cmd
, PCI_COMMAND_IO
),
851 FLAG(cmd
, PCI_COMMAND_MEMORY
),
852 FLAG(cmd
, PCI_COMMAND_MASTER
),
853 FLAG(cmd
, PCI_COMMAND_SPECIAL
),
854 FLAG(cmd
, PCI_COMMAND_INVALIDATE
),
855 FLAG(cmd
, PCI_COMMAND_VGA_PALETTE
),
856 FLAG(cmd
, PCI_COMMAND_PARITY
),
857 FLAG(cmd
, PCI_COMMAND_WAIT
),
858 FLAG(cmd
, PCI_COMMAND_SERR
),
859 FLAG(cmd
, PCI_COMMAND_FAST_BACK
),
860 FLAG(cmd
, PCI_COMMAND_DISABLE_INTx
));
861 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",
862 FLAG(status
, PCI_STATUS_CAP_LIST
),
863 FLAG(status
, PCI_STATUS_66MHZ
),
864 FLAG(status
, PCI_STATUS_UDF
),
865 FLAG(status
, PCI_STATUS_FAST_BACK
),
866 FLAG(status
, PCI_STATUS_PARITY
),
867 ((status
& PCI_STATUS_DEVSEL_MASK
) == PCI_STATUS_DEVSEL_SLOW
) ? "slow" :
868 ((status
& PCI_STATUS_DEVSEL_MASK
) == PCI_STATUS_DEVSEL_MEDIUM
) ? "medium" :
869 ((status
& PCI_STATUS_DEVSEL_MASK
) == PCI_STATUS_DEVSEL_FAST
) ? "fast" : "??",
870 FLAG(status
, PCI_STATUS_SIG_TARGET_ABORT
),
871 FLAG(status
, PCI_STATUS_REC_TARGET_ABORT
),
872 FLAG(status
, PCI_STATUS_REC_MASTER_ABORT
),
873 FLAG(status
, PCI_STATUS_SIG_SYSTEM_ERROR
),
874 FLAG(status
, PCI_STATUS_DETECTED_PARITY
),
875 FLAG(status
, PCI_STATUS_INTx
));
876 if (cmd
& PCI_COMMAND_MASTER
)
878 byte latency
= get_conf_byte(d
, PCI_LATENCY_TIMER
);
879 byte cache_line
= get_conf_byte(d
, PCI_CACHE_LINE_SIZE
);
880 printf("\tLatency: %d", latency
);
881 if (min_gnt
|| max_lat
)
885 printf("%dns min", min_gnt
*250);
886 if (min_gnt
&& max_lat
)
889 printf("%dns max", max_lat
*250);
893 printf(", Cache Line Size: %d bytes", cache_line
* 4);
900 byte int_pin
= unknown_config_data
? 0 : get_conf_byte(d
, PCI_INTERRUPT_PIN
);
901 if (int_pin
|| p
->irq
)
902 printf("\tInterrupt: pin %c routed to IRQ " PCIIRQ_FMT
"\n",
903 (int_pin
? 'A' + int_pin
- 1 : '?'), p
->irq
);
904 if (p
->numa_node
!= -1)
905 printf("\tNUMA node: %d\n", p
->numa_node
);
906 if (iommu_group
= pci_get_string_property(p
, PCI_FILL_IOMMU_GROUP
))
907 printf("\tIOMMU group: %s\n", iommu_group
);
910 if (!unknown_config_data
&& verbose
<= 1)
912 word cmd
= get_conf_word(d
, PCI_COMMAND
);
913 word status
= get_conf_word(d
, PCI_STATUS
);
914 byte latency
= get_conf_byte(d
, PCI_LATENCY_TIMER
);
916 if (cmd
& PCI_COMMAND_MASTER
)
917 printf("bus master, ");
918 if (cmd
& PCI_COMMAND_VGA_PALETTE
)
919 printf("VGA palette snoop, ");
920 if (cmd
& PCI_COMMAND_WAIT
)
921 printf("stepping, ");
922 if (cmd
& PCI_COMMAND_FAST_BACK
)
923 printf("fast Back2Back, ");
924 if (status
& PCI_STATUS_66MHZ
)
926 if (status
& PCI_STATUS_UDF
)
927 printf("user-definable features, ");
929 ((status
& PCI_STATUS_DEVSEL_MASK
) == PCI_STATUS_DEVSEL_SLOW
) ? "slow" :
930 ((status
& PCI_STATUS_DEVSEL_MASK
) == PCI_STATUS_DEVSEL_MEDIUM
) ? "medium" :
931 ((status
& PCI_STATUS_DEVSEL_MASK
) == PCI_STATUS_DEVSEL_FAST
) ? "fast" : "??");
932 if (cmd
& PCI_COMMAND_MASTER
)
933 printf(", latency %d", latency
);
935 printf(", IRQ " PCIIRQ_FMT
, p
->irq
);
936 if (p
->numa_node
!= -1)
937 printf(", NUMA node %d", p
->numa_node
);
938 if (iommu_group
= pci_get_string_property(p
, PCI_FILL_IOMMU_GROUP
))
939 printf(", IOMMU group %s", iommu_group
);
943 if (bist
& PCI_BIST_CAPABLE
)
945 if (bist
& PCI_BIST_START
)
946 printf("\tBIST is running\n");
948 printf("\tBIST result: %02x\n", bist
& PCI_BIST_CODE_MASK
);
953 case PCI_HEADER_TYPE_NORMAL
:
956 case PCI_HEADER_TYPE_BRIDGE
:
959 case PCI_HEADER_TYPE_CARDBUS
:
963 show_htype_unknown(d
);
967 /*** Machine-readable dumps ***/
970 show_hex_dump(struct device
*d
)
974 if (d
->no_config_access
)
976 printf("WARNING: Cannot show hex-dump of the config space\n");
980 cnt
= d
->config_cached
;
981 if (opt_hex
>= 3 && config_fetch(d
, cnt
, 256-cnt
))
984 if (opt_hex
>= 4 && config_fetch(d
, 256, 4096-256))
988 for (i
=0; i
<cnt
; i
++)
992 printf(" %02x", get_conf_byte(d
, i
));
999 print_shell_escaped(char *c
)
1004 if (*c
== '"' || *c
== '\\')
1012 show_machine(struct device
*d
)
1014 struct pci_dev
*p
= d
->dev
;
1015 char classbuf
[256], vendbuf
[256], devbuf
[256], svbuf
[256], sdbuf
[256];
1016 char *dt_node
, *iommu_group
;
1020 pci_fill_info(p
, PCI_FILL_PHYS_SLOT
| PCI_FILL_NUMA_NODE
| PCI_FILL_DT_NODE
| PCI_FILL_IOMMU_GROUP
);
1021 printf((opt_machine
>= 2) ? "Slot:\t" : "Device:\t");
1024 printf("Class:\t%s\n",
1025 pci_lookup_name(pacc
, classbuf
, sizeof(classbuf
), PCI_LOOKUP_CLASS
, p
->device_class
));
1026 printf("Vendor:\t%s\n",
1027 pci_lookup_name(pacc
, vendbuf
, sizeof(vendbuf
), PCI_LOOKUP_VENDOR
, p
->vendor_id
, p
->device_id
));
1028 printf("Device:\t%s\n",
1029 pci_lookup_name(pacc
, devbuf
, sizeof(devbuf
), PCI_LOOKUP_DEVICE
, p
->vendor_id
, p
->device_id
));
1030 if ((p
->known_fields
& PCI_FILL_SUBSYS
) &&
1031 p
->subsys_vendor_id
&& p
->subsys_vendor_id
!= 0xffff)
1033 printf("SVendor:\t%s\n",
1034 pci_lookup_name(pacc
, svbuf
, sizeof(svbuf
), PCI_LOOKUP_SUBSYSTEM
| PCI_LOOKUP_VENDOR
, p
->subsys_vendor_id
));
1035 printf("SDevice:\t%s\n",
1036 pci_lookup_name(pacc
, sdbuf
, sizeof(sdbuf
), PCI_LOOKUP_SUBSYSTEM
| PCI_LOOKUP_DEVICE
, p
->vendor_id
, p
->device_id
, p
->subsys_vendor_id
, p
->subsys_id
));
1039 printf("PhySlot:\t%s\n", p
->phy_slot
);
1040 if ((p
->known_fields
& PCI_FILL_CLASS_EXT
) && p
->rev_id
)
1041 printf("Rev:\t%02x\n", p
->rev_id
);
1042 if (p
->known_fields
& PCI_FILL_CLASS_EXT
)
1043 printf("ProgIf:\t%02x\n", p
->prog_if
);
1045 show_kernel_machine(d
);
1046 if (p
->numa_node
!= -1)
1047 printf("NUMANode:\t%d\n", p
->numa_node
);
1048 if (dt_node
= pci_get_string_property(p
, PCI_FILL_DT_NODE
))
1049 printf("DTNode:\t%s\n", dt_node
);
1050 if (iommu_group
= pci_get_string_property(p
, PCI_FILL_IOMMU_GROUP
))
1051 printf("IOMMUGroup:\t%s\n", iommu_group
);
1056 print_shell_escaped(pci_lookup_name(pacc
, classbuf
, sizeof(classbuf
), PCI_LOOKUP_CLASS
, p
->device_class
));
1057 print_shell_escaped(pci_lookup_name(pacc
, vendbuf
, sizeof(vendbuf
), PCI_LOOKUP_VENDOR
, p
->vendor_id
, p
->device_id
));
1058 print_shell_escaped(pci_lookup_name(pacc
, devbuf
, sizeof(devbuf
), PCI_LOOKUP_DEVICE
, p
->vendor_id
, p
->device_id
));
1059 if ((p
->known_fields
& PCI_FILL_CLASS_EXT
) && p
->rev_id
)
1060 printf(" -r%02x", p
->rev_id
);
1061 if (p
->known_fields
& PCI_FILL_CLASS_EXT
)
1062 printf(" -p%02x", p
->prog_if
);
1063 if ((p
->known_fields
& PCI_FILL_SUBSYS
) &&
1064 p
->subsys_vendor_id
&& p
->subsys_vendor_id
!= 0xffff)
1066 print_shell_escaped(pci_lookup_name(pacc
, svbuf
, sizeof(svbuf
), PCI_LOOKUP_SUBSYSTEM
| PCI_LOOKUP_VENDOR
, p
->subsys_vendor_id
));
1067 print_shell_escaped(pci_lookup_name(pacc
, sdbuf
, sizeof(sdbuf
), PCI_LOOKUP_SUBSYSTEM
| PCI_LOOKUP_DEVICE
, p
->vendor_id
, p
->device_id
, p
->subsys_vendor_id
, p
->subsys_id
));
1070 printf(" \"\" \"\"");
1075 /*** Main show function ***/
1078 show_device(struct device
*d
)
1088 if (opt_kernel
|| verbose
)
1093 if (verbose
|| opt_hex
)
1102 for (d
=first_dev
; d
; d
=d
->next
)
1103 if (pci_filter_match(&filter
, d
->dev
))
1110 main(int argc
, char **argv
)
1115 if (argc
== 2 && !strcmp(argv
[1], "--version"))
1117 puts("lspci version " PCIUTILS_VERSION
);
1123 pci_filter_init(pacc
, &filter
);
1125 while ((i
= getopt(argc
, argv
, options
)) != -1)
1129 pacc
->numeric_ids
++;
1135 pacc
->buscentric
= 1;
1138 if (msg
= pci_filter_parse_slot(&filter
, optarg
))
1143 if (msg
= pci_filter_parse_id(&filter
, optarg
))
1159 pci_set_name_list_path(pacc
, optarg
, 0);
1165 opt_pcimap
= optarg
;
1188 die("DNS queries are not available in this version");
1191 if (parse_generic_option(i
, pacc
, optarg
))
1194 fprintf(stderr
, help_msg
, pacc
->id_file_name
);
1202 pacc
->id_lookup_mode
|= PCI_LOOKUP_NETWORK
;
1203 if (opt_query_dns
> 1)
1204 pacc
->id_lookup_mode
|= PCI_LOOKUP_REFRESH_CACHE
;
1207 pacc
->id_lookup_mode
|= PCI_LOOKUP_NETWORK
| PCI_LOOKUP_SKIP_LOCAL
;
1213 die("Bus mapping mode does not recognize bus topology");
1223 show_forest(opt_filter
? &filter
: NULL
);
1227 show_kernel_cleanup();
1230 return (seen_errors
? 2 : 0);