Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/pci Add an ioctl interface to the PCI bus. Add ioct...



details:   https://anonhg.NetBSD.org/src/rev/2571b3c8c06c
branches:  trunk
changeset: 514911:2571b3c8c06c
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Thu Sep 13 21:49:40 2001 +0000

description:
Add an ioctl interface to the PCI bus.  Add ioctls to read/write
PCI configuration space registers, and to fetch bus info.

diffstat:

 sys/dev/pci/files.pci    |    3 +-
 sys/dev/pci/pci.c        |   13 +---
 sys/dev/pci/pci_usrreq.c |  160 +++++++++++++++++++++++++++++++++++++++++++++++
 sys/dev/pci/pciio.h      |   96 ++++++++++++++++++++++++++++
 sys/dev/pci/pcivar.h     |   27 +++++++-
 5 files changed, 283 insertions(+), 16 deletions(-)

diffs (truncated from 376 to 300 lines):

diff -r a0afa26de655 -r 2571b3c8c06c sys/dev/pci/files.pci
--- a/sys/dev/pci/files.pci     Thu Sep 13 21:42:57 2001 +0000
+++ b/sys/dev/pci/files.pci     Thu Sep 13 21:49:40 2001 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: files.pci,v 1.138 2001/09/04 13:37:29 itohy Exp $
+#      $NetBSD: files.pci,v 1.139 2001/09/13 21:49:40 thorpej Exp $
 #
 # Config file and device description for machine-independent PCI code.
 # Included by ports that need it.  Requires that the SCSI files be
@@ -21,6 +21,7 @@
 file   dev/pci/pci_map.c               pci
 file   dev/pci/pci_quirks.c            pci
 file   dev/pci/pci_subr.c              pci
+file   dev/pci/pci_usrreq.c            pci
 file   dev/pci/pciconf.c               pci_netbsd_configure
 
 # Cypress 82c693 hyperCache(tm) Stand-Alone PCI Peripheral Controller
