summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--usr.sbin/pcidump/pcidump.838
-rw-r--r--usr.sbin/pcidump/pcidump.c65
2 files changed, 77 insertions, 26 deletions
diff --git a/usr.sbin/pcidump/pcidump.8 b/usr.sbin/pcidump/pcidump.8
index e80e4f34bf7..04995312021 100644
--- a/usr.sbin/pcidump/pcidump.8
+++ b/usr.sbin/pcidump/pcidump.8
@@ -1,4 +1,4 @@
-.\" $OpenBSD: pcidump.8,v 1.6 2008/03/02 17:59:10 kettenis Exp $
+.\" $OpenBSD: pcidump.8,v 1.7 2008/10/07 09:23:32 dlg Exp $
.\"
.\" Copyright (c) 2007 Paul de Weerd <weerd@weirdnet.nl>
.\"
@@ -14,7 +14,7 @@
.\" TORTIOUS ACTION, ARISING OUT OF
.\" PERFORMANCE OF THIS SOFTWARE.
.\"
-.Dd $Mdocdate: March 2 2008 $
+.Dd $Mdocdate: October 7 2008 $
.Dt PCIDUMP 8
.Os
.Sh NAME
@@ -34,26 +34,40 @@ utility displays the device address, vendor, and product name
of PCI devices.
When no arguments are given,
information on all PCI devices in the system is shown;
-otherwise a single device may be specified by bus, device, and function:
-.Sm off
-.Ar bus : dev : func .
-.Sm on
+otherwise a single PCI domain or device may be specified.
.Pp
The options are as follows:
.Bl -tag -width Ds
.It Fl d Ar pcidev
-Specify another file to use for PCI lookups.
+Specify a file to use for PCI lookups.
+If specified without
+.Sm off
+.Ar bus : dev : func ,
+.Sm on
+all PCI devices in the domain will be shown.
.It Fl v
Shows detailed information about PCI devices.
.It Fl x
Shows a hexadecimal dump of the first 64 bytes of PCI config space.
.It Fl xx
Shows a hexadecimal dump of the full PCI config space.
+.It Xo
+.Sm off
+.Ar bus : dev : func
+.Sm on
+.Xc
+Show information about the PCI device specified by the tuple given on
+the command line.
+If the
+.Fl d
+option is not given,
+.Pa /dev/pci
+is used.
.El
.Sh FILES
-.Bl -tag -width /dev/pci -compact
-.It Pa /dev/pci
-Default file for PCI lookups.
+.Bl -tag -width /dev/pci* -compact
+.It Pa /dev/pci*
+Device files for accessing PCI domains.
.El
.Sh SEE ALSO
.Xr pci 4
@@ -69,3 +83,7 @@ The
utility was written by
.An David Gwynne
.Aq dlg@openbsd.org .
+.Sh BUGS
+The default behaviour of scanning all PCI domains is limited to those
+domains that have an entry in
+.Pa /dev .
diff --git a/usr.sbin/pcidump/pcidump.c b/usr.sbin/pcidump/pcidump.c
index 642761a5726..d7efe42161c 100644
--- a/usr.sbin/pcidump/pcidump.c
+++ b/usr.sbin/pcidump/pcidump.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pcidump.c,v 1.15 2008/07/23 15:39:52 kettenis Exp $ */
+/* $OpenBSD: pcidump.c,v 1.16 2008/10/07 09:23:32 dlg Exp $ */
/*
* Copyright (c) 2006, 2007 David Gwynne <loki@animata.net>
@@ -25,6 +25,7 @@
#include <err.h>
#include <sys/ioctl.h>
+#include <sys/param.h>
#include <sys/pciio.h>
#include <dev/pci/pcireg.h>
#include <dev/pci/pcidevs.h>
@@ -33,6 +34,7 @@
#define PCIDEV "/dev/pci"
__dead void usage(void);
+void scanpcidomain(void);
int probe(int, int, int);
void dump(int, int, int);
void hexdump(int, int, int, int);
@@ -82,14 +84,15 @@ main(int argc, char *argv[])
{
int nfuncs;
int bus, dev, func;
- char *pcidev = PCIDEV;
+ char pcidev[MAXPATHLEN] = PCIDEV;
const char *errstr;
- int c, error = 0;
+ int c, error = 0, dumpall = 1, domid = 0;
while ((c = getopt(argc, argv, "d:vx")) != -1) {
switch (c) {
case 'd':
- pcidev = optarg;
+ strlcpy(pcidev, optarg, sizeof(pcidev));
+ dumpall = 0;
break;
case 'v':
verbose = 1;
@@ -107,9 +110,30 @@ main(int argc, char *argv[])
if (argc > 1 || (verbose && hex))
usage();
- pcifd = open(pcidev, O_RDONLY, 0777);
- if (pcifd == -1)
- err(1, "%s", pcidev);
+ if (argc == 1)
+ dumpall = 0;
+
+ if (dumpall == 0) {
+ pcifd = open(pcidev, O_RDONLY, 0777);
+ if (pcifd == -1)
+ err(1, "%s", pcidev);
+ printf("Domain %s:\n", pcidev);
+ } else {
+ for (;;) {
+ snprintf(pcidev, 16, "/dev/pci%d", domid++);
+ pcifd = open(pcidev, O_RDONLY, 0777);
+ if (pcifd == -1) {
+ if (errno == ENXIO || errno == ENOENT) {
+ return 0;
+ } else {
+ err(1, "%s", pcidev);
+ }
+ }
+ printf("Domain %s:\n", pcidev);
+ scanpcidomain();
+ close(pcifd);
+ }
+ }
if (argc == 1) {
errstr = str2busdevfunc(argv[0], &bus, &dev, &func);
@@ -125,19 +149,28 @@ main(int argc, char *argv[])
if (error != 0)
errx(1, "\"%s\": %s", argv[0], strerror(error));
} else {
- for (bus = 0; bus < 256; bus++) {
- for (dev = 0; dev < 32; dev++) {
- nfuncs = pci_nfuncs(bus, dev);
- for (func = 0; func < nfuncs; func++) {
- probe(bus, dev, func);
- }
- }
- }
+ scanpcidomain();
}
return (0);
}
+void
+scanpcidomain(void)
+{
+ int nfuncs;
+ int bus, dev, func;
+
+ for (bus = 0; bus < 256; bus++) {
+ for (dev = 0; dev < 32; dev++) {
+ nfuncs = pci_nfuncs(bus, dev);
+ for (func = 0; func < nfuncs; func++) {
+ probe(bus, dev, func);
+ }
+ }
+ }
+}
+
const char *
str2busdevfunc(const char *string, int *bus, int *dev, int *func)
{
@@ -200,7 +233,7 @@ probe(int bus, int dev, int func)
}
}
- printf("%d:%d:%d: %s %s\n", bus, dev, func,
+ printf(" %d:%d:%d: %s %s\n", bus, dev, func,
(vendor == NULL) ? "unknown" : vendor,
(product == NULL) ? "unknown" : product);