static void vfio_pci_size_rom(VFIOPCIDevice *vdev)

{

    uint32_t orig, size = cpu_to_le32((uint32_t)PCI_ROM_ADDRESS_MASK);

    off_t offset = vdev->config_offset + PCI_ROM_ADDRESS;

    DeviceState *dev = DEVICE(vdev);

    char name[32];

    int fd = vdev->vbasedev.fd;



    if (vdev->pdev.romfile || !vdev->pdev.rom_bar) {

        /* Since pci handles romfile, just print a message and return */

        if (vfio_blacklist_opt_rom(vdev) && vdev->pdev.romfile) {

            error_printf("Warning : Device at %04x:%02x:%02x.%x "

                         "is known to cause system instability issues during "

                         "option rom execution. "

                         "Proceeding anyway since user specified romfile\n",

                         vdev->host.domain, vdev->host.bus, vdev->host.slot,

                         vdev->host.function);

        }

        return;

    }



    /*

     * Use the same size ROM BAR as the physical device.  The contents

     * will get filled in later when the guest tries to read it.

     */

    if (pread(fd, &orig, 4, offset) != 4 ||

        pwrite(fd, &size, 4, offset) != 4 ||

        pread(fd, &size, 4, offset) != 4 ||

        pwrite(fd, &orig, 4, offset) != 4) {

        error_report("%s(%04x:%02x:%02x.%x) failed: %m",

                     __func__, vdev->host.domain, vdev->host.bus,

                     vdev->host.slot, vdev->host.function);

        return;

    }



    size = ~(le32_to_cpu(size) & PCI_ROM_ADDRESS_MASK) + 1;



    if (!size) {

        return;

    }



    if (vfio_blacklist_opt_rom(vdev)) {

        if (dev->opts && qemu_opt_get(dev->opts, "rombar")) {

            error_printf("Warning : Device at %04x:%02x:%02x.%x "

                         "is known to cause system instability issues during "

                         "option rom execution. "

                         "Proceeding anyway since user specified non zero value for "

                         "rombar\n",

                         vdev->host.domain, vdev->host.bus, vdev->host.slot,

                         vdev->host.function);

        } else {

            error_printf("Warning : Rom loading for device at "

                         "%04x:%02x:%02x.%x has been disabled due to "

                         "system instability issues. "

                         "Specify rombar=1 or romfile to force\n",

                         vdev->host.domain, vdev->host.bus, vdev->host.slot,

                         vdev->host.function);

            return;

        }

    }



    trace_vfio_pci_size_rom(vdev->vbasedev.name, size);



    snprintf(name, sizeof(name), "vfio[%04x:%02x:%02x.%x].rom",

             vdev->host.domain, vdev->host.bus, vdev->host.slot,

             vdev->host.function);



    memory_region_init_io(&vdev->pdev.rom, OBJECT(vdev),

                          &vfio_rom_ops, vdev, name, size);



    pci_register_bar(&vdev->pdev, PCI_ROM_SLOT,

                     PCI_BASE_ADDRESS_SPACE_MEMORY, &vdev->pdev.rom);



    vdev->pdev.has_rom = true;

    vdev->rom_read_failed = false;

}

static void vfio_pci_size_rom(VFIOPCIDevice *vdev)

