static void vfio_msi_enable(VFIOPCIDevice *vdev)

{

    int ret, i;



    vfio_disable_interrupts(vdev);



    vdev->nr_vectors = msi_nr_vectors_allocated(&vdev->pdev);

retry:

    vdev->msi_vectors = g_malloc0(vdev->nr_vectors * sizeof(VFIOMSIVector));



    for (i = 0; i < vdev->nr_vectors; i++) {

        VFIOMSIVector *vector = &vdev->msi_vectors[i];

        MSIMessage msg = msi_get_message(&vdev->pdev, i);



        vector->vdev = vdev;

        vector->virq = -1;

        vector->use = true;



        if (event_notifier_init(&vector->interrupt, 0)) {

            error_report("vfio: Error: event_notifier_init failed");

        }



        qemu_set_fd_handler(event_notifier_get_fd(&vector->interrupt),

                            vfio_msi_interrupt, NULL, vector);



        /*

         * Attempt to enable route through KVM irqchip,

         * default to userspace handling if unavailable.

         */

        vfio_add_kvm_msi_virq(vdev, vector, &msg, false);

    }



    /* Set interrupt type prior to possible interrupts */

    vdev->interrupt = VFIO_INT_MSI;



    ret = vfio_enable_vectors(vdev, false);

    if (ret) {

        if (ret < 0) {

            error_report("vfio: Error: Failed to setup MSI fds: %m");

        } else if (ret != vdev->nr_vectors) {

            error_report("vfio: Error: Failed to enable %d "

                         "MSI vectors, retry with %d", vdev->nr_vectors, ret);

        }



        for (i = 0; i < vdev->nr_vectors; i++) {

            VFIOMSIVector *vector = &vdev->msi_vectors[i];

            if (vector->virq >= 0) {

                vfio_remove_kvm_msi_virq(vector);

            }

            qemu_set_fd_handler(event_notifier_get_fd(&vector->interrupt),

                                NULL, NULL, NULL);

            event_notifier_cleanup(&vector->interrupt);

        }



        g_free(vdev->msi_vectors);



        if (ret > 0 && ret != vdev->nr_vectors) {

            vdev->nr_vectors = ret;

            goto retry;

        }

        vdev->nr_vectors = 0;



        /*

         * Failing to setup MSI doesn't really fall within any specification.

         * Let's try leaving interrupts disabled and hope the guest figures

         * out to fall back to INTx for this device.

         */

        error_report("vfio: Error: Failed to enable MSI");

        vdev->interrupt = VFIO_INT_NONE;



        return;

    }



    trace_vfio_msi_enable(vdev->vbasedev.name, vdev->nr_vectors);

}

static void vfio_msi_enable(VFIOPCIDevice *vdev)

{

    int ret, i;



    vfio_disable_interrupts(vdev);



    vdev->nr_vectors = msi_nr_vectors_allocated(&vdev->pdev);

retry:

    vdev->msi_vectors = g_malloc0(vdev->nr_vectors * sizeof(VFIOMSIVector));



    for (i = 0; i < vdev->nr_vectors; i++) {

        VFIOMSIVector *vector = &vdev->msi_vectors[i];

        MSIMessage msg = msi_get_message(&vdev->pdev, i);



        vector->vdev = vdev;

        vector->virq = -1;

        vector->use = true;



        if (event_notifier_init(&vector->interrupt, 0)) {

            error_report("vfio: Error: event_notifier_init failed");

        }



        qemu_set_fd_handler(event_notifier_get_fd(&vector->interrupt),

                            vfio_msi_interrupt, NULL, vector);



        







        vfio_add_kvm_msi_virq(vdev, vector, &msg, false);

    }



    

    vdev->interrupt = VFIO_INT_MSI;



    ret = vfio_enable_vectors(vdev, false);

    if (ret) {

        if (ret < 0) {

            error_report("vfio: Error: Failed to setup MSI fds: %m");

        } else if (ret != vdev->nr_vectors) {

            error_report("vfio: Error: Failed to enable %d "

                         "MSI vectors, retry with %d", vdev->nr_vectors, ret);

        }



        for (i = 0; i < vdev->nr_vectors; i++) {

            VFIOMSIVector *vector = &vdev->msi_vectors[i];

            if (vector->virq >= 0) {

                vfio_remove_kvm_msi_virq(vector);

            }

            qemu_set_fd_handler(event_notifier_get_fd(&vector->interrupt),

                                NULL, NULL, NULL);

            event_notifier_cleanup(&vector->interrupt);

        }



        g_free(vdev->msi_vectors);



        if (ret > 0 && ret != vdev->nr_vectors) {

            vdev->nr_vectors = ret;

            goto retry;

        }

        vdev->nr_vectors = 0;



        









        error_report("vfio: Error: Failed to enable MSI");

        vdev->interrupt = VFIO_INT_NONE;



        return;

    }



    trace_vfio_msi_enable(vdev->vbasedev.name, vdev->nr_vectors);

}

    vdev->msi_vectors = g_malloc0(vdev->nr_vectors * sizeof(VFIOMSIVector));
