mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
devices: Extend the Bus trait to carry the device range base
With the range base for the IO/MMIO vm exit address, a device with multiple ranges has all the needed information for resolving which of its range the exit is coming from Fixes: #87 Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
This commit is contained in:
@@ -19,9 +19,9 @@ use std::sync::{Arc, Mutex};
|
||||
#[allow(unused_variables)]
|
||||
pub trait BusDevice: Send {
|
||||
/// Reads at `offset` from this device
|
||||
fn read(&mut self, offset: u64, data: &mut [u8]) {}
|
||||
fn read(&mut self, base: u64, offset: u64, data: &mut [u8]) {}
|
||||
/// Writes at `offset` into this device
|
||||
fn write(&mut self, offset: u64, data: &[u8]) {}
|
||||
fn write(&mut self, base: u64, offset: u64, data: &[u8]) {}
|
||||
/// Triggers the `irq_mask` interrupt on this device
|
||||
fn interrupt(&self, irq_mask: u32) {}
|
||||
}
|
||||
@@ -137,11 +137,11 @@ impl Bus {
|
||||
///
|
||||
/// Returns true on success, otherwise `data` is untouched.
|
||||
pub fn read(&self, addr: u64, data: &mut [u8]) -> bool {
|
||||
if let Some((_base, offset, dev)) = self.resolve(addr) {
|
||||
if let Some((base, offset, dev)) = self.resolve(addr) {
|
||||
// OK to unwrap as lock() failing is a serious error condition and should panic.
|
||||
dev.lock()
|
||||
.expect("Failed to acquire device lock")
|
||||
.read(offset, data);
|
||||
.read(base, offset, data);
|
||||
true
|
||||
} else {
|
||||
false
|
||||
@@ -152,11 +152,11 @@ impl Bus {
|
||||
///
|
||||
/// Returns true on success, otherwise `data` is untouched.
|
||||
pub fn write(&self, addr: u64, data: &[u8]) -> bool {
|
||||
if let Some((_base, offset, dev)) = self.resolve(addr) {
|
||||
if let Some((base, offset, dev)) = self.resolve(addr) {
|
||||
// OK to unwrap as lock() failing is a serious error condition and should panic.
|
||||
dev.lock()
|
||||
.expect("Failed to acquire device lock")
|
||||
.write(offset, data);
|
||||
.write(base, offset, data);
|
||||
true
|
||||
} else {
|
||||
false
|
||||
|
||||
Reference in New Issue
Block a user