lib.rs 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. //! VirtIO guest drivers.
  2. #![no_std]
  3. #![deny(unused_must_use, missing_docs)]
  4. #[macro_use]
  5. extern crate log;
  6. mod blk;
  7. mod gpu;
  8. mod hal;
  9. mod header;
  10. mod queue;
  11. pub use self::blk::VirtIOBlk;
  12. pub use self::gpu::VirtIOGpu;
  13. pub use self::header::*;
  14. use hal::*;
  15. const PAGE_SIZE: usize = 0x1000;
  16. /// The type returned by driver methods.
  17. pub type Result<T = ()> = core::result::Result<T, Error>;
  18. // pub struct Error {
  19. // kind: ErrorKind,
  20. // reason: &'static str,
  21. // }
  22. /// The error type of VirtIO drivers.
  23. #[derive(Debug, Eq, PartialEq)]
  24. pub enum Error {
  25. /// The buffer is too small.
  26. BufferTooSmall,
  27. /// The device is not ready.
  28. NotReady,
  29. /// The queue is already in use.
  30. AlreadyUsed,
  31. /// Invalid parameter.
  32. InvalidParam,
  33. /// Failed to alloc DMA memory.
  34. DmaError,
  35. /// I/O Error
  36. IoError,
  37. }
  38. /// Align `size` up to a page.
  39. fn align_up(size: usize) -> usize {
  40. (size + PAGE_SIZE) & !(PAGE_SIZE - 1)
  41. }
  42. /// Pages of `size`.
  43. fn pages(size: usize) -> usize {
  44. (size + PAGE_SIZE - 1) / PAGE_SIZE
  45. }