static void amdvi_realize(DeviceState *dev, Error **err)

{

    int ret = 0;

    AMDVIState *s = AMD_IOMMU_DEVICE(dev);

    X86IOMMUState *x86_iommu = X86_IOMMU_DEVICE(dev);

    MachineState *ms = MACHINE(qdev_get_machine());

    MachineClass *mc = MACHINE_GET_CLASS(ms);

    PCMachineState *pcms =

        PC_MACHINE(object_dynamic_cast(OBJECT(ms), TYPE_PC_MACHINE));

    PCIBus *bus;



    if (!pcms) {

        error_setg(err, "Machine-type '%s' not supported by amd-iommu",

                   mc->name);

        return;

    }



    bus = pcms->bus;

    s->iotlb = g_hash_table_new_full(amdvi_uint64_hash,

                                     amdvi_uint64_equal, g_free, g_free);



    /* This device should take care of IOMMU PCI properties */

    x86_iommu->type = TYPE_AMD;

    qdev_set_parent_bus(DEVICE(&s->pci), &bus->qbus);

    object_property_set_bool(OBJECT(&s->pci), true, "realized", err);

    ret = pci_add_capability(&s->pci.dev, AMDVI_CAPAB_ID_SEC, 0,

                                         AMDVI_CAPAB_SIZE, err);

    if (ret < 0) {

        return;

    }

    s->capab_offset = ret;



    ret = pci_add_capability(&s->pci.dev, PCI_CAP_ID_MSI, 0,

                             AMDVI_CAPAB_REG_SIZE, err);

    if (ret < 0) {

        return;

    }

    ret = pci_add_capability(&s->pci.dev, PCI_CAP_ID_HT, 0,

                             AMDVI_CAPAB_REG_SIZE, err);

    if (ret < 0) {

        return;

    }



    /* set up MMIO */

    memory_region_init_io(&s->mmio, OBJECT(s), &mmio_mem_ops, s, "amdvi-mmio",

                          AMDVI_MMIO_SIZE);



    sysbus_init_mmio(SYS_BUS_DEVICE(s), &s->mmio);

    sysbus_mmio_map(SYS_BUS_DEVICE(s), 0, AMDVI_BASE_ADDR);

    pci_setup_iommu(bus, amdvi_host_dma_iommu, s);

    s->devid = object_property_get_int(OBJECT(&s->pci), "addr", err);

    msi_init(&s->pci.dev, 0, 1, true, false, err);

    amdvi_init(s);

}

static void amdvi_realize(DeviceState *dev, Error **err)

{

    int ret = 0;

    AMDVIState *s = AMD_IOMMU_DEVICE(dev);

    X86IOMMUState *x86_iommu = X86_IOMMU_DEVICE(dev);

    MachineState *ms = MACHINE(qdev_get_machine());

    MachineClass *mc = MACHINE_GET_CLASS(ms);

    PCMachineState *pcms =

        PC_MACHINE(object_dynamic_cast(OBJECT(ms), TYPE_PC_MACHINE));

    PCIBus *bus;



    if (!pcms) {

        error_setg(err, "Machine-type '%s' not supported by amd-iommu",

                   mc->name);

        return;

    }



    bus = pcms->bus;

    s->iotlb = g_hash_table_new_full(amdvi_uint64_hash,

                                     amdvi_uint64_equal, g_free, g_free);



    

    x86_iommu->type = TYPE_AMD;

    qdev_set_parent_bus(DEVICE(&s->pci), &bus->qbus);

    object_property_set_bool(OBJECT(&s->pci), true, "realized", err);

    ret = pci_add_capability(&s->pci.dev, AMDVI_CAPAB_ID_SEC, 0,

                                         AMDVI_CAPAB_SIZE, err);

    if (ret < 0) {

        return;

    }

    s->capab_offset = ret;



    ret = pci_add_capability(&s->pci.dev, PCI_CAP_ID_MSI, 0,

                             AMDVI_CAPAB_REG_SIZE, err);

    if (ret < 0) {

        return;

    }

    ret = pci_add_capability(&s->pci.dev, PCI_CAP_ID_HT, 0,

                             AMDVI_CAPAB_REG_SIZE, err);

    if (ret < 0) {

        return;

    }



    

    memory_region_init_io(&s->mmio, OBJECT(s), &mmio_mem_ops, s, "amdvi-mmio",

                          AMDVI_MMIO_SIZE);



    sysbus_init_mmio(SYS_BUS_DEVICE(s), &s->mmio);

    sysbus_mmio_map(SYS_BUS_DEVICE(s), 0, AMDVI_BASE_ADDR);

    pci_setup_iommu(bus, amdvi_host_dma_iommu, s);

    s->devid = object_property_get_int(OBJECT(&s->pci), "addr", err);

    msi_init(&s->pci.dev, 0, 1, true, false, err);

    amdvi_init(s);

}

static void FUNC_0(DeviceState *VAR_0, Error **VAR_1)

