arm_gic: convert to vmstate
cover arm_gic: convert to vmstate
Convert the arm_gic save/load support from hand-coded save/load functions to use VMState. This seems like a good thing to do before we get to the point with KVM/ARM that we need to start supporting between-version migration...
Peter Maydell (2):
arm_gic: Fix sizes of state fields in preparation for vmstate support hw/arm_gic_common: Use vmstate struct rather than save/load functions
hw/arm_gic_common.c | 113 +++++++++++++++++++------------------------------ hw/arm_gic_internal.h | 42 +++++++++--------- hw/armv7m_nvic.c | 4 +- 3 files changed, 67 insertions(+), 92 deletions(-)
Signature · 1 line
1.7.9.5
PATCH 1/2 arm_gic: Fix sizes of state fields in preparation for vmstate support
In preparation for switching to vmstate for migration support, fix the sizes of various GIC state fields. In particular, we replace all the bitfields (which VMState can't deal with) with straightforward uint8_t values which we do bit operations on. (The bitfields made more sense when NCPU was set differently in different situations, but we now always model at the architectural limit of 8.)
--- hw/arm_gic_common.c | 4 ++-- hw/arm_gic_internal.h | 42 +++++++++++++++++++++--------------------- hw/armv7m_nvic.c | 4 ++-- 3 files changed, 25 insertions(+), 25 deletions(-)
hw/arm_gic_common.c +2 -2
@@ -149,7 +149,7 @@ static void arm_gic_common_reset(DeviceState *dev) s->current_pending[i] =1023 ; s->running_irq[i] =1023 ; s->running_priority[i] =0x100 ; - s->cpu_enabled[i] =0 ; + s->cpu_enabled[i] = false; }for (i =0 ; i <16 ; i++) {GIC_SET_ENABLED (i,ALL_CPU_MASK );
@@ -161,7 +161,7 @@ static void arm_gic_common_reset(DeviceState *dev) s->irq_target[i] =1 ; } } - s->enabled =0 ; + s->enabled = false; }static Property arm_gic_common_properties[] = {
hw/arm_gic_internal.h +21 -21
65 lines not on this page · raw message
hw/armv7m_nvic.c +2 -2
@@ -458,10 +458,10 @@ static void armv7m_nvic_reset(DeviceState *dev)* as enabled by default, and with a priority mask which allows * all interrupts through. */ - s->gic.cpu_enabled[0 ] =1 ; + s->gic.cpu_enabled[0 ] = false; s->gic.priority_mask[0 ] =0x100 ;/* The NVIC as a whole is always enabled. */ - s->gic.enabled =1 ; + s->gic.enabled = true;systick_reset (s); }
Signature · 1 line
1.7.9.5
Re: [Qemu-devel] [PATCH 1/2] arm_gic: Fix sizes of state fields in preparation for vmstate support
Am 18.03.2013 17:30, schrieb Peter Maydell:
Quoted 8 lines
In preparation for switching to vmstate for migration support, fix the sizes of various GIC state fields. In particular, we replace all the bitfields (which VMState can't deal with) with straightforward
uint8_tvalues which we do bit operations on. (The bitfields made more sense when NCPU was set differently in different situations, but we now always model at the architectural limit of 8.)Signed-off-by Peter Maydell <[email protected]>
[...]
hw/armv7m_nvic.c static void armv7m_nvic_reset(DeviceState *dev) · line 461
Quoted 10 lines
hw/armv7m_nvic.c +1
-1@@ -458,10 +458,10 @@ static void armv7m_nvic_reset(DeviceState *dev)* as enabled by default, and with a priority mask which allows * all interrupts through. */ - s->gic.cpu_enabled[0 ] =1 ; + s->gic.cpu_enabled[0 ] = false;
true?
Andreas
Quoted 8 lines
hw/armv7m_nvic.c +1
-1s->gic.priority_mask[0 ] =0x100 ;/* The NVIC as a whole is always enabled. */ - s->gic.enabled =1 ; + s->gic.enabled = true;systick_reset (s); }
Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
Re: [Qemu-devel] [PATCH 1/2] arm_gic: Fix sizes of state fields in preparation for vmstate support
Quoted 13 lines · Andreas Färber
Am 18.03.2013 17:30, schrieb Peter Maydell:
hw/armv7m_nvic.c static void armv7m_nvic_reset(DeviceState *dev) · line 461
Quoted 10 lines
hw/armv7m_nvic.c +1
-1@@ -458,10 +458,10 @@ static void armv7m_nvic_reset(DeviceState *dev)* as enabled by default, and with a priority mask which allows * all interrupts through. */ - s->gic.cpu_enabled[0 ] =1 ; + s->gic.cpu_enabled[0 ] = false;true?
Doh. Forgot to run my armv7m test case, which would have caught this.
-- PMM
PATCH 2/2 hw/arm_gic_common: Use vmstate struct rather than save/load functions
In reply to Peter MaydellUpdate the GIC save/restore to use vmstate rather than hand-rolled save/load functions.
--- hw/arm_gic_common.c | 109 ++++++++++++++++++++------------------------------- 1 file changed, 42 insertions(+), 67 deletions(-)
hw/arm_gic_common.c +42 -67
@@ -20,90 +20,66 @@#include "hw/arm_gic_internal.h" -static void gic_save (QEMUFile *f,void *opaque) +static void gic_pre_save (void *opaque) {GICState *s = (GICState *)opaque;ARMGICCommonClass *c =ARM_GIC_COMMON_GET_CLASS (s); -int i; -int j;if (c->pre_save) { c->pre_save (s); } - -qemu_put_be32 (f, s->enabled); -for (i =0 ; i < s->num_cpu; i++) { -qemu_put_be32 (f, s->cpu_enabled[i]); -for (j =0 ; j <GIC_INTERNAL ; j++) { -qemu_put_be32 (f, s->priority1[j][i]); - } -for (j =0 ; j < s->num_irq; j++) { -qemu_put_be32 (f, s->last_active[j][i]); - } -qemu_put_be32 (f, s->priority_mask[i]); -qemu_put_be32 (f, s->running_irq[i]); -qemu_put_be32 (f, s->running_priority[i]); -qemu_put_be32 (f, s->current_pending[i]); - } -for (i =0 ; i < s->num_irq -GIC_INTERNAL ; i++) { -qemu_put_be32 (f, s->priority2[i]); - } -for (i =0 ; i < s->num_irq; i++) { -qemu_put_be32 (f, s->irq_target[i]); -qemu_put_byte (f, s->irq_state[i].enabled); -qemu_put_byte (f, s->irq_state[i].pending); -qemu_put_byte (f, s->irq_state[i].active); -qemu_put_byte (f, s->irq_state[i].level); -qemu_put_byte (f, s->irq_state[i].model); -qemu_put_byte (f, s->irq_state[i].trigger); - } } -static int gic_load (QEMUFile *f,void *opaque,int version_id) +static int gic_post_load (void *opaque,int version_id) {GICState *s = (GICState *)opaque;ARMGICCommonClass *c =ARM_GIC_COMMON_GET_CLASS (s); -int i; -int j; - -if (version_id !=3 ) { -return -EINVAL ; - } - - s->enabled =qemu_get_be32 (f); -for (i =0 ; i < s->num_cpu; i++) { - s->cpu_enabled[i] =qemu_get_be32 (f); -for (j =0 ; j <GIC_INTERNAL ; j++) { - s->priority1[j][i] =qemu_get_be32 (f); - } -for (j =0 ; j < s->num_irq; j++) { - s->last_active[j][i] =qemu_get_be32 (f); - } - s->priority_mask[i] =qemu_get_be32 (f); - s->running_irq[i] =qemu_get_be32 (f); - s->running_priority[i] =qemu_get_be32 (f); - s->current_pending[i] =qemu_get_be32 (f); - } -for (i =0 ; i < s->num_irq -GIC_INTERNAL ; i++) { - s->priority2[i] =qemu_get_be32 (f); - } -for (i =0 ; i < s->num_irq; i++) { - s->irq_target[i] =qemu_get_be32 (f); - s->irq_state[i].enabled =qemu_get_byte (f); - s->irq_state[i].pending =qemu_get_byte (f); - s->irq_state[i].active =qemu_get_byte (f); - s->irq_state[i].level =qemu_get_byte (f); - s->irq_state[i].model =qemu_get_byte (f); - s->irq_state[i].trigger =qemu_get_byte (f); - }if (c->post_load) { c->post_load (s); } -return 0 ; } +static const VMStateDescription vmstate_gic_irq_state = { + .name ="arm_gic_irq_state" , + .version_id =1 , + .minimum_version_id =1 , + .fields = (VMStateField []) { +VMSTATE_UINT8 (enabled, gic_irq_state), +VMSTATE_UINT8 (pending, gic_irq_state), +VMSTATE_UINT8 (active, gic_irq_state), +VMSTATE_UINT8 (level, gic_irq_state), +VMSTATE_BOOL (model, gic_irq_state), +VMSTATE_BOOL (trigger, gic_irq_state), +VMSTATE_END_OF_LIST () + } +}; + +static const VMStateDescription vmstate_gic = { + .name ="arm_gic" , + .version_id =4 , + .minimum_version_id =4 , + .pre_save = gic_pre_save, + .post_load = gic_post_load, + .fields = (VMStateField []) { +VMSTATE_BOOL (enabled, GICState), +VMSTATE_BOOL_ARRAY (cpu_enabled, GICState,NCPU ), +VMSTATE_STRUCT_ARRAY (irq_state, GICState,GIC_MAXIRQ ,1 , + vmstate_gic_irq_state, gic_irq_state), +VMSTATE_UINT8_ARRAY (irq_target, GICState,GIC_MAXIRQ ), +VMSTATE_BUFFER_UNSAFE (priority1, GICState,0 ,GIC_INTERNAL *NCPU ), +VMSTATE_UINT8_ARRAY (priority2, GICState,GIC_MAXIRQ -GIC_INTERNAL ), +VMSTATE_BUFFER_UNSAFE (last_active, GICState,0 , +GIC_MAXIRQ *NCPU *sizeof (uint16_t )), +VMSTATE_UINT16_ARRAY (priority_mask, GICState,NCPU ), +VMSTATE_UINT16_ARRAY (running_irq, GICState,NCPU ), +VMSTATE_UINT16_ARRAY (running_priority, GICState,NCPU ), +VMSTATE_UINT16_ARRAY (current_pending, GICState,NCPU ), +VMSTATE_END_OF_LIST () + } +}; +static void arm_gic_common_realize (DeviceState *dev,Error **errp) {GICState *s =ARM_GIC_COMMON (dev);
@@ -131,8 +107,6 @@ static void arm_gic_common_realize(DeviceState *dev, Error **errp) num_irq);return ; } - -register_savevm (NULL ,"arm_gic" ,-1 ,3 , gic_save, gic_load, s); }static void arm_gic_common_reset (DeviceState *dev)
@@ -182,6 +156,7 @@ static void arm_gic_common_class_init(ObjectClass *klass, void *data) dc->reset = arm_gic_common_reset; dc->realize = arm_gic_common_realize; dc->props = arm_gic_common_properties; + dc->vmsd = &vmstate_gic; dc->no_user =1 ; }
Signature · 1 line
1.7.9.5