jazzio.c revision 1.12 1 /* $NetBSD: jazzio.c,v 1.12 2003/10/08 18:12:24 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.12 2003/10/08 18:12:24 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 __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_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(parent, match, aux)
97 struct device *parent;
98 struct cfdata *match;
99 void *aux;
100 {
101 struct confargs *ca = aux;
102
103 /* Make sure that we're looking for a jazzio bus. */
104 if (strcmp(ca->ca_name, jazzio_cd.cd_name) != 0)
105 return (0);
106
107 return (1);
108 }
109
110 void
111 jazzioattach(parent, self, aux)
112 struct device *parent;
113 struct device *self;
114 void *aux;
115 {
116 struct jazzio_softc *sc = (struct jazzio_softc *)self;
117 struct jazzio_attach_args ja;
118 int i;
119
120 if (jazzio_conf == NULL)
121 panic("jazzio_conf isn't initialized");
122 if (jazzio_devconfig == NULL)
123 panic("jazzio_devconfig isn't initialized");
124
125 jazzio_found = 1;
126
127 printf("\n");
128
129 /* keep our CPU device description handy */
130 sc->sc_devs = jazzio_devconfig;
131
132 /* initialize interrupt handler table */
133 for (i = 0; i < sizeof(jazzio_intrtab)/sizeof(jazzio_intrtab[0]); i++) {
134 jazzio_intrtab[i].ih_func = jazzio_no_handler;
135 jazzio_intrtab[i].ih_arg = NULL;
136 }
137
138 /* set up interrupt handlers */
139 (*platform->set_intr)(MIPS_INT_MASK_1, jazzio_intr, 2);
140
141 sc->sc_bus.ab_dv = (struct device *)sc;
142
143 /* Initialize jazzio DMA mapping register area and pool */
144 jazz_dmatlb_init(&jazzio_bus, jazzio_conf->jc_dmatlbreg);
145
146 /* Create bus_dma_tag */
147 jazz_bus_dma_tag_init(&sc->sc_dmat);
148
149 /* Try to configure each jazzio attached device */
150 for (i = 0; sc->sc_devs[i].ps_ca.ca_name != NULL; i++) {
151
152 ja.ja_name = sc->sc_devs[i].ps_ca.ca_name;
153 ja.ja_bus = &sc->sc_bus;
154 ja.ja_bust = &jazzio_bus;
155 ja.ja_dmat = &sc->sc_dmat;
156 ja.ja_addr = (bus_addr_t)sc->sc_devs[i].ps_base;
157 ja.ja_intr = sc->sc_devs[i].ps_ca.ca_slot;
158 ja.ja_dma = 0;
159
160 /* Tell the autoconfig machinery we've found the hardware. */
161 config_found(self, &ja, jazzioprint);
162 }
163 }
164
165 int
166 jazzioprint(aux, pnp)
167 void *aux;
168 const char *pnp;
169 {
170 struct jazzio_attach_args *ja = aux;
171
172 if (pnp)
173 aprint_normal("%s at %s", ja->ja_name, pnp);
174 aprint_normal(" addr 0x%lx", ja->ja_addr);
175 if (ja->ja_intr != -1)
176 aprint_normal(" intr %d", ja->ja_intr);
177 return (UNCONF);
178 }
179
180 void
181 jazzio_intr_establish(intr, handler, val)
182 int intr;
183 intr_handler_t handler;
184 void *val;
185 {
186 struct jazzio_intrhand *jirp;
187
188 if (intr < 0 ||
189 intr >= sizeof(jazzio_intrtab)/sizeof(jazzio_intrtab[0]))
190 panic("jazzio intr %d out of range", intr);
191 jirp = &jazzio_intrtab[intr];
192 if (jirp->ih_func != jazzio_no_handler)
193 panic("jazzio intr %d already set to %p", intr, jirp->ih_func);
194
195 jazzio_int_mask |= 1 << intr;
196 jirp->ih_func = handler;
197 jirp->ih_arg = val;
198 snprintf(jirp->ih_evname, sizeof(jirp->ih_evname), "intr %d", intr);
199 evcnt_attach_dynamic(&jirp->ih_evcnt, EVCNT_TYPE_INTR,
200 NULL, "jazzio", jirp->ih_evname);
201
202 (*jazzio_conf->jc_set_iointr_mask)(jazzio_int_mask);
203 }
204
205 void
206 jazzio_intr_disestablish(intr)
207 int intr;
208 {
209 struct jazzio_intrhand *jirp;
210
211 jazzio_int_mask &= ~(1 << intr);
212 jirp = &jazzio_intrtab[intr];
213 jirp->ih_func = jazzio_no_handler;
214 jirp->ih_arg = NULL;
215 evcnt_detach(&jirp->ih_evcnt);
216
217 (*jazzio_conf->jc_set_iointr_mask)(jazzio_int_mask);
218 }
219
220 int
221 jazzio_no_handler(arg)
222 void *arg;
223 {
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_intrhand *jirp;
238
239 while ((vector = inb(jazzio_conf->jc_iointr_status_reg)) != 0) {
240 jirp = &jazzio_intrtab[(vector >> 2) - 1];
241 (*jirp->ih_func)(jirp->ih_arg);
242 jirp->ih_evcnt.ev_count++;
243 }
244 return (~0); /* Don't reenable */
245 }
246
247 void
248 jazzio_reset()
249 {
250
251 arc_sysreset(PICA_SYS_KBD, JAZZIO_KBCMDP);
252 }
253