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