mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2025-01-03 03:15:20 +00:00
pci: msi: Move MsiConfig to the new restore design
Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
parent
d6bf1f5eb0
commit
1eac37bd5f
@ -39,13 +39,15 @@ pub fn msi_num_enabled_vectors(msg_ctl: u16) -> usize {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Error, Debug)]
|
#[derive(Error, Debug)]
|
||||||
enum Error {
|
pub enum Error {
|
||||||
#[error("Failed enabling the interrupt route: {0}")]
|
#[error("Failed enabling the interrupt route: {0}")]
|
||||||
EnableInterruptRoute(io::Error),
|
EnableInterruptRoute(io::Error),
|
||||||
#[error("Failed updating the interrupt route: {0}")]
|
#[error("Failed updating the interrupt route: {0}")]
|
||||||
UpdateInterruptRoute(io::Error),
|
UpdateInterruptRoute(io::Error),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub const MSI_CONFIG_ID: &str = "msi_config";
|
||||||
|
|
||||||
#[derive(Clone, Copy, Default, Versionize)]
|
#[derive(Clone, Copy, Default, Versionize)]
|
||||||
pub struct MsiCap {
|
pub struct MsiCap {
|
||||||
// Message Control Register
|
// Message Control Register
|
||||||
@ -172,7 +174,7 @@ impl MsiCap {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Versionize)]
|
#[derive(Versionize)]
|
||||||
struct MsiConfigState {
|
pub struct MsiConfigState {
|
||||||
cap: MsiCap,
|
cap: MsiCap,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -184,16 +186,47 @@ pub struct MsiConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl MsiConfig {
|
impl MsiConfig {
|
||||||
pub fn new(msg_ctl: u16, interrupt_source_group: Arc<dyn InterruptSourceGroup>) -> Self {
|
pub fn new(
|
||||||
let cap = MsiCap {
|
msg_ctl: u16,
|
||||||
msg_ctl,
|
interrupt_source_group: Arc<dyn InterruptSourceGroup>,
|
||||||
..Default::default()
|
state: Option<MsiConfigState>,
|
||||||
|
) -> Result<Self, Error> {
|
||||||
|
let cap = if let Some(state) = state {
|
||||||
|
if state.cap.enabled() {
|
||||||
|
for idx in 0..state.cap.num_enabled_vectors() {
|
||||||
|
let config = MsiIrqSourceConfig {
|
||||||
|
high_addr: state.cap.msg_addr_hi,
|
||||||
|
low_addr: state.cap.msg_addr_lo,
|
||||||
|
data: state.cap.msg_data as u32,
|
||||||
|
devid: 0,
|
||||||
|
};
|
||||||
|
|
||||||
|
interrupt_source_group
|
||||||
|
.update(
|
||||||
|
idx as InterruptIndex,
|
||||||
|
InterruptSourceConfig::MsiIrq(config),
|
||||||
|
state.cap.vector_masked(idx),
|
||||||
|
)
|
||||||
|
.map_err(Error::UpdateInterruptRoute)?;
|
||||||
|
}
|
||||||
|
|
||||||
|
interrupt_source_group
|
||||||
|
.enable()
|
||||||
|
.map_err(Error::EnableInterruptRoute)?;
|
||||||
|
}
|
||||||
|
|
||||||
|
state.cap
|
||||||
|
} else {
|
||||||
|
MsiCap {
|
||||||
|
msg_ctl,
|
||||||
|
..Default::default()
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
MsiConfig {
|
Ok(MsiConfig {
|
||||||
cap,
|
cap,
|
||||||
interrupt_source_group,
|
interrupt_source_group,
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn state(&self) -> MsiConfigState {
|
fn state(&self) -> MsiConfigState {
|
||||||
@ -281,7 +314,7 @@ impl Pausable for MsiConfig {}
|
|||||||
|
|
||||||
impl Snapshottable for MsiConfig {
|
impl Snapshottable for MsiConfig {
|
||||||
fn id(&self) -> String {
|
fn id(&self) -> String {
|
||||||
String::from("msi_config")
|
String::from(MSI_CONFIG_ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn snapshot(&mut self) -> std::result::Result<Snapshot, MigratableError> {
|
fn snapshot(&mut self) -> std::result::Result<Snapshot, MigratableError> {
|
||||||
|
@ -735,7 +735,7 @@ impl VfioCommon {
|
|||||||
})
|
})
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let msi_config = MsiConfig::new(msg_ctl, interrupt_source_group.clone());
|
let msi_config = MsiConfig::new(msg_ctl, interrupt_source_group.clone(), None).unwrap();
|
||||||
|
|
||||||
self.interrupt.msi = Some(VfioMsi {
|
self.interrupt.msi = Some(VfioMsi {
|
||||||
cfg: msi_config,
|
cfg: msi_config,
|
||||||
|
Loading…
Reference in New Issue
Block a user