intr.h revision 1.27 1 /* $NetBSD: intr.h,v 1.27 2008/01/28 16:21:20 tsutsui Exp $ */
2
3 /*-
4 * Copyright (c) 1996, 1997, 1999 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jason R. Thorpe.
9 *
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.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the NetBSD
21 * Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39 #ifndef _HP300_INTR_H_
40 #define _HP300_INTR_H_
41
42 #include <sys/device.h>
43 #include <sys/queue.h>
44 #include <machine/psl.h>
45
46 /*
47 * Interrupt "levels". These are a more abstract representation
48 * of interrupt levels, and do not have the same meaning as m68k
49 * CPU interrupt levels. They serve the following purposes:
50 *
51 * - properly order ISRs in the list for that CPU ipl
52 * - compute CPU PSL values for the spl*() calls.
53 * - used to create cookie for the splraiseipl().
54 */
55 #define IPL_NONE 0
56 #define IPL_SOFTCLOCK 1
57 #define IPL_SOFTBIO 2
58 #define IPL_SOFTNET 3
59 #define IPL_SOFTSERIAL 4
60 #define IPL_VM 5
61 #define IPL_SCHED 6
62 #define IPL_HIGH 7
63 #define NIPL 8
64
65 /*
66 * Convert PSL values to m68k CPU IPLs and vice-versa.
67 * Note: CPU IPL values are different from IPL_* used by splraiseipl().
68 */
69 #define PSLTOIPL(x) (((x) >> 8) & 0xf)
70 #define IPLTOPSL(x) ((((x) & 0xf) << 8) | PSL_S)
71
72 extern int idepth;
73 extern u_short hp300_ipl2psl[];
74
75 typedef int ipl_t;
76 typedef struct {
77 uint16_t _psl;
78 } ipl_cookie_t;
79
80 static inline ipl_cookie_t
81 makeiplcookie(ipl_t ipl)
82 {
83
84 return (ipl_cookie_t){._psl = hp300_ipl2psl[ipl]};
85 }
86
87 static inline int
88 splraiseipl(ipl_cookie_t icookie)
89 {
90
91 return _splraise(icookie._psl);
92 }
93
94 /* These spl calls are _not_ to be used by machine-independent code. */
95 #define splhil() splraise1()
96 #define splkbd() splhil()
97
98 /* These spl calls are used by machine-independent code. */
99 /* spl0 requires checking for software interrupts */
100 #define splsoftbio() splraise1()
101 #define splsoftclock() splraise1()
102 #define splsoftnet() splraise1()
103 #define splsoftserial() splraise1()
104 #define splvm() _splraise(hp300_ipl2psl[IPL_VM])
105 #define splsched() spl6()
106 #define splhigh() spl7()
107
108 /* watch out for side effects */
109 #define splx(s) ((s) & PSL_IPL ? _spl((s)) : spl0())
110
111 struct hp300_intrhand {
112 LIST_ENTRY(hp300_intrhand) ih_q;
113 int (*ih_fn)(void *);
114 void *ih_arg;
115 int ih_ipl;
116 int ih_priority;
117 };
118
119 struct hp300_intr {
120 LIST_HEAD(, hp300_intrhand) hi_q;
121 struct evcnt hi_evcnt;
122 };
123
124 /* locore.s */
125 int spl0(void);
126
127 /* intr.c */
128 void intr_init(void);
129 void *intr_establish(int (*)(void *), void *, int, int);
130 void intr_disestablish(void *);
131 void intr_dispatch(int);
132 void intr_printlevels(void);
133
134 #endif /* _HP300_INTR_H_ */
135