Home | History | Annotate | Line # | Download | only in jazz
jazzio.c revision 1.11
      1 /*	$NetBSD: jazzio.c,v 1.11 2003/07/15 00:04:49 lukem Exp $	*/
      2 /*	$OpenBSD: picabus.c,v 1.11 1999/01/11 05:11:10 millert Exp $	*/
      3 /*	NetBSD: tc.c,v 1.2 1995/03/08 00:39:05 cgd Exp 	*/
      4 
      5 /*
      6  * Copyright (c) 1994, 1995 Carnegie-Mellon University.
      7  * All rights reserved.
      8  *
      9  * Author: Chris G. Demetriou
     10  * Author: Per Fogelstrom. (Mips R4x00)
     11  *
     12  * Permission to use, copy, modify and distribute this software and
     13  * its documentation is hereby granted, provided that both the copyright
     14  * notice and this permission notice appear in all copies of the
     15  * software, derivative works or modified versions, and any portions
     16  * thereof, and that both notices appear in supporting documentation.
     17  *
     18  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
     19  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
     20  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
     21  *
     22  * Carnegie Mellon requests users of this software to return to
     23  *
     24  *  Software Distribution Coordinator  or  Software.Distribution (at) CS.CMU.EDU
     25  *  School of Computer Science
     26  *  Carnegie Mellon University
     27  *  Pittsburgh PA 15213-3890
     28  *
     29  * any improvements or extensions that they make and grant Carnegie the
     30  * rights to redistribute these changes.
     31  */
     32 
     33 #include <sys/cdefs.h>
     34 __KERNEL_RCSID(0, "$NetBSD: jazzio.c,v 1.11 2003/07/15 00:04:49 lukem Exp $");
     35 
     36 #include <sys/param.h>
     37 #include <sys/systm.h>
     38 #include <sys/device.h>
     39 
     40 #include <machine/bus.h>
     41 #include <machine/pio.h>
     42 #include <machine/autoconf.h>
     43 #include <machine/platform.h>
     44 
     45 #include <arc/jazz/jazziovar.h>
     46 #include <arc/jazz/pica.h>
     47 #include <arc/jazz/jazzdmatlbreg.h>
     48 #include <arc/jazz/jazzdmatlbvar.h>
     49 #include <arc/jazz/dma.h>
     50 #include <arc/jazz/pckbc_jazzioreg.h>
     51 
     52 void arc_sysreset __P((bus_addr_t, bus_size_t));
     53 
     54 struct jazzio_softc {
     55 	struct	device sc_dv;
     56 	struct	abus sc_bus;
     57 	struct	arc_bus_dma_tag sc_dmat;
     58 	struct	pica_dev *sc_devs;
     59 };
     60 
     61 /* Definition of the driver for autoconfig. */
     62 int	jazziomatch(struct device *, struct cfdata *, void *);
     63 void	jazzioattach(struct device *, struct device *, void *);
     64 int	jazzioprint(void *, const char *);
     65 
     66 CFATTACH_DECL(jazzio, sizeof(struct jazzio_softc),
     67     jazziomatch, jazzioattach, NULL, NULL);
     68 extern struct cfdriver jazzio_cd;
     69 
     70 void	jazzio_intr_establish(int, int (*)(void *), void *);
     71 void	jazzio_intr_disestablish(int);
     72 int	jazzio_intr(unsigned, struct clockframe *);
     73 int	jazzio_no_handler __P((void *));
     74 
     75 /*
     76  *  Interrupt dispatch table for jazz i/o bus.
     77  */
     78 struct jazzio_intr_registry {
     79 	intr_handler_t	int_hand;	/* Interrupt handler */
     80 	void		*param;		/* Parameter to send to handler */
     81 };
     82 
     83 struct jazzio_intr_registry jazzio_intrtab[] = {
     84 	{ jazzio_no_handler, (void *)NULL, },  /*  0 */
     85 	{ jazzio_no_handler, (void *)NULL, },  /*  1 */
     86 	{ jazzio_no_handler, (void *)NULL, },  /*  2 */
     87 	{ jazzio_no_handler, (void *)NULL, },  /*  3 */
     88 	{ jazzio_no_handler, (void *)NULL, },  /*  4 */
     89 	{ jazzio_no_handler, (void *)NULL, },  /*  5 */
     90 	{ jazzio_no_handler, (void *)NULL, },  /*  6 */
     91 	{ jazzio_no_handler, (void *)NULL, },  /*  7 */
     92 	{ jazzio_no_handler, (void *)NULL, },  /*  8 */
     93 	{ jazzio_no_handler, (void *)NULL, },  /*  9 */
     94 	{ jazzio_no_handler, (void *)NULL, },  /* 10 */
     95 	{ jazzio_no_handler, (void *)NULL, },  /* 11 */
     96 	{ jazzio_no_handler, (void *)NULL, },  /* 12 */
     97 	{ jazzio_no_handler, (void *)NULL, },  /* 13 */
     98 	{ jazzio_no_handler, (void *)NULL, },  /* 14 */
     99 	{ jazzio_no_handler, (void *)NULL, },  /* 15 */
    100 };
    101 
    102 
    103 struct jazzio_config *jazzio_conf = NULL;
    104 struct pica_dev *jazzio_devconfig = NULL;
    105 int jazzio_found = 0;
    106 int jazzio_int_mask = 0;	/* jazz i/o interrupt enable mask */
    107 
    108 struct arc_bus_space jazzio_bus;
    109 
    110 int
    111 jazziomatch(parent, match, aux)
    112 	struct device *parent;
    113 	struct cfdata *match;
    114 	void *aux;
    115 {
    116 	struct confargs *ca = aux;
    117 
    118         /* Make sure that we're looking for a jazzio bus. */
    119         if (strcmp(ca->ca_name, jazzio_cd.cd_name) != 0)
    120                 return (0);
    121 
    122 	return (1);
    123 }
    124 
    125 void
    126 jazzioattach(parent, self, aux)
    127 	struct device *parent;
    128 	struct device *self;
    129 	void *aux;
    130 {
    131 	struct jazzio_softc *sc = (struct jazzio_softc *)self;
    132 	struct jazzio_attach_args ja;
    133 	int i;
    134 
    135 	if (jazzio_conf == NULL)
    136 		panic("jazzio_conf isn't initialized");
    137 	if (jazzio_devconfig == NULL)
    138 		panic("jazzio_devconfig isn't initialized");
    139 
    140 	jazzio_found = 1;
    141 
    142 	printf("\n");
    143 
    144 	/* keep our CPU device description handy */
    145 	sc->sc_devs = jazzio_devconfig;
    146 
    147 	/* set up interrupt handlers */
    148 	(*platform->set_intr)(MIPS_INT_MASK_1, jazzio_intr, 2);
    149 
    150 	sc->sc_bus.ab_dv = (struct device *)sc;
    151 
    152 	/* Initialize jazzio DMA mapping register area and pool */
    153 	jazz_dmatlb_init(&jazzio_bus, jazzio_conf->jc_dmatlbreg);
    154 
    155 	/* Create bus_dma_tag */
    156 	jazz_bus_dma_tag_init(&sc->sc_dmat);
    157 
    158 	/* Try to configure each jazzio attached device */
    159 	for (i = 0; sc->sc_devs[i].ps_ca.ca_name != NULL; i++) {
    160 
    161 		ja.ja_name = sc->sc_devs[i].ps_ca.ca_name;
    162 		ja.ja_bus = &sc->sc_bus;
    163 		ja.ja_bust = &jazzio_bus;
    164 		ja.ja_dmat = &sc->sc_dmat;
    165 		ja.ja_addr = (bus_addr_t)sc->sc_devs[i].ps_base;
    166 		ja.ja_intr = sc->sc_devs[i].ps_ca.ca_slot;
    167 		ja.ja_dma = 0;
    168 
    169 		/* Tell the autoconfig machinery we've found the hardware. */
    170 		config_found(self, &ja, jazzioprint);
    171 	}
    172 }
    173 
    174 int
    175 jazzioprint(aux, pnp)
    176 	void *aux;
    177 	const char *pnp;
    178 {
    179 	struct jazzio_attach_args *ja = aux;
    180 
    181 	if (pnp)
    182 		aprint_normal("%s at %s", ja->ja_name, pnp);
    183 	aprint_normal(" addr 0x%lx", ja->ja_addr);
    184 	if (ja->ja_intr != -1)
    185 		aprint_normal(" intr %d", ja->ja_intr);
    186 	return (UNCONF);
    187 }
    188 
    189 void
    190 jazzio_intr_establish(intr, handler, val)
    191 	int intr;
    192 	intr_handler_t handler;
    193 	void *val;
    194 {
    195 	if (intr < 0 ||
    196 	    intr >= sizeof(jazzio_intrtab)/sizeof(jazzio_intrtab[0])) {
    197 		panic("jazzio intr %d out of range", intr);
    198 	} else if (jazzio_intrtab[intr].int_hand != jazzio_no_handler) {
    199 		panic("jazzio intr %d already set to %p", intr,
    200 		    jazzio_intrtab[intr].int_hand);
    201 	} else {
    202 		jazzio_int_mask |= 1 << intr;
    203 		jazzio_intrtab[intr].int_hand = handler;
    204 		jazzio_intrtab[intr].param = val;
    205 	}
    206 
    207 	(*jazzio_conf->jc_set_iointr_mask)(jazzio_int_mask);
    208 }
    209 
    210 void
    211 jazzio_intr_disestablish(intr)
    212 	int intr;
    213 {
    214 	jazzio_int_mask &= ~(1 << intr);
    215 	jazzio_intrtab[intr].int_hand = jazzio_no_handler;
    216 	jazzio_intrtab[intr].param = (void *)NULL;
    217 
    218 	(*jazzio_conf->jc_set_iointr_mask)(jazzio_int_mask);
    219 }
    220 
    221 int
    222 jazzio_no_handler(arg)
    223 	void *arg;
    224 {
    225 	panic("uncaught jazzio interrupt with arg %p", arg);
    226 }
    227 
    228 /*
    229  *   Handle jazz i/o interrupt.
    230  */
    231 int
    232 jazzio_intr(mask, cf)
    233 	unsigned mask;
    234 	struct clockframe *cf;
    235 {
    236 	unsigned int vector;
    237 	struct jazzio_intr_registry *jirp;
    238 
    239 	while ((vector = inb(jazzio_conf->jc_iointr_status_reg)) != 0) {
    240 		jirp = &jazzio_intrtab[(vector >> 2) - 1];
    241 		(*jirp->int_hand)(jirp->param);
    242 	}
    243 	return (~0);  /* Dont reenable */
    244 }
    245 
    246 void
    247 jazzio_reset()
    248 {
    249 	arc_sysreset(PICA_SYS_KBD, JAZZIO_KBCMDP);
    250 }
    251