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

@@ -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))
}