diff options
author | Mark Kettenis <kettenis@cvs.openbsd.org> | 2007-11-18 00:33:46 +0000 |
---|---|---|
committer | Mark Kettenis <kettenis@cvs.openbsd.org> | 2007-11-18 00:33:46 +0000 |
commit | 4cd964a488cf7ad44ae2a0a0da86b65371c369f7 (patch) | |
tree | 17841e2b7cabeb28ff56048ef011bfb835130ece /usr.sbin | |
parent | b62bb5130b85d93fd980f3719cb85d547bcbde36 (diff) |
Add support for dumping PCI config space in hex.
ok dlg@
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/pcidump/pcidump.8 | 10 | ||||
-rw-r--r-- | usr.sbin/pcidump/pcidump.c | 34 |
2 files changed, 37 insertions, 7 deletions
diff --git a/usr.sbin/pcidump/pcidump.8 b/usr.sbin/pcidump/pcidump.8 index dbb8049bc92..8e50c802fd3 100644 --- a/usr.sbin/pcidump/pcidump.8 +++ b/usr.sbin/pcidump/pcidump.8 @@ -1,4 +1,4 @@ -.\" $OpenBSD: pcidump.8,v 1.3 2007/10/22 08:29:09 jmc Exp $ +.\" $OpenBSD: pcidump.8,v 1.4 2007/11/18 00:33:45 kettenis 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: October 22 2007 $ +.Dd $Mdocdate: November 18 2007 $ .Dt PCIDUMP 8 .Os .Sh NAME @@ -22,7 +22,7 @@ .Nd show PCI device data .Sh SYNOPSIS .Nm pcidump -.Op Fl v +.Op Fl v | Fl x | Fl xx .Op Fl d Ar pcidev .Sm off .Op Ar dev : bus : func @@ -45,6 +45,10 @@ The options are as follows: Specify another file to use for PCI lookups. .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. .El .Sh FILES .Bl -tag -width /dev/pci -compact diff --git a/usr.sbin/pcidump/pcidump.c b/usr.sbin/pcidump/pcidump.c index da6fcff37e1..5f69d3c5e62 100644 --- a/usr.sbin/pcidump/pcidump.c +++ b/usr.sbin/pcidump/pcidump.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pcidump.c,v 1.9 2007/11/17 18:32:21 kettenis Exp $ */ +/* $OpenBSD: pcidump.c,v 1.10 2007/11/18 00:33:45 kettenis Exp $ */ /* * Copyright (c) 2006, 2007 David Gwynne <loki@animata.net> @@ -35,6 +35,7 @@ __dead void usage(void); int probe(int, int, int); void dump(int, int, int); +void hexdump(int, int, int, int); const char *str2busdevfunc(const char *, int *, int *, int *); int pci_nfuncs(int, int); int pci_read(int, int, int, u_int32_t, u_int32_t *); @@ -44,13 +45,14 @@ usage(void) { extern char *__progname; - fprintf(stderr, "usage: %s [-v] [-d pcidev] [dev:bus:func]\n", + fprintf(stderr, "usage: %s [-v|-x|-xx] [-d pcidev] [dev:bus:func]\n", __progname); exit(1); } int pcifd; int verbose = 0; +int hex = 0; int main(int argc, char *argv[]) @@ -61,7 +63,7 @@ main(int argc, char *argv[]) const char *errstr; int c, error = 0; - while ((c = getopt(argc, argv, "d:v")) != -1) { + while ((c = getopt(argc, argv, "d:vx")) != -1) { switch (c) { case 'd': pcidev = optarg; @@ -69,6 +71,9 @@ main(int argc, char *argv[]) case 'v': verbose = 1; break; + case 'x': + hex++; + break; default: usage(); } @@ -76,7 +81,7 @@ main(int argc, char *argv[]) argc -= optind; argv += optind; - if (argc > 1) + if (argc > 1 || (verbose && hex)) usage(); pcifd = open(pcidev, O_RDONLY, 0777); @@ -178,6 +183,8 @@ probe(int bus, int dev, int func) if (verbose) dump(bus, dev, func); + if (hex > 0) + hexdump(bus, dev, func, hex > 1); return (0); } @@ -418,6 +425,25 @@ dump(int bus, int dev, int func) } +void +hexdump(int bus, int dev, int func, int full) +{ + u_int32_t reg; + int i; + + for (i = 0; i < (full ? 256 : 64); i += 4) { + if ((i % 16) == 0) + printf("\t0x%04x:", i); + + if (pci_read(bus, dev, func, i, ®) != 0) + warn("unable to read 0x%02x", i); + printf(" %08x", reg); + + if ((i % 16) == 12) + printf("\n"); + } +} + int pci_nfuncs(int bus, int dev) { |