static void vfio_pci_load_rom(VFIOPCIDevice *vdev)

{

    struct vfio_region_info reg_info = {

        .argsz = sizeof(reg_info),

        .index = VFIO_PCI_ROM_REGION_INDEX

    };

    uint64_t size;

    off_t off = 0;

    size_t bytes;



    if (ioctl(vdev->vbasedev.fd, VFIO_DEVICE_GET_REGION_INFO, &reg_info)) {

        error_report("vfio: Error getting ROM info: %m");

        return;

    }



    trace_vfio_pci_load_rom(vdev->vbasedev.name, (unsigned long)reg_info.size,

                            (unsigned long)reg_info.offset,

                            (unsigned long)reg_info.flags);



    vdev->rom_size = size = reg_info.size;

    vdev->rom_offset = reg_info.offset;



    if (!vdev->rom_size) {

        vdev->rom_read_failed = true;

        error_report("vfio-pci: Cannot read device rom at "

                    "%s", vdev->vbasedev.name);

        error_printf("Device option ROM contents are probably invalid "

                    "(check dmesg).\nSkip option ROM probe with rombar=0, "

                    "or load from file with romfile=\n");

        return;

    }



    vdev->rom = g_malloc(size);

    memset(vdev->rom, 0xff, size);



    while (size) {

        bytes = pread(vdev->vbasedev.fd, vdev->rom + off,

                      size, vdev->rom_offset + 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");

            break;

        }

    }

}

static void vfio_pci_load_rom(VFIOPCIDevice *vdev)

{

    struct vfio_region_info reg_info = {

        .argsz = sizeof(reg_info),

        .index = VFIO_PCI_ROM_REGION_INDEX

    };

    uint64_t size;

    off_t off = 0;

    size_t bytes;



    if (ioctl(vdev->vbasedev.fd, VFIO_DEVICE_GET_REGION_INFO, &reg_info)) {

        error_report("vfio: Error getting ROM info: %m");

        return;

    }



    trace_vfio_pci_load_rom(vdev->vbasedev.name, (unsigned long)reg_info.size,

                            (unsigned long)reg_info.offset,

                            (unsigned long)reg_info.flags);



    vdev->rom_size = size = reg_info.size;

    vdev->rom_offset = reg_info.offset;



    if (!vdev->rom_size) {

        vdev->rom_read_failed = true;

        error_report("vfio-pci: Cannot read device rom at "

                    "%s", vdev->vbasedev.name);

        error_printf("Device option ROM contents are probably invalid "

                    "(check dmesg).\nSkip option ROM probe with rombar=0, "

                    "or load from file with romfile=\n");

        return;

    }



    vdev->rom = g_malloc(size);

    memset(vdev->rom, 0xff, size);



    while (size) {

        bytes = pread(vdev->vbasedev.fd, vdev->rom + off,

                      size, vdev->rom_offset + 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");

            break;

        }

    }

}

static void FUNC_0(VFIOPCIDevice *VAR_0)

{

    struct vfio_region_info VAR_1 = {

        .argsz = sizeof(VAR_1),

        .index = VFIO_PCI_ROM_REGION_INDEX

    };

    uint64_t size;

    off_t off = 0;

    size_t bytes;



    if (ioctl(VAR_0->vbasedev.fd, VFIO_DEVICE_GET_REGION_INFO, &VAR_1)) {

        error_report("vfio: Error getting ROM info: %m");

        return;

    }



    trace_vfio_pci_load_rom(VAR_0->vbasedev.name, (unsigned long)VAR_1.size,

                            (unsigned long)VAR_1.offset,

                            (unsigned long)VAR_1.flags);



    VAR_0->rom_size = size = VAR_1.size;

    VAR_0->rom_offset = VAR_1.offset;



    if (!VAR_0->rom_size) {

        VAR_0->rom_read_failed = true;

        error_report("vfio-pci: Cannot read device rom at "

                    "%s", VAR_0->vbasedev.name);

        error_printf("Device option ROM contents are probably invalid "

                    "(check dmesg).\nSkip option ROM probe with rombar=0, "

                    "or load from file with romfile=\n");

        return;

    }



    VAR_0->rom = g_malloc(size);

    memset(VAR_0->rom, 0xff, size);



    while (size) {

        bytes = pread(VAR_0->vbasedev.fd, VAR_0->rom + off,

                      size, VAR_0->rom_offset + 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");

            break;

        }

    }

}

static void FUNC_0(VFIOPCIDevice *VAR_0)
{ struct vfio_region_info VAR_1 = { .argsz = sizeof(VAR_1),
.index = VFIO_PCI_ROM_REGION_INDEX
}; uint64_t size; off_t off = 0; size_t bytes; if (ioctl(VAR_0->vbasedev.fd, VFIO_DEVICE_GET_REGION_INFO, &VAR_1)) { error_report("vfio: Error getting ROM info: %m"); return; } trace_vfio_pci_load_rom(VAR_0->vbasedev.name, (unsigned long)VAR_1.size,
(unsigned long)VAR_1.offset,
(unsigned long)VAR_1.flags); VAR_0->rom_size = size = VAR_1.size; VAR_0->rom_offset = VAR_1.offset; if (!VAR_0->rom_size) { VAR_0->rom_read_failed = true; error_report("vfio-pci: Cannot read device rom at "
"%s", VAR_0->vbasedev.name); error_printf("Device option ROM contents are probably invalid "
"(check dmesg).\nSkip option ROM probe with rombar=0, "
"or load from file with romfile=\n"); return; } VAR_0->rom = g_malloc(size); memset(VAR_0->rom, 0xff, size); while (size) { bytes = pread(VAR_0->vbasedev.fd, VAR_0->rom + off,
size, VAR_0->rom_offset + 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"); break; } } }