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.
This commit is contained in:
bjorn3
2025-03-03 19:51:55 +01:00
parent ff0ac17992
commit ce9564dd3c
3 changed files with 34 additions and 34 deletions
-7
View File
@@ -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"]
+26 -22
View File
@@ -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<u16>,
data: Pio<u16>,
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::<u16>()
.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);
}
}
+8 -5
View File
@@ -1,4 +1,5 @@
use common::acquire_port_io_rights;
//! <https://www.qemu.org/docs/master/specs/standard-vga.html>
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 {