Home | History | Annotate | Line # | Download | only in tc
ioasic.c revision 1.1
      1  1.1  cgd /*	$NetBSD: ioasic.c,v 1.1 1995/12/20 00:43:20 cgd Exp $	*/
      2  1.1  cgd 
      3  1.1  cgd /*
      4  1.1  cgd  * Copyright (c) 1994, 1995 Carnegie-Mellon University.
      5  1.1  cgd  * All rights reserved.
      6  1.1  cgd  *
      7  1.1  cgd  * Author: Keith Bostic, Chris G. Demetriou
      8  1.1  cgd  *
      9  1.1  cgd  * Permission to use, copy, modify and distribute this software and
     10  1.1  cgd  * its documentation is hereby granted, provided that both the copyright
     11  1.1  cgd  * notice and this permission notice appear in all copies of the
     12  1.1  cgd  * software, derivative works or modified versions, and any portions
     13  1.1  cgd  * thereof, and that both notices appear in supporting documentation.
     14  1.1  cgd  *
     15  1.1  cgd  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
     16  1.1  cgd  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
     17  1.1  cgd  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
     18  1.1  cgd  *
     19  1.1  cgd  * Carnegie Mellon requests users of this software to return to
     20  1.1  cgd  *
     21  1.1  cgd  *  Software Distribution Coordinator  or  Software.Distribution (at) CS.CMU.EDU
     22  1.1  cgd  *  School of Computer Science
     23  1.1  cgd  *  Carnegie Mellon University
     24  1.1  cgd  *  Pittsburgh PA 15213-3890
     25  1.1  cgd  *
     26  1.1  cgd  * any improvements or extensions that they make and grant Carnegie the
     27  1.1  cgd  * rights to redistribute these changes.
     28  1.1  cgd  */
     29  1.1  cgd 
     30  1.1  cgd #include <sys/param.h>
     31  1.1  cgd #include <sys/kernel.h>
     32  1.1  cgd #include <sys/systm.h>
     33  1.1  cgd #include <sys/device.h>
     34  1.1  cgd 
     35  1.1  cgd #include <machine/autoconf.h>
     36  1.1  cgd #include <machine/pte.h>
     37  1.1  cgd #include <machine/rpb.h>
     38  1.1  cgd 
     39  1.1  cgd #include <dev/tc/tcvar.h>
     40  1.1  cgd #include <alpha/tc/ioasicreg.h>
     41  1.1  cgd #include <dev/tc/ioasicvar.h>
     42  1.1  cgd 
     43  1.1  cgd struct ioasic_softc {
     44  1.1  cgd 	struct	device sc_dv;
     45  1.1  cgd 
     46  1.1  cgd 	tc_addr_t sc_base;
     47  1.1  cgd 	void	*sc_cookie;
     48  1.1  cgd };
     49  1.1  cgd 
     50  1.1  cgd /* Definition of the driver for autoconfig. */
     51  1.1  cgd int	ioasicmatch __P((struct device *, void *, void *));
     52  1.1  cgd void	ioasicattach __P((struct device *, struct device *, void *));
     53  1.1  cgd int     ioasicprint(void *, char *);
     54  1.1  cgd struct cfdriver ioasiccd =
     55  1.1  cgd     { NULL, "ioasic", ioasicmatch, ioasicattach, DV_DULL,
     56  1.1  cgd     sizeof(struct ioasic_softc) };
     57  1.1  cgd 
     58  1.1  cgd int	ioasic_intr __P((void *));
     59  1.1  cgd int	ioasic_intrnull __P((void *));
     60  1.1  cgd 
     61  1.1  cgd #define	C(x)	((void *)(x))
     62  1.1  cgd 
     63  1.1  cgd #define	IOASIC_DEV_LANCE	0
     64  1.1  cgd #define	IOASIC_DEV_SCC0		1
     65  1.1  cgd #define	IOASIC_DEV_SCC1		2
     66  1.1  cgd #define	IOASIC_DEV_ISDN		3
     67  1.1  cgd 
     68  1.1  cgd #define	IOASIC_DEV_BOGUS	-1
     69  1.1  cgd 
     70  1.1  cgd #define	IOASIC_NCOOKIES		4
     71  1.1  cgd 
     72  1.1  cgd struct ioasic_dev {
     73  1.1  cgd 	char		*iad_modname;
     74  1.1  cgd 	tc_offset_t	iad_offset;
     75  1.1  cgd 	void		*iad_cookie;
     76  1.1  cgd 	u_int32_t	iad_intrbits;
     77  1.1  cgd } ioasic_devs[] = {
     78  1.1  cgd 	{ "lance   ", 0x000c0000, C(IOASIC_DEV_LANCE), IOASIC_INTR_LANCE, },
     79  1.1  cgd 	{ "z8530   ", 0x00100000, C(IOASIC_DEV_SCC0),  IOASIC_INTR_SCC_0, },
     80  1.1  cgd 	{ "z8530   ", 0x00180000, C(IOASIC_DEV_SCC1),  IOASIC_INTR_SCC_1, },
     81  1.1  cgd 	{ "TOY_RTC ", 0x00200000, C(IOASIC_DEV_BOGUS), 0,                 },
     82  1.1  cgd 	{ "AMD79c30", 0x00240000, C(IOASIC_DEV_ISDN),  IOASIC_INTR_ISDN,  },
     83  1.1  cgd };
     84  1.1  cgd int ioasic_ndevs = sizeof(ioasic_devs) / sizeof(ioasic_devs[0]);
     85  1.1  cgd 
     86  1.1  cgd struct ioasicintr {
     87  1.1  cgd 	int	(*iai_func) __P((void *));
     88  1.1  cgd 	void	*iai_arg;
     89  1.1  cgd } ioasicintrs[IOASIC_NCOOKIES];
     90  1.1  cgd 
     91  1.1  cgd tc_addr_t ioasic_base;		/* XXX XXX XXX */
     92  1.1  cgd 
     93  1.1  cgd /* There can be only one. */
     94  1.1  cgd int ioasicfound;
     95  1.1  cgd 
     96  1.1  cgd extern int cputype;
     97  1.1  cgd 
     98  1.1  cgd int
     99  1.1  cgd ioasicmatch(parent, cfdata, aux)
    100  1.1  cgd 	struct device *parent;
    101  1.1  cgd 	void *cfdata;
    102  1.1  cgd 	void *aux;
    103  1.1  cgd {
    104  1.1  cgd 	struct tcdev_attach_args *tcdev = aux;
    105  1.1  cgd 
    106  1.1  cgd 	/* Make sure that we're looking for this type of device. */
    107  1.1  cgd 	if (strncmp("FLAMG-IO", tcdev->tcda_modname, TC_ROM_LLEN))
    108  1.1  cgd 		return (0);
    109  1.1  cgd 
    110  1.1  cgd 	/* Check that it can actually exist. */
    111  1.1  cgd 	if ((cputype != ST_DEC_3000_500) && (cputype != ST_DEC_3000_300))
    112  1.1  cgd 		panic("ioasicmatch: how did we get here?");
    113  1.1  cgd 
    114  1.1  cgd 	if (ioasicfound)
    115  1.1  cgd 		return (0);
    116  1.1  cgd 
    117  1.1  cgd 	return (1);
    118  1.1  cgd }
    119  1.1  cgd 
    120  1.1  cgd void
    121  1.1  cgd ioasicattach(parent, self, aux)
    122  1.1  cgd 	struct device *parent, *self;
    123  1.1  cgd 	void *aux;
    124  1.1  cgd {
    125  1.1  cgd 	struct ioasic_softc *sc = (struct ioasic_softc *)self;
    126  1.1  cgd 	struct tcdev_attach_args *tcdev = aux;
    127  1.1  cgd 	struct ioasicdev_attach_args ioasicdev;
    128  1.1  cgd 	u_long i;
    129  1.1  cgd 
    130  1.1  cgd 	ioasicfound = 1;
    131  1.1  cgd 
    132  1.1  cgd 	sc->sc_base = tcdev->tcda_addr;
    133  1.1  cgd 	ioasic_base = sc->sc_base;			/* XXX XXX XXX */
    134  1.1  cgd 	sc->sc_cookie = tcdev->tcda_cookie;
    135  1.1  cgd 
    136  1.1  cgd #ifdef DEC_3000_300
    137  1.1  cgd 	if (cputype == ST_DEC_3000_300) {
    138  1.1  cgd 		*(volatile u_int *)IOASIC_REG_CSR(sc->sc_base) |=
    139  1.1  cgd 		    IOASIC_CSR_FASTMODE;
    140  1.1  cgd 		tc_mb();
    141  1.1  cgd 		printf(": slow mode\n");
    142  1.1  cgd 	} else
    143  1.1  cgd #endif
    144  1.1  cgd 		printf(": fast mode\n");
    145  1.1  cgd 
    146  1.1  cgd 	/*
    147  1.1  cgd 	 * Turn off all device interrupt bits.
    148  1.1  cgd 	 * (This does _not_ include 3000/300 TC option slot bits.
    149  1.1  cgd 	 */
    150  1.1  cgd 	for (i = 0; i < ioasic_ndevs; i++)
    151  1.1  cgd 		*(volatile u_int32_t *)IOASIC_REG_IMSK(ioasic_base) &=
    152  1.1  cgd 			~ioasic_devs[i].iad_intrbits;
    153  1.1  cgd 	tc_mb();
    154  1.1  cgd 
    155  1.1  cgd 	/*
    156  1.1  cgd 	 * Set up interrupt handlers.
    157  1.1  cgd 	 */
    158  1.1  cgd 	for (i = 0; i < IOASIC_NCOOKIES; i++) {
    159  1.1  cgd 		ioasicintrs[i].iai_func = ioasic_intrnull;
    160  1.1  cgd 		ioasicintrs[i].iai_arg = (void *)i;
    161  1.1  cgd 	}
    162  1.1  cgd 	tc_intr_establish(parent, sc->sc_cookie, TC_IPL_NONE, ioasic_intr, sc);
    163  1.1  cgd 
    164  1.1  cgd         /*
    165  1.1  cgd 	 * Try to configure each device.
    166  1.1  cgd 	 */
    167  1.1  cgd         for (i = 0; i < ioasic_ndevs; i++) {
    168  1.1  cgd 		strncpy(ioasicdev.iada_modname, ioasic_devs[i].iad_modname,
    169  1.1  cgd 			TC_ROM_LLEN);
    170  1.1  cgd 		ioasicdev.iada_modname[TC_ROM_LLEN] = '\0';
    171  1.1  cgd 		ioasicdev.iada_offset = ioasic_devs[i].iad_offset;
    172  1.1  cgd 		ioasicdev.iada_addr = sc->sc_base + ioasic_devs[i].iad_offset;
    173  1.1  cgd 		ioasicdev.iada_cookie = ioasic_devs[i].iad_cookie;
    174  1.1  cgd 
    175  1.1  cgd                 /* Tell the autoconfig machinery we've found the hardware. */
    176  1.1  cgd                 config_found(self, &ioasicdev, ioasicprint);
    177  1.1  cgd         }
    178  1.1  cgd }
    179  1.1  cgd 
    180  1.1  cgd int
    181  1.1  cgd ioasicprint(aux, pnp)
    182  1.1  cgd 	void *aux;
    183  1.1  cgd 	char *pnp;
    184  1.1  cgd {
    185  1.1  cgd 	struct ioasicdev_attach_args *d = aux;
    186  1.1  cgd 
    187  1.1  cgd         if (pnp)
    188  1.1  cgd                 printf("%s at %s", d->iada_modname, pnp);
    189  1.1  cgd         printf(" offset 0x%lx", (long)d->iada_offset);
    190  1.1  cgd         return (UNCONF);
    191  1.1  cgd }
    192  1.1  cgd 
    193  1.1  cgd int
    194  1.1  cgd ioasic_submatch(match, d)
    195  1.1  cgd 	struct cfdata *match;
    196  1.1  cgd 	struct ioasicdev_attach_args *d;
    197  1.1  cgd {
    198  1.1  cgd 
    199  1.1  cgd 	return ((match->ioasiccf_offset == d->iada_offset) ||
    200  1.1  cgd 		(match->ioasiccf_offset == IOASIC_OFFSET_UNKNOWN));
    201  1.1  cgd }
    202  1.1  cgd 
    203  1.1  cgd void
    204  1.1  cgd ioasic_intr_establish(ioa, cookie, level, func, arg)
    205  1.1  cgd 	struct device *ioa;
    206  1.1  cgd 	void *cookie, *arg;
    207  1.1  cgd 	tc_intrlevel_t level;
    208  1.1  cgd 	int (*func) __P((void *));
    209  1.1  cgd {
    210  1.1  cgd 	u_long dev, i;
    211  1.1  cgd 
    212  1.1  cgd 	dev = (u_long)cookie;
    213  1.1  cgd #ifdef DIAGNOSTIC
    214  1.1  cgd 	/* XXX check cookie. */
    215  1.1  cgd #endif
    216  1.1  cgd 
    217  1.1  cgd 	if (ioasicintrs[dev].iai_func != ioasic_intrnull)
    218  1.1  cgd 		panic("ioasic_intr_establish: cookie %d twice", dev);
    219  1.1  cgd 
    220  1.1  cgd 	ioasicintrs[dev].iai_func = func;
    221  1.1  cgd 	ioasicintrs[dev].iai_arg = arg;
    222  1.1  cgd 
    223  1.1  cgd 	/* Enable interrupts for the device. */
    224  1.1  cgd 	for (i = 0; i < ioasic_ndevs; i++)
    225  1.1  cgd 		if (ioasic_devs[i].iad_cookie == cookie)
    226  1.1  cgd 			break;
    227  1.1  cgd 	if (i == ioasic_ndevs)
    228  1.1  cgd 		panic("ioasic_intr_establish: invalid cookie.");
    229  1.1  cgd 	*(volatile u_int32_t *)IOASIC_REG_IMSK(ioasic_base) |=
    230  1.1  cgd 		ioasic_devs[i].iad_intrbits;
    231  1.1  cgd 	tc_mb();
    232  1.1  cgd }
    233  1.1  cgd 
    234  1.1  cgd void
    235  1.1  cgd ioasic_intr_disestablish(ioa, cookie)
    236  1.1  cgd 	struct device *ioa;
    237  1.1  cgd 	void *cookie;
    238  1.1  cgd {
    239  1.1  cgd 	u_long dev, i;
    240  1.1  cgd 
    241  1.1  cgd 	dev = (u_long)cookie;
    242  1.1  cgd #ifdef DIAGNOSTIC
    243  1.1  cgd 	/* XXX check cookie. */
    244  1.1  cgd #endif
    245  1.1  cgd 
    246  1.1  cgd 	if (ioasicintrs[dev].iai_func == ioasic_intrnull)
    247  1.1  cgd 		panic("ioasic_intr_disestablish: cookie %d missing intr", dev);
    248  1.1  cgd 
    249  1.1  cgd 	/* Enable interrupts for the device. */
    250  1.1  cgd 	for (i = 0; i < ioasic_ndevs; i++)
    251  1.1  cgd 		if (ioasic_devs[i].iad_cookie == cookie)
    252  1.1  cgd 			break;
    253  1.1  cgd 	if (i == ioasic_ndevs)
    254  1.1  cgd 		panic("ioasic_intr_disestablish: invalid cookie.");
    255  1.1  cgd 	*(volatile u_int32_t *)IOASIC_REG_IMSK(ioasic_base) &=
    256  1.1  cgd 		~ioasic_devs[i].iad_intrbits;
    257  1.1  cgd 	tc_mb();
    258  1.1  cgd 
    259  1.1  cgd 	ioasicintrs[dev].iai_func = ioasic_intrnull;
    260  1.1  cgd 	ioasicintrs[dev].iai_arg = (void *)dev;
    261  1.1  cgd }
    262  1.1  cgd 
    263  1.1  cgd int
    264  1.1  cgd ioasic_intrnull(val)
    265  1.1  cgd 	void *val;
    266  1.1  cgd {
    267  1.1  cgd 
    268  1.1  cgd 	panic("ioasic_intrnull: uncaught IOASIC intr for cookie %ld\n",
    269  1.1  cgd 	    (u_long)val);
    270  1.1  cgd }
    271  1.1  cgd 
    272  1.1  cgd /*
    273  1.1  cgd  * asic_intr --
    274  1.1  cgd  *	ASIC interrupt handler.
    275  1.1  cgd  */
    276  1.1  cgd int
    277  1.1  cgd ioasic_intr(val)
    278  1.1  cgd 	void *val;
    279  1.1  cgd {
    280  1.1  cgd 	register struct ioasic_softc *sc = val;
    281  1.1  cgd 	register int i, ifound;
    282  1.1  cgd 	int gifound;
    283  1.1  cgd 	u_int32_t sir, junk;
    284  1.1  cgd 	volatile u_int32_t *sirp, *junkp;
    285  1.1  cgd 
    286  1.1  cgd 	sirp = (volatile u_int32_t *)IOASIC_REG_INTR(sc->sc_base);
    287  1.1  cgd 
    288  1.1  cgd 	gifound = 0;
    289  1.1  cgd 	do {
    290  1.1  cgd 		ifound = 0;
    291  1.1  cgd 		tc_syncbus();
    292  1.1  cgd 
    293  1.1  cgd 		sir = *sirp;
    294  1.1  cgd 
    295  1.1  cgd 		/* XXX DUPLICATION OF INTERRUPT BIT INFORMATION... */
    296  1.1  cgd #define	CHECKINTR(slot, bits)						\
    297  1.1  cgd 		if (sir & bits) {					\
    298  1.1  cgd 			ifound = 1;					\
    299  1.1  cgd 			(*ioasicintrs[slot].iai_func)			\
    300  1.1  cgd 			    (ioasicintrs[slot].iai_arg);		\
    301  1.1  cgd 		}
    302  1.1  cgd 		CHECKINTR(IOASIC_DEV_SCC0, IOASIC_INTR_SCC_0);
    303  1.1  cgd 		CHECKINTR(IOASIC_DEV_SCC1, IOASIC_INTR_SCC_1);
    304  1.1  cgd 		CHECKINTR(IOASIC_DEV_LANCE, IOASIC_INTR_LANCE);
    305  1.1  cgd 		CHECKINTR(IOASIC_DEV_ISDN, IOASIC_INTR_ISDN);
    306  1.1  cgd 
    307  1.1  cgd 		gifound |= ifound;
    308  1.1  cgd 	} while (ifound);
    309  1.1  cgd 
    310  1.1  cgd 	return (gifound);
    311  1.1  cgd }
    312  1.1  cgd 
    313  1.1  cgd /* XXX */
    314  1.1  cgd char *
    315  1.1  cgd ioasic_lance_ether_address()
    316  1.1  cgd {
    317  1.1  cgd 
    318  1.1  cgd 	return (u_char *)IOASIC_SYS_ETHER_ADDRESS(ioasic_base);
    319  1.1  cgd }
    320  1.1  cgd 
    321  1.1  cgd void
    322  1.1  cgd ioasic_lance_dma_setup(v)
    323  1.1  cgd 	void *v;
    324  1.1  cgd {
    325  1.1  cgd 	volatile u_int32_t *ldp;
    326  1.1  cgd 	tc_addr_t tca;
    327  1.1  cgd 
    328  1.1  cgd 	tca = (tc_addr_t)v;
    329  1.1  cgd 
    330  1.1  cgd 	ldp = (volatile u_int *)IOASIC_REG_LANCE_DMAPTR(ioasic_base);
    331  1.1  cgd 	*ldp = ((tca << 3) & ~(tc_addr_t)0x1f) | ((tca >> 29) & 0x1f);
    332  1.1  cgd 	tc_wmb();
    333  1.1  cgd 
    334  1.1  cgd 	*(volatile u_int32_t *)IOASIC_REG_CSR(ioasic_base) |=
    335  1.1  cgd 	    IOASIC_CSR_DMAEN_LANCE;
    336  1.1  cgd 	tc_mb();
    337  1.1  cgd }
    338  1.1  cgd 
    339  1.1  cgd #ifdef DEC_3000_300
    340  1.1  cgd void
    341  1.1  cgd ioasic_intr_300_opt0_enable(enable)
    342  1.1  cgd 	int enable;
    343  1.1  cgd {
    344  1.1  cgd 
    345  1.1  cgd 	if (enable)
    346  1.1  cgd 		*(volatile u_int32_t *)IOASIC_REG_IMSK(ioasic_base) |=
    347  1.1  cgd 			IOASIC_INTR_300_OPT0;
    348  1.1  cgd 	else
    349  1.1  cgd 		*(volatile u_int32_t *)IOASIC_REG_IMSK(ioasic_base) &=
    350  1.1  cgd 			~IOASIC_INTR_300_OPT0;
    351  1.1  cgd }
    352  1.1  cgd 
    353  1.1  cgd void
    354  1.1  cgd ioasic_intr_300_opt1_enable(enable)
    355  1.1  cgd 	int enable;
    356  1.1  cgd {
    357  1.1  cgd 
    358  1.1  cgd 	if (enable)
    359  1.1  cgd 		*(volatile u_int32_t *)IOASIC_REG_IMSK(ioasic_base) |=
    360  1.1  cgd 			IOASIC_INTR_300_OPT1;
    361  1.1  cgd 	else
    362  1.1  cgd 		*(volatile u_int32_t *)IOASIC_REG_IMSK(ioasic_base) &=
    363  1.1  cgd 			~IOASIC_INTR_300_OPT1;
    364  1.1  cgd }
    365  1.1  cgd 
    366  1.1  cgd void
    367  1.1  cgd ioasic_300_opts_isintr(opt0, opt1)
    368  1.1  cgd 	int *opt0, *opt1;
    369  1.1  cgd {
    370  1.1  cgd 	u_int32_t sir;
    371  1.1  cgd 
    372  1.1  cgd 	sir = *(volatile u_int32_t *)IOASIC_REG_INTR(ioasic_base);
    373  1.1  cgd 	*opt0 = sir & IOASIC_INTR_300_OPT0;
    374  1.1  cgd 	*opt1 = sir & IOASIC_INTR_300_OPT1;
    375  1.1  cgd }
    376  1.1  cgd #endif
    377