1 /* $NetBSD: frodo.c,v 1.28 2008/03/29 06:47:07 tsutsui Exp $ */
4 * Copyright (c) 1997, 1998, 1999 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
33 * Copyright (c) 1997 Michael Smith. All rights reserved.
35 * Redistribution and use in source and binary forms, with or without
36 * modification, are permitted provided that the following conditions
38 * 1. Redistributions of source code must retain the above copyright
39 * notice, this list of conditions and the following disclaimer.
40 * 2. Redistributions in binary form must reproduce the above copyright
41 * notice, this list of conditions and the following disclaimer in the
42 * documentation and/or other materials provided with the distribution.
44 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
45 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
46 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
47 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
48 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
49 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
50 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
51 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
52 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
53 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
58 * Support for the "Frodo" (a.k.a. "Apollo Utility") chip found
59 * in HP Apollo 9000/4xx workstations, as well as
60 * HP 9000/362 and 9000/382 controllers.
63 #include <sys/cdefs.h>
64 __KERNEL_RCSID(0, "$NetBSD: frodo.c,v 1.28 2008/03/29 06:47:07 tsutsui Exp $");
66 #define _HP300_INTR_H_PRIVATE
68 #include <sys/param.h>
69 #include <sys/systm.h>
70 #include <sys/kernel.h>
71 #include <sys/syslog.h>
72 #include <sys/device.h>
74 #include <machine/bus.h>
75 #include <machine/cpu.h>
76 #include <machine/intr.h>
77 #include <machine/hp300spu.h>
79 #include <hp300/dev/intiovar.h>
81 #include <hp300/dev/frodoreg.h>
82 #include <hp300/dev/frodovar.h>
85 * Description of a Frodo interrupt handler.
87 struct frodo_interhand
{
94 device_t sc_dev
; /* generic device glue */
95 volatile uint8_t *sc_regs
; /* register base */
96 struct frodo_interhand sc_intr
[FRODO_NINTR
]; /* interrupt handlers */
98 void *sc_ih
; /* out interrupt cookie */
99 int sc_refcnt
; /* number of interrupt refs */
100 struct bus_space_tag sc_tag
; /* bus space tag */
103 static int frodomatch(device_t
, cfdata_t
, void *);
104 static void frodoattach(device_t
, device_t
, void *);
106 static int frodoprint(void *, const char *);
107 static int frodosubmatch(device_t
, cfdata_t
, const int *, void *);
109 static int frodointr(void *);
111 static void frodo_imask(struct frodo_softc
*, uint16_t, uint16_t);
113 CFATTACH_DECL_NEW(frodo
, sizeof(struct frodo_softc
),
114 frodomatch
, frodoattach
, NULL
, NULL
);
116 static const struct frodo_device frodo_subdevs
[] = {
117 { "dnkbd", FRODO_APCI_OFFSET(0), FRODO_INTR_APCI0
},
118 { "com", FRODO_APCI_OFFSET(1), FRODO_INTR_APCI1
},
119 { "com", FRODO_APCI_OFFSET(2), FRODO_INTR_APCI2
},
120 { "com", FRODO_APCI_OFFSET(3), FRODO_INTR_APCI3
},
125 frodomatch(device_t parent
, cfdata_t cf
, void *aux
)
127 struct intio_attach_args
*ia
= aux
;
128 static int frodo_matched
= 0;
130 /* only allow one instance */
134 if (strcmp(ia
->ia_modname
, "frodo") != 0)
137 if (badaddr((void *)ia
->ia_addr
))
145 frodoattach(device_t parent
, device_t self
, void *aux
)
147 struct frodo_softc
*sc
= device_private(self
);
148 struct intio_attach_args
*ia
= aux
;
149 bus_space_tag_t bst
= &sc
->sc_tag
;
150 const struct frodo_device
*fd
;
151 struct frodo_attach_args fa
;
154 sc
->sc_regs
= (volatile uint8_t *)ia
->ia_addr
;
155 sc
->sc_ipl
= ia
->ia_ipl
;
157 if ((FRODO_READ(sc
, FRODO_IISR
) & FRODO_IISR_SERVICE
) == 0)
158 aprint_error(": service mode enabled");
161 /* Initialize bus_space_tag_t for frodo */
162 frodo_init_bus_space(bst
);
164 /* Clear all of the interrupt handlers. */
165 memset(sc
->sc_intr
, 0, sizeof(sc
->sc_intr
));
169 * Disable all of the interrupt lines; we reenable them
170 * as subdevices attach.
172 frodo_imask(sc
, 0, 0xffff);
174 /* Clear any pending interrupts. */
175 FRODO_WRITE(sc
, FRODO_PIC_PU
, 0xff);
176 FRODO_WRITE(sc
, FRODO_PIC_PL
, 0xff);
178 /* Set interrupt polarities. */
179 FRODO_WRITE(sc
, FRODO_PIO_IPR
, 0x10);
181 /* ...and configure for edge triggering. */
182 FRODO_WRITE(sc
, FRODO_PIO_IELR
, 0xcf);
185 * We defer hooking up our interrupt handler until
186 * a subdevice hooks up theirs.
190 /* ... and attach subdevices. */
191 for (fd
= frodo_subdevs
; fd
->fd_name
!= NULL
; fd
++) {
193 * Skip the first serial port if we're not a 425e;
194 * it's mapped to the DCA at select code 9 on all
197 if (fd
->fd_offset
== FRODO_APCI_OFFSET(1) &&
198 mmuid
!= MMUID_425_E
)
200 fa
.fa_name
= fd
->fd_name
;
202 fa
.fa_base
= ia
->ia_iobase
;
203 fa
.fa_offset
= fd
->fd_offset
;
204 fa
.fa_line
= fd
->fd_line
;
205 config_found_sm_loc(self
, "frodo", NULL
, &fa
, frodoprint
,
211 frodosubmatch(device_t parent
, cfdata_t cf
, const int *ldesc
, void *aux
)
213 struct frodo_attach_args
*fa
= aux
;
215 if (cf
->frodocf_offset
!= FRODO_UNKNOWN_OFFSET
&&
216 cf
->frodocf_offset
!= fa
->fa_offset
)
219 return config_match(parent
, cf
, aux
);
223 frodoprint(void *aux
, const char *pnp
)
225 struct frodo_attach_args
*fa
= aux
;
228 aprint_normal("%s at %s", fa
->fa_name
, pnp
);
229 aprint_normal(" offset 0x%x", fa
->fa_offset
);
234 frodo_intr_establish(device_t frdev
, int (*func
)(void *), void *arg
,
235 int line
, int priority
)
237 struct frodo_softc
*sc
= device_private(frdev
);
238 struct hp300_intrhand
*ih
= sc
->sc_ih
;
240 if (line
< 0 || line
>= FRODO_NINTR
) {
241 aprint_error_dev(frdev
, "bad interrupt line %d\n", line
);
244 if (sc
->sc_intr
[line
].ih_fn
!= NULL
) {
245 aprint_error_dev(frdev
, "interrupt line %d already used\n",
250 /* Install the handler. */
251 sc
->sc_intr
[line
].ih_fn
= func
;
252 sc
->sc_intr
[line
].ih_arg
= arg
;
253 sc
->sc_intr
[line
].ih_priority
= priority
;
256 * If this is the first one, establish the frodo
257 * interrupt handler. If not, reestablish at a
258 * higher priority if necessary.
260 if (ih
== NULL
|| ih
->ih_priority
< priority
) {
262 intr_disestablish(ih
);
263 sc
->sc_ih
= intr_establish(frodointr
, sc
, sc
->sc_ipl
, priority
);
268 /* Enable the interrupt line. */
269 frodo_imask(sc
, (1 << line
), 0);
272 panic("frodo_intr_establish");
276 frodo_intr_disestablish(device_t frdev
, int line
)
278 struct frodo_softc
*sc
= device_private(frdev
);
279 struct hp300_intrhand
*ih
= sc
->sc_ih
;
282 if (sc
->sc_intr
[line
].ih_fn
== NULL
) {
283 printf("%s: no handler for line %d\n",
284 device_xname(sc
->sc_dev
), line
);
285 panic("frodo_intr_disestablish");
288 sc
->sc_intr
[line
].ih_fn
= NULL
;
289 frodo_imask(sc
, 0, (1 << line
));
291 /* If this was the last, unhook ourselves. */
292 if (sc
->sc_refcnt
-- == 1) {
293 intr_disestablish(ih
);
297 /* Lower our priority, if appropriate. */
298 for (newpri
= 0, line
= 0; line
< FRODO_NINTR
; line
++)
299 if (sc
->sc_intr
[line
].ih_fn
!= NULL
&&
300 sc
->sc_intr
[line
].ih_priority
> newpri
)
301 newpri
= sc
->sc_intr
[line
].ih_priority
;
303 if (newpri
!= ih
->ih_priority
) {
304 intr_disestablish(ih
);
305 sc
->sc_ih
= intr_establish(frodointr
, sc
, sc
->sc_ipl
, newpri
);
312 struct frodo_softc
*sc
= arg
;
313 struct frodo_interhand
*fih
;
316 /* Any interrupts pending? */
317 if (FRODO_GETPEND(sc
) == 0)
322 * Get pending interrupt; this also clears it for us.
324 line
= FRODO_IPEND(sc
);
325 fih
= &sc
->sc_intr
[line
];
326 if (fih
->ih_fn
== NULL
||
327 (*fih
->ih_fn
)(fih
->ih_arg
) == 0)
328 printf("%s: spurious interrupt on line %d\n",
329 device_xname(sc
->sc_dev
), line
);
331 panic("frodointr: looping!");
332 } while (FRODO_GETPEND(sc
) != 0);
338 frodo_imask(struct frodo_softc
*sc
, uint16_t set
, uint16_t clear
)
342 imask
= FRODO_GETMASK(sc
);
347 FRODO_SETMASK(sc
, imask
);
351 * frodo chip specific bus_space(9) support functions.
353 static uint8_t frodo_bus_space_read_sparse_1(bus_space_tag_t
,
354 bus_space_handle_t
, bus_size_t
);
355 static void frodo_bus_space_write_sparse_1(bus_space_tag_t
,
356 bus_space_handle_t
, bus_size_t
, uint8_t);
358 static void frodo_bus_space_read_multi_sparse_1(bus_space_tag_t
,
359 bus_space_handle_t
, bus_size_t
, uint8_t *, bus_size_t
);
360 static void frodo_bus_space_write_multi_sparse_1(bus_space_tag_t
,
361 bus_space_handle_t
, bus_size_t
, const uint8_t *, bus_size_t
);
363 static void frodo_bus_space_read_region_sparse_1(bus_space_tag_t
,
364 bus_space_handle_t
, bus_size_t
, uint8_t *, bus_size_t
);
365 static void frodo_bus_space_write_region_sparse_1(bus_space_tag_t
,
366 bus_space_handle_t
, bus_size_t
, const uint8_t *, bus_size_t
);
368 static void frodo_bus_space_set_multi_sparse_1(bus_space_tag_t
,
369 bus_space_handle_t
, bus_size_t
, uint8_t, bus_size_t
);
371 static void frodo_bus_space_set_region_sparse_1(bus_space_tag_t
,
372 bus_space_handle_t
, bus_size_t
, uint8_t, bus_size_t
);
375 * frodo_init_bus_space():
376 * Initialize bus_space functions in bus_space_tag_t
377 * for frodo devices which have sparse address space.
380 frodo_init_bus_space(bus_space_tag_t bst
)
383 memset(bst
, 0, sizeof(struct bus_space_tag
));
384 bst
->bustype
= HP300_BUS_SPACE_INTIO
;
386 bst
->bsr1
= frodo_bus_space_read_sparse_1
;
387 bst
->bsw1
= frodo_bus_space_write_sparse_1
;
389 bst
->bsrm1
= frodo_bus_space_read_multi_sparse_1
;
390 bst
->bswm1
= frodo_bus_space_write_multi_sparse_1
;
392 bst
->bsrr1
= frodo_bus_space_read_region_sparse_1
;
393 bst
->bswr1
= frodo_bus_space_write_region_sparse_1
;
395 bst
->bssm1
= frodo_bus_space_set_multi_sparse_1
;
397 bst
->bssr1
= frodo_bus_space_set_region_sparse_1
;
401 frodo_bus_space_read_sparse_1(bus_space_tag_t bst
, bus_space_handle_t bsh
,
405 return *(volatile uint8_t *)(bsh
+ (offset
<< 2));
409 frodo_bus_space_write_sparse_1(bus_space_tag_t bst
, bus_space_handle_t bsh
,
410 bus_size_t offset
, uint8_t val
)
413 *(volatile uint8_t *)(bsh
+ (offset
<< 2)) = val
;
417 frodo_bus_space_read_multi_sparse_1(bus_space_tag_t bst
, bus_space_handle_t bsh
,
418 bus_size_t offset
, uint8_t *addr
, bus_size_t len
)
425 "1: movb %%a0@,%%a1@+ ;\n"
429 : "r" (bsh
+ (offset
<< 2)), "g" (addr
), "g" (len
)
430 : "%a0","%a1","%d0");
434 frodo_bus_space_write_multi_sparse_1(bus_space_tag_t bst
,
435 bus_space_handle_t bsh
, bus_size_t offset
, const uint8_t *addr
,
443 "1: movb %%a1@+,%%a0@ ;\n"
447 : "r" (bsh
+ (offset
<< 2)), "g" (addr
), "g" (len
)
448 : "%a0","%a1","%d0");
452 frodo_bus_space_read_region_sparse_1(bus_space_tag_t bst
,
453 bus_space_handle_t bsh
, bus_size_t offset
, uint8_t *addr
, bus_size_t len
)
459 "1: movb %%a0@,%%a1@+ ;\n"
464 : "r" (bsh
+ (offset
<< 2)), "g" (addr
), "g" (len
)
465 : "%a0","%a1","%d0");
469 frodo_bus_space_write_region_sparse_1(bus_space_tag_t bst
,
470 bus_space_handle_t bsh
, bus_size_t offset
, const uint8_t *addr
,
478 "1: movb %%a1@+,%%a0@ ;\n"
483 : "r" (bsh
+ (offset
<< 2)), "g" (addr
), "g" (len
)
484 : "%a0","%a1","%d0");
488 frodo_bus_space_set_multi_sparse_1(bus_space_tag_t bst
, bus_space_handle_t bsh
,
489 bus_size_t offset
, uint8_t val
, bus_size_t count
)
495 "1: movb %%d1,%%a0@ ;\n"
499 : "r" (bsh
+ (offset
<< 2)), "g" (val
), "g" (count
)
500 : "%a0","%d0","%d1");
504 frodo_bus_space_set_region_sparse_1(bus_space_tag_t bst
, bus_space_handle_t bsh
,
505 bus_size_t offset
, uint8_t val
, bus_size_t count
)
512 "1: movb %%d1,%%a0@ ;\n"
517 : "r" (bsh
+ (offset
<< 2)), "g" (val
), "g" (count
)
518 : "%a0","%d0","%d1");