lib.rs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. //! VirtIO guest drivers.
  2. #![cfg_attr(not(test), no_std)]
  3. #![deny(unused_must_use, missing_docs)]
  4. #![allow(clippy::identity_op)]
  5. #![allow(dead_code)]
  6. #[cfg(any(feature = "alloc", test))]
  7. extern crate alloc;
  8. pub mod device;
  9. mod hal;
  10. mod queue;
  11. pub mod transport;
  12. mod volatile;
  13. pub use self::hal::{Hal, PhysAddr, VirtAddr};
  14. /// The page size in bytes supported by the library (4 KiB).
  15. pub const PAGE_SIZE: usize = 0x1000;
  16. /// The type returned by driver methods.
  17. pub type Result<T = ()> = core::result::Result<T, Error>;
  18. /// The error type of VirtIO drivers.
  19. #[derive(Copy, Clone, Debug, Eq, PartialEq)]
  20. pub enum Error {
  21. /// There are not enough descriptors available in the virtqueue, try again later.
  22. QueueFull,
  23. /// The device is not ready.
  24. NotReady,
  25. /// The queue is already in use.
  26. AlreadyUsed,
  27. /// Invalid parameter.
  28. InvalidParam,
  29. /// Failed to alloc DMA memory.
  30. DmaError,
  31. /// I/O Error
  32. IoError,
  33. /// The config space advertised by the device is smaller than the driver expected.
  34. ConfigSpaceTooSmall,
  35. /// The device doesn't have any config space, but the driver expects some.
  36. ConfigSpaceMissing,
  37. }
  38. /// Align `size` up to a page.
  39. fn align_up(size: usize) -> usize {
  40. (size + PAGE_SIZE) & !(PAGE_SIZE - 1)
  41. }
  42. /// The number of pages required to store `size` bytes, rounded up to a whole number of pages.
  43. fn pages(size: usize) -> usize {
  44. (size + PAGE_SIZE - 1) / PAGE_SIZE
  45. }