Ignore:
File:
1 edited

Legend:

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

    rd99c1d2 rda1bafb  
    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 /**
    84  * Spinlock protecting the kernel IRQ hash table.
     80#define KEY_INR    0
     81#define KEY_DEVNO  1
     82
     83/** Spinlock protecting the kernel IRQ hash table.
     84 *
    8585 * This lock must be taken only when interrupts are disabled.
    86  */
    87 SPINLOCK_INITIALIZE(irq_kernel_hash_table_lock);
     86 *
     87 */
     88IRQ_SPINLOCK_STATIC_INITIALIZE(irq_kernel_hash_table_lock);
     89
    8890/** The kernel IRQ hash table. */
    8991static hash_table_t irq_kernel_hash_table;
    9092
    91 /**
    92  * Spinlock protecting the uspace IRQ hash table.
     93/** Spinlock protecting the uspace IRQ hash table.
     94 *
    9395 * This lock must be taken only when interrupts are disabled.
    94  */
    95 SPINLOCK_INITIALIZE(irq_uspace_hash_table_lock);
     96 *
     97 */
     98IRQ_SPINLOCK_INITIALIZE(irq_uspace_hash_table_lock);
     99
    96100/** The uspace IRQ hash table. */
    97101hash_table_t irq_uspace_hash_table;
     
    100104 * Hash table operations for cases when we know that
    101105 * there will be collisions between different keys.
     106 *
    102107 */
    103108static size_t irq_ht_hash(unative_t *key);
     
    116121 * However, there might be still collisions among
    117122 * elements with single key (sharing of one IRQ).
     123 *
    118124 */
    119125static size_t irq_lin_hash(unative_t *key);
     
    132138/** Initialize IRQ subsystem.
    133139 *
    134  * @param inrs Numbers of unique IRQ numbers or INRs.
     140 * @param inrs   Numbers of unique IRQ numbers or INRs.
    135141 * @param chains Number of chains in the hash table.
     142 *
    136143 */
    137144void irq_init(size_t inrs, size_t chains)
     
    166173        memsetb(irq, sizeof(irq_t), 0);
    167174        link_initialize(&irq->link);
    168         spinlock_initialize(&irq->lock, "irq.lock");
     175        irq_spinlock_initialize(&irq->lock, "irq.lock");
    169176        link_initialize(&irq->notif_cfg.link);
    170177        irq->inr = -1;
    171178        irq->devno = -1;
    172 
     179       
    173180        irq_initialize_arch(irq);
    174181}
     
    180187 * function pointer and handler() function pointer.
    181188 *
    182  * @param irq           IRQ structure belonging to a device.
    183  * @return              True on success, false on failure.
     189 * @param irq IRQ structure belonging to a device.
     190 *
     191 * @return True on success, false on failure.
     192 *
    184193 */
    185194void irq_register(irq_t *irq)
    186195{
    187         ipl_t ipl;
    188196        unative_t key[] = {
    189197                (unative_t) irq->inr,
     
    191199        };
    192200       
    193         ipl = interrupts_disable();
    194         spinlock_lock(&irq_kernel_hash_table_lock);
    195         spinlock_lock(&irq->lock);
     201        irq_spinlock_lock(&irq_kernel_hash_table_lock, true);
     202        irq_spinlock_lock(&irq->lock, false);
    196203        hash_table_insert(&irq_kernel_hash_table, key, &irq->link);
    197         spinlock_unlock(&irq->lock);   
    198         spinlock_unlock(&irq_kernel_hash_table_lock);
    199         interrupts_restore(ipl);
     204        irq_spinlock_unlock(&irq->lock, false);
     205        irq_spinlock_unlock(&irq_kernel_hash_table_lock, true);
    200206}
    201207
     
    208214        unative_t key[] = {
    209215                (unative_t) inr,
    210                 (unative_t) -1    /* search will use claim() instead of devno */
     216                (unative_t) -1    /* Search will use claim() instead of devno */
    211217        };
    212218       
    213         spinlock_lock(&irq_uspace_hash_table_lock);
     219        irq_spinlock_lock(&irq_uspace_hash_table_lock, false);
    214220        lnk = hash_table_find(&irq_uspace_hash_table, key);
    215221        if (lnk) {
    216                 irq_t *irq;
    217                
    218                 irq = hash_table_get_instance(lnk, irq_t, link);
    219                 spinlock_unlock(&irq_uspace_hash_table_lock);
     222                irq_t *irq = hash_table_get_instance(lnk, irq_t, link);
     223                irq_spinlock_unlock(&irq_uspace_hash_table_lock, false);
    220224                return irq;
    221225        }
    222         spinlock_unlock(&irq_uspace_hash_table_lock);
     226        irq_spinlock_unlock(&irq_uspace_hash_table_lock, false);
    223227       
    224228        return NULL;
     
    233237        unative_t key[] = {
    234238                (unative_t) inr,
    235                 (unative_t) -1    /* search will use claim() instead of devno */
     239                (unative_t) -1    /* Search will use claim() instead of devno */
    236240        };
    237241       
    238         spinlock_lock(&irq_kernel_hash_table_lock);
     242        irq_spinlock_lock(&irq_kernel_hash_table_lock, false);
    239243        lnk = hash_table_find(&irq_kernel_hash_table, key);
    240244        if (lnk) {
    241                 irq_t *irq;
    242                
    243                 irq = hash_table_get_instance(lnk, irq_t, link);
    244                 spinlock_unlock(&irq_kernel_hash_table_lock);
     245                irq_t *irq = hash_table_get_instance(lnk, irq_t, link);
     246                irq_spinlock_unlock(&irq_kernel_hash_table_lock, false);
    245247                return irq;
    246248        }
    247         spinlock_unlock(&irq_kernel_hash_table_lock);
     249        irq_spinlock_unlock(&irq_kernel_hash_table_lock, false);
    248250       
    249251        return NULL;
     
    263265 *
    264266 * @return IRQ structure of the respective device or NULL.
     267 *
    265268 */
    266269irq_t *irq_dispatch_and_lock(inr_t inr)
    267270{
    268         irq_t *irq;
    269        
    270271        /*
    271272         * If the kernel console is silenced,
     
    277278         */
    278279        if (silent) {
    279                 irq = irq_dispatch_and_lock_uspace(inr);
     280                irq_t *irq = irq_dispatch_and_lock_uspace(inr);
    280281                if (irq)
    281282                        return irq;
     283               
    282284                return irq_dispatch_and_lock_kernel(inr);
    283285        }
    284286       
    285         irq = irq_dispatch_and_lock_kernel(inr);
     287        irq_t *irq = irq_dispatch_and_lock_kernel(inr);
    286288        if (irq)
    287289                return irq;
     290       
    288291        return irq_dispatch_and_lock_uspace(inr);
    289292}
     
    301304 *
    302305 * @return Index into the hash table.
     306 *
    303307 */
    304308size_t irq_ht_hash(unative_t key[])
     
    322326 * This function assumes interrupts are already disabled.
    323327 *
    324  * @param key Keys (i.e. inr and devno).
     328 * @param key  Keys (i.e. inr and devno).
    325329 * @param keys This is 2.
    326330 * @param item The item to compare the key with.
    327331 *
    328332 * @return True on match or false otherwise.
     333 *
    329334 */
    330335bool irq_ht_compare(unative_t key[], size_t keys, link_t *item)
     
    333338        inr_t inr = (inr_t) key[KEY_INR];
    334339        devno_t devno = (devno_t) key[KEY_DEVNO];
    335 
     340       
    336341        bool rv;
    337342       
    338         spinlock_lock(&irq->lock);
     343        irq_spinlock_lock(&irq->lock, false);
    339344        if (devno == -1) {
    340345                /* Invoked by irq_dispatch_and_lock(). */
     
    348353        /* unlock only on non-match */
    349354        if (!rv)
    350                 spinlock_unlock(&irq->lock);
    351 
     355                irq_spinlock_unlock(&irq->lock, false);
     356       
    352357        return rv;
    353358}
     
    361366        irq_t *irq __attribute__((unused))
    362367            = hash_table_get_instance(lnk, irq_t, link);
    363         spinlock_unlock(&irq->lock);
     368        irq_spinlock_unlock(&irq->lock, false);
    364369}
    365370
     
    374379 *
    375380 * @return Index into the hash table.
     381 *
    376382 */
    377383size_t irq_lin_hash(unative_t key[])
     
    395401 * This function assumes interrupts are already disabled.
    396402 *
    397  * @param key Keys (i.e. inr and devno).
     403 * @param key  Keys (i.e. inr and devno).
    398404 * @param keys This is 2.
    399405 * @param item The item to compare the key with.
    400406 *
    401407 * @return True on match or false otherwise.
     408 *
    402409 */
    403410bool irq_lin_compare(unative_t key[], size_t keys, link_t *item)
     
    407414        bool rv;
    408415       
    409         spinlock_lock(&irq->lock);
     416        irq_spinlock_lock(&irq->lock, false);
    410417        if (devno == -1) {
    411418                /* Invoked by irq_dispatch_and_lock() */
     
    418425        /* unlock only on non-match */
    419426        if (!rv)
    420                 spinlock_unlock(&irq->lock);
     427                irq_spinlock_unlock(&irq->lock, false);
    421428       
    422429        return rv;
     
    425432/** Unlock IRQ structure after hash_table_remove().
    426433 *
    427  * @param lnk           Link in the removed and locked IRQ structure.
     434 * @param lnk Link in the removed and locked IRQ structure.
     435 *
    428436 */
    429437void irq_lin_remove(link_t *lnk)
     
    431439        irq_t *irq __attribute__((unused))
    432440            = hash_table_get_instance(lnk, irq_t, link);
    433         spinlock_unlock(&irq->lock);
     441        irq_spinlock_unlock(&irq->lock, false);
    434442}
    435443
Note: See TracChangeset for help on using the changeset viewer.