{

    int VAR_2 = 0;

    AMDVIState *s = AMD_IOMMU_DEVICE(VAR_0);

    X86IOMMUState *x86_iommu = X86_IOMMU_DEVICE(VAR_0);

    MachineState *ms = MACHINE(qdev_get_machine());

    MachineClass *mc = MACHINE_GET_CLASS(ms);

    PCMachineState *pcms =

        PC_MACHINE(object_dynamic_cast(OBJECT(ms), TYPE_PC_MACHINE));

    PCIBus *bus;



    if (!pcms) {

        error_setg(VAR_1, "Machine-type '%s' not supported by amd-iommu",

                   mc->name);

        return;

    }



    bus = pcms->bus;

    s->iotlb = g_hash_table_new_full(amdvi_uint64_hash,

                                     amdvi_uint64_equal, g_free, g_free);



    

    x86_iommu->type = TYPE_AMD;

    qdev_set_parent_bus(DEVICE(&s->pci), &bus->qbus);

    object_property_set_bool(OBJECT(&s->pci), true, "realized", VAR_1);

    VAR_2 = pci_add_capability(&s->pci.VAR_0, AMDVI_CAPAB_ID_SEC, 0,

                                         AMDVI_CAPAB_SIZE, VAR_1);

    if (VAR_2 < 0) {

        return;

    }

    s->capab_offset = VAR_2;



    VAR_2 = pci_add_capability(&s->pci.VAR_0, PCI_CAP_ID_MSI, 0,

                             AMDVI_CAPAB_REG_SIZE, VAR_1);

    if (VAR_2 < 0) {

        return;

    }

    VAR_2 = pci_add_capability(&s->pci.VAR_0, PCI_CAP_ID_HT, 0,

                             AMDVI_CAPAB_REG_SIZE, VAR_1);

    if (VAR_2 < 0) {

        return;

    }



    

    memory_region_init_io(&s->mmio, OBJECT(s), &mmio_mem_ops, s, "amdvi-mmio",

                          AMDVI_MMIO_SIZE);



    sysbus_init_mmio(SYS_BUS_DEVICE(s), &s->mmio);

    sysbus_mmio_map(SYS_BUS_DEVICE(s), 0, AMDVI_BASE_ADDR);

    pci_setup_iommu(bus, amdvi_host_dma_iommu, s);

    s->devid = object_property_get_int(OBJECT(&s->pci), "addr", VAR_1);

    msi_init(&s->pci.VAR_0, 0, 1, true, false, VAR_1);

    amdvi_init(s);

}

static void FUNC_0(DeviceState *VAR_0, Error **VAR_1)
{ int VAR_2 = 0; AMDVIState *s = AMD_IOMMU_DEVICE(VAR_0); X86IOMMUState *x86_iommu = X86_IOMMU_DEVICE(VAR_0); MachineState *ms = MACHINE(qdev_get_machine()); MachineClass *mc = MACHINE_GET_CLASS(ms); PCMachineState *pcms =
PC_MACHINE(object_dynamic_cast(OBJECT(ms), TYPE_PC_MACHINE)); PCIBus *bus; if (!pcms) { error_setg(VAR_1, "Machine-type '%s' not supported by amd-iommu",
mc->name); return; } bus = pcms->bus; s->iotlb = g_hash_table_new_full(amdvi_uint64_hash,
amdvi_uint64_equal, g_free, g_free); x86_iommu->type = TYPE_AMD; qdev_set_parent_bus(DEVICE(&s->pci), &bus->qbus); object_property_set_bool(OBJECT(&s->pci), true, "realized", VAR_1); VAR_2 = pci_add_capability(&s->pci.VAR_0, AMDVI_CAPAB_ID_SEC, 0,
AMDVI_CAPAB_SIZE, VAR_1); if (VAR_2 < 0) { return; } s->capab_offset = VAR_2; VAR_2 = pci_add_capability(&s->pci.VAR_0, PCI_CAP_ID_MSI, 0,
AMDVI_CAPAB_REG_SIZE, VAR_1); if (VAR_2 < 0) { return; } VAR_2 = pci_add_capability(&s->pci.VAR_0, PCI_CAP_ID_HT, 0,
AMDVI_CAPAB_REG_SIZE, VAR_1); if (VAR_2 < 0) { return; } memory_region_init_io(&s->mmio, OBJECT(s), &mmio_mem_ops, s, "amdvi-mmio",
AMDVI_MMIO_SIZE); sysbus_init_mmio(SYS_BUS_DEVICE(s), &s->mmio); sysbus_mmio_map(SYS_BUS_DEVICE(s), 0, AMDVI_BASE_ADDR); pci_setup_iommu(bus, amdvi_host_dma_iommu, s); s->devid = object_property_get_int(OBJECT(&s->pci), "addr", VAR_1); msi_init(&s->pci.VAR_0, 0, 1, true, false, VAR_1); amdvi_init(s); }