static void pci_add_option_rom(PCIDevice *pdev, bool is_default_rom,

                               Error **errp)

{

    int size;

    char *path;

    void *ptr;

    char name[32];

    const VMStateDescription *vmsd;



    if (!pdev->romfile)

        return;

    if (strlen(pdev->romfile) == 0)

        return;



    if (!pdev->rom_bar) {

        /*

         * Load rom via fw_cfg instead of creating a rom bar,

         * for 0.11 compatibility.

         */

        int class = pci_get_word(pdev->config + PCI_CLASS_DEVICE);



        /*

         * Hot-plugged devices can't use the option ROM

         * if the rom bar is disabled.

         */

        if (DEVICE(pdev)->hotplugged) {

            error_setg(errp, "Hot-plugged device without ROM bar"

                       " can't have an option ROM");

            return;

        }



        if (class == 0x0300) {

            rom_add_vga(pdev->romfile);

        } else {

            rom_add_option(pdev->romfile, -1);

        }

        return;

    }



    path = qemu_find_file(QEMU_FILE_TYPE_BIOS, pdev->romfile);

    if (path == NULL) {

        path = g_strdup(pdev->romfile);

    }



    size = get_image_size(path);

    if (size < 0) {

        error_setg(errp, "failed to find romfile \"%s\"", pdev->romfile);

        g_free(path);

        return;

    } else if (size == 0) {

        error_setg(errp, "romfile \"%s\" is empty", pdev->romfile);

        g_free(path);

        return;

    }

    size = pow2ceil(size);



    vmsd = qdev_get_vmsd(DEVICE(pdev));



    if (vmsd) {

        snprintf(name, sizeof(name), "%s.rom", vmsd->name);

    } else {

        snprintf(name, sizeof(name), "%s.rom", object_get_typename(OBJECT(pdev)));

    }

    pdev->has_rom = true;

    memory_region_init_ram(&pdev->rom, OBJECT(pdev), name, size, &error_abort);

    vmstate_register_ram(&pdev->rom, &pdev->qdev);

    ptr = memory_region_get_ram_ptr(&pdev->rom);

    load_image(path, ptr);

    g_free(path);



    if (is_default_rom) {

        /* Only the default rom images will be patched (if needed). */

        pci_patch_ids(pdev, ptr, size);

    }



    pci_register_bar(pdev, PCI_ROM_SLOT, 0, &pdev->rom);

}

static void pci_add_option_rom(PCIDevice *pdev, bool is_default_rom,

                               Error **errp)

{

    int size;

    char *path;

    void *ptr;

    char name[32];

    const VMStateDescription *vmsd;



    if (!pdev->romfile)

        return;

    if (strlen(pdev->romfile) == 0)

        return;



    if (!pdev->rom_bar) {

        







        int class = pci_get_word(pdev->config + PCI_CLASS_DEVICE);



        







        if (DEVICE(pdev)->hotplugged) {

            error_setg(errp, "Hot-plugged device without ROM bar"

                       " can't have an option ROM");

            return;

        }



        if (class == 0x0300) {

            rom_add_vga(pdev->romfile);

        } else {

            rom_add_option(pdev->romfile, -1);

        }

        return;

    }



    path = qemu_find_file(QEMU_FILE_TYPE_BIOS, pdev->romfile);

    if (path == NULL) {

        path = g_strdup(pdev->romfile);

    }



    size = get_image_size(path);

    if (size < 0) {

        error_setg(errp, "failed to find romfile \"%s\"", pdev->romfile);

        g_free(path);

        return;

    } else if (size == 0) {

        error_setg(errp, "romfile \"%s\" is empty", pdev->romfile);

        g_free(path);

        return;

    }

    size = pow2ceil(size);



    vmsd = qdev_get_vmsd(DEVICE(pdev));



    if (vmsd) {

        snprintf(name, sizeof(name), "%s.rom", vmsd->name);

    } else {

        snprintf(name, sizeof(name), "%s.rom", object_get_typename(OBJECT(pdev)));

    }

    pdev->has_rom = true;

    memory_region_init_ram(&pdev->rom, OBJECT(pdev), name, size, &error_abort);

    vmstate_register_ram(&pdev->rom, &pdev->qdev);

    ptr = memory_region_get_ram_ptr(&pdev->rom);

    load_image(path, ptr);

    g_free(path);



    if (is_default_rom) {

        

        pci_patch_ids(pdev, ptr, size);

    }



    pci_register_bar(pdev, PCI_ROM_SLOT, 0, &pdev->rom);

}

    memory_region_init_ram(&pdev->rom, OBJECT(pdev), name, size, &error_abort);
static void FUNC_0(PCIDevice *VAR_0, bool VAR_1,

                               Error **VAR_2)

