mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2024-10-02 11:35:46 +00:00
pci: Extend the Device trait to carry the device BARs
When reading from or writing to a PCI BAR to handle a VM exit, we need to have the BAR address itself to be able to support multiple BARs PCI devices. Fixes: #87 Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
This commit is contained in:
parent
8173e1ccd7
commit
4605ecf1a8
@ -90,11 +90,11 @@ pub trait PciDevice: BusDevice {
|
|||||||
/// Reads from a BAR region mapped in to the device.
|
/// Reads from a BAR region mapped in to the device.
|
||||||
/// * `addr` - The guest address inside the BAR.
|
/// * `addr` - The guest address inside the BAR.
|
||||||
/// * `data` - Filled with the data from `addr`.
|
/// * `data` - Filled with the data from `addr`.
|
||||||
fn read_bar(&mut self, addr: u64, data: &mut [u8]);
|
fn read_bar(&mut self, base: u64, offset: u64, data: &mut [u8]);
|
||||||
/// Writes to a BAR region mapped in to the device.
|
/// Writes to a BAR region mapped in to the device.
|
||||||
/// * `addr` - The guest address inside the BAR.
|
/// * `addr` - The guest address inside the BAR.
|
||||||
/// * `data` - The data to write.
|
/// * `data` - The data to write.
|
||||||
fn write_bar(&mut self, addr: u64, data: &[u8]);
|
fn write_bar(&mut self, base: u64, offset: u64, data: &[u8]);
|
||||||
/// Invoked when the device is sandboxed.
|
/// Invoked when the device is sandboxed.
|
||||||
fn on_device_sandboxed(&mut self) {}
|
fn on_device_sandboxed(&mut self) {}
|
||||||
}
|
}
|
||||||
|
@ -480,7 +480,7 @@ impl PciDevice for VirtioPciDevice {
|
|||||||
Ok(ranges)
|
Ok(ranges)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn read_bar(&mut self, offset: u64, data: &mut [u8]) {
|
fn read_bar(&mut self, _base: u64, offset: u64, data: &mut [u8]) {
|
||||||
match offset {
|
match offset {
|
||||||
o if o < COMMON_CONFIG_BAR_OFFSET + COMMON_CONFIG_SIZE => self.common_config.read(
|
o if o < COMMON_CONFIG_BAR_OFFSET + COMMON_CONFIG_SIZE => self.common_config.read(
|
||||||
o - COMMON_CONFIG_BAR_OFFSET,
|
o - COMMON_CONFIG_BAR_OFFSET,
|
||||||
@ -524,7 +524,7 @@ impl PciDevice for VirtioPciDevice {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn write_bar(&mut self, offset: u64, data: &[u8]) {
|
fn write_bar(&mut self, _base: u64, offset: u64, data: &[u8]) {
|
||||||
match offset {
|
match offset {
|
||||||
o if o < COMMON_CONFIG_BAR_OFFSET + COMMON_CONFIG_SIZE => self.common_config.write(
|
o if o < COMMON_CONFIG_BAR_OFFSET + COMMON_CONFIG_SIZE => self.common_config.write(
|
||||||
o - COMMON_CONFIG_BAR_OFFSET,
|
o - COMMON_CONFIG_BAR_OFFSET,
|
||||||
@ -607,11 +607,11 @@ impl PciDevice for VirtioPciDevice {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl BusDevice for VirtioPciDevice {
|
impl BusDevice for VirtioPciDevice {
|
||||||
fn read(&mut self, _base: u64, offset: u64, data: &mut [u8]) {
|
fn read(&mut self, base: u64, offset: u64, data: &mut [u8]) {
|
||||||
self.read_bar(offset, data)
|
self.read_bar(base, offset, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn write(&mut self, _base: u64, offset: u64, data: &[u8]) {
|
fn write(&mut self, base: u64, offset: u64, data: &[u8]) {
|
||||||
self.write_bar(offset, data)
|
self.write_bar(base, offset, data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user