Changes in kernel/generic/src/ddi/irq.c [da1bafb:d99c1d2] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/src/ddi/irq.c
rda1bafb rd99c1d2 32 32 /** 33 33 * @file 34 * @brief 34 * @brief IRQ dispatcher. 35 35 * 36 36 * This file provides means of connecting IRQs with particular … … 78 78 #include <arch.h> 79 79 80 #define KEY_INR 81 #define KEY_DEVNO 82 83 /** Spinlock protecting the kernel IRQ hash table.84 * 80 #define KEY_INR 0 81 #define KEY_DEVNO 1 82 83 /** 84 * Spinlock protecting the kernel IRQ hash table. 85 85 * This lock must be taken only when interrupts are disabled. 86 * 87 */ 88 IRQ_SPINLOCK_STATIC_INITIALIZE(irq_kernel_hash_table_lock); 89 86 */ 87 SPINLOCK_INITIALIZE(irq_kernel_hash_table_lock); 90 88 /** The kernel IRQ hash table. */ 91 89 static hash_table_t irq_kernel_hash_table; 92 90 93 /** Spinlock protecting the uspace IRQ hash table.94 * 91 /** 92 * Spinlock protecting the uspace IRQ hash table. 95 93 * This lock must be taken only when interrupts are disabled. 96 * 97 */ 98 IRQ_SPINLOCK_INITIALIZE(irq_uspace_hash_table_lock); 99 94 */ 95 SPINLOCK_INITIALIZE(irq_uspace_hash_table_lock); 100 96 /** The uspace IRQ hash table. */ 101 97 hash_table_t irq_uspace_hash_table; … … 104 100 * Hash table operations for cases when we know that 105 101 * there will be collisions between different keys. 106 *107 102 */ 108 103 static size_t irq_ht_hash(unative_t *key); … … 121 116 * However, there might be still collisions among 122 117 * elements with single key (sharing of one IRQ). 123 *124 118 */ 125 119 static size_t irq_lin_hash(unative_t *key); … … 138 132 /** Initialize IRQ subsystem. 139 133 * 140 * @param inrs 134 * @param inrs Numbers of unique IRQ numbers or INRs. 141 135 * @param chains Number of chains in the hash table. 142 *143 136 */ 144 137 void irq_init(size_t inrs, size_t chains) … … 173 166 memsetb(irq, sizeof(irq_t), 0); 174 167 link_initialize(&irq->link); 175 irq_spinlock_initialize(&irq->lock, "irq.lock");168 spinlock_initialize(&irq->lock, "irq.lock"); 176 169 link_initialize(&irq->notif_cfg.link); 177 170 irq->inr = -1; 178 171 irq->devno = -1; 179 172 180 173 irq_initialize_arch(irq); 181 174 } … … 187 180 * function pointer and handler() function pointer. 188 181 * 189 * @param irq IRQ structure belonging to a device. 190 * 191 * @return True on success, false on failure. 192 * 182 * @param irq IRQ structure belonging to a device. 183 * @return True on success, false on failure. 193 184 */ 194 185 void irq_register(irq_t *irq) 195 186 { 187 ipl_t ipl; 196 188 unative_t key[] = { 197 189 (unative_t) irq->inr, … … 199 191 }; 200 192 201 irq_spinlock_lock(&irq_kernel_hash_table_lock, true); 202 irq_spinlock_lock(&irq->lock, false); 193 ipl = interrupts_disable(); 194 spinlock_lock(&irq_kernel_hash_table_lock); 195 spinlock_lock(&irq->lock); 203 196 hash_table_insert(&irq_kernel_hash_table, key, &irq->link); 204 irq_spinlock_unlock(&irq->lock, false); 205 irq_spinlock_unlock(&irq_kernel_hash_table_lock, true); 197 spinlock_unlock(&irq->lock); 198 spinlock_unlock(&irq_kernel_hash_table_lock); 199 interrupts_restore(ipl); 206 200 } 207 201 … … 214 208 unative_t key[] = { 215 209 (unative_t) inr, 216 (unative_t) -1 /* Search will use claim() instead of devno */210 (unative_t) -1 /* search will use claim() instead of devno */ 217 211 }; 218 212 219 irq_spinlock_lock(&irq_uspace_hash_table_lock, false);213 spinlock_lock(&irq_uspace_hash_table_lock); 220 214 lnk = hash_table_find(&irq_uspace_hash_table, key); 221 215 if (lnk) { 222 irq_t *irq = hash_table_get_instance(lnk, irq_t, link); 223 irq_spinlock_unlock(&irq_uspace_hash_table_lock, false); 216 irq_t *irq; 217 218 irq = hash_table_get_instance(lnk, irq_t, link); 219 spinlock_unlock(&irq_uspace_hash_table_lock); 224 220 return irq; 225 221 } 226 irq_spinlock_unlock(&irq_uspace_hash_table_lock, false);222 spinlock_unlock(&irq_uspace_hash_table_lock); 227 223 228 224 return NULL; … … 237 233 unative_t key[] = { 238 234 (unative_t) inr, 239 (unative_t) -1 /* Search will use claim() instead of devno */235 (unative_t) -1 /* search will use claim() instead of devno */ 240 236 }; 241 237 242 irq_spinlock_lock(&irq_kernel_hash_table_lock, false);238 spinlock_lock(&irq_kernel_hash_table_lock); 243 239 lnk = hash_table_find(&irq_kernel_hash_table, key); 244 240 if (lnk) { 245 irq_t *irq = hash_table_get_instance(lnk, irq_t, link); 246 irq_spinlock_unlock(&irq_kernel_hash_table_lock, false); 241 irq_t *irq; 242 243 irq = hash_table_get_instance(lnk, irq_t, link); 244 spinlock_unlock(&irq_kernel_hash_table_lock); 247 245 return irq; 248 246 } 249 irq_spinlock_unlock(&irq_kernel_hash_table_lock, false);247 spinlock_unlock(&irq_kernel_hash_table_lock); 250 248 251 249 return NULL; … … 265 263 * 266 264 * @return IRQ structure of the respective device or NULL. 267 *268 265 */ 269 266 irq_t *irq_dispatch_and_lock(inr_t inr) 270 267 { 268 irq_t *irq; 269 271 270 /* 272 271 * If the kernel console is silenced, … … 278 277 */ 279 278 if (silent) { 280 irq _t *irq= irq_dispatch_and_lock_uspace(inr);279 irq = irq_dispatch_and_lock_uspace(inr); 281 280 if (irq) 282 281 return irq; 283 284 282 return irq_dispatch_and_lock_kernel(inr); 285 283 } 286 284 287 irq _t *irq= irq_dispatch_and_lock_kernel(inr);285 irq = irq_dispatch_and_lock_kernel(inr); 288 286 if (irq) 289 287 return irq; 290 291 288 return irq_dispatch_and_lock_uspace(inr); 292 289 } … … 304 301 * 305 302 * @return Index into the hash table. 306 *307 303 */ 308 304 size_t irq_ht_hash(unative_t key[]) … … 326 322 * This function assumes interrupts are already disabled. 327 323 * 328 * @param key 324 * @param key Keys (i.e. inr and devno). 329 325 * @param keys This is 2. 330 326 * @param item The item to compare the key with. 331 327 * 332 328 * @return True on match or false otherwise. 333 *334 329 */ 335 330 bool irq_ht_compare(unative_t key[], size_t keys, link_t *item) … … 338 333 inr_t inr = (inr_t) key[KEY_INR]; 339 334 devno_t devno = (devno_t) key[KEY_DEVNO]; 340 335 341 336 bool rv; 342 337 343 irq_spinlock_lock(&irq->lock, false);338 spinlock_lock(&irq->lock); 344 339 if (devno == -1) { 345 340 /* Invoked by irq_dispatch_and_lock(). */ … … 353 348 /* unlock only on non-match */ 354 349 if (!rv) 355 irq_spinlock_unlock(&irq->lock, false);356 350 spinlock_unlock(&irq->lock); 351 357 352 return rv; 358 353 } … … 366 361 irq_t *irq __attribute__((unused)) 367 362 = hash_table_get_instance(lnk, irq_t, link); 368 irq_spinlock_unlock(&irq->lock, false);363 spinlock_unlock(&irq->lock); 369 364 } 370 365 … … 379 374 * 380 375 * @return Index into the hash table. 381 *382 376 */ 383 377 size_t irq_lin_hash(unative_t key[]) … … 401 395 * This function assumes interrupts are already disabled. 402 396 * 403 * @param key 397 * @param key Keys (i.e. inr and devno). 404 398 * @param keys This is 2. 405 399 * @param item The item to compare the key with. 406 400 * 407 401 * @return True on match or false otherwise. 408 *409 402 */ 410 403 bool irq_lin_compare(unative_t key[], size_t keys, link_t *item) … … 414 407 bool rv; 415 408 416 irq_spinlock_lock(&irq->lock, false);409 spinlock_lock(&irq->lock); 417 410 if (devno == -1) { 418 411 /* Invoked by irq_dispatch_and_lock() */ … … 425 418 /* unlock only on non-match */ 426 419 if (!rv) 427 irq_spinlock_unlock(&irq->lock, false);420 spinlock_unlock(&irq->lock); 428 421 429 422 return rv; … … 432 425 /** Unlock IRQ structure after hash_table_remove(). 433 426 * 434 * @param lnk Link in the removed and locked IRQ structure. 435 * 427 * @param lnk Link in the removed and locked IRQ structure. 436 428 */ 437 429 void irq_lin_remove(link_t *lnk) … … 439 431 irq_t *irq __attribute__((unused)) 440 432 = hash_table_get_instance(lnk, irq_t, link); 441 irq_spinlock_unlock(&irq->lock, false);433 spinlock_unlock(&irq->lock); 442 434 } 443 435
Note:
See TracChangeset
for help on using the changeset viewer.