static int opt_machine; /* Generate machine-readable output */
static int opt_map_mode; /* Bus mapping mode enabled */
static int opt_domains; /* Show domain numbers (0=disabled, 1=auto-detected, 2=requested) */
+static int opt_kernel; /* Show kernel drivers */
static char *opt_pcimap; /* Override path to Linux modules.pcimap */
const char program_name[] = "lspci";
-static char options[] = "nvbxs:d:ti:mgp:MD" GENERIC_OPTIONS ;
+static char options[] = "nvbxs:d:ti:mgp:kMD" GENERIC_OPTIONS ;
static char help_msg[] = "\
Usage: lspci [<switches>]\n\
-i <file>\tUse specified ID database instead of %s\n"
#ifdef PCI_OS_LINUX
"\
+-k\t\tShow kernel drivers handling each device\n\
-p <file>\tLook up kernel modules in a given file instead of default modules.pcimap\n"
#endif
"\
#undef MATCH
}
-static void
-show_driver(struct device *d)
+#define DRIVER_BUF_SIZE 1024
+
+static char *
+find_driver(struct device *d, char *buf)
{
struct pci_dev *dev = d->dev;
char *base = dev->access->method_params[PCI_ACCESS_SYS_BUS_PCI];
- char name[1024], driver[1024], *drv;
+ char name[1024], *drv;
int n;
if (dev->access->method != PCI_ACCESS_SYS_BUS_PCI)
- return;
+ return NULL;
n = snprintf(name, sizeof(name), "%s/devices/%04x:%02x:%02x.%d/driver",
base, dev->domain, dev->bus, dev->dev, dev->func);
- if (n < 0 || n >= 1024)
+ if (n < 0 || n >= (int)sizeof(name))
die("show_driver: sysfs device name too long, why?");
- n = readlink(name, driver, sizeof(driver));
+ n = readlink(name, buf, DRIVER_BUF_SIZE);
if (n < 0)
- return;
- if (n >= (int)sizeof(driver))
- {
- printf("\t!!! Driver name too long\n");
- return;
- }
- driver[n] = 0;
+ return NULL;
+ if (n >= DRIVER_BUF_SIZE)
+ return "<name-too-long>";
+ buf[n] = 0;
- if (drv = strrchr(driver, '/'))
- drv++;
+ if (drv = strrchr(buf, '/'))
+ return drv+1;
else
- drv = driver;
- printf("\tKernel driver in use: %s\n", drv);
+ return buf;
}
static void
-show_module(struct device *d)
+show_kernel(struct device *d)
{
+ char buf[DRIVER_BUF_SIZE];
+ char *driver;
struct pcimap_entry *e, *last = NULL;
+ if (driver = find_driver(d, buf))
+ printf("\tKernel driver in use: %s\n", driver);
+
load_pcimap();
for (e=pcimap_head; e; e=e->next)
if (match_pcimap(d, e) && (!last || strcmp(last->module, e->module)))
putchar('\n');
}
+static void
+show_kernel_machine(struct device *d)
+{
+ char buf[DRIVER_BUF_SIZE];
+ char *driver;
+ struct pcimap_entry *e, *last = NULL;
+
+ if (driver = find_driver(d, buf))
+ printf("Driver:\t%s\n", driver);
+
+ load_pcimap();
+ for (e=pcimap_head; e; e=e->next)
+ if (match_pcimap(d, e) && (!last || strcmp(last->module, e->module)))
+ {
+ printf("Module:\t%s\n", e->module);
+ last = e;
+ }
+}
+
#else
static void
-show_driver(void)
+show_kernel(struct device *d UNUSED)
{
}
static void
-show_module(void)
+show_kernel_machine(struct device *d UNUSED)
{
}
show_htype2(d);
break;
}
-
- show_driver(d);
- show_module(d);
}
/*** Machine-readable dumps ***/
printf("Rev:\t%02x\n", c);
if (c = get_conf_byte(d, PCI_CLASS_PROG))
printf("ProgIf:\t%02x\n", c);
+ if (opt_kernel)
+ show_kernel_machine(d);
}
else
{
{
if (opt_machine)
show_machine(d);
- else if (verbose)
- show_verbose(d);
else
- show_terse(d);
+ {
+ if (verbose)
+ show_verbose(d);
+ else
+ show_terse(d);
+ if (opt_kernel || verbose)
+ show_kernel(d);
+ }
if (opt_hex)
show_hex_dump(d);
if (verbose || opt_hex)
case 'p':
opt_pcimap = optarg;
break;
+ case 'k':
+ opt_kernel++;
+ break;
case 'M':
opt_map_mode++;
break;
Show hexadecimal dump of the extended (4096-byte) PCI configuration space available
on PCI-X 2.0 and PCI Express buses.
.TP
+.B -k
+Show kernel drivers handling each device and also kernel modules capable of handling it.
+Turned on by default when
+.B -v
+is given in the normal mode of output.
+(Currently works only on Linux with kernel 2.6 or newer.)
+.TP
.B -b
Bus-centric view. Show all IRQ numbers and addresses as seen by the cards on the
PCI bus instead of as seen by the kernel.
<file>
as the PCI ID list instead of @IDSDIR@/pci.ids.
.TP
+.B -p <file>
+Use
+.B
+<file>
+as the map of PCI ID's handled by kernel modules. By default, lspci uses
+.RI /lib/modules/ kernel_version /modules.pcimap.
+Applies only to Linux systems with recent enough module tools.
+.TP
.B -m
Dump PCI device data in a backward-compatible machine readable form.
See below for details.
The
.B /sys
filesystem on Linux 2.6 and newer. The standard header of the config space is available
-to all users, the rest only to root. Supports extended configuration space and PCI domains.
+to all users, the rest only to root. Supports extended configuration space, PCI domains
+and information on attached kernel drivers.
.TP
.B linux_proc
The
.B ProgIf
Programming interface (optional).
+.TP
+.B Driver
+Kernel driver currently handling the device (optional, Linux only).
+
+.TP
+.B Module
+Kernel module reporting that it is capable of handling the device
+(optional, Linux only).
+
.P
New tags can be added in future versions, so you should silently ignore any tags you don't recognize.