plumicu.c revision 1.1 1 1.1 uch /* $NetBSD: plumicu.c,v 1.1 1999/11/21 06:50:26 uch Exp $ */
2 1.1 uch
3 1.1 uch /*
4 1.1 uch * Copyright (c) 1999, by UCHIYAMA Yasushi
5 1.1 uch * All rights reserved.
6 1.1 uch *
7 1.1 uch * Redistribution and use in source and binary forms, with or without
8 1.1 uch * modification, are permitted provided that the following conditions
9 1.1 uch * are met:
10 1.1 uch * 1. Redistributions of source code must retain the above copyright
11 1.1 uch * notice, this list of conditions and the following disclaimer.
12 1.1 uch * 2. The name of the developer may NOT be used to endorse or promote products
13 1.1 uch * derived from this software without specific prior written permission.
14 1.1 uch *
15 1.1 uch * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 1.1 uch * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 1.1 uch * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 1.1 uch * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 1.1 uch * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 1.1 uch * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 1.1 uch * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 1.1 uch * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 1.1 uch * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 1.1 uch * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 1.1 uch * SUCH DAMAGE.
26 1.1 uch *
27 1.1 uch */
28 1.1 uch
29 1.1 uch #include "opt_tx39_debug.h"
30 1.1 uch
31 1.1 uch #include <sys/param.h>
32 1.1 uch #include <sys/systm.h>
33 1.1 uch #include <sys/device.h>
34 1.1 uch #include <sys/malloc.h>
35 1.1 uch #include <sys/queue.h>
36 1.1 uch #define TAILQ_FOREACH(var, head, field) \
37 1.1 uch for (var = TAILQ_FIRST(head); var; var = TAILQ_NEXT(var, field))
38 1.1 uch #define TAILQ_EMPTY(head) ((head)->tqh_first == NULL)
39 1.1 uch
40 1.1 uch #include <machine/bus.h>
41 1.1 uch #include <machine/intr.h>
42 1.1 uch
43 1.1 uch #include <hpcmips/tx/tx39var.h>
44 1.1 uch #include <hpcmips/dev/plumvar.h>
45 1.1 uch #include <hpcmips/dev/plumicuvar.h>
46 1.1 uch #include <hpcmips/dev/plumicureg.h>
47 1.1 uch
48 1.1 uch #define PLUMICUDEBUG
49 1.1 uch #ifdef PLUMICUDEBUG
50 1.1 uch #define DPRINTF(arg) printf arg
51 1.1 uch #else
52 1.1 uch #define DPRINTF(arg)
53 1.1 uch #endif
54 1.1 uch
55 1.1 uch int plumicu_match __P((struct device*, struct cfdata*, void*));
56 1.1 uch void plumicu_attach __P((struct device*, struct device*, void*));
57 1.1 uch int plumicu_intr __P((void*));
58 1.1 uch
59 1.1 uch struct plum_intr_ctrl {
60 1.1 uch plumreg_t ic_ackpat1;
61 1.1 uch plumreg_t ic_ackpat2;
62 1.1 uch int ic_ackreg2;
63 1.1 uch plumreg_t ic_ienpat;
64 1.1 uch int ic_ienreg;
65 1.1 uch plumreg_t ic_senpat;
66 1.1 uch int ic_senreg;
67 1.1 uch } pi_ctrl[] = {
68 1.1 uch [PLUM_INT_C1IO] = {PLUM_INT_INTSTA_PCCINT,
69 1.1 uch PLUM_INT_PCCINTS_C1IO, PLUM_INT_PCCINTS_REG,
70 1.1 uch PLUM_INT_PCCIEN_IENC1IO, PLUM_INT_PCCIEN_REG,
71 1.1 uch PLUM_INT_PCCIEN_SENC1IO, PLUM_INT_PCCIEN_REG
72 1.1 uch },
73 1.1 uch [PLUM_INT_C1RI] = {PLUM_INT_INTSTA_PCCINT,
74 1.1 uch PLUM_INT_PCCINTS_C1RI, PLUM_INT_PCCINTS_REG,
75 1.1 uch PLUM_INT_PCCIEN_IENC1RI, PLUM_INT_PCCIEN_REG,
76 1.1 uch PLUM_INT_PCCIEN_SENC1RI, PLUM_INT_PCCIEN_REG
77 1.1 uch },
78 1.1 uch [PLUM_INT_C1SC] = {PLUM_INT_INTSTA_C1SCINT, 0, 0, 0, 0, 0, 0},
79 1.1 uch [PLUM_INT_C2IO] = {PLUM_INT_INTSTA_PCCINT,
80 1.1 uch PLUM_INT_PCCINTS_C2IO, PLUM_INT_PCCINTS_REG,
81 1.1 uch PLUM_INT_PCCIEN_IENC2IO, PLUM_INT_PCCIEN_REG,
82 1.1 uch PLUM_INT_PCCIEN_SENC2IO, PLUM_INT_PCCIEN_REG
83 1.1 uch },
84 1.1 uch [PLUM_INT_C2RI] = {PLUM_INT_INTSTA_PCCINT,
85 1.1 uch PLUM_INT_PCCINTS_C2RI, PLUM_INT_PCCINTS_REG,
86 1.1 uch PLUM_INT_PCCIEN_IENC2RI, PLUM_INT_PCCIEN_REG,
87 1.1 uch PLUM_INT_PCCIEN_SENC2RI, PLUM_INT_PCCIEN_REG
88 1.1 uch },
89 1.1 uch [PLUM_INT_C2SC] = {PLUM_INT_INTSTA_C2SCINT, 0, 0, 0, 0, 0, 0},
90 1.1 uch [PLUM_INT_DISP] = {PLUM_INT_INTSTA_DISPINT, 0, 0, 0, 0, 0, 0},
91 1.1 uch [PLUM_INT_USB] = {PLUM_INT_INTSTA_USBINT,
92 1.1 uch 0, 0,
93 1.1 uch PLUM_INT_USBINTEN_IEN, PLUM_INT_USBINTEN_REG,
94 1.1 uch 0, 0
95 1.1 uch },
96 1.1 uch [PLUM_INT_USBWAKE] = {PLUM_INT_INTSTA_USBWAKE,
97 1.1 uch 0, 0,
98 1.1 uch PLUM_INT_USBINTEN_WIEN, PLUM_INT_USBINTEN_REG,
99 1.1 uch 0, 0
100 1.1 uch },
101 1.1 uch [PLUM_INT_SM] = {PLUM_INT_INTSTA_SMINT,
102 1.1 uch 0, 0,
103 1.1 uch PLUM_INT_SMIEN, PLUM_INT_SMIEN_REG,
104 1.1 uch 0, 0
105 1.1 uch },
106 1.1 uch [PLUM_INT_EXT5IO0] = {PLUM_INT_INTSTA_EXTINT,
107 1.1 uch PLUM_INT_EXTINTS_IO5INT0, PLUM_INT_EXTINTS_REG,
108 1.1 uch PLUM_INT_EXTIEN_IENIO5INT0, PLUM_INT_EXTIEN_REG,
109 1.1 uch PLUM_INT_EXTIEN_SENIO5INT0, PLUM_INT_EXTIEN_REG,
110 1.1 uch },
111 1.1 uch [PLUM_INT_EXT5IO1] = {PLUM_INT_INTSTA_EXTINT,
112 1.1 uch PLUM_INT_EXTINTS_IO5INT1, PLUM_INT_EXTINTS_REG,
113 1.1 uch PLUM_INT_EXTIEN_IENIO5INT1, PLUM_INT_EXTIEN_REG,
114 1.1 uch PLUM_INT_EXTIEN_SENIO5INT1, PLUM_INT_EXTIEN_REG,
115 1.1 uch },
116 1.1 uch [PLUM_INT_EXT5IO2] = {PLUM_INT_INTSTA_EXTINT,
117 1.1 uch PLUM_INT_EXTINTS_IO5INT2, PLUM_INT_EXTINTS_REG,
118 1.1 uch PLUM_INT_EXTIEN_IENIO5INT2, PLUM_INT_EXTIEN_REG,
119 1.1 uch PLUM_INT_EXTIEN_SENIO5INT2, PLUM_INT_EXTIEN_REG,
120 1.1 uch },
121 1.1 uch [PLUM_INT_EXT5IO3] = {PLUM_INT_INTSTA_EXTINT,
122 1.1 uch PLUM_INT_EXTINTS_IO5INT3, PLUM_INT_EXTINTS_REG,
123 1.1 uch PLUM_INT_EXTIEN_IENIO5INT0, PLUM_INT_EXTIEN_REG,
124 1.1 uch PLUM_INT_EXTIEN_SENIO5INT0, PLUM_INT_EXTIEN_REG,
125 1.1 uch },
126 1.1 uch [PLUM_INT_EXT3IO0] = {PLUM_INT_INTSTA_EXTINT,
127 1.1 uch PLUM_INT_EXTINTS_IO3INT0, PLUM_INT_EXTINTS_REG,
128 1.1 uch PLUM_INT_EXTIEN_IENIO3INT0, PLUM_INT_EXTIEN_REG,
129 1.1 uch PLUM_INT_EXTIEN_SENIO3INT0, PLUM_INT_EXTIEN_REG,
130 1.1 uch },
131 1.1 uch [PLUM_INT_EXT3IO1] = {PLUM_INT_INTSTA_EXTINT,
132 1.1 uch PLUM_INT_EXTINTS_IO3INT1, PLUM_INT_EXTINTS_REG,
133 1.1 uch PLUM_INT_EXTIEN_IENIO3INT1, PLUM_INT_EXTIEN_REG,
134 1.1 uch PLUM_INT_EXTIEN_SENIO3INT1, PLUM_INT_EXTIEN_REG,
135 1.1 uch }
136 1.1 uch };
137 1.1 uch
138 1.1 uch struct plum_intr_entry {
139 1.1 uch int pi_line;
140 1.1 uch int (*pi_fun) __P((void*));
141 1.1 uch void *pi_arg;
142 1.1 uch struct plum_intr_ctrl *pi_ctrl;
143 1.1 uch TAILQ_ENTRY(plum_intr_entry) pi_link;
144 1.1 uch };
145 1.1 uch
146 1.1 uch struct plumicu_softc {
147 1.1 uch struct device sc_dev;
148 1.1 uch plum_chipset_tag_t sc_pc;
149 1.1 uch bus_space_tag_t sc_regt;
150 1.1 uch bus_space_handle_t sc_regh;
151 1.1 uch void *sc_ih;
152 1.1 uch int sc_enable_count;
153 1.1 uch TAILQ_HEAD(, plum_intr_entry) sc_pi_head[PLUM_INTR_MAX];
154 1.1 uch };
155 1.1 uch
156 1.1 uch struct cfattach plumicu_ca = {
157 1.1 uch sizeof(struct plumicu_softc), plumicu_match, plumicu_attach
158 1.1 uch };
159 1.1 uch
160 1.1 uch void plumicu_dump __P((struct plumicu_softc*));
161 1.1 uch
162 1.1 uch int
163 1.1 uch plumicu_match(parent, cf, aux)
164 1.1 uch struct device *parent;
165 1.1 uch struct cfdata *cf;
166 1.1 uch void *aux;
167 1.1 uch {
168 1.1 uch return 2; /* 1st attach group */
169 1.1 uch }
170 1.1 uch
171 1.1 uch void
172 1.1 uch plumicu_attach(parent, self, aux)
173 1.1 uch struct device *parent;
174 1.1 uch struct device *self;
175 1.1 uch void *aux;
176 1.1 uch {
177 1.1 uch struct plum_attach_args *pa = aux;
178 1.1 uch struct plumicu_softc *sc = (void*)self;
179 1.1 uch struct plum_intr_ctrl *pic;
180 1.1 uch bus_space_tag_t regt;
181 1.1 uch bus_space_handle_t regh;
182 1.1 uch plumreg_t reg;
183 1.1 uch int i;
184 1.1 uch
185 1.1 uch sc->sc_pc = pa->pa_pc;
186 1.1 uch sc->sc_regt = pa->pa_regt;
187 1.1 uch
188 1.1 uch /* map plum2 interrupt controller register space */
189 1.1 uch if (bus_space_map(sc->sc_regt, PLUM_INT_REGBASE,
190 1.1 uch PLUM_INT_REGSIZE, 0, &sc->sc_regh)) {
191 1.1 uch printf(":interrupt register map failed\n");
192 1.1 uch return;
193 1.1 uch }
194 1.1 uch
195 1.1 uch /* disable all interrupt */
196 1.1 uch regt = sc->sc_regt;
197 1.1 uch regh = sc->sc_regh;
198 1.1 uch for (i = 0; i < PLUM_INTR_MAX; i++) {
199 1.1 uch pic = &pi_ctrl[i];
200 1.1 uch if (pic->ic_ienreg) {
201 1.1 uch reg = plum_conf_read(regt, regh, pic->ic_ienreg);
202 1.1 uch reg &= ~pic->ic_ienpat;
203 1.1 uch plum_conf_write(regt, regh, pic->ic_ienreg, reg);
204 1.1 uch }
205 1.1 uch if (pic->ic_senreg) {
206 1.1 uch reg = plum_conf_read(regt, regh, pic->ic_senreg);
207 1.1 uch reg &= ~pic->ic_senpat;
208 1.1 uch plum_conf_write(regt, regh, pic->ic_senreg, reg);
209 1.1 uch }
210 1.1 uch }
211 1.1 uch
212 1.1 uch for (i = 0; i < PLUM_INTR_MAX; i++) {
213 1.1 uch TAILQ_INIT(&sc->sc_pi_head[i]);
214 1.1 uch }
215 1.1 uch
216 1.1 uch /* register handle to plum_chipset_tag */
217 1.1 uch plum_conf_register_intr(sc->sc_pc, (void*)sc);
218 1.1 uch
219 1.1 uch /* disable interrupt redirect to TX39 core */
220 1.1 uch plum_conf_write(sc->sc_regt, sc->sc_regh, PLUM_INT_INTIEN_REG, 0);
221 1.1 uch
222 1.1 uch if (!(sc->sc_ih = tx_intr_establish(sc->sc_pc->pc_tc, pa->pa_irq,
223 1.1 uch IST_EDGE, IPL_BIO, plumicu_intr, sc))) {
224 1.1 uch printf(": can't establish interrupt\n");
225 1.1 uch }
226 1.1 uch printf("\n");
227 1.1 uch
228 1.1 uch plumicu_dump(sc);
229 1.1 uch }
230 1.1 uch
231 1.1 uch void*
232 1.1 uch plum_intr_establish(pc, line, mode, level, ih_fun, ih_arg)
233 1.1 uch plum_chipset_tag_t pc;
234 1.1 uch int line;
235 1.1 uch int mode; /* no meaning */
236 1.1 uch int level; /* XXX not yet */
237 1.1 uch int (*ih_fun) __P((void*));
238 1.1 uch void *ih_arg;
239 1.1 uch {
240 1.1 uch struct plumicu_softc *sc = pc->pc_intrt;
241 1.1 uch bus_space_tag_t regt = sc->sc_regt;
242 1.1 uch bus_space_handle_t regh = sc->sc_regh;
243 1.1 uch plumreg_t reg;
244 1.1 uch struct plum_intr_entry *pi;
245 1.1 uch
246 1.1 uch if (!LEGAL_PRUM_INTR(line)) {
247 1.1 uch panic("plum_intr_establish: bogus interrupt line");
248 1.1 uch }
249 1.1 uch
250 1.1 uch if (!(pi = malloc(sizeof(struct plum_intr_entry),
251 1.1 uch M_DEVBUF, M_NOWAIT))) {
252 1.1 uch panic ("plum_intr_establish: no memory.");
253 1.1 uch }
254 1.1 uch
255 1.1 uch memset(pi, 0, sizeof(struct plum_intr_entry));
256 1.1 uch pi->pi_line = line;
257 1.1 uch pi->pi_fun = ih_fun;
258 1.1 uch pi->pi_arg = ih_arg;
259 1.1 uch pi->pi_ctrl = &pi_ctrl[line];
260 1.1 uch TAILQ_INSERT_TAIL(&sc->sc_pi_head[line], pi, pi_link);
261 1.1 uch
262 1.1 uch /* Enable interrupt */
263 1.1 uch if (pi->pi_ctrl->ic_ienreg) {
264 1.1 uch reg = plum_conf_read(regt, regh, pi->pi_ctrl->ic_ienreg);
265 1.1 uch reg |= pi->pi_ctrl->ic_ienpat;
266 1.1 uch plum_conf_write(regt, regh, pi->pi_ctrl->ic_ienreg, reg);
267 1.1 uch }
268 1.1 uch if (pi->pi_ctrl->ic_senreg) {
269 1.1 uch reg = plum_conf_read(regt, regh, pi->pi_ctrl->ic_senreg);
270 1.1 uch reg |= pi->pi_ctrl->ic_senpat;
271 1.1 uch plum_conf_write(regt, regh, pi->pi_ctrl->ic_senreg, reg);
272 1.1 uch }
273 1.1 uch
274 1.1 uch /* Enable redirect to TX39 core */
275 1.1 uch DPRINTF(("plum_intr_establish: %d (count=%d)\n", line, sc->sc_enable_count));
276 1.1 uch sc->sc_enable_count++;
277 1.1 uch plum_conf_write(regt, regh, PLUM_INT_INTIEN_REG, 1);
278 1.1 uch
279 1.1 uch return ih_fun;
280 1.1 uch }
281 1.1 uch
282 1.1 uch void
283 1.1 uch plum_intr_disestablish(pc, arg)
284 1.1 uch plum_chipset_tag_t pc;
285 1.1 uch void *arg;
286 1.1 uch {
287 1.1 uch struct plumicu_softc *sc = pc->pc_intrt;
288 1.1 uch bus_space_tag_t regt = sc->sc_regt;
289 1.1 uch bus_space_handle_t regh = sc->sc_regh;
290 1.1 uch plumreg_t reg;
291 1.1 uch struct plum_intr_entry *pi;
292 1.1 uch int i;
293 1.1 uch
294 1.1 uch sc = pc->pc_intrt;
295 1.1 uch for (i = 0; i < PLUM_INTR_MAX; i++) {
296 1.1 uch TAILQ_FOREACH(pi, &sc->sc_pi_head[i], pi_link) {
297 1.1 uch if (pi->pi_fun == arg) {
298 1.1 uch TAILQ_REMOVE(&sc->sc_pi_head[i], pi, pi_link);
299 1.1 uch DPRINTF(("plum_intr_disestablish: %d (count=%d)\n",
300 1.1 uch pi->pi_line, sc->sc_enable_count - 1));
301 1.1 uch free(pi, M_DEVBUF);
302 1.1 uch goto found;
303 1.1 uch }
304 1.1 uch }
305 1.1 uch }
306 1.1 uch panic("plum_intr_disestablish: can't find entry.");
307 1.1 uch found:
308 1.1 uch /* Disable interrupt */
309 1.1 uch if (pi->pi_ctrl->ic_ienreg) {
310 1.1 uch reg = plum_conf_read(regt, regh, pi->pi_ctrl->ic_ienreg);
311 1.1 uch reg &= ~(pi->pi_ctrl->ic_ienpat);
312 1.1 uch plum_conf_write(regt, regh, pi->pi_ctrl->ic_ienreg, reg);
313 1.1 uch }
314 1.1 uch if (pi->pi_ctrl->ic_senreg) {
315 1.1 uch reg = plum_conf_read(regt, regh, pi->pi_ctrl->ic_senreg);
316 1.1 uch reg &= ~(pi->pi_ctrl->ic_senpat);
317 1.1 uch plum_conf_write(regt, regh, pi->pi_ctrl->ic_senreg, reg);
318 1.1 uch }
319 1.1 uch
320 1.1 uch /* Disable redirect to TX39 core */
321 1.1 uch if (--sc->sc_enable_count == 0) {
322 1.1 uch /* Disable redirect to TX39 core to avoid lost interrupt */
323 1.1 uch plum_conf_write(regt, regh, PLUM_INT_INTIEN_REG, 0);
324 1.1 uch }
325 1.1 uch }
326 1.1 uch
327 1.1 uch int
328 1.1 uch plumicu_intr(arg)
329 1.1 uch void *arg;
330 1.1 uch {
331 1.1 uch struct plumicu_softc *sc = arg;
332 1.1 uch struct plum_intr_entry *pi;
333 1.1 uch bus_space_tag_t regt = sc->sc_regt;
334 1.1 uch bus_space_handle_t regh = sc->sc_regh;
335 1.1 uch plumreg_t reg1, reg2;
336 1.1 uch int i;
337 1.1 uch
338 1.1 uch reg1 = plum_conf_read(regt, regh, PLUM_INT_INTSTA_REG);
339 1.1 uch for (i = 0; i < PLUM_INTR_MAX; i++) {
340 1.1 uch struct plum_intr_ctrl *pic = &pi_ctrl[i];
341 1.1 uch if (pic->ic_ackpat1 & reg1) {
342 1.1 uch if (pic->ic_ackpat2) {
343 1.1 uch reg2 = plum_conf_read(regt, regh,
344 1.1 uch pic->ic_ackreg2);
345 1.1 uch TAILQ_FOREACH(pi, &sc->sc_pi_head[i],
346 1.1 uch pi_link) {
347 1.1 uch if (pi->pi_ctrl->ic_ackpat2 & reg2) {
348 1.1 uch plum_conf_write(
349 1.1 uch regt, regh,
350 1.1 uch pic->ic_ackreg2,
351 1.1 uch pi->pi_ctrl->ic_ackpat2);
352 1.1 uch (*pi->pi_fun)(pi->pi_arg);
353 1.1 uch }
354 1.1 uch }
355 1.1 uch } else {
356 1.1 uch TAILQ_FOREACH(pi, &sc->sc_pi_head[i],
357 1.1 uch pi_link) {
358 1.1 uch (*pi->pi_fun)(pi->pi_arg);
359 1.1 uch printf("INT(2) %d:", i);
360 1.1 uch }
361 1.1 uch }
362 1.1 uch }
363 1.1 uch }
364 1.1 uch
365 1.1 uch return 0;
366 1.1 uch }
367 1.1 uch
368 1.1 uch void
369 1.1 uch plumicu_dump(sc)
370 1.1 uch struct plumicu_softc *sc;
371 1.1 uch {
372 1.1 uch bus_space_tag_t regt = sc->sc_regt;
373 1.1 uch bus_space_handle_t regh = sc->sc_regh;
374 1.1 uch plumreg_t reg;
375 1.1 uch
376 1.1 uch printf("status:");
377 1.1 uch reg = plum_conf_read(regt, regh, PLUM_INT_INTSTA_REG);
378 1.1 uch bitdisp(reg);
379 1.1 uch printf("ExtIO\n");
380 1.1 uch printf("status:");
381 1.1 uch reg = plum_conf_read(regt, regh, PLUM_INT_EXTINTS_REG);
382 1.1 uch bitdisp(reg);
383 1.1 uch printf("enable:");
384 1.1 uch reg = plum_conf_read(regt, regh, PLUM_INT_EXTIEN_REG);
385 1.1 uch bitdisp(reg);
386 1.1 uch
387 1.1 uch }
388