Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/i386 Added a PCI frontend for the legacy ISA joysti...



details:   https://anonhg.NetBSD.org/src/rev/e9db91768823
branches:  trunk
changeset: 484136:e9db91768823
user:      martin <martin%NetBSD.org@localhost>
date:      Sun Mar 26 15:36:48 2000 +0000

description:
Added a PCI frontend for the legacy ISA joystick driver.
Some PCI soundcards don't seem to use the generic gameport function with
interface 0x10 used here, but have either an own BAR dedicated to this
(i.e. Sonic Vibes or ESS Solo-1) or specify their own device (see
PCI_PRODUCT_CREATIVELABS_SBJOY in sys/dev/pci/pcidevs.h).
Probably these use a similar simple sheme and adding a frontend for them would
be trivial, but I don't own any of these cards, so I didn't.

diffstat:

 sys/arch/i386/conf/GENERIC    |    7 +-
 sys/arch/i386/conf/files.i386 |   14 ++-
 sys/arch/i386/pci/joy_pci.c   |  135 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 149 insertions(+), 7 deletions(-)

diffs (201 lines):

diff -r db36a1a6fb87 -r e9db91768823 sys/arch/i386/conf/GENERIC
--- a/sys/arch/i386/conf/GENERIC        Sun Mar 26 15:08:43 2000 +0000
+++ b/sys/arch/i386/conf/GENERIC        Sun Mar 26 15:36:48 2000 +0000
@@ -1,11 +1,11 @@
-#      $NetBSD: GENERIC,v 1.316 2000/03/22 11:22:21 onoe Exp $
+#      $NetBSD: GENERIC,v 1.317 2000/03/26 15:36:49 martin Exp $
 #
 #      GENERIC -- everything that's currently supported
 #
 
 include "arch/i386/conf/std.i386"
 
-#ident                 "GENERIC-$Revision: 1.316 $"
+#ident                 "GENERIC-$Revision: 1.317 $"
 
 maxusers       32              # estimated number of users
 
@@ -754,6 +754,9 @@
 # ISA Plug-and-Play joysticks
 joy*   at isapnp?                      # Game ports (usually on audio cards)
 
+# PCI joysticks
+joy*   at pci?                         # Game ports (usually on audio cards)
+
 # ISA joysticks. Probe is a little strange; add only if you have one.
 #joy0  at isa? port 0x201
 
diff -r db36a1a6fb87 -r e9db91768823 sys/arch/i386/conf/files.i386
--- a/sys/arch/i386/conf/files.i386     Sun Mar 26 15:08:43 2000 +0000
+++ b/sys/arch/i386/conf/files.i386     Sun Mar 26 15:36:48 2000 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: files.i386,v 1.152 2000/03/22 20:58:25 ws Exp $
+#      $NetBSD: files.i386,v 1.153 2000/03/26 15:36:49 martin Exp $
 #
 # new style config file for i386 architecture
 #
@@ -149,6 +149,14 @@
 attach pcib at pci
 file   arch/i386/pci/pcib.c            pcib
 
+# Game adapter (joystick)
+device joy
+file   arch/i386/isa/joy.c             joy needs-flag
+
+# PCI joysticks
+attach joy at pci with pci_joy
+file   arch/i386/pci/joy_pci.c         pci_joy
+
 #
 # ISA and mixed ISA+EISA or ISA+PCI drivers
 #
@@ -230,10 +238,6 @@
 file   arch/i386/isa/fd.c              fdc needs-flag
 major  {fd = 2}
 
-# Game adapter (joystick)
-device joy
-file   arch/i386/isa/joy.c             joy needs-flag
-
 attach joy at isa with joy_isa
 file   arch/i386/isa/joy_isa.c         joy_isa
 
