Home | History | Annotate | Line # | Download | only in jazz
jazzio.c revision 1.19
      1 /*	$NetBSD: jazzio.c,v 1.19 2008/03/14 16:43:27 tsutsui 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.19 2008/03/14 16:43:27 tsutsui 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 #include "ioconf.h"
     53 
     54 void arc_sysreset(bus_addr_t, bus_size_t);
     55 
     56 struct jazzio_softc {
     57 	struct	device sc_dv;
     58 	struct	arc_bus_dma_tag sc_dmat;
     59 	struct	pica_dev *sc_devs;
     60 };
     61 
     62 /* Definition of the driver for autoconfig. */
     63 int	jazziomatch(struct device *, struct cfdata *, void *);
     64 void	jazzioattach(struct device *, struct device *, void *);
     65 int	jazzioprint(void *, const char *);
     66 
     67 CFATTACH_DECL(jazzio, sizeof(struct jazzio_softc),
     68     jazziomatch, jazzioattach, NULL, NULL);
     69 
     70 void	jazzio_intr_establish(int, int (*)(void *), void *);
     71 void	jazzio_intr_disestablish(int);
     72 uint32_t jazzio_intr(uint32_t, struct clockframe *);
     73 int	jazzio_no_handler(void *);
     74 
     75 /*
     76  *  Interrupt dispatch table for jazz i/o bus.
     77  */
     78 struct jazzio_intrhand {
     79 	intr_handler_t	ih_func;	/* Interrupt handler */
     80 	void		*ih_arg;	/* Parameter to send to handler */
     81 	struct evcnt	ih_evcnt;	/* interrupt counter */
     82 	char		ih_evname[32];	/* event counter name */
     83 };
     84 
     85 struct jazzio_intrhand jazzio_intrtab[16];
     86 
     87 
     88 struct jazzio_config *jazzio_conf = NULL;
     89 struct pica_dev *jazzio_devconfig = NULL;
     90 int jazzio_found = 0;
     91 int jazzio_int_mask = 0;	/* jazz i/o interrupt enable mask */
     92 
     93 struct arc_bus_space jazzio_bus;
     94 
     95 int
     96 jazziomatch(struct device *parent, struct cfdata *match, void *aux)
     97 {
     98 	struct confargs *ca = aux;
     99 
    100         /* Make sure that we're looking for a jazzio bus. */
    101         if (strcmp(ca->ca_name, jazzio_cd.cd_name) != 0)
    102                 return 0;
    103 
    104 	return 1;
    105 }
    106 
    107 void
    108 jazzioattach(struct device *parent, struct device *self, void *aux)
    109 {
    110 	struct jazzio_softc *sc = (struct jazzio_softc *)self;
    111 	struct jazzio_attach_args ja;
    112 	int i;
    113 
    114 	if (jazzio_conf == NULL)
    115 		panic("jazzio_conf isn't initialized");
    116 	if (jazzio_devconfig == NULL)
    117 		panic("jazzio_devconfig isn't initialized");
    118 
    119 	jazzio_found = 1;
    120 
    121 	printf("\n");
    122 
    123 	/* keep our CPU device description handy */
    124 	sc->sc_devs = jazzio_devconfig;
    125 
    126 	/* initialize interrupt handler table */
    127 	for (i = 0; i < sizeof(jazzio_intrtab)/sizeof(jazzio_intrtab[0]); i++) {
    128 		jazzio_intrtab[i].ih_func = jazzio_no_handler;
    129 		jazzio_intrtab[i].ih_arg = NULL;
    130 	}
    131 
    132 	/* set up interrupt handlers */
    133 	(*platform->set_intr)(MIPS_INT_MASK_1, jazzio_intr, ARC_INTPRI_JAZZ);
    134 
    135 	/* Initialize jazzio DMA mapping register area and pool */
    136 	jazz_dmatlb_init(&jazzio_bus, jazzio_conf->jc_dmatlbreg);
    137 
    138 	/* Create bus_dma_tag */
    139 	jazz_bus_dma_tag_init(&sc->sc_dmat);
    140 
    141 	/* Try to configure each jazzio attached device */
    142 	for (i = 0; sc->sc_devs[i].ps_ca.ca_name != NULL; i++) {
    143 
    144 		ja.ja_name = sc->sc_devs[i].ps_ca.ca_name;
    145 		ja.ja_bust = &jazzio_bus;
    146 		ja.ja_dmat = &sc->sc_dmat;
    147 		ja.ja_addr = (bus_addr_t)sc->sc_devs[i].ps_base;
    148 		ja.ja_intr = sc->sc_devs[i].ps_ca.ca_slot;
    149 		ja.ja_dma = 0;
    150 
    151 		/* Tell the autoconfig machinery we've found the hardware. */
    152 		config_found(self, &ja, jazzioprint);
    153 	}
    154 }
    155 
    156 int
    157 jazzioprint(void *aux, const char *pnp)
    158 {
    159 	struct jazzio_attach_args *ja = aux;
    160 
    161 	if (pnp)
    162 		aprint_normal("%s at %s", ja->ja_name, pnp);
    163 	aprint_normal(" addr 0x%lx", ja->ja_addr);
    164 	if (ja->ja_intr != -1)
    165 		aprint_normal(" intr %d", ja->ja_intr);
    166 	return UNCONF;
    167 }
    168 
    169 void
    170 jazzio_intr_establish(int intr, intr_handler_t handler, void *val)
    171 {
    172 	struct jazzio_intrhand *jirp;
    173 
    174 	if (intr < 0 ||
    175 	    intr >= sizeof(jazzio_intrtab)/sizeof(jazzio_intrtab[0]))
    176 		panic("jazzio intr %d out of range", intr);
    177 	jirp = &jazzio_intrtab[intr];
    178 	if (jirp->ih_func != jazzio_no_handler)
    179 		panic("jazzio intr %d already set to %p", intr, jirp->ih_func);
    180 
    181 	jazzio_int_mask |= 1 << intr;
    182 	jirp->ih_func = handler;
    183 	jirp->ih_arg = val;
    184 	snprintf(jirp->ih_evname, sizeof(jirp->ih_evname), "intr %d", intr);
    185 	evcnt_attach_dynamic(&jirp->ih_evcnt, EVCNT_TYPE_INTR,
    186 	    NULL, "jazzio", jirp->ih_evname);
    187 
    188 	(*jazzio_conf->jc_set_iointr_mask)(jazzio_int_mask);
    189 }
    190 
    191 void
    192 jazzio_intr_disestablish(int intr)
    193 {
    194 	struct jazzio_intrhand *jirp;
    195 
    196 	jazzio_int_mask &= ~(1 << intr);
    197 	jirp = &jazzio_intrtab[intr];
    198 	jirp->ih_func = jazzio_no_handler;
    199 	jirp->ih_arg = NULL;
    200 	evcnt_detach(&jirp->ih_evcnt);
    201 
    202 	(*jazzio_conf->jc_set_iointr_mask)(jazzio_int_mask);
    203 }
    204 
    205 int
    206 jazzio_no_handler(void *arg)
    207 {
    208 
    209 	panic("uncaught jazzio interrupt with arg %p", arg);
    210 }
    211 
    212 /*
    213  *   Handle jazz i/o interrupt.
    214  */
    215 uint32_t
    216 jazzio_intr(uint32_t mask, struct clockframe *cf)
    217 {
    218 	unsigned int vector;
    219 	struct jazzio_intrhand *jirp;
    220 
    221 	while ((vector = inb(jazzio_conf->jc_iointr_status_reg)) != 0) {
    222 		jirp = &jazzio_intrtab[(vector >> 2) - 1];
    223 		(*jirp->ih_func)(jirp->ih_arg);
    224 		jirp->ih_evcnt.ev_count++;
    225 	}
    226 	return MIPS_INT_MASK_1;
    227 }
    228 
    229 void
    230 jazzio_reset(void)
    231 {
    232 
    233 	arc_sysreset(PICA_SYS_KBD, JAZZIO_KBCMDP);
    234 }
    235