diff -r a0afa26de655 -r 2571b3c8c06c sys/dev/pci/pci.c
--- a/sys/dev/pci/pci.c Thu Sep 13 21:42:57 2001 +0000
+++ b/sys/dev/pci/pci.c Thu Sep 13 21:49:40 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pci.c,v 1.55 2001/09/10 10:04:49 fvdl Exp $    */
+/*     $NetBSD: pci.c,v 1.56 2001/09/13 21:49:40 thorpej Exp $ */
 
 /*
  * Copyright (c) 1995, 1996, 1997, 1998
@@ -54,17 +54,6 @@
 int pcimatch __P((struct device *, struct cfdata *, void *));
 void pciattach __P((struct device *, struct device *, void *));
 
-struct pci_softc {
-       struct device sc_dev;
-       bus_space_tag_t sc_iot, sc_memt;
-       bus_dma_tag_t sc_dmat;
-       pci_chipset_tag_t sc_pc;
-       int sc_bus, sc_maxndevs;
-       u_int sc_intrswiz;
-       pcitag_t sc_intrtag;
-       int sc_flags;
-};
-
 struct cfattach pci_ca = {
        sizeof(struct pci_softc), pcimatch, pciattach
 };
diff -r a0afa26de655 -r 2571b3c8c06c sys/dev/pci/pci_usrreq.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/dev/pci/pci_usrreq.c  Thu Sep 13 21:49:40 2001 +0000
@@ -0,0 +1,160 @@
+/*     $NetBSD: pci_usrreq.c,v 1.1 2001/09/13 21:49:40 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.
+ */
+
+/*
+ * User -> kernel interface for PCI bus access.
+ */
+
+#include <sys/param.h>
+#include <sys/conf.h>
+#include <sys/device.h>
+#include <sys/ioctl.h>
+#include <sys/proc.h>
+#include <sys/systm.h>
+#include <sys/errno.h>
+#include <sys/fcntl.h>
+
+#include <dev/pci/pcireg.h>
+#include <dev/pci/pcivar.h>
+#include <dev/pci/pciio.h>
+
+cdev_decl(pci);
+
+int
+pciopen(dev_t dev, int flags, int mode, struct proc *p)
+{
+       struct pci_softc *sc;
+       int unit;
+
+       unit = minor(dev);
+       sc = device_lookup(&pci_cd, unit);
+       if (sc == NULL)
+               return (ENXIO);
+
+       return (0);
+}
+
+int
+pciclose(dev_t dev, int flags, int mode, struct proc *p)
+{
+
+       return (0);
+}
+
+int
+pciioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p)
+{
+       struct pci_softc *sc = device_lookup(&pci_cd, minor(dev));
+       struct pciio_bdf_cfgreg *bdfr = (void *) data;
+       struct pciio_businfo *binfo = (void *) data;
+       pcitag_t tag;
+
+       switch (cmd) {
+       case PCI_IOC_BDF_CFGREAD:
+       case PCI_IOC_BDF_CFGWRITE:
+               if (bdfr->bus > 255 || bdfr->device >= sc->sc_maxndevs ||
+                   bdfr->function > 7)
+                       return (EINVAL);
+               tag = pci_make_tag(sc->sc_pc, bdfr->bus, bdfr->device,
+                   bdfr->function);
+               if (cmd == PCI_IOC_BDF_CFGREAD)
+                       bdfr->cfgreg.val = pci_conf_read(sc->sc_pc, tag,
+                           bdfr->cfgreg.reg);
+               else {
+                       if ((flag & FWRITE) == 0)
+                               return (EBADF);
+                       pci_conf_write(sc->sc_pc, tag, bdfr->cfgreg.reg,
+                           bdfr->cfgreg.val);
+               }
+               break;
+
+       case PCI_IOC_BUSINFO:
+               binfo->busno = sc->sc_bus;
+               binfo->maxdevs = sc->sc_maxndevs;
+               break;
+
+       default:
+               return (ENOTTY);
+       }
+
+       return (0);
+}
+
+paddr_t
+pcimmap(dev_t dev, off_t offset, int prot)
+{
+       struct pci_softc *sc = device_lookup(&pci_cd, minor(dev));
+
+       /*
+        * Since we allow mapping of the entire bus, we
+        * take the offset to be the address on the bus,
+        * and pass 0 as the offset into that range.
+        *
+        * XXX Need a way to deal with linear/prefetchable/etc.
+        */
+       return (bus_space_mmap(sc->sc_memt, offset, 0, prot, 0));
+}
+
+/*
+ * pci_devioctl:
+ *
+ *     PCI ioctls that can be performed on devices directly.
+ */
+int
+pci_devioctl(pci_chipset_tag_t pc, pcitag_t tag, u_long cmd, caddr_t data,
+    int flag, struct proc *p)
+{
+       struct pciio_cfgreg *r = (void *) data;
+
+       switch (cmd) {
+       case PCI_IOC_CFGREAD:
+       case PCI_IOC_CFGWRITE:
+               if (cmd == PCI_IOC_CFGREAD)
+                       r->val = pci_conf_read(pc, tag, r->reg);
+               else {
+                       if ((flag & FWRITE) == 0)
+                               return (EBADF);
+                       pci_conf_write(pc, tag, r->reg, r->val);
+               }
+               break;
+
+       default:
+               return (ENOTTY);
+       }
+
+       return (0);
+}
diff -r a0afa26de655 -r 2571b3c8c06c sys/dev/pci/pciio.h
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/dev/pci/pciio.h       Thu Sep 13 21:49:40 2001 +0000
@@ -0,0 +1,96 @@
+/*     $NetBSD: pciio.h,v 1.1 2001/09/13 21:49:40 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.
+ */
+
+#ifndef _DEV_PCI_PCIIO_H_
+#define        _DEV_PCI_PCIIO_H_
+
+/*
+ * User -> kernel interface for PCI bus access.
+ */
+
+#include <sys/ioccom.h>
+
+/*
+ * pciio_cfgreg:
+ *
+ *     Representation of a PCI config space register.
+ */
+struct pciio_cfgreg {
+       u_int    reg;   /* offset into PCI configuration space */
+       uint32_t val;   /* value of the register */
+};
+
+/*
+ * Read and write PCI configuration space registers on a
+ * specific device.
+ */
+#define        PCI_IOC_CFGREAD         _IOWR('P', 0, struct pciio_cfgreg)
+#define        PCI_IOC_CFGWRITE         _IOW('P', 1, struct pciio_cfgreg)
+
+/*
+ * pciio_bdf_cfgreg:
+ *
+ *     Like pciio_cfgreg, except for any bus/dev/func within
+ *     a given PCI domain.
+ */
+struct pciio_bdf_cfgreg {
+       u_int   bus;
+       u_int   device;
+       u_int   function;
+       struct pciio_cfgreg cfgreg;
+};
+
+/*
+ * Read and write PCI configuration space registers on any
+ * device within a given PCI domain.
+ */
+#define        PCI_IOC_BDF_CFGREAD     _IOWR('P', 2, struct pciio_bdf_cfgreg)
+#define        PCI_IOC_BDF_CFGWRITE     _IOW('P', 3, struct pciio_bdf_cfgreg)
+
+/*
+ * pciio_businfo:
+ *
+ *     Unformation for a PCI bus (autconfiguration node) instance.
+ */



Home | Main Index | Thread Index | Old Index