Rev 4153 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4153 | Rev 4263 | ||
---|---|---|---|
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 single device |
42 | * - multiple IRQs per single device |
43 | * - multiple instances of the same device |
43 | * - multiple instances of the same device |
44 | * |
44 | * |
45 | * |
45 | * |
46 | * Note about architectures. |
46 | * Note about architectures. |
47 | * |
47 | * |
48 | * Some architectures has the term IRQ well defined. Examples |
48 | * Some architectures has the term IRQ well defined. Examples |
49 | * of such architectures include amd64, ia32 and mips32. Some |
49 | * of such architectures include amd64, ia32 and mips32. Some |
50 | * other architectures, such as sparc64, don't use the term |
50 | * other architectures, such as sparc64, don't use the term |
51 | * at all. In those cases, we boldly step forward and define what |
51 | * at all. In those cases, we boldly step forward and define what |
52 | * an IRQ is. |
52 | * an IRQ is. |
53 | * |
53 | * |
54 | * The implementation is generic enough and still allows the |
54 | * The implementation is generic enough and still allows the |
55 | * architectures to use the hardware layout effectively. |
55 | * architectures to use the hardware layout effectively. |
56 | * For instance, on amd64 and ia32, where there is only 16 |
56 | * For instance, on amd64 and ia32, where there is only 16 |
57 | * IRQs, the irq_hash_table can be optimized to a one-dimensional |
57 | * IRQs, the irq_hash_table can be optimized to a one-dimensional |
58 | * array. Next, when it is known that the IRQ numbers (aka INR's) |
58 | * array. Next, when it is known that the IRQ numbers (aka INR's) |
59 | * are unique, the claim functions can always return IRQ_ACCEPT. |
59 | * are unique, the claim functions can always return IRQ_ACCEPT. |
60 | * |
60 | * |
61 | * |
61 | * |
62 | * Note about the irq_hash_table. |
62 | * Note about the irq_hash_table. |
63 | * |
63 | * |
64 | * The hash table is configured to use two keys: inr and devno. |
64 | * The hash table is configured to use two keys: inr and devno. |
65 | * However, the hash index is computed only from inr. Moreover, |
65 | * However, the hash index is computed only from inr. Moreover, |
66 | * if devno is -1, the match is based on the return value of |
66 | * if devno is -1, the match is based on the return value of |
67 | * the claim() function instead of on devno. |
67 | * the claim() function instead of on devno. |
68 | */ |
68 | */ |
69 | 69 | ||
70 | #include <ddi/irq.h> |
70 | #include <ddi/irq.h> |
71 | #include <adt/hash_table.h> |
71 | #include <adt/hash_table.h> |
72 | #include <mm/slab.h> |
72 | #include <mm/slab.h> |
73 | #include <arch/types.h> |
73 | #include <arch/types.h> |
74 | #include <synch/spinlock.h> |
74 | #include <synch/spinlock.h> |
75 | #include <console/console.h> |
75 | #include <console/console.h> |
76 | #include <memstr.h> |
76 | #include <memstr.h> |
77 | #include <arch.h> |
77 | #include <arch.h> |
78 | 78 | ||
79 | #define KEY_INR 0 |
79 | #define KEY_INR 0 |
80 | #define KEY_DEVNO 1 |
80 | #define KEY_DEVNO 1 |
81 | 81 | ||
82 | /** |
82 | /** |
83 | * Spinlock protecting the kernel IRQ hash table. |
83 | * Spinlock protecting the kernel IRQ hash table. |
84 | * This lock must be taken only when interrupts are disabled. |
84 | * This lock must be taken only when interrupts are disabled. |
85 | */ |
85 | */ |
86 | SPINLOCK_INITIALIZE(irq_kernel_hash_table_lock); |
86 | SPINLOCK_INITIALIZE(irq_kernel_hash_table_lock); |
87 | /** The kernel IRQ hash table. */ |
87 | /** The kernel IRQ hash table. */ |
88 | static hash_table_t irq_kernel_hash_table; |
88 | static hash_table_t irq_kernel_hash_table; |
89 | 89 | ||
90 | /** |
90 | /** |
91 | * Spinlock protecting the uspace IRQ hash table. |
91 | * Spinlock protecting the uspace IRQ hash table. |
92 | * This lock must be taken only when interrupts are disabled. |
92 | * This lock must be taken only when interrupts are disabled. |
93 | */ |
93 | */ |
94 | SPINLOCK_INITIALIZE(irq_uspace_hash_table_lock); |
94 | SPINLOCK_INITIALIZE(irq_uspace_hash_table_lock); |
95 | /** The uspace IRQ hash table. */ |
95 | /** The uspace IRQ hash table. */ |
96 | hash_table_t irq_uspace_hash_table; |
96 | hash_table_t irq_uspace_hash_table; |
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 collisions between different keys. |
100 | * there will be collisions between different keys. |
101 | */ |
101 | */ |
102 | static index_t irq_ht_hash(unative_t *key); |
102 | static index_t irq_ht_hash(unative_t *key); |
103 | static bool irq_ht_compare(unative_t *key, count_t keys, link_t *item); |
103 | static bool irq_ht_compare(unative_t *key, count_t keys, link_t *item); |
- | 104 | static void irq_ht_remove(link_t *item); |
|
104 | 105 | ||
105 | static hash_table_operations_t irq_ht_ops = { |
106 | static hash_table_operations_t irq_ht_ops = { |
106 | .hash = irq_ht_hash, |
107 | .hash = irq_ht_hash, |
107 | .compare = irq_ht_compare, |
108 | .compare = irq_ht_compare, |
108 | .remove_callback = NULL /* not used */ |
109 | .remove_callback = irq_ht_remove, |
109 | }; |
110 | }; |
110 | 111 | ||
111 | /** |
112 | /** |
112 | * Hash table operations for cases when we know that |
113 | * Hash table operations for cases when we know that |
113 | * there will be no collisions between different keys. |
114 | * there will be no collisions between different keys. |
114 | * However, there might be still collisions among |
115 | * However, there might be still collisions among |
115 | * elements with single key (sharing of one IRQ). |
116 | * elements with single key (sharing of one IRQ). |
116 | */ |
117 | */ |
117 | static index_t irq_lin_hash(unative_t *key); |
118 | static index_t irq_lin_hash(unative_t *key); |
118 | static bool irq_lin_compare(unative_t *key, count_t keys, link_t *item); |
119 | static bool irq_lin_compare(unative_t *key, count_t keys, link_t *item); |
- | 120 | static void irq_lin_remove(link_t *item); |
|
119 | 121 | ||
120 | static hash_table_operations_t irq_lin_ops = { |
122 | static hash_table_operations_t irq_lin_ops = { |
121 | .hash = irq_lin_hash, |
123 | .hash = irq_lin_hash, |
122 | .compare = irq_lin_compare, |
124 | .compare = irq_lin_compare, |
123 | .remove_callback = NULL /* not used */ |
125 | .remove_callback = irq_lin_remove, |
124 | }; |
126 | }; |
125 | 127 | ||
126 | /** Number of buckets in either of the hash tables. */ |
128 | /** Number of buckets in either of the hash tables. */ |
127 | static count_t buckets; |
129 | static count_t buckets; |
128 | 130 | ||
129 | /** Initialize IRQ subsystem. |
131 | /** Initialize IRQ subsystem. |
130 | * |
132 | * |
131 | * @param inrs Numbers of unique IRQ numbers or INRs. |
133 | * @param inrs Numbers of unique IRQ numbers or INRs. |
132 | * @param chains Number of chains in the hash table. |
134 | * @param chains Number of chains in the hash table. |
133 | */ |
135 | */ |
134 | void irq_init(count_t inrs, count_t chains) |
136 | void irq_init(count_t inrs, count_t chains) |
135 | { |
137 | { |
136 | buckets = chains; |
138 | buckets = chains; |
137 | /* |
139 | /* |
138 | * Be smart about the choice of the hash table operations. |
140 | * Be smart about the choice of the hash table operations. |
139 | * In cases in which inrs equals the requested number of |
141 | * In cases in which inrs equals the requested number of |
140 | * chains (i.e. where there is no collision between |
142 | * chains (i.e. where there is no collision between |
141 | * different keys), we can use optimized set of operations. |
143 | * different keys), we can use optimized set of operations. |
142 | */ |
144 | */ |
143 | if (inrs == chains) { |
145 | if (inrs == chains) { |
144 | hash_table_create(&irq_uspace_hash_table, chains, 2, |
146 | hash_table_create(&irq_uspace_hash_table, chains, 2, |
145 | &irq_lin_ops); |
147 | &irq_lin_ops); |
146 | hash_table_create(&irq_kernel_hash_table, chains, 2, |
148 | hash_table_create(&irq_kernel_hash_table, chains, 2, |
147 | &irq_lin_ops); |
149 | &irq_lin_ops); |
148 | } else { |
150 | } else { |
149 | hash_table_create(&irq_uspace_hash_table, chains, 2, |
151 | hash_table_create(&irq_uspace_hash_table, chains, 2, |
150 | &irq_ht_ops); |
152 | &irq_ht_ops); |
151 | hash_table_create(&irq_kernel_hash_table, chains, 2, |
153 | hash_table_create(&irq_kernel_hash_table, chains, 2, |
152 | &irq_ht_ops); |
154 | &irq_ht_ops); |
153 | } |
155 | } |
154 | } |
156 | } |
155 | 157 | ||
156 | /** Initialize one IRQ structure. |
158 | /** Initialize one IRQ structure. |
157 | * |
159 | * |
158 | * @param irq Pointer to the IRQ structure to be initialized. |
160 | * @param irq Pointer to the IRQ structure to be initialized. |
159 | * |
161 | * |
160 | */ |
162 | */ |
161 | void irq_initialize(irq_t *irq) |
163 | void irq_initialize(irq_t *irq) |
162 | { |
164 | { |
163 | memsetb(irq, sizeof(irq_t), 0); |
165 | memsetb(irq, sizeof(irq_t), 0); |
164 | link_initialize(&irq->link); |
166 | link_initialize(&irq->link); |
165 | spinlock_initialize(&irq->lock, "irq.lock"); |
167 | spinlock_initialize(&irq->lock, "irq.lock"); |
166 | link_initialize(&irq->notif_cfg.link); |
168 | link_initialize(&irq->notif_cfg.link); |
167 | irq->inr = -1; |
169 | irq->inr = -1; |
168 | irq->devno = -1; |
170 | irq->devno = -1; |
169 | } |
171 | } |
170 | 172 | ||
171 | /** Register IRQ for device. |
173 | /** Register IRQ for device. |
172 | * |
174 | * |
173 | * The irq structure must be filled with information |
175 | * The irq structure must be filled with information |
174 | * about the interrupt source and with the claim() |
176 | * about the interrupt source and with the claim() |
175 | * function pointer and handler() function pointer. |
177 | * function pointer and handler() function pointer. |
176 | * |
178 | * |
177 | * @param irq IRQ structure belonging to a device. |
179 | * @param irq IRQ structure belonging to a device. |
178 | * @return True on success, false on failure. |
180 | * @return True on success, false on failure. |
179 | */ |
181 | */ |
180 | void irq_register(irq_t *irq) |
182 | void irq_register(irq_t *irq) |
181 | { |
183 | { |
182 | ipl_t ipl; |
184 | ipl_t ipl; |
183 | unative_t key[] = { |
185 | unative_t key[] = { |
184 | (unative_t) irq->inr, |
186 | (unative_t) irq->inr, |
185 | (unative_t) irq->devno |
187 | (unative_t) irq->devno |
186 | }; |
188 | }; |
187 | 189 | ||
188 | ipl = interrupts_disable(); |
190 | ipl = interrupts_disable(); |
189 | spinlock_lock(&irq_kernel_hash_table_lock); |
191 | spinlock_lock(&irq_kernel_hash_table_lock); |
190 | spinlock_lock(&irq->lock); |
192 | spinlock_lock(&irq->lock); |
191 | hash_table_insert(&irq_kernel_hash_table, key, &irq->link); |
193 | hash_table_insert(&irq_kernel_hash_table, key, &irq->link); |
192 | spinlock_unlock(&irq->lock); |
194 | spinlock_unlock(&irq->lock); |
193 | spinlock_unlock(&irq_kernel_hash_table_lock); |
195 | spinlock_unlock(&irq_kernel_hash_table_lock); |
194 | interrupts_restore(ipl); |
196 | interrupts_restore(ipl); |
195 | } |
197 | } |
196 | 198 | ||
197 | /** Search and lock the uspace IRQ hash table. |
199 | /** Search and lock the uspace IRQ hash table. |
198 | * |
200 | * |
199 | */ |
201 | */ |
200 | static irq_t *irq_dispatch_and_lock_uspace(inr_t inr) |
202 | static irq_t *irq_dispatch_and_lock_uspace(inr_t inr) |
201 | { |
203 | { |
202 | link_t *lnk; |
204 | link_t *lnk; |
203 | unative_t key[] = { |
205 | unative_t key[] = { |
204 | (unative_t) inr, |
206 | (unative_t) inr, |
205 | (unative_t) -1 /* search will use claim() instead of devno */ |
207 | (unative_t) -1 /* search will use claim() instead of devno */ |
206 | }; |
208 | }; |
207 | 209 | ||
208 | spinlock_lock(&irq_uspace_hash_table_lock); |
210 | spinlock_lock(&irq_uspace_hash_table_lock); |
209 | lnk = hash_table_find(&irq_uspace_hash_table, key); |
211 | lnk = hash_table_find(&irq_uspace_hash_table, key); |
210 | if (lnk) { |
212 | if (lnk) { |
211 | irq_t *irq; |
213 | irq_t *irq; |
212 | 214 | ||
213 | irq = hash_table_get_instance(lnk, irq_t, link); |
215 | irq = hash_table_get_instance(lnk, irq_t, link); |
214 | spinlock_unlock(&irq_uspace_hash_table_lock); |
216 | spinlock_unlock(&irq_uspace_hash_table_lock); |
215 | return irq; |
217 | return irq; |
216 | } |
218 | } |
217 | spinlock_unlock(&irq_uspace_hash_table_lock); |
219 | spinlock_unlock(&irq_uspace_hash_table_lock); |
218 | 220 | ||
219 | return NULL; |
221 | return NULL; |
220 | } |
222 | } |
221 | 223 | ||
222 | /** Search and lock the kernel IRQ hash table. |
224 | /** Search and lock the kernel IRQ hash table. |
223 | * |
225 | * |
224 | */ |
226 | */ |
225 | static irq_t *irq_dispatch_and_lock_kernel(inr_t inr) |
227 | static irq_t *irq_dispatch_and_lock_kernel(inr_t inr) |
226 | { |
228 | { |
227 | link_t *lnk; |
229 | link_t *lnk; |
228 | unative_t key[] = { |
230 | unative_t key[] = { |
229 | (unative_t) inr, |
231 | (unative_t) inr, |
230 | (unative_t) -1 /* search will use claim() instead of devno */ |
232 | (unative_t) -1 /* search will use claim() instead of devno */ |
231 | }; |
233 | }; |
232 | 234 | ||
233 | spinlock_lock(&irq_kernel_hash_table_lock); |
235 | spinlock_lock(&irq_kernel_hash_table_lock); |
234 | lnk = hash_table_find(&irq_kernel_hash_table, key); |
236 | lnk = hash_table_find(&irq_kernel_hash_table, key); |
235 | if (lnk) { |
237 | if (lnk) { |
236 | irq_t *irq; |
238 | irq_t *irq; |
237 | 239 | ||
238 | irq = hash_table_get_instance(lnk, irq_t, link); |
240 | irq = hash_table_get_instance(lnk, irq_t, link); |
239 | spinlock_unlock(&irq_kernel_hash_table_lock); |
241 | spinlock_unlock(&irq_kernel_hash_table_lock); |
240 | return irq; |
242 | return irq; |
241 | } |
243 | } |
242 | spinlock_unlock(&irq_kernel_hash_table_lock); |
244 | spinlock_unlock(&irq_kernel_hash_table_lock); |
243 | 245 | ||
244 | return NULL; |
246 | return NULL; |
245 | } |
247 | } |
246 | 248 | ||
247 | /** Dispatch the IRQ. |
249 | /** Dispatch the IRQ. |
248 | * |
250 | * |
249 | * We assume this function is only called from interrupt |
251 | * We assume this function is only called from interrupt |
250 | * context (i.e. that interrupts are disabled prior to |
252 | * context (i.e. that interrupts are disabled prior to |
251 | * this call). |
253 | * this call). |
252 | * |
254 | * |
253 | * This function attempts to lookup a fitting IRQ |
255 | * This function attempts to lookup a fitting IRQ |
254 | * structure. In case of success, return with interrupts |
256 | * structure. In case of success, return with interrupts |
255 | * disabled and holding the respective structure. |
257 | * disabled and holding the respective structure. |
256 | * |
258 | * |
257 | * @param inr Interrupt number (aka inr or irq). |
259 | * @param inr Interrupt number (aka inr or irq). |
258 | * |
260 | * |
259 | * @return IRQ structure of the respective device or NULL. |
261 | * @return IRQ structure of the respective device or NULL. |
260 | */ |
262 | */ |
261 | irq_t *irq_dispatch_and_lock(inr_t inr) |
263 | irq_t *irq_dispatch_and_lock(inr_t inr) |
262 | { |
264 | { |
263 | irq_t *irq; |
265 | irq_t *irq; |
264 | 266 | ||
265 | /* |
267 | /* |
266 | * If the kernel console is silenced, |
268 | * If the kernel console is silenced, |
267 | * then try first the uspace handlers, |
269 | * then try first the uspace handlers, |
268 | * eventually fall back to kernel handlers. |
270 | * eventually fall back to kernel handlers. |
269 | * |
271 | * |
270 | * If the kernel console is active, |
272 | * If the kernel console is active, |
271 | * then do it the other way around. |
273 | * then do it the other way around. |
272 | */ |
274 | */ |
273 | if (silent) { |
275 | if (silent) { |
274 | irq = irq_dispatch_and_lock_uspace(inr); |
276 | irq = irq_dispatch_and_lock_uspace(inr); |
275 | if (irq) |
277 | if (irq) |
276 | return irq; |
278 | return irq; |
277 | return irq_dispatch_and_lock_kernel(inr); |
279 | return irq_dispatch_and_lock_kernel(inr); |
278 | } |
280 | } |
279 | 281 | ||
280 | irq = irq_dispatch_and_lock_kernel(inr); |
282 | irq = irq_dispatch_and_lock_kernel(inr); |
281 | if (irq) |
283 | if (irq) |
282 | return irq; |
284 | return irq; |
283 | return irq_dispatch_and_lock_uspace(inr); |
285 | return irq_dispatch_and_lock_uspace(inr); |
284 | } |
286 | } |
285 | 287 | ||
286 | /** Compute hash index for the key. |
288 | /** Compute hash index for the key. |
287 | * |
289 | * |
288 | * This function computes hash index into |
290 | * This function computes hash index into |
289 | * the IRQ hash table for which there |
291 | * the IRQ hash table for which there |
290 | * can be collisions between different |
292 | * can be collisions between different |
291 | * INRs. |
293 | * INRs. |
292 | * |
294 | * |
293 | * The devno is not used to compute the hash. |
295 | * The devno is not used to compute the hash. |
294 | * |
296 | * |
295 | * @param key The first of the keys is inr and the second is devno or -1. |
297 | * @param key The first of the keys is inr and the second is devno or -1. |
296 | * |
298 | * |
297 | * @return Index into the hash table. |
299 | * @return Index into the hash table. |
298 | */ |
300 | */ |
299 | index_t irq_ht_hash(unative_t key[]) |
301 | index_t irq_ht_hash(unative_t key[]) |
300 | { |
302 | { |
301 | inr_t inr = (inr_t) key[KEY_INR]; |
303 | inr_t inr = (inr_t) key[KEY_INR]; |
302 | return inr % buckets; |
304 | return inr % buckets; |
303 | } |
305 | } |
304 | 306 | ||
305 | /** Compare hash table element with a key. |
307 | /** Compare hash table element with a key. |
306 | * |
308 | * |
307 | * There are two things to note about this function. |
309 | * There are two things to note about this function. |
308 | * First, it is used for the more complex architecture setup |
310 | * First, it is used for the more complex architecture setup |
309 | * in which there are way too many interrupt numbers (i.e. inr's) |
311 | * in which there are way too many interrupt numbers (i.e. inr's) |
310 | * to arrange the hash table so that collisions occur only |
312 | * to arrange the hash table so that collisions occur only |
311 | * among same inrs of different devnos. So the explicit check |
313 | * among same inrs of different devnos. So the explicit check |
312 | * for inr match must be done. |
314 | * for inr match must be done. |
313 | * Second, if devno is -1, the second key (i.e. devno) is not |
315 | * Second, if devno is -1, the second key (i.e. devno) is not |
314 | * used for the match and the result of the claim() function |
316 | * used for the match and the result of the claim() function |
315 | * is used instead. |
317 | * is used instead. |
316 | * |
318 | * |
317 | * This function assumes interrupts are already disabled. |
319 | * This function assumes interrupts are already disabled. |
318 | * |
320 | * |
319 | * @param key Keys (i.e. inr and devno). |
321 | * @param key Keys (i.e. inr and devno). |
320 | * @param keys This is 2. |
322 | * @param keys This is 2. |
321 | * @param item The item to compare the key with. |
323 | * @param item The item to compare the key with. |
322 | * |
324 | * |
323 | * @return True on match or false otherwise. |
325 | * @return True on match or false otherwise. |
324 | */ |
326 | */ |
325 | bool irq_ht_compare(unative_t key[], count_t keys, link_t *item) |
327 | bool irq_ht_compare(unative_t key[], count_t keys, link_t *item) |
326 | { |
328 | { |
327 | irq_t *irq = hash_table_get_instance(item, irq_t, link); |
329 | irq_t *irq = hash_table_get_instance(item, irq_t, link); |
328 | inr_t inr = (inr_t) key[KEY_INR]; |
330 | inr_t inr = (inr_t) key[KEY_INR]; |
329 | devno_t devno = (devno_t) key[KEY_DEVNO]; |
331 | devno_t devno = (devno_t) key[KEY_DEVNO]; |
330 | 332 | ||
331 | bool rv; |
333 | bool rv; |
332 | 334 | ||
333 | spinlock_lock(&irq->lock); |
335 | spinlock_lock(&irq->lock); |
334 | if (devno == -1) { |
336 | if (devno == -1) { |
335 | /* Invoked by irq_dispatch_and_lock(). */ |
337 | /* Invoked by irq_dispatch_and_lock(). */ |
336 | rv = ((irq->inr == inr) && |
338 | rv = ((irq->inr == inr) && |
337 | (irq->claim(irq) == IRQ_ACCEPT)); |
339 | (irq->claim(irq) == IRQ_ACCEPT)); |
338 | } else { |
340 | } else { |
339 | /* Invoked by irq_find_and_lock(). */ |
341 | /* Invoked by irq_find_and_lock(). */ |
340 | rv = ((irq->inr == inr) && (irq->devno == devno)); |
342 | rv = ((irq->inr == inr) && (irq->devno == devno)); |
341 | } |
343 | } |
342 | 344 | ||
343 | /* unlock only on non-match */ |
345 | /* unlock only on non-match */ |
344 | if (!rv) |
346 | if (!rv) |
345 | spinlock_unlock(&irq->lock); |
347 | spinlock_unlock(&irq->lock); |
346 | 348 | ||
347 | return rv; |
349 | return rv; |
348 | } |
350 | } |
349 | 351 | ||
- | 352 | /** Unlock IRQ structure after hash_table_remove(). |
|
- | 353 | * |
|
- | 354 | * @param lnk Link in the removed and locked IRQ structure. |
|
- | 355 | */ |
|
- | 356 | void irq_ht_remove(link_t *lnk) |
|
- | 357 | { |
|
- | 358 | irq_t *irq = hash_table_get_instance(lnk, irq_t, link); |
|
- | 359 | spinlock_unlock(&irq->lock); |
|
- | 360 | } |
|
- | 361 | ||
350 | /** Compute hash index for the key. |
362 | /** Compute hash index for the key. |
351 | * |
363 | * |
352 | * This function computes hash index into |
364 | * This function computes hash index into |
353 | * the IRQ hash table for which there |
365 | * the IRQ hash table for which there |
354 | * are no collisions between different |
366 | * are no collisions between different |
355 | * INRs. |
367 | * INRs. |
356 | * |
368 | * |
357 | * @param key The first of the keys is inr and the second is devno or -1. |
369 | * @param key The first of the keys is inr and the second is devno or -1. |
358 | * |
370 | * |
359 | * @return Index into the hash table. |
371 | * @return Index into the hash table. |
360 | */ |
372 | */ |
361 | index_t irq_lin_hash(unative_t key[]) |
373 | index_t irq_lin_hash(unative_t key[]) |
362 | { |
374 | { |
363 | inr_t inr = (inr_t) key[KEY_INR]; |
375 | inr_t inr = (inr_t) key[KEY_INR]; |
364 | return inr; |
376 | return inr; |
365 | } |
377 | } |
366 | 378 | ||
367 | /** Compare hash table element with a key. |
379 | /** Compare hash table element with a key. |
368 | * |
380 | * |
369 | * There are two things to note about this function. |
381 | * There are two things to note about this function. |
370 | * First, it is used for the less complex architecture setup |
382 | * First, it is used for the less complex architecture setup |
371 | * in which there are not too many interrupt numbers (i.e. inr's) |
383 | * in which there are not too many interrupt numbers (i.e. inr's) |
372 | * to arrange the hash table so that collisions occur only |
384 | * to arrange the hash table so that collisions occur only |
373 | * among same inrs of different devnos. So the explicit check |
385 | * among same inrs of different devnos. So the explicit check |
374 | * for inr match is not done. |
386 | * for inr match is not done. |
375 | * Second, if devno is -1, the second key (i.e. devno) is not |
387 | * Second, if devno is -1, the second key (i.e. devno) is not |
376 | * used for the match and the result of the claim() function |
388 | * used for the match and the result of the claim() function |
377 | * is used instead. |
389 | * is used instead. |
378 | * |
390 | * |
379 | * This function assumes interrupts are already disabled. |
391 | * This function assumes interrupts are already disabled. |
380 | * |
392 | * |
381 | * @param key Keys (i.e. inr and devno). |
393 | * @param key Keys (i.e. inr and devno). |
382 | * @param keys This is 2. |
394 | * @param keys This is 2. |
383 | * @param item The item to compare the key with. |
395 | * @param item The item to compare the key with. |
384 | * |
396 | * |
385 | * @return True on match or false otherwise. |
397 | * @return True on match or false otherwise. |
386 | */ |
398 | */ |
387 | bool irq_lin_compare(unative_t key[], count_t keys, link_t *item) |
399 | bool irq_lin_compare(unative_t key[], count_t keys, link_t *item) |
388 | { |
400 | { |
389 | irq_t *irq = list_get_instance(item, irq_t, link); |
401 | irq_t *irq = list_get_instance(item, irq_t, link); |
390 | devno_t devno = (devno_t) key[KEY_DEVNO]; |
402 | devno_t devno = (devno_t) key[KEY_DEVNO]; |
391 | bool rv; |
403 | bool rv; |
392 | 404 | ||
393 | spinlock_lock(&irq->lock); |
405 | spinlock_lock(&irq->lock); |
394 | if (devno == -1) { |
406 | if (devno == -1) { |
395 | /* Invoked by irq_dispatch_and_lock() */ |
407 | /* Invoked by irq_dispatch_and_lock() */ |
396 | rv = (irq->claim(irq) == IRQ_ACCEPT); |
408 | rv = (irq->claim(irq) == IRQ_ACCEPT); |
397 | } else { |
409 | } else { |
398 | /* Invoked by irq_find_and_lock() */ |
410 | /* Invoked by irq_find_and_lock() */ |
399 | rv = (irq->devno == devno); |
411 | rv = (irq->devno == devno); |
400 | } |
412 | } |
401 | 413 | ||
402 | /* unlock only on non-match */ |
414 | /* unlock only on non-match */ |
403 | if (!rv) |
415 | if (!rv) |
404 | spinlock_unlock(&irq->lock); |
416 | spinlock_unlock(&irq->lock); |
405 | 417 | ||
406 | return rv; |
418 | return rv; |
407 | } |
419 | } |
- | 420 | ||
- | 421 | /** Unlock IRQ structure after hash_table_remove(). |
|
- | 422 | * |
|
- | 423 | * @param lnk Link in the removed and locked IRQ structure. |
|
- | 424 | */ |
|
- | 425 | void irq_lin_remove(link_t *lnk) |
|
- | 426 | { |
|
- | 427 | irq_t *irq = hash_table_get_instance(lnk, irq_t, link); |
|
- | 428 | spinlock_unlock(&irq->lock); |
|
- | 429 | } |
|
408 | 430 | ||
409 | /** @} |
431 | /** @} |
410 | */ |
432 | */ |
411 | 433 |