Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/src/ddi/irq.c

    rda1bafb rd99c1d2  
    3232/**
    3333 * @file
    34  * @brief IRQ dispatcher.
     34 * @brief       IRQ dispatcher.
    3535 *
    3636 * This file provides means of connecting IRQs with particular
     
    7878#include <arch.h>
    7979
    80 #define KEY_INR    0
    81 #define KEY_DEVNO  1
    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.
    8585 * This lock must be taken only when interrupts are disabled.
    86  *
    87  */
    88 IRQ_SPINLOCK_STATIC_INITIALIZE(irq_kernel_hash_table_lock);
    89 
     86 */
     87SPINLOCK_INITIALIZE(irq_kernel_hash_table_lock);
    9088/** The kernel IRQ hash table. */
    9189static hash_table_t irq_kernel_hash_table;
    9290
    93 /** Spinlock protecting the uspace IRQ hash table.
    94  *
     91/**
     92 * Spinlock protecting the uspace IRQ hash table.
    9593 * This lock must be taken only when interrupts are disabled.
    96  *
    97  */
    98 IRQ_SPINLOCK_INITIALIZE(irq_uspace_hash_table_lock);
    99 
     94 */
     95SPINLOCK_INITIALIZE(irq_uspace_hash_table_lock);
    10096/** The uspace IRQ hash table. */
    10197hash_table_t irq_uspace_hash_table;
     
    104100 * Hash table operations for cases when we know that
    105101 * there will be collisions between different keys.
    106  *
    107102 */
    108103static size_t irq_ht_hash(unative_t *key);
     
    121116 * However, there might be still collisions among
    122117 * elements with single key (sharing of one IRQ).
    123  *
    124118 */
    125119static size_t irq_lin_hash(unative_t *key);
     
    138132/** Initialize IRQ subsystem.
    139133 *
    140  * @param inrs   Numbers of unique IRQ numbers or INRs.
     134 * @param inrs Numbers of unique IRQ numbers or INRs.
    141135 * @param chains Number of chains in the hash table.
    142  *
    143136 */
    144137void irq_init(size_t inrs, size_t chains)
     
    173166        memsetb(irq, sizeof(irq_t), 0);
    174167        link_initialize(&irq->link);
    175         irq_spinlock_initialize(&irq->lock, "irq.lock");
     168        spinlock_initialize(&irq->lock, "irq.lock");
    176169        link_initialize(&irq->notif_cfg.link);
    177170        irq->inr = -1;
    178171        irq->devno = -1;
    179        
     172
    180173        irq_initialize_arch(irq);
    181174}
     
    187180 * function pointer and handler() function pointer.
    188181 *
    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.
    193184 */
    194185void irq_register(irq_t *irq)
    195186{
     187        ipl_t ipl;
    196188        unative_t key[] = {
    197189                (unative_t) irq->inr,
     
    199191        };
    200192       
    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);
    203196        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);
    206200}
    207201
     
    214208        unative_t key[] = {
    215209                (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 */
    217211        };
    218212       
    219         irq_spinlock_lock(&irq_uspace_hash_table_lock, false);
     213        spinlock_lock(&irq_uspace_hash_table_lock);
    220214        lnk = hash_table_find(&irq_uspace_hash_table, key);
    221215        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);
    224220                return irq;
    225221        }
    226         irq_spinlock_unlock(&irq_uspace_hash_table_lock, false);
     222        spinlock_unlock(&irq_uspace_hash_table_lock);
    227223       
    228224        return NULL;
     
    237233        unative_t key[] = {
    238234                (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 */
    240236        };
    241237       
    242         irq_spinlock_lock(&irq_kernel_hash_table_lock, false);
     238        spinlock_lock(&irq_kernel_hash_table_lock);
    243239        lnk = hash_table_find(&irq_kernel_hash_table, key);
    244240        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);
    247245                return irq;
    248246        }
    249         irq_spinlock_unlock(&irq_kernel_hash_table_lock, false);
     247        spinlock_unlock(&irq_kernel_hash_table_lock);
    250248       
    251249        return NULL;
     
    265263 *
    266264 * @return IRQ structure of the respective device or NULL.
    267  *
    268265 */
    269266irq_t *irq_dispatch_and_lock(inr_t inr)
    270267{
     268        irq_t *irq;
     269       
    271270        /*
    272271         * If the kernel console is silenced,
     
    278277         */
    279278        if (silent) {
    280                 irq_t *irq = irq_dispatch_and_lock_uspace(inr);
     279                irq = irq_dispatch_and_lock_uspace(inr);
    281280                if (irq)
    282281                        return irq;
    283                
    284282                return irq_dispatch_and_lock_kernel(inr);
    285283        }
    286284       
    287         irq_t *irq = irq_dispatch_and_lock_kernel(inr);
     285        irq = irq_dispatch_and_lock_kernel(inr);
    288286        if (irq)
    289287                return irq;
    290        
    291288        return irq_dispatch_and_lock_uspace(inr);
    292289}
     
    304301 *
    305302 * @return Index into the hash table.
    306  *
    307303 */
    308304size_t irq_ht_hash(unative_t key[])
     
    326322 * This function assumes interrupts are already disabled.
    327323 *
    328  * @param key  Keys (i.e. inr and devno).
     324 * @param key Keys (i.e. inr and devno).
    329325 * @param keys This is 2.
    330326 * @param item The item to compare the key with.
    331327 *
    332328 * @return True on match or false otherwise.
    333  *
    334329 */
    335330bool irq_ht_compare(unative_t key[], size_t keys, link_t *item)
     
    338333        inr_t inr = (inr_t) key[KEY_INR];
    339334        devno_t devno = (devno_t) key[KEY_DEVNO];
    340        
     335
    341336        bool rv;
    342337       
    343         irq_spinlock_lock(&irq->lock, false);
     338        spinlock_lock(&irq->lock);
    344339        if (devno == -1) {
    345340                /* Invoked by irq_dispatch_and_lock(). */
     
    353348        /* unlock only on non-match */
    354349        if (!rv)
    355                 irq_spinlock_unlock(&irq->lock, false);
    356        
     350                spinlock_unlock(&irq->lock);
     351
    357352        return rv;
    358353}
     
    366361        irq_t *irq __attribute__((unused))
    367362            = hash_table_get_instance(lnk, irq_t, link);
    368         irq_spinlock_unlock(&irq->lock, false);
     363        spinlock_unlock(&irq->lock);
    369364}
    370365
     
    379374 *
    380375 * @return Index into the hash table.
    381  *
    382376 */
    383377size_t irq_lin_hash(unative_t key[])
     
    401395 * This function assumes interrupts are already disabled.
    402396 *
    403  * @param key  Keys (i.e. inr and devno).
     397 * @param key Keys (i.e. inr and devno).
    404398 * @param keys This is 2.
    405399 * @param item The item to compare the key with.
    406400 *
    407401 * @return True on match or false otherwise.
    408  *
    409402 */
    410403bool irq_lin_compare(unative_t key[], size_t keys, link_t *item)
     
    414407        bool rv;
    415408       
    416         irq_spinlock_lock(&irq->lock, false);
     409        spinlock_lock(&irq->lock);
    417410        if (devno == -1) {
    418411                /* Invoked by irq_dispatch_and_lock() */
     
    425418        /* unlock only on non-match */
    426419        if (!rv)
    427                 irq_spinlock_unlock(&irq->lock, false);
     420                spinlock_unlock(&irq->lock);
    428421       
    429422        return rv;
     
    432425/** Unlock IRQ structure after hash_table_remove().
    433426 *
    434  * @param lnk Link in the removed and locked IRQ structure.
    435  *
     427 * @param lnk           Link in the removed and locked IRQ structure.
    436428 */
    437429void irq_lin_remove(link_t *lnk)
     
    439431        irq_t *irq __attribute__((unused))
    440432            = hash_table_get_instance(lnk, irq_t, link);
    441         irq_spinlock_unlock(&irq->lock, false);
     433        spinlock_unlock(&irq->lock);
    442434}
    443435
Note: See TracChangeset for help on using the changeset viewer.