Rev 1922 | Rev 1933 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1922 | Rev 1923 | ||
---|---|---|---|
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 <typedefs.h> |
72 | #include <typedefs.h> |
73 | #include <synch/spinlock.h> |
73 | #include <synch/spinlock.h> |
74 | #include <atomic.h> |
- | |
75 | #include <arch.h> |
74 | #include <arch.h> |
76 | 75 | ||
77 | #define KEY_INR 0 |
76 | #define KEY_INR 0 |
78 | #define KEY_DEVNO 1 |
77 | #define KEY_DEVNO 1 |
79 | 78 | ||
80 | /** |
79 | /** |
81 | * Spinlock protecting the hash table. |
80 | * Spinlock protecting the hash table. |
82 | * This lock must be taken only when interrupts are disabled. |
81 | * This lock must be taken only when interrupts are disabled. |
83 | */ |
82 | */ |
84 | SPINLOCK_INITIALIZE(irq_hash_table_lock); |
83 | SPINLOCK_INITIALIZE(irq_hash_table_lock); |
85 | static hash_table_t irq_hash_table; |
84 | static hash_table_t irq_hash_table; |
86 | 85 | ||
87 | /** |
86 | /** |
88 | * Hash table operations for cases when we know that |
87 | * Hash table operations for cases when we know that |
89 | * there will be collisions between different keys. |
88 | * there will be collisions between different keys. |
90 | */ |
89 | */ |
91 | static index_t irq_ht_hash(unative_t *key); |
90 | static index_t irq_ht_hash(unative_t *key); |
92 | static bool irq_ht_compare(unative_t *key, count_t keys, link_t *item); |
91 | static bool irq_ht_compare(unative_t *key, count_t keys, link_t *item); |
93 | 92 | ||
94 | static hash_table_operations_t irq_ht_ops = { |
93 | static hash_table_operations_t irq_ht_ops = { |
95 | .hash = irq_ht_hash, |
94 | .hash = irq_ht_hash, |
96 | .compare = irq_ht_compare, |
95 | .compare = irq_ht_compare, |
97 | .remove_callback = NULL /* not used */ |
96 | .remove_callback = NULL /* not used */ |
98 | }; |
97 | }; |
99 | 98 | ||
100 | /** |
99 | /** |
101 | * Hash table operations for cases when we know that |
100 | * Hash table operations for cases when we know that |
102 | * there will be no collisions between different keys. |
101 | * there will be no collisions between different keys. |
103 | * However, there might be still collisions among |
102 | * However, there might be still collisions among |
104 | * elements with single key (sharing of one IRQ). |
103 | * elements with single key (sharing of one IRQ). |
105 | */ |
104 | */ |
106 | static index_t irq_lin_hash(unative_t *key); |
105 | static index_t irq_lin_hash(unative_t *key); |
107 | static bool irq_lin_compare(unative_t *key, count_t keys, link_t *item); |
106 | static bool irq_lin_compare(unative_t *key, count_t keys, link_t *item); |
108 | 107 | ||
109 | static hash_table_operations_t irq_lin_ops = { |
108 | static hash_table_operations_t irq_lin_ops = { |
110 | .hash = irq_lin_hash, |
109 | .hash = irq_lin_hash, |
111 | .compare = irq_lin_compare, |
110 | .compare = irq_lin_compare, |
112 | .remove_callback = NULL /* not used */ |
111 | .remove_callback = NULL /* not used */ |
113 | }; |
112 | }; |
114 | 113 | ||
115 | /** Initialize IRQ subsystem. |
114 | /** Initialize IRQ subsystem. |
116 | * |
115 | * |
117 | * @param inrs Numbers of unique IRQ numbers or INRs. |
116 | * @param inrs Numbers of unique IRQ numbers or INRs. |
118 | * @param chains Number of chains in the hash table. |
117 | * @param chains Number of chains in the hash table. |
119 | */ |
118 | */ |
120 | void irq_init(count_t inrs, count_t chains) |
119 | void irq_init(count_t inrs, count_t chains) |
121 | { |
120 | { |
122 | /* |
121 | /* |
123 | * Be smart about the choice of the hash table operations. |
122 | * Be smart about the choice of the hash table operations. |
124 | * In cases in which inrs equals the requested number of |
123 | * In cases in which inrs equals the requested number of |
125 | * chains (i.e. where there is no collision between |
124 | * chains (i.e. where there is no collision between |
126 | * different keys), we can use optimized set of operations. |
125 | * different keys), we can use optimized set of operations. |
127 | */ |
126 | */ |
128 | if (inrs == chains) |
127 | if (inrs == chains) |
129 | hash_table_create(&irq_hash_table, chains, 2, &irq_lin_ops); |
128 | hash_table_create(&irq_hash_table, chains, 2, &irq_lin_ops); |
130 | else |
129 | else |
131 | hash_table_create(&irq_hash_table, chains, 2, &irq_ht_ops); |
130 | hash_table_create(&irq_hash_table, chains, 2, &irq_ht_ops); |
132 | } |
131 | } |
133 | 132 | ||
134 | /** Initialize one IRQ structure. |
133 | /** Initialize one IRQ structure. |
135 | * |
134 | * |
136 | * @param irq Pointer to the IRQ structure to be initialized. |
135 | * @param irq Pointer to the IRQ structure to be initialized. |
137 | * |
136 | * |
138 | */ |
137 | */ |
139 | void irq_initialize(irq_t *irq) |
138 | void irq_initialize(irq_t *irq) |
140 | { |
139 | { |
141 | link_initialize(&irq->link); |
140 | link_initialize(&irq->link); |
142 | spinlock_initialize(&irq->lock, "irq.lock"); |
141 | spinlock_initialize(&irq->lock, "irq.lock"); |
143 | irq->inr = -1; |
142 | irq->inr = -1; |
144 | irq->devno = -1; |
143 | irq->devno = -1; |
145 | irq->trigger = 0; |
144 | irq->trigger = 0; |
146 | irq->claim = NULL; |
145 | irq->claim = NULL; |
147 | irq->handler = NULL; |
146 | irq->handler = NULL; |
148 | irq->arg = NULL; |
147 | irq->arg = NULL; |
149 | irq->notif_answerbox = NULL; |
148 | irq->notif_cfg.answerbox = NULL; |
150 | irq->code = NULL; |
149 | irq->notif_cfg.code = NULL; |
151 | irq->method = 0; |
150 | irq->notif_cfg.method = 0; |
152 | atomic_set(&irq->counter, 0); |
151 | irq->notif_cfg.counter = 0; |
153 | } |
152 | } |
154 | 153 | ||
155 | /** Register IRQ for device. |
154 | /** Register IRQ for device. |
156 | * |
155 | * |
157 | * The irq structure must be filled with information |
156 | * The irq structure must be filled with information |
158 | * about the interrupt source and with the claim() |
157 | * about the interrupt source and with the claim() |
159 | * function pointer and irq_handler() function pointer. |
158 | * function pointer and irq_handler() function pointer. |
160 | * |
159 | * |
161 | * @param irq IRQ structure belonging to a device. |
160 | * @param irq IRQ structure belonging to a device. |
162 | */ |
161 | */ |
163 | void irq_register(irq_t *irq) |
162 | void irq_register(irq_t *irq) |
164 | { |
163 | { |
165 | ipl_t ipl; |
164 | ipl_t ipl; |
166 | unative_t key[] = { |
165 | unative_t key[] = { |
167 | (unative_t) irq->inr, |
166 | (unative_t) irq->inr, |
168 | (unative_t) irq->devno |
167 | (unative_t) irq->devno |
169 | }; |
168 | }; |
170 | 169 | ||
171 | ipl = interrupts_disable(); |
170 | ipl = interrupts_disable(); |
172 | spinlock_lock(&irq_hash_table_lock); |
171 | spinlock_lock(&irq_hash_table_lock); |
173 | hash_table_insert(&irq_hash_table, key, &irq->link); |
172 | hash_table_insert(&irq_hash_table, key, &irq->link); |
174 | spinlock_unlock(&irq_hash_table_lock); |
173 | spinlock_unlock(&irq_hash_table_lock); |
175 | interrupts_restore(ipl); |
174 | interrupts_restore(ipl); |
176 | } |
175 | } |
177 | 176 | ||
178 | /** Dispatch the IRQ. |
177 | /** Dispatch the IRQ. |
179 | * |
178 | * |
180 | * We assume this function is only called from interrupt |
179 | * We assume this function is only called from interrupt |
181 | * context (i.e. that interrupts are disabled prior to |
180 | * context (i.e. that interrupts are disabled prior to |
182 | * this call). |
181 | * this call). |
183 | * |
182 | * |
184 | * This function attempts to lookup a fitting IRQ |
183 | * This function attempts to lookup a fitting IRQ |
185 | * structure. In case of success, return with interrupts |
184 | * structure. In case of success, return with interrupts |
186 | * disabled and holding the respective structure. |
185 | * disabled and holding the respective structure. |
187 | * |
186 | * |
188 | * @param inr Interrupt number (aka inr or irq). |
187 | * @param inr Interrupt number (aka inr or irq). |
189 | * |
188 | * |
190 | * @return IRQ structure of the respective device or NULL. |
189 | * @return IRQ structure of the respective device or NULL. |
191 | */ |
190 | */ |
192 | irq_t *irq_dispatch_and_lock(inr_t inr) |
191 | irq_t *irq_dispatch_and_lock(inr_t inr) |
193 | { |
192 | { |
194 | link_t *lnk; |
193 | link_t *lnk; |
195 | unative_t key[] = { |
194 | unative_t key[] = { |
196 | (unative_t) inr, |
195 | (unative_t) inr, |
197 | (unative_t) -1 /* search will use claim() instead of devno */ |
196 | (unative_t) -1 /* search will use claim() instead of devno */ |
198 | }; |
197 | }; |
199 | 198 | ||
200 | spinlock_lock(&irq_hash_table_lock); |
199 | spinlock_lock(&irq_hash_table_lock); |
201 | 200 | ||
202 | lnk = hash_table_find(&irq_hash_table, key); |
201 | lnk = hash_table_find(&irq_hash_table, key); |
203 | if (lnk) { |
202 | if (lnk) { |
204 | irq_t *irq; |
203 | irq_t *irq; |
205 | 204 | ||
206 | irq = hash_table_get_instance(lnk, irq_t, link); |
205 | irq = hash_table_get_instance(lnk, irq_t, link); |
207 | 206 | ||
208 | spinlock_unlock(&irq_hash_table_lock); |
207 | spinlock_unlock(&irq_hash_table_lock); |
209 | return irq; |
208 | return irq; |
210 | } |
209 | } |
211 | 210 | ||
212 | spinlock_unlock(&irq_hash_table_lock); |
211 | spinlock_unlock(&irq_hash_table_lock); |
213 | 212 | ||
214 | return NULL; |
213 | return NULL; |
215 | } |
214 | } |
216 | 215 | ||
217 | /** Find the IRQ structure corresponding to inr and devno. |
216 | /** Find the IRQ structure corresponding to inr and devno. |
218 | * |
217 | * |
219 | * This functions attempts to lookup the IRQ structure |
218 | * This functions attempts to lookup the IRQ structure |
220 | * corresponding to its arguments. On success, this |
219 | * corresponding to its arguments. On success, this |
221 | * function returns with interrups disabled, holding |
220 | * function returns with interrups disabled, holding |
222 | * the lock of the respective IRQ structure. |
221 | * the lock of the respective IRQ structure. |
223 | * |
222 | * |
224 | * This function assumes interrupts are already disabled. |
223 | * This function assumes interrupts are already disabled. |
225 | * |
224 | * |
226 | * @param inr INR being looked up. |
225 | * @param inr INR being looked up. |
227 | * @param devno Devno being looked up. |
226 | * @param devno Devno being looked up. |
228 | * |
227 | * |
229 | * @return Locked IRQ structure on success or NULL on failure. |
228 | * @return Locked IRQ structure on success or NULL on failure. |
230 | */ |
229 | */ |
231 | irq_t *irq_find_and_lock(inr_t inr, devno_t devno) |
230 | irq_t *irq_find_and_lock(inr_t inr, devno_t devno) |
232 | { |
231 | { |
233 | link_t *lnk; |
232 | link_t *lnk; |
234 | unative_t keys[] = { |
233 | unative_t keys[] = { |
235 | (unative_t) inr, |
234 | (unative_t) inr, |
236 | (unative_t) devno |
235 | (unative_t) devno |
237 | }; |
236 | }; |
238 | 237 | ||
239 | spinlock_lock(&irq_hash_table_lock); |
238 | spinlock_lock(&irq_hash_table_lock); |
240 | 239 | ||
241 | lnk = hash_table_find(&irq_hash_table, keys); |
240 | lnk = hash_table_find(&irq_hash_table, keys); |
242 | if (lnk) { |
241 | if (lnk) { |
243 | irq_t *irq; |
242 | irq_t *irq; |
244 | 243 | ||
245 | irq = hash_table_get_instance(lnk, irq_t, link); |
244 | irq = hash_table_get_instance(lnk, irq_t, link); |
246 | 245 | ||
247 | spinlock_unlock(&irq_hash_table_lock); |
246 | spinlock_unlock(&irq_hash_table_lock); |
248 | return irq; |
247 | return irq; |
249 | } |
248 | } |
250 | 249 | ||
251 | spinlock_unlock(&irq_hash_table_lock); |
250 | spinlock_unlock(&irq_hash_table_lock); |
252 | 251 | ||
253 | return NULL; |
252 | return NULL; |
254 | } |
253 | } |
255 | 254 | ||
256 | /** Compute hash index for the key. |
255 | /** Compute hash index for the key. |
257 | * |
256 | * |
258 | * This function computes hash index into |
257 | * This function computes hash index into |
259 | * the IRQ hash table for which there |
258 | * the IRQ hash table for which there |
260 | * can be collisions between different |
259 | * can be collisions between different |
261 | * INRs. |
260 | * INRs. |
262 | * |
261 | * |
263 | * The devno is not used to compute the hash. |
262 | * The devno is not used to compute the hash. |
264 | * |
263 | * |
265 | * @param key The first of the keys is inr and the second is devno or -1. |
264 | * @param key The first of the keys is inr and the second is devno or -1. |
266 | * |
265 | * |
267 | * @return Index into the hash table. |
266 | * @return Index into the hash table. |
268 | */ |
267 | */ |
269 | index_t irq_ht_hash(unative_t key[]) |
268 | index_t irq_ht_hash(unative_t key[]) |
270 | { |
269 | { |
271 | inr_t inr = (inr_t) key[KEY_INR]; |
270 | inr_t inr = (inr_t) key[KEY_INR]; |
272 | return inr % irq_hash_table.entries; |
271 | return inr % irq_hash_table.entries; |
273 | } |
272 | } |
274 | 273 | ||
275 | /** Compare hash table element with a key. |
274 | /** Compare hash table element with a key. |
276 | * |
275 | * |
277 | * There are two things to note about this function. |
276 | * There are two things to note about this function. |
278 | * First, it is used for the more complex architecture setup |
277 | * First, it is used for the more complex architecture setup |
279 | * in which there are way too many interrupt numbers (i.e. inr's) |
278 | * in which there are way too many interrupt numbers (i.e. inr's) |
280 | * to arrange the hash table so that collisions occur only |
279 | * to arrange the hash table so that collisions occur only |
281 | * among same inrs of different devnos. So the explicit check |
280 | * among same inrs of different devnos. So the explicit check |
282 | * for inr match must be done. |
281 | * for inr match must be done. |
283 | * Second, if devno is -1, the second key (i.e. devno) is not |
282 | * Second, if devno is -1, the second key (i.e. devno) is not |
284 | * used for the match and the result of the claim() function |
283 | * used for the match and the result of the claim() function |
285 | * is used instead. |
284 | * is used instead. |
286 | * |
285 | * |
287 | * This function assumes interrupts are already disabled. |
286 | * This function assumes interrupts are already disabled. |
288 | * |
287 | * |
289 | * @param key Keys (i.e. inr and devno). |
288 | * @param key Keys (i.e. inr and devno). |
290 | * @param keys This is 2. |
289 | * @param keys This is 2. |
291 | * @param item The item to compare the key with. |
290 | * @param item The item to compare the key with. |
292 | * |
291 | * |
293 | * @return True on match or false otherwise. |
292 | * @return True on match or false otherwise. |
294 | */ |
293 | */ |
295 | bool irq_ht_compare(unative_t key[], count_t keys, link_t *item) |
294 | bool irq_ht_compare(unative_t key[], count_t keys, link_t *item) |
296 | { |
295 | { |
297 | irq_t *irq = hash_table_get_instance(item, irq_t, link); |
296 | irq_t *irq = hash_table_get_instance(item, irq_t, link); |
298 | inr_t inr = (inr_t) key[KEY_INR]; |
297 | inr_t inr = (inr_t) key[KEY_INR]; |
299 | devno_t devno = (devno_t) key[KEY_DEVNO]; |
298 | devno_t devno = (devno_t) key[KEY_DEVNO]; |
300 | 299 | ||
301 | bool rv; |
300 | bool rv; |
302 | 301 | ||
303 | spinlock_lock(&irq->lock); |
302 | spinlock_lock(&irq->lock); |
304 | if (devno == -1) { |
303 | if (devno == -1) { |
305 | /* Invoked by irq_dispatch(). */ |
304 | /* Invoked by irq_dispatch(). */ |
306 | rv = ((irq->inr == inr) && (irq->claim() == IRQ_ACCEPT)); |
305 | rv = ((irq->inr == inr) && (irq->claim() == IRQ_ACCEPT)); |
307 | } else { |
306 | } else { |
308 | /* Invoked by irq_find(). */ |
307 | /* Invoked by irq_find(). */ |
309 | rv = ((irq->inr == inr) && (irq->devno == devno)); |
308 | rv = ((irq->inr == inr) && (irq->devno == devno)); |
310 | } |
309 | } |
311 | 310 | ||
312 | /* unlock only on non-match */ |
311 | /* unlock only on non-match */ |
313 | if (!rv) |
312 | if (!rv) |
314 | spinlock_unlock(&irq->lock); |
313 | spinlock_unlock(&irq->lock); |
315 | 314 | ||
316 | return rv; |
315 | return rv; |
317 | } |
316 | } |
318 | 317 | ||
319 | /** Compute hash index for the key. |
318 | /** Compute hash index for the key. |
320 | * |
319 | * |
321 | * This function computes hash index into |
320 | * This function computes hash index into |
322 | * the IRQ hash table for which there |
321 | * the IRQ hash table for which there |
323 | * are no collisions between different |
322 | * are no collisions between different |
324 | * INRs. |
323 | * INRs. |
325 | * |
324 | * |
326 | * @param key The first of the keys is inr and the second is devno or -1. |
325 | * @param key The first of the keys is inr and the second is devno or -1. |
327 | * |
326 | * |
328 | * @return Index into the hash table. |
327 | * @return Index into the hash table. |
329 | */ |
328 | */ |
330 | index_t irq_lin_hash(unative_t key[]) |
329 | index_t irq_lin_hash(unative_t key[]) |
331 | { |
330 | { |
332 | inr_t inr = (inr_t) key[KEY_INR]; |
331 | inr_t inr = (inr_t) key[KEY_INR]; |
333 | return inr; |
332 | return inr; |
334 | } |
333 | } |
335 | 334 | ||
336 | /** Compare hash table element with a key. |
335 | /** Compare hash table element with a key. |
337 | * |
336 | * |
338 | * There are two things to note about this function. |
337 | * There are two things to note about this function. |
339 | * First, it is used for the less complex architecture setup |
338 | * First, it is used for the less complex architecture setup |
340 | * in which there are not too many interrupt numbers (i.e. inr's) |
339 | * in which there are not too many interrupt numbers (i.e. inr's) |
341 | * to arrange the hash table so that collisions occur only |
340 | * to arrange the hash table so that collisions occur only |
342 | * among same inrs of different devnos. So the explicit check |
341 | * among same inrs of different devnos. So the explicit check |
343 | * for inr match is not done. |
342 | * for inr match is not done. |
344 | * Second, if devno is -1, the second key (i.e. devno) is not |
343 | * Second, if devno is -1, the second key (i.e. devno) is not |
345 | * used for the match and the result of the claim() function |
344 | * used for the match and the result of the claim() function |
346 | * is used instead. |
345 | * is used instead. |
347 | * |
346 | * |
348 | * This function assumes interrupts are already disabled. |
347 | * This function assumes interrupts are already disabled. |
349 | * |
348 | * |
350 | * @param key Keys (i.e. inr and devno). |
349 | * @param key Keys (i.e. inr and devno). |
351 | * @param keys This is 2. |
350 | * @param keys This is 2. |
352 | * @param item The item to compare the key with. |
351 | * @param item The item to compare the key with. |
353 | * |
352 | * |
354 | * @return True on match or false otherwise. |
353 | * @return True on match or false otherwise. |
355 | */ |
354 | */ |
356 | bool irq_lin_compare(unative_t key[], count_t keys, link_t *item) |
355 | bool irq_lin_compare(unative_t key[], count_t keys, link_t *item) |
357 | { |
356 | { |
358 | irq_t *irq = list_get_instance(item, irq_t, link); |
357 | irq_t *irq = list_get_instance(item, irq_t, link); |
359 | devno_t devno = (devno_t) key[KEY_DEVNO]; |
358 | devno_t devno = (devno_t) key[KEY_DEVNO]; |
360 | bool rv; |
359 | bool rv; |
361 | 360 | ||
362 | spinlock_lock(&irq->lock); |
361 | spinlock_lock(&irq->lock); |
363 | if (devno == -1) { |
362 | if (devno == -1) { |
364 | /* Invoked by irq_dispatch() */ |
363 | /* Invoked by irq_dispatch() */ |
365 | rv = (irq->claim() == IRQ_ACCEPT); |
364 | rv = (irq->claim() == IRQ_ACCEPT); |
366 | } else { |
365 | } else { |
367 | /* Invoked by irq_find() */ |
366 | /* Invoked by irq_find() */ |
368 | rv = (irq->devno == devno); |
367 | rv = (irq->devno == devno); |
369 | } |
368 | } |
370 | 369 | ||
371 | /* unlock only on non-match */ |
370 | /* unlock only on non-match */ |
372 | if (!rv) |
371 | if (!rv) |
373 | spinlock_unlock(&irq->lock); |
372 | spinlock_unlock(&irq->lock); |
374 | 373 | ||
375 | return rv; |
374 | return rv; |
376 | } |
375 | } |
377 | 376 | ||
378 | /** @} |
377 | /** @} |
379 | */ |
378 | */ |
380 | 379 |