void *pci_assign_dev_load_option_rom(PCIDevice *dev, struct Object *owner,

                                     int *size, unsigned int domain,

                                     unsigned int bus, unsigned int slot,

                                     unsigned int function)

{

    char name[32], rom_file[64];

    FILE *fp;

    uint8_t val;

    struct stat st;

    void *ptr = NULL;



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

    if (dev->romfile || !dev->rom_bar) {

        return NULL;

    }



    snprintf(rom_file, sizeof(rom_file),

             "/sys/bus/pci/devices/%04x:%02x:%02x.%01x/rom",

             domain, bus, slot, function);



    if (stat(rom_file, &st)) {

        return NULL;

    }



    if (access(rom_file, F_OK)) {

        error_report("pci-assign: Insufficient privileges for %s", rom_file);

        return NULL;

    }



    /* Write "1" to the ROM file to enable it */

    fp = fopen(rom_file, "r+");

    if (fp == NULL) {

        return NULL;

    }

    val = 1;

    if (fwrite(&val, 1, 1, fp) != 1) {

        goto close_rom;

    }

    fseek(fp, 0, SEEK_SET);



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

    memory_region_init_ram(&dev->rom, owner, name, st.st_size, &error_abort);

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

    ptr = memory_region_get_ram_ptr(&dev->rom);

    memset(ptr, 0xff, st.st_size);



    if (!fread(ptr, 1, st.st_size, fp)) {

        error_report("pci-assign: Cannot read from host %s", rom_file);

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

        goto close_rom;

    }



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

    dev->has_rom = true;

    *size = st.st_size;

close_rom:

    /* Write "0" to disable ROM */

    fseek(fp, 0, SEEK_SET);

    val = 0;

    if (!fwrite(&val, 1, 1, fp)) {

        DEBUG("%s\n", "Failed to disable pci-sysfs rom file");

    }

    fclose(fp);



    return ptr;

}

void *pci_assign_dev_load_option_rom(PCIDevice *dev, struct Object *owner,

                                     int *size, unsigned int domain,

                                     unsigned int bus, unsigned int slot,

                                     unsigned int function)

{

    char name[32], rom_file[64];

    FILE *fp;

    uint8_t val;

    struct stat st;

    void *ptr = NULL;



    

    if (dev->romfile || !dev->rom_bar) {

        return NULL;

    }



    snprintf(rom_file, sizeof(rom_file),

             "/sys/bus/pci/devices/%04x:%02x:%02x.%01x/rom",

             domain, bus, slot, function);



    if (stat(rom_file, &st)) {

        return NULL;

    }



    if (access(rom_file, F_OK)) {

        error_report("pci-assign: Insufficient privileges for %s", rom_file);

        return NULL;

    }



    

    fp = fopen(rom_file, "r+");

    if (fp == NULL) {

        return NULL;

    }

    val = 1;

    if (fwrite(&val, 1, 1, fp) != 1) {

        goto close_rom;

    }

    fseek(fp, 0, SEEK_SET);



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

    memory_region_init_ram(&dev->rom, owner, name, st.st_size, &error_abort);

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

    ptr = memory_region_get_ram_ptr(&dev->rom);

    memset(ptr, 0xff, st.st_size);



    if (!fread(ptr, 1, st.st_size, fp)) {

        error_report("pci-assign: Cannot read from host %s", rom_file);

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

        goto close_rom;

    }



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

    dev->has_rom = true;

    *size = st.st_size;

close_rom:

    

    fseek(fp, 0, SEEK_SET);

    val = 0;

    if (!fwrite(&val, 1, 1, fp)) {

        DEBUG("%s\n", "Failed to disable pci-sysfs rom file");

    }

    fclose(fp);



    return ptr;

}

    if (access(rom_file, F_OK)) {         error_report("pci-assign: Insufficient privileges for %s", rom_file);         return NULL;
void *FUNC_0(PCIDevice *VAR_0, struct Object *VAR_1,

                                     int *VAR_2, unsigned int VAR_3,

                                     unsigned int VAR_4, unsigned int VAR_5,

                                     unsigned int VAR_6)

{

    char VAR_7[32], VAR_8[64];

    FILE *fp;

    uint8_t val;

    struct stat VAR_9;

    void *VAR_10 = NULL;



    

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

        return NULL;

    }



    snprintf(VAR_8, sizeof(VAR_8),

             "/sys/VAR_4/pci/devices/%04x:%02x:%02x.%01x/rom",

             VAR_3, VAR_4, VAR_5, VAR_6);



    if (stat(VAR_8, &VAR_9)) {

        return NULL;

    }



    if (access(VAR_8, F_OK)) {

        error_report("pci-assign: Insufficient privileges for %s", VAR_8);

        return NULL;

    }



    

    fp = fopen(VAR_8, "r+");

    if (fp == NULL) {

        return NULL;

    }

    val = 1;

    if (fwrite(&val, 1, 1, fp) != 1) {

        goto close_rom;

    }

    fseek(fp, 0, SEEK_SET);



    snprintf(VAR_7, sizeof(VAR_7), "%s.rom", object_get_typename(VAR_1));

    memory_region_init_ram(&VAR_0->rom, VAR_1, VAR_7, VAR_9.st_size, &error_abort);

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

    VAR_10 = memory_region_get_ram_ptr(&VAR_0->rom);

    memset(VAR_10, 0xff, VAR_9.st_size);



    if (!fread(VAR_10, 1, VAR_9.st_size, fp)) {

        error_report("pci-assign: Cannot read from host %s", VAR_8);

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

        goto close_rom;

    }



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

    VAR_0->has_rom = true;

    *VAR_2 = VAR_9.st_size;

close_rom:

    

    fseek(fp, 0, SEEK_SET);

    val = 0;

    if (!fwrite(&val, 1, 1, fp)) {

        DEBUG("%s\n", "Failed to disable pci-sysfs rom file");

    }

    fclose(fp);



    return VAR_10;

}

