diff --git a/awkernel_lib/src/lib.rs b/awkernel_lib/src/lib.rs index 37be10fb9..76af7c2eb 100644 --- a/awkernel_lib/src/lib.rs +++ b/awkernel_lib/src/lib.rs @@ -26,6 +26,7 @@ pub mod mmio; pub mod net; pub mod priority_queue; pub mod sanity; +pub mod storage; pub mod sync; pub mod time; pub mod timer; diff --git a/awkernel_lib/src/storage.rs b/awkernel_lib/src/storage.rs new file mode 100644 index 000000000..dfde592dc --- /dev/null +++ b/awkernel_lib/src/storage.rs @@ -0,0 +1 @@ +pub mod storage_device; diff --git a/awkernel_lib/src/storage/storage_device.rs b/awkernel_lib/src/storage/storage_device.rs new file mode 100644 index 000000000..905d941a9 --- /dev/null +++ b/awkernel_lib/src/storage/storage_device.rs @@ -0,0 +1,46 @@ +use alloc::{borrow::Cow, vec::Vec}; + +#[derive(Debug, Clone, Copy)] +pub enum StorageDeviceType { + NVMe, + SATA, + USB, + VirtIO, + Memory, +} + +#[derive(Debug)] +pub enum StorageDevError { + IoError, + InvalidCommand, + DeviceNotReady, + InvalidBlock, + BufferTooSmall, + NotSupported, +} + +pub trait StorageDevice: Send + Sync { + fn device_id(&self) -> u64; + + fn device_name(&self) -> Cow<'static, str>; + + fn device_short_name(&self) -> Cow<'static, str>; + + fn device_type(&self) -> StorageDeviceType; + + fn irqs(&self) -> Vec; + + fn interrupt(&self, irq: u16) -> Result<(), StorageDevError>; + + fn block_size(&self) -> usize; + + fn num_blocks(&self) -> u64; + + fn read_blocks(&self, buf: &mut [u8], transfer_id: u16) -> Result<(), StorageDevError>; + + fn write_blocks(&self, buf: &[u8], transfer_id: u16) -> Result<(), StorageDevError>; + + fn flush(&self, _transfer_id: u16) -> Result<(), StorageDevError> { + Ok(()) + } +}