11// Copyright 2025 Amazon.com, Inc. or its affiliates. All Rights Reserved.
22// SPDX-License-Identifier: Apache-2.0
33
4- use kvm_bindings:: { kvm_mp_state, kvm_vcpu_init} ;
54use serde:: { Deserialize , Serialize } ;
65
7- use crate :: convert:: { ConvertError , irq_to_gsi} ;
8- use crate :: v1_12;
6+ use super :: { ACPIDeviceManagerState , ConvertError , GuestMemoryState , MMIODeviceInfo ,
7+ ResourceAllocator , irq_to_gsi} ;
8+ use crate :: devices:: acpi:: vmgenid:: VMGenIDState ;
9+ use crate :: persist:: v1_12;
910
10- use super :: {
11- ACPIDeviceManagerState , GuestMemoryState , MMIODeviceInfo , ResourceAllocator , VMGenIDState ,
12- } ;
11+ // ───────────────────────────────────────────────────────────────────
12+ // Re-export runtime types — v1.14 snapshot format matches the runtime format.
13+ // These are used by v1.12 (and v1.10 via v1.12) as canonical type definitions.
14+ // ───────────────────────────────────────────────────────────────────
15+
16+ pub use crate :: arch:: aarch64:: gic:: { GicRegState , GicState , GicVcpuState } ;
17+ pub use crate :: arch:: aarch64:: regs:: Aarch64RegisterVec ;
18+ pub use crate :: arch:: aarch64:: vcpu:: VcpuState ;
19+ pub use crate :: arch:: aarch64:: vm:: VmState ;
1320
1421// ───────────────────────────────────────────────────────────────────
15- // StaticCpuTemplate — canonical definition (identical in v1.10, v1.12, v1.14)
22+ // StaticCpuTemplate — aarch64-specific snapshot enum (same in v1.10, v1.12, v1.14)
1623// ───────────────────────────────────────────────────────────────────
1724
1825#[ derive( Debug , Default , Clone , PartialEq , Eq , Serialize , Deserialize ) ]
@@ -23,7 +30,7 @@ pub enum StaticCpuTemplate {
2330}
2431
2532// ───────────────────────────────────────────────────────────────────
26- // aarch64 legacy device types — canonical definitions
33+ // DeviceType — aarch64 legacy device type enum (snapshot format)
2734// ───────────────────────────────────────────────────────────────────
2835
2936#[ derive( Debug , Clone , Serialize , Deserialize ) ]
@@ -33,94 +40,34 @@ pub enum DeviceType {
3340 Rtc ,
3441}
3542
36- // ───────────────────────────────────────────────────────────────────
37- // GIC helper types — canonical definitions (unchanged since v1.10)
38- // ───────────────────────────────────────────────────────────────────
39-
40- #[ derive( Debug , Clone , Serialize , Deserialize ) ]
41- #[ serde( bound( serialize = "T: Serialize" , deserialize = "T: for<'a> Deserialize<'a>" ) ) ]
42- pub struct GicRegState < T : Serialize + for < ' a > Deserialize < ' a > > {
43- pub chunks : Vec < T > ,
44- }
45-
46- #[ derive( Debug , Clone , Serialize , Deserialize ) ]
47- pub struct VgicSysRegsState {
48- pub main_icc_regs : Vec < GicRegState < u64 > > ,
49- pub ap_icc_regs : Vec < Option < GicRegState < u64 > > > ,
50- }
51-
52- #[ derive( Debug , Clone , Serialize , Deserialize ) ]
53- pub struct GicVcpuState {
54- pub rdist : Vec < GicRegState < u32 > > ,
55- pub icc : VgicSysRegsState ,
56- }
57-
58- // ───────────────────────────────────────────────────────────────────
59- // aarch64 register vector — canonical definition (unchanged since v1.10)
60- // ───────────────────────────────────────────────────────────────────
61-
62- /// aarch64 register vector with custom serde: serialized as (Vec<u64>, Vec<u8>)
63- #[ derive( Debug , Clone ) ]
64- pub struct Aarch64RegisterVec {
65- pub ids : Vec < u64 > ,
66- pub data : Vec < u8 > ,
67- }
68-
69- impl Serialize for Aarch64RegisterVec {
70- fn serialize < S : serde:: Serializer > ( & self , serializer : S ) -> Result < S :: Ok , S :: Error > {
71- ( & self . ids , & self . data ) . serialize ( serializer)
72- }
73- }
74-
75- impl < ' de > Deserialize < ' de > for Aarch64RegisterVec {
76- fn deserialize < D : serde:: Deserializer < ' de > > ( deserializer : D ) -> Result < Self , D :: Error > {
77- let ( ids, data) = <( Vec < u64 > , Vec < u8 > ) >:: deserialize ( deserializer) ?;
78- Ok ( Aarch64RegisterVec { ids, data } )
43+ impl From < DeviceType > for crate :: arch:: DeviceType {
44+ fn from ( dt : DeviceType ) -> Self {
45+ match dt {
46+ DeviceType :: Virtio ( n) => crate :: arch:: DeviceType :: Virtio ( n) ,
47+ DeviceType :: Serial => crate :: arch:: DeviceType :: Serial ,
48+ DeviceType :: Rtc => crate :: arch:: DeviceType :: Rtc ,
49+ }
7950 }
8051}
8152
8253// ───────────────────────────────────────────────────────────────────
83- // aarch64 ConnectedLegacyState (uses updated MMIODeviceInfo with gsi)
54+ // ConnectedLegacyState — convert v1.12 snapshot type to runtime type
8455// ───────────────────────────────────────────────────────────────────
8556
86- #[ derive( Debug , Clone , Serialize , Deserialize ) ]
87- pub struct ConnectedLegacyState {
88- pub type_ : DeviceType ,
89- pub device_info : MMIODeviceInfo ,
90- }
91-
92- impl From < v1_12:: ConnectedLegacyState > for ConnectedLegacyState {
57+ impl From < v1_12:: ConnectedLegacyState > for crate :: device_manager:: persist:: ConnectedLegacyState {
9358 fn from ( s : v1_12:: ConnectedLegacyState ) -> Self {
94- ConnectedLegacyState {
95- type_ : s. type_ ,
59+ crate :: device_manager :: persist :: ConnectedLegacyState {
60+ type_ : crate :: arch :: DeviceType :: from ( s. type_ ) ,
9661 device_info : MMIODeviceInfo :: from ( s. device_info ) ,
9762 }
9863 }
9964}
10065
10166// ───────────────────────────────────────────────────────────────────
102- // aarch64 GIC state (v1.14: adds its_state)
103- // GicRegState, VgicSysRegsState, GicVcpuState are defined above
67+ // GIC state (aarch64, v1.14: adds its_state)
68+ // GicState is the runtime type (re-exported above); conversion from v1.12 is here.
10469// ───────────────────────────────────────────────────────────────────
10570
106- #[ derive( Debug , Clone , Serialize , Deserialize ) ]
107- pub struct ItsRegisterState {
108- pub iidr : u64 ,
109- pub cbaser : u64 ,
110- pub creadr : u64 ,
111- pub cwriter : u64 ,
112- pub baser : [ u64 ; 8 ] ,
113- pub ctlr : u64 ,
114- }
115-
116- #[ derive( Debug , Clone , Serialize , Deserialize ) ]
117- pub struct GicState {
118- pub dist : Vec < GicRegState < u32 > > ,
119- pub gic_vcpu_states : Vec < GicVcpuState > ,
120- /// ITS state (GICv3 only). None for GICv2 or when converted from v1.12.
121- pub its_state : Option < ItsRegisterState > ,
122- }
123-
12471impl GicState {
12572 pub ( crate ) fn from ( old_state : v1_12:: GicState ) -> GicState {
12673 GicState {
@@ -133,17 +80,9 @@ impl GicState {
13380
13481// ───────────────────────────────────────────────────────────────────
13582// vCPU state (aarch64, v1.14: gains pvtime_ipa)
83+ // VcpuState is the runtime type (re-exported above); conversion from v1.12 is here.
13684// ───────────────────────────────────────────────────────────────────
13785
138- #[ derive( Debug , Clone , Serialize , Deserialize ) ]
139- pub struct VcpuState {
140- pub mp_state : kvm_mp_state ,
141- pub regs : Aarch64RegisterVec ,
142- pub mpidr : u64 ,
143- pub kvi : kvm_vcpu_init ,
144- pub pvtime_ipa : Option < u64 > ,
145- }
146-
14786impl VcpuState {
14887 pub ( crate ) fn from ( old_state : v1_12:: VcpuState ) -> VcpuState {
14988 VcpuState {
@@ -157,7 +96,7 @@ impl VcpuState {
15796}
15897
15998// ───────────────────────────────────────────────────────────────────
160- // ACPI device state impl (aarch64: no vmclock)
99+ // ACPI device state (aarch64: no vmclock)
161100// ───────────────────────────────────────────────────────────────────
162101
163102impl ACPIDeviceManagerState {
@@ -178,15 +117,9 @@ impl ACPIDeviceManagerState {
178117
179118// ───────────────────────────────────────────────────────────────────
180119// VM state (aarch64, v1.14: adds resource_allocator)
120+ // VmState is the runtime type (re-exported above); conversion from v1.12 is here.
181121// ───────────────────────────────────────────────────────────────────
182122
183- #[ derive( Debug , Clone , Serialize , Deserialize ) ]
184- pub struct VmState {
185- pub memory : GuestMemoryState ,
186- pub gic : GicState ,
187- pub resource_allocator : ResourceAllocator ,
188- }
189-
190123impl VmState {
191124 pub ( crate ) fn from (
192125 old_state : v1_12:: VmState ,
0 commit comments