void *FUNC_0(PCIDevice *VAR_0, struct Object *VAR_1,
int *VAR_2, unsigned int VAR_3,
unsigned int VAR_4, unsigned int VAR_5,
unsigned int VAR_6)
{ char VAR_7[32], VAR_8[64]; FILE *fp; uint8_t val; struct stat VAR_9; void *VAR_10 = NULL; if (VAR_0->romfile || !VAR_0->rom_bar) { return NULL; } snprintf(VAR_8, sizeof(VAR_8),
"/sys/VAR_4/pci/devices/%04x:%02x:%02x.%01x/rom",
VAR_3, VAR_4, VAR_5, VAR_6); if (stat(VAR_8, &VAR_9)) { return NULL; } if (access(VAR_8, F_OK)) { error_report("pci-assign: Insufficient privileges for %s", VAR_8); return NULL; } fp = fopen(VAR_8, "r+"); if (fp == NULL) { return NULL; } val = 1; if (fwrite(&val, 1, 1, fp) != 1) { goto close_rom; } fseek(fp, 0, SEEK_SET); snprintf(VAR_7, sizeof(VAR_7), "%s.rom", object_get_typename(VAR_1)); memory_region_init_ram(&VAR_0->rom, VAR_1, VAR_7, VAR_9.st_size, &error_abort); vmstate_register_ram(&VAR_0->rom, &VAR_0->qdev); VAR_10 = memory_region_get_ram_ptr(&VAR_0->rom); memset(VAR_10, 0xff, VAR_9.st_size); if (!fread(VAR_10, 1, VAR_9.st_size, fp)) { error_report("pci-assign: Cannot read from host %s", VAR_8); 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"); goto close_rom; } pci_register_bar(VAR_0, PCI_ROM_SLOT, 0, &VAR_0->rom); VAR_0->has_rom = true; *VAR_2 = VAR_9.st_size; close_rom:
fseek(fp, 0, SEEK_SET); val = 0; if (!fwrite(&val, 1, 1, fp)) { DEBUG("%s\n", "Failed to disable pci-sysfs rom file"); } fclose(fp); return VAR_10; }