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