static int vfio_load_rom(VFIODevice *vdev)

{

    uint64_t size = vdev->rom_size;

    char name[32];

    off_t off = 0, voff = vdev->rom_offset;

    ssize_t bytes;

    void *ptr;



    /* If loading ROM from file, pci handles it */

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

        return 0;

    }



    DPRINTF("%s(%04x:%02x:%02x.%x)\n", __func__, vdev->host.domain,

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



    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_ram(&vdev->pdev.rom, OBJECT(vdev), name, size);

    ptr = memory_region_get_ram_ptr(&vdev->pdev.rom);

    memset(ptr, 0xff, size);



    while (size) {

        bytes = pread(vdev->fd, ptr + off, size, voff + off);

        if (bytes == 0) {

            break; /* expect that we could get back less than the ROM BAR */

        } else if (bytes > 0) {

            off += bytes;

            size -= bytes;

        } else {

            if (errno == EINTR || errno == EAGAIN) {

                continue;

            }

            error_report("vfio: Error reading device ROM: %m");

            memory_region_destroy(&vdev->pdev.rom);

            return -errno;

        }

    }



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

    vdev->pdev.has_rom = true;

    return 0;

}

static int vfio_load_rom(VFIODevice *vdev)

{

    uint64_t size = vdev->rom_size;

    char name[32];

    off_t off = 0, voff = vdev->rom_offset;

    ssize_t bytes;

    void *ptr;



    

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

        return 0;

    }



    DPRINTF("%s(%04x:%02x:%02x.%x)\n", __func__, vdev->host.domain,

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



    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_ram(&vdev->pdev.rom, OBJECT(vdev), name, size);

    ptr = memory_region_get_ram_ptr(&vdev->pdev.rom);

    memset(ptr, 0xff, size);



    while (size) {

        bytes = pread(vdev->fd, ptr + off, size, voff + off);

        if (bytes == 0) {

            break; 

        } else if (bytes > 0) {

            off += bytes;

            size -= bytes;

        } else {

            if (errno == EINTR || errno == EAGAIN) {

                continue;

            }

            error_report("vfio: Error reading device ROM: %m");

            memory_region_destroy(&vdev->pdev.rom);

            return -errno;

        }

    }



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

    vdev->pdev.has_rom = true;

    return 0;

}

static int FUNC_0(VFIODevice *VAR_0)

{

    uint64_t size = VAR_0->rom_size;

    char VAR_1[32];

    off_t off = 0, voff = VAR_0->rom_offset;

    ssize_t bytes;

    void *VAR_2;



    

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

        return 0;

    }



    DPRINTF("%s(%04x:%02x:%02x.%x)\n", __func__, VAR_0->host.domain,

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



    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_ram(&VAR_0->pdev.rom, OBJECT(VAR_0), VAR_1, size);

    VAR_2 = memory_region_get_ram_ptr(&VAR_0->pdev.rom);

    memset(VAR_2, 0xff, size);



    while (size) {

        bytes = pread(VAR_0->fd, VAR_2 + off, size, voff + off);

        if (bytes == 0) {

            break; 

        } else if (bytes > 0) {

            off += bytes;

            size -= bytes;

        } else {

            if (errno == EINTR || errno == EAGAIN) {

                continue;

            }

            error_report("vfio: Error reading device ROM: %m");

            memory_region_destroy(&VAR_0->pdev.rom);

            return -errno;

        }

    }



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

    VAR_0->pdev.has_rom = true;

    return 0;

}

static int FUNC_0(VFIODevice *VAR_0)
{ uint64_t size = VAR_0->rom_size; char VAR_1[32]; off_t off = 0, voff = VAR_0->rom_offset; ssize_t bytes; void *VAR_2; if (VAR_0->pdev.romfile || !VAR_0->pdev.rom_bar || !size) { return 0; } DPRINTF("%s(%04x:%02x:%02x.%x)\n", __func__, VAR_0->host.domain,
VAR_0->host.bus, VAR_0->host.slot, VAR_0->host.function); 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_ram(&VAR_0->pdev.rom, OBJECT(VAR_0), VAR_1, size); VAR_2 = memory_region_get_ram_ptr(&VAR_0->pdev.rom); memset(VAR_2, 0xff, size); while (size) { bytes = pread(VAR_0->fd, VAR_2 + off, size, voff + off); if (bytes == 0) { break; } else if (bytes > 0) { off += bytes; size -= bytes; } else { if (errno == EINTR || errno == EAGAIN) { continue; } error_report("vfio: Error reading device ROM: %m"); memory_region_destroy(&VAR_0->pdev.rom); return -errno; } } pci_register_bar(&VAR_0->pdev, PCI_ROM_SLOT, 0, &VAR_0->pdev.rom); VAR_0->pdev.has_rom = true; return 0; }