footbridge_intr.h revision 1.3 1 1.3 chris /* $NetBSD: footbridge_intr.h,v 1.3 2002/11/11 20:44:41 chris Exp $ */
2 1.1 chris
3 1.1 chris /*
4 1.3 chris * Copyright (c) 2001, 2002 Wasabi Systems, Inc.
5 1.1 chris * All rights reserved.
6 1.1 chris *
7 1.3 chris * Written by Jason R. Thorpe for Wasabi Systems, Inc.
8 1.3 chris *
9 1.1 chris * Redistribution and use in source and binary forms, with or without
10 1.1 chris * modification, are permitted provided that the following conditions
11 1.1 chris * are met:
12 1.1 chris * 1. Redistributions of source code must retain the above copyright
13 1.1 chris * notice, this list of conditions and the following disclaimer.
14 1.1 chris * 2. Redistributions in binary form must reproduce the above copyright
15 1.1 chris * notice, this list of conditions and the following disclaimer in the
16 1.1 chris * documentation and/or other materials provided with the distribution.
17 1.1 chris * 3. All advertising materials mentioning features or use of this software
18 1.1 chris * must display the following acknowledgement:
19 1.3 chris * This product includes software developed for the NetBSD Project by
20 1.3 chris * Wasabi Systems, Inc.
21 1.3 chris * 4. The name of Wasabi Systems, Inc. may not be used to endorse
22 1.3 chris * or promote products derived from this software without specific prior
23 1.3 chris * written permission.
24 1.1 chris *
25 1.3 chris * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
26 1.3 chris * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27 1.3 chris * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 1.3 chris * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
29 1.3 chris * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 1.3 chris * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 1.3 chris * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 1.3 chris * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 1.3 chris * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 1.3 chris * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 1.3 chris * POSSIBILITY OF SUCH DAMAGE.
36 1.1 chris */
37 1.1 chris
38 1.1 chris #ifndef _FOOTBRIDGE_INTR_H_
39 1.1 chris #define _FOOTBRIDGE_INTR_H_
40 1.1 chris
41 1.2 chris #include <arm/armreg.h>
42 1.2 chris
43 1.1 chris /* Define the various Interrupt Priority Levels */
44 1.1 chris
45 1.1 chris /* Hardware Interrupt Priority Levels are not mutually exclusive. */
46 1.1 chris
47 1.2 chris #define IPL_NONE 0 /* nothing */
48 1.2 chris #define IPL_SOFT 1 /* generic soft interrupts */
49 1.2 chris #define IPL_SOFTCLOCK 2 /* clock software interrupts */
50 1.2 chris #define IPL_SOFTNET 3 /* network software interrupts */
51 1.2 chris #define IPL_BIO 4 /* block I/O */
52 1.2 chris #define IPL_NET 5 /* network */
53 1.2 chris #define IPL_SOFTSERIAL 6 /* serial software interrupts */
54 1.2 chris #define IPL_TTY 7 /* terminal */
55 1.2 chris #define IPL_IMP 8 /* memory allocation */
56 1.2 chris #define IPL_AUDIO 9 /* audio */
57 1.2 chris #define IPL_CLOCK 10 /* clock */
58 1.2 chris #define IPL_STATCLOCK 11 /* statclock */
59 1.2 chris #define IPL_HIGH 12 /* everything */
60 1.2 chris #define IPL_SERIAL 13 /* serial */
61 1.1 chris
62 1.2 chris #define NIPL 14
63 1.1 chris
64 1.1 chris #define IST_UNUSABLE -1 /* interrupt cannot be used */
65 1.1 chris #define IST_NONE 0 /* none (dummy) */
66 1.1 chris #define IST_PULSE 1 /* pulsed */
67 1.1 chris #define IST_EDGE 2 /* edge-triggered */
68 1.1 chris #define IST_LEVEL 3 /* level-triggered */
69 1.1 chris
70 1.2 chris #define __NEWINTR /* enables new hooks in cpu_fork()/cpu_switch() */
71 1.2 chris
72 1.2 chris #ifndef _LOCORE
73 1.2 chris #include <arm/cpufunc.h>
74 1.2 chris
75 1.2 chris #include <arm/footbridge/dc21285mem.h>
76 1.2 chris #include <arm/footbridge/dc21285reg.h>
77 1.1 chris
78 1.2 chris #define INT_SWMASK \
79 1.2 chris ((1U << IRQ_SOFTINT) | (1U << IRQ_RESERVED0) | \
80 1.2 chris (1U << IRQ_RESERVED1) | (1U << IRQ_RESERVED2))
81 1.2 chris #define ICU_INT_HWMASK (0xffffffff & ~(INT_SWMASK | (1U << IRQ_RESERVED3)))
82 1.2 chris
83 1.2 chris /* only call this with interrupts off */
84 1.2 chris static __inline void __attribute__((__unused__))
85 1.2 chris footbridge_set_intrmask(void)
86 1.2 chris {
87 1.2 chris extern __volatile uint32_t intr_enabled;
88 1.2 chris /* fetch once so we write the same number to both registers */
89 1.2 chris uint32_t tmp = intr_enabled & ICU_INT_HWMASK;
90 1.2 chris
91 1.2 chris ((__volatile uint32_t*)(DC21285_ARMCSR_VBASE))[IRQ_ENABLE_SET>>2] = tmp;
92 1.2 chris ((__volatile uint32_t*)(DC21285_ARMCSR_VBASE))[IRQ_ENABLE_CLEAR>>2] = ~tmp;
93 1.2 chris }
94 1.2 chris
95 1.2 chris static __inline void __attribute__((__unused__))
96 1.2 chris footbridge_splx(int newspl)
97 1.2 chris {
98 1.2 chris extern __volatile uint32_t intr_enabled;
99 1.2 chris extern __volatile int current_spl_level;
100 1.2 chris extern __volatile int footbridge_ipending;
101 1.2 chris extern void footbridge_do_pending(void);
102 1.2 chris int oldirqstate, hwpend;
103 1.2 chris
104 1.2 chris current_spl_level = newspl;
105 1.2 chris
106 1.2 chris hwpend = (footbridge_ipending & ICU_INT_HWMASK) & ~newspl;
107 1.2 chris if (hwpend != 0) {
108 1.2 chris oldirqstate = disable_interrupts(I32_bit);
109 1.2 chris intr_enabled |= hwpend;
110 1.2 chris footbridge_set_intrmask();
111 1.2 chris restore_interrupts(oldirqstate);
112 1.2 chris }
113 1.2 chris
114 1.2 chris if ((footbridge_ipending & INT_SWMASK) & ~newspl)
115 1.2 chris footbridge_do_pending();
116 1.2 chris }
117 1.2 chris
118 1.2 chris static __inline int __attribute__((__unused__))
119 1.2 chris footbridge_splraise(int ipl)
120 1.2 chris {
121 1.2 chris extern __volatile int current_spl_level;
122 1.2 chris extern int footbridge_imask[];
123 1.2 chris int old;
124 1.2 chris
125 1.2 chris old = current_spl_level;
126 1.2 chris current_spl_level |= footbridge_imask[ipl];
127 1.2 chris
128 1.2 chris return (old);
129 1.2 chris }
130 1.2 chris
131 1.2 chris static __inline int __attribute__((__unused__))
132 1.2 chris footbridge_spllower(int ipl)
133 1.2 chris {
134 1.2 chris extern __volatile int current_spl_level;
135 1.2 chris extern int footbridge_imask[];
136 1.2 chris int old = current_spl_level;
137 1.2 chris
138 1.2 chris footbridge_splx(footbridge_imask[ipl]);
139 1.2 chris return(old);
140 1.2 chris }
141 1.2 chris
142 1.2 chris /* should only be defined in footbridge_intr.c */
143 1.2 chris #if !defined(ARM_SPL_NOINLINE)
144 1.2 chris
145 1.2 chris #define splx(newspl) footbridge_splx(newspl)
146 1.2 chris #define _spllower(ipl) footbridge_spllower(ipl)
147 1.2 chris #define _splraise(ipl) footbridge_splraise(ipl)
148 1.2 chris void _setsoftintr(int);
149 1.2 chris
150 1.2 chris #else
151 1.2 chris
152 1.2 chris int _splraise(int);
153 1.2 chris int _spllower(int);
154 1.2 chris void splx(int);
155 1.2 chris void _setsoftintr(int);
156 1.1 chris
157 1.2 chris #endif /* ! ARM_SPL_NOINLINE */
158 1.1 chris
159 1.2 chris #include <sys/device.h>
160 1.2 chris #include <sys/queue.h>
161 1.1 chris #include <machine/irqhandler.h>
162 1.2 chris
163 1.2 chris #define splsoft() _splraise(IPL_SOFT)
164 1.2 chris #define splsoftclock() _splraise(IPL_SOFTCLOCK)
165 1.2 chris #define splsoftnet() _splraise(IPL_SOFTNET)
166 1.2 chris #define splbio() _splraise(IPL_BIO)
167 1.2 chris #define splnet() _splraise(IPL_NET)
168 1.2 chris #define splsoftserial() _splraise(IPL_SOFTSERIAL)
169 1.2 chris #define spltty() _splraise(IPL_TTY)
170 1.2 chris #define spllpt() spltty()
171 1.2 chris #define splvm() _splraise(IPL_IMP)
172 1.2 chris #define splaudio() _splraise(IPL_AUDIO)
173 1.2 chris #define splclock() _splraise(IPL_CLOCK)
174 1.2 chris #define splstatclock() _splraise(IPL_STATCLOCK)
175 1.2 chris #define splhigh() _splraise(IPL_HIGH)
176 1.2 chris #define splserial() _splraise(IPL_SERIAL)
177 1.2 chris
178 1.2 chris #define spl0() (void)_spllower(IPL_NONE)
179 1.2 chris #define spllowersoftclock() (void)_spllower(IPL_SOFTCLOCK)
180 1.2 chris
181 1.2 chris #define splsched() splhigh()
182 1.2 chris #define spllock() splhigh()
183 1.2 chris
184 1.2 chris /* Use generic software interrupt support. */
185 1.2 chris #include <arm/softintr.h>
186 1.2 chris
187 1.2 chris /* footbridge has 32 interrupt lines */
188 1.2 chris #define NIRQ 32
189 1.2 chris
190 1.2 chris struct intrhand {
191 1.2 chris TAILQ_ENTRY(intrhand) ih_list; /* link on intrq list */
192 1.2 chris int (*ih_func)(void *); /* handler */
193 1.2 chris void *ih_arg; /* arg for handler */
194 1.2 chris int ih_ipl; /* IPL_* */
195 1.2 chris int ih_irq; /* IRQ number */
196 1.2 chris };
197 1.2 chris
198 1.2 chris #define IRQNAMESIZE sizeof("footbridge irq 31")
199 1.2 chris
200 1.2 chris struct intrq {
201 1.2 chris TAILQ_HEAD(, intrhand) iq_list; /* handler list */
202 1.2 chris struct evcnt iq_ev; /* event counter */
203 1.2 chris int iq_mask; /* IRQs to mask while handling */
204 1.2 chris int iq_levels; /* IPL_*'s this IRQ has */
205 1.2 chris int iq_ist; /* share type */
206 1.2 chris char iq_name[IRQNAMESIZE]; /* interrupt name */
207 1.2 chris };
208 1.2 chris
209 1.2 chris #endif /* _LOCORE */
210 1.1 chris
211 1.1 chris #endif /* _FOOTBRIDGE_INTR_H */
212