Skip to contentSkip to conversation

PC system flash support

PATCH Superseded Jordan Justen 4 participants 10 messages Nov 28, 2011 – Dec 1, 2011 Kbuild

v8 of 11 Superseded Latest is v11 →

lore
Share & tools
lore
#0 lore raw

v8 cover PC system flash support

Enable flash emulation in a PC system using pflash_cfi01.

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 (2):
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                            |   55 +---------
 hw/pc.h                            |    3 +
 hw/pc_sysfw.c                      |  194 ++++++++++++++++++++++++++++++++++++
 hw/pflash_cfi01.c                  |   44 ++++++---
 hw/pflash_cfi02.c                  |   83 ++++++++-------
 vl.c                               |    2 +-
 11 files changed, 284 insertions(+), 104 deletions(-)
 create mode 100644 hw/pc_sysfw.c
#1 lore raw

PATCH v8 1/2 pflash: Support read-only mode

When 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
index 2228186..ff58d5e 100644
@@ -506,7 +506,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
#2 lore raw

PATCH v8 2/2 pc: Support system flash memory with pflash

In reply to 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.

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                            |    3 +
 hw/pc_sysfw.c                      |  194 ++++++++++++++++++++++++++++++++++++
 vl.c                               |    2 +-
 8 files changed, 207 insertions(+), 51 deletions(-)
 create mode 100644 hw/pc_sysfw.c
Makefile.target +1 -0
index a111521..b1dc882 100644
@@ -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
index e67ebb3..cd407a9 100644
@@ -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
index b75757e..47734ea 100644
@@ -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
index 716fd7b..45a31a1 100644
@@ -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 +3 -0
index 4515006..6a03f00 100644
@@ -244,6 +244,9 @@ 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);
+
 /* e820 types */
 #define E820_RAM        1
 #define E820_RESERVED   2
hw/pc_sysfw.c new file +194 -0

194 lines not on this page · raw message

vl.c +1 -1
index f5afed4..5cfe5c6 100644
@@ -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
#3 lore raw
In reply to Jordan Justen
Quoted 3 lines · Jordan Justen

Enable flash emulation in a PC system using pflash_cfi01.

The new memory layout should be made conditional on the machine type (-M pc-1.1 or later) to allow migration from/to pc-1.0 and earlier.

Memory layout in this context are the names of memory ranges given to memory_region_init_ram(), sizes, and locations. Also, the flash interface should not be there for older machines.

Signature · 1 line
error compiling committee.c: too many arguments to function
#4 lore raw
Quoted 9 lines · Avi Kivity
Quoted 1 line · Jordan Justen

Enable flash emulation in a PC system using pflash_cfi01.

The new memory layout should be made conditional on the machine type (-M pc-1.1 or later) to allow migration from/to pc-1.0 and earlier.

Memory layout in this context are the names of memory ranges given to memory_region_init_ram(), sizes, and locations.  Also, the flash interface should not be there for older machines.

Is this the right way to go about it?
1. Create a new pc-sysfw qdev
2. Use a flash property in pc_piix.c to selectively enable the flash

Or, is there an easier or better way to say pc > pc-1.0?

How do I enable "migration from/to pc-1.0 and earlier"? It seems like some code will need to shuttle the data (rom <=> pflash). Can you point me an an example?

Thanks,

-Jordan

#5 lore raw
Quoted 11 lines · Jordan Justen
Quoted 9 lines · Avi Kivity
Quoted 1 line · Jordan Justen

Enable flash emulation in a PC system using pflash_cfi01.

The new memory layout should be made conditional on the machine type (-M pc-1.1 or later) to allow migration from/to pc-1.0 and earlier.

Memory layout in this context are the names of memory ranges given to memory_region_init_ram(), sizes, and locations. Also, the flash interface should not be there for older machines.

Quoted 5 lines

Is this the right way to go about it?
1. Create a new pc-sysfw qdev
2. Use a flash property in pc_piix.c to selectively enable the flash

Or, is there an easier or better way to say pc > pc-1.0?

No idea, copying some qdev people.

Quoted 3 lines

How do I enable "migration from/to pc-1.0 and earlier"? It seems like some code will need to shuttle the data (rom <=> pflash). Can you point me an an example?

It should be completely transparent, so long as you instantiate a ROM for <= pc-1.0 (say based on a property) and flash for >= pc-1.1.

One way to verify is to to 'info qdev' and 'info mtree' with qemu-1.0 and qemu-1.1 -M pc-1.0, and see that you get the same results.

Signature · 1 line
error compiling committee.c: too many arguments to function
#6 lore raw
Quoted 24 lines · Avi Kivity
Quoted 11 lines · Jordan Justen
Quoted 9 lines · Avi Kivity
Quoted 1 line · Jordan Justen

Enable flash emulation in a PC system using pflash_cfi01.

