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