From 4bbda21f0bcf6c024516dffaccf2d1ad12c23e90 Mon Sep 17 00:00:00 2001 From: Anhad Singh Date: Thu, 29 Jun 2023 16:37:59 +1000 Subject: [PATCH] drivers: start building `virtio-gpu` Signed-off-by: Anhad Singh --- Cargo.lock | 10 ++++++++++ Cargo.toml | 1 + README.md | 2 +- initfs.toml | 9 +++++++++ virtio-core/src/utils.rs | 4 ++++ virtio-gpud/Cargo.toml | 13 +++++++++++++ virtio-gpud/src/main.rs | 28 ++++++++++++++++++++++++++++ 7 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 virtio-gpud/Cargo.toml create mode 100644 virtio-gpud/src/main.rs diff --git a/Cargo.lock b/Cargo.lock index cc75943e6c..69722a682a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1948,6 +1948,16 @@ dependencies = [ "thiserror", ] +[[package]] +name = "virtio-gpud" +version = "0.1.0" +dependencies = [ + "log", + "pcid", + "redox-daemon", + "virtio-core", +] + [[package]] name = "virtio-netd" version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml index 717d492594..2ccefbc9b4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,6 +25,7 @@ members = [ "virtio-blkd", "virtio-netd", + "virtio-gpud", "virtio-core", ] diff --git a/README.md b/README.md index 0262ed8d1b..72e8c1788d 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ These are the currently implemented devices/hardware interfaces. - usbctl - USB control (incomplete). - usbhidd - USB HID (incomplete). - usbscsid - USB SCSI (incomplete). -- virtio-* - VirtIO (incomplete) (`virtio-blk`, `virtio-net`). +- virtio-* - VirtIO (incomplete) (`virtio-blk`, `virtio-net`, `virtio-gpu`). ## Contributing to Drivers diff --git a/initfs.toml b/initfs.toml index 067001a19d..631768911d 100644 --- a/initfs.toml +++ b/initfs.toml @@ -41,3 +41,12 @@ vendor = 6900 device = 4096 command = ["virtio-netd"] use_channel = true + +[[drivers]] +name = "virtio-gpu" +class = 3 +subclass = 0 +vendor = 6900 +device = 4176 +command = ["virtio-gpud"] +use_channel = true diff --git a/virtio-core/src/utils.rs b/virtio-core/src/utils.rs index d05b74c41e..85d39e54af 100644 --- a/virtio-core/src/utils.rs +++ b/virtio-core/src/utils.rs @@ -64,6 +64,10 @@ pub const fn align(val: usize, align: usize) -> usize { (val + align) & !align } +pub const fn align_down(addr: usize) -> usize { + addr & !(syscall::PAGE_SIZE - 1) +} + #[cfg(target_os = "redox")] pub fn setup_logging(level: log::LevelFilter, name: &str) { use redox_log::{OutputBuilder, RedoxLogger}; diff --git a/virtio-gpud/Cargo.toml b/virtio-gpud/Cargo.toml new file mode 100644 index 0000000000..17fdf4384a --- /dev/null +++ b/virtio-gpud/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "virtio-gpud" +version = "0.1.0" +edition = "2021" +authors = ["Anhad Singh "] + +[dependencies] +log = "0.4" + +virtio-core = { path = "../virtio-core" } +pcid = { path = "../pcid" } + +redox-daemon = "0.1" diff --git a/virtio-gpud/src/main.rs b/virtio-gpud/src/main.rs new file mode 100644 index 0000000000..140c73ac2c --- /dev/null +++ b/virtio-gpud/src/main.rs @@ -0,0 +1,28 @@ +use pcid_interface::PcidServerHandle; +use virtio_core::transport::Error; + +fn deamon(deamon: redox_daemon::Daemon) -> Result<(), Error> { + let mut pcid_handle = PcidServerHandle::connect_default()?; + + // Double check that we have the right device. + // + // 0x1050 - virtio-gpu + let pci_config = pcid_handle.fetch_config()?; + + assert_eq!(pci_config.func.devid, 0x1050); + log::info!("virtio-gpu: initiating startup sequence :^)"); + + let device = virtio_core::probe_device(&mut pcid_handle)?; + loop {} +} + +fn daemon_runner(redox_daemon: redox_daemon::Daemon) -> ! { + deamon(redox_daemon).unwrap(); + unreachable!(); +} + +pub fn main() { + #[cfg(target_os = "redox")] + virtio_core::utils::setup_logging(log::LevelFilter::Trace, "virtio-gpud"); + redox_daemon::Daemon::new(daemon_runner).expect("virtio-core: failed to daemonize"); +}