static int assign_device(AssignedDevice *dev)

{

    uint32_t flags = KVM_DEV_ASSIGN_ENABLE_IOMMU;

    int r;



    /* Only pass non-zero PCI segment to capable module */

    if (!kvm_check_extension(kvm_state, KVM_CAP_PCI_SEGMENT) &&

        dev->host.domain) {

        error_report("Can't assign device inside non-zero PCI segment "

                     "as this KVM module doesn't support it.");

        return -ENODEV;

    }



    if (!kvm_check_extension(kvm_state, KVM_CAP_IOMMU)) {

        error_report("No IOMMU found.  Unable to assign device \"%s\"",

                     dev->dev.qdev.id);

        return -ENODEV;

    }



    if (dev->features & ASSIGNED_DEVICE_SHARE_INTX_MASK &&

        kvm_has_intx_set_mask()) {

        flags |= KVM_DEV_ASSIGN_PCI_2_3;

    }



    r = kvm_device_pci_assign(kvm_state, &dev->host, flags, &dev->dev_id);

    if (r < 0) {

        switch (r) {

        case -EBUSY: {

            char *cause;



            cause = assign_failed_examine(dev);

            error_report("Failed to assign device \"%s\" : %s\n%s",

                         dev->dev.qdev.id, strerror(-r), cause);

            g_free(cause);

            break;

        }

        default:

            error_report("Failed to assign device \"%s\" : %s",

                         dev->dev.qdev.id, strerror(-r));

            break;

        }

    }

    return r;

}

static int assign_device(AssignedDevice *dev)

{

    uint32_t flags = KVM_DEV_ASSIGN_ENABLE_IOMMU;

    int r;



    

    if (!kvm_check_extension(kvm_state, KVM_CAP_PCI_SEGMENT) &&

        dev->host.domain) {

        error_report("Can't assign device inside non-zero PCI segment "

                     "as this KVM module doesn't support it.");

        return -ENODEV;

    }



    if (!kvm_check_extension(kvm_state, KVM_CAP_IOMMU)) {

        error_report("No IOMMU found.  Unable to assign device \"%s\"",

                     dev->dev.qdev.id);

        return -ENODEV;

    }



    if (dev->features & ASSIGNED_DEVICE_SHARE_INTX_MASK &&

        kvm_has_intx_set_mask()) {

        flags |= KVM_DEV_ASSIGN_PCI_2_3;

    }



    r = kvm_device_pci_assign(kvm_state, &dev->host, flags, &dev->dev_id);

    if (r < 0) {

        switch (r) {

        case -EBUSY: {

            char *cause;



            cause = assign_failed_examine(dev);

            error_report("Failed to assign device \"%s\" : %s\n%s",

                         dev->dev.qdev.id, strerror(-r), cause);

            g_free(cause);

            break;

        }

        default:

            error_report("Failed to assign device \"%s\" : %s",

                         dev->dev.qdev.id, strerror(-r));

            break;

        }

    }

    return r;

}

static int FUNC_0(AssignedDevice *VAR_0)

{

    uint32_t flags = KVM_DEV_ASSIGN_ENABLE_IOMMU;

    int VAR_1;



    

    if (!kvm_check_extension(kvm_state, KVM_CAP_PCI_SEGMENT) &&

        VAR_0->host.domain) {

        error_report("Can't assign device inside non-zero PCI segment "

                     "as this KVM module doesn't support it.");

        return -ENODEV;

    }



    if (!kvm_check_extension(kvm_state, KVM_CAP_IOMMU)) {

        error_report("No IOMMU found.  Unable to assign device \"%s\"",

                     VAR_0->VAR_0.qdev.id);

        return -ENODEV;

    }



    if (VAR_0->features & ASSIGNED_DEVICE_SHARE_INTX_MASK &&

        kvm_has_intx_set_mask()) {

        flags |= KVM_DEV_ASSIGN_PCI_2_3;

    }



    VAR_1 = kvm_device_pci_assign(kvm_state, &VAR_0->host, flags, &VAR_0->dev_id);

    if (VAR_1 < 0) {

        switch (VAR_1) {

        case -EBUSY: {

            char *VAR_2;



            VAR_2 = assign_failed_examine(VAR_0);

            error_report("Failed to assign device \"%s\" : %s\n%s",

                         VAR_0->VAR_0.qdev.id, strerror(-VAR_1), VAR_2);

            g_free(VAR_2);

            break;

        }

        default:

            error_report("Failed to assign device \"%s\" : %s",

                         VAR_0->VAR_0.qdev.id, strerror(-VAR_1));

            break;

        }

    }

    return VAR_1;

}

static int FUNC_0(AssignedDevice *VAR_0)
{ uint32_t flags = KVM_DEV_ASSIGN_ENABLE_IOMMU; int VAR_1; if (!kvm_check_extension(kvm_state, KVM_CAP_PCI_SEGMENT) &&
VAR_0->host.domain) { error_report("Can't assign device inside non-zero PCI segment "
"as this KVM module doesn't support it."); return -ENODEV; } if (!kvm_check_extension(kvm_state, KVM_CAP_IOMMU)) { error_report("No IOMMU found.  Unable to assign device \"%s\"",
VAR_0->VAR_0.qdev.id); return -ENODEV; } if (VAR_0->features & ASSIGNED_DEVICE_SHARE_INTX_MASK &&
kvm_has_intx_set_mask()) { flags |= KVM_DEV_ASSIGN_PCI_2_3; } VAR_1 = kvm_device_pci_assign(kvm_state, &VAR_0->host, flags, &VAR_0->dev_id); if (VAR_1 < 0) { switch (VAR_1) { case -EBUSY: { char *VAR_2; VAR_2 = assign_failed_examine(VAR_0); error_report("Failed to assign device \"%s\" : %s\n%s",
VAR_0->VAR_0.qdev.id, strerror(-VAR_1), VAR_2); g_free(VAR_2); break; } default:
error_report("Failed to assign device \"%s\" : %s",
VAR_0->VAR_0.qdev.id, strerror(-VAR_1)); break; } } return VAR_1; }