VMState: Fix design faults, i2c port, x86 cpu port, ...
cover VMState: Fix design faults, i2c port, x86 cpu port, ...
Hi
This is the whole VMState patches from this last two weeks. It has integrated the VMState design flaws and the i2c devices port.
New is:
- remove const from *_pre_save(), and port all users
- x86 cpu is ported to vmstate.
- fpregs: it allows load/save mix of 64/80 bits floats, ugly as hell (it was already ugly as hell)
- field_exist() method, now we can have optional fields
- ac97 got integrated in the buch.
Comments?
Later, Juan.
Quoted 1 line
From older series.
Subject: [PATCH v2 0/4] Fix VMState design flaws
v2:
- fix old_version field for ps2 keyboard (thanks paolo)
v1:
I know you are not going to believe it, but VMState design have flaws:
(everybody) Ooohhhhhhh!!!!
This patches fixes (some) of them:
* When we added .pre_save() and .post_save(), we have it basically to change values in the variable pointed by the "void *opaque". Without this functions, it made sense that this variables were const, with them, it means that we have to do
FooState *s = (void *)opaque
in every pre/post_save() function. Just remove the const.
* Add version_id field to post_load(). Now we can assign default values in post_load for old versions of the state (ps2_kbd as example). This one is also needed for ioapic in qemu-kvm.
* Add support for sending partial struct arrays (i.e. only some fields starting from the beggining) fdc cleanups for getting pc98 in need it.
Quoted 1 line
From Subject: [PATCH 00/20] VMState: port all i2c devices
This ports all i2c_devices to vmstate. Big changes:
- i2c->address now are uint8_t, my review of all uses is that they are always used as uint8_t (and that is the type that is passed on the value). If you know i2c, please check. Change 0002 looks big, but it is because as I was auditing the paths, I changed the types of the functios to reflect that they use uint8_t. Real part of the patch is changing the struct definitions.
- qdev: there was not support for uint8_t (the i2c addresses) in qdev, now it is I missed this change in my 1st pass (on mips_malta)
- qdev_prop_set_uint32(eeprom, "address", 0x50 + i);
+ qdev_prop_set_uint8(eeprom, "address", 0x50 + i);
And qdev complained during compilation. qdev++
- I had to fix lots of places where values of one type were sent with a different type. qemu_put_byte/qemu_put_be16/qemu_put_be32 should be just baned. Yesterday.
- tmp105: We have a winner, the 1st user of post_save(). Can anyone explain me what we need to do _anything_ after saving
s->faults = tmp105_faultq[(s->config >> 3) & 3]; /* F */
I can't see why saving have to change faults, and no, I don't understand what that line does.
- twl922230: here we go.
It pass all the fields of a struct tm (they are ints) as uint16_t. All solutions are bad (tm):
* marshalling the struct tm in a struct tm_16bits fields, and use normal vmstate
* up version and declare all previous versions baned. No forward migration for you.
* Do the hack that I did, new type:
vmstate_hack_int32_as_uint16
local to that function, and be done with it. It is a big hack, but the function were already abusing the format.
- lm832x: I got an unused command (0xff) to be send as an error. it was using an int, -1 means an error, and a small number meaned a command. As the numbers of commands is very limited, I think this is the best solution. Notice that we were doing this already when we saved/loaded the value. Name the constant instead of -1 to make things easier.
- vmstate arrays shortened the save/load code for this series _a lot_.
Juan Quintela (49):
vmstate: remove const for put operations
vmstate: add version_id argument to post_load
vmstate: remove const from pre_save() functions
vmstate: remove ps2_kbd_load_old()
vmstate: Add support for sending partial arrays
qdev: Add support for uint8_t
i2c: addresses are load/save as uint8_t values, change types to
reflect this
vmstate: port i2c_bus device
vmstate: port i2c_slave device
vmstate: add uint8 array
vmstate: create VMSTATE_I2C_SLAVE
vmstate: port wm8750 device
vmstate: port max7310 device
vmstate: create VMSTATE_STRUCT_POINTER
vmstate: port pxa2xx_i2c device
vmstate: port ssd0303 device
vmstate: create VMSTATE_INT16_ARRAY
tmp105: change len and alorm to uint8_t
vmstate: port tmp105 device
twl92230: change pwrbtn_state to uint8_t
vmstate: port twl92230 device
vmstate: add support for arrays of pointers
lm832x: make fields to have the same types that they are saved/loaded
vmstate: port lm832x device
vmstate: remove i2c_slave_load/save
vmstate: port audio/audio.c
ac97: add active to the state
vmstate: port ac97 device
x86: hflags is not modified at all, just save it directly
x86: make a20_mask int32_t
x86: fpuc is uint16_t not unsigned int
x86: fpus is uint16_t not unsigned int
x86: add fptag_vmstate to the state
x86: add pending_irq_vmstate to the state
x86: add fpregs_format_vmstate
x86: mce_banks always have the same size
x86: send mce_banks as an array
x86: mcg_cap is never 0
x86: split FPReg union
x86: split MTRRVar union
Add *TL functions to vmstate
x86: port segments to vmstate
x86: factor out cpu_pre_save()
x86: factor out cpu_pre/post_load()
x86: factor out cpu_get/put_xmm_reg()
x86: factor out cpu_get/put_mttr_var()
x86: factor out cpu_get/put_fpreg()
vmstate: Add suppot for field_exist() test
x86: port cpu to vmstate
audio/audio.c | 26 +-- exec.c | 6 +- hw/ac97.c | 136 ++++----- hw/acpi.c | 2 +- hw/cirrus_vga.c | 2 +- hw/dma.c | 2 +- hw/fdc.c | 6 +- hw/hpet.c | 6 +- hw/hw.h | 114 ++++++++- hw/i2c.c | 64 +++-- hw/i2c.h | 10 +- hw/lm832x.c | 148 ++++------ hw/max7310.c | 51 ++--- hw/mips_malta.c | 2 +- hw/pc.c | 2 +- hw/pci.c | 2 +- hw/piix_pci.c | 2 +- hw/ps2.c | 16 +- hw/ptimer.c | 4 +- hw/pxa2xx.c | 54 ++-- hw/qdev-properties.c | 33 +++ hw/qdev.h | 5 + hw/serial.c | 6 +- hw/slavio_intctl.c | 2 +- hw/smbus.c | 18 +- hw/smbus.h | 18 +- hw/ssd0303.c | 65 ++--- hw/tcx.c | 2 +- hw/tmp105.c | 60 ++--- hw/twl92230.c | 200 ++++++-------- hw/vmmouse.c | 2 +- hw/wm8750.c | 120 +++----- savevm.c | 87 ++++--- target-i386/cpu.h | 40 ++- target-i386/helper.c | 9 +- target-i386/machine.c | 725 ++++++++++++++++++++++++++++--------------------- 36 files changed, 1083 insertions(+), 964 deletions(-)
PATCH 1/49 vmstate: remove const for put operations
In a later patch, we introduce pre_save() and post_save() functions. The whole point of that operation is to change things in the state. Without this patch, we have to remove the const qualifier in each use with a cast
--- hw/hw.h | 4 ++-- hw/pci.c | 2 +- hw/ptimer.c | 4 ++-- savevm.c | 46 +++++++++++++++++++++++----------------------- 4 files changed, 28 insertions(+), 28 deletions(-)
hw/hw.h +2 -2
@@ -276,7 +276,7 @@ typedef struct VMStateDescription VMStateDescription;struct VMStateInfo {const char *name;int (*get)(QEMUFile *f,void *pv,size_t size); -void (*put)(QEMUFile *f,const void *pv,size_t size); +void (*put)(QEMUFile *f,void *pv,size_t size); };enum VMStateFlags {
@@ -534,7 +534,7 @@ extern const VMStateDescription vmstate_pci_device;extern int vmstate_load_state (QEMUFile *f,const VMStateDescription *vmsd,void *opaque,int version_id);extern void vmstate_save_state (QEMUFile *f,const VMStateDescription *vmsd, -const void *opaque); +void *opaque);extern int vmstate_register (int instance_id,const VMStateDescription *vmsd,void *base);void vmstate_unregister (const VMStateDescription *vmsd,void *opaque);
hw/pci.c +1 -1
@@ -156,7 +156,7 @@ static int get_pci_config_device(QEMUFile *f, void *pv, size_t size) }/* just put buffer */ -static void put_pci_config_device (QEMUFile *f,const void *pv,size_t size) +static void put_pci_config_device (QEMUFile *f,void *pv,size_t size) {const uint8_t *v = pv;qemu_put_buffer (f, v, size);
hw/ptimer.c +2 -2
@@ -220,9 +220,9 @@ static int get_ptimer(QEMUFile *f, void *pv, size_t size)return 0 ; } -static void put_ptimer (QEMUFile *f,const void *pv,size_t size) +static void put_ptimer (QEMUFile *f,void *pv,size_t size) { -ptimer_state *v = (void *)pv; +ptimer_state *v = pv;qemu_put_ptimer (f, v); }
savevm.c +23 -23
134 lines not on this page · raw message
Signature · 1 line
1.6.2.5
PATCH 2/49 vmstate: add version_id argument to post_load
In reply to Juan Quintela--- exec.c | 2 +- hw/acpi.c | 2 +- hw/cirrus_vga.c | 2 +- hw/dma.c | 2 +- hw/fdc.c | 2 +- hw/hpet.c | 2 +- hw/hw.h | 2 +- hw/piix_pci.c | 2 +- hw/serial.c | 2 +- hw/slavio_intctl.c | 2 +- hw/tcx.c | 2 +- hw/vmmouse.c | 2 +- savevm.c | 2 +- 13 files changed, 13 insertions(+), 13 deletions(-)
exec.c +1 -1
@@ -528,7 +528,7 @@ static int cpu_common_pre_load(void *opaque)return 0 ; } -static int cpu_common_post_load (void *opaque) +static int cpu_common_post_load (void *opaque,int version_id) {CPUState *env = opaque;
hw/acpi.c +1 -1
@@ -441,7 +441,7 @@ static void pm_write_config(PCIDevice *d,pm_io_space_update ((PIIX4PMState *)d); } -static int vmstate_acpi_post_load (void *opaque) +static int vmstate_acpi_post_load (void *opaque,int version_id) {PIIX4PMState *s = opaque;
hw/cirrus_vga.c +1 -1
@@ -2955,7 +2955,7 @@ static CPUWriteMemoryFunc * const cirrus_mmio_write[3] = {/* load/save state */ -static int cirrus_post_load (void *opaque) +static int cirrus_post_load (void *opaque,int version_id) {CirrusVGAState *s = opaque;
hw/dma.c +1 -1
@@ -517,7 +517,7 @@ static const VMStateDescription vmstate_dma_regs = { } }; -static int dma_post_load (void *opaque) +static int dma_post_load (void *opaque,int version_id) {DMA_run ();
hw/fdc.c +1 -1
@@ -650,7 +650,7 @@ static void fdc_pre_save(const void *opaque) s->dor_vmstate = s->dor |GET_CUR_DRV (s); } -static int fdc_post_load (void *opaque) +static int fdc_post_load (void *opaque,int version_id) {fdctrl_t *s = opaque;
hw/hpet.c +1 -1
@@ -164,7 +164,7 @@ static void hpet_pre_save(const void *opaque) s->hpet_counter =hpet_get_ticks (); } -static int hpet_post_load (void *opaque) +static int hpet_post_load (void *opaque,int version_id) {HPETState *s = opaque;
hw/hw.h +1 -1
@@ -307,7 +307,7 @@ struct VMStateDescription {int minimum_version_id_old;LoadStateHandler *load_state_old;int (*pre_load)(void *opaque); -int (*post_load)(void *opaque); +int (*post_load)(void *opaque,int version_id);void (*pre_save)(const void *opaque);void (*post_save)(const void *opaque);VMStateField *fields;
hw/piix_pci.c +1 -1
@@ -172,7 +172,7 @@ static int i440fx_load_old(QEMUFile* f, void *opaque, int version_id)return 0 ; } -static int i440fx_post_load (void *opaque) +static int i440fx_post_load (void *opaque,int version_id) {PCII440FXState *d = opaque;
hw/serial.c +1 -1
@@ -648,7 +648,7 @@ static int serial_pre_load(void *opaque)return 0 ; } -static int serial_post_load (void *opaque) +static int serial_post_load (void *opaque,int version_id) {SerialState *s = opaque;
hw/slavio_intctl.c +1 -1
@@ -374,7 +374,7 @@ static void slavio_set_irq_all(void *opaque, int irq, int level) } } -static int vmstate_intctl_post_load (void *opaque) +static int vmstate_intctl_post_load (void *opaque,int version_id) {SLAVIO_INTCTLState *s = opaque;
hw/tcx.c +1 -1
@@ -378,7 +378,7 @@ static void tcx24_invalidate_display(void *opaque)qemu_console_resize (s->ds, s->width, s->height); } -static int vmstate_tcx_post_load (void *opaque) +static int vmstate_tcx_post_load (void *opaque,int version_id) {TCXState *s = opaque;
hw/vmmouse.c +1 -1
@@ -235,7 +235,7 @@ static uint32_t vmmouse_ioport_read(void *opaque, uint32_t addr)return data[0 ]; } -static int vmmouse_post_load (void *opaque) +static int vmmouse_post_load (void *opaque,int version_id) {VMMouseState *s = opaque;
savevm.c +1 -1
@@ -1084,7 +1084,7 @@ int vmstate_load_state(QEMUFile *f, const VMStateDescription *vmsd, field++; }if (vmsd->post_load) { -return vmsd->post_load (opaque); +return vmsd->post_load (opaque, version_id); }return 0 ; }
Signature · 1 line
1.6.2.5
PATCH 3/49 vmstate: remove const from pre_save() functions
In reply to Juan Quintela--- exec.c | 4 ++-- hw/fdc.c | 4 ++-- hw/hpet.c | 4 ++-- hw/hw.h | 4 ++-- hw/serial.c | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-)
exec.c +2 -2
@@ -513,9 +513,9 @@ void cpu_exec_init_all(unsigned long tb_size)#if defined(CPU_SAVE_VERSION ) && !defined(CONFIG_USER_ONLY ) -static void cpu_common_pre_save (const void *opaque) +static void cpu_common_pre_save (void *opaque) { -CPUState *env = (void *)opaque; +CPUState *env = opaque;cpu_synchronize_state (env); }
hw/fdc.c +2 -2
@@ -643,9 +643,9 @@ static const VMStateDescription vmstate_fdrive = { } }; -static void fdc_pre_save (const void *opaque) +static void fdc_pre_save (void *opaque) { -fdctrl_t *s = (void *)opaque; +fdctrl_t *s = opaque; s->dor_vmstate = s->dor |GET_CUR_DRV (s); }
hw/hpet.c +2 -2
@@ -157,9 +157,9 @@ static void update_irq(struct HPETTimer *timer) } } -static void hpet_pre_save (const void *opaque) +static void hpet_pre_save (void *opaque) { -HPETState *s = (void *)opaque; +HPETState *s = opaque;/* save current counter value */ s->hpet_counter =hpet_get_ticks (); }
hw/hw.h +2 -2
@@ -308,8 +308,8 @@ struct VMStateDescription {LoadStateHandler *load_state_old;int (*pre_load)(void *opaque);int (*post_load)(void *opaque,int version_id); -void (*pre_save)(const void *opaque); -void (*post_save)(const void *opaque); +void (*pre_save)(void *opaque); +void (*post_save)(void *opaque);VMStateField *fields; };
hw/serial.c +2 -2
@@ -635,9 +635,9 @@ static void serial_event(void *opaque, int event)serial_receive_break (s); } -static void serial_pre_save (const void *opaque) +static void serial_pre_save (void *opaque) { -SerialState *s = (void *)opaque; +SerialState *s = opaque; s->fcr_vmstate = s->fcr; }
Signature · 1 line
1.6.2.5
PATCH 4/49 vmstate: remove ps2_kbd_load_old()
In reply to Juan QuintelaNow that we have version_id on post_load() we don't need the old load function
--- hw/ps2.c | 16 ++++------------ 1 files changed, 4 insertions(+), 12 deletions(-)
hw/ps2.c +4 -12
@@ -541,19 +541,11 @@ static const VMStateDescription vmstate_ps2_common = { } }; -static int ps2_kbd_load_old (QEMUFile * f,void * opaque,int version_id) +static int ps2_kbd_post_load (void * opaque,int version_id) {PS2KbdState *s = (PS2KbdState *)opaque; -if (version_id !=2 && version_id !=3 ) -return -EINVAL ; - -vmstate_load_state (f, &vmstate_ps2_common, &s->common, version_id); - s->scan_enabled=qemu_get_be32 (f); - s->translate=qemu_get_be32 (f); -if (version_id ==3 ) - s->scancode_set=qemu_get_be32 (f); -else +if (version_id ==2 ) s->scancode_set=2 ;return 0 ; }
@@ -561,9 +553,9 @@ static int ps2_kbd_load_old(QEMUFile* f, void* opaque, int version_id)static const VMStateDescription vmstate_ps2_keyboard = { .name ="ps2kbd" , .version_id =3 , - .minimum_version_id =3 , + .minimum_version_id =2 , .minimum_version_id_old =2 , - .load_state_old = ps2_kbd_load_old, + .post_load = ps2_kbd_post_load, .fields = (VMStateField []) {VMSTATE_STRUCT (common, PS2KbdState,0 , vmstate_ps2_common, PS2State),VMSTATE_INT32 (scan_enabled, PS2KbdState),
Signature · 1 line
1.6.2.5
PATCH 5/49 vmstate: Add support for sending partial arrays
In reply to Juan QuintelaThis one is needed for changees happening on fdc. It allows you to send arrays of structs whose size we want to send it is another field with type uint8_t. (If you have been able to read the whole sentence without stoping for breathing, you can use it.
--- hw/hw.h | 12 ++++++++++++ 1 files changed, 12 insertions(+), 0 deletions(-)
hw/hw.h +12 -0
@@ -398,6 +398,18 @@ extern const VMStateInfo vmstate_info_buffer; + type_check_array(_type,typeof_field(_state, _field),_num) \ } +#define VMSTATE_STRUCT_ARRAY_SIZE_UINT8 (_field, _state, _field__num, _version, _vmsd, _type) { \ + .name = (stringify(_field)), \ + .num_offset = offsetof(_state, _field_num) \ + + type_check(uint8_t,typeof_field(_state, _field_num)), \ + .version_id = (_version), \ + .vmsd = &(_vmsd), \ + .size = sizeof(_type), \ + .flags = VMS_STRUCT|VMS_ARRAY, \ + .offset = offsetof(_state, _field) \ + + type_check_array(_type,typeof_field(_state, _field),_num) \ +} +#define VMSTATE_STATIC_BUFFER (_field, _state, _version) { \ .name = (stringify(_field)), \ .version_id = (_version), \
Signature · 1 line
1.6.2.5
PATCH 6/49 qdev: Add support for uint8_t
In reply to Juan Quintela--- hw/qdev-properties.c | 33 +++++++++++++++++++++++++++++++++ hw/qdev.h | 5 +++++ 2 files changed, 38 insertions(+), 0 deletions(-)
hw/qdev-properties.c +33 -0
@@ -8,6 +8,34 @@ void *qdev_get_prop_ptr(DeviceState *dev, Property *prop)return ptr; } +/* --- 8bit integer --- */ + +static int parse_uint8 (DeviceState *dev,Property *prop,const char *str) +{ +uint8_t *ptr =qdev_get_prop_ptr (dev, prop); +const char *fmt; + +/* accept both hex and decimal */ + fmt =strncasecmp (str,"0x" ,2 ) ==0 ?"%" PRIx8 :"%" PRIu8; +if (sscanf (str, fmt, ptr) !=1 ) +return -1 ; +return 0 ; +} + +static int print_uint8 (DeviceState *dev,Property *prop,char *dest,size_t len) +{ +uint8_t *ptr =qdev_get_prop_ptr (dev, prop); +return snprintf (dest, len,"%" PRIu8, *ptr); +} + +PropertyInfo qdev_prop_uint8 = { + .name ="uint8" , + .type =PROP_TYPE_UINT8 , + .size =sizeof (uint8_t ), + .parse = parse_uint8, + .print = print_uint8, +}; +/* --- 16bit integer --- */ static int parse_uint16 (DeviceState *dev,Property *prop,const char *str)
@@ -391,6 +419,11 @@ void qdev_prop_set(DeviceState *dev, const char *name, void *src, enum PropertyTmemcpy (dst, src, prop->info->size); } +void qdev_prop_set_uint8 (DeviceState *dev,const char *name,uint8_t value) +{ +qdev_prop_set (dev, name, &value,PROP_TYPE_UINT8 ); +} +void qdev_prop_set_uint16 (DeviceState *dev,const char *name,uint16_t value) {qdev_prop_set (dev, name, &value,PROP_TYPE_UINT16 );
hw/qdev.h +5 -0
@@ -60,6 +60,7 @@ struct Property {enum PropertyType {PROP_TYPE_UNSPEC =0 , +PROP_TYPE_UINT8 ,PROP_TYPE_UINT16 ,PROP_TYPE_UINT32 ,PROP_TYPE_INT32 ,
@@ -155,6 +156,7 @@ void do_info_qdm(Monitor *mon);/*** qdev-properties.c ***/ +extern PropertyInfo qdev_prop_uint8;extern PropertyInfo qdev_prop_uint16;extern PropertyInfo qdev_prop_uint32;extern PropertyInfo qdev_prop_int32;
@@ -181,6 +183,8 @@ extern PropertyInfo qdev_prop_pci_devfn; .defval = (_type[]) { _defval }, \ } +#define DEFINE_PROP_UINT8 (_n, _s, _f, _d) \ + DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_uint8, uint8_t)#define DEFINE_PROP_UINT16 (_n, _s, _f, _d) \ DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_uint16, uint16_t)#define DEFINE_PROP_UINT32 (_n, _s, _f, _d) \
@@ -212,6 +216,7 @@ extern PropertyInfo qdev_prop_pci_devfn;void *qdev_get_prop_ptr (DeviceState *dev,Property *prop);int qdev_prop_parse (DeviceState *dev,const char *name,const char *value);void qdev_prop_set (DeviceState *dev,const char *name,void *src,enum PropertyType type); +void qdev_prop_set_uint8 (DeviceState *dev,const char *name,uint8_t value);void qdev_prop_set_uint16 (DeviceState *dev,const char *name,uint16_t value);void qdev_prop_set_uint32 (DeviceState *dev,const char *name,uint32_t value);void qdev_prop_set_int32 (DeviceState *dev,const char *name,int32_t value);
Signature · 1 line
1.6.2.5
PATCH 7/49 i2c: addresses are load/save as uint8_t values, change types to reflect this
In reply to Juan Quintela--- hw/i2c.c | 21 +++++++++++---------- hw/i2c.h | 8 ++++---- hw/mips_malta.c | 2 +- hw/pc.c | 2 +- hw/smbus.c | 18 +++++++++--------- hw/smbus.h | 18 +++++++++--------- 6 files changed, 35 insertions(+), 34 deletions(-)
hw/i2c.c +11 -10
@@ -14,14 +14,14 @@ struct i2c_busBusState qbus;i2c_slave *current_dev;i2c_slave *dev; -int saved_address; +uint8_t saved_address; };static struct BusInfo i2c_bus_info = { .name ="I2C" , .size =sizeof (i2c_bus), .props = (Property []) { - DEFINE_PROP_UINT32("address", struct i2c_slave, address, 0), + DEFINE_PROP_UINT8("address", struct i2c_slave, address, 0),DEFINE_PROP_END_OF_LIST (), } };
@@ -29,8 +29,9 @@ static struct BusInfo i2c_bus_info = {static void i2c_bus_save (QEMUFile *f,void *opaque) {i2c_bus *bus = (i2c_bus *)opaque; + bus->saved_address = bus->current_dev ? bus->current_dev->address :-1 ; -qemu_put_byte (f, bus->current_dev ? bus->current_dev->address :-1 ); +qemu_put_8s (f, &bus->saved_address); }static int i2c_bus_load (QEMUFile *f,void *opaque,int version_id)
@@ -42,7 +43,7 @@ static int i2c_bus_load(QEMUFile *f, void *opaque, int version_id)/* The bus is loaded before attached devices, so load and save the current device id. Devices will check themselves as loaded. */ - bus->saved_address = (int8_t )qemu_get_byte (f); +qemu_get_8s (f, &bus->saved_address); bus->current_dev =NULL ;return 0 ;
@@ -58,7 +59,7 @@ i2c_bus *i2c_init_bus(DeviceState *parent, const char *name)return bus; } -void i2c_set_slave_address (i2c_slave *dev,int address) +void i2c_set_slave_address (i2c_slave *dev,uint8_t address) { dev->address = address; }
@@ -71,7 +72,7 @@ int i2c_bus_busy(i2c_bus *bus)/* Returns non-zero if the address is not valid. */ /* TODO: Make this handle multiple masters. */ -int i2c_start_transfer (i2c_bus *bus,int address,int recv) +int i2c_start_transfer (i2c_bus *bus,uint8_t address,int recv) {DeviceState *qdev;i2c_slave *slave =NULL ;
@@ -136,14 +137,14 @@ void i2c_nack(i2c_bus *bus)void i2c_slave_save (QEMUFile *f,i2c_slave *dev) { -qemu_put_byte (f, dev->address); +qemu_put_8s (f, &dev->address); }void i2c_slave_load (QEMUFile *f,i2c_slave *dev) {i2c_bus *bus; bus =FROM_QBUS (i2c_bus,qdev_get_parent_bus (&dev->qdev)); - dev->address =qemu_get_byte (f); +qemu_get_8s (f, &dev->address);if (bus->saved_address == dev->address) { bus->current_dev = dev; }
@@ -167,12 +168,12 @@ void i2c_register_slave(I2CSlaveInfo *info)qdev_register (&info->qdev); } -DeviceState *i2c_create_slave (i2c_bus *bus,const char *name,int addr) +DeviceState *i2c_create_slave (i2c_bus *bus,const char *name,uint8_t addr) {DeviceState *dev; dev =qdev_create (&bus->qbus, name); -qdev_prop_set_uint32 (dev,"address" , addr); +qdev_prop_set_uint8 (dev,"address" , addr);qdev_init (dev);return dev; }
hw/i2c.h +4 -4
@@ -40,13 +40,13 @@ struct i2c_slaveI2CSlaveInfo *info;/* Remaining fields for internal use by the I2C code. */ -uint32_t address; +uint8_t address; };i2c_bus *i2c_init_bus (DeviceState *parent,const char *name); -void i2c_set_slave_address (i2c_slave *dev,int address); +void i2c_set_slave_address (i2c_slave *dev,uint8_t address);int i2c_bus_busy (i2c_bus *bus); -int i2c_start_transfer (i2c_bus *bus,int address,int recv); +int i2c_start_transfer (i2c_bus *bus,uint8_t address,int recv);void i2c_end_transfer (i2c_bus *bus);void i2c_nack (i2c_bus *bus);int i2c_send (i2c_bus *bus,uint8_t data);
@@ -59,7 +59,7 @@ void i2c_slave_load(QEMUFile *f, i2c_slave *dev);void i2c_register_slave (I2CSlaveInfo *type); -DeviceState *i2c_create_slave (i2c_bus *bus,const char *name,int addr); +DeviceState *i2c_create_slave (i2c_bus *bus,const char *name,uint8_t addr);/* max7310.c */ void max7310_reset (i2c_slave *i2c);
hw/mips_malta.c +1 -1
@@ -931,7 +931,7 @@ void mips_malta_init (ram_addr_t ram_size,/* TODO: Populate SPD eeprom data. */ DeviceState *eeprom; eeprom =qdev_create ((BusState *)smbus,"smbus-eeprom" ); -qdev_prop_set_uint32 (eeprom,"address" ,0x50 + i); +qdev_prop_set_uint8 (eeprom,"address" ,0x50 + i);qdev_prop_set_ptr (eeprom,"data" , eeprom_buf + (i *256 ));qdev_init (eeprom); }
hw/pc.c +1 -1
@@ -1402,7 +1402,7 @@ static void pc_init1(ram_addr_t ram_size,for (i =0 ; i <8 ; i++) {DeviceState *eeprom; eeprom =qdev_create ((BusState *)smbus,"smbus-eeprom" ); -qdev_prop_set_uint32 (eeprom,"address" ,0x50 + i); +qdev_prop_set_uint8 (eeprom,"address" ,0x50 + i);qdev_prop_set_ptr (eeprom,"data" , eeprom_buf + (i *256 ));qdev_init (eeprom); }
hw/smbus.c +9 -9
@@ -217,13 +217,13 @@ void smbus_register_device(SMBusDeviceInfo *info) }/* Master device commands. */ -void smbus_quick_command (i2c_bus *bus,int addr,int read) +void smbus_quick_command (i2c_bus *bus,uint8_t addr,int read) {i2c_start_transfer (bus, addr, read);i2c_end_transfer (bus); } -uint8_t smbus_receive_byte (i2c_bus *bus,int addr) +uint8_t smbus_receive_byte (i2c_bus *bus,uint8_t addr) {uint8_t data;
@@ -234,14 +234,14 @@ uint8_t smbus_receive_byte(i2c_bus *bus, int addr)return data; } -void smbus_send_byte (i2c_bus *bus,int addr,uint8_t data) +void smbus_send_byte (i2c_bus *bus,uint8_t addr,uint8_t data) {i2c_start_transfer (bus, addr,0 );i2c_send (bus, data);i2c_end_transfer (bus); } -uint8_t smbus_read_byte (i2c_bus *bus,int addr,uint8_t command) +uint8_t smbus_read_byte (i2c_bus *bus,uint8_t addr,uint8_t command) {uint8_t data;i2c_start_transfer (bus, addr,0 );
@@ -253,7 +253,7 @@ uint8_t smbus_read_byte(i2c_bus *bus, int addr, uint8_t command)return data; } -void smbus_write_byte (i2c_bus *bus,int addr,uint8_t command,uint8_t data) +void smbus_write_byte (i2c_bus *bus,uint8_t addr,uint8_t command,uint8_t data) {i2c_start_transfer (bus, addr,0 );i2c_send (bus, command);
@@ -261,7 +261,7 @@ void smbus_write_byte(i2c_bus *bus, int addr, uint8_t command, uint8_t data)i2c_end_transfer (bus); } -uint16_t smbus_read_word (i2c_bus *bus,int addr,uint8_t command) +uint16_t smbus_read_word (i2c_bus *bus,uint8_t addr,uint8_t command) {uint16_t data;i2c_start_transfer (bus, addr,0 );
@@ -274,7 +274,7 @@ uint16_t smbus_read_word(i2c_bus *bus, int addr, uint8_t command)return data; } -void smbus_write_word (i2c_bus *bus,int addr,uint8_t command,uint16_t data) +void smbus_write_word (i2c_bus *bus,uint8_t addr,uint8_t command,uint16_t data) {i2c_start_transfer (bus, addr,0 );i2c_send (bus, command);
@@ -283,7 +283,7 @@ void smbus_write_word(i2c_bus *bus, int addr, uint8_t command, uint16_t data)i2c_end_transfer (bus); } -int smbus_read_block (i2c_bus *bus,int addr,uint8_t command,uint8_t *data) +int smbus_read_block (i2c_bus *bus,uint8_t addr,uint8_t command,uint8_t *data) {int len;int i;
@@ -301,7 +301,7 @@ int smbus_read_block(i2c_bus *bus, int addr, uint8_t command, uint8_t *data)return len; } -void smbus_write_block (i2c_bus *bus,int addr,uint8_t command,uint8_t *data, +void smbus_write_block (i2c_bus *bus,uint8_t addr,uint8_t command,uint8_t *data,int len) {int i;
hw/smbus.h +9 -9
@@ -56,13 +56,13 @@ typedef struct {void smbus_register_device (SMBusDeviceInfo *info);/* Master device commands. */ -void smbus_quick_command (i2c_bus *bus,int addr,int read); -uint8_t smbus_receive_byte (i2c_bus *bus,int addr); -void smbus_send_byte (i2c_bus *bus,int addr,uint8_t data); -uint8_t smbus_read_byte (i2c_bus *bus,int addr,uint8_t command); -void smbus_write_byte (i2c_bus *bus,int addr,uint8_t command,uint8_t data); -uint16_t smbus_read_word (i2c_bus *bus,int addr,uint8_t command); -void smbus_write_word (i2c_bus *bus,int addr,uint8_t command,uint16_t data); -int smbus_read_block (i2c_bus *bus,int addr,uint8_t command,uint8_t *data); -void smbus_write_block (i2c_bus *bus,int addr,uint8_t command,uint8_t *data, +void smbus_quick_command (i2c_bus *bus,uint8_t addr,int read); +uint8_t smbus_receive_byte (i2c_bus *bus,uint8_t addr); +void smbus_send_byte (i2c_bus *bus,uint8_t addr,uint8_t data); +uint8_t smbus_read_byte (i2c_bus *bus,uint8_t addr,uint8_t command); +void smbus_write_byte (i2c_bus *bus,uint8_t addr,uint8_t command,uint8_t data); +uint16_t smbus_read_word (i2c_bus *bus,uint8_t addr,uint8_t command); +void smbus_write_word (i2c_bus *bus,uint8_t addr,uint8_t command,uint16_t data); +int smbus_read_block (i2c_bus *bus,uint8_t addr,uint8_t command,uint8_t *data); +void smbus_write_block (i2c_bus *bus,uint8_t addr,uint8_t command,uint8_t *data,int len);
Signature · 1 line
1.6.2.5
PATCH 8/49 vmstate: port i2c_bus device
In reply to Juan Quintela--- hw/i2c.c | 31 +++++++++++++++++++------------ 1 files changed, 19 insertions(+), 12 deletions(-)
hw/i2c.c +19 -12
@@ -26,36 +26,43 @@ static struct BusInfo i2c_bus_info = { } }; -static void i2c_bus_save (QEMUFile *f,void *opaque) +static void i2c_bus_pre_save (void *opaque) { -i2c_bus *bus = (i2c_bus *)opaque; - bus->saved_address = bus->current_dev ? bus->current_dev->address :-1 ; +i2c_bus *bus = opaque; -qemu_put_8s (f, &bus->saved_address); + bus->saved_address = bus->current_dev ? bus->current_dev->address :-1 ; } -static int i2c_bus_load (QEMUFile *f,void *opaque,int version_id) +static int i2c_bus_post_load (void *opaque,int version_id) { -i2c_bus *bus = (i2c_bus *)opaque; - -if (version_id !=1 ) -return -EINVAL ; +i2c_bus *bus = opaque;/* The bus is loaded before attached devices, so load and save the current device id. Devices will check themselves as loaded. */ -qemu_get_8s (f, &bus->saved_address); bus->current_dev =NULL ; -return 0 ; } +static const VMStateDescription vmstate_i2c_bus = { + .name ="i2c_bus" , + .version_id =1 , + .minimum_version_id =1 , + .minimum_version_id_old =1 , + .pre_save = i2c_bus_pre_save, + .post_load = i2c_bus_post_load, + .fields = (VMStateField []) { +VMSTATE_UINT8 (saved_address, i2c_bus), +VMSTATE_END_OF_LIST () + } +}; +/* Create a new I2C bus. */ i2c_bus *i2c_init_bus (DeviceState *parent,const char *name) {i2c_bus *bus; bus =FROM_QBUS (i2c_bus,qbus_create (&i2c_bus_info, parent, name)); -register_savevm ("i2c_bus" ,-1 ,1 , i2c_bus_save, i2c_bus_load, bus); +vmstate_register (-1 , &vmstate_i2c_bus, bus);return bus; }
Signature · 1 line
1.6.2.5
PATCH 9/49 vmstate: port i2c_slave device
In reply to Juan Quintela--- hw/i2c.c | 33 ++++++++++++++++++++++++++------- 1 files changed, 26 insertions(+), 7 deletions(-)
hw/i2c.c +26 -7
@@ -142,19 +142,38 @@ void i2c_nack(i2c_bus *bus) dev->info->event (dev,I2C_NACK ); } -void i2c_slave_save (QEMUFile *f,i2c_slave *dev) -{ -qemu_put_8s (f, &dev->address); -} - -void i2c_slave_load (QEMUFile *f,i2c_slave *dev) +static int i2c_slave_post_load (void *opaque,int version_id) { +i2c_slave *dev = opaque;i2c_bus *bus; bus =FROM_QBUS (i2c_bus,qdev_get_parent_bus (&dev->qdev)); -qemu_get_8s (f, &dev->address);if (bus->saved_address == dev->address) { bus->current_dev = dev; } +return 0 ; +} + +static const VMStateDescription vmstate_i2c_slave = { + .name ="i2c_slave" , + .version_id =1 , + .minimum_version_id =1 , + .minimum_version_id_old =1 , + .post_load = i2c_slave_post_load, + .fields = (VMStateField []) { +VMSTATE_UINT8 (address, i2c_slave), +VMSTATE_END_OF_LIST () + } +}; + +void i2c_slave_save (QEMUFile *f,i2c_slave *dev) +{ +vmstate_save_state (f, &vmstate_i2c_slave, dev); +} + +void i2c_slave_load (QEMUFile *f,i2c_slave *dev) +{ +vmstate_load_state (f, &vmstate_i2c_slave, dev, + vmstate_i2c_slave.version_id); }static int i2c_slave_qdev_init (DeviceState *dev,DeviceInfo *base)
Signature · 1 line
1.6.2.5
PATCH 10/49 vmstate: add uint8 array
In reply to Juan Quintela--- hw/hw.h | 6 ++++++ 1 files changed, 6 insertions(+), 0 deletions(-)
hw/hw.h +6 -0
@@ -510,6 +510,12 @@ extern const VMStateDescription vmstate_pci_device;#define VMSTATE_UINT16_ARRAY (_f, _s, _n) \ VMSTATE_UINT16_ARRAY_V(_f, _s, _n, 0) +#define VMSTATE_UINT8_ARRAY_V (_f, _s, _n, _v) \ + VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_uint8, uint8_t) + +#define VMSTATE_UINT8_ARRAY (_f, _s, _n) \ + VMSTATE_UINT8_ARRAY_V(_f, _s, _n, 0) +#define VMSTATE_UINT32_ARRAY_V (_f, _s, _n, _v) \ VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_uint32, uint32_t)
Signature · 1 line
1.6.2.5
PATCH 11/49 vmstate: create VMSTATE_I2C_SLAVE
In reply to Juan Quintela--- hw/hw.h | 11 +++++++++++ hw/i2c.c | 2 +- 2 files changed, 12 insertions(+), 1 deletions(-)
hw/hw.h +11 -0
@@ -440,6 +440,17 @@ extern const VMStateDescription vmstate_pci_device; + type_check(PCIDevice,typeof_field(_state, _field)) \ } +extern const VMStateDescription vmstate_i2c_slave; + +#define VMSTATE_I2C_SLAVE (_field, _state) { \ + .name = (stringify(_field)), \ + .size = sizeof(i2c_slave), \ + .vmsd = &vmstate_i2c_slave, \ + .flags = VMS_STRUCT, \ + .offset = offsetof(_state, _field) \ + + type_check(i2c_slave,typeof_field(_state, _field)) \ +} +/* _f : field name _f_n : num of elements field_name _n : num of elements
hw/i2c.c +1 -1
@@ -153,7 +153,7 @@ static int i2c_slave_post_load(void *opaque, int version_id)return 0 ; } -static const VMStateDescription vmstate_i2c_slave = { +const VMStateDescription vmstate_i2c_slave = { .name ="i2c_slave" , .version_id =1 , .minimum_version_id =1 ,
Signature · 1 line
1.6.2.5
PATCH 12/49 vmstate: port wm8750 device
In reply to Juan Quintela--- hw/wm8750.c | 120 ++++++++++++++++++++++------------------------------------- 1 files changed, 45 insertions(+), 75 deletions(-)
hw/wm8750.c +45 -75
@@ -46,6 +46,7 @@ typedef struct {uint8_t diff[2 ], pol, ds, monomix[2 ], alc, mute;uint8_t path[4 ], mpath[2 ], power, format;const WMRate *rate; +uint8_t rate_vmstate;int adc_hz, dac_hz, ext_adc_hz, ext_dac_hz, master; } WM8750State;
@@ -564,87 +565,56 @@ static int wm8750_rx(i2c_slave *i2c)return 0x00 ; } -static void wm8750_save (QEMUFile *f,void *opaque) +static void wm8750_pre_save (void *opaque) { -WM8750State *s = (WM8750State *) opaque; -int i; -qemu_put_8s (f, &s->i2c_data[0 ]); -qemu_put_8s (f, &s->i2c_data[1 ]); -qemu_put_be32 (f, s->i2c_len); -qemu_put_be32 (f, s->enable); -qemu_put_be32 (f, s->idx_in); -qemu_put_be32 (f, s->req_in); -qemu_put_be32 (f, s->idx_out); -qemu_put_be32 (f, s->req_out); - -for (i =0 ; i <7 ; i ++) -qemu_put_8s (f, &s->outvol[i]); -for (i =0 ; i <2 ; i ++) -qemu_put_8s (f, &s->outmute[i]); -for (i =0 ; i <4 ; i ++) -qemu_put_8s (f, &s->invol[i]); -for (i =0 ; i <2 ; i ++) -qemu_put_8s (f, &s->inmute[i]); - -for (i =0 ; i <2 ; i ++) -qemu_put_8s (f, &s->diff[i]); -qemu_put_8s (f, &s->pol); -qemu_put_8s (f, &s->ds); -for (i =0 ; i <2 ; i ++) -qemu_put_8s (f, &s->monomix[i]); -qemu_put_8s (f, &s->alc); -qemu_put_8s (f, &s->mute); -for (i =0 ; i <4 ; i ++) -qemu_put_8s (f, &s->path[i]); -for (i =0 ; i <2 ; i ++) -qemu_put_8s (f, &s->mpath[i]); -qemu_put_8s (f, &s->format); -qemu_put_8s (f, &s->power); -qemu_put_byte (f, (s->rate - wm_rate_table) /sizeof (*s->rate)); -i2c_slave_save (f, &s->i2c); +WM8750State *s = opaque; + + s->rate_vmstate = (s->rate - wm_rate_table) /sizeof (*s->rate); } -static int wm8750_load (QEMUFile *f,void *opaque,int version_id) +static int wm8750_post_load (void *opaque,int version_id) { -WM8750State *s = (WM8750State *) opaque; -int i; -qemu_get_8s (f, &s->i2c_data[0 ]); -qemu_get_8s (f, &s->i2c_data[1 ]); - s->i2c_len =qemu_get_be32 (f); - s->enable =qemu_get_be32 (f); - s->idx_in =qemu_get_be32 (f); - s->req_in =qemu_get_be32 (f); - s->idx_out =qemu_get_be32 (f); - s->req_out =qemu_get_be32 (f); - -for (i =0 ; i <7 ; i ++) -qemu_get_8s (f, &s->outvol[i]); -for (i =0 ; i <2 ; i ++) -qemu_get_8s (f, &s->outmute[i]); -for (i =0 ; i <4 ; i ++) -qemu_get_8s (f, &s->invol[i]); -for (i =0 ; i <2 ; i ++) -qemu_get_8s (f, &s->inmute[i]); - -for (i =0 ; i <2 ; i ++) -qemu_get_8s (f, &s->diff[i]); -qemu_get_8s (f, &s->pol); -qemu_get_8s (f, &s->ds); -for (i =0 ; i <2 ; i ++) -qemu_get_8s (f, &s->monomix[i]); -qemu_get_8s (f, &s->alc); -qemu_get_8s (f, &s->mute); -for (i =0 ; i <4 ; i ++) -qemu_get_8s (f, &s->path[i]); -for (i =0 ; i <2 ; i ++) -qemu_get_8s (f, &s->mpath[i]); -qemu_get_8s (f, &s->format); -qemu_get_8s (f, &s->power); - s->rate = &wm_rate_table[(uint8_t )qemu_get_byte (f) &0x1f ]; -i2c_slave_load (f, &s->i2c); +WM8750State *s = opaque; + + s->rate = &wm_rate_table[s->rate_vmstate &0x1f ];return 0 ; } +static const VMStateDescription vmstate_wm8750 = { + .name =CODEC , + .version_id =0 , + .minimum_version_id =0 , + .minimum_version_id_old =0 , + .pre_save = wm8750_pre_save, + .post_load = wm8750_post_load, + .fields = (VMStateField []) { +VMSTATE_UINT8_ARRAY (i2c_data, WM8750State,2 ), +VMSTATE_INT32 (i2c_len, WM8750State), +VMSTATE_INT32 (enable, WM8750State), +VMSTATE_INT32 (idx_in, WM8750State), +VMSTATE_INT32 (req_in, WM8750State), +VMSTATE_INT32 (idx_out, WM8750State), +VMSTATE_INT32 (req_out, WM8750State), +VMSTATE_UINT8_ARRAY (outvol, WM8750State,7 ), +VMSTATE_UINT8_ARRAY (outmute, WM8750State,2 ), +VMSTATE_UINT8_ARRAY (invol, WM8750State,4 ), +VMSTATE_UINT8_ARRAY (inmute, WM8750State,2 ), +VMSTATE_UINT8_ARRAY (diff, WM8750State,2 ), +VMSTATE_UINT8 (pol, WM8750State), +VMSTATE_UINT8 (ds, WM8750State), +VMSTATE_UINT8_ARRAY (monomix, WM8750State,2 ), +VMSTATE_UINT8 (alc, WM8750State), +VMSTATE_UINT8 (mute, WM8750State), +VMSTATE_UINT8_ARRAY (path, WM8750State,4 ), +VMSTATE_UINT8_ARRAY (mpath, WM8750State,2 ), +VMSTATE_UINT8 (format, WM8750State), +VMSTATE_UINT8 (power, WM8750State), +VMSTATE_UINT8 (rate_vmstate, WM8750State), +VMSTATE_I2C_SLAVE (i2c, WM8750State), +VMSTATE_END_OF_LIST () + } +}; +static int wm8750_init (i2c_slave *i2c) {WM8750State *s =FROM_I2C_SLAVE (WM8750State, i2c);
@@ -652,7 +622,7 @@ static int wm8750_init(i2c_slave *i2c)AUD_register_card (CODEC , &s->card);wm8750_reset (&s->i2c); -register_savevm (CODEC ,-1 ,0 , wm8750_save, wm8750_load, s); +vmstate_register (-1 , &vmstate_wm8750, s);return 0 ; }
Signature · 1 line
1.6.2.5
PATCH 13/49 vmstate: port max7310 device
In reply to Juan Quintela--- hw/max7310.c | 51 ++++++++++++++++++--------------------------------- 1 files changed, 18 insertions(+), 33 deletions(-)
hw/max7310.c +18 -33
@@ -143,38 +143,23 @@ static void max7310_event(i2c_slave *i2c, enum i2c_event event) } } -static void max7310_save (QEMUFile *f,void *opaque) -{ -MAX7310State *s = (MAX7310State *) opaque; - -qemu_put_be32 (f, s->i2c_command_byte); -qemu_put_be32 (f, s->len); - -qemu_put_8s (f, &s->level); -qemu_put_8s (f, &s->direction); -qemu_put_8s (f, &s->polarity); -qemu_put_8s (f, &s->status); -qemu_put_8s (f, &s->command); - -i2c_slave_save (f, &s->i2c); -} - -static int max7310_load (QEMUFile *f,void *opaque,int version_id) -{ -MAX7310State *s = (MAX7310State *) opaque; - - s->i2c_command_byte =qemu_get_be32 (f); - s->len =qemu_get_be32 (f); - -qemu_get_8s (f, &s->level); -qemu_get_8s (f, &s->direction); -qemu_get_8s (f, &s->polarity); -qemu_get_8s (f, &s->status); -qemu_get_8s (f, &s->command); - -i2c_slave_load (f, &s->i2c); -return 0 ; -} +static const VMStateDescription vmstate_max7310 = { + .name ="max7310" , + .version_id =0 , + .minimum_version_id =0 , + .minimum_version_id_old =0 , + .fields = (VMStateField []) { +VMSTATE_INT32 (i2c_command_byte, MAX7310State), +VMSTATE_INT32 (len, MAX7310State), +VMSTATE_UINT8 (level, MAX7310State), +VMSTATE_UINT8 (direction, MAX7310State), +VMSTATE_UINT8 (polarity, MAX7310State), +VMSTATE_UINT8 (status, MAX7310State), +VMSTATE_UINT8 (command, MAX7310State), +VMSTATE_I2C_SLAVE (i2c, MAX7310State), +VMSTATE_END_OF_LIST () + } +};static void max7310_gpio_set (void *opaque,int line,int level) {
@@ -199,7 +184,7 @@ static int max7310_init(i2c_slave *i2c)max7310_reset (&s->i2c); -register_savevm ("max7310" ,-1 ,0 , max7310_save, max7310_load, s); +vmstate_register (-1 , &vmstate_max7310, s);return 0 ; }
Signature · 1 line
1.6.2.5
PATCH 14/49 vmstate: create VMSTATE_STRUCT_POINTER
In reply to Juan Quintela--- hw/hw.h | 9 +++++++++ 1 files changed, 9 insertions(+), 0 deletions(-)
hw/hw.h +9 -0
@@ -387,6 +387,15 @@ extern const VMStateInfo vmstate_info_buffer; + type_check(_type,typeof_field(_state, _field)) \ } +#define VMSTATE_STRUCT_POINTER (_field, _state, _vmsd, _type) { \ + .name = (stringify(_field)), \ + .vmsd = &(_vmsd), \ + .size = sizeof(_type), \ + .flags = VMS_STRUCT|VMS_POINTER, \ + .offset = offsetof(_state, _field) \ + + type_check(_type,typeof_field(_state, _field)) \ +} +#define VMSTATE_STRUCT_ARRAY (_field, _state, _num, _version, _vmsd, _type) { \ .name = (stringify(_field)), \ .num = (_num), \
Signature · 1 line
1.6.2.5
PATCH 15/49 vmstate: port pxa2xx_i2c device
In reply to Juan Quintela--- hw/pxa2xx.c | 54 ++++++++++++++++++++++++++---------------------------- 1 files changed, 26 insertions(+), 28 deletions(-)
hw/pxa2xx.c +26 -28
@@ -1452,33 +1452,32 @@ static CPUWriteMemoryFunc * const pxa2xx_i2c_writefn[] = { pxa2xx_i2c_write, }; -static void pxa2xx_i2c_save (QEMUFile *f,void *opaque) -{ -PXA2xxI2CState *s = (PXA2xxI2CState *) opaque; - -qemu_put_be16s (f, &s->control); -qemu_put_be16s (f, &s->status); -qemu_put_8s (f, &s->ibmr); -qemu_put_8s (f, &s->data); - -i2c_slave_save (f, &s->slave->i2c); -} - -static int pxa2xx_i2c_load (QEMUFile *f,void *opaque,int version_id) -{ -PXA2xxI2CState *s = (PXA2xxI2CState *) opaque; - -if (version_id !=1 ) -return -EINVAL ; - -qemu_get_be16s (f, &s->control); -qemu_get_be16s (f, &s->status); -qemu_get_8s (f, &s->ibmr); -qemu_get_8s (f, &s->data); +static const VMStateDescription vmstate_pxa2xx_i2c_slave = { + .name ="pxa2xx_i2c_slave" , + .version_id =1 , + .minimum_version_id =1 , + .minimum_version_id_old =1 , + .fields = (VMStateField []) { +VMSTATE_I2C_SLAVE (i2c, PXA2xxI2CSlaveState), +VMSTATE_END_OF_LIST () + } +}; -i2c_slave_load (f, &s->slave->i2c); -return 0 ; -} +static const VMStateDescription vmstate_pxa2xx_i2c = { + .name ="pxa2xx_i2c" , + .version_id =1 , + .minimum_version_id =1 , + .minimum_version_id_old =1 , + .fields = (VMStateField []) { +VMSTATE_UINT16 (control, PXA2xxI2CState), +VMSTATE_UINT16 (status, PXA2xxI2CState), +VMSTATE_UINT8 (ibmr, PXA2xxI2CState), +VMSTATE_UINT8 (data, PXA2xxI2CState), +VMSTATE_STRUCT_POINTER (slave, PXA2xxI2CState, + vmstate_pxa2xx_i2c, PXA2xxI2CSlaveState *), +VMSTATE_END_OF_LIST () + } +};static int pxa2xx_i2c_slave_init (i2c_slave *i2c) {
@@ -1516,8 +1515,7 @@ PXA2xxI2CState *pxa2xx_i2c_init(target_phys_addr_t base,cpu_register_physical_memory (base & ~region_size, region_size +1 , iomemtype); -register_savevm ("pxa2xx_i2c" , base,1 , - pxa2xx_i2c_save, pxa2xx_i2c_load, s); +vmstate_register (base, &vmstate_pxa2xx_i2c, s);return s; }
Signature · 1 line
1.6.2.5
PATCH 16/49 vmstate: port ssd0303 device
In reply to Juan Quintela--- hw/ssd0303.c | 65 +++++++++++++++++++-------------------------------------- 1 files changed, 22 insertions(+), 43 deletions(-)
hw/ssd0303.c +22 -43
@@ -261,48 +261,27 @@ static void ssd0303_invalidate_display(void * opaque) s->redraw =1 ; } -static void ssd0303_save (QEMUFile *f,void *opaque) -{ -ssd0303_state *s = (ssd0303_state *)opaque; - -qemu_put_be32 (f, s->row); -qemu_put_be32 (f, s->col); -qemu_put_be32 (f, s->start_line); -qemu_put_be32 (f, s->mirror); -qemu_put_be32 (f, s->flash); -qemu_put_be32 (f, s->enabled); -qemu_put_be32 (f, s->inverse); -qemu_put_be32 (f, s->redraw); -qemu_put_be32 (f, s->mode); -qemu_put_be32 (f, s->cmd_state); -qemu_put_buffer (f, s->framebuffer,sizeof (s->framebuffer)); - -i2c_slave_save (f, &s->i2c); -} - -static int ssd0303_load (QEMUFile *f,void *opaque,int version_id) -{ -ssd0303_state *s = (ssd0303_state *)opaque; - -if (version_id !=1 ) -return -EINVAL ; - - s->row =qemu_get_be32 (f); - s->col =qemu_get_be32 (f); - s->start_line =qemu_get_be32 (f); - s->mirror =qemu_get_be32 (f); - s->flash =qemu_get_be32 (f); - s->enabled =qemu_get_be32 (f); - s->inverse =qemu_get_be32 (f); - s->redraw =qemu_get_be32 (f); - s->mode =qemu_get_be32 (f); - s->cmd_state =qemu_get_be32 (f); -qemu_get_buffer (f, s->framebuffer,sizeof (s->framebuffer)); - -i2c_slave_load (f, &s->i2c); - -return 0 ; -} +static const VMStateDescription vmstate_ssd0303 = { + .name ="ssd0303_oled" , + .version_id =1 , + .minimum_version_id =1 , + .minimum_version_id_old =1 , + .fields = (VMStateField []) { +VMSTATE_INT32 (row, ssd0303_state), +VMSTATE_INT32 (col, ssd0303_state), +VMSTATE_INT32 (start_line, ssd0303_state), +VMSTATE_INT32 (mirror, ssd0303_state), +VMSTATE_INT32 (flash, ssd0303_state), +VMSTATE_INT32 (enabled, ssd0303_state), +VMSTATE_INT32 (inverse, ssd0303_state), +VMSTATE_INT32 (redraw, ssd0303_state), +VMSTATE_UINT32 (mode, ssd0303_state), +VMSTATE_UINT32 (cmd_state, ssd0303_state), +VMSTATE_BUFFER (framebuffer, ssd0303_state), +VMSTATE_I2C_SLAVE (i2c, ssd0303_state), +VMSTATE_END_OF_LIST () + } +};static int ssd0303_init (i2c_slave *i2c) {
@@ -312,7 +291,7 @@ static int ssd0303_init(i2c_slave *i2c) ssd0303_invalidate_display, NULL, NULL, s);qemu_console_resize (s->ds,96 *MAGNIFY ,16 *MAGNIFY ); -register_savevm ("ssd0303_oled" ,-1 ,1 , ssd0303_save, ssd0303_load, s); +vmstate_register (-1 , &vmstate_ssd0303, s);return 0 ; }
Signature · 1 line
1.6.2.5
PATCH 17/49 vmstate: create VMSTATE_INT16_ARRAY
In reply to Juan Quintela--- hw/hw.h | 6 ++++++ 1 files changed, 6 insertions(+), 0 deletions(-)
hw/hw.h +6 -0
@@ -548,6 +548,12 @@ extern const VMStateDescription vmstate_i2c_slave;#define VMSTATE_UINT64_ARRAY (_f, _s, _n) \ VMSTATE_UINT64_ARRAY_V(_f, _s, _n, 0) +#define VMSTATE_INT16_ARRAY_V (_f, _s, _n, _v) \ + VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_int16, int16_t) + +#define VMSTATE_INT16_ARRAY (_f, _s, _n) \ + VMSTATE_INT16_ARRAY_V(_f, _s, _n, 0) +#define VMSTATE_INT32_ARRAY_V (_f, _s, _n, _v) \ VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_int32, int32_t)
Signature · 1 line
1.6.2.5
PATCH 18/49 tmp105: change len and alorm to uint8_t
In reply to Juan QuintelaThey were using only with very small integers, and they are sent/read as bytes. They can't become negative as far as I can see
--- hw/tmp105.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
hw/tmp105.c +2 -2
@@ -23,7 +23,7 @@ typedef struct { i2c_slave i2c; - int len; + uint8_t len; uint8_t buf[2]; qemu_irq pin;
@@ -32,7 +32,7 @@ typedef struct {int16_t temperature;int16_t limit[2 ];int faults; -int alarm; +uint8_t alarm; } TMP105State;static void tmp105_interrupt_update (TMP105State *s)
Signature · 1 line
1.6.2.5
PATCH 19/49 vmstate: port tmp105 device
In reply to Juan Quintela--- hw/tmp105.c | 56 +++++++++++++++++++++++++------------------------------- 1 files changed, 25 insertions(+), 31 deletions(-)
hw/tmp105.c +25 -31
@@ -173,46 +173,40 @@ static void tmp105_event(i2c_slave *i2c, enum i2c_event event) s->len =0 ; } -static void tmp105_save (QEMUFile *f,void *opaque) +static void tmp105_post_save (void *opaque) { -TMP105State *s = (TMP105State *) opaque; - -qemu_put_byte (f, s->len); -qemu_put_8s (f, &s->buf[0 ]); -qemu_put_8s (f, &s->buf[1 ]); - -qemu_put_8s (f, &s->pointer); -qemu_put_8s (f, &s->config); -qemu_put_sbe16s (f, &s->temperature); -qemu_put_sbe16s (f, &s->limit[0 ]); -qemu_put_sbe16s (f, &s->limit[1 ]); -qemu_put_byte (f, s->alarm); +TMP105State *s = opaque; s->faults = tmp105_faultq[(s->config >>3 ) &3 ];/* F */ - -i2c_slave_save (f, &s->i2c); } -static int tmp105_load (QEMUFile *f,void *opaque,int version_id) +static int tmp105_post_load (void *opaque,int version_id) { -TMP105State *s = (TMP105State *) opaque; - - s->len =qemu_get_byte (f); -qemu_get_8s (f, &s->buf[0 ]); -qemu_get_8s (f, &s->buf[1 ]); - -qemu_get_8s (f, &s->pointer); -qemu_get_8s (f, &s->config); -qemu_get_sbe16s (f, &s->temperature); -qemu_get_sbe16s (f, &s->limit[0 ]); -qemu_get_sbe16s (f, &s->limit[1 ]); - s->alarm =qemu_get_byte (f); +TMP105State *s = opaque;tmp105_interrupt_update (s); - -i2c_slave_load (f, &s->i2c);return 0 ; } +static const VMStateDescription vmstate_tmp105 = { + .name ="TMP105" , + .version_id =0 , + .minimum_version_id =0 , + .minimum_version_id_old =0 , + .post_save = tmp105_post_save, + .post_load = tmp105_post_load, + .fields = (VMStateField []) { +VMSTATE_UINT8 (len, TMP105State), +VMSTATE_UINT8_ARRAY (buf, TMP105State,2 ), +VMSTATE_UINT8 (pointer, TMP105State), +VMSTATE_UINT8 (config, TMP105State), +VMSTATE_INT16 (temperature, TMP105State), +VMSTATE_INT16_ARRAY (limit, TMP105State,2 ), +VMSTATE_UINT8 (alarm, TMP105State), +VMSTATE_I2C_SLAVE (i2c, TMP105State), +VMSTATE_END_OF_LIST () + } +}; +static void tmp105_reset (i2c_slave *i2c) {TMP105State *s = (TMP105State *) i2c;
@@ -234,7 +228,7 @@ static int tmp105_init(i2c_slave *i2c)tmp105_reset (&s->i2c); -register_savevm ("TMP105" ,-1 ,0 , tmp105_save, tmp105_load, s); +vmstate_register (-1 , &vmstate_tmp105, s);return 0 ; }
Signature · 1 line
1.6.2.5
PATCH 20/49 twl92230: change pwrbtn_state to uint8_t
In reply to Juan Quintelaits value is always the level of an interrupt, 0 or 1
--- hw/twl92230.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
hw/twl92230.c +1 -1
@@ -62,7 +62,7 @@ typedef struct { } rtc;qemu_irq out[4 ];qemu_irq *in; -int pwrbtn_state; +uint8_t pwrbtn_state;qemu_irq pwrbtn; } MenelausState;
Signature · 1 line
1.6.2.5
PATCH 21/49 vmstate: port twl92230 device
In reply to Juan QuintelaJust don't look. struct tm members are ints' and they are sent as uint16_t. VMState code complains as it should. Have to create hacky int32_as_uint16 type. Don't ever think about copying it
--- hw/twl92230.c | 198 +++++++++++++++++++++++++------------------------------- 1 files changed, 88 insertions(+), 110 deletions(-)
hw/twl92230.c +88 -110
@@ -60,6 +60,7 @@ typedef struct {int alm_sec;int next_comp; } rtc; +uint16_t rtc_next_vmstate;qemu_irq out[4 ];qemu_irq *in;uint8_t pwrbtn_state;
@@ -747,134 +748,111 @@ static int menelaus_rx(i2c_slave *i2c)return menelaus_read (s, s->reg ++); } -static void tm_put (QEMUFile *f,struct tm *tm) { -qemu_put_be16 (f, tm->tm_sec); -qemu_put_be16 (f, tm->tm_min); -qemu_put_be16 (f, tm->tm_hour); -qemu_put_be16 (f, tm->tm_mday); -qemu_put_be16 (f, tm->tm_min); -qemu_put_be16 (f, tm->tm_year); -} +/* Save restore 32 bit int as uint16_t +This is a Big hack, but it is how the old state did it. +Or we broke compatibility in the state, or we can't use struct tm +*/ -static void tm_get (QEMUFile *f,struct tm *tm) { - tm->tm_sec =qemu_get_be16 (f); - tm->tm_min =qemu_get_be16 (f); - tm->tm_hour =qemu_get_be16 (f); - tm->tm_mday =qemu_get_be16 (f); - tm->tm_min =qemu_get_be16 (f); - tm->tm_year =qemu_get_be16 (f); +static int get_int32_as_uint16 (QEMUFile *f,void *pv,size_t size) +{ +int *v = pv; + *v =qemu_get_be16 (f); +return 0 ; } -static void menelaus_save (QEMUFile *f,void *opaque) +static void put_int32_as_uint16 (QEMUFile *f,void *pv,size_t size) { -MenelausState *s = (MenelausState *) opaque; +int *v = pv; +qemu_put_be16 (f, *v); +} -qemu_put_be32 (f, s->firstbyte); -qemu_put_8s (f, &s->reg); - -qemu_put_8s (f, &s->vcore[0 ]); -qemu_put_8s (f, &s->vcore[1 ]); -qemu_put_8s (f, &s->vcore[2 ]); -qemu_put_8s (f, &s->vcore[3 ]); -qemu_put_8s (f, &s->vcore[4 ]); -qemu_put_8s (f, &s->dcdc[0 ]); -qemu_put_8s (f, &s->dcdc[1 ]); -qemu_put_8s (f, &s->dcdc[2 ]); -qemu_put_8s (f, &s->ldo[0 ]); -qemu_put_8s (f, &s->ldo[1 ]); -qemu_put_8s (f, &s->ldo[2 ]); -qemu_put_8s (f, &s->ldo[3 ]); -qemu_put_8s (f, &s->ldo[4 ]); -qemu_put_8s (f, &s->ldo[5 ]); -qemu_put_8s (f, &s->ldo[6 ]); -qemu_put_8s (f, &s->ldo[7 ]); -qemu_put_8s (f, &s->sleep[0 ]); -qemu_put_8s (f, &s->sleep[1 ]); -qemu_put_8s (f, &s->osc); -qemu_put_8s (f, &s->detect); -qemu_put_be16s (f, &s->mask); -qemu_put_be16s (f, &s->status); -qemu_put_8s (f, &s->dir); -qemu_put_8s (f, &s->inputs); -qemu_put_8s (f, &s->outputs); -qemu_put_8s (f, &s->bbsms); -qemu_put_8s (f, &s->pull[0 ]); -qemu_put_8s (f, &s->pull[1 ]); -qemu_put_8s (f, &s->pull[2 ]); -qemu_put_8s (f, &s->pull[3 ]); -qemu_put_8s (f, &s->mmc_ctrl[0 ]); -qemu_put_8s (f, &s->mmc_ctrl[1 ]); -qemu_put_8s (f, &s->mmc_ctrl[2 ]); -qemu_put_8s (f, &s->mmc_debounce); -qemu_put_8s (f, &s->rtc.ctrl); -qemu_put_be16s (f, &s->rtc.comp); -/* Should be <= 1000 */ -qemu_put_be16 (f, s->rtc.next -qemu_get_clock (rt_clock)); -tm_put (f, &s->rtc.new); -tm_put (f, &s->rtc.alm); -qemu_put_byte (f, s->pwrbtn_state); +const VMStateInfo vmstate_hack_int32_as_uint16 = { + .name ="int32_as_uint16" , + .get = get_int32_as_uint16, + .put = put_int32_as_uint16, +}; -i2c_slave_save (f, &s->i2c); -} +#define VMSTATE_UINT16_HACK (_f, _s) \ + VMSTATE_SINGLE(_f, _s, 0, vmstate_hack_int32_as_uint16, int32_t) + + +static const VMStateDescription vmstate_menelaus_tm = { + .name ="menelaus_tm" , + .version_id =0 , + .minimum_version_id =0 , + .minimum_version_id_old =0 , + .fields = (VMStateField []) { + VMSTATE_UINT16_HACK(tm_sec, struct tm), + VMSTATE_UINT16_HACK(tm_min, struct tm), + VMSTATE_UINT16_HACK(tm_hour, struct tm), + VMSTATE_UINT16_HACK(tm_mday, struct tm), + VMSTATE_UINT16_HACK(tm_min, struct tm), + VMSTATE_UINT16_HACK(tm_year, struct tm), +VMSTATE_END_OF_LIST () + } +}; -static int menelaus_load (QEMUFile *f,void *opaque,int version_id) +static void menelaus_pre_save (void *opaque) { -MenelausState *s = (MenelausState *) opaque; +MenelausState *s = opaque; +/* Should be <= 1000 */ + s->rtc_next_vmstate = s->rtc.next -qemu_get_clock (rt_clock); +} - s->firstbyte =qemu_get_be32 (f); -qemu_get_8s (f, &s->reg); +static int menelaus_post_load (void *opaque,int version_id) +{ +MenelausState *s = opaque;if (s->rtc.ctrl &1 )/* RTC_EN */ menelaus_rtc_stop (s); -qemu_get_8s (f, &s->vcore[0 ]); -qemu_get_8s (f, &s->vcore[1 ]); -qemu_get_8s (f, &s->vcore[2 ]); -qemu_get_8s (f, &s->vcore[3 ]); -qemu_get_8s (f, &s->vcore[4 ]); -qemu_get_8s (f, &s->dcdc[0 ]); -qemu_get_8s (f, &s->dcdc[1 ]); -qemu_get_8s (f, &s->dcdc[2 ]); -qemu_get_8s (f, &s->ldo[0 ]); -qemu_get_8s (f, &s->ldo[1 ]); -qemu_get_8s (f, &s->ldo[2 ]); -qemu_get_8s (f, &s->ldo[3 ]); -qemu_get_8s (f, &s->ldo[4 ]); -qemu_get_8s (f, &s->ldo[5 ]); -qemu_get_8s (f, &s->ldo[6 ]); -qemu_get_8s (f, &s->ldo[7 ]); -qemu_get_8s (f, &s->sleep[0 ]); -qemu_get_8s (f, &s->sleep[1 ]); -qemu_get_8s (f, &s->osc); -qemu_get_8s (f, &s->detect); -qemu_get_be16s (f, &s->mask); -qemu_get_be16s (f, &s->status); -qemu_get_8s (f, &s->dir); -qemu_get_8s (f, &s->inputs); -qemu_get_8s (f, &s->outputs); -qemu_get_8s (f, &s->bbsms); -qemu_get_8s (f, &s->pull[0 ]); -qemu_get_8s (f, &s->pull[1 ]); -qemu_get_8s (f, &s->pull[2 ]); -qemu_get_8s (f, &s->pull[3 ]); -qemu_get_8s (f, &s->mmc_ctrl[0 ]); -qemu_get_8s (f, &s->mmc_ctrl[1 ]); -qemu_get_8s (f, &s->mmc_ctrl[2 ]); -qemu_get_8s (f, &s->mmc_debounce); -qemu_get_8s (f, &s->rtc.ctrl); -qemu_get_be16s (f, &s->rtc.comp); - s->rtc.next =qemu_get_be16 (f); -tm_get (f, &s->rtc.new); -tm_get (f, &s->rtc.alm); - s->pwrbtn_state =qemu_get_byte (f); + + s->rtc.next = s->rtc_next_vmstate; +menelaus_alm_update (s);menelaus_update (s);if (s->rtc.ctrl &1 )/* RTC_EN */ menelaus_rtc_start (s); - -i2c_slave_load (f, &s->i2c);return 0 ; } +static const VMStateDescription vmstate_menelaus = { + .name ="menelaus" , + .version_id =0 , + .minimum_version_id =0 , + .minimum_version_id_old =0 , + .pre_save = menelaus_pre_save, + .post_load = menelaus_post_load, + .fields = (VMStateField []) { +VMSTATE_INT32 (firstbyte, MenelausState), +VMSTATE_UINT8 (reg, MenelausState), +VMSTATE_UINT8_ARRAY (vcore, MenelausState,5 ), +VMSTATE_UINT8_ARRAY (dcdc, MenelausState,3 ), +VMSTATE_UINT8_ARRAY (ldo, MenelausState,8 ), +VMSTATE_UINT8_ARRAY (sleep, MenelausState,2 ), +VMSTATE_UINT8 (osc, MenelausState), +VMSTATE_UINT8 (detect, MenelausState), +VMSTATE_UINT16 (mask, MenelausState), +VMSTATE_UINT16 (status, MenelausState), +VMSTATE_UINT8 (dir, MenelausState), +VMSTATE_UINT8 (inputs, MenelausState), +VMSTATE_UINT8 (outputs, MenelausState), +VMSTATE_UINT8 (bbsms, MenelausState), +VMSTATE_UINT8_ARRAY (pull, MenelausState,4 ), +VMSTATE_UINT8_ARRAY (mmc_ctrl, MenelausState,3 ), +VMSTATE_UINT8 (mmc_debounce, MenelausState), +VMSTATE_UINT8 (rtc.ctrl, MenelausState), +VMSTATE_UINT16 (rtc.comp, MenelausState), +VMSTATE_UINT16 (rtc_next_vmstate, MenelausState), +VMSTATE_STRUCT (rtc.new, MenelausState,0 , vmstate_menelaus_tm, + struct tm), +VMSTATE_STRUCT (rtc.alm, MenelausState,0 , vmstate_menelaus_tm, + struct tm), +VMSTATE_UINT8 (pwrbtn_state, MenelausState), +VMSTATE_I2C_SLAVE (i2c, MenelausState), +VMSTATE_END_OF_LIST () + } +}; +static int twl92230_init (i2c_slave *i2c) {MenelausState *s =FROM_I2C_SLAVE (MenelausState, i2c);
@@ -887,7 +865,7 @@ static int twl92230_init(i2c_slave *i2c)menelaus_reset (&s->i2c); -register_savevm ("menelaus" ,-1 ,0 , menelaus_save, menelaus_load, s); +vmstate_register (-1 , &vmstate_menelaus, s);return 0 ; }
Signature · 1 line
1.6.2.5
PATCH 22/49 vmstate: add support for arrays of pointers
In reply to Juan QuintelaWe need this to send arrays of timers
--- hw/hw.h | 15 +++++++++++++++ savevm.c | 3 +++ 2 files changed, 18 insertions(+), 0 deletions(-)
hw/hw.h +15 -0
@@ -286,6 +286,7 @@ enum VMStateFlags {VMS_STRUCT =0x008 ,VMS_VARRAY =0x010 ,/* Array with size in another field */ VMS_BUFFER =0x020 ,/* static sized buffer */ + VMS_ARRAY_OF_POINTER = 0x040, }; typedef struct {
@@ -396,6 +397,17 @@ extern const VMStateInfo vmstate_info_buffer; + type_check(_type,typeof_field(_state, _field)) \ } +#define VMSTATE_ARRAY_OF_POINTER (_field, _state, _num, _version, _info, _type) {\ + .name = (stringify(_field)), \ + .version_id = (_version), \ + .num = (_num), \ + .info = &(_info), \ + .size = sizeof(_type), \ + .flags = VMS_ARRAY|VMS_ARRAY_OF_POINTER, \ + .offset = offsetof(_state, _field) \ + + type_check_array(_type,typeof_field(_state, _field),_num) \ +} +#define VMSTATE_STRUCT_ARRAY (_field, _state, _num, _version, _vmsd, _type) { \ .name = (stringify(_field)), \ .num = (_num), \
@@ -518,6 +530,9 @@ extern const VMStateDescription vmstate_i2c_slave;#define VMSTATE_TIMER (_f, _s) \ VMSTATE_TIMER_V(_f, _s, 0) +#define VMSTATE_TIMER_ARRAY (_f, _s, _n) \ + VMSTATE_ARRAY_OF_POINTER(_f, _s, _n, 0, vmstate_info_timer, QEMUTimer *) +#define VMSTATE_PTIMER_V (_f, _s, _v) \ VMSTATE_POINTER(_f, _s, _v, vmstate_info_ptimer, ptimer_state *)
savevm.c +3 -0
@@ -1070,6 +1070,9 @@ int vmstate_load_state(QEMUFile *f, const VMStateDescription *vmsd,for (i =0 ; i < n_elems; i++) {void *addr = base_addr + field->size * i; +if (field->flags &VMS_ARRAY_OF_POINTER ) { + addr = *(void **)addr; + }if (field->flags &VMS_STRUCT ) { ret =vmstate_load_state (f, field->vmsd, addr, field->vmsd->version_id); }else {
Signature · 1 line
1.6.2.5
PATCH 23/49 lm832x: make fields to have the same types that they are saved/loaded
In reply to Juan QuintelaThey were saved as uint8_t already. To make things simpler, I just reg == -1 used to indicate an error, I create LM832x_GENERAL_ERROR with vale 0xff to represet it
--- hw/lm832x.c | 41 ++++++++++++++++++++++------------------- 1 files changed, 22 insertions(+), 19 deletions(-)
hw/lm832x.c +22 -19
@@ -25,9 +25,9 @@ typedef struct { i2c_slave i2c; - int i2c_dir; - int i2c_cycle; - int reg; + uint8_t i2c_dir; + uint8_t i2c_cycle; + uint8_t reg; qemu_irq nirq; uint16_t model;
@@ -54,8 +54,8 @@ typedef struct {struct {uint8_t dbnctime;uint8_t size; -int start; -int len; +uint8_t start; +uint8_t len;uint8_t fifo[16 ]; } kbd;
@@ -152,6 +152,9 @@ enum { LM832x_CMD_PWM_WRITE =0x95 ,/* Write PWM script. */ LM832x_CMD_PWM_START =0x96 ,/* Start PWM engine. */ LM832x_CMD_PWM_STOP =0x97 ,/* Stop PWM engine. */ + LM832x_GENERAL_ERROR = 0xff, /* There was one error. + Previously was represented by -1 + This is not a command */ };#define LM832x_MAX_KPX 8
@@ -257,7 +260,7 @@ static void lm_kbd_write(LM823KbdState *s, int reg, int byte, uint8_t value)lm_kbd_irq_update (s); s->kbd.len =0 ; s->kbd.start =0 ; - s->reg =-1 ; + s->reg = LM832x_GENERAL_ERROR;break ;case LM832x_CMD_RESET:
@@ -265,7 +268,7 @@ static void lm_kbd_write(LM823KbdState *s, int reg, int byte, uint8_t value)lm_kbd_reset (s); elselm_kbd_error (s ,ERR_BADPAR ); - s->reg =-1 ; + s->reg = LM832x_GENERAL_ERROR;break ;case LM823x_CMD_WRITE_PULL_DOWN:
@@ -274,7 +277,7 @@ static void lm_kbd_write(LM823KbdState *s, int reg, int byte, uint8_t value)else { s->gpio.pull |= value <<8 ;lm_kbd_gpio_update (s); - s->reg =-1 ; + s->reg = LM832x_GENERAL_ERROR; }break ;case LM832x_CMD_WRITE_PORT_SEL:
@@ -283,7 +286,7 @@ static void lm_kbd_write(LM823KbdState *s, int reg, int byte, uint8_t value)else { s->gpio.dir |= value <<8 ;lm_kbd_gpio_update (s); - s->reg =-1 ; + s->reg = LM832x_GENERAL_ERROR; }break ;case LM832x_CMD_WRITE_PORT_STATE:
@@ -292,25 +295,25 @@ static void lm_kbd_write(LM823KbdState *s, int reg, int byte, uint8_t value)else { s->gpio.mask |= value <<8 ;lm_kbd_gpio_update (s); - s->reg =-1 ; + s->reg = LM832x_GENERAL_ERROR; }break ;case LM832x_CMD_SET_ACTIVE: s->acttime = value; - s->reg =-1 ; + s->reg = LM832x_GENERAL_ERROR;break ;case LM832x_CMD_SET_DEBOUNCE: s->kbd.dbnctime = value; - s->reg =-1 ; + s->reg = LM832x_GENERAL_ERROR;if (!value)lm_kbd_error (s,ERR_BADPAR );break ;case LM832x_CMD_SET_KEY_SIZE: s->kbd.size = value; - s->reg =-1 ; + s->reg = LM832x_GENERAL_ERROR;if ( (value &0xf ) <3 || (value &0xf ) > LM832x_MAX_KPY || (value >>4 ) <3 || (value >>4 ) > LM832x_MAX_KPX)
@@ -319,7 +322,7 @@ static void lm_kbd_write(LM823KbdState *s, int reg, int byte, uint8_t value)case LM832x_CMD_WRITE_CLOCK: s->clock = value; - s->reg =-1 ; + s->reg = LM832x_GENERAL_ERROR;if ((value &3 ) && (value &3 ) !=3 ) {lm_kbd_error (s,ERR_BADPAR ); fprintf(stderr, "%s: invalid clock setting in RCPWM\n",
@@ -332,7 +335,7 @@ static void lm_kbd_write(LM823KbdState *s, int reg, int byte, uint8_t value)if (byte ==0 ) {if (!(value &3 ) || (value >>2 ) >59 ) {lm_kbd_error (s,ERR_BADPAR ); - s->reg =-1 ; + s->reg = LM832x_GENERAL_ERROR;break ; }
@@ -342,11 +345,11 @@ static void lm_kbd_write(LM823KbdState *s, int reg, int byte, uint8_t value) s->pwm.file[s->pwm.faddr] |= value <<8 ; }else if (byte ==2 ) { s->pwm.file[s->pwm.faddr] |= value <<0 ; - s->reg =-1 ; + s->reg = LM832x_GENERAL_ERROR; }break ;case LM832x_CMD_PWM_START: - s->reg =-1 ; + s->reg = LM832x_GENERAL_ERROR;if (!(value &3 ) || (value >>2 ) >59 ) {lm_kbd_error (s,ERR_BADPAR );break ;
@@ -356,7 +359,7 @@ static void lm_kbd_write(LM823KbdState *s, int reg, int byte, uint8_t value)lm_kbd_pwm_start (s, (value &3 ) -1 );break ;case LM832x_CMD_PWM_STOP: - s->reg =-1 ; + s->reg = LM832x_GENERAL_ERROR;if (!(value &3 )) {lm_kbd_error (s,ERR_BADPAR );break ;
@@ -365,7 +368,7 @@ static void lm_kbd_write(LM823KbdState *s, int reg, int byte, uint8_t value)qemu_del_timer (s->pwm.tm[(value &3 ) -1 ]);break ; -case -1 : +case LM832x_GENERAL_ERROR:lm_kbd_error (s,ERR_BADPAR );break ;default :
Signature · 1 line
1.6.2.5
PATCH 24/49 vmstate: port lm832x device
In reply to Juan Quintela--- hw/lm832x.c | 107 ++++++++++++++++++++-------------------------------------- 1 files changed, 37 insertions(+), 70 deletions(-)
hw/lm832x.c +37 -70
@@ -414,76 +414,9 @@ static int lm_i2c_tx(i2c_slave *i2c, uint8_t data)return 0 ; } -static void lm_kbd_save (QEMUFile *f,void *opaque) +static int lm_kbd_post_load (void *opaque,int version_id) { -LM823KbdState *s = (LM823KbdState *) opaque; -int i; - -i2c_slave_save (f, &s->i2c); -qemu_put_byte (f, s->i2c_dir); -qemu_put_byte (f, s->i2c_cycle); -qemu_put_byte (f, (uint8_t ) s->reg); - -qemu_put_8s (f, &s->config); -qemu_put_8s (f, &s->status); -qemu_put_8s (f, &s->acttime); -qemu_put_8s (f, &s->error); -qemu_put_8s (f, &s->clock); - -qemu_put_be16s (f, &s->gpio.pull); -qemu_put_be16s (f, &s->gpio.mask); -qemu_put_be16s (f, &s->gpio.dir); -qemu_put_be16s (f, &s->gpio.level); - -qemu_put_byte (f, s->kbd.dbnctime); -qemu_put_byte (f, s->kbd.size); -qemu_put_byte (f, s->kbd.start); -qemu_put_byte (f, s->kbd.len); -qemu_put_buffer (f, s->kbd.fifo,sizeof (s->kbd.fifo)); - -for (i =0 ; i <sizeof (s->pwm.file); i ++) -qemu_put_be16s (f, &s->pwm.file[i]); -qemu_put_8s (f, &s->pwm.faddr); -qemu_put_buffer (f, s->pwm.addr,sizeof (s->pwm.addr)); -qemu_put_timer (f, s->pwm.tm[0 ]); -qemu_put_timer (f, s->pwm.tm[1 ]); -qemu_put_timer (f, s->pwm.tm[2 ]); -} - -static int lm_kbd_load (QEMUFile *f,void *opaque,int version_id) -{ -LM823KbdState *s = (LM823KbdState *) opaque; -int i; - -i2c_slave_load (f, &s->i2c); - s->i2c_dir =qemu_get_byte (f); - s->i2c_cycle =qemu_get_byte (f); - s->reg = (int8_t )qemu_get_byte (f); - -qemu_get_8s (f, &s->config); -qemu_get_8s (f, &s->status); -qemu_get_8s (f, &s->acttime); -qemu_get_8s (f, &s->error); -qemu_get_8s (f, &s->clock); - -qemu_get_be16s (f, &s->gpio.pull); -qemu_get_be16s (f, &s->gpio.mask); -qemu_get_be16s (f, &s->gpio.dir); -qemu_get_be16s (f, &s->gpio.level); - - s->kbd.dbnctime =qemu_get_byte (f); - s->kbd.size =qemu_get_byte (f); - s->kbd.start =qemu_get_byte (f); - s->kbd.len =qemu_get_byte (f); -qemu_get_buffer (f, s->kbd.fifo,sizeof (s->kbd.fifo)); - -for (i =0 ; i <sizeof (s->pwm.file); i ++) -qemu_get_be16s (f, &s->pwm.file[i]); -qemu_get_8s (f, &s->pwm.faddr); -qemu_get_buffer (f, s->pwm.addr,sizeof (s->pwm.addr)); -qemu_get_timer (f, s->pwm.tm[0 ]); -qemu_get_timer (f, s->pwm.tm[1 ]); -qemu_get_timer (f, s->pwm.tm[2 ]); +LM823KbdState *s = opaque;lm_kbd_irq_update (s);lm_kbd_gpio_update (s);
@@ -491,6 +424,40 @@ static int lm_kbd_load(QEMUFile *f, void *opaque, int version_id)return 0 ; } +static const VMStateDescription vmstate_lm_kbd = { + .name ="LM8323" , + .version_id =0 , + .minimum_version_id =0 , + .minimum_version_id_old =0 , + .post_load = lm_kbd_post_load, + .fields = (VMStateField []) { +VMSTATE_I2C_SLAVE (i2c, LM823KbdState), +VMSTATE_UINT8 (i2c_dir, LM823KbdState), +VMSTATE_UINT8 (i2c_cycle, LM823KbdState), +VMSTATE_UINT8 (reg, LM823KbdState), +VMSTATE_UINT8 (config, LM823KbdState), +VMSTATE_UINT8 (status, LM823KbdState), +VMSTATE_UINT8 (acttime, LM823KbdState), +VMSTATE_UINT8 (error, LM823KbdState), +VMSTATE_UINT8 (clock, LM823KbdState), +VMSTATE_UINT16 (gpio.pull, LM823KbdState), +VMSTATE_UINT16 (gpio.mask, LM823KbdState), +VMSTATE_UINT16 (gpio.dir, LM823KbdState), +VMSTATE_UINT16 (gpio.level, LM823KbdState), +VMSTATE_UINT8 (kbd.dbnctime, LM823KbdState), +VMSTATE_UINT8 (kbd.size, LM823KbdState), +VMSTATE_UINT8 (kbd.start, LM823KbdState), +VMSTATE_UINT8 (kbd.len, LM823KbdState), +VMSTATE_BUFFER (kbd.fifo, LM823KbdState), +VMSTATE_UINT16_ARRAY (pwm.file, LM823KbdState,256 ), +VMSTATE_UINT8 (pwm.faddr, LM823KbdState), +VMSTATE_BUFFER (pwm.addr, LM823KbdState), +VMSTATE_TIMER_ARRAY (pwm.tm, LM823KbdState,3 ), +VMSTATE_END_OF_LIST () + } +}; + +static int lm8323_init (i2c_slave *i2c) {LM823KbdState *s =FROM_I2C_SLAVE (LM823KbdState, i2c);
@@ -504,7 +471,7 @@ static int lm8323_init(i2c_slave *i2c)lm_kbd_reset (s);qemu_register_reset ((void *) lm_kbd_reset, s); -register_savevm ("LM8323" ,-1 ,0 , lm_kbd_save, lm_kbd_load, s); +vmstate_register (-1 , &vmstate_lm_kbd, s);return 0 ; }
Signature · 1 line
1.6.2.5
PATCH 25/49 vmstate: remove i2c_slave_load/save
In reply to Juan QuintelaAll its users moved to vmstate
--- hw/i2c.c | 11 ----------- hw/i2c.h | 2 -- 2 files changed, 0 insertions(+), 13 deletions(-)
hw/i2c.c +0 -11
@@ -165,17 +165,6 @@ const VMStateDescription vmstate_i2c_slave = { } }; -void i2c_slave_save (QEMUFile *f,i2c_slave *dev) -{ -vmstate_save_state (f, &vmstate_i2c_slave, dev); -} - -void i2c_slave_load (QEMUFile *f,i2c_slave *dev) -{ -vmstate_load_state (f, &vmstate_i2c_slave, dev, - vmstate_i2c_slave.version_id); -} -static int i2c_slave_qdev_init (DeviceState *dev,DeviceInfo *base) {I2CSlaveInfo *info =container_of (base, I2CSlaveInfo, qdev);
hw/i2c.h +0 -2
@@ -51,8 +51,6 @@ void i2c_end_transfer(i2c_bus *bus);void i2c_nack (i2c_bus *bus);int i2c_send (i2c_bus *bus,uint8_t data);int i2c_recv (i2c_bus *bus); -void i2c_slave_save (QEMUFile *f,i2c_slave *dev); -void i2c_slave_load (QEMUFile *f,i2c_slave *dev);#define I2C_SLAVE_FROM_QDEV (dev) DO_UPCAST(i2c_slave, qdev, dev)#define FROM_I2C_SLAVE (type, dev) DO_UPCAST(type, i2c, dev)
Signature · 1 line
1.6.2.5
PATCH 26/49 vmstate: port audio/audio.c
In reply to Juan Quintela--- audio/audio.c | 26 +++++++++----------------- 1 files changed, 9 insertions(+), 17 deletions(-)
audio/audio.c +9 -17
@@ -1784,23 +1784,15 @@ static void audio_atexit (void) } } -static void audio_save (QEMUFile *f,void *opaque) -{ - (void ) f; - (void ) opaque; -} - -static int audio_load (QEMUFile *f,void *opaque,int version_id) -{ - (void ) f; - (void ) opaque; - -if (version_id !=1 ) { -return -EINVAL ; +static const VMStateDescription vmstate_audio = { + .name ="audio" , + .version_id =1 , + .minimum_version_id =1 , + .minimum_version_id_old =1 , + .fields = (VMStateField []) { +VMSTATE_END_OF_LIST () } - -return 0 ; -} +};static void audio_init (void ) {
@@ -1900,7 +1892,7 @@ static void audio_init (void) }QLIST_INIT (&s->card_head); -register_savevm ("audio" ,0 ,1 , audio_save, audio_load, s); +vmstate_register (0 , &vmstate_audio, s); }void AUD_register_card (const char *name,QEMUSoundCard *card)
Signature · 1 line
1.6.2.5
PATCH 27/49 ac97: add active to the state
In reply to Juan QuintelaThis simplifies reset_voices, that only takes one argument now.
--- hw/ac97.c | 42 ++++++++++++++++++++---------------------- 1 files changed, 20 insertions(+), 22 deletions(-)
hw/ac97.c +20 -22
@@ -146,6 +146,13 @@ typedef struct AC97BusMasterRegs {BD bd; } AC97BusMasterRegs; +enum { +PI_INDEX =0 , +PO_INDEX , +MC_INDEX , +LAST_INDEX +}; + typedef struct AC97LinkState { PCIDevice dev; QEMUSoundCard card;
@@ -162,6 +169,7 @@ typedef struct AC97LinkState {uint8_t silence[128 ];uint32_t base[2 ];int bup_flag; +uint8_t active[LAST_INDEX ]; } AC97LinkState;enum {
@@ -186,13 +194,6 @@ enum { \ prefix ## _CR = start + 11 \ } -enum { -PI_INDEX =0 , -PO_INDEX , -MC_INDEX , -LAST_INDEX -}; -MKREGS (PI ,PI_INDEX *16 );MKREGS (PO ,PO_INDEX *16 );MKREGS (MC ,MC_INDEX *16 );
@@ -414,21 +415,21 @@ static void open_voice (AC97LinkState *s, int index, int freq) } } -static void reset_voices (AC97LinkState *s,uint8_t active[LAST_INDEX ]) +static void reset_voices (AC97LinkState *s) {uint16_t freq; freq =mixer_load (s, AC97_PCM_LR_ADC_Rate);open_voice (s,PI_INDEX , freq); -AUD_set_active_in (s->voice_pi, active[PI_INDEX ]); +AUD_set_active_in (s->voice_pi, s->active[PI_INDEX ]); freq =mixer_load (s, AC97_PCM_Front_DAC_Rate);open_voice (s,PO_INDEX , freq); -AUD_set_active_out (s->voice_po, active[PO_INDEX ]); +AUD_set_active_out (s->voice_po, s->active[PO_INDEX ]); freq =mixer_load (s, AC97_MIC_ADC_Rate);open_voice (s,MC_INDEX , freq); -AUD_set_active_in (s->voice_mc, active[MC_INDEX ]); +AUD_set_active_in (s->voice_mc, s->active[MC_INDEX ]); }#ifdef USE_MIXER
@@ -526,11 +527,10 @@ static void record_select (AC97LinkState *s, uint32_t val)static void mixer_reset (AC97LinkState *s) { -uint8_t active[LAST_INDEX ];dolog ("mixer_reset\n" );memset (s->mixer_data,0 ,sizeof (s->mixer_data)); -memset (active,0 ,sizeof (active)); +memset (s->active,0 ,sizeof (s->active));mixer_store (s, AC97_Reset ,0x0000 );/* 6940 */ mixer_store (s, AC97_Master_Volume_Mono_Mute ,0x8000 );mixer_store (s, AC97_PC_BEEP_Volume_Mute ,0x0000 );
@@ -564,7 +564,7 @@ static void mixer_reset (AC97LinkState *s)set_volume (s, AC97_PCM_Out_Volume_Mute,AUD_MIXER_PCM ,0x8808 );set_volume (s, AC97_Line_In_Volume_Mute,AUD_MIXER_LINE_IN ,0x8808 );#endif -reset_voices (s, active); +reset_voices (s); }/**
@@ -1170,7 +1170,6 @@ static void po_callback (void *opaque, int free)static void ac97_save (QEMUFile *f,void *opaque) {size_t i; -uint8_t active[LAST_INDEX ];AC97LinkState *s = opaque;pci_device_save (&s->dev, f);
@@ -1194,17 +1193,16 @@ static void ac97_save (QEMUFile *f, void *opaque) }qemu_put_buffer (f, s->mixer_data,sizeof (s->mixer_data)); - active[PI_INDEX ] =AUD_is_active_in (s->voice_pi) ?1 :0 ; - active[PO_INDEX ] =AUD_is_active_out (s->voice_po) ?1 :0 ; - active[MC_INDEX ] =AUD_is_active_in (s->voice_mc) ?1 :0 ; -qemu_put_buffer (f, active,sizeof (active)); + s->active[PI_INDEX ] =AUD_is_active_in (s->voice_pi) ?1 :0 ; + s->active[PO_INDEX ] =AUD_is_active_out (s->voice_po) ?1 :0 ; + s->active[MC_INDEX ] =AUD_is_active_in (s->voice_mc) ?1 :0 ; +qemu_put_buffer (f, s->active,sizeof (s->active)); }static int ac97_load (QEMUFile *f,void *opaque,int version_id) {int ret;size_t i; -uint8_t active[LAST_INDEX ];AC97LinkState *s = opaque;if (version_id !=2 )
@@ -1232,7 +1230,7 @@ static int ac97_load (QEMUFile *f, void *opaque, int version_id)qemu_get_be32s (f, &r->bd.ctl_len); }qemu_get_buffer (f, s->mixer_data,sizeof (s->mixer_data)); -qemu_get_buffer (f, active,sizeof (active)); +qemu_get_buffer (f, s->active,sizeof (s->active));#ifdef USE_MIXER record_select (s,mixer_load (s, AC97_Record_Select));
@@ -1242,7 +1240,7 @@ static int ac97_load (QEMUFile *f, void *opaque, int version_id)V_ (AC97_Line_In_Volume_Mute,AUD_MIXER_LINE_IN );#undef V_#endif -reset_voices (s, active); +reset_voices (s); s->bup_flag =0 ; s->last_samp =0 ;
Signature · 1 line
1.6.2.5
Re: [Qemu-devel] [PATCH 27/49] ac97: add active to the state
Quoted 12 lines · Juan Quintela
This simplifies
reset_voices, that only takes one argument now.Signed-off-by Juan Quintela <[email protected]>--- hw/ac97.c | 42 ++++++++++++++++++++---------------------- 1 files changed, 20 insertions(+), 22 deletions(-)hw/ac97.c +0
-0
hw/ac97.c typedef struct AC97BusMasterRegs { · line 154
Quoted 9 lines
hw/ac97.c +6
-0@@ -146,6 +146,13 @@ typedef struct AC97BusMasterRegs {BD bd; } AC97BusMasterRegs; +enum { +PI_INDEX =0 , +PO_INDEX , +MC_INDEX , +LAST_INDEX +};
And this was moved becasue...?
hw/ac97.c typedef struct AC97LinkState { · line 172
Quoted 9 lines
hw/ac97.c +2
-0+ typedef struct AC97LinkState { PCIDevice dev; QEMUSoundCard card;@@ -162,6 +169,7 @@ typedef struct AC97LinkState {uint8_t silence[128 ];uint32_t base[2 ];int bup_flag; +uint8_t active[LAST_INDEX ];
This doesn't belong here, cause the only purpose i can see is to hack around defficiencies of the new load/savevm APIs.
Quoted 114 lines
hw/ac97.c +12
-22} AC97LinkState;enum {@@ -186,13 +194,6 @@ enum { \ prefix ## _CR = start + 11 \ } -enum { -PI_INDEX =0 , -PO_INDEX , -MC_INDEX , -LAST_INDEX -}; -MKREGS (PI ,PI_INDEX *16 );MKREGS (PO ,PO_INDEX *16 );MKREGS (MC ,MC_INDEX *16 );@@ -414,21 +415,21 @@ static void open_voice (AC97LinkState *s, int index, int freq) } } -static void reset_voices (AC97LinkState *s,uint8_t active[LAST_INDEX ]) +static void reset_voices (AC97LinkState *s) {uint16_t freq; freq =mixer_load (s, AC97_PCM_LR_ADC_Rate);open_voice (s,PI_INDEX , freq); -AUD_set_active_in (s->voice_pi, active[PI_INDEX ]); +AUD_set_active_in (s->voice_pi, s->active[PI_INDEX ]); freq =mixer_load (s, AC97_PCM_Front_DAC_Rate);open_voice (s,PO_INDEX , freq); -AUD_set_active_out (s->voice_po, active[PO_INDEX ]); +AUD_set_active_out (s->voice_po, s->active[PO_INDEX ]); freq =mixer_load (s, AC97_MIC_ADC_Rate);open_voice (s,MC_INDEX , freq); -AUD_set_active_in (s->voice_mc, active[MC_INDEX ]); +AUD_set_active_in (s->voice_mc, s->active[MC_INDEX ]); }#ifdef USE_MIXER @@ -526,11 +527,10 @@ static void record_select (AC97LinkState *s, uint32_t val)static void mixer_reset (AC97LinkState *s) { -uint8_t active[LAST_INDEX ];dolog ("mixer_reset\n" );memset (s->mixer_data,0 ,sizeof (s->mixer_data)); -memset (active,0 ,sizeof (active)); +memset (s->active,0 ,sizeof (s->active));mixer_store (s, AC97_Reset ,0x0000 );/* 6940 */ mixer_store (s, AC97_Master_Volume_Mono_Mute ,0x8000 );mixer_store (s, AC97_PC_BEEP_Volume_Mute ,0x0000 );@@ -564,7 +564,7 @@ static void mixer_reset (AC97LinkState *s)set_volume (s, AC97_PCM_Out_Volume_Mute,AUD_MIXER_PCM ,0x8808 );set_volume (s, AC97_Line_In_Volume_Mute,AUD_MIXER_LINE_IN ,0x8808 );#endif -reset_voices (s, active); +reset_voices (s); }/** @@ -1170,7 +1170,6 @@ static void po_callback (void *opaque, int free)static void ac97_save (QEMUFile *f,void *opaque) {size_t i; -uint8_t active[LAST_INDEX ];AC97LinkState *s = opaque;pci_device_save (&s->dev, f);@@ -1194,17 +1193,16 @@ static void ac97_save (QEMUFile *f, void *opaque) }qemu_put_buffer (f, s->mixer_data,sizeof (s->mixer_data)); - active[PI_INDEX ] =AUD_is_active_in (s->voice_pi) ?1 :0 ; - active[PO_INDEX ] =AUD_is_active_out (s->voice_po) ?1 :0 ; - active[MC_INDEX ] =AUD_is_active_in (s->voice_mc) ?1 :0 ; -qemu_put_buffer (f, active,sizeof (active)); + s->active[PI_INDEX ] =AUD_is_active_in (s->voice_pi) ?1 :0 ; + s->active[PO_INDEX ] =AUD_is_active_out (s->voice_po) ?1 :0 ; + s->active[MC_INDEX ] =AUD_is_active_in (s->voice_mc) ?1 :0 ; +qemu_put_buffer (f, s->active,sizeof (s->active)); }static int ac97_load (QEMUFile *f,void *opaque,int version_id) {int ret;size_t i; -uint8_t active[LAST_INDEX ];AC97LinkState *s = opaque;if (version_id !=2 )@@ -1232,7 +1230,7 @@ static int ac97_load (QEMUFile *f, void *opaque, int version_id)qemu_get_be32s (f, &r->bd.ctl_len); }qemu_get_buffer (f, s->mixer_data,sizeof (s->mixer_data)); -qemu_get_buffer (f, active,sizeof (active)); +qemu_get_buffer (f, s->active,sizeof (s->active));#ifdef USE_MIXER record_select (s,mixer_load (s, AC97_Record_Select));@@ -1242,7 +1240,7 @@ static int ac97_load (QEMUFile *f, void *opaque, int version_id)V_ (AC97_Line_In_Volume_Mute,AUD_MIXER_LINE_IN );#undef V_#endif -reset_voices (s, active); +reset_voices (s); s->bup_flag =0 ; s->last_samp =0 ;
Signature · 1 line
mailto:[email protected]
[Qemu-devel] Re: [PATCH 27/49] ac97: add active to the state
Quoted 17 lines · malc
Quoted 15 lines · Juan Quintela
This simplifies
reset_voices, that only takes one argument now.Signed-off-by Juan Quintela <[email protected]>--- hw/ac97.c | 42 ++++++++++++++++++++---------------------- 1 files changed, 20 insertions(+), 22 deletions(-)hw/ac97.c +0
-0@@ -146,6 +146,13 @@ typedef struct AC97BusMasterRegs {BD bd; } AC97BusMasterRegs;
Quoted 8 lines
hw/ac97.c typedef struct AC97BusMasterRegs { · line 154
Quoted 6 lines
hw/ac97.c +6
-0+enum { +PI_INDEX =0 , +PO_INDEX , +MC_INDEX , +LAST_INDEX +};And this was moved becasue...?
Because I need LAST_INDEX in next part that you quoted.
Quoted 4 lines
Quoted 4 lines
hw/ac97.c +1
-0+ typedef struct AC97LinkState { PCIDevice dev; QEMUSoundCard card;
Quoted 8 lines
hw/ac97.c typedef struct AC97LinkState { · line 172
Quoted 5 lines
hw/ac97.c +1
-0@@ -162,6 +169,7 @@ typedef struct AC97LinkState {uint8_t silence[128 ];uint32_t base[2 ];int bup_flag; +uint8_t active[LAST_INDEX ];This doesn't belong here, cause the only purpose i can see is to hack around defficiencies of the new load/savevm APIs.
That was supposed to be one of the features, not deficiences. You can't sent stuff that it is not in the state. It is "by design" that you can't sent arbitrary variables.
Later, Juan.
[Qemu-devel] Re: [PATCH 27/49] ac97: add active to the state
Quoted 27 lines · Juan Quintela
Quoted 17 lines · malc
Quoted 15 lines · Juan Quintela
This simplifies
reset_voices, that only takes one argument now.Signed-off-by Juan Quintela <[email protected]>--- hw/ac97.c | 42 ++++++++++++++++++++---------------------- 1 files changed, 20 insertions(+), 22 deletions(-)hw/ac97.c +0
-0@@ -146,6 +146,13 @@ typedef struct AC97BusMasterRegs {BD bd; } AC97BusMasterRegs;Quoted 8 lines
hw/ac97.c typedef struct AC97BusMasterRegs { · line 154
Quoted 6 lines
hw/ac97.c +6
-0+enum { +PI_INDEX =0 , +PO_INDEX , +MC_INDEX , +LAST_INDEX +};And this was moved becasue...?
Quoted 1 line
Because I need
LAST_INDEXin next part that you quoted.
Ah, missed that, yes.
Quoted 13 lines
Quoted 4 lines
Quoted 4 lines
hw/ac97.c +1
-0+ typedef struct AC97LinkState { PCIDevice dev; QEMUSoundCard card;Quoted 8 lines
hw/ac97.c typedef struct AC97LinkState { · line 172
Quoted 5 lines
hw/ac97.c +1
-0@@ -162,6 +169,7 @@ typedef struct AC97LinkState {uint8_t silence[128 ];uint32_t base[2 ];int bup_flag; +uint8_t active[LAST_INDEX ];This doesn't belong here, cause the only purpose i can see is to hack around defficiencies of the new load/savevm APIs.
Quoted 3 lines
That was supposed to be one of the features, not deficiences. You can't sent stuff that it is not in the state. It is "by design" that you can't sent arbitrary variables.
active doesn't belong in the above structure, it's not used for anything other than save/loadvm. If this "design" doesn't allow this, either find another way to accomplish the same or fix the "design".
Signature · 1 line
mailto:[email protected]
[Qemu-devel] Re: [PATCH 27/49] ac97: add active to the state
Quoted 4 lines · malc
On Wed, 30 Sep 2009, Juan Quintela wrote:
active doesn't belong in the above structure, it's not used for anything other than save/loadvm.
It is used for reset, for instance. We can discuss if it belongs there or not, but will let that for another day.
Quoted 2 lines
If this "design" doesn't allow this, either find another way to accomplish the same or fix the "design".
VMStateDescription is a list of offsets from a known address. Address is the one from the state. That is the design.
Now, back to ac97. Rest of ac97 don't need the active field, because it is stored anywhere else (basically where AUD_set_active* store it).
Clearly it is part of ac97 state, becase it is needed for load/save/reset to work properly. It just happens that it is stored anywhere else for the design of the audio system.
At load/save time we don't want to call malloc(), and now we have descriptions of the state, not functions that save/load the state. Only sane way of storing this kind of variables is storing them into the state.
Sorry, there is no way that we are going to have a declarative description of the state and retain the old functions to do save/load. You can only get only declarative description or functions, not both.
There are more temporary variables in other devices, and this was the way it was done there. Normally I would have called it active_vmstate to make that explicit, but here, it was also used for reset, that is the way I named it with the _vmstate suffix.
Later, Juan.
[Qemu-devel] Re: [PATCH 27/49] ac97: add active to the state
Quoted 22 lines · Juan Quintela
Quoted 4 lines · malc
On Wed, 30 Sep 2009, Juan Quintela wrote:
active doesn't belong in the above structure, it's not used for anything other than save/loadvm.
It is used for reset, for instance. We can discuss if it belongs there or not, but will let that for another day.
Quoted 2 lines
If this "design" doesn't allow this, either find another way to accomplish the same or fix the "design".
VMStateDescription is a list of offsets from a known address. Address is the one from the state. That is the design.
Now, back to ac97. Rest of ac97 don't need the active field, because it is stored anywhere else (basically where AUD_set_active* store it).
Clearly it is part of ac97 state, becase it is needed for load/save/reset to work properly. It just happens that it is stored anywhere else for the design of the audio system.
Quoted 8 lines
At load/save time we don't want to call
malloc(), and now we have descriptions of the state, not functions that save/load the state. Only sane way of storing this kind of variables is storing them into the state.Sorry, there is no way that we are going to have a declarative description of the state and retain the old functions to do save/load. You can only get only declarative description or functions, not both.
I don't want to have declarative description to begin with, i was and sitll am perfectly happy with how it was done before, the monstricity of the new system is frightening and things are kept being added all the time.
Quoted 5 lines
There are more temporary variables in other devices, and this was the way it was done there. Normally I would have called it
active_vmstateto make that explicit, but here, it was also used for reset, that is the way I named it with the_vmstatesuffix.
In any case the while i can understand the fear of malloc, nobody forces you to do that you can have a scratch space on the stack, with an some upper cap, that's the way it's done now anyhow, only the cap is stack size reserved for the process and not something you have to choose.
Signature · 1 line
mailto:[email protected]
[Qemu-devel] Re: [PATCH 27/49] ac97: add active to the state
Quoted 29 lines · malc
Quoted 27 lines · Juan Quintela
Quoted 4 lines · malc
On Wed, 30 Sep 2009, Juan Quintela wrote:
active doesn't belong in the above structure, it's not used for anything other than save/loadvm.
It is used for reset, for instance. We can discuss if it belongs there or not, but will let that for another day.
Quoted 2 lines
If this "design" doesn't allow this, either find another way to accomplish the same or fix the "design".
VMStateDescription is a list of offsets from a known address. Address is the one from the state. That is the design.
Now, back to ac97. Rest of ac97 don't need the active field, because it is stored anywhere else (basically where AUD_set_active* store it).
Clearly it is part of ac97 state, becase it is needed for load/save/reset to work properly. It just happens that it is stored anywhere else for the design of the audio system.
At load/save time we don't want to call
malloc(), and now we have descriptions of the state, not functions that save/load the state. Only sane way of storing this kind of variables is storing them into the state.
Quoted 8 lines
Quoted 3 lines
Sorry, there is no way that we are going to have a declarative description of the state and retain the old functions to do save/load. You can only get only declarative description or functions, not both.
I don't want to have declarative description to begin with, i was and sitll am perfectly happy with how it was done before, the monstricity of the new system is frightening and things are kept being added all the time.
I can't answer to that.
Quoted 10 lines
Quoted 5 lines
There are more temporary variables in other devices, and this was the way it was done there. Normally I would have called it
active_vmstateto make that explicit, but here, it was also used for reset, that is the way I named it with the_vmstatesuffix.In any case the while i can understand the fear of malloc, nobody forces you to do that you can have a scratch space on the stack, with an some upper cap, that's the way it's done now anyhow, only the cap is stack size reserved for the process and not something you have to choose.
You call new way a monstrosity, and now propose a solution that makes the monster bigger?
I still stand behind the patch, and I still want it applied.
Later, Juan.
[Qemu-devel] Re: [PATCH 27/49] ac97: add active to the state
Quoted 52 lines · Juan Quintela
Quoted 29 lines · malc
Quoted 27 lines · Juan Quintela
Quoted 4 lines · malc
On Wed, 30 Sep 2009, Juan Quintela wrote:
active doesn't belong in the above structure, it's not used for anything other than save/loadvm.
It is used for reset, for instance. We can discuss if it belongs there or not, but will let that for another day.
Quoted 2 lines
If this "design" doesn't allow this, either find another way to accomplish the same or fix the "design".
VMStateDescription is a list of offsets from a known address. Address is the one from the state. That is the design.
Now, back to ac97. Rest of ac97 don't need the active field, because it is stored anywhere else (basically where AUD_set_active* store it).
Clearly it is part of ac97 state, becase it is needed for load/save/reset to work properly. It just happens that it is stored anywhere else for the design of the audio system.
At load/save time we don't want to call
malloc(), and now we have descriptions of the state, not functions that save/load the state. Only sane way of storing this kind of variables is storing them into the state.Quoted 8 lines
Quoted 3 lines
Sorry, there is no way that we are going to have a declarative description of the state and retain the old functions to do save/load. You can only get only declarative description or functions, not both.
I don't want to have declarative description to begin with, i was and sitll am perfectly happy with how it was done before, the monstricity of the new system is frightening and things are kept being added all the time.
I can't answer to that.
Quoted 10 lines
Quoted 5 lines
There are more temporary variables in other devices, and this was the way it was done there. Normally I would have called it
active_vmstateto make that explicit, but here, it was also used for reset, that is the way I named it with the_vmstatesuffix.In any case the while i can understand the fear of malloc, nobody forces you to do that you can have a scratch space on the stack, with an some upper cap, that's the way it's done now anyhow, only the cap is stack size reserved for the process and not something you have to choose.
Quoted 5 lines
You call new way a monstrosity, and now propose a solution that makes the monster bigger?
I still stand behind the patch, and I still want it applied.
And it wont be, not this part of it, not in this state.
Signature · 1 line
mailto:[email protected]
[Qemu-devel] Re: [PATCH 27/49] ac97: add active to the state
Quoted 10 lines · malc
Quoted 10 lines
Quoted 9 lines
Quoted 4 lines
There are more temporary variables in other devices, and this was the way it was done there. Normally I would have called it
active_vmstateto make that explicit, but here, it was also used for reset, that is the way I named it with the_vmstatesuffix.In any case the while i can understand the fear of malloc, nobody forces you to do that you can have a scratch space on the stack, with an some upper cap, that's the way it's done now anyhow, only the cap is stack size reserved for the process and not something you have to choose.
Quoted 7 lines
Quoted 5 lines
You call new way a monstrosity, and now propose a solution that makes the monster bigger?
I still stand behind the patch, and I still want it applied.
And it wont be, not this part of it, not in this state.
Suggestions? Because you are not telling me that you expect to move something to the stack, reimplement alloca() and work from there was a _real suggestion_?
Later, Juan.
[Qemu-devel] Re: [PATCH 27/49] ac97: add active to the state
Quoted 14 lines · Juan Quintela
Quoted 13 lines · malc
Quoted 13 lines
Quoted 9 lines
Quoted 4 lines
There are more temporary variables in other devices, and this was the way it was done there. Normally I would have called it
active_vmstateto make that explicit, but here, it was also used for reset, that is the way I named it with the_vmstatesuffix.In any case the while i can understand the fear of malloc, nobody forces you to do that you can have a scratch space on the stack, with an some upper cap, that's the way it's done now anyhow, only the cap is stack size reserved for the process and not something you have to choose.
You call new way a monstrosity, and now propose a solution that makes the monster bigger?
Quoted 9 lines
Quoted 4 lines
Quoted 2 lines
I still stand behind the patch, and I still want it applied.
And it wont be, not this part of it, not in this state.
Suggestions? Because you are not telling me that you expect to move something to the stack, reimplement
alloca()and work from there was a_realsuggestion_?
Yet somehow you are explecting me to solve the problems with your design for you, neat. Alloca can be used but is not strictly necessary.
char buf[UPPER_CAP]; and maybe temp_fields that point to it and survive the period between pre/post functions, would suffice, but anyhow, it's your problem to solve, to reiterate i'm quite happy with what is there now.
Signature · 1 line
mailto:[email protected]
[Qemu-devel] Re: [PATCH 27/49] ac97: add active to the state
Quoted 26 lines · malc
Quoted 14 lines · Juan Quintela
Quoted 13 lines · malc
Quoted 13 lines
Quoted 9 lines
Quoted 4 lines
There are more temporary variables in other devices, and this was the way it was done there. Normally I would have called it
active_vmstateto make that explicit, but here, it was also used for reset, that is the way I named it with the_vmstatesuffix.In any case the while i can understand the fear of malloc, nobody forces you to do that you can have a scratch space on the stack, with an some upper cap, that's the way it's done now anyhow, only the cap is stack size reserved for the process and not something you have to choose.
You call new way a monstrosity, and now propose a solution that makes the monster bigger?
Quoted 9 lines
Quoted 4 lines
Quoted 2 lines
I still stand behind the patch, and I still want it applied.
And it wont be, not this part of it, not in this state.
Suggestions? Because you are not telling me that you expect to move something to the stack, reimplement
alloca()and work from there was a_realsuggestion_?
Quoted 7 lines
Yet somehow you are explecting me to solve the problems with your design for you, neat. Alloca can be used but is not strictly necessary.
char buf[UPPER_CAP]; and maybe
temp_fieldsthat point to it and survive the period between pre/post functions, would suffice, but anyhow, it's your problem to solve, to reiterate i'm quite happy with what is there now.
No. Everywhere code changed as I changed in ac97. And everybody agrees. And now you told that everybody else was wrong, and that the only true way is changing everything else for a worse/uglier solution. As I told before, you have commit access, you win.
Discussion is at the point:
- you will accept _any_ solution that means not changing ac97. No compromises taken.
- I will not make VMState worse/uglier/more complex just to work-around your veto.
Patch don't goes in, you win and I have lost time porting ac97 to VMState.
Later, Juan.
[Qemu-devel] Re: [PATCH 27/49] ac97: add active to the state
Quoted 35 lines · Juan Quintela
Quoted 26 lines · malc
Quoted 14 lines · Juan Quintela
Quoted 13 lines · malc
Quoted 13 lines
Quoted 9 lines
Quoted 4 lines
There are more temporary variables in other devices, and this was the way it was done there. Normally I would have called it
active_vmstateto make that explicit, but here, it was also used for reset, that is the way I named it with the_vmstatesuffix.In any case the while i can understand the fear of malloc, nobody forces you to do that you can have a scratch space on the stack, with an some upper cap, that's the way it's done now anyhow, only the cap is stack size reserved for the process and not something you have to choose.
You call new way a monstrosity, and now propose a solution that makes the monster bigger?
Quoted 9 lines
Quoted 4 lines
Quoted 2 lines
I still stand behind the patch, and I still want it applied.
And it wont be, not this part of it, not in this state.
Suggestions? Because you are not telling me that you expect to move something to the stack, reimplement
alloca()and work from there was a_realsuggestion_?Quoted 7 lines
Yet somehow you are explecting me to solve the problems with your design for you, neat. Alloca can be used but is not strictly necessary.
char buf[UPPER_CAP]; and maybe
temp_fieldsthat point to it and survive the period between pre/post functions, would suffice, but anyhow, it's your problem to solve, to reiterate i'm quite happy with what is there now.
Quoted 8 lines
No. Everywhere code changed as I changed in ac97. And everybody agrees. And now you told that everybody else was wrong, and that the only true way is changing everything else for a worse/uglier solution. As I told before, you have commit access, you win.
Discussion is at the point:
- you will accept _any_ solution that means not changing ac97. No compromises taken.
I dont get this part, if you meant - am i against the patch modulo ac97 changes, then no i'm not, it's the respective maintainers opinion what matters.
Quoted 4 lines
- I will not make VMState worse/uglier/more complex just to work-around your veto.
Patch don't goes in, you win and I have lost time porting ac97 to VMState.
Yep.
Signature · 1 line
mailto:[email protected]
[Qemu-devel] Re: [PATCH 27/49] ac97: add active to the state
Quoted 9 lines · malc
Quoted 4 lines · Juan Quintela
Discussion is at the point:
- you will accept _any_ solution that means not changing ac97. No compromises taken.I dont get this part, if you meant - am i against the patch modulo ac97 changes, then no i'm not, it's the respective maintainers opinion what matters.
Just to clarify, I just meaned the ac97 patch.
Quoted 6 lines
Quoted 4 lines
- I will not make VMState worse/uglier/more complex just to work-around your veto.
Patch don't goes in, you win and I have lost time porting ac97 to VMState.
Yep.
Later, Juan.
Re: [Qemu-devel] Re: [PATCH 27/49] ac97: add active to the state
In reply to malcQuoted 13 lines · malc
Quoted 13 lines
Quoted 13 lines
hw/ac97.c typedef struct AC97LinkState { · line 173
Quoted 10 lines
hw/ac97.c +2
-0+ typedef struct AC97LinkState { PCIDevice dev; QEMUSoundCard card;@@ -162,6 +169,7 @@ typedef struct AC97LinkState {uint8_t silence[128 ];uint32_t base[2 ];int bup_flag; +uint8_t active[LAST_INDEX ];This doesn't belong here, cause the only purpose i can see is to hack around defficiencies of the new load/savevm APIs.
Quoted 9 lines
Quoted 4 lines
That was supposed to be one of the features, not deficiences. You can't sent stuff that it is not in the state. It is "by design" that you can't sent arbitrary variables.
active doesn't belong in the above structure, it's not used for anything other than save/loadvm. If this "design" doesn't allow this, either find another way to accomplish the same or fix the "design".
Looking briefly at the code, it looks like the active[] array isn't technically needed in the savevm state.
I think you could basically do:
AUD_set_active_in(s->voice_pi, !!(s->bm_regs[PI_INDEX].cr & CR_RPBM));
...
Better yet, active[] can be dynamically built from the contents of bm_regs->cr so there would be little code change.
So I think we should bump the version of the ac97 format, remove the active[] array from the vmstate, and then generate it in a post function that can then be passed to reset_voices().
Regards,
Anthony Liguori
[Qemu-devel] Re: [PATCH 27/49] ac97: add active to the state
Quoted 24 lines · Anthony Liguori
Quoted 13 lines · malc
Quoted 13 lines
Quoted 13 lines
hw/ac97.c typedef struct AC97LinkState { · line 173
Quoted 10 lines
hw/ac97.c +2
-0+ typedef struct AC97LinkState { PCIDevice dev; QEMUSoundCard card;@@ -162,6 +169,7 @@ typedef struct AC97LinkState {uint8_t silence[128 ];uint32_t base[2 ];int bup_flag; +uint8_t active[LAST_INDEX ];This doesn't belong here, cause the only purpose i can see is to hack around defficiencies of the new load/savevm APIs.
Quoted 9 lines
Quoted 4 lines
That was supposed to be one of the features, not deficiences. You can't sent stuff that it is not in the state. It is "by design" that you can't sent arbitrary variables.
active doesn't belong in the above structure, it's not used for anything other than save/loadvm. If this "design" doesn't allow this, either find another way to accomplish the same or fix the "design".
Quoted 7 lines
Looking briefly at the code, it looks like the active[] array isn't technically needed in the savevm state.
I think you could basically do:
AUD_set_active_in(s->voice_pi, !!(s->bm_regs[PI_INDEX].cr & CR_RPBM));
...
I don't doubt that you are right. I don't understand that bit of the code. active is created in other way, but I don't know if they are equivalent or not.
Quoted 6 lines
Better yet, active[] can be dynamically built from the contents of
bm_regs->crso there would be little code change.So I think we should bump the version of the ac97 format, remove the active[] array from the vmstate, and then generate it in a post function that can then be passed to
reset_voices().
Malc?
Later, Juan.
Re: [Qemu-devel] Re: [PATCH 27/49] ac97: add active to the state
In reply to Anthony LiguoriQuoted 32 lines · Anthony Liguori
Quoted 13 lines · malc
Quoted 13 lines
Quoted 13 lines
hw/ac97.c typedef struct AC97LinkState { · line 173
Quoted 10 lines
hw/ac97.c +2
-0+ typedef struct AC97LinkState { PCIDevice dev; QEMUSoundCard card;@@ -162,6 +169,7 @@ typedef struct AC97LinkState {uint8_t silence[128 ];uint32_t base[2 ];int bup_flag; +uint8_t active[LAST_INDEX ];This doesn't belong here, cause the only purpose i can see is to hack around defficiencies of the new load/savevm APIs.
Quoted 9 lines
Quoted 4 lines
That was supposed to be one of the features, not deficiences. You can't sent stuff that it is not in the state. It is "by design" that you can't sent arbitrary variables.
active doesn't belong in the above structure, it's not used for anything other than save/loadvm. If this "design" doesn't allow this, either find another way to accomplish the same or fix the "design".
Looking briefly at the code, it looks like the active[] array isn't technically needed in the savevm state.
I think you could basically do:
AUD_set_active_in(s->voice_pi, !!(s->bm_regs[PI_INDEX].cr & CR_RPBM)); ..
Quoted 6 lines
Better yet, active[] can be dynamically built from the contents of
bm_regs->crso there would be little code change.So I think we should bump the version of the ac97 format, remove the active[] array from the vmstate, and then generate it in a post function that can then be passed to
reset_voices().
Yes, however, what bothers me though, is that i ended up NOT doing that when the original code was written, there must have been a reason for me not doing that, and it completely elludes me at the moment, so no this isn't better yet, better yet implies someone having to go through the code and figure out whether it's safe or not.
Signature · 1 line
mailto:[email protected]
Re: [Qemu-devel] Re: [PATCH 27/49] ac97: add active to the state
Quoted 11 lines · malc
Quoted 2 lines · Anthony Liguori
So I think we should bump the version of the ac97 format, remove the active[] array from the vmstate, and then generate it in a post function that can then be passed to
reset_voices().Yes, however, what bothers me though, is that i ended up NOT doing that when the original code was written, there must have been a reason for me not doing that, and it completely elludes me at the moment, so no this isn't better yet, better yet implies someone having to go through the code and figure out whether it's safe or not.
I'm pretty convinced it's safe. The only way it wouldn't be is if it was possible for the active_in/active_out state in AUD to be changed through a means other than the device itself. Looking at audio.c, it's not possible.
But I also expect that Juan will be testing this device model when he resubmits the patch so that should confirm it.
Regards,
Anthony Liguori
Re: [Qemu-devel] Re: [PATCH 27/49] ac97: add active to the state
Quoted 15 lines · Anthony Liguori
Quoted 7 lines · malc
Quoted 4 lines · Anthony Liguori
So I think we should bump the version of the ac97 format, remove the active[] array from the vmstate, and then generate it in a post function that can then be passed to
reset_voices().Quoted 6 lines
Yes, however, what bothers me though, is that i ended up NOT doing that when the original code was written, there must have been a reason for me not doing that, and it completely elludes me at the moment, so no this isn't better yet, better yet implies someone having to go through the code and figure out whether it's safe or not.
Quoted 6 lines
I'm pretty convinced it's safe. The only way it wouldn't be is if it was possible for the active_in/active_out state in AUD to be changed through a means other than the device itself. Looking at
audio.c, it's not possible.But I also expect that Juan will be testing this device model when he resubmits the patch so that should confirm it.
Okay then, given it is tested.
Signature · 1 line
mailto:[email protected]
PATCH 28/49 vmstate: port ac97 device
In reply to Juan Quintela--- hw/ac97.c | 98 ++++++++++++++++++++++++++---------------------------------- 1 files changed, 43 insertions(+), 55 deletions(-)
hw/ac97.c +43 -55
@@ -1167,71 +1167,39 @@ static void po_callback (void *opaque, int free)transfer_audio (opaque,PO_INDEX , free); } -static void ac97_save (QEMUFile *f,void *opaque) +static const VMStateDescription vmstate_ac97_bm_regs = { + .name ="ac97_bm_regs" , + .version_id =1 , + .minimum_version_id =1 , + .minimum_version_id_old =1 , + .fields = (VMStateField []) { +VMSTATE_UINT32 (bdbar, AC97BusMasterRegs), +VMSTATE_UINT8 (civ, AC97BusMasterRegs), +VMSTATE_UINT8 (lvi, AC97BusMasterRegs), +VMSTATE_UINT16 (sr, AC97BusMasterRegs), +VMSTATE_UINT16 (picb, AC97BusMasterRegs), +VMSTATE_UINT8 (piv, AC97BusMasterRegs), +VMSTATE_UINT8 (cr, AC97BusMasterRegs), +VMSTATE_UINT32 (bd_valid, AC97BusMasterRegs), +VMSTATE_UINT32 (bd.addr, AC97BusMasterRegs), +VMSTATE_UINT32 (bd.ctl_len, AC97BusMasterRegs), +VMSTATE_END_OF_LIST () + } +}; + +static void ac97_pre_save (void *opaque) { -size_t i;AC97LinkState *s = opaque; -pci_device_save (&s->dev, f); - -qemu_put_be32s (f, &s->glob_cnt); -qemu_put_be32s (f, &s->glob_sta); -qemu_put_be32s (f, &s->cas); - -for (i =0 ; i <ARRAY_SIZE (s->bm_regs); ++i) { -AC97BusMasterRegs *r = &s->bm_regs[i]; -qemu_put_be32s (f, &r->bdbar); -qemu_put_8s (f, &r->civ); -qemu_put_8s (f, &r->lvi); -qemu_put_be16s (f, &r->sr); -qemu_put_be16s (f, &r->picb); -qemu_put_8s (f, &r->piv); -qemu_put_8s (f, &r->cr); -qemu_put_be32s (f, &r->bd_valid); -qemu_put_be32s (f, &r->bd.addr); -qemu_put_be32s (f, &r->bd.ctl_len); - } -qemu_put_buffer (f, s->mixer_data,sizeof (s->mixer_data)); - s->active[PI_INDEX ] =AUD_is_active_in (s->voice_pi) ?1 :0 ; s->active[PO_INDEX ] =AUD_is_active_out (s->voice_po) ?1 :0 ; s->active[MC_INDEX ] =AUD_is_active_in (s->voice_mc) ?1 :0 ; -qemu_put_buffer (f, s->active,sizeof (s->active)); } -static int ac97_load (QEMUFile *f,void *opaque,int version_id) +static int ac97_post_load (void *opaque,int version_id) { -int ret; -size_t i;AC97LinkState *s = opaque; -if (version_id !=2 ) -return -EINVAL ; - - ret =pci_device_load (&s->dev, f); -if (ret) -return ret; - -qemu_get_be32s (f, &s->glob_cnt); -qemu_get_be32s (f, &s->glob_sta); -qemu_get_be32s (f, &s->cas); - -for (i =0 ; i <ARRAY_SIZE (s->bm_regs); ++i) { -AC97BusMasterRegs *r = &s->bm_regs[i]; -qemu_get_be32s (f, &r->bdbar); -qemu_get_8s (f, &r->civ); -qemu_get_8s (f, &r->lvi); -qemu_get_be16s (f, &r->sr); -qemu_get_be16s (f, &r->picb); -qemu_get_8s (f, &r->piv); -qemu_get_8s (f, &r->cr); -qemu_get_be32s (f, &r->bd_valid); -qemu_get_be32s (f, &r->bd.addr); -qemu_get_be32s (f, &r->bd.ctl_len); - } -qemu_get_buffer (f, s->mixer_data,sizeof (s->mixer_data)); -qemu_get_buffer (f, s->active,sizeof (s->active)); -#ifdef USE_MIXER record_select (s,mixer_load (s, AC97_Record_Select));#define V_ (a, b) set_volume (s, a, b, mixer_load (s, a))
@@ -1247,6 +1215,26 @@ static int ac97_load (QEMUFile *f, void *opaque, int version_id)return 0 ; } +static const VMStateDescription vmstate_ac97 = { + .name ="ac97" , + .version_id =2 , + .minimum_version_id =2 , + .minimum_version_id_old =2 , + .pre_save = ac97_pre_save, + .post_load = ac97_post_load, + .fields = (VMStateField []) { +VMSTATE_PCI_DEVICE (dev, AC97LinkState), +VMSTATE_UINT32 (glob_cnt, AC97LinkState), +VMSTATE_UINT32 (glob_sta, AC97LinkState), +VMSTATE_UINT32 (cas, AC97LinkState), +VMSTATE_STRUCT_ARRAY (bm_regs, AC97LinkState,3 ,1 , + vmstate_ac97_bm_regs, AC97BusMasterRegs), +VMSTATE_BUFFER (mixer_data, AC97LinkState), +VMSTATE_BUFFER (active, AC97LinkState), +VMSTATE_END_OF_LIST () + } +}; +static void ac97_map (PCIDevice *pci_dev,int region_num,uint32_t addr,uint32_t size,int type) {
@@ -1331,7 +1319,7 @@ static int ac97_initfn (PCIDevice *dev)pci_register_bar (&s->dev,0 ,256 *4 ,PCI_ADDRESS_SPACE_IO , ac97_map);pci_register_bar (&s->dev,1 ,64 *4 ,PCI_ADDRESS_SPACE_IO , ac97_map); -register_savevm ("ac97" ,0 ,2 , ac97_save, ac97_load, s); +vmstate_register (0 , &vmstate_ac97, s);qemu_register_reset (ac97_on_reset, s);AUD_register_card ("ac97" , &s->card);ac97_on_reset (s);
Signature · 1 line
1.6.2.5
PATCH 29/49 x86: hflags is not modified at all, just save it directly
In reply to Juan Quintela--- target-i386/machine.c | 10 ++-------- 1 files changed, 2 insertions(+), 8 deletions(-)
target-i386/machine.c +2 -8
@@ -27,7 +27,6 @@ void cpu_save(QEMUFile *f, void *opaque) {CPUState *env = opaque;uint16_t fptag, fpus, fpuc, fpregs_format; -uint32_t hflags;int32_t a20_mask;int32_t pending_irq;int i, bit;
@@ -38,8 +37,7 @@ void cpu_save(QEMUFile *f, void *opaque)qemu_put_betls (f, &env->regs[i]);qemu_put_betls (f, &env->eip);qemu_put_betls (f, &env->eflags); - hflags = env->hflags;/* XXX: suppress most of the redundant hflags */ -qemu_put_be32s (f, &hflags); +qemu_put_be32s (f, &env->hflags);/* FPU */ fpuc = env->fpuc;
@@ -201,7 +199,6 @@ int cpu_load(QEMUFile *f, void *opaque, int version_id) {CPUState *env = opaque;int i, guess_mmx; -uint32_t hflags;uint16_t fpus, fpuc, fptag, fpregs_format;int32_t a20_mask;int32_t pending_irq;
@@ -213,7 +210,7 @@ int cpu_load(QEMUFile *f, void *opaque, int version_id)qemu_get_betls (f, &env->regs[i]);qemu_get_betls (f, &env->eip);qemu_get_betls (f, &env->eflags); -qemu_get_be32s (f, &hflags); +qemu_get_be32s (f, &env->hflags);qemu_get_be16s (f, &fpuc);qemu_get_be16s (f, &fpus);
@@ -377,9 +374,6 @@ int cpu_load(QEMUFile *f, void *opaque, int version_id) } } -/* XXX: ensure compatiblity for halted bit ? */ -/* XXX: compute redundant hflags bits */ - env->hflags = hflags;tlb_flush (env,1 );return 0 ; }
Signature · 1 line
1.6.2.5
PATCH 30/49 x86: make a20_mask int32_t
In reply to Juan QuintelaThis makes the savevm code correct, and sign extensins gives us exactly what we need (namely, sign extend to 64 bits when used with 64bit addresess.
Once there, change 0x100000 for 1 << 20, that maks all a20 use the same syntax.
--- target-i386/cpu.h | 2 +- target-i386/helper.c | 6 +++--- target-i386/machine.c | 9 ++------- 3 files changed, 6 insertions(+), 11 deletions(-)
target-i386/cpu.h +1 -1
@@ -588,7 +588,7 @@ typedef struct CPUX86State {SegmentCache idt;/* only base and limit are used */ target_ulong cr[5 ];/* NOTE: cr1 is unused */ -uint64_t a20_mask; +int32_t a20_mask;/* FPU state */ unsigned int fpstt;/* top of stack index */
target-i386/helper.c +3 -3
@@ -780,7 +780,7 @@ void cpu_dump_state(CPUState *env, FILE *f, eflags &CC_C ?'C' :'-' , env->hflags &HF_CPL_MASK , (env->hflags >>HF_INHIBIT_IRQ_SHIFT ) &1 , - (int )(env->a20_mask >>20 ) &1 , + (env->a20_mask >>20 ) &1 , (env->hflags >>HF_SMM_SHIFT ) &1 , env->halted); }else
@@ -807,7 +807,7 @@ void cpu_dump_state(CPUState *env, FILE *f, eflags &CC_C ?'C' :'-' , env->hflags &HF_CPL_MASK , (env->hflags >>HF_INHIBIT_IRQ_SHIFT ) &1 , - (int )(env->a20_mask >>20 ) &1 , + (env->a20_mask >>20 ) &1 , (env->hflags >>HF_SMM_SHIFT ) &1 , env->halted); }
@@ -938,7 +938,7 @@ void cpu_x86_set_a20(CPUX86State *env, int a20_state)/* when a20 is changed, all the MMU mappings are invalid, so we must flush everything */ tlb_flush (env,1 ); - env->a20_mask = (~0x100000 ) | (a20_state <<20 ); + env->a20_mask = ~(1 <<20 ) | (a20_state <<20 ); } }
target-i386/machine.c +2 -7
@@ -27,7 +27,6 @@ void cpu_save(QEMUFile *f, void *opaque) {CPUState *env = opaque;uint16_t fptag, fpus, fpuc, fpregs_format; -int32_t a20_mask;int32_t pending_irq;int i, bit;
@@ -98,8 +97,7 @@ void cpu_save(QEMUFile *f, void *opaque)qemu_put_betls (f, &env->dr[i]);/* MMU */ - a20_mask = (int32_t ) env->a20_mask; -qemu_put_sbe32s (f, &a20_mask); +qemu_put_sbe32s (f, &env->a20_mask);/* XMM */ qemu_put_be32s (f, &env->mxcsr);
@@ -200,7 +198,6 @@ int cpu_load(QEMUFile *f, void *opaque, int version_id)CPUState *env = opaque;int i, guess_mmx;uint16_t fpus, fpuc, fptag, fpregs_format; -int32_t a20_mask;int32_t pending_irq;cpu_synchronize_state (env);
@@ -299,9 +296,7 @@ int cpu_load(QEMUFile *f, void *opaque, int version_id)for (i =0 ; i <4 ; i++)hw_breakpoint_insert (env, i); -/* MMU */ -qemu_get_sbe32s (f, &a20_mask); - env->a20_mask = a20_mask; +qemu_get_sbe32s (f, &env->a20_mask);qemu_get_be32s (f, &env->mxcsr);for (i =0 ; i <CPU_NB_REGS ; i++) {
Signature · 1 line
1.6.2.5
PATCH 31/49 x86: fpuc is uint16_t not unsigned int
In reply to Juan Quintela--- target-i386/cpu.h | 2 +- target-i386/machine.c | 10 ++++------ 2 files changed, 5 insertions(+), 7 deletions(-)
target-i386/cpu.h +1 -1
@@ -593,7 +593,7 @@ typedef struct CPUX86State {/* FPU state */ unsigned int fpstt;/* top of stack index */ unsigned int fpus; -unsigned int fpuc; +uint16_t fpuc;uint8_t fptags[8 ];/* 0 = valid, 1 = empty */ union {#ifdef USE_X86LDOUBLE
target-i386/machine.c +4 -6
@@ -26,7 +26,7 @@ static void cpu_get_seg(QEMUFile *f, SegmentCache *dt)void cpu_save (QEMUFile *f,void *opaque) {CPUState *env = opaque; -uint16_t fptag, fpus, fpuc, fpregs_format; +uint16_t fptag, fpus, fpregs_format;int32_t pending_irq;int i, bit;
@@ -39,14 +39,13 @@ void cpu_save(QEMUFile *f, void *opaque)qemu_put_be32s (f, &env->hflags);/* FPU */ - fpuc = env->fpuc; fpus = (env->fpus & ~0x3800 ) | (env->fpstt &0x7 ) <<11 ; fptag =0 ;for (i =0 ; i <8 ; i++) { fptag |= ((!env->fptags[i]) << i); } -qemu_put_be16s (f, &fpuc); +qemu_put_be16s (f, &env->fpuc);qemu_put_be16s (f, &fpus);qemu_put_be16s (f, &fptag);
@@ -197,7 +196,7 @@ int cpu_load(QEMUFile *f, void *opaque, int version_id) {CPUState *env = opaque;int i, guess_mmx; -uint16_t fpus, fpuc, fptag, fpregs_format; +uint16_t fpus, fptag, fpregs_format;int32_t pending_irq;cpu_synchronize_state (env);
@@ -209,7 +208,7 @@ int cpu_load(QEMUFile *f, void *opaque, int version_id)qemu_get_betls (f, &env->eflags);qemu_get_be32s (f, &env->hflags); -qemu_get_be16s (f, &fpuc); +qemu_get_be16s (f, &env->fpuc);qemu_get_be16s (f, &fpus);qemu_get_be16s (f, &fptag);qemu_get_be16s (f, &fpregs_format);
@@ -259,7 +258,6 @@ int cpu_load(QEMUFile *f, void *opaque, int version_id) } } - env->fpuc = fpuc;/* XXX: restore FPU round state */ env->fpstt = (fpus >>11 ) &7 ; env->fpus = fpus & ~0x3800 ;
Signature · 1 line
1.6.2.5
PATCH 32/49 x86: fpus is uint16_t not unsigned int
In reply to Juan QuintelaWe save more that fpus on that 16 bits (fpstt), we need an additional field
--- target-i386/cpu.h | 3 ++- target-i386/machine.c | 16 ++++++++-------- 2 files changed, 10 insertions(+), 9 deletions(-)
target-i386/cpu.h +2 -1
@@ -592,7 +592,8 @@ typedef struct CPUX86State {/* FPU state */ unsigned int fpstt;/* top of stack index */ -unsigned int fpus; +uint16_t fpus; +uint16_t fpus_vmstate;uint16_t fpuc;uint8_t fptags[8 ];/* 0 = valid, 1 = empty */ union {
target-i386/machine.c +8 -8
@@ -26,7 +26,7 @@ static void cpu_get_seg(QEMUFile *f, SegmentCache *dt)void cpu_save (QEMUFile *f,void *opaque) {CPUState *env = opaque; -uint16_t fptag, fpus, fpregs_format; +uint16_t fptag, fpregs_format;int32_t pending_irq;int i, bit;
@@ -39,14 +39,14 @@ void cpu_save(QEMUFile *f, void *opaque)qemu_put_be32s (f, &env->hflags);/* FPU */ - fpus = (env->fpus & ~0x3800 ) | (env->fpstt &0x7 ) <<11 ; + env->fpus_vmstate = (env->fpus & ~0x3800 ) | (env->fpstt &0x7 ) <<11 ; fptag =0 ;for (i =0 ; i <8 ; i++) { fptag |= ((!env->fptags[i]) << i); }qemu_put_be16s (f, &env->fpuc); -qemu_put_be16s (f, &fpus); +qemu_put_be16s (f, &env->fpus_vmstate);qemu_put_be16s (f, &fptag);#ifdef USE_X86LDOUBLE
@@ -196,7 +196,7 @@ int cpu_load(QEMUFile *f, void *opaque, int version_id) {CPUState *env = opaque;int i, guess_mmx; -uint16_t fpus, fptag, fpregs_format; +uint16_t fptag, fpregs_format;int32_t pending_irq;cpu_synchronize_state (env);
@@ -209,14 +209,14 @@ int cpu_load(QEMUFile *f, void *opaque, int version_id)qemu_get_be32s (f, &env->hflags);qemu_get_be16s (f, &env->fpuc); -qemu_get_be16s (f, &fpus); +qemu_get_be16s (f, &env->fpus_vmstate);qemu_get_be16s (f, &fptag);qemu_get_be16s (f, &fpregs_format);/* NOTE: we cannot always restore the FPU state if the image come from a host with a different 'USE_X86LDOUBLE' define. We guess if we are in an MMX state to restore correctly in that case. */ - guess_mmx = ((fptag ==0xff ) && (fpus &0x3800 ) ==0 ); + guess_mmx = ((fptag ==0xff ) && (env->fpus_vmstate &0x3800 ) ==0 );for (i =0 ; i <8 ; i++) {uint64_t mant;uint16_t exp;
@@ -259,8 +259,8 @@ int cpu_load(QEMUFile *f, void *opaque, int version_id) }/* XXX: restore FPU round state */ - env->fpstt = (fpus >>11 ) &7 ; - env->fpus = fpus & ~0x3800 ; + env->fpstt = (env->fpus_vmstate >>11 ) &7 ; + env->fpus = env->fpus_vmstate & ~0x3800 ; fptag ^=0xff ;for (i =0 ; i <8 ; i++) { env->fptags[i] = (fptag >> i) &1 ;
Signature · 1 line
1.6.2.5
PATCH 33/49 x86: add fptag_vmstate to the state
In reply to Juan QuintelaIt is needed to store fptags
--- target-i386/cpu.h | 1 + target-i386/machine.c | 18 +++++++++--------- 2 files changed, 10 insertions(+), 9 deletions(-)
target-i386/cpu.h +1 -0
@@ -594,6 +594,7 @@ typedef struct CPUX86State {unsigned int fpstt;/* top of stack index */ uint16_t fpus;uint16_t fpus_vmstate; +uint16_t fptag_vmstate;uint16_t fpuc;uint8_t fptags[8 ];/* 0 = valid, 1 = empty */ union {
target-i386/machine.c +9 -9
@@ -26,7 +26,7 @@ static void cpu_get_seg(QEMUFile *f, SegmentCache *dt)void cpu_save (QEMUFile *f,void *opaque) {CPUState *env = opaque; -uint16_t fptag, fpregs_format; +uint16_t fpregs_format;int32_t pending_irq;int i, bit;
@@ -40,14 +40,14 @@ void cpu_save(QEMUFile *f, void *opaque)/* FPU */ env->fpus_vmstate = (env->fpus & ~0x3800 ) | (env->fpstt &0x7 ) <<11 ; - fptag =0 ; + env->fptag_vmstate =0 ;for (i =0 ; i <8 ; i++) { - fptag |= ((!env->fptags[i]) << i); + env->fptag_vmstate |= ((!env->fptags[i]) << i); }qemu_put_be16s (f, &env->fpuc);qemu_put_be16s (f, &env->fpus_vmstate); -qemu_put_be16s (f, &fptag); +qemu_put_be16s (f, &env->fptag_vmstate);#ifdef USE_X86LDOUBLE fpregs_format =0 ;
@@ -196,7 +196,7 @@ int cpu_load(QEMUFile *f, void *opaque, int version_id) {CPUState *env = opaque;int i, guess_mmx; -uint16_t fptag, fpregs_format; +uint16_t fpregs_format;int32_t pending_irq;cpu_synchronize_state (env);
@@ -210,13 +210,13 @@ int cpu_load(QEMUFile *f, void *opaque, int version_id)qemu_get_be16s (f, &env->fpuc);qemu_get_be16s (f, &env->fpus_vmstate); -qemu_get_be16s (f, &fptag); +qemu_get_be16s (f, &env->fptag_vmstate);qemu_get_be16s (f, &fpregs_format);/* NOTE: we cannot always restore the FPU state if the image come from a host with a different 'USE_X86LDOUBLE' define. We guess if we are in an MMX state to restore correctly in that case. */ - guess_mmx = ((fptag ==0xff ) && (env->fpus_vmstate &0x3800 ) ==0 ); + guess_mmx = ((env->fptag_vmstate ==0xff ) && (env->fpus_vmstate &0x3800 ) ==0 );for (i =0 ; i <8 ; i++) {uint64_t mant;uint16_t exp;
@@ -261,9 +261,9 @@ int cpu_load(QEMUFile *f, void *opaque, int version_id)/* XXX: restore FPU round state */ env->fpstt = (env->fpus_vmstate >>11 ) &7 ; env->fpus = env->fpus_vmstate & ~0x3800 ; - fptag ^=0xff ; + env->fptag_vmstate ^=0xff ;for (i =0 ; i <8 ; i++) { - env->fptags[i] = (fptag >> i) &1 ; + env->fptags[i] = (env->fptag_vmstate >> i) &1 ; }for (i =0 ; i <6 ; i++)
Signature · 1 line
1.6.2.5
PATCH 34/49 x86: add pending_irq_vmstate to the state
In reply to Juan QuintelaIt is needed to save the interrupt_bitmap
--- target-i386/cpu.h | 1 + target-i386/machine.c | 16 +++++++--------- 2 files changed, 8 insertions(+), 9 deletions(-)
target-i386/cpu.h +1 -0
@@ -686,6 +686,7 @@ typedef struct CPUX86State {/* For KVM */ uint64_t interrupt_bitmap[256 /64 ]; +int32_t pending_irq_vmstate;uint32_t mp_state;/* in order to simplify APIC support, we leave this pointer to the
target-i386/machine.c +7 -9
@@ -27,7 +27,6 @@ void cpu_save(QEMUFile *f, void *opaque) {CPUState *env = opaque;uint16_t fpregs_format; -int32_t pending_irq;int i, bit;cpu_synchronize_state (env);
@@ -142,15 +141,15 @@ void cpu_save(QEMUFile *f, void *opaque)/* There can only be one pending IRQ set in the bitmap at a time, so try to find it and save its number instead (-1 for none). */ - pending_irq =-1 ; + env->pending_irq_vmstate =-1 ;for (i =0 ; i <ARRAY_SIZE (env->interrupt_bitmap); i++) {if (env->interrupt_bitmap[i]) { bit =ctz64 (env->interrupt_bitmap[i]); - pending_irq = i *64 + bit; + env->pending_irq_vmstate = i *64 + bit;break ; } } -qemu_put_sbe32s (f, &pending_irq); +qemu_put_sbe32s (f, &env->pending_irq_vmstate);qemu_put_be32s (f, &env->mp_state);qemu_put_be64s (f, &env->tsc);
@@ -197,7 +196,6 @@ int cpu_load(QEMUFile *f, void *opaque, int version_id)CPUState *env = opaque;int i, guess_mmx;uint16_t fpregs_format; -int32_t pending_irq;cpu_synchronize_state (env);if (version_id <3 || version_id >CPU_SAVE_VERSION )
@@ -343,11 +341,11 @@ int cpu_load(QEMUFile *f, void *opaque, int version_id) }if (version_id >=9 ) { -qemu_get_sbe32s (f, &pending_irq); +qemu_get_sbe32s (f, &env->pending_irq_vmstate);memset (&env->interrupt_bitmap,0 ,sizeof (env->interrupt_bitmap)); -if (pending_irq >=0 ) { - env->interrupt_bitmap[pending_irq /64 ] |= - (uint64_t )1 << (pending_irq %64 ); +if (env->pending_irq_vmstate >=0 ) { + env->interrupt_bitmap[env->pending_irq_vmstate /64 ] |= + (uint64_t )1 << (env->pending_irq_vmstate %64 ); }qemu_get_be32s (f, &env->mp_state);qemu_get_be64s (f, &env->tsc);
Signature · 1 line
1.6.2.5
PATCH 35/49 x86: add fpregs_format_vmstate
In reply to Juan QuintelaDon't even ask, being able to load/save between 64<->80bit floats should be forbidden
--- target-i386/cpu.h | 1 + target-i386/machine.c | 12 +++++------- 2 files changed, 6 insertions(+), 7 deletions(-)
target-i386/cpu.h +1 -0
@@ -595,6 +595,7 @@ typedef struct CPUX86State {uint16_t fpus;uint16_t fpus_vmstate;uint16_t fptag_vmstate; +uint16_t fpregs_format_vmstate;uint16_t fpuc;uint8_t fptags[8 ];/* 0 = valid, 1 = empty */ union {
target-i386/machine.c +5 -7
@@ -26,7 +26,6 @@ static void cpu_get_seg(QEMUFile *f, SegmentCache *dt)void cpu_save (QEMUFile *f,void *opaque) {CPUState *env = opaque; -uint16_t fpregs_format;int i, bit;cpu_synchronize_state (env);
@@ -49,11 +48,11 @@ void cpu_save(QEMUFile *f, void *opaque)qemu_put_be16s (f, &env->fptag_vmstate);#ifdef USE_X86LDOUBLE - fpregs_format =0 ; + env->fpregs_format_vmstate =0 ;#else - fpregs_format =1 ; + env->fpregs_format_vmstate =1 ;#endif -qemu_put_be16s (f, &fpregs_format); +qemu_put_be16s (f, &env->fpregs_format_vmstate);for (i =0 ; i <8 ; i++) {#ifdef USE_X86LDOUBLE
@@ -195,7 +194,6 @@ int cpu_load(QEMUFile *f, void *opaque, int version_id) {CPUState *env = opaque;int i, guess_mmx; -uint16_t fpregs_format;cpu_synchronize_state (env);if (version_id <3 || version_id >CPU_SAVE_VERSION )
@@ -209,7 +207,7 @@ int cpu_load(QEMUFile *f, void *opaque, int version_id)qemu_get_be16s (f, &env->fpuc);qemu_get_be16s (f, &env->fpus_vmstate);qemu_get_be16s (f, &env->fptag_vmstate); -qemu_get_be16s (f, &fpregs_format); +qemu_get_be16s (f, &env->fpregs_format_vmstate);/* NOTE: we cannot always restore the FPU state if the image come from a host with a different 'USE_X86LDOUBLE' define. We guess
@@ -219,7 +217,7 @@ int cpu_load(QEMUFile *f, void *opaque, int version_id)uint64_t mant;uint16_t exp; -switch (fpregs_format) { +switch (env->fpregs_format_vmstate) {case 0 : mant =qemu_get_be64 (f); exp =qemu_get_be16 (f);
Signature · 1 line
1.6.2.5
PATCH 36/49 x86: mce_banks always have the same size
In reply to Juan Quintelamce_banks is always MCE_BANKS_DEF * 4 in size, value never change
--- target-i386/cpu.h | 2 +- target-i386/helper.c | 3 +-- target-i386/machine.c | 4 ++-- 3 files changed, 4 insertions(+), 5 deletions(-)
target-i386/cpu.h +1 -1
@@ -697,7 +697,7 @@ typedef struct CPUX86State {uint64 mcg_cap;uint64 mcg_status;uint64 mcg_ctl; -uint64 *mce_banks; +uint64 mce_banks[MCE_BANKS_DEF *4 ]; } CPUX86State;CPUX86State *cpu_x86_init (const char *cpu_model);
target-i386/helper.c +1 -2
@@ -1597,8 +1597,7 @@ static void mce_init(CPUX86State *cenv) && (cenv->cpuid_features&(CPUID_MCE|CPUID_MCA)) == (CPUID_MCE|CPUID_MCA)) { cenv->mcg_cap =MCE_CAP_DEF |MCE_BANKS_DEF ; cenv->mcg_ctl = ~(uint64_t )0 ; - bank_num = cenv->mcg_cap &0xff ; - cenv->mce_banks =qemu_mallocz (bank_num *sizeof (uint64_t ) *4 ); + bank_num =MCE_BANKS_DEF ;for (bank =0 ; bank < bank_num; bank++) cenv->mce_banks[bank*4 ] = ~(uint64_t )0 ; }
target-i386/machine.c +2 -2
@@ -157,7 +157,7 @@ void cpu_save(QEMUFile *f, void *opaque)if (env->mcg_cap) {qemu_put_be64s (f, &env->mcg_status);qemu_put_be64s (f, &env->mcg_ctl); -for (i =0 ; i < (env->mcg_cap &0xff ); i++) { +for (i =0 ; i <MCE_BANKS_DEF ; i++) {qemu_put_be64s (f, &env->mce_banks[4 *i]);qemu_put_be64s (f, &env->mce_banks[4 *i +1 ]);qemu_put_be64s (f, &env->mce_banks[4 *i +2 ]);
@@ -354,7 +354,7 @@ int cpu_load(QEMUFile *f, void *opaque, int version_id)if (env->mcg_cap) {qemu_get_be64s (f, &env->mcg_status);qemu_get_be64s (f, &env->mcg_ctl); -for (i =0 ; i < (env->mcg_cap &0xff ); i++) { +for (i =0 ; i <MCE_BANKS_DEF ; i++) {qemu_get_be64s (f, &env->mce_banks[4 *i]);qemu_get_be64s (f, &env->mce_banks[4 *i +1 ]);qemu_get_be64s (f, &env->mce_banks[4 *i +2 ]);
Signature · 1 line
1.6.2.5
PATCH 37/49 x86: send mce_banks as an array
In reply to Juan Quintela--- target-i386/machine.c | 14 ++++---------- 1 files changed, 4 insertions(+), 10 deletions(-)
target-i386/machine.c +4 -10
@@ -157,11 +157,8 @@ void cpu_save(QEMUFile *f, void *opaque)if (env->mcg_cap) {qemu_put_be64s (f, &env->mcg_status);qemu_put_be64s (f, &env->mcg_ctl); -for (i =0 ; i <MCE_BANKS_DEF ; i++) { -qemu_put_be64s (f, &env->mce_banks[4 *i]); -qemu_put_be64s (f, &env->mce_banks[4 *i +1 ]); -qemu_put_be64s (f, &env->mce_banks[4 *i +2 ]); -qemu_put_be64s (f, &env->mce_banks[4 *i +3 ]); +for (i =0 ; i <MCE_BANKS_DEF *4 ; i++) { +qemu_put_be64s (f, &env->mce_banks[i]); } } }
@@ -354,11 +351,8 @@ int cpu_load(QEMUFile *f, void *opaque, int version_id)if (env->mcg_cap) {qemu_get_be64s (f, &env->mcg_status);qemu_get_be64s (f, &env->mcg_ctl); -for (i =0 ; i <MCE_BANKS_DEF ; i++) { -qemu_get_be64s (f, &env->mce_banks[4 *i]); -qemu_get_be64s (f, &env->mce_banks[4 *i +1 ]); -qemu_get_be64s (f, &env->mce_banks[4 *i +2 ]); -qemu_get_be64s (f, &env->mce_banks[4 *i +3 ]); +for (i =0 ; i <MCE_BANKS_DEF *4 ; i++) { +qemu_get_be64s (f, &env->mce_banks[i]); } } }
Signature · 1 line
1.6.2.5
PATCH 38/49 x86: mcg_cap is never 0
In reply to Juan Quintela--- target-i386/machine.c | 20 ++++++++------------ 1 files changed, 8 insertions(+), 12 deletions(-)
target-i386/machine.c +8 -12
@@ -154,12 +154,10 @@ void cpu_save(QEMUFile *f, void *opaque)/* MCE */ qemu_put_be64s (f, &env->mcg_cap); -if (env->mcg_cap) { -qemu_put_be64s (f, &env->mcg_status); -qemu_put_be64s (f, &env->mcg_ctl); -for (i =0 ; i <MCE_BANKS_DEF *4 ; i++) { -qemu_put_be64s (f, &env->mce_banks[i]); - } +qemu_put_be64s (f, &env->mcg_status); +qemu_put_be64s (f, &env->mcg_ctl); +for (i =0 ; i <MCE_BANKS_DEF *4 ; i++) { +qemu_put_be64s (f, &env->mce_banks[i]); } }
@@ -348,12 +346,10 @@ int cpu_load(QEMUFile *f, void *opaque, int version_id)if (version_id >=10 ) {qemu_get_be64s (f, &env->mcg_cap); -if (env->mcg_cap) { -qemu_get_be64s (f, &env->mcg_status); -qemu_get_be64s (f, &env->mcg_ctl); -for (i =0 ; i <MCE_BANKS_DEF *4 ; i++) { -qemu_get_be64s (f, &env->mce_banks[i]); - } +qemu_get_be64s (f, &env->mcg_status); +qemu_get_be64s (f, &env->mcg_ctl); +for (i =0 ; i <MCE_BANKS_DEF *4 ; i++) { +qemu_get_be64s (f, &env->mce_banks[i]); } }
Signature · 1 line
1.6.2.5
PATCH 39/49 x86: split FPReg union
In reply to Juan Quintela--- target-i386/cpu.h | 18 ++++++++++-------- 1 files changed, 10 insertions(+), 8 deletions(-)
target-i386/cpu.h +10 -8
@@ -555,6 +555,15 @@ typedef union {#endif #define MMX_Q (n) q +typedef union { +#ifdef USE_X86LDOUBLE +CPU86_LDouble d __attribute__((aligned (16 ))); +#else +CPU86_LDouble d; +#endif +MMXReg mmx; +}FPReg ; +#ifdef TARGET_X86_64 #define CPU_NB_REGS 16#else
@@ -598,14 +607,7 @@ typedef struct CPUX86State {uint16_t fpregs_format_vmstate;uint16_t fpuc;uint8_t fptags[8 ];/* 0 = valid, 1 = empty */ -union { -#ifdef USE_X86LDOUBLE -CPU86_LDouble d __attribute__((aligned (16 ))); -#else -CPU86_LDouble d; -#endif -MMXReg mmx; - } fpregs[8 ]; +FPReg fpregs[8 ];/* emulator internal variables */ float_status fp_status;
Signature · 1 line
1.6.2.5
PATCH 40/49 x86: split MTRRVar union
In reply to Juan Quintela--- target-i386/cpu.h | 10 ++++++---- 1 files changed, 6 insertions(+), 4 deletions(-)
target-i386/cpu.h +6 -4
@@ -564,6 +564,11 @@ typedef union {MMXReg mmx; } FPReg; +typedef struct { +uint64_t base; +uint64_t mask; +}MTRRVar ; +#ifdef TARGET_X86_64 #define CPU_NB_REGS 16#else
@@ -682,10 +687,7 @@ typedef struct CPUX86State {/* MTRRs */ uint64_t mtrr_fixed[11 ];uint64_t mtrr_deftype; -struct { -uint64_t base; -uint64_t mask; - } mtrr_var[8 ]; +MTRRVar mtrr_var[8 ];/* For KVM */ uint64_t interrupt_bitmap[256 /64 ];
Signature · 1 line
1.6.2.5
PATCH 41/49 Add *TL functions to vmstate
In reply to Juan Quintela--- hw/hw.h | 19 +++++++++++++++++++ 1 files changed, 19 insertions(+), 0 deletions(-)
hw/hw.h +19 -0
@@ -587,6 +587,25 @@ extern const VMStateDescription vmstate_i2c_slave;#define VMSTATE_BUFFER (_f, _s) \ VMSTATE_STATIC_BUFFER(_f, _s, 0) +#ifdef NEED_CPU_H +#if TARGET_LONG_BITS ==64 +#define VMSTATE_UINTTL_V (_f, _s, _v) \ + VMSTATE_UINT64_V(_f, _s, _v) +#define VMSTATE_UINTTL_ARRAY_V (_f, _s, _n, _v) \ + VMSTATE_UINT64_ARRAY_V(_f, _s, _n, _v) +#else +#define VMSTATE_UINTTL_V (_f, _s, _v) \ + VMSTATE_UINT32_V(_f, _s, _v) +#define VMSTATE_UINTTL_ARRAY_V (_f, _s, _n, _v) \ + VMSTATE_UINT32_ARRAY_V(_f, _s, _n, _v) +#endif +#define VMSTATE_UINTTL (_f, _s) \ + VMSTATE_UINTTL_V(_f, _s, 0) +#define VMSTATE_UINTTL_ARRAY (_f, _s, _n) \ + VMSTATE_UINTTL_ARRAY_V(_f, _s, _n, 0) + +#endif +#define VMSTATE_END_OF_LIST () \ {}
Signature · 1 line
1.6.2.5
PATCH 42/49 x86: port segments to vmstate
In reply to Juan Quintela--- target-i386/machine.c | 24 ++++++++++++++++-------- 1 files changed, 16 insertions(+), 8 deletions(-)
target-i386/machine.c +16 -8
@@ -7,20 +7,28 @@#include "exec-all.h" #include "kvm.h" +static const VMStateDescription vmstate_segment = { + .name ="segment" , + .version_id =1 , + .minimum_version_id =1 , + .minimum_version_id_old =1 , + .fields = (VMStateField []) { +VMSTATE_UINT32 (selector, SegmentCache), +VMSTATE_UINTTL (base, SegmentCache), +VMSTATE_UINT32 (limit, SegmentCache), +VMSTATE_UINT32 (flags, SegmentCache), +VMSTATE_END_OF_LIST () + } +}; +static void cpu_put_seg (QEMUFile *f,SegmentCache *dt) { -qemu_put_be32 (f, dt->selector); -qemu_put_betl (f, dt->base); -qemu_put_be32 (f, dt->limit); -qemu_put_be32 (f, dt->flags); +vmstate_save_state (f, &vmstate_segment, dt); }static void cpu_get_seg (QEMUFile *f,SegmentCache *dt) { - dt->selector =qemu_get_be32 (f); - dt->base =qemu_get_betl (f); - dt->limit =qemu_get_be32 (f); - dt->flags =qemu_get_be32 (f); +vmstate_load_state (f, &vmstate_segment, dt, vmstate_segment.version_id); }void cpu_save (QEMUFile *f,void *opaque)
Signature · 1 line
1.6.2.5
PATCH 43/49 x86: factor out cpu_pre_save()
In reply to Juan Quintela--- target-i386/machine.c | 53 +++++++++++++++++++++++++++++------------------- 1 files changed, 32 insertions(+), 21 deletions(-)
target-i386/machine.c +32 -21
@@ -31,19 +31,13 @@ static void cpu_get_seg(QEMUFile *f, SegmentCache *dt)vmstate_load_state (f, &vmstate_segment, dt, vmstate_segment.version_id); } -void cpu_save (QEMUFile *f,void *opaque) +static void cpu_pre_save (void *opaque) {CPUState *env = opaque;int i, bit;cpu_synchronize_state (env); -for (i =0 ; i <CPU_NB_REGS ; i++) -qemu_put_betls (f, &env->regs[i]); -qemu_put_betls (f, &env->eip); -qemu_put_betls (f, &env->eflags); -qemu_put_be32s (f, &env->hflags); -/* FPU */ env->fpus_vmstate = (env->fpus & ~0x3800 ) | (env->fpstt &0x7 ) <<11 ; env->fptag_vmstate =0 ;
@@ -51,15 +45,42 @@ void cpu_save(QEMUFile *f, void *opaque) env->fptag_vmstate |= ((!env->fptags[i]) << i); } -qemu_put_be16s (f, &env->fpuc); -qemu_put_be16s (f, &env->fpus_vmstate); -qemu_put_be16s (f, &env->fptag_vmstate); -#ifdef USE_X86LDOUBLE env->fpregs_format_vmstate =0 ;#else env->fpregs_format_vmstate =1 ;#endif + +/* There can only be one pending IRQ set in the bitmap at a time, so try +to find it and save its number instead (-1 for none). */ + env->pending_irq_vmstate =-1 ; +for (i =0 ; i <ARRAY_SIZE (env->interrupt_bitmap); i++) { +if (env->interrupt_bitmap[i]) { + bit =ctz64 (env->interrupt_bitmap[i]); + env->pending_irq_vmstate = i *64 + bit; +break ; + } + } +} + +void cpu_save (QEMUFile *f,void *opaque) +{ +CPUState *env = opaque; +int i; + +cpu_pre_save (opaque); + +for (i =0 ; i <CPU_NB_REGS ; i++) +qemu_put_betls (f, &env->regs[i]); +qemu_put_betls (f, &env->eip); +qemu_put_betls (f, &env->eflags); +qemu_put_be32s (f, &env->hflags); + +/* FPU */ +qemu_put_be16s (f, &env->fpuc); +qemu_put_be16s (f, &env->fpus_vmstate); +qemu_put_be16s (f, &env->fptag_vmstate); +qemu_put_be16s (f, &env->fpregs_format_vmstate);for (i =0 ; i <8 ; i++) {
@@ -146,16 +167,6 @@ void cpu_save(QEMUFile *f, void *opaque)/* KVM-related states */ -/* There can only be one pending IRQ set in the bitmap at a time, so try -to find it and save its number instead (-1 for none). */ - env->pending_irq_vmstate =-1 ; -for (i =0 ; i <ARRAY_SIZE (env->interrupt_bitmap); i++) { -if (env->interrupt_bitmap[i]) { - bit =ctz64 (env->interrupt_bitmap[i]); - env->pending_irq_vmstate = i *64 + bit; -break ; - } - }qemu_put_sbe32s (f, &env->pending_irq_vmstate);qemu_put_be32s (f, &env->mp_state);qemu_put_be64s (f, &env->tsc);
Signature · 1 line
1.6.2.5
PATCH 44/49 x86: factor out cpu_pre/post_load()
In reply to Juan Quintela--- target-i386/machine.c | 61 +++++++++++++++++++++++++++++++++---------------- 1 files changed, 41 insertions(+), 20 deletions(-)
target-i386/machine.c +41 -20
@@ -204,12 +204,51 @@ static void fp64_to_fp80(union x86_longdouble *p, uint64_t temp) }#endif +static int cpu_pre_load (void *opaque) +{ +CPUState *env = opaque; + +cpu_synchronize_state (env); +return 0 ; +} + +static int cpu_post_load (void *opaque,int version_id) +{ +CPUState *env = opaque; +int i; + +/* XXX: restore FPU round state */ + env->fpstt = (env->fpus_vmstate >>11 ) &7 ; + env->fpus = env->fpus_vmstate & ~0x3800 ; + env->fptag_vmstate ^=0xff ; +for (i =0 ; i <8 ; i++) { + env->fptags[i] = (env->fptag_vmstate >> i) &1 ; + } + +cpu_breakpoint_remove_all (env,BP_CPU ); +cpu_watchpoint_remove_all (env,BP_CPU ); +for (i =0 ; i <4 ; i++) +hw_breakpoint_insert (env, i); + +if (version_id >=9 ) { +memset (&env->interrupt_bitmap,0 ,sizeof (env->interrupt_bitmap)); +if (env->pending_irq_vmstate >=0 ) { + env->interrupt_bitmap[env->pending_irq_vmstate /64 ] |= + (uint64_t )1 << (env->pending_irq_vmstate %64 ); + } + } + +tlb_flush (env,1 ); +return 0 ; +} +int cpu_load (QEMUFile *f,void *opaque,int version_id) {CPUState *env = opaque;int i, guess_mmx; -cpu_synchronize_state (env); +cpu_pre_load (env); +if (version_id <3 || version_id >CPU_SAVE_VERSION )return -EINVAL ;for (i =0 ; i <CPU_NB_REGS ; i++)
@@ -268,14 +307,6 @@ int cpu_load(QEMUFile *f, void *opaque, int version_id) } } -/* XXX: restore FPU round state */ - env->fpstt = (env->fpus_vmstate >>11 ) &7 ; - env->fpus = env->fpus_vmstate & ~0x3800 ; - env->fptag_vmstate ^=0xff ; -for (i =0 ; i <8 ; i++) { - env->fptags[i] = (env->fptag_vmstate >> i) &1 ; - } -for (i =0 ; i <6 ; i++)cpu_get_seg (f, &env->segs[i]);cpu_get_seg (f, &env->ldt);
@@ -299,10 +330,6 @@ int cpu_load(QEMUFile *f, void *opaque, int version_id)for (i =0 ; i <8 ; i++)qemu_get_betls (f, &env->dr[i]); -cpu_breakpoint_remove_all (env,BP_CPU ); -cpu_watchpoint_remove_all (env,BP_CPU ); -for (i =0 ; i <4 ; i++) -hw_breakpoint_insert (env, i);qemu_get_sbe32s (f, &env->a20_mask);
@@ -354,11 +381,6 @@ int cpu_load(QEMUFile *f, void *opaque, int version_id)if (version_id >=9 ) {qemu_get_sbe32s (f, &env->pending_irq_vmstate); -memset (&env->interrupt_bitmap,0 ,sizeof (env->interrupt_bitmap)); -if (env->pending_irq_vmstate >=0 ) { - env->interrupt_bitmap[env->pending_irq_vmstate /64 ] |= - (uint64_t )1 << (env->pending_irq_vmstate %64 ); - }qemu_get_be32s (f, &env->mp_state);qemu_get_be64s (f, &env->tsc); }
@@ -372,6 +394,5 @@ int cpu_load(QEMUFile *f, void *opaque, int version_id) } } -tlb_flush (env,1 ); -return 0 ; +return cpu_post_load (env, version_id); }
Signature · 1 line
1.6.2.5
PATCH 45/49 x86: factor out cpu_get/put_xmm_reg()
In reply to Juan Quintela--- target-i386/machine.c | 28 ++++++++++++++++++++++++---- 1 files changed, 24 insertions(+), 4 deletions(-)
target-i386/machine.c +24 -4
@@ -31,6 +31,28 @@ static void cpu_get_seg(QEMUFile *f, SegmentCache *dt)vmstate_load_state (f, &vmstate_segment, dt, vmstate_segment.version_id); } +static const VMStateDescription vmstate_xmm_reg = { + .name ="xmm_reg" , + .version_id =1 , + .minimum_version_id =1 , + .minimum_version_id_old =1 , + .fields = (VMStateField []) { +VMSTATE_UINT64 (XMM_Q (0 ), XMMReg), +VMSTATE_UINT64 (XMM_Q (1 ), XMMReg), +VMSTATE_END_OF_LIST () + } +}; + +static void cpu_put_xmm_reg (QEMUFile *f,XMMReg *xmm_reg) +{ +vmstate_save_state (f, &vmstate_xmm_reg, xmm_reg); +} + +static void cpu_get_xmm_reg (QEMUFile *f,XMMReg *xmm_reg) +{ +vmstate_load_state (f, &vmstate_xmm_reg, xmm_reg, vmstate_xmm_reg.version_id); +} +static void cpu_pre_save (void *opaque) {CPUState *env = opaque;
@@ -128,8 +150,7 @@ void cpu_save(QEMUFile *f, void *opaque)/* XMM */ qemu_put_be32s (f, &env->mxcsr);for (i =0 ; i <CPU_NB_REGS ; i++) { -qemu_put_be64s (f, &env->xmm_regs[i].XMM_Q (0 )); -qemu_put_be64s (f, &env->xmm_regs[i].XMM_Q (1 )); +cpu_put_xmm_reg (f, &env->xmm_regs[i]); }#ifdef TARGET_X86_64
@@ -335,8 +356,7 @@ int cpu_load(QEMUFile *f, void *opaque, int version_id)qemu_get_be32s (f, &env->mxcsr);for (i =0 ; i <CPU_NB_REGS ; i++) { -qemu_get_be64s (f, &env->xmm_regs[i].XMM_Q (0 )); -qemu_get_be64s (f, &env->xmm_regs[i].XMM_Q (1 )); +cpu_get_xmm_reg (f, &env->xmm_regs[i]); }#ifdef TARGET_X86_64
Signature · 1 line
1.6.2.5
PATCH 46/49 x86: factor out cpu_get/put_mttr_var()
In reply to Juan Quintela--- target-i386/machine.c | 28 ++++++++++++++++++++++++---- 1 files changed, 24 insertions(+), 4 deletions(-)
target-i386/machine.c +24 -4
@@ -53,6 +53,28 @@ static void cpu_get_xmm_reg(QEMUFile *f, XMMReg *xmm_reg)vmstate_load_state (f, &vmstate_xmm_reg, xmm_reg, vmstate_xmm_reg.version_id); } +static const VMStateDescription vmstate_mtrr_var = { + .name ="mtrr_var" , + .version_id =1 , + .minimum_version_id =1 , + .minimum_version_id_old =1 , + .fields = (VMStateField []) { +VMSTATE_UINT64 (base, MTRRVar), +VMSTATE_UINT64 (mask, MTRRVar), +VMSTATE_END_OF_LIST () + } +}; + +static void cpu_put_mtrr_var (QEMUFile *f,MTRRVar *mtrr_var) +{ +vmstate_save_state (f, &vmstate_mtrr_var, mtrr_var); +} + +static void cpu_get_mtrr_var (QEMUFile *f,MTRRVar *mtrr_var) +{ +vmstate_load_state (f, &vmstate_mtrr_var, mtrr_var, vmstate_mtrr_var.version_id); +} +static void cpu_pre_save (void *opaque) {CPUState *env = opaque;
@@ -182,8 +204,7 @@ void cpu_save(QEMUFile *f, void *opaque)qemu_put_be64s (f, &env->mtrr_fixed[i]);qemu_put_be64s (f, &env->mtrr_deftype);for (i =0 ; i <8 ; i++) { -qemu_put_be64s (f, &env->mtrr_var[i].base); -qemu_put_be64s (f, &env->mtrr_var[i].mask); +cpu_put_mtrr_var (f, &env->mtrr_var[i]); }/* KVM-related states */
@@ -394,8 +415,7 @@ int cpu_load(QEMUFile *f, void *opaque, int version_id)qemu_get_be64s (f, &env->mtrr_fixed[i]);qemu_get_be64s (f, &env->mtrr_deftype);for (i =0 ; i <8 ; i++) { -qemu_get_be64s (f, &env->mtrr_var[i].base); -qemu_get_be64s (f, &env->mtrr_var[i].mask); +cpu_get_mtrr_var (f, &env->mtrr_var[i]); } }
Signature · 1 line
1.6.2.5
PATCH 47/49 x86: factor out cpu_get/put_fpreg()
In reply to Juan Quintela--- target-i386/machine.c | 209 ++++++++++++++++++++++++++++++++----------------- 1 files changed, 137 insertions(+), 72 deletions(-)
target-i386/machine.c +137 -72
@@ -75,6 +75,120 @@ static void cpu_get_mtrr_var(QEMUFile *f, MTRRVar *mtrr_var)vmstate_load_state (f, &vmstate_mtrr_var, mtrr_var, vmstate_mtrr_var.version_id); } +#ifdef USE_X86LDOUBLE +/* XXX: add that in a FPU generic layer */ +union x86_longdouble { +uint64_t mant; +uint16_t exp; +}; + +#define MANTD1 (fp) (fp & ((1LL << 52) - 1)) +#define EXPBIAS1 1023 +#define EXPD1 (fp) ((fp >> 52) & 0x7FF) +#define SIGND1 (fp) ((fp >> 32) & 0x80000000) + +static void fp64_to_fp80 (union x86_longdouble *p,uint64_t temp) +{ +int e; +/* mantissa */ + p->mant = (MANTD1 (temp) <<11 ) | (1LL <<63 ); +/* exponent + sign */ + e =EXPD1 (temp) -EXPBIAS1 +16383 ; + e |=SIGND1 (temp) >>16 ; + p->exp = e; +} + +static int get_fpreg (QEMUFile *f,void *opaque,size_t size) +{ +FPReg *fp_reg = opaque; +uint64_t mant; +uint16_t exp; + +qemu_get_be64s (f, &mant); +qemu_get_be16s (f, &exp); + fp_reg->d =cpu_set_fp80 (mant, exp); +return 0 ; +} + +static void put_fpreg (QEMUFile *f,void *opaque,size_t size) +{ +FPReg *fp_reg = opaque; +uint64_t mant; +uint16_t exp; +/* we save the real CPU data (in case of MMX usage only 'mant' +contains the MMX register */ +cpu_get_fp80 (&mant, &exp, fp_reg->d); +qemu_put_be64s (f, &mant); +qemu_put_be16s (f, &exp); +} + +static int get_fpreg_1_mmx (QEMUFile *f,void *opaque,size_t size) +{ +union x86_longdouble *p = opaque; +uint64_t mant; + +qemu_get_be64s (f, &mant); + p->mant = mant; + p->exp =0xffff ; +return 0 ; +} + +static int get_fpreg_1_no_mmx (QEMUFile *f,void *opaque,size_t size) +{ +union x86_longdouble *p = opaque; +uint64_t mant; + +qemu_get_be64s (f, &mant); +fp64_to_fp80 (p, mant); +return 0 ; +} + +#else +static int get_fpreg (QEMUFile *f,void *opaque,size_t size) +{ +FPReg *fp_reg = opaque; + +qemu_get_be64s (f, &fp_reg->mmx.MMX_Q (0 )); +return 0 ; +} + +static void put_fpreg (QEMUFile *f,void *opaque,size_t size) +{ +FPReg *fp_reg = opaque; +/* if we use doubles for float emulation, we save the doubles to +avoid losing information in case of MMX usage. It can give +problems if the image is restored on a CPU where long +doubles are used instead. */ +qemu_put_be64s (f, &fp_reg->mmx.MMX_Q (0 )); +} + +static int get_fpreg_0_mmx (QEMUFile *f,void *opaque,size_t size) +{ +FPReg *fp_reg = opaque; +uint64_t mant; +uint16_t exp; + +qemu_get_be64s (f, &mant); +qemu_get_be16s (f, &exp); + fp_reg->mmx.MMX_Q (0 ) = mant; +return 0 ; +} + +static int get_fpreg_0_no_mmx (QEMUFile *f,void *opaque,size_t size) +{ +FPReg *fp_reg = opaque; +uint64_t mant; +uint16_t exp; + +qemu_get_be64s (f, &mant); +qemu_get_be16s (f, &exp); + + fp_reg->d =cpu_set_fp80 (mant, exp); +return 0 ; +} + +#endif /* USE_X86LDOUBLE */ +static void cpu_pre_save (void *opaque) {CPUState *env = opaque;
@@ -128,23 +242,7 @@ void cpu_save(QEMUFile *f, void *opaque)qemu_put_be16s (f, &env->fpregs_format_vmstate);for (i =0 ; i <8 ; i++) { -#ifdef USE_X86LDOUBLE - { -uint64_t mant; -uint16_t exp; -/* we save the real CPU data (in case of MMX usage only 'mant' -contains the MMX register */ -cpu_get_fp80 (&mant, &exp, env->fpregs[i].d); -qemu_put_be64 (f, mant); -qemu_put_be16 (f, exp); - } -#else -/* if we use doubles for float emulation, we save the doubles to -avoid losing information in case of MMX usage. It can give -problems if the image is restored on a CPU where long -doubles are used instead. */ -qemu_put_be64 (f, env->fpregs[i].mmx.MMX_Q (0 )); -#endif +put_fpreg (f, &env->fpregs[i],0 ); }for (i =0 ; i <6 ; i++)
@@ -222,30 +320,6 @@ void cpu_save(QEMUFile *f, void *opaque) } } -#ifdef USE_X86LDOUBLE -/* XXX: add that in a FPU generic layer */ -union x86_longdouble { -uint64_t mant; -uint16_t exp; -}; - -#define MANTD1 (fp) (fp & ((1LL << 52) - 1)) -#define EXPBIAS1 1023 -#define EXPD1 (fp) ((fp >> 52) & 0x7FF) -#define SIGND1 (fp) ((fp >> 32) & 0x80000000) - -static void fp64_to_fp80 (union x86_longdouble *p,uint64_t temp) -{ -int e; -/* mantissa */ - p->mant = (MANTD1 (temp) <<11 ) | (1LL <<63 ); -/* exponent + sign */ - e =EXPD1 (temp) -EXPBIAS1 +16383 ; - e |=SIGND1 (temp) >>16 ; - p->exp = e; -} -#endif -static int cpu_pre_load (void *opaque) {CPUState *env = opaque;
@@ -304,49 +378,40 @@ int cpu_load(QEMUFile *f, void *opaque, int version_id)qemu_get_be16s (f, &env->fptag_vmstate);qemu_get_be16s (f, &env->fpregs_format_vmstate); -/* NOTE: we cannot always restore the FPU state if the image come -from a host with a different 'USE_X86LDOUBLE' define. We guess -if we are in an MMX state to restore correctly in that case. */ guess_mmx = ((env->fptag_vmstate ==0xff ) && (env->fpus_vmstate &0x3800 ) ==0 ); -for (i =0 ; i <8 ; i++) { -uint64_t mant; -uint16_t exp; +for (i =0 ; i <8 ; i++) { +#ifdef USE_X86LDOUBLE switch (env->fpregs_format_vmstate) {case 0 : - mant =qemu_get_be64 (f); - exp =qemu_get_be16 (f); -#ifdef USE_X86LDOUBLE - env->fpregs[i].d =cpu_set_fp80 (mant, exp); -#else -/* difficult case */ -if (guess_mmx) - env->fpregs[i].mmx.MMX_Q (0 ) = mant; -else - env->fpregs[i].d =cpu_set_fp80 (mant, exp); -#endif +get_fpreg (f, &env->fpregs[i],0 );break ;case 1 : - mant =qemu_get_be64 (f); -#ifdef USE_X86LDOUBLE - { -union x86_longdouble *p; -/* difficult case */ - p = (void *)&env->fpregs[i]; -if (guess_mmx) { - p->mant = mant; - p->exp =0xffff ; - }else { -fp64_to_fp80 (p, mant); - } +if (guess_mmx) { +get_fpreg_1_mmx (f, &env->fpregs[i],0 ); + }else { +get_fpreg_1_no_mmx (f, &env->fpregs[i],0 ); } +break ; +default : +return -EINVAL ; + }#else - env->fpregs[i].mmx.MMX_Q (0 ) = mant; -#endif +switch (env->fpregs_format_vmstate) { +case 0 : +if (guess_mmx) { +get_fpreg_0_mmx (f, &env->fpregs[i],0 ); + }else { +get_fpreg_0_no_mmx (f, &env->fpregs[i],0 ); + } +break ; +case 1 : +get_fpreg (f, &env->fpregs[i],0 );break ;default :return -EINVAL ; } +#endif }for (i =0 ; i <6 ; i++)
Signature · 1 line
1.6.2.5
PATCH 48/49 vmstate: Add suppot for field_exist() test
In reply to Juan Quintela--- hw/hw.h | 26 ++++++++++++++++++++++++++ savevm.c | 40 +++++++++++++++++++++++----------------- 2 files changed, 49 insertions(+), 17 deletions(-)
hw/hw.h +26 -0
@@ -10,6 +10,7 @@#include "cpu-common.h" #endif +#include <stdbool.h> #include "ioport.h" #include "irq.h"
@@ -299,6 +300,7 @@ typedef struct {enum VMStateFlags flags;const VMStateDescription *vmsd;int version_id; +bool (*field_exists)(void *opaque,int version_id); } VMStateField;struct VMStateDescription {
@@ -345,6 +347,16 @@ extern const VMStateInfo vmstate_info_buffer; + type_check(_type,typeof_field(_state, _field)) \ } +#define VMSTATE_SINGLE_TEST (_field, _state, _test, _info, _type) { \ + .name = (stringify(_field)), \ + .field_exists = (_test), \ + .size = sizeof(_type), \ + .info = &(_info), \ + .flags = VMS_SINGLE, \ + .offset = offsetof(_state, _field) \ + + type_check(_type,typeof_field(_state, _field)) \ +} +#define VMSTATE_POINTER (_field, _state, _version, _info, _type) { \ .name = (stringify(_field)), \ .version_id = (_version), \
@@ -366,6 +378,17 @@ extern const VMStateInfo vmstate_info_buffer; + type_check_array(_type,typeof_field(_state, _field),_num) \ } +#define VMSTATE_ARRAY_TEST (_field, _state, _num, _test, _info, _type) {\ + .name = (stringify(_field)), \ + .field_exists = (_test), \ + .num = (_num), \ + .info = &(_info), \ + .size = sizeof(_type), \ + .flags = VMS_ARRAY, \ + .offset = offsetof(_state, _field) \ + + type_check_array(_type,typeof_field(_state, _field),_num) \ +} +#define VMSTATE_VARRAY (_field, _state, _field_num, _version, _info, _type) {\ .name = (stringify(_field)), \ .version_id = (_version), \
@@ -524,6 +547,9 @@ extern const VMStateDescription vmstate_i2c_slave;#define VMSTATE_INT32_LE (_f, _s) \ VMSTATE_SINGLE(_f, _s, 0, vmstate_info_int32_le, int32_t) +#define VMSTATE_UINT32_TEST (_f, _s, _t) \ + VMSTATE_SINGLE_TEST(_f, _s, _t, vmstate_info_uint32, uint32_t) +#define VMSTATE_TIMER_V (_f, _s, _v) \ VMSTATE_POINTER(_f, _s, _v, vmstate_info_timer, QEMUTimer *)
savevm.c +23 -17
@@ -1055,7 +1055,10 @@ int vmstate_load_state(QEMUFile *f, const VMStateDescription *vmsd,return ret; }while (field->name) { -if (field->version_id <= version_id) { +if ((field->field_exists && + field->field_exists (opaque, version_id)) || + (!field->field_exists && + field->version_id <= version_id)) {void *base_addr = opaque + field->offset;int ret, i, n_elems =1 ;
@@ -1101,24 +1104,27 @@ void vmstate_save_state(QEMUFile *f, const VMStateDescription *vmsd, vmsd->pre_save (opaque); }while (field->name) { -void *base_addr = opaque + field->offset; -int i, n_elems =1 ; +if (!field->field_exists || + field->field_exists (opaque, vmsd->version_id)) { +void *base_addr = opaque + field->offset; +int i, n_elems =1 ; -if (field->flags &VMS_ARRAY ) { - n_elems = field->num; - }else if (field->flags &VMS_VARRAY ) { - n_elems = *(size_t *)(opaque+field->num_offset); - } -if (field->flags &VMS_POINTER ) { - base_addr = *(void **)base_addr; - } -for (i =0 ; i < n_elems; i++) { -void *addr = base_addr + field->size * i; +if (field->flags &VMS_ARRAY ) { + n_elems = field->num; + }else if (field->flags &VMS_VARRAY ) { + n_elems = *(size_t *)(opaque+field->num_offset); + } +if (field->flags &VMS_POINTER ) { + base_addr = *(void **)base_addr; + } +for (i =0 ; i < n_elems; i++) { +void *addr = base_addr + field->size * i; -if (field->flags &VMS_STRUCT ) { -vmstate_save_state (f, field->vmsd, addr); - }else { - field->info->put (f, addr, field->size); +if (field->flags &VMS_STRUCT ) { +vmstate_save_state (f, field->vmsd, addr); + }else { + field->info->put (f, addr, field->size); + } } } field++;
Signature · 1 line
1.6.2.5
PATCH 49/49 x86: port cpu to vmstate
In reply to Juan Quintela--- target-i386/machine.c | 491 ++++++++++++++++++++++++------------------------- 1 files changed, 238 insertions(+), 253 deletions(-)
target-i386/machine.c +238 -253
@@ -21,15 +21,17 @@ static const VMStateDescription vmstate_segment = { } }; -static void cpu_put_seg (QEMUFile *f,SegmentCache *dt) -{ -vmstate_save_state (f, &vmstate_segment, dt); +#define VMSTATE_SEGMENT (_field, _state) { \ + .name = (stringify(_field)), \ + .size = sizeof(SegmentCache), \ + .vmsd = &vmstate_segment, \ + .flags = VMS_STRUCT, \ + .offset = offsetof(_state, _field) \ + + type_check(SegmentCache,typeof_field(_state, _field)) \ } -static void cpu_get_seg (QEMUFile *f,SegmentCache *dt) -{ -vmstate_load_state (f, &vmstate_segment, dt, vmstate_segment.version_id); -} +#define VMSTATE_SEGMENT_ARRAY (_field, _state, _n) \ + VMSTATE_STRUCT_ARRAY(_field, _state, _n, 0, vmstate_segment, SegmentCache)static const VMStateDescription vmstate_xmm_reg = { .name ="xmm_reg" ,
@@ -43,15 +45,8 @@ static const VMStateDescription vmstate_xmm_reg = { } }; -static void cpu_put_xmm_reg (QEMUFile *f,XMMReg *xmm_reg) -{ -vmstate_save_state (f, &vmstate_xmm_reg, xmm_reg); -} - -static void cpu_get_xmm_reg (QEMUFile *f,XMMReg *xmm_reg) -{ -vmstate_load_state (f, &vmstate_xmm_reg, xmm_reg, vmstate_xmm_reg.version_id); -} +#define VMSTATE_XMM_REGS (_field, _state, _n) \ + VMSTATE_STRUCT_ARRAY(_field, _state, _n, 0, vmstate_xmm_reg, XMMReg)static const VMStateDescription vmstate_mtrr_var = { .name ="mtrr_var" ,
@@ -65,14 +60,13 @@ static const VMStateDescription vmstate_mtrr_var = { } }; -static void cpu_put_mtrr_var (QEMUFile *f,MTRRVar *mtrr_var) -{ -vmstate_save_state (f, &vmstate_mtrr_var, mtrr_var); -} +#define VMSTATE_MTRR_VARS (_field, _state, _n, _v) \ + VMSTATE_STRUCT_ARRAY(_field, _state, _n, _v, vmstate_mtrr_var, MTRRVar) -static void cpu_get_mtrr_var (QEMUFile *f,MTRRVar *mtrr_var) +static void put_fpreg_error (QEMUFile *f,void *opaque,size_t size) { -vmstate_load_state (f, &vmstate_mtrr_var, mtrr_var, vmstate_mtrr_var.version_id); +fprintf (stderr,"call put_fpreg() with invalid arguments\n" ); +exit (0 ); }#ifdef USE_X86LDOUBLE
@@ -122,6 +116,12 @@ static void put_fpreg(QEMUFile *f, void *opaque, size_t size)qemu_put_be16s (f, &exp); } +const VMStateInfo vmstate_fpreg = { + .name ="fpreg" , + .get = get_fpreg, + .put = put_fpreg, +}; +static int get_fpreg_1_mmx (QEMUFile *f,void *opaque,size_t size) {union x86_longdouble *p = opaque;
@@ -133,6 +133,12 @@ static int get_fpreg_1_mmx(QEMUFile *f, void *opaque, size_t size)return 0 ; } +const VMStateInfo vmstate_fpreg_1_mmx = { + .name ="fpreg_1_mmx" , + .get = get_fpreg_1_mmx, + .put = put_fpreg_error, +}; +static int get_fpreg_1_no_mmx (QEMUFile *f,void *opaque,size_t size) {union x86_longdouble *p = opaque;
@@ -143,6 +149,44 @@ static int get_fpreg_1_no_mmx(QEMUFile *f, void *opaque, size_t size)return 0 ; } +const VMStateInfo vmstate_fpreg_1_no_mmx = { + .name ="fpreg_1_no_mmx" , + .get = get_fpreg_1_no_mmx, + .put = put_fpreg_error, +}; + +static bool fpregs_is_0 (void *opaque,int version_id) +{ +CPUState *env = opaque; + +return (env->fpregs_format_vmstate ==0 ); +} + +static bool fpregs_is_1_mmx (void *opaque,int version_id) +{ +CPUState *env = opaque; +int guess_mmx; + + guess_mmx = ((env->fptag_vmstate ==0xff ) && + (env->fpus_vmstate &0x3800 ) ==0 ); +return (guess_mmx && (env->fpregs_format_vmstate ==1 )); +} + +static bool fpregs_is_1_no_mmx (void *opaque,int version_id) +{ +CPUState *env = opaque; +int guess_mmx; + + guess_mmx = ((env->fptag_vmstate ==0xff ) && + (env->fpus_vmstate &0x3800 ) ==0 ); +return (!guess_mmx && (env->fpregs_format_vmstate ==1 )); +} + +#define VMSTATE_FP_REGS (_field, _state, _n) \ + VMSTATE_ARRAY_TEST(_field, _state, _n, fpregs_is_0, vmstate_fpreg, FPReg), \ + VMSTATE_ARRAY_TEST(_field, _state, _n, fpregs_is_1_mmx, vmstate_fpreg_1_mmx, FPReg), \ + VMSTATE_ARRAY_TEST(_field, _state, _n, fpregs_is_1_no_mmx, vmstate_fpreg_1_no_mmx, FPReg) +#else static int get_fpreg (QEMUFile *f,void *opaque,size_t size) {
@@ -162,6 +206,12 @@ static void put_fpreg(QEMUFile *f, void *opaque, size_t size)qemu_put_be64s (f, &fp_reg->mmx.MMX_Q (0 )); } +const VMStateInfo vmstate_fpreg = { + .name ="fpreg" , + .get = get_fpreg, + .put = put_fpreg, +}; +static int get_fpreg_0_mmx (QEMUFile *f,void *opaque,size_t size) {FPReg *fp_reg = opaque;
@@ -174,6 +224,12 @@ static int get_fpreg_0_mmx(QEMUFile *f, void *opaque, size_t size)return 0 ; } +const VMStateInfo vmstate_fpreg_0_mmx = { + .name ="fpreg_0_mmx" , + .get = get_fpreg_0_mmx, + .put = put_fpreg_error, +}; +static int get_fpreg_0_no_mmx (QEMUFile *f,void *opaque,size_t size) {FPReg *fp_reg = opaque;
@@ -187,8 +243,80 @@ static int get_fpreg_0_no_mmx(QEMUFile *f, void *opaque, size_t size)return 0 ; } +const VMStateInfo vmstate_fpreg_0_no_mmx = { + .name ="fpreg_0_no_mmx" , + .get = get_fpreg_0_no_mmx, + .put = put_fpreg_error, +}; + +static bool fpregs_is_1 (void *opaque,int version_id) +{ +CPUState *env = opaque; + +return env->fpregs_format_vmstate ==1 ; +} + +static bool fpregs_is_0_mmx (void *opaque,int version_id) +{ +CPUState *env = opaque; +int guess_mmx; + + guess_mmx = ((env->fptag_vmstate ==0xff ) && + (env->fpus_vmstate &0x3800 ) ==0 ); +return guess_mmx && env->fpregs_format_vmstate ==0 ; +} + +static bool fpregs_is_0_no_mmx (void *opaque,int version_id) +{ +CPUState *env = opaque; +int guess_mmx; + + guess_mmx = ((env->fptag_vmstate ==0xff ) && + (env->fpus_vmstate &0x3800 ) ==0 ); +return !guess_mmx && env->fpregs_format_vmstate ==0 ; +} + +#define VMSTATE_FP_REGS (_field, _state, _n) \ + VMSTATE_ARRAY_TEST(_field, _state, _n, fpregs_is_1, vmstate_fpreg, FPReg), \ + VMSTATE_ARRAY_TEST(_field, _state, _n, fpregs_is_0_mmx, vmstate_fpreg_0_mmx, FPReg), \ + VMSTATE_ARRAY_TEST(_field, _state, _n, fpregs_is_0_no_mmx, vmstate_fpreg_0_no_mmx, FPReg) +#endif /* USE_X86LDOUBLE */ +static bool version_is_5 (void *opaque,int version_id) +{ +return version_id ==5 ; +} + +#ifdef TARGET_X86_64 +static bool less_than_7 (void *opaque,int version_id) +{ +return version_id <7 ; +} + +static int get_uint64_as_uint32 (QEMUFile *f,void *pv,size_t size) +{ +uint64_t *v = pv; + *v =qemu_get_be32 (f); +return 0 ; +} + +static void put_uint64_as_uint32 (QEMUFile *f,void *pv,size_t size) +{ +uint64_t *v = pv; +qemu_put_be32 (f, *v); +} + +const VMStateInfo vmstate_hack_uint64_as_uint32 = { + .name ="uint64_as_uint32" , + .get = get_uint64_as_uint32, + .put = put_uint64_as_uint32, +}; + +#define VMSTATE_HACK_UINT32 (_f, _s, _t) \ + VMSTATE_SINGLE_TEST(_f, _s, _t, vmstate_hack_uint64_as_uint32, uint64_t) +#endif +static void cpu_pre_save (void *opaque) {CPUState *env = opaque;
@@ -221,105 +349,6 @@ static void cpu_pre_save(void *opaque) } } -void cpu_save (QEMUFile *f,void *opaque) -{ -CPUState *env = opaque; -int i; - -cpu_pre_save (opaque); - -for (i =0 ; i <CPU_NB_REGS ; i++) -qemu_put_betls (f, &env->regs[i]); -qemu_put_betls (f, &env->eip); -qemu_put_betls (f, &env->eflags); -qemu_put_be32s (f, &env->hflags); - -/* FPU */ -qemu_put_be16s (f, &env->fpuc); -qemu_put_be16s (f, &env->fpus_vmstate); -qemu_put_be16s (f, &env->fptag_vmstate); - -qemu_put_be16s (f, &env->fpregs_format_vmstate); - -for (i =0 ; i <8 ; i++) { -put_fpreg (f, &env->fpregs[i],0 ); - } - -for (i =0 ; i <6 ; i++) -cpu_put_seg (f, &env->segs[i]); -cpu_put_seg (f, &env->ldt); -cpu_put_seg (f, &env->tr); -cpu_put_seg (f, &env->gdt); -cpu_put_seg (f, &env->idt); - -qemu_put_be32s (f, &env->sysenter_cs); -qemu_put_betls (f, &env->sysenter_esp); -qemu_put_betls (f, &env->sysenter_eip); - -qemu_put_betls (f, &env->cr[0 ]); -qemu_put_betls (f, &env->cr[2 ]); -qemu_put_betls (f, &env->cr[3 ]); -qemu_put_betls (f, &env->cr[4 ]); - -for (i =0 ; i <8 ; i++) -qemu_put_betls (f, &env->dr[i]); - -/* MMU */ -qemu_put_sbe32s (f, &env->a20_mask); - -/* XMM */ -qemu_put_be32s (f, &env->mxcsr); -for (i =0 ; i <CPU_NB_REGS ; i++) { -cpu_put_xmm_reg (f, &env->xmm_regs[i]); - } - -#ifdef TARGET_X86_64 -qemu_put_be64s (f, &env->efer); -qemu_put_be64s (f, &env->star); -qemu_put_be64s (f, &env->lstar); -qemu_put_be64s (f, &env->cstar); -qemu_put_be64s (f, &env->fmask); -qemu_put_be64s (f, &env->kernelgsbase); -#endif -qemu_put_be32s (f, &env->smbase); - -qemu_put_be64s (f, &env->pat); -qemu_put_be32s (f, &env->hflags2); - -qemu_put_be64s (f, &env->vm_hsave); -qemu_put_be64s (f, &env->vm_vmcb); -qemu_put_be64s (f, &env->tsc_offset); -qemu_put_be64s (f, &env->intercept); -qemu_put_be16s (f, &env->intercept_cr_read); -qemu_put_be16s (f, &env->intercept_cr_write); -qemu_put_be16s (f, &env->intercept_dr_read); -qemu_put_be16s (f, &env->intercept_dr_write); -qemu_put_be32s (f, &env->intercept_exceptions); -qemu_put_8s (f, &env->v_tpr); - -/* MTRRs */ -for (i =0 ; i <11 ; i++) -qemu_put_be64s (f, &env->mtrr_fixed[i]); -qemu_put_be64s (f, &env->mtrr_deftype); -for (i =0 ; i <8 ; i++) { -cpu_put_mtrr_var (f, &env->mtrr_var[i]); - } - -/* KVM-related states */ - -qemu_put_sbe32s (f, &env->pending_irq_vmstate); -qemu_put_be32s (f, &env->mp_state); -qemu_put_be64s (f, &env->tsc); - -/* MCE */ -qemu_put_be64s (f, &env->mcg_cap); -qemu_put_be64s (f, &env->mcg_status); -qemu_put_be64s (f, &env->mcg_ctl); -for (i =0 ; i <MCE_BANKS_DEF *4 ; i++) { -qemu_put_be64s (f, &env->mce_banks[i]); - } - } -static int cpu_pre_load (void *opaque) {CPUState *env = opaque;
@@ -358,146 +387,102 @@ static int cpu_post_load(void *opaque, int version_id)return 0 ; } -int cpu_load (QEMUFile *f,void *opaque,int version_id) -{ -CPUState *env = opaque; -int i, guess_mmx; - -cpu_pre_load (env); - -if (version_id <3 || version_id >CPU_SAVE_VERSION ) -return -EINVAL ; -for (i =0 ; i <CPU_NB_REGS ; i++) -qemu_get_betls (f, &env->regs[i]); -qemu_get_betls (f, &env->eip); -qemu_get_betls (f, &env->eflags); -qemu_get_be32s (f, &env->hflags); - -qemu_get_be16s (f, &env->fpuc); -qemu_get_be16s (f, &env->fpus_vmstate); -qemu_get_be16s (f, &env->fptag_vmstate); -qemu_get_be16s (f, &env->fpregs_format_vmstate); - - guess_mmx = ((env->fptag_vmstate ==0xff ) && (env->fpus_vmstate &0x3800 ) ==0 ); - -for (i =0 ; i <8 ; i++) { -#ifdef USE_X86LDOUBLE -switch (env->fpregs_format_vmstate) { -case 0 : -get_fpreg (f, &env->fpregs[i],0 ); -break ; -case 1 : -if (guess_mmx) { -get_fpreg_1_mmx (f, &env->fpregs[i],0 ); - }else { -get_fpreg_1_no_mmx (f, &env->fpregs[i],0 ); - } -break ; -default : -return -EINVAL ; - } +const VMStateDescription vmstate_cpu = { + .name ="cpu" , + .version_id =CPU_SAVE_VERSION , + .minimum_version_id =3 , + .minimum_version_id_old =3 , + .pre_save = cpu_pre_save, + .pre_load = cpu_pre_load, + .post_load = cpu_post_load, + .fields = (VMStateField []) { +VMSTATE_UINTTL_ARRAY (regs, CPUState,CPU_NB_REGS ), +VMSTATE_UINTTL (eip, CPUState), +VMSTATE_UINTTL (eflags, CPUState), +VMSTATE_UINT32 (hflags, CPUState), +/* FPU */ +VMSTATE_UINT16 (fpuc, CPUState), +VMSTATE_UINT16 (fpus_vmstate, CPUState), +VMSTATE_UINT16 (fptag_vmstate, CPUState), +VMSTATE_UINT16 (fpregs_format_vmstate, CPUState), +VMSTATE_FP_REGS (fpregs, CPUState,8 ), + +VMSTATE_SEGMENT_ARRAY (segs, CPUState,6 ), +VMSTATE_SEGMENT (ldt, CPUState), +VMSTATE_SEGMENT (tr, CPUState), +VMSTATE_SEGMENT (gdt, CPUState), +VMSTATE_SEGMENT (idt, CPUState), + +VMSTATE_UINT32 (sysenter_cs, CPUState), +#ifdef TARGET_X86_64 +/* Hack: In v7 size changed from 32 to 64 bits on x86_64 */ +VMSTATE_HACK_UINT32 (sysenter_esp, CPUState, less_than_7), +VMSTATE_HACK_UINT32 (sysenter_eip, CPUState, less_than_7), +VMSTATE_UINTTL_V (sysenter_esp, CPUState,7 ), +VMSTATE_UINTTL_V (sysenter_eip, CPUState,7 ), #else -switch (env->fpregs_format_vmstate) { -case 0 : -if (guess_mmx) { -get_fpreg_0_mmx (f, &env->fpregs[i],0 ); - }else { -get_fpreg_0_no_mmx (f, &env->fpregs[i],0 ); - } -break ; -case 1 : -get_fpreg (f, &env->fpregs[i],0 ); -break ; -default : -return -EINVAL ; - } +VMSTATE_UINTTL (sysenter_esp, CPUState), +VMSTATE_UINTTL (sysenter_eip, CPUState), #endif - } -for (i =0 ; i <6 ; i++) -cpu_get_seg (f, &env->segs[i]); -cpu_get_seg (f, &env->ldt); -cpu_get_seg (f, &env->tr); -cpu_get_seg (f, &env->gdt); -cpu_get_seg (f, &env->idt); - -qemu_get_be32s (f, &env->sysenter_cs); -if (version_id >=7 ) { -qemu_get_betls (f, &env->sysenter_esp); -qemu_get_betls (f, &env->sysenter_eip); - }else { - env->sysenter_esp =qemu_get_be32 (f); - env->sysenter_eip =qemu_get_be32 (f); - } - -qemu_get_betls (f, &env->cr[0 ]); -qemu_get_betls (f, &env->cr[2 ]); -qemu_get_betls (f, &env->cr[3 ]); -qemu_get_betls (f, &env->cr[4 ]); - -for (i =0 ; i <8 ; i++) -qemu_get_betls (f, &env->dr[i]); - -qemu_get_sbe32s (f, &env->a20_mask); - -qemu_get_be32s (f, &env->mxcsr); -for (i =0 ; i <CPU_NB_REGS ; i++) { -cpu_get_xmm_reg (f, &env->xmm_regs[i]); - } +VMSTATE_UINTTL (cr[0 ], CPUState), +VMSTATE_UINTTL (cr[2 ], CPUState), +VMSTATE_UINTTL (cr[3 ], CPUState), +VMSTATE_UINTTL (cr[4 ], CPUState), +VMSTATE_UINTTL_ARRAY (dr, CPUState,8 ), +/* MMU */ +VMSTATE_INT32 (a20_mask, CPUState), +/* XMM */ +VMSTATE_UINT32 (mxcsr, CPUState), +VMSTATE_XMM_REGS (xmm_regs, CPUState,CPU_NB_REGS ), #ifdef TARGET_X86_64 -qemu_get_be64s (f, &env->efer); -qemu_get_be64s (f, &env->star); -qemu_get_be64s (f, &env->lstar); -qemu_get_be64s (f, &env->cstar); -qemu_get_be64s (f, &env->fmask); -qemu_get_be64s (f, &env->kernelgsbase); +VMSTATE_UINT64 (efer, CPUState), +VMSTATE_UINT64 (star, CPUState), +VMSTATE_UINT64 (lstar, CPUState), +VMSTATE_UINT64 (cstar, CPUState), +VMSTATE_UINT64 (fmask, CPUState), +VMSTATE_UINT64 (kernelgsbase, CPUState), #endif -if (version_id >=4 ) { -qemu_get_be32s (f, &env->smbase); - } -if (version_id >=5 ) { -qemu_get_be64s (f, &env->pat); -qemu_get_be32s (f, &env->hflags2); -if (version_id <6 ) -qemu_get_be32s (f, &env->halted); - -qemu_get_be64s (f, &env->vm_hsave); -qemu_get_be64s (f, &env->vm_vmcb); -qemu_get_be64s (f, &env->tsc_offset); -qemu_get_be64s (f, &env->intercept); -qemu_get_be16s (f, &env->intercept_cr_read); -qemu_get_be16s (f, &env->intercept_cr_write); -qemu_get_be16s (f, &env->intercept_dr_read); -qemu_get_be16s (f, &env->intercept_dr_write); -qemu_get_be32s (f, &env->intercept_exceptions); -qemu_get_8s (f, &env->v_tpr); - } - -if (version_id >=8 ) { +VMSTATE_UINT32_V (smbase, CPUState,4 ), + +VMSTATE_UINT64_V (pat, CPUState,5 ), +VMSTATE_UINT32_V (hflags2, CPUState,5 ), + +VMSTATE_UINT32_TEST (halted, CPUState, version_is_5), +VMSTATE_UINT64_V (vm_hsave, CPUState,5 ), +VMSTATE_UINT64_V (vm_vmcb, CPUState,5 ), +VMSTATE_UINT64_V (tsc_offset, CPUState,5 ), +VMSTATE_UINT64_V (intercept, CPUState,5 ), +VMSTATE_UINT16_V (intercept_cr_read, CPUState,5 ), +VMSTATE_UINT16_V (intercept_cr_write, CPUState,5 ), +VMSTATE_UINT16_V (intercept_dr_read, CPUState,5 ), +VMSTATE_UINT16_V (intercept_dr_write, CPUState,5 ), +VMSTATE_UINT32_V (intercept_exceptions, CPUState,5 ), +VMSTATE_UINT8_V (v_tpr, CPUState,5 ),/* MTRRs */ -for (i =0 ; i <11 ; i++) -qemu_get_be64s (f, &env->mtrr_fixed[i]); -qemu_get_be64s (f, &env->mtrr_deftype); -for (i =0 ; i <8 ; i++) { -cpu_get_mtrr_var (f, &env->mtrr_var[i]); - } - } - -if (version_id >=9 ) { -qemu_get_sbe32s (f, &env->pending_irq_vmstate); -qemu_get_be32s (f, &env->mp_state); -qemu_get_be64s (f, &env->tsc); +VMSTATE_UINT64_ARRAY_V (mtrr_fixed, CPUState,11 ,8 ), +VMSTATE_UINT64_V (mtrr_deftype, CPUState,8 ), +VMSTATE_MTRR_VARS (mtrr_var, CPUState,8 ,8 ), +/* KVM-related states */ +VMSTATE_INT32_V (pending_irq_vmstate, CPUState,9 ), +VMSTATE_UINT32_V (mp_state, CPUState,9 ), +VMSTATE_UINT64_V (tsc, CPUState,9 ), +/* MCE */ +VMSTATE_UINT64_V (mcg_cap, CPUState,10 ), +VMSTATE_UINT64_V (mcg_status, CPUState,10 ), +VMSTATE_UINT64_V (mcg_ctl, CPUState,10 ), +VMSTATE_UINT64_ARRAY_V (mce_banks, CPUState,MCE_BANKS_DEF *4 ,10 ), +VMSTATE_END_OF_LIST () } +}; -if (version_id >=10 ) { -qemu_get_be64s (f, &env->mcg_cap); -qemu_get_be64s (f, &env->mcg_status); -qemu_get_be64s (f, &env->mcg_ctl); -for (i =0 ; i <MCE_BANKS_DEF *4 ; i++) { -qemu_get_be64s (f, &env->mce_banks[i]); - } - } +void cpu_save (QEMUFile *f,void *opaque) +{ +vmstate_save_state (f, &vmstate_cpu, opaque); +} -return cpu_post_load (env, version_id); +int cpu_load (QEMUFile *f,void *opaque,int version_id) +{ +return vmstate_load_state (f, &vmstate_cpu, opaque, version_id); }
Signature · 1 line
1.6.2.5