Subversion Repositories HelenOS

Compare Revisions

Ignore whitespace Rev 1932 → Rev 1933

/trunk/kernel/generic/include/ipc/ipc.h
174,14 → 174,15
 
waitq_t wq;
 
link_t connected_phones; /**< Phones connected to this answerbox */
link_t calls; /**< Received calls */
link_t dispatched_calls; /* Should be hash table in the future */
link_t connected_phones; /**< Phones connected to this answerbox */
link_t calls; /**< Received calls */
link_t dispatched_calls; /* Should be hash table in the future */
 
link_t answers; /**< Answered calls */
link_t answers; /**< Answered calls */
 
SPINLOCK_DECLARE(irq_lock);
link_t irq_notifs; /**< Notifications from IRQ handlers */
link_t irq_notifs; /**< Notifications from IRQ handlers */
link_t irq_head; /**< IRQs with notifications to this answerbox. */
};
 
typedef enum {
/trunk/kernel/generic/include/ipc/irq.h
71,6 → 71,7
#include <ipc/ipc.h>
#include <typedefs.h>
#include <arch/types.h>
#include <adt/list.h>
 
/** IPC notification config structure.
*
83,6 → 84,9
unative_t method; /**< Method to be used for the notification. */
irq_code_t *code; /**< Top-half pseudocode. */
count_t counter; /**< Counter. */
link_t link; /**< Link between IRQs that are notifying the
same answerbox. The list is protected by
the answerbox irq_lock. */
};
 
extern int ipc_irq_register(answerbox_t *box, inr_t inr, devno_t devno, unative_t method,
/trunk/kernel/generic/src/ddi/irq.c
145,10 → 145,12
irq->claim = NULL;
irq->handler = NULL;
irq->arg = NULL;
irq->notif_cfg.notify = false;
irq->notif_cfg.answerbox = NULL;
irq->notif_cfg.code = NULL;
irq->notif_cfg.method = 0;
irq->notif_cfg.counter = 0;
link_initialize(&irq->notif_cfg.link);
}
 
/** Register IRQ for device.
/trunk/kernel/generic/src/ipc/ipc.c
108,6 → 108,7
list_initialize(&box->dispatched_calls);
list_initialize(&box->answers);
list_initialize(&box->irq_notifs);
list_initialize(&box->irq_head);
box->task = TASK;
}
 
/trunk/kernel/generic/src/ipc/irq.c
176,12 → 176,17
irq = irq_find_and_lock(inr, devno);
if (irq) {
if (irq->notif_cfg.answerbox == box) {
code_free(irq->notif_cfg.code);
irq->notif_cfg.notify = false;
irq->notif_cfg.answerbox = NULL;
irq->notif_cfg.code = NULL;
irq->notif_cfg.method = 0;
irq->notif_cfg.counter = 0;
code_free(irq->notif_cfg.code);
 
spinlock_lock(&box->irq_lock);
list_remove(&irq->notif_cfg.link);
spinlock_unlock(&box->irq_lock);
spinlock_unlock(&irq->lock);
}
}
198,8 → 203,7
*
* @return EBADMEM, ENOENT or EEXISTS on failure or 0 on success.
*/
int
ipc_irq_register(answerbox_t *box, inr_t inr, devno_t devno, unative_t method, irq_code_t *ucode)
int ipc_irq_register(answerbox_t *box, inr_t inr, devno_t devno, unative_t method, irq_code_t *ucode)
{
ipl_t ipl;
irq_code_t *code;
232,6 → 236,11
irq->notif_cfg.method = method;
irq->notif_cfg.code = code;
irq->notif_cfg.counter = 0;
 
spinlock_lock(&box->irq_lock);
list_append(&irq->notif_cfg.link, &box->irq_head);
spinlock_unlock(&box->irq_lock);
 
spinlock_unlock(&irq->lock);
interrupts_restore(ipl);
 
310,11 → 319,54
 
/** Disconnect all IRQ notifications from an answerbox.
*
* This function is effective because the answerbox contains
* list of all irq_t structures that are registered to
* send notifications to it.
*
* @param box Answerbox for which we want to carry out the cleanup.
*/
void ipc_irq_cleanup(answerbox_t *box)
{
/* TODO */
ipl_t ipl;
loop:
ipl = interrupts_disable();
spinlock_lock(&box->irq_lock);
while (box->irq_head.next != &box->irq_head) {
link_t *cur = box->irq_head.next;
irq_t *irq;
irq = list_get_instance(cur, irq_t, notif_cfg.link);
if (!spinlock_trylock(&irq->lock)) {
/*
* Avoid deadlock by trying again.
*/
spinlock_unlock(&box->irq_lock);
interrupts_restore(ipl);
goto loop;
}
ASSERT(irq->notif_cfg.answerbox == box);
list_remove(&irq->notif_cfg.link);
/*
* Don't forget to free any top-half pseudocode.
*/
code_free(irq->notif_cfg.code);
irq->notif_cfg.notify = false;
irq->notif_cfg.answerbox = NULL;
irq->notif_cfg.code = NULL;
irq->notif_cfg.method = 0;
irq->notif_cfg.counter = 0;
 
spinlock_unlock(&irq->lock);
}
spinlock_unlock(&box->irq_lock);
interrupts_restore(ipl);
}
 
/** @}