static void FUNC_0(VFIOPCIDevice *VAR_0)

{

    int VAR_1, VAR_2;



    vfio_disable_interrupts(VAR_0);



    VAR_0->nr_vectors = msi_nr_vectors_allocated(&VAR_0->pdev);

retry:

    VAR_0->msi_vectors = g_malloc0(VAR_0->nr_vectors * sizeof(VFIOMSIVector));



    for (VAR_2 = 0; VAR_2 < VAR_0->nr_vectors; VAR_2++) {

        VFIOMSIVector *vector = &VAR_0->msi_vectors[VAR_2];

        MSIMessage msg = msi_get_message(&VAR_0->pdev, VAR_2);



        vector->VAR_0 = VAR_0;

        vector->virq = -1;

        vector->use = true;



        if (event_notifier_init(&vector->interrupt, 0)) {

            error_report("vfio: Error: event_notifier_init failed");

        }



        qemu_set_fd_handler(event_notifier_get_fd(&vector->interrupt),

                            vfio_msi_interrupt, NULL, vector);



        







        vfio_add_kvm_msi_virq(VAR_0, vector, &msg, false);

    }



    

    VAR_0->interrupt = VFIO_INT_MSI;



    VAR_1 = vfio_enable_vectors(VAR_0, false);

    if (VAR_1) {

        if (VAR_1 < 0) {

            error_report("vfio: Error: Failed to setup MSI fds: %m");

        } else if (VAR_1 != VAR_0->nr_vectors) {

            error_report("vfio: Error: Failed to enable %d "

                         "MSI vectors, retry with %d", VAR_0->nr_vectors, VAR_1);

        }



        for (VAR_2 = 0; VAR_2 < VAR_0->nr_vectors; VAR_2++) {

            VFIOMSIVector *vector = &VAR_0->msi_vectors[VAR_2];

            if (vector->virq >= 0) {

                vfio_remove_kvm_msi_virq(vector);

            }

            qemu_set_fd_handler(event_notifier_get_fd(&vector->interrupt),

                                NULL, NULL, NULL);

            event_notifier_cleanup(&vector->interrupt);

        }



        g_free(VAR_0->msi_vectors);



        if (VAR_1 > 0 && VAR_1 != VAR_0->nr_vectors) {

            VAR_0->nr_vectors = VAR_1;

            goto retry;

        }

        VAR_0->nr_vectors = 0;



        









        error_report("vfio: Error: Failed to enable MSI");

        VAR_0->interrupt = VFIO_INT_NONE;



        return;

    }



    trace_vfio_msi_enable(VAR_0->vbasedev.name, VAR_0->nr_vectors);

}

static void FUNC_0(VFIOPCIDevice *VAR_0)
{ int VAR_1, VAR_2; vfio_disable_interrupts(VAR_0); VAR_0->nr_vectors = msi_nr_vectors_allocated(&VAR_0->pdev); retry:
VAR_0->msi_vectors = g_malloc0(VAR_0->nr_vectors * sizeof(VFIOMSIVector)); for (VAR_2 = 0; VAR_2 < VAR_0->nr_vectors; VAR_2++) { VFIOMSIVector *vector = &VAR_0->msi_vectors[VAR_2]; MSIMessage msg = msi_get_message(&VAR_0->pdev, VAR_2); vector->VAR_0 = VAR_0; vector->virq = -1; vector->use = true; if (event_notifier_init(&vector->interrupt, 0)) { error_report("vfio: Error: event_notifier_init failed"); } qemu_set_fd_handler(event_notifier_get_fd(&vector->interrupt),
vfio_msi_interrupt, NULL, vector); vfio_add_kvm_msi_virq(VAR_0, vector, &msg, false); } VAR_0->interrupt = VFIO_INT_MSI; VAR_1 = vfio_enable_vectors(VAR_0, false); if (VAR_1) { if (VAR_1 < 0) { error_report("vfio: Error: Failed to setup MSI fds: %m"); } else if (VAR_1 != VAR_0->nr_vectors) { error_report("vfio: Error: Failed to enable %d "
"MSI vectors, retry with %d", VAR_0->nr_vectors, VAR_1); } for (VAR_2 = 0; VAR_2 < VAR_0->nr_vectors; VAR_2++) { VFIOMSIVector *vector = &VAR_0->msi_vectors[VAR_2]; if (vector->virq >= 0) { vfio_remove_kvm_msi_virq(vector); } qemu_set_fd_handler(event_notifier_get_fd(&vector->interrupt),
NULL, NULL, NULL); event_notifier_cleanup(&vector->interrupt); } g_free(VAR_0->msi_vectors); if (VAR_1 > 0 && VAR_1 != VAR_0->nr_vectors) { VAR_0->nr_vectors = VAR_1; goto retry; } VAR_0->nr_vectors = 0; error_report("vfio: Error: Failed to enable MSI"); VAR_0->interrupt = VFIO_INT_NONE; return; } trace_vfio_msi_enable(VAR_0->vbasedev.name, VAR_0->nr_vectors); }