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