Home | History | Annotate | Line # | Download | only in eisa
      1  1.26   thorpej /*	$NetBSD: cac_eisa.c,v 1.26 2021/01/27 04:35:15 thorpej 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  *
     19   1.1        ad  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20   1.1        ad  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21   1.1        ad  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22   1.1        ad  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23   1.1        ad  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24   1.1        ad  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25   1.1        ad  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26   1.1        ad  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27   1.1        ad  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28   1.1        ad  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29   1.1        ad  * POSSIBILITY OF SUCH DAMAGE.
     30   1.1        ad  */
     31   1.1        ad 
     32   1.1        ad /*
     33   1.1        ad  * Copyright (c) 2000 Jonathan Lemon
     34   1.1        ad  * Copyright (c) 1999 by Matthew N. Dodd <winter (at) jurai.net>
     35   1.1        ad  * All Rights Reserved.
     36   1.1        ad  *
     37   1.1        ad  * Redistribution and use in source and binary forms, with or without
     38   1.1        ad  * modification, are permitted provided that the following conditions
     39   1.1        ad  * are met:
     40   1.1        ad  * 1. Redistributions of source code must retain the above copyright
     41   1.1        ad  *    notice, this list of conditions, and the following disclaimer,
     42   1.1        ad  *    without modification, immediately at the beginning of the file.
     43   1.1        ad  * 2. The name of the author may not be used to endorse or promote products
     44   1.1        ad  *    derived from this software without specific prior written permission.
     45   1.1        ad  *
     46   1.1        ad  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
     47   1.1        ad  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     48   1.1        ad  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     49   1.1        ad  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
     50   1.1        ad  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     51   1.1        ad  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     52   1.1        ad  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     53   1.1        ad  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     54   1.1        ad  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     55   1.1        ad  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     56   1.1        ad  * SUCH DAMAGE.
     57   1.1        ad  */
     58   1.1        ad 
     59   1.1        ad /*
     60   1.1        ad  * EISA front-end for cac(4) driver.
     61   1.1        ad  */
     62   1.3     lukem 
     63   1.3     lukem #include <sys/cdefs.h>
     64  1.26   thorpej __KERNEL_RCSID(0, "$NetBSD: cac_eisa.c,v 1.26 2021/01/27 04:35:15 thorpej Exp $");
     65   1.1        ad 
     66   1.1        ad #include <sys/param.h>
     67   1.1        ad #include <sys/systm.h>
     68   1.1        ad #include <sys/device.h>
     69  1.25  pgoyette #include <sys/module.h>
     70  1.18        ad #include <sys/bus.h>
     71  1.18        ad #include <sys/intr.h>
     72   1.1        ad 
     73   1.1        ad #include <dev/eisa/eisavar.h>
     74   1.1        ad #include <dev/eisa/eisadevs.h>
     75   1.1        ad 
     76   1.1        ad #include <dev/ic/cacreg.h>
     77   1.1        ad #include <dev/ic/cacvar.h>
     78   1.1        ad 
     79  1.25  pgoyette #include "ioconf.h"
     80  1.25  pgoyette 
     81   1.1        ad #define CAC_EISA_SLOT_OFFSET		0x0c88
     82   1.1        ad #define CAC_EISA_IOSIZE			0x0017
     83   1.1        ad #define CAC_EISA_IOCONF			0x38
     84   1.1        ad 
     85  1.21    cegger static void	cac_eisa_attach(device_t, device_t, void *);
     86  1.21    cegger static int	cac_eisa_match(device_t, cfdata_t, void *);
     87   1.1        ad 
     88   1.9   thorpej static struct	cac_ccb *cac_eisa_l0_completed(struct cac_softc *);
     89   1.9   thorpej static int	cac_eisa_l0_fifo_full(struct cac_softc *);
     90   1.9   thorpej static void	cac_eisa_l0_intr_enable(struct cac_softc *, int);
     91   1.9   thorpej static int	cac_eisa_l0_intr_pending(struct cac_softc *);
     92   1.9   thorpej static void	cac_eisa_l0_submit(struct cac_softc *, struct cac_ccb *);
     93   1.1        ad 
     94  1.25  pgoyette CFATTACH_DECL3_NEW(cac_eisa, sizeof(struct cac_softc),
     95  1.25  pgoyette     cac_eisa_match, cac_eisa_attach, NULL, NULL, cac_rescan, NULL, 0);
     96   1.1        ad 
     97   1.5        ad static const struct cac_linkage cac_eisa_l0 = {
     98   1.1        ad 	cac_eisa_l0_completed,
     99   1.1        ad 	cac_eisa_l0_fifo_full,
    100   1.1        ad 	cac_eisa_l0_intr_enable,
    101   1.1        ad 	cac_eisa_l0_intr_pending,
    102   1.1        ad 	cac_eisa_l0_submit
    103   1.1        ad };
    104   1.1        ad 
    105  1.26   thorpej struct cac_eisa_type {
    106   1.1        ad 	const char	*ct_typestr;
    107   1.5        ad 	const struct	cac_linkage *ct_linkage;
    108  1.26   thorpej };
    109  1.26   thorpej 
    110  1.26   thorpej static const struct cac_eisa_type cpq4001 = {
    111  1.26   thorpej 	.ct_typestr = "IDA",
    112  1.26   thorpej 	.ct_linkage = &cac_eisa_l0
    113  1.26   thorpej };
    114  1.26   thorpej 
    115  1.26   thorpej static const struct cac_eisa_type cpq4002 = {
    116  1.26   thorpej 	.ct_typestr = "IDA-2",
    117  1.26   thorpej 	.ct_linkage = &cac_eisa_l0
    118  1.26   thorpej };
    119  1.26   thorpej 
    120  1.26   thorpej static const struct cac_eisa_type cpq4010 = {
    121  1.26   thorpej 	.ct_typestr = "IEAS",
    122  1.26   thorpej 	.ct_linkage = &cac_eisa_l0
    123  1.26   thorpej };
    124  1.26   thorpej 
    125  1.26   thorpej static const struct cac_eisa_type cpq4020 = {
    126  1.26   thorpej 	.ct_typestr = "SMART",
    127  1.26   thorpej 	.ct_linkage = &cac_eisa_l0
    128  1.26   thorpej };
    129  1.26   thorpej 
    130  1.26   thorpej static const struct cac_eisa_type cpq4030 = {
    131  1.26   thorpej 	.ct_typestr = "SMART-2/E",
    132  1.26   thorpej 	.ct_linkage = &cac_l0
    133  1.26   thorpej };
    134  1.26   thorpej 
    135  1.26   thorpej static const struct device_compatible_entry compat_data[] = {
    136  1.26   thorpej 	{ .compat = "CPQ4001",	.data = &cpq4001 },
    137  1.26   thorpej 	{ .compat = "CPQ4002",	.data = &cpq4002 },
    138  1.26   thorpej 	{ .compat = "CPQ4010",	.data = &cpq4010 },
    139  1.26   thorpej 	{ .compat = "CPQ4020",	.data = &cpq4020 },
    140  1.26   thorpej 	{ .compat = "CPQ4030",	.data = &cpq4030 },
    141  1.26   thorpej 	DEVICE_COMPAT_EOL
    142   1.1        ad };
    143   1.1        ad 
    144   1.9   thorpej static int
    145  1.24   msaitoh cac_eisa_match(device_t parent, cfdata_t match, void *aux)
    146   1.1        ad {
    147  1.26   thorpej 	struct eisa_attach_args *ea = aux;
    148   1.1        ad 
    149  1.26   thorpej 	return (eisa_compatible_match(ea, compat_data));
    150   1.1        ad }
    151   1.1        ad 
    152   1.9   thorpej static void
    153  1.21    cegger cac_eisa_attach(device_t parent, device_t self, void *aux)
    154   1.1        ad {
    155  1.26   thorpej 	struct eisa_attach_args *ea = aux;
    156  1.26   thorpej 	const struct device_compatible_entry *dce;
    157  1.26   thorpej 	const struct cac_eisa_type *ct;
    158   1.1        ad 	bus_space_handle_t ioh;
    159   1.1        ad 	eisa_chipset_tag_t ec;
    160   1.1        ad 	eisa_intr_handle_t ih;
    161   1.1        ad 	struct cac_softc *sc;
    162   1.1        ad 	bus_space_tag_t iot;
    163   1.1        ad 	const char *intrstr;
    164  1.26   thorpej 	int irq;
    165  1.23  christos 	char intrbuf[EISA_INTRSTR_LEN];
    166  1.10     perry 
    167  1.12   thorpej 	sc = device_private(self);
    168   1.1        ad 	iot = ea->ea_iot;
    169   1.1        ad 	ec = ea->ea_ec;
    170  1.10     perry 
    171   1.1        ad 	if (bus_space_map(iot, EISA_SLOT_ADDR(ea->ea_slot) +
    172   1.1        ad 	    CAC_EISA_SLOT_OFFSET, CAC_EISA_IOSIZE, 0, &ioh)) {
    173  1.24   msaitoh 		aprint_error(": can't map i/o space\n");
    174   1.1        ad 		return;
    175   1.1        ad 	}
    176   1.1        ad 
    177  1.26   thorpej 	dce = eisa_compatible_lookup(ea, compat_data);
    178  1.26   thorpej 	KASSERT(dce != NULL);
    179  1.26   thorpej 	ct = dce->data;
    180  1.26   thorpej 
    181  1.22       chs 	sc->sc_dev = self;
    182   1.1        ad 	sc->sc_iot = iot;
    183   1.1        ad 	sc->sc_ioh = ioh;
    184   1.1        ad 	sc->sc_dmat = ea->ea_dmat;
    185   1.1        ad 
    186  1.10     perry 	/*
    187   1.1        ad 	 * Map and establish the interrupt.
    188   1.1        ad 	 */
    189   1.1        ad 	switch (bus_space_read_1(iot, ioh, CAC_EISA_IOCONF) & 0xf0) {
    190   1.1        ad 	case 0x20:
    191   1.1        ad 		irq = 10;
    192   1.1        ad 		break;
    193   1.1        ad 	case 0x10:
    194   1.1        ad 		irq = 11;
    195   1.1        ad 		break;
    196   1.1        ad 	case 0x40:
    197   1.1        ad 		irq = 14;
    198   1.1        ad 		break;
    199   1.1        ad 	case 0x80:
    200   1.1        ad 		irq = 15;
    201   1.1        ad 		break;
    202   1.1        ad 	default:
    203  1.24   msaitoh 		aprint_error(": controller on invalid IRQ\n");
    204   1.1        ad 		return;
    205   1.1        ad 	}
    206   1.1        ad 
    207   1.1        ad 	if (eisa_intr_map(ec, irq, &ih)) {
    208  1.24   msaitoh 		aprint_error(": can't map interrupt (%d)\n", irq);
    209   1.1        ad 		return;
    210   1.1        ad 	}
    211  1.10     perry 
    212  1.23  christos 	intrstr = eisa_intr_string(ec, ih, intrbuf, sizeof(intrbuf));
    213   1.1        ad 	if ((sc->sc_ih = eisa_intr_establish(ec, ih, IST_LEVEL, IPL_BIO,
    214   1.1        ad 	    cac_intr, sc)) == NULL) {
    215  1.24   msaitoh 		aprint_error(": can't establish interrupt");
    216   1.1        ad 		if (intrstr != NULL)
    217  1.24   msaitoh 			aprint_normal(" at %s", intrstr);
    218  1.24   msaitoh 		aprint_normal("\n");
    219   1.1        ad 		return;
    220   1.1        ad 	}
    221   1.1        ad 
    222   1.1        ad 	/*
    223   1.1        ad 	 * Print board type and attach to the bus-independent code.
    224   1.1        ad 	 */
    225  1.26   thorpej 	aprint_normal(": Compaq %s\n", ct->ct_typestr);
    226  1.26   thorpej 	memcpy(&sc->sc_cl, ct->ct_linkage, sizeof(sc->sc_cl));
    227   1.1        ad 	cac_init(sc, intrstr, 0);
    228   1.1        ad }
    229   1.1        ad 
    230   1.1        ad /*
    231   1.1        ad  * Linkage specific to EISA boards.
    232   1.1        ad  */
    233   1.1        ad 
    234   1.9   thorpej static int
    235   1.1        ad cac_eisa_l0_fifo_full(struct cac_softc *sc)
    236   1.1        ad {
    237   1.1        ad 
    238   1.1        ad 	return ((cac_inb(sc, CAC_EISAREG_SYSTEM_DOORBELL) &
    239   1.1        ad 	    CAC_EISA_CHANNEL_CLEAR) == 0);
    240   1.1        ad }
    241   1.1        ad 
    242   1.9   thorpej static void
    243   1.1        ad cac_eisa_l0_submit(struct cac_softc *sc, struct cac_ccb *ccb)
    244   1.1        ad {
    245   1.1        ad 	u_int16_t size;
    246   1.1        ad 
    247   1.1        ad 	/*
    248   1.1        ad 	 * On these boards, `ccb_hdr.size' is actually for control flags.
    249   1.1        ad 	 * Set it to zero and pass the value by means of an I/O port.
    250   1.1        ad 	 */
    251   1.1        ad 	size = le16toh(ccb->ccb_hdr.size) << 2;
    252   1.1        ad 	ccb->ccb_hdr.size = 0;
    253   1.1        ad 
    254  1.17  christos 	bus_dmamap_sync(sc->sc_dmat, sc->sc_dmamap,
    255  1.17  christos 	    (char *)ccb - (char *)sc->sc_ccbs,
    256   1.1        ad 	    sizeof(struct cac_ccb), BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD);
    257   1.1        ad 
    258   1.1        ad 	cac_outb(sc, CAC_EISAREG_SYSTEM_DOORBELL, CAC_EISA_CHANNEL_CLEAR);
    259   1.1        ad 	cac_outl(sc, CAC_EISAREG_LIST_ADDR, ccb->ccb_paddr);
    260   1.1        ad 	cac_outw(sc, CAC_EISAREG_LIST_LEN, size);
    261   1.1        ad 	cac_outb(sc, CAC_EISAREG_LOCAL_DOORBELL, CAC_EISA_CHANNEL_BUSY);
    262   1.1        ad }
    263   1.1        ad 
    264   1.9   thorpej static struct cac_ccb *
    265   1.1        ad cac_eisa_l0_completed(struct cac_softc *sc)
    266   1.1        ad {
    267   1.1        ad 	struct cac_ccb *ccb;
    268   1.1        ad 	u_int32_t off;
    269   1.1        ad 	u_int8_t status;
    270   1.1        ad 
    271   1.1        ad 	if ((cac_inb(sc, CAC_EISAREG_SYSTEM_DOORBELL) &
    272   1.1        ad 	    CAC_EISA_CHANNEL_BUSY) == 0)
    273   1.1        ad 		return (NULL);
    274   1.1        ad 
    275   1.1        ad 	cac_outb(sc, CAC_EISAREG_SYSTEM_DOORBELL, CAC_EISA_CHANNEL_BUSY);
    276   1.1        ad 	off = cac_inl(sc, CAC_EISAREG_COMPLETE_ADDR);
    277   1.1        ad 	status = cac_inb(sc, CAC_EISAREG_LIST_STATUS);
    278   1.1        ad 	cac_outb(sc, CAC_EISAREG_LOCAL_DOORBELL, CAC_EISA_CHANNEL_CLEAR);
    279   1.1        ad 
    280   1.1        ad 	if (off == 0)
    281   1.1        ad 		return (NULL);
    282   1.1        ad 
    283   1.1        ad 	off = (off & ~3) - sc->sc_ccbs_paddr;
    284  1.17  christos 	ccb = (struct cac_ccb *)((char *)sc->sc_ccbs + off);
    285   1.1        ad 
    286   1.1        ad 	bus_dmamap_sync(sc->sc_dmat, sc->sc_dmamap, off, sizeof(struct cac_ccb),
    287   1.1        ad 	    BUS_DMASYNC_POSTWRITE | BUS_DMASYNC_POSTREAD);
    288   1.1        ad 
    289   1.1        ad 	ccb->ccb_req.error = status;
    290  1.16        ad 
    291  1.16        ad 	if ((off & 3) != 0 && ccb->ccb_req.error == 0)
    292  1.16        ad 		ccb->ccb_req.error = CAC_RET_CMD_REJECTED;
    293  1.16        ad 
    294   1.1        ad 	return (ccb);
    295   1.1        ad }
    296   1.1        ad 
    297   1.9   thorpej static int
    298   1.1        ad cac_eisa_l0_intr_pending(struct cac_softc *sc)
    299   1.1        ad {
    300   1.1        ad 
    301   1.1        ad 	return (cac_inb(sc, CAC_EISAREG_SYSTEM_DOORBELL) &
    302   1.1        ad 	    CAC_EISA_CHANNEL_BUSY);
    303   1.1        ad }
    304   1.1        ad 
    305   1.9   thorpej static void
    306   1.1        ad cac_eisa_l0_intr_enable(struct cac_softc *sc, int state)
    307   1.1        ad {
    308   1.1        ad 
    309   1.1        ad 	if (state) {
    310   1.1        ad 		cac_outb(sc, CAC_EISAREG_SYSTEM_DOORBELL,
    311   1.1        ad 		    ~CAC_EISA_CHANNEL_CLEAR);
    312   1.1        ad 		cac_outb(sc, CAC_EISAREG_LOCAL_DOORBELL,
    313   1.1        ad 		    CAC_EISA_CHANNEL_BUSY);
    314   1.1        ad 		cac_outb(sc, CAC_EISAREG_INTR_MASK, CAC_INTR_ENABLE);
    315   1.1        ad 		cac_outb(sc, CAC_EISAREG_SYSTEM_MASK, CAC_INTR_ENABLE);
    316   1.1        ad 	} else
    317   1.1        ad 		cac_outb(sc, CAC_EISAREG_SYSTEM_MASK, CAC_INTR_DISABLE);
    318   1.1        ad }
    319  1.25  pgoyette 
    320  1.25  pgoyette MODULE(MODULE_CLASS_DRIVER, cac_eisa, "cac");	/* No eisa module yet! */
    321  1.25  pgoyette 
    322  1.25  pgoyette #ifdef _MODULE
    323  1.25  pgoyette /*
    324  1.25  pgoyette  * XXX Don't allow ioconf.c to redefine the "struct cfdriver cac_cd"
    325  1.25  pgoyette  * XXX it will be defined in the common-code module
    326  1.25  pgoyette  */
    327  1.25  pgoyette #undef  CFDRIVER_DECL
    328  1.25  pgoyette #define CFDRIVER_DECL(name, class, attr)
    329  1.25  pgoyette #include "ioconf.c"
    330  1.25  pgoyette #endif
    331  1.25  pgoyette 
    332  1.25  pgoyette static int
    333  1.25  pgoyette cac_eisa_modcmd(modcmd_t cmd, void *opaque)
    334  1.25  pgoyette {
    335  1.25  pgoyette 	int error = 0;
    336  1.25  pgoyette 
    337  1.25  pgoyette #ifdef _MODULE
    338  1.25  pgoyette 	switch (cmd) {
    339  1.25  pgoyette 	case MODULE_CMD_INIT:
    340  1.25  pgoyette 		/*
    341  1.25  pgoyette 		 * We skip over the first entry in cfdriver[] array
    342  1.25  pgoyette 		 * since the cfdriver is attached by the common
    343  1.25  pgoyette 		 * (non-attachment-specific) code.
    344  1.25  pgoyette 		 */
    345  1.25  pgoyette 		error = config_init_component(&cfdriver_ioconf_cac_eisa[1],
    346  1.25  pgoyette 		    cfattach_ioconf_cac_eisa, cfdata_ioconf_cac_eisa);
    347  1.25  pgoyette 		break;
    348  1.25  pgoyette 	case MODULE_CMD_FINI:
    349  1.25  pgoyette 		error = config_fini_component(&cfdriver_ioconf_cac_eisa[1],
    350  1.25  pgoyette 		    cfattach_ioconf_cac_eisa, cfdata_ioconf_cac_eisa);
    351  1.25  pgoyette 		break;
    352  1.25  pgoyette 	default:
    353  1.25  pgoyette 		error = ENOTTY;
    354  1.25  pgoyette 		break;
    355  1.25  pgoyette 	}
    356  1.25  pgoyette #endif
    357  1.25  pgoyette 
    358  1.25  pgoyette 	return error;
    359  1.25  pgoyette }
    360