diff --git a/kernel/src/fs/device.rs b/kernel/src/fs/device.rs index 53a7303a..9d3763f8 100644 --- a/kernel/src/fs/device.rs +++ b/kernel/src/fs/device.rs @@ -8,6 +8,7 @@ use crate::arch::driver::ide; #[cfg(target_arch = "aarch64")] use crate::arch::board::emmc; +use crate::sync::SpinNoIrqLock as Mutex; pub struct MemBuf(RwLock<&'static mut [u8]>); @@ -63,20 +64,25 @@ impl BlockDevice for ide::IDE { } #[cfg(target_arch = "aarch64")] -impl BlockDevice for emmc::EmmcCtl { +pub struct EmmcDriver(Mutex); + +#[cfg(target_arch = "aarch64")] +impl BlockDevice for EmmcDriver { const BLOCK_SIZE_LOG2: u8 = 9; fn read_at(&self, block_id: usize, buf: &mut [u8]) -> Result<()> { use core::slice; assert!(buf.len() >= emmc::BLOCK_SIZE); let buf = unsafe { slice::from_raw_parts_mut(buf.as_ptr() as *mut u32, emmc::BLOCK_SIZE / 4) }; - self.read(block_id as u32, 1, buf).map_err(|_| DevError)?; + let mut ctrl = self.0.lock(); + ctrl.read(block_id as u32, 1, buf).map_err(|_| DevError)?; Ok(()) } fn write_at(&self, block_id: usize, buf: &[u8]) -> Result<()> { use core::slice; assert!(buf.len() >= emmc::BLOCK_SIZE); let buf = unsafe { slice::from_raw_parts(buf.as_ptr() as *mut u32, emmc::BLOCK_SIZE / 4) }; - self.write(block_id as u32, 1, buf).map_err(|_| DevError)?; + let mut ctrl = self.0.lock(); + ctrl.write(block_id as u32, 1, buf).map_err(|_| DevError)?; Ok(()) } fn sync(&self) -> Result<()> {