pci: Versionize PCI state

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
This commit is contained in:
Rob Bradford
2021-05-26 15:28:15 +00:00
committed by Sebastien Boeuf
parent cacec04df6
commit 3ffd2cb9be
5 changed files with 23 additions and 19 deletions
+10 -6
View File
@@ -7,7 +7,9 @@ use crate::{MsixConfig, PciInterruptPin};
use byteorder::{ByteOrder, LittleEndian};
use std::fmt::{self, Display};
use std::sync::{Arc, Mutex};
use vm_migration::{MigratableError, Pausable, Snapshot, Snapshottable};
use versionize::{VersionMap, Versionize, VersionizeError, VersionizeResult};
use versionize_derive::Versionize;
use vm_migration::{MigratableError, Pausable, Snapshot, Snapshottable, VersionMapped};
// The number of 32bit registers in the config space, 4096 bytes.
const NUM_CONFIGURATION_REGISTERS: usize = 1024;
@@ -276,7 +278,7 @@ fn decode_64_bits_bar_size(bar_size_hi: u32, bar_size_lo: u32) -> Option<u64> {
None
}
#[derive(Serialize, Deserialize, Default, Clone, Copy)]
#[derive(Default, Clone, Copy, Versionize)]
struct PciBar {
addr: u32,
size: u32,
@@ -284,7 +286,7 @@ struct PciBar {
r#type: Option<PciBarRegionType>,
}
#[derive(Serialize, Deserialize)]
#[derive(Versionize)]
struct PciConfigurationState {
registers: Vec<u32>,
writable_bits: Vec<u32>,
@@ -296,6 +298,8 @@ struct PciConfigurationState {
msix_cap_reg_idx: Option<usize>,
}
impl VersionMapped for PciConfigurationState {}
/// Contains the configuration space of a PCI node.
/// See the [specification](https://en.wikipedia.org/wiki/PCI_configuration_space).
/// The configuration space is accessed with DWORD reads and writes from the guest.
@@ -313,7 +317,7 @@ pub struct PciConfiguration {
}
/// See pci_regs.h in kernel
#[derive(Copy, Clone, PartialEq, Serialize, Deserialize)]
#[derive(Copy, Clone, PartialEq, Versionize)]
pub enum PciBarRegionType {
Memory32BitRegion = 0,
IoRegion = 0x01,
@@ -881,11 +885,11 @@ impl Snapshottable for PciConfiguration {
}
fn snapshot(&mut self) -> std::result::Result<Snapshot, MigratableError> {
Snapshot::new_from_state(&self.id(), &self.state())
Snapshot::new_from_versioned_state(&self.id(), &self.state())
}
fn restore(&mut self, snapshot: Snapshot) -> std::result::Result<(), MigratableError> {
self.set_state(&snapshot.to_state(&self.id())?);
self.set_state(&snapshot.to_versioned_state(&self.id())?);
Ok(())
}
}