1*ce099b40Smartin /* $NetBSD: hd6446xintc.c,v 1.8 2008/04/28 20:23:22 martin Exp $ */
2260c29f0Such
3260c29f0Such /*-
4260c29f0Such * Copyright (c) 2002 The NetBSD Foundation, Inc.
5260c29f0Such * All rights reserved.
6260c29f0Such *
7260c29f0Such * This code is derived from software contributed to The NetBSD Foundation
8260c29f0Such * by UCHIYAMA Yasushi.
9260c29f0Such *
10260c29f0Such * Redistribution and use in source and binary forms, with or without
11260c29f0Such * modification, are permitted provided that the following conditions
12260c29f0Such * are met:
13260c29f0Such * 1. Redistributions of source code must retain the above copyright
14260c29f0Such * notice, this list of conditions and the following disclaimer.
15260c29f0Such * 2. Redistributions in binary form must reproduce the above copyright
16260c29f0Such * notice, this list of conditions and the following disclaimer in the
17260c29f0Such * documentation and/or other materials provided with the distribution.
18260c29f0Such *
19260c29f0Such * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20260c29f0Such * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21260c29f0Such * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22260c29f0Such * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23260c29f0Such * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24260c29f0Such * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25260c29f0Such * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26260c29f0Such * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27260c29f0Such * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28260c29f0Such * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29260c29f0Such * POSSIBILITY OF SUCH DAMAGE.
30260c29f0Such */
31260c29f0Such
320c82163cSlukem #include <sys/cdefs.h>
33*ce099b40Smartin __KERNEL_RCSID(0, "$NetBSD: hd6446xintc.c,v 1.8 2008/04/28 20:23:22 martin Exp $");
340c82163cSlukem
35260c29f0Such #include <sys/param.h>
36260c29f0Such #include <sys/systm.h>
37260c29f0Such
38260c29f0Such #include <sh3/devreg.h>
39260c29f0Such #include <hpcsh/dev/hd6446x/hd6446xintcreg.h>
404ebaf810Suwe #include <hpcsh/dev/hd6446x/hd6446xintcvar.h>
41260c29f0Such
42260c29f0Such struct hd6446x_intrhand hd6446x_intrhand[_HD6446X_INTR_N];
434ebaf810Suwe uint16_t hd6446x_imask[_IPL_N];
444ebaf810Suwe uint16_t hd6446x_ienable;
454ebaf810Suwe
464ebaf810Suwe static void hd6446x_intr_priority_update(void);
474ebaf810Suwe
48260c29f0Such
49260c29f0Such void
hd6446x_intr_init(void)504ebaf810Suwe hd6446x_intr_init(void)
51260c29f0Such {
52260c29f0Such
53260c29f0Such /* Initialize interrupt priority masks. */
54260c29f0Such hd6446x_intr_priority_update();
55260c29f0Such }
56260c29f0Such
57260c29f0Such void *
hd6446x_intr_establish(int irq,int mode,int level,int (* func)(void *),void * arg)58260c29f0Such hd6446x_intr_establish(int irq, int mode, int level,
59260c29f0Such int (*func)(void *), void *arg)
60260c29f0Such {
61260c29f0Such struct hd6446x_intrhand *hh = &hd6446x_intrhand[ffs(irq) - 1];
62260c29f0Such int s;
63260c29f0Such
64260c29f0Such s = splhigh();
65260c29f0Such
66260c29f0Such /* Register interrupt handler */
67260c29f0Such hh->hh_func = func;
68260c29f0Such hh->hh_arg = arg;
69260c29f0Such hh->hh_ipl = level << 4;
70260c29f0Such hh->hh_imask = irq;
71260c29f0Such hd6446x_ienable |= hh->hh_imask;
72260c29f0Such
73260c29f0Such /* Update interrupt priority masks. */
74260c29f0Such hd6446x_intr_priority_update();
75260c29f0Such
76260c29f0Such splx(s);
77260c29f0Such
78260c29f0Such return (hh);
79260c29f0Such }
80260c29f0Such
81260c29f0Such void
hd6446x_intr_disestablish(void * handle)82260c29f0Such hd6446x_intr_disestablish(void *handle)
83260c29f0Such {
84260c29f0Such struct hd6446x_intrhand *hh = handle;
85260c29f0Such int s;
86260c29f0Such
87260c29f0Such s = splhigh();
88260c29f0Such
89260c29f0Such /* Update interrupt priority masks */
90260c29f0Such hd6446x_ienable &= ~hh->hh_imask;
91260c29f0Such memset(hh, 0, sizeof(*hh));
92260c29f0Such hd6446x_intr_priority_update();
93260c29f0Such
94260c29f0Such splx(s);
95260c29f0Such }
96260c29f0Such
97260c29f0Such void
hd6446x_intr_priority(int irq,int level)98260c29f0Such hd6446x_intr_priority(int irq, int level)
99260c29f0Such {
100260c29f0Such struct hd6446x_intrhand *hh = &hd6446x_intrhand[ffs(irq) - 1];
101260c29f0Such int s;
102260c29f0Such
103260c29f0Such KDASSERT(hh->hh_func != NULL);
104260c29f0Such s = splhigh();
105260c29f0Such hh->hh_ipl = level << 4;
106260c29f0Such hd6446x_intr_priority_update();
107260c29f0Such splx(s);
108260c29f0Such }
109260c29f0Such
1104ebaf810Suwe static void
hd6446x_intr_priority_update(void)1114ebaf810Suwe hd6446x_intr_priority_update(void)
112260c29f0Such {
11343d9f78eSuwe int ipl, src;
114260c29f0Such
115260c29f0Such for (ipl = 0; ipl < _IPL_N; ipl++) {
116485a350cSuwe uint16_t mask = ~hd6446x_ienable; /* mask disabled */
117485a350cSuwe
118485a350cSuwe /* mask sources interrupting at <= ipl */
11943d9f78eSuwe for (src = 0; src < _HD6446X_INTR_N; ++src) {
12043d9f78eSuwe struct hd6446x_intrhand *hh = &hd6446x_intrhand[src];
121485a350cSuwe
122485a350cSuwe if (hh->hh_func != NULL && hh->hh_ipl <= (ipl << 4))
12343d9f78eSuwe mask |= 1 << src;
124260c29f0Such }
125260c29f0Such
126485a350cSuwe hd6446x_imask[ipl] = mask;
127485a350cSuwe }
128260c29f0Such }
129