{

    int VAR_3;

    char *VAR_4;

    void *VAR_5;

    char VAR_6[32];

    const VMStateDescription *VAR_7;



    if (!VAR_0->romfile)

        return;

    if (strlen(VAR_0->romfile) == 0)

        return;



    if (!VAR_0->rom_bar) {

        







        int VAR_8 = pci_get_word(VAR_0->config + PCI_CLASS_DEVICE);



        







        if (DEVICE(VAR_0)->hotplugged) {

            error_setg(VAR_2, "Hot-plugged device without ROM bar"

                       " can't have an option ROM");

            return;

        }



        if (VAR_8 == 0x0300) {

            rom_add_vga(VAR_0->romfile);

        } else {

            rom_add_option(VAR_0->romfile, -1);

        }

        return;

    }



    VAR_4 = qemu_find_file(QEMU_FILE_TYPE_BIOS, VAR_0->romfile);

    if (VAR_4 == NULL) {

        VAR_4 = g_strdup(VAR_0->romfile);

    }



    VAR_3 = get_image_size(VAR_4);

    if (VAR_3 < 0) {

        error_setg(VAR_2, "failed to find romfile \"%s\"", VAR_0->romfile);

        g_free(VAR_4);

        return;

    } else if (VAR_3 == 0) {

        error_setg(VAR_2, "romfile \"%s\" is empty", VAR_0->romfile);

        g_free(VAR_4);

        return;

    }

    VAR_3 = pow2ceil(VAR_3);



    VAR_7 = qdev_get_vmsd(DEVICE(VAR_0));



    if (VAR_7) {

        snprintf(VAR_6, sizeof(VAR_6), "%s.rom", VAR_7->VAR_6);

    } else {

        snprintf(VAR_6, sizeof(VAR_6), "%s.rom", object_get_typename(OBJECT(VAR_0)));

    }

    VAR_0->has_rom = true;

    memory_region_init_ram(&VAR_0->rom, OBJECT(VAR_0), VAR_6, VAR_3, &error_abort);

    vmstate_register_ram(&VAR_0->rom, &VAR_0->qdev);

    VAR_5 = memory_region_get_ram_ptr(&VAR_0->rom);

    load_image(VAR_4, VAR_5);

    g_free(VAR_4);



    if (VAR_1) {

        

        pci_patch_ids(VAR_0, VAR_5, VAR_3);

    }



    pci_register_bar(VAR_0, PCI_ROM_SLOT, 0, &VAR_0->rom);

}

static void FUNC_0(PCIDevice *VAR_0, bool VAR_1,
Error **VAR_2)
{ int VAR_3; char *VAR_4; void *VAR_5; char VAR_6[32]; const VMStateDescription *VAR_7; if (!VAR_0->romfile)
return; if (strlen(VAR_0->romfile) == 0)
return; if (!VAR_0->rom_bar) { int VAR_8 = pci_get_word(VAR_0->config + PCI_CLASS_DEVICE); if (DEVICE(VAR_0)->hotplugged) { error_setg(VAR_2, "Hot-plugged device without ROM bar"
" can't have an option ROM"); return; } if (VAR_8 == 0x0300) { rom_add_vga(VAR_0->romfile); } else { rom_add_option(VAR_0->romfile, -1); } return; } VAR_4 = qemu_find_file(QEMU_FILE_TYPE_BIOS, VAR_0->romfile); if (VAR_4 == NULL) { VAR_4 = g_strdup(VAR_0->romfile); } VAR_3 = get_image_size(VAR_4); if (VAR_3 < 0) { error_setg(VAR_2, "failed to find romfile \"%s\"", VAR_0->romfile); g_free(VAR_4); return; } else if (VAR_3 == 0) { error_setg(VAR_2, "romfile \"%s\" is empty", VAR_0->romfile); g_free(VAR_4); return; } VAR_3 = pow2ceil(VAR_3); VAR_7 = qdev_get_vmsd(DEVICE(VAR_0)); if (VAR_7) { snprintf(VAR_6, sizeof(VAR_6), "%s.rom", VAR_7->VAR_6); } else { snprintf(VAR_6, sizeof(VAR_6), "%s.rom", object_get_typename(OBJECT(VAR_0))); } VAR_0->has_rom = true; memory_region_init_ram(&VAR_0->rom, OBJECT(VAR_0), VAR_6, VAR_3, &error_abort); vmstate_register_ram(&VAR_0->rom, &VAR_0->qdev); VAR_5 = memory_region_get_ram_ptr(&VAR_0->rom); load_image(VAR_4, VAR_5); g_free(VAR_4); if (VAR_1) { pci_patch_ids(VAR_0, VAR_5, VAR_3); } pci_register_bar(VAR_0, PCI_ROM_SLOT, 0, &VAR_0->rom); }