{

    uint32_t orig, size = cpu_to_le32((uint32_t)PCI_ROM_ADDRESS_MASK);

    off_t offset = vdev->config_offset + PCI_ROM_ADDRESS;

    DeviceState *dev = DEVICE(vdev);

    char name[32];

    int fd = vdev->vbasedev.fd;



    if (vdev->pdev.romfile || !vdev->pdev.rom_bar) {

        

        if (vfio_blacklist_opt_rom(vdev) && vdev->pdev.romfile) {

            error_printf("Warning : Device at %04x:%02x:%02x.%x "

                         "is known to cause system instability issues during "

                         "option rom execution. "

                         "Proceeding anyway since user specified romfile\n",

                         vdev->host.domain, vdev->host.bus, vdev->host.slot,

                         vdev->host.function);

        }

        return;

    }



    







    if (pread(fd, &orig, 4, offset) != 4 ||

        pwrite(fd, &size, 4, offset) != 4 ||

        pread(fd, &size, 4, offset) != 4 ||

        pwrite(fd, &orig, 4, offset) != 4) {

        error_report("%s(%04x:%02x:%02x.%x) failed: %m",

                     __func__, vdev->host.domain, vdev->host.bus,

                     vdev->host.slot, vdev->host.function);

        return;

    }



    size = ~(le32_to_cpu(size) & PCI_ROM_ADDRESS_MASK) + 1;



    if (!size) {

        return;

    }



    if (vfio_blacklist_opt_rom(vdev)) {

        if (dev->opts && qemu_opt_get(dev->opts, "rombar")) {

            error_printf("Warning : Device at %04x:%02x:%02x.%x "

                         "is known to cause system instability issues during "

                         "option rom execution. "

                         "Proceeding anyway since user specified non zero value for "

                         "rombar\n",

                         vdev->host.domain, vdev->host.bus, vdev->host.slot,

                         vdev->host.function);

        } else {

            error_printf("Warning : Rom loading for device at "

                         "%04x:%02x:%02x.%x has been disabled due to "

                         "system instability issues. "

                         "Specify rombar=1 or romfile to force\n",

                         vdev->host.domain, vdev->host.bus, vdev->host.slot,

                         vdev->host.function);

            return;

        }

    }



    trace_vfio_pci_size_rom(vdev->vbasedev.name, size);



    snprintf(name, sizeof(name), "vfio[%04x:%02x:%02x.%x].rom",

             vdev->host.domain, vdev->host.bus, vdev->host.slot,

             vdev->host.function);



    memory_region_init_io(&vdev->pdev.rom, OBJECT(vdev),

                          &vfio_rom_ops, vdev, name, size);



    pci_register_bar(&vdev->pdev, PCI_ROM_SLOT,

                     PCI_BASE_ADDRESS_SPACE_MEMORY, &vdev->pdev.rom);



    vdev->pdev.has_rom = true;

    vdev->rom_read_failed = false;

}

static void FUNC_0(VFIOPCIDevice *VAR_0)

{

    uint32_t orig, size = cpu_to_le32((uint32_t)PCI_ROM_ADDRESS_MASK);

    off_t offset = VAR_0->config_offset + PCI_ROM_ADDRESS;

    DeviceState *dev = DEVICE(VAR_0);

    char VAR_1[32];

    int VAR_2 = VAR_0->vbasedev.VAR_2;



    if (VAR_0->pdev.romfile || !VAR_0->pdev.rom_bar) {

        

        if (vfio_blacklist_opt_rom(VAR_0) && VAR_0->pdev.romfile) {

            error_printf("Warning : Device at %04x:%02x:%02x.%x "

                         "is known to cause system instability issues during "

                         "option rom execution. "

                         "Proceeding anyway since user specified romfile\n",

                         VAR_0->host.domain, VAR_0->host.bus, VAR_0->host.slot,

                         VAR_0->host.function);

        }

        return;

    }



    







    if (pread(VAR_2, &orig, 4, offset) != 4 ||

        pwrite(VAR_2, &size, 4, offset) != 4 ||

        pread(VAR_2, &size, 4, offset) != 4 ||

        pwrite(VAR_2, &orig, 4, offset) != 4) {

        error_report("%s(%04x:%02x:%02x.%x) failed: %m",

                     __func__, VAR_0->host.domain, VAR_0->host.bus,

                     VAR_0->host.slot, VAR_0->host.function);

        return;

    }



    size = ~(le32_to_cpu(size) & PCI_ROM_ADDRESS_MASK) + 1;



    if (!size) {

        return;

    }



    if (vfio_blacklist_opt_rom(VAR_0)) {

        if (dev->opts && qemu_opt_get(dev->opts, "rombar")) {

            error_printf("Warning : Device at %04x:%02x:%02x.%x "

                         "is known to cause system instability issues during "

                         "option rom execution. "

                         "Proceeding anyway since user specified non zero value for "

                         "rombar\n",

                         VAR_0->host.domain, VAR_0->host.bus, VAR_0->host.slot,

                         VAR_0->host.function);

        } else {

            error_printf("Warning : Rom loading for device at "

                         "%04x:%02x:%02x.%x has been disabled due to "

                         "system instability issues. "

                         "Specify rombar=1 or romfile to force\n",

                         VAR_0->host.domain, VAR_0->host.bus, VAR_0->host.slot,

                         VAR_0->host.function);

            return;

        }

    }



    trace_vfio_pci_size_rom(VAR_0->vbasedev.VAR_1, size);



    snprintf(VAR_1, sizeof(VAR_1), "vfio[%04x:%02x:%02x.%x].rom",

             VAR_0->host.domain, VAR_0->host.bus, VAR_0->host.slot,

             VAR_0->host.function);



    memory_region_init_io(&VAR_0->pdev.rom, OBJECT(VAR_0),

                          &vfio_rom_ops, VAR_0, VAR_1, size);



    pci_register_bar(&VAR_0->pdev, PCI_ROM_SLOT,

                     PCI_BASE_ADDRESS_SPACE_MEMORY, &VAR_0->pdev.rom);



    VAR_0->pdev.has_rom = true;

    VAR_0->rom_read_failed = false;

}