The new memory layout should be made conditional on the machine type (-M pc-1.1 or later) to allow migration from/to pc-1.0 and earlier.

Memory layout in this context are the names of memory ranges given to memory_region_init_ram(), sizes, and locations.  Also, the flash interface should not be there for older machines.

Quoted 5 lines

Is this the right way to go about it?
1. Create a new pc-sysfw qdev
2. Use a flash property in pc_piix.c to selectively enable the flash

Or, is there an easier or better way to say pc > pc-1.0?

No idea, copying some qdev people.

Quoted 3 lines

How do I enable "migration from/to pc-1.0 and earlier"?  It seems like some code will need to shuttle the data (rom <=> pflash).  Can you point me an an example?

Quoted 5 lines

It should be completely transparent, so long as you instantiate a ROM for <= pc-1.0 (say based on a property) and flash for >= pc-1.1.

One way to verify is to to 'info qdev' and 'info mtree' with qemu-1.0 and qemu-1.1 -M pc-1.0, and see that you get the same results.

I think this means that I cannot add a pc-sysfw qdev for pc-1.0. (Even if the rom memory usage matches pc-1.0.) Is that right?

If so, the plan I mentioned above would not work. In the plan above, a property of the pc-sysfw qdev would have determined if the old rom method would be used, or the newer flash method would be used.

Thanks,

-Jordan

#7 lore raw
Quoted 5 lines · Jordan Justen
Quoted 2 lines

One way to verify is to to 'info qdev' and 'info mtree' with qemu-1.0 and qemu-1.1 -M pc-1.0, and see that you get the same results.

I think this means that I cannot add a pc-sysfw qdev for pc-1.0. (Even if the rom memory usage matches pc-1.0.) Is that right?

Yes.

Quoted 3 lines

If so, the plan I mentioned above would not work. In the plan above, a property of the pc-sysfw qdev would have determined if the old rom method would be used, or the newer flash method would be used.

Okay. It needs to be a machine/global property then.

Signature · 1 line
error compiling committee.c: too many arguments to function
#8 lore raw
In reply to Avi Kivity
Quoted 24 lines · Avi Kivity
Quoted 11 lines · Jordan Justen
Quoted 9 lines · Avi Kivity
Quoted 1 line · Jordan Justen

Enable flash emulation in a PC system using pflash_cfi01.

The new memory layout should be made conditional on the machine type (-M pc-1.1 or later) to allow migration from/to pc-1.0 and earlier.

Memory layout in this context are the names of memory ranges given to memory_region_init_ram(), sizes, and locations. Also, the flash interface should not be there for older machines.

Quoted 5 lines

Is this the right way to go about it?
1. Create a new pc-sysfw qdev
2. Use a flash property in pc_piix.c to selectively enable the flash

Or, is there an easier or better way to say pc > pc-1.0?

No idea, copying some qdev people.

Quoted 3 lines

How do I enable "migration from/to pc-1.0 and earlier"? It seems like some code will need to shuttle the data (rom <=> pflash). Can you point me an an example?

Quoted 5 lines

It should be completely transparent, so long as you instantiate a ROM for <= pc-1.0 (say based on a property) and flash for >= pc-1.1.

One way to verify is to to 'info qdev' and 'info mtree' with qemu-1.0 and qemu-1.1 -M pc-1.0, and see that you get the same results.

Gerd created the compatibility machinery (commit b6b61144), and I'm not really familiar with it. But I can give it a try.

Our tool to configure devices is qdev properties.

The device defines property default values. The board can override them, with QEMUMachine member compat_props.

For examples, peruse git-log -Scompat_props. Random pick with [my explanations in brackets]:

commit b1aeb92666d2fde413c34578b3b42bbfe5f2a506

Author: Isaku Yamahata <[email protected]>
Date:   Fri Nov 26 21:01:41 2010 +0900

pci: make command SERR bit writable

pcie aer needs SERR bit to be writable, and the PCI spec requires this as well. For compatibility, introduce compat global property command_serr_enable and make this bit readonly for a pre 0.14 pc machine.

[Patch hunks reordered to make the patch easier to follow]

hw/pci.c +0 -0
index 0c15b13..ca878e8 100644
@@ -57,6 +57,8 @@ struct BusInfo pci_bus_info = {

[Define a property to make the incompatible change configurable. Store in PCIDevice member cap_present bit QEMU_PCI_CAP_SERR_BITNR, default is true.]
DEFINE_PROP_UINT32("rombar", PCIDevice, rom_bar, 1), DEFINE_PROP_BIT("multifunction", PCIDevice, cap_present,
QEMU_PCI_CAP_MULTIFUNCTION_BITNR, false),
+ DEFINE_PROP_BIT("command_serr_enable", PCIDevice, cap_present,
+ QEMU_PCI_CAP_SERR_BITNR, true),

         DEFINE_PROP_END_OF_LIST()
     }

};

