Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.sbin/pcictl pcictl(8) -- a program for frobbing the PCI ...
details: https://anonhg.NetBSD.org/src/rev/d4ed7f1e865c
branches: trunk
changeset: 514929:d4ed7f1e865c
user: thorpej <thorpej%NetBSD.org@localhost>
date: Thu Sep 13 23:51:04 2001 +0000
description:
pcictl(8) -- a program for frobbing the PCI bus, and also an example
of how to use libpci.
Currently has "list" (list devices within a PCI domain) and "dump" (dump
PCI configuration header for a device) sub-commands.
diffstat:
usr.sbin/pcictl/Makefile | 9 +
usr.sbin/pcictl/pcictl.8 | 87 ++++++++++++
usr.sbin/pcictl/pcictl.c | 317 +++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 413 insertions(+), 0 deletions(-)
diffs (truncated from 425 to 300 lines):
diff -r 2dd3597f2e8b -r d4ed7f1e865c usr.sbin/pcictl/Makefile
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.sbin/pcictl/Makefile Thu Sep 13 23:51:04 2001 +0000
@@ -0,0 +1,9 @@
+# $NetBSD: Makefile,v 1.1 2001/09/13 23:51:04 thorpej Exp $
+
+PROG= pcictl
+MAN= pcictl.8
+
+DPADD+= ${LIBPCI} ${LIBUTIL}
+LDADD+= -lpci -lutil
+
+.include <bsd.prog.mk>
diff -r 2dd3597f2e8b -r d4ed7f1e865c usr.sbin/pcictl/pcictl.8
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.sbin/pcictl/pcictl.8 Thu Sep 13 23:51:04 2001 +0000
@@ -0,0 +1,87 @@
+.\" $NetBSD: pcictl.8,v 1.1 2001/09/13 23:51:04 thorpej Exp $
+.\"
+.\" Copyright 2001 Wasabi Systems, Inc.
+.\" All rights reserved.
+.\"
+.\" Written by Jason R. Thorpe for Wasabi Systems, Inc.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\" notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\" notice, this list of conditions and the following disclaimer in the
+.\" documentation and/or other materials provided with the distribution.
+.\" 3. All advertising materials mentioning features or use of this software
+.\" must display the following acknowledgement:
+.\" This product includes software developed for the NetBSD Project by
+.\" Wasabi Systems, Inc.
+.\" 4. The name of Wasabi Systems, Inc. may not be used to endorse
+.\" or promote products derived from this software without specific prior
+.\" written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
+.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
+.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+.\" POSSIBILITY OF SUCH DAMAGE.
+.\"
+.Dd September 12, 2001
+.Os
+.Dt PCICTL 8
+.Sh NAME
+.Nm pcictl
+.Nd a program to manipulate the PCI bus
+.Sh SYNOPSIS
+.Nm
+.Ar pcibus
+.Ar command
+.Oo
+.Ar arg Oo ...
+.Oc
+.Oc
+.Sh DESCRIPTION
+.Nm
+allows a user to system administrator to access various resources
+on a PCI bus.
+.Pp
+The following commands are available:
+.Pp
+.Nm list
+.Op Fl b Ar bus
+.Op Fl d Ar device
+.Op Fl f Ar function
+.Pp
+List the devices in the PCI domain. The bus, device, and function
+numbers may be specified by flags. Any locator not specified defaults
+to a wildcard, or may be explicitly wildcarded by specifying
+.Dq any .
+.Pp
+.Nm dump
+.Op Fl b Ar bus
+.Fl d Ar device
+.Op Fl f Ar function
+.Pp
+Dump the PCI configuration space for the specified device located
+at the specified bus, device, and function. If the bus is not
+specified, it defaults to the bus number of the PCI bus specified
+on the command line. If the function is not specified, it defaults
+to 0.
+.Sh FILES
+.Pa /dev/pci*
+- PCI bus device nodes
+.Sh SEE ALSO
+.Xr pci 3 ,
+.Xr pci 4
+.Sh HISTORY
+The
+.Nm
+command first appeared in
+.Nx 1.6 .
diff -r 2dd3597f2e8b -r d4ed7f1e865c usr.sbin/pcictl/pcictl.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.sbin/pcictl/pcictl.c Thu Sep 13 23:51:04 2001 +0000
@@ -0,0 +1,317 @@
+/* $NetBSD: pcictl.c,v 1.1 2001/09/13 23:51:04 thorpej Exp $ */
+
+/*
+ * Copyright 2001 Wasabi Systems, Inc.
+ * All rights reserved.
+ *
+ * Written by Jason R. Thorpe for Wasabi Systems, Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed for the NetBSD Project by
+ * Wasabi Systems, Inc.
+ * 4. The name of Wasabi Systems, Inc. may not be used to endorse
+ * or promote products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*
+ * pcictl(8) -- a program to manipulate the PCI bus
+ */
+
+#include <sys/param.h>
+#include <sys/ioctl.h>
+#include <err.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <pci.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <util.h>
+
+#include <dev/pci/pcireg.h>
+#include <dev/pci/pcidevs.h>
+#include <dev/pci/pciio.h>
+
+struct command {
+ const char *cmd_name;
+ const char *arg_names;
+ void (*cmd_func)(int, char *[]);
+ int open_flags;
+};
+
+int main(int, char *[]);
+void usage(void);
+
+int pcifd;
+
+struct pciio_businfo pci_businfo;
+
+const char *dvname;
+char dvname_store[MAXPATHLEN];
+const char *cmdname;
+const char *argnames;
+
+void cmd_list(int, char *[]);
+void cmd_dump(int, char *[]);
+
+const struct command commands[] = {
+ { "list",
+ "[-b bus] [-d device] [-f function]",
+ cmd_list,
+ O_RDONLY },
+
+ { "dump",
+ "[-b bus] -d device [-f function]",
+ cmd_dump,
+ O_RDONLY },
+
+ { 0 },
+};
+
+int parse_bdf(const char *);
+
+void scan_pci(int, int, int, void (*)(u_int, u_int, u_int));
+
+void scan_pci_list(u_int, u_int, u_int);
+void scan_pci_dump(u_int, u_int, u_int);
+
+int
+main(int argc, char *argv[])
+{
+ int i;
+
+ /* Must have at least: device command */
+ if (argc < 3)
+ usage();
+
+ /* Skip program name, get and skip device name, get command. */
+ dvname = argv[1];
+ cmdname = argv[2];
+ argv += 2;
+ argc -= 2;
+
+ /* Look up and call the command. */
+ for (i = 0; commands[i].cmd_name != NULL; i++)
+ if (strcmp(cmdname, commands[i].cmd_name) == 0)
+ break;
+ if (commands[i].cmd_name == NULL)
+ errx(1, "unknown command: %s", cmdname);
+
+ argnames = commands[i].arg_names;
+
+ /* Open the device. */
+ pcifd = opendisk(dvname, commands[i].open_flags, dvname_store,
+ sizeof(dvname_store), 1);
+ if (pcifd == -1)
+ err(1, "%s", dvname);
+
+ dvname = dvname_store;
+
+ /* Make sure the device is a PCI bus. */
+ if (ioctl(pcifd, PCI_IOC_BUSINFO, &pci_businfo) != 0)
+ errx(1, "%s: not a PCI bus device\n", dvname);
+
+ (*commands[i].cmd_func)(argc, argv);
+ exit(0);
+}
+
+void
+usage()
+{
+ int i;
+
+ fprintf(stderr, "Usage: %s device command [arg [...]]\n",
+ getprogname());
+
+ fprintf(stderr, " Available commands:\n");
+ for (i = 0; commands[i].cmd_name != NULL; i++)
+ fprintf(stderr, "\t%s %s\n", commands[i].cmd_name,
+ commands[i].arg_names);
+
+ exit(1);
+}
+
+void
+cmd_list(int argc, char *argv[])
+{
+ int bus, dev, func;
+ int ch;
+
+ bus = dev = func = -1;
+
+ while ((ch = getopt(argc, argv, "b:d:f:")) != -1) {
+ switch (ch) {
+ case 'b':
+ bus = parse_bdf(optarg);
+ break;
+ case 'd':
+ dev = parse_bdf(optarg);
+ break;
+ case 'f':
+ func = parse_bdf(optarg);
+ break;
+ default:
+ usage();
+ }
+ }
+ argv += optind;
+ argc -= optind;
+
+ if (argc != 0)
+ usage();
+
+ scan_pci(bus, dev, func, scan_pci_list);
+}
+
+void
+cmd_dump(int argc, char *argv[])
+{
+ int bus, dev, func;
Home |
Main Index |
Thread Index |
Old Index