* [Qemu-devel] [PATCH 00/25] VMState cleanups and conversion of network drivers
@ 2009-10-19 18:42 Juan Quintela
2009-10-19 18:42 ` [Qemu-devel] [PATCH 01/25] vmstate: Add support for partial buffers transmission Juan Quintela
` (25 more replies)
0 siblings, 26 replies; 30+ messages in thread
From: Juan Quintela @ 2009-10-19 18:42 UTC (permalink / raw)
To: qemu-devel
Hi
This series cleans VMState internals and port all the pc network devices to
VMState (except virtio-net).
- Cleanups:
* we can send partial buffers, and clean how we do it
* refactor all the buffer code.
* refactor all the offset code
* add VARRAY_UINT16_UNSAFE: unsafe here means that type checking is off
(a.k.a. as a cast in C). In this case the problem is that the last
element of one struct is int foo[0], and we allocate the right size
for the array we want. Problem? I haven't been able to abuse^Wuse
gcc + cpp + magic to typecheck that for vmstate:
We have
struct FOO {
int32_t foo[0];
}
We want to "compare the type of foo (t1) with int32_t (t2)
((t1(*)[n])0 - (t2*)0)
This one don't work, because we don't have 'n'
((t1(**))0 - (t2*)0)
This don't work either because t1 is one array.
((t1(*)[])0 - (t2*)0)
Too clever, imposible cast to on array type.
I tried some other variants, but have not able to get one that compiles.
* UNUSED support. This allows to mark some space in the VMStateDescription
as "useless", that is there for backwards compatibility. We don't need
a field in the State to load/save that values anymore.
* SUB_ARRAY(..,start, num, ...)
This allows us to send only slices of one array, i.e. 'num' elemns starting
at position 'start'.
- Network Devices
* rtl8139; Drop support for version < 3, it don't work as non-pci anymore.
* eeprom93xx (only used by eepro100), this one was quite "interesting"
- savevm state had pading by design
- size field changed from 8 bits to 16 bits using the pading space
- VMARRAY with size uint16_t and UNSAFE was needed for this driver
- Wint the price of the more complicated conversion of the series.
* eepro100:
- really, really needed the UNUSED support
- it is the only driver so far that uses a different "name"
* pcnet: nothing special, just port
* ne2000: nothing special, just port
* e1000: after I understood the mac_reg*save arrays just
- unfold them
- save them as SUB_ARRAY
result is clear that previous code.
Reason why cleanup + devices came together is because the cleanups/additons
are needed to implement this devices.
Comments?
Later, Juan.
Juan Quintela (25):
vmstate: Add support for partial buffers transmission
serial: use post_load version_id field and remove pre_load function
vnmstate: fix name for uint8_equal
vmstate: add VMSTATE_UINT16_EQUAL[_V]
vmstate: Rename VMS_VARRAY to VMS_VARRAY_INT32
vmstate: fix indentation
vmstate: factor vmstate_offset_value
vmstate: factor vmstate_offset_pointer
vmstate: factor vmstate_offset_array
vmstate: factor vmstate_offset_buffer
vmstate: factor VMSTATE_*BUFFER* definitions
vmstate: Unfold VMSTATE_INT32_VARRAY() only use and remove it
vmstate: add VMS_VARRAY_UINT16_UNSAFE (varrays with uint16 indexes)
vmstate: Add version arg to VMSTATE_SINGLE_TEST()
vmstate: Add VMSTATE_BUFFER_UNUSED
vmstate: Introduce the concept of sub-arrays
rtl8139: port TallyCounters to vmstate
rtl8139: port to vmstate
eeprom93xx: port to vmstate
eepro100: port to vmstate
pcnet: port to vmstate
ne2000: port to vmstate
e1000: unfold mac_reg_tosave array
e1000: unfold mac_regarraystosave array
e1000: port to vmstate
hw/e1000.c | 185 ++++++++++++---------------
hw/eepro100.c | 195 +++++++++-------------------
hw/eeprom93xx.c | 102 +++++++--------
hw/fdc.c | 2 +-
hw/hw.h | 171 +++++++++++++++---------
hw/ne2000-isa.c | 4 +-
hw/ne2000.c | 133 +++++++------------
hw/ne2000.h | 3 +-
hw/pci.c | 2 +-
hw/pcnet.c | 110 ++++++----------
hw/rtl8139.c | 347 +++++++++++++++----------------------------------
hw/serial.c | 11 +-
savevm.c | 54 +++++++-
target-i386/machine.c | 2 +-
14 files changed, 548 insertions(+), 773 deletions(-)
^ permalink raw reply [flat|nested] 30+ messages in thread
* [Qemu-devel] [PATCH 01/25] vmstate: Add support for partial buffers transmission
2009-10-19 18:42 [Qemu-devel] [PATCH 00/25] VMState cleanups and conversion of network drivers Juan Quintela
@ 2009-10-19 18:42 ` Juan Quintela
2009-10-19 18:42 ` [Qemu-devel] [PATCH 02/25] serial: use post_load version_id field and remove pre_load function Juan Quintela
` (24 subsequent siblings)
25 siblings, 0 replies; 30+ messages in thread
From: Juan Quintela @ 2009-10-19 18:42 UTC (permalink / raw)
To: qemu-devel
Signed-off-by: Juan Quintela <quintela@redhat.com>
---
hw/hw.h | 9 +++++++++
1 files changed, 9 insertions(+), 0 deletions(-)
diff --git a/hw/hw.h b/hw/hw.h
index 8c223f8..5f48ef8 100644
--- a/hw/hw.h
+++ b/hw/hw.h
@@ -464,6 +464,15 @@ extern const VMStateInfo vmstate_info_buffer;
+ type_check_array(uint8_t,typeof_field(_state, _field),sizeof(typeof_field(_state,_field))) \
}
+#define VMSTATE_PARTIAL_BUFFER(_field, _state, _size) { \
+ .name = (stringify(_field)), \
+ .size = (_size), \
+ .info = &vmstate_info_buffer, \
+ .flags = VMS_BUFFER, \
+ .offset = offsetof(_state, _field) \
+ + type_check_array(uint8_t,typeof_field(_state, _field),sizeof(typeof_field(_state,_field))) \
+}
+
#define VMSTATE_BUFFER_START_MIDDLE(_field, _state, start) { \
.name = (stringify(_field)), \
.size = sizeof(typeof_field(_state,_field)) - start, \
--
1.6.2.5
^ permalink raw reply related [flat|nested] 30+ messages in thread
* [Qemu-devel] [PATCH 02/25] serial: use post_load version_id field and remove pre_load function
2009-10-19 18:42 [Qemu-devel] [PATCH 00/25] VMState cleanups and conversion of network drivers Juan Quintela
2009-10-19 18:42 ` [Qemu-devel] [PATCH 01/25] vmstate: Add support for partial buffers transmission Juan Quintela
@ 2009-10-19 18:42 ` Juan Quintela
2009-10-19 18:42 ` [Qemu-devel] [PATCH 03/25] vnmstate: fix name for uint8_equal Juan Quintela
` (23 subsequent siblings)
25 siblings, 0 replies; 30+ messages in thread
From: Juan Quintela @ 2009-10-19 18:42 UTC (permalink / raw)
To: qemu-devel
Signed-off-by: Juan Quintela <quintela@redhat.com>
---
hw/serial.c | 11 +++--------
1 files changed, 3 insertions(+), 8 deletions(-)
diff --git a/hw/serial.c b/hw/serial.c
index eb14f11..ea4154f 100644
--- a/hw/serial.c
+++ b/hw/serial.c
@@ -648,17 +648,13 @@ static void serial_pre_save(void *opaque)
s->fcr_vmstate = s->fcr;
}
-static int serial_pre_load(void *opaque)
-{
- SerialState *s = opaque;
- s->fcr_vmstate = 0;
- return 0;
-}
-
static int serial_post_load(void *opaque, int version_id)
{
SerialState *s = opaque;
+ if (version_id < 3) {
+ s->fcr_vmstate = 0;
+ }
/* Initialize fcr via setter to perform essential side-effects */
serial_ioport_write(s, 0x02, s->fcr_vmstate);
return 0;
@@ -669,7 +665,6 @@ static const VMStateDescription vmstate_serial = {
.version_id = 3,
.minimum_version_id = 2,
.pre_save = serial_pre_save,
- .pre_load = serial_pre_load,
.post_load = serial_post_load,
.fields = (VMStateField []) {
VMSTATE_UINT16_V(divider, SerialState, 2),
--
1.6.2.5
^ permalink raw reply related [flat|nested] 30+ messages in thread
* [Qemu-devel] [PATCH 03/25] vnmstate: fix name for uint8_equal
2009-10-19 18:42 [Qemu-devel] [PATCH 00/25] VMState cleanups and conversion of network drivers Juan Quintela
2009-10-19 18:42 ` [Qemu-devel] [PATCH 01/25] vmstate: Add support for partial buffers transmission Juan Quintela
2009-10-19 18:42 ` [Qemu-devel] [PATCH 02/25] serial: use post_load version_id field and remove pre_load function Juan Quintela
@ 2009-10-19 18:42 ` Juan Quintela
2009-10-19 18:42 ` [Qemu-devel] [PATCH 04/25] vmstate: add VMSTATE_UINT16_EQUAL[_V] Juan Quintela
` (22 subsequent siblings)
25 siblings, 0 replies; 30+ messages in thread
From: Juan Quintela @ 2009-10-19 18:42 UTC (permalink / raw)
To: qemu-devel
Signed-off-by: Juan Quintela <quintela@redhat.com>
---
savevm.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/savevm.c b/savevm.c
index 27a7686..3d91202 100644
--- a/savevm.c
+++ b/savevm.c
@@ -863,7 +863,7 @@ static int get_uint8_equal(QEMUFile *f, void *pv, size_t size)
}
const VMStateInfo vmstate_info_uint8_equal = {
- .name = "int32 equal",
+ .name = "uint8 equal",
.get = get_uint8_equal,
.put = put_uint8,
};
--
1.6.2.5
^ permalink raw reply related [flat|nested] 30+ messages in thread
* [Qemu-devel] [PATCH 04/25] vmstate: add VMSTATE_UINT16_EQUAL[_V]
2009-10-19 18:42 [Qemu-devel] [PATCH 00/25] VMState cleanups and conversion of network drivers Juan Quintela
` (2 preceding siblings ...)
2009-10-19 18:42 ` [Qemu-devel] [PATCH 03/25] vnmstate: fix name for uint8_equal Juan Quintela
@ 2009-10-19 18:42 ` Juan Quintela
2009-10-19 18:42 ` [Qemu-devel] [PATCH 05/25] vmstate: Rename VMS_VARRAY to VMS_VARRAY_INT32 Juan Quintela
` (21 subsequent siblings)
25 siblings, 0 replies; 30+ messages in thread
From: Juan Quintela @ 2009-10-19 18:42 UTC (permalink / raw)
To: qemu-devel
Signed-off-by: Juan Quintela <quintela@redhat.com>
---
hw/hw.h | 7 +++++++
savevm.c | 20 ++++++++++++++++++++
2 files changed, 27 insertions(+), 0 deletions(-)
diff --git a/hw/hw.h b/hw/hw.h
index 5f48ef8..9a40b43 100644
--- a/hw/hw.h
+++ b/hw/hw.h
@@ -322,6 +322,7 @@ extern const VMStateInfo vmstate_info_int32;
extern const VMStateInfo vmstate_info_int64;
extern const VMStateInfo vmstate_info_uint8_equal;
+extern const VMStateInfo vmstate_info_uint16_equal;
extern const VMStateInfo vmstate_info_int32_equal;
extern const VMStateInfo vmstate_info_int32_le;
@@ -550,6 +551,12 @@ extern const VMStateDescription vmstate_i2c_slave;
#define VMSTATE_UINT8_EQUAL(_f, _s) \
VMSTATE_SINGLE(_f, _s, 0, vmstate_info_uint8_equal, uint8_t)
+#define VMSTATE_UINT16_EQUAL(_f, _s) \
+ VMSTATE_SINGLE(_f, _s, 0, vmstate_info_uint16_equal, uint16_t)
+
+#define VMSTATE_UINT16_EQUAL_V(_f, _s, _v) \
+ VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint16_equal, uint16_t)
+
#define VMSTATE_INT32_EQUAL(_f, _s) \
VMSTATE_SINGLE(_f, _s, 0, vmstate_info_int32_equal, int32_t)
diff --git a/savevm.c b/savevm.c
index 3d91202..6a10bc7 100644
--- a/savevm.c
+++ b/savevm.c
@@ -868,6 +868,26 @@ const VMStateInfo vmstate_info_uint8_equal = {
.put = put_uint8,
};
+/* 16 bit unsigned int int. See that the received value is the same than the one
+ in the field */
+
+static int get_uint16_equal(QEMUFile *f, void *pv, size_t size)
+{
+ uint16_t *v = pv;
+ uint16_t v2;
+ qemu_get_be16s(f, &v2);
+
+ if (*v == v2)
+ return 0;
+ return -EINVAL;
+}
+
+const VMStateInfo vmstate_info_uint16_equal = {
+ .name = "uint16 equal",
+ .get = get_uint16_equal,
+ .put = put_uint16,
+};
+
/* timers */
static int get_timer(QEMUFile *f, void *pv, size_t size)
--
1.6.2.5
^ permalink raw reply related [flat|nested] 30+ messages in thread
* [Qemu-devel] [PATCH 05/25] vmstate: Rename VMS_VARRAY to VMS_VARRAY_INT32
2009-10-19 18:42 [Qemu-devel] [PATCH 00/25] VMState cleanups and conversion of network drivers Juan Quintela
` (3 preceding siblings ...)
2009-10-19 18:42 ` [Qemu-devel] [PATCH 04/25] vmstate: add VMSTATE_UINT16_EQUAL[_V] Juan Quintela
@ 2009-10-19 18:42 ` Juan Quintela
2009-10-19 18:42 ` [Qemu-devel] [PATCH 06/25] vmstate: fix indentation Juan Quintela
` (20 subsequent siblings)
25 siblings, 0 replies; 30+ messages in thread
From: Juan Quintela @ 2009-10-19 18:42 UTC (permalink / raw)
To: qemu-devel
Signed-off-by: Juan Quintela <quintela@redhat.com>
---
hw/fdc.c | 2 +-
hw/hw.h | 8 ++++----
savevm.c | 8 ++++----
3 files changed, 9 insertions(+), 9 deletions(-)
diff --git a/hw/fdc.c b/hw/fdc.c
index a21e05f..df0532a 100644
--- a/hw/fdc.c
+++ b/hw/fdc.c
@@ -679,7 +679,7 @@ static const VMStateDescription vmstate_fdc = {
VMSTATE_UINT8(status1, fdctrl_t),
VMSTATE_UINT8(status2, fdctrl_t),
/* Command FIFO */
- VMSTATE_VARRAY(fifo, fdctrl_t, fifo_size, 0, vmstate_info_uint8, uint8),
+ VMSTATE_VARRAY_INT32(fifo, fdctrl_t, fifo_size, 0, vmstate_info_uint8, uint8),
VMSTATE_UINT32(data_pos, fdctrl_t),
VMSTATE_UINT32(data_len, fdctrl_t),
VMSTATE_UINT8(data_state, fdctrl_t),
diff --git a/hw/hw.h b/hw/hw.h
index 9a40b43..89c138d 100644
--- a/hw/hw.h
+++ b/hw/hw.h
@@ -285,7 +285,7 @@ enum VMStateFlags {
VMS_POINTER = 0x002,
VMS_ARRAY = 0x004,
VMS_STRUCT = 0x008,
- VMS_VARRAY = 0x010, /* Array with size in another field */
+ VMS_VARRAY_INT32 = 0x010, /* Array with size in another field */
VMS_BUFFER = 0x020, /* static sized buffer */
VMS_ARRAY_OF_POINTER = 0x040,
};
@@ -390,14 +390,14 @@ extern const VMStateInfo vmstate_info_buffer;
+ type_check_array(_type,typeof_field(_state, _field),_num) \
}
-#define VMSTATE_VARRAY(_field, _state, _field_num, _version, _info, _type) {\
+#define VMSTATE_VARRAY_INT32(_field, _state, _field_num, _version, _info, _type) {\
.name = (stringify(_field)), \
.version_id = (_version), \
.num_offset = offsetof(_state, _field_num) \
+ type_check(int32_t,typeof_field(_state, _field_num)), \
.info = &(_info), \
.size = sizeof(_type), \
- .flags = VMS_VARRAY|VMS_POINTER, \
+ .flags = VMS_VARRAY_INT32|VMS_POINTER, \
.offset = offsetof(_state, _field) \
+ type_check_pointer(_type,typeof_field(_state, _field)) \
}
@@ -618,7 +618,7 @@ extern const VMStateDescription vmstate_i2c_slave;
VMSTATE_INT32_ARRAY_V(_f, _s, _n, 0)
#define VMSTATE_INT32_VARRAY_V(_f, _s, _f_n, _v) \
- VMSTATE_VARRAY(_f, _s, _f_n, _v, vmstate_info_int32, int32_t)
+ VMSTATE_VARRAY_INT32(_f, _s, _f_n, _v, vmstate_info_int32, int32_t)
#define VMSTATE_INT32_VARRAY(_f, _s, _f_n) \
VMSTATE_INT32_VARRAY_V(_f, _s, _f_n, 0)
diff --git a/savevm.c b/savevm.c
index 6a10bc7..ccbbae8 100644
--- a/savevm.c
+++ b/savevm.c
@@ -1084,8 +1084,8 @@ int vmstate_load_state(QEMUFile *f, const VMStateDescription *vmsd,
if (field->flags & VMS_ARRAY) {
n_elems = field->num;
- } else if (field->flags & VMS_VARRAY) {
- n_elems = *(size_t *)(opaque+field->num_offset);
+ } else if (field->flags & VMS_VARRAY_INT32) {
+ n_elems = *(int32_t *)(opaque+field->num_offset);
}
if (field->flags & VMS_POINTER) {
base_addr = *(void **)base_addr;
@@ -1131,8 +1131,8 @@ void vmstate_save_state(QEMUFile *f, const VMStateDescription *vmsd,
if (field->flags & VMS_ARRAY) {
n_elems = field->num;
- } else if (field->flags & VMS_VARRAY) {
- n_elems = *(size_t *)(opaque+field->num_offset);
+ } else if (field->flags & VMS_VARRAY_INT32) {
+ n_elems = *(int32_t *)(opaque+field->num_offset);
}
if (field->flags & VMS_POINTER) {
base_addr = *(void **)base_addr;
--
1.6.2.5
^ permalink raw reply related [flat|nested] 30+ messages in thread
* [Qemu-devel] [PATCH 06/25] vmstate: fix indentation
2009-10-19 18:42 [Qemu-devel] [PATCH 00/25] VMState cleanups and conversion of network drivers Juan Quintela
` (4 preceding siblings ...)
2009-10-19 18:42 ` [Qemu-devel] [PATCH 05/25] vmstate: Rename VMS_VARRAY to VMS_VARRAY_INT32 Juan Quintela
@ 2009-10-19 18:42 ` Juan Quintela
2009-10-19 18:42 ` [Qemu-devel] [PATCH 07/25] vmstate: factor vmstate_offset_value Juan Quintela
` (19 subsequent siblings)
25 siblings, 0 replies; 30+ messages in thread
From: Juan Quintela @ 2009-10-19 18:42 UTC (permalink / raw)
To: qemu-devel
Signed-off-by: Juan Quintela <quintela@redhat.com>
---
hw/hw.h | 12 ++++++------
1 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/hw/hw.h b/hw/hw.h
index 89c138d..cd42f74 100644
--- a/hw/hw.h
+++ b/hw/hw.h
@@ -281,12 +281,12 @@ struct VMStateInfo {
};
enum VMStateFlags {
- VMS_SINGLE = 0x001,
- VMS_POINTER = 0x002,
- VMS_ARRAY = 0x004,
- VMS_STRUCT = 0x008,
- VMS_VARRAY_INT32 = 0x010, /* Array with size in another field */
- VMS_BUFFER = 0x020, /* static sized buffer */
+ VMS_SINGLE = 0x001,
+ VMS_POINTER = 0x002,
+ VMS_ARRAY = 0x004,
+ VMS_STRUCT = 0x008,
+ VMS_VARRAY_INT32 = 0x010, /* Array with size in another field */
+ VMS_BUFFER = 0x020, /* static sized buffer */
VMS_ARRAY_OF_POINTER = 0x040,
};
--
1.6.2.5
^ permalink raw reply related [flat|nested] 30+ messages in thread
* [Qemu-devel] [PATCH 07/25] vmstate: factor vmstate_offset_value
2009-10-19 18:42 [Qemu-devel] [PATCH 00/25] VMState cleanups and conversion of network drivers Juan Quintela
` (5 preceding siblings ...)
2009-10-19 18:42 ` [Qemu-devel] [PATCH 06/25] vmstate: fix indentation Juan Quintela
@ 2009-10-19 18:42 ` Juan Quintela
2009-10-19 18:42 ` [Qemu-devel] [PATCH 08/25] vmstate: factor vmstate_offset_pointer Juan Quintela
` (18 subsequent siblings)
25 siblings, 0 replies; 30+ messages in thread
From: Juan Quintela @ 2009-10-19 18:42 UTC (permalink / raw)
To: qemu-devel
Signed-off-by: Juan Quintela <quintela@redhat.com>
---
hw/hw.h | 31 +++++++++++++------------------
1 files changed, 13 insertions(+), 18 deletions(-)
diff --git a/hw/hw.h b/hw/hw.h
index cd42f74..d1395e9 100644
--- a/hw/hw.h
+++ b/hw/hw.h
@@ -338,14 +338,17 @@ extern const VMStateInfo vmstate_info_buffer;
#define type_check_array(t1,t2,n) ((t1(*)[n])0 - (t2*)0)
#define type_check_pointer(t1,t2) ((t1**)0 - (t2*)0)
+#define vmstate_offset_value(_state, _field, _type) \
+ (offsetof(_state, _field) + \
+ type_check(_type, typeof_field(_state, _field)))
+
#define VMSTATE_SINGLE(_field, _state, _version, _info, _type) { \
.name = (stringify(_field)), \
.version_id = (_version), \
.size = sizeof(_type), \
.info = &(_info), \
.flags = VMS_SINGLE, \
- .offset = offsetof(_state, _field) \
- + type_check(_type,typeof_field(_state, _field)) \
+ .offset = vmstate_offset_value(_state, _field, _type), \
}
#define VMSTATE_SINGLE_TEST(_field, _state, _test, _info, _type) { \
@@ -354,8 +357,7 @@ extern const VMStateInfo vmstate_info_buffer;
.size = sizeof(_type), \
.info = &(_info), \
.flags = VMS_SINGLE, \
- .offset = offsetof(_state, _field) \
- + type_check(_type,typeof_field(_state, _field)) \
+ .offset = vmstate_offset_value(_state, _field, _type), \
}
#define VMSTATE_POINTER(_field, _state, _version, _info, _type) { \
@@ -364,8 +366,7 @@ extern const VMStateInfo vmstate_info_buffer;
.info = &(_info), \
.size = sizeof(_type), \
.flags = VMS_SINGLE|VMS_POINTER, \
- .offset = offsetof(_state, _field) \
- + type_check(_type,typeof_field(_state, _field)) \
+ .offset = vmstate_offset_value(_state, _field, _type), \
}
#define VMSTATE_ARRAY(_field, _state, _num, _version, _info, _type) {\
@@ -393,8 +394,7 @@ extern const VMStateInfo vmstate_info_buffer;
#define VMSTATE_VARRAY_INT32(_field, _state, _field_num, _version, _info, _type) {\
.name = (stringify(_field)), \
.version_id = (_version), \
- .num_offset = offsetof(_state, _field_num) \
- + type_check(int32_t,typeof_field(_state, _field_num)), \
+ .num_offset = vmstate_offset_value(_state, _field_num, int32_t), \
.info = &(_info), \
.size = sizeof(_type), \
.flags = VMS_VARRAY_INT32|VMS_POINTER, \
@@ -408,8 +408,7 @@ extern const VMStateInfo vmstate_info_buffer;
.vmsd = &(_vmsd), \
.size = sizeof(_type), \
.flags = VMS_STRUCT, \
- .offset = offsetof(_state, _field) \
- + type_check(_type,typeof_field(_state, _field)) \
+ .offset = vmstate_offset_value(_state, _field, _type), \
}
#define VMSTATE_STRUCT_POINTER(_field, _state, _vmsd, _type) { \
@@ -417,8 +416,7 @@ extern const VMStateInfo vmstate_info_buffer;
.vmsd = &(_vmsd), \
.size = sizeof(_type), \
.flags = VMS_STRUCT|VMS_POINTER, \
- .offset = offsetof(_state, _field) \
- + type_check(_type,typeof_field(_state, _field)) \
+ .offset = vmstate_offset_value(_state, _field, _type), \
}
#define VMSTATE_ARRAY_OF_POINTER(_field, _state, _num, _version, _info, _type) {\
@@ -445,8 +443,7 @@ extern const VMStateInfo vmstate_info_buffer;
#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)), \
+ .num_offset = vmstate_offset_value(_state, _field_num, uint8_t), \
.version_id = (_version), \
.vmsd = &(_vmsd), \
.size = sizeof(_type), \
@@ -490,8 +487,7 @@ extern const VMStateDescription vmstate_pci_device;
.size = sizeof(PCIDevice), \
.vmsd = &vmstate_pci_device, \
.flags = VMS_STRUCT, \
- .offset = offsetof(_state, _field) \
- + type_check(PCIDevice,typeof_field(_state, _field)) \
+ .offset = vmstate_offset_value(_state, _field, PCIDevice), \
}
extern const VMStateDescription vmstate_i2c_slave;
@@ -501,8 +497,7 @@ extern const VMStateDescription vmstate_i2c_slave;
.size = sizeof(i2c_slave), \
.vmsd = &vmstate_i2c_slave, \
.flags = VMS_STRUCT, \
- .offset = offsetof(_state, _field) \
- + type_check(i2c_slave,typeof_field(_state, _field)) \
+ .offset = vmstate_offset_value(_state, _field, i2c_slave), \
}
/* _f : field name
--
1.6.2.5
^ permalink raw reply related [flat|nested] 30+ messages in thread
* [Qemu-devel] [PATCH 08/25] vmstate: factor vmstate_offset_pointer
2009-10-19 18:42 [Qemu-devel] [PATCH 00/25] VMState cleanups and conversion of network drivers Juan Quintela
` (6 preceding siblings ...)
2009-10-19 18:42 ` [Qemu-devel] [PATCH 07/25] vmstate: factor vmstate_offset_value Juan Quintela
@ 2009-10-19 18:42 ` Juan Quintela
2009-10-19 18:42 ` [Qemu-devel] [PATCH 09/25] vmstate: factor vmstate_offset_array Juan Quintela
` (17 subsequent siblings)
25 siblings, 0 replies; 30+ messages in thread
From: Juan Quintela @ 2009-10-19 18:42 UTC (permalink / raw)
To: qemu-devel
Signed-off-by: Juan Quintela <quintela@redhat.com>
---
hw/hw.h | 7 +++++--
1 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/hw/hw.h b/hw/hw.h
index d1395e9..a331844 100644
--- a/hw/hw.h
+++ b/hw/hw.h
@@ -342,6 +342,10 @@ extern const VMStateInfo vmstate_info_buffer;
(offsetof(_state, _field) + \
type_check(_type, typeof_field(_state, _field)))
+#define vmstate_offset_pointer(_state, _field, _type) \
+ (offsetof(_state, _field) + \
+ type_check_pointer(_type, typeof_field(_state, _field)))
+
#define VMSTATE_SINGLE(_field, _state, _version, _info, _type) { \
.name = (stringify(_field)), \
.version_id = (_version), \
@@ -398,8 +402,7 @@ extern const VMStateInfo vmstate_info_buffer;
.info = &(_info), \
.size = sizeof(_type), \
.flags = VMS_VARRAY_INT32|VMS_POINTER, \
- .offset = offsetof(_state, _field) \
- + type_check_pointer(_type,typeof_field(_state, _field)) \
+ .offset = vmstate_offset_pointer(_state, _field, _type), \
}
#define VMSTATE_STRUCT(_field, _state, _version, _vmsd, _type) { \
--
1.6.2.5
^ permalink raw reply related [flat|nested] 30+ messages in thread
* [Qemu-devel] [PATCH 09/25] vmstate: factor vmstate_offset_array
2009-10-19 18:42 [Qemu-devel] [PATCH 00/25] VMState cleanups and conversion of network drivers Juan Quintela
` (7 preceding siblings ...)
2009-10-19 18:42 ` [Qemu-devel] [PATCH 08/25] vmstate: factor vmstate_offset_pointer Juan Quintela
@ 2009-10-19 18:42 ` Juan Quintela
2009-10-19 18:42 ` [Qemu-devel] [PATCH 10/25] vmstate: factor vmstate_offset_buffer Juan Quintela
` (16 subsequent siblings)
25 siblings, 0 replies; 30+ messages in thread
From: Juan Quintela @ 2009-10-19 18:42 UTC (permalink / raw)
To: qemu-devel
Signed-off-by: Juan Quintela <quintela@redhat.com>
---
hw/hw.h | 19 +++++++++----------
1 files changed, 9 insertions(+), 10 deletions(-)
diff --git a/hw/hw.h b/hw/hw.h
index a331844..d669755 100644
--- a/hw/hw.h
+++ b/hw/hw.h
@@ -346,6 +346,10 @@ extern const VMStateInfo vmstate_info_buffer;
(offsetof(_state, _field) + \
type_check_pointer(_type, typeof_field(_state, _field)))
+#define vmstate_offset_array(_state, _field, _type, _num) \
+ (offsetof(_state, _field) + \
+ type_check_array(_type, typeof_field(_state, _field), _num))
+
#define VMSTATE_SINGLE(_field, _state, _version, _info, _type) { \
.name = (stringify(_field)), \
.version_id = (_version), \
@@ -380,8 +384,7 @@ extern const VMStateInfo vmstate_info_buffer;
.info = &(_info), \
.size = sizeof(_type), \
.flags = VMS_ARRAY, \
- .offset = offsetof(_state, _field) \
- + type_check_array(_type,typeof_field(_state, _field),_num) \
+ .offset = vmstate_offset_array(_state, _field, _type, _num), \
}
#define VMSTATE_ARRAY_TEST(_field, _state, _num, _test, _info, _type) {\
@@ -391,8 +394,7 @@ extern const VMStateInfo vmstate_info_buffer;
.info = &(_info), \
.size = sizeof(_type), \
.flags = VMS_ARRAY, \
- .offset = offsetof(_state, _field) \
- + type_check_array(_type,typeof_field(_state, _field),_num) \
+ .offset = vmstate_offset_array(_state, _field, _type, _num),\
}
#define VMSTATE_VARRAY_INT32(_field, _state, _field_num, _version, _info, _type) {\
@@ -429,8 +431,7 @@ extern const VMStateInfo vmstate_info_buffer;
.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) \
+ .offset = vmstate_offset_array(_state, _field, _type, _num), \
}
#define VMSTATE_STRUCT_ARRAY(_field, _state, _num, _version, _vmsd, _type) { \
@@ -440,8 +441,7 @@ extern const VMStateInfo vmstate_info_buffer;
.vmsd = &(_vmsd), \
.size = sizeof(_type), \
.flags = VMS_STRUCT|VMS_ARRAY, \
- .offset = offsetof(_state, _field) \
- + type_check_array(_type,typeof_field(_state, _field),_num) \
+ .offset = vmstate_offset_array(_state, _field, _type, _num), \
}
#define VMSTATE_STRUCT_ARRAY_SIZE_UINT8(_field, _state, _field__num, _version, _vmsd, _type) { \
@@ -451,8 +451,7 @@ extern const VMStateInfo vmstate_info_buffer;
.vmsd = &(_vmsd), \
.size = sizeof(_type), \
.flags = VMS_STRUCT|VMS_ARRAY, \
- .offset = offsetof(_state, _field) \
- + type_check_array(_type,typeof_field(_state, _field),_num) \
+ .offset = vmstate_offset_array(_state, _field, _type, _num), \
}
#define VMSTATE_STATIC_BUFFER(_field, _state, _version) { \
--
1.6.2.5
^ permalink raw reply related [flat|nested] 30+ messages in thread
* [Qemu-devel] [PATCH 10/25] vmstate: factor vmstate_offset_buffer
2009-10-19 18:42 [Qemu-devel] [PATCH 00/25] VMState cleanups and conversion of network drivers Juan Quintela
` (8 preceding siblings ...)
2009-10-19 18:42 ` [Qemu-devel] [PATCH 09/25] vmstate: factor vmstate_offset_array Juan Quintela
@ 2009-10-19 18:42 ` Juan Quintela
2009-10-19 18:42 ` [Qemu-devel] [PATCH 11/25] vmstate: factor VMSTATE_*BUFFER* definitions Juan Quintela
` (15 subsequent siblings)
25 siblings, 0 replies; 30+ messages in thread
From: Juan Quintela @ 2009-10-19 18:42 UTC (permalink / raw)
To: qemu-devel
Signed-off-by: Juan Quintela <quintela@redhat.com>
---
hw/hw.h | 13 +++++++------
1 files changed, 7 insertions(+), 6 deletions(-)
diff --git a/hw/hw.h b/hw/hw.h
index d669755..aea50a6 100644
--- a/hw/hw.h
+++ b/hw/hw.h
@@ -350,6 +350,10 @@ extern const VMStateInfo vmstate_info_buffer;
(offsetof(_state, _field) + \
type_check_array(_type, typeof_field(_state, _field), _num))
+#define vmstate_offset_buffer(_state, _field) \
+ vmstate_offset_array(_state, _field, uint8_t, \
+ sizeof(typeof_field(_state, _field)))
+
#define VMSTATE_SINGLE(_field, _state, _version, _info, _type) { \
.name = (stringify(_field)), \
.version_id = (_version), \
@@ -460,8 +464,7 @@ extern const VMStateInfo vmstate_info_buffer;
.size = sizeof(typeof_field(_state,_field)), \
.info = &vmstate_info_buffer, \
.flags = VMS_BUFFER, \
- .offset = offsetof(_state, _field) \
- + type_check_array(uint8_t,typeof_field(_state, _field),sizeof(typeof_field(_state,_field))) \
+ .offset = vmstate_offset_buffer(_state, _field), \
}
#define VMSTATE_PARTIAL_BUFFER(_field, _state, _size) { \
@@ -469,8 +472,7 @@ extern const VMStateInfo vmstate_info_buffer;
.size = (_size), \
.info = &vmstate_info_buffer, \
.flags = VMS_BUFFER, \
- .offset = offsetof(_state, _field) \
- + type_check_array(uint8_t,typeof_field(_state, _field),sizeof(typeof_field(_state,_field))) \
+ .offset = vmstate_offset_buffer(_state, _field), \
}
#define VMSTATE_BUFFER_START_MIDDLE(_field, _state, start) { \
@@ -478,8 +480,7 @@ extern const VMStateInfo vmstate_info_buffer;
.size = sizeof(typeof_field(_state,_field)) - start, \
.info = &vmstate_info_buffer, \
.flags = VMS_BUFFER, \
- .offset = offsetof(_state, _field) + start \
- + type_check_array(uint8_t,typeof_field(_state, _field),sizeof(typeof_field(_state,_field))) \
+ .offset = vmstate_offset_buffer(_state, _field) + start, \
}
extern const VMStateDescription vmstate_pci_device;
--
1.6.2.5
^ permalink raw reply related [flat|nested] 30+ messages in thread
* [Qemu-devel] [PATCH 11/25] vmstate: factor VMSTATE_*BUFFER* definitions
2009-10-19 18:42 [Qemu-devel] [PATCH 00/25] VMState cleanups and conversion of network drivers Juan Quintela
` (9 preceding siblings ...)
2009-10-19 18:42 ` [Qemu-devel] [PATCH 10/25] vmstate: factor vmstate_offset_buffer Juan Quintela
@ 2009-10-19 18:42 ` Juan Quintela
2009-10-19 18:42 ` [Qemu-devel] [PATCH 12/25] vmstate: Unfold VMSTATE_INT32_VARRAY() only use and remove it Juan Quintela
` (14 subsequent siblings)
25 siblings, 0 replies; 30+ messages in thread
From: Juan Quintela @ 2009-10-19 18:42 UTC (permalink / raw)
To: qemu-devel
Signed-off-by: Juan Quintela <quintela@redhat.com>
---
hw/hw.h | 32 +++++++++++---------------------
1 files changed, 11 insertions(+), 21 deletions(-)
diff --git a/hw/hw.h b/hw/hw.h
index aea50a6..dd065c8 100644
--- a/hw/hw.h
+++ b/hw/hw.h
@@ -458,29 +458,13 @@ extern const VMStateInfo vmstate_info_buffer;
.offset = vmstate_offset_array(_state, _field, _type, _num), \
}
-#define VMSTATE_STATIC_BUFFER(_field, _state, _version) { \
+#define VMSTATE_STATIC_BUFFER(_field, _state, _version, _start, _size) { \
.name = (stringify(_field)), \
.version_id = (_version), \
- .size = sizeof(typeof_field(_state,_field)), \
+ .size = (_size - _start), \
.info = &vmstate_info_buffer, \
.flags = VMS_BUFFER, \
- .offset = vmstate_offset_buffer(_state, _field), \
-}
-
-#define VMSTATE_PARTIAL_BUFFER(_field, _state, _size) { \
- .name = (stringify(_field)), \
- .size = (_size), \
- .info = &vmstate_info_buffer, \
- .flags = VMS_BUFFER, \
- .offset = vmstate_offset_buffer(_state, _field), \
-}
-
-#define VMSTATE_BUFFER_START_MIDDLE(_field, _state, start) { \
- .name = (stringify(_field)), \
- .size = sizeof(typeof_field(_state,_field)) - start, \
- .info = &vmstate_info_buffer, \
- .flags = VMS_BUFFER, \
- .offset = vmstate_offset_buffer(_state, _field) + start, \
+ .offset = vmstate_offset_buffer(_state, _field) + _start, \
}
extern const VMStateDescription vmstate_pci_device;
@@ -622,10 +606,16 @@ extern const VMStateDescription vmstate_i2c_slave;
VMSTATE_INT32_VARRAY_V(_f, _s, _f_n, 0)
#define VMSTATE_BUFFER_V(_f, _s, _v) \
- VMSTATE_STATIC_BUFFER(_f, _s, _v)
+ VMSTATE_STATIC_BUFFER(_f, _s, _v, 0, sizeof(typeof_field(_s, _f)))
#define VMSTATE_BUFFER(_f, _s) \
- VMSTATE_STATIC_BUFFER(_f, _s, 0)
+ VMSTATE_BUFFER_V(_f, _s, 0)
+
+#define VMSTATE_PARTIAL_BUFFER(_f, _s, _size) \
+ VMSTATE_STATIC_BUFFER(_f, _s, 0, 0, _size)
+
+#define VMSTATE_BUFFER_START_MIDDLE(_f, _s, _start) \
+ VMSTATE_STATIC_BUFFER(_f, _s, 0, _start, sizeof(typeof_field(_s, _f)))
#ifdef NEED_CPU_H
#if TARGET_LONG_BITS == 64
--
1.6.2.5
^ permalink raw reply related [flat|nested] 30+ messages in thread
* [Qemu-devel] [PATCH 12/25] vmstate: Unfold VMSTATE_INT32_VARRAY() only use and remove it
2009-10-19 18:42 [Qemu-devel] [PATCH 00/25] VMState cleanups and conversion of network drivers Juan Quintela
` (10 preceding siblings ...)
2009-10-19 18:42 ` [Qemu-devel] [PATCH 11/25] vmstate: factor VMSTATE_*BUFFER* definitions Juan Quintela
@ 2009-10-19 18:42 ` Juan Quintela
2009-10-19 18:42 ` [Qemu-devel] [PATCH 13/25] vmstate: add VMS_VARRAY_UINT16_UNSAFE (varrays with uint16 indexes) Juan Quintela
` (13 subsequent siblings)
25 siblings, 0 replies; 30+ messages in thread
From: Juan Quintela @ 2009-10-19 18:42 UTC (permalink / raw)
To: qemu-devel
Signed-off-by: Juan Quintela <quintela@redhat.com>
---
hw/hw.h | 6 ------
hw/pci.c | 2 +-
2 files changed, 1 insertions(+), 7 deletions(-)
diff --git a/hw/hw.h b/hw/hw.h
index dd065c8..5edfff7 100644
--- a/hw/hw.h
+++ b/hw/hw.h
@@ -599,12 +599,6 @@ extern const VMStateDescription vmstate_i2c_slave;
#define VMSTATE_INT32_ARRAY(_f, _s, _n) \
VMSTATE_INT32_ARRAY_V(_f, _s, _n, 0)
-#define VMSTATE_INT32_VARRAY_V(_f, _s, _f_n, _v) \
- VMSTATE_VARRAY_INT32(_f, _s, _f_n, _v, vmstate_info_int32, int32_t)
-
-#define VMSTATE_INT32_VARRAY(_f, _s, _f_n) \
- VMSTATE_INT32_VARRAY_V(_f, _s, _f_n, 0)
-
#define VMSTATE_BUFFER_V(_f, _s, _v) \
VMSTATE_STATIC_BUFFER(_f, _s, _v, 0, sizeof(typeof_field(_s, _f)))
diff --git a/hw/pci.c b/hw/pci.c
index abf07ca..a632818 100644
--- a/hw/pci.c
+++ b/hw/pci.c
@@ -79,7 +79,7 @@ static const VMStateDescription vmstate_pcibus = {
.minimum_version_id_old = 1,
.fields = (VMStateField []) {
VMSTATE_INT32_EQUAL(nirq, PCIBus),
- VMSTATE_INT32_VARRAY(irq_count, PCIBus, nirq),
+ VMSTATE_VARRAY_INT32(irq_count, PCIBus, nirq, 0, vmstate_info_int32, int32_t),
VMSTATE_END_OF_LIST()
}
};
--
1.6.2.5
^ permalink raw reply related [flat|nested] 30+ messages in thread
* [Qemu-devel] [PATCH 13/25] vmstate: add VMS_VARRAY_UINT16_UNSAFE (varrays with uint16 indexes)
2009-10-19 18:42 [Qemu-devel] [PATCH 00/25] VMState cleanups and conversion of network drivers Juan Quintela
` (11 preceding siblings ...)
2009-10-19 18:42 ` [Qemu-devel] [PATCH 12/25] vmstate: Unfold VMSTATE_INT32_VARRAY() only use and remove it Juan Quintela
@ 2009-10-19 18:42 ` Juan Quintela
2009-10-19 18:42 ` [Qemu-devel] [PATCH 14/25] vmstate: Add version arg to VMSTATE_SINGLE_TEST() Juan Quintela
` (12 subsequent siblings)
25 siblings, 0 replies; 30+ messages in thread
From: Juan Quintela @ 2009-10-19 18:42 UTC (permalink / raw)
To: qemu-devel
It don't check types.
Signed-off-by: Juan Quintela <quintela@redhat.com>
---
hw/hw.h | 13 ++++++++++++-
savevm.c | 4 ++++
2 files changed, 16 insertions(+), 1 deletions(-)
diff --git a/hw/hw.h b/hw/hw.h
index 5edfff7..eb199fb 100644
--- a/hw/hw.h
+++ b/hw/hw.h
@@ -285,9 +285,10 @@ enum VMStateFlags {
VMS_POINTER = 0x002,
VMS_ARRAY = 0x004,
VMS_STRUCT = 0x008,
- VMS_VARRAY_INT32 = 0x010, /* Array with size in another field */
+ VMS_VARRAY_INT32 = 0x010, /* Array with size in int32_t field*/
VMS_BUFFER = 0x020, /* static sized buffer */
VMS_ARRAY_OF_POINTER = 0x040,
+ VMS_VARRAY_UINT16 = 0x080, /* Array with size in uint16_t field */
};
typedef struct {
@@ -411,6 +412,16 @@ extern const VMStateInfo vmstate_info_buffer;
.offset = vmstate_offset_pointer(_state, _field, _type), \
}
+#define VMSTATE_VARRAY_UINT16_UNSAFE(_field, _state, _field_num, _version, _info, _type) {\
+ .name = (stringify(_field)), \
+ .version_id = (_version), \
+ .num_offset = vmstate_offset_value(_state, _field_num, uint16_t),\
+ .info = &(_info), \
+ .size = sizeof(_type), \
+ .flags = VMS_VARRAY_UINT16, \
+ .offset = offsetof(_state, _field), \
+}
+
#define VMSTATE_STRUCT(_field, _state, _version, _vmsd, _type) { \
.name = (stringify(_field)), \
.version_id = (_version), \
diff --git a/savevm.c b/savevm.c
index ccbbae8..f377bfe 100644
--- a/savevm.c
+++ b/savevm.c
@@ -1086,6 +1086,8 @@ int vmstate_load_state(QEMUFile *f, const VMStateDescription *vmsd,
n_elems = field->num;
} else if (field->flags & VMS_VARRAY_INT32) {
n_elems = *(int32_t *)(opaque+field->num_offset);
+ } else if (field->flags & VMS_VARRAY_UINT16) {
+ n_elems = *(uint16_t *)(opaque+field->num_offset);
}
if (field->flags & VMS_POINTER) {
base_addr = *(void **)base_addr;
@@ -1133,6 +1135,8 @@ void vmstate_save_state(QEMUFile *f, const VMStateDescription *vmsd,
n_elems = field->num;
} else if (field->flags & VMS_VARRAY_INT32) {
n_elems = *(int32_t *)(opaque+field->num_offset);
+ } else if (field->flags & VMS_VARRAY_UINT16) {
+ n_elems = *(uint16_t *)(opaque+field->num_offset);
}
if (field->flags & VMS_POINTER) {
base_addr = *(void **)base_addr;
--
1.6.2.5
^ permalink raw reply related [flat|nested] 30+ messages in thread
* [Qemu-devel] [PATCH 14/25] vmstate: Add version arg to VMSTATE_SINGLE_TEST()
2009-10-19 18:42 [Qemu-devel] [PATCH 00/25] VMState cleanups and conversion of network drivers Juan Quintela
` (12 preceding siblings ...)
2009-10-19 18:42 ` [Qemu-devel] [PATCH 13/25] vmstate: add VMS_VARRAY_UINT16_UNSAFE (varrays with uint16 indexes) Juan Quintela
@ 2009-10-19 18:42 ` Juan Quintela
2009-10-19 18:43 ` [Qemu-devel] [PATCH 15/25] vmstate: Add VMSTATE_BUFFER_UNUSED Juan Quintela
` (11 subsequent siblings)
25 siblings, 0 replies; 30+ messages in thread
From: Juan Quintela @ 2009-10-19 18:42 UTC (permalink / raw)
To: qemu-devel
This allows to define VMSTATE_SINGLE with VMSTATE_SINGLE_TEST
Signed-off-by: Juan Quintela <quintela@redhat.com>
---
hw/hw.h | 17 ++++++-----------
target-i386/machine.c | 2 +-
2 files changed, 7 insertions(+), 12 deletions(-)
diff --git a/hw/hw.h b/hw/hw.h
index eb199fb..3feb9df 100644
--- a/hw/hw.h
+++ b/hw/hw.h
@@ -355,17 +355,9 @@ extern const VMStateInfo vmstate_info_buffer;
vmstate_offset_array(_state, _field, uint8_t, \
sizeof(typeof_field(_state, _field)))
-#define VMSTATE_SINGLE(_field, _state, _version, _info, _type) { \
- .name = (stringify(_field)), \
- .version_id = (_version), \
- .size = sizeof(_type), \
- .info = &(_info), \
- .flags = VMS_SINGLE, \
- .offset = vmstate_offset_value(_state, _field, _type), \
-}
-
-#define VMSTATE_SINGLE_TEST(_field, _state, _test, _info, _type) { \
+#define VMSTATE_SINGLE_TEST(_field, _state, _test, _version, _info, _type) { \
.name = (stringify(_field)), \
+ .version_id = (_version), \
.field_exists = (_test), \
.size = sizeof(_type), \
.info = &(_info), \
@@ -505,6 +497,9 @@ extern const VMStateDescription vmstate_i2c_slave;
_v : version
*/
+#define VMSTATE_SINGLE(_field, _state, _version, _info, _type) \
+ VMSTATE_SINGLE_TEST(_field, _state, NULL, _version, _info, _type)
+
#define VMSTATE_INT8_V(_f, _s, _v) \
VMSTATE_SINGLE(_f, _s, _v, vmstate_info_int8, int8_t)
#define VMSTATE_INT16_V(_f, _s, _v) \
@@ -557,7 +552,7 @@ extern const VMStateDescription vmstate_i2c_slave;
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)
+ VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_uint32, uint32_t)
#define VMSTATE_TIMER_V(_f, _s, _v) \
VMSTATE_POINTER(_f, _s, _v, vmstate_info_timer, QEMUTimer *)
diff --git a/target-i386/machine.c b/target-i386/machine.c
index 26d012d..869c681 100644
--- a/target-i386/machine.c
+++ b/target-i386/machine.c
@@ -314,7 +314,7 @@ static const VMStateInfo vmstate_hack_uint64_as_uint32 = {
};
#define VMSTATE_HACK_UINT32(_f, _s, _t) \
- VMSTATE_SINGLE_TEST(_f, _s, _t, vmstate_hack_uint64_as_uint32, uint64_t)
+ VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_hack_uint64_as_uint32, uint64_t)
#endif
static void cpu_pre_save(void *opaque)
--
1.6.2.5
^ permalink raw reply related [flat|nested] 30+ messages in thread
* [Qemu-devel] [PATCH 15/25] vmstate: Add VMSTATE_BUFFER_UNUSED
2009-10-19 18:42 [Qemu-devel] [PATCH 00/25] VMState cleanups and conversion of network drivers Juan Quintela
` (13 preceding siblings ...)
2009-10-19 18:42 ` [Qemu-devel] [PATCH 14/25] vmstate: Add version arg to VMSTATE_SINGLE_TEST() Juan Quintela
@ 2009-10-19 18:43 ` Juan Quintela
2009-10-19 18:43 ` [Qemu-devel] [PATCH 16/25] vmstate: Introduce the concept of sub-arrays Juan Quintela
` (10 subsequent siblings)
25 siblings, 0 replies; 30+ messages in thread
From: Juan Quintela @ 2009-10-19 18:43 UTC (permalink / raw)
To: qemu-devel
It allows to have 'things' in savevm format not backed in the device state
Signed-off-by: Juan Quintela <quintela@redhat.com>
---
hw/hw.h | 18 ++++++++++++++++++
savevm.c | 20 ++++++++++++++++++++
2 files changed, 38 insertions(+), 0 deletions(-)
diff --git a/hw/hw.h b/hw/hw.h
index 3feb9df..d3bf0a7 100644
--- a/hw/hw.h
+++ b/hw/hw.h
@@ -335,6 +335,7 @@ extern const VMStateInfo vmstate_info_uint64;
extern const VMStateInfo vmstate_info_timer;
extern const VMStateInfo vmstate_info_ptimer;
extern const VMStateInfo vmstate_info_buffer;
+extern const VMStateInfo vmstate_info_unused_buffer;
#define type_check_array(t1,t2,n) ((t1(*)[n])0 - (t2*)0)
#define type_check_pointer(t1,t2) ((t1**)0 - (t2*)0)
@@ -470,6 +471,14 @@ extern const VMStateInfo vmstate_info_buffer;
.offset = vmstate_offset_buffer(_state, _field) + _start, \
}
+#define VMSTATE_UNUSED_BUFFER(_test, _version, _size) { \
+ .name = "unused", \
+ .field_exists = (_test), \
+ .version_id = (_version), \
+ .size = (_size), \
+ .info = &vmstate_info_unused_buffer, \
+ .flags = VMS_BUFFER, \
+}
extern const VMStateDescription vmstate_pci_device;
#define VMSTATE_PCI_DEVICE(_field, _state) { \
@@ -617,6 +626,15 @@ extern const VMStateDescription vmstate_i2c_slave;
#define VMSTATE_BUFFER_START_MIDDLE(_f, _s, _start) \
VMSTATE_STATIC_BUFFER(_f, _s, 0, _start, sizeof(typeof_field(_s, _f)))
+#define VMSTATE_UNUSED_V(_v, _size) \
+ VMSTATE_UNUSED_BUFFER(NULL, _v, _size)
+
+#define VMSTATE_UNUSED(_size) \
+ VMSTATE_UNUSED_V(0, _size)
+
+#define VMSTATE_UNUSED_TEST(_test, _size) \
+ VMSTATE_UNUSED_BUFFER(_test, 0, _size)
+
#ifdef NEED_CPU_H
#if TARGET_LONG_BITS == 64
#define VMSTATE_UINTTL_V(_f, _s, _v) \
diff --git a/savevm.c b/savevm.c
index f377bfe..ed16cea 100644
--- a/savevm.c
+++ b/savevm.c
@@ -930,6 +930,26 @@ const VMStateInfo vmstate_info_buffer = {
.put = put_buffer,
};
+/* unused buffers: space that was used for some fields that are
+ not usefull anymore */
+
+static int get_unused_buffer(QEMUFile *f, void *pv, size_t size)
+{
+ qemu_fseek(f, size, SEEK_CUR);
+ return 0;
+}
+
+static void put_unused_buffer(QEMUFile *f, void *pv, size_t size)
+{
+ qemu_fseek(f, size, SEEK_CUR);
+}
+
+const VMStateInfo vmstate_info_unused_buffer = {
+ .name = "unused_buffer",
+ .get = get_unused_buffer,
+ .put = put_unused_buffer,
+};
+
typedef struct SaveStateEntry {
QTAILQ_ENTRY(SaveStateEntry) entry;
char idstr[256];
--
1.6.2.5
^ permalink raw reply related [flat|nested] 30+ messages in thread
* [Qemu-devel] [PATCH 16/25] vmstate: Introduce the concept of sub-arrays
2009-10-19 18:42 [Qemu-devel] [PATCH 00/25] VMState cleanups and conversion of network drivers Juan Quintela
` (14 preceding siblings ...)
2009-10-19 18:43 ` [Qemu-devel] [PATCH 15/25] vmstate: Add VMSTATE_BUFFER_UNUSED Juan Quintela
@ 2009-10-19 18:43 ` Juan Quintela
2009-10-19 18:43 ` [Qemu-devel] [PATCH 17/25] rtl8139: port TallyCounters to vmstate Juan Quintela
` (9 subsequent siblings)
25 siblings, 0 replies; 30+ messages in thread
From: Juan Quintela @ 2009-10-19 18:43 UTC (permalink / raw)
To: qemu-devel
VMSTATE_SUB_ARRAY(..., start, num, ...) saves the num elems starting at
position start of the array
Signed-off-by: Juan Quintela <quintela@redhat.com>
---
hw/hw.h | 19 +++++++++++++++++++
1 files changed, 19 insertions(+), 0 deletions(-)
diff --git a/hw/hw.h b/hw/hw.h
index d3bf0a7..b98f0c9 100644
--- a/hw/hw.h
+++ b/hw/hw.h
@@ -352,6 +352,9 @@ extern const VMStateInfo vmstate_info_unused_buffer;
(offsetof(_state, _field) + \
type_check_array(_type, typeof_field(_state, _field), _num))
+#define vmstate_offset_sub_array(_state, _field, _type, _start) \
+ (offsetof(_state, _field[_start]))
+
#define vmstate_offset_buffer(_state, _field) \
vmstate_offset_array(_state, _field, uint8_t, \
sizeof(typeof_field(_state, _field)))
@@ -395,6 +398,16 @@ extern const VMStateInfo vmstate_info_unused_buffer;
.offset = vmstate_offset_array(_state, _field, _type, _num),\
}
+#define VMSTATE_SUB_ARRAY(_field, _state, _start, _num, _version, _info, _type) { \
+ .name = (stringify(_field)), \
+ .version_id = (_version), \
+ .num = (_num), \
+ .info = &(_info), \
+ .size = sizeof(_type), \
+ .flags = VMS_ARRAY, \
+ .offset = vmstate_offset_sub_array(_state, _field, _type, _start), \
+}
+
#define VMSTATE_VARRAY_INT32(_field, _state, _field_num, _version, _info, _type) {\
.name = (stringify(_field)), \
.version_id = (_version), \
@@ -614,6 +627,12 @@ extern const VMStateDescription vmstate_i2c_slave;
#define VMSTATE_INT32_ARRAY(_f, _s, _n) \
VMSTATE_INT32_ARRAY_V(_f, _s, _n, 0)
+#define VMSTATE_UINT32_SUB_ARRAY(_f, _s, _start, _num) \
+ VMSTATE_SUB_ARRAY(_f, _s, _start, _num, 0, vmstate_info_uint32, uint32_t)
+
+#define VMSTATE_UINT32_ARRAY(_f, _s, _n) \
+ VMSTATE_UINT32_ARRAY_V(_f, _s, _n, 0)
+
#define VMSTATE_BUFFER_V(_f, _s, _v) \
VMSTATE_STATIC_BUFFER(_f, _s, _v, 0, sizeof(typeof_field(_s, _f)))
--
1.6.2.5
^ permalink raw reply related [flat|nested] 30+ messages in thread
* [Qemu-devel] [PATCH 17/25] rtl8139: port TallyCounters to vmstate
2009-10-19 18:42 [Qemu-devel] [PATCH 00/25] VMState cleanups and conversion of network drivers Juan Quintela
` (15 preceding siblings ...)
2009-10-19 18:43 ` [Qemu-devel] [PATCH 16/25] vmstate: Introduce the concept of sub-arrays Juan Quintela
@ 2009-10-19 18:43 ` Juan Quintela
2009-10-19 18:43 ` [Qemu-devel] [PATCH 18/25] rtl8139: port " Juan Quintela
` (8 subsequent siblings)
25 siblings, 0 replies; 30+ messages in thread
From: Juan Quintela @ 2009-10-19 18:43 UTC (permalink / raw)
To: qemu-devel
Signed-off-by: Juan Quintela <quintela@redhat.com>
---
hw/rtl8139.c | 50 ++++++++++++++++++++++++--------------------------
1 files changed, 24 insertions(+), 26 deletions(-)
diff --git a/hw/rtl8139.c b/hw/rtl8139.c
index 10daeb2..7efa119 100644
--- a/hw/rtl8139.c
+++ b/hw/rtl8139.c
@@ -1327,39 +1327,37 @@ static void RTL8139TallyCounters_physical_memory_write(target_phys_addr_t tc_add
}
/* Loads values of tally counters from VM state file */
+
+static const VMStateDescription vmstate_tally_counters = {
+ .name = "tally_counters",
+ .version_id = 1,
+ .minimum_version_id = 1,
+ .minimum_version_id_old = 1,
+ .fields = (VMStateField []) {
+ VMSTATE_UINT64(TxOk, RTL8139TallyCounters),
+ VMSTATE_UINT64(RxOk, RTL8139TallyCounters),
+ VMSTATE_UINT64(TxERR, RTL8139TallyCounters),
+ VMSTATE_UINT32(RxERR, RTL8139TallyCounters),
+ VMSTATE_UINT16(MissPkt, RTL8139TallyCounters),
+ VMSTATE_UINT16(FAE, RTL8139TallyCounters),
+ VMSTATE_UINT32(Tx1Col, RTL8139TallyCounters),
+ VMSTATE_UINT32(TxMCol, RTL8139TallyCounters),
+ VMSTATE_UINT64(RxOkPhy, RTL8139TallyCounters),
+ VMSTATE_UINT64(RxOkBrd, RTL8139TallyCounters),
+ VMSTATE_UINT16(TxAbt, RTL8139TallyCounters),
+ VMSTATE_UINT16(TxUndrn, RTL8139TallyCounters),
+ VMSTATE_END_OF_LIST()
+ }
+};
static void RTL8139TallyCounters_load(QEMUFile* f, RTL8139TallyCounters *tally_counters)
{
- qemu_get_be64s(f, &tally_counters->TxOk);
- qemu_get_be64s(f, &tally_counters->RxOk);
- qemu_get_be64s(f, &tally_counters->TxERR);
- qemu_get_be32s(f, &tally_counters->RxERR);
- qemu_get_be16s(f, &tally_counters->MissPkt);
- qemu_get_be16s(f, &tally_counters->FAE);
- qemu_get_be32s(f, &tally_counters->Tx1Col);
- qemu_get_be32s(f, &tally_counters->TxMCol);
- qemu_get_be64s(f, &tally_counters->RxOkPhy);
- qemu_get_be64s(f, &tally_counters->RxOkBrd);
- qemu_get_be32s(f, &tally_counters->RxOkMul);
- qemu_get_be16s(f, &tally_counters->TxAbt);
- qemu_get_be16s(f, &tally_counters->TxUndrn);
+ vmstate_load_state(f, &vmstate_tally_counters, tally_counters, vmstate_tally_counters.version_id);
}
/* Saves values of tally counters to VM state file */
static void RTL8139TallyCounters_save(QEMUFile* f, RTL8139TallyCounters *tally_counters)
{
- qemu_put_be64s(f, &tally_counters->TxOk);
- qemu_put_be64s(f, &tally_counters->RxOk);
- qemu_put_be64s(f, &tally_counters->TxERR);
- qemu_put_be32s(f, &tally_counters->RxERR);
- qemu_put_be16s(f, &tally_counters->MissPkt);
- qemu_put_be16s(f, &tally_counters->FAE);
- qemu_put_be32s(f, &tally_counters->Tx1Col);
- qemu_put_be32s(f, &tally_counters->TxMCol);
- qemu_put_be64s(f, &tally_counters->RxOkPhy);
- qemu_put_be64s(f, &tally_counters->RxOkBrd);
- qemu_put_be32s(f, &tally_counters->RxOkMul);
- qemu_put_be16s(f, &tally_counters->TxAbt);
- qemu_put_be16s(f, &tally_counters->TxUndrn);
+ vmstate_save_state(f, &vmstate_tally_counters, tally_counters);
}
static void rtl8139_ChipCmd_write(RTL8139State *s, uint32_t val)
--
1.6.2.5
^ permalink raw reply related [flat|nested] 30+ messages in thread
* [Qemu-devel] [PATCH 18/25] rtl8139: port to vmstate
2009-10-19 18:42 [Qemu-devel] [PATCH 00/25] VMState cleanups and conversion of network drivers Juan Quintela
` (16 preceding siblings ...)
2009-10-19 18:43 ` [Qemu-devel] [PATCH 17/25] rtl8139: port TallyCounters to vmstate Juan Quintela
@ 2009-10-19 18:43 ` Juan Quintela
2009-10-19 18:43 ` [Qemu-devel] [PATCH 19/25] eeprom93xx: " Juan Quintela
` (7 subsequent siblings)
25 siblings, 0 replies; 30+ messages in thread
From: Juan Quintela @ 2009-10-19 18:43 UTC (permalink / raw)
To: qemu-devel
Signed-off-by: Juan Quintela <quintela@redhat.com>
---
hw/rtl8139.c | 301 ++++++++++++++++-----------------------------------------
1 files changed, 85 insertions(+), 216 deletions(-)
diff --git a/hw/rtl8139.c b/hw/rtl8139.c
index 7efa119..ab3f398 100644
--- a/hw/rtl8139.c
+++ b/hw/rtl8139.c
@@ -416,12 +416,6 @@ static void RTL8139TallyCounters_clear(RTL8139TallyCounters* counters);
/* Writes tally counters to specified physical memory address */
static void RTL8139TallyCounters_physical_memory_write(target_phys_addr_t tc_addr, RTL8139TallyCounters* counters);
-/* Loads values of tally counters from VM state file */
-static void RTL8139TallyCounters_load(QEMUFile* f, RTL8139TallyCounters *tally_counters);
-
-/* Saves values of tally counters to VM state file */
-static void RTL8139TallyCounters_save(QEMUFile* f, RTL8139TallyCounters *tally_counters);
-
typedef struct RTL8139State {
PCIDevice dev;
uint8_t phys[8]; /* mac address */
@@ -1349,16 +1343,6 @@ static const VMStateDescription vmstate_tally_counters = {
VMSTATE_END_OF_LIST()
}
};
-static void RTL8139TallyCounters_load(QEMUFile* f, RTL8139TallyCounters *tally_counters)
-{
- vmstate_load_state(f, &vmstate_tally_counters, tally_counters, vmstate_tally_counters.version_id);
-}
-
-/* Saves values of tally counters to VM state file */
-static void RTL8139TallyCounters_save(QEMUFile* f, RTL8139TallyCounters *tally_counters)
-{
- vmstate_save_state(f, &vmstate_tally_counters, tally_counters);
-}
static void rtl8139_ChipCmd_write(RTL8139State *s, uint32_t val)
{
@@ -3112,212 +3096,97 @@ static uint32_t rtl8139_mmio_readl(void *opaque, target_phys_addr_t addr)
return val;
}
-/* */
-
-static void rtl8139_save(QEMUFile* f,void* opaque)
-{
- RTL8139State* s = opaque;
- unsigned int i;
-
- pci_device_save(&s->dev, f);
-
- qemu_put_buffer(f, s->phys, 6);
- qemu_put_buffer(f, s->mult, 8);
-
- for (i=0; i<4; ++i)
- {
- qemu_put_be32s(f, &s->TxStatus[i]); /* TxStatus0 */
- }
- for (i=0; i<4; ++i)
- {
- qemu_put_be32s(f, &s->TxAddr[i]); /* TxAddr0 */
- }
-
- qemu_put_be32s(f, &s->RxBuf); /* Receive buffer */
- qemu_put_be32s(f, &s->RxBufferSize);/* internal variable, receive ring buffer size in C mode */
- qemu_put_be32s(f, &s->RxBufPtr);
- qemu_put_be32s(f, &s->RxBufAddr);
-
- qemu_put_be16s(f, &s->IntrStatus);
- qemu_put_be16s(f, &s->IntrMask);
-
- qemu_put_be32s(f, &s->TxConfig);
- qemu_put_be32s(f, &s->RxConfig);
- qemu_put_be32s(f, &s->RxMissed);
- qemu_put_be16s(f, &s->CSCR);
-
- qemu_put_8s(f, &s->Cfg9346);
- qemu_put_8s(f, &s->Config0);
- qemu_put_8s(f, &s->Config1);
- qemu_put_8s(f, &s->Config3);
- qemu_put_8s(f, &s->Config4);
- qemu_put_8s(f, &s->Config5);
-
- qemu_put_8s(f, &s->clock_enabled);
- qemu_put_8s(f, &s->bChipCmdState);
-
- qemu_put_be16s(f, &s->MultiIntr);
-
- qemu_put_be16s(f, &s->BasicModeCtrl);
- qemu_put_be16s(f, &s->BasicModeStatus);
- qemu_put_be16s(f, &s->NWayAdvert);
- qemu_put_be16s(f, &s->NWayLPAR);
- qemu_put_be16s(f, &s->NWayExpansion);
-
- qemu_put_be16s(f, &s->CpCmd);
- qemu_put_8s(f, &s->TxThresh);
-
- i = 0;
- qemu_put_be32s(f, &i); /* unused. */
- qemu_put_buffer(f, s->macaddr, 6);
- qemu_put_be32(f, s->rtl8139_mmio_io_addr);
-
- qemu_put_be32s(f, &s->currTxDesc);
- qemu_put_be32s(f, &s->currCPlusRxDesc);
- qemu_put_be32s(f, &s->currCPlusTxDesc);
- qemu_put_be32s(f, &s->RxRingAddrLO);
- qemu_put_be32s(f, &s->RxRingAddrHI);
-
- for (i=0; i<EEPROM_9346_SIZE; ++i)
- {
- qemu_put_be16s(f, &s->eeprom.contents[i]);
- }
- qemu_put_be32(f, s->eeprom.mode);
- qemu_put_be32s(f, &s->eeprom.tick);
- qemu_put_8s(f, &s->eeprom.address);
- qemu_put_be16s(f, &s->eeprom.input);
- qemu_put_be16s(f, &s->eeprom.output);
-
- qemu_put_8s(f, &s->eeprom.eecs);
- qemu_put_8s(f, &s->eeprom.eesk);
- qemu_put_8s(f, &s->eeprom.eedi);
- qemu_put_8s(f, &s->eeprom.eedo);
-
- qemu_put_be32s(f, &s->TCTR);
- qemu_put_be32s(f, &s->TimerInt);
- qemu_put_be64(f, s->TCTR_base);
-
- RTL8139TallyCounters_save(f, &s->tally_counters);
-
- qemu_put_be32s(f, &s->cplus_enabled);
-}
-
-static int rtl8139_load(QEMUFile* f,void* opaque,int version_id)
+static int rtl8139_post_load(void *opaque, int version_id)
{
RTL8139State* s = opaque;
- unsigned int i;
- int ret;
-
- /* just 2 versions for now */
- if (version_id > 4)
- return -EINVAL;
-
- if (version_id >= 3) {
- ret = pci_device_load(&s->dev, f);
- if (ret < 0)
- return ret;
- }
-
- /* saved since version 1 */
- qemu_get_buffer(f, s->phys, 6);
- qemu_get_buffer(f, s->mult, 8);
-
- for (i=0; i<4; ++i)
- {
- qemu_get_be32s(f, &s->TxStatus[i]); /* TxStatus0 */
- }
- for (i=0; i<4; ++i)
- {
- qemu_get_be32s(f, &s->TxAddr[i]); /* TxAddr0 */
- }
-
- qemu_get_be32s(f, &s->RxBuf); /* Receive buffer */
- qemu_get_be32s(f, &s->RxBufferSize);/* internal variable, receive ring buffer size in C mode */
- qemu_get_be32s(f, &s->RxBufPtr);
- qemu_get_be32s(f, &s->RxBufAddr);
-
- qemu_get_be16s(f, &s->IntrStatus);
- qemu_get_be16s(f, &s->IntrMask);
-
- qemu_get_be32s(f, &s->TxConfig);
- qemu_get_be32s(f, &s->RxConfig);
- qemu_get_be32s(f, &s->RxMissed);
- qemu_get_be16s(f, &s->CSCR);
-
- qemu_get_8s(f, &s->Cfg9346);
- qemu_get_8s(f, &s->Config0);
- qemu_get_8s(f, &s->Config1);
- qemu_get_8s(f, &s->Config3);
- qemu_get_8s(f, &s->Config4);
- qemu_get_8s(f, &s->Config5);
-
- qemu_get_8s(f, &s->clock_enabled);
- qemu_get_8s(f, &s->bChipCmdState);
-
- qemu_get_be16s(f, &s->MultiIntr);
-
- qemu_get_be16s(f, &s->BasicModeCtrl);
- qemu_get_be16s(f, &s->BasicModeStatus);
- qemu_get_be16s(f, &s->NWayAdvert);
- qemu_get_be16s(f, &s->NWayLPAR);
- qemu_get_be16s(f, &s->NWayExpansion);
-
- qemu_get_be16s(f, &s->CpCmd);
- qemu_get_8s(f, &s->TxThresh);
-
- qemu_get_be32s(f, &i); /* unused. */
- qemu_get_buffer(f, s->macaddr, 6);
- s->rtl8139_mmio_io_addr=qemu_get_be32(f);
-
- qemu_get_be32s(f, &s->currTxDesc);
- qemu_get_be32s(f, &s->currCPlusRxDesc);
- qemu_get_be32s(f, &s->currCPlusTxDesc);
- qemu_get_be32s(f, &s->RxRingAddrLO);
- qemu_get_be32s(f, &s->RxRingAddrHI);
-
- for (i=0; i<EEPROM_9346_SIZE; ++i)
- {
- qemu_get_be16s(f, &s->eeprom.contents[i]);
- }
- s->eeprom.mode=qemu_get_be32(f);
- qemu_get_be32s(f, &s->eeprom.tick);
- qemu_get_8s(f, &s->eeprom.address);
- qemu_get_be16s(f, &s->eeprom.input);
- qemu_get_be16s(f, &s->eeprom.output);
-
- qemu_get_8s(f, &s->eeprom.eecs);
- qemu_get_8s(f, &s->eeprom.eesk);
- qemu_get_8s(f, &s->eeprom.eedi);
- qemu_get_8s(f, &s->eeprom.eedo);
-
- /* saved since version 2 */
- if (version_id >= 2)
- {
- qemu_get_be32s(f, &s->TCTR);
- qemu_get_be32s(f, &s->TimerInt);
- s->TCTR_base=qemu_get_be64(f);
-
- RTL8139TallyCounters_load(f, &s->tally_counters);
- }
- else
- {
- /* not saved, use default */
- s->TCTR = 0;
- s->TimerInt = 0;
- s->TCTR_base = 0;
-
- RTL8139TallyCounters_clear(&s->tally_counters);
- }
-
- if (version_id >= 4) {
- qemu_get_be32s(f, &s->cplus_enabled);
- } else {
+ if (version_id < 4) {
s->cplus_enabled = s->CpCmd != 0;
}
return 0;
}
+static const VMStateDescription vmstate_rtl8139 = {
+ .name = "rtl8139",
+ .version_id = 4,
+ .minimum_version_id = 3,
+ .minimum_version_id_old = 3,
+ .post_load = rtl8139_post_load,
+ .fields = (VMStateField []) {
+ VMSTATE_PCI_DEVICE(dev, RTL8139State),
+ VMSTATE_PARTIAL_BUFFER(phys, RTL8139State, 6),
+ VMSTATE_BUFFER(mult, RTL8139State),
+ VMSTATE_UINT32_ARRAY(TxStatus, RTL8139State, 4),
+ VMSTATE_UINT32_ARRAY(TxAddr, RTL8139State, 4),
+
+ VMSTATE_UINT32(RxBuf, RTL8139State),
+ VMSTATE_UINT32(RxBufferSize, RTL8139State),
+ VMSTATE_UINT32(RxBufPtr, RTL8139State),
+ VMSTATE_UINT32(RxBufAddr, RTL8139State),
+
+ VMSTATE_UINT16(IntrStatus, RTL8139State),
+ VMSTATE_UINT16(IntrMask, RTL8139State),
+
+ VMSTATE_UINT32(TxConfig, RTL8139State),
+ VMSTATE_UINT32(RxConfig, RTL8139State),
+ VMSTATE_UINT32(RxMissed, RTL8139State),
+ VMSTATE_UINT16(CSCR, RTL8139State),
+
+ VMSTATE_UINT8(Cfg9346, RTL8139State),
+ VMSTATE_UINT8(Config0, RTL8139State),
+ VMSTATE_UINT8(Config1, RTL8139State),
+ VMSTATE_UINT8(Config3, RTL8139State),
+ VMSTATE_UINT8(Config4, RTL8139State),
+ VMSTATE_UINT8(Config5, RTL8139State),
+
+ VMSTATE_UINT8(clock_enabled, RTL8139State),
+ VMSTATE_UINT8(bChipCmdState, RTL8139State),
+
+ VMSTATE_UINT16(MultiIntr, RTL8139State),
+
+ VMSTATE_UINT16(BasicModeCtrl, RTL8139State),
+ VMSTATE_UINT16(BasicModeStatus, RTL8139State),
+ VMSTATE_UINT16(NWayAdvert, RTL8139State),
+ VMSTATE_UINT16(NWayLPAR, RTL8139State),
+ VMSTATE_UINT16(NWayExpansion, RTL8139State),
+
+ VMSTATE_UINT16(CpCmd, RTL8139State),
+ VMSTATE_UINT8(TxThresh, RTL8139State),
+
+ VMSTATE_UNUSED(4),
+ VMSTATE_BUFFER(macaddr, RTL8139State),
+ VMSTATE_INT32(rtl8139_mmio_io_addr, RTL8139State),
+
+ VMSTATE_UINT32(currTxDesc, RTL8139State),
+ VMSTATE_UINT32(currCPlusRxDesc, RTL8139State),
+ VMSTATE_UINT32(currCPlusTxDesc, RTL8139State),
+ VMSTATE_UINT32(RxRingAddrLO, RTL8139State),
+ VMSTATE_UINT32(RxRingAddrHI, RTL8139State),
+
+ VMSTATE_UINT16_ARRAY(eeprom.contents, RTL8139State, EEPROM_9346_SIZE),
+ VMSTATE_INT32(eeprom.mode, RTL8139State),
+ VMSTATE_UINT32(eeprom.tick, RTL8139State),
+ VMSTATE_UINT8(eeprom.address, RTL8139State),
+ VMSTATE_UINT16(eeprom.input, RTL8139State),
+ VMSTATE_UINT16(eeprom.output, RTL8139State),
+
+ VMSTATE_UINT8(eeprom.eecs, RTL8139State),
+ VMSTATE_UINT8(eeprom.eesk, RTL8139State),
+ VMSTATE_UINT8(eeprom.eedi, RTL8139State),
+ VMSTATE_UINT8(eeprom.eedo, RTL8139State),
+
+ VMSTATE_UINT32(TCTR, RTL8139State),
+ VMSTATE_UINT32(TimerInt, RTL8139State),
+ VMSTATE_INT64(TCTR_base, RTL8139State),
+
+ VMSTATE_STRUCT(tally_counters, RTL8139State, 0,
+ vmstate_tally_counters, RTL8139TallyCounters),
+
+ VMSTATE_UINT32_V(cplus_enabled, RTL8139State, 4),
+ VMSTATE_END_OF_LIST()
+ }
+};
+
/***********************************************************/
/* PCI RTL8139 definitions */
@@ -3424,7 +3293,7 @@ static void rtl8139_cleanup(VLANClientState *vc)
qemu_free_timer(s->timer);
#endif
- unregister_savevm("rtl8139", s);
+ vmstate_unregister(&vmstate_rtl8139, s);
}
static int pci_rtl8139_uninit(PCIDevice *dev)
@@ -3473,7 +3342,7 @@ static int pci_rtl8139_init(PCIDevice *dev)
s->cplus_txbuffer_len = 0;
s->cplus_txbuffer_offset = 0;
- register_savevm("rtl8139", -1, 4, rtl8139_save, rtl8139_load, s);
+ vmstate_register(-1, &vmstate_rtl8139, s);
#ifdef RTL8139_ONBOARD_TIMER
s->timer = qemu_new_timer(vm_clock, rtl8139_timer, s);
--
1.6.2.5
^ permalink raw reply related [flat|nested] 30+ messages in thread
* [Qemu-devel] [PATCH 19/25] eeprom93xx: port to vmstate
2009-10-19 18:42 [Qemu-devel] [PATCH 00/25] VMState cleanups and conversion of network drivers Juan Quintela
` (17 preceding siblings ...)
2009-10-19 18:43 ` [Qemu-devel] [PATCH 18/25] rtl8139: port " Juan Quintela
@ 2009-10-19 18:43 ` Juan Quintela
2009-10-19 18:43 ` [Qemu-devel] [PATCH 20/25] eepro100: " Juan Quintela
` (6 subsequent siblings)
25 siblings, 0 replies; 30+ messages in thread
From: Juan Quintela @ 2009-10-19 18:43 UTC (permalink / raw)
To: qemu-devel
Signed-off-by: Juan Quintela <quintela@redhat.com>
---
hw/eeprom93xx.c | 102 ++++++++++++++++++++++++++----------------------------
1 files changed, 49 insertions(+), 53 deletions(-)
diff --git a/hw/eeprom93xx.c b/hw/eeprom93xx.c
index 66dfc43..43244e7 100644
--- a/hw/eeprom93xx.c
+++ b/hw/eeprom93xx.c
@@ -89,66 +89,63 @@ struct _eeprom_t {
/* Code for saving and restoring of EEPROM state. */
-static void eeprom_save(QEMUFile *f, void *opaque)
+/* Restore an uint16_t from an uint8_t
+ This is a Big hack, but it is how the old state did it.
+ */
+
+static int get_uint16_from_uint8(QEMUFile *f, void *pv, size_t size)
{
- /* Save EEPROM data. */
- unsigned address;
- eeprom_t *eeprom = (eeprom_t *)opaque;
+ uint16_t *v = pv;
+ *v = qemu_get_ubyte(f);
+ return 0;
+}
- qemu_put_byte(f, eeprom->tick);
- qemu_put_byte(f, eeprom->address);
- qemu_put_byte(f, eeprom->command);
- qemu_put_byte(f, eeprom->writeable);
+static void put_unused(QEMUFile *f, void *pv, size_t size)
+{
+ fprintf(stderr, "uint16_from_uint8 is used only for backwards compatibility.\n");
+ fprintf(stderr, "Never should be used to write a new state.\n");
+ exit(0);
+}
- qemu_put_byte(f, eeprom->eecs);
- qemu_put_byte(f, eeprom->eesk);
- qemu_put_byte(f, eeprom->eedo);
+const VMStateInfo vmstate_hack_uint16_from_uint8 = {
+ .name = "uint16_from_uint8",
+ .get = get_uint16_from_uint8,
+ .put = put_unused,
+};
- qemu_put_byte(f, eeprom->addrbits);
- qemu_put_be16(f, eeprom->size);
- qemu_put_be16(f, eeprom->data);
- for (address = 0; address < eeprom->size; address++) {
- qemu_put_be16(f, eeprom->contents[address]);
- }
-}
+#define VMSTATE_UINT16_HACK_TEST(_f, _s, _t) \
+ VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_hack_uint16_from_uint8, uint16_t)
-static int eeprom_load(QEMUFile *f, void *opaque, int version_id)
+static bool is_old_eeprom_version(void *opaque, int version_id)
{
- /* Load EEPROM data from saved data if version and EEPROM size
- of data and current EEPROM are identical. */
- eeprom_t *eeprom = (eeprom_t *)opaque;
- int result = -EINVAL;
- if (version_id >= OLD_EEPROM_VERSION) {
- unsigned address;
- int size = eeprom->size;
-
- eeprom->tick = qemu_get_byte(f);
- eeprom->address = qemu_get_byte(f);
- eeprom->command = qemu_get_byte(f);
- eeprom->writeable = qemu_get_byte(f);
+ return version_id == OLD_EEPROM_VERSION;
+}
- eeprom->eecs = qemu_get_byte(f);
- eeprom->eesk = qemu_get_byte(f);
- eeprom->eedo = qemu_get_byte(f);
+static const VMStateDescription vmstate_eeprom = {
+ .name = "eeprom",
+ .version_id = EEPROM_VERSION,
+ .minimum_version_id = OLD_EEPROM_VERSION,
+ .minimum_version_id_old = OLD_EEPROM_VERSION,
+ .fields = (VMStateField []) {
+ VMSTATE_UINT8(tick, eeprom_t),
+ VMSTATE_UINT8(address, eeprom_t),
+ VMSTATE_UINT8(command, eeprom_t),
+ VMSTATE_UINT8(writeable, eeprom_t),
- eeprom->addrbits = qemu_get_byte(f);
- if (version_id == OLD_EEPROM_VERSION) {
- eeprom->size = qemu_get_byte(f);
- qemu_get_byte(f);
- } else {
- eeprom->size = qemu_get_be16(f);
- }
+ VMSTATE_UINT8(eecs, eeprom_t),
+ VMSTATE_UINT8(eesk, eeprom_t),
+ VMSTATE_UINT8(eedo, eeprom_t),
- if (eeprom->size == size) {
- eeprom->data = qemu_get_be16(f);
- for (address = 0; address < eeprom->size; address++) {
- eeprom->contents[address] = qemu_get_be16(f);
- }
- result = 0;
- }
+ VMSTATE_UINT8(addrbits, eeprom_t),
+ VMSTATE_UINT16_HACK_TEST(size, eeprom_t, is_old_eeprom_version),
+ VMSTATE_UNUSED_TEST(is_old_eeprom_version, 1),
+ VMSTATE_UINT16_EQUAL_V(size, eeprom_t, EEPROM_VERSION),
+ VMSTATE_UINT16(data, eeprom_t),
+ VMSTATE_VARRAY_UINT16_UNSAFE(contents, eeprom_t, size, 0,
+ vmstate_info_uint16, uint16_t),
+ VMSTATE_END_OF_LIST()
}
- return result;
-}
+};
void eeprom93xx_write(eeprom_t *eeprom, int eecs, int eesk, int eedi)
{
@@ -319,8 +316,7 @@ eeprom_t *eeprom93xx_new(uint16_t nwords)
/* Output DO is tristate, read results in 1. */
eeprom->eedo = 1;
logout("eeprom = 0x%p, nwords = %u\n", eeprom, nwords);
- register_savevm("eeprom", EEPROM_INSTANCE, EEPROM_VERSION,
- eeprom_save, eeprom_load, eeprom);
+ vmstate_register(0, &vmstate_eeprom, eeprom);
return eeprom;
}
@@ -328,7 +324,7 @@ void eeprom93xx_free(eeprom_t *eeprom)
{
/* Destroy EEPROM. */
logout("eeprom = 0x%p\n", eeprom);
- unregister_savevm("eeprom", eeprom);
+ vmstate_unregister(&vmstate_eeprom, eeprom);
qemu_free(eeprom);
}
--
1.6.2.5
^ permalink raw reply related [flat|nested] 30+ messages in thread
* [Qemu-devel] [PATCH 20/25] eepro100: port to vmstate
2009-10-19 18:42 [Qemu-devel] [PATCH 00/25] VMState cleanups and conversion of network drivers Juan Quintela
` (18 preceding siblings ...)
2009-10-19 18:43 ` [Qemu-devel] [PATCH 19/25] eeprom93xx: " Juan Quintela
@ 2009-10-19 18:43 ` Juan Quintela
2009-10-19 18:43 ` [Qemu-devel] [PATCH 21/25] pcnet: " Juan Quintela
` (5 subsequent siblings)
25 siblings, 0 replies; 30+ messages in thread
From: Juan Quintela @ 2009-10-19 18:43 UTC (permalink / raw)
To: qemu-devel
Signed-off-by: Juan Quintela <quintela@redhat.com>
---
hw/eepro100.c | 195 ++++++++++++++++++---------------------------------------
1 files changed, 60 insertions(+), 135 deletions(-)
diff --git a/hw/eepro100.c b/hw/eepro100.c
index 62207da..965de32 100644
--- a/hw/eepro100.c
+++ b/hw/eepro100.c
@@ -220,6 +220,8 @@ typedef struct {
/* Data in mem is always in the byte order of the controller (le). */
uint8_t mem[PCI_MEM_SIZE];
+ /* vmstate for each particular nic */
+ VMStateDescription *vmstate;
} EEPRO100State;
/* Default values for MDI (PHY) registers */
@@ -1591,147 +1593,68 @@ static ssize_t nic_receive(VLANClientState *vc, const uint8_t * buf, size_t size
return size;
}
-static int nic_load(QEMUFile * f, void *opaque, int version_id)
-{
- EEPRO100State *s = opaque;
- int i;
- int ret;
-
- if (version_id > 3)
- return -EINVAL;
-
- ret = pci_device_load(&s->dev, f);
- if (ret < 0) {
- return ret;
- }
-
- /* Skip unused entries. */
- qemu_fseek(f, 32, SEEK_CUR);
-
- qemu_get_buffer(f, s->mult, 8);
- qemu_get_buffer(f, s->mem, sizeof(s->mem));
-
- /* Restore all members of struct between scb_stat and mem. */
- qemu_get_8s(f, &s->scb_stat);
- qemu_get_8s(f, &s->int_stat);
- /* Skip unused entries. */
- qemu_fseek(f, 3 * 4, SEEK_CUR);
- qemu_get_buffer(f, s->macaddr, 6);
- /* Skip unused entries. */
- qemu_fseek(f, 19 * 4, SEEK_CUR);
- for (i = 0; i < 32; i++) {
- qemu_get_be16s(f, &s->mdimem[i]);
- }
- /* The eeprom should be saved and restored by its own routines. */
- qemu_get_be32s(f, &s->device);
- // TODO check device.
- qemu_get_be32s(f, &s->pointer);
- qemu_get_be32s(f, &s->cu_base);
- qemu_get_be32s(f, &s->cu_offset);
- qemu_get_be32s(f, &s->ru_base);
- qemu_get_be32s(f, &s->ru_offset);
- qemu_get_be32s(f, &s->statsaddr);
- /* Restore epro100_stats_t statistics. */
- qemu_get_be32s(f, &s->statistics.tx_good_frames);
- qemu_get_be32s(f, &s->statistics.tx_max_collisions);
- qemu_get_be32s(f, &s->statistics.tx_late_collisions);
- qemu_get_be32s(f, &s->statistics.tx_underruns);
- qemu_get_be32s(f, &s->statistics.tx_lost_crs);
- qemu_get_be32s(f, &s->statistics.tx_deferred);
- qemu_get_be32s(f, &s->statistics.tx_single_collisions);
- qemu_get_be32s(f, &s->statistics.tx_multiple_collisions);
- qemu_get_be32s(f, &s->statistics.tx_total_collisions);
- qemu_get_be32s(f, &s->statistics.rx_good_frames);
- qemu_get_be32s(f, &s->statistics.rx_crc_errors);
- qemu_get_be32s(f, &s->statistics.rx_alignment_errors);
- qemu_get_be32s(f, &s->statistics.rx_resource_errors);
- qemu_get_be32s(f, &s->statistics.rx_overrun_errors);
- qemu_get_be32s(f, &s->statistics.rx_cdt_errors);
- qemu_get_be32s(f, &s->statistics.rx_short_frame_errors);
- qemu_get_be32s(f, &s->statistics.fc_xmt_pause);
- qemu_get_be32s(f, &s->statistics.fc_rcv_pause);
- qemu_get_be32s(f, &s->statistics.fc_rcv_unsupported);
- qemu_get_be16s(f, &s->statistics.xmt_tco_frames);
- qemu_get_be16s(f, &s->statistics.rcv_tco_frames);
- qemu_get_be32s(f, &s->statistics.complete);
+static const VMStateDescription vmstate_eepro100 = {
+ .version_id = 3,
+ .minimum_version_id = 2,
+ .minimum_version_id_old = 2,
+ .fields = (VMStateField []) {
+ VMSTATE_PCI_DEVICE(dev, EEPRO100State),
+ VMSTATE_UNUSED(32),
+ VMSTATE_BUFFER(mult, EEPRO100State),
+ VMSTATE_BUFFER(mem, EEPRO100State),
+ /* Save all members of struct between scb_stat and mem. */
+ VMSTATE_UINT8(scb_stat, EEPRO100State),
+ VMSTATE_UINT8(int_stat, EEPRO100State),
+ VMSTATE_UNUSED(3*4),
+ VMSTATE_BUFFER(macaddr, EEPRO100State),
+ VMSTATE_UNUSED(19*4),
+ VMSTATE_UINT16_ARRAY(mdimem, EEPRO100State, 32),
+ /* The eeprom should be saved and restored by its own routines. */
+ VMSTATE_UINT32(device, EEPRO100State),
+ /* TODO check device. */
+ VMSTATE_UINT32(pointer, EEPRO100State),
+ VMSTATE_UINT32(cu_base, EEPRO100State),
+ VMSTATE_UINT32(cu_offset, EEPRO100State),
+ VMSTATE_UINT32(ru_base, EEPRO100State),
+ VMSTATE_UINT32(ru_offset, EEPRO100State),
+ VMSTATE_UINT32(statsaddr, EEPRO100State),
+ /* Save epro100_stats_t statistics. */
+ VMSTATE_UINT32(statistics.tx_good_frames, EEPRO100State),
+ VMSTATE_UINT32(statistics.tx_max_collisions, EEPRO100State),
+ VMSTATE_UINT32(statistics.tx_late_collisions, EEPRO100State),
+ VMSTATE_UINT32(statistics.tx_underruns, EEPRO100State),
+ VMSTATE_UINT32(statistics.tx_lost_crs, EEPRO100State),
+ VMSTATE_UINT32(statistics.tx_deferred, EEPRO100State),
+ VMSTATE_UINT32(statistics.tx_single_collisions, EEPRO100State),
+ VMSTATE_UINT32(statistics.tx_multiple_collisions, EEPRO100State),
+ VMSTATE_UINT32(statistics.tx_total_collisions, EEPRO100State),
+ VMSTATE_UINT32(statistics.rx_good_frames, EEPRO100State),
+ VMSTATE_UINT32(statistics.rx_crc_errors, EEPRO100State),
+ VMSTATE_UINT32(statistics.rx_alignment_errors, EEPRO100State),
+ VMSTATE_UINT32(statistics.rx_resource_errors, EEPRO100State),
+ VMSTATE_UINT32(statistics.rx_overrun_errors, EEPRO100State),
+ VMSTATE_UINT32(statistics.rx_cdt_errors, EEPRO100State),
+ VMSTATE_UINT32(statistics.rx_short_frame_errors, EEPRO100State),
+ VMSTATE_UINT32(statistics.fc_xmt_pause, EEPRO100State),
+ VMSTATE_UINT32(statistics.fc_rcv_pause, EEPRO100State),
+ VMSTATE_UINT32(statistics.fc_rcv_unsupported, EEPRO100State),
+ VMSTATE_UINT16(statistics.xmt_tco_frames, EEPRO100State),
+ VMSTATE_UINT16(statistics.rcv_tco_frames, EEPRO100State),
+ VMSTATE_UINT32(statistics.complete, EEPRO100State),
#if 0
- qemu_get_be16s(f, &s->status);
+ VMSTATE_UINT16(status, EEPRO100State),
#endif
-
- /* Configuration bytes. */
- qemu_get_buffer(f, s->configuration, sizeof(s->configuration));
-
- return 0;
-}
-
-static void nic_save(QEMUFile * f, void *opaque)
-{
- EEPRO100State *s = opaque;
- int i;
-
- pci_device_save(&s->dev, f);
-
- /* Skip unused entries. */
- qemu_fseek(f, 32, SEEK_CUR);
-
- qemu_put_buffer(f, s->mult, 8);
- qemu_put_buffer(f, s->mem, sizeof(s->mem));
-
- /* Save all members of struct between scb_stat and mem. */
- qemu_put_8s(f, &s->scb_stat);
- qemu_put_8s(f, &s->int_stat);
- /* Skip unused entries. */
- qemu_fseek(f, 3 * 4, SEEK_CUR);
- qemu_put_buffer(f, s->macaddr, 6);
- /* Skip unused entries. */
- qemu_fseek(f, 19 * 4, SEEK_CUR);
- for (i = 0; i < 32; i++) {
- qemu_put_be16s(f, &s->mdimem[i]);
+ /* Configuration bytes. */
+ VMSTATE_BUFFER(configuration, EEPRO100State),
+ VMSTATE_END_OF_LIST()
}
- /* The eeprom should be saved and restored by its own routines. */
- qemu_put_be32s(f, &s->device);
- qemu_put_be32s(f, &s->pointer);
- qemu_put_be32s(f, &s->cu_base);
- qemu_put_be32s(f, &s->cu_offset);
- qemu_put_be32s(f, &s->ru_base);
- qemu_put_be32s(f, &s->ru_offset);
- qemu_put_be32s(f, &s->statsaddr);
- /* Save epro100_stats_t statistics. */
- qemu_put_be32s(f, &s->statistics.tx_good_frames);
- qemu_put_be32s(f, &s->statistics.tx_max_collisions);
- qemu_put_be32s(f, &s->statistics.tx_late_collisions);
- qemu_put_be32s(f, &s->statistics.tx_underruns);
- qemu_put_be32s(f, &s->statistics.tx_lost_crs);
- qemu_put_be32s(f, &s->statistics.tx_deferred);
- qemu_put_be32s(f, &s->statistics.tx_single_collisions);
- qemu_put_be32s(f, &s->statistics.tx_multiple_collisions);
- qemu_put_be32s(f, &s->statistics.tx_total_collisions);
- qemu_put_be32s(f, &s->statistics.rx_good_frames);
- qemu_put_be32s(f, &s->statistics.rx_crc_errors);
- qemu_put_be32s(f, &s->statistics.rx_alignment_errors);
- qemu_put_be32s(f, &s->statistics.rx_resource_errors);
- qemu_put_be32s(f, &s->statistics.rx_overrun_errors);
- qemu_put_be32s(f, &s->statistics.rx_cdt_errors);
- qemu_put_be32s(f, &s->statistics.rx_short_frame_errors);
- qemu_put_be32s(f, &s->statistics.fc_xmt_pause);
- qemu_put_be32s(f, &s->statistics.fc_rcv_pause);
- qemu_put_be32s(f, &s->statistics.fc_rcv_unsupported);
- qemu_put_be16s(f, &s->statistics.xmt_tco_frames);
- qemu_put_be16s(f, &s->statistics.rcv_tco_frames);
- qemu_put_be32s(f, &s->statistics.complete);
-#if 0
- qemu_put_be16s(f, &s->status);
-#endif
-
- /* Configuration bytes. */
- qemu_put_buffer(f, s->configuration, sizeof(s->configuration));
-}
+};
static void nic_cleanup(VLANClientState *vc)
{
EEPRO100State *s = vc->opaque;
- unregister_savevm(vc->model, s);
+ vmstate_unregister(s->vmstate, s);
eeprom93xx_free(s->eeprom);
}
@@ -1748,7 +1671,6 @@ static int pci_nic_uninit(PCIDevice *pci_dev)
static int nic_init(PCIDevice *pci_dev, uint32_t device)
{
EEPRO100State *s = DO_UPCAST(EEPRO100State, dev, pci_dev);
-
TRACE(OTHER, logout("\n"));
s->device = device;
@@ -1786,7 +1708,10 @@ static int nic_init(PCIDevice *pci_dev, uint32_t device)
qemu_register_reset(nic_reset, s);
- register_savevm(s->vc->model, -1, 3, nic_save, nic_load, s);
+ s->vmstate = qemu_malloc(sizeof(vmstate_eepro100));
+ memcpy(s->vmstate, &vmstate_eepro100, sizeof(vmstate_eepro100));
+ s->vmstate->name = s->vc->model;
+ vmstate_register(-1, s->vmstate, s);
return 0;
}
--
1.6.2.5
^ permalink raw reply related [flat|nested] 30+ messages in thread
* [Qemu-devel] [PATCH 21/25] pcnet: port to vmstate
2009-10-19 18:42 [Qemu-devel] [PATCH 00/25] VMState cleanups and conversion of network drivers Juan Quintela
` (19 preceding siblings ...)
2009-10-19 18:43 ` [Qemu-devel] [PATCH 20/25] eepro100: " Juan Quintela
@ 2009-10-19 18:43 ` Juan Quintela
2009-10-19 18:43 ` [Qemu-devel] [PATCH 22/25] ne2000: " Juan Quintela
` (4 subsequent siblings)
25 siblings, 0 replies; 30+ messages in thread
From: Juan Quintela @ 2009-10-19 18:43 UTC (permalink / raw)
To: qemu-devel
Signed-off-by: Juan Quintela <quintela@redhat.com>
---
hw/pcnet.c | 110 +++++++++++++++++++++--------------------------------------
1 files changed, 39 insertions(+), 71 deletions(-)
diff --git a/hw/pcnet.c b/hw/pcnet.c
index fecbff7..bd69735 100644
--- a/hw/pcnet.c
+++ b/hw/pcnet.c
@@ -1878,83 +1878,49 @@ static uint32_t pcnet_mmio_readl(void *opaque, target_phys_addr_t addr)
return val;
}
-
-static void pcnet_save(QEMUFile *f, void *opaque)
+static bool is_version_2(void *opaque, int version_id)
{
- PCNetState *s = opaque;
- unsigned int i;
-
- qemu_put_sbe32(f, s->rap);
- qemu_put_sbe32(f, s->isr);
- qemu_put_sbe32(f, s->lnkst);
- qemu_put_be32s(f, &s->rdra);
- qemu_put_be32s(f, &s->tdra);
- qemu_put_buffer(f, s->prom, 16);
- for (i = 0; i < 128; i++)
- qemu_put_be16s(f, &s->csr[i]);
- for (i = 0; i < 32; i++)
- qemu_put_be16s(f, &s->bcr[i]);
- qemu_put_be64s(f, &s->timer);
- qemu_put_sbe32(f, s->xmit_pos);
- qemu_put_buffer(f, s->buffer, 4096);
- qemu_put_sbe32(f, s->tx_busy);
- qemu_put_timer(f, s->poll_timer);
+ return version_id == 2;
}
-static int pcnet_load(QEMUFile *f, void *opaque, int version_id)
-{
- PCNetState *s = opaque;
- int i, dummy;
-
- if (version_id < 2 || version_id > 3)
- return -EINVAL;
-
- qemu_get_sbe32s(f, &s->rap);
- qemu_get_sbe32s(f, &s->isr);
- qemu_get_sbe32s(f, &s->lnkst);
- qemu_get_be32s(f, &s->rdra);
- qemu_get_be32s(f, &s->tdra);
- qemu_get_buffer(f, s->prom, 16);
- for (i = 0; i < 128; i++)
- qemu_get_be16s(f, &s->csr[i]);
- for (i = 0; i < 32; i++)
- qemu_get_be16s(f, &s->bcr[i]);
- qemu_get_be64s(f, &s->timer);
- qemu_get_sbe32s(f, &s->xmit_pos);
- if (version_id == 2) {
- qemu_get_sbe32s(f, &dummy);
+static const VMStateDescription vmstate_pcnet = {
+ .name = "pcnet",
+ .version_id = 3,
+ .minimum_version_id = 2,
+ .minimum_version_id_old = 2,
+ .fields = (VMStateField []) {
+ VMSTATE_INT32(rap, PCNetState),
+ VMSTATE_INT32(isr, PCNetState),
+ VMSTATE_INT32(lnkst, PCNetState),
+ VMSTATE_UINT32(rdra, PCNetState),
+ VMSTATE_UINT32(tdra, PCNetState),
+ VMSTATE_BUFFER(prom, PCNetState),
+ VMSTATE_UINT16_ARRAY(csr, PCNetState, 128),
+ VMSTATE_UINT16_ARRAY(bcr, PCNetState, 32),
+ VMSTATE_UINT64(timer, PCNetState),
+ VMSTATE_INT32(xmit_pos, PCNetState),
+ VMSTATE_BUFFER(buffer, PCNetState),
+ VMSTATE_UNUSED_TEST(is_version_2, 4),
+ VMSTATE_INT32(tx_busy, PCNetState),
+ VMSTATE_TIMER(poll_timer, PCNetState),
+ VMSTATE_END_OF_LIST()
}
- qemu_get_buffer(f, s->buffer, 4096);
- qemu_get_sbe32s(f, &s->tx_busy);
- qemu_get_timer(f, s->poll_timer);
-
- return 0;
-}
-
-static void pci_pcnet_save(QEMUFile *f, void *opaque)
-{
- PCIPCNetState *s = opaque;
-
- pci_device_save(&s->pci_dev, f);
- pcnet_save(f, &s->state);
-}
-
-static int pci_pcnet_load(QEMUFile *f, void *opaque, int version_id)
-{
- PCIPCNetState *s = opaque;
- int ret;
-
- ret = pci_device_load(&s->pci_dev, f);
- if (ret < 0)
- return ret;
+};
- return pcnet_load(f, &s->state, version_id);
-}
+static const VMStateDescription vmstate_pci_pcnet = {
+ .name = "pcnet",
+ .version_id = 3,
+ .minimum_version_id = 2,
+ .minimum_version_id_old = 2,
+ .fields = (VMStateField []) {
+ VMSTATE_PCI_DEVICE(pci_dev, PCIPCNetState),
+ VMSTATE_STRUCT(state, PCIPCNetState, 0, vmstate_pcnet, PCNetState),
+ VMSTATE_END_OF_LIST()
+ }
+};
static void pcnet_common_cleanup(PCNetState *d)
{
- unregister_savevm("pcnet", d);
-
qemu_del_timer(d->poll_timer);
qemu_free_timer(d->poll_timer);
}
@@ -2015,6 +1981,7 @@ static void pci_pcnet_cleanup(VLANClientState *vc)
{
PCNetState *d = vc->opaque;
+ vmstate_unregister(&vmstate_pci_pcnet, d);
pcnet_common_cleanup(d);
}
@@ -2070,7 +2037,7 @@ static int pci_pcnet_init(PCIDevice *pci_dev)
s->phys_mem_read = pci_physical_memory_read;
s->phys_mem_write = pci_physical_memory_write;
- register_savevm("pcnet", -1, 3, pci_pcnet_save, pci_pcnet_load, d);
+ vmstate_register(-1, &vmstate_pci_pcnet, d);
return pcnet_common_init(&pci_dev->qdev, s, pci_pcnet_cleanup);
}
@@ -2127,6 +2094,7 @@ static void lance_cleanup(VLANClientState *vc)
{
PCNetState *d = vc->opaque;
+ vmstate_unregister(&vmstate_pcnet, d);
pcnet_common_cleanup(d);
}
@@ -2147,7 +2115,7 @@ static int lance_init(SysBusDevice *dev)
s->phys_mem_read = ledma_memory_read;
s->phys_mem_write = ledma_memory_write;
- register_savevm("pcnet", -1, 3, pcnet_save, pcnet_load, s);
+ vmstate_register(-1, &vmstate_pcnet, d);
return pcnet_common_init(&dev->qdev, s, lance_cleanup);
}
--
1.6.2.5
^ permalink raw reply related [flat|nested] 30+ messages in thread
* [Qemu-devel] [PATCH 22/25] ne2000: port to vmstate
2009-10-19 18:42 [Qemu-devel] [PATCH 00/25] VMState cleanups and conversion of network drivers Juan Quintela
` (20 preceding siblings ...)
2009-10-19 18:43 ` [Qemu-devel] [PATCH 21/25] pcnet: " Juan Quintela
@ 2009-10-19 18:43 ` Juan Quintela
2009-10-19 18:43 ` [Qemu-devel] [PATCH 23/25] e1000: unfold mac_reg_tosave array Juan Quintela
` (3 subsequent siblings)
25 siblings, 0 replies; 30+ messages in thread
From: Juan Quintela @ 2009-10-19 18:43 UTC (permalink / raw)
To: qemu-devel
Signed-off-by: Juan Quintela <quintela@redhat.com>
---
hw/ne2000-isa.c | 4 +-
hw/ne2000.c | 133 ++++++++++++++++++++-----------------------------------
hw/ne2000.h | 3 +-
3 files changed, 51 insertions(+), 89 deletions(-)
diff --git a/hw/ne2000-isa.c b/hw/ne2000-isa.c
index e346731..0948b82 100644
--- a/hw/ne2000-isa.c
+++ b/hw/ne2000-isa.c
@@ -40,7 +40,7 @@ static void isa_ne2000_cleanup(VLANClientState *vc)
NE2000State *s = vc->opaque;
ISANE2000State *isa = container_of(s, ISANE2000State, ne2000);
- unregister_savevm("ne2000", s);
+ vmstate_unregister(&vmstate_ne2000, s);
isa_unassign_ioport(isa->iobase, 16);
isa_unassign_ioport(isa->iobase + 0x10, 2);
@@ -73,7 +73,7 @@ static int isa_ne2000_initfn(ISADevice *dev)
isa_ne2000_cleanup, s);
qemu_format_nic_info_str(s->vc, s->macaddr);
- register_savevm("ne2000", -1, 2, ne2000_save, ne2000_load, s);
+ vmstate_register(-1, &vmstate_ne2000, s);
return 0;
}
diff --git a/hw/ne2000.c b/hw/ne2000.c
index 87f1e59..88a81fb 100644
--- a/hw/ne2000.c
+++ b/hw/ne2000.c
@@ -622,94 +622,57 @@ uint32_t ne2000_reset_ioport_read(void *opaque, uint32_t addr)
return 0;
}
-void ne2000_save(QEMUFile* f, void* opaque)
+static int ne2000_post_load(void* opaque, int version_id)
{
- NE2000State* s = opaque;
- uint32_t tmp;
-
- qemu_put_8s(f, &s->rxcr);
-
- qemu_put_8s(f, &s->cmd);
- qemu_put_be32s(f, &s->start);
- qemu_put_be32s(f, &s->stop);
- qemu_put_8s(f, &s->boundary);
- qemu_put_8s(f, &s->tsr);
- qemu_put_8s(f, &s->tpsr);
- qemu_put_be16s(f, &s->tcnt);
- qemu_put_be16s(f, &s->rcnt);
- qemu_put_be32s(f, &s->rsar);
- qemu_put_8s(f, &s->rsr);
- qemu_put_8s(f, &s->isr);
- qemu_put_8s(f, &s->dcfg);
- qemu_put_8s(f, &s->imr);
- qemu_put_buffer(f, s->phys, 6);
- qemu_put_8s(f, &s->curpag);
- qemu_put_buffer(f, s->mult, 8);
- tmp = 0;
- qemu_put_be32s(f, &tmp); /* ignored, was irq */
- qemu_put_buffer(f, s->mem, NE2000_MEM_SIZE);
-}
-
-int ne2000_load(QEMUFile* f, void* opaque, int version_id)
-{
- NE2000State* s = opaque;
- uint32_t tmp;
-
- if (version_id > 3)
- return -EINVAL;
-
- if (version_id >= 2) {
- qemu_get_8s(f, &s->rxcr);
- } else {
- s->rxcr = 0x0c;
- }
-
- qemu_get_8s(f, &s->cmd);
- qemu_get_be32s(f, &s->start);
- qemu_get_be32s(f, &s->stop);
- qemu_get_8s(f, &s->boundary);
- qemu_get_8s(f, &s->tsr);
- qemu_get_8s(f, &s->tpsr);
- qemu_get_be16s(f, &s->tcnt);
- qemu_get_be16s(f, &s->rcnt);
- qemu_get_be32s(f, &s->rsar);
- qemu_get_8s(f, &s->rsr);
- qemu_get_8s(f, &s->isr);
- qemu_get_8s(f, &s->dcfg);
- qemu_get_8s(f, &s->imr);
- qemu_get_buffer(f, s->phys, 6);
- qemu_get_8s(f, &s->curpag);
- qemu_get_buffer(f, s->mult, 8);
- qemu_get_be32s(f, &tmp); /* ignored */
- qemu_get_buffer(f, s->mem, NE2000_MEM_SIZE);
-
- return 0;
-}
-
-static void pci_ne2000_save(QEMUFile* f, void* opaque)
-{
- PCINE2000State* s = opaque;
+ NE2000State* s = opaque;
- pci_device_save(&s->dev, f);
- ne2000_save(f, &s->ne2000);
+ if (version_id < 2) {
+ s->rxcr = 0x0c;
+ }
+ return 0;
}
-static int pci_ne2000_load(QEMUFile* f, void* opaque, int version_id)
-{
- PCINE2000State* s = opaque;
- int ret;
-
- if (version_id > 3)
- return -EINVAL;
-
- if (version_id >= 3) {
- ret = pci_device_load(&s->dev, f);
- if (ret < 0)
- return ret;
- }
+const VMStateDescription vmstate_ne2000 = {
+ .name = "ne2000",
+ .version_id = 2,
+ .minimum_version_id = 0,
+ .minimum_version_id_old = 0,
+ .post_load = ne2000_post_load,
+ .fields = (VMStateField []) {
+ VMSTATE_UINT8_V(rxcr, NE2000State, 2),
+ VMSTATE_UINT8(cmd, NE2000State),
+ VMSTATE_UINT32(start, NE2000State),
+ VMSTATE_UINT32(stop, NE2000State),
+ VMSTATE_UINT8(boundary, NE2000State),
+ VMSTATE_UINT8(tsr, NE2000State),
+ VMSTATE_UINT8(tpsr, NE2000State),
+ VMSTATE_UINT16(tcnt, NE2000State),
+ VMSTATE_UINT16(rcnt, NE2000State),
+ VMSTATE_UINT32(rsar, NE2000State),
+ VMSTATE_UINT8(rsr, NE2000State),
+ VMSTATE_UINT8(isr, NE2000State),
+ VMSTATE_UINT8(dcfg, NE2000State),
+ VMSTATE_UINT8(imr, NE2000State),
+ VMSTATE_BUFFER(phys, NE2000State),
+ VMSTATE_UINT8(curpag, NE2000State),
+ VMSTATE_BUFFER(mult, NE2000State),
+ VMSTATE_UNUSED(4), /* was irq */
+ VMSTATE_BUFFER(mem, NE2000State),
+ VMSTATE_END_OF_LIST()
+ }
+};
- return ne2000_load(f, &s->ne2000, version_id);
-}
+const VMStateDescription vmstate_pci_ne2000 = {
+ .name = "ne2000",
+ .version_id = 3,
+ .minimum_version_id = 3,
+ .minimum_version_id_old = 3,
+ .fields = (VMStateField []) {
+ VMSTATE_PCI_DEVICE(dev, PCINE2000State),
+ VMSTATE_STRUCT(ne2000, PCINE2000State, 0, vmstate_ne2000, NE2000State),
+ VMSTATE_END_OF_LIST()
+ }
+};
/***********************************************************/
/* PCI NE2000 definitions */
@@ -738,7 +701,7 @@ static void ne2000_cleanup(VLANClientState *vc)
{
NE2000State *s = vc->opaque;
- unregister_savevm("ne2000", s);
+ vmstate_unregister(&vmstate_pci_ne2000, s);
}
static int pci_ne2000_init(PCIDevice *pci_dev)
@@ -766,7 +729,7 @@ static int pci_ne2000_init(PCIDevice *pci_dev)
qemu_format_nic_info_str(s->vc, s->macaddr);
- register_savevm("ne2000", -1, 3, pci_ne2000_save, pci_ne2000_load, d);
+ vmstate_register(-1, &vmstate_pci_ne2000, d);
return 0;
}
diff --git a/hw/ne2000.h b/hw/ne2000.h
index 92a2ddb..9bd5cab 100644
--- a/hw/ne2000.h
+++ b/hw/ne2000.h
@@ -33,8 +33,7 @@ void ne2000_asic_ioport_write(void *opaque, uint32_t addr, uint32_t val);
uint32_t ne2000_asic_ioport_read(void *opaque, uint32_t addr);
void ne2000_reset_ioport_write(void *opaque, uint32_t addr, uint32_t val);
uint32_t ne2000_reset_ioport_read(void *opaque, uint32_t addr);
-void ne2000_save(QEMUFile* f, void* opaque);
-int ne2000_load(QEMUFile* f, void* opaque, int version_id);
+extern const VMStateDescription vmstate_ne2000;
void ne2000_reset(NE2000State *s);
int ne2000_can_receive(VLANClientState *vc);
ssize_t ne2000_receive(VLANClientState *vc, const uint8_t *buf, size_t size_);
--
1.6.2.5
^ permalink raw reply related [flat|nested] 30+ messages in thread
* [Qemu-devel] [PATCH 23/25] e1000: unfold mac_reg_tosave array
2009-10-19 18:42 [Qemu-devel] [PATCH 00/25] VMState cleanups and conversion of network drivers Juan Quintela
` (21 preceding siblings ...)
2009-10-19 18:43 ` [Qemu-devel] [PATCH 22/25] ne2000: " Juan Quintela
@ 2009-10-19 18:43 ` Juan Quintela
2009-10-19 18:43 ` [Qemu-devel] [PATCH 24/25] e1000: unfold mac_regarraystosave array Juan Quintela
` (2 subsequent siblings)
25 siblings, 0 replies; 30+ messages in thread
From: Juan Quintela @ 2009-10-19 18:43 UTC (permalink / raw)
To: qemu-devel
Signed-off-by: Juan Quintela <quintela@redhat.com>
---
hw/e1000.c | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++---------
1 files changed, 74 insertions(+), 13 deletions(-)
diff --git a/hw/e1000.c b/hw/e1000.c
index f123bda..0d40fbe 100644
--- a/hw/e1000.c
+++ b/hw/e1000.c
@@ -879,15 +879,6 @@ e1000_mmio_readw(void *opaque, target_phys_addr_t addr)
(8 * (addr & 3))) & 0xffff;
}
-static const int mac_regtosave[] = {
- CTRL, EECD, EERD, GPRC, GPTC, ICR, ICS, IMC, IMS,
- LEDCTL, MANC, MDIC, MPC, PBA, RCTL, RDBAH, RDBAL, RDH,
- RDLEN, RDT, STATUS, SWSM, TCTL, TDBAH, TDBAL, TDH, TDLEN,
- TDT, TORH, TORL, TOTH, TOTL, TPR, TPT, TXDCTL, WUFC,
- VET,
-};
-enum { MAC_NSAVE = ARRAY_SIZE(mac_regtosave) };
-
static const struct {
int size;
int array0;
@@ -929,8 +920,43 @@ nic_save(QEMUFile *f, void *opaque)
qemu_put_be16s(f, s->eeprom_data + i);
for (i = 0; i < 0x20; i++)
qemu_put_be16s(f, s->phy_reg + i);
- for (i = 0; i < MAC_NSAVE; i++)
- qemu_put_be32s(f, s->mac_reg + mac_regtosave[i]);
+ qemu_put_be32s(f, &s->mac_reg[CTRL]);
+ qemu_put_be32s(f, &s->mac_reg[EECD]);
+ qemu_put_be32s(f, &s->mac_reg[EERD]);
+ qemu_put_be32s(f, &s->mac_reg[GPRC]);
+ qemu_put_be32s(f, &s->mac_reg[GPTC]);
+ qemu_put_be32s(f, &s->mac_reg[ICR]);
+ qemu_put_be32s(f, &s->mac_reg[ICS]);
+ qemu_put_be32s(f, &s->mac_reg[IMC]);
+ qemu_put_be32s(f, &s->mac_reg[IMS]);
+ qemu_put_be32s(f, &s->mac_reg[LEDCTL]);
+ qemu_put_be32s(f, &s->mac_reg[MANC]);
+ qemu_put_be32s(f, &s->mac_reg[MDIC]);
+ qemu_put_be32s(f, &s->mac_reg[MPC]);
+ qemu_put_be32s(f, &s->mac_reg[PBA]);
+ qemu_put_be32s(f, &s->mac_reg[RCTL]);
+ qemu_put_be32s(f, &s->mac_reg[RDBAH]);
+ qemu_put_be32s(f, &s->mac_reg[RDBAL]);
+ qemu_put_be32s(f, &s->mac_reg[RDH]);
+ qemu_put_be32s(f, &s->mac_reg[RDLEN]);
+ qemu_put_be32s(f, &s->mac_reg[RDT]);
+ qemu_put_be32s(f, &s->mac_reg[STATUS]);
+ qemu_put_be32s(f, &s->mac_reg[SWSM]);
+ qemu_put_be32s(f, &s->mac_reg[TCTL]);
+ qemu_put_be32s(f, &s->mac_reg[TDBAH]);
+ qemu_put_be32s(f, &s->mac_reg[TDBAL]);
+ qemu_put_be32s(f, &s->mac_reg[TDH]);
+ qemu_put_be32s(f, &s->mac_reg[TDLEN]);
+ qemu_put_be32s(f, &s->mac_reg[TDT]);
+ qemu_put_be32s(f, &s->mac_reg[TORH]);
+ qemu_put_be32s(f, &s->mac_reg[TORL]);
+ qemu_put_be32s(f, &s->mac_reg[TOTH]);
+ qemu_put_be32s(f, &s->mac_reg[TOTL]);
+ qemu_put_be32s(f, &s->mac_reg[TPR]);
+ qemu_put_be32s(f, &s->mac_reg[TPT]);
+ qemu_put_be32s(f, &s->mac_reg[TXDCTL]);
+ qemu_put_be32s(f, &s->mac_reg[WUFC]);
+ qemu_put_be32s(f, &s->mac_reg[VET]);
for (i = 0; i < MAC_NARRAYS; i++)
for (j = 0; j < mac_regarraystosave[i].size; j++)
qemu_put_be32s(f,
@@ -975,8 +1001,43 @@ nic_load(QEMUFile *f, void *opaque, int version_id)
qemu_get_be16s(f, s->eeprom_data + i);
for (i = 0; i < 0x20; i++)
qemu_get_be16s(f, s->phy_reg + i);
- for (i = 0; i < MAC_NSAVE; i++)
- qemu_get_be32s(f, s->mac_reg + mac_regtosave[i]);
+ qemu_get_be32s(f, &s->mac_reg[CTRL]);
+ qemu_get_be32s(f, &s->mac_reg[EECD]);
+ qemu_get_be32s(f, &s->mac_reg[EERD]);
+ qemu_get_be32s(f, &s->mac_reg[GPRC]);
+ qemu_get_be32s(f, &s->mac_reg[GPTC]);
+ qemu_get_be32s(f, &s->mac_reg[ICR]);
+ qemu_get_be32s(f, &s->mac_reg[ICS]);
+ qemu_get_be32s(f, &s->mac_reg[IMC]);
+ qemu_get_be32s(f, &s->mac_reg[IMS]);
+ qemu_get_be32s(f, &s->mac_reg[LEDCTL]);
+ qemu_get_be32s(f, &s->mac_reg[MANC]);
+ qemu_get_be32s(f, &s->mac_reg[MDIC]);
+ qemu_get_be32s(f, &s->mac_reg[MPC]);
+ qemu_get_be32s(f, &s->mac_reg[PBA]);
+ qemu_get_be32s(f, &s->mac_reg[RCTL]);
+ qemu_get_be32s(f, &s->mac_reg[RDBAH]);
+ qemu_get_be32s(f, &s->mac_reg[RDBAL]);
+ qemu_get_be32s(f, &s->mac_reg[RDH]);
+ qemu_get_be32s(f, &s->mac_reg[RDLEN]);
+ qemu_get_be32s(f, &s->mac_reg[RDT]);
+ qemu_get_be32s(f, &s->mac_reg[STATUS]);
+ qemu_get_be32s(f, &s->mac_reg[SWSM]);
+ qemu_get_be32s(f, &s->mac_reg[TCTL]);
+ qemu_get_be32s(f, &s->mac_reg[TDBAH]);
+ qemu_get_be32s(f, &s->mac_reg[TDBAL]);
+ qemu_get_be32s(f, &s->mac_reg[TDH]);
+ qemu_get_be32s(f, &s->mac_reg[TDLEN]);
+ qemu_get_be32s(f, &s->mac_reg[TDT]);
+ qemu_get_be32s(f, &s->mac_reg[TORH]);
+ qemu_get_be32s(f, &s->mac_reg[TORL]);
+ qemu_get_be32s(f, &s->mac_reg[TOTH]);
+ qemu_get_be32s(f, &s->mac_reg[TOTL]);
+ qemu_get_be32s(f, &s->mac_reg[TPR]);
+ qemu_get_be32s(f, &s->mac_reg[TPT]);
+ qemu_get_be32s(f, &s->mac_reg[TXDCTL]);
+ qemu_get_be32s(f, &s->mac_reg[WUFC]);
+ qemu_get_be32s(f, &s->mac_reg[VET]);
for (i = 0; i < MAC_NARRAYS; i++)
for (j = 0; j < mac_regarraystosave[i].size; j++)
qemu_get_be32s(f,
--
1.6.2.5
^ permalink raw reply related [flat|nested] 30+ messages in thread
* [Qemu-devel] [PATCH 24/25] e1000: unfold mac_regarraystosave array
2009-10-19 18:42 [Qemu-devel] [PATCH 00/25] VMState cleanups and conversion of network drivers Juan Quintela
` (22 preceding siblings ...)
2009-10-19 18:43 ` [Qemu-devel] [PATCH 23/25] e1000: unfold mac_reg_tosave array Juan Quintela
@ 2009-10-19 18:43 ` Juan Quintela
2009-10-19 18:43 ` [Qemu-devel] [PATCH 25/25] e1000: port to vmstate Juan Quintela
2009-10-19 19:15 ` [Qemu-devel] [PATCH 00/25] VMState cleanups and conversion of network drivers Jamie Lokier
25 siblings, 0 replies; 30+ messages in thread
From: Juan Quintela @ 2009-10-19 18:43 UTC (permalink / raw)
To: qemu-devel
Signed-off-by: Juan Quintela <quintela@redhat.com>
---
hw/e1000.c | 30 ++++++++++++++----------------
1 files changed, 14 insertions(+), 16 deletions(-)
diff --git a/hw/e1000.c b/hw/e1000.c
index 0d40fbe..e5541c7 100644
--- a/hw/e1000.c
+++ b/hw/e1000.c
@@ -879,17 +879,11 @@ e1000_mmio_readw(void *opaque, target_phys_addr_t addr)
(8 * (addr & 3))) & 0xffff;
}
-static const struct {
- int size;
- int array0;
-} mac_regarraystosave[] = { {32, RA}, {128, MTA}, {128, VFTA} };
-enum { MAC_NARRAYS = ARRAY_SIZE(mac_regarraystosave) };
-
static void
nic_save(QEMUFile *f, void *opaque)
{
E1000State *s = opaque;
- int i, j;
+ int i;
pci_device_save(&s->dev, f);
qemu_put_be32(f, 0);
@@ -957,17 +951,19 @@ nic_save(QEMUFile *f, void *opaque)
qemu_put_be32s(f, &s->mac_reg[TXDCTL]);
qemu_put_be32s(f, &s->mac_reg[WUFC]);
qemu_put_be32s(f, &s->mac_reg[VET]);
- for (i = 0; i < MAC_NARRAYS; i++)
- for (j = 0; j < mac_regarraystosave[i].size; j++)
- qemu_put_be32s(f,
- s->mac_reg + mac_regarraystosave[i].array0 + j);
+ for (i = RA; i < RA + 32; i++)
+ qemu_put_be32s(f, &s->mac_reg[i]);
+ for (i = MTA; i < MTA + 128; i++)
+ qemu_put_be32s(f, &s->mac_reg[i]);
+ for (i = VFTA; i < VFTA + 128; i++)
+ qemu_put_be32s(f, &s->mac_reg[i]);
}
static int
nic_load(QEMUFile *f, void *opaque, int version_id)
{
E1000State *s = opaque;
- int i, j, ret;
+ int i, ret;
if ((ret = pci_device_load(&s->dev, f)) < 0)
return ret;
@@ -1038,10 +1034,12 @@ nic_load(QEMUFile *f, void *opaque, int version_id)
qemu_get_be32s(f, &s->mac_reg[TXDCTL]);
qemu_get_be32s(f, &s->mac_reg[WUFC]);
qemu_get_be32s(f, &s->mac_reg[VET]);
- for (i = 0; i < MAC_NARRAYS; i++)
- for (j = 0; j < mac_regarraystosave[i].size; j++)
- qemu_get_be32s(f,
- s->mac_reg + mac_regarraystosave[i].array0 + j);
+ for (i = RA; i < RA + 32; i++)
+ qemu_get_be32s(f, &s->mac_reg[i]);
+ for (i = MTA; i < MTA + 128; i++)
+ qemu_get_be32s(f, &s->mac_reg[i]);
+ for (i = VFTA; i < VFTA + 128; i++)
+ qemu_get_be32s(f, &s->mac_reg[i]);
return 0;
}
--
1.6.2.5
^ permalink raw reply related [flat|nested] 30+ messages in thread
* [Qemu-devel] [PATCH 25/25] e1000: port to vmstate
2009-10-19 18:42 [Qemu-devel] [PATCH 00/25] VMState cleanups and conversion of network drivers Juan Quintela
` (23 preceding siblings ...)
2009-10-19 18:43 ` [Qemu-devel] [PATCH 24/25] e1000: unfold mac_regarraystosave array Juan Quintela
@ 2009-10-19 18:43 ` Juan Quintela
2009-10-19 19:15 ` [Qemu-devel] [PATCH 00/25] VMState cleanups and conversion of network drivers Jamie Lokier
25 siblings, 0 replies; 30+ messages in thread
From: Juan Quintela @ 2009-10-19 18:43 UTC (permalink / raw)
To: qemu-devel
Signed-off-by: Juan Quintela <quintela@redhat.com>
---
hw/e1000.c | 244 ++++++++++++++++++++----------------------------------------
1 files changed, 81 insertions(+), 163 deletions(-)
diff --git a/hw/e1000.c b/hw/e1000.c
index e5541c7..4d74ca1 100644
--- a/hw/e1000.c
+++ b/hw/e1000.c
@@ -879,169 +879,88 @@ e1000_mmio_readw(void *opaque, target_phys_addr_t addr)
(8 * (addr & 3))) & 0xffff;
}
-static void
-nic_save(QEMUFile *f, void *opaque)
+static bool is_version_1(void *opaque, int version_id)
{
- E1000State *s = opaque;
- int i;
-
- pci_device_save(&s->dev, f);
- qemu_put_be32(f, 0);
- qemu_put_be32s(f, &s->rxbuf_size);
- qemu_put_be32s(f, &s->rxbuf_min_shift);
- qemu_put_be32s(f, &s->eecd_state.val_in);
- qemu_put_be16s(f, &s->eecd_state.bitnum_in);
- qemu_put_be16s(f, &s->eecd_state.bitnum_out);
- qemu_put_be16s(f, &s->eecd_state.reading);
- qemu_put_be32s(f, &s->eecd_state.old_eecd);
- qemu_put_8s(f, &s->tx.ipcss);
- qemu_put_8s(f, &s->tx.ipcso);
- qemu_put_be16s(f, &s->tx.ipcse);
- qemu_put_8s(f, &s->tx.tucss);
- qemu_put_8s(f, &s->tx.tucso);
- qemu_put_be16s(f, &s->tx.tucse);
- qemu_put_be32s(f, &s->tx.paylen);
- qemu_put_8s(f, &s->tx.hdr_len);
- qemu_put_be16s(f, &s->tx.mss);
- qemu_put_be16s(f, &s->tx.size);
- qemu_put_be16s(f, &s->tx.tso_frames);
- qemu_put_8s(f, &s->tx.sum_needed);
- qemu_put_s8s(f, &s->tx.ip);
- qemu_put_s8s(f, &s->tx.tcp);
- qemu_put_buffer(f, s->tx.header, sizeof s->tx.header);
- qemu_put_buffer(f, s->tx.data, sizeof s->tx.data);
- for (i = 0; i < 64; i++)
- qemu_put_be16s(f, s->eeprom_data + i);
- for (i = 0; i < 0x20; i++)
- qemu_put_be16s(f, s->phy_reg + i);
- qemu_put_be32s(f, &s->mac_reg[CTRL]);
- qemu_put_be32s(f, &s->mac_reg[EECD]);
- qemu_put_be32s(f, &s->mac_reg[EERD]);
- qemu_put_be32s(f, &s->mac_reg[GPRC]);
- qemu_put_be32s(f, &s->mac_reg[GPTC]);
- qemu_put_be32s(f, &s->mac_reg[ICR]);
- qemu_put_be32s(f, &s->mac_reg[ICS]);
- qemu_put_be32s(f, &s->mac_reg[IMC]);
- qemu_put_be32s(f, &s->mac_reg[IMS]);
- qemu_put_be32s(f, &s->mac_reg[LEDCTL]);
- qemu_put_be32s(f, &s->mac_reg[MANC]);
- qemu_put_be32s(f, &s->mac_reg[MDIC]);
- qemu_put_be32s(f, &s->mac_reg[MPC]);
- qemu_put_be32s(f, &s->mac_reg[PBA]);
- qemu_put_be32s(f, &s->mac_reg[RCTL]);
- qemu_put_be32s(f, &s->mac_reg[RDBAH]);
- qemu_put_be32s(f, &s->mac_reg[RDBAL]);
- qemu_put_be32s(f, &s->mac_reg[RDH]);
- qemu_put_be32s(f, &s->mac_reg[RDLEN]);
- qemu_put_be32s(f, &s->mac_reg[RDT]);
- qemu_put_be32s(f, &s->mac_reg[STATUS]);
- qemu_put_be32s(f, &s->mac_reg[SWSM]);
- qemu_put_be32s(f, &s->mac_reg[TCTL]);
- qemu_put_be32s(f, &s->mac_reg[TDBAH]);
- qemu_put_be32s(f, &s->mac_reg[TDBAL]);
- qemu_put_be32s(f, &s->mac_reg[TDH]);
- qemu_put_be32s(f, &s->mac_reg[TDLEN]);
- qemu_put_be32s(f, &s->mac_reg[TDT]);
- qemu_put_be32s(f, &s->mac_reg[TORH]);
- qemu_put_be32s(f, &s->mac_reg[TORL]);
- qemu_put_be32s(f, &s->mac_reg[TOTH]);
- qemu_put_be32s(f, &s->mac_reg[TOTL]);
- qemu_put_be32s(f, &s->mac_reg[TPR]);
- qemu_put_be32s(f, &s->mac_reg[TPT]);
- qemu_put_be32s(f, &s->mac_reg[TXDCTL]);
- qemu_put_be32s(f, &s->mac_reg[WUFC]);
- qemu_put_be32s(f, &s->mac_reg[VET]);
- for (i = RA; i < RA + 32; i++)
- qemu_put_be32s(f, &s->mac_reg[i]);
- for (i = MTA; i < MTA + 128; i++)
- qemu_put_be32s(f, &s->mac_reg[i]);
- for (i = VFTA; i < VFTA + 128; i++)
- qemu_put_be32s(f, &s->mac_reg[i]);
+ return version_id == 1;
}
-static int
-nic_load(QEMUFile *f, void *opaque, int version_id)
-{
- E1000State *s = opaque;
- int i, ret;
-
- if ((ret = pci_device_load(&s->dev, f)) < 0)
- return ret;
- if (version_id == 1)
- qemu_get_sbe32s(f, &i); /* once some unused instance id */
- qemu_get_be32(f); /* Ignored. Was mmio_base. */
- qemu_get_be32s(f, &s->rxbuf_size);
- qemu_get_be32s(f, &s->rxbuf_min_shift);
- qemu_get_be32s(f, &s->eecd_state.val_in);
- qemu_get_be16s(f, &s->eecd_state.bitnum_in);
- qemu_get_be16s(f, &s->eecd_state.bitnum_out);
- qemu_get_be16s(f, &s->eecd_state.reading);
- qemu_get_be32s(f, &s->eecd_state.old_eecd);
- qemu_get_8s(f, &s->tx.ipcss);
- qemu_get_8s(f, &s->tx.ipcso);
- qemu_get_be16s(f, &s->tx.ipcse);
- qemu_get_8s(f, &s->tx.tucss);
- qemu_get_8s(f, &s->tx.tucso);
- qemu_get_be16s(f, &s->tx.tucse);
- qemu_get_be32s(f, &s->tx.paylen);
- qemu_get_8s(f, &s->tx.hdr_len);
- qemu_get_be16s(f, &s->tx.mss);
- qemu_get_be16s(f, &s->tx.size);
- qemu_get_be16s(f, &s->tx.tso_frames);
- qemu_get_8s(f, &s->tx.sum_needed);
- qemu_get_s8s(f, &s->tx.ip);
- qemu_get_s8s(f, &s->tx.tcp);
- qemu_get_buffer(f, s->tx.header, sizeof s->tx.header);
- qemu_get_buffer(f, s->tx.data, sizeof s->tx.data);
- for (i = 0; i < 64; i++)
- qemu_get_be16s(f, s->eeprom_data + i);
- for (i = 0; i < 0x20; i++)
- qemu_get_be16s(f, s->phy_reg + i);
- qemu_get_be32s(f, &s->mac_reg[CTRL]);
- qemu_get_be32s(f, &s->mac_reg[EECD]);
- qemu_get_be32s(f, &s->mac_reg[EERD]);
- qemu_get_be32s(f, &s->mac_reg[GPRC]);
- qemu_get_be32s(f, &s->mac_reg[GPTC]);
- qemu_get_be32s(f, &s->mac_reg[ICR]);
- qemu_get_be32s(f, &s->mac_reg[ICS]);
- qemu_get_be32s(f, &s->mac_reg[IMC]);
- qemu_get_be32s(f, &s->mac_reg[IMS]);
- qemu_get_be32s(f, &s->mac_reg[LEDCTL]);
- qemu_get_be32s(f, &s->mac_reg[MANC]);
- qemu_get_be32s(f, &s->mac_reg[MDIC]);
- qemu_get_be32s(f, &s->mac_reg[MPC]);
- qemu_get_be32s(f, &s->mac_reg[PBA]);
- qemu_get_be32s(f, &s->mac_reg[RCTL]);
- qemu_get_be32s(f, &s->mac_reg[RDBAH]);
- qemu_get_be32s(f, &s->mac_reg[RDBAL]);
- qemu_get_be32s(f, &s->mac_reg[RDH]);
- qemu_get_be32s(f, &s->mac_reg[RDLEN]);
- qemu_get_be32s(f, &s->mac_reg[RDT]);
- qemu_get_be32s(f, &s->mac_reg[STATUS]);
- qemu_get_be32s(f, &s->mac_reg[SWSM]);
- qemu_get_be32s(f, &s->mac_reg[TCTL]);
- qemu_get_be32s(f, &s->mac_reg[TDBAH]);
- qemu_get_be32s(f, &s->mac_reg[TDBAL]);
- qemu_get_be32s(f, &s->mac_reg[TDH]);
- qemu_get_be32s(f, &s->mac_reg[TDLEN]);
- qemu_get_be32s(f, &s->mac_reg[TDT]);
- qemu_get_be32s(f, &s->mac_reg[TORH]);
- qemu_get_be32s(f, &s->mac_reg[TORL]);
- qemu_get_be32s(f, &s->mac_reg[TOTH]);
- qemu_get_be32s(f, &s->mac_reg[TOTL]);
- qemu_get_be32s(f, &s->mac_reg[TPR]);
- qemu_get_be32s(f, &s->mac_reg[TPT]);
- qemu_get_be32s(f, &s->mac_reg[TXDCTL]);
- qemu_get_be32s(f, &s->mac_reg[WUFC]);
- qemu_get_be32s(f, &s->mac_reg[VET]);
- for (i = RA; i < RA + 32; i++)
- qemu_get_be32s(f, &s->mac_reg[i]);
- for (i = MTA; i < MTA + 128; i++)
- qemu_get_be32s(f, &s->mac_reg[i]);
- for (i = VFTA; i < VFTA + 128; i++)
- qemu_get_be32s(f, &s->mac_reg[i]);
- return 0;
-}
+static const VMStateDescription vmstate_e1000 = {
+ .name = "e1000",
+ .version_id = 2,
+ .minimum_version_id = 1,
+ .minimum_version_id_old = 1,
+ .fields = (VMStateField []) {
+ VMSTATE_PCI_DEVICE(dev, E1000State),
+ VMSTATE_UNUSED_TEST(is_version_1, 4), /* was instance id */
+ VMSTATE_UNUSED(4), /* Was mmio_base. */
+ VMSTATE_UINT32(rxbuf_size, E1000State),
+ VMSTATE_UINT32(rxbuf_min_shift, E1000State),
+ VMSTATE_UINT32(eecd_state.val_in, E1000State),
+ VMSTATE_UINT16(eecd_state.bitnum_in, E1000State),
+ VMSTATE_UINT16(eecd_state.bitnum_out, E1000State),
+ VMSTATE_UINT16(eecd_state.reading, E1000State),
+ VMSTATE_UINT32(eecd_state.old_eecd, E1000State),
+ VMSTATE_UINT8(tx.ipcss, E1000State),
+ VMSTATE_UINT8(tx.ipcso, E1000State),
+ VMSTATE_UINT16(tx.ipcse, E1000State),
+ VMSTATE_UINT8(tx.tucss, E1000State),
+ VMSTATE_UINT8(tx.tucso, E1000State),
+ VMSTATE_UINT16(tx.tucse, E1000State),
+ VMSTATE_UINT32(tx.paylen, E1000State),
+ VMSTATE_UINT8(tx.hdr_len, E1000State),
+ VMSTATE_UINT16(tx.mss, E1000State),
+ VMSTATE_UINT16(tx.size, E1000State),
+ VMSTATE_UINT16(tx.tso_frames, E1000State),
+ VMSTATE_UINT8(tx.sum_needed, E1000State),
+ VMSTATE_INT8(tx.ip, E1000State),
+ VMSTATE_INT8(tx.tcp, E1000State),
+ VMSTATE_BUFFER(tx.header, E1000State),
+ VMSTATE_BUFFER(tx.data, E1000State),
+ VMSTATE_UINT16_ARRAY(eeprom_data, E1000State, 64),
+ VMSTATE_UINT16_ARRAY(phy_reg, E1000State, 0x20),
+ VMSTATE_UINT32(mac_reg[CTRL], E1000State),
+ VMSTATE_UINT32(mac_reg[EECD], E1000State),
+ VMSTATE_UINT32(mac_reg[EERD], E1000State),
+ VMSTATE_UINT32(mac_reg[GPRC], E1000State),
+ VMSTATE_UINT32(mac_reg[GPTC], E1000State),
+ VMSTATE_UINT32(mac_reg[ICR], E1000State),
+ VMSTATE_UINT32(mac_reg[ICS], E1000State),
+ VMSTATE_UINT32(mac_reg[IMC], E1000State),
+ VMSTATE_UINT32(mac_reg[IMS], E1000State),
+ VMSTATE_UINT32(mac_reg[LEDCTL], E1000State),
+ VMSTATE_UINT32(mac_reg[MANC], E1000State),
+ VMSTATE_UINT32(mac_reg[MDIC], E1000State),
+ VMSTATE_UINT32(mac_reg[MPC], E1000State),
+ VMSTATE_UINT32(mac_reg[PBA], E1000State),
+ VMSTATE_UINT32(mac_reg[RCTL], E1000State),
+ VMSTATE_UINT32(mac_reg[RDBAH], E1000State),
+ VMSTATE_UINT32(mac_reg[RDBAL], E1000State),
+ VMSTATE_UINT32(mac_reg[RDH], E1000State),
+ VMSTATE_UINT32(mac_reg[RDLEN], E1000State),
+ VMSTATE_UINT32(mac_reg[RDT], E1000State),
+ VMSTATE_UINT32(mac_reg[STATUS], E1000State),
+ VMSTATE_UINT32(mac_reg[SWSM], E1000State),
+ VMSTATE_UINT32(mac_reg[TCTL], E1000State),
+ VMSTATE_UINT32(mac_reg[TDBAH], E1000State),
+ VMSTATE_UINT32(mac_reg[TDBAL], E1000State),
+ VMSTATE_UINT32(mac_reg[TDH], E1000State),
+ VMSTATE_UINT32(mac_reg[TDLEN], E1000State),
+ VMSTATE_UINT32(mac_reg[TDT], E1000State),
+ VMSTATE_UINT32(mac_reg[TORH], E1000State),
+ VMSTATE_UINT32(mac_reg[TORL], E1000State),
+ VMSTATE_UINT32(mac_reg[TOTH], E1000State),
+ VMSTATE_UINT32(mac_reg[TOTL], E1000State),
+ VMSTATE_UINT32(mac_reg[TPR], E1000State),
+ VMSTATE_UINT32(mac_reg[TPT], E1000State),
+ VMSTATE_UINT32(mac_reg[TXDCTL], E1000State),
+ VMSTATE_UINT32(mac_reg[WUFC], E1000State),
+ VMSTATE_UINT32(mac_reg[VET], E1000State),
+ VMSTATE_UINT32_SUB_ARRAY(mac_reg, E1000State, RA, 32),
+ VMSTATE_UINT32_SUB_ARRAY(mac_reg, E1000State, MTA, 128),
+ VMSTATE_UINT32_SUB_ARRAY(mac_reg, E1000State, VFTA, 128),
+ VMSTATE_END_OF_LIST()
+ }
+};
static const uint16_t e1000_eeprom_template[64] = {
0x0000, 0x0000, 0x0000, 0x0000, 0xffff, 0x0000, 0x0000, 0x0000,
@@ -1115,7 +1034,7 @@ e1000_cleanup(VLANClientState *vc)
{
E1000State *d = vc->opaque;
- unregister_savevm("e1000", d);
+ vmstate_unregister(&vmstate_e1000, d);
}
static int
@@ -1145,7 +1064,6 @@ static int pci_e1000_init(PCIDevice *pci_dev)
E1000State *d = DO_UPCAST(E1000State, dev, pci_dev);
uint8_t *pci_conf;
uint16_t checksum = 0;
- static const char info_str[] = "e1000";
int i;
uint8_t macaddr[6];
@@ -1187,7 +1105,7 @@ static int pci_e1000_init(PCIDevice *pci_dev)
qemu_format_nic_info_str(d->vc, macaddr);
- register_savevm(info_str, -1, 2, nic_save, nic_load, d);
+ vmstate_register(-1, &vmstate_e1000, d);
qemu_register_reset(e1000_reset, d);
e1000_reset(d);
return 0;
--
1.6.2.5
^ permalink raw reply related [flat|nested] 30+ messages in thread
* Re: [Qemu-devel] [PATCH 00/25] VMState cleanups and conversion of network drivers
2009-10-19 18:42 [Qemu-devel] [PATCH 00/25] VMState cleanups and conversion of network drivers Juan Quintela
` (24 preceding siblings ...)
2009-10-19 18:43 ` [Qemu-devel] [PATCH 25/25] e1000: port to vmstate Juan Quintela
@ 2009-10-19 19:15 ` Jamie Lokier
2009-10-19 20:34 ` [Qemu-devel] " Juan Quintela
2009-10-20 15:41 ` Paolo Bonzini
25 siblings, 2 replies; 30+ messages in thread
From: Jamie Lokier @ 2009-10-19 19:15 UTC (permalink / raw)
To: Juan Quintela; +Cc: qemu-devel
Juan Quintela wrote:
> * add VARRAY_UINT16_UNSAFE: unsafe here means that type checking is off
> (a.k.a. as a cast in C). In this case the problem is that the last
> element of one struct is int foo[0], and we allocate the right size
> for the array we want. Problem? I haven't been able to abuse^Wuse
> gcc + cpp + magic to typecheck that for vmstate:
>
> We have
> struct FOO {
> int32_t foo[0];
> }
> We want to "compare the type of foo (t1) with int32_t (t2)
>
> ((t1(*)[n])0 - (t2*)0)
> This one don't work, because we don't have 'n'
> ((t1(**))0 - (t2*)0)
> This don't work either because t1 is one array.
> ((t1(*)[])0 - (t2*)0)
> Too clever, imposible cast to on array type.
> I tried some other variants, but have not able to get one that compiles.
Since you mention GCC, is it ok to use GCC extensions? __typeof__(t1)
often does the trick for this sort of thing where t1 alone does not
compile, even if t1 is a type.
__builtin_types_compatible_p(), __builtin_choose_exper and
__attribute__((__error__)) are good for informative error messages.
-- Jamie
^ permalink raw reply [flat|nested] 30+ messages in thread
* [Qemu-devel] Re: [PATCH 00/25] VMState cleanups and conversion of network drivers
2009-10-19 19:15 ` [Qemu-devel] [PATCH 00/25] VMState cleanups and conversion of network drivers Jamie Lokier
@ 2009-10-19 20:34 ` Juan Quintela
2009-10-19 21:11 ` Jamie Lokier
2009-10-20 15:41 ` Paolo Bonzini
1 sibling, 1 reply; 30+ messages in thread
From: Juan Quintela @ 2009-10-19 20:34 UTC (permalink / raw)
To: Jamie Lokier; +Cc: qemu-devel
Jamie Lokier <jamie@shareable.org> wrote:
> Juan Quintela wrote:
>> * add VARRAY_UINT16_UNSAFE: unsafe here means that type checking is off
>> (a.k.a. as a cast in C). In this case the problem is that the last
>> element of one struct is int foo[0], and we allocate the right size
>> for the array we want. Problem? I haven't been able to abuse^Wuse
>> gcc + cpp + magic to typecheck that for vmstate:
>>
>> We have
>> struct FOO {
>> int32_t foo[0];
>> }
>> We want to "compare the type of foo (t1) with int32_t (t2)
>>
>> ((t1(*)[n])0 - (t2*)0)
>> This one don't work, because we don't have 'n'
>> ((t1(**))0 - (t2*)0)
>> This don't work either because t1 is one array.
>> ((t1(*)[])0 - (t2*)0)
>> Too clever, imposible cast to on array type.
>> I tried some other variants, but have not able to get one that compiles.
>
> Since you mention GCC, is it ok to use GCC extensions?
I would bet that qemu don't compile with anyother compiler without big
changes :)
> __typeof__(t1)
> often does the trick for this sort of thing where t1 alone does not
> compile, even if t1 is a type.
>
> __builtin_types_compatible_p(), __builtin_choose_exper and
> __attribute__((__error__)) are good for informative error messages.
Thanks, will take a look.
I have good error messages, I don't have good ideas about how to trick
the compiler. Error messages are clear.
Example:
struct FOO {
unt16_t foo[0];
}
#define vmstate_offset_pointer(_state, _field, _type) \
(offsetof(_state, _field) + \
type_check_pointer(_type, typeof_field(_state, _field)))
Called with (after doing substitutions)
type_check_pointer(uint16_t, struct FOO, foo);
Give that, we try several definitions for type_check_pointer:
#define type_check_pointer(t1,t2) ((t1**)0 - (t2*)0)
Gives the following error:
/scratch/qemu/hw/eeprom93xx.c:144: error: invalid operands to binary -
(have ‘uint16_t **’ and ‘uint16_t (*)[]’)
Another try:
#define type_check_pointer(t1,t2) ((t1(*)[])0 - (t2*)0)
gives
/scratch/qemu/hw/eeprom93xx.c:148: error: arithmetic on pointer to an incomplete type
Another one:
#define type_check_pointer(t1,t2) ((t1(*)[0])0 - (t2*)0)
gives:
/scratch/qemu/hw/eeprom93xx.c:151: error: initializer element is not constant
/scratch/qemu/hw/eeprom93xx.c:151: error: (near initialization for ‘vmstate_eeprom’)
And at this point, I got confused :(
After reading the info of __builtin_types_compatible_p(), it could
perhas be useful. Thinking and testing a bit more about it.
Later, Juan.
^ permalink raw reply [flat|nested] 30+ messages in thread
* [Qemu-devel] Re: [PATCH 00/25] VMState cleanups and conversion of network drivers
2009-10-19 20:34 ` [Qemu-devel] " Juan Quintela
@ 2009-10-19 21:11 ` Jamie Lokier
0 siblings, 0 replies; 30+ messages in thread
From: Jamie Lokier @ 2009-10-19 21:11 UTC (permalink / raw)
To: Juan Quintela; +Cc: qemu-devel
Juan Quintela wrote:
> I have good error messages, I don't have good ideas about how to trick
> the compiler. Error messages are clear.
>
> Example:
>
> struct FOO {
> unt16_t foo[0];
> }
> #define vmstate_offset_pointer(_state, _field, _type) \
> (offsetof(_state, _field) + \
> type_check_pointer(_type, typeof_field(_state, _field)))
>
> Called with (after doing substitutions)
> type_check_pointer(uint16_t, struct FOO, foo);
>
> Give that, we try several definitions for type_check_pointer:
>
> #define type_check_pointer(t1,t2) ((t1**)0 - (t2*)0)
>
> Gives the following error:
>
> /scratch/qemu/hw/eeprom93xx.c:144: error: invalid operands to binary -
> (have ‘uint16_t **’ and ‘uint16_t (*)[]’)
>
> Another try:
>
> #define type_check_pointer(t1,t2) ((t1(*)[])0 - (t2*)0)
>
> gives
>
> /scratch/qemu/hw/eeprom93xx.c:148: error: arithmetic on pointer to an incomplete type
>
> Another one:
>
> #define type_check_pointer(t1,t2) ((t1(*)[0])0 - (t2*)0)
>
> gives:
>
> /scratch/qemu/hw/eeprom93xx.c:151: error: initializer element is not constant
> /scratch/qemu/hw/eeprom93xx.c:151: error: (near initialization for ‘vmstate_eeprom’)
#define type_check_pointer(t1,t2) (0*sizeof((t1(*)[0])0 - (t2*)0))
Or if you want foo[] to work:
#define type_check_pointer(t1,t2) (0*sizeof((t1(**)[])0 - (t2**)0))
Dubiously, but fortunately, the second one works with foo[] and foo[0]
in GCC.
Enjoy :-)
-- Jamie
^ permalink raw reply [flat|nested] 30+ messages in thread
* [Qemu-devel] Re: [PATCH 00/25] VMState cleanups and conversion of network drivers
2009-10-19 19:15 ` [Qemu-devel] [PATCH 00/25] VMState cleanups and conversion of network drivers Jamie Lokier
2009-10-19 20:34 ` [Qemu-devel] " Juan Quintela
@ 2009-10-20 15:41 ` Paolo Bonzini
1 sibling, 0 replies; 30+ messages in thread
From: Paolo Bonzini @ 2009-10-20 15:41 UTC (permalink / raw)
To: Jamie Lokier; +Cc: qemu-devel, Juan Quintela
On 10/19/2009 09:15 PM, Jamie Lokier wrote:
> __builtin_types_compatible_p(), __builtin_choose_exper and
> __attribute__((__error__)) are good for informative error messages.
Unfortunately __attribute__((__error__)) cannot be applied in this case
for several reasons:
1) it cannot apply to types so you cannot do
extern void compile_error (void);
#define raise_compile_error(x) \
(((void __attribute__ ((error(x))) (*) (void)) x) ())
2) it only operates for calls, so you cannot use it in initializers
I whipped up a patch to add to GCC __builtin_compile_error, to be used
inside __builtin_choose_expr:
#define typecheck(t1, t2) \
__builtin_choose_expr (__builtin_types_compatible(t1, t2), (void)0, \
__builtin_compile_error (#t1 " and " #t2 \
"are not compatible types"))
#define if_types_compatible(t1, t2, value) (typecheck (t1, t2), value)
and I will send it upstream, but it will be a long time before it is in
a released version (especially since GCC is currently in bug-fixing-only
mode)---anyway Jamie got the array case to work, AFAIU.
Paolo
^ permalink raw reply [flat|nested] 30+ messages in thread
end of thread, other threads:[~2009-10-20 15:41 UTC | newest]
Thread overview: 30+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-10-19 18:42 [Qemu-devel] [PATCH 00/25] VMState cleanups and conversion of network drivers Juan Quintela
2009-10-19 18:42 ` [Qemu-devel] [PATCH 01/25] vmstate: Add support for partial buffers transmission Juan Quintela
2009-10-19 18:42 ` [Qemu-devel] [PATCH 02/25] serial: use post_load version_id field and remove pre_load function Juan Quintela
2009-10-19 18:42 ` [Qemu-devel] [PATCH 03/25] vnmstate: fix name for uint8_equal Juan Quintela
2009-10-19 18:42 ` [Qemu-devel] [PATCH 04/25] vmstate: add VMSTATE_UINT16_EQUAL[_V] Juan Quintela
2009-10-19 18:42 ` [Qemu-devel] [PATCH 05/25] vmstate: Rename VMS_VARRAY to VMS_VARRAY_INT32 Juan Quintela
2009-10-19 18:42 ` [Qemu-devel] [PATCH 06/25] vmstate: fix indentation Juan Quintela
2009-10-19 18:42 ` [Qemu-devel] [PATCH 07/25] vmstate: factor vmstate_offset_value Juan Quintela
2009-10-19 18:42 ` [Qemu-devel] [PATCH 08/25] vmstate: factor vmstate_offset_pointer Juan Quintela
2009-10-19 18:42 ` [Qemu-devel] [PATCH 09/25] vmstate: factor vmstate_offset_array Juan Quintela
2009-10-19 18:42 ` [Qemu-devel] [PATCH 10/25] vmstate: factor vmstate_offset_buffer Juan Quintela
2009-10-19 18:42 ` [Qemu-devel] [PATCH 11/25] vmstate: factor VMSTATE_*BUFFER* definitions Juan Quintela
2009-10-19 18:42 ` [Qemu-devel] [PATCH 12/25] vmstate: Unfold VMSTATE_INT32_VARRAY() only use and remove it Juan Quintela
2009-10-19 18:42 ` [Qemu-devel] [PATCH 13/25] vmstate: add VMS_VARRAY_UINT16_UNSAFE (varrays with uint16 indexes) Juan Quintela
2009-10-19 18:42 ` [Qemu-devel] [PATCH 14/25] vmstate: Add version arg to VMSTATE_SINGLE_TEST() Juan Quintela
2009-10-19 18:43 ` [Qemu-devel] [PATCH 15/25] vmstate: Add VMSTATE_BUFFER_UNUSED Juan Quintela
2009-10-19 18:43 ` [Qemu-devel] [PATCH 16/25] vmstate: Introduce the concept of sub-arrays Juan Quintela
2009-10-19 18:43 ` [Qemu-devel] [PATCH 17/25] rtl8139: port TallyCounters to vmstate Juan Quintela
2009-10-19 18:43 ` [Qemu-devel] [PATCH 18/25] rtl8139: port " Juan Quintela
2009-10-19 18:43 ` [Qemu-devel] [PATCH 19/25] eeprom93xx: " Juan Quintela
2009-10-19 18:43 ` [Qemu-devel] [PATCH 20/25] eepro100: " Juan Quintela
2009-10-19 18:43 ` [Qemu-devel] [PATCH 21/25] pcnet: " Juan Quintela
2009-10-19 18:43 ` [Qemu-devel] [PATCH 22/25] ne2000: " Juan Quintela
2009-10-19 18:43 ` [Qemu-devel] [PATCH 23/25] e1000: unfold mac_reg_tosave array Juan Quintela
2009-10-19 18:43 ` [Qemu-devel] [PATCH 24/25] e1000: unfold mac_regarraystosave array Juan Quintela
2009-10-19 18:43 ` [Qemu-devel] [PATCH 25/25] e1000: port to vmstate Juan Quintela
2009-10-19 19:15 ` [Qemu-devel] [PATCH 00/25] VMState cleanups and conversion of network drivers Jamie Lokier
2009-10-19 20:34 ` [Qemu-devel] " Juan Quintela
2009-10-19 21:11 ` Jamie Lokier
2009-10-20 15:41 ` Paolo Bonzini
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).