hw/pci.h +0 -0
index 89f7b76..099c251 100644
@@ -118,6 +118,10 @@ enum {

[Since we use a new bit of the existing cap_present, we don't have to define a new member. Instead we need to define the new bit:]

     /* multifunction capable device */

#define QEMU_PCI_CAP_MULTIFUNCTION_BITNR 3
QEMU_PCI_CAP_MULTIFUNCTION = (1 << QEMU_PCI_CAP_MULTIFUNCTION_BITNR),
+
+ /* command register SERR bit enabled */
+#define QEMU_PCI_CAP_SERR_BITNR 4
+ QEMU_PCI_CAP_SERR = (1 << QEMU_PCI_CAP_SERR_BITNR),
};

struct PCIDevice {

hw/pc_piix.c +0 -0
index 7d29d43..a2fb554 100644

[Change default to off for pc-0.13 and all the older machine types.] @@ -217,6 +217,14 @@ static QEMUMachine pc_machine = {
.desc = "Standard PC",
.init = pc_init_pci,
.max_cpus = 255,
+ .compat_props = (GlobalProperty[]) {
+ {

+            .driver   = "PCI",
+            .property = "command_serr_enable",
+            .value    = "off",
+        },
+        { /* end of list */ }
+    },
     .is_default = 1,

};

@@ -265,6 +273,10 @@ static QEMUMachine pc_machine_v0_12 = {
.driver = "vmware-svga",
.property = "rombar",
.value = stringify(0),
+ },{

+            .driver   = "PCI",
+            .property = "command_serr_enable",
+            .value    = "off",
         },
         { /* end of list */ }
     }

@@ -300,6 +312,10 @@ static QEMUMachine pc_machine_v0_11 = {
.driver = "PCI",
.property = "rombar",
.value = stringify(0),
+ },{

+            .driver   = "PCI",
+            .property = "command_serr_enable",
+            .value    = "off",
         },
         { /* end of list */ }
     }

@@ -347,6 +363,10 @@ static QEMUMachine pc_machine_v0_10 = {
.driver = "PCI",
.property = "rombar",
.value = stringify(0),
+ },{

+            .driver   = "PCI",
+            .property = "command_serr_enable",
+            .value    = "off",
         },
         { /* end of list */ }
     },
@@ -568,6 +570,9 @@ static void pci_init_wmask(PCIDevice *dev)
[Compatible behavior when QEMU_PCI_CAP_SERR_BITNR is off:]
     pci_set_word(dev->wmask + PCI_COMMAND,
                  PCI_COMMAND_IO | PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER |
                  PCI_COMMAND_INTX_DISABLE);

+ if (dev->cap_present & QEMU_PCI_CAP_SERR) {
+ pci_word_test_and_set_mask(dev->wmask + PCI_COMMAND, PCI_COMMAND_SERR);
+ }

     memset(dev->wmask + PCI_CONFIG_HEADER_SIZE, 0xff,
            config_size - PCI_CONFIG_HEADER_SIZE);
#9 lore raw
Quoted 32 lines · Markus Armbruster
Quoted 24 lines · Avi Kivity
Quoted 11 lines · Jordan Justen
Quoted 9 lines · Avi Kivity
Quoted 1 line · Jordan Justen

Enable flash emulation in a PC system using pflash_cfi01.

The new memory layout should be made conditional on the machine type (-M pc-1.1 or later) to allow migration from/to pc-1.0 and earlier.

Memory layout in this context are the names of memory ranges given to memory_region_init_ram(), sizes, and locations. Also, the flash interface should not be there for older machines.

Quoted 5 lines

Is this the right way to go about it?
1. Create a new pc-sysfw qdev
2. Use a flash property in pc_piix.c to selectively enable the flash

Or, is there an easier or better way to say pc > pc-1.0?

No idea, copying some qdev people.

Quoted 3 lines

How do I enable "migration from/to pc-1.0 and earlier"? It seems like some code will need to shuttle the data (rom <=> pflash). Can you point me an an example?

Quoted 5 lines

It should be completely transparent, so long as you instantiate a ROM for <= pc-1.0 (say based on a property) and flash for >= pc-1.1.

One way to verify is to to 'info qdev' and 'info mtree' with qemu-1.0 and qemu-1.1 -M pc-1.0, and see that you get the same results.

Quoted 7 lines

Gerd created the compatibility machinery (commit b6b61144), and I'm not really familiar with it. But I can give it a try.

Our tool to configure devices is qdev properties.

The device defines property default values. The board can override them, with QEMUMachine member compat_props.

If you need more than just configuring a device differently, you probably need to hack the board init method. Check out commit 0ec329da for an example. Works roughly like this:

* Add suitable parameter to pc_init1()

* Change pc_init_pci() to pass the "new behavior on" argument.

* Define pc_init_pci_no_kvmclock() like pc_init_pci(), except pass the "new behavior off" argument. Change old boards to use it.

[...]