static void FUNC_0(VFIOPCIDevice *VAR_0)
{ uint32_t orig, size = cpu_to_le32((uint32_t)PCI_ROM_ADDRESS_MASK); off_t offset = VAR_0->config_offset + PCI_ROM_ADDRESS; DeviceState *dev = DEVICE(VAR_0); char VAR_1[32]; int VAR_2 = VAR_0->vbasedev.VAR_2; if (VAR_0->pdev.romfile || !VAR_0->pdev.rom_bar) { if (vfio_blacklist_opt_rom(VAR_0) && VAR_0->pdev.romfile) { error_printf("Warning : Device at %04x:%02x:%02x.%x "
"is known to cause system instability issues during "
"option rom execution. "
"Proceeding anyway since user specified romfile\n",
VAR_0->host.domain, VAR_0->host.bus, VAR_0->host.slot,
VAR_0->host.function); } return; } if (pread(VAR_2, &orig, 4, offset) != 4 ||
pwrite(VAR_2, &size, 4, offset) != 4 ||
pread(VAR_2, &size, 4, offset) != 4 ||
pwrite(VAR_2, &orig, 4, offset) != 4) { error_report("%s(%04x:%02x:%02x.%x) failed: %m",
__func__, VAR_0->host.domain, VAR_0->host.bus,
VAR_0->host.slot, VAR_0->host.function); return; } size = ~(le32_to_cpu(size) & PCI_ROM_ADDRESS_MASK) + 1; if (!size) { return; } if (vfio_blacklist_opt_rom(VAR_0)) { if (dev->opts && qemu_opt_get(dev->opts, "rombar")) { error_printf("Warning : Device at %04x:%02x:%02x.%x "
"is known to cause system instability issues during "
"option rom execution. "
"Proceeding anyway since user specified non zero value for "
"rombar\n",
VAR_0->host.domain, VAR_0->host.bus, VAR_0->host.slot,
VAR_0->host.function); } else { error_printf("Warning : Rom loading for device at "
"%04x:%02x:%02x.%x has been disabled due to "
"system instability issues. "
"Specify rombar=1 or romfile to force\n",
VAR_0->host.domain, VAR_0->host.bus, VAR_0->host.slot,
VAR_0->host.function); return; } } trace_vfio_pci_size_rom(VAR_0->vbasedev.VAR_1, size); snprintf(VAR_1, sizeof(VAR_1), "vfio[%04x:%02x:%02x.%x].rom",
VAR_0->host.domain, VAR_0->host.bus, VAR_0->host.slot,
VAR_0->host.function); memory_region_init_io(&VAR_0->pdev.rom, OBJECT(VAR_0),
&vfio_rom_ops, VAR_0, VAR_1, size); pci_register_bar(&VAR_0->pdev, PCI_ROM_SLOT,
PCI_BASE_ADDRESS_SPACE_MEMORY, &VAR_0->pdev.rom); VAR_0->pdev.has_rom = true; VAR_0->rom_read_failed = false; }