refactor: ByteOffset newtype for window/register/ring offsets; named virtio-gpu cmd fields

This commit is contained in:
2026-10-27 21:52:33 +01:00
parent 842d14987c
commit 7b8258b231
13 changed files with 145 additions and 93 deletions

View File

@@ -3,11 +3,12 @@
use libkos::Window;
use port_input_device::{InputDevice, InputEvent, Key};
use types::address::VirtualAddress;
use types::address::{ByteOffset, VirtualAddress};
const UART_VA: VirtualAddress = VirtualAddress::from_raw(0x20000);
const UART_IER_OFFSET: usize = 1;
const UART_LSR_OFFSET: usize = 5;
const UART_RBR: ByteOffset = ByteOffset::new(0);
const UART_IER_OFFSET: ByteOffset = ByteOffset::new(1);
const UART_LSR_OFFSET: ByteOffset = ByteOffset::new(5);
/// IER bit: interrupt when a received byte is waiting (cleared by reading
/// it, so `acknowledge` has nothing to do).
const IER_RX_READY: u8 = 1;
@@ -27,7 +28,7 @@ impl UartInputDevice {
}
fn read_byte(&self) -> Option<u8> {
self.has_event().then(|| self.regs.read(0))
self.has_event().then(|| self.regs.read(UART_RBR))
}
fn byte_to_key(byte: u8) -> Key {

View File

@@ -7,7 +7,7 @@ use core::sync::atomic::{Ordering, fence};
use hw_virtio::mmio::{MmioAccess, Registers};
use libkos::Window;
use port_input_device::{InputDevice, InputEvent};
use types::address::{PhysicalAddress, VirtualAddress};
use types::address::{ByteOffset, PhysicalAddress, VirtualAddress};
use types::bounded::PageCount;
const INPUT_MMIO_VA: VirtualAddress = VirtualAddress::from_raw(0x25000);
@@ -18,8 +18,8 @@ const QUEUE_SIZE: usize = 32;
const EVENT_SIZE: usize = 8;
const DESC_SIZE: usize = 16;
/// Where the legacy layout puts the available and used rings.
const AVAIL: usize = QUEUE_SIZE * DESC_SIZE;
const USED: usize = 4096;
const AVAIL: ByteOffset = ByteOffset::new(QUEUE_SIZE * DESC_SIZE);
const USED: ByteOffset = ByteOffset::new(4096);
const EV_KEY: u16 = 1;
const KEY_PRESS: u32 = 1;
@@ -67,7 +67,7 @@ impl VirtioInputDevice {
/// Every buffer goes to the device, one event each.
fn fill_queue(&mut self) {
for i in 0..QUEUE_SIZE {
let desc = i * DESC_SIZE;
let desc = ByteOffset::new(i * DESC_SIZE);
self.rings.write(desc, (self.events_pa.raw() + i * EVENT_SIZE) as u64);
self.rings.write(desc + 8, EVENT_SIZE as u32);
self.rings.write(desc + 12, 2u16); // WRITE flag
@@ -92,7 +92,7 @@ impl VirtioInputDevice {
}
fn read_event(&self, desc_idx: u16) -> (u16, u16, u32) {
let at = desc_idx as usize % QUEUE_SIZE * EVENT_SIZE;
let at = ByteOffset::new(desc_idx as usize % QUEUE_SIZE * EVENT_SIZE);
(self.events.read(at), self.events.read(at + 2), self.events.read(at + 4))
}