Rev 2131 | Rev 2292 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 2131 | Rev 2265 | ||
|---|---|---|---|
| Line 1... | Line 1... | ||
| 1 | /* |
1 | /* |
| 2 | * Copyright (c) 2006 Jakub Jermar |
2 | * Copyright (c) 2006 Jakub Jermar |
| 3 | * All rights reserved. |
3 | * All rights reserved. |
| 4 | * |
4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions |
6 | * modification, are permitted provided that the following conditions |
| 7 | * are met: |
7 | * are met: |
| 8 | * |
8 | * |
| 9 | * - Redistributions of source code must retain the above copyright |
9 | * - Redistributions of source code must retain the above copyright |
| 10 | * notice, this list of conditions and the following disclaimer. |
10 | * notice, this list of conditions and the following disclaimer. |
| 11 | * - Redistributions in binary form must reproduce the above copyright |
11 | * - Redistributions in binary form must reproduce the above copyright |
| 12 | * notice, this list of conditions and the following disclaimer in the |
12 | * notice, this list of conditions and the following disclaimer in the |
| 13 | * documentation and/or other materials provided with the distribution. |
13 | * documentation and/or other materials provided with the distribution. |
| 14 | * - The name of the author may not be used to endorse or promote products |
14 | * - The name of the author may not be used to endorse or promote products |
| 15 | * derived from this software without specific prior written permission. |
15 | * derived from this software without specific prior written permission. |
| 16 | * |
16 | * |
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | */ |
27 | */ |
| 28 | 28 | ||
| 29 | /** @addtogroup genericddi |
29 | /** @addtogroup genericddi |
| 30 | * @{ |
30 | * @{ |
| 31 | */ |
31 | */ |
| 32 | /** |
32 | /** |
| 33 | * @file |
33 | * @file |
| 34 | * @brief IRQ dispatcher. |
34 | * @brief IRQ dispatcher. |
| 35 | * |
35 | * |
| 36 | * This file provides means of connecting IRQs with particular |
36 | * This file provides means of connecting IRQs with particular |
| 37 | * devices and logic for dispatching interrupts to IRQ handlers |
37 | * devices and logic for dispatching interrupts to IRQ handlers |
| 38 | * defined by those devices. |
38 | * defined by those devices. |
| 39 | * |
39 | * |
| 40 | * This code is designed to support: |
40 | * This code is designed to support: |
| 41 | * - multiple devices sharing single IRQ |
41 | * - multiple devices sharing single IRQ |
| 42 | * - multiple IRQs per signle device |
42 | * - multiple IRQs per signle device |
| 43 | * |
43 | * |
| 44 | * |
44 | * |
| 45 | * Note about architectures. |
45 | * Note about architectures. |
| 46 | * |
46 | * |
| 47 | * Some architectures has the term IRQ well defined. Examples |
47 | * Some architectures has the term IRQ well defined. Examples |
| 48 | * of such architectures include amd64, ia32 and mips32. Some |
48 | * of such architectures include amd64, ia32 and mips32. Some |
| 49 | * other architectures, such as sparc64, don't use the term |
49 | * other architectures, such as sparc64, don't use the term |
| 50 | * at all. In those cases, we boldly step forward and define what |
50 | * at all. In those cases, we boldly step forward and define what |
| 51 | * an IRQ is. |
51 | * an IRQ is. |
| 52 | * |
52 | * |
| 53 | * The implementation is generic enough and still allows the |
53 | * The implementation is generic enough and still allows the |
| 54 | * architectures to use the hardware layout effectively. |
54 | * architectures to use the hardware layout effectively. |
| 55 | * For instance, on amd64 and ia32, where there is only 16 |
55 | * For instance, on amd64 and ia32, where there is only 16 |
| 56 | * IRQs, the irq_hash_table can be optimized to a one-dimensional |
56 | * IRQs, the irq_hash_table can be optimized to a one-dimensional |
| 57 | * array. Next, when it is known that the IRQ numbers (aka INR's) |
57 | * array. Next, when it is known that the IRQ numbers (aka INR's) |
| 58 | * are unique, the claim functions can always return IRQ_ACCEPT. |
58 | * are unique, the claim functions can always return IRQ_ACCEPT. |
| 59 | * |
59 | * |
| 60 | * |
60 | * |
| 61 | * Note about the irq_hash_table. |
61 | * Note about the irq_hash_table. |
| 62 | * |
62 | * |
| 63 | * The hash table is configured to use two keys: inr and devno. |
63 | * The hash table is configured to use two keys: inr and devno. |
| 64 | * However, the hash index is computed only from inr. Moreover, |
64 | * However, the hash index is computed only from inr. Moreover, |
| 65 | * if devno is -1, the match is based on the return value of |
65 | * if devno is -1, the match is based on the return value of |
| 66 | * the claim() function instead of on devno. |
66 | * the claim() function instead of on devno. |
| 67 | */ |
67 | */ |
| 68 | 68 | ||
| 69 | #include <ddi/irq.h> |
69 | #include <ddi/irq.h> |
| 70 | #include <adt/hash_table.h> |
70 | #include <adt/hash_table.h> |
| 71 | #include <arch/types.h> |
71 | #include <arch/types.h> |
| 72 | #include <synch/spinlock.h> |
72 | #include <synch/spinlock.h> |
| 73 | #include <arch.h> |
73 | #include <arch.h> |
| 74 | 74 | ||
| 75 | #define KEY_INR 0 |
75 | #define KEY_INR 0 |
| 76 | #define KEY_DEVNO 1 |
76 | #define KEY_DEVNO 1 |
| 77 | 77 | ||
| 78 | /** |
78 | /** |
| 79 | * Spinlock protecting the hash table. |
79 | * Spinlock protecting the hash table. |
| 80 | * This lock must be taken only when interrupts are disabled. |
80 | * This lock must be taken only when interrupts are disabled. |
| 81 | */ |
81 | */ |
| 82 | SPINLOCK_INITIALIZE(irq_hash_table_lock); |
82 | SPINLOCK_INITIALIZE(irq_hash_table_lock); |
| 83 | static hash_table_t irq_hash_table; |
83 | static hash_table_t irq_hash_table; |
| 84 | 84 | ||
| 85 | /** |
85 | /** |
| 86 | * Hash table operations for cases when we know that |
86 | * Hash table operations for cases when we know that |
| 87 | * there will be collisions between different keys. |
87 | * there will be collisions between different keys. |
| 88 | */ |
88 | */ |
| 89 | static index_t irq_ht_hash(unative_t *key); |
89 | static index_t irq_ht_hash(unative_t *key); |
| 90 | static bool irq_ht_compare(unative_t *key, count_t keys, link_t *item); |
90 | static bool irq_ht_compare(unative_t *key, count_t keys, link_t *item); |
| 91 | 91 | ||
| 92 | static hash_table_operations_t irq_ht_ops = { |
92 | static hash_table_operations_t irq_ht_ops = { |
| 93 | .hash = irq_ht_hash, |
93 | .hash = irq_ht_hash, |
| 94 | .compare = irq_ht_compare, |
94 | .compare = irq_ht_compare, |
| 95 | .remove_callback = NULL /* not used */ |
95 | .remove_callback = NULL /* not used */ |
| 96 | }; |
96 | }; |
| 97 | 97 | ||
| 98 | /** |
98 | /** |
| 99 | * Hash table operations for cases when we know that |
99 | * Hash table operations for cases when we know that |
| 100 | * there will be no collisions between different keys. |
100 | * there will be no collisions between different keys. |
| 101 | * However, there might be still collisions among |
101 | * However, there might be still collisions among |
| 102 | * elements with single key (sharing of one IRQ). |
102 | * elements with single key (sharing of one IRQ). |
| 103 | */ |
103 | */ |
| 104 | static index_t irq_lin_hash(unative_t *key); |
104 | static index_t irq_lin_hash(unative_t *key); |
| 105 | static bool irq_lin_compare(unative_t *key, count_t keys, link_t *item); |
105 | static bool irq_lin_compare(unative_t *key, count_t keys, link_t *item); |
| 106 | 106 | ||
| 107 | static hash_table_operations_t irq_lin_ops = { |
107 | static hash_table_operations_t irq_lin_ops = { |
| 108 | .hash = irq_lin_hash, |
108 | .hash = irq_lin_hash, |
| 109 | .compare = irq_lin_compare, |
109 | .compare = irq_lin_compare, |
| 110 | .remove_callback = NULL /* not used */ |
110 | .remove_callback = NULL /* not used */ |
| 111 | }; |
111 | }; |
| 112 | 112 | ||
| 113 | /** Initialize IRQ subsystem. |
113 | /** Initialize IRQ subsystem. |
| 114 | * |
114 | * |
| 115 | * @param inrs Numbers of unique IRQ numbers or INRs. |
115 | * @param inrs Numbers of unique IRQ numbers or INRs. |
| 116 | * @param chains Number of chains in the hash table. |
116 | * @param chains Number of chains in the hash table. |
| 117 | */ |
117 | */ |
| 118 | void irq_init(count_t inrs, count_t chains) |
118 | void irq_init(count_t inrs, count_t chains) |
| 119 | { |
119 | { |
| 120 | /* |
120 | /* |
| 121 | * Be smart about the choice of the hash table operations. |
121 | * Be smart about the choice of the hash table operations. |
| 122 | * In cases in which inrs equals the requested number of |
122 | * In cases in which inrs equals the requested number of |
| 123 | * chains (i.e. where there is no collision between |
123 | * chains (i.e. where there is no collision between |
| 124 | * different keys), we can use optimized set of operations. |
124 | * different keys), we can use optimized set of operations. |
| 125 | */ |
125 | */ |
| 126 | if (inrs == chains) |
126 | if (inrs == chains) |
| 127 | hash_table_create(&irq_hash_table, chains, 2, &irq_lin_ops); |
127 | hash_table_create(&irq_hash_table, chains, 2, &irq_lin_ops); |
| 128 | else |
128 | else |
| 129 | hash_table_create(&irq_hash_table, chains, 2, &irq_ht_ops); |
129 | hash_table_create(&irq_hash_table, chains, 2, &irq_ht_ops); |
| 130 | } |
130 | } |
| 131 | 131 | ||
| 132 | /** Initialize one IRQ structure. |
132 | /** Initialize one IRQ structure. |
| 133 | * |
133 | * |
| 134 | * @param irq Pointer to the IRQ structure to be initialized. |
134 | * @param irq Pointer to the IRQ structure to be initialized. |
| 135 | * |
135 | * |
| 136 | */ |
136 | */ |
| 137 | void irq_initialize(irq_t *irq) |
137 | void irq_initialize(irq_t *irq) |
| 138 | { |
138 | { |
| 139 | link_initialize(&irq->link); |
139 | link_initialize(&irq->link); |
| 140 | spinlock_initialize(&irq->lock, "irq.lock"); |
140 | spinlock_initialize(&irq->lock, "irq.lock"); |
| 141 | irq->inr = -1; |
141 | irq->preack = false; |
| 142 | irq->devno = -1; |
142 | irq->inr = -1; |
| 143 | irq->trigger = (irq_trigger_t) 0; |
143 | irq->devno = -1; |
| 144 | irq->claim = NULL; |
144 | irq->trigger = (irq_trigger_t) 0; |
| 145 | irq->handler = NULL; |
145 | irq->claim = NULL; |
| 146 | irq->arg = NULL; |
146 | irq->handler = NULL; |
| 147 | irq->notif_cfg.notify = false; |
147 | irq->arg = NULL; |
| 148 | irq->notif_cfg.answerbox = NULL; |
148 | irq->notif_cfg.notify = false; |
| 149 | irq->notif_cfg.code = NULL; |
149 | irq->notif_cfg.answerbox = NULL; |
| 150 | irq->notif_cfg.method = 0; |
150 | irq->notif_cfg.code = NULL; |
| 151 | irq->notif_cfg.counter = 0; |
151 | irq->notif_cfg.method = 0; |
| 152 | link_initialize(&irq->notif_cfg.link); |
152 | irq->notif_cfg.counter = 0; |
| 153 | } |
153 | link_initialize(&irq->notif_cfg.link); |
| 154 | 154 | } |
|
| 155 | /** Register IRQ for device. |
155 | |
| 156 | * |
156 | /** Register IRQ for device. |
| 157 | * The irq structure must be filled with information |
157 | * |
| 158 | * about the interrupt source and with the claim() |
158 | * The irq structure must be filled with information |
| 159 | * function pointer and irq_handler() function pointer. |
159 | * about the interrupt source and with the claim() |
| 160 | * |
160 | * function pointer and irq_handler() function pointer. |
| 161 | * @param irq IRQ structure belonging to a device. |
161 | * |
| 162 | */ |
162 | * @param irq IRQ structure belonging to a device. |
| 163 | void irq_register(irq_t *irq) |
163 | */ |
| 164 | { |
164 | void irq_register(irq_t *irq) |
| 165 | ipl_t ipl; |
165 | { |
| 166 | unative_t key[] = { |
166 | ipl_t ipl; |
| 167 | (unative_t) irq->inr, |
167 | unative_t key[] = { |
| 168 | (unative_t) irq->devno |
168 | (unative_t) irq->inr, |
| 169 | }; |
169 | (unative_t) irq->devno |
| 170 | 170 | }; |
|
| 171 | ipl = interrupts_disable(); |
171 | |
| 172 | spinlock_lock(&irq_hash_table_lock); |
172 | ipl = interrupts_disable(); |
| 173 | hash_table_insert(&irq_hash_table, key, &irq->link); |
173 | spinlock_lock(&irq_hash_table_lock); |
| 174 | spinlock_unlock(&irq_hash_table_lock); |
174 | hash_table_insert(&irq_hash_table, key, &irq->link); |
| 175 | interrupts_restore(ipl); |
175 | spinlock_unlock(&irq_hash_table_lock); |
| 176 | } |
176 | interrupts_restore(ipl); |
| 177 | 177 | } |
|
| 178 | /** Dispatch the IRQ. |
178 | |
| 179 | * |
179 | /** Dispatch the IRQ. |
| 180 | * We assume this function is only called from interrupt |
180 | * |
| 181 | * context (i.e. that interrupts are disabled prior to |
181 | * We assume this function is only called from interrupt |
| 182 | * this call). |
182 | * context (i.e. that interrupts are disabled prior to |
| 183 | * |
183 | * this call). |
| 184 | * This function attempts to lookup a fitting IRQ |
184 | * |
| 185 | * structure. In case of success, return with interrupts |
185 | * This function attempts to lookup a fitting IRQ |
| 186 | * disabled and holding the respective structure. |
186 | * structure. In case of success, return with interrupts |
| 187 | * |
187 | * disabled and holding the respective structure. |
| 188 | * @param inr Interrupt number (aka inr or irq). |
188 | * |
| 189 | * |
189 | * @param inr Interrupt number (aka inr or irq). |
| 190 | * @return IRQ structure of the respective device or NULL. |
190 | * |
| 191 | */ |
191 | * @return IRQ structure of the respective device or NULL. |
| 192 | irq_t *irq_dispatch_and_lock(inr_t inr) |
192 | */ |
| 193 | { |
193 | irq_t *irq_dispatch_and_lock(inr_t inr) |
| 194 | link_t *lnk; |
194 | { |
| 195 | unative_t key[] = { |
195 | link_t *lnk; |
| 196 | (unative_t) inr, |
196 | unative_t key[] = { |
| 197 | (unative_t) -1 /* search will use claim() instead of devno */ |
197 | (unative_t) inr, |
| 198 | }; |
198 | (unative_t) -1 /* search will use claim() instead of devno */ |
| 199 | 199 | }; |
|
| 200 | spinlock_lock(&irq_hash_table_lock); |
200 | |
| 201 | 201 | spinlock_lock(&irq_hash_table_lock); |
|
| 202 | lnk = hash_table_find(&irq_hash_table, key); |
202 | |
| 203 | if (lnk) { |
203 | lnk = hash_table_find(&irq_hash_table, key); |
| 204 | irq_t *irq; |
204 | if (lnk) { |
| 205 | 205 | irq_t *irq; |
|
| 206 | irq = hash_table_get_instance(lnk, irq_t, link); |
206 | |
| 207 | 207 | irq = hash_table_get_instance(lnk, irq_t, link); |
|
| 208 | spinlock_unlock(&irq_hash_table_lock); |
208 | |
| 209 | return irq; |
209 | spinlock_unlock(&irq_hash_table_lock); |
| 210 | } |
210 | return irq; |
| 211 | 211 | } |
|
| 212 | spinlock_unlock(&irq_hash_table_lock); |
212 | |
| 213 | 213 | spinlock_unlock(&irq_hash_table_lock); |
|
| 214 | return NULL; |
214 | |
| 215 | } |
215 | return NULL; |
| 216 | 216 | } |
|
| 217 | /** Find the IRQ structure corresponding to inr and devno. |
217 | |
| 218 | * |
218 | /** Find the IRQ structure corresponding to inr and devno. |
| 219 | * This functions attempts to lookup the IRQ structure |
219 | * |
| 220 | * corresponding to its arguments. On success, this |
220 | * This functions attempts to lookup the IRQ structure |
| 221 | * function returns with interrups disabled, holding |
221 | * corresponding to its arguments. On success, this |
| 222 | * the lock of the respective IRQ structure. |
222 | * function returns with interrups disabled, holding |
| 223 | * |
223 | * the lock of the respective IRQ structure. |
| 224 | * This function assumes interrupts are already disabled. |
224 | * |
| 225 | * |
225 | * This function assumes interrupts are already disabled. |
| 226 | * @param inr INR being looked up. |
226 | * |
| 227 | * @param devno Devno being looked up. |
227 | * @param inr INR being looked up. |
| 228 | * |
228 | * @param devno Devno being looked up. |
| 229 | * @return Locked IRQ structure on success or NULL on failure. |
229 | * |
| 230 | */ |
230 | * @return Locked IRQ structure on success or NULL on failure. |
| 231 | irq_t *irq_find_and_lock(inr_t inr, devno_t devno) |
231 | */ |
| 232 | { |
232 | irq_t *irq_find_and_lock(inr_t inr, devno_t devno) |
| 233 | link_t *lnk; |
233 | { |
| 234 | unative_t keys[] = { |
234 | link_t *lnk; |
| 235 | (unative_t) inr, |
235 | unative_t keys[] = { |
| 236 | (unative_t) devno |
236 | (unative_t) inr, |
| 237 | }; |
237 | (unative_t) devno |
| 238 | 238 | }; |
|
| 239 | spinlock_lock(&irq_hash_table_lock); |
239 | |
| 240 | 240 | spinlock_lock(&irq_hash_table_lock); |
|
| 241 | lnk = hash_table_find(&irq_hash_table, keys); |
241 | |
| 242 | if (lnk) { |
242 | lnk = hash_table_find(&irq_hash_table, keys); |
| 243 | irq_t *irq; |
243 | if (lnk) { |
| 244 | 244 | irq_t *irq; |
|
| 245 | irq = hash_table_get_instance(lnk, irq_t, link); |
245 | |
| 246 | 246 | irq = hash_table_get_instance(lnk, irq_t, link); |
|
| 247 | spinlock_unlock(&irq_hash_table_lock); |
247 | |
| 248 | return irq; |
248 | spinlock_unlock(&irq_hash_table_lock); |
| 249 | } |
249 | return irq; |
| 250 | 250 | } |
|
| 251 | spinlock_unlock(&irq_hash_table_lock); |
251 | |
| 252 | 252 | spinlock_unlock(&irq_hash_table_lock); |
|
| 253 | return NULL; |
253 | |
| 254 | } |
254 | return NULL; |
| 255 | 255 | } |
|
| 256 | /** Compute hash index for the key. |
256 | |
| 257 | * |
257 | /** Compute hash index for the key. |
| 258 | * This function computes hash index into |
258 | * |
| 259 | * the IRQ hash table for which there |
259 | * This function computes hash index into |
| 260 | * can be collisions between different |
260 | * the IRQ hash table for which there |
| 261 | * INRs. |
261 | * can be collisions between different |
| 262 | * |
262 | * INRs. |
| 263 | * The devno is not used to compute the hash. |
263 | * |
| 264 | * |
264 | * The devno is not used to compute the hash. |
| 265 | * @param key The first of the keys is inr and the second is devno or -1. |
265 | * |
| 266 | * |
266 | * @param key The first of the keys is inr and the second is devno or -1. |
| 267 | * @return Index into the hash table. |
267 | * |
| 268 | */ |
268 | * @return Index into the hash table. |
| 269 | index_t irq_ht_hash(unative_t key[]) |
269 | */ |
| 270 | { |
270 | index_t irq_ht_hash(unative_t key[]) |
| 271 | inr_t inr = (inr_t) key[KEY_INR]; |
271 | { |
| 272 | return inr % irq_hash_table.entries; |
272 | inr_t inr = (inr_t) key[KEY_INR]; |
| 273 | } |
273 | return inr % irq_hash_table.entries; |
| 274 | 274 | } |
|
| 275 | /** Compare hash table element with a key. |
275 | |
| 276 | * |
276 | /** Compare hash table element with a key. |
| 277 | * There are two things to note about this function. |
277 | * |
| 278 | * First, it is used for the more complex architecture setup |
278 | * There are two things to note about this function. |
| 279 | * in which there are way too many interrupt numbers (i.e. inr's) |
279 | * First, it is used for the more complex architecture setup |
| 280 | * to arrange the hash table so that collisions occur only |
280 | * in which there are way too many interrupt numbers (i.e. inr's) |
| 281 | * among same inrs of different devnos. So the explicit check |
281 | * to arrange the hash table so that collisions occur only |
| 282 | * for inr match must be done. |
282 | * among same inrs of different devnos. So the explicit check |
| 283 | * Second, if devno is -1, the second key (i.e. devno) is not |
283 | * for inr match must be done. |
| 284 | * used for the match and the result of the claim() function |
284 | * Second, if devno is -1, the second key (i.e. devno) is not |
| 285 | * is used instead. |
285 | * used for the match and the result of the claim() function |
| 286 | * |
286 | * is used instead. |
| 287 | * This function assumes interrupts are already disabled. |
287 | * |
| 288 | * |
288 | * This function assumes interrupts are already disabled. |
| 289 | * @param key Keys (i.e. inr and devno). |
289 | * |
| 290 | * @param keys This is 2. |
290 | * @param key Keys (i.e. inr and devno). |
| 291 | * @param item The item to compare the key with. |
291 | * @param keys This is 2. |
| 292 | * |
292 | * @param item The item to compare the key with. |
| 293 | * @return True on match or false otherwise. |
293 | * |
| 294 | */ |
294 | * @return True on match or false otherwise. |
| 295 | bool irq_ht_compare(unative_t key[], count_t keys, link_t *item) |
295 | */ |
| 296 | { |
296 | bool irq_ht_compare(unative_t key[], count_t keys, link_t *item) |
| 297 | irq_t *irq = hash_table_get_instance(item, irq_t, link); |
297 | { |
| 298 | inr_t inr = (inr_t) key[KEY_INR]; |
298 | irq_t *irq = hash_table_get_instance(item, irq_t, link); |
| 299 | devno_t devno = (devno_t) key[KEY_DEVNO]; |
299 | inr_t inr = (inr_t) key[KEY_INR]; |
| 300 | 300 | devno_t devno = (devno_t) key[KEY_DEVNO]; |
|
| 301 | bool rv; |
301 | |
| 302 | 302 | bool rv; |
|
| 303 | spinlock_lock(&irq->lock); |
303 | |
| 304 | if (devno == -1) { |
304 | spinlock_lock(&irq->lock); |
| 305 | /* Invoked by irq_dispatch_and_lock(). */ |
305 | if (devno == -1) { |
| 306 | rv = ((irq->inr == inr) && (irq->claim() == IRQ_ACCEPT)); |
306 | /* Invoked by irq_dispatch_and_lock(). */ |
| 307 | } else { |
307 | rv = ((irq->inr == inr) && (irq->claim() == IRQ_ACCEPT)); |
| 308 | /* Invoked by irq_find_and_lock(). */ |
308 | } else { |
| 309 | rv = ((irq->inr == inr) && (irq->devno == devno)); |
309 | /* Invoked by irq_find_and_lock(). */ |
| 310 | } |
310 | rv = ((irq->inr == inr) && (irq->devno == devno)); |
| 311 | 311 | } |
|
| 312 | /* unlock only on non-match */ |
312 | |
| 313 | if (!rv) |
313 | /* unlock only on non-match */ |
| 314 | spinlock_unlock(&irq->lock); |
314 | if (!rv) |
| 315 | 315 | spinlock_unlock(&irq->lock); |
|
| 316 | return rv; |
316 | |
| 317 | } |
317 | return rv; |
| 318 | 318 | } |
|
| 319 | /** Compute hash index for the key. |
319 | |
| 320 | * |
320 | /** Compute hash index for the key. |
| 321 | * This function computes hash index into |
321 | * |
| 322 | * the IRQ hash table for which there |
322 | * This function computes hash index into |
| 323 | * are no collisions between different |
323 | * the IRQ hash table for which there |
| 324 | * INRs. |
324 | * are no collisions between different |
| 325 | * |
325 | * INRs. |
| 326 | * @param key The first of the keys is inr and the second is devno or -1. |
326 | * |
| 327 | * |
327 | * @param key The first of the keys is inr and the second is devno or -1. |
| 328 | * @return Index into the hash table. |
328 | * |
| 329 | */ |
329 | * @return Index into the hash table. |
| 330 | index_t irq_lin_hash(unative_t key[]) |
330 | */ |
| 331 | { |
331 | index_t irq_lin_hash(unative_t key[]) |
| 332 | inr_t inr = (inr_t) key[KEY_INR]; |
332 | { |
| 333 | return inr; |
333 | inr_t inr = (inr_t) key[KEY_INR]; |
| 334 | } |
334 | return inr; |
| 335 | 335 | } |
|
| 336 | /** Compare hash table element with a key. |
336 | |
| 337 | * |
337 | /** Compare hash table element with a key. |
| 338 | * There are two things to note about this function. |
338 | * |
| 339 | * First, it is used for the less complex architecture setup |
339 | * There are two things to note about this function. |
| 340 | * in which there are not too many interrupt numbers (i.e. inr's) |
340 | * First, it is used for the less complex architecture setup |
| 341 | * to arrange the hash table so that collisions occur only |
341 | * in which there are not too many interrupt numbers (i.e. inr's) |
| 342 | * among same inrs of different devnos. So the explicit check |
342 | * to arrange the hash table so that collisions occur only |
| 343 | * for inr match is not done. |
343 | * among same inrs of different devnos. So the explicit check |
| 344 | * Second, if devno is -1, the second key (i.e. devno) is not |
344 | * for inr match is not done. |
| 345 | * used for the match and the result of the claim() function |
345 | * Second, if devno is -1, the second key (i.e. devno) is not |
| 346 | * is used instead. |
346 | * used for the match and the result of the claim() function |
| 347 | * |
347 | * is used instead. |
| 348 | * This function assumes interrupts are already disabled. |
348 | * |
| 349 | * |
349 | * This function assumes interrupts are already disabled. |
| 350 | * @param key Keys (i.e. inr and devno). |
350 | * |
| 351 | * @param keys This is 2. |
351 | * @param key Keys (i.e. inr and devno). |
| 352 | * @param item The item to compare the key with. |
352 | * @param keys This is 2. |
| 353 | * |
353 | * @param item The item to compare the key with. |
| 354 | * @return True on match or false otherwise. |
354 | * |
| 355 | */ |
355 | * @return True on match or false otherwise. |
| 356 | bool irq_lin_compare(unative_t key[], count_t keys, link_t *item) |
356 | */ |
| 357 | { |
357 | bool irq_lin_compare(unative_t key[], count_t keys, link_t *item) |
| 358 | irq_t *irq = list_get_instance(item, irq_t, link); |
358 | { |
| 359 | devno_t devno = (devno_t) key[KEY_DEVNO]; |
359 | irq_t *irq = list_get_instance(item, irq_t, link); |
| 360 | bool rv; |
360 | devno_t devno = (devno_t) key[KEY_DEVNO]; |
| 361 | 361 | bool rv; |
|
| 362 | spinlock_lock(&irq->lock); |
362 | |
| 363 | if (devno == -1) { |
363 | spinlock_lock(&irq->lock); |
| 364 | /* Invoked by irq_dispatch_and_lock() */ |
364 | if (devno == -1) { |
| 365 | rv = (irq->claim() == IRQ_ACCEPT); |
365 | /* Invoked by irq_dispatch_and_lock() */ |
| 366 | } else { |
366 | rv = (irq->claim() == IRQ_ACCEPT); |
| 367 | /* Invoked by irq_find_and_lock() */ |
367 | } else { |
| 368 | rv = (irq->devno == devno); |
368 | /* Invoked by irq_find_and_lock() */ |
| 369 | } |
369 | rv = (irq->devno == devno); |
| 370 | 370 | } |
|
| 371 | /* unlock only on non-match */ |
371 | |
| 372 | if (!rv) |
372 | /* unlock only on non-match */ |
| 373 | spinlock_unlock(&irq->lock); |
373 | if (!rv) |
| 374 | 374 | spinlock_unlock(&irq->lock); |
|
| 375 | return rv; |
375 | |
| 376 | } |
376 | return rv; |
| 377 | 377 | } |
|
| 378 | /** @} |
378 | |
| 379 | */ |
379 | /** @} |
| - | 380 | */ |
|