PC system flash support
v10 cover PC system flash support
Enable flash emulation in a PC system using pflash_cfi01.
v10:
* Rebase to HEAD
* "decouple vmstate from memory API" as in c5705a7
* Break changes into smaller pieces
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 (8):
blockdev: allow read-only pflash devices pflash_cfi01/02: support read-only pflash devices
vl: make find_default_machine externally visible hw/pc: move rom init to pc_sysfw.c hw/pc_sysfw: Support system flash memory with pflash hw/pc_piix: remove is_default for pc-0.15 hw/pc_piix: add pc-1.1
pc: enable system flash for pc-1.1
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 | 59 +-------- hw/pc.h | 7 +- hw/pc_piix.c | 43 +++++-- hw/pc_sysfw.c | 256 ++++++++++++++++++++++++++++++++++++ hw/pflash_cfi01.c | 44 ++++-- hw/pflash_cfi02.c | 83 +++++++------ vl.c | 2 +- 12 files changed, 384 insertions(+), 117 deletions(-) create mode 100644 hw/pc_sysfw.c
PATCH v10 1/8 blockdev: allow read-only pflash devices
--- blockdev.c | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-)
blockdev.c +2 -1
@@ -557,7 +557,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; }
Signature · 1 line
1.7.1
PATCH v10 2/8 pflash_cfi01/02: support read-only pflash devices
In reply to Jordan Justen--- hw/pflash_cfi01.c | 44 +++++++++++++++++++--------- hw/pflash_cfi02.c | 83 ++++++++++++++++++++++++++++------------------------ 2 files changed, 75 insertions(+), 52 deletions(-)
hw/pflash_cfi01.c +30 -14
@@ -283,8 +283,12 @@ static void pflash_write(pflash_t *pfl, target_phys_addr_t offset, TARGET_FMT_plx"\n" , __func__, offset, pfl->sector_len); -memset (p + offset,0xff , pfl->sector_len); -pflash_update (pfl, offset, pfl->sector_len); +if (!pfl->ro) { +memset (p + offset,0xff , pfl->sector_len); +pflash_update (pfl, offset, pfl->sector_len); + }else { + pfl->status |=0x20 ;/* Block erase error */ + } pfl->status |=0x80 ;/* Ready! */ break ;case 0x50 :/* Clear status bits */
@@ -323,8 +327,12 @@ static void pflash_write(pflash_t *pfl, target_phys_addr_t offset,case 0x10 :/* Single Byte Program */ case 0x40 :/* Single Byte Program */ DPRINTF ("%s: Single Byte Program\n" , __func__); -pflash_data_write (pfl, offset, value, width, be); -pflash_update (pfl, offset, width); +if (!pfl->ro) { +pflash_data_write (pfl, offset, value, width, be); +pflash_update (pfl, offset, width); + }else { + pfl->status |=0x10 ;/* Programming error */ + } pfl->status |=0x80 ;/* Ready! */ pfl->wcycle =0 ;break ;
@@ -372,7 +380,11 @@ static void pflash_write(pflash_t *pfl, target_phys_addr_t offset,case 2 :switch (pfl->cmd) {case 0xe8 :/* Block write */ -pflash_data_write (pfl, offset, value, width, be); +if (!pfl->ro) { +pflash_data_write (pfl, offset, value, width, be); + }else { + pfl->status |=0x10 ;/* Programming error */ + } pfl->status |=0x80 ;
@@ -382,8 +394,12 @@ static void pflash_write(pflash_t *pfl, target_phys_addr_t offset,DPRINTF ("%s: block write finished\n" , __func__); pfl->wcycle++; -/* Flush the entire write buffer onto backing storage. */ -pflash_update (pfl, offset & mask, pfl->writeblock_size); +if (!pfl->ro) { +/* Flush the entire write buffer onto backing storage. */ +pflash_update (pfl, offset & mask, pfl->writeblock_size); + }else { + pfl->status |=0x10 ;/* Programming error */ + } } pfl->counter--;
@@ -607,13 +623,13 @@ pflash_t *pflash_cfi01_register(target_phys_addr_t base, }bdrv_attach_dev_nofail (pfl->bs, pfl); } -#if 0 /* XXX: there should be a bit to set up read-only, -* the same way the hardware does (with WP pin). -*/ - pfl->ro =1 ; -#else - pfl->ro =0 ; -#endif + +if (pfl->bs) { + pfl->ro =bdrv_is_read_only (pfl->bs); + }else { + pfl->ro =0 ; + } + pfl->timer =qemu_new_timer_ns (vm_clock, pflash_timer, pfl); pfl->base = base; pfl->sector_len = sector_len;
hw/pflash_cfi02.c +45 -38
113 lines not on this page · raw message
Signature · 1 line
1.7.1
PATCH v10 3/8 vl: make find_default_machine externally visible
In reply to Jordan Justen--- hw/boards.h | 1 + vl.c | 2 +- 2 files changed, 2 insertions(+), 1 deletions(-)
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;
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
PATCH v10 4/8 hw/pc: move rom init to pc_sysfw.c
In reply to Jordan Justen--- Makefile.target | 1 + hw/pc.c | 56 +++------------------------------ hw/pc.h | 3 ++ hw/pc_sysfw.c | 92 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 101 insertions(+), 51 deletions(-) create mode 100644 hw/pc_sysfw.c
Makefile.target +1 -0
@@ -228,6 +228,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
hw/pc.c +5 -51
81 lines not on this page · raw message
hw/pc.h +3 -0
@@ -246,6 +246,9 @@ static inline bool isa_ne2000_init(ISABus *bus, int base, int irq, NICInfo *nd)return true; } +/* pc_sysfw.c */ +void pc_system_firmware_init (MemoryRegion *rom_memory); +/* e820 types */ #define E820_RAM 1#define E820_RESERVED 2
hw/pc_sysfw.c new file +92 -0
92 lines not on this page · raw message
Signature · 1 line
1.7.1
PATCH v10 5/8 hw/pc_sysfw: Support system flash memory with pflash
In reply to Jordan JustenFlash can be enabled by calling pc_system_firmware_init with the system_flash_enabled parameter being non-zero. If system_flash_enabled is zero, then the older qemu rom creation method will be used.
If flash is enabled and a pflash image is found, then it is used for the system firmware image.
If flash is enabled and 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.
--- default-configs/i386-softmmu.mak | 1 + default-configs/x86_64-softmmu.mak | 1 + hw/pc.c | 2 +- hw/pc.h | 3 +- hw/pc_sysfw.c | 172 +++++++++++++++++++++++++++++++++++- 5 files changed, 173 insertions(+), 6 deletions(-)
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/pc.c +1 -1
@@ -999,7 +999,7 @@ void pc_memory_init(MemoryRegion *system_memory,/* Initialize PC system firmware */ -pc_system_firmware_init (rom_memory); +pc_system_firmware_init (rom_memory,0 ); option_rom_mr =g_malloc (sizeof (*option_rom_mr));memory_region_init_ram (option_rom_mr,"pc.rom" ,PC_ROM_SIZE );
hw/pc.h +2 -1
@@ -247,7 +247,8 @@ static inline bool isa_ne2000_init(ISABus *bus, int base, int irq, NICInfo *nd) }/* pc_sysfw.c */ -void pc_system_firmware_init (MemoryRegion *rom_memory); +void pc_system_firmware_init (MemoryRegion *rom_memory, +int system_flash_enabled);/* e820 types */ #define E820_RAM 1
hw/pc_sysfw.c +168 -4
190 lines not on this page · raw message
Signature · 1 line
1.7.1
PATCH v10 6/8 hw/pc_piix: remove is_default for pc-0.15
In reply to Jordan Justen--- hw/pc_piix.c | 1 - 1 files changed, 0 insertions(+), 1 deletions(-)
hw/pc_piix.c +0 -1
@@ -328,7 +328,6 @@ static QEMUMachine pc_machine_v0_15 = { .desc = "Standard PC", .init = pc_init_pci, .max_cpus = 255, - .is_default = 1, };static QEMUMachine pc_machine_v0_14 = {
Signature · 1 line
1.7.1
PATCH v10 7/8 hw/pc_piix: add pc-1.1
In reply to Jordan Justen--- hw/pc_piix.c | 11 +++++++++-- 1 files changed, 9 insertions(+), 2 deletions(-)
hw/pc_piix.c +9 -2
@@ -314,8 +314,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,
@@ -323,6 +323,13 @@ 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, + .max_cpus =255 , +}; +static QEMUMachine pc_machine_v0_15 = { .name ="pc-0.15" , .desc ="Standard PC" ,
Signature · 1 line
1.7.1
Re: [Qemu-devel] [PATCH v10 7/8] hw/pc_piix: add pc-1.1
Quoted 24 lines · Jordan Justen
Signed-off-by Jordan Justen <[email protected]>---
hw/pc_piix.c| 11 +++++++++--1 files changed, 9 insertions(+), 2 deletions(-)hw/pc_piix.c +2
-2@@ -314,8 +314,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,@@ -323,6 +323,13 @@ static QEMUMachine pc_machine_v1_0 = { .is_default = 1, };
hw/pc_piix.c static QEMUMachine pc_machine_v1_0 = { · line 335
Quoted 10 lines
hw/pc_piix.c +7
-0+static QEMUMachine pc_machine_v1_0 = { + .name ="pc-1.0" , + .desc ="Standard PC" , + .init = pc_init_pci, + .max_cpus =255 , +}; +static QEMUMachine pc_machine_v0_15 = { .name ="pc-0.15" , .desc ="Standard PC" ,
This is missing registration of the v1.1 machine, no? Please see my -cpu best default patch I just posted.
Alex
Re: [Qemu-devel] [PATCH v10 7/8] hw/pc_piix: add pc-1.1
Quoted 27 lines · Alexander Graf
Quoted 24 lines · Jordan Justen
Signed-off-by Jordan Justen <[email protected]>---
hw/pc_piix.c| 11 +++++++++--1 files changed, 9 insertions(+), 2 deletions(-)hw/pc_piix.c +2
-2@@ -314,8 +314,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,@@ -323,6 +323,13 @@ static QEMUMachine pc_machine_v1_0 = { .is_default = 1, };
Quoted 12 lines
hw/pc_piix.c static QEMUMachine pc_machine_v1_0 = { · line 335
Quoted 10 lines
hw/pc_piix.c +7
-0+static QEMUMachine pc_machine_v1_0 = { + .name = "pc-1.0", + .desc = "Standard PC", + .init = pc_init_pci, + .max_cpus = 255, +}; +static QEMUMachine pc_machine_v0_15 = { .name = "pc-0.15", .desc = "Standard PC",This is missing registration of the v1.1 machine, no? Please see my -cpu best default patch I just posted.
Yep, whoops. I was splitting my change apart compared to v9, and it looks like I mistakenly added the registration portion into patch 8/8.
Now that I see you are adding pc-1.1, it seems likely that I'll probably be reworking my changeset again after yours is merged.
I also had added that pc-0.15 is_default change into my changeset, but hopefully you'll have that change merged soon as well.
Thanks,
-Jordan
PATCH v10 8/8 pc: enable system flash for pc-1.1
In reply to Jordan Justen--- hw/pc.c | 5 +++-- hw/pc.h | 3 ++- hw/pc_piix.c | 33 +++++++++++++++++++++++++-------- 3 files changed, 30 insertions(+), 11 deletions(-)
hw/pc.c +3 -2
@@ -967,7 +967,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_flash_enabled) { int linux_boot, i;MemoryRegion *ram, *option_rom_mr;
@@ -999,7 +1000,7 @@ void pc_memory_init(MemoryRegion *system_memory,/* Initialize PC system firmware */ -pc_system_firmware_init (rom_memory,0 ); +pc_system_firmware_init (rom_memory, system_flash_enabled); option_rom_mr =g_malloc (sizeof (*option_rom_mr));memory_region_init_ram (option_rom_mr,"pc.rom" ,PC_ROM_SIZE );
hw/pc.h +2 -1
@@ -139,7 +139,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_flash_enabled);qemu_irq *pc_allocate_cpu_irq (void );DeviceState *pc_vga_init (ISABus *isa_bus,PCIBus *pci_bus); void pc_basic_device_init(ISABus *isa_bus, qemu_irq *gsi,
hw/pc_piix.c +25 -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_flash_enabled) { int i;ram_addr_t below_4g_mem_size, above_4g_mem_size;
@@ -130,7 +131,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_flash_enabled); } gsi_state =g_malloc0 (sizeof (*gsi_state));
@@ -263,7 +265,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,
@@ -277,7 +293,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,
@@ -293,7 +309,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
@@ -326,21 +342,21 @@ static QEMUMachine pc_machine_v1_1 = {static QEMUMachine pc_machine_v1_0 = { .name ="pc-1.0" , .desc ="Standard PC" , - .init = pc_init_pci, + .init = pc_init_pci_system_rom_only, .max_cpus =255 , };static QEMUMachine pc_machine_v0_15 = { .name ="pc-0.15" , .desc ="Standard PC" , - .init = pc_init_pci, + .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 []) { {
@@ -619,6 +635,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_15);qemu_register_machine (&pc_machine_v0_14);
Signature · 1 line
1.7.1
This currently depends on Avi's patch to avoid an assert during boot.
* Fix vmstate_register_ram() for rom/device regions
-Jordan
Quoted 68 lines · Jordan Justen
Enable flash emulation in a PC system using
pflash_cfi01.v10:
* Rebase to HEAD
* "decouple vmstate from memory API" as in c5705a7
* Break changes into smaller piecesv9:
* 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 (8):
blockdev: allow read-only pflash devices pflash_cfi01/02: support read-only pflash devices
vl: makefind_default_machineexternally visible hw/pc: move rom init topc_sysfw.chw/pc_sysfw: Support system flash memory with pflash hw/pc_piix: removeis_defaultfor pc-0.15 hw/pc_piix: add pc-1.1
pc: enable system flash for pc-1.1Makefile.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 | 59 +--------
hw/pc.h | 7 +-
hw/pc_piix.c | 43 +++++--
hw/pc_sysfw.c | 256 ++++++++++++++++++++++++++++++++++++hw/pflash_cfi01.c| 44 ++++--hw/pflash_cfi02.c| 83 +++++++------
vl.c | 2 +-12 files changed, 384 insertions(+), 117 deletions(-)create mode 100644
hw/pc_sysfw.c