PC system flash support
v9 cover PC system flash support
Enable flash emulation in a PC system using pflash_cfi01.
v9:
* Add pc-1.1
* pc-1.0 uses previous rom firmware init code path
v8:
* Cleanup two chunks of debug code (printf messages)
* Fix comment in pc.h (pcflash.c => pc_sysfw.c)
v7:
* Do not add system firmware to qemu roms
* If kvm is enabled, copy pflash drive contents into a read-only ram region, since kvm cannot currently execute code from a pflash device.
* Rename pcflash.c to pc_sysfw.c
v6:
* Rebase for memory API
* pflash_cfi01: Set error in status register when a write to erase is attempted in read-only mode.
* Add system firmware to qemu roms
v5:
* Enable pflash read-only mode
* Enable -drive with if=pflash to define system firmware image
v4:
* Rebase
v3:
* Fix code style issues
* Add additional comments
v2:
* Convert debug printf to DPRINTF
Jordan Justen (3):
pc: Add pc-1.1 machine type
pflash: Support read-only mode
pc: Support system flash memory with pflash
Makefile.target | 1 + blockdev.c | 3 +- default-configs/i386-softmmu.mak | 1 + default-configs/x86_64-softmmu.mak | 1 + hw/boards.h | 1 + hw/pc.c | 58 +------- hw/pc.h | 7 +- hw/pc_piix.c | 40 +++++- hw/pc_sysfw.c | 255 ++++++++++++++++++++++++++++++++++++ hw/pflash_cfi01.c | 44 ++++-- hw/pflash_cfi02.c | 83 +++++++------ vl.c | 2 +- 12 files changed, 382 insertions(+), 114 deletions(-) create mode 100644 hw/pc_sysfw.c
PATCH v9 1/3 pc: Add pc-1.1 machine type
This machine type adds a new system_firmware_enabled parameter which is passed into pc_memory_init.
This will be used by the system firmware support which enables a flash memory to be used with qemu.
--- hw/pc.c | 3 ++- hw/pc.h | 3 ++- hw/pc_piix.c | 40 ++++++++++++++++++++++++++++++++-------- 3 files changed, 36 insertions(+), 10 deletions(-)
hw/pc.c +2 -1
@@ -971,7 +971,8 @@ void pc_memory_init(MemoryRegion *system_memory,ram_addr_t below_4g_mem_size, ram_addr_t above_4g_mem_size, MemoryRegion *rom_memory, - MemoryRegion **ram_memory) + MemoryRegion **ram_memory, + int system_firmware_enabled) { char *filename;int ret, linux_boot, i;
hw/pc.h +2 -1
@@ -138,7 +138,8 @@ void pc_memory_init(MemoryRegion *system_memory,ram_addr_t below_4g_mem_size, ram_addr_t above_4g_mem_size, MemoryRegion *rom_memory, - MemoryRegion **ram_memory); + MemoryRegion **ram_memory, + int system_firmware_enabled);qemu_irq *pc_allocate_cpu_irq (void );void pc_vga_init (PCIBus *pci_bus); void pc_basic_device_init(qemu_irq *gsi,
hw/pc_piix.c +32 -8
@@ -79,7 +79,8 @@ static void pc_init1(MemoryRegion *system_memory,const char *initrd_filename, const char *cpu_model, int pci_enabled, - int kvmclock_enabled) + int kvmclock_enabled, + int system_firmware_enabled) { int i;ram_addr_t below_4g_mem_size, above_4g_mem_size;
@@ -128,7 +129,8 @@ static void pc_init1(MemoryRegion *system_memory,pc_memory_init (system_memory, kernel_filename, kernel_cmdline, initrd_filename, below_4g_mem_size, above_4g_mem_size, - pci_enabled ? rom_memory : system_memory, &ram_memory); + pci_enabled ? rom_memory : system_memory, &ram_memory, + system_firmware_enabled); } gsi_state =g_malloc0 (sizeof (*gsi_state));
@@ -246,7 +248,21 @@ static void pc_init_pci(ram_addr_t ram_size,get_system_io (), ram_size, boot_device, kernel_filename, kernel_cmdline, - initrd_filename, cpu_model, 1, 1); + initrd_filename, cpu_model, 1, 1, 1); +} + +static void pc_init_pci_system_rom_only (ram_addr_t ram_size, +const char *boot_device, +const char *kernel_filename, +const char *kernel_cmdline, +const char *initrd_filename, +const char *cpu_model) +{ +pc_init1 (get_system_memory (), +get_system_io (), + ram_size, boot_device, + kernel_filename, kernel_cmdline, + initrd_filename, cpu_model,1 ,1 ,0 ); } static void pc_init_pci_no_kvmclock(ram_addr_t ram_size,
@@ -260,7 +276,7 @@ static void pc_init_pci_no_kvmclock(ram_addr_t ram_size,get_system_io (), ram_size, boot_device, kernel_filename, kernel_cmdline, - initrd_filename, cpu_model, 1, 0); + initrd_filename, cpu_model, 1, 0, 0); } static void pc_init_isa(ram_addr_t ram_size,
@@ -276,7 +292,7 @@ static void pc_init_isa(ram_addr_t ram_size,get_system_io (), ram_size, boot_device, kernel_filename, kernel_cmdline, - initrd_filename, cpu_model, 0, 1); + initrd_filename, cpu_model, 0, 1, 0); }#ifdef CONFIG_XEN
@@ -297,8 +313,8 @@ static void pc_xen_hvm_init(ram_addr_t ram_size, }#endif -static QEMUMachine pc_machine_v1_0 = { - .name ="pc-1.0" , +static QEMUMachine pc_machine_v1_1 = { + .name ="pc-1.1" , .alias ="pc" , .desc ="Standard PC" , .init = pc_init_pci,
@@ -306,10 +322,17 @@ static QEMUMachine pc_machine_v1_0 = { .is_default = 1, }; +static QEMUMachine pc_machine_v1_0 = { + .name ="pc-1.0" , + .desc ="Standard PC" , + .init = pc_init_pci_system_rom_only, + .max_cpus =255 , +}; +static QEMUMachine pc_machine_v0_14 = { .name ="pc-0.14" , .desc ="Standard PC" , - .init = pc_init_pci, + .init = pc_init_pci_system_rom_only, .max_cpus =255 , .compat_props = (GlobalProperty []) { {
@@ -556,6 +579,7 @@ static QEMUMachine xenfv_machine = {static void pc_machine_init (void ) { +qemu_register_machine (&pc_machine_v1_1);qemu_register_machine (&pc_machine_v1_0);qemu_register_machine (&pc_machine_v0_14);qemu_register_machine (&pc_machine_v0_13);
Signature · 1 line
1.7.1
PATCH v9 2/3 pflash: Support read-only mode
In reply to Jordan JustenWhen read-only mode is enabled, no changes will be made to the flash image in memory, and no bdrv_write calls will be made.
For pflash_cfi01 (Intel), if the flash is in read-only mode then the status register will signal block erase error or program error when these operations are attempted.
For pflash_cfi02 (AMD), if the flash is in read-only mode then the pflash will silently ignore all write/erase commands.
--- blockdev.c | 3 +- hw/pflash_cfi01.c | 44 +++++++++++++++++++--------- hw/pflash_cfi02.c | 83 ++++++++++++++++++++++++++++------------------------ 3 files changed, 77 insertions(+), 53 deletions(-)
blockdev.c +2 -1
@@ -556,7 +556,8 @@ DriveInfo *drive_init(QemuOpts *opts, int default_to_scsi)/* CDROM is fine for any interface, don't check. */ ro =1 ; }else if (ro ==1 ) { -if (type !=IF_SCSI && type !=IF_VIRTIO && type !=IF_FLOPPY && type !=IF_NONE ) { +if (type !=IF_SCSI && type !=IF_VIRTIO && type !=IF_FLOPPY && + type !=IF_NONE && type !=IF_PFLASH ) {error_report ("readonly not supported by this bus type" ); goto err; }
hw/pflash_cfi01.c +30 -14
74 lines not on this page · raw message
hw/pflash_cfi02.c +45 -38
113 lines not on this page · raw message
Signature · 1 line
1.7.1
PATCH v9 3/3 pc: Support system flash memory with pflash
In reply to Jordan JustenIf a pflash image is found, then it is used for the system firmware image.
If a pflash image is not initially found, then a read-only pflash device is created using the -bios filename.
KVM cannot execute from a pflash region currently. Therefore, when KVM is enabled, a (read-only) ram memory region is created and filled with the contents of the pflash drive.
--- Makefile.target | 1 + default-configs/i386-softmmu.mak | 1 + default-configs/x86_64-softmmu.mak | 1 + hw/boards.h | 1 + hw/pc.c | 55 +------- hw/pc.h | 4 + hw/pc_sysfw.c | 255 ++++++++++++++++++++++++++++++++++++ vl.c | 2 +- 8 files changed, 269 insertions(+), 51 deletions(-) create mode 100644 hw/pc_sysfw.c
Makefile.target +1 -0
@@ -236,6 +236,7 @@ obj-i386-y += vmport.o obj-i386-y += device-hotplug.o pci-hotplug.o smbios.o wdt_ib700.o obj-i386-y += debugcon.o multiboot.o obj-i386-y += pc_piix.o +obj-i386-y += pc_sysfw.o obj-i386-$(CONFIG_KVM) += kvmclock.o obj-i386-$(CONFIG_SPICE) += qxl.o qxl-logger.o qxl-render.o
default-configs/i386-softmmu.mak +1 -0
@@ -22,3 +22,4 @@ CONFIG_SOUND=y CONFIG_HPET=y CONFIG_APPLESMC=y CONFIG_I8259=y +CONFIG_PFLASH_CFI01=y
default-configs/x86_64-softmmu.mak +1 -0
@@ -22,3 +22,4 @@ CONFIG_SOUND=y CONFIG_HPET=y CONFIG_APPLESMC=y CONFIG_I8259=y +CONFIG_PFLASH_CFI01=y
hw/boards.h +1 -0
@@ -33,6 +33,7 @@ typedef struct QEMUMachine { } QEMUMachine;int qemu_register_machine (QEMUMachine *m); +QEMUMachine *find_default_machine (void );extern QEMUMachine *current_machine;
hw/pc.c +5 -50
80 lines not on this page · raw message
hw/pc.h +4 -0
@@ -246,6 +246,10 @@ static inline bool isa_ne2000_init(int base, int irq, NICInfo *nd)return true; } +/* pc_sysfw.c */ +void pc_system_firmware_init (MemoryRegion *rom_memory, +int system_firmware_enabled); +/* e820 types */ #define E820_RAM 1#define E820_RESERVED 2
hw/pc_sysfw.c new file +255 -0
255 lines not on this page · raw message
vl.c +1 -1
@@ -1186,7 +1186,7 @@ static QEMUMachine *find_machine(const char *name)return NULL ; } -static QEMUMachine *find_default_machine (void ) +QEMUMachine *find_default_machine (void ) {QEMUMachine *m;
Signature · 1 line
1.7.1
Re: [Qemu-devel] [PATCH v9 3/3] pc: Support system flash memory with pflash
Quoted 320 lines · Jordan Justen
If a pflash image is found, then it is used for the system firmware image.
If a pflash image is not initially found, then a read-only pflash device is created using the -bios filename.
KVM cannot execute from a pflash region currently. Therefore, when KVM is enabled, a (read-only) ram memory region is created and filled with the contents of the pflash drive.
Signed-off-by Jordan Justen<[email protected]>Cc Anthony Liguori<[email protected]>--- Makefile.target | 1 + default-configs/i386-softmmu.mak | 1 + default-configs/x86_64-softmmu.mak | 1 + hw/boards.h | 1 + hw/pc.c | 55 +------- hw/pc.h | 4 + hw/pc_sysfw.c | 255 ++++++++++++++++++++++++++++++++++++ vl.c | 2 +- 8 files changed, 269 insertions(+), 51 deletions(-)create mode 100644
hw/pc_sysfw.cMakefile.target +1
-0@@ -236,6 +236,7 @@ obj-i386-y += vmport.o obj-i386-y += device-hotplug.o pci-hotplug.o smbios.o wdt_ib700.o obj-i386-y += debugcon.o multiboot.o obj-i386-y += pc_piix.o +obj-i386-y += pc_sysfw.o obj-i386-$(CONFIG_KVM) += kvmclock.o obj-i386-$(CONFIG_SPICE) += qxl.o qxl-logger.o qxl-render.odefault-configs/i386-softmmu.mak +1
-0@@ -22,3 +22,4 @@ CONFIG_SOUND=y CONFIG_HPET=y CONFIG_APPLESMC=y CONFIG_I8259=y +CONFIG_PFLASH_CFI01=ydefault-configs/x86_64-softmmu.mak +1
-0@@ -22,3 +22,4 @@ CONFIG_SOUND=y CONFIG_HPET=y CONFIG_APPLESMC=y CONFIG_I8259=y +CONFIG_PFLASH_CFI01=yhw/boards.h +1
-0@@ -33,6 +33,7 @@ typedef struct QEMUMachine { } QEMUMachine;int qemu_register_machine (QEMUMachine *m); +QEMUMachine *find_default_machine (void );extern QEMUMachine *current_machine;hw/pc.c +5
-50@@ -57,10 +57,6 @@#define DPRINTF (fmt, ...)#endif -#define BIOS_FILENAME "bios.bin" - -#define PC_MAX_BIOS_SIZE (4 * 1024 * 1024) -/* Leave a chunk of memory at the top of RAM for the BIOS ACPI tables. */ #define ACPI_DATA_SIZE 0x10000#define BIOS_CFG_IOPORT 0x510@@ -974,11 +970,9 @@ void pc_memory_init(MemoryRegion *system_memory,MemoryRegion **ram_memory, int system_firmware_enabled) { - char *filename; -int ret, linux_boot, i; -MemoryRegion *ram, *bios, *isa_bios, *option_rom_mr; + int linux_boot, i; +MemoryRegion *ram, *option_rom_mr;MemoryRegion *ram_below_4g, *ram_above_4g; -int bios_size, isa_bios_size;void *fw_cfg; linux_boot = (kernel_filename !=NULL );@@ -1003,43 +997,9 @@ void pc_memory_init(MemoryRegion *system_memory, ram_above_4g); } -/* BIOS load */ -if (bios_name ==NULL ) - bios_name =BIOS_FILENAME ; - filename =qemu_find_file (QEMU_FILE_TYPE_BIOS , bios_name); -if (filename) { - bios_size =get_image_size (filename); - }else { - bios_size =-1 ; - } -if (bios_size<=0 || - (bios_size %65536 ) !=0 ) { - goto bios_error; - } - bios =g_malloc (sizeof (*bios)); -memory_region_init_ram (bios,NULL ,"pc.bios" , bios_size); -memory_region_set_readonly (bios, true); - ret =rom_add_file_fixed (bios_name, (uint32_t )(-bios_size),-1 ); -if (ret !=0 ) { - bios_error: -fprintf (stderr,"qemu: could not load PC BIOS '%s'\n" , bios_name); -exit (1 ); - } -if (filename) { -g_free (filename); - } -/* map the last 128KB of the BIOS in ISA space */ - isa_bios_size = bios_size; -if (isa_bios_size> (128 *1024 )) - isa_bios_size =128 *1024 ; - isa_bios =g_malloc (sizeof (*isa_bios)); -memory_region_init_alias (isa_bios,"isa-bios" , bios, - bios_size - isa_bios_size, isa_bios_size); -memory_region_add_subregion_overlap (rom_memory, -0x100000 - isa_bios_size, - isa_bios, -1 ); -memory_region_set_readonly (isa_bios, true); + +/* Initialize ROM or flash ranges for PC firmware */ +pc_system_firmware_init (rom_memory, system_firmware_enabled); option_rom_mr =g_malloc (sizeof (*option_rom_mr));memory_region_init_ram (option_rom_mr,NULL ,"pc.rom" ,PC_ROM_SIZE );@@ -1048,11 +1008,6 @@ void pc_memory_init(MemoryRegion *system_memory, option_rom_mr, 1); -/* map all the bios at the top of memory */ -memory_region_add_subregion (rom_memory, - (uint32_t )(-bios_size), - bios); - fw_cfg =bochs_bios_init ();rom_set_fw (fw_cfg);hw/pc.h +4
-0@@ -246,6 +246,10 @@ static inline bool isa_ne2000_init(int base, int irq, NICInfo *nd)return true; } +/* pc_sysfw.c */ +void pc_system_firmware_init (MemoryRegion *rom_memory, +int system_firmware_enabled); +/* e820 types */ #define E820_RAM 1#define E820_RESERVED 2hw/pc_sysfw.c new file +144
-0@@ -0,0 +1,255 @@ +/* +* QEMU PC System Firmware +* +* Copyright (c) 2003-2004 Fabrice Bellard +* Copyright (c) 2011 Intel Corporation +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +* THE SOFTWARE. +*/ + +#include "hw.h" +#include "pc.h" +#include "hw/boards.h" +#include "loader.h" +#include "sysemu.h" +#include "flash.h" +#include "kvm.h" + +#define BIOS_FILENAME "bios.bin" + +static void pc_isa_bios_init (MemoryRegion *rom_memory, +MemoryRegion *flash_mem, +int ram_size) +{ +int isa_bios_size; +MemoryRegion *isa_bios; +uint64_t flash_size; +void *flash_ptr, *isa_bios_ptr; + + flash_size =memory_region_size (flash_mem); + +/* map the last 128KB of the BIOS in ISA space */ + isa_bios_size = flash_size; +if (isa_bios_size> (128 *1024 )) { + isa_bios_size =128 *1024 ; + } + isa_bios =g_malloc (sizeof (*isa_bios)); +memory_region_init_ram (isa_bios,NULL ,"isa-bios" , isa_bios_size); +memory_region_add_subregion_overlap (rom_memory, +0x100000 - isa_bios_size, + isa_bios, +1 ); + +/* copy ISA rom image from top of flash memory */ + flash_ptr =memory_region_get_ram_ptr (flash_mem); + isa_bios_ptr =memory_region_get_ram_ptr (isa_bios); +memcpy (isa_bios_ptr, + ((uint8_t *)flash_ptr) + (flash_size - isa_bios_size), + isa_bios_size); + +memory_region_set_readonly (isa_bios, true); +} + +static void pc_fw_add_pflash_drv (void ) +{ +QemuOpts *opts; +QEMUMachine *machine; +char *filename; + +if (bios_name ==NULL ) { + bios_name =BIOS_FILENAME ; + } + filename =qemu_find_file (QEMU_FILE_TYPE_BIOS , bios_name); + + opts =drive_add (IF_PFLASH ,-1 , filename,"readonly=on" ); +if (opts ==NULL ) { +return ; + } + + machine =find_default_machine (); +if (machine ==NULL ) { +return ; + } + +drive_init (opts, machine->use_scsi); +} + +static void pc_system_flash_init (MemoryRegion *rom_memory, +DriveInfo *pflash_drv) +{ +BlockDriverState *bdrv; +int64_t size; +target_phys_addr_t phys_addr; +int sector_bits, sector_size; +pflash_t *system_flash; +MemoryRegion *flash_mem; + + bdrv = pflash_drv->bdrv; + size =bdrv_getlength (pflash_drv->bdrv); + sector_bits =12 ; + sector_size =1 << sector_bits; + +if ((size % sector_size) !=0 ) { +fprintf (stderr, +"qemu: PC system firmware (pflash) must be a multiple of 0x%x\n" , + sector_size); +exit (1 ); + } + + phys_addr =0x100000000ULL - size; + system_flash =pflash_cfi01_register (phys_addr,NULL ,"system.flash" , size, + bdrv, sector_size, size>> sector_bits, +1 ,0x0000 ,0x0000 ,0x0000 ,0x0000 ,0 ); + flash_mem =pflash_cfi01_get_memory (system_flash); + +pc_isa_bios_init (rom_memory, flash_mem, size); +} + +static void pc_system_rom_init (MemoryRegion *rom_memory, +DriveInfo *pflash_drv) +{ +BlockDriverState *bdrv; +int64_t size; +target_phys_addr_t phys_addr; +int sector_bits, sector_size; +MemoryRegion *sys_rom; +void *buffer; +int ret; + + bdrv = pflash_drv->bdrv; + size =bdrv_getlength (pflash_drv->bdrv); + sector_bits =9 ; + sector_size =1 << sector_bits; + +if ((size % sector_size) !=0 ) { +fprintf (stderr, +"qemu: PC system rom (pflash) must be a multiple of 0x%x\n" , + sector_size); +exit (1 );
hw/pc_sysfw.c line 154
Quoted 10 lines
hw/pc_sysfw.c new file +10
-0+ } + + phys_addr =0x100000000ULL - size; + sys_rom =g_malloc (sizeof (*sys_rom)); +memory_region_init_ram (sys_rom,NULL ,"system.rom" , size); + buffer =memory_region_get_ram_ptr (sys_rom); +memory_region_add_subregion (rom_memory, phys_addr, sys_rom); + +/* read the rom content */ + ret =bdrv_read (bdrv,0 , buffer, size>> sector_bits);
I think we're trying to get rid of synchronous block I/O in machine initialization for a number of reasons.
Kevin/Stefan, care to comment? Will this be problematic in the future?
Regards,
Anthony Liguori
Re: [Qemu-devel] [PATCH v9 3/3] pc: Support system flash memory with pflash
Quoted 359 lines · Anthony Liguori
Quoted 344 lines · Jordan Justen
If a pflash image is found, then it is used for the system firmware image.
If a pflash image is not initially found, then a read-only pflash device is created using the -bios filename.
KVM cannot execute from a pflash region currently. Therefore, when KVM is enabled, a (read-only) ram memory region is created and filled with the contents of the pflash drive.
Signed-off-by Jordan Justen<[email protected]>Cc Anthony Liguori<[email protected]>---
Makefile.target | 1 + default-configs/i386-softmmu.mak | 1 + default-configs/x86_64-softmmu.mak | 1 +hw/boards.h| 1 +hw/pc.c| 55 +-------hw/pc.h| 4 +hw/pc_sysfw.c| 255
++++++++++++++++++++++++++++++++++++
vl.c | 2 +-8 files changed, 269 insertions(+), 51 deletions(-)create mode 100644
hw/pc_sysfw.cMakefile.target +0
-0@@ -236,6 +236,7 @@ obj-i386-y += vmport.oobj-i386-y += device-hotplug.o pci-hotplug.o smbios.o wdt_ib700.o obj-i386-y += debugcon.o multiboot.o
obj-i386-y += pc_piix.o
+obj-i386-y += pc_sysfw.o
obj-i386-$(CONFIG_KVM) += kvmclock.o obj-i386-$(CONFIG_SPICE) += qxl.o qxl-logger.o qxl-render.odefault-configs/i386-softmmu.mak +0
-0@@ -22,3 +22,4 @@ CONFIG_SOUND=yCONFIG_HPET=y
CONFIG_APPLESMC=y
CONFIG_I8259=ydefault-configs/i386-softmmu.mak +1
-0+CONFIG_PFLASH_CFI01=ydefault-configs/x86_64-softmmu.mak +0
-0@@ -22,3 +22,4 @@ CONFIG_SOUND=yCONFIG_HPET=y
CONFIG_APPLESMC=y
CONFIG_I8259=ydefault-configs/x86_64-softmmu.mak +1
-0+CONFIG_PFLASH_CFI01=yhw/boards.h +1
-0@@ -33,6 +33,7 @@ typedef struct QEMUMachine { } QEMUMachine; int qemu_register_machine(QEMUMachine *m); +QEMUMachine *find_default_machine (void ); extern QEMUMachine *current_machine;hw/pc.c +0
-4@@ -57,10 +57,6 @@ #define DPRINTF(fmt, ...) #endif -#define BIOS_FILENAME "bios.bin" - -#define PC_MAX_BIOS_SIZE (4 * 1024 * 1024) - /* Leave a chunk of memory at the top of RAM for the BIOS ACPI tables. */ #define ACPI_DATA_SIZE 0x10000#define
BIOS_CFG_IOPORT0x510hw/pc.c +5
-41@@ -974,11 +970,9 @@ void pc_memory_init(MemoryRegion *system_memory, MemoryRegion **ram_memory, int system_firmware_enabled) { - char *filename; - int ret, linux_boot, i; - MemoryRegion *ram, *bios, *isa_bios, *option_rom_mr; + int linux_boot, i; + MemoryRegion *ram, *option_rom_mr; MemoryRegion *ram_below_4g, *ram_above_4g; - int bios_size, isa_bios_size; void *fw_cfg; linux_boot = (kernel_filename != NULL);@@ -1003,43 +997,9 @@ void pc_memory_init(MemoryRegion *system_memory, ram_above_4g); } - /* BIOS load */ - if (bios_name == NULL) - bios_name = BIOS_FILENAME; - filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name); - if (filename) { - bios_size = get_image_size(filename); - } else { - bios_size = -1; - } - if (bios_size<= 0 || - (bios_size % 65536) != 0) { - goto bios_error; - } - bios = g_malloc(sizeof(*bios)); - memory_region_init_ram(bios, NULL, "pc.bios", bios_size); - memory_region_set_readonly(bios, true); - ret = rom_add_file_fixed(bios_name, (uint32_t)(-bios_size), -1); - if (ret != 0) { - bios_error: - fprintf(stderr, "qemu: could not load PC BIOS '%s'\n", bios_name); - exit(1); - } - if (filename) { - g_free(filename); - } - /* map the last 128KB of the BIOS in ISA space */ - isa_bios_size = bios_size; - if (isa_bios_size> (128 * 1024)) - isa_bios_size = 128 * 1024; - isa_bios = g_malloc(sizeof(*isa_bios)); - memory_region_init_alias(isa_bios, "isa-bios", bios, - bios_size - isa_bios_size, isa_bios_size); - memory_region_add_subregion_overlap(rom_memory, - 0x100000 - isa_bios_size, - isa_bios, - 1); - memory_region_set_readonly(isa_bios, true); + + /* Initialize ROM or flash ranges for PC firmware */ + pc_system_firmware_init(rom_memory, system_firmware_enabled); option_rom_mr = g_malloc(sizeof(*option_rom_mr));memory_region_init_ram(option_rom_mr, NULL, "pc.rom",
PC_ROM_SIZE);hw/pc.c +0
-5@@ -1048,11 +1008,6 @@ void pc_memory_init(MemoryRegion *system_memory, option_rom_mr, 1); - /* map all the bios at the top of memory */ - memory_region_add_subregion(rom_memory, - (uint32_t)(-bios_size), - bios); - fw_cfg = bochs_bios_init(); rom_set_fw(fw_cfg);hw/pc.h +4
-0@@ -246,6 +246,10 @@ static inline bool isa_ne2000_init(int base, int irq, NICInfo *nd) return true; } +/* pc_sysfw.c */ +void pc_system_firmware_init (MemoryRegion *rom_memory, + int system_firmware_enabled); + /* e820 types */ #define E820_RAM 1#define
E820_RESERVED2hw/pc_sysfw.c new file +7
-0@@ -0,0 +1,255 @@ +/* +* QEMU PC System Firmware +* +* Copyright (c) 2003-2004 Fabrice Bellard +* Copyright (c) 2011 Intel Corporation +* +* Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */hw/pc_sysfw.c new file +86
-0+ +#include "hw.h" +#include "pc.h" +#include "hw/boards.h" +#include "loader.h" +#include "sysemu.h" +#include "flash.h" +#include "kvm.h" + +#define BIOS_FILENAME "bios.bin" + +static void pc_isa_bios_init (MemoryRegion *rom_memory, + MemoryRegion *flash_mem, + int ram_size) +{ + int isa_bios_size; + MemoryRegion *isa_bios; + uint64_t flash_size; + void *flash_ptr, *isa_bios_ptr; + + flash_size = memory_region_size(flash_mem); + + /* map the last 128KB of the BIOS in ISA space */ + isa_bios_size = flash_size; + if (isa_bios_size> (128 * 1024)) { + isa_bios_size = 128 * 1024; + } + isa_bios = g_malloc(sizeof(*isa_bios)); + memory_region_init_ram(isa_bios, NULL, "isa-bios", isa_bios_size); + memory_region_add_subregion_overlap(rom_memory, + 0x100000 - isa_bios_size, + isa_bios, + 1); + + /* copy ISA rom image from top of flash memory */ + flash_ptr = memory_region_get_ram_ptr(flash_mem); + isa_bios_ptr = memory_region_get_ram_ptr(isa_bios); + memcpy(isa_bios_ptr, + ((uint8_t*)flash_ptr) + (flash_size - isa_bios_size), + isa_bios_size); + + memory_region_set_readonly(isa_bios, true); +} + +static void pc_fw_add_pflash_drv (void ) +{ + QemuOpts *opts; + QEMUMachine *machine; + char *filename; + + if (bios_name == NULL) { + bios_name = BIOS_FILENAME; + } + filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name); + + opts = drive_add(IF_PFLASH, -1, filename, "readonly=on"); + if (opts == NULL) { + return; + } + + machine = find_default_machine(); + if (machine == NULL) { + return; + } + + drive_init(opts, machine->use_scsi); +} + +static void pc_system_flash_init (MemoryRegion *rom_memory, + DriveInfo *pflash_drv) +{ + BlockDriverState *bdrv; + int64_t size; + target_phys_addr_t phys_addr; + int sector_bits, sector_size; + pflash_t *system_flash; + MemoryRegion *flash_mem; + + bdrv = pflash_drv->bdrv; + size = bdrv_getlength(pflash_drv->bdrv); + sector_bits = 12; + sector_size = 1<< sector_bits; + + if ((size % sector_size) != 0) { + fprintf(stderr, + "qemu: PC system firmware (pflash) must be a multiple of0x%x\n",
+ sector_size);
+ exit(1);
+ }
+
+ phys_addr =0x100000000ULL- size;
+ system_flash = pflash_cfi01_register(phys_addr, NULL, "system.flash", size,
+ bdrv,sector_size, size>>sector_bits,
+ 1,0x0000,0x0000,0x0000,0x0000, 0);
+ flash_mem =pflash_cfi01_get_memory(system_flash);hw/pc_sysfw.c new file +23
-0+ + pc_isa_bios_init(rom_memory, flash_mem, size); +} + +static void pc_system_rom_init (MemoryRegion *rom_memory, + DriveInfo *pflash_drv) +{ + BlockDriverState *bdrv; + int64_t size; + target_phys_addr_t phys_addr; + int sector_bits, sector_size; + MemoryRegion *sys_rom; + void *buffer; + int ret; + + bdrv = pflash_drv->bdrv; + size = bdrv_getlength(pflash_drv->bdrv); + sector_bits = 9; + sector_size = 1<< sector_bits; + + if ((size % sector_size) != 0) { + fprintf(stderr, + "qemu: PC system rom (pflash) must be a multiple of0x%x\n",
+ sector_size);
+ exit(1);
+ }hw/pc_sysfw.c
Quoted 9 lines
hw/pc_sysfw.c new file +9
-0+ + phys_addr = 0x100000000ULL - size; + sys_rom = g_malloc(sizeof(*sys_rom)); + memory_region_init_ram(sys_rom, NULL, "system.rom", size); + buffer = memory_region_get_ram_ptr(sys_rom); + memory_region_add_subregion(rom_memory, phys_addr, sys_rom); + + /* read the rom content */ + ret = bdrv_read(bdrv, 0, buffer, size>> sector_bits);I think we're trying to get rid of synchronous block I/O in machine initialization for a number of reasons.
Quoted 1 line
Kevin/Stefan, care to comment? Will this be problematic in the future?
I was hoping pc-1.1 with and without kvm could be as close as possible, but I guess I can make pc-1.1 with kvm behave the same as pc-1.0. Then I can delete pc_system_rom_init.
-Jordan
Re: [Qemu-devel] [PATCH v9 3/3] pc: Support system flash memory with pflash
Quoted 360 lines · Jordan Justen
Quoted 359 lines · Anthony Liguori
Quoted 343 lines · Jordan Justen
If a pflash image is found, then it is used for the system firmware image.
If a pflash image is not initially found, then a read-only pflash device is created using the -bios filename.
KVM cannot execute from a pflash region currently. Therefore, when KVM is enabled, a (read-only) ram memory region is created and filled with the contents of the pflash drive.
Signed-off-by Jordan Justen<[email protected]>Cc Anthony Liguori<[email protected]>--- Makefile.target | 1 + default-configs/i386-softmmu.mak | 1 + default-configs/x86_64-softmmu.mak | 1 + hw/boards.h | 1 + hw/pc.c | 55 +------- hw/pc.h | 4 + hw/pc_sysfw.c | 255 ++++++++++++++++++++++++++++++++++++ vl.c | 2 +- 8 files changed, 269 insertions(+), 51 deletions(-)create mode 100644
hw/pc_sysfw.cMakefile.target +1
-0@@ -236,6 +236,7 @@ obj-i386-y += vmport.o obj-i386-y += device-hotplug.o pci-hotplug.o smbios.o wdt_ib700.o obj-i386-y += debugcon.o multiboot.o obj-i386-y += pc_piix.o +obj-i386-y += pc_sysfw.o obj-i386-$(CONFIG_KVM) += kvmclock.o obj-i386-$(CONFIG_SPICE) += qxl.o qxl-logger.o qxl-render.odefault-configs/i386-softmmu.mak +1
-0@@ -22,3 +22,4 @@ CONFIG_SOUND=y CONFIG_HPET=y CONFIG_APPLESMC=y CONFIG_I8259=y +CONFIG_PFLASH_CFI01=ydefault-configs/x86_64-softmmu.mak +1
-0@@ -22,3 +22,4 @@ CONFIG_SOUND=y CONFIG_HPET=y CONFIG_APPLESMC=y CONFIG_I8259=y +CONFIG_PFLASH_CFI01=yhw/boards.h +1
-0@@ -33,6 +33,7 @@ typedef struct QEMUMachine { } QEMUMachine;int qemu_register_machine (QEMUMachine *m); +QEMUMachine *find_default_machine (void );extern QEMUMachine *current_machine;hw/pc.c +0
-4@@ -57,10 +57,6 @@#define DPRINTF (fmt, ...)#endif -#define BIOS_FILENAME "bios.bin" - -#define PC_MAX_BIOS_SIZE (4 * 1024 * 1024) -/* Leave a chunk of memory at the top of RAM for the BIOS ACPI tables. */ #define ACPI_DATA_SIZE 0x10000#define BIOS_CFG_IOPORT 0x510hw/pc.c +5
-41@@ -974,11 +970,9 @@ void pc_memory_init(MemoryRegion *system_memory,MemoryRegion **ram_memory, int system_firmware_enabled) { - char *filename; -int ret, linux_boot, i; -MemoryRegion *ram, *bios, *isa_bios, *option_rom_mr; + int linux_boot, i; +MemoryRegion *ram, *option_rom_mr;MemoryRegion *ram_below_4g, *ram_above_4g; -int bios_size, isa_bios_size;void *fw_cfg; linux_boot = (kernel_filename !=NULL );@@ -1003,43 +997,9 @@ void pc_memory_init(MemoryRegion *system_memory, ram_above_4g); } -/* BIOS load */ -if (bios_name ==NULL ) - bios_name =BIOS_FILENAME ; - filename =qemu_find_file (QEMU_FILE_TYPE_BIOS , bios_name); -if (filename) { - bios_size =get_image_size (filename); - }else { - bios_size =-1 ; - } -if (bios_size<=0 || - (bios_size %65536 ) !=0 ) { - goto bios_error; - } - bios =g_malloc (sizeof (*bios)); -memory_region_init_ram (bios,NULL ,"pc.bios" , bios_size); -memory_region_set_readonly (bios, true); - ret =rom_add_file_fixed (bios_name, (uint32_t )(-bios_size),-1 ); -if (ret !=0 ) { - bios_error: -fprintf (stderr,"qemu: could not load PC BIOS '%s'\n" , bios_name); -exit (1 ); - } -if (filename) { -g_free (filename); - } -/* map the last 128KB of the BIOS in ISA space */ - isa_bios_size = bios_size; -if (isa_bios_size> (128 *1024 )) - isa_bios_size =128 *1024 ; - isa_bios =g_malloc (sizeof (*isa_bios)); -memory_region_init_alias (isa_bios,"isa-bios" , bios, - bios_size - isa_bios_size, isa_bios_size); -memory_region_add_subregion_overlap (rom_memory, -0x100000 - isa_bios_size, - isa_bios, -1 ); -memory_region_set_readonly (isa_bios, true); + +/* Initialize ROM or flash ranges for PC firmware */ +pc_system_firmware_init (rom_memory, system_firmware_enabled); option_rom_mr =g_malloc (sizeof (*option_rom_mr));memory_region_init_ram(option_rom_mr, NULL, "pc.rom", PC_ROM_SIZE);hw/pc.c +0
-5@@ -1048,11 +1008,6 @@ void pc_memory_init(MemoryRegion *system_memory, option_rom_mr, 1); -/* map all the bios at the top of memory */ -memory_region_add_subregion (rom_memory, - (uint32_t )(-bios_size), - bios); - fw_cfg =bochs_bios_init ();rom_set_fw (fw_cfg);hw/pc.h +4
-0@@ -246,6 +246,10 @@ static inline bool isa_ne2000_init(int base, int irq, NICInfo *nd)return true; } +/* pc_sysfw.c */ +void pc_system_firmware_init (MemoryRegion *rom_memory, +int system_firmware_enabled); +/* e820 types */ #define E820_RAM 1#define E820_RESERVED 2hw/pc_sysfw.c new file +7
-0@@ -0,0 +1,255 @@ +/* +* QEMU PC System Firmware +* +* Copyright (c) 2003-2004 Fabrice Bellard +* Copyright (c) 2011 Intel Corporation +* +* Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */hw/pc_sysfw.c new file +86
-0+ +#include "hw.h" +#include "pc.h" +#include "hw/boards.h" +#include "loader.h" +#include "sysemu.h" +#include "flash.h" +#include "kvm.h" + +#define BIOS_FILENAME "bios.bin" + +static void pc_isa_bios_init (MemoryRegion *rom_memory, +MemoryRegion *flash_mem, +int ram_size) +{ +int isa_bios_size; +MemoryRegion *isa_bios; +uint64_t flash_size; +void *flash_ptr, *isa_bios_ptr; + + flash_size =memory_region_size (flash_mem); + +/* map the last 128KB of the BIOS in ISA space */ + isa_bios_size = flash_size; +if (isa_bios_size> (128 *1024 )) { + isa_bios_size =128 *1024 ; + } + isa_bios =g_malloc (sizeof (*isa_bios)); +memory_region_init_ram (isa_bios,NULL ,"isa-bios" , isa_bios_size); +memory_region_add_subregion_overlap (rom_memory, +0x100000 - isa_bios_size, + isa_bios, +1 ); + +/* copy ISA rom image from top of flash memory */ + flash_ptr =memory_region_get_ram_ptr (flash_mem); + isa_bios_ptr =memory_region_get_ram_ptr (isa_bios); +memcpy (isa_bios_ptr, + ((uint8_t *)flash_ptr) + (flash_size - isa_bios_size), + isa_bios_size); + +memory_region_set_readonly (isa_bios, true); +} + +static void pc_fw_add_pflash_drv (void ) +{ +QemuOpts *opts; +QEMUMachine *machine; +char *filename; + +if (bios_name ==NULL ) { + bios_name =BIOS_FILENAME ; + } + filename =qemu_find_file (QEMU_FILE_TYPE_BIOS , bios_name); + + opts =drive_add (IF_PFLASH ,-1 , filename,"readonly=on" ); +if (opts ==NULL ) { +return ; + } + + machine =find_default_machine (); +if (machine ==NULL ) { +return ; + } + +drive_init (opts, machine->use_scsi); +} + +static void pc_system_flash_init (MemoryRegion *rom_memory, +DriveInfo *pflash_drv) +{ +BlockDriverState *bdrv; +int64_t size; +target_phys_addr_t phys_addr; +int sector_bits, sector_size; +pflash_t *system_flash; +MemoryRegion *flash_mem; + + bdrv = pflash_drv->bdrv; + size =bdrv_getlength (pflash_drv->bdrv); + sector_bits =12 ; + sector_size =1 << sector_bits; + +if ((size % sector_size) !=0 ) { + fprintf(stderr, + "qemu: PC system firmware (pflash) must be a multiple of0x%x\n",
hw/pc_sysfw.c new file +6
-0+ sector_size); +exit (1 ); + } + + phys_addr =0x100000000ULL - size; + system_flash = pflash_cfi01_register(phys_addr, NULL, "system.flash",size,
hw/pc_sysfw.c new file +2
-0+ bdrv, sector_size, size>> sector_bits, + 1, 0x0000, 0x0000, 0x0000,
0x0000, 0);hw/pc_sysfw.c new file +24
-0+ flash_mem =pflash_cfi01_get_memory (system_flash); + +pc_isa_bios_init (rom_memory, flash_mem, size); +} + +static void pc_system_rom_init (MemoryRegion *rom_memory, +DriveInfo *pflash_drv) +{ +BlockDriverState *bdrv; +int64_t size; +target_phys_addr_t phys_addr; +int sector_bits, sector_size; +MemoryRegion *sys_rom; +void *buffer; +int ret; + + bdrv = pflash_drv->bdrv; + size =bdrv_getlength (pflash_drv->bdrv); + sector_bits =9 ; + sector_size =1 << sector_bits; + +if ((size % sector_size) !=0 ) { + fprintf(stderr, + "qemu: PC system rom (pflash) must be a multiple of0x%x\n",
hw/pc_sysfw.c new file +2
-0+ sector_size); +exit (1 );hw/pc_sysfw.c
Quoted 10 lines
hw/pc_sysfw.c new file +10
-0+ } + + phys_addr =0x100000000ULL - size; + sys_rom =g_malloc (sizeof (*sys_rom)); +memory_region_init_ram (sys_rom,NULL ,"system.rom" , size); + buffer =memory_region_get_ram_ptr (sys_rom); +memory_region_add_subregion (rom_memory, phys_addr, sys_rom); + +/* read the rom content */ + ret =bdrv_read (bdrv,0 , buffer, size>> sector_bits);I think we're trying to get rid of synchronous block I/O in machine initialization for a number of reasons.
Quoted 5 lines
Quoted 1 line
Kevin/Stefan, care to comment? Will this be problematic in the future?
I was hoping pc-1.1 with and without kvm could be as close as possible, but I guess I can make pc-1.1 with kvm behave the same as pc-1.0. Then I can delete
pc_system_rom_init.
I think your general approach is right, I'm just not sure what we're going to do short term about synchronous I/O in the machine init routines. It may just be a matter of structuring this in such a way that you can use an async interface.
Regards,
Anthony Liguori
Quoted 3 lines
-Jordan
Re: [Qemu-devel] [PATCH v9 3/3] pc: Support system flash memory with pflash
Am 19.12.2011 23:19, schrieb Anthony Liguori:
Quoted 363 lines · Jordan Justen
Quoted 362 lines · Anthony Liguori
Quoted 360 lines · Jordan Justen
Quoted 343 lines
If a pflash image is found, then it is used for the system firmware image.
If a pflash image is not initially found, then a read-only pflash device is created using the -bios filename.
KVM cannot execute from a pflash region currently. Therefore, when KVM is enabled, a (read-only) ram memory region is created and filled with the contents of the pflash drive.
Signed-off-by Jordan Justen<[email protected]>Cc Anthony Liguori<[email protected]>--- Makefile.target | 1 + default-configs/i386-softmmu.mak | 1 + default-configs/x86_64-softmmu.mak | 1 + hw/boards.h | 1 + hw/pc.c | 55 +------- hw/pc.h | 4 + hw/pc_sysfw.c | 255 ++++++++++++++++++++++++++++++++++++ vl.c | 2 +- 8 files changed, 269 insertions(+), 51 deletions(-)create mode 100644
hw/pc_sysfw.cMakefile.target +1
-0@@ -236,6 +236,7 @@ obj-i386-y += vmport.o obj-i386-y += device-hotplug.o pci-hotplug.o smbios.o wdt_ib700.o obj-i386-y += debugcon.o multiboot.o obj-i386-y += pc_piix.o +obj-i386-y += pc_sysfw.o obj-i386-$(CONFIG_KVM) += kvmclock.o obj-i386-$(CONFIG_SPICE) += qxl.o qxl-logger.o qxl-render.odefault-configs/i386-softmmu.mak +1
-0@@ -22,3 +22,4 @@ CONFIG_SOUND=y CONFIG_HPET=y CONFIG_APPLESMC=y CONFIG_I8259=y +CONFIG_PFLASH_CFI01=ydefault-configs/x86_64-softmmu.mak +1
-0@@ -22,3 +22,4 @@ CONFIG_SOUND=y CONFIG_HPET=y CONFIG_APPLESMC=y CONFIG_I8259=y +CONFIG_PFLASH_CFI01=yhw/boards.h +1
-0@@ -33,6 +33,7 @@ typedef struct QEMUMachine { } QEMUMachine;int qemu_register_machine (QEMUMachine *m); +QEMUMachine *find_default_machine (void );extern QEMUMachine *current_machine;hw/pc.c +0
-4@@ -57,10 +57,6 @@#define DPRINTF (fmt, ...)#endif -#define BIOS_FILENAME "bios.bin" - -#define PC_MAX_BIOS_SIZE (4 * 1024 * 1024) -/* Leave a chunk of memory at the top of RAM for the BIOS ACPI tables. */ #define ACPI_DATA_SIZE 0x10000#define BIOS_CFG_IOPORT 0x510hw/pc.c +5
-41@@ -974,11 +970,9 @@ void pc_memory_init(MemoryRegion *system_memory,MemoryRegion **ram_memory, int system_firmware_enabled) { - char *filename; -int ret, linux_boot, i; -MemoryRegion *ram, *bios, *isa_bios, *option_rom_mr; + int linux_boot, i; +MemoryRegion *ram, *option_rom_mr;MemoryRegion *ram_below_4g, *ram_above_4g; -int bios_size, isa_bios_size;void *fw_cfg; linux_boot = (kernel_filename !=NULL );@@ -1003,43 +997,9 @@ void pc_memory_init(MemoryRegion *system_memory, ram_above_4g); } -/* BIOS load */ -if (bios_name ==NULL ) - bios_name =BIOS_FILENAME ; - filename =qemu_find_file (QEMU_FILE_TYPE_BIOS , bios_name); -if (filename) { - bios_size =get_image_size (filename); - }else { - bios_size =-1 ; - } -if (bios_size<=0 || - (bios_size %65536 ) !=0 ) { - goto bios_error; - } - bios =g_malloc (sizeof (*bios)); -memory_region_init_ram (bios,NULL ,"pc.bios" , bios_size); -memory_region_set_readonly (bios, true); - ret =rom_add_file_fixed (bios_name, (uint32_t )(-bios_size),-1 ); -if (ret !=0 ) { - bios_error: -fprintf (stderr,"qemu: could not load PC BIOS '%s'\n" , bios_name); -exit (1 ); - } -if (filename) { -g_free (filename); - } -/* map the last 128KB of the BIOS in ISA space */ - isa_bios_size = bios_size; -if (isa_bios_size> (128 *1024 )) - isa_bios_size =128 *1024 ; - isa_bios =g_malloc (sizeof (*isa_bios)); -memory_region_init_alias (isa_bios,"isa-bios" , bios, - bios_size - isa_bios_size, isa_bios_size); -memory_region_add_subregion_overlap (rom_memory, -0x100000 - isa_bios_size, - isa_bios, -1 ); -memory_region_set_readonly (isa_bios, true); + +/* Initialize ROM or flash ranges for PC firmware */ +pc_system_firmware_init (rom_memory, system_firmware_enabled); option_rom_mr =g_malloc (sizeof (*option_rom_mr));memory_region_init_ram(option_rom_mr, NULL, "pc.rom", PC_ROM_SIZE);hw/pc.c +0
-5@@ -1048,11 +1008,6 @@ void pc_memory_init(MemoryRegion *system_memory, option_rom_mr, 1); -/* map all the bios at the top of memory */ -memory_region_add_subregion (rom_memory, - (uint32_t )(-bios_size), - bios); - fw_cfg =bochs_bios_init ();rom_set_fw (fw_cfg);hw/pc.h +4
-0@@ -246,6 +246,10 @@ static inline bool isa_ne2000_init(int base, int irq, NICInfo *nd)return true; } +/* pc_sysfw.c */ +void pc_system_firmware_init (MemoryRegion *rom_memory, +int system_firmware_enabled); +/* e820 types */ #define E820_RAM 1#define E820_RESERVED 2hw/pc_sysfw.c new file +7
-0@@ -0,0 +1,255 @@ +/* +* QEMU PC System Firmware +* +* Copyright (c) 2003-2004 Fabrice Bellard +* Copyright (c) 2011 Intel Corporation +* +* Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */hw/pc_sysfw.c new file +86
-0+ +#include "hw.h" +#include "pc.h" +#include "hw/boards.h" +#include "loader.h" +#include "sysemu.h" +#include "flash.h" +#include "kvm.h" + +#define BIOS_FILENAME "bios.bin" + +static void pc_isa_bios_init (MemoryRegion *rom_memory, +MemoryRegion *flash_mem, +int ram_size) +{ +int isa_bios_size; +MemoryRegion *isa_bios; +uint64_t flash_size; +void *flash_ptr, *isa_bios_ptr; + + flash_size =memory_region_size (flash_mem); + +/* map the last 128KB of the BIOS in ISA space */ + isa_bios_size = flash_size; +if (isa_bios_size> (128 *1024 )) { + isa_bios_size =128 *1024 ; + } + isa_bios =g_malloc (sizeof (*isa_bios)); +memory_region_init_ram (isa_bios,NULL ,"isa-bios" , isa_bios_size); +memory_region_add_subregion_overlap (rom_memory, +0x100000 - isa_bios_size, + isa_bios, +1 ); + +/* copy ISA rom image from top of flash memory */ + flash_ptr =memory_region_get_ram_ptr (flash_mem); + isa_bios_ptr =memory_region_get_ram_ptr (isa_bios); +memcpy (isa_bios_ptr, + ((uint8_t *)flash_ptr) + (flash_size - isa_bios_size), + isa_bios_size); + +memory_region_set_readonly (isa_bios, true); +} + +static void pc_fw_add_pflash_drv (void ) +{ +QemuOpts *opts; +QEMUMachine *machine; +char *filename; + +if (bios_name ==NULL ) { + bios_name =BIOS_FILENAME ; + } + filename =qemu_find_file (QEMU_FILE_TYPE_BIOS , bios_name); + + opts =drive_add (IF_PFLASH ,-1 , filename,"readonly=on" ); +if (opts ==NULL ) { +return ; + } + + machine =find_default_machine (); +if (machine ==NULL ) { +return ; + } + +drive_init (opts, machine->use_scsi); +} + +static void pc_system_flash_init (MemoryRegion *rom_memory, +DriveInfo *pflash_drv) +{ +BlockDriverState *bdrv; +int64_t size; +target_phys_addr_t phys_addr; +int sector_bits, sector_size; +pflash_t *system_flash; +MemoryRegion *flash_mem; + + bdrv = pflash_drv->bdrv; + size =bdrv_getlength (pflash_drv->bdrv); + sector_bits =12 ; + sector_size =1 << sector_bits; + +if ((size % sector_size) !=0 ) { + fprintf(stderr, + "qemu: PC system firmware (pflash) must be a multiple of0x%x\n",
hw/pc_sysfw.c new file +6
-0+ sector_size); +exit (1 ); + } + + phys_addr =0x100000000ULL - size; + system_flash = pflash_cfi01_register(phys_addr, NULL, "system.flash",size,
hw/pc_sysfw.c new file +2
-0+ bdrv, sector_size, size>> sector_bits, + 1, 0x0000, 0x0000, 0x0000,
0x0000, 0);hw/pc_sysfw.c new file +24
-0+ flash_mem =pflash_cfi01_get_memory (system_flash); + +pc_isa_bios_init (rom_memory, flash_mem, size); +} + +static void pc_system_rom_init (MemoryRegion *rom_memory, +DriveInfo *pflash_drv) +{ +BlockDriverState *bdrv; +int64_t size; +target_phys_addr_t phys_addr; +int sector_bits, sector_size; +MemoryRegion *sys_rom; +void *buffer; +int ret; + + bdrv = pflash_drv->bdrv; + size =bdrv_getlength (pflash_drv->bdrv); + sector_bits =9 ; + sector_size =1 << sector_bits; + +if ((size % sector_size) !=0 ) { + fprintf(stderr, + "qemu: PC system rom (pflash) must be a multiple of0x%x\n",
hw/pc_sysfw.c new file +2
-0+ sector_size); +exit (1 );hw/pc_sysfw.c
Quoted 10 lines
hw/pc_sysfw.c new file +10
-0+ } + + phys_addr =0x100000000ULL - size; + sys_rom =g_malloc (sizeof (*sys_rom)); +memory_region_init_ram (sys_rom,NULL ,"system.rom" , size); + buffer =memory_region_get_ram_ptr (sys_rom); +memory_region_add_subregion (rom_memory, phys_addr, sys_rom); + +/* read the rom content */ + ret =bdrv_read (bdrv,0 , buffer, size>> sector_bits);I think we're trying to get rid of synchronous block I/O in machine initialization for a number of reasons.
Kevin/Stefan, care to comment? Will this be problematic in the future?
Quoted 7 lines
Quoted 3 lines
I was hoping pc-1.1 with and without kvm could be as close as possible, but I guess I can make pc-1.1 with kvm behave the same as pc-1.0. Then I can delete
pc_system_rom_init.I think your general approach is right, I'm just not sure what we're going to do short term about synchronous I/O in the machine init routines. It may just be a matter of structuring this in such a way that you can use an async interface.
I don't think there is a problem with using the synchronous interface here. But I'm not sure if having any I/O in the machine init is a good idea with respect to migration. Didn't we already have to move some code there to a later stage to make sure that the destination doesn't use outdated data?
Kevin
Re: [Qemu-devel] [PATCH v9 3/3] pc: Support system flash memory with pflash
Quoted 51 lines · Kevin Wolf
Am 19.12.2011 23:19, schrieb Anthony Liguori:
Quoted 42 lines · Jordan Justen
Quoted 41 lines · Anthony Liguori
Quoted 39 lines · Jordan Justen
Quoted 23 lines
hw/pc_sysfw.c new file +19
-0+static void pc_system_rom_init (MemoryRegion *rom_memory, + DriveInfo *pflash_drv) +{ + BlockDriverState *bdrv; + int64_t size; + target_phys_addr_t phys_addr; + int sector_bits, sector_size; + MemoryRegion *sys_rom; + void *buffer; + int ret; + + bdrv = pflash_drv->bdrv; + size = bdrv_getlength(pflash_drv->bdrv); + sector_bits = 9; + sector_size = 1<< sector_bits; + + if ((size % sector_size) != 0) { + fprintf(stderr, + "qemu: PC system rom (pflash) must be a multiple of0x%x\n",
+ sector_size);
+ exit(1);
+ }hw/pc_sysfw.c
Quoted 9 lines
hw/pc_sysfw.c new file +9
-0+ + phys_addr = 0x100000000ULL - size; + sys_rom = g_malloc(sizeof(*sys_rom)); + memory_region_init_ram(sys_rom, NULL, "system.rom", size); + buffer = memory_region_get_ram_ptr(sys_rom); + memory_region_add_subregion(rom_memory, phys_addr, sys_rom); + + /* read the rom content */ + ret = bdrv_read(bdrv, 0, buffer, size>> sector_bits);I think we're trying to get rid of synchronous block I/O in machine initialization for a number of reasons.
Kevin/Stefan, care to comment? Will this be problematic in the future?
Quoted 7 lines
Quoted 3 lines
I was hoping pc-1.1 with and without kvm could be as close as possible, but I guess I can make pc-1.1 with kvm behave the same as pc-1.0. Then I can delete
pc_system_rom_init.I think your general approach is right, I'm just not sure what we're going to do short term about synchronous I/O in the machine init routines. It may just be a matter of structuring this in such a way that you can use an async interface.
Quoted 5 lines
I don't think there is a problem with using the synchronous interface here. But I'm not sure if having any I/O in the machine init is a good idea with respect to migration. Didn't we already have to move some code there to a later stage to make sure that the destination doesn't use outdated data?
The pc_system_rom_init function is only used when kvm is enabled. Since kvm cannot currently execute code from device memory, we have to create a ram region, and transfer the pflash contents into the ram region.
Instead of bdrv_read, should I get the pflash memory region buffer, and use memcpy? Or, would still suffer from the same issue of getting outdated data?
Thanks,
-Jordan
Re: [Qemu-devel] [PATCH v9 3/3] pc: Support system flash memory with pflash
In reply to Kevin WolfQuoted 372 lines · Kevin Wolf
Am 19.12.2011 23:19, schrieb Anthony Liguori:
Quoted 363 lines · Jordan Justen
Quoted 362 lines · Anthony Liguori
Quoted 360 lines · Jordan Justen
Quoted 344 lines
If a pflash image is found, then it is used for the system firmware image.
If a pflash image is not initially found, then a read-only pflash device is created using the -bios filename.
KVM cannot execute from a pflash region currently. Therefore, when KVM is enabled, a (read-only) ram memory region is created and filled with the contents of the pflash drive.
Signed-off-by Jordan Justen<[email protected]>Cc Anthony Liguori<[email protected]>---
Makefile.target | 1 + default-configs/i386-softmmu.mak | 1 + default-configs/x86_64-softmmu.mak | 1 +hw/boards.h| 1 +hw/pc.c| 55 +-------hw/pc.h| 4 +hw/pc_sysfw.c| 255
++++++++++++++++++++++++++++++++++++
vl.c| 2 +-8 files changed, 269 insertions(+), 51 deletions(-)create mode 100644
hw/pc_sysfw.cMakefile.target +0
-0@@ -236,6 +236,7 @@ obj-i386-y += vmport.oobj-i386-y += device-hotplug.o pci-hotplug.o smbios.o wdt_ib700.o obj-i386-y += debugcon.o multiboot.o
obj-i386-y += pc_piix.o
+obj-i386-y += pc_sysfw.o
obj-i386-$(CONFIG_KVM) += kvmclock.o obj-i386-$(CONFIG_SPICE) += qxl.o qxl-logger.o qxl-render.odefault-configs/i386-softmmu.mak +0
-0@@ -22,3 +22,4 @@ CONFIG_SOUND=y
CONFIG_HPET=y
CONFIG_APPLESMC=y
CONFIG_I8259=ydefault-configs/i386-softmmu.mak +1
-0+CONFIG_PFLASH_CFI01=ydefault-configs/x86_64-softmmu.mak +0
-0@@ -22,3 +22,4 @@ CONFIG_SOUND=y
CONFIG_HPET=y
CONFIG_APPLESMC=y
CONFIG_I8259=ydefault-configs/x86_64-softmmu.mak +1
-0+CONFIG_PFLASH_CFI01=yhw/boards.h +1
-0@@ -33,6 +33,7 @@ typedef struct QEMUMachine { } QEMUMachine; int qemu_register_machine(QEMUMachine *m); +QEMUMachine *find_default_machine (void ); extern QEMUMachine *current_machine;hw/pc.c +0
-4@@ -57,10 +57,6 @@ #define DPRINTF(fmt, ...) #endif -#define BIOS_FILENAME "bios.bin" - -#define PC_MAX_BIOS_SIZE (4 * 1024 * 1024) - /* Leave a chunk of memory at the top of RAM for the BIOS ACPI tables. */ #define ACPI_DATA_SIZE 0x10000#define
BIOS_CFG_IOPORT0x510hw/pc.c +5
-41@@ -974,11 +970,9 @@ void pc_memory_init(MemoryRegion *system_memory, MemoryRegion **ram_memory, int system_firmware_enabled) { - char *filename; - int ret, linux_boot, i; - MemoryRegion *ram, *bios, *isa_bios, *option_rom_mr; + int linux_boot, i; + MemoryRegion *ram, *option_rom_mr; MemoryRegion *ram_below_4g, *ram_above_4g; - int bios_size, isa_bios_size; void *fw_cfg; linux_boot = (kernel_filename != NULL);@@ -1003,43 +997,9 @@ void pc_memory_init(MemoryRegion *system_memory, ram_above_4g); } - /* BIOS load */ - if (bios_name == NULL) - bios_name = BIOS_FILENAME; - filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name); - if (filename) { - bios_size = get_image_size(filename); - } else { - bios_size = -1; - } - if (bios_size<= 0 || - (bios_size % 65536) != 0) { - goto bios_error; - } - bios = g_malloc(sizeof(*bios)); - memory_region_init_ram(bios, NULL, "pc.bios", bios_size); - memory_region_set_readonly(bios, true); - ret = rom_add_file_fixed(bios_name, (uint32_t)(-bios_size), -1); - if (ret != 0) { - bios_error: - fprintf(stderr, "qemu: could not load PC BIOS '%s'\n", bios_name); - exit(1); - } - if (filename) { - g_free(filename); - } - /* map the last 128KB of the BIOS in ISA space */ - isa_bios_size = bios_size; - if (isa_bios_size> (128 * 1024)) - isa_bios_size = 128 * 1024; - isa_bios = g_malloc(sizeof(*isa_bios)); - memory_region_init_alias(isa_bios, "isa-bios", bios, - bios_size - isa_bios_size, isa_bios_size); - memory_region_add_subregion_overlap(rom_memory, - 0x100000 - isa_bios_size, - isa_bios, - 1); - memory_region_set_readonly(isa_bios, true); + + /* Initialize ROM or flash ranges for PC firmware */ + pc_system_firmware_init(rom_memory, system_firmware_enabled); option_rom_mr = g_malloc(sizeof(*option_rom_mr));
memory_region_init_ram(option_rom_mr, NULL, "pc.rom", PC_ROM_SIZE);hw/pc.c +0
-5@@ -1048,11 +1008,6 @@ void pc_memory_init(MemoryRegion *system_memory, option_rom_mr, 1); - /* map all the bios at the top of memory */ - memory_region_add_subregion(rom_memory, - (uint32_t)(-bios_size), - bios); - fw_cfg = bochs_bios_init(); rom_set_fw(fw_cfg);hw/pc.h +4
-0@@ -246,6 +246,10 @@ static inline bool isa_ne2000_init(int base, int irq, NICInfo *nd) return true; } +/* pc_sysfw.c */ +void pc_system_firmware_init (MemoryRegion *rom_memory, + int system_firmware_enabled); + /* e820 types */ #define E820_RAM 1#define
E820_RESERVED2hw/pc_sysfw.c new file +7
-0@@ -0,0 +1,255 @@ +/* +* QEMU PC System Firmware +* +* Copyright (c) 2003-2004 Fabrice Bellard +* Copyright (c) 2011 Intel Corporation +* +* Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */hw/pc_sysfw.c new file +86
-0+ +#include "hw.h" +#include "pc.h" +#include "hw/boards.h" +#include "loader.h" +#include "sysemu.h" +#include "flash.h" +#include "kvm.h" + +#define BIOS_FILENAME "bios.bin" + +static void pc_isa_bios_init (MemoryRegion *rom_memory, + MemoryRegion *flash_mem, + int ram_size) +{ + int isa_bios_size; + MemoryRegion *isa_bios; + uint64_t flash_size; + void *flash_ptr, *isa_bios_ptr; + + flash_size = memory_region_size(flash_mem); + + /* map the last 128KB of the BIOS in ISA space */ + isa_bios_size = flash_size; + if (isa_bios_size> (128 * 1024)) { + isa_bios_size = 128 * 1024; + } + isa_bios = g_malloc(sizeof(*isa_bios)); + memory_region_init_ram(isa_bios, NULL, "isa-bios", isa_bios_size); + memory_region_add_subregion_overlap(rom_memory, + 0x100000 - isa_bios_size, + isa_bios, + 1); + + /* copy ISA rom image from top of flash memory */ + flash_ptr = memory_region_get_ram_ptr(flash_mem); + isa_bios_ptr = memory_region_get_ram_ptr(isa_bios); + memcpy(isa_bios_ptr, + ((uint8_t*)flash_ptr) + (flash_size - isa_bios_size), + isa_bios_size); + + memory_region_set_readonly(isa_bios, true); +} + +static void pc_fw_add_pflash_drv (void ) +{ + QemuOpts *opts; + QEMUMachine *machine; + char *filename; + + if (bios_name == NULL) { + bios_name = BIOS_FILENAME; + } + filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name); + + opts = drive_add(IF_PFLASH, -1, filename, "readonly=on"); + if (opts == NULL) { + return; + } + + machine = find_default_machine(); + if (machine == NULL) { + return; + } + + drive_init(opts, machine->use_scsi); +} + +static void pc_system_flash_init (MemoryRegion *rom_memory, + DriveInfo *pflash_drv) +{ + BlockDriverState *bdrv; + int64_t size; + target_phys_addr_t phys_addr; + int sector_bits, sector_size; + pflash_t *system_flash; + MemoryRegion *flash_mem; + + bdrv = pflash_drv->bdrv; + size = bdrv_getlength(pflash_drv->bdrv); + sector_bits = 12; + sector_size = 1<< sector_bits; + + if ((size % sector_size) != 0) { + fprintf(stderr, + "qemu: PC system firmware (pflash) must be a multiple of0x%x\n",
+ sector_size);
+ exit(1);
+ }
+
+ phys_addr =0x100000000ULL- size;
+ system_flash = pflash_cfi01_register(phys_addr, NULL, "system.flash", size,
+ bdrv,sector_size, size>>sector_bits,
+ 1,0x0000,0x0000,0x0000,0x0000, 0);
+ flash_mem =pflash_cfi01_get_memory(system_flash);hw/pc_sysfw.c new file +23
-0+ + pc_isa_bios_init(rom_memory, flash_mem, size); +} + +static void pc_system_rom_init (MemoryRegion *rom_memory, + DriveInfo *pflash_drv) +{ + BlockDriverState *bdrv; + int64_t size; + target_phys_addr_t phys_addr; + int sector_bits, sector_size; + MemoryRegion *sys_rom; + void *buffer; + int ret; + + bdrv = pflash_drv->bdrv; + size = bdrv_getlength(pflash_drv->bdrv); + sector_bits = 9; + sector_size = 1<< sector_bits; + + if ((size % sector_size) != 0) { + fprintf(stderr, + "qemu: PC system rom (pflash) must be a multiple of0x%x\n",
+ sector_size);
+ exit(1);
+ }hw/pc_sysfw.c
Quoted 9 lines
hw/pc_sysfw.c new file +9
-0+ + phys_addr = 0x100000000ULL - size; + sys_rom = g_malloc(sizeof(*sys_rom)); + memory_region_init_ram(sys_rom, NULL, "system.rom", size); + buffer = memory_region_get_ram_ptr(sys_rom); + memory_region_add_subregion(rom_memory, phys_addr, sys_rom); + + /* read the rom content */ + ret = bdrv_read(bdrv, 0, buffer, size>> sector_bits);I think we're trying to get rid of synchronous block I/O in machine initialization for a number of reasons.
Kevin/Stefan, care to comment? Will this be problematic in the future?
Quoted 7 lines
Quoted 3 lines
I was hoping pc-1.1 with and without kvm could be as close as possible, but I guess I can make pc-1.1 with kvm behave the same as pc-1.0. Then I can delete
pc_system_rom_init.I think your general approach is right, I'm just not sure what we're going to do short term about synchronous I/O in the machine init routines. It may just be a matter of structuring this in such a way that you can use an async interface.
Quoted 5 lines
I don't think there is a problem with using the synchronous interface here. But I'm not sure if having any I/O in the machine init is a good idea with respect to migration. Didn't we already have to move some code there to a later stage to make sure that the destination doesn't use outdated data?
Since the bdrv_read call seems to be the concern here, I noticed that in hw/pflash_cfi01.c pflash_cfi01_register there is a call to bdrv_read. So, it seems like it is not possible to initialize a pflash/cfi device without a bdrv_read call being made.
So, what should pflash/cfi be doing instead? Should these devices somehow hold off on initializing their contents from the drive until a later stage? If so, is there a later call into the devices before the firmware is launched that could be used for this later initialization step?
-Jordan
Re: [Qemu-devel] [PATCH v9 3/3] pc: Support system flash memory with pflash
In reply to Anthony LiguoriQuoted 335 lines · Anthony Liguori
Quoted 320 lines · Jordan Justen
If a pflash image is found, then it is used for the system firmware image.
If a pflash image is not initially found, then a read-only pflash device is created using the -bios filename.
KVM cannot execute from a pflash region currently. Therefore, when KVM is enabled, a (read-only) ram memory region is created and filled with the contents of the pflash drive.
Signed-off-by Jordan Justen<[email protected]>Cc Anthony Liguori<[email protected]>--- Makefile.target | 1 + default-configs/i386-softmmu.mak | 1 + default-configs/x86_64-softmmu.mak | 1 + hw/boards.h | 1 + hw/pc.c | 55 +------- hw/pc.h | 4 + hw/pc_sysfw.c | 255 ++++++++++++++++++++++++++++++++++++ vl.c | 2 +- 8 files changed, 269 insertions(+), 51 deletions(-) create mode 100644 hw/pc_sysfw.cMakefile.target +1
-0@@ -236,6 +236,7 @@ obj-i386-y += vmport.o obj-i386-y += device-hotplug.o pci-hotplug.o smbios.o wdt_ib700.o obj-i386-y += debugcon.o multiboot.o obj-i386-y += pc_piix.o +obj-i386-y += pc_sysfw.o obj-i386-$(CONFIG_KVM) += kvmclock.o obj-i386-$(CONFIG_SPICE) += qxl.o qxl-logger.o qxl-render.odefault-configs/i386-softmmu.mak +1
-0@@ -22,3 +22,4 @@ CONFIG_SOUND=y CONFIG_HPET=y CONFIG_APPLESMC=y CONFIG_I8259=y +CONFIG_PFLASH_CFI01=ydefault-configs/x86_64-softmmu.mak +1
-0@@ -22,3 +22,4 @@ CONFIG_SOUND=y CONFIG_HPET=y CONFIG_APPLESMC=y CONFIG_I8259=y +CONFIG_PFLASH_CFI01=yhw/boards.h +1
-0@@ -33,6 +33,7 @@ typedef struct QEMUMachine { } QEMUMachine;int qemu_register_machine (QEMUMachine *m); +QEMUMachine *find_default_machine (void );extern QEMUMachine *current_machine;hw/pc.c +5
-50@@ -57,10 +57,6 @@#define DPRINTF (fmt, ...)#endif -#define BIOS_FILENAME "bios.bin" - -#define PC_MAX_BIOS_SIZE (4 * 1024 * 1024) -/* Leave a chunk of memory at the top of RAM for the BIOS ACPI tables. */ #define ACPI_DATA_SIZE 0x10000#define BIOS_CFG_IOPORT 0x510@@ -974,11 +970,9 @@ void pc_memory_init(MemoryRegion *system_memory,MemoryRegion **ram_memory, int system_firmware_enabled) { - char *filename; -int ret, linux_boot, i; -MemoryRegion *ram, *bios, *isa_bios, *option_rom_mr; + int linux_boot, i; +MemoryRegion *ram, *option_rom_mr;MemoryRegion *ram_below_4g, *ram_above_4g; -int bios_size, isa_bios_size;void *fw_cfg; linux_boot = (kernel_filename !=NULL );@@ -1003,43 +997,9 @@ void pc_memory_init(MemoryRegion *system_memory, ram_above_4g); } -/* BIOS load */ -if (bios_name ==NULL ) - bios_name =BIOS_FILENAME ; - filename =qemu_find_file (QEMU_FILE_TYPE_BIOS , bios_name); -if (filename) { - bios_size =get_image_size (filename); - }else { - bios_size =-1 ; - } -if (bios_size<=0 || - (bios_size %65536 ) !=0 ) { - goto bios_error; - } - bios =g_malloc (sizeof (*bios)); -memory_region_init_ram (bios,NULL ,"pc.bios" , bios_size); -memory_region_set_readonly (bios, true); - ret =rom_add_file_fixed (bios_name, (uint32_t )(-bios_size),-1 ); -if (ret !=0 ) { - bios_error: -fprintf (stderr,"qemu: could not load PC BIOS '%s'\n" , bios_name); -exit (1 ); - } -if (filename) { -g_free (filename); - } -/* map the last 128KB of the BIOS in ISA space */ - isa_bios_size = bios_size; -if (isa_bios_size> (128 *1024 )) - isa_bios_size =128 *1024 ; - isa_bios =g_malloc (sizeof (*isa_bios)); -memory_region_init_alias (isa_bios,"isa-bios" , bios, - bios_size - isa_bios_size, isa_bios_size); -memory_region_add_subregion_overlap (rom_memory, -0x100000 - isa_bios_size, - isa_bios, -1 ); -memory_region_set_readonly (isa_bios, true); + +/* Initialize ROM or flash ranges for PC firmware */ +pc_system_firmware_init (rom_memory, system_firmware_enabled); option_rom_mr =g_malloc (sizeof (*option_rom_mr));memory_region_init_ram (option_rom_mr,NULL ,"pc.rom" ,PC_ROM_SIZE );@@ -1048,11 +1008,6 @@ void pc_memory_init(MemoryRegion *system_memory, option_rom_mr, 1); -/* map all the bios at the top of memory */ -memory_region_add_subregion (rom_memory, - (uint32_t )(-bios_size), - bios); - fw_cfg =bochs_bios_init ();rom_set_fw (fw_cfg);hw/pc.h +4
-0@@ -246,6 +246,10 @@ static inline bool isa_ne2000_init(int base, int irq, NICInfo *nd)return true; } +/* pc_sysfw.c */ +void pc_system_firmware_init (MemoryRegion *rom_memory, +int system_firmware_enabled); +/* e820 types */ #define E820_RAM 1#define E820_RESERVED 2hw/pc_sysfw.c new file +144
-0@@ -0,0 +1,255 @@ +/* +* QEMU PC System Firmware +* +* Copyright (c) 2003-2004 Fabrice Bellard +* Copyright (c) 2011 Intel Corporation +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +* THE SOFTWARE. +*/ + +#include "hw.h" +#include "pc.h" +#include "hw/boards.h" +#include "loader.h" +#include "sysemu.h" +#include "flash.h" +#include "kvm.h" + +#define BIOS_FILENAME "bios.bin" + +static void pc_isa_bios_init (MemoryRegion *rom_memory, +MemoryRegion *flash_mem, +int ram_size) +{ +int isa_bios_size; +MemoryRegion *isa_bios; +uint64_t flash_size; +void *flash_ptr, *isa_bios_ptr; + + flash_size =memory_region_size (flash_mem); + +/* map the last 128KB of the BIOS in ISA space */ + isa_bios_size = flash_size; +if (isa_bios_size> (128 *1024 )) { + isa_bios_size =128 *1024 ; + } + isa_bios =g_malloc (sizeof (*isa_bios)); +memory_region_init_ram (isa_bios,NULL ,"isa-bios" , isa_bios_size); +memory_region_add_subregion_overlap (rom_memory, +0x100000 - isa_bios_size, + isa_bios, +1 ); + +/* copy ISA rom image from top of flash memory */ + flash_ptr =memory_region_get_ram_ptr (flash_mem); + isa_bios_ptr =memory_region_get_ram_ptr (isa_bios); +memcpy (isa_bios_ptr, + ((uint8_t *)flash_ptr) + (flash_size - isa_bios_size), + isa_bios_size); + +memory_region_set_readonly (isa_bios, true); +} + +static void pc_fw_add_pflash_drv (void ) +{ +QemuOpts *opts; +QEMUMachine *machine; +char *filename; + +if (bios_name ==NULL ) { + bios_name =BIOS_FILENAME ; + } + filename =qemu_find_file (QEMU_FILE_TYPE_BIOS , bios_name); + + opts =drive_add (IF_PFLASH ,-1 , filename,"readonly=on" ); +if (opts ==NULL ) { +return ; + } + + machine =find_default_machine (); +if (machine ==NULL ) { +return ; + } + +drive_init (opts, machine->use_scsi); +} + +static void pc_system_flash_init (MemoryRegion *rom_memory, +DriveInfo *pflash_drv) +{ +BlockDriverState *bdrv; +int64_t size; +target_phys_addr_t phys_addr; +int sector_bits, sector_size; +pflash_t *system_flash; +MemoryRegion *flash_mem; + + bdrv = pflash_drv->bdrv; + size =bdrv_getlength (pflash_drv->bdrv); + sector_bits =12 ; + sector_size =1 << sector_bits; + +if ((size % sector_size) !=0 ) { +fprintf (stderr, +"qemu: PC system firmware (pflash) must be a multiple of 0x%x\n" , + sector_size); +exit (1 ); + } + + phys_addr =0x100000000ULL - size; + system_flash =pflash_cfi01_register (phys_addr,NULL ,"system.flash" , size, + bdrv, sector_size, size>> sector_bits, +1 ,0x0000 ,0x0000 ,0x0000 ,0x0000 ,0 ); + flash_mem =pflash_cfi01_get_memory (system_flash); + +pc_isa_bios_init (rom_memory, flash_mem, size); +} + +static void pc_system_rom_init (MemoryRegion *rom_memory, +DriveInfo *pflash_drv) +{ +BlockDriverState *bdrv; +int64_t size; +target_phys_addr_t phys_addr; +int sector_bits, sector_size; +MemoryRegion *sys_rom; +void *buffer; +int ret; + + bdrv = pflash_drv->bdrv; + size =bdrv_getlength (pflash_drv->bdrv); + sector_bits =9 ; + sector_size =1 << sector_bits; + +if ((size % sector_size) !=0 ) { +fprintf (stderr, +"qemu: PC system rom (pflash) must be a multiple of 0x%x\n" , + sector_size); +exit (1 );hw/pc_sysfw.c line 154
Quoted 10 lines
hw/pc_sysfw.c new file +10
-0+ } + + phys_addr =0x100000000ULL - size; + sys_rom =g_malloc (sizeof (*sys_rom)); +memory_region_init_ram (sys_rom,NULL ,"system.rom" , size); + buffer =memory_region_get_ram_ptr (sys_rom); +memory_region_add_subregion (rom_memory, phys_addr, sys_rom); + +/* read the rom content */ + ret =bdrv_read (bdrv,0 , buffer, size>> sector_bits);I think we're trying to get rid of synchronous block I/O in machine initialization for a number of reasons.
Quoted 1 line
Kevin/Stefan, care to comment? Will this be problematic in the future?
This looks okay to me because it is not called from vcpu context. We need to avoid device emulation that uses synchronous I/O for pio/mmio because that blocks the guest from executing code. In this case the code runs before the VM starts and should be easy to update if we ever drop the bdrv_read() interface.
Stefan
I verified that 'info mtree' and 'info qdev' are equivalent for pc-1.0 when using master and with my patches.
However, I did discover that v1.0 seems to differ from master for this same test.
I've attached the logs.
master-pc-1.0.log renamed from v1.0-pc.log +1 -1
@@ -1,4 +1,4 @@ -QEMU 1.0 monitor - type 'help' for more information +QEMU 1.0.50 monitor - type 'help' for more information (qemu) info mtree memory 0000000000000000-7ffffffffffffffe (prio 0): system
@@ -18,6 +18,8 @@ 00000000000ec000-00000000000effff (prio 1): alias pam-ram @pc.ram
00000000000ec000-00000000000effff
00000000000f0000-00000000000fffff (prio 1): alias pam-rom @pc.ram
00000000000f0000-00000000000fffff
0000000008000000-00000000ffffffff (prio 0): alias pci-hole @pci
0000000008000000-00000000ffffffff
+ 00000000fec00000-00000000fec00fff (prio 0): ioapic
+ 00000000fed00000-00000000fed003ff (prio 0): hpet 00000000fee00000-00000000feefffff (prio 0): apic 4000000000000000-7fffffffffffffff (prio 0): alias pci-hole64 @pci
4000000000000000-7fffffffffffffff
pc.ram
@@ -56,6 +58,7 @@
00000000000003f8-00000000000003ff (prio 0): serial 00000000000004d0-00000000000004d0 (prio 0): elcr 00000000000004d1-00000000000004d1 (prio 0): elcr
+ 0000000000000510-0000000000000511 (prio 0): fwcfg 0000000000000cf8-0000000000000cfb (prio 0): pci-conf-idx 0000000000000cfc-0000000000000cff (prio 0): pci-conf-data 0000000000005658-0000000000005658 (prio 0): vmport
@@ -126,7 +129,7 @@
dev-prop: opt_io_size = 0
dev-prop: bootindex = -1
dev-prop: discard_granularity = 0
- dev-prop: ver = "1.0"
+ dev-prop: ver = "1.0.50"
dev-prop: serial = "QM00003"
bus-prop: unit = 0
bus: ide.0
@@ -218,7 +221,7 @@
dev-prop: data_iobase = 0x511
irq 0
mmio ffffffffffffffff/0000000000000002- mmio ffffffffffffffff/0000000000000002
+ mmio ffffffffffffffff/0000000000000001
dev: apic, id ""
dev-prop: id = 0
irq 0
Thanks,
-Jordan
Quoted 54 lines · Jordan Justen
Enable flash emulation in a PC system using
pflash_cfi01.v9:
* Add pc-1.1
* pc-1.0 uses previous rom firmware init code pathv8:
* Cleanup two chunks of debug code (printf messages)
* Fix comment inpc.h(pcflash.c=>pc_sysfw.c)v7:
* Do not add system firmware to qemu roms
* If kvm is enabled, copy pflash drive contents into a read-only ram region, since kvm cannot currently execute code from a pflash device.
* Renamepcflash.ctopc_sysfw.cv6:
* Rebase for memory API
*pflash_cfi01: Set error in status register when a write to erase is attempted in read-only mode.
* Add system firmware to qemu romsv5:
* Enable pflash read-only mode
* Enable -drive with if=pflash to define system firmware imagev4:
* Rebasev3:
* Fix code style issues
* Add additional commentsv2:
* Convert debug printf to DPRINTFJordan Justen (3):
pc: Add pc-1.1 machine type
pflash: Support read-only mode
pc: Support system flash memory with pflashMakefile.target | 1 +
blockdev.c | 3 +- default-configs/i386-softmmu.mak | 1 + default-configs/x86_64-softmmu.mak | 1 +
hw/boards.h | 1 +
hw/pc.c | 58 +-------
hw/pc.h | 7 +-
hw/pc_piix.c | 40 +++++-
hw/pc_sysfw.c | 255 ++++++++++++++++++++++++++++++++++++hw/pflash_cfi01.c| 44 ++++--hw/pflash_cfi02.c| 83 +++++++------
vl.c | 2 +-
Quoted 4 lines
12 files changed, 382 insertions(+), 114 deletions(-)create mode 100644
hw/pc_sysfw.c
QEMU 1.0.50 monitor - type 'help' for more information
(qemu) i[K[Din[K[D[Dinf[K[D[D[Dinfo[K[D[D[D[Dinfo [K[D[D[D[D[Dinfo m[K[D[D[D[D[D[Dinfo mt[K[D[D[D[D[D[D[Dinfo mtr[K[D[D[D[D[D[D[D[Dinfo mtre[K[D[D[D[D[D[D[D[D[Dinfo mtree[K memory
0000000000000000-7ffffffffffffffe (prio 0): system
0000000000000000-0000000007ffffff (prio 0): alias ram-below-4g @pc.ram 0000000000000000-0000000007ffffff
00000000000a0000-00000000000bffff (prio 1): alias smram-region @pci 00000000000a0000-00000000000bffff
00000000000c0000-00000000000c3fff (prio 1): alias pam-rom @pc.ram 00000000000c0000-00000000000c3fff
00000000000c4000-00000000000c7fff (prio 1): alias pam-rom @pc.ram 00000000000c4000-00000000000c7fff
00000000000c8000-00000000000cbfff (prio 1): alias pam-rom @pc.ram 00000000000c8000-00000000000cbfff
00000000000cc000-00000000000cffff (prio 1): alias pam-ram @pc.ram 00000000000cc000-00000000000cffff
00000000000d0000-00000000000d3fff (prio 1): alias pam-ram @pc.ram 00000000000d0000-00000000000d3fff
00000000000d4000-00000000000d7fff (prio 1): alias pam-ram @pc.ram 00000000000d4000-00000000000d7fff
00000000000d8000-00000000000dbfff (prio 1): alias pam-ram @pc.ram 00000000000d8000-00000000000dbfff
00000000000dc000-00000000000dffff (prio 1): alias pam-ram @pc.ram 00000000000dc000-00000000000dffff
00000000000e0000-00000000000e3fff (prio 1): alias pam-ram @pc.ram 00000000000e0000-00000000000e3fff
00000000000e4000-00000000000e7fff (prio 1): alias pam-ram @pc.ram 00000000000e4000-00000000000e7fff
00000000000e8000-00000000000ebfff (prio 1): alias pam-ram @pc.ram 00000000000e8000-00000000000ebfff
00000000000ec000-00000000000effff (prio 1): alias pam-ram @pc.ram 00000000000ec000-00000000000effff
00000000000f0000-00000000000fffff (prio 1): alias pam-rom @pc.ram 00000000000f0000-00000000000fffff
0000000008000000-00000000ffffffff (prio 0): alias pci-hole @pci 0000000008000000-00000000ffffffff
00000000fec00000-00000000fec00fff (prio 0): ioapic
00000000fed00000-00000000fed003ff (prio 0): hpet
00000000fee00000-00000000feefffff (prio 0): apic
4000000000000000-7fffffffffffffff (prio 0): alias pci-hole64 @pci 4000000000000000-7fffffffffffffff
pc.ram
0000000000000000-0000000007ffffff (prio 0): pc.ram
pci
0000000000000000-7ffffffffffffffe (prio 0): pci
00000000000a0000-00000000000bffff (prio 1): cirrus-lowmem-container
00000000000a0000-00000000000bffff (prio 0): cirrus-low-memory
00000000000c0000-00000000000dffff (prio 1): pc.rom
00000000000e0000-00000000000fffff (prio 1): alias isa-bios @pc.bios 0000000000000000-000000000001ffff
00000000fc000000-00000000fdffffff (prio 1): cirrus-pci-bar0
00000000fc000000-00000000fc7fffff (prio 1): vga.vram
00000000fc000000-00000000fc7fffff (prio 0): cirrus-linear-io
00000000fd000000-00000000fd3fffff (prio 0): cirrus-bitblt-mmio 00000000feba0000-00000000febbffff (prio 1): e1000-mmio 00000000febf0000-00000000febf0fff (prio 1): cirrus-mmio 00000000fffe0000-00000000ffffffff (prio 0): pc.bios
pc.bios
00000000fffe0000-00000000ffffffff (prio 0): pc.bios
I/O
0000000000000000-000000000000ffff (prio 0): io
0000000000000020-0000000000000021 (prio 0): pic 0000000000000040-0000000000000043 (prio 0): pit 0000000000000060-0000000000000060 (prio 0): i8042-data 0000000000000064-0000000000000064 (prio 0): i8042-cmd 0000000000000070-0000000000000071 (prio 0): rtc 0000000000000092-0000000000000092 (prio 0): port92 00000000000000a0-00000000000000a1 (prio 0): pic 0000000000000170-0000000000000177 (prio 0): ide 00000000000001f0-00000000000001f7 (prio 0): ide 0000000000000376-0000000000000376 (prio 0): ide 0000000000000378-000000000000037f (prio 0): parallel 00000000000003f1-00000000000003f5 (prio 0): fdc 00000000000003f6-00000000000003f6 (prio 0): ide 00000000000003f7-00000000000003f7 (prio 0): fdc 00000000000003f8-00000000000003ff (prio 0): serial 00000000000004d0-00000000000004d0 (prio 0): elcr 00000000000004d1-00000000000004d1 (prio 0): elcr 0000000000000510-0000000000000511 (prio 0): fwcfg 0000000000000cf8-0000000000000cfb (prio 0): pci-conf-idx 0000000000000cfc-0000000000000cff (prio 0): pci-conf-data 0000000000005658-0000000000005658 (prio 0): vmport 000000000000c000-000000000000c03f (prio 1): e1000-io 000000000000c040-000000000000c04f (prio 1): piix-bmdma-container
000000000000c040-000000000000c043 (prio 0): piix-bmdma
000000000000c044-000000000000c047 (prio 0): bmdma
000000000000c048-000000000000c04b (prio 0): piix-bmdma
000000000000c04c-000000000000c04f (prio 0): bmdma(qemu) i[K[Din[K[D[Dinf[K[D[D[Dinfo[K[D[D[D[Dinfo [K[D[D[D[D[Dinfo q[K[D[D[D[D[D[Dinfo qt[K[D[D[D[D[D[D[Dinfo qtr[K[D[D[D[D[D[D[D[Dinfo qtre[K[D[D[D[D[D[D[D[D[Dinfo qtree[K
bus: main-system-bus
type System
dev: hpet, id ""
gpio-in 1
dev-prop: timers = 3
dev-prop: msi = off
irq 32
mmio 00000000fed00000/0000000000000400
dev: ioapic, id ""
gpio-in 24
irq 0
mmio 00000000fec00000/0000000000001000
dev: i440FX-pcihost, id ""
irq 0
bus: pci.0
type PCI
dev: PIIX4_PM, id ""
dev-prop: smb_io_base = 45312
bus-prop: addr = 01.3
bus-prop: romfile = <null>
bus-prop: rombar = 1
bus-prop: multifunction = off
bus-prop: command_serr_enable = on
class Bridge, addr 00:01.3, pci id 8086:7113 (sub 1af4:1100)
bus: i2c
type I2C
dev: smbus-eeprom, id ""
bus-prop: address = 87
dev: smbus-eeprom, id ""
bus-prop: address = 86
dev: smbus-eeprom, id ""
bus-prop: address = 85
dev: smbus-eeprom, id ""
bus-prop: address = 84
dev: smbus-eeprom, id ""
bus-prop: address = 83
dev: smbus-eeprom, id ""
bus-prop: address = 82
dev: smbus-eeprom, id ""
bus-prop: address = 81
dev: smbus-eeprom, id ""
bus-prop: address = 80
dev: piix3-ide, id ""
bus-prop: addr = 01.1
bus-prop: romfile = <null>
bus-prop: rombar = 1
bus-prop: multifunction = off
bus-prop: command_serr_enable = on
class IDE controller, addr 00:01.1, pci id 8086:7010 (sub 1af4:1100)
bar 4: i/o at 0xc040 [0xc04f]
bus: ide.1
type IDE
dev: ide-cd, id ""
dev-prop: drive = ide1-cd0
dev-prop: logical_block_size = 512
dev-prop: physical_block_size = 512
dev-prop: min_io_size = 0
dev-prop: opt_io_size = 0
dev-prop: bootindex = -1
dev-prop: discard_granularity = 0
dev-prop: ver = "1.0.50"
dev-prop: serial = "QM00003"
bus-prop: unit = 0
bus: ide.0
type IDE
dev: e1000, id ""
dev-prop: mac = 52:54:00:12:34:56
dev-prop: vlan = 0
dev-prop: netdev = <null>
dev-prop: bootindex = -1
bus-prop: addr = 03.0
bus-prop: romfile = "pxe-e1000.rom"
bus-prop: rombar = 1
bus-prop: multifunction = off
bus-prop: command_serr_enable = on
class Ethernet controller, addr 00:03.0, pci id 8086:100e (sub 1af4:1100)
bar 0: mem at 0xfeba0000 [0xfebbffff]
bar 1: i/o at 0xc000 [0xc03f]
bar 6: mem at 0xffffffffffffffff [0x1fffe]
dev: cirrus-vga, id ""
bus-prop: addr = 02.0
bus-prop: romfile = "vgabios-cirrus.bin"
bus-prop: rombar = 1
bus-prop: multifunction = off
bus-prop: command_serr_enable = on
class VGA controller, addr 00:02.0, pci id 1013:00b8 (sub 1af4:1100)
bar 0: mem at 0xfc000000 [0xfdffffff]
bar 1: mem at 0xfebf0000 [0xfebf0fff]
bar 6: mem at 0xffffffffffffffff [0xfffe]
dev: PIIX3, id ""
bus-prop: addr = 01.0
bus-prop: romfile = <null>
bus-prop: rombar = 1
bus-prop: multifunction = on
bus-prop: command_serr_enable = on
class ISA bridge, addr 00:01.0, pci id 8086:7000 (sub 1af4:1100)
bus: isa.0
type ISA
dev: isa-fdc, id ""
dev-prop: driveA = floppy0
dev-prop: driveB = <null>
dev-prop: bootindexA = -1
dev-prop: bootindexB = -1
isa irq 6
dev: port92, id ""
dev: vmmouse, id ""
dev: vmport, id ""
dev: i8042, id ""
isa irqs 1,12
dev: isa-parallel, id ""
dev-prop: index = 0
dev-prop: iobase = 0x378
dev-prop: irq = 7
dev-prop: chardev = parallel0
isa irq 7
dev: isa-serial, id ""
dev-prop: index = 0
dev-prop: iobase = 0x3f8
dev-prop: irq = 4
dev-prop: chardev = serial0
isa irq 4
dev: isa-pit, id ""
dev-prop: irq = 0
dev-prop: iobase = 0x40
dev: mc146818rtc, id ""
dev-prop: base_year = 2000
dev: isa-i8259, id ""
gpio-in 8
gpio-out 1
dev-prop: iobase = 0xa0
dev-prop: elcr_addr = 0x4d1
dev-prop: elcr_mask = 0xde
dev-prop: master = off
dev: isa-i8259, id ""
gpio-in 8
gpio-out 1
dev-prop: iobase = 0x20
dev-prop: elcr_addr = 0x4d0
dev-prop: elcr_mask = 0xf8
dev-prop: master = on
dev: i440FX, id ""
bus-prop: addr = 00.0
bus-prop: romfile = <null>
bus-prop: rombar = 1
bus-prop: multifunction = off
bus-prop: command_serr_enable = on
class Host bridge, addr 00:00.0, pci id 8086:1237 (sub 1af4:1100)
dev: fw_cfg, id ""
dev-prop: ctl_iobase = 0x510
dev-prop: data_iobase = 0x511
irq 0
mmio ffffffffffffffff/0000000000000002
mmio ffffffffffffffff/0000000000000001 dev: apic, id ""
dev-prop: id = 0
irq 0
mmio 00000000fee00000/0000000000100000
(qemu) q[K
QEMU 1.0 monitor - type 'help' for more information
(qemu) i[K[Din[K[D[Dinf[K[D[D[Dinfo[K[D[D[D[Dinfo [K[D[D[D[D[Dinfo m[K[D[D[D[D[D[Dinfo mt[K[D[D[D[D[D[D[Dinfo mtr[K[D[D[D[D[D[D[D[Dinfo mtre[K[D[D[D[D[D[D[D[D[Dinfo mtree[K memory
0000000000000000-7ffffffffffffffe (prio 0): system
0000000000000000-0000000007ffffff (prio 0): alias ram-below-4g @pc.ram 0000000000000000-0000000007ffffff
00000000000a0000-00000000000bffff (prio 1): alias smram-region @pci 00000000000a0000-00000000000bffff
00000000000c0000-00000000000c3fff (prio 1): alias pam-rom @pc.ram 00000000000c0000-00000000000c3fff
00000000000c4000-00000000000c7fff (prio 1): alias pam-rom @pc.ram 00000000000c4000-00000000000c7fff
00000000000c8000-00000000000cbfff (prio 1): alias pam-rom @pc.ram 00000000000c8000-00000000000cbfff
00000000000cc000-00000000000cffff (prio 1): alias pam-ram @pc.ram 00000000000cc000-00000000000cffff
00000000000d0000-00000000000d3fff (prio 1): alias pam-ram @pc.ram 00000000000d0000-00000000000d3fff
00000000000d4000-00000000000d7fff (prio 1): alias pam-ram @pc.ram 00000000000d4000-00000000000d7fff
00000000000d8000-00000000000dbfff (prio 1): alias pam-ram @pc.ram 00000000000d8000-00000000000dbfff
00000000000dc000-00000000000dffff (prio 1): alias pam-ram @pc.ram 00000000000dc000-00000000000dffff
00000000000e0000-00000000000e3fff (prio 1): alias pam-ram @pc.ram 00000000000e0000-00000000000e3fff
00000000000e4000-00000000000e7fff (prio 1): alias pam-ram @pc.ram 00000000000e4000-00000000000e7fff
00000000000e8000-00000000000ebfff (prio 1): alias pam-ram @pc.ram 00000000000e8000-00000000000ebfff
00000000000ec000-00000000000effff (prio 1): alias pam-ram @pc.ram 00000000000ec000-00000000000effff
00000000000f0000-00000000000fffff (prio 1): alias pam-rom @pc.ram 00000000000f0000-00000000000fffff
0000000008000000-00000000ffffffff (prio 0): alias pci-hole @pci 0000000008000000-00000000ffffffff
00000000fee00000-00000000feefffff (prio 0): apic
4000000000000000-7fffffffffffffff (prio 0): alias pci-hole64 @pci 4000000000000000-7fffffffffffffff
pc.ram
0000000000000000-0000000007ffffff (prio 0): pc.ram
pci
0000000000000000-7ffffffffffffffe (prio 0): pci
00000000000a0000-00000000000bffff (prio 1): cirrus-lowmem-container
00000000000a0000-00000000000bffff (prio 0): cirrus-low-memory
00000000000c0000-00000000000dffff (prio 1): pc.rom
00000000000e0000-00000000000fffff (prio 1): alias isa-bios @pc.bios 0000000000000000-000000000001ffff
00000000fc000000-00000000fdffffff (prio 1): cirrus-pci-bar0
00000000fc000000-00000000fc7fffff (prio 1): vga.vram
00000000fc000000-00000000fc7fffff (prio 0): cirrus-linear-io
00000000fd000000-00000000fd3fffff (prio 0): cirrus-bitblt-mmio 00000000feba0000-00000000febbffff (prio 1): e1000-mmio 00000000febf0000-00000000febf0fff (prio 1): cirrus-mmio 00000000fffe0000-00000000ffffffff (prio 0): pc.bios
pc.bios
00000000fffe0000-00000000ffffffff (prio 0): pc.bios
I/O
0000000000000000-000000000000ffff (prio 0): io
0000000000000020-0000000000000021 (prio 0): pic 0000000000000040-0000000000000043 (prio 0): pit 0000000000000060-0000000000000060 (prio 0): i8042-data 0000000000000064-0000000000000064 (prio 0): i8042-cmd 0000000000000070-0000000000000071 (prio 0): rtc 0000000000000092-0000000000000092 (prio 0): port92 00000000000000a0-00000000000000a1 (prio 0): pic 0000000000000170-0000000000000177 (prio 0): ide 00000000000001f0-00000000000001f7 (prio 0): ide 0000000000000376-0000000000000376 (prio 0): ide 0000000000000378-000000000000037f (prio 0): parallel 00000000000003f1-00000000000003f5 (prio 0): fdc 00000000000003f6-00000000000003f6 (prio 0): ide 00000000000003f7-00000000000003f7 (prio 0): fdc 00000000000003f8-00000000000003ff (prio 0): serial 00000000000004d0-00000000000004d0 (prio 0): elcr 00000000000004d1-00000000000004d1 (prio 0): elcr 0000000000000cf8-0000000000000cfb (prio 0): pci-conf-idx 0000000000000cfc-0000000000000cff (prio 0): pci-conf-data 0000000000005658-0000000000005658 (prio 0): vmport 000000000000c000-000000000000c03f (prio 1): e1000-io 000000000000c040-000000000000c04f (prio 1): piix-bmdma-container
000000000000c040-000000000000c043 (prio 0): piix-bmdma
000000000000c044-000000000000c047 (prio 0): bmdma
000000000000c048-000000000000c04b (prio 0): piix-bmdma
000000000000c04c-000000000000c04f (prio 0): bmdma(qemu) i[K[Din[K[D[Dinf[K[D[D[Dinfo[K[D[D[D[Dinfo [K[D[D[D[D[Dinfo q[K[D[D[D[D[D[Dinfo qt[K[D[D[D[D[D[D[Dinfo qtr[K[D[D[D[D[D[D[D[Dinfo qtre[K[D[D[D[D[D[D[D[D[Dinfo qtree[K
bus: main-system-bus
type System
dev: hpet, id ""
gpio-in 1
dev-prop: timers = 3
dev-prop: msi = off
irq 32
mmio 00000000fed00000/0000000000000400
dev: ioapic, id ""
gpio-in 24
irq 0
mmio 00000000fec00000/0000000000001000
dev: i440FX-pcihost, id ""
irq 0
bus: pci.0
type PCI
dev: PIIX4_PM, id ""
dev-prop: smb_io_base = 45312
bus-prop: addr = 01.3
bus-prop: romfile = <null>
bus-prop: rombar = 1
bus-prop: multifunction = off
bus-prop: command_serr_enable = on
class Bridge, addr 00:01.3, pci id 8086:7113 (sub 1af4:1100)
bus: i2c
type I2C
dev: smbus-eeprom, id ""
bus-prop: address = 87
dev: smbus-eeprom, id ""
bus-prop: address = 86
dev: smbus-eeprom, id ""
bus-prop: address = 85
dev: smbus-eeprom, id ""
bus-prop: address = 84
dev: smbus-eeprom, id ""
bus-prop: address = 83
dev: smbus-eeprom, id ""
bus-prop: address = 82
dev: smbus-eeprom, id ""
bus-prop: address = 81
dev: smbus-eeprom, id ""
bus-prop: address = 80
dev: piix3-ide, id ""
bus-prop: addr = 01.1
bus-prop: romfile = <null>
bus-prop: rombar = 1
bus-prop: multifunction = off
bus-prop: command_serr_enable = on
class IDE controller, addr 00:01.1, pci id 8086:7010 (sub 1af4:1100)
bar 4: i/o at 0xc040 [0xc04f]
bus: ide.1
type IDE
dev: ide-cd, id ""
dev-prop: drive = ide1-cd0
dev-prop: logical_block_size = 512
dev-prop: physical_block_size = 512
dev-prop: min_io_size = 0
dev-prop: opt_io_size = 0
dev-prop: bootindex = -1
dev-prop: discard_granularity = 0
dev-prop: ver = "1.0"
dev-prop: serial = "QM00003"
bus-prop: unit = 0
bus: ide.0
type IDE
dev: e1000, id ""
dev-prop: mac = 52:54:00:12:34:56
dev-prop: vlan = 0
dev-prop: netdev = <null>
dev-prop: bootindex = -1
bus-prop: addr = 03.0
bus-prop: romfile = "pxe-e1000.rom"
bus-prop: rombar = 1
bus-prop: multifunction = off
bus-prop: command_serr_enable = on
class Ethernet controller, addr 00:03.0, pci id 8086:100e (sub 1af4:1100)
bar 0: mem at 0xfeba0000 [0xfebbffff]
bar 1: i/o at 0xc000 [0xc03f]
bar 6: mem at 0xffffffffffffffff [0x1fffe]
dev: cirrus-vga, id ""
bus-prop: addr = 02.0
bus-prop: romfile = "vgabios-cirrus.bin"
bus-prop: rombar = 1
bus-prop: multifunction = off
bus-prop: command_serr_enable = on
class VGA controller, addr 00:02.0, pci id 1013:00b8 (sub 1af4:1100)
bar 0: mem at 0xfc000000 [0xfdffffff]
bar 1: mem at 0xfebf0000 [0xfebf0fff]
bar 6: mem at 0xffffffffffffffff [0xfffe]
dev: PIIX3, id ""
bus-prop: addr = 01.0
bus-prop: romfile = <null>
bus-prop: rombar = 1
bus-prop: multifunction = on
bus-prop: command_serr_enable = on
class ISA bridge, addr 00:01.0, pci id 8086:7000 (sub 1af4:1100)
bus: isa.0
type ISA
dev: isa-fdc, id ""
dev-prop: driveA = floppy0
dev-prop: driveB = <null>
dev-prop: bootindexA = -1
dev-prop: bootindexB = -1
isa irq 6
dev: port92, id ""
dev: vmmouse, id ""
dev: vmport, id ""
dev: i8042, id ""
isa irqs 1,12
dev: isa-parallel, id ""
dev-prop: index = 0
dev-prop: iobase = 0x378
dev-prop: irq = 7
dev-prop: chardev = parallel0
isa irq 7
dev: isa-serial, id ""
dev-prop: index = 0
dev-prop: iobase = 0x3f8
dev-prop: irq = 4
dev-prop: chardev = serial0
isa irq 4
dev: isa-pit, id ""
dev-prop: irq = 0
dev-prop: iobase = 0x40
dev: mc146818rtc, id ""
dev-prop: base_year = 2000
dev: isa-i8259, id ""
gpio-in 8
gpio-out 1
dev-prop: iobase = 0xa0
dev-prop: elcr_addr = 0x4d1
dev-prop: elcr_mask = 0xde
dev-prop: master = off
dev: isa-i8259, id ""
gpio-in 8
gpio-out 1
dev-prop: iobase = 0x20
dev-prop: elcr_addr = 0x4d0
dev-prop: elcr_mask = 0xf8
dev-prop: master = on
dev: i440FX, id ""
bus-prop: addr = 00.0
bus-prop: romfile = <null>
bus-prop: rombar = 1
bus-prop: multifunction = off
bus-prop: command_serr_enable = on
class Host bridge, addr 00:00.0, pci id 8086:1237 (sub 1af4:1100)
dev: fw_cfg, id ""
dev-prop: ctl_iobase = 0x510
dev-prop: data_iobase = 0x511
irq 0
mmio ffffffffffffffff/0000000000000002
mmio ffffffffffffffff/0000000000000002 dev: apic, id ""
dev-prop: id = 0
irq 0
mmio 00000000fee00000/0000000000100000
(qemu) q[K
Quoted 6 lines · Jordan Justen
I verified that 'info mtree' and 'info qdev' are equivalent for pc-1.0 when using master and with my patches.
However, I did discover that v1.0 seems to differ from master for this same test.
That's are fine; pre-memory-API devices don't show up in info mtree.
Review line 225
Quoted 7 lines
(quoted diff) +1
-1@@ -218,7 +221,7 @@ dev-prop: data_iobase = 0x511 irq 0 mmio ffffffffffffffff/0000000000000002 - mmio ffffffffffffffff/0000000000000002 + mmio ffffffffffffffff/0000000000000001
This one isn't nice. Doesn't affect pc though.
Signature · 1 line
error compiling committee.c: too many arguments to function
Quoted 10 lines · Avi Kivity
Quoted 6 lines · Jordan Justen
I verified that 'info mtree' and 'info qdev' are equivalent for pc-1.0 when using master and with my patches.
However, I did discover that v1.0 seems to differ from master for this same test.
That's are fine; pre-memory-API devices don't show up in info mtree.
Quoted 9 lines
Quoted 7 lines
(quoted diff) +0
-0@@ -218,7 +221,7 @@dev-prop:
data_iobase=0x511
irq 0
mmio ffffffffffffffff/0000000000000002
- mmio ffffffffffffffff/0000000000000002
+ mmio ffffffffffffffff/0000000000000001This one isn't nice. Doesn't affect pc though.
Thanks Avi. Does this patch series now address your concerns about qtree/mtree and pc-1.0 with regards to the x86 flash feature?
-Jordan
Quoted 21 lines · Jordan Justen
Quoted 10 lines · Avi Kivity
Quoted 6 lines · Jordan Justen
I verified that 'info mtree' and 'info qdev' are equivalent for pc-1.0 when using master and with my patches.
However, I did discover that v1.0 seems to differ from master for this same test.
That's are fine; pre-memory-API devices don't show up in info mtree.
Quoted 9 lines
Review line 225
Quoted 7 lines
(quoted diff) +1
-1@@ -218,7 +221,7 @@ dev-prop: data_iobase = 0x511 irq 0 mmio ffffffffffffffff/0000000000000002 - mmio ffffffffffffffff/0000000000000002 + mmio ffffffffffffffff/0000000000000001This one isn't nice. Doesn't affect pc though.
Quoted 3 lines
Thanks Avi. Does this patch series now address your concerns about qtree/mtree and pc-1.0 with regards to the x86 flash feature?
It's hard to review, since you move a large function and edit it in the same patch. Usually we separate this into two patches so the changes are visible.
The test however indicates that it's probably fine.
Signature · 1 line
error compiling committee.c: too many arguments to function