1 /* $NetBSD: hd6446xintc.c,v 1.7 2006/07/22 02:13:06 uwe Exp $ */
4 * Copyright (c) 2002 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.
32 #include <sys/cdefs.h>
33 __KERNEL_RCSID(0, "$NetBSD: hd6446xintc.c,v 1.7 2006/07/22 02:13:06 uwe Exp $");
35 #include <sys/param.h>
36 #include <sys/systm.h>
38 #include <sh3/devreg.h>
39 #include <hpcsh/dev/hd6446x/hd6446xintcreg.h>
40 #include <hpcsh/dev/hd6446x/hd6446xintcvar.h>
42 struct hd6446x_intrhand hd6446x_intrhand
[_HD6446X_INTR_N
];
43 uint16_t hd6446x_imask
[_IPL_N
];
44 uint16_t hd6446x_ienable
;
46 static void hd6446x_intr_priority_update(void);
50 hd6446x_intr_init(void)
53 /* Initialize interrupt priority masks. */
54 hd6446x_intr_priority_update();
58 hd6446x_intr_establish(int irq
, int mode
, int level
,
59 int (*func
)(void *), void *arg
)
61 struct hd6446x_intrhand
*hh
= &hd6446x_intrhand
[ffs(irq
) - 1];
66 /* Register interrupt handler */
69 hh
->hh_ipl
= level
<< 4;
71 hd6446x_ienable
|= hh
->hh_imask
;
73 /* Update interrupt priority masks. */
74 hd6446x_intr_priority_update();
82 hd6446x_intr_disestablish(void *handle
)
84 struct hd6446x_intrhand
*hh
= handle
;
89 /* Update interrupt priority masks */
90 hd6446x_ienable
&= ~hh
->hh_imask
;
91 memset(hh
, 0, sizeof(*hh
));
92 hd6446x_intr_priority_update();
98 hd6446x_intr_priority(int irq
, int level
)
100 struct hd6446x_intrhand
*hh
= &hd6446x_intrhand
[ffs(irq
) - 1];
103 KDASSERT(hh
->hh_func
!= NULL
);
105 hh
->hh_ipl
= level
<< 4;
106 hd6446x_intr_priority_update();
111 hd6446x_intr_priority_update(void)
115 for (ipl
= 0; ipl
< _IPL_N
; ipl
++) {
116 uint16_t mask
= ~hd6446x_ienable
; /* mask disabled */
118 /* mask sources interrupting at <= ipl */
119 for (src
= 0; src
< _HD6446X_INTR_N
; ++src
) {
120 struct hd6446x_intrhand
*hh
= &hd6446x_intrhand
[src
];
122 if (hh
->hh_func
!= NULL
&& hh
->hh_ipl
<= (ipl
<< 4))
126 hd6446x_imask
[ipl
] = mask
;