From ce9564dd3cdf5f50f917f9c2b9fbcecc82cca6d2 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Mon, 3 Mar 2025 19:51:55 +0100 Subject: [PATCH] graphics/bgad: Use the MMIO based interface rather than port based one This only works in QEMU, so disable bgad in VirtualBox. It currently doesn't do much useful anyway. It supports reporting the display size (which vesad already supports) and changing the display size (which doesn't really work anyway as the framebuffer mapping used by vesad doesn't get resized.) And in any case vboxd already has code to use the BGA interface for resizing that is broken to the same extend the resizing in bgad is. --- graphics/bgad/config.toml | 7 ------ graphics/bgad/src/bga.rs | 48 +++++++++++++++++++++------------------ graphics/bgad/src/main.rs | 13 +++++++---- 3 files changed, 34 insertions(+), 34 deletions(-) diff --git a/graphics/bgad/config.toml b/graphics/bgad/config.toml index a07ff05bbc..c76de694b1 100644 --- a/graphics/bgad/config.toml +++ b/graphics/bgad/config.toml @@ -4,10 +4,3 @@ class = 0x03 vendor = 0x1234 device = 0x1111 command = ["bgad"] - -[[drivers]] -name = "VirtualBox Graphics Array" -class = 0x03 -vendor = 0x80EE -device = 0xBEEF -command = ["bgad"] diff --git a/graphics/bgad/src/bga.rs b/graphics/bgad/src/bga.rs index a498125c9a..5014100c2f 100644 --- a/graphics/bgad/src/bga.rs +++ b/graphics/bgad/src/bga.rs @@ -1,47 +1,51 @@ -use common::io::{Io, Pio}; - const BGA_INDEX_XRES: u16 = 1; const BGA_INDEX_YRES: u16 = 2; const BGA_INDEX_BPP: u16 = 3; const BGA_INDEX_ENABLE: u16 = 4; pub struct Bga { - index: Pio, - data: Pio, + bar: *mut u8, } impl Bga { - pub fn new() -> Bga { - Bga { - index: Pio::new(0x1CE), - data: Pio::new(0x1CF), + pub unsafe fn new(bar: *mut u8) -> Bga { + Bga { bar } + } + + fn bochs_dispi_addr(&mut self, index: u16) -> *mut u16 { + assert!(index <= 0x10); + unsafe { + self.bar + .byte_add(0x500) + .cast::() + .add(usize::from(index)) } } - fn read(&mut self, index: u16) -> u16 { - self.index.write(index); - self.data.read() + fn bochs_dispi_read(&mut self, index: u16) -> u16 { + unsafe { self.bochs_dispi_addr(index).read_volatile() } } - fn write(&mut self, index: u16, data: u16) { - self.index.write(index); - self.data.write(data); + fn bochs_dispi_write(&mut self, index: u16, data: u16) { + assert!(index <= 0x10); + unsafe { + self.bochs_dispi_addr(index).write_volatile(data); + } } pub fn width(&mut self) -> u16 { - self.read(BGA_INDEX_XRES) + self.bochs_dispi_read(BGA_INDEX_XRES) } pub fn height(&mut self) -> u16 { - self.read(BGA_INDEX_YRES) + self.bochs_dispi_read(BGA_INDEX_YRES) } - #[allow(dead_code)] pub fn set_size(&mut self, width: u16, height: u16) { - self.write(BGA_INDEX_ENABLE, 0); - self.write(BGA_INDEX_XRES, width); - self.write(BGA_INDEX_YRES, height); - self.write(BGA_INDEX_BPP, 32); - self.write(BGA_INDEX_ENABLE, 0x41); + self.bochs_dispi_write(BGA_INDEX_ENABLE, 0); + self.bochs_dispi_write(BGA_INDEX_XRES, width); + self.bochs_dispi_write(BGA_INDEX_YRES, height); + self.bochs_dispi_write(BGA_INDEX_BPP, 32); + self.bochs_dispi_write(BGA_INDEX_ENABLE, 0x41); } } diff --git a/graphics/bgad/src/main.rs b/graphics/bgad/src/main.rs index 2e2ca05564..461b1b8b84 100644 --- a/graphics/bgad/src/main.rs +++ b/graphics/bgad/src/main.rs @@ -1,4 +1,5 @@ -use common::acquire_port_io_rights; +//! + use inputd::ProducerHandle; use pcid_interface::PciFunctionHandle; use redox_scheme::{RequestKind, SignalBehavior, Socket}; @@ -9,8 +10,10 @@ use crate::scheme::BgaScheme; mod bga; mod scheme; +// FIXME add a driver-graphics implementation + fn main() { - let pcid_handle = PciFunctionHandle::connect_default(); + let mut pcid_handle = PciFunctionHandle::connect_default(); let pci_config = pcid_handle.config(); let mut name = pci_config.func.name(); @@ -27,11 +30,11 @@ fn main() { log::info!("BGA {}", pci_config.func.display()); redox_daemon::Daemon::new(move |daemon| { - acquire_port_io_rights().expect("bgad: failed to get port IO permission"); - let socket = Socket::create("bga").expect("bgad: failed to create bga scheme"); - let mut bga = Bga::new(); + let bar = unsafe { pcid_handle.map_bar(2) }.ptr.as_ptr(); + + let mut bga = unsafe { Bga::new(bar) }; log::debug!("BGA {}x{}", bga.width(), bga.height()); let mut scheme = BgaScheme {