Files
k-os/crates/servers/input-server/src/server.rs
Gabriel Kaszewski 3a0395453b refactor: extract shared hw-virtio crate, eliminate VirtIO protocol duplication
Two VirtIO block and two VirtIO GPU implementations (adapter + driver)
shared 90% of their protocol logic. Extracted the common code into
hw-virtio, parameterized by MmioAccess trait.

New crate: hw-virtio (no_std, zero deps)
  - mmio.rs: MmioAccess trait, DirectMmio, init_legacy_device(), scan
  - queue.rs: VirtioQueue with descriptor chain submit + poll
  - block.rs: block read protocol (3-descriptor chain)
  - gpu.rs: GPU commands (create_2d, attach_backing, set_scanout,
            transfer_to_host, resource_flush)

Adapter thin wrappers (identity-mapped, statics for DMA):
  - virtio_blk.rs: 220 → 53 lines
  - virtio_gpu.rs: 165 → 37 lines

Driver thin wrappers (mapped VAs, phys-info for DMA):
  - drivers/block/virtio: 139 → 70 lines
  - drivers/framebuffer/virtio: 146 → 95 lines

Also deleted input-server/input_device.rs (1-line re-export,
superseded by port-input-device).
2026-10-18 13:29:28 +02:00

37 lines
952 B
Rust

use server_framework::Server;
use port_input_device::InputDevice;
use crate::protocol::{InputRequest, InputResponse};
pub struct InputServer<D: InputDevice> {
device: D,
}
impl<D: InputDevice> InputServer<D> {
pub fn new(device: D) -> Self {
Self { device }
}
pub fn device(&self) -> &D {
&self.device
}
}
impl<D: InputDevice> Server for InputServer<D> {
type Request = InputRequest;
type Response = InputResponse;
fn handle(&mut self, request: InputRequest) -> InputResponse {
match request {
InputRequest::PollEvent => match self.device.poll() {
Some(event) => InputResponse::Event(event),
None => InputResponse::NoEvent,
},
InputRequest::WaitEvent => match self.device.poll() {
Some(event) => InputResponse::Event(event),
None => InputResponse::NoEvent,
},
}
}
}