Support RISC-V migration
Subsystems (3)
cover Support RISC-V migration
This patches supported RISC-V migration based on tcg accel. And we have verified related migration features such as snapshot and live migration.
A few weeks ago, we submitted RFC patches about supporting RISC-V migration based on kvm accel: https://www.spinics.net/lists/kvm/msg223605.html.
And we found that tcg accelerated migration can be supported with a few changes. Most of the devices have already implemented the migration interface, so, to achieve the tcg accelerated migration, we just need to add vmstate of both cpu and sifive_plic.
Yifei Jiang (5):
target/riscv: Add basic vmstate description of CPU target/riscv: Add PMP state description target/riscv: Add H extention state description target/riscv: Add V extention state description target/riscv: Add sifive_plic vmstate
hw/intc/sifive_plic.c | 26 +++++- hw/intc/sifive_plic.h | 1 + target/riscv/cpu.c | 7 -- target/riscv/cpu.h | 4 + target/riscv/machine.c | 184 +++++++++++++++++++++++++++++++++++++++ target/riscv/meson.build | 3 +- 6 files changed, 214 insertions(+), 9 deletions(-) create mode 100644 target/riscv/machine.c
Signature · 1 line
2.19.1
PATCH 1/5 target/riscv: Add basic vmstate description of CPU
Add basic CPU state description to the newly created machine.c
--- target/riscv/cpu.c | 7 ----- target/riscv/cpu.h | 4 +++ target/riscv/machine.c | 59 ++++++++++++++++++++++++++++++++++++++++ target/riscv/meson.build | 3 +- 4 files changed, 65 insertions(+), 8 deletions(-) create mode 100644 target/riscv/machine.c
target/riscv/cpu.c +0 -7
@@ -496,13 +496,6 @@ static void riscv_cpu_init(Object *obj)cpu_set_cpustate_pointers (cpu); } -#ifndef CONFIG_USER_ONLY -static const VMStateDescription vmstate_riscv_cpu = { - .name ="cpu" , - .unmigratable =1 , -}; -#endif -static Property riscv_cpu_properties[] = {DEFINE_PROP_BOOL ("i" ,RISCVCPU , cfg.ext_i, true),DEFINE_PROP_BOOL ("e" ,RISCVCPU , cfg.ext_e, false),
target/riscv/cpu.h +4 -0
@@ -311,6 +311,10 @@ extern const char * const riscv_fpr_regnames[];extern const char *const riscv_excp_names[];extern const char *const riscv_intr_names[]; +#ifndef CONFIG_USER_ONLY +extern const VMStateDescription vmstate_riscv_cpu; +#endif +const char *riscv_cpu_get_trap_name (target_ulong cause,bool async);void riscv_cpu_do_interrupt (CPUState *cpu);int riscv_cpu_gdb_read_register (CPUState *cpu,GByteArray *buf,int reg);
target/riscv/machine.c new file +59 -0
59 lines not on this page · raw message
target/riscv/meson.build +2 -1
@@ -27,7 +27,8 @@ riscv_ss.add(files( riscv_softmmu_ss = ss.source_set() riscv_softmmu_ss.add(files( 'pmp.c', - 'monitor.c' + 'monitor.c', + 'machine.c' )) target_arch += {'riscv': riscv_ss}
Signature · 1 line
2.19.1
Re: [PATCH 1/5] target/riscv: Add basic vmstate description of CPU
target/riscv/machine.c line 2
Quoted 5 lines · Yifei Jiang
target/riscv/machine.c new file +2
-0@@ -0,0 +1,59 @@ +#include "qemu/osdep.h" +#include "cpu.h"
All new files must contain license boilerplate.
Otherwise, considering the followups, this seems ok.
r~
RE: [PATCH 1/5] target/riscv: Add basic vmstate description of CPU
Quoted 23 lines
-----Original Message-----
From: Richard Henderson [mailto:[email protected]]
Sent: Friday, October 2, 2020 1:23 AM
To: Jiangyifei <[email protected]>; [email protected]; [email protected]
Cc: Zhanghailiang <[email protected]>; [email protected]; [email protected]; Zhangxiaofeng
(F) <[email protected]>; [email protected]; yinyipeng <[email protected]>; [email protected]; Wubin (H) <[email protected]>; dengkai (A) <[email protected]>
Subject: Re: [PATCH 1/5] target/riscv: Add basic vmstate description of CPUtarget/riscv/machine.c line 2
Quoted 5 lines · Yifei Jiang
target/riscv/machine.c new file +2
-0@@ -0,0 +1,59 @@ +#include "qemu/osdep.h" +#include "cpu.h" All new files must contain license boilerplate.
Quoted 2 lines
Otherwise, considering the followups, this seems ok.
Thanks, I'll add license boilerplate in the next series.
Yifei
Quoted 2 lines
r~
PATCH 2/5 target/riscv: Add PMP state description
In reply to Yifei JiangIn the case of supporting PMP feature, add PMP state description to vmstate_riscv_cpu.
--- target/riscv/machine.c | 49 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+)
target/riscv/machine.c +49 -0
@@ -4,6 +4,51 @@#include "sysemu/kvm.h" #include "migration/cpu.h" +static bool pmp_needed (void *opaque) +{ +RISCVCPU *cpu = opaque; +CPURISCVState *env = &cpu->env; + +return riscv_feature (env,RISCV_FEATURE_PMP ); +} + +static const VMStateDescription vmstate_pmp_entry = { + .name ="cpu/pmp/entry" , + .version_id =1 , + .minimum_version_id =1 , + .fields = (VMStateField []) { +VMSTATE_UINTTL (addr_reg, pmp_entry_t), +VMSTATE_UINT8 (cfg_reg, pmp_entry_t), +VMSTATE_END_OF_LIST () + } +}; + +static const VMStateDescription vmstate_pmp_addr = { + .name ="cpu/pmp/addr" , + .version_id =1 , + .minimum_version_id =1 , + .fields = (VMStateField []) { +VMSTATE_UINTTL (sa, pmp_addr_t), +VMSTATE_UINTTL (ea, pmp_addr_t), +VMSTATE_END_OF_LIST () + } +}; + +static const VMStateDescription vmstate_pmp = { + .name ="cpu/pmp" , + .version_id =1 , + .minimum_version_id =1 , + .needed = pmp_needed, + .fields = (VMStateField []) { +VMSTATE_STRUCT_ARRAY (env.pmp_state.pmp,RISCVCPU ,MAX_RISCV_PMPS , +0 , vmstate_pmp_entry, pmp_entry_t), +VMSTATE_STRUCT_ARRAY (env.pmp_state.addr,RISCVCPU ,MAX_RISCV_PMPS , +0 , vmstate_pmp_addr, pmp_addr_t), +VMSTATE_UINT32 (env.pmp_state.num_rules,RISCVCPU ), +VMSTATE_END_OF_LIST () + } +}; +const VMStateDescription vmstate_riscv_cpu = { .name ="cpu" , .version_id =1 ,
@@ -55,5 +100,9 @@ const VMStateDescription vmstate_riscv_cpu = {VMSTATE_UINTTL (env.mstatush,RISCVCPU ), #endifVMSTATE_END_OF_LIST () + }, + .subsections = (const VMStateDescription * []) { + &vmstate_pmp, +NULL } };
Signature · 1 line
2.19.1
Re: [PATCH 2/5] target/riscv: Add PMP state description
Quoted 49 lines · Yifei Jiang
In the case of supporting PMP feature, add PMP state description to
vmstate_riscv_cpu.Signed-off-by Yifei Jiang <[email protected]>Signed-off-by Yipeng Yin <[email protected]>--- target/riscv/machine.c | 49 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+)target/riscv/machine.c +31
-0@@ -4,6 +4,51 @@#include "sysemu/kvm.h" #include "migration/cpu.h" +static bool pmp_needed (void *opaque) +{ +RISCVCPU *cpu = opaque; +CPURISCVState *env = &cpu->env; + +return riscv_feature (env,RISCV_FEATURE_PMP ); +} + +static const VMStateDescription vmstate_pmp_entry = { + .name ="cpu/pmp/entry" , + .version_id =1 , + .minimum_version_id =1 , + .fields = (VMStateField []) { +VMSTATE_UINTTL (addr_reg, pmp_entry_t), +VMSTATE_UINT8 (cfg_reg, pmp_entry_t), +VMSTATE_END_OF_LIST () + } +}; + +static const VMStateDescription vmstate_pmp_addr = { + .name ="cpu/pmp/addr" , + .version_id =1 , + .minimum_version_id =1 , + .fields = (VMStateField []) { +VMSTATE_UINTTL (sa, pmp_addr_t), +VMSTATE_UINTTL (ea, pmp_addr_t), +VMSTATE_END_OF_LIST () + } +}; + +static const VMStateDescription vmstate_pmp = {
target/riscv/machine.c line 47
Quoted 10 lines
target/riscv/machine.c +10
-0+ .name = "cpu/pmp", + .version_id = 1, + .minimum_version_id = 1, + .needed = pmp_needed, + .fields = (VMStateField []) { +VMSTATE_STRUCT_ARRAY (env.pmp_state.pmp,RISCVCPU ,MAX_RISCV_PMPS , +0 , vmstate_pmp_entry, pmp_entry_t), +VMSTATE_STRUCT_ARRAY (env.pmp_state.addr,RISCVCPU ,MAX_RISCV_PMPS , +0 , vmstate_pmp_addr, pmp_addr_t), +VMSTATE_UINT32 (env.pmp_state.num_rules,RISCVCPU ),
I would prefer to re-generate these from the PMP CSRs post load.
Alistair
Quoted 21 lines
target/riscv/machine.c +8
-1+ VMSTATE_END_OF_LIST() + } +}; +const VMStateDescription vmstate_riscv_cpu = { .name ="cpu" , .version_id =1 ,@@ -55,5 +100,9 @@ const VMStateDescription vmstate_riscv_cpu = {VMSTATE_UINTTL (env.mstatush,RISCVCPU ), #endifVMSTATE_END_OF_LIST () + }, + .subsections = (const VMStateDescription * []) { + &vmstate_pmp, +NULL } }; --2.19.1
RE: [PATCH 2/5] target/riscv: Add PMP state description
Quoted 76 lines
-----Original Message-----
From: Alistair Francis [mailto:[email protected]]
Sent: Tuesday, October 6, 2020 6:11 AM
To: Jiangyifei <[email protected]>
Cc: [email protected] Developers <[email protected]>; open list:RISC-V <[email protected]>; Zhanghailiang <[email protected]>; Sagar Karandikar <[email protected]>; Bastian Koppelmann <[email protected]>; Zhangxiaofeng (F) <[email protected]>; Alistair Francis <[email protected]>; yinyipeng <[email protected]>; Palmer Dabbelt <[email protected]>; Wubin (H) <[email protected]>; dengkai (A) <[email protected]>
Subject: Re: [PATCH 2/5] target/riscv: Add PMP state descriptionQuoted 45 lines · Yifei Jiang
In the case of supporting PMP feature, add PMP state description to
vmstate_riscv_cpu.Signed-off-by Yifei Jiang <[email protected]>Signed-off-by Yipeng Yin <[email protected]>--- target/riscv/machine.c | 49 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+)target/riscv/machine.c index renamed from target/riscv/machine.c +0
-0
3451b888b1..b1fc839b43100644target/riscv/machine.c +26
-0@@ -4,6 +4,51 @@#include "sysemu/kvm.h" #include "migration/cpu.h" +static bool pmp_needed (void *opaque) +{ +RISCVCPU *cpu = opaque; +CPURISCVState *env = &cpu->env; + +return riscv_feature (env,RISCV_FEATURE_PMP ); } + +static const VMStateDescription vmstate_pmp_entry = { + .name ="cpu/pmp/entry" , + .version_id =1 , + .minimum_version_id =1 , + .fields = (VMStateField []) { +VMSTATE_UINTTL (addr_reg, pmp_entry_t), +VMSTATE_UINT8 (cfg_reg, pmp_entry_t), +VMSTATE_END_OF_LIST () + } +}; + +static const VMStateDescription vmstate_pmp_addr = { + .name ="cpu/pmp/addr" , + .version_id =1 , + .minimum_version_id =1 , + .fields = (VMStateField []) { +VMSTATE_UINTTL (sa, pmp_addr_t), +VMSTATE_UINTTL (ea, pmp_addr_t), +VMSTATE_END_OF_LIST ()target/riscv/machine.c line 42
Quoted 10 lines
target/riscv/machine.c +10
-0+ } +}; + +static const VMStateDescription vmstate_pmp = { + .name ="cpu/pmp" , + .version_id =1 , + .minimum_version_id =1 , + .needed = pmp_needed, + .fields = (VMStateField []) { + VMSTATE_STRUCT_ARRAY(env.pmp_state.pmp, RISCVCPU,
MAX_RISCV_PMPS,target/riscv/machine.c line 44
Quoted 2 lines
target/riscv/machine.c +2
-0+ 0, vmstate_pmp_entry, pmp_entry_t), + VMSTATE_STRUCT_ARRAY(env.pmp_state.addr, RISCVCPU,
Quoted 8 lines
MAX_RISCV_PMPS,target/riscv/machine.c line 47
Quoted 2 lines
target/riscv/machine.c +2
-0+ 0, vmstate_pmp_addr, pmp_addr_t), + VMSTATE_UINT32(env.pmp_state.num_rules, RISCVCPU),I would prefer to re-generate these from the PMP CSRs post load.
Alistair
Thanks for your advice. Yes, you are right.vmstate_pmp_entry cannot be regenerated, but vmstate_pmp_addr and num_rules could be regenerated.
I'll add post_load hook for regenerating vmstate_pmp_addr and num_rules in the next series.
Yifei
Quoted 20 lines
Quoted 20 lines
target/riscv/machine.c +8
-1+ VMSTATE_END_OF_LIST() + } +}; +const VMStateDescription vmstate_riscv_cpu = { .name ="cpu" , .version_id =1 ,@@ -55,5 +100,9 @@ const VMStateDescription vmstate_riscv_cpu = { VMSTATE_UINTTL(env.mstatush, RISCVCPU), #endifVMSTATE_END_OF_LIST () + }, + .subsections = (const VMStateDescription * []) { + &vmstate_pmp, +NULL } }; --2.19.1
PATCH 3/5 target/riscv: Add H extention state description
In reply to Yifei JiangIn the case of supporting H extention, add H extention description to vmstate_riscv_cpu.
--- target/riscv/machine.c | 51 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+)
target/riscv/machine.c +51 -0
@@ -49,6 +49,56 @@ static const VMStateDescription vmstate_pmp = { } }; +static bool hyper_needed (void *opaque) +{ +RISCVCPU *cpu = opaque; +CPURISCVState *env = &cpu->env; + +return riscv_has_ext (env,RVH ); +} + +static const VMStateDescription vmstate_hyper = { + .name ="cpu/hyper" , + .version_id =1 , + .minimum_version_id =1 , + .needed = hyper_needed, + .fields = (VMStateField []) { +VMSTATE_UINTTL (env.hstatus,RISCVCPU ), +VMSTATE_UINTTL (env.hedeleg,RISCVCPU ), +VMSTATE_UINTTL (env.hideleg,RISCVCPU ), +VMSTATE_UINTTL (env.hcounteren,RISCVCPU ), +VMSTATE_UINTTL (env.htval,RISCVCPU ), +VMSTATE_UINTTL (env.htinst,RISCVCPU ), +VMSTATE_UINTTL (env.hgatp,RISCVCPU ), +VMSTATE_UINT64 (env.htimedelta,RISCVCPU ), + +VMSTATE_UINTTL (env.vsstatus,RISCVCPU ), +VMSTATE_UINTTL (env.vstvec,RISCVCPU ), +VMSTATE_UINTTL (env.vsscratch,RISCVCPU ), +VMSTATE_UINTTL (env.vsepc,RISCVCPU ), +VMSTATE_UINTTL (env.vscause,RISCVCPU ), +VMSTATE_UINTTL (env.vstval,RISCVCPU ), +VMSTATE_UINTTL (env.vsatp,RISCVCPU ), + +VMSTATE_UINTTL (env.mtval2,RISCVCPU ), +VMSTATE_UINTTL (env.mtinst,RISCVCPU ), + +VMSTATE_UINTTL (env.stvec_hs,RISCVCPU ), +VMSTATE_UINTTL (env.sscratch_hs,RISCVCPU ), +VMSTATE_UINTTL (env.sepc_hs,RISCVCPU ), +VMSTATE_UINTTL (env.scause_hs,RISCVCPU ), +VMSTATE_UINTTL (env.stval_hs,RISCVCPU ), +VMSTATE_UINTTL (env.satp_hs,RISCVCPU ), +VMSTATE_UINTTL (env.mstatus_hs,RISCVCPU ), + +#ifdef TARGET_RISCV32 +VMSTATE_UINTTL (env.vsstatush,RISCVCPU ), +VMSTATE_UINTTL (env.mstatush_hs,RISCVCPU ), +#endif +VMSTATE_END_OF_LIST () + } +}; +const VMStateDescription vmstate_riscv_cpu = { .name ="cpu" , .version_id =1 ,
@@ -103,6 +153,7 @@ const VMStateDescription vmstate_riscv_cpu = { }, .subsections = (const VMStateDescription * []) { &vmstate_pmp, + &vmstate_hyper,NULL } };
Signature · 1 line
2.19.1
Re: [PATCH 3/5] target/riscv: Add H extention state description
target/riscv/machine.c static const VMStateDescription vmstate_pmp = { · line 81
Quoted 7 lines · Yifei Jiang
target/riscv/machine.c +7
-0+VMSTATE_UINTTL (env.vsstatus,RISCVCPU ), +VMSTATE_UINTTL (env.vstvec,RISCVCPU ), +VMSTATE_UINTTL (env.vsscratch,RISCVCPU ), +VMSTATE_UINTTL (env.vsepc,RISCVCPU ), +VMSTATE_UINTTL (env.vscause,RISCVCPU ), +VMSTATE_UINTTL (env.vstval,RISCVCPU ), + VMSTATE_UINTTL(env.vsatp, RISCVCPU),
So... if I understand things correctly, this is synthetic state, internal to QEMU. It is generally better to only serialize architectural state, so that if qemu internals are rearranged, it is easy to decide on the correct sequence of operations.
It seems like this should be re-generated with a post_load hook, calling some of the code currently in riscv_cpu_swap_hypervisor_regs(). Note that some minor rearrangement would be needed to call that code from this new context.
r~
Re: [PATCH 3/5] target/riscv: Add H extention state description
Quoted 10 lines · Richard Henderson
target/riscv/machine.c static const VMStateDescription vmstate_pmp = { · line 81
Quoted 7 lines · Yifei Jiang
target/riscv/machine.c +7
-0+VMSTATE_UINTTL (env.vsstatus,RISCVCPU ), +VMSTATE_UINTTL (env.vstvec,RISCVCPU ), +VMSTATE_UINTTL (env.vsscratch,RISCVCPU ), +VMSTATE_UINTTL (env.vsepc,RISCVCPU ), +VMSTATE_UINTTL (env.vscause,RISCVCPU ), +VMSTATE_UINTTL (env.vstval,RISCVCPU ), + VMSTATE_UINTTL(env.vsatp, RISCVCPU),
Quoted 4 lines
So... if I understand things correctly, this is synthetic state, internal to QEMU. It is generally better to only serialize architectural state, so that if qemu internals are rearranged, it is easy to decide on the correct sequence of operations.
I don't think the virtual registers are synthetic, they contain what the guest Hypervisor/Hypervisor guest wrote to those CSRs. I don't think we could re-generate them from anything else.
There are some other registers in this series that I think can be re-generated. The PMP is a good example of that, where the PMP config data could be re-generated from the CSRs.
Alistair
Quoted 8 lines
It seems like this should be re-generated with a
post_loadhook, calling some of the code currently inriscv_cpu_swap_hypervisor_regs(). Note that some minor rearrangement would be needed to call that code from this new context.r~
RE: [PATCH 3/5] target/riscv: Add H extention state description
In reply to Richard HendersonQuoted 28 lines
-----Original Message-----
From: Richard Henderson [mailto:[email protected]]
Sent: Friday, October 2, 2020 1:28 AM
To: Jiangyifei <[email protected]>; [email protected]; [email protected]
Cc: Zhanghailiang <[email protected]>; [email protected]; [email protected]; Zhangxiaofeng
(F) <[email protected]>; [email protected]; yinyipeng <[email protected]>; [email protected]; Wubin (H) <[email protected]>; dengkai (A) <[email protected]>
Subject: Re: [PATCH 3/5] target/riscv: Add H extention state descriptiontarget/riscv/machine.c static const VMStateDescription vmstate_pmp = { · line 81
Quoted 7 lines · Yifei Jiang
target/riscv/machine.c +7
-0+VMSTATE_UINTTL (env.vsstatus,RISCVCPU ), +VMSTATE_UINTTL (env.vstvec,RISCVCPU ), +VMSTATE_UINTTL (env.vsscratch,RISCVCPU ), +VMSTATE_UINTTL (env.vsepc,RISCVCPU ), +VMSTATE_UINTTL (env.vscause,RISCVCPU ), +VMSTATE_UINTTL (env.vstval,RISCVCPU ), + VMSTATE_UINTTL(env.vsatp, RISCVCPU),So... if I understand things correctly, this is synthetic state, internal to QEMU. It is generally better to only serialize architectural state, so that if qemu internals are rearranged, it is easy to decide on the correct sequence of operations.
Quoted 6 lines
It seems like this should be re-generated with a
post_loadhook, calling some of the code currently inriscv_cpu_swap_hypervisor_regs(). Note that some minor rearrangement would be needed to call that code from this new context.r~
Thank you for your comments.
As Alistair said, Those vs* are Virtual Supervisor CSRs. Hypervisor may write those. Actually,except *_hs, all states are real CSRs and cannot be regenerated. *_hs are backup of Supervisor CSRs when V=1,so, I don't think could re-generate them.
In conclusion, I think all H extension states in this patch need to be described in vmstate.
Yifei
PATCH 4/5 target/riscv: Add V extention state description
In reply to Yifei JiangIn the case of supporting V extention, add V extention description to vmstate_riscv_cpu.
--- target/riscv/machine.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+)
target/riscv/machine.c +25 -0
@@ -57,6 +57,30 @@ static bool hyper_needed(void *opaque)return riscv_has_ext (env,RVH ); } +static bool vector_needed (void *opaque) +{ +RISCVCPU *cpu = opaque; +CPURISCVState *env = &cpu->env; + +return riscv_has_ext (env,RVV ); +} + +static const VMStateDescription vmstate_vector = { + .name ="cpu/vector" , + .version_id =1 , + .minimum_version_id =1 , + .needed = vector_needed, + .fields = (VMStateField []) { +VMSTATE_UINT64_ARRAY (env.vreg,RISCVCPU ,32 *RV_VLEN_MAX /64 ), +VMSTATE_UINTTL (env.vxrm,RISCVCPU ), +VMSTATE_UINTTL (env.vxsat,RISCVCPU ), +VMSTATE_UINTTL (env.vl,RISCVCPU ), +VMSTATE_UINTTL (env.vstart,RISCVCPU ), +VMSTATE_UINTTL (env.vtype,RISCVCPU ), +VMSTATE_END_OF_LIST () + } +}; +static const VMStateDescription vmstate_hyper = { .name ="cpu/hyper" , .version_id =1 ,
@@ -154,6 +178,7 @@ const VMStateDescription vmstate_riscv_cpu = { .subsections = (const VMStateDescription * []) { &vmstate_pmp, &vmstate_hyper, + &vmstate_vector,NULL } };
Signature · 1 line
2.19.1
Re: [PATCH 4/5] target/riscv: Add V extention state description
Quoted 8 lines · Yifei Jiang
In the case of supporting V extention, add V extention description to
vmstate_riscv_cpu.Signed-off-by Yifei Jiang <[email protected]>Signed-off-by Yipeng Yin <[email protected]>--- target/riscv/machine.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+)
Though of course this is racing with the v1.0 patch set, which changes the set of vector csrs.
r~
PATCH 5/5 target/riscv: Add sifive_plic vmstate
In reply to Yifei JiangAdd sifive_plic vmstate for supporting sifive_plic migration. Current vmstate framework only supports one structure parameter as num field to describe variable length arrays, so introduce num_enables.
--- hw/intc/sifive_plic.c | 26 +++++++++++++++++++++++++- hw/intc/sifive_plic.h | 1 + 2 files changed, 26 insertions(+), 1 deletion(-)
hw/intc/sifive_plic.c +25 -1
@@ -30,6 +30,7 @@#include "hw/intc/sifive_plic.h" #include "target/riscv/cpu.h" #include "sysemu/sysemu.h" +#include "migration/vmstate.h" #define RISCV_DEBUG_PLIC 0
@@ -448,11 +449,12 @@ static void sifive_plic_realize(DeviceState *dev, Error **errp) TYPE_SIFIVE_PLIC, plic->aperture_size);parse_hart_config (plic); plic->bitfield_words = (plic->num_sources +31 ) >>5 ; + plic->num_enables = plic->bitfield_words * plic->num_addrs; plic->source_priority =g_new0 (uint32_t, plic->num_sources); plic->target_priority =g_new (uint32_t, plic->num_addrs); plic->pending =g_new0 (uint32_t, plic->bitfield_words); plic->claimed =g_new0 (uint32_t, plic->bitfield_words); - plic->enable =g_new0 (uint32_t, plic->bitfield_words * plic->num_addrs); + plic->enable =g_new0 (uint32_t, plic->num_enables);sysbus_init_mmio (SYS_BUS_DEVICE (dev), &plic->mmio);qdev_init_gpio_in (dev, sifive_plic_irq_request, plic->num_sources);
@@ -472,12 +474,34 @@ static void sifive_plic_realize(DeviceState *dev, Error **errp) msi_nonbroken = true; } +static const VMStateDescription vmstate_sifive_plic = { + .name ="riscv_sifive_plic" , + .version_id =1 , + .minimum_version_id =1 , + .fields = (VMStateField []) { +VMSTATE_VARRAY_UINT32 (source_priority, SiFivePLICState, + num_sources,0 , + vmstate_info_uint32, uint32_t), +VMSTATE_VARRAY_UINT32 (target_priority, SiFivePLICState, + num_addrs,0 , + vmstate_info_uint32, uint32_t), +VMSTATE_VARRAY_UINT32 (pending, SiFivePLICState, bitfield_words,0 , + vmstate_info_uint32, uint32_t), +VMSTATE_VARRAY_UINT32 (claimed, SiFivePLICState, bitfield_words,0 , + vmstate_info_uint32, uint32_t), +VMSTATE_VARRAY_UINT32 (enable, SiFivePLICState, num_enables,0 , + vmstate_info_uint32, uint32_t), +VMSTATE_END_OF_LIST () + } +}; +static void sifive_plic_class_init (ObjectClass *klass,void *data) {DeviceClass *dc =DEVICE_CLASS (klass);device_class_set_props (dc, sifive_plic_properties); dc->realize = sifive_plic_realize; + dc->vmsd = &vmstate_sifive_plic; }static const TypeInfo sifive_plic_info = {
hw/intc/sifive_plic.h +1 -0
@@ -52,6 +52,7 @@ struct SiFivePLICState {uint32_t num_addrs;uint32_t num_harts;uint32_t bitfield_words; +uint32_t num_enables;PLICAddr *addr_config;uint32_t *source_priority;uint32_t *target_priority;
Signature · 1 line
2.19.1