static int pci_add_option_rom(PCIDevice *pdev, bool is_default_rom)

{

    int size;

    char *path;

    void *ptr;

    char name[32];

    const VMStateDescription *vmsd;



    if (!pdev->romfile)

        return 0;

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

        return 0;



    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);

        if (class == 0x0300) {

            rom_add_vga(pdev->romfile);

        } else {

            rom_add_option(pdev->romfile, -1);

        }

        return 0;

    }



    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_report("%s: failed to find romfile \"%s\"",

                     __FUNCTION__, pdev->romfile);

        g_free(path);

        return -1;

    }

    if (size & (size - 1)) {

        size = 1 << qemu_fls(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, name, size);

    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);

    }



    qemu_put_ram_ptr(ptr);



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



    return 0;

}

static int pci_add_option_rom(PCIDevice *pdev, bool is_default_rom)

{

    int size;

    char *path;

    void *ptr;

    char name[32];

    const VMStateDescription *vmsd;



    if (!pdev->romfile)

        return 0;

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

        return 0;



    if (!pdev->rom_bar) {

        







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

        if (class == 0x0300) {

            rom_add_vga(pdev->romfile);

        } else {

            rom_add_option(pdev->romfile, -1);

        }

        return 0;

    }



    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_report("%s: failed to find romfile \"%s\"",

                     __FUNCTION__, pdev->romfile);

        g_free(path);

        return -1;

    }

    if (size & (size - 1)) {

        size = 1 << qemu_fls(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, name, size);

    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);

    }



    qemu_put_ram_ptr(ptr);



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



    return 0;

}

static int FUNC_0(PCIDevice *VAR_0, bool VAR_1)

{

    int VAR_2;

    char *VAR_3;

    void *VAR_4;

    char VAR_5[32];

    const VMStateDescription *VAR_6;



    if (!VAR_0->romfile)

        return 0;

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

        return 0;



    if (!VAR_0->rom_bar) {

        







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

        if (VAR_7 == 0x0300) {

            rom_add_vga(VAR_0->romfile);

        } else {

            rom_add_option(VAR_0->romfile, -1);

        }

        return 0;

    }



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

    if (VAR_3 == NULL) {

        VAR_3 = g_strdup(VAR_0->romfile);

    }



    VAR_2 = get_image_size(VAR_3);

    if (VAR_2 < 0) {

        error_report("%s: failed to find romfile \"%s\"",

                     __FUNCTION__, VAR_0->romfile);

        g_free(VAR_3);

        return -1;

    }

    if (VAR_2 & (VAR_2 - 1)) {

        VAR_2 = 1 << qemu_fls(VAR_2);

    }



    VAR_6 = qdev_get_vmsd(DEVICE(VAR_0));



    if (VAR_6) {

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

    } else {

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

    }

    VAR_0->has_rom = true;

    memory_region_init_ram(&VAR_0->rom, VAR_5, VAR_2);

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

    VAR_4 = memory_region_get_ram_ptr(&VAR_0->rom);

    load_image(VAR_3, VAR_4);

    g_free(VAR_3);



    if (VAR_1) {

        

        pci_patch_ids(VAR_0, VAR_4, VAR_2);

    }



    qemu_put_ram_ptr(VAR_4);



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



    return 0;

}

static int FUNC_0(PCIDevice *VAR_0, bool VAR_1)
{ int VAR_2; char *VAR_3; void *VAR_4; char VAR_5[32]; const VMStateDescription *VAR_6; if (!VAR_0->romfile)
return 0; if (strlen(VAR_0->romfile) == 0)
return 0; if (!VAR_0->rom_bar) { int VAR_7 = pci_get_word(VAR_0->config + PCI_CLASS_DEVICE); if (VAR_7 == 0x0300) { rom_add_vga(VAR_0->romfile); } else { rom_add_option(VAR_0->romfile, -1); } return 0; } VAR_3 = qemu_find_file(QEMU_FILE_TYPE_BIOS, VAR_0->romfile); if (VAR_3 == NULL) { VAR_3 = g_strdup(VAR_0->romfile); } VAR_2 = get_image_size(VAR_3); if (VAR_2 < 0) { error_report("%s: failed to find romfile \"%s\"",
__FUNCTION__, VAR_0->romfile); g_free(VAR_3); return -1; } if (VAR_2 & (VAR_2 - 1)) { VAR_2 = 1 << qemu_fls(VAR_2); } VAR_6 = qdev_get_vmsd(DEVICE(VAR_0)); if (VAR_6) { snprintf(VAR_5, sizeof(VAR_5), "%s.rom", VAR_6->VAR_5); } else { snprintf(VAR_5, sizeof(VAR_5), "%s.rom", object_get_typename(OBJECT(VAR_0))); } VAR_0->has_rom = true; memory_region_init_ram(&VAR_0->rom, VAR_5, VAR_2); vmstate_register_ram(&VAR_0->rom, &VAR_0->qdev); VAR_4 = memory_region_get_ram_ptr(&VAR_0->rom); load_image(VAR_3, VAR_4); g_free(VAR_3); if (VAR_1) { pci_patch_ids(VAR_0, VAR_4, VAR_2); } qemu_put_ram_ptr(VAR_4); pci_register_bar(VAR_0, PCI_ROM_SLOT, 0, &VAR_0->rom); return 0; }