static int irqsetntfncommon(irqcookie_t *irqcookie, ntfnidt ntfnid, irqidt irqid,…
- User
static int irq_set_ntfn_common(irq_cookie_t *irq_cookie, ntfn_id_t ntfn_id, irq_id_t irq_id, seL4_Word *ret_badge) { irq_entry_t *irq_entry = &(irq_cookie->irq_table[irq_id]);
/* Check if the IRQ is already bound to something */ if (irq_entry->paired_ntfn > UNPAIRED_ID) { return -EINVAL; } ntfn_entry_t *ntfn_entry = &(irq_cookie->ntfn_table[ntfn_id]); /* Check if we have space to bound another IRQ to this notification */ if (ntfn_entry->num_irqs_bound >= MAX_INTERRUPTS_TO_NOTIFICATIONS) { return -ENOSPC; } /* Find an empty space (unclaimed bit in the badge) for the IRQ */ int badge_index = find_free_ntfn_badge_index(ntfn_entry); if (badge_index == -1) { return -ENOSPC; } /* Allocate a CSpace slot and mint the root notification object with badge */ cspacepath_t mint_path = {0}; int error = vka_cspace_alloc_path(irq_cookie->vka, &mint_path); if (error) { return -ENOMEM; } seL4_Word badge = BIT(badge_index); error = vka_cnode_mint(&mint_path, &(ntfn_entry->root_ntfn_path), seL4_AllRights, badge); if (error) { vka_cspace_free_path(irq_cookie->vka, mint_path); return -ENOMEM; } - Assistant
The function
irq_set_ntfn_commonis used to bind an interrupt request (IRQ) to a notification object. It takes anirq_cookieobject which contains information about the IRQ and notification, anntfn_idwhich is the ID of the notification, anirq_idwhich is the ID of the IRQ, and a pointer toret_badgewhich will store the badge value of the minted notification.The function first checks if the IRQ is already bound to something by checking if the paired notification ID is greater than
UNPAIRED_ID. If it is, then the function returns an error code indicating that the IRQ is already bound.Next, it checks if there is space to bind another IRQ to the notification by checking if the number of IRQs bound to the notification is less than the maximum allowed (
MAX_INTERRUPTS_TO_NOTIFICATIONS). If it is not, then the function returns an error code indicating that there is no space.The function then finds an empty space (unclaimed bit in the badge) for the IRQ by calling the
find_free_ntfn_badge_indexfunction. This function searches the badge of the notification for an unclaimed bit and returns the index of that bit. If no unclaimed bit is found, the function returns -1, indicating that there is no space.If an empty space is found, the function allocates a new CSpace slot using
vka_cspace_alloc_pathfunction. If an error occurs during the allocation, the function returns an error code indicating that there is not enough memory.Next, the function mints the root notification object with the badge value using
vka_cnode_mintfunction. Themint_pathparameter contains the path to the newly allocated CSpace slot. Theroot_ntfn_pathparameter contains the path to the root notification object. TheseL4_AllRightsparameter specifies that all rights should be minted. Thebadgeparameter contains the badge value to mint.If an error occurs during the minting, the function frees the allocated CSpace slot and returns an error code indicating that there is not enough memory.
Finally, if the minting is successful, the function stores the badge value in the
ret_badgevariable and returns 0 to indicate success.