1 /* $NetBSD: jazzio.c,v 1.7 2002/10/02 04:59:49 thorpej 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/param.h> 34 #include <sys/systm.h> 35 #include <sys/device.h> 36 37 #include <machine/bus.h> 38 #include <machine/pio.h> 39 #include <machine/autoconf.h> 40 #include <machine/platform.h> 41 42 #include <arc/jazz/jazziovar.h> 43 #include <arc/jazz/pica.h> 44 #include <arc/jazz/jazzdmatlbreg.h> 45 #include <arc/jazz/dma.h> 46 #include <arc/jazz/pckbc_jazzioreg.h> 47 48 void arc_sysreset __P((bus_addr_t, bus_size_t)); 49 50 struct jazzio_softc { 51 struct device sc_dv; 52 struct abus sc_bus; 53 struct arc_bus_dma_tag sc_dmat; 54 struct pica_dev *sc_devs; 55 }; 56 57 /* Definition of the driver for autoconfig. */ 58 int jazziomatch(struct device *, struct cfdata *, void *); 59 void jazzioattach(struct device *, struct device *, void *); 60 int jazzioprint(void *, const char *); 61 62 CFATTACH_DECL(jazzio, sizeof(struct jazzio_softc), 63 jazziomatch, jazzioattach, NULL, NULL); 64 extern struct cfdriver jazzio_cd; 65 66 void jazzio_intr_establish(int, int (*)(void *), void *); 67 void jazzio_intr_disestablish(int); 68 int jazzio_intr(unsigned, struct clockframe *); 69 int jazzio_no_handler __P((void *)); 70 71 /* 72 * Interrupt dispatch table for jazz i/o bus. 73 */ 74 struct jazzio_intr_registry { 75 intr_handler_t int_hand; /* Interrupt handler */ 76 void *param; /* Parameter to send to handler */ 77 }; 78 79 struct jazzio_intr_registry jazzio_intrtab[] = { 80 { jazzio_no_handler, (void *)NULL, }, /* 0 */ 81 { jazzio_no_handler, (void *)NULL, }, /* 1 */ 82 { jazzio_no_handler, (void *)NULL, }, /* 2 */ 83 { jazzio_no_handler, (void *)NULL, }, /* 3 */ 84 { jazzio_no_handler, (void *)NULL, }, /* 4 */ 85 { jazzio_no_handler, (void *)NULL, }, /* 5 */ 86 { jazzio_no_handler, (void *)NULL, }, /* 6 */ 87 { jazzio_no_handler, (void *)NULL, }, /* 7 */ 88 { jazzio_no_handler, (void *)NULL, }, /* 8 */ 89 { jazzio_no_handler, (void *)NULL, }, /* 9 */ 90 { jazzio_no_handler, (void *)NULL, }, /* 10 */ 91 { jazzio_no_handler, (void *)NULL, }, /* 11 */ 92 { jazzio_no_handler, (void *)NULL, }, /* 12 */ 93 { jazzio_no_handler, (void *)NULL, }, /* 13 */ 94 { jazzio_no_handler, (void *)NULL, }, /* 14 */ 95 { jazzio_no_handler, (void *)NULL, }, /* 15 */ 96 }; 97 98 99 struct jazzio_config *jazzio_conf = NULL; 100 struct pica_dev *jazzio_devconfig = NULL; 101 int jazzio_found = 0; 102 int jazzio_int_mask = 0; /* jazz i/o interrupt enable mask */ 103 104 struct arc_bus_space jazzio_bus; 105 106 int 107 jazziomatch(parent, match, aux) 108 struct device *parent; 109 struct cfdata *match; 110 void *aux; 111 { 112 struct confargs *ca = aux; 113 114 /* Make sure that we're looking for a jazzio bus. */ 115 if (strcmp(ca->ca_name, jazzio_cd.cd_name) != 0) 116 return (0); 117 118 return (1); 119 } 120 121 void 122 jazzioattach(parent, self, aux) 123 struct device *parent; 124 struct device *self; 125 void *aux; 126 { 127 struct jazzio_softc *sc = (struct jazzio_softc *)self; 128 struct jazzio_attach_args ja; 129 int i; 130 131 if (jazzio_conf == NULL) 132 panic("jazzio_conf isn't initialized"); 133 if (jazzio_devconfig == NULL) 134 panic("jazzio_devconfig isn't initialized"); 135 136 jazzio_found = 1; 137 138 printf("\n"); 139 140 /* keep our CPU device description handy */ 141 sc->sc_devs = jazzio_devconfig; 142 143 /* set up interrupt handlers */ 144 (*platform->set_intr)(MIPS_INT_MASK_1, jazzio_intr, 2); 145 146 sc->sc_bus.ab_dv = (struct device *)sc; 147 148 /* Initialize PICA Dma */ 149 picaDmaInit(); 150 151 /* Create bus_dma_tag */ 152 jazz_bus_dma_tag_init(&sc->sc_dmat); 153 154 /* Try to configure each jazzio attached device */ 155 for (i = 0; sc->sc_devs[i].ps_ca.ca_name != NULL; i++) { 156 157 ja.ja_name = sc->sc_devs[i].ps_ca.ca_name; 158 ja.ja_bus = &sc->sc_bus; 159 ja.ja_bust = &jazzio_bus; 160 ja.ja_dmat = &sc->sc_dmat; 161 ja.ja_addr = (bus_addr_t)sc->sc_devs[i].ps_base; 162 ja.ja_intr = sc->sc_devs[i].ps_ca.ca_slot; 163 ja.ja_dma = 0; 164 165 /* Tell the autoconfig machinery we've found the hardware. */ 166 config_found(self, &ja, jazzioprint); 167 } 168 } 169 170 int 171 jazzioprint(aux, pnp) 172 void *aux; 173 const char *pnp; 174 { 175 struct jazzio_attach_args *ja = aux; 176 177 if (pnp) 178 printf("%s at %s", ja->ja_name, pnp); 179 printf(" addr 0x%lx", ja->ja_addr); 180 if (ja->ja_intr != -1) 181 printf(" intr %d", ja->ja_intr); 182 return (UNCONF); 183 } 184 185 void 186 jazzio_intr_establish(intr, handler, val) 187 int intr; 188 intr_handler_t handler; 189 void *val; 190 { 191 if (intr < 0 || 192 intr >= sizeof(jazzio_intrtab)/sizeof(jazzio_intrtab[0])) { 193 panic("jazzio intr %d out of range", intr); 194 } else if (jazzio_intrtab[intr].int_hand != jazzio_no_handler) { 195 panic("jazzio intr %d already set to %p", intr, 196 jazzio_intrtab[intr].int_hand); 197 } else { 198 jazzio_int_mask |= 1 << intr; 199 jazzio_intrtab[intr].int_hand = handler; 200 jazzio_intrtab[intr].param = val; 201 } 202 203 (*jazzio_conf->jc_set_iointr_mask)(jazzio_int_mask); 204 } 205 206 void 207 jazzio_intr_disestablish(intr) 208 int intr; 209 { 210 jazzio_int_mask &= ~(1 << intr); 211 jazzio_intrtab[intr].int_hand = jazzio_no_handler; 212 jazzio_intrtab[intr].param = (void *)NULL; 213 214 (*jazzio_conf->jc_set_iointr_mask)(jazzio_int_mask); 215 } 216 217 int 218 jazzio_no_handler(arg) 219 void *arg; 220 { 221 panic("uncaught jazzio interrupt with arg %p", arg); 222 } 223 224 /* 225 * Handle jazz i/o interrupt. 226 */ 227 int 228 jazzio_intr(mask, cf) 229 unsigned mask; 230 struct clockframe *cf; 231 { 232 unsigned int vector; 233 struct jazzio_intr_registry *jirp; 234 235 while ((vector = inb(jazzio_conf->jc_iointr_status_reg)) != 0) { 236 jirp = &jazzio_intrtab[(vector >> 2) - 1]; 237 (*jirp->int_hand)(jirp->param); 238 } 239 return (~0); /* Dont reenable */ 240 } 241 242 void 243 jazzio_reset() 244 { 245 arc_sysreset(PICA_SYS_KBD, JAZZIO_KBCMDP); 246 } 247