xref: /cloud-hypervisor/hypervisor/src/mshv/aarch64/gic/mod.rs (revision 1968805ba291ae08e07abf0ef8c0ade4cf11ab68)
1 // SPDX-License-Identifier: Apache-2.0 OR BSD-3-Clause
2 //
3 // Copyright © 2025, Microsoft Corporation
4 //
5 use std::any::Any;
6 
7 use serde::{Deserialize, Serialize};
8 
9 use crate::arch::aarch64::gic::{GicState, Result, Vgic, VgicConfig};
10 use crate::{CpuState, Vm};
11 
12 pub struct MshvGicV2M {
13     /// GIC distributor address
14     pub dist_addr: u64,
15 
16     /// GIC distributor size
17     pub dist_size: u64,
18 
19     /// GIC re-distributors address
20     pub redists_addr: u64,
21 
22     /// GIC re-distributors size
23     pub redists_size: u64,
24 
25     /// GITS translator address
26     pub gits_addr: u64,
27 
28     /// GITS translator size
29     pub gits_size: u64,
30 
31     /// Number of CPUs handled by the device
32     pub vcpu_count: u64,
33 }
34 
35 #[derive(Clone, Default, Serialize, Deserialize)]
36 pub struct MshvGicV2MState {}
37 
38 impl From<GicState> for MshvGicV2MState {
39     fn from(state: GicState) -> Self {
40         match state {
41             GicState::MshvGicV2M(state) => state,
42             /* Needed in case other hypervisors are enabled */
43             #[allow(unreachable_patterns)]
44             _ => panic!("GicState is not valid"),
45         }
46     }
47 }
48 
49 impl From<MshvGicV2MState> for GicState {
50     fn from(state: MshvGicV2MState) -> Self {
51         GicState::MshvGicV2M(state)
52     }
53 }
54 
55 impl MshvGicV2M {
56     /// Create a new GICv2m device
57     pub fn new(_vm: &dyn Vm, config: VgicConfig) -> Result<MshvGicV2M> {
58         let gic_device = MshvGicV2M {
59             dist_addr: config.dist_addr,
60             dist_size: config.dist_size,
61             redists_addr: config.redists_addr,
62             redists_size: config.redists_size,
63             gits_addr: config.msi_addr,
64             gits_size: config.msi_size,
65             vcpu_count: config.vcpu_count,
66         };
67         Ok(gic_device)
68     }
69 }
70 
71 impl Vgic for MshvGicV2M {
72     fn fdt_compatibility(&self) -> &str {
73         "arm,gic-v3"
74     }
75 
76     fn msi_compatible(&self) -> bool {
77         true
78     }
79 
80     fn msi_compatibility(&self) -> &str {
81         "arm,gic-v2m-frame"
82     }
83 
84     fn fdt_maint_irq(&self) -> u32 {
85         0
86     }
87 
88     fn vcpu_count(&self) -> u64 {
89         self.vcpu_count
90     }
91 
92     fn msi_properties(&self) -> [u64; 2] {
93         [self.gits_addr, self.gits_size]
94     }
95 
96     fn device_properties(&self) -> [u64; 4] {
97         [
98             self.dist_addr,
99             self.dist_size,
100             self.redists_addr,
101             self.redists_size,
102         ]
103     }
104 
105     fn set_gicr_typers(&mut self, _vcpu_states: &[CpuState]) {
106         unimplemented!()
107     }
108 
109     fn state(&self) -> Result<GicState> {
110         unimplemented!()
111     }
112 
113     fn as_any_concrete_mut(&mut self) -> &mut dyn Any {
114         self
115     }
116 
117     fn set_state(&mut self, _state: &GicState) -> Result<()> {
118         unimplemented!()
119     }
120 
121     fn save_data_tables(&self) -> Result<()> {
122         unimplemented!()
123     }
124 }
125