| @@ -1,379 +1,373 @@ | | | @@ -1,379 +1,373 @@ |
1 | /* $NetBSD: pic_uic.c,v 1.4 2013/11/19 12:46:43 kiyohara Exp $ */ | | 1 | /* $NetBSD: pic_uic.c,v 1.5 2020/03/05 11:33:14 rin Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Copyright 2002 Wasabi Systems, Inc. | | 4 | * Copyright 2002 Wasabi Systems, Inc. |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * Written by Eduardo Horvath and Simon Burge for Wasabi Systems, Inc. | | 7 | * Written by Eduardo Horvath and Simon Burge for Wasabi Systems, Inc. |
8 | * | | 8 | * |
9 | * Redistribution and use in source and binary forms, with or without | | 9 | * Redistribution and use in source and binary forms, with or without |
10 | * modification, are permitted provided that the following conditions | | 10 | * modification, are permitted provided that the following conditions |
11 | * are met: | | 11 | * are met: |
12 | * 1. Redistributions of source code must retain the above copyright | | 12 | * 1. Redistributions of source code must retain the above copyright |
13 | * notice, this list of conditions and the following disclaimer. | | 13 | * notice, this list of conditions and the following disclaimer. |
14 | * 2. Redistributions in binary form must reproduce the above copyright | | 14 | * 2. Redistributions in binary form must reproduce the above copyright |
15 | * notice, this list of conditions and the following disclaimer in the | | 15 | * notice, this list of conditions and the following disclaimer in the |
16 | * documentation and/or other materials provided with the distribution. | | 16 | * documentation and/or other materials provided with the distribution. |
17 | * 3. All advertising materials mentioning features or use of this software | | 17 | * 3. All advertising materials mentioning features or use of this software |
18 | * must display the following acknowledgement: | | 18 | * must display the following acknowledgement: |
19 | * This product includes software developed for the NetBSD Project by | | 19 | * This product includes software developed for the NetBSD Project by |
20 | * Wasabi Systems, Inc. | | 20 | * Wasabi Systems, Inc. |
21 | * 4. The name of Wasabi Systems, Inc. may not be used to endorse | | 21 | * 4. The name of Wasabi Systems, Inc. may not be used to endorse |
22 | * or promote products derived from this software without specific prior | | 22 | * or promote products derived from this software without specific prior |
23 | * written permission. | | 23 | * written permission. |
24 | * | | 24 | * |
25 | * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND | | 25 | * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND |
26 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | | 26 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
27 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | | 27 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
28 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC | | 28 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC |
29 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | | 29 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
30 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | | 30 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
31 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | | 31 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
32 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | | 32 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
33 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | | 33 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
34 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | | 34 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
35 | * POSSIBILITY OF SUCH DAMAGE. | | 35 | * POSSIBILITY OF SUCH DAMAGE. |
36 | */ | | 36 | */ |
37 | | | 37 | |
38 | #include <sys/cdefs.h> | | 38 | #include <sys/cdefs.h> |
39 | __KERNEL_RCSID(0, "$NetBSD: pic_uic.c,v 1.4 2013/11/19 12:46:43 kiyohara Exp $"); | | 39 | __KERNEL_RCSID(0, "$NetBSD: pic_uic.c,v 1.5 2020/03/05 11:33:14 rin Exp $"); |
40 | | | 40 | |
41 | #include <sys/param.h> | | 41 | #include <sys/param.h> |
42 | #include <sys/kernel.h> | | 42 | #include <sys/kernel.h> |
43 | #include <sys/evcnt.h> | | 43 | #include <sys/evcnt.h> |
44 | #include <sys/cpu.h> | | 44 | #include <sys/cpu.h> |
45 | | | 45 | |
46 | #include <machine/intr.h> | | 46 | #include <machine/intr.h> |
47 | #include <machine/psl.h> | | 47 | #include <machine/psl.h> |
48 | | | 48 | |
49 | #include <powerpc/spr.h> | | 49 | #include <powerpc/spr.h> |
50 | #include <powerpc/ibm4xx/spr.h> | | 50 | #include <powerpc/ibm4xx/spr.h> |
51 | #include <powerpc/ibm4xx/cpu.h> | | 51 | #include <powerpc/ibm4xx/cpu.h> |
52 | | | 52 | |
53 | #include <powerpc/pic/picvar.h> | | 53 | #include <powerpc/pic/picvar.h> |
54 | | | 54 | |
55 | | | 55 | |
56 | /* | | 56 | /* |
57 | * Number of interrupts (hard + soft), irq number legality test, | | 57 | * Number of interrupts (hard + soft), irq number legality test, |
58 | * mapping of irq number to mask and a way to pick irq number | | 58 | * mapping of irq number to mask and a way to pick irq number |
59 | * off a mask of active intrs. | | 59 | * off a mask of active intrs. |
60 | */ | | 60 | */ |
61 | #define IRQ_TO_MASK(irq) (0x80000000UL >> ((irq) & 0x1f)) | | 61 | #define IRQ_TO_MASK(irq) (0x80000000UL >> ((irq) & 0x1f)) |
62 | #define IRQ_OF_MASK(mask) __builtin_clz(mask) | | 62 | #define IRQ_OF_MASK(mask) __builtin_clz(mask) |
63 | | | 63 | |
64 | static void uic_enable_irq(struct pic_ops *, int, int); | | 64 | static void uic_enable_irq(struct pic_ops *, int, int); |
65 | static void uic_disable_irq(struct pic_ops *, int); | | 65 | static void uic_disable_irq(struct pic_ops *, int); |
66 | static int uic_get_irq(struct pic_ops *, int); | | 66 | static int uic_get_irq(struct pic_ops *, int); |
67 | static void uic_ack_irq(struct pic_ops *, int); | | 67 | static void uic_ack_irq(struct pic_ops *, int); |
68 | static void uic_establish_irq(struct pic_ops *, int, int, int); | | 68 | static void uic_establish_irq(struct pic_ops *, int, int, int); |
69 | | | 69 | |
70 | struct uic { | | 70 | struct uic { |
71 | uint32_t uic_intr_enable; /* cached intr enable mask */ | | 71 | uint32_t uic_intr_enable; /* cached intr enable mask */ |
72 | uint32_t (*uic_mf_intr_status)(void); | | 72 | uint32_t (*uic_mf_intr_status)(void); |
73 | uint32_t (*uic_mf_intr_enable)(void); | | 73 | uint32_t (*uic_mf_intr_enable)(void); |
74 | void (*uic_mt_intr_enable)(uint32_t); | | 74 | void (*uic_mt_intr_enable)(uint32_t); |
75 | void (*uic_mt_intr_ack)(uint32_t); | | 75 | void (*uic_mt_intr_ack)(uint32_t); |
76 | }; | | 76 | }; |
77 | | | 77 | |
78 | /* | | 78 | /* |
79 | * Platform specific code may override any of the above. | | 79 | * Platform specific code may override any of the above. |
80 | */ | | 80 | */ |
81 | #ifdef PPC_IBM403 | | 81 | #ifdef PPC_IBM403 |
82 | | | 82 | |
83 | #include <powerpc/ibm4xx/dcr403cgx.h> | | 83 | #include <powerpc/ibm4xx/dcr403cgx.h> |
84 | | | 84 | |
85 | static uint32_t | | 85 | static uint32_t |
86 | uic403_mfdcr_intr_status(void) | | 86 | uic403_mfdcr_intr_status(void) |
87 | { | | 87 | { |
88 | return mfdcr(DCR_EXISR); | | 88 | return mfdcr(DCR_EXISR); |
89 | } | | 89 | } |
90 | | | 90 | |
91 | static uint32_t | | 91 | static uint32_t |
92 | uic403_mfdcr_intr_enable(void) | | 92 | uic403_mfdcr_intr_enable(void) |
93 | { | | 93 | { |
94 | return mfdcr(DCR_EXIER); | | 94 | return mfdcr(DCR_EXIER); |
95 | } | | 95 | } |
96 | | | 96 | |
97 | static void | | 97 | static void |
98 | uic403_mtdcr_intr_ack(uint32_t v) | | 98 | uic403_mtdcr_intr_ack(uint32_t v) |
99 | { | | 99 | { |
100 | mtdcr(DCR_EXISR, v); | | 100 | mtdcr(DCR_EXISR, v); |
101 | } | | 101 | } |
102 | | | 102 | |
103 | static void | | 103 | static void |
104 | uic403_mtdcr_intr_enable(uint32_t v) | | 104 | uic403_mtdcr_intr_enable(uint32_t v) |
105 | { | | 105 | { |
106 | mtdcr(DCR_EXIER, v); | | 106 | mtdcr(DCR_EXIER, v); |
107 | } | | 107 | } |
108 | | | 108 | |
109 | struct uic uic403 = { | | 109 | struct uic uic403 = { |
110 | .uic_intr_enable = 0, | | 110 | .uic_intr_enable = 0, |
111 | .uic_mf_intr_status = uic403_mfdcr_intr_status, | | 111 | .uic_mf_intr_status = uic403_mfdcr_intr_status, |
112 | .uic_mf_intr_enable = uic403_mfdcr_intr_enable, | | 112 | .uic_mf_intr_enable = uic403_mfdcr_intr_enable, |
113 | .uic_mt_intr_enable = uic403_mtdcr_intr_enable, | | 113 | .uic_mt_intr_enable = uic403_mtdcr_intr_enable, |
114 | .uic_mt_intr_ack = uic403_mtdcr_intr_ack, | | 114 | .uic_mt_intr_ack = uic403_mtdcr_intr_ack, |
115 | }; | | 115 | }; |
116 | | | 116 | |
117 | struct pic_ops pic_uic403 = { | | 117 | struct pic_ops pic_uic403 = { |
118 | .pic_cookie = &uic403, | | 118 | .pic_cookie = &uic403, |
119 | .pic_numintrs = 32, | | 119 | .pic_numintrs = 32, |
120 | .pic_enable_irq = uic_enable_irq, | | 120 | .pic_enable_irq = uic_enable_irq, |
121 | .pic_reenable_irq = uic_enable_irq, | | 121 | .pic_reenable_irq = uic_enable_irq, |
122 | .pic_disable_irq = uic_disable_irq, | | 122 | .pic_disable_irq = uic_disable_irq, |
123 | .pic_establish_irq = uic_establish_irq, | | 123 | .pic_establish_irq = uic_establish_irq, |
124 | .pic_get_irq = uic_get_irq, | | 124 | .pic_get_irq = uic_get_irq, |
125 | .pic_ack_irq = uic_ack_irq, | | 125 | .pic_ack_irq = uic_ack_irq, |
126 | .pic_finish_setup = NULL, | | 126 | .pic_finish_setup = NULL, |
127 | .pic_name = "uic0" | | 127 | .pic_name = "uic0" |
128 | }; | | 128 | }; |
129 | | | 129 | |
130 | #else /* Generic 405/440/460 Universal Interrupt Controller */ | | 130 | #else /* Generic 405/440/460 Universal Interrupt Controller */ |
131 | | | 131 | |
132 | #include <powerpc/ibm4xx/dcr4xx.h> | | 132 | #include <powerpc/ibm4xx/dcr4xx.h> |
133 | | | 133 | |
134 | #include "opt_uic.h" | | 134 | #include "opt_uic.h" |
135 | | | 135 | |
136 | /* 405EP/405GP/405GPr/Virtex-4 */ | | 136 | /* 405EP/405GP/405GPr/Virtex-4 */ |
137 | | | 137 | |
138 | static uint32_t | | 138 | static uint32_t |
139 | uic0_mfdcr_intr_status(void) | | 139 | uic0_mfdcr_intr_status(void) |
140 | { | | 140 | { |
141 | return mfdcr(DCR_UIC0_BASE + DCR_UIC_MSR); | | 141 | return mfdcr(DCR_UIC0_BASE + DCR_UIC_MSR); |
142 | } | | 142 | } |
143 | | | 143 | |
144 | static uint32_t | | 144 | static uint32_t |
145 | uic0_mfdcr_intr_enable(void) | | 145 | uic0_mfdcr_intr_enable(void) |
146 | { | | 146 | { |
147 | return mfdcr(DCR_UIC0_BASE + DCR_UIC_ER); | | 147 | return mfdcr(DCR_UIC0_BASE + DCR_UIC_ER); |
148 | } | | 148 | } |
149 | | | 149 | |
150 | static void | | 150 | static void |
151 | uic0_mtdcr_intr_ack(uint32_t v) | | 151 | uic0_mtdcr_intr_ack(uint32_t v) |
152 | { | | 152 | { |
153 | mtdcr(DCR_UIC0_BASE + DCR_UIC_SR, v); | | 153 | mtdcr(DCR_UIC0_BASE + DCR_UIC_SR, v); |
154 | } | | 154 | } |
155 | | | 155 | |
156 | static void | | 156 | static void |
157 | uic0_mtdcr_intr_enable(uint32_t v) | | 157 | uic0_mtdcr_intr_enable(uint32_t v) |
158 | { | | 158 | { |
159 | mtdcr(DCR_UIC0_BASE + DCR_UIC_ER, v); | | 159 | mtdcr(DCR_UIC0_BASE + DCR_UIC_ER, v); |
160 | } | | 160 | } |
161 | | | 161 | |
162 | struct uic uic0 = { | | 162 | struct uic uic0 = { |
163 | .uic_intr_enable = 0, | | 163 | .uic_intr_enable = 0, |
164 | .uic_mf_intr_status = uic0_mfdcr_intr_status, | | 164 | .uic_mf_intr_status = uic0_mfdcr_intr_status, |
165 | .uic_mf_intr_enable = uic0_mfdcr_intr_enable, | | 165 | .uic_mf_intr_enable = uic0_mfdcr_intr_enable, |
166 | .uic_mt_intr_enable = uic0_mtdcr_intr_enable, | | 166 | .uic_mt_intr_enable = uic0_mtdcr_intr_enable, |
167 | .uic_mt_intr_ack = uic0_mtdcr_intr_ack, | | 167 | .uic_mt_intr_ack = uic0_mtdcr_intr_ack, |
168 | }; | | 168 | }; |
169 | | | 169 | |
170 | struct pic_ops pic_uic0 = { | | 170 | struct pic_ops pic_uic0 = { |
171 | .pic_cookie = &uic0, | | 171 | .pic_cookie = &uic0, |
172 | .pic_numintrs = 32, | | 172 | .pic_numintrs = 32, |
173 | .pic_enable_irq = uic_enable_irq, | | 173 | .pic_enable_irq = uic_enable_irq, |
174 | .pic_reenable_irq = uic_enable_irq, | | 174 | .pic_reenable_irq = uic_enable_irq, |
175 | .pic_disable_irq = uic_disable_irq, | | 175 | .pic_disable_irq = uic_disable_irq, |
176 | .pic_establish_irq = uic_establish_irq, | | 176 | .pic_establish_irq = uic_establish_irq, |
177 | .pic_get_irq = uic_get_irq, | | 177 | .pic_get_irq = uic_get_irq, |
178 | .pic_ack_irq = uic_ack_irq, | | 178 | .pic_ack_irq = uic_ack_irq, |
179 | .pic_finish_setup = NULL, | | 179 | .pic_finish_setup = NULL, |
180 | .pic_name = "uic0" | | 180 | .pic_name = "uic0" |
181 | }; | | 181 | }; |
182 | | | 182 | |
183 | #ifdef MULTIUIC | | 183 | #ifdef MULTIUIC |
184 | | | 184 | |
185 | /* 440EP/440GP/440SP/405EX/440SPe/440GX */ | | 185 | /* 440EP/440GP/440SP/405EX/440SPe/440GX */ |
186 | | | 186 | |
187 | static uint32_t | | 187 | static uint32_t |
188 | uic1_mfdcr_intr_status(void) | | 188 | uic1_mfdcr_intr_status(void) |
189 | { | | 189 | { |
190 | return mfdcr(DCR_UIC1_BASE + DCR_UIC_MSR); | | 190 | return mfdcr(DCR_UIC1_BASE + DCR_UIC_MSR); |
191 | } | | 191 | } |
192 | | | 192 | |
193 | static uint32_t | | 193 | static uint32_t |
194 | uic1_mfdcr_intr_enable(void) | | 194 | uic1_mfdcr_intr_enable(void) |
195 | { | | 195 | { |
196 | return mfdcr(DCR_UIC1_BASE + DCR_UIC_ER); | | 196 | return mfdcr(DCR_UIC1_BASE + DCR_UIC_ER); |
197 | } | | 197 | } |
198 | | | 198 | |
199 | static void | | 199 | static void |
200 | uic1_mtdcr_intr_ack(uint32_t v) | | 200 | uic1_mtdcr_intr_ack(uint32_t v) |
201 | { | | 201 | { |
202 | mtdcr(DCR_UIC1_BASE + DCR_UIC_SR, v); | | 202 | mtdcr(DCR_UIC1_BASE + DCR_UIC_SR, v); |
203 | } | | 203 | } |
204 | | | 204 | |
205 | static void | | 205 | static void |
206 | uic1_mtdcr_intr_enable(uint32_t v) | | 206 | uic1_mtdcr_intr_enable(uint32_t v) |
207 | { | | 207 | { |
208 | mtdcr(DCR_UIC1_BASE + DCR_UIC_ER, v); | | 208 | mtdcr(DCR_UIC1_BASE + DCR_UIC_ER, v); |
209 | } | | 209 | } |
210 | | | 210 | |
211 | extern struct pic_ops pic_uic1; | | 211 | extern struct pic_ops pic_uic1; |
212 | | | 212 | |
213 | static void | | 213 | static void |
214 | uic1_finish_setup(struct pic_ops *pic) | | 214 | uic1_finish_setup(struct pic_ops *pic) |
215 | { | | 215 | { |
216 | intr_establish(30, IST_LEVEL, IPL_HIGH, pic_handle_intr, &pic_uic1); | | 216 | intr_establish(30, IST_LEVEL, IPL_HIGH, pic_handle_intr, &pic_uic1); |
217 | } | | 217 | } |
218 | | | 218 | |
219 | struct uic uic1 = { | | 219 | struct uic uic1 = { |
220 | .uic_intr_enable = 0, | | 220 | .uic_intr_enable = 0, |
221 | .uic_mf_intr_status = uic1_mfdcr_intr_status, | | 221 | .uic_mf_intr_status = uic1_mfdcr_intr_status, |
222 | .uic_mf_intr_enable = uic1_mfdcr_intr_enable, | | 222 | .uic_mf_intr_enable = uic1_mfdcr_intr_enable, |
223 | .uic_mt_intr_enable = uic1_mtdcr_intr_enable, | | 223 | .uic_mt_intr_enable = uic1_mtdcr_intr_enable, |
224 | .uic_mt_intr_ack = uic1_mtdcr_intr_ack, | | 224 | .uic_mt_intr_ack = uic1_mtdcr_intr_ack, |
225 | }; | | 225 | }; |
226 | | | 226 | |
227 | struct pic_ops pic_uic1 = { | | 227 | struct pic_ops pic_uic1 = { |
228 | .pic_cookie = &uic1, | | 228 | .pic_cookie = &uic1, |
229 | .pic_numintrs = 32, | | 229 | .pic_numintrs = 32, |
230 | .pic_enable_irq = uic_enable_irq, | | 230 | .pic_enable_irq = uic_enable_irq, |
231 | .pic_reenable_irq = uic_enable_irq, | | 231 | .pic_reenable_irq = uic_enable_irq, |
232 | .pic_disable_irq = uic_disable_irq, | | 232 | .pic_disable_irq = uic_disable_irq, |
233 | .pic_establish_irq = uic_establish_irq, | | 233 | .pic_establish_irq = uic_establish_irq, |
234 | .pic_get_irq = uic_get_irq, | | 234 | .pic_get_irq = uic_get_irq, |
235 | .pic_ack_irq = uic_ack_irq, | | 235 | .pic_ack_irq = uic_ack_irq, |
236 | .pic_finish_setup = uic1_finish_setup, | | 236 | .pic_finish_setup = uic1_finish_setup, |
237 | .pic_name = "uic1" | | 237 | .pic_name = "uic1" |
238 | }; | | 238 | }; |
239 | | | 239 | |
240 | /* 440EP/440GP/440SP/405EX/440SPe */ | | 240 | /* 440EP/440GP/440SP/405EX/440SPe */ |
241 | | | 241 | |
242 | static uint32_t | | 242 | static uint32_t |
243 | uic2_mfdcr_intr_status(void) | | 243 | uic2_mfdcr_intr_status(void) |
244 | { | | 244 | { |
245 | return mfdcr(DCR_UIC2_BASE + DCR_UIC_MSR); | | 245 | return mfdcr(DCR_UIC2_BASE + DCR_UIC_MSR); |
246 | } | | 246 | } |
247 | | | 247 | |
248 | static uint32_t | | 248 | static uint32_t |
249 | uic2_mfdcr_intr_enable(void) | | 249 | uic2_mfdcr_intr_enable(void) |
250 | { | | 250 | { |
251 | return mfdcr(DCR_UIC2_BASE + DCR_UIC_ER); | | 251 | return mfdcr(DCR_UIC2_BASE + DCR_UIC_ER); |
252 | } | | 252 | } |
253 | | | 253 | |
254 | static void | | 254 | static void |
255 | uic2_mtdcr_intr_ack(uint32_t v) | | 255 | uic2_mtdcr_intr_ack(uint32_t v) |
256 | { | | 256 | { |
257 | mtdcr(DCR_UIC2_BASE + DCR_UIC_SR, v); | | 257 | mtdcr(DCR_UIC2_BASE + DCR_UIC_SR, v); |
258 | } | | 258 | } |
259 | | | 259 | |
260 | static void | | 260 | static void |
261 | uic2_mtdcr_intr_enable(uint32_t v) | | 261 | uic2_mtdcr_intr_enable(uint32_t v) |
262 | { | | 262 | { |
263 | mtdcr(DCR_UIC2_BASE + DCR_UIC_ER, v); | | 263 | mtdcr(DCR_UIC2_BASE + DCR_UIC_ER, v); |
264 | } | | 264 | } |
265 | | | 265 | |
266 | extern struct pic_ops pic_uic2; | | 266 | extern struct pic_ops pic_uic2; |
267 | | | 267 | |
268 | static void | | 268 | static void |
269 | uic2_finish_setup(struct pic_ops *pic) | | 269 | uic2_finish_setup(struct pic_ops *pic) |
270 | { | | 270 | { |
271 | intr_establish(28, IST_LEVEL, IPL_HIGH, pic_handle_intr, &pic_uic2); | | 271 | intr_establish(28, IST_LEVEL, IPL_HIGH, pic_handle_intr, &pic_uic2); |
272 | } | | 272 | } |
273 | | | 273 | |
274 | static struct uic uic2 = { | | 274 | static struct uic uic2 = { |
275 | .uic_intr_enable = 0, | | 275 | .uic_intr_enable = 0, |
276 | .uic_mf_intr_status = uic2_mfdcr_intr_status, | | 276 | .uic_mf_intr_status = uic2_mfdcr_intr_status, |
277 | .uic_mf_intr_enable = uic2_mfdcr_intr_enable, | | 277 | .uic_mf_intr_enable = uic2_mfdcr_intr_enable, |
278 | .uic_mt_intr_enable = uic2_mtdcr_intr_enable, | | 278 | .uic_mt_intr_enable = uic2_mtdcr_intr_enable, |
279 | .uic_mt_intr_ack = uic2_mtdcr_intr_ack, | | 279 | .uic_mt_intr_ack = uic2_mtdcr_intr_ack, |
280 | }; | | 280 | }; |
281 | | | 281 | |
282 | struct pic_ops pic_uic2 = { | | 282 | struct pic_ops pic_uic2 = { |
283 | .pic_cookie = &uic2, | | 283 | .pic_cookie = &uic2, |
284 | .pic_numintrs = 32, | | 284 | .pic_numintrs = 32, |
285 | .pic_enable_irq = uic_enable_irq, | | 285 | .pic_enable_irq = uic_enable_irq, |
286 | .pic_reenable_irq = uic_enable_irq, | | 286 | .pic_reenable_irq = uic_enable_irq, |
287 | .pic_disable_irq = uic_disable_irq, | | 287 | .pic_disable_irq = uic_disable_irq, |
288 | .pic_establish_irq = uic_establish_irq, | | 288 | .pic_establish_irq = uic_establish_irq, |
289 | .pic_get_irq = uic_get_irq, | | 289 | .pic_get_irq = uic_get_irq, |
290 | .pic_ack_irq = uic_ack_irq, | | 290 | .pic_ack_irq = uic_ack_irq, |
291 | .pic_finish_setup = uic2_finish_setup, | | 291 | .pic_finish_setup = uic2_finish_setup, |
292 | .pic_name = "uic2" | | 292 | .pic_name = "uic2" |
293 | }; | | 293 | }; |
294 | | | 294 | |
295 | #endif /* MULTIUIC */ | | 295 | #endif /* MULTIUIC */ |
296 | #endif /* !PPC_IBM403 */ | | 296 | #endif /* !PPC_IBM403 */ |
297 | | | 297 | |
298 | /* Write External Enable Immediate */ | | | |
299 | #define wrteei(en) __asm volatile ("wrteei %0" : : "K"(en)) | | | |
300 | | | | |
301 | /* Enforce In Order Execution of I/O */ | | | |
302 | #define eieio() __asm volatile ("eieio") | | | |
303 | | | | |
304 | /* | | 298 | /* |
305 | * Set up interrupt mapping array. | | 299 | * Set up interrupt mapping array. |
306 | */ | | 300 | */ |
307 | void | | 301 | void |
308 | intr_init(void) | | 302 | intr_init(void) |
309 | { | | 303 | { |
310 | #ifdef PPC_IBM403 | | 304 | #ifdef PPC_IBM403 |
311 | struct pic_ops * const pic = &pic_uic403; | | 305 | struct pic_ops * const pic = &pic_uic403; |
312 | #else | | 306 | #else |
313 | struct pic_ops * const pic = &pic_uic0; | | 307 | struct pic_ops * const pic = &pic_uic0; |
314 | #endif | | 308 | #endif |
315 | struct uic * const uic = pic->pic_cookie; | | 309 | struct uic * const uic = pic->pic_cookie; |
316 | | | 310 | |
317 | uic->uic_mt_intr_enable(0x00000000); /* mask all */ | | 311 | uic->uic_mt_intr_enable(0x00000000); /* mask all */ |
318 | uic->uic_mt_intr_ack(0xffffffff); /* acknowledge all */ | | 312 | uic->uic_mt_intr_ack(0xffffffff); /* acknowledge all */ |
319 | | | 313 | |
320 | pic_add(pic); | | 314 | pic_add(pic); |
321 | } | | 315 | } |
322 | | | 316 | |
323 | static void | | 317 | static void |
324 | uic_disable_irq(struct pic_ops *pic, int irq) | | 318 | uic_disable_irq(struct pic_ops *pic, int irq) |
325 | { | | 319 | { |
326 | struct uic * const uic = pic->pic_cookie; | | 320 | struct uic * const uic = pic->pic_cookie; |
327 | const uint32_t irqmask = IRQ_TO_MASK(irq); | | 321 | const uint32_t irqmask = IRQ_TO_MASK(irq); |
328 | if ((uic->uic_intr_enable & irqmask) == 0) | | 322 | if ((uic->uic_intr_enable & irqmask) == 0) |
329 | return; | | 323 | return; |
330 | uic->uic_intr_enable ^= irqmask; | | 324 | uic->uic_intr_enable ^= irqmask; |
331 | (*uic->uic_mt_intr_enable)(uic->uic_intr_enable); | | 325 | (*uic->uic_mt_intr_enable)(uic->uic_intr_enable); |
332 | #ifdef IRQ_DEBUG | | 326 | #ifdef IRQ_DEBUG |
333 | printf("%s: %s: irq=%d, mask=%08x\n", __func__, | | 327 | printf("%s: %s: irq=%d, mask=%08x\n", __func__, |
334 | pic->pic_name, irq, irqmask); | | 328 | pic->pic_name, irq, irqmask); |
335 | #endif | | 329 | #endif |
336 | } | | 330 | } |
337 | | | 331 | |
338 | static void | | 332 | static void |
339 | uic_enable_irq(struct pic_ops *pic, int irq, int type) | | 333 | uic_enable_irq(struct pic_ops *pic, int irq, int type) |
340 | { | | 334 | { |
341 | struct uic * const uic = pic->pic_cookie; | | 335 | struct uic * const uic = pic->pic_cookie; |
342 | const uint32_t irqmask = IRQ_TO_MASK(irq); | | 336 | const uint32_t irqmask = IRQ_TO_MASK(irq); |
343 | if ((uic->uic_intr_enable & irqmask) != 0) | | 337 | if ((uic->uic_intr_enable & irqmask) != 0) |
344 | return; | | 338 | return; |
345 | uic->uic_intr_enable ^= irqmask; | | 339 | uic->uic_intr_enable ^= irqmask; |
346 | (*uic->uic_mt_intr_enable)(uic->uic_intr_enable); | | 340 | (*uic->uic_mt_intr_enable)(uic->uic_intr_enable); |
347 | #ifdef IRQ_DEBUG | | 341 | #ifdef IRQ_DEBUG |
348 | printf("%s: %s: irq=%d, mask=%08x\n", __func__, | | 342 | printf("%s: %s: irq=%d, mask=%08x\n", __func__, |
349 | pic->pic_name, irq, irqmask); | | 343 | pic->pic_name, irq, irqmask); |
350 | #endif | | 344 | #endif |
351 | } | | 345 | } |
352 | | | 346 | |
353 | static void | | 347 | static void |
354 | uic_ack_irq(struct pic_ops *pic, int irq) | | 348 | uic_ack_irq(struct pic_ops *pic, int irq) |
355 | { | | 349 | { |
356 | struct uic * const uic = pic->pic_cookie; | | 350 | struct uic * const uic = pic->pic_cookie; |
357 | const uint32_t irqmask = IRQ_TO_MASK(irq); | | 351 | const uint32_t irqmask = IRQ_TO_MASK(irq); |
358 | | | 352 | |
359 | (*uic->uic_mt_intr_ack)(irqmask); | | 353 | (*uic->uic_mt_intr_ack)(irqmask); |
360 | } | | 354 | } |
361 | | | 355 | |
362 | static int | | 356 | static int |
363 | uic_get_irq(struct pic_ops *pic, int dummy) | | 357 | uic_get_irq(struct pic_ops *pic, int dummy) |
364 | { | | 358 | { |
365 | struct uic * const uic = pic->pic_cookie; | | 359 | struct uic * const uic = pic->pic_cookie; |
366 | | | 360 | |
367 | const uint32_t irqmask = (*uic->uic_mf_intr_status)(); | | 361 | const uint32_t irqmask = (*uic->uic_mf_intr_status)(); |
368 | if (irqmask == 0) | | 362 | if (irqmask == 0) |
369 | return 255; | | 363 | return 255; |
370 | return IRQ_OF_MASK(irqmask); | | 364 | return IRQ_OF_MASK(irqmask); |
371 | } | | 365 | } |
372 | | | 366 | |
373 | /* | | 367 | /* |
374 | * Register an interrupt handler. | | 368 | * Register an interrupt handler. |
375 | */ | | 369 | */ |
376 | static void | | 370 | static void |
377 | uic_establish_irq(struct pic_ops *pic, int irq, int type, int ipl) | | 371 | uic_establish_irq(struct pic_ops *pic, int irq, int type, int ipl) |
378 | { | | 372 | { |
379 | } | | 373 | } |