Home | History | Annotate | Line # | Download | only in eisa
cac_eisa.c revision 1.8
      1 /*	$NetBSD: cac_eisa.c,v 1.8 2002/10/02 16:33:46 thorpej Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 2000 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Andrew Doran.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  * 3. All advertising materials mentioning features or use of this software
     19  *    must display the following acknowledgement:
     20  *        This product includes software developed by the NetBSD
     21  *        Foundation, Inc. and its contributors.
     22  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  *    contributors may be used to endorse or promote products derived
     24  *    from this software without specific prior written permission.
     25  *
     26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  * POSSIBILITY OF SUCH DAMAGE.
     37  */
     38 
     39 /*
     40  * Copyright (c) 2000 Jonathan Lemon
     41  * Copyright (c) 1999 by Matthew N. Dodd <winter (at) jurai.net>
     42  * All Rights Reserved.
     43  *
     44  * Redistribution and use in source and binary forms, with or without
     45  * modification, are permitted provided that the following conditions
     46  * are met:
     47  * 1. Redistributions of source code must retain the above copyright
     48  *    notice, this list of conditions, and the following disclaimer,
     49  *    without modification, immediately at the beginning of the file.
     50  * 2. The name of the author may not be used to endorse or promote products
     51  *    derived from this software without specific prior written permission.
     52  *
     53  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
     54  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     55  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     56  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
     57  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     58  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     59  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     60  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     61  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     62  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     63  * SUCH DAMAGE.
     64  */
     65 
     66 /*
     67  * EISA front-end for cac(4) driver.
     68  */
     69 
     70 #include <sys/cdefs.h>
     71 __KERNEL_RCSID(0, "$NetBSD: cac_eisa.c,v 1.8 2002/10/02 16:33:46 thorpej Exp $");
     72 
     73 #include <sys/param.h>
     74 #include <sys/systm.h>
     75 #include <sys/device.h>
     76 
     77 #include <machine/bus.h>
     78 #include <machine/intr.h>
     79 
     80 #include <dev/eisa/eisavar.h>
     81 #include <dev/eisa/eisadevs.h>
     82 
     83 #include <dev/ic/cacreg.h>
     84 #include <dev/ic/cacvar.h>
     85 
     86 #define CAC_EISA_SLOT_OFFSET		0x0c88
     87 #define CAC_EISA_IOSIZE			0x0017
     88 #define CAC_EISA_IOCONF			0x38
     89 
     90 void	cac_eisa_attach(struct device *, struct device *, void *);
     91 int	cac_eisa_match(struct device *, struct cfdata *, void *);
     92 
     93 struct	cac_ccb *cac_eisa_l0_completed(struct cac_softc *);
     94 int	cac_eisa_l0_fifo_full(struct cac_softc *);
     95 void	cac_eisa_l0_intr_enable(struct cac_softc *, int);
     96 int	cac_eisa_l0_intr_pending(struct cac_softc *);
     97 void	cac_eisa_l0_submit(struct cac_softc *, struct cac_ccb *);
     98 
     99 CFATTACH_DECL(cac_eisa, sizeof(struct cac_softc),
    100     cac_eisa_match, cac_eisa_attach, NULL, NULL);
    101 
    102 static const struct cac_linkage cac_eisa_l0 = {
    103 	cac_eisa_l0_completed,
    104 	cac_eisa_l0_fifo_full,
    105 	cac_eisa_l0_intr_enable,
    106 	cac_eisa_l0_intr_pending,
    107 	cac_eisa_l0_submit
    108 };
    109 
    110 struct cac_eisa_type {
    111 	const char	*ct_prodstr;
    112 	const char	*ct_typestr;
    113 	const struct	cac_linkage *ct_linkage;
    114 } static cac_eisa_type[] = {
    115 	{ "CPQ4001",	"IDA",		&cac_eisa_l0 },
    116 	{ "CPQ4002",	"IDA-2",	&cac_eisa_l0 },
    117 	{ "CPQ4010",	"IEAS",		&cac_eisa_l0 },
    118 	{ "CPQ4020",	"SMART",	&cac_eisa_l0 },
    119 	{ "CPQ4030",	"SMART-2/E",	&cac_l0 },
    120 };
    121 
    122 int
    123 cac_eisa_match(struct device *parent, struct cfdata *match, void *aux)
    124 {
    125 	struct eisa_attach_args *ea;
    126 	int i;
    127 
    128 	ea = aux;
    129 
    130 	for (i = 0; i < sizeof(cac_eisa_type) / sizeof(cac_eisa_type[0]); i++)
    131 		if (strcmp(ea->ea_idstring, cac_eisa_type[i].ct_prodstr) == 0)
    132 			return (1);
    133 
    134 	return (0);
    135 }
    136 
    137 void
    138 cac_eisa_attach(struct device *parent, struct device *self, void *aux)
    139 {
    140 	struct eisa_attach_args *ea;
    141 	bus_space_handle_t ioh;
    142 	eisa_chipset_tag_t ec;
    143 	eisa_intr_handle_t ih;
    144 	struct cac_softc *sc;
    145 	bus_space_tag_t iot;
    146 	const char *intrstr;
    147 	int irq, i;
    148 
    149 	ea = aux;
    150 	sc = (struct cac_softc *)self;
    151 	iot = ea->ea_iot;
    152 	ec = ea->ea_ec;
    153 
    154 	if (bus_space_map(iot, EISA_SLOT_ADDR(ea->ea_slot) +
    155 	    CAC_EISA_SLOT_OFFSET, CAC_EISA_IOSIZE, 0, &ioh)) {
    156 		printf("can't map i/o space\n");
    157 		return;
    158 	}
    159 
    160 	sc->sc_iot = iot;
    161 	sc->sc_ioh = ioh;
    162 	sc->sc_dmat = ea->ea_dmat;
    163 
    164 	/*
    165 	 * Map and establish the interrupt.
    166 	 */
    167 	switch (bus_space_read_1(iot, ioh, CAC_EISA_IOCONF) & 0xf0) {
    168 	case 0x20:
    169 		irq = 10;
    170 		break;
    171 	case 0x10:
    172 		irq = 11;
    173 		break;
    174 	case 0x40:
    175 		irq = 14;
    176 		break;
    177 	case 0x80:
    178 		irq = 15;
    179 		break;
    180 	default:
    181 		printf("controller on invalid IRQ\n");
    182 		return;
    183 	}
    184 
    185 	if (eisa_intr_map(ec, irq, &ih)) {
    186 		printf("can't map interrupt (%d)\n", irq);
    187 		return;
    188 	}
    189 
    190 	intrstr = eisa_intr_string(ec, ih);
    191 	if ((sc->sc_ih = eisa_intr_establish(ec, ih, IST_LEVEL, IPL_BIO,
    192 	    cac_intr, sc)) == NULL) {
    193 		printf("can't establish interrupt");
    194 		if (intrstr != NULL)
    195 			printf(" at %s", intrstr);
    196 		printf("\n");
    197 		return;
    198 	}
    199 
    200 	/*
    201 	 * Print board type and attach to the bus-independent code.
    202 	 */
    203 	for (i = 0; i < sizeof(cac_eisa_type) / sizeof(cac_eisa_type[0]); i++)
    204 		if (strcmp(ea->ea_idstring, cac_eisa_type[i].ct_prodstr) == 0)
    205 			break;
    206 
    207 	printf(": Compaq %s\n", cac_eisa_type[i].ct_typestr);
    208 	memcpy(&sc->sc_cl, cac_eisa_type[i].ct_linkage, sizeof(sc->sc_cl));
    209 	cac_init(sc, intrstr, 0);
    210 }
    211 
    212 /*
    213  * Linkage specific to EISA boards.
    214  */
    215 
    216 int
    217 cac_eisa_l0_fifo_full(struct cac_softc *sc)
    218 {
    219 
    220 	return ((cac_inb(sc, CAC_EISAREG_SYSTEM_DOORBELL) &
    221 	    CAC_EISA_CHANNEL_CLEAR) == 0);
    222 }
    223 
    224 void
    225 cac_eisa_l0_submit(struct cac_softc *sc, struct cac_ccb *ccb)
    226 {
    227 	u_int16_t size;
    228 
    229 	/*
    230 	 * On these boards, `ccb_hdr.size' is actually for control flags.
    231 	 * Set it to zero and pass the value by means of an I/O port.
    232 	 */
    233 	size = le16toh(ccb->ccb_hdr.size) << 2;
    234 	ccb->ccb_hdr.size = 0;
    235 
    236 	bus_dmamap_sync(sc->sc_dmat, sc->sc_dmamap, (caddr_t)ccb - sc->sc_ccbs,
    237 	    sizeof(struct cac_ccb), BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD);
    238 
    239 	cac_outb(sc, CAC_EISAREG_SYSTEM_DOORBELL, CAC_EISA_CHANNEL_CLEAR);
    240 	cac_outl(sc, CAC_EISAREG_LIST_ADDR, ccb->ccb_paddr);
    241 	cac_outw(sc, CAC_EISAREG_LIST_LEN, size);
    242 	cac_outb(sc, CAC_EISAREG_LOCAL_DOORBELL, CAC_EISA_CHANNEL_BUSY);
    243 }
    244 
    245 struct cac_ccb *
    246 cac_eisa_l0_completed(struct cac_softc *sc)
    247 {
    248 	struct cac_ccb *ccb;
    249 	u_int32_t off;
    250 	u_int8_t status;
    251 
    252 	if ((cac_inb(sc, CAC_EISAREG_SYSTEM_DOORBELL) &
    253 	    CAC_EISA_CHANNEL_BUSY) == 0)
    254 		return (NULL);
    255 
    256 	cac_outb(sc, CAC_EISAREG_SYSTEM_DOORBELL, CAC_EISA_CHANNEL_BUSY);
    257 	off = cac_inl(sc, CAC_EISAREG_COMPLETE_ADDR);
    258 	status = cac_inb(sc, CAC_EISAREG_LIST_STATUS);
    259 	cac_outb(sc, CAC_EISAREG_LOCAL_DOORBELL, CAC_EISA_CHANNEL_CLEAR);
    260 
    261 	if (off == 0)
    262 		return (NULL);
    263 
    264 	off = (off & ~3) - sc->sc_ccbs_paddr;
    265 	ccb = (struct cac_ccb *)(sc->sc_ccbs + off);
    266 
    267 	bus_dmamap_sync(sc->sc_dmat, sc->sc_dmamap, off, sizeof(struct cac_ccb),
    268 	    BUS_DMASYNC_POSTWRITE | BUS_DMASYNC_POSTREAD);
    269 
    270 	ccb->ccb_req.error = status;
    271 	return (ccb);
    272 }
    273 
    274 int
    275 cac_eisa_l0_intr_pending(struct cac_softc *sc)
    276 {
    277 
    278 	return (cac_inb(sc, CAC_EISAREG_SYSTEM_DOORBELL) &
    279 	    CAC_EISA_CHANNEL_BUSY);
    280 }
    281 
    282 void
    283 cac_eisa_l0_intr_enable(struct cac_softc *sc, int state)
    284 {
    285 
    286 	if (state) {
    287 		cac_outb(sc, CAC_EISAREG_SYSTEM_DOORBELL,
    288 		    ~CAC_EISA_CHANNEL_CLEAR);
    289 		cac_outb(sc, CAC_EISAREG_LOCAL_DOORBELL,
    290 		    CAC_EISA_CHANNEL_BUSY);
    291 		cac_outb(sc, CAC_EISAREG_INTR_MASK, CAC_INTR_ENABLE);
    292 		cac_outb(sc, CAC_EISAREG_SYSTEM_MASK, CAC_INTR_ENABLE);
    293 	} else
    294 		cac_outb(sc, CAC_EISAREG_SYSTEM_MASK, CAC_INTR_DISABLE);
    295 }
    296