Ignore:
File:
1 edited

Legend:

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

    r78ffb70 r98000fb  
    3232/**
    3333 * @file
    34  * @brief IRQ dispatcher.
     34 * @brief       IRQ dispatcher.
    3535 *
    3636 * This file provides means of connecting IRQs with particular
     
    7171#include <adt/hash_table.h>
    7272#include <mm/slab.h>
    73 #include <typedefs.h>
     73#include <arch/types.h>
    7474#include <synch/spinlock.h>
    7575#include <console/console.h>
    76 #include <interrupt.h>
    7776#include <memstr.h>
    7877#include <arch.h>
    7978
    80 #define KEY_INR    0
    81 #define KEY_DEVNO  1
    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.
    8584 * This lock must be taken only when interrupts are disabled.
    86  *
    87  */
    88 IRQ_SPINLOCK_STATIC_INITIALIZE(irq_kernel_hash_table_lock);
    89 
     85 */
     86SPINLOCK_INITIALIZE(irq_kernel_hash_table_lock);
    9087/** The kernel IRQ hash table. */
    9188static hash_table_t irq_kernel_hash_table;
    9289
    93 /** Spinlock protecting the uspace IRQ hash table.
    94  *
     90/**
     91 * Spinlock protecting the uspace IRQ hash table.
    9592 * This lock must be taken only when interrupts are disabled.
    96  *
    97  */
    98 IRQ_SPINLOCK_INITIALIZE(irq_uspace_hash_table_lock);
    99 
     93 */
     94SPINLOCK_INITIALIZE(irq_uspace_hash_table_lock);
    10095/** The uspace IRQ hash table. */
    10196hash_table_t irq_uspace_hash_table;
     
    10499 * Hash table operations for cases when we know that
    105100 * 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 */
     102static size_t irq_ht_hash(unative_t *key);
     103static bool irq_ht_compare(unative_t *key, size_t keys, link_t *item);
    110104static void irq_ht_remove(link_t *item);
    111105
     
    121115 * However, there might be still collisions among
    122116 * 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 */
     118static size_t irq_lin_hash(unative_t *key);
     119static bool irq_lin_compare(unative_t *key, size_t keys, link_t *item);
    127120static void irq_lin_remove(link_t *item);
    128121
     
    136129static size_t buckets;
    137130
    138 /** Last valid INR. */
    139 inr_t last_inr = 0;
    140 
    141131/** Initialize IRQ subsystem.
    142132 *
    143  * @param inrs   Numbers of unique IRQ numbers or INRs.
     133 * @param inrs Numbers of unique IRQ numbers or INRs.
    144134 * @param chains Number of chains in the hash table.
    145  *
    146135 */
    147136void irq_init(size_t inrs, size_t chains)
    148137{
    149138        buckets = chains;
    150         last_inr = inrs - 1;
    151 
    152139        /*
    153140         * Be smart about the choice of the hash table operations.
     
    178165        memsetb(irq, sizeof(irq_t), 0);
    179166        link_initialize(&irq->link);
    180         irq_spinlock_initialize(&irq->lock, "irq.lock");
     167        spinlock_initialize(&irq->lock, "irq.lock");
    181168        link_initialize(&irq->notif_cfg.link);
    182169        irq->inr = -1;
    183170        irq->devno = -1;
    184        
    185         irq_initialize_arch(irq);
    186171}
    187172
     
    192177 * function pointer and handler() function pointer.
    193178 *
    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.
    198181 */
    199182void irq_register(irq_t *irq)
    200183{
    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
    204188        };
    205189       
    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);
    208193        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);
    211197}
    212198
     
    217203{
    218204        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 */
    222208        };
    223209       
    224         irq_spinlock_lock(&irq_uspace_hash_table_lock, false);
     210        spinlock_lock(&irq_uspace_hash_table_lock);
    225211        lnk = hash_table_find(&irq_uspace_hash_table, key);
    226212        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);
    229217                return irq;
    230218        }
    231         irq_spinlock_unlock(&irq_uspace_hash_table_lock, false);
     219        spinlock_unlock(&irq_uspace_hash_table_lock);
    232220       
    233221        return NULL;
     
    240228{
    241229        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 */
    245233        };
    246234       
    247         irq_spinlock_lock(&irq_kernel_hash_table_lock, false);
     235        spinlock_lock(&irq_kernel_hash_table_lock);
    248236        lnk = hash_table_find(&irq_kernel_hash_table, key);
    249237        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);
    252242                return irq;
    253243        }
    254         irq_spinlock_unlock(&irq_kernel_hash_table_lock, false);
     244        spinlock_unlock(&irq_kernel_hash_table_lock);
    255245       
    256246        return NULL;
     
    270260 *
    271261 * @return IRQ structure of the respective device or NULL.
    272  *
    273262 */
    274263irq_t *irq_dispatch_and_lock(inr_t inr)
    275264{
     265        irq_t *irq;
     266       
    276267        /*
    277268         * If the kernel console is silenced,
     
    283274         */
    284275        if (silent) {
    285                 irq_t *irq = irq_dispatch_and_lock_uspace(inr);
     276                irq = irq_dispatch_and_lock_uspace(inr);
    286277                if (irq)
    287278                        return irq;
    288                
    289279                return irq_dispatch_and_lock_kernel(inr);
    290280        }
    291281       
    292         irq_t *irq = irq_dispatch_and_lock_kernel(inr);
     282        irq = irq_dispatch_and_lock_kernel(inr);
    293283        if (irq)
    294284                return irq;
    295        
    296285        return irq_dispatch_and_lock_uspace(inr);
    297286}
     
    309298 *
    310299 * @return Index into the hash table.
    311  *
    312  */
    313 size_t irq_ht_hash(sysarg_t key[])
     300 */
     301size_t irq_ht_hash(unative_t key[])
    314302{
    315303        inr_t inr = (inr_t) key[KEY_INR];
     
    331319 * This function assumes interrupts are already disabled.
    332320 *
    333  * @param key  Keys (i.e. inr and devno).
     321 * @param key Keys (i.e. inr and devno).
    334322 * @param keys This is 2.
    335323 * @param item The item to compare the key with.
    336324 *
    337325 * @return True on match or false otherwise.
    338  *
    339  */
    340 bool irq_ht_compare(sysarg_t key[], size_t keys, link_t *item)
     326 */
     327bool irq_ht_compare(unative_t key[], size_t keys, link_t *item)
    341328{
    342329        irq_t *irq = hash_table_get_instance(item, irq_t, link);
    343330        inr_t inr = (inr_t) key[KEY_INR];
    344331        devno_t devno = (devno_t) key[KEY_DEVNO];
    345        
     332
    346333        bool rv;
    347334       
    348         irq_spinlock_lock(&irq->lock, false);
     335        spinlock_lock(&irq->lock);
    349336        if (devno == -1) {
    350337                /* Invoked by irq_dispatch_and_lock(). */
     
    358345        /* unlock only on non-match */
    359346        if (!rv)
    360                 irq_spinlock_unlock(&irq->lock, false);
    361        
     347                spinlock_unlock(&irq->lock);
     348
    362349        return rv;
    363350}
     
    371358        irq_t *irq __attribute__((unused))
    372359            = hash_table_get_instance(lnk, irq_t, link);
    373         irq_spinlock_unlock(&irq->lock, false);
     360        spinlock_unlock(&irq->lock);
    374361}
    375362
     
    384371 *
    385372 * @return Index into the hash table.
    386  *
    387  */
    388 size_t irq_lin_hash(sysarg_t key[])
     373 */
     374size_t irq_lin_hash(unative_t key[])
    389375{
    390376        inr_t inr = (inr_t) key[KEY_INR];
     
    406392 * This function assumes interrupts are already disabled.
    407393 *
    408  * @param key  Keys (i.e. inr and devno).
     394 * @param key Keys (i.e. inr and devno).
    409395 * @param keys This is 2.
    410396 * @param item The item to compare the key with.
    411397 *
    412398 * @return True on match or false otherwise.
    413  *
    414  */
    415 bool irq_lin_compare(sysarg_t key[], size_t keys, link_t *item)
     399 */
     400bool irq_lin_compare(unative_t key[], size_t keys, link_t *item)
    416401{
    417402        irq_t *irq = list_get_instance(item, irq_t, link);
     
    419404        bool rv;
    420405       
    421         irq_spinlock_lock(&irq->lock, false);
     406        spinlock_lock(&irq->lock);
    422407        if (devno == -1) {
    423408                /* Invoked by irq_dispatch_and_lock() */
     
    430415        /* unlock only on non-match */
    431416        if (!rv)
    432                 irq_spinlock_unlock(&irq->lock, false);
     417                spinlock_unlock(&irq->lock);
    433418       
    434419        return rv;
     
    437422/** Unlock IRQ structure after hash_table_remove().
    438423 *
    439  * @param lnk Link in the removed and locked IRQ structure.
    440  *
     424 * @param lnk           Link in the removed and locked IRQ structure.
    441425 */
    442426void irq_lin_remove(link_t *lnk)
     
    444428        irq_t *irq __attribute__((unused))
    445429            = hash_table_get_instance(lnk, irq_t, link);
    446         irq_spinlock_unlock(&irq->lock, false);
     430        spinlock_unlock(&irq->lock);
    447431}
    448432
Note: See TracChangeset for help on using the changeset viewer.