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