Sync usage with man page.
[netbsd-mini2440.git] / sys / arch / hpcsh / dev / hd6446x / hd6446xintc.c
blob95ca0c49d39fc42727bcbcf000315ec075fcaa63
1 /* $NetBSD: hd6446xintc.c,v 1.7 2006/07/22 02:13:06 uwe Exp $ */
3 /*-
4 * Copyright (c) 2002 The NetBSD Foundation, Inc.
5 * All rights reserved.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by UCHIYAMA Yasushi.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
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);
49 void
50 hd6446x_intr_init(void)
53 /* Initialize interrupt priority masks. */
54 hd6446x_intr_priority_update();
57 void *
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];
62 int s;
64 s = splhigh();
66 /* Register interrupt handler */
67 hh->hh_func = func;
68 hh->hh_arg = arg;
69 hh->hh_ipl = level << 4;
70 hh->hh_imask = irq;
71 hd6446x_ienable |= hh->hh_imask;
73 /* Update interrupt priority masks. */
74 hd6446x_intr_priority_update();
76 splx(s);
78 return (hh);
81 void
82 hd6446x_intr_disestablish(void *handle)
84 struct hd6446x_intrhand *hh = handle;
85 int s;
87 s = splhigh();
89 /* Update interrupt priority masks */
90 hd6446x_ienable &= ~hh->hh_imask;
91 memset(hh, 0, sizeof(*hh));
92 hd6446x_intr_priority_update();
94 splx(s);
97 void
98 hd6446x_intr_priority(int irq, int level)
100 struct hd6446x_intrhand *hh = &hd6446x_intrhand[ffs(irq) - 1];
101 int s;
103 KDASSERT(hh->hh_func != NULL);
104 s = splhigh();
105 hh->hh_ipl = level << 4;
106 hd6446x_intr_priority_update();
107 splx(s);
110 static void
111 hd6446x_intr_priority_update(void)
113 int ipl, src;
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))
123 mask |= 1 << src;
126 hd6446x_imask[ipl] = mask;