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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#![no_std]
#![deny(unused_must_use, missing_docs)]
#![allow(clippy::identity_op)]
#![allow(dead_code)]
extern crate log;
extern crate alloc;
mod blk;
mod console;
mod gpu;
mod hal;
mod header;
mod input;
mod net;
mod queue;
pub use self::blk::{BlkResp, RespStatus, VirtIOBlk};
pub use self::console::VirtIOConsole;
pub use self::gpu::VirtIOGpu;
pub use self::header::*;
pub use self::input::{InputConfigSelect, InputEvent, VirtIOInput};
pub use self::net::VirtIONet;
use self::queue::VirtQueue;
use core::mem::size_of;
use hal::*;
const PAGE_SIZE: usize = 0x1000;
pub type Result<T = ()> = core::result::Result<T, Error>;
#[derive(Debug, Eq, PartialEq)]
pub enum Error {
BufferTooSmall,
NotReady,
AlreadyUsed,
InvalidParam,
DmaError,
IoError,
}
fn align_up(size: usize) -> usize {
(size + PAGE_SIZE) & !(PAGE_SIZE - 1)
}
fn pages(size: usize) -> usize {
(size + PAGE_SIZE - 1) / PAGE_SIZE
}
unsafe trait AsBuf: Sized {
fn as_buf(&self) -> &[u8] {
unsafe { core::slice::from_raw_parts(self as *const _ as _, size_of::<Self>()) }
}
fn as_buf_mut(&mut self) -> &mut [u8] {
unsafe { core::slice::from_raw_parts_mut(self as *mut _ as _, size_of::<Self>()) }
}
}