mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2024-07-16 06:07:15 +00:00
devices, vmm: Move Pl011 to new restore design
Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
parent
0bd910e8b0
commit
9fbf52b998
@ -122,24 +122,79 @@ impl Pl011 {
|
|||||||
irq: Arc<dyn InterruptSourceGroup>,
|
irq: Arc<dyn InterruptSourceGroup>,
|
||||||
out: Option<Box<dyn io::Write + Send>>,
|
out: Option<Box<dyn io::Write + Send>>,
|
||||||
timestamp: Instant,
|
timestamp: Instant,
|
||||||
|
state: Option<Pl011State>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
|
let (
|
||||||
|
flags,
|
||||||
|
lcr,
|
||||||
|
rsr,
|
||||||
|
cr,
|
||||||
|
dmacr,
|
||||||
|
debug,
|
||||||
|
int_enabled,
|
||||||
|
int_level,
|
||||||
|
read_fifo,
|
||||||
|
ilpr,
|
||||||
|
ibrd,
|
||||||
|
fbrd,
|
||||||
|
ifl,
|
||||||
|
read_count,
|
||||||
|
read_trigger,
|
||||||
|
) = if let Some(state) = state {
|
||||||
|
(
|
||||||
|
state.flags,
|
||||||
|
state.lcr,
|
||||||
|
state.rsr,
|
||||||
|
state.cr,
|
||||||
|
state.dmacr,
|
||||||
|
state.debug,
|
||||||
|
state.int_enabled,
|
||||||
|
state.int_level,
|
||||||
|
state.read_fifo.into(),
|
||||||
|
state.ilpr,
|
||||||
|
state.ibrd,
|
||||||
|
state.fbrd,
|
||||||
|
state.ifl,
|
||||||
|
state.read_count,
|
||||||
|
state.read_trigger,
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
(
|
||||||
|
0x90,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0x300,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
VecDeque::new(),
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0x12,
|
||||||
|
0,
|
||||||
|
1,
|
||||||
|
)
|
||||||
|
};
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
id,
|
id,
|
||||||
flags: 0x90u32,
|
flags,
|
||||||
lcr: 0u32,
|
lcr,
|
||||||
rsr: 0u32,
|
rsr,
|
||||||
cr: 0x300u32,
|
cr,
|
||||||
dmacr: 0u32,
|
dmacr,
|
||||||
debug: 0u32,
|
debug,
|
||||||
int_enabled: 0u32,
|
int_enabled,
|
||||||
int_level: 0u32,
|
int_level,
|
||||||
read_fifo: VecDeque::new(),
|
read_fifo,
|
||||||
ilpr: 0u32,
|
ilpr,
|
||||||
ibrd: 0u32,
|
ibrd,
|
||||||
fbrd: 0u32,
|
fbrd,
|
||||||
ifl: 0x12u32,
|
ifl,
|
||||||
read_count: 0u32,
|
read_count,
|
||||||
read_trigger: 1u32,
|
read_trigger,
|
||||||
irq,
|
irq,
|
||||||
out,
|
out,
|
||||||
timestamp,
|
timestamp,
|
||||||
@ -170,24 +225,6 @@ impl Pl011 {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_state(&mut self, state: &Pl011State) {
|
|
||||||
self.flags = state.flags;
|
|
||||||
self.lcr = state.lcr;
|
|
||||||
self.rsr = state.rsr;
|
|
||||||
self.cr = state.cr;
|
|
||||||
self.dmacr = state.dmacr;
|
|
||||||
self.debug = state.debug;
|
|
||||||
self.int_enabled = state.int_enabled;
|
|
||||||
self.int_level = state.int_level;
|
|
||||||
self.read_fifo = state.read_fifo.clone().into();
|
|
||||||
self.ilpr = state.ilpr;
|
|
||||||
self.ibrd = state.ibrd;
|
|
||||||
self.fbrd = state.fbrd;
|
|
||||||
self.ifl = state.ifl;
|
|
||||||
self.read_count = state.read_count;
|
|
||||||
self.read_trigger = state.read_trigger;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Queues raw bytes for the guest to read and signals the interrupt
|
/// Queues raw bytes for the guest to read and signals the interrupt
|
||||||
pub fn queue_input_bytes(&mut self, c: &[u8]) -> vmm_sys_util::errno::Result<()> {
|
pub fn queue_input_bytes(&mut self, c: &[u8]) -> vmm_sys_util::errno::Result<()> {
|
||||||
self.read_fifo.extend(c);
|
self.read_fifo.extend(c);
|
||||||
@ -419,11 +456,6 @@ impl Snapshottable for Pl011 {
|
|||||||
fn snapshot(&mut self) -> std::result::Result<Snapshot, MigratableError> {
|
fn snapshot(&mut self) -> std::result::Result<Snapshot, MigratableError> {
|
||||||
Snapshot::new_from_versioned_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_versioned_state(&self.id)?);
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Pausable for Pl011 {}
|
impl Pausable for Pl011 {}
|
||||||
@ -498,6 +530,7 @@ mod tests {
|
|||||||
Arc::new(TestInterrupt::new(intr_evt.try_clone().unwrap())),
|
Arc::new(TestInterrupt::new(intr_evt.try_clone().unwrap())),
|
||||||
Some(Box::new(pl011_out.clone())),
|
Some(Box::new(pl011_out.clone())),
|
||||||
Instant::now(),
|
Instant::now(),
|
||||||
|
None,
|
||||||
);
|
);
|
||||||
|
|
||||||
pl011.write(0, UARTDR as u64, &[b'x', b'y']);
|
pl011.write(0, UARTDR as u64, &[b'x', b'y']);
|
||||||
@ -519,6 +552,7 @@ mod tests {
|
|||||||
Arc::new(TestInterrupt::new(intr_evt.try_clone().unwrap())),
|
Arc::new(TestInterrupt::new(intr_evt.try_clone().unwrap())),
|
||||||
Some(Box::new(pl011_out)),
|
Some(Box::new(pl011_out)),
|
||||||
Instant::now(),
|
Instant::now(),
|
||||||
|
None,
|
||||||
);
|
);
|
||||||
|
|
||||||
// write 1 to the interrupt event fd, so that read doesn't block in case the event fd
|
// write 1 to the interrupt event fd, so that read doesn't block in case the event fd
|
||||||
|
@ -1773,6 +1773,8 @@ impl DeviceManager {
|
|||||||
interrupt_group,
|
interrupt_group,
|
||||||
serial_writer,
|
serial_writer,
|
||||||
self.timestamp,
|
self.timestamp,
|
||||||
|
versioned_state_from_id(self.snapshot.as_ref(), id.as_str())
|
||||||
|
.map_err(DeviceManagerError::RestoreGetState)?,
|
||||||
)));
|
)));
|
||||||
|
|
||||||
self.bus_devices
|
self.bus_devices
|
||||||
|
Loading…
Reference in New Issue
Block a user