vmm: Add PCI root

Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
This commit is contained in:
Samuel Ortiz 2019-04-18 12:26:09 +02:00
parent e8308dd13b
commit 0adc3481df
3 changed files with 53 additions and 2 deletions

39
Cargo.lock generated
View File

@ -44,6 +44,11 @@ name = "byteorder"
version = "1.2.1" version = "1.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "cfg-if"
version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]] [[package]]
name = "clap" name = "clap"
version = "2.27.1" version = "2.27.1"
@ -113,6 +118,29 @@ dependencies = [
"vm-memory 0.1.0 (git+https://github.com/rust-vmm/vm-memory)", "vm-memory 0.1.0 (git+https://github.com/rust-vmm/vm-memory)",
] ]
[[package]]
name = "log"
version = "0.4.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "pci"
version = "0.1.0"
dependencies = [
"byteorder 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"devices 0.1.0",
"kvm-bindings 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"kvm-ioctls 0.1.0 (git+https://github.com/rust-vmm/kvm-ioctls)",
"libc 0.2.48 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
"vm-allocator 0.1.0",
"vm-memory 0.1.0 (git+https://github.com/rust-vmm/vm-memory)",
"vmm-sys-util 0.1.0 (git+https://github.com/sameo/vmm-sys-util)",
]
[[package]] [[package]]
name = "redox_syscall" name = "redox_syscall"
version = "0.1.51" version = "0.1.51"
@ -159,6 +187,14 @@ name = "vec_map"
version = "0.8.1" version = "0.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "vm-allocator"
version = "0.1.0"
dependencies = [
"libc 0.2.48 (registry+https://github.com/rust-lang/crates.io-index)",
"vm-memory 0.1.0 (git+https://github.com/rust-vmm/vm-memory)",
]
[[package]] [[package]]
name = "vm-memory" name = "vm-memory"
version = "0.1.0" version = "0.1.0"
@ -178,6 +214,7 @@ dependencies = [
"kvm-ioctls 0.1.0 (git+https://github.com/rust-vmm/kvm-ioctls)", "kvm-ioctls 0.1.0 (git+https://github.com/rust-vmm/kvm-ioctls)",
"libc 0.2.48 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.48 (registry+https://github.com/rust-lang/crates.io-index)",
"linux-loader 0.1.0 (git+https://github.com/sameo/linux-loader)", "linux-loader 0.1.0 (git+https://github.com/sameo/linux-loader)",
"pci 0.1.0",
"vm-memory 0.1.0 (git+https://github.com/rust-vmm/vm-memory)", "vm-memory 0.1.0 (git+https://github.com/rust-vmm/vm-memory)",
"vmm-sys-util 0.1.0 (git+https://github.com/sameo/vmm-sys-util)", "vmm-sys-util 0.1.0 (git+https://github.com/sameo/vmm-sys-util)",
] ]
@ -215,12 +252,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum bitflags 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4efd02e230a02e18f92fc2735f44597385ed02ad8f831e7c1c1156ee5e1ab3a5" "checksum bitflags 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4efd02e230a02e18f92fc2735f44597385ed02ad8f831e7c1c1156ee5e1ab3a5"
"checksum bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "228047a76f468627ca71776ecdebd732a3423081fcf5125585bcd7c49886ce12" "checksum bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "228047a76f468627ca71776ecdebd732a3423081fcf5125585bcd7c49886ce12"
"checksum byteorder 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "652805b7e73fada9d85e9a6682a4abd490cb52d96aeecc12e33a0de34dfd0d23" "checksum byteorder 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "652805b7e73fada9d85e9a6682a4abd490cb52d96aeecc12e33a0de34dfd0d23"
"checksum cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "11d43355396e872eefb45ce6342e4374ed7bc2b3a502d1b28e36d6e23c05d1f4"
"checksum clap 2.27.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1b8c532887f1a292d17de05ae858a8fe50a301e196f9ef0ddb7ccd0d1d00f180" "checksum clap 2.27.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1b8c532887f1a292d17de05ae858a8fe50a301e196f9ef0ddb7ccd0d1d00f180"
"checksum epoll 4.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f3f0680f2a6f2a17fa7a8668a27c54e45e1ad1cf8a632f56a7c19b9e4e3bbe8a" "checksum epoll 4.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f3f0680f2a6f2a17fa7a8668a27c54e45e1ad1cf8a632f56a7c19b9e4e3bbe8a"
"checksum kvm-bindings 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c223e8703d2eb76d990c5f58e29c85b0f6f50e24b823babde927948e7c71fc03" "checksum kvm-bindings 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c223e8703d2eb76d990c5f58e29c85b0f6f50e24b823babde927948e7c71fc03"
"checksum kvm-ioctls 0.1.0 (git+https://github.com/rust-vmm/kvm-ioctls)" = "<none>" "checksum kvm-ioctls 0.1.0 (git+https://github.com/rust-vmm/kvm-ioctls)" = "<none>"
"checksum libc 0.2.48 (registry+https://github.com/rust-lang/crates.io-index)" = "e962c7641008ac010fa60a7dfdc1712449f29c44ef2d4702394aea943ee75047" "checksum libc 0.2.48 (registry+https://github.com/rust-lang/crates.io-index)" = "e962c7641008ac010fa60a7dfdc1712449f29c44ef2d4702394aea943ee75047"
"checksum linux-loader 0.1.0 (git+https://github.com/sameo/linux-loader)" = "<none>" "checksum linux-loader 0.1.0 (git+https://github.com/sameo/linux-loader)" = "<none>"
"checksum log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c84ec4b527950aa83a329754b01dbe3f58361d1c5efacd1f6d68c494d08a17c6"
"checksum redox_syscall 0.1.51 (registry+https://github.com/rust-lang/crates.io-index)" = "423e376fffca3dfa06c9e9790a9ccd282fafb3cc6e6397d01dbf64f9bacc6b85" "checksum redox_syscall 0.1.51 (registry+https://github.com/rust-lang/crates.io-index)" = "423e376fffca3dfa06c9e9790a9ccd282fafb3cc6e6397d01dbf64f9bacc6b85"
"checksum redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76" "checksum redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76"
"checksum strsim 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b4d15c810519a91cf877e7e36e63fe068815c678181439f2f29e2562147c3694" "checksum strsim 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b4d15c810519a91cf877e7e36e63fe068815c678181439f2f29e2562147c3694"

View File

@ -11,6 +11,7 @@ epoll = "=4.0.1"
kvm-bindings = "0.1" kvm-bindings = "0.1"
kvm-ioctls = { git = "https://github.com/rust-vmm/kvm-ioctls" } kvm-ioctls = { git = "https://github.com/rust-vmm/kvm-ioctls" }
libc = ">=0.2.39" libc = ">=0.2.39"
pci = {path = "../pci"}
linux-loader = { git = "https://github.com/sameo/linux-loader" } linux-loader = { git = "https://github.com/sameo/linux-loader" }
vmm-sys-util = { git = "https://github.com/sameo/vmm-sys-util" } vmm-sys-util = { git = "https://github.com/sameo/vmm-sys-util" }

View File

@ -17,6 +17,7 @@ use kvm_ioctls::*;
use libc::{c_void, siginfo_t, EFD_NONBLOCK}; use libc::{c_void, siginfo_t, EFD_NONBLOCK};
use linux_loader::cmdline; use linux_loader::cmdline;
use linux_loader::loader::KernelLoader; use linux_loader::loader::KernelLoader;
use pci::{PciConfigIo, PciRoot};
use std::ffi::CString; use std::ffi::CString;
use std::fs::File; use std::fs::File;
use std::io::{self, stdout}; use std::io::{self, stdout};
@ -35,7 +36,7 @@ use vmm_sys_util::EventFd;
const VCPU_RTSIG_OFFSET: i32 = 0; const VCPU_RTSIG_OFFSET: i32 = 0;
pub const DEFAULT_VCPUS: u8 = 1; pub const DEFAULT_VCPUS: u8 = 1;
pub const DEFAULT_MEMORY: GuestUsize = 512; pub const DEFAULT_MEMORY: GuestUsize = 512;
const DEFAULT_CMDLINE: &str = "console=ttyS0 reboot=k panic=1 pci=off nomodules \ const DEFAULT_CMDLINE: &str = "console=ttyS0 reboot=k panic=1 nomodules \
i8042.noaux i8042.nomux i8042.nopnp i8042.dumbkbd"; i8042.noaux i8042.nomux i8042.nopnp i8042.dumbkbd";
const CMDLINE_OFFSET: GuestAddress = GuestAddress(0x20000); const CMDLINE_OFFSET: GuestAddress = GuestAddress(0x20000);
@ -217,6 +218,9 @@ struct DeviceManager {
// i8042 device for exit // i8042 device for exit
i8042: Arc<Mutex<devices::legacy::I8042Device>>, i8042: Arc<Mutex<devices::legacy::I8042Device>>,
exit_evt: EventFd, exit_evt: EventFd,
// PCI root
pci: Arc<Mutex<PciConfigIo>>,
} }
impl DeviceManager { impl DeviceManager {
@ -233,16 +237,19 @@ impl DeviceManager {
exit_evt.try_clone().map_err(Error::EventFd)?, exit_evt.try_clone().map_err(Error::EventFd)?,
))); )));
let pci_root = PciRoot::new(None);
let pci = Arc::new(Mutex::new(PciConfigIo::new(pci_root)));
Ok(DeviceManager { Ok(DeviceManager {
io_bus, io_bus,
serial, serial,
serial_evt, serial_evt,
i8042, i8042,
exit_evt, exit_evt,
pci,
}) })
} }
/// Register legacy devices.
pub fn register_devices(&mut self) -> Result<()> { pub fn register_devices(&mut self) -> Result<()> {
// Insert serial device // Insert serial device
self.io_bus self.io_bus
@ -254,6 +261,10 @@ impl DeviceManager {
.insert(self.i8042.clone(), 0x61, 0x4) .insert(self.i8042.clone(), 0x61, 0x4)
.map_err(Error::BusError)?; .map_err(Error::BusError)?;
// Insert the PCI root configuration space.
self.io_bus
.insert(self.pci.clone(), 0xcf8, 0x8)
.map_err(Error::BusError)?;
Ok(()) Ok(())
} }
} }