Home | History | Annotate | Line # | Download | only in tc
ioasic.c revision 1.9
      1 /*	$NetBSD: ioasic.c,v 1.9 2000/02/03 05:22:47 nisimura Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1994, 1995 Carnegie-Mellon University.
      5  * All rights reserved.
      6  *
      7  * Author: Keith Bostic, Chris G. Demetriou, Jonathan Stone
      8  *
      9  * Permission to use, copy, modify and distribute this software and
     10  * its documentation is hereby granted, provided that both the copyright
     11  * notice and this permission notice appear in all copies of the
     12  * software, derivative works or modified versions, and any portions
     13  * thereof, and that both notices appear in supporting documentation.
     14  *
     15  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
     16  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
     17  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
     18  *
     19  * Carnegie Mellon requests users of this software to return to
     20  *
     21  *  Software Distribution Coordinator  or  Software.Distribution (at) CS.CMU.EDU
     22  *  School of Computer Science
     23  *  Carnegie Mellon University
     24  *  Pittsburgh PA 15213-3890
     25  *
     26  * any improvements or extensions that they make and grant Carnegie the
     27  * rights to redistribute these changes.
     28  */
     29 
     30 #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
     31 __KERNEL_RCSID(0, "$NetBSD: ioasic.c,v 1.9 2000/02/03 05:22:47 nisimura Exp $");
     32 
     33 #include <sys/param.h>
     34 #include <sys/systm.h>
     35 #include <sys/device.h>
     36 
     37 #include <dev/tc/tcvar.h>
     38 #include <dev/tc/ioasicvar.h>
     39 
     40 #include <machine/sysconf.h>
     41 
     42 #include <pmax/pmax/pmaxtype.h>
     43 #include <pmax/pmax/asic.h>
     44 #include <pmax/pmax/kmin.h>
     45 #include <pmax/pmax/maxine.h>
     46 #include <pmax/pmax/kn03.h>
     47 
     48 #include "opt_dec_3min.h"
     49 #include "opt_dec_maxine.h"
     50 #include "opt_dec_3maxplus.h"
     51 
     52 #define	C(x)		((void *)(x))
     53 #define ARRAY_SIZEOF(x) (sizeof((x)) / sizeof((x)[0]))
     54 
     55 #if defined(DEC_3MIN)
     56 static struct ioasic_dev kmin_ioasic_devs[] = {
     57 	{ "lance",	0x0C0000, C(KMIN_LANCE_SLOT),	IOASIC_INTR_LANCE, },
     58 	{ "scc",	0x100000, C(KMIN_SCC0_SLOT),	IOASIC_INTR_SCC_0, },
     59 	{ "scc",	0x180000, C(KMIN_SCC1_SLOT),	IOASIC_INTR_SCC_1, },
     60 	{ "mc146818",	0x200000, C(-1),		0 },
     61 	{ "asc",	0x300000, C(KMIN_SCSI_SLOT),	IOASIC_INTR_SCSI, },
     62 };
     63 static int kmin_builtin_ndevs = ARRAY_SIZEOF(kmin_ioasic_devs);
     64 static int kmin_ioasic_ndevs = ARRAY_SIZEOF(kmin_ioasic_devs);
     65 #endif
     66 
     67 #if defined(DEC_MAXINE)
     68 static struct ioasic_dev xine_ioasic_devs[] = {
     69 	{ "lance",	0x0C0000, C(XINE_LANCE_SLOT),	IOASIC_INTR_LANCE },
     70 	{ "scc",	0x100000, C(XINE_SCC0_SLOT),	IOASIC_INTR_SCC_0 },
     71 	{ "mc146818",	0x200000, C(-1),		0 },
     72 	{ "isdn",	0x240000, C(XINE_ISDN_SLOT),	XINE_INTR_ISDN, },
     73 	{ "dtop",	0x280000, C(XINE_DTOP_SLOT),	XINE_INTR_DTOP, },
     74 	{ "fdc",	0x2C0000, C(XINE_FLOPPY_SLOT),	0 },
     75 	{ "asc",	0x300000, C(XINE_SCSI_SLOT),	IOASIC_INTR_SCSI, },
     76 	{ "(TC0)",	0x0,	  C(0),			XINE_INTR_TC_0,	},
     77 	{ "(TC1)",	0x0,	  C(1),			XINE_INTR_TC_1,	},
     78 	{ "(TC2)",	0x0,	  C(2),			XINE_INTR_VINT,	},
     79 };
     80 static int xine_builtin_ndevs = ARRAY_SIZEOF(xine_ioasic_devs) - 3;
     81 static int xine_ioasic_ndevs = ARRAY_SIZEOF(xine_ioasic_devs);
     82 #endif
     83 
     84 #if defined(DEC_3MAXPLUS)
     85 static struct ioasic_dev kn03_ioasic_devs[] = {
     86 	{ "lance",	0x0C0000, C(KN03_LANCE_SLOT),	IOASIC_INTR_LANCE, },
     87 	{ "z8530   ",	0x100000, C(KN03_SCC0_SLOT),	IOASIC_INTR_SCC_0, },
     88 	{ "z8530   ",	0x180000, C(KN03_SCC1_SLOT),	IOASIC_INTR_SCC_1, },
     89 	{ "mc146818",	0x200000, C(-1),		0,		},
     90 	{ "asc",	0x300000, C(KN03_SCSI_SLOT),	IOASIC_INTR_SCSI, },
     91 	{ "(TC0)",	0x0,	  C(0),			KN03_INTR_TC_0,	},
     92 	{ "(TC1)",	0x0,	  C(1),			KN03_INTR_TC_1,	},
     93 	{ "(TC2)",	0x0,	  C(2),			KN03_INTR_TC_2,	},
     94 };
     95 static int kn03_builtin_ndevs = ARRAY_SIZEOF(kn03_ioasic_devs) - 3;
     96 static int kn03_ioasic_ndevs = ARRAY_SIZEOF(kn03_ioasic_devs);
     97 #endif
     98 
     99 static int	ioasicmatch __P((struct device *, struct cfdata *, void *));
    100 static void	ioasicattach __P((struct device *, struct device *, void *));
    101 
    102 const struct cfattach ioasic_ca = {
    103 	sizeof(struct ioasic_softc), ioasicmatch, ioasicattach
    104 };
    105 
    106 tc_addr_t ioasic_base;	/* XXX XXX XXX */
    107 
    108 /* There can be only one. */
    109 int ioasicfound;
    110 
    111 static int
    112 ioasicmatch(parent, cfdata, aux)
    113 	struct device *parent;
    114 	struct cfdata *cfdata;
    115 	void *aux;
    116 {
    117 	struct tc_attach_args *ta = aux;
    118 
    119 	/* Make sure that we're looking for this type of device. */
    120 	if (strncmp("IOCTL   ", ta->ta_modname, TC_ROM_LLEN))
    121 		return (0);
    122 
    123 	if (ioasicfound)
    124 		return (0);
    125 
    126 	return (1);
    127 }
    128 
    129 static void
    130 ioasicattach(parent, self, aux)
    131 	struct device *parent, *self;
    132 	void *aux;
    133 {
    134 	struct ioasic_softc *sc = (struct ioasic_softc *)self;
    135 	struct tc_attach_args *ta = aux;
    136 	struct ioasic_dev *ioasic_devs;
    137 	int ioasic_ndevs, builtin_ndevs;
    138 	int i, imsk;
    139 
    140 	ioasicfound = 1;
    141 
    142 	sc->sc_bst = ta->ta_memt;
    143 	if (bus_space_map(ta->ta_memt, ta->ta_addr,
    144 			0x400000, 0, &sc->sc_bsh)) {
    145 		printf("%s: unable to map device\n", sc->sc_dv.dv_xname);
    146 		return;
    147 	}
    148 	sc->sc_dmat = ta->ta_dmat;
    149 	sc->sc_cookie = ta->ta_cookie;
    150 
    151 	sc->sc_base = ta->ta_addr; /* XXX XXX XXX */
    152 
    153 	printf("\n");
    154 
    155 	switch (systype) {
    156 #if defined(DEC_3MIN)
    157 	case DS_3MIN:
    158 		ioasic_devs = kmin_ioasic_devs;
    159 		ioasic_ndevs = kmin_ioasic_ndevs;
    160 		builtin_ndevs = kmin_builtin_ndevs;
    161 		break;
    162 #endif
    163 #if defined(DEC_MAXINE)
    164 	case DS_MAXINE:
    165 		ioasic_devs = xine_ioasic_devs;
    166 		ioasic_ndevs = xine_ioasic_ndevs;
    167 		builtin_ndevs = xine_builtin_ndevs;
    168 		break;
    169 #endif
    170 #if defined(DEC_3MAXPLUS)
    171 	case DS_3MAXPLUS:
    172 		ioasic_devs = kn03_ioasic_devs;
    173 		ioasic_ndevs = kn03_ioasic_ndevs;
    174 		builtin_ndevs = kn03_builtin_ndevs;
    175 		break;
    176 #endif
    177 	default:
    178 		panic("ioasicmatch: how did we get here?");
    179 	}
    180 
    181 	/*
    182 	 * Turn off all device interrupt bits.
    183 	 * (This _does_ include TC option slot bits.
    184 	 */
    185 	imsk = bus_space_read_4(sc->sc_bst, sc->sc_bsh, IOASIC_IMSK);
    186 	for (i = 0; i < ioasic_ndevs; i++)
    187 		imsk &= ~ioasic_devs[i].iad_intrbits;
    188 	bus_space_write_4(sc->sc_bst, sc->sc_bsh, IOASIC_IMSK, imsk);
    189 
    190 	/*
    191 	 * Try to configure each device.
    192 	 */
    193 	ioasic_attach_devs(sc, ioasic_devs, builtin_ndevs);
    194 }
    195 
    196 #if 1 /* XXX for now XXX */
    197 void
    198 ioasic_intr_establish(dev, cookie, level, handler, val)
    199 	struct device *dev;
    200 	void *cookie;
    201 	int level;
    202 	int (*handler) __P((void *));
    203 	void *val;
    204 {
    205 	(*platform.intr_establish)(dev, cookie, level, handler, val);
    206 }
    207 
    208 #else /* XXX eventually XXX */
    209 
    210 void
    211 ioasic_intr_establish(ioa, cookie, level, func, arg)
    212 	struct device *ioa;
    213 	void *cookie, *arg;
    214 	int level;
    215 	int (*func) __P((void *));
    216 {
    217 	struct ioasic_softc *sc = (void *)ioasic_cd.cd_devs[0];
    218 	int i, intrbits;
    219 
    220 	for (i = 0; i < ioasic_ndevs; i++) {
    221 		if (ioasic_devs[i].iad_cookie == cookie)
    222 			goto found;
    223 	}
    224 	panic("ioasic_intr_establish: invalid cookie %d", (int)cookie);
    225 found:
    226 
    227 	intrtab[(int)cookie].ih_func = func;
    228 	intrtab[(int)cookie].ih_arg = arg;
    229 
    230 	intrbits = ioasic_devs[i].iad_intrbits;
    231 	i = bus_space_read_4(sc->sc_bst, sc->sc_bsh, IOASIC_IMSK);
    232 	i |= intrbits;
    233 	bus_space_write_4(sc->sc_bst, sc->sc_bsh, IOASIC_IMSK, i);
    234 }
    235 
    236 void
    237 ioasic_intr_disestablish(ioa, cookie)
    238 	struct device *ioa;
    239 	void *cookie;
    240 {
    241 	panic("ioasic_intr_disestablish: cookie %d", (int)cookie);
    242 }
    243 #endif
    244