summary refs log tree commit diff
diff options
context:
space:
mode:
authorAlyssa Ross <hi@alyssa.is>2020-03-14 00:17:26 +0000
committerAlyssa Ross <hi@alyssa.is>2020-06-15 09:36:51 +0000
commitc895e48de84f2a6b6f5b21e8037abef50e365a51 (patch)
tree77756aab4f39d7d36dd7c2040e982467335d08fe
parent4ccaa638e7e068e885ac2d9fedf7161ea8970514 (diff)
downloadcrosvm-c895e48de84f2a6b6f5b21e8037abef50e365a51.tar
crosvm-c895e48de84f2a6b6f5b21e8037abef50e365a51.tar.gz
crosvm-c895e48de84f2a6b6f5b21e8037abef50e365a51.tar.bz2
crosvm-c895e48de84f2a6b6f5b21e8037abef50e365a51.tar.lz
crosvm-c895e48de84f2a6b6f5b21e8037abef50e365a51.tar.xz
crosvm-c895e48de84f2a6b6f5b21e8037abef50e365a51.tar.zst
crosvm-c895e48de84f2a6b6f5b21e8037abef50e365a51.zip
get_device_bars
-rw-r--r--devices/src/pci/pci_configuration.rs7
-rw-r--r--devices/src/pci/pci_root.rs3
-rw-r--r--devices/src/virtio/controller.rs22
-rw-r--r--src/wl.rs7
4 files changed, 34 insertions, 5 deletions
diff --git a/devices/src/pci/pci_configuration.rs b/devices/src/pci/pci_configuration.rs
index ff2da1a..a0c92bd 100644
--- a/devices/src/pci/pci_configuration.rs
+++ b/devices/src/pci/pci_configuration.rs
@@ -6,6 +6,7 @@ use std::convert::TryInto;
 use std::fmt::{self, Display};
 
 use crate::pci::PciInterruptPin;
+use serde::{Deserialize, Serialize};
 use sys_util::warn;
 
 // The number of 32bit registers in the config space, 256 bytes.
@@ -178,20 +179,20 @@ pub struct PciConfiguration {
 }
 
 /// See pci_regs.h in kernel
-#[derive(Copy, Clone, Debug, Eq, PartialEq)]
+#[derive(Copy, Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
 pub enum PciBarRegionType {
     Memory32BitRegion = 0,
     IORegion = 0x01,
     Memory64BitRegion = 0x04,
 }
 
-#[derive(Copy, Clone, Debug, Eq, PartialEq)]
+#[derive(Copy, Clone, Debug, Eq, PartialEq, Deserialize, Serialize)]
 pub enum PciBarPrefetchable {
     NotPrefetchable = 0,
     Prefetchable = 0x08,
 }
 
-#[derive(Copy, Clone, Debug)]
+#[derive(Copy, Clone, Debug, Deserialize, Serialize)]
 pub struct PciBarConfiguration {
     addr: u64,
     size: u64,
diff --git a/devices/src/pci/pci_root.rs b/devices/src/pci/pci_root.rs
index 91d6094..0169793 100644
--- a/devices/src/pci/pci_root.rs
+++ b/devices/src/pci/pci_root.rs
@@ -8,6 +8,7 @@ use std::fmt::{self, Display};
 use std::os::unix::io::RawFd;
 use std::sync::Arc;
 
+use serde::{Deserialize, Serialize};
 use sync::Mutex;
 
 use crate::pci::pci_configuration::{
@@ -42,7 +43,7 @@ impl PciDevice for PciRootConfiguration {
 }
 
 /// PCI Device Address, AKA Bus:Device.Function
-#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
+#[derive(Clone, Copy, Debug, Deserialize, Eq, Ord, PartialEq, PartialOrd, Serialize)]
 pub struct PciAddress {
     pub bus: u8,
     pub dev: u8,  /* u5 */
diff --git a/devices/src/virtio/controller.rs b/devices/src/virtio/controller.rs
index 7a5ab71..33dbdd4 100644
--- a/devices/src/virtio/controller.rs
+++ b/devices/src/virtio/controller.rs
@@ -36,7 +36,10 @@ use std::thread;
 
 use super::resource_bridge::*;
 use super::{Interrupt, InterruptProxyEvent, Queue, VirtioDevice, TYPE_WL, VIRTIO_F_VERSION_1};
-use crate::MemoryParams;
+use crate::{
+    pci::{PciAddress, PciBarConfiguration},
+    MemoryParams,
+};
 use vm_control::{MaybeOwnedFd, VmMemoryControlRequestSocket};
 
 use msg_socket::{MsgOnSocket, MsgReceiver, MsgSocket};
@@ -74,6 +77,8 @@ pub enum MsgOnSocketRequest {
 pub enum BincodeRequest {
     ReadConfig { offset: u64, len: usize },
     WriteConfig { offset: u64, data: Vec<u8> },
+
+    GetDeviceBars(PciAddress),
 }
 
 pub type Request = poly_msg_socket::Value<MsgOnSocketRequest, BincodeRequest>;
@@ -99,6 +104,8 @@ pub enum MsgOnSocketResponse {
 #[derive(Debug, Deserialize, Serialize)]
 pub enum BincodeResponse {
     ReadConfig(Vec<u8>),
+
+    GetDeviceBars(Vec<PciBarConfiguration>),
 }
 
 pub type Response = poly_msg_socket::Value<MsgOnSocketResponse, BincodeResponse>;
@@ -386,4 +393,17 @@ impl VirtioDevice for Controller {
             }
         }
     }
+
+    fn get_device_bars(&mut self, address: PciAddress) -> Vec<PciBarConfiguration> {
+        if let Err(e) = self.socket.send(BincodeRequest::GetDeviceBars(address)) {
+            panic!("failed to send GetDeviceBars: {}", e);
+        }
+
+        match self.socket.recv_bincode() {
+            Ok(BincodeResponse::GetDeviceBars(bars)) => bars,
+            response => {
+                panic!("bad response to GetDeviceBars: {:?}", response);
+            }
+        }
+    }
 }
diff --git a/src/wl.rs b/src/wl.rs
index 169edb2..5576acb 100644
--- a/src/wl.rs
+++ b/src/wl.rs
@@ -118,6 +118,13 @@ fn main() {
                 }
             }
 
+            Ok(Bincode(BincodeRequest::GetDeviceBars(address))) => {
+                let result = wl.get_device_bars(address);
+                if let Err(e) = msg_socket.send(BincodeResponse::GetDeviceBars(result)) {
+                    panic!("responding to GetDeviceBars failed: {}", e);
+                }
+            }
+
             Ok(MsgOnSocket(msg @ MsgOnSocketRequest::Create { .. })) => {
                 panic!("unexpected message {:?}", msg)
             }