From 42e545806c0aa04f38060dbae35f6c67e5ec40c4 Mon Sep 17 00:00:00 2001 From: Samuel Ortiz Date: Wed, 3 Jul 2019 01:13:06 +0200 Subject: [PATCH] devices: bus: Return the range base address when resolving When resolving an IO address to a device, return the range base address, the offset, and the device itself. This is needed for devices with multiple IO regions to find out which region an IO/MMIO exit is coming from. We also use this change as an opportunity to rename get_device to resolve as we're doing more than just getting a device. Signed-off-by: Samuel Ortiz --- devices/src/bus.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/devices/src/bus.rs b/devices/src/bus.rs index 707a646ab..f24243909 100644 --- a/devices/src/bus.rs +++ b/devices/src/bus.rs @@ -97,11 +97,11 @@ impl Bus { Some((*range, dev)) } - pub fn get_device(&self, addr: u64) -> Option<(u64, &Mutex)> { + pub fn resolve(&self, addr: u64) -> Option<(u64, u64, &Mutex)> { if let Some((range, dev)) = self.first_before(addr) { let offset = addr - range.base; if offset < range.len { - return Some((offset, dev)); + return Some((range.base, offset, dev)); } } None @@ -137,7 +137,7 @@ impl Bus { /// /// Returns true on success, otherwise `data` is untouched. pub fn read(&self, addr: u64, data: &mut [u8]) -> bool { - if let Some((offset, dev)) = self.get_device(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") @@ -152,7 +152,7 @@ impl Bus { /// /// Returns true on success, otherwise `data` is untouched. pub fn write(&self, addr: u64, data: &[u8]) -> bool { - if let Some((offset, dev)) = self.get_device(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")