diff -r db36a1a6fb87 -r e9db91768823 sys/arch/i386/pci/joy_pci.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/i386/pci/joy_pci.c       Sun Mar 26 15:36:48 2000 +0000
@@ -0,0 +1,135 @@
+/*     $NetBSD: joy_pci.c,v 1.1 2000/03/26 15:36:48 martin Exp $       */
+
+/*-
+ * Copyright (c) 2000 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Martin Husemann
+ *
+ * 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 by the NetBSD
+ *        Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``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 THE FOUNDATION OR CONTRIBUTORS
+ * 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.
+ */
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+#include <sys/device.h>
+
+#include <machine/bus.h>
+
+#include <dev/pci/pcireg.h>
+#include <dev/pci/pcivar.h>
+
+#include <i386/isa/joyvar.h>
+
+int    joy_pci_match __P((struct device *, struct cfdata *, void *));
+void   joy_pci_attach __P((struct device *, struct device *, void *));
+static int bar_is_io __P((pci_chipset_tag_t pc, pcitag_t tag, int reg));
+
+struct cfattach pci_joy_ca = {
+       sizeof(struct joy_softc), joy_pci_match, joy_pci_attach
+};
+
+int
+joy_pci_match(parent, match, aux)
+       struct device *parent;
+       struct cfdata *match;
+       void *aux;
+{
+       struct pci_attach_args *pa = aux;
+
+       if (PCI_CLASS(pa->pa_class) == PCI_CLASS_INPUT &&
+           PCI_SUBCLASS(pa->pa_class) == PCI_SUBCLASS_INPUT_GAMEPORT &&
+           PCI_INTERFACE(pa->pa_class) == 0x10)
+               return (1);
+
+       return (0);
+}
+
+/* check if this BAR assigns/requests IO space */
+static int
+bar_is_io(pc, tag, reg)
+        pci_chipset_tag_t pc;
+        pcitag_t tag;
+        int reg;
+{
+       pcireg_t address, mask;
+       int s;
+
+       /*
+        * The splhigh() is not realy necessary at autoconfig time,
+        * but maybe useful if used in lkm context later.
+        */
+       s = splhigh();
+       address = pci_conf_read(pc, tag, reg);
+       pci_conf_write(pc, tag, reg, 0xffffffff);
+       mask = pci_conf_read(pc, tag, reg);
+       pci_conf_write(pc, tag, reg, address);
+       splx(s);
+
+       return (PCI_MAPREG_TYPE(address) == PCI_MAPREG_TYPE_IO && PCI_MAPREG_IO_SIZE(mask) > 0);
+}
+
+void
+joy_pci_attach(parent, self, aux)
+       struct device *parent, *self;
+       void *aux;
+{
+       struct joy_softc *sc = (struct joy_softc *)self;
+       struct pci_attach_args *pa = aux;
+       char devinfo[256];
+       bus_size_t mapsize;
+       int reg;
+
+       pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo);
+       printf(": %s (rev 0x%02x)\n", devinfo, PCI_REVISION(pa->pa_class));
+
+       for (reg = PCI_MAPREG_START; reg < PCI_MAPREG_END; reg++)
+               if (bar_is_io(pa->pa_pc, pa->pa_tag, reg))
+                       break;
+       if (reg >= PCI_MAPREG_END) {
+               printf("%s: violates PCI spec, no IO region found\n", sc->sc_dev.dv_xname);
+               return;
+       }
+
+       if (pci_mapreg_map(pa, reg, PCI_MAPREG_TYPE_IO, 0,
+           &sc->sc_iot, &sc->sc_ioh, NULL, &mapsize)) {
+               printf("%s: could not map IO space\n", sc->sc_dev.dv_xname);
+               return;
+       }
+
+       if (mapsize != 2) {
+               if (!bus_space_subregion(sc->sc_iot, sc->sc_ioh, 1, 1, &sc->sc_ioh) < 0) {
+                       printf("%s: error mapping subregion\n", sc->sc_dev.dv_xname);
+                       return;
+               }
+       }
+
+       joyattach(sc);
+}



Home | Main Index | Thread Index | Old Index