Changes in kernel/generic/src/ddi/irq.c [78ffb70:98000fb] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/src/ddi/irq.c
r78ffb70 r98000fb 32 32 /** 33 33 * @file 34 * @brief 34 * @brief IRQ dispatcher. 35 35 * 36 36 * This file provides means of connecting IRQs with particular … … 71 71 #include <adt/hash_table.h> 72 72 #include <mm/slab.h> 73 #include < typedefs.h>73 #include <arch/types.h> 74 74 #include <synch/spinlock.h> 75 75 #include <console/console.h> 76 #include <interrupt.h>77 76 #include <memstr.h> 78 77 #include <arch.h> 79 78 80 #define KEY_INR 81 #define KEY_DEVNO 82 83 /** Spinlock protecting the kernel IRQ hash table.84 * 79 #define KEY_INR 0 80 #define KEY_DEVNO 1 81 82 /** 83 * Spinlock protecting the kernel IRQ hash table. 85 84 * This lock must be taken only when interrupts are disabled. 86 * 87 */ 88 IRQ_SPINLOCK_STATIC_INITIALIZE(irq_kernel_hash_table_lock); 89 85 */ 86 SPINLOCK_INITIALIZE(irq_kernel_hash_table_lock); 90 87 /** The kernel IRQ hash table. */ 91 88 static hash_table_t irq_kernel_hash_table; 92 89 93 /** Spinlock protecting the uspace IRQ hash table.94 * 90 /** 91 * Spinlock protecting the uspace IRQ hash table. 95 92 * This lock must be taken only when interrupts are disabled. 96 * 97 */ 98 IRQ_SPINLOCK_INITIALIZE(irq_uspace_hash_table_lock); 99 93 */ 94 SPINLOCK_INITIALIZE(irq_uspace_hash_table_lock); 100 95 /** The uspace IRQ hash table. */ 101 96 hash_table_t irq_uspace_hash_table; … … 104 99 * Hash table operations for cases when we know that 105 100 * there will be collisions between different keys. 106 * 107 */ 108 static size_t irq_ht_hash(sysarg_t *key); 109 static bool irq_ht_compare(sysarg_t *key, size_t keys, link_t *item); 101 */ 102 static size_t irq_ht_hash(unative_t *key); 103 static bool irq_ht_compare(unative_t *key, size_t keys, link_t *item); 110 104 static void irq_ht_remove(link_t *item); 111 105 … … 121 115 * However, there might be still collisions among 122 116 * elements with single key (sharing of one IRQ). 123 * 124 */ 125 static size_t irq_lin_hash(sysarg_t *key); 126 static bool irq_lin_compare(sysarg_t *key, size_t keys, link_t *item); 117 */ 118 static size_t irq_lin_hash(unative_t *key); 119 static bool irq_lin_compare(unative_t *key, size_t keys, link_t *item); 127 120 static void irq_lin_remove(link_t *item); 128 121 … … 136 129 static size_t buckets; 137 130 138 /** Last valid INR. */139 inr_t last_inr = 0;140 141 131 /** Initialize IRQ subsystem. 142 132 * 143 * @param inrs 133 * @param inrs Numbers of unique IRQ numbers or INRs. 144 134 * @param chains Number of chains in the hash table. 145 *146 135 */ 147 136 void irq_init(size_t inrs, size_t chains) 148 137 { 149 138 buckets = chains; 150 last_inr = inrs - 1;151 152 139 /* 153 140 * Be smart about the choice of the hash table operations. … … 178 165 memsetb(irq, sizeof(irq_t), 0); 179 166 link_initialize(&irq->link); 180 irq_spinlock_initialize(&irq->lock, "irq.lock");167 spinlock_initialize(&irq->lock, "irq.lock"); 181 168 link_initialize(&irq->notif_cfg.link); 182 169 irq->inr = -1; 183 170 irq->devno = -1; 184 185 irq_initialize_arch(irq);186 171 } 187 172 … … 192 177 * function pointer and handler() function pointer. 193 178 * 194 * @param irq IRQ structure belonging to a device. 195 * 196 * @return True on success, false on failure. 197 * 179 * @param irq IRQ structure belonging to a device. 180 * @return True on success, false on failure. 198 181 */ 199 182 void irq_register(irq_t *irq) 200 183 { 201 sysarg_t key[] = { 202 (sysarg_t) irq->inr, 203 (sysarg_t) irq->devno 184 ipl_t ipl; 185 unative_t key[] = { 186 (unative_t) irq->inr, 187 (unative_t) irq->devno 204 188 }; 205 189 206 irq_spinlock_lock(&irq_kernel_hash_table_lock, true); 207 irq_spinlock_lock(&irq->lock, false); 190 ipl = interrupts_disable(); 191 spinlock_lock(&irq_kernel_hash_table_lock); 192 spinlock_lock(&irq->lock); 208 193 hash_table_insert(&irq_kernel_hash_table, key, &irq->link); 209 irq_spinlock_unlock(&irq->lock, false); 210 irq_spinlock_unlock(&irq_kernel_hash_table_lock, true); 194 spinlock_unlock(&irq->lock); 195 spinlock_unlock(&irq_kernel_hash_table_lock); 196 interrupts_restore(ipl); 211 197 } 212 198 … … 217 203 { 218 204 link_t *lnk; 219 sysarg_t key[] = {220 ( sysarg_t) inr,221 ( sysarg_t) -1 /* Search will use claim() instead of devno */205 unative_t key[] = { 206 (unative_t) inr, 207 (unative_t) -1 /* search will use claim() instead of devno */ 222 208 }; 223 209 224 irq_spinlock_lock(&irq_uspace_hash_table_lock, false);210 spinlock_lock(&irq_uspace_hash_table_lock); 225 211 lnk = hash_table_find(&irq_uspace_hash_table, key); 226 212 if (lnk) { 227 irq_t *irq = hash_table_get_instance(lnk, irq_t, link); 228 irq_spinlock_unlock(&irq_uspace_hash_table_lock, false); 213 irq_t *irq; 214 215 irq = hash_table_get_instance(lnk, irq_t, link); 216 spinlock_unlock(&irq_uspace_hash_table_lock); 229 217 return irq; 230 218 } 231 irq_spinlock_unlock(&irq_uspace_hash_table_lock, false);219 spinlock_unlock(&irq_uspace_hash_table_lock); 232 220 233 221 return NULL; … … 240 228 { 241 229 link_t *lnk; 242 sysarg_t key[] = {243 ( sysarg_t) inr,244 ( sysarg_t) -1 /* Search will use claim() instead of devno */230 unative_t key[] = { 231 (unative_t) inr, 232 (unative_t) -1 /* search will use claim() instead of devno */ 245 233 }; 246 234 247 irq_spinlock_lock(&irq_kernel_hash_table_lock, false);235 spinlock_lock(&irq_kernel_hash_table_lock); 248 236 lnk = hash_table_find(&irq_kernel_hash_table, key); 249 237 if (lnk) { 250 irq_t *irq = hash_table_get_instance(lnk, irq_t, link); 251 irq_spinlock_unlock(&irq_kernel_hash_table_lock, false); 238 irq_t *irq; 239 240 irq = hash_table_get_instance(lnk, irq_t, link); 241 spinlock_unlock(&irq_kernel_hash_table_lock); 252 242 return irq; 253 243 } 254 irq_spinlock_unlock(&irq_kernel_hash_table_lock, false);244 spinlock_unlock(&irq_kernel_hash_table_lock); 255 245 256 246 return NULL; … … 270 260 * 271 261 * @return IRQ structure of the respective device or NULL. 272 *273 262 */ 274 263 irq_t *irq_dispatch_and_lock(inr_t inr) 275 264 { 265 irq_t *irq; 266 276 267 /* 277 268 * If the kernel console is silenced, … … 283 274 */ 284 275 if (silent) { 285 irq _t *irq= irq_dispatch_and_lock_uspace(inr);276 irq = irq_dispatch_and_lock_uspace(inr); 286 277 if (irq) 287 278 return irq; 288 289 279 return irq_dispatch_and_lock_kernel(inr); 290 280 } 291 281 292 irq _t *irq= irq_dispatch_and_lock_kernel(inr);282 irq = irq_dispatch_and_lock_kernel(inr); 293 283 if (irq) 294 284 return irq; 295 296 285 return irq_dispatch_and_lock_uspace(inr); 297 286 } … … 309 298 * 310 299 * @return Index into the hash table. 311 * 312 */ 313 size_t irq_ht_hash(sysarg_t key[]) 300 */ 301 size_t irq_ht_hash(unative_t key[]) 314 302 { 315 303 inr_t inr = (inr_t) key[KEY_INR]; … … 331 319 * This function assumes interrupts are already disabled. 332 320 * 333 * @param key 321 * @param key Keys (i.e. inr and devno). 334 322 * @param keys This is 2. 335 323 * @param item The item to compare the key with. 336 324 * 337 325 * @return True on match or false otherwise. 338 * 339 */ 340 bool irq_ht_compare(sysarg_t key[], size_t keys, link_t *item) 326 */ 327 bool irq_ht_compare(unative_t key[], size_t keys, link_t *item) 341 328 { 342 329 irq_t *irq = hash_table_get_instance(item, irq_t, link); 343 330 inr_t inr = (inr_t) key[KEY_INR]; 344 331 devno_t devno = (devno_t) key[KEY_DEVNO]; 345 332 346 333 bool rv; 347 334 348 irq_spinlock_lock(&irq->lock, false);335 spinlock_lock(&irq->lock); 349 336 if (devno == -1) { 350 337 /* Invoked by irq_dispatch_and_lock(). */ … … 358 345 /* unlock only on non-match */ 359 346 if (!rv) 360 irq_spinlock_unlock(&irq->lock, false);361 347 spinlock_unlock(&irq->lock); 348 362 349 return rv; 363 350 } … … 371 358 irq_t *irq __attribute__((unused)) 372 359 = hash_table_get_instance(lnk, irq_t, link); 373 irq_spinlock_unlock(&irq->lock, false);360 spinlock_unlock(&irq->lock); 374 361 } 375 362 … … 384 371 * 385 372 * @return Index into the hash table. 386 * 387 */ 388 size_t irq_lin_hash(sysarg_t key[]) 373 */ 374 size_t irq_lin_hash(unative_t key[]) 389 375 { 390 376 inr_t inr = (inr_t) key[KEY_INR]; … … 406 392 * This function assumes interrupts are already disabled. 407 393 * 408 * @param key 394 * @param key Keys (i.e. inr and devno). 409 395 * @param keys This is 2. 410 396 * @param item The item to compare the key with. 411 397 * 412 398 * @return True on match or false otherwise. 413 * 414 */ 415 bool irq_lin_compare(sysarg_t key[], size_t keys, link_t *item) 399 */ 400 bool irq_lin_compare(unative_t key[], size_t keys, link_t *item) 416 401 { 417 402 irq_t *irq = list_get_instance(item, irq_t, link); … … 419 404 bool rv; 420 405 421 irq_spinlock_lock(&irq->lock, false);406 spinlock_lock(&irq->lock); 422 407 if (devno == -1) { 423 408 /* Invoked by irq_dispatch_and_lock() */ … … 430 415 /* unlock only on non-match */ 431 416 if (!rv) 432 irq_spinlock_unlock(&irq->lock, false);417 spinlock_unlock(&irq->lock); 433 418 434 419 return rv; … … 437 422 /** Unlock IRQ structure after hash_table_remove(). 438 423 * 439 * @param lnk Link in the removed and locked IRQ structure. 440 * 424 * @param lnk Link in the removed and locked IRQ structure. 441 425 */ 442 426 void irq_lin_remove(link_t *lnk) … … 444 428 irq_t *irq __attribute__((unused)) 445 429 = hash_table_get_instance(lnk, irq_t, link); 446 irq_spinlock_unlock(&irq->lock, false);430 spinlock_unlock(&irq->lock); 447 431 } 448 432
Note:
See TracChangeset
for help on using the changeset viewer.