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