Changeset 48bcf49 in mainline for kernel/generic/src/ipc/irq.c


Ignore:
Timestamp:
2017-09-28T22:08:15Z (7 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
6636fb19
Parents:
dd20cbb
Message:

Introduce reference-counted kobjects

Capabilities are thus reduced to task-local names for references to kobjects.

File:
1 edited

Legend:

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

    rdd20cbb r48bcf49  
    271271}
    272272
     273static void irq_destroy(void *arg)
     274{
     275        irq_t *irq = (irq_t *) arg;
     276
     277        /* Free up the IRQ code and associated structures. */
     278        code_free(irq->notif_cfg.code);
     279        slab_free(irq_slab, irq);
     280}
     281
     282static kobject_ops_t irq_kobject_ops = {
     283        .destroy = irq_destroy
     284};
     285
    273286/** Subscribe an answerbox as a receiving end for IRQ notifications.
    274287 *
     
    304317         * Allocate and populate the IRQ kernel object.
    305318         */
    306         int handle = cap_alloc(TASK);
     319        cap_handle_t handle = cap_alloc(TASK);
    307320        if (handle < 0)
    308321                return handle;
     
    311324        if (!irq) {
    312325                cap_free(TASK, handle);
     326                return ENOMEM;
     327        }
     328
     329        kobject_t *kobject = malloc(sizeof(kobject_t), FRAME_ATOMIC);
     330        if (!kobject) {
     331                cap_free(TASK, handle);
     332                slab_free(irq_slab, irq);
    313333                return ENOMEM;
    314334        }
     
    330350        irq_spinlock_lock(&irq->lock, false);
    331351       
     352        irq->notif_cfg.hashed_in = true;
    332353        hash_table_insert(&irq_uspace_hash_table, key, &irq->link);
    333354       
     
    335356        irq_spinlock_unlock(&irq_uspace_hash_table_lock, true);
    336357
    337         cap_publish(TASK, handle, CAP_TYPE_IRQ, irq);
     358        kobject_initialize(kobject, KOBJECT_TYPE_IRQ, irq, &irq_kobject_ops);
     359        cap_publish(TASK, handle, kobject);
    338360       
    339361        return handle;
     
    350372int ipc_irq_unsubscribe(answerbox_t *box, int handle)
    351373{
    352         cap_t *cap = cap_unpublish(TASK, handle, CAP_TYPE_IRQ);
    353         if (!cap)
     374        kobject_t *kobj = cap_unpublish(TASK, handle, KOBJECT_TYPE_IRQ);
     375        if (!kobj)
    354376                return ENOENT;
    355377       
    356         irq_t *irq = (irq_t *) cap->kobject;
    357        
     378        assert(kobj->irq->notif_cfg.answerbox == box);
     379
    358380        irq_spinlock_lock(&irq_uspace_hash_table_lock, true);
    359         irq_spinlock_lock(&irq->lock, false);
    360        
    361         assert(irq->notif_cfg.answerbox == box);
    362        
    363         /* Remove the IRQ from the uspace IRQ hash table. */
    364         hash_table_remove_item(&irq_uspace_hash_table, &irq->link);
    365        
    366         /* irq->lock unlocked by the hash table remove_callback */
     381        irq_spinlock_lock(&kobj->irq->lock, false);
     382       
     383        if (kobj->irq->notif_cfg.hashed_in) {
     384                /* Remove the IRQ from the uspace IRQ hash table. */
     385                hash_table_remove_item(&irq_uspace_hash_table,
     386                    &kobj->irq->link);
     387                kobj->irq->notif_cfg.hashed_in = false;
     388        }
     389
     390        /* kobj->irq->lock unlocked by the hash table remove_callback */
    367391        irq_spinlock_unlock(&irq_uspace_hash_table_lock, true);
    368        
    369         /* Free up the IRQ code and associated structures. */
    370         code_free(irq->notif_cfg.code);
    371        
    372         /* Free up the IRQ capability and the underlying kernel object. */
    373         slab_free(irq_slab, cap->kobject);
     392
     393        kobject_put(kobj);
    374394        cap_free(TASK, handle);
    375395       
Note: See TracChangeset for help on using the changeset viewer.