Home | History | Annotate | Line # | Download | only in tc
ioasic.c revision 1.42.4.1
      1  1.42.4.1     rmind /* $NetBSD: ioasic.c,v 1.42.4.1 2011/06/12 00:23:52 rmind Exp $ */
      2      1.17   thorpej 
      3      1.17   thorpej /*-
      4      1.17   thorpej  * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
      5      1.17   thorpej  * All rights reserved.
      6      1.17   thorpej  *
      7      1.17   thorpej  * This code is derived from software contributed to The NetBSD Foundation
      8      1.17   thorpej  * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
      9      1.17   thorpej  * NASA Ames Research Center.
     10      1.17   thorpej  *
     11      1.17   thorpej  * Redistribution and use in source and binary forms, with or without
     12      1.17   thorpej  * modification, are permitted provided that the following conditions
     13      1.17   thorpej  * are met:
     14      1.17   thorpej  * 1. Redistributions of source code must retain the above copyright
     15      1.17   thorpej  *    notice, this list of conditions and the following disclaimer.
     16      1.17   thorpej  * 2. Redistributions in binary form must reproduce the above copyright
     17      1.17   thorpej  *    notice, this list of conditions and the following disclaimer in the
     18      1.17   thorpej  *    documentation and/or other materials provided with the distribution.
     19      1.17   thorpej  *
     20      1.17   thorpej  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     21      1.17   thorpej  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     22      1.17   thorpej  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     23      1.17   thorpej  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     24      1.17   thorpej  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     25      1.17   thorpej  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     26      1.17   thorpej  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     27      1.17   thorpej  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     28      1.17   thorpej  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     29      1.17   thorpej  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     30      1.17   thorpej  * POSSIBILITY OF SUCH DAMAGE.
     31      1.17   thorpej  */
     32       1.1       cgd 
     33       1.1       cgd /*
     34       1.4       cgd  * Copyright (c) 1994, 1995, 1996 Carnegie-Mellon University.
     35       1.1       cgd  * All rights reserved.
     36       1.1       cgd  *
     37       1.1       cgd  * Author: Keith Bostic, Chris G. Demetriou
     38       1.1       cgd  *
     39       1.1       cgd  * Permission to use, copy, modify and distribute this software and
     40       1.1       cgd  * its documentation is hereby granted, provided that both the copyright
     41       1.1       cgd  * notice and this permission notice appear in all copies of the
     42       1.1       cgd  * software, derivative works or modified versions, and any portions
     43       1.1       cgd  * thereof, and that both notices appear in supporting documentation.
     44       1.1       cgd  *
     45       1.1       cgd  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
     46       1.1       cgd  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
     47       1.1       cgd  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
     48       1.1       cgd  *
     49       1.1       cgd  * Carnegie Mellon requests users of this software to return to
     50       1.1       cgd  *
     51       1.1       cgd  *  Software Distribution Coordinator  or  Software.Distribution (at) CS.CMU.EDU
     52       1.1       cgd  *  School of Computer Science
     53       1.1       cgd  *  Carnegie Mellon University
     54       1.1       cgd  *  Pittsburgh PA 15213-3890
     55       1.1       cgd  *
     56       1.1       cgd  * any improvements or extensions that they make and grant Carnegie the
     57       1.1       cgd  * rights to redistribute these changes.
     58       1.1       cgd  */
     59      1.12       cgd 
     60      1.15   thorpej #include "opt_dec_3000_300.h"
     61      1.15   thorpej 
     62      1.13       cgd #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
     63      1.13       cgd 
     64  1.42.4.1     rmind __KERNEL_RCSID(0, "$NetBSD: ioasic.c,v 1.42.4.1 2011/06/12 00:23:52 rmind Exp $");
     65       1.1       cgd 
     66       1.1       cgd #include <sys/param.h>
     67       1.1       cgd #include <sys/kernel.h>
     68       1.1       cgd #include <sys/systm.h>
     69       1.1       cgd #include <sys/device.h>
     70      1.32   thorpej #include <sys/malloc.h>
     71       1.1       cgd 
     72       1.1       cgd #include <machine/autoconf.h>
     73      1.17   thorpej #include <machine/bus.h>
     74       1.1       cgd #include <machine/pte.h>
     75       1.1       cgd #include <machine/rpb.h>
     76       1.1       cgd 
     77       1.1       cgd #include <dev/tc/tcvar.h>
     78      1.28  nisimura #include <dev/tc/ioasicreg.h>
     79       1.1       cgd #include <dev/tc/ioasicvar.h>
     80       1.1       cgd 
     81       1.1       cgd /* Definition of the driver for autoconfig. */
     82  1.42.4.1     rmind int	ioasicmatch(device_t, cfdata_t, void *);
     83  1.42.4.1     rmind void	ioasicattach(device_t, device_t, void *);
     84       1.2   thorpej 
     85  1.42.4.1     rmind CFATTACH_DECL_NEW(ioasic, sizeof(struct ioasic_softc),
     86      1.37   thorpej     ioasicmatch, ioasicattach, NULL, NULL);
     87       1.1       cgd 
     88      1.40       dsl int	ioasic_intr(void *);
     89      1.40       dsl int	ioasic_intrnull(void *);
     90       1.1       cgd 
     91       1.1       cgd #define	C(x)	((void *)(x))
     92       1.1       cgd 
     93       1.1       cgd #define	IOASIC_DEV_LANCE	0
     94       1.1       cgd #define	IOASIC_DEV_SCC0		1
     95       1.1       cgd #define	IOASIC_DEV_SCC1		2
     96       1.1       cgd #define	IOASIC_DEV_ISDN		3
     97       1.1       cgd 
     98       1.1       cgd #define	IOASIC_DEV_BOGUS	-1
     99       1.1       cgd 
    100       1.1       cgd #define	IOASIC_NCOOKIES		4
    101       1.1       cgd 
    102      1.21  jonathan struct ioasic_dev ioasic_devs[] = {
    103      1.33  nisimura 	{ "PMAD-BA ", IOASIC_SLOT_3_START, C(IOASIC_DEV_LANCE),
    104      1.19   thorpej 	  IOASIC_INTR_LANCE, },
    105      1.19   thorpej 	{ "z8530   ", IOASIC_SLOT_4_START, C(IOASIC_DEV_SCC0),
    106      1.19   thorpej 	  IOASIC_INTR_SCC_0, },
    107      1.19   thorpej 	{ "z8530   ", IOASIC_SLOT_6_START, C(IOASIC_DEV_SCC1),
    108      1.19   thorpej 	  IOASIC_INTR_SCC_1, },
    109      1.19   thorpej 	{ "TOY_RTC ", IOASIC_SLOT_8_START, C(IOASIC_DEV_BOGUS),
    110      1.19   thorpej 	  0, },
    111      1.19   thorpej 	{ "AMD79c30", IOASIC_SLOT_9_START, C(IOASIC_DEV_ISDN),
    112      1.30  gmcgarry 	  IOASIC_INTR_ISDN_TXLOAD | IOASIC_INTR_ISDN_RXLOAD,  },
    113       1.1       cgd };
    114       1.1       cgd int ioasic_ndevs = sizeof(ioasic_devs) / sizeof(ioasic_devs[0]);
    115       1.1       cgd 
    116       1.1       cgd struct ioasicintr {
    117      1.40       dsl 	int	(*iai_func)(void *);
    118       1.1       cgd 	void	*iai_arg;
    119      1.32   thorpej 	struct evcnt iai_evcnt;
    120       1.1       cgd } ioasicintrs[IOASIC_NCOOKIES];
    121       1.1       cgd 
    122       1.1       cgd tc_addr_t ioasic_base;		/* XXX XXX XXX */
    123       1.1       cgd 
    124       1.1       cgd /* There can be only one. */
    125       1.1       cgd int ioasicfound;
    126       1.1       cgd 
    127       1.1       cgd int
    128  1.42.4.1     rmind ioasicmatch(device_t parent, cfdata_t cf, void *aux)
    129       1.1       cgd {
    130       1.3       cgd 	struct tc_attach_args *ta = aux;
    131       1.1       cgd 
    132       1.1       cgd 	/* Make sure that we're looking for this type of device. */
    133       1.3       cgd 	if (strncmp("FLAMG-IO", ta->ta_modname, TC_ROM_LLEN))
    134       1.1       cgd 		return (0);
    135       1.1       cgd 
    136       1.1       cgd 	/* Check that it can actually exist. */
    137       1.1       cgd 	if ((cputype != ST_DEC_3000_500) && (cputype != ST_DEC_3000_300))
    138       1.1       cgd 		panic("ioasicmatch: how did we get here?");
    139       1.1       cgd 
    140       1.1       cgd 	if (ioasicfound)
    141       1.1       cgd 		return (0);
    142       1.1       cgd 
    143       1.1       cgd 	return (1);
    144       1.1       cgd }
    145       1.1       cgd 
    146       1.1       cgd void
    147  1.42.4.1     rmind ioasicattach(device_t parent, device_t self, void *aux)
    148       1.1       cgd {
    149  1.42.4.1     rmind 	struct ioasic_softc *sc = device_private(self);
    150       1.3       cgd 	struct tc_attach_args *ta = aux;
    151      1.27       mrg #ifdef DEC_3000_300
    152      1.27       mrg 	u_long ssr;
    153      1.27       mrg #endif
    154      1.27       mrg 	u_long i, imsk;
    155      1.32   thorpej 	const struct evcnt *pevcnt;
    156      1.32   thorpej 	char *cp;
    157       1.1       cgd 
    158       1.1       cgd 	ioasicfound = 1;
    159       1.1       cgd 
    160  1.42.4.1     rmind 	sc->sc_dev = self;
    161      1.25  nisimura 	sc->sc_bst = ta->ta_memt;
    162      1.25  nisimura 	if (bus_space_map(ta->ta_memt, ta->ta_addr,
    163      1.25  nisimura 			0x400000, 0, &sc->sc_bsh)) {
    164  1.42.4.1     rmind 		printf("%s: unable to map device\n", device_xname(self));
    165      1.25  nisimura 		return;
    166      1.25  nisimura 	}
    167      1.25  nisimura 	sc->sc_dmat = ta->ta_dmat;
    168      1.25  nisimura 
    169      1.25  nisimura 	ioasic_base = sc->sc_base = ta->ta_addr; /* XXX XXX XXX */
    170       1.1       cgd 
    171       1.1       cgd #ifdef DEC_3000_300
    172       1.1       cgd 	if (cputype == ST_DEC_3000_300) {
    173      1.25  nisimura 		ssr = bus_space_read_4(sc->sc_bst, sc->sc_bsh, IOASIC_CSR);
    174      1.25  nisimura 		ssr |= IOASIC_CSR_FASTMODE;
    175      1.25  nisimura 		bus_space_write_4(sc->sc_bst, sc->sc_bsh, IOASIC_CSR, ssr);
    176       1.9  christos 		printf(": slow mode\n");
    177       1.1       cgd 	} else
    178       1.1       cgd #endif
    179       1.9  christos 		printf(": fast mode\n");
    180       1.1       cgd 
    181       1.1       cgd 	/*
    182       1.1       cgd 	 * Turn off all device interrupt bits.
    183       1.1       cgd 	 * (This does _not_ include 3000/300 TC option slot bits.
    184       1.1       cgd 	 */
    185      1.25  nisimura 	imsk = bus_space_read_4(sc->sc_bst, sc->sc_bsh, IOASIC_IMSK);
    186       1.1       cgd 	for (i = 0; i < ioasic_ndevs; i++)
    187      1.25  nisimura 		imsk &= ~ioasic_devs[i].iad_intrbits;
    188      1.25  nisimura 	bus_space_write_4(sc->sc_bst, sc->sc_bsh, IOASIC_IMSK, imsk);
    189       1.1       cgd 
    190       1.1       cgd 	/*
    191       1.1       cgd 	 * Set up interrupt handlers.
    192       1.1       cgd 	 */
    193      1.32   thorpej 	pevcnt = tc_intr_evcnt(parent, ta->ta_cookie);
    194       1.1       cgd 	for (i = 0; i < IOASIC_NCOOKIES; i++) {
    195       1.1       cgd 		ioasicintrs[i].iai_func = ioasic_intrnull;
    196       1.1       cgd 		ioasicintrs[i].iai_arg = (void *)i;
    197      1.32   thorpej 
    198      1.32   thorpej 		cp = malloc(12, M_DEVBUF, M_NOWAIT);
    199      1.32   thorpej 		if (cp == NULL)
    200      1.32   thorpej 			panic("ioasicattach");
    201      1.32   thorpej 		sprintf(cp, "slot %lu", i);
    202      1.32   thorpej 		evcnt_attach_dynamic(&ioasicintrs[i].iai_evcnt,
    203  1.42.4.1     rmind 		    EVCNT_TYPE_INTR, pevcnt, device_xname(self), cp);
    204       1.1       cgd 	}
    205      1.29  nisimura 	tc_intr_establish(parent, ta->ta_cookie, TC_IPL_NONE, ioasic_intr, sc);
    206       1.1       cgd 
    207      1.26  nisimura 	/*
    208       1.1       cgd 	 * Try to configure each device.
    209       1.1       cgd 	 */
    210      1.26  nisimura 	ioasic_attach_devs(sc, ioasic_devs, ioasic_ndevs);
    211       1.1       cgd }
    212       1.1       cgd 
    213       1.1       cgd void
    214      1.39    cegger ioasic_intr_establish(device_t ioa, void *cookie, tc_intrlevel_t level,
    215      1.39    cegger 		int (*func)(void *), void *arg)
    216       1.1       cgd {
    217      1.39    cegger 	struct ioasic_softc *sc = device_lookup_private(&ioasic_cd,0);
    218      1.25  nisimura 	u_long dev, i, imsk;
    219       1.1       cgd 
    220       1.1       cgd 	dev = (u_long)cookie;
    221       1.1       cgd #ifdef DIAGNOSTIC
    222       1.1       cgd 	/* XXX check cookie. */
    223       1.1       cgd #endif
    224       1.1       cgd 
    225       1.1       cgd 	if (ioasicintrs[dev].iai_func != ioasic_intrnull)
    226      1.20   thorpej 		panic("ioasic_intr_establish: cookie %lu twice", dev);
    227       1.1       cgd 
    228       1.1       cgd 	ioasicintrs[dev].iai_func = func;
    229       1.1       cgd 	ioasicintrs[dev].iai_arg = arg;
    230       1.1       cgd 
    231       1.1       cgd 	/* Enable interrupts for the device. */
    232       1.1       cgd 	for (i = 0; i < ioasic_ndevs; i++)
    233       1.1       cgd 		if (ioasic_devs[i].iad_cookie == cookie)
    234       1.1       cgd 			break;
    235       1.1       cgd 	if (i == ioasic_ndevs)
    236       1.1       cgd 		panic("ioasic_intr_establish: invalid cookie.");
    237      1.25  nisimura 
    238      1.25  nisimura 	imsk = bus_space_read_4(sc->sc_bst, sc->sc_bsh, IOASIC_IMSK);
    239      1.25  nisimura         imsk |= ioasic_devs[i].iad_intrbits;
    240      1.25  nisimura         bus_space_write_4(sc->sc_bst, sc->sc_bsh, IOASIC_IMSK, imsk);
    241       1.1       cgd }
    242       1.1       cgd 
    243       1.1       cgd void
    244      1.39    cegger ioasic_intr_disestablish(device_t ioa, void *cookie)
    245       1.1       cgd {
    246      1.39    cegger 	struct ioasic_softc *sc = device_lookup_private(&ioasic_cd,0);
    247      1.25  nisimura 	u_long dev, i, imsk;
    248       1.1       cgd 
    249       1.1       cgd 	dev = (u_long)cookie;
    250       1.1       cgd #ifdef DIAGNOSTIC
    251       1.1       cgd 	/* XXX check cookie. */
    252       1.1       cgd #endif
    253       1.1       cgd 
    254       1.1       cgd 	if (ioasicintrs[dev].iai_func == ioasic_intrnull)
    255      1.20   thorpej 		panic("ioasic_intr_disestablish: cookie %lu missing intr", dev);
    256       1.1       cgd 
    257       1.1       cgd 	/* Enable interrupts for the device. */
    258       1.1       cgd 	for (i = 0; i < ioasic_ndevs; i++)
    259       1.1       cgd 		if (ioasic_devs[i].iad_cookie == cookie)
    260       1.1       cgd 			break;
    261       1.1       cgd 	if (i == ioasic_ndevs)
    262       1.1       cgd 		panic("ioasic_intr_disestablish: invalid cookie.");
    263      1.25  nisimura 
    264      1.25  nisimura 	imsk = bus_space_read_4(sc->sc_bst, sc->sc_bsh, IOASIC_IMSK);
    265      1.25  nisimura 	imsk &= ~ioasic_devs[i].iad_intrbits;
    266      1.25  nisimura 	bus_space_write_4(sc->sc_bst, sc->sc_bsh, IOASIC_IMSK, imsk);
    267       1.1       cgd 
    268       1.1       cgd 	ioasicintrs[dev].iai_func = ioasic_intrnull;
    269       1.1       cgd 	ioasicintrs[dev].iai_arg = (void *)dev;
    270       1.1       cgd }
    271       1.1       cgd 
    272       1.1       cgd int
    273      1.41       dsl ioasic_intrnull(void *val)
    274       1.1       cgd {
    275       1.1       cgd 
    276      1.35    provos 	panic("ioasic_intrnull: uncaught IOASIC intr for cookie %ld",
    277       1.1       cgd 	    (u_long)val);
    278       1.1       cgd }
    279       1.1       cgd 
    280       1.1       cgd /*
    281      1.26  nisimura  * ASIC interrupt handler.
    282       1.1       cgd  */
    283       1.1       cgd int
    284      1.41       dsl ioasic_intr(void *val)
    285       1.1       cgd {
    286       1.1       cgd 	register struct ioasic_softc *sc = val;
    287       1.6       cgd 	register int ifound;
    288       1.1       cgd 	int gifound;
    289      1.34   thorpej 	u_int32_t sir, osir;
    290       1.1       cgd 
    291       1.1       cgd 	gifound = 0;
    292       1.1       cgd 	do {
    293       1.1       cgd 		ifound = 0;
    294       1.1       cgd 		tc_syncbus();
    295       1.1       cgd 
    296      1.34   thorpej 		osir = sir =
    297      1.34   thorpej 		    bus_space_read_4(sc->sc_bst, sc->sc_bsh, IOASIC_INTR);
    298       1.1       cgd 
    299      1.32   thorpej #define	INCRINTRCNT(slot)	ioasicintrs[slot].iai_evcnt.ev_count++
    300       1.5       cgd 
    301       1.1       cgd 		/* XXX DUPLICATION OF INTERRUPT BIT INFORMATION... */
    302      1.34   thorpej #define	CHECKINTR(slot, bits, clear)					\
    303      1.31      matt 		if (sir & (bits)) {					\
    304       1.1       cgd 			ifound = 1;					\
    305       1.5       cgd 			INCRINTRCNT(slot);				\
    306       1.1       cgd 			(*ioasicintrs[slot].iai_func)			\
    307       1.1       cgd 			    (ioasicintrs[slot].iai_arg);		\
    308      1.34   thorpej 			if (clear)					\
    309      1.34   thorpej 				sir &= ~(bits);				\
    310       1.1       cgd 		}
    311      1.34   thorpej 		CHECKINTR(IOASIC_DEV_SCC0, IOASIC_INTR_SCC_0, 0);
    312      1.34   thorpej 		CHECKINTR(IOASIC_DEV_SCC1, IOASIC_INTR_SCC_1, 0);
    313      1.34   thorpej 		CHECKINTR(IOASIC_DEV_LANCE, IOASIC_INTR_LANCE, 0);
    314      1.34   thorpej 		CHECKINTR(IOASIC_DEV_ISDN, IOASIC_INTR_ISDN_TXLOAD |
    315      1.34   thorpej 		    IOASIC_INTR_ISDN_RXLOAD | IOASIC_INTR_ISDN_OVRUN, 1);
    316      1.34   thorpej 
    317      1.34   thorpej 		if (sir != osir)
    318      1.34   thorpej 			bus_space_write_4(sc->sc_bst, sc->sc_bsh,
    319      1.34   thorpej 			    IOASIC_INTR, sir);
    320       1.1       cgd 
    321       1.1       cgd 		gifound |= ifound;
    322       1.1       cgd 	} while (ifound);
    323       1.1       cgd 
    324       1.1       cgd 	return (gifound);
    325       1.1       cgd }
    326