summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Downs <downsj@cvs.openbsd.org>1997-12-21 14:41:29 +0000
committerJason Downs <downsj@cvs.openbsd.org>1997-12-21 14:41:29 +0000
commit7e6d3badae322b7db18165c8e8372043086045d5 (patch)
tree87c5c1f8df4d75f9c9b3d613eb6003273501539a
parent845b9b531517de61c796048492b408b5519f4be8 (diff)
Obliterate old PnP `code' and outright replace with christos' code.
-rw-r--r--sys/dev/isa/devlist2h.awk4
-rw-r--r--sys/dev/isa/files.isa10
-rw-r--r--sys/dev/isa/files.isapnp19
-rw-r--r--sys/dev/isa/isa.c47
-rw-r--r--sys/dev/isa/isadma.c22
-rw-r--r--sys/dev/isa/isadmavar.h3
-rw-r--r--sys/dev/isa/isapnp.c1814
-rw-r--r--sys/dev/isa/isapnpdebug.c411
-rw-r--r--sys/dev/isa/isapnpreg.h223
-rw-r--r--sys/dev/isa/isapnpres.c524
-rw-r--r--sys/dev/isa/isapnpvar.h240
-rw-r--r--sys/dev/isa/isavar.h28
-rw-r--r--sys/dev/isa/pnpdevs.h16
13 files changed, 2030 insertions, 1331 deletions
diff --git a/sys/dev/isa/devlist2h.awk b/sys/dev/isa/devlist2h.awk
index 2d21fdeeaab..25e9f1c623a 100644
--- a/sys/dev/isa/devlist2h.awk
+++ b/sys/dev/isa/devlist2h.awk
@@ -1,5 +1,5 @@
#! /usr/bin/awk -f
-# $OpenBSD: devlist2h.awk,v 1.2 1997/11/07 08:06:44 niklas Exp $
+# $OpenBSD: devlist2h.awk,v 1.3 1997/12/21 14:41:21 downsj Exp $
# $NetBSD: devlist2h.awk,v 1.2 1996/01/22 21:08:09 cgd Exp $
#
# Copyright (c) 1995, 1996 Christopher G. Demetriou
@@ -69,7 +69,7 @@ END {
printf("\n") > dfile
- printf("struct pnp_knowndev pnp_knowndevs[] = {\n") > dfile
+ printf("struct isapnp_knowndev isapnp_knowndevs[] = {\n") > dfile
for (i = 1; i <= nproducts; i++) {
printf("\t{ \"%s\", \"%s\" },",
products[i, 2], products[i, 1]) \
diff --git a/sys/dev/isa/files.isa b/sys/dev/isa/files.isa
index b3a2a64f75d..e4c204e5671 100644
--- a/sys/dev/isa/files.isa
+++ b/sys/dev/isa/files.isa
@@ -1,4 +1,4 @@
-# $OpenBSD: files.isa,v 1.35 1997/11/06 02:53:42 niklas Exp $
+# $OpenBSD: files.isa,v 1.36 1997/12/21 14:41:22 downsj Exp $
# $NetBSD: files.isa,v 1.21 1996/05/16 03:45:55 mycroft Exp $
#
# Config.new file and device description for machine-independent ISA code.
@@ -25,13 +25,6 @@ attach isadma at isa: isa_dma
file dev/isa/isadma.c isadma needs-flag
#
-# ISA PnP capability
-#
-device isapnp
-attach isapnp at isa
-file dev/isa/isapnp.c isapnp needs-flag
-
-#
# 8250/16[45]50-based multi-port serial boards
#
@@ -281,3 +274,4 @@ attach pcic at pcicmaster
file dev/isa/pcmcia_pcic.c pcic | pcicmaster
file dev/isa/pcmcia_isa.c pcmcia
+
diff --git a/sys/dev/isa/files.isapnp b/sys/dev/isa/files.isapnp
new file mode 100644
index 00000000000..585ef752b12
--- /dev/null
+++ b/sys/dev/isa/files.isapnp
@@ -0,0 +1,19 @@
+# $OpenBSD: files.isapnp,v 1.1 1997/12/21 14:41:22 downsj Exp $
+# $NetBSD: files.isapnp,v 1.7 1997/10/16 17:16:36 matt Exp $
+#
+# Config file and device description for machine-independent ISAPnP code.
+# Included by ports that need it.
+
+device isapnp {[port = -1], [size = 0],
+ [iomem = -1], [iosiz = 0],
+ [irq = -1], [drq = -1]}
+attach isapnp at isa
+file dev/isa/isapnp.c isapnp
+file dev/isa/isapnpdebug.c isapnp
+file dev/isa/isapnpres.c isapnp
+
+#
+# MI PnP devices go here...
+#
+
+#attach com at isapnp with com_isapnp
diff --git a/sys/dev/isa/isa.c b/sys/dev/isa/isa.c
index f85294f24ae..057ac452207 100644
--- a/sys/dev/isa/isa.c
+++ b/sys/dev/isa/isa.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: isa.c,v 1.22 1997/01/04 14:14:55 niklas Exp $ */
+/* $OpenBSD: isa.c,v 1.23 1997/12/21 14:41:23 downsj Exp $ */
/* $NetBSD: isa.c,v 1.85 1996/05/14 00:31:04 thorpej Exp $ */
/*-
@@ -43,8 +43,6 @@
#include <dev/isa/isareg.h>
#include <dev/isa/isavar.h>
-#include "isapnp.h"
-
int isamatch __P((struct device *, void *, void *));
void isaattach __P((struct device *, struct device *, void *));
@@ -79,9 +77,6 @@ isaattach(parent, self, aux)
{
struct isa_softc *sc = (struct isa_softc *)self;
struct isabus_attach_args *iba = aux;
-#if NISAPNP > 0
- void postisapnpattach __P((struct device *, struct device *, void *));
-#endif /* NISAPNP > 0 */
isa_attach_hook(parent, self, iba);
printf("\n");
@@ -100,10 +95,6 @@ isaattach(parent, self, aux)
TAILQ_INIT(&sc->sc_subdevs);
config_scan(isascan, self);
-
-#if NISAPNP > 0
- postisapnpattach(parent, self, aux);
-#endif /* NISAPNP > 0 */
}
int
@@ -137,19 +128,6 @@ isascan(parent, match)
struct device *dev = match;
struct cfdata *cf = dev->dv_cfdata;
struct isa_attach_args ia;
-#if 0
- struct emap *io_map, *mem_map, *irq_map, *drq_map;
-#endif
-
- if (cf->cf_loc[6] != -1) /* pnp device, scanned later */
- return;
-
-#if 0
- io_map = find_emap("io");
- mem_map = find_emap("mem");
- irq_map = find_emap("irq");
- drq_map = find_emap("drq");
-#endif
ia.ia_iot = sc->sc_iot;
ia.ia_memt = sc->sc_memt;
@@ -171,16 +149,6 @@ isascan(parent, match)
sc->sc_dev.dv_xname);
ia2.ia_iosize = 0;
}
-#if 0
- if (ia2.ia_iobase != -1 && ia2.ia_iosize > 0)
- add_extent(io_map, ia2.ia_iobase, ia2.ia_iosize);
- if (ia.ia_maddr != -1 && ia.ia_msize > 0)
- add_extent(mem_map, ia2.ia_maddr, ia2.ia_msize);
- if (ia2.ia_irq != -1)
- add_extent(irq_map, ia2.ia_irq, 1);
- if (ia2.ia_drq != -1)
- add_extent(drq_map, ia2.ia_drq, 1);
-#endif
config_attach(parent, dev, &ia2, isaprint);
dev = config_make_softc(parent, cf);
ia2 = ia;
@@ -189,19 +157,8 @@ isascan(parent, match)
return;
}
- if ((*cf->cf_attach->ca_match)(parent, dev, &ia) > 0) {
-#if 0
- if (ia.ia_iobase > 0 && ia.ia_iosize > 0)
- add_extent(io_map, ia.ia_iobase, ia.ia_iosize);
- if (ia.ia_maddr > 0 && ia.ia_msize > 0)
- add_extent(mem_map, ia.ia_maddr, ia.ia_msize);
- if (ia.ia_irq > 0)
- add_extent(irq_map, ia.ia_irq, 1);
- if (ia.ia_drq > 0)
- add_extent(drq_map, ia.ia_drq, 1);
-#endif
+ if ((*cf->cf_attach->ca_match)(parent, dev, &ia) > 0)
config_attach(parent, dev, &ia, isaprint);
- }
else
free(dev, M_DEVBUF);
}
diff --git a/sys/dev/isa/isadma.c b/sys/dev/isa/isadma.c
index ffdb083b424..8d854b4b381 100644
--- a/sys/dev/isa/isadma.c
+++ b/sys/dev/isa/isadma.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: isadma.c,v 1.14 1997/11/04 10:32:51 provos Exp $ */
+/* $OpenBSD: isadma.c,v 1.15 1997/12/21 14:41:23 downsj Exp $ */
/* $NetBSD: isadma.c,v 1.19 1996/04/29 20:03:26 christos Exp $ */
#include <sys/param.h>
@@ -128,6 +128,20 @@ isadma_release(chan)
di->inuse = 0;
}
+int
+isadma_isdrqfree(chan)
+ int chan;
+{
+ struct dma_info *di;
+#ifdef DIAGNOSTIC
+ if (chan < 0 || chan > 7)
+ panic("isadma_release: channel out of range");
+#endif
+ di = dma_info + chan;
+
+ return (di->inuse);
+}
+
/*
* isadma_cascade(): program 8237 DMA controller channel to accept
* external dma control by a board.
@@ -136,11 +150,13 @@ void
isadma_cascade(chan)
int chan;
{
+ struct dma_info *di;
#ifdef ISADMA_DEBUG
if (chan < 0 || chan > 7)
panic("isadma_cascade: impossible request");
#endif
+ di = dma_info + chan;
/* set dma channel mode, and set dma channel mode */
if ((chan & 4) == 0) {
@@ -152,6 +168,10 @@ isadma_cascade(chan)
outb(DMA2_MODE, chan | DMA37MD_CASCADE);
outb(DMA2_SMSK, chan);
}
+
+ /* Mark it as in use, if needed. XXX */
+ if (!di->inuse)
+ di->inuse = 1;
}
/*
diff --git a/sys/dev/isa/isadmavar.h b/sys/dev/isa/isadmavar.h
index d976150b045..9e424edc959 100644
--- a/sys/dev/isa/isadmavar.h
+++ b/sys/dev/isa/isadmavar.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: isadmavar.h,v 1.8 1997/11/04 10:32:51 provos Exp $ */
+/* $OpenBSD: isadmavar.h,v 1.9 1997/12/21 14:41:24 downsj Exp $ */
/* $NetBSD: isadmavar.h,v 1.4 1996/03/01 04:08:46 mycroft Exp $ */
#define DMAMODE_WRITE 0
@@ -26,6 +26,7 @@ void isadma_copyfrombuf __P((caddr_t, vm_size_t, int, struct isadma_seg *));
int isadma_acquire __P((int));
void isadma_release __P((int));
+int isadma_isdrqfree __P((int));
void isadma_cascade __P((int));
void isadma_start __P((caddr_t, vm_size_t, int, int));
void isadma_abort __P((int));
diff --git a/sys/dev/isa/isapnp.c b/sys/dev/isa/isapnp.c
index cd2bfa429ec..2b90da5cb38 100644
--- a/sys/dev/isa/isapnp.c
+++ b/sys/dev/isa/isapnp.c
@@ -1,8 +1,8 @@
-/* $OpenBSD: isapnp.c,v 1.11 1997/07/13 22:27:04 weingart Exp $ */
+/* $OpenBSD: isapnp.c,v 1.12 1997/12/21 14:41:24 downsj Exp $ */
+/* $NetBSD: isapnp.c,v 1.9.4.3 1997/10/29 00:40:43 thorpej Exp $ */
/*
- * Copyright (c) 1996, Shawn Hsiao <shawn@alpha.secc.fju.edu.tw>
- * All rights reserved.
+ * Copyright (c) 1996 Christos Zoulas. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -12,1271 +12,885 @@
* 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 Christos Zoulas.
+ * 4. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
*
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
*/
/*
- * Note: Most of the basic code was originally written by Sujal M. Patel,
- * plus some code takes from his pnpinfo(8).
- */
-/*
- * Copyright (c) 1996, Sujal M. Patel
- * All rights reserved.
- *
- * 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.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
+ * ISA PnP bus autoconfiguration.
*/
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/device.h>
#include <sys/malloc.h>
-#include <sys/queue.h>
-#include <sys/extent.h>
+
#include <machine/bus.h>
#include <dev/isa/isavar.h>
+#include <dev/isa/isadmavar.h>
#include <dev/isa/isapnpreg.h>
#include <dev/isa/isapnpvar.h>
+
#include <dev/isa/pnpdevs.h>
-#define SEND(d, r) { bus_space_write_1(sc->iot, sc->addrh, 0, d); \
- bus_space_write_1(sc->iot, sc->wdh, 0, r); }
+void isapnp_init __P((struct isapnp_softc *));
+static __inline u_char isapnp_shift_bit __P((struct isapnp_softc *));
+int isapnp_findcard __P((struct isapnp_softc *));
+void isapnp_free_region __P((bus_space_tag_t, struct isapnp_region *));
+int isapnp_alloc_region __P((bus_space_tag_t, struct isapnp_region *));
+int isapnp_alloc_irq __P((isa_chipset_tag_t, struct isapnp_pin *));
+int isapnp_alloc_drq __P((struct device *, struct isapnp_pin *));
+int isapnp_testconfig __P((bus_space_tag_t, bus_space_tag_t,
+ struct isapnp_attach_args *, int));
+struct isapnp_attach_args *isapnp_bestconfig __P((struct device *,
+ struct isapnp_softc *, struct isapnp_attach_args **));
+void isapnp_print_region __P((const char *, struct isapnp_region *,
+ size_t));
+void isapnp_configure __P((struct isapnp_softc *,
+ const struct isapnp_attach_args *));
+void isapnp_print_pin __P((const char *, struct isapnp_pin *, size_t));
+int isapnp_print __P((void *, const char *));
+#ifdef _KERNEL
+int isapnp_submatch __P((struct device *, void *, void *));
+#endif
+int isapnp_find __P((struct isapnp_softc *, int));
+int isapnp_match __P((struct device *, void *, void *));
+void isapnp_attach __P((struct device *, struct device *, void *));
-int isapnpmatch __P((struct device *, void *, void *));
-void isapnpattach __P((struct device *, struct device *, void *));
-int isapnpprint __P((void *aux, const char *pnp));
-int isapnpsubmatch __P((struct device *parent, void *match, void *aux));
+struct cfattach isapnp_ca = {
+ sizeof(struct isapnp_softc), isapnp_match, isapnp_attach
+};
-/* XXX */
-struct emap {
- int whatever;
+struct cfdriver isapnp_cd = {
+ NULL, "isapnp", DV_DULL
};
-void add_extent __P((struct emap *, long, int));
-struct emap *find_emap __P((char *));
-int probe_extent __P((struct emap *, int, int));
-struct isapnp_softc {
- struct device sc_dev;
- struct device *parent;
+/* isapnp_init():
+ * Write the PNP initiation key to wake up the cards...
+ */
+void
+isapnp_init(sc)
+ struct isapnp_softc *sc;
+{
+ int i;
+ u_char v = ISAPNP_LFSR_INIT;
- bus_space_tag_t iot;
- bus_space_handle_t addrh;
- bus_space_handle_t wdh;
- bus_space_handle_t rdh;
+ /* First write 0's twice to enter the Wait for Key state */
+ ISAPNP_WRITE_ADDR(sc, 0);
+ ISAPNP_WRITE_ADDR(sc, 0);
- int rd_port;
+ /* Send the 32 byte sequence to awake the logic */
+ for (i = 0; i < ISAPNP_LFSR_LENGTH; i++) {
+ ISAPNP_WRITE_ADDR(sc, v);
+ v = ISAPNP_LFSR_NEXT(v);
+ }
+}
- TAILQ_HEAD(, cardinfo) q_card;
-};
-struct cfattach isapnp_ca = {
- sizeof(struct isapnp_softc), isapnpmatch, isapnpattach
-};
+/* isapnp_shift_bit():
+ * Read a bit at a time from the config card.
+ */
+static __inline u_char
+isapnp_shift_bit(sc)
+ struct isapnp_softc *sc;
+{
+ u_char c1, c2;
-struct cfdriver isapnp_cd = {
- NULL, "isapnp", DV_DULL, 1
-};
+ DELAY(250);
+ c1 = ISAPNP_READ_DATA(sc);
+ DELAY(250);
+ c2 = ISAPNP_READ_DATA(sc);
+
+ if (c1 == 0x55 && c2 == 0xAA)
+ return 0x80;
+ else
+ return 0;
+}
-int isapnpquery __P((struct isapnp_softc *, u_int32_t,
- struct isa_attach_args *));
-void send_Initiation_LFSR __P((struct isapnp_softc *));
-int get_serial __P((struct isapnp_softc *, unsigned char *));
-int isolation_protocol __P((struct isapnp_softc *));
-void read_config __P((struct isapnp_softc *, struct cardinfo *, int));
-int get_resource_info __P((struct isapnp_softc *, u_char *, int));
-void config_device __P((struct isapnp_softc *, struct isa_attach_args *));
-int find_free_irq __P((int));
-int find_free_drq __P((int));
-int find_free_io __P((struct isapnp_softc *, int, int, int, int,
- int, int));
-void postisapnpattach __P((struct device *, struct device *, void *));
-char *searchpnpdevtab __P((char *));
-char *makepnpname __P((u_int32_t));
-void isapnpextent __P((struct isa_attach_args *));
-int handle_small_res __P((unsigned char *, int, int, struct cardinfo *));
-void handle_large_res __P((unsigned char *, int, int, struct cardinfo *));
+/* isapnp_findcard():
+ * Attempt to read the vendor/serial/checksum for a card
+ * If a card is found [the checksum matches], assign the
+ * next card number to it and return 1
+ */
int
-isapnpmatch(parent, match, aux)
- struct device *parent;
- void *match, *aux;
+isapnp_findcard(sc)
+ struct isapnp_softc *sc;
{
- struct isa_attach_args *ia = aux;
+ u_char v = ISAPNP_LFSR_INIT, csum, w;
+ int i, b;
- /* sure we exist */
- ia->ia_iosize = 0;
- return(1);
-}
+ if (sc->sc_ncards == ISAPNP_MAX_CARDS) {
+ printf("%s: Too many pnp cards\n", sc->sc_dev.dv_xname);
+ return 0;
+ }
-void
-isapnpattach(parent, self, aux)
- struct device *parent, *self;
- void *aux;
-{
- struct isa_softc *isc = (void *)parent;
- struct isapnp_softc *sc = (void *)self;
- struct isa_attach_args *ia = aux;
- int num_pnp_devs;
-
- /*
- * a reference to corresponding isapnp_softc
- */
- isc->pnpsc = sc;
-
- sc->iot = ia->ia_iot;
- sc->parent = parent;
- TAILQ_INIT(&sc->q_card);
-
- /* The bus_space_*() stuff needs to be done differently.
- * With PNP you want to be able to allocate a region,
- * but not necessarily map it. Why? The drivers themselves
- * should really map the bus regions they need. So, which
- * way should this be done?
- *
- * Me thinks to seperate the resource allocation and mapping
- * of said resources.
- */
-
- /* ADDRESS and WRITE_DATA ports are static */
- if (bus_space_map(sc->iot, ADDRESS, 1, 0, &(sc->addrh)))
- panic("isapnpattach: io mapping for ADDRESS port failed");
- if (bus_space_map(sc->iot, WRITE_DATA, 1, 0, &(sc->wdh)))
- panic("isapnpattach: io mapping for WRITE_DATA port failed");
-
- /* Try various READ_DATA ports from 0x203-0x3ff
- * We try in increments of 16. Note that the rd_port
- * figure is really port number ((rd_port << 2) | 0x3).
- */
- for (sc->rd_port = 0x80; (sc->rd_port < 0xff); sc->rd_port += 0x10) {
- int real_port = (sc->rd_port << 2) | 0x3;
-
- /* Try to map a READ_DATA port */
- if (bus_space_map(sc->iot, real_port, 1, 0, &(sc->rdh))) {
-#ifdef DEBUG
- printf("\nisapnpattach: READ_PORT 0x%x failed", real_port);
-#endif
- continue;
- }
+ /* Set the read port */
+ isapnp_write_reg(sc, ISAPNP_WAKE, 0);
+ isapnp_write_reg(sc, ISAPNP_SET_RD_PORT, sc->sc_read_port >> 2);
+ sc->sc_read_port |= 3;
+ DELAY(1000);
- /* Try isolation protocol on this port */
- num_pnp_devs = isolation_protocol(sc);
- if (num_pnp_devs)
- break;
-
- /* isolation protocol failed for this port */
- bus_space_unmap(sc->iot, real_port, 1);
+ ISAPNP_WRITE_ADDR(sc, ISAPNP_SERIAL_ISOLATION);
+ DELAY(1000);
+
+ /* Read the 8 bytes of the Vendor ID and Serial Number */
+ for(i = 0; i < 8; i++) {
+ /* Read each bit separately */
+ for (w = 0, b = 0; b < 8; b++) {
+ u_char neg = isapnp_shift_bit(sc);
+
+ w >>= 1;
+ w |= neg;
+ v = ISAPNP_LFSR_NEXT(v) ^ neg;
+ }
+ sc->sc_id[sc->sc_ncards][i] = w;
}
- printf(": readport 0x%x, %d devices\n",
- (sc->rd_port << 2) | 0x3, num_pnp_devs);
-}
-char *
-searchpnpdevtab(name)
- char *name;
-{
- int i;
+ /* Read the remaining checksum byte */
+ for (csum = 0, b = 0; b < 8; b++) {
+ u_char neg = isapnp_shift_bit(sc);
- for (i = 0; pnp_knowndevs[i].pnpid; i++)
- if (strcmp(pnp_knowndevs[i].pnpid, name) == 0)
- return (pnp_knowndevs[i].driver);
- return (NULL);
-}
+ csum >>= 1;
+ csum |= neg;
+ }
+ sc->sc_id[sc->sc_ncards][8] = csum;
-char *
-makepnpname(id)
- u_int32_t id;
-{
- static char name[8];
- u_char info[4];
-
- bcopy(&id, info, sizeof id);
- sprintf(name, "%c%c%c%02x%02x",
- ((info[0] & 0x7c) >> 2) + 64,
- (((info[0] & 0x03) << 3) | ((info[1] & 0xe0) >> 5)) + 64,
- (info[1] & 0x1f) + 64,
- info[2], info[3]);
- return (name);
+ if (csum == v) {
+ sc->sc_ncards++;
+ isapnp_write_reg(sc, ISAPNP_CARD_SELECT_NUM, sc->sc_ncards);
+ return 1;
+ }
+ return 0;
}
+
+/* isapnp_free_region():
+ * Free a region
+ */
void
-postisapnpattach(parent, self, aux)
- struct device *parent, *self;
- void *aux;
+isapnp_free_region(t, r)
+ bus_space_tag_t t;
+ struct isapnp_region *r;
{
- struct isa_softc *isc = (struct isa_softc *)self;
- struct isapnp_softc *sc = (struct isapnp_softc *)isc->pnpsc;
- struct isabus_attach_args *iba = aux;
- struct cardinfo *card;
- struct devinfo *dev;
- struct device *r;
-#if 0
- extern char *msgs[];
+#ifdef _KERNEL
+ bus_space_unmap(t, r->h, r->length);
#endif
- void *match;
+}
- printf("postisapnpattach:\n");
- for (card = sc->q_card.tqh_first; card; card = card->card_link.tqe_next) {
- for (dev = card->q_dev.tqh_first; dev; dev = dev->dev_link.tqe_next) {
- struct isa_attach_args ia;
-
- bzero(&ia, sizeof(ia));
- ia.ia_iot = iba->iba_iot;
- ia.ia_ic = iba->iba_ic;
- ia.id = dev->id;
- ia.comp_id = dev->comp_id;
- ia.csn = card->csn;
- ia.ldn = dev->ldn;
-
- if (!isapnpquery(sc, ia.id, &ia)) {
- printf("isapnpquery failed\n");
- goto bail;
- }
- printf("id %x comp_id %x csn %x ldn %x\n", ia.id,
- ia.comp_id, ia.csn, ia.ldn);
- printf("io %x/%x mem %x/%x irq %x drq %x\n",
- ia.ia_iobase, ia.ia_iosize, ia.ia_maddr,
- ia.ia_msize, ia.ia_irq, ia.ia_drq);
- match = config_search(isapnpsubmatch, self, &ia);
- printf("config search %x\n", match);
-
- if (match) {
- r = config_attach(self, match, &ia, NULL);
- printf("config attach %x\n", r);
- }
- if (match == NULL || r == NULL) {
-bail:
-#if 0
- printf(msgs[isapnpprint(&ia, self->dv_xname)]);
-#endif
-#if 1
- /*
- * XXX does this shut down devices we
- * are using??
- * supplied configuration fails,
- * disable the device.
- */
- SEND(WAKE, ia.csn);
- SEND(SET_LDN, ia.ldn);
- SEND(ACTIVATE, 0);
-#endif
- }
- }
+/* isapnp_alloc_region():
+ * Allocate a single region if possible
+ */
+int
+isapnp_alloc_region(t, r)
+ bus_space_tag_t t;
+ struct isapnp_region *r;
+{
+ int error = 0;
- delay(1000*500);
+ for (r->base = r->minbase; r->base <= r->maxbase;
+ r->base += r->align) {
+#ifdef _KERNEL
+ error = bus_space_map(t, r->base, r->length, 0, &r->h);
+#endif
+ if (error == 0)
+ return 0;
}
+ return error;
}
+
+/* isapnp_alloc_irq():
+ * Allocate an irq
+ */
int
-isapnpprint(aux, pnp)
- void *aux;
- const char *pnp;
+isapnp_alloc_irq(ic, i)
+ isa_chipset_tag_t ic;
+ struct isapnp_pin *i;
{
- register struct isa_attach_args *ia = aux;
-
- if (pnp) {
- printf("device ");
- if (ia->comp_id)
- printf("<%s> ", makepnpname(ia->comp_id));
- printf("<%s> at %s", makepnpname(ia->id), pnp);
- } else {
- if (ia->ia_iosize)
- printf(" port 0x%x", ia->ia_iobase);
- if (ia->ia_iosize > 1)
- printf("-0x%x", ia->ia_iobase + ia->ia_iosize - 1);
- if (ia->ia_msize)
- printf(" iomem 0x%x", ia->ia_maddr);
- if (ia->ia_msize > 1)
- printf("-0x%x", ia->ia_maddr + ia->ia_msize - 1);
- if (ia->ia_irq != IRQUNK)
- printf(" irq %d", ia->ia_irq);
- if (ia->ia_drq != DRQUNK)
- printf(" drq %d", ia->ia_drq);
+ int irq;
+#define LEVEL_IRQ (ISAPNP_IRQTYPE_LEVEL_PLUS|ISAPNP_IRQTYPE_LEVEL_MINUS)
+ i->type = (i->flags & LEVEL_IRQ) ? IST_LEVEL : IST_EDGE;
+
+ if (i->bits == 0) {
+ i->num = 0;
+ return 0;
+ }
+
+ if (isa_intr_alloc(ic, i->bits, i->type, &irq) == 0) {
+ i->num = irq;
+ return 0;
}
- return(UNCONF);
+
+ return EINVAL;
}
-/* XXX */
-/* Always return success */
+/* isapnp_alloc_drq():
+ * Allocate a drq
+ */
int
-probe_extent(ext, s, l)
- struct emap *ext;
- int s, l;
+isapnp_alloc_drq(isa, i)
+ struct device *isa;
+ struct isapnp_pin *i;
{
- return(0);
-}
+ int b;
-/* XXX */
-/* Return bogus map */
-struct emap *
-find_emap(key)
- char *key;
-{
- return(NULL);
-}
+ if (i->bits == 0) {
+ i->num = 0;
+ return 0;
+ }
-/* XXX */
-/* Do nothing at all */
-void
-add_extent(m, base, size)
- struct emap *m;
- long base;
- int size;
-{
-}
+ for (b = 0; b < 16; b++)
+ if ((i->bits & (1 << b)) && isadma_isdrqfree(b)) {
+ i->num = b;
+ return 0;
+ }
-void
-isapnpextent(ia)
- struct isa_attach_args *ia;
-{
- struct emap *io_map, *mem_map, *irq_map, *drq_map;
-
- io_map = find_emap("io");
- mem_map = find_emap("mem");
- irq_map = find_emap("irq");
- drq_map = find_emap("drq");
-
- if (ia->ia_iosize > 0)
- add_extent(io_map, ia->ia_iobase, ia->ia_iosize);
- if (ia->ia_msize > 0)
- add_extent(mem_map, ia->ia_maddr, ia->ia_msize);
- if (ia->ia_irq != IRQUNK)
- add_extent(irq_map, ia->ia_irq, 1);
- if (ia->ia_drq != DRQUNK)
- add_extent(drq_map, ia->ia_drq, 1);
+ return EINVAL;
}
+/* isapnp_testconfig():
+ * Test/Allocate the regions used
+ */
int
-isapnpsubmatch(parent, match, aux)
- struct device *parent;
- void *match, *aux;
+isapnp_testconfig(iot, memt, ipa, alloc)
+ bus_space_tag_t iot, memt;
+ struct isapnp_attach_args *ipa;
+ int alloc;
{
- struct device *dev = match;
- struct cfdata *cf = dev->dv_cfdata;
- struct isa_attach_args *ia = aux;
- char *name, *dname;
- int ret = 0;
-
- /* XXX should check for id/comp_id being 0 */
- if (cf->cf_pnpid != 0 &&
- (ia->id == cf->cf_pnpid || ia->comp_id == cf->cf_pnpid)) {
- printf("isapnpsubmatch going\n");
- ret = (*cf->cf_attach->ca_match)(parent, match, aux);
- goto done;
+ int nio = 0, nmem = 0, nmem32 = 0, nirq = 0, ndrq = 0;
+ int error = 0;
+
+#ifdef DEBUG_ISAPNP
+ isapnp_print_attach(ipa);
+#endif
+
+ for (; nio < ipa->ipa_nio; nio++) {
+ error = isapnp_alloc_region(iot, &ipa->ipa_io[nio]);
+ if (error)
+ goto bad;
}
- if (ia->comp_id) {
- name = makepnpname(ia->comp_id);
- dname = searchpnpdevtab(name);
- if (dname && strcmp(dname, cf->cf_driver->cd_name) == 0) {
- ret = (*cf->cf_attach->ca_match)(parent, match, aux);
- goto done;
- }
+ for (; nmem < ipa->ipa_nmem; nmem++) {
+ error = isapnp_alloc_region(memt, &ipa->ipa_mem[nmem]);
+ if (error)
+ goto bad;
}
- name = makepnpname(ia->id);
- dname = searchpnpdevtab(name);
- if (dname && strcmp(dname, cf->cf_driver->cd_name) == 0) {
- printf("match %s\n", dname);
- ret = (*cf->cf_attach->ca_match)(parent, match, aux);
+
+ for (; nmem32 < ipa->ipa_nmem32; nmem32++) {
+ error = isapnp_alloc_region(memt, &ipa->ipa_mem32[nmem32]);
+ if (error)
+ goto bad;
}
-done:
- if (ret)
- isapnpextent(ia);
- return (ret);
-}
-/*
- * given the logical device ID, return 1 if found and configured.
- */
-int
-isapnpquery(sc, dev_id, ipa)
- struct isapnp_softc *sc;
- u_int32_t dev_id;
- struct isa_attach_args *ipa;
-{
- struct cardinfo *card;
- struct devinfo *dev;
- struct confinfo *conf;
- struct isa_attach_args *tmp;
- int c, i, j, fail, success = 0;
-
-/* XXX - Wait for character */
-#if 0
- {
- char resp[10];
- printf("isapnpquery? ");
- getsn(resp, sizeof resp);
+ for (; nirq < ipa->ipa_nirq; nirq++) {
+ error = isapnp_alloc_irq(ipa->ipa_ic, &ipa->ipa_irq[nirq]);
+ if (error)
+ goto bad;
}
-#endif
- for (card = sc->q_card.tqh_first; card; card = card->card_link.tqe_next) {
- for (dev = card->q_dev.tqh_first; dev; dev = dev->dev_link.tqe_next) {
- if (dev_id != dev->id && dev_id != dev->comp_id)
- continue;
- tmp = malloc(sizeof(*tmp), M_DEVBUF, M_WAITOK);
- bzero(tmp, sizeof(*tmp));
- SEND(WAKE, card->csn);
- SEND(SET_LDN, dev->ldn);
-
- /* Find a usable and acceptable configuration */
- for (conf = dev->q_conf.tqh_first; conf;
- conf = conf->conf_link.tqe_next) {
- /*
- * BASIC CONFIGURATION
- */
- if (conf->prio == BASIC_CONFIGURATION) {
- for (c=0; c < 2; c++) {
- ipa->irq[c].num = -1;
- if (conf->irq[c] == 0)
- continue;
-#if 0
- printf("irq %d %d %d\n", c,
- conf->irq[c]->num,
- conf->irq[c]->info);
-#endif
- i = conf->irq[c]->num;
- if (i == 0)
- continue;
- j = find_free_irq(i);
- if (j != 0)
- continue;
- ipa->irq[c].num = j;
-
- /*
- * XXX if the interrupt cannot
- * be configured as low true
- * level-triggered then set it
- * to high true edge-triggered.
- */
- if (conf->irq[c]->info & 0x08)
- ipa->irq[c].type = 0x01;
- else
- ipa->irq[c].type = 0x10;
- }
- for (c=0; c < 2; c++) {
- ipa->drq[c] = -1;
- if (conf->dma[c] == 0)
- continue;
-#if 0
- printf("dma %d %d\n", c,
- conf->dma[c]->channel);
-#endif
- i = conf->dma[c]->channel;
- if (i == 0)
- continue;
- j = find_free_drq(i);
- if (j)
- ipa->drq[c] = j;
- }
- for (c=0; c < 8; c++) {
- if (conf->io[c] == 0)
- continue;
-#if 0
- printf("io %d %d %d %d %d %d\n",
- c, conf->io[c]->min_base,
- conf->io[c]->max_base,
- conf->io[c]->size,
- conf->io[c]->alignment,
- dev->io_range_check);
-#endif
- ipa->port[c] = find_free_io(sc,
- c, conf->io[c]->min_base,
- conf->io[c]->max_base,
- conf->io[c]->size,
- conf->io[c]->alignment,
- dev->io_range_check);
- }
- for (c=0; c < 4; c++) {
- if (conf->mem[c] == 0)
- continue;
-#if 0
- printf("mem %d %d %d\n", c,
- conf->mem[c]->min_base,
- conf->mem[c]->size);
-#endif
- ipa->mem[c].base =
- conf->mem[c]->min_base;
- ipa->mem[c].range =
- conf->mem[c]->size;
- }
- }
- /*
- * DEPENDENT FUNCTION
- */
- fail = 0;
- success = 1;
- for (c=0; conf->irq[c] && c < 2; c++) {
- i = conf->irq[c]->num;
- tmp->irq[c].num = -1;
- if (i == 0)
- continue;
- j = find_free_irq(i);
- if (j) {
- tmp->irq[c].num = j;
- if (conf->irq[c]->info & 0x08)
- tmp->irq[c].type = 0x01;
- else
- tmp->irq[c].type = 0x10;
- } else {
- fail = 1;
-#if 0
- printf("irq bail\n");
-#endif
- success = 0;
- break;
- }
- }
- for (c=0; conf->dma[c] && c < 2; c++) {
- i = conf->dma[c]->channel;
- tmp->drq[c] = -1;
- if (i == 0)
- continue;
- j = find_free_drq(i);
- if (j)
- tmp->drq[c] = j;
- else {
- fail = 1;
-#if 0
- printf("dma bail\n");
-#endif
- success = 0;
- break;
- }
- }
+ for (; ndrq < ipa->ipa_ndrq; ndrq++) {
+ error = isapnp_alloc_drq(ipa->ipa_isa, &ipa->ipa_drq[ndrq]);
+ if (error)
+ goto bad;
+ }
-#if 0
- printf("ports:");
-#endif
- for (c=0; conf->io[c] && c < 8; c++) {
-#if 0
- printf("%x/%x ", conf->io[c]->min_base,
- conf->io[c]->size);
-#endif
- if (conf->io[c]->size == 0)
- continue;
- tmp->port[c] = find_free_io(sc, c,
- conf->io[c]->min_base,
- conf->io[c]->max_base,
- conf->io[c]->size,
- conf->io[c]->alignment,
- dev->io_range_check);
- if (tmp->port[c] == NULL) {
- fail = 1;
-#if 0
- printf("io bail\n");
-#endif
- success = 0;
- break;
- }
- }
-#if 0
- printf("\n");
+ if (alloc)
+ return error;
- printf("mem:");
-#endif
- for (c=0; conf->mem[c] && c < 4; c++) {
-#if 0
- printf("%x/%x ", conf->mem[c]->min_base,
- conf->mem[c]->size);
-#endif
- if (conf->mem[c]->size == 0)
- continue;
- tmp->mem[c].base =
- conf->mem[c]->min_base;
- tmp->mem[c].range =
- conf->mem[c]->size;
- if (tmp->mem[c].base == NULL) {
- fail = 1;
-#if 0
- printf("mem bail\n");
-#endif
- success = 0;
- break;
- }
- }
-#if 0
- printf("\n");
-#endif
-
- if (fail) {
- continue;
- }
+bad:
+#ifdef notyet
+ for (ndrq--; ndrq >= 0; ndrq--)
+ isapnp_free_pin(&ipa->ipa_drq[ndrq]);
- if (!success) {
- free(tmp, M_DEVBUF);
-#if 0
- printf("bailing\n");
+ for (nirq--; nirq >= 0; nirq--)
+ isapnp_free_pin(&ipa->ipa_irq[nirq]);
#endif
- return(0);
- }
- }
+ for (nmem32--; nmem32 >= 0; nmem32--)
+ isapnp_free_region(memt, &ipa->ipa_mem32[nmem32]);
- /* Copy usable configuration */
- for (c = 0; c < 2; c++) {
- if (tmp->irq[c].num) {
- ipa->irq[c].num = tmp->irq[c].num;
- ipa->irq[c].type = tmp->irq[c].type;
- }
- }
- for (c = 0; c < 8; c++) {
- if (tmp->port[c])
- ipa->port[c] = tmp->port[c];
- }
- for (c = 0; c < 4; c++) {
- if (tmp->mem[c].base)
- ipa->mem[c].base = tmp->mem[c].base;
- }
+ for (nmem--; nmem >= 0; nmem--)
+ isapnp_free_region(memt, &ipa->ipa_mem[nmem]);
- /* Configure device */
- config_device(sc, ipa);
- ipa->ia_iobase = ipa->port[0];
- ipa->ia_iosize = 16; /* XXX */
- ipa->ia_irq = ipa->irq[0].num;
- ipa->ia_drq = ipa->drq[0];
- free(tmp, M_DEVBUF);
- return(1);
- }
- }
- return(0);
+ for (nio--; nio >= 0; nio--)
+ isapnp_free_region(iot, &ipa->ipa_io[nio]);
+
+ return error;
}
-/*
- * Send Initiation LFSR as described in "Plug and Play ISA Specification,
- * Intel May 94."
+
+/* isapnp_config():
+ * Test/Allocate the regions used
+ */
+int
+isapnp_config(iot, memt, ipa)
+ bus_space_tag_t iot, memt;
+ struct isapnp_attach_args *ipa;
+{
+ return isapnp_testconfig(iot, memt, ipa, 1);
+}
+
+
+/* isapnp_unconfig():
+ * Free the regions used
*/
void
-send_Initiation_LFSR(sc)
- struct isapnp_softc *sc;
+isapnp_unconfig(iot, memt, ipa)
+ bus_space_tag_t iot, memt;
+ struct isapnp_attach_args *ipa;
{
- bus_space_tag_t iot = sc->iot;
- bus_space_handle_t addrh = sc->addrh;
- int cur, i;
+ int i;
- /* Reset the LSFR */
- bus_space_write_1(iot, addrh, 0, 0);
- bus_space_write_1(iot, addrh, 0, 0);
+#ifdef notyet
+ for (i = 0; i < ipa->ipa_ndrq; i++)
+ isapnp_free_pin(&ipa->ipa_drq[i]);
- cur = 0x6a;
- bus_space_write_1(iot, addrh, 0, cur);
+ for (i = 0; i < ipa->ipa_nirq; i++)
+ isapnp_free_pin(&ipa->ipa_irq[i]);
+#endif
- for (i = 1; i < 32; i++) {
- cur = (cur >> 1) | (((cur ^ (cur >> 1)) << 7) & 0xff);
- bus_space_write_1(iot, addrh, 0, cur);
- }
+ for (i = 0; i < ipa->ipa_nmem32; i++)
+ isapnp_free_region(memt, &ipa->ipa_mem32[i]);
+
+ for (i = 0; i < ipa->ipa_nmem; i++)
+ isapnp_free_region(memt, &ipa->ipa_mem[i]);
+
+ for (i = 0; i < ipa->ipa_nio; i++)
+ isapnp_free_region(iot, &ipa->ipa_io[i]);
}
-/*
- * Get the device's serial number. Returns 1 if the serial is valid.
+
+/* isapnp_bestconfig():
+ * Return the best configuration for each logical device, remove and
+ * free all other configurations.
*/
-int
-get_serial(sc, data)
+struct isapnp_attach_args *
+isapnp_bestconfig(isa, sc, ipa)
+ struct device *isa;
struct isapnp_softc *sc;
- unsigned char *data;
+ struct isapnp_attach_args **ipa;
{
- bus_space_tag_t iot = sc->iot;
- bus_space_handle_t rdh = sc->rdh;
+ struct isapnp_attach_args *c, *best, *f = *ipa;
+ int error;
- int i, bit, valid = 0, sum = 0x6a;
+ for (;;) {
+ if (f == NULL)
+ return NULL;
- bzero(data, sizeof(char) * 9);
+#define SAMEDEV(a, b) (strcmp((a)->ipa_devlogic, (b)->ipa_devlogic) == 0)
+ /* Find the best config */
+ for (best = c = f; c != NULL; c = c->ipa_sibling) {
+ if (!SAMEDEV(c, f))
+ continue;
+ if (c->ipa_pref < best->ipa_pref)
+ best = c;
+ }
- for (i = 0; i < 72; i++) {
- bit = bus_space_read_1(iot, rdh, 0) == 0x55;
- delay(250); /* Delay 250 usec */
+ best->ipa_isa = isa;
+ /* Test the best config */
+ error = isapnp_testconfig(sc->sc_iot, sc->sc_memt, best, 0);
- /* Can't Short Circuit the next evaluation, so 'and' is last */
- bit = (bus_space_read_1(iot, rdh, 0) == 0xaa) && bit;
- delay(250); /* Delay 250 usec */
+ /* Remove this config from the list */
+ if (best == f)
+ f = f->ipa_sibling;
+ else {
+ for (c = f; c->ipa_sibling != best; c = c->ipa_sibling)
+ continue;
+ c->ipa_sibling = best->ipa_sibling;
+ }
- valid = valid || bit;
+ if (error) {
+ best->ipa_pref = ISAPNP_DEP_CONFLICTING;
- if (i < 64)
- sum = (sum >> 1) |
- (((sum ^ (sum >> 1) ^ bit) << 7) & 0xff);
+ for (c = f; c != NULL; c = c->ipa_sibling)
+ if (c != best && SAMEDEV(c, best))
+ break;
+ /* Last config for this logical device is conflicting */
+ if (c == NULL) {
+ *ipa = f;
+ return best;
+ }
- data[i / 8] = (data[i / 8] >> 1) | (bit ? 0x80 : 0);
+ ISAPNP_FREE(best);
+ continue;
+ }
+ else {
+ /* Remove all other configs for this device */
+ struct isapnp_attach_args *l = NULL, *n = NULL, *d;
+
+ for (c = f; c; ) {
+ if (c == best)
+ continue;
+ d = c->ipa_sibling;
+ if (SAMEDEV(c, best))
+ ISAPNP_FREE(c);
+ else {
+ if (n)
+ n->ipa_sibling = c;
+
+ else
+ l = c;
+ n = c;
+ c->ipa_sibling = NULL;
+ }
+ c = d;
+ }
+ f = l;
+ }
+ *ipa = f;
+ return best;
}
+}
- valid = valid && (data[8] == sum);
- return valid;
+/* isapnp_id_to_vendor():
+ * Convert a pnp ``compressed ascii'' vendor id to a string
+ */
+char *
+isapnp_id_to_vendor(v, id)
+ char *v;
+ const u_char *id;
+{
+ static const char hex[] = "0123456789ABCDEF";
+ char *p = v;
+
+ *p++ = 'A' + (id[0] >> 2) - 1;
+ *p++ = 'A' + ((id[0] & 3) << 3) + (id[1] >> 5) - 1;
+ *p++ = 'A' + (id[1] & 0x1f) - 1;
+ *p++ = hex[id[2] >> 4];
+ *p++ = hex[id[2] & 0x0f];
+ *p++ = hex[id[3] >> 4];
+ *p++ = hex[id[3] & 0x0f];
+ *p = '\0';
+
+ return v;
}
-int
-get_resource_info(sc, buffer, len)
- struct isapnp_softc *sc;
- u_char *buffer;
- int len;
+
+/* isapnp_print_region():
+ * Print a region allocation
+ */
+void
+isapnp_print_region(str, r, n)
+ const char *str;
+ struct isapnp_region *r;
+ size_t n;
{
- int i, j;
+ size_t i;
-#if 0
- printf("gri: ");
-#endif
- for (i = 0; i < len; i++) {
- bus_space_write_1(sc->iot, sc->addrh, 0, STATUS);
- for (j = 0; j < 100; j++) {
- if ((bus_space_read_1(sc->iot, sc->rdh, 0)) & 0x1)
- break;
- delay(1);
- }
- if (j == 100) {
- printf("isapnp: %s failed to report resource data\n",
- sc->sc_dev.dv_xname);
- return 0;
- }
- bus_space_write_1(sc->iot, sc->addrh, 0, RESOURCE_DATA);
- buffer[i] = bus_space_read_1(sc->iot, sc->rdh, 0);
+ if (n == 0)
+ return;
-#if 0
- printf("%2x ", buffer[i]);
-#endif
+ printf(" %s ", str);
+ for (i = 0; i < n; i++, r++) {
+ printf("0x%x", r->base);
+ if (r->length)
+ printf("/%d", r->length);
+ if (i != n - 1)
+ printf(",");
}
-#if 0
- printf("\n");
-#endif
- return 1;
}
-/*
- * Small Resource Tag Handler
- *
- * Returns 1 if checksum was valid (and an END_TAG was received).
- * Returns -1 if checksum was invalid (and an END_TAG was received).
- * Returns 0 for other tags.
- *
- * XXX checksum is ignored now ...
+
+/* isapnp_print_pin():
+ * Print an irq/drq assignment
*/
-int
-handle_small_res(resinfo, item, len, card)
- unsigned char *resinfo;
- int item, len;
- struct cardinfo *card;
+void
+isapnp_print_pin(str, p, n)
+ const char *str;
+ struct isapnp_pin *p;
+ size_t n;
{
- int i;
+ size_t i;
- switch (item) {
- case PNP_VERSION:
- bcopy(resinfo, card->pnp_version, 2);
- break;
- case LOG_DEVICE_ID:
- card->dev = malloc(sizeof(struct devinfo), M_DEVBUF, M_WAITOK);
- bzero(card->dev, sizeof(struct devinfo));
- TAILQ_INSERT_TAIL(&card->q_dev, card->dev, dev_link);
- card->dev->id = *(u_int32_t *)resinfo;
- card->dev->ldn = card->num_ld;
- card->dev->io_range_check = resinfo[4] & 0x2 ? 1 : 0;
- TAILQ_INIT(&card->dev->q_conf);
-
- /*
- * if the resource data is not enclosed in a START_DEPEND_FUNC and
- * a END_DEPEND_FUNC, it's the basic configuration.
- *
- * we simply treat it as a special case.
- */
- card->dev->basic = malloc(sizeof(struct confinfo), M_DEVBUF, M_WAITOK);
- TAILQ_INSERT_TAIL(&card->dev->q_conf, card->dev->basic, conf_link);
- card->dev->basic->prio = BASIC_CONFIGURATION;
- bzero(card->dev->basic->irq, 2*sizeof(void *));
- bzero(card->dev->basic->dma, 2*sizeof(void *));
- bzero(card->dev->basic->io, 8*sizeof(void *));
- bzero(card->dev->basic->mem, 4*sizeof(void *));
- card->dev->conf = card->dev->basic;
-
- card->num_ld++;
- break;
- case COMP_DEVICE_ID:
- card->dev->comp_id = *(u_int32_t *)resinfo;
- break;
- case IRQ_FORMAT:
- for (i = 0; card->dev->conf->irq[i]; i++)
- ;
- card->dev->conf->irq[i] = malloc(sizeof(struct irq_format),
- M_DEVBUF, M_WAITOK);
- card->dev->conf->irq[i]->num = resinfo[0] | (resinfo[1] << 8);
- if (len == 3)
- card->dev->conf->irq[i]->info = resinfo[2];
- else
- card->dev->conf->irq[i]->info = 0;
- break;
- case DMA_FORMAT:
- for (i = 0; card->dev->conf->dma[i]; i++)
- ;
- card->dev->conf->dma[i] = malloc(sizeof(struct dma_format),
- M_DEVBUF, M_WAITOK);
- card->dev->conf->dma[i]->channel = resinfo[0];
- card->dev->conf->dma[i]->info = resinfo[1];
- break;
- case START_DEPEND_FUNC:
- card->dev->conf = malloc(sizeof(struct confinfo),
- M_DEVBUF, M_WAITOK);
- TAILQ_INSERT_TAIL(&card->dev->q_conf, card->dev->conf,
- conf_link);
- card->dev->conf->prio = ACCEPTABLE_CONFIGURATION;
- bzero(card->dev->conf->irq, 2*sizeof(void *));
- bzero(card->dev->conf->dma, 2*sizeof(void *));
- bzero(card->dev->conf->io, 8*sizeof(void *));
- bzero(card->dev->conf->mem, 4*sizeof(void *));
-
- if (len == 1) {
- switch (resinfo[0]) {
- case GOOD_CONFIGURATION:
- card->dev->conf->prio =
- GOOD_CONFIGURATION;
- break;
- case ACCEPTABLE_CONFIGURATION:
- card->dev->conf->prio =
- ACCEPTABLE_CONFIGURATION;
- break;
- case SUBOPTIMAL_CONFIGURATION:
- card->dev->conf->prio =
- SUBOPTIMAL_CONFIGURATION;
- break;
- default:
- card->dev->conf->prio =
- RESERVED_CONFIGURATION;
- break;
- }
- }
- break;
- case END_DEPEND_FUNC:
- break;
- case IO_PORT_DESC:
- for (i = 0; card->dev->conf->io[i]; i++)
- ;
- card->dev->conf->io[i] = malloc(sizeof(struct io_descriptor),
- M_DEVBUF, M_WAITOK);
- card->dev->conf->io[i]->type = 0; /* 0 for normal I/O desc. */
- card->dev->conf->io[i]->info = resinfo[0];
- card->dev->conf->io[i]->min_base =
- resinfo[1] | (resinfo[2] << 8);
- card->dev->conf->io[i]->max_base =
- resinfo[3] | (resinfo[4] << 8);
- card->dev->conf->io[i]->alignment = resinfo[5];
- card->dev->conf->io[i]->size = resinfo[6];
- break;
- case FIXED_IO_PORT_DESC:
- for (i = 0; card->dev->conf->io[i]; i++) ;
- card->dev->conf->io[i] = malloc(sizeof(struct io_descriptor),
- M_DEVBUF, M_WAITOK);
- card->dev->conf->io[i]->type = 1; /* 1 for fixed I/O desc. */
- card->dev->conf->io[i]->info = 0;
- card->dev->conf->io[i]->min_base =
- resinfo[0] | (resinfo[1] & 0x3) << 8;
- card->dev->conf->io[i]->max_base =
- card->dev->conf->io[i]->min_base;
- card->dev->conf->io[i]->alignment = 0;
- card->dev->conf->io[i]->size = resinfo[2];
- break;
- case END_TAG:
- /*
- * XXX checksum is ignored
- */
-#if 0
- printf("end of res\n");
-#endif
- return(1);
- }
+ if (n == 0)
+ return;
- return(0);
+ printf(" %s ", str);
+ for (i = 0; i < n; i++, p++) {
+ printf("%d", p->num);
+ if (i != n - 1)
+ printf(",");
+ }
}
-void
-handle_large_res(resinfo, item, len, card)
- unsigned char *resinfo;
- int item, len;
- struct cardinfo *card;
+
+/* isapnp_print():
+ * Print the configuration line for an ISA PnP card.
+ */
+int
+isapnp_print(aux, str)
+ void *aux;
+ const char *str;
{
- int i;
+ struct isapnp_attach_args *ipa = aux;
- switch (item) {
- case MEMORY_RANGE_DESC:
- for (i = 0; card->dev->conf->mem[i]; i++)
- ;
- card->dev->conf->mem[i] = malloc(sizeof(struct mem_descriptor),
- M_DEVBUF, M_WAITOK);
- card->dev->conf->mem[i]->type = 0; /* 0 for 24bit mem desc. */
- card->dev->conf->mem[i]->info = resinfo[0];
- card->dev->conf->mem[i]->min_base =
- (resinfo[1] | (resinfo[2] << 8)) << 8;
- card->dev->conf->mem[i]->max_base =
- (resinfo[3] | (resinfo[4] << 8)) << 8;
- card->dev->conf->mem[i]->alignment =
- resinfo[5] | (resinfo[6] << 8);
- if (!card->dev->conf->mem[i]->alignment)
- card->dev->conf->mem[i]->alignment = 1 << 16;
- card->dev->conf->mem[i]->size =
- (resinfo[7] | (resinfo[8] << 8)) << 8;
- break;
- case ID_STRING_ANSI:
- if (card->dev) {
- card->dev->id_string = (char *)malloc(len+1, M_DEVBUF,
- M_WAITOK);
- strncpy(card->dev->id_string, resinfo, len+1);
- card->dev->id_string[len] = '\0';
-#if 0
- printf("ID_STRING_ANSI: %s\n", card->dev->id_string);
-#endif
- } else {
- card->id_string = (char *)malloc(len+1, M_DEVBUF,
- M_WAITOK);
- strncpy(card->id_string, resinfo, len+1);
- card->id_string[len] = '\0';
-#if 0
- printf("ID_STRING_ANSI: %s\n", card->id_string);
-#endif
- }
- break;
- case ID_STRING_UNICODE:
- break;
- case LG_VENDOR_DEFINED:
- break;
- case _32BIT_MEM_RANGE_DESC:
- break;
- case _32BIT_FIXED_LOC_DESC:
- break;
-
- /* XXX - Check how this is defined! Bogus!!! */
- case LG_RES_RESERVED:
- break;
- default:
- break;
- }
-}
+ if (str != NULL)
+ printf("%s: <%s, %s, %s, %s>",
+ str, ipa->ipa_devident, ipa->ipa_devlogic,
+ ipa->ipa_devcompat, ipa->ipa_devclass);
-void
-read_config(sc, card, csn)
- struct isapnp_softc *sc;
- struct cardinfo *card;
- int csn;
-{
- u_char tag, *resinfo;
- u_short large_len;
- int i;
+ isapnp_print_region("port", ipa->ipa_io, ipa->ipa_nio);
+ isapnp_print_region("mem", ipa->ipa_mem, ipa->ipa_nmem);
+ isapnp_print_region("mem32", ipa->ipa_mem32, ipa->ipa_nmem32);
+ isapnp_print_pin("irq", ipa->ipa_irq, ipa->ipa_nirq);
+ isapnp_print_pin("drq", ipa->ipa_drq, ipa->ipa_ndrq);
-#if 0
- /*
- * set card with csn to Config state
- */
- SEND(SET_CSN, csn);
-#endif
+ return UNCONF;
+}
- /*
- * since we are in the card isolation process, so theres no reason
- * to rewind and skip the first 9 bytes
- */
- /* allow up to 1KB of resource info, should be plenty */
- for (i = 0; i < 4096; i++) {
- if (!get_resource_info(sc, &tag, 1))
- return;
+#ifdef _KERNEL
+/* isapnp_submatch():
+ * Probe the logical device...
+ */
+int
+isapnp_submatch(parent, match, aux)
+ struct device *parent;
+ void *match, *aux;
+{
+ struct cfdata *cf = match;
+ struct isapnp_attach_args *ipa = aux;
+ const char *dname;
+ int i;
-#define TYPE (tag >> 7)
-#define S_ITEM (tag >> 3)
-#define S_LEN (tag & 0x7)
-#define L_ITEM (tag & 0x7f)
+ for (i = 0; isapnp_knowndevs[i].pnpid; i++) {
+ dname = NULL;
- if (TYPE == 0) {
-#if 0
- printf("small %d %d\n", S_ITEM, S_LEN);
-#endif
- resinfo = malloc(S_LEN, M_TEMP, M_WAITOK);
- if (!get_resource_info(sc, resinfo, S_LEN)) {
- printf("bail getting small info\n");
- return;
- }
+ if (strcmp(isapnp_knowndevs[i].pnpid, ipa->ipa_devlogic) == 0)
+ dname = isapnp_knowndevs[i].driver;
+ else if (strcmp(isapnp_knowndevs[i].pnpid, ipa->ipa_devcompat) == 0)
+ dname = isapnp_knowndevs[i].driver;
- if (handle_small_res(resinfo, S_ITEM, S_LEN, card) == 1)
- return;
- free(resinfo, M_TEMP);
- } else {
- large_len = 0;
- if (!get_resource_info(sc, (char *)&large_len, 2)) {
- printf("bail getting large info\n");
- return;
- }
- resinfo = malloc(large_len, M_TEMP, M_WAITOK);
- if (!get_resource_info(sc, resinfo, large_len)) {
- printf("bail sadf info\n");
- free(resinfo, M_TEMP);
- return;
+ if (dname && strcmp(dname, cf->cf_driver->cd_name) == 0) {
+ /*
+ * We found a match. Configure the card and call the
+ * ISA probe...
+ */
+ if (isapnp_config(ipa->ipa_iot, ipa->ipa_memt, ipa)) {
+ printf ("%s: error in region allocation\n",
+ cf->cf_driver->cd_name);
+ return (0);
}
-#if 0
- printf("large %d %d\n", L_ITEM, large_len);
-#endif
- handle_large_res(resinfo, L_ITEM, large_len, card);
- free(resinfo, M_TEMP);
+ return ((*cf->cf_attach->ca_match)(parent, match, ipa));
}
}
+
+ return (0);
}
+#endif
-/*
- * Run the isolaion protocol. Use rd_port as the READ_DATA port value (caller
- * should try multiple READ_DATA locations before giving up). Upon exiting,
- * all cards are aware that they should use rd_port as the READ_DATA port;
+
+/* isapnp_find():
+ * Probe and add cards
*/
int
-isolation_protocol(sc)
+isapnp_find(sc, all)
struct isapnp_softc *sc;
+ int all;
{
- int csn;
- unsigned char data[9];
-
- /* Reset CSN for All Cards */
- /* Well, all cards who are *NOT* in Wait for Key state:
- *
- * 0x01 - Reset command. (READ_PORT, CSN, PNP state preserved)
- * 0x02 - Wait for Key. (Everything preserved)
- * 0x04 - Reset CSN. (Nuke CSN goto wait for key state)
- *
- * Use 0x08 for the equivelant to RESET_DRV.
- */
- SEND(CONFIG_CONTROL, 0x05);
-
- /* Move all PNP cards from WFK state to sleep state */
- send_Initiation_LFSR(sc);
-
- /* We should do the following until we do not
- * find anymore PNP cards, with the max being
- * 255 cards. This is faster
- */
- for (csn = 1; (csn < MAX_CARDS); csn++) {
- /* Wake up cards without a CSN */
- SEND(WAKE, 0);
- SEND(SET_RD_DATA, sc->rd_port);
- bus_space_write_1(sc->iot, sc->addrh, 0, SERIAL_ISOLATION);
- delay(1000); /* Delay 1 msec */
-
- if (get_serial(sc, data)) {
- struct cardinfo *card;
-
- /* Move card into config state */
- SEND(SET_CSN, csn);
- card = malloc(sizeof(struct cardinfo), M_DEVBUF, M_WAITOK);
- bzero(card, sizeof(struct cardinfo));
- TAILQ_INSERT_TAIL(&sc->q_card, card, card_link);
- bcopy(data, card->serial, 9);
- card->csn = csn;
- TAILQ_INIT(&card->q_dev);
- /*
- * read card's resource data
- */
- read_config(sc, card, csn);
- } else
+ int p;
+
+ isapnp_init(sc);
+
+ isapnp_write_reg(sc, ISAPNP_CONFIG_CONTROL, ISAPNP_CC_RESET_DRV);
+ DELAY(2000);
+
+ isapnp_init(sc);
+ DELAY(2000);
+
+ for (p = ISAPNP_RDDATA_MIN; p <= ISAPNP_RDDATA_MAX; p += 4) {
+ sc->sc_read_port = p;
+ if (isapnp_map_readport(sc))
+ continue;
+ DPRINTF(("%s: Trying port %x\n", sc->sc_dev.dv_xname, p));
+ if (isapnp_findcard(sc))
break;
+ isapnp_unmap_readport(sc);
+ }
+
+ if (p > ISAPNP_RDDATA_MAX) {
+ sc->sc_read_port = 0;
+ return 0;
}
- return csn - 1;
+
+ if (all)
+ while (isapnp_findcard(sc))
+ continue;
+
+ return 1;
}
-/*
- * Configure PNP devices, given a set of configuration data
+
+/* isapnp_configure():
+ * Configure a PnP card
+ * XXX: The memory configuration code is wrong. We need to check the
+ * range/length bit an do appropriate sets.
*/
void
-config_device(sc, data)
+isapnp_configure(sc, ipa)
struct isapnp_softc *sc;
- struct isa_attach_args *data;
+ const struct isapnp_attach_args *ipa;
{
int i;
+ static u_char isapnp_mem_range[] = ISAPNP_MEM_DESC;
+ static u_char isapnp_io_range[] = ISAPNP_IO_DESC;
+ static u_char isapnp_irq_range[] = ISAPNP_IRQ_DESC;
+ static u_char isapnp_drq_range[] = ISAPNP_DRQ_DESC;
+ static u_char isapnp_mem32_range[] = ISAPNP_MEM32_DESC;
+ const struct isapnp_region *r;
+ const struct isapnp_pin *p;
+ struct isapnp_region rz;
+ struct isapnp_pin pz;
+
+ memset(&pz, 0, sizeof(pz));
+ memset(&rz, 0, sizeof(rz));
+
+#define B0(a) ((a) & 0xff)
+#define B1(a) (((a) >> 8) & 0xff)
+#define B2(a) (((a) >> 16) & 0xff)
+#define B3(a) (((a) >> 24) & 0xff)
+
+ for (i = 0; i < sizeof(isapnp_io_range); i++) {
+ if (i < ipa->ipa_nio)
+ r = &ipa->ipa_io[i];
+ else
+ r = &rz;
- if (data->csn <= 0) {
- return;
+ isapnp_write_reg(sc,
+ isapnp_io_range[i] + ISAPNP_IO_BASE_15_8, B1(r->base));
+ isapnp_write_reg(sc,
+ isapnp_io_range[i] + ISAPNP_IO_BASE_7_0, B0(r->base));
}
-#if 1
- printf ("%s: configuring CSN %x (LDN %x)\n",
- sc->sc_dev.dv_xname, data->csn,
- data->ldn != -1 ? data->ldn : 0);
-#endif
+ for (i = 0; i < sizeof(isapnp_mem_range); i++) {
+ if (i < ipa->ipa_nmem)
+ r = &ipa->ipa_mem[i];
+ else
+ r = &rz;
+
+ isapnp_write_reg(sc,
+ isapnp_mem_range[i] + ISAPNP_MEM_BASE_23_16, B2(r->base));
+ isapnp_write_reg(sc,
+ isapnp_mem_range[i] + ISAPNP_MEM_BASE_15_8, B1(r->base));
+
+ isapnp_write_reg(sc,
+ isapnp_mem_range[i] + ISAPNP_MEM_LRANGE_23_16,
+ B2(r->length));
+ isapnp_write_reg(sc,
+ isapnp_mem_range[i] + ISAPNP_MEM_LRANGE_15_8,
+ B1(r->length));
+ }
- /* Wake up card, set LDN */
- SEND(WAKE, data->csn);
- if (data->ldn > 0)
- SEND (SET_LDN, data->ldn);
-
- /* Config IO */
- for (i = 0; i < 8; i++)
- if (data->port[i] > 0) {
- SEND (IO_CONFIG_BASE + i * 2,
- data->port[i] >> 8);
- SEND (IO_CONFIG_BASE + i * 2 + 1,
- data->port[i] & 0xff);
- }
+ for (i = 0; i < sizeof(isapnp_irq_range); i++) {
+ u_char v;
- /* Config IRQ */
- for (i = 0; i < 2; i++)
- if (data->irq[i].num > 0) {
- SEND (IRQ_CONFIG + i * 2, data->irq[i].num);
- if (data->irq[i].type >= 0)
- SEND (IRQ_CONFIG + i * 2 + 1, data->irq[i].type);
- }
+ if (i < ipa->ipa_nirq)
+ p = &ipa->ipa_irq[i];
+ else
+ p = &pz;
- /* Config DRQ */
- for (i = 0; i < 2; i++)
- if (data->drq[i] > 0) {
- SEND (DRQ_CONFIG + i, data->drq[i]);
- }
+ isapnp_write_reg(sc,
+ isapnp_irq_range[i] + ISAPNP_IRQ_NUMBER, p->num);
- /* Config MEM */
- for (i = 0; i < 4; i++)
- if (data->mem[i].base > 0) {
- SEND (MEM_CONFIG + i * 8,
- data->mem[i].base >> 16);
- SEND (MEM_CONFIG + i * 8 + 1,
- (data->mem[i].base >> 8) &
- 0xff);
- /*
- * This needs to be handled better for
- * the user's sake. XXX
- */
- if (data->mem[i].control >= 0) {
- SEND (MEM_CONFIG + i * 8 + 2,
- data->mem[i].control);
- }
- SEND (MEM_CONFIG + i * 8 + 3,
- data->mem[i].range >> 16);
- SEND (MEM_CONFIG + i * 8 + 4,
- (data->mem[i].range >> 8) &
- 0xff);
+ switch (p->flags) {
+ case ISAPNP_IRQTYPE_LEVEL_PLUS:
+ v = ISAPNP_IRQ_LEVEL|ISAPNP_IRQ_HIGH;
+ break;
+
+ case ISAPNP_IRQTYPE_EDGE_PLUS:
+ v = ISAPNP_IRQ_HIGH;
+ break;
+
+ case ISAPNP_IRQTYPE_LEVEL_MINUS:
+ v = ISAPNP_IRQ_LEVEL;
+ break;
+
+ default:
+ case ISAPNP_IRQTYPE_EDGE_MINUS:
+ v = 0;
+ break;
}
+ isapnp_write_reg(sc,
+ isapnp_irq_range[i] + ISAPNP_IRQ_CONTROL, v);
+ }
- /* Disable RANGE_CHECK & ACTIVATE logical device */
- SEND (IO_RANGE_CHECK, 0);
- SEND (ACTIVATE, 1);
-}
+ for (i = 0; i < sizeof(isapnp_drq_range); i++) {
+ u_char v;
-int
-find_free_irq(irq_mask)
- int irq_mask;
-{
- struct emap *irq_map;
- int i, j;
-
- irq_map = find_emap("irq");
- i = irq_mask;
-
- while (1) {
- j = ffs(i);
- if (j == 0)
- return(0);
- j--;
- if (!probe_extent(irq_map, j, 1))
- return(j);
- i &= ~(0x1 << j);
+ if (i < ipa->ipa_ndrq)
+ v = ipa->ipa_drq[i].num;
+ else
+ v = 4;
+
+ isapnp_write_reg(sc, isapnp_drq_range[i], v);
}
- return(0);
+ for (i = 0; i < sizeof(isapnp_mem32_range); i++) {
+ if (i < ipa->ipa_nmem32)
+ r = &ipa->ipa_mem32[i];
+ else
+ r = &rz;
+
+ isapnp_write_reg(sc,
+ isapnp_mem32_range[i] + ISAPNP_MEM32_BASE_31_24,
+ B3(r->base));
+ isapnp_write_reg(sc,
+ isapnp_mem32_range[i] + ISAPNP_MEM32_BASE_23_16,
+ B2(r->base));
+ isapnp_write_reg(sc,
+ isapnp_mem32_range[i] + ISAPNP_MEM32_BASE_15_8,
+ B1(r->base));
+ isapnp_write_reg(sc,
+ isapnp_mem32_range[i] + ISAPNP_MEM32_BASE_7_0,
+ B0(r->base));
+
+ isapnp_write_reg(sc,
+ isapnp_mem32_range[i] + ISAPNP_MEM32_LRANGE_31_24,
+ B3(r->length));
+ isapnp_write_reg(sc,
+ isapnp_mem32_range[i] + ISAPNP_MEM32_LRANGE_23_16,
+ B2(r->length));
+ isapnp_write_reg(sc,
+ isapnp_mem32_range[i] + ISAPNP_MEM32_LRANGE_15_8,
+ B1(r->length));
+ isapnp_write_reg(sc,
+ isapnp_mem32_range[i] + ISAPNP_MEM32_LRANGE_7_0,
+ B0(r->length));
+ }
}
+
+/* isapnp_match():
+ * Probe routine
+ */
int
-find_free_drq(drq_mask)
- int drq_mask;
+isapnp_match(parent, match, aux)
+ struct device *parent;
+ void *match;
+ void *aux;
{
- struct emap *drq_map;
- int i, j;
-
- drq_map = find_emap("drq");
- i = drq_mask;
-
- while (1) {
- j = ffs(i);
- if (j == 0)
- return(0);
- j--;
- if (!probe_extent(drq_map, j, 1))
- return(j);
- i &= ~(0x1 << j);
- }
+ int rv;
+ struct isapnp_softc sc;
+ struct isa_attach_args *ia = aux;
+
+ sc.sc_iot = ia->ia_iot;
+ sc.sc_ncards = 0;
+ (void) strcpy(sc.sc_dev.dv_xname, "(isapnp probe)");
+
+ if (isapnp_map(&sc))
+ return 0;
- return(0);
+ rv = isapnp_find(&sc, 0);
+ ia->ia_iobase = ISAPNP_ADDR;
+ ia->ia_iosize = 1;
+
+ isapnp_unmap(&sc);
+ if (rv)
+ isapnp_unmap_readport(&sc);
+
+ return (rv);
}
-/*
- * find free I/O space.
- * if device is capable of doing I/O range check, then use it.
- * else, try to find free region from extent map.
- *
- * assume caller has set csn and ldn properly.
+
+/* isapnp_attach
+ * Find and attach PnP cards.
*/
-int
-find_free_io(sc, desc, min_addr, max_addr, size, alignment, range_check)
- struct isapnp_softc *sc;
- int desc, min_addr, max_addr, size, alignment, range_check;
+void
+isapnp_attach(parent, self, aux)
+ struct device *parent, *self;
+ void *aux;
{
- int addr, i, success = 0;
- bus_space_handle_t data;
- struct emap *io_map;
-
- if (range_check) {
- for (addr = min_addr; addr <= max_addr; addr += alignment) {
- SEND(ACTIVATE, 0);
- SEND(IO_CONFIG_BASE + desc * 2, addr >> 8);
- SEND(IO_CONFIG_BASE + desc * 2 + 1, addr & 0xff);
- SEND(IO_RANGE_CHECK, 0x2);
- bus_space_map(sc->iot, addr, size, 0, &data);
- i = 0;
- for (i = 0; i < size; i++) {
- if (bus_space_read_1(sc->iot, data, i) !=
- 0xAA) {
- bus_space_unmap(sc->iot, data, size);
- break;
- }
+ struct isapnp_softc *sc = (struct isapnp_softc *) self;
+ struct isa_attach_args *ia = aux;
+ int c, d;
+
+ sc->sc_iot = ia->ia_iot;
+ sc->sc_memt = ia->ia_memt;
+ sc->sc_ncards = 0;
+
+ if (isapnp_map(sc))
+ panic("%s: bus map failed\n", sc->sc_dev.dv_xname);
+
+ if (!isapnp_find(sc, 1))
+ panic("%s: no cards found\n", sc->sc_dev.dv_xname);
+
+ printf(": read port 0x%x\n", sc->sc_read_port);
+
+ for (c = 0; c < sc->sc_ncards; c++) {
+ struct isapnp_attach_args *ipa, *lpa;
+
+ /* Good morning card c */
+ isapnp_write_reg(sc, ISAPNP_WAKE, c + 1);
+
+ if ((ipa = isapnp_get_resource(sc, c)) == NULL)
+ continue;
+
+ DPRINTF(("Selecting attachments\n"));
+ for (d = 0;
+ (lpa = isapnp_bestconfig(parent, sc, &ipa)) != NULL; d++) {
+ isapnp_write_reg(sc, ISAPNP_LOGICAL_DEV_NUM, d);
+ isapnp_configure(sc, lpa);
+#ifdef DEBUG_ISAPNP
+ {
+ struct isapnp_attach_args pa;
+
+ isapnp_get_config(sc, &pa);
+ isapnp_print_config(&pa);
}
- if (i == size) {
- success = 1;
- bus_space_unmap(sc->iot, data, size);
- break;
+#endif
+
+ DPRINTF(("%s: configuring <%s, %s, %s, %s>\n",
+ sc->sc_dev.dv_xname,
+ lpa->ipa_devident, lpa->ipa_devlogic,
+ lpa->ipa_devcompat, lpa->ipa_devclass));
+ if (lpa->ipa_pref == ISAPNP_DEP_CONFLICTING) {
+ printf("%s: <%s, %s, %s, %s> ignored; %s\n",
+ sc->sc_dev.dv_xname,
+ lpa->ipa_devident, lpa->ipa_devlogic,
+ lpa->ipa_devcompat, lpa->ipa_devclass,
+ "resource conflict");
+ ISAPNP_FREE(lpa);
+ continue;
}
- }
- if (success) {
- return(addr);
- }
- else {
- return(0);
- }
- } else {
-#if 0
- printf("%x len %x\n", addr, size);
+ lpa->ipa_ic = ia->ia_ic;
+ lpa->ipa_iot = ia->ia_iot;
+ lpa->ipa_memt = ia->ia_memt;
+ lpa->ipa_delaybah = ia->ia_delaybah;
+
+ isapnp_write_reg(sc, ISAPNP_ACTIVATE, 1);
+#ifdef _KERNEL
+ if (config_found_sm(self, lpa, isapnp_print,
+ isapnp_submatch) == NULL)
+ isapnp_write_reg(sc, ISAPNP_ACTIVATE, 0);
+#else
+ isapnp_print(lpa, NULL);
+ printf("\n");
#endif
- io_map = find_emap("io");
- addr = min_addr;
- if (!probe_extent(io_map, addr, size))
- return(addr);
- return (0);
+ ISAPNP_FREE(lpa);
+ }
+ isapnp_write_reg(sc, ISAPNP_WAKE, 0); /* Good night cards */
}
}
diff --git a/sys/dev/isa/isapnpdebug.c b/sys/dev/isa/isapnpdebug.c
new file mode 100644
index 00000000000..f02f80a17a0
--- /dev/null
+++ b/sys/dev/isa/isapnpdebug.c
@@ -0,0 +1,411 @@
+/* $OpenBSD: isapnpdebug.c,v 1.1 1997/12/21 14:41:25 downsj Exp $ */
+/* $NetBSD: isapnpdebug.c,v 1.4 1997/08/03 08:12:23 mikel Exp $ */
+
+/*
+ * Copyright (c) 1996 Christos Zoulas. All rights reserved.
+ *
+ * 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 Christos Zoulas.
+ * 4. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
+ */
+
+#ifdef DEBUG_ISAPNP
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/device.h>
+
+#include <machine/bus.h>
+
+#include <dev/isa/isavar.h>
+
+#include <dev/isa/isapnpreg.h>
+#include <dev/isa/isapnpvar.h>
+
+/* isapnp_print_mem():
+ * Print a memory tag
+ */
+void
+isapnp_print_mem(str, mem)
+ const char *str;
+ const struct isapnp_region *mem;
+{
+ printf("%sMemory: %s,%sshadowable,decode-%s,%scacheable,%s", str,
+ (mem->flags & ISAPNP_MEMATTR_ROM) ? "ROM," : "RAM,",
+ (mem->flags & ISAPNP_MEMATTR_SHADOWABLE) ? "" : "non-",
+ (mem->flags & ISAPNP_MEMATTR_HIGH_ADDR) ?
+ "high-addr," : "range-len,",
+ (mem->flags & ISAPNP_MEMATTR_CACHEABLE) ? "" : "non-",
+ (mem->flags & ISAPNP_MEMATTR_WRITEABLE) ?
+ "writeable," : "read-only,");
+
+ switch (mem->flags & ISAPNP_MEMWIDTH_MASK) {
+ case ISAPNP_MEMWIDTH_8:
+ printf("8-bit ");
+ break;
+ case ISAPNP_MEMWIDTH_16:
+ printf("16-bit ");
+ break;
+ case ISAPNP_MEMWIDTH_8_16:
+ printf("8/16-bit ");
+ break;
+ case ISAPNP_MEMWIDTH_32:
+ printf("32-bit ");
+ break;
+ }
+
+ printf("min 0x%x, max 0x%x, ", mem->minbase, mem->maxbase);
+ printf("align 0x%x, length 0x%x\n", mem->align, mem->length);
+}
+
+
+/* isapnp_print_io():
+ * Print an io tag
+ */
+void
+isapnp_print_io(str, io)
+ const char *str;
+ const struct isapnp_region *io;
+{
+ printf("%d %sIO Ports: %d address bits, alignment %d ",
+ io->length, str, (io->flags & ISAPNP_IOFLAGS_16) ? 16 : 10,
+ io->align);
+
+ printf("min 0x%x, max 0x%x\n", io->minbase, io->maxbase);
+}
+
+
+/* isapnp_print_irq():
+ * Print an irq tag
+ */
+void
+isapnp_print_irq(str, irq)
+ const char *str;
+ const struct isapnp_pin *irq;
+{
+ int i;
+
+ printf("%sIRQ's supported: ", str);
+ for (i = 0; i < 16; i++)
+ if (irq->bits & (1 << i))
+ printf("%d ", i);
+
+ if (irq->flags & ISAPNP_IRQTYPE_EDGE_PLUS)
+ printf("E+");
+ if (irq->flags & ISAPNP_IRQTYPE_EDGE_MINUS)
+ printf("E-");
+ if (irq->flags & ISAPNP_IRQTYPE_LEVEL_PLUS)
+ printf("L+");
+ if (irq->flags & ISAPNP_IRQTYPE_LEVEL_MINUS)
+ printf("L-");
+ printf("\n");
+}
+
+/* isapnp_print_drq():
+ * Print a drq tag
+ */
+void
+isapnp_print_drq(str, drq)
+ const char *str;
+ const struct isapnp_pin *drq;
+{
+ int i;
+ u_char flags = drq->flags;
+
+ printf("%sDRQ's supported: ", str);
+ for (i = 0; i < 8; i++)
+ if (drq->bits & (1 << i))
+ printf("%d ", i);
+
+ printf("Width: ");
+ switch (flags & ISAPNP_DMAWIDTH_MASK) {
+ case ISAPNP_DMAWIDTH_8:
+ printf("8-bit ");
+ break;
+ case ISAPNP_DMAWIDTH_8_16:
+ printf("8/16-bit ");
+ break;
+ case ISAPNP_DMAWIDTH_16:
+ printf("16-bit ");
+ break;
+ case ISAPNP_DMAWIDTH_RESERVED:
+ printf("Reserved ");
+ break;
+ }
+
+ printf("Speed: ");
+ switch (flags & ISAPNP_DMASPEED_MASK) {
+ case ISAPNP_DMASPEED_COMPAT:
+ printf("compat ");
+ break;
+ case ISAPNP_DMASPEED_A:
+ printf("A ");
+ break;
+ case ISAPNP_DMASPEED_B:
+ printf("B ");
+ break;
+ case ISAPNP_DMASPEED_F:
+ printf("F ");
+ break;
+ }
+
+ if (flags & ISAPNP_DMAATTR_MASK)
+ printf("Attributes: %s%s%s",
+ (flags & ISAPNP_DMAATTR_BUS_MASTER) ? "bus master " : "",
+ (flags & ISAPNP_DMAATTR_INCR_8) ? "incr 8 " : "",
+ (flags & ISAPNP_DMAATTR_INCR_16) ? "incr 16 " : "");
+ printf("\n");
+}
+
+
+/* isapnp_print_dep_start():
+ * Print a start dependencies tag
+ */
+void
+isapnp_print_dep_start(str, pref)
+ const char *str;
+ const u_char pref;
+{
+
+ printf("%sconfig: ", str);
+ switch (pref) {
+ case ISAPNP_DEP_PREFERRED:
+ printf("preferred\n");
+ break;
+
+ case ISAPNP_DEP_ACCEPTABLE:
+ printf("acceptable\n");
+ break;
+
+ case ISAPNP_DEP_FUNCTIONAL:
+ printf("functional\n");
+ break;
+
+ case ISAPNP_DEP_UNSET: /* Used internally */
+ printf("unset\n");
+ break;
+
+ case ISAPNP_DEP_CONFLICTING: /* Used internally */
+ printf("conflicting\n");
+ break;
+
+ default:
+ printf("invalid\n");
+ break;
+ }
+}
+
+void
+isapnp_print_attach(pa)
+ const struct isapnp_attach_args *pa;
+{
+ int i;
+
+ printf("Found <%s, %s, %s, %s> ", pa->ipa_devident,
+ pa->ipa_devlogic, pa->ipa_devcompat, pa->ipa_devclass);
+ isapnp_print_dep_start("", pa->ipa_pref);
+
+ for (i = 0; i < pa->ipa_nio; i++)
+ isapnp_print_io("", &pa->ipa_io[i]);
+
+ for (i = 0; i < pa->ipa_nmem; i++)
+ isapnp_print_mem("", &pa->ipa_mem[i]);
+
+ for (i = 0; i < pa->ipa_nirq; i++)
+ isapnp_print_irq("", &pa->ipa_irq[i]);
+
+ for (i = 0; i < pa->ipa_ndrq; i++)
+ isapnp_print_drq("", &pa->ipa_drq[i]);
+
+ for (i = 0; i < pa->ipa_nmem32; i++)
+ isapnp_print_mem("", &pa->ipa_mem32[i]);
+}
+
+
+/* isapnp_get_config():
+ * Get the current configuration of the card
+ */
+void
+isapnp_get_config(sc, pa)
+ struct isapnp_softc *sc;
+ struct isapnp_attach_args *pa;
+{
+ int i;
+ u_char v0, v1, v2, v3;
+ static u_char isapnp_mem_range[] = ISAPNP_MEM_DESC;
+ static u_char isapnp_io_range[] = ISAPNP_IO_DESC;
+ static u_char isapnp_irq_range[] = ISAPNP_IRQ_DESC;
+ static u_char isapnp_drq_range[] = ISAPNP_DRQ_DESC;
+ static u_char isapnp_mem32_range[] = ISAPNP_MEM32_DESC;
+ struct isapnp_region *r;
+ struct isapnp_pin *p;
+
+ memset(pa, 0, sizeof(*pa));
+
+ for (i = 0; i < sizeof(isapnp_io_range); i++) {
+ r = &pa->ipa_io[i];
+ v0 = isapnp_read_reg(sc,
+ isapnp_io_range[i] + ISAPNP_IO_BASE_15_8);
+ v1 = isapnp_read_reg(sc,
+ isapnp_io_range[i] + ISAPNP_IO_BASE_7_0);
+ r->base = (v0 << 8) | v1;
+ if (r->base == 0)
+ break;
+ }
+ pa->ipa_nio = i;
+
+ for (i = 0; i < sizeof(isapnp_mem_range); i++) {
+ r = &pa->ipa_mem[i];
+ v0 = isapnp_read_reg(sc,
+ isapnp_mem_range[i] + ISAPNP_MEM_BASE_23_16);
+ v1 = isapnp_read_reg(sc,
+ isapnp_mem_range[i] + ISAPNP_MEM_BASE_15_8);
+ r->base = (v0 << 16) | (v1 << 8);
+ if (r->base == 0)
+ break;
+
+ v0 = isapnp_read_reg(sc,
+ isapnp_mem_range[i] + ISAPNP_MEM_LRANGE_23_16);
+ v1 = isapnp_read_reg(sc,
+ isapnp_mem_range[i] + ISAPNP_MEM_LRANGE_15_8);
+ r->length = (v0 << 16) | (v1 << 8);
+ v0 = isapnp_read_reg(sc,
+ isapnp_mem_range[i] + ISAPNP_MEM_CONTROL);
+ r->flags = 0;
+ if (v0 & ISAPNP_MEM_CONTROL_LIMIT)
+ r->flags |= ISAPNP_MEMATTR_HIGH_ADDR;
+ if (v0 & ISAPNP_MEM_CONTROL_16)
+ r->flags |= ISAPNP_MEMWIDTH_16;
+ }
+ pa->ipa_nmem = i;
+
+ for (i = 0; i < sizeof(isapnp_irq_range); i++) {
+ v0 = isapnp_read_reg(sc,
+ isapnp_irq_range[i] + ISAPNP_IRQ_NUMBER);
+ p = &pa->ipa_irq[i];
+ p->num = v0 & 0xf;
+ if (p->num == 0)
+ break;
+
+ switch (v0 & (ISAPNP_IRQ_LEVEL|ISAPNP_IRQ_HIGH)) {
+ case ISAPNP_IRQ_LEVEL|ISAPNP_IRQ_HIGH:
+ p->flags = ISAPNP_IRQTYPE_LEVEL_PLUS;
+ break;
+ case ISAPNP_IRQ_HIGH:
+ p->flags = ISAPNP_IRQTYPE_EDGE_PLUS;
+ break;
+ case ISAPNP_IRQ_LEVEL:
+ p->flags = ISAPNP_IRQTYPE_LEVEL_MINUS;
+ break;
+ default:
+ p->flags = ISAPNP_IRQTYPE_EDGE_MINUS;
+ break;
+ }
+ }
+ pa->ipa_nirq = i;
+
+ for (i = 0; i < sizeof(isapnp_drq_range); i++) {
+ v0 = isapnp_read_reg(sc, isapnp_drq_range[i]);
+ p = &pa->ipa_drq[i];
+ p->num = v0 & 0xf;
+ if (p->num == 4)
+ break;
+ }
+ pa->ipa_ndrq = i;
+
+ for (i = 0; i < sizeof(isapnp_mem32_range); i++) {
+ r = &pa->ipa_mem32[i];
+ v0 = isapnp_read_reg(sc,
+ isapnp_mem32_range[i] + ISAPNP_MEM32_BASE_31_24);
+ v1 = isapnp_read_reg(sc,
+ isapnp_mem32_range[i] + ISAPNP_MEM32_BASE_23_16);
+ v2 = isapnp_read_reg(sc,
+ isapnp_mem32_range[i] + ISAPNP_MEM32_BASE_15_8);
+ v3 = isapnp_read_reg(sc,
+ isapnp_mem32_range[i] + ISAPNP_MEM32_BASE_7_0);
+ r->base = (v0 << 24) | (v1 << 16) | (v2 << 8) | v3;
+ if (r->base == 0)
+ break;
+
+ v0 = isapnp_read_reg(sc,
+ isapnp_mem32_range[i] + ISAPNP_MEM32_LRANGE_31_24);
+ v1 = isapnp_read_reg(sc,
+ isapnp_mem32_range[i] + ISAPNP_MEM32_LRANGE_23_16);
+ v2 = isapnp_read_reg(sc,
+ isapnp_mem32_range[i] + ISAPNP_MEM32_LRANGE_15_8);
+ v3 = isapnp_read_reg(sc,
+ isapnp_mem32_range[i] + ISAPNP_MEM32_LRANGE_7_0);
+ r->length = (v0 << 24) | (v1 << 16) | (v2 << 8) | v3;
+ v0 = isapnp_read_reg(sc,
+ isapnp_mem_range[i] + ISAPNP_MEM_CONTROL);
+ r->flags = v0;
+ }
+ pa->ipa_nmem32 = i;
+}
+
+
+/* isapnp_print_config():
+ * Print the current configuration of the card
+ */
+void
+isapnp_print_config(pa)
+ const struct isapnp_attach_args *pa;
+{
+ int i;
+ const struct isapnp_region *r;
+ const struct isapnp_pin *p;
+
+ printf("Register configuration:\n");
+ if (pa->ipa_nio)
+ for (i = 0; i < pa->ipa_nio; i++) {
+ r = &pa->ipa_io[i];
+ printf("io[%d]: 0x%x/%d\n", i, r->base, r->length);
+ }
+
+ if (pa->ipa_nmem)
+ for (i = 0; i < pa->ipa_nmem; i++) {
+ r = &pa->ipa_mem[i];
+ printf("mem[%d]: 0x%x/%d\n", i, r->base, r->length);
+ }
+
+ if (pa->ipa_nirq)
+ for (i = 0; i < pa->ipa_nirq; i++) {
+ p = &pa->ipa_irq[i];
+ printf("irq[%d]: %d\n", i, p->num);
+ }
+
+ if (pa->ipa_ndrq)
+ for (i = 0; i < pa->ipa_ndrq; i++) {
+ p = &pa->ipa_drq[i];
+ printf("drq[%d]: %d\n", i, p->num);
+ }
+
+ if (pa->ipa_nmem32)
+ for (i = 0; i < pa->ipa_nmem32; i++) {
+ r = &pa->ipa_mem32[i];
+ printf("mem32[%d]: 0x%x/%d\n", i, r->base, r->length);
+ }
+}
+
+#endif
diff --git a/sys/dev/isa/isapnpreg.h b/sys/dev/isa/isapnpreg.h
index ffff96583ef..d379dccc22d 100644
--- a/sys/dev/isa/isapnpreg.h
+++ b/sys/dev/isa/isapnpreg.h
@@ -1,8 +1,8 @@
-/* $OpenBSD: isapnpreg.h,v 1.2 1997/07/12 23:22:01 weingart Exp $ */
+/* $OpenBSD: isapnpreg.h,v 1.3 1997/12/21 14:41:26 downsj Exp $ */
+/* $NetBSD: isapnpreg.h,v 1.5 1997/08/12 07:34:34 mikel Exp $ */
/*
- * Copyright (c) 1996, Sujal M. Patel
- * All rights reserved.
+ * Copyright (c) 1996 Christos Zoulas. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -14,87 +14,160 @@
* 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 Sujal M. Patel
- * 4. Neither the name of the author nor the names of any co-contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
+ * This product includes software developed by Christos Zoulas.
+ * 4. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
*
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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_ISA_ISAPNPREG_H_
-#define _DEV_ISA_ISAPNPREG_H_
+/*
+ * ISA Plug and Play register definitions;
+ * From Plug and Play ISA Specification V1.0a, May 5 1994
+ */
+
+#define ISAPNP_MAX_CARDS 8
+#define ISAPNP_MAX_IDENT 32
+#define ISAPNP_MAX_DEVCLASS 16
+#define ISAPNP_SERIAL_SIZE 9
+#define ISAPNP_MAX_TAGSIZE 256
+
+#define ISAPNP_ADDR 0x279 /* Write only */
+#define ISAPNP_WRDATA 0xa79 /* Write only */
+
+/* The read port is in range 0x203 to 0x3ff */
+#define ISAPNP_RDDATA_MIN 0x203 /* Read only */
+#define ISAPNP_RDDATA_MAX 0x3ff
+
+#define ISAPNP_LFSR_INIT 0x6A /* Initial value of LFSR sequence */
+#define ISAPNP_LFSR_LENGTH 32 /* Number of values in LFSR sequence */
+ /* Formula to compute the next value */
+#define ISAPNP_LFSR_NEXT(v) (((v) >> 1) | (((v) & 1) ^ (((v) & 2) >> 1)) << 7)
-/* Maximum Number of PnP Devices. 8 should be plenty */
-#define MAX_CARDS 8
+#define ISAPNP_SET_RD_PORT 0x00
+#define ISAPNP_SERIAL_ISOLATION 0x01
+#define ISAPNP_CONFIG_CONTROL 0x02
+#define ISAPNP_CC_RESET 0x01
+#define ISAPNP_CC_WAIT_FOR_KEY 0x02
+#define ISAPNP_CC_RESET_CSN 0x04
+#define ISAPNP_CC_RESET_DRV 0x07
+#define ISAPNP_WAKE 0x03
+#define ISAPNP_RESOURCE_DATA 0x04
+#define ISAPNP_STATUS 0x05
+#define ISAPNP_CARD_SELECT_NUM 0x06
+#define ISAPNP_LOGICAL_DEV_NUM 0x07
+#define ISAPNP_ACTIVATE 0x30
+#define ISAPNP_IO_RANGE_CHECK 0x31
-/* Static ports */
-#define ADDRESS 0x279
-#if 0
-#define WRITE_DATA 0xa79
-#else
-#define WRITE_DATA (ADDRESS+0x0800)
-#endif
+#define ISAPNP_NUM_MEM 4
+#define ISAPNP_MEM_DESC { 0x40, 0x48, 0x50, 0x58 }
+#define ISAPNP_MEM_BASE_23_16 0x0
+#define ISAPNP_MEM_BASE_15_8 0x1
+#define ISAPNP_MEM_CONTROL 0x2
+#define ISAPNP_MEM_CONTROL_LIMIT 1
+#define ISAPNP_MEM_CONTROL_16 2
+#define ISAPNP_MEM_LRANGE_23_16 0x3
+#define ISAPNP_MEM_LRANGE_15_8 0x4
+#define ISAPNP_NUM_IO 8
+#define ISAPNP_IO_DESC { 0x60, 0x62, 0x64, 0x68, 0x6a, 0x6c, 0x6e }
+#define ISAPNP_IO_BASE_15_8 0x0
+#define ISAPNP_IO_BASE_7_0 0x1
-/* PnP Registers. Write to ADDRESS and then use WRITE/READ_DATA */
-#define SET_RD_DATA 0x00
-#define SERIAL_ISOLATION 0x01
-#define CONFIG_CONTROL 0x02
-#define WAKE 0x03
-#define RESOURCE_DATA 0x04
-#define STATUS 0x05
-#define SET_CSN 0x06
-#define SET_LDN 0x07
-#define ACTIVATE 0x30
-#define IO_RANGE_CHECK 0x31
-#define MEM_CONFIG 0x40
-#define IO_CONFIG_BASE 0x60
-#define IRQ_CONFIG 0x70
-#define DRQ_CONFIG 0x74
+#define ISAPNP_NUM_IRQ 16
+#define ISAPNP_IRQ_DESC { 0x70, 0x72 }
+#define ISAPNP_IRQ_NUMBER 0x0
+#define ISAPNP_IRQ_CONTROL 0x1
+#define ISAPNP_IRQ_LEVEL 1
+#define ISAPNP_IRQ_HIGH 2
-/* Small Resource Item names */
-#define PNP_VERSION 0x1
-#define LOG_DEVICE_ID 0x2
-#define COMP_DEVICE_ID 0x3
-#define IRQ_FORMAT 0x4
-#define DMA_FORMAT 0x5
-#define START_DEPEND_FUNC 0x6
-#define END_DEPEND_FUNC 0x7
-#define IO_PORT_DESC 0x8
-#define FIXED_IO_PORT_DESC 0x9
-#define SM_RES_RESERVED1 0xa
-#define SM_RES_RESERVED2 0xb
-#define SM_RES_RESERVED3 0xc
-#define SM_RES_RESERVED4 0xd
-#define SM_VENDOR_DEFINED 0xe
-#define END_TAG 0xf
+#define ISAPNP_NUM_DRQ 8
+#define ISAPNP_DRQ_DESC { 0x74, 0x75 }
-/* Large Resource Item names */
-#define MEMORY_RANGE_DESC 0x1
-#define ID_STRING_ANSI 0x2
-#define ID_STRING_UNICODE 0x3
-#define LG_VENDOR_DEFINED 0x4
-#define _32BIT_MEM_RANGE_DESC 0x5
-#define _32BIT_FIXED_LOC_DESC 0x6
-#define LG_RES_RESERVED 0x7-0x7f
+#define ISAPNP_NUM_MEM32 4
+#define ISAPNP_MEM32_DESC { 0x76, 0x80, 0x90, 0xa0 }
+#define ISAPNP_MEM32_BASE_31_24 0x0
+#define ISAPNP_MEM32_BASE_23_16 0x1
+#define ISAPNP_MEM32_BASE_15_8 0x2
+#define ISAPNP_MEM32_BASE_7_0 0x3
+#define ISAPNP_MEM32_CONTROL 0x4
+#define ISAPNP_MEM32_CONTROL_LIMIT 1
+#define ISAPNP_MEM32_CONTROL_16 2
+#define ISAPNP_MEM32_CONTROL_32 6
+#define ISAPNP_MEM32_LRANGE_31_24 0x5
+#define ISAPNP_MEM32_LRANGE_23_16 0x6
+#define ISAPNP_MEM32_LRANGE_15_8 0x7
+#define ISAPNP_MEM32_LRANGE_7_0 0x8
-/* Priority for Resource Group */
-#define BASIC_CONFIGURATION -1
-#define GOOD_CONFIGURATION 0x0
-#define ACCEPTABLE_CONFIGURATION 0x1
-#define SUBOPTIMAL_CONFIGURATION 0x2
-#define RESERVED_CONFIGURATION 0x3
+/* Small Tags */
+#define ISAPNP_TAG_VERSION_NUM 0x1
+#define ISAPNP_TAG_LOGICAL_DEV_ID 0x2
+#define ISAPNP_TAG_COMPAT_DEV_ID 0x3
+#define ISAPNP_TAG_IRQ_FORMAT 0x4
+#define ISAPNP_IRQTYPE_EDGE_PLUS 1
+#define ISAPNP_IRQTYPE_EDGE_MINUS 2
+#define ISAPNP_IRQTYPE_LEVEL_PLUS 4
+#define ISAPNP_IRQTYPE_LEVEL_MINUS 8
+#define ISAPNP_TAG_DMA_FORMAT 0x5
+#define ISAPNP_DMAWIDTH_8 0x00
+#define ISAPNP_DMAWIDTH_8_16 0x01
+#define ISAPNP_DMAWIDTH_16 0x02
+#define ISAPNP_DMAWIDTH_RESERVED 0x03
+#define ISAPNP_DMAWIDTH_MASK 0x03
+#define ISAPNP_DMAATTR_BUS_MASTER 0x04
+#define ISAPNP_DMAATTR_INCR_8 0x08
+#define ISAPNP_DMAATTR_INCR_16 0x10
+#define ISAPNP_DMAATTR_MASK 0x1c
+#define ISAPNP_DMASPEED_COMPAT 0x00
+#define ISAPNP_DMASPEED_A 0x20
+#define ISAPNP_DMASPEED_B 0x40
+#define ISAPNP_DMASPEED_F 0x60
+#define ISAPNP_DMASPEED_MASK 0x60
+#define ISAPNP_TAG_DEP_START 0x6
+#define ISAPNP_DEP_PREFERRED 0x0
+#define ISAPNP_DEP_ACCEPTABLE 0x1
+#define ISAPNP_DEP_FUNCTIONAL 0x2
+#define ISAPNP_DEP_RESERVED 0x3
+#define ISAPNP_DEP_MASK 0x3
+#define ISAPNP_DEP_UNSET 0x80 /* Internal */
+#define ISAPNP_DEP_CONFLICTING 0x81 /* Internal */
+#define ISAPNP_TAG_DEP_END 0x7
+#define ISAPNP_TAG_IO_PORT_DESC 0x8
+#define ISAPNP_IOFLAGS_16 0x1
+#define ISAPNP_TAG_FIXED_IO_PORT_DESC 0x9
+#define ISAPNP_TAG_RESERVED1 0xa
+#define ISAPNP_TAG_RESERVED2 0xb
+#define ISAPNP_TAG_RESERVED3 0xc
+#define ISAPNP_TAG_RESERVED4 0xd
+#define ISAPNP_TAG_VENDOR_DEF 0xe
+#define ISAPNP_TAG_END 0xf
-#endif /* !_DEV_ISA_ISAPNPREG_H_ */
+/* Large Tags */
+#define ISAPNP_LARGE_TAG 0x80
+#define ISAPNP_TAG_MEM_RANGE_DESC 0x81
+#define ISAPNP_MEMATTR_WRITEABLE 0x01
+#define ISAPNP_MEMATTR_CACHEABLE 0x02
+#define ISAPNP_MEMATTR_HIGH_ADDR 0x04
+#define ISAPNP_MEMATTR_SHADOWABLE 0x20
+#define ISAPNP_MEMATTR_ROM 0x40
+#define ISAPNP_MEMATTR_MASK 0x67
+#define ISAPNP_MEMWIDTH_8 0x00
+#define ISAPNP_MEMWIDTH_16 0x08
+#define ISAPNP_MEMWIDTH_8_16 0x10
+#define ISAPNP_MEMWIDTH_32 0x18
+#define ISAPNP_MEMWIDTH_MASK 0x18
+#define ISAPNP_TAG_ANSI_IDENT_STRING 0x82
+#define ISAPNP_TAG_UNICODE_IDENT_STRING 0x83
+#define ISAPNP_TAG_VENDOR_DEFINED 0x84
+#define ISAPNP_TAG_MEM32_RANGE_DESC 0x85
+#define ISAPNP_TAG_FIXED_MEM32_RANGE_DESC 0x86
diff --git a/sys/dev/isa/isapnpres.c b/sys/dev/isa/isapnpres.c
new file mode 100644
index 00000000000..99044fabe83
--- /dev/null
+++ b/sys/dev/isa/isapnpres.c
@@ -0,0 +1,524 @@
+/* $OpenBSD: isapnpres.c,v 1.1 1997/12/21 14:41:26 downsj Exp $ */
+/* $NetBSD: isapnpres.c,v 1.7.4.1 1997/11/20 07:46:13 mellon Exp $ */
+
+/*
+ * Copyright (c) 1996 Christos Zoulas. All rights reserved.
+ *
+ * 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 Christos Zoulas.
+ * 4. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
+ */
+
+/*
+ * Resource parser for Plug and Play cards.
+ */
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/device.h>
+#include <sys/malloc.h>
+
+#include <machine/bus.h>
+
+#include <dev/isa/isavar.h>
+
+#include <dev/isa/isapnpreg.h>
+#include <dev/isa/isapnpvar.h>
+
+
+int isapnp_wait_status __P((struct isapnp_softc *));
+struct isapnp_attach_args *
+ isapnp_newdev __P((struct isapnp_attach_args *));
+struct isapnp_attach_args *
+ isapnp_newconf __P((struct isapnp_attach_args *));
+void isapnp_merge __P((struct isapnp_attach_args *,
+ const struct isapnp_attach_args *));
+struct isapnp_attach_args *
+ isapnp_flatten __P((struct isapnp_attach_args *));
+int isapnp_process_tag __P((u_char, u_char, u_char *,
+ struct isapnp_attach_args **, struct isapnp_attach_args **,
+ struct isapnp_attach_args **));
+
+
+/* isapnp_wait_status():
+ * Wait for the next byte of resource data to become available
+ */
+int
+isapnp_wait_status(sc)
+ struct isapnp_softc *sc;
+{
+ int i;
+
+ /* wait up to 1 ms for each resource byte */
+ for (i = 0; i < 10; i++) {
+ if (isapnp_read_reg(sc, ISAPNP_STATUS) & 1)
+ return 0;
+ DELAY(100);
+ }
+ return 1;
+}
+
+
+/* isapnp_newdev():
+ * Add a new logical device to the current card; expand the configuration
+ * resources of the current card if needed.
+ */
+struct isapnp_attach_args *
+isapnp_newdev(card)
+ struct isapnp_attach_args *card;
+{
+ struct isapnp_attach_args *ipa, *dev = ISAPNP_MALLOC(sizeof(*dev));
+
+ memset(dev, 0, sizeof(*dev));
+
+ dev->ipa_pref = ISAPNP_DEP_ACCEPTABLE;
+ memcpy(dev->ipa_devident, card->ipa_devident,
+ sizeof(card->ipa_devident));
+
+ if (card->ipa_child == NULL)
+ card->ipa_child = dev;
+ else {
+ for (ipa = card->ipa_child; ipa->ipa_sibling != NULL;
+ ipa = ipa->ipa_sibling)
+ continue;
+ ipa->ipa_sibling = dev;
+ }
+
+
+ return dev;
+}
+
+
+/* isapnp_newconf():
+ * Add a new alternate configuration to a logical device
+ */
+struct isapnp_attach_args *
+isapnp_newconf(dev)
+ struct isapnp_attach_args *dev;
+{
+ struct isapnp_attach_args *ipa, *conf = ISAPNP_MALLOC(sizeof(*conf));
+
+ memset(conf, 0, sizeof(*conf));
+
+ memcpy(conf->ipa_devident, dev->ipa_devident,
+ sizeof(conf->ipa_devident));
+ memcpy(conf->ipa_devlogic, dev->ipa_devlogic,
+ sizeof(conf->ipa_devlogic));
+ memcpy(conf->ipa_devcompat, dev->ipa_devcompat,
+ sizeof(conf->ipa_devcompat));
+ memcpy(conf->ipa_devclass, dev->ipa_devclass,
+ sizeof(conf->ipa_devclass));
+
+ if (dev->ipa_child == NULL)
+ dev->ipa_child = conf;
+ else {
+ for (ipa = dev->ipa_child; ipa->ipa_sibling;
+ ipa = ipa->ipa_sibling)
+ continue;
+ ipa->ipa_sibling = conf;
+ }
+
+ return conf;
+}
+
+
+/* isapnp_merge():
+ * Merge the common device configurations to the subconfigurations
+ */
+void
+isapnp_merge(c, d)
+ struct isapnp_attach_args *c;
+ const struct isapnp_attach_args *d;
+{
+ int i;
+
+ for (i = 0; i < d->ipa_nio; i++)
+ c->ipa_io[c->ipa_nio++] = d->ipa_io[i];
+
+ for (i = 0; i < d->ipa_nmem; i++)
+ c->ipa_mem[c->ipa_nmem++] = d->ipa_mem[i];
+
+ for (i = 0; i < d->ipa_nmem32; i++)
+ c->ipa_mem32[c->ipa_nmem32++] = d->ipa_mem32[i];
+
+ for (i = 0; i < d->ipa_nirq; i++)
+ c->ipa_irq[c->ipa_nirq++] = d->ipa_irq[i];
+
+ for (i = 0; i < d->ipa_ndrq; i++)
+ c->ipa_drq[c->ipa_ndrq++] = d->ipa_drq[i];
+}
+
+
+/* isapnp_flatten():
+ * Flatten the tree to a list of config entries.
+ */
+struct isapnp_attach_args *
+isapnp_flatten(card)
+ struct isapnp_attach_args *card;
+{
+ struct isapnp_attach_args *dev, *conf, *d, *c, *pa;
+
+ dev = card->ipa_child;
+ ISAPNP_FREE(card);
+
+ for (conf = c = NULL, d = dev; d; d = dev) {
+ dev = d->ipa_sibling;
+ if (d->ipa_child == NULL) {
+ /*
+ * No subconfigurations; all configuration info
+ * is in the device node.
+ */
+ d->ipa_sibling = NULL;
+ pa = d;
+ }
+ else {
+ /*
+ * Push down device configuration info to the
+ * subconfigurations
+ */
+ for (pa = d->ipa_child; pa; pa = pa->ipa_sibling)
+ isapnp_merge(pa, d);
+
+ pa = d->ipa_child;
+ ISAPNP_FREE(d);
+ }
+
+ if (c == NULL)
+ c = conf = pa;
+ else
+ c->ipa_sibling = pa;
+
+ while (c->ipa_sibling)
+ c = c->ipa_sibling;
+ }
+ return conf;
+}
+
+
+/* isapnp_process_tag():
+ * Process a resource tag
+ */
+int
+isapnp_process_tag(tag, len, buf, card, dev, conf)
+ u_char tag, len, *buf;
+ struct isapnp_attach_args **card, **dev, **conf;
+{
+ char str[64];
+ struct isapnp_region *r;
+ struct isapnp_pin *p;
+ struct isapnp_attach_args *pa;
+
+#define COPY(a, b) strncpy((a), (b), sizeof(a)), (a)[sizeof(a) - 1] = '\0'
+
+ switch (tag) {
+ case ISAPNP_TAG_VERSION_NUM:
+ DPRINTF(("PnP version %d.%d, Vendor version %d.%d\n",
+ buf[0] >> 4, buf[0] & 0xf, buf[1] >> 4, buf[1] & 0xf));
+ return 0;
+
+ case ISAPNP_TAG_LOGICAL_DEV_ID:
+ (void) isapnp_id_to_vendor(str, buf);
+ DPRINTF(("Logical device id %s\n", str));
+
+ *dev = isapnp_newdev(*card);
+ COPY((*dev)->ipa_devlogic, str);
+ return 0;
+
+ case ISAPNP_TAG_COMPAT_DEV_ID:
+ (void) isapnp_id_to_vendor(str, buf);
+ DPRINTF(("Compatible device id %s\n", str));
+
+ if (*dev == NULL)
+ return -1;
+
+ if (*(*dev)->ipa_devcompat == '\0')
+ COPY((*dev)->ipa_devcompat, str);
+ return 0;
+
+ case ISAPNP_TAG_DEP_START:
+ if (len == 0)
+ buf[0] = ISAPNP_DEP_ACCEPTABLE;
+
+ if (*dev == NULL)
+ return -1;
+
+ *conf = isapnp_newconf(*dev);
+ (*conf)->ipa_pref = buf[0];
+#ifdef DEBUG_ISAPNP
+ isapnp_print_dep_start(">>> Start dependent function ",
+ (*conf)->ipa_pref);
+#endif
+ return 0;
+
+ case ISAPNP_TAG_DEP_END:
+ DPRINTF(("<<<End dependent functions\n"));
+ *conf = NULL;
+ return 0;
+
+ case ISAPNP_TAG_ANSI_IDENT_STRING:
+ buf[len] = '\0';
+ DPRINTF(("ANSI Ident: %s\n", buf));
+ if (*dev == NULL)
+ COPY((*card)->ipa_devident, buf);
+ else
+ COPY((*dev)->ipa_devclass, buf);
+ return 0;
+
+ case ISAPNP_TAG_END:
+ *dev = NULL;
+ return 0;
+
+ default:
+ /* Handled below */
+ break;
+ }
+
+
+ /*
+ * Decide which configuration we add the tag to
+ */
+ if (*conf)
+ pa = *conf;
+ else if (*dev)
+ pa = *dev;
+ else
+ /* error */
+ return -1;
+
+ switch (tag) {
+ case ISAPNP_TAG_IRQ_FORMAT:
+ if (len < 2)
+ break;
+
+ if (len != 3)
+ buf[2] = ISAPNP_IRQTYPE_EDGE_PLUS;
+
+ p = &pa->ipa_irq[pa->ipa_nirq++];
+ p->bits = buf[0] | (buf[1] << 8);
+ p->flags = buf[2];
+#ifdef DEBUG_ISAPNP
+ isapnp_print_irq("", p);
+#endif
+ break;
+
+ case ISAPNP_TAG_DMA_FORMAT:
+ if (buf[0] == 0)
+ break;
+
+ p = &pa->ipa_drq[pa->ipa_ndrq++];
+ p->bits = buf[0];
+ p->flags = buf[1];
+#ifdef DEBUG_ISAPNP
+ isapnp_print_drq("", p);
+#endif
+ break;
+
+
+ case ISAPNP_TAG_IO_PORT_DESC:
+ r = &pa->ipa_io[pa->ipa_nio++];
+ r->flags = buf[0];
+ r->minbase = (buf[2] << 8) | buf[1];
+ r->maxbase = (buf[4] << 8) | buf[3];
+ r->align = buf[5];
+ r->length = buf[6];
+#ifdef DEBUG_ISAPNP
+ isapnp_print_io("", r);
+#endif
+ break;
+
+ case ISAPNP_TAG_FIXED_IO_PORT_DESC:
+ r = &pa->ipa_io[pa->ipa_nio++];
+ r->flags = 0;
+ r->minbase = (buf[1] << 8) | buf[0];
+ r->maxbase = r->minbase;
+ r->align = 1;
+ r->length = buf[2];
+#ifdef DEBUG_ISAPNP
+ isapnp_print_io("FIXED ", r);
+#endif
+ break;
+
+ case ISAPNP_TAG_VENDOR_DEF:
+ DPRINTF(("Vendor defined (short)\n"));
+ break;
+
+ case ISAPNP_TAG_MEM_RANGE_DESC:
+ r = &pa->ipa_mem[pa->ipa_nmem++];
+ r->flags = buf[0];
+ r->minbase = (buf[2] << 16) | (buf[1] << 8);
+ r->maxbase = (buf[4] << 16) | (buf[3] << 8);
+ r->align = (buf[6] << 8) | buf[5];
+ r->length = (buf[8] << 16) | (buf[7] << 8);
+#ifdef DEBUG_ISAPNP
+ isapnp_print_mem("", r);
+#endif
+ break;
+
+
+ case ISAPNP_TAG_UNICODE_IDENT_STRING:
+ DPRINTF(("Unicode Ident\n"));
+ break;
+
+ case ISAPNP_TAG_VENDOR_DEFINED:
+ DPRINTF(("Vendor defined (long)\n"));
+ break;
+
+ case ISAPNP_TAG_MEM32_RANGE_DESC:
+ r = &pa->ipa_mem32[pa->ipa_nmem32++];
+ r->flags = buf[0];
+ r->minbase = (buf[4] << 24) | (buf[3] << 16) |
+ (buf[2] << 8) | buf[1];
+ r->maxbase = (buf[8] << 24) | (buf[7] << 16) |
+ (buf[6] << 8) | buf[5];
+ r->align = (buf[12] << 24) | (buf[11] << 16) |
+ (buf[10] << 8) | buf[9];
+ r->length = (buf[16] << 24) | (buf[15] << 16) |
+ (buf[14] << 8) | buf[13];
+#ifdef DEBUG_ISAPNP
+ isapnp_print_mem("32-bit ", r);
+#endif
+ break;
+
+ case ISAPNP_TAG_FIXED_MEM32_RANGE_DESC:
+ r = &pa->ipa_mem32[pa->ipa_nmem32++];
+ r->flags = buf[0];
+ r->minbase = (buf[4] << 24) | (buf[3] << 16) |
+ (buf[2] << 8) | buf[1];
+ r->maxbase = r->minbase;
+ r->align = 1;
+ r->length = (buf[8] << 24) | (buf[7] << 16) |
+ (buf[6] << 8) | buf[5];
+#ifdef DEBUG_ISAPNP
+ isapnp_print_mem("FIXED 32-bit ", r);
+#endif
+ break;
+
+ default:
+#ifdef DEBUG_ISAPNP
+ {
+ int i;
+ printf("tag %.2x, len %d: ", tag, len);
+ for (i = 0; i < len; i++)
+ printf("%.2x ", buf[i]);
+ printf("\n");
+ }
+#endif
+ break;
+ }
+ return 0;
+}
+
+
+/* isapnp_get_resource():
+ * Read the resources for card c
+ */
+struct isapnp_attach_args *
+isapnp_get_resource(sc, c)
+ struct isapnp_softc *sc;
+ int c;
+{
+ u_char d, tag;
+ u_short len;
+ int i;
+ int warned = 0;
+ struct isapnp_attach_args *card, *dev = NULL, *conf = NULL;
+ u_char buf[ISAPNP_MAX_TAGSIZE], *p;
+
+ memset(buf, 0, sizeof(buf));
+
+ card = ISAPNP_MALLOC(sizeof(*card));
+ memset(card, 0, sizeof(*card));
+
+#define NEXT_BYTE \
+ if (isapnp_wait_status(sc)) \
+ goto bad; \
+ d = isapnp_read_reg(sc, ISAPNP_RESOURCE_DATA)
+
+ for (i = 0; i < ISAPNP_SERIAL_SIZE; i++) {
+ NEXT_BYTE;
+
+ if (d != sc->sc_id[c][i] && i != ISAPNP_SERIAL_SIZE - 1) {
+ if (!warned) {
+ printf("%s: card %d violates PnP spec; byte %d\n",
+ sc->sc_dev.dv_xname, c + 1, i);
+ warned++;
+ }
+ if (i == 0) {
+ /*
+ * Magic! If this is the first byte, we
+ * assume that the tag data begins here.
+ */
+ goto parse;
+ }
+ }
+ }
+
+ do {
+ NEXT_BYTE;
+parse:
+
+ if (d & ISAPNP_LARGE_TAG) {
+ tag = d;
+ NEXT_BYTE;
+ buf[0] = d;
+ NEXT_BYTE;
+ buf[1] = d;
+ len = (buf[1] << 8) | buf[0];
+ }
+ else {
+ tag = (d >> 3) & 0xf;
+ len = d & 0x7;
+ }
+
+ for (p = buf, i = 0; i < len; i++) {
+ NEXT_BYTE;
+ if (i < ISAPNP_MAX_TAGSIZE)
+ *p++ = d;
+ }
+
+ if (len >= ISAPNP_MAX_TAGSIZE) {
+ printf("%s: Maximum tag size exceeded, card %d\n",
+ sc->sc_dev.dv_xname, c + 1);
+ len = ISAPNP_MAX_TAGSIZE;
+ if (++warned == 10)
+ goto bad;
+ }
+
+ if (isapnp_process_tag(tag, len, buf, &card, &dev, &conf) == -1)
+ printf("%s: No current device for tag, card %d\n",
+ sc->sc_dev.dv_xname, c + 1);
+ }
+ while (tag != ISAPNP_TAG_END);
+ return isapnp_flatten(card);
+
+bad:
+ for (card = isapnp_flatten(card); card; ) {
+ dev = card->ipa_sibling;
+ ISAPNP_FREE(card);
+ card = dev;
+ }
+ printf("%s: %s, card %d\n", sc->sc_dev.dv_xname,
+ warned >= 10 ? "Too many tag errors" : "Resource timeout", c + 1);
+ return NULL;
+}
diff --git a/sys/dev/isa/isapnpvar.h b/sys/dev/isa/isapnpvar.h
index 5458419fc46..5feb9ea17a7 100644
--- a/sys/dev/isa/isapnpvar.h
+++ b/sys/dev/isa/isapnpvar.h
@@ -1,8 +1,8 @@
-/* $OpenBSD: isapnpvar.h,v 1.2 1997/07/12 23:22:02 weingart Exp $ */
+/* $OpenBSD: isapnpvar.h,v 1.3 1997/12/21 14:41:27 downsj Exp $ */
+/* $NetBSD: isapnpvar.h,v 1.5.4.2 1997/10/29 00:40:49 thorpej Exp $ */
/*
- * Copyright (c) 1996, Shawn Hsiao <shawn@alpha.secc.fju.edu.tw>
- * All rights reserved.
+ * Copyright (c) 1996 Christos Zoulas. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -12,92 +12,192 @@
* 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 Christos Zoulas.
+ * 4. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
*
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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_ISA_ISAPNPVAR_H_
-#define _DEV_ISA_ISAPNPVAR_H_
+#ifndef _DEV_ISAPNP_ISAPNPVAR_H_
+#define _DEV_ISAPNP_ISAPNPVAR_H_
-struct irq_format {
- int num; /* IRQ number */
- int info; /* IRQ type */
-};
+/*
+ * ISA Plug and Play register definitions;
+ * From Plug and Play ISA Specification V1.0a, May 5 1994
+ */
-struct dma_format {
- int channel; /* DMA channel */
- int info; /* DMA type */
+/*
+ * Structures and definitions needed by the machine-dependent header.
+ */
+struct isapnp_softc;
+
+#if (i386 != 1)
+ERROR: COMPILING FOR UNSUPPORTED MACHINE, OR MORE THAN ONE.
+#endif
+#if i386
+#include <i386/isa/isapnp_machdep.h>
+#endif
+
+#ifndef _KERNEL
+
+# include <stdlib.h>
+# include <string.h>
+# include <unistd.h>
+
+# define ISAPNP_WRITE_ADDR(sc, v) outb(ISAPNP_ADDR, v)
+# define ISAPNP_WRITE_DATA(sc, v) outb(ISAPNP_WRDATA, v)
+# define ISAPNP_READ_DATA(sc) inb(sc->sc_read_port)
+
+# define DELAY(us) usleep(us)
+# define ISAPNP_MALLOC(a) malloc(a)
+# define ISAPNP_FREE(a) free(a)
+
+# define panic printf
+
+#else
+
+/* XXX */
+# define memset(a, b, c) bzero(a, c)
+
+# define ISAPNP_WRITE_ADDR(sc, v) \
+ bus_space_write_1(sc->sc_iot, sc->sc_addr_ioh, 0, v)
+# define ISAPNP_WRITE_DATA(sc, v) \
+ bus_space_write_1(sc->sc_iot, sc->sc_wrdata_ioh, 0, v)
+# define ISAPNP_READ_DATA(sc) \
+ bus_space_read_1(sc->sc_iot, sc->sc_read_ioh, 0)
+
+# define ISAPNP_MALLOC(a) malloc(a, M_DEVBUF, M_WAITOK)
+# define ISAPNP_FREE(a) free(a, M_DEVBUF)
+
+#endif
+
+#ifdef DEBUG_ISAPNP
+# define DPRINTF(a) printf a
+#else
+# define DPRINTF(a)
+#endif
+
+struct isapnp_softc {
+ struct device sc_dev;
+ int sc_read_port;
+ bus_space_tag_t sc_iot;
+ bus_space_tag_t sc_memt;
+ bus_space_handle_t sc_addr_ioh;
+ bus_space_handle_t sc_wrdata_ioh;
+ bus_space_handle_t sc_read_ioh;
+ bus_space_handle_t sc_memh;
+ u_int8_t sc_ncards;
+ u_int8_t sc_id[ISAPNP_MAX_CARDS][ISAPNP_SERIAL_SIZE];
};
-struct io_descriptor {
- int type; /* normal or fixed I/O descriptor */
- int info; /* decoding information */
- int min_base; /* minimum base I/O address */
- int max_base; /* maximum base I/O address */
- int alignment; /* alignment for base address */
- int size; /* number of contiguous ports */
-};
+struct isapnp_region {
+ bus_space_handle_t h;
+ u_int32_t base;
-struct mem_descriptor {
- int type; /* 24 or 32bit memory descriptor */
- int info; /* misc. memory information */
- int min_base; /* minimum base mem address */
- int max_base; /* maximum base mem address */
- int alignment; /* aligment for base address */
- int size; /* number of memory range length */
+ u_int32_t minbase;
+ u_int32_t maxbase;
+ u_int32_t length;
+ u_int32_t align;
+ u_int8_t flags;
};
-struct confinfo {
- int prio;
- struct irq_format *irq[2];
- struct dma_format *dma[2];
- struct io_descriptor *io[8];
- struct mem_descriptor *mem[4];
-
- TAILQ_ENTRY(confinfo) conf_link;
+struct isapnp_pin {
+ u_int8_t num;
+ u_int8_t flags:4;
+ u_int8_t type:4;
+ u_int16_t bits;
};
-struct devinfo {
- u_int32_t id;
- u_int32_t comp_id;
- char *id_string;
+struct isapnp_attach_args {
+ struct device *ipa_isa; /* isa device */
+ bus_space_tag_t ipa_iot; /* isa i/o space tag */
+ bus_space_tag_t ipa_memt; /* isa mem space tag */
- int ldn;
- int io_range_check;
+ bus_space_handle_t ipa_delaybah;
- TAILQ_HEAD(, confinfo) q_conf;
- struct confinfo *conf;
- struct confinfo *basic;
+ isa_chipset_tag_t ipa_ic;
- TAILQ_ENTRY(devinfo) dev_link;
-};
+ struct isapnp_attach_args *ipa_sibling;
+ struct isapnp_attach_args *ipa_child;
+
+ char ipa_devident[ISAPNP_MAX_IDENT];
+ char ipa_devlogic[ISAPNP_MAX_DEVCLASS];
+ char ipa_devcompat[ISAPNP_MAX_DEVCLASS];
+ char ipa_devclass[ISAPNP_MAX_DEVCLASS];
-struct cardinfo {
- char serial[9];
- char pnp_version[2];
- int csn;
- char *id_string;
+ u_char ipa_pref;
+ u_char ipa_devnum;
- int num_ld;
+ u_char ipa_nio;
+ u_char ipa_nirq;
+ u_char ipa_ndrq;
+ u_char ipa_nmem;
+ u_char ipa_nmem32;
- TAILQ_HEAD(, devinfo) q_dev;
- struct devinfo *dev;
- TAILQ_ENTRY(cardinfo) card_link;
+ struct isapnp_region ipa_io[ISAPNP_NUM_IO];
+ struct isapnp_region ipa_mem[ISAPNP_NUM_MEM];
+ struct isapnp_region ipa_mem32[ISAPNP_NUM_MEM32];
+ struct isapnp_pin ipa_irq[ISAPNP_NUM_IRQ];
+ struct isapnp_pin ipa_drq[ISAPNP_NUM_DRQ];
};
-struct pnp_knowndev {
- char *pnpid;
- char *driver;
+struct isapnp_knowndev {
+ const char *pnpid;
+ const char *driver;
};
-#endif /* !_DEV_ISA_ISAPNPVAR_H_ */
+static __inline void isapnp_write_reg __P((struct isapnp_softc *, int, u_char));
+static __inline u_char isapnp_read_reg __P((struct isapnp_softc *, int));
+
+static __inline void
+isapnp_write_reg(sc, r, v)
+ struct isapnp_softc *sc;
+ int r;
+ u_char v;
+{
+ ISAPNP_WRITE_ADDR(sc, r);
+ ISAPNP_WRITE_DATA(sc, v);
+}
+
+static __inline u_char
+isapnp_read_reg(sc, r)
+ struct isapnp_softc *sc;
+{
+ ISAPNP_WRITE_ADDR(sc, r);
+ return ISAPNP_READ_DATA(sc);
+}
+
+struct isapnp_attach_args *
+ isapnp_get_resource __P((struct isapnp_softc *, int));
+char *isapnp_id_to_vendor __P((char *, const u_char *));
+
+int isapnp_config __P((bus_space_tag_t, bus_space_tag_t,
+ struct isapnp_attach_args *));
+void isapnp_unconfig __P((bus_space_tag_t, bus_space_tag_t,
+ struct isapnp_attach_args *));
+
+#ifdef DEBUG_ISAPNP
+void isapnp_print_mem __P((const char *, const struct isapnp_region *));
+void isapnp_print_io __P((const char *, const struct isapnp_region *));
+void isapnp_print_irq __P((const char *, const struct isapnp_pin *));
+void isapnp_print_drq __P((const char *, const struct isapnp_pin *));
+void isapnp_print_dep_start __P((const char *, const u_char));
+void isapnp_print_attach __P((const struct isapnp_attach_args *));
+void isapnp_get_config __P((struct isapnp_softc *,
+ struct isapnp_attach_args *));
+void isapnp_print_config __P((const struct isapnp_attach_args *));
+#endif
+
+#endif /* ! _DEV_ISAPNP_ISAPNPVAR_H_ */
diff --git a/sys/dev/isa/isavar.h b/sys/dev/isa/isavar.h
index 872c1394be9..b2e0a295f27 100644
--- a/sys/dev/isa/isavar.h
+++ b/sys/dev/isa/isavar.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: isavar.h,v 1.22 1997/10/13 14:46:45 pefo Exp $ */
+/* $OpenBSD: isavar.h,v 1.23 1997/12/21 14:41:27 downsj Exp $ */
/* $NetBSD: isavar.h,v 1.24 1996/10/21 22:41:11 thorpej Exp $ */
/*
@@ -102,25 +102,6 @@ struct isa_attach_args {
void *ia_aux; /* driver specific */
bus_space_handle_t ia_delaybah; /* i/o handle for `delay port' */
-
- /* XXX need fixes, some are duplicated */
- /* begin isapnp section */
- int id; /* logical device ID */
- int comp_id; /* compatible device ID */
- int csn; /* card selection number */
- int ldn; /* logical device number */
- struct {
- int num;
- int type;
- } irq[2];
- int drq[2];
- int port[8];
- struct {
- int base;
- int control;
- int range;
- } mem[4];
- /* end isapnp stuff */
};
#define IOBASEUNK -1 /* i/o address is unknown */
@@ -157,12 +138,6 @@ struct isa_softc {
* via isa_attach_args.
*/
bus_space_handle_t sc_delaybah;
-
- /*
- * This points to the isapnp_softc structure that holds
- * information of PnP devices on the ISA bus.
- */
- void *pnpsc;
};
#define cf_iobase cf_loc[0]
@@ -171,7 +146,6 @@ struct isa_softc {
#define cf_msize cf_loc[3]
#define cf_irq cf_loc[4]
#define cf_drq cf_loc[5]
-#define cf_pnpid cf_loc[6]
/*
* ISA interrupt handler manipulation.
diff --git a/sys/dev/isa/pnpdevs.h b/sys/dev/isa/pnpdevs.h
index e7c30636e82..36958c53af4 100644
--- a/sys/dev/isa/pnpdevs.h
+++ b/sys/dev/isa/pnpdevs.h
@@ -2,10 +2,14 @@
* THIS FILE AUTOMATICALLY GENERATED. DO NOT EDIT.
*
* generated from:
- * # OpenBSD: pnpdevs,v 1.2 1997/11/07 08:07:07 niklas Exp
+ * # OpenBSD: pnpdevs,v 1.3 1997/12/21 14:36:44 downsj Exp
*/
-struct pnp_knowndev pnp_knowndevs[] = {
+struct isapnp_knowndev isapnp_knowndevs[] = {
+ { "PNP0500", "com" },
+ { "PNP0500", "pccom" },
+ { "PNP0501", "com" },
+ { "PNP0501", "pccom" },
{ "PNP80d3", "ed" },
{ "PNP80d4", "ed" },
{ "PNP80d5", "ed" },
@@ -33,5 +37,13 @@ struct pnp_knowndev pnp_knowndevs[] = {
{ "PNP828C", "le" },
{ "PNP828D", "le" },
{ "WUMbeef", "le" },
+ { "PNPC000", "com" },
+ { "PNPC000", "pccom" },
+ { "PNPC001", "com" },
+ { "PNPC001", "pccom" },
+ { "MOT1170", "com" },
+ { "MOT1170", "pccom" },
+ { "NECE761", "com" },
+ { "NECE761", "pccom" },
{ NULL, NULL, }
};