diff options
author | Gurchetan Singh <gurchetansingh@chromium.org> | 2019-09-16 17:59:56 -0700 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2019-09-20 16:55:31 +0000 |
commit | b2d4e11579b23e84ef62290600337084a64770c4 (patch) | |
tree | 0e4be6226673fdb010c59bdc9b75e12ca8f17a11 | |
parent | aa781bafdf1641e6c36e340a9a7e97aa50536eea (diff) | |
download | crosvm-b2d4e11579b23e84ef62290600337084a64770c4.tar crosvm-b2d4e11579b23e84ef62290600337084a64770c4.tar.gz crosvm-b2d4e11579b23e84ef62290600337084a64770c4.tar.bz2 crosvm-b2d4e11579b23e84ef62290600337084a64770c4.tar.lz crosvm-b2d4e11579b23e84ef62290600337084a64770c4.tar.xz crosvm-b2d4e11579b23e84ef62290600337084a64770c4.tar.zst crosvm-b2d4e11579b23e84ef62290600337084a64770c4.zip |
devices: modify get_device_bars(..) interface
Alloc::PciBar {..} is used as a key in the AddressAllocator's hashmap, so inform the device about the pci bus/dev numbers. BUG=chromium:924405 TEST=compile Change-Id: Ib9d94e516269c1dc9a375c2ceb9775cf5a421156 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1811585 Reviewed-by: Daniel Verkamp <dverkamp@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Tested-by: Gurchetan Singh <gurchetansingh@chromium.org> Commit-Queue: Gurchetan Singh <gurchetansingh@chromium.org>
-rw-r--r-- | devices/src/virtio/gpu/backend.rs | 5 | ||||
-rw-r--r-- | devices/src/virtio/gpu/mod.rs | 26 | ||||
-rw-r--r-- | devices/src/virtio/virtio_device.rs | 2 | ||||
-rw-r--r-- | devices/src/virtio/virtio_pci_device.rs | 2 |
4 files changed, 25 insertions, 10 deletions
diff --git a/devices/src/virtio/gpu/backend.rs b/devices/src/virtio/gpu/backend.rs index b93547d..9415226 100644 --- a/devices/src/virtio/gpu/backend.rs +++ b/devices/src/virtio/gpu/backend.rs @@ -14,6 +14,7 @@ use std::usize; use data_model::*; use msg_socket::{MsgReceiver, MsgSender}; +use resources::Alloc; use sys_util::{error, GuestAddress, GuestMemory}; use gpu_display::*; @@ -148,6 +149,8 @@ pub struct Backend { cursor_surface: Option<u32>, scanout_resource: u32, cursor_resource: u32, + #[allow(dead_code)] + pci_bar: Alloc, } impl Backend { @@ -160,6 +163,7 @@ impl Backend { display: GpuDisplay, renderer: Renderer, gpu_device_socket: VmMemoryControlRequestSocket, + pci_bar: Alloc, ) -> Backend { Backend { display: Rc::new(RefCell::new(display)), @@ -171,6 +175,7 @@ impl Backend { cursor_surface: None, scanout_resource: 0, cursor_resource: 0, + pci_bar, } } diff --git a/devices/src/virtio/gpu/mod.rs b/devices/src/virtio/gpu/mod.rs index 491a058..b229cb5 100644 --- a/devices/src/virtio/gpu/mod.rs +++ b/devices/src/virtio/gpu/mod.rs @@ -27,6 +27,8 @@ use sys_util::{ use gpu_display::*; use gpu_renderer::{Renderer, RendererFlags}; +use resources::Alloc; + use super::{ copy_config, resource_bridge::*, DescriptorChain, Queue, Reader, VirtioDevice, Writer, INTERRUPT_STATUS_USED_RING, TYPE_GPU, VIRTIO_F_VERSION_1, @@ -577,6 +579,7 @@ impl DisplayBackend { fn build_backend( possible_displays: &[DisplayBackend], gpu_device_socket: VmMemoryControlRequestSocket, + pci_bar: Alloc, ) -> Option<Backend> { let mut renderer_flags = RendererFlags::default(); let mut display_opt = None; @@ -620,7 +623,7 @@ fn build_backend( } }; - Some(Backend::new(display, renderer, gpu_device_socket)) + Some(Backend::new(display, renderer, gpu_device_socket, pci_bar)) } pub struct Gpu { @@ -632,6 +635,7 @@ pub struct Gpu { worker_thread: Option<thread::JoinHandle<()>>, num_scanouts: NonZeroU8, display_backends: Vec<DisplayBackend>, + pci_bar: Option<Alloc>, } impl Gpu { @@ -651,6 +655,7 @@ impl Gpu { worker_thread: None, num_scanouts, display_backends, + pci_bar: None, } } @@ -770,15 +775,18 @@ impl VirtioDevice for Gpu { let cursor_queue = queues.remove(0); let cursor_evt = queue_evts.remove(0); let display_backends = self.display_backends.clone(); - if let Some(gpu_device_socket) = self.gpu_device_socket.take() { + if let (Some(gpu_device_socket), Some(pci_bar)) = + (self.gpu_device_socket.take(), self.pci_bar.take()) + { let worker_result = thread::Builder::new() .name("virtio_gpu".to_string()) .spawn(move || { - let backend = match build_backend(&display_backends, gpu_device_socket) { - Some(backend) => backend, - None => return, - }; + let backend = + match build_backend(&display_backends, gpu_device_socket, pci_bar) { + Some(backend) => backend, + None => return, + }; Worker { exit_evt, @@ -810,9 +818,11 @@ impl VirtioDevice for Gpu { } // Require 1 BAR for mapping 3D buffers - fn get_device_bars(&self) -> Vec<PciBarConfiguration> { + fn get_device_bars(&mut self, bus: u8, dev: u8) -> Vec<PciBarConfiguration> { + let bar: u8 = 4; + self.pci_bar = Some(Alloc::PciBar { bus, dev, bar }); vec![PciBarConfiguration::new( - 4, + bar as usize, 1 << 33, PciBarRegionType::Memory64BitRegion, PciBarPrefetchable::NotPrefetchable, diff --git a/devices/src/virtio/virtio_device.rs b/devices/src/virtio/virtio_device.rs index d5d5266..d024d33 100644 --- a/devices/src/virtio/virtio_device.rs +++ b/devices/src/virtio/virtio_device.rs @@ -77,7 +77,7 @@ pub trait VirtioDevice: Send { } /// Returns any additional BAR configuration required by the device. - fn get_device_bars(&self) -> Vec<PciBarConfiguration> { + fn get_device_bars(&mut self, _bus: u8, _dev: u8) -> Vec<PciBarConfiguration> { Vec::new() } diff --git a/devices/src/virtio/virtio_pci_device.rs b/devices/src/virtio/virtio_pci_device.rs index 7da2e45..f99b753 100644 --- a/devices/src/virtio/virtio_pci_device.rs +++ b/devices/src/virtio/virtio_pci_device.rs @@ -375,7 +375,7 @@ impl PciDevice for VirtioPciDevice { .pci_bus_dev .expect("assign_bus_dev must be called prior to allocate_device_bars"); let mut ranges = Vec::new(); - for config in self.device.get_device_bars() { + for config in self.device.get_device_bars(bus, dev) { let device_addr = resources .device_allocator() .allocate_with_align( |