roms: remove option rom packing logic
Now that we load the option roms via fw_cfg, we can stop copying them to the 0xc000 -> 0xe000. The patch does just that. Also the rom loader gets simplified as all remaining users of the rom loader load the bits at a fixed address so the packing and aligning logic can go away. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
This commit is contained in:
		
							parent
							
								
									379526a40e
								
							
						
					
					
						commit
						632cf034b4
					
				
							
								
								
									
										103
									
								
								hw/loader.c
								
								
								
								
							
							
						
						
									
										103
									
								
								hw/loader.c
								
								
								
								
							| 
						 | 
				
			
			@ -527,13 +527,10 @@ struct Rom {
 | 
			
		|||
    char *path;
 | 
			
		||||
    size_t romsize;
 | 
			
		||||
    uint8_t *data;
 | 
			
		||||
    int align;
 | 
			
		||||
    int isrom;
 | 
			
		||||
    char *fw_dir;
 | 
			
		||||
    char *fw_file;
 | 
			
		||||
 | 
			
		||||
    target_phys_addr_t min;
 | 
			
		||||
    target_phys_addr_t max;
 | 
			
		||||
    target_phys_addr_t addr;
 | 
			
		||||
    QTAILQ_ENTRY(Rom) next;
 | 
			
		||||
};
 | 
			
		||||
| 
						 | 
				
			
			@ -551,7 +548,7 @@ static void rom_insert(Rom *rom)
 | 
			
		|||
 | 
			
		||||
    /* list is ordered by load address */
 | 
			
		||||
    QTAILQ_FOREACH(item, &roms, next) {
 | 
			
		||||
        if (rom->min >= item->min)
 | 
			
		||||
        if (rom->addr >= item->addr)
 | 
			
		||||
            continue;
 | 
			
		||||
        QTAILQ_INSERT_BEFORE(item, rom, next);
 | 
			
		||||
        return;
 | 
			
		||||
| 
						 | 
				
			
			@ -560,7 +557,7 @@ static void rom_insert(Rom *rom)
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
int rom_add_file(const char *file, const char *fw_dir, const char *fw_file,
 | 
			
		||||
                 target_phys_addr_t min, target_phys_addr_t max, int align)
 | 
			
		||||
                 target_phys_addr_t addr)
 | 
			
		||||
{
 | 
			
		||||
    Rom *rom;
 | 
			
		||||
    int rc, fd = -1;
 | 
			
		||||
| 
						 | 
				
			
			@ -581,9 +578,7 @@ int rom_add_file(const char *file, const char *fw_dir, const char *fw_file,
 | 
			
		|||
 | 
			
		||||
    rom->fw_dir  = fw_dir  ? qemu_strdup(fw_dir)  : NULL;
 | 
			
		||||
    rom->fw_file = fw_file ? qemu_strdup(fw_file) : NULL;
 | 
			
		||||
    rom->align   = align;
 | 
			
		||||
    rom->min     = min;
 | 
			
		||||
    rom->max     = max;
 | 
			
		||||
    rom->addr    = addr;
 | 
			
		||||
    rom->romsize = lseek(fd, 0, SEEK_END);
 | 
			
		||||
    rom->data    = qemu_mallocz(rom->romsize);
 | 
			
		||||
    lseek(fd, 0, SEEK_SET);
 | 
			
		||||
| 
						 | 
				
			
			@ -608,15 +603,13 @@ err:
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
int rom_add_blob(const char *name, const void *blob, size_t len,
 | 
			
		||||
                 target_phys_addr_t min, target_phys_addr_t max, int align)
 | 
			
		||||
                 target_phys_addr_t addr)
 | 
			
		||||
{
 | 
			
		||||
    Rom *rom;
 | 
			
		||||
 | 
			
		||||
    rom = qemu_mallocz(sizeof(*rom));
 | 
			
		||||
    rom->name    = qemu_strdup(name);
 | 
			
		||||
    rom->align   = align;
 | 
			
		||||
    rom->min     = min;
 | 
			
		||||
    rom->max     = max;
 | 
			
		||||
    rom->addr    = addr;
 | 
			
		||||
    rom->romsize = len;
 | 
			
		||||
    rom->data    = qemu_mallocz(rom->romsize);
 | 
			
		||||
    memcpy(rom->data, blob, len);
 | 
			
		||||
| 
						 | 
				
			
			@ -628,16 +621,14 @@ int rom_add_vga(const char *file)
 | 
			
		|||
{
 | 
			
		||||
    if (!rom_enable_driver_roms)
 | 
			
		||||
        return 0;
 | 
			
		||||
    return rom_add_file(file, "vgaroms", file,
 | 
			
		||||
                        PC_ROM_MIN_VGA, PC_ROM_MAX, PC_ROM_ALIGN);
 | 
			
		||||
    return rom_add_file(file, "vgaroms", file, 0);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int rom_add_option(const char *file)
 | 
			
		||||
{
 | 
			
		||||
    if (!rom_enable_driver_roms)
 | 
			
		||||
        return 0;
 | 
			
		||||
    return rom_add_file(file, "genroms", file,
 | 
			
		||||
                        PC_ROM_MIN_OPTION, PC_ROM_MAX, PC_ROM_ALIGN);
 | 
			
		||||
    return rom_add_file(file, "genroms", file, 0);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void rom_reset(void *unused)
 | 
			
		||||
| 
						 | 
				
			
			@ -645,6 +636,8 @@ static void rom_reset(void *unused)
 | 
			
		|||
    Rom *rom;
 | 
			
		||||
 | 
			
		||||
    QTAILQ_FOREACH(rom, &roms, next) {
 | 
			
		||||
        if (rom->addr == 0)
 | 
			
		||||
            continue;
 | 
			
		||||
        if (rom->data == NULL)
 | 
			
		||||
            continue;
 | 
			
		||||
        cpu_physical_memory_write_rom(rom->addr, rom->data, rom->romsize);
 | 
			
		||||
| 
						 | 
				
			
			@ -663,32 +656,16 @@ int rom_load_all(void)
 | 
			
		|||
    Rom *rom;
 | 
			
		||||
 | 
			
		||||
    QTAILQ_FOREACH(rom, &roms, next) {
 | 
			
		||||
        if (addr < rom->min)
 | 
			
		||||
            addr = rom->min;
 | 
			
		||||
        if (rom->max) {
 | 
			
		||||
            /* load address range */
 | 
			
		||||
            if (rom->align) {
 | 
			
		||||
                addr += (rom->align-1);
 | 
			
		||||
                addr &= ~(rom->align-1);
 | 
			
		||||
            }
 | 
			
		||||
            if (addr + rom->romsize > rom->max) {
 | 
			
		||||
                fprintf(stderr, "rom: out of memory (rom %s, "
 | 
			
		||||
                        "addr 0x" TARGET_FMT_plx
 | 
			
		||||
                        ", size 0x%zx, max 0x" TARGET_FMT_plx ")\n",
 | 
			
		||||
                        rom->name, addr, rom->romsize, rom->max);
 | 
			
		||||
                continue;
 | 
			
		||||
            }
 | 
			
		||||
        } else {
 | 
			
		||||
            /* fixed address requested */
 | 
			
		||||
            if (addr != rom->min) {
 | 
			
		||||
                fprintf(stderr, "rom: requested regions overlap "
 | 
			
		||||
                        "(rom %s. free=0x" TARGET_FMT_plx
 | 
			
		||||
                        ", addr=0x" TARGET_FMT_plx ")\n",
 | 
			
		||||
                        rom->name, addr, rom->min);
 | 
			
		||||
                return -1;
 | 
			
		||||
            }
 | 
			
		||||
        if (rom->addr == 0)
 | 
			
		||||
            continue;
 | 
			
		||||
        if (addr > rom->addr) {
 | 
			
		||||
            fprintf(stderr, "rom: requested regions overlap "
 | 
			
		||||
                    "(rom %s. free=0x" TARGET_FMT_plx
 | 
			
		||||
                    ", addr=0x" TARGET_FMT_plx ")\n",
 | 
			
		||||
                    rom->name, addr, rom->addr);
 | 
			
		||||
            return -1;
 | 
			
		||||
        }
 | 
			
		||||
        rom->addr = addr;
 | 
			
		||||
        addr  = rom->addr;
 | 
			
		||||
        addr += rom->romsize;
 | 
			
		||||
        memtype = cpu_get_physical_page_desc(rom->addr) & (3 << IO_MEM_SHIFT);
 | 
			
		||||
        if (memtype == IO_MEM_ROM)
 | 
			
		||||
| 
						 | 
				
			
			@ -716,11 +693,11 @@ static Rom *find_rom(target_phys_addr_t addr)
 | 
			
		|||
    Rom *rom;
 | 
			
		||||
 | 
			
		||||
    QTAILQ_FOREACH(rom, &roms, next) {
 | 
			
		||||
        if (rom->max)
 | 
			
		||||
        if (rom->addr == 0)
 | 
			
		||||
            continue;
 | 
			
		||||
        if (rom->min > addr)
 | 
			
		||||
        if (rom->addr > addr)
 | 
			
		||||
            continue;
 | 
			
		||||
        if (rom->min + rom->romsize < addr)
 | 
			
		||||
        if (rom->addr + rom->romsize < addr)
 | 
			
		||||
            continue;
 | 
			
		||||
        return rom;
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			@ -735,23 +712,25 @@ int rom_copy(uint8_t *dest, target_phys_addr_t addr, size_t size)
 | 
			
		|||
    Rom *rom;
 | 
			
		||||
 | 
			
		||||
    QTAILQ_FOREACH(rom, &roms, next) {
 | 
			
		||||
        if (rom->max)
 | 
			
		||||
        if (rom->addr == 0)
 | 
			
		||||
            continue;
 | 
			
		||||
        if (rom->min + rom->romsize < addr)
 | 
			
		||||
        if (rom->addr > addr)
 | 
			
		||||
            continue;
 | 
			
		||||
        if (rom->min > end)
 | 
			
		||||
        if (rom->addr + rom->romsize < addr)
 | 
			
		||||
            continue;
 | 
			
		||||
        if (rom->addr > end)
 | 
			
		||||
            break;
 | 
			
		||||
        if (!rom->data)
 | 
			
		||||
            continue;
 | 
			
		||||
 | 
			
		||||
        d = dest + (rom->min - addr);
 | 
			
		||||
        d = dest + (rom->addr - addr);
 | 
			
		||||
        s = rom->data;
 | 
			
		||||
        l = rom->romsize;
 | 
			
		||||
 | 
			
		||||
        if (rom->min < addr) {
 | 
			
		||||
        if (rom->addr < addr) {
 | 
			
		||||
            d = dest;
 | 
			
		||||
            s += (addr - rom->min);
 | 
			
		||||
            l -= (addr - rom->min);
 | 
			
		||||
            s += (addr - rom->addr);
 | 
			
		||||
            l -= (addr - rom->addr);
 | 
			
		||||
        }
 | 
			
		||||
        if ((d + l) > (dest + size)) {
 | 
			
		||||
            l = dest - d;
 | 
			
		||||
| 
						 | 
				
			
			@ -770,7 +749,7 @@ void *rom_ptr(target_phys_addr_t addr)
 | 
			
		|||
    rom = find_rom(addr);
 | 
			
		||||
    if (!rom || !rom->data)
 | 
			
		||||
        return NULL;
 | 
			
		||||
    return rom->data + (addr - rom->min);
 | 
			
		||||
    return rom->data + (addr - rom->addr);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void do_info_roms(Monitor *mon)
 | 
			
		||||
| 
						 | 
				
			
			@ -778,10 +757,20 @@ void do_info_roms(Monitor *mon)
 | 
			
		|||
    Rom *rom;
 | 
			
		||||
 | 
			
		||||
    QTAILQ_FOREACH(rom, &roms, next) {
 | 
			
		||||
        monitor_printf(mon, "addr=" TARGET_FMT_plx
 | 
			
		||||
                       " size=0x%06zx mem=%s name=\"%s\" \n",
 | 
			
		||||
                       rom->addr, rom->romsize,
 | 
			
		||||
                       rom->isrom ? "rom" : "ram",
 | 
			
		||||
                       rom->name);
 | 
			
		||||
        if (rom->addr) {
 | 
			
		||||
            monitor_printf(mon, "addr=" TARGET_FMT_plx
 | 
			
		||||
                           " size=0x%06zx mem=%s name=\"%s\" \n",
 | 
			
		||||
                           rom->addr, rom->romsize,
 | 
			
		||||
                           rom->isrom ? "rom" : "ram",
 | 
			
		||||
                           rom->name);
 | 
			
		||||
        } else {
 | 
			
		||||
            monitor_printf(mon, "fw=%s%s%s"
 | 
			
		||||
                           " size=0x%06zx name=\"%s\" \n",
 | 
			
		||||
                           rom->fw_dir ? rom->fw_dir : "",
 | 
			
		||||
                           rom->fw_dir ? "/" : "",
 | 
			
		||||
                           rom->fw_file,
 | 
			
		||||
                           rom->romsize,
 | 
			
		||||
                           rom->name);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -20,9 +20,9 @@ void pstrcpy_targphys(const char *name,
 | 
			
		|||
                      const char *source);
 | 
			
		||||
 | 
			
		||||
int rom_add_file(const char *file, const char *fw_dir, const char *fw_file,
 | 
			
		||||
                 target_phys_addr_t min, target_phys_addr_t max, int align);
 | 
			
		||||
                 target_phys_addr_t addr);
 | 
			
		||||
int rom_add_blob(const char *name, const void *blob, size_t len,
 | 
			
		||||
                 target_phys_addr_t min, target_phys_addr_t max, int align);
 | 
			
		||||
                 target_phys_addr_t addr);
 | 
			
		||||
int rom_load_all(void);
 | 
			
		||||
int rom_load_fw(void *fw_cfg);
 | 
			
		||||
int rom_copy(uint8_t *dest, target_phys_addr_t addr, size_t size);
 | 
			
		||||
| 
						 | 
				
			
			@ -30,9 +30,9 @@ void *rom_ptr(target_phys_addr_t addr);
 | 
			
		|||
void do_info_roms(Monitor *mon);
 | 
			
		||||
 | 
			
		||||
#define rom_add_file_fixed(_f, _a)              \
 | 
			
		||||
    rom_add_file(_f, NULL, NULL, _a, 0, 0)
 | 
			
		||||
    rom_add_file(_f, NULL, NULL, _a)
 | 
			
		||||
#define rom_add_blob_fixed(_f, _b, _l, _a)      \
 | 
			
		||||
    rom_add_blob(_f, _b, _l, _a, 0, 0)
 | 
			
		||||
    rom_add_blob(_f, _b, _l, _a)
 | 
			
		||||
 | 
			
		||||
#define PC_ROM_MIN_VGA     0xc0000
 | 
			
		||||
#define PC_ROM_MIN_OPTION  0xc8000
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue