Skip to content
TheChatArchiveThe Chat Archive
gpt-3.5-turbo-0613· OpenAIAi2 WildChat-4.8M (AI2)

static int irqsetntfncommon(irqcookie_t *irqcookie, ntfnidt ntfnid, irqidt irqid,…

  1. 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;
    }
    
  2. Assistant

    The function irq_set_ntfn_common is used to bind an interrupt request (IRQ) to a notification object. It takes an irq_cookie object which contains information about the IRQ and notification, an ntfn_id which is the ID of the notification, an irq_id which is the ID of the IRQ, and a pointer to ret_badge which 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_index function. 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_path function. 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_mint function. The mint_path parameter contains the path to the newly allocated CSpace slot. The root_ntfn_path parameter contains the path to the root notification object. The seL4_AllRights parameter specifies that all rights should be minted. The badge parameter 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_badge variable and returns 0 to indicate success.