forked from hermit-os/kernel
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmmio.rs
More file actions
61 lines (57 loc) · 1.84 KB
/
Copy pathmmio.rs
File metadata and controls
61 lines (57 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
use virtio::console::Config;
use virtio::mmio::{DeviceRegisters, DeviceRegistersVolatileFieldAccess};
use volatile::VolatileRef;
use crate::drivers::console::{ConsoleDevCfg, RxQueue, TxQueue, VirtioConsoleDriver};
use crate::drivers::virtio::error::VirtioError;
use crate::drivers::virtio::transport::mmio::{ComCfg, IsrStatus, NotifCfg};
use crate::drivers::{InterruptHandlerMap, InterruptLine};
// Backend-dependent interface for Virtio console driver
impl VirtioConsoleDriver {
pub fn new(
dev_id: u16,
mut registers: VolatileRef<'static, DeviceRegisters>,
) -> Result<VirtioConsoleDriver, VirtioError> {
let dev_cfg_raw: &'static Config = unsafe {
&*registers
.borrow_mut()
.as_mut_ptr()
.config()
.as_raw_ptr()
.cast::<Config>()
.as_ptr()
};
let dev_cfg_raw = VolatileRef::from_ref(dev_cfg_raw);
let dev_cfg = ConsoleDevCfg {
raw: dev_cfg_raw,
dev_id,
features: virtio::console::F::empty(),
};
let isr_stat = IsrStatus::new(registers.borrow_mut());
let notif_cfg = NotifCfg::new(registers.borrow_mut());
Ok(VirtioConsoleDriver {
dev_cfg,
com_cfg: ComCfg::new(registers),
isr_stat,
notif_cfg,
recv_vq: RxQueue::new(),
send_vq: TxQueue::new(),
})
}
/// Initializes virtio console device by mapping configuration layout to
/// respective structs (configuration structs are:
///
/// Returns a driver instance of
/// [VirtioConsoleDriver](structs.virtionetdriver.html) or an [VirtioError](enums.virtioerror.html).
pub fn init(
dev_id: u16,
registers: VolatileRef<'static, DeviceRegisters>,
irq: InterruptLine,
handlers: &mut InterruptHandlerMap,
) -> Result<VirtioConsoleDriver, VirtioError> {
let mut drv = VirtioConsoleDriver::new(dev_id, registers)?;
drv.init_dev(handlers, Some(irq))
.map_err(VirtioError::ConsoleDriver)?;
drv.com_cfg.print_information();
Ok(drv)
}
}