1 /* $NetBSD: jazzio.c,v 1.15 2005/11/15 15:07:36 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@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.15 2005/11/15 15:07:36 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 void arc_sysreset(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 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, 2); 134 135 sc->sc_bus.ab_dv = (struct device *)sc; 136 137 /* Initialize jazzio DMA mapping register area and pool */ 138 jazz_dmatlb_init(&jazzio_bus, jazzio_conf->jc_dmatlbreg); 139 140 /* Create bus_dma_tag */ 141 jazz_bus_dma_tag_init(&sc->sc_dmat); 142 143 /* Try to configure each jazzio attached device */ 144 for (i = 0; sc->sc_devs[i].ps_ca.ca_name != NULL; i++) { 145 146 ja.ja_name = sc->sc_devs[i].ps_ca.ca_name; 147 ja.ja_bus = &sc->sc_bus; 148 ja.ja_bust = &jazzio_bus; 149 ja.ja_dmat = &sc->sc_dmat; 150 ja.ja_addr = (bus_addr_t)sc->sc_devs[i].ps_base; 151 ja.ja_intr = sc->sc_devs[i].ps_ca.ca_slot; 152 ja.ja_dma = 0; 153 154 /* Tell the autoconfig machinery we've found the hardware. */ 155 config_found(self, &ja, jazzioprint); 156 } 157 } 158 159 int 160 jazzioprint(void *aux, const char *pnp) 161 { 162 struct jazzio_attach_args *ja = aux; 163 164 if (pnp) 165 aprint_normal("%s at %s", ja->ja_name, pnp); 166 aprint_normal(" addr 0x%lx", ja->ja_addr); 167 if (ja->ja_intr != -1) 168 aprint_normal(" intr %d", ja->ja_intr); 169 return UNCONF; 170 } 171 172 void 173 jazzio_intr_establish(int intr, intr_handler_t handler, void *val) 174 { 175 struct jazzio_intrhand *jirp; 176 177 if (intr < 0 || 178 intr >= sizeof(jazzio_intrtab)/sizeof(jazzio_intrtab[0])) 179 panic("jazzio intr %d out of range", intr); 180 jirp = &jazzio_intrtab[intr]; 181 if (jirp->ih_func != jazzio_no_handler) 182 panic("jazzio intr %d already set to %p", intr, jirp->ih_func); 183 184 jazzio_int_mask |= 1 << intr; 185 jirp->ih_func = handler; 186 jirp->ih_arg = val; 187 snprintf(jirp->ih_evname, sizeof(jirp->ih_evname), "intr %d", intr); 188 evcnt_attach_dynamic(&jirp->ih_evcnt, EVCNT_TYPE_INTR, 189 NULL, "jazzio", jirp->ih_evname); 190 191 (*jazzio_conf->jc_set_iointr_mask)(jazzio_int_mask); 192 } 193 194 void 195 jazzio_intr_disestablish(int intr) 196 { 197 struct jazzio_intrhand *jirp; 198 199 jazzio_int_mask &= ~(1 << intr); 200 jirp = &jazzio_intrtab[intr]; 201 jirp->ih_func = jazzio_no_handler; 202 jirp->ih_arg = NULL; 203 evcnt_detach(&jirp->ih_evcnt); 204 205 (*jazzio_conf->jc_set_iointr_mask)(jazzio_int_mask); 206 } 207 208 int 209 jazzio_no_handler(void *arg) 210 { 211 212 panic("uncaught jazzio interrupt with arg %p", arg); 213 } 214 215 /* 216 * Handle jazz i/o interrupt. 217 */ 218 uint32_t 219 jazzio_intr(uint32_t mask, struct clockframe *cf) 220 { 221 unsigned int vector; 222 struct jazzio_intrhand *jirp; 223 224 while ((vector = inb(jazzio_conf->jc_iointr_status_reg)) != 0) { 225 jirp = &jazzio_intrtab[(vector >> 2) - 1]; 226 (*jirp->ih_func)(jirp->ih_arg); 227 jirp->ih_evcnt.ev_count++; 228 } 229 return ~MIPS_INT_MASK_1; 230 } 231 232 void 233 jazzio_reset(void) 234 { 235 236 arc_sysreset(PICA_SYS_KBD, JAZZIO_KBCMDP); 237 } 238