36 lines
1.3 KiB
Rust
36 lines
1.3 KiB
Rust
use super::{dma_buffer, info_page, map_mmio};
|
|
use crate::board;
|
|
use crate::hw::uart::Uart;
|
|
use types::id::ProcessId;
|
|
|
|
const UART_VA: usize = 0x20000;
|
|
const INPUT_MMIO_VA: usize = 0x25000;
|
|
const INPUT_VQUEUE_VA: usize = 0x26000;
|
|
const INPUT_EVBUF_VA: usize = 0x28000;
|
|
const INPUT_PHYSINFO_VA: usize = 0x29000;
|
|
|
|
pub fn configure(uart: &Uart, input_pid: ProcessId) {
|
|
// Always map UART for fallback
|
|
map_mmio(uart, input_pid, UART_VA, board::UART_BASE, 1);
|
|
|
|
// Try to find VirtIO input device
|
|
let first = crate::mmu::phys_to_virt(hw_virtio::mmio::MMIO_FIRST);
|
|
if let Some(mmio) = hw_virtio::mmio::scan_for_device(first, hw_virtio::mmio::DEVICE_ID_INPUT) {
|
|
let base = crate::mmu::virt_to_phys(mmio.base());
|
|
map_mmio(uart, input_pid, INPUT_MMIO_VA, base, 1);
|
|
let vq_phys = dma_buffer(uart, input_pid, INPUT_VQUEUE_VA, 2);
|
|
let evbuf_phys = dma_buffer(uart, input_pid, INPUT_EVBUF_VA, 1);
|
|
info_page(
|
|
uart,
|
|
input_pid,
|
|
INPUT_PHYSINFO_VA,
|
|
&[evbuf_phys as u64, vq_phys as u64],
|
|
);
|
|
|
|
hw_virtio::mmio::init_legacy_device(&mmio, vq_phys, 32);
|
|
uart.write_str("k-os: VirtIO keyboard configured\n");
|
|
} else {
|
|
uart.write_str("k-os: UART mapped for input\n");
|
|
}
|
|
}
|