Files
RedBear-OS/virtio-gpud/patches/00-init.patch
T
2023-07-03 17:12:59 +10:00

46 lines
2.3 KiB
Diff

diff --git a/src/main.rs b/src/main.rs
index a99488a..ec97fdd 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -78,6 +78,40 @@ pub fn run(file: &Path) -> Result<()> {
println!("init: failed to run: no argument");
},
"run.d" => if let Some(new_dir) = args.next() {
+ // On startup, the VESA display driver is started which basically makes use of the framebuffer
+ // provided by the firmware. The GPU device are latter started by `pcid` (such as `virtio-gpu`).
+ let mut devices = vec![];
+ let schemes = std::fs::read_dir(":").unwrap();
+
+ for entry in schemes {
+ let path = entry.unwrap().path();
+ let path_str = path
+ .into_os_string()
+ .into_string()
+ .expect("init: failed to convert path to string");
+
+ if path_str.contains("display") {
+ println!("init: found display scheme {}", path_str);
+ devices.push(path_str);
+ }
+ }
+
+ let device = devices.iter().filter(|d| !d.contains("vesa")).collect::<Vec<_>>();
+ let device = if device.is_empty() {
+ // No GPU available, fallback to VESA display which *should* always be accessible via `display/vesa:`.
+ "vesa"
+ } else {
+ // Parts:
+ // :/display/virtio-gpu
+ //
+ // 1st: ":"
+ // 2nd: "display"
+ // 3rd: "virtio-gpu" (the one we want!)
+ device[0].split("/").nth(2).unwrap()
+ };
+
+ std::env::set_var("DISPLAY", &format!("display/{}:3/activate", device));
+
let mut entries = vec![];
match read_dir(&new_dir) {
Ok(list) => for entry_res in list {