diff --git a/Cargo.lock b/Cargo.lock index 9ddd5ca8d4..9171b6ef16 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -461,7 +461,7 @@ checksum = "7b7e4c2464d97fe331d41de9d5db0def0a96f4d823b8b32a2efd503578988973" [[package]] name = "bcm2835-sdhci" version = "0.1.0" -source = "git+https://github.com/lhw2002426/bcm2835-sdhci.git?rev=dc9d587#dc9d58773daa523d8662a48db654fa02fe491a7e" +source = "git+https://github.com/lhw2002426/bcm2835-sdhci.git?rev=e974f16#e974f168efa72b470a01f61bdef32240c66f54fc" dependencies = [ "aarch64-cpu", "log", diff --git a/crates/driver_block/Cargo.toml b/crates/driver_block/Cargo.toml index 22aecc5e60..11c88d7fa1 100644 --- a/crates/driver_block/Cargo.toml +++ b/crates/driver_block/Cargo.toml @@ -18,5 +18,5 @@ default = [] log = "0.4" driver_common = { path = "../driver_common" } spinlock = { path = "../spinlock",option = "smp"} -bcm2835-sdhci = {git = "https://github.com/lhw2002426/bcm2835-sdhci.git", rev = "dc9d587", optional = true} +bcm2835-sdhci = {git = "https://github.com/lhw2002426/bcm2835-sdhci.git", rev = "e974f16", optional = true} diff --git a/crates/driver_block/src/bcm2835sdhci.rs b/crates/driver_block/src/bcm2835sdhci.rs index 07a868474a..343377393a 100644 --- a/crates/driver_block/src/bcm2835sdhci.rs +++ b/crates/driver_block/src/bcm2835sdhci.rs @@ -9,7 +9,7 @@ use driver_common::{BaseDriverOps, DevError, DevResult, DeviceType}; use spinlock::SpinNoIrq as Mutex; ///sdhci driver -pub struct SDHCIDriver(pub Mutex); +pub struct SDHCIDriver(pub EmmcCtl); impl SDHCIDriver { ///sd driver new @@ -20,7 +20,7 @@ impl SDHCIDriver { } else { warn!("BCM2835 sdhci: init failed"); } - SDHCIDriver(Mutex::new(ctrl)) + SDHCIDriver(ctrl) } } @@ -52,20 +52,13 @@ impl BlockDriverOps for SDHCIDriver { if buf.len() < BLOCK_SIZE { return Err(DevError::InvalidParam); } - //let buf = unsafe { slice::from_raw_parts_mut(buf.as_ptr() as *mut u32, BLOCK_SIZE / 4) }; - let mut aligned_buf: [u32; BLOCK_SIZE / 4] = [0; BLOCK_SIZE / 4]; - let res = self - .0 - .lock() - .read_block(block_id as u32, 1, &mut aligned_buf); + let (prefix, aligned_buf, suffix) = unsafe { buf.align_to_mut::() }; + if !prefix.is_empty() || !suffix.is_empty() { + return Err(DevError::InvalidParam); + } + let res = self.0.read_block(block_id as u32, 1, aligned_buf); match res { - Ok(()) => { - for i in 0..(BLOCK_SIZE / 4) { - let start = i * 4; - buf[start..start + 4].copy_from_slice(&aligned_buf[i].to_le_bytes()); - } - Ok(()) - } + Ok(()) => Ok(()), Err(e) => Err(deal_sdhci(e)), } } @@ -80,7 +73,7 @@ impl BlockDriverOps for SDHCIDriver { let aligned_buf: &mut [u32] = unsafe { slice::from_raw_parts_mut(buf_mut.as_mut_ptr().cast::(), BLOCK_SIZE / 4) }; - let res = self.0.lock().write_block(block_id as u32, 1, aligned_buf); + let res = self.0.write_block(block_id as u32, 1, aligned_buf); match res { Ok(()) => Ok(()), Err(e) => Err(deal_sdhci(e)), @@ -91,11 +84,11 @@ impl BlockDriverOps for SDHCIDriver { } #[inline] fn num_blocks(&self) -> u64 { - self.0.lock().get_block_num() + self.0.get_block_num() } #[inline] fn block_size(&self) -> usize { - self.0.lock().get_block_size() + self.0.get_block_size() } } diff --git a/modules/axdriver/src/drivers.rs b/modules/axdriver/src/drivers.rs index 73f6f653ec..e0bce174a8 100644 --- a/modules/axdriver/src/drivers.rs +++ b/modules/axdriver/src/drivers.rs @@ -66,6 +66,7 @@ cfg_if::cfg_if! { } } } + cfg_if::cfg_if! { if #[cfg(block_dev = "mmc")]{ pub struct MmcDriver; @@ -74,9 +75,8 @@ cfg_if::cfg_if! { impl DriverProbe for MmcDriver { fn probe_global() -> Option { debug!("mmc probe"); - // TODO: format RAM disk Some(AxDeviceEnum::from_block( - driver_block::bcm2835sdhci::SDHCIDriver::new(), // 16 MiB + driver_block::bcm2835sdhci::SDHCIDriver::new(), )) } } diff --git a/modules/axhal/src/platform/aarch64_common/pl011.rs b/modules/axhal/src/platform/aarch64_common/pl011.rs index 886448a902..d162ce5c22 100644 --- a/modules/axhal/src/platform/aarch64_common/pl011.rs +++ b/modules/axhal/src/platform/aarch64_common/pl011.rs @@ -7,7 +7,6 @@ use spinlock::SpinNoIrq; use crate::mem::phys_to_virt; const UART_BASE: PhysAddr = PhysAddr::from(axconfig::UART_PADDR); -//const UART_BASE: PhysAddr = PhysAddr::from(0xFE20_1000); static UART: SpinNoIrq = SpinNoIrq::new(Pl011Uart::new(phys_to_virt(UART_BASE).as_mut_ptr())); diff --git a/platforms/aarch64-qemu-virt.toml b/platforms/aarch64-qemu-virt.toml index ed93c9a3d5..b01d9f5bf7 100644 --- a/platforms/aarch64-qemu-virt.toml +++ b/platforms/aarch64-qemu-virt.toml @@ -75,4 +75,4 @@ uart-irq-num = "33" # GICC Address gicc-paddr = "0x0801_0000" -gicd-paddr = "0x0800_0000" \ No newline at end of file +gicd-paddr = "0x0800_0000" diff --git a/platforms/aarch64-raspi4.toml b/platforms/aarch64-raspi4.toml index 616c45b131..cfe9d1bb9d 100644 --- a/platforms/aarch64-raspi4.toml +++ b/platforms/aarch64-raspi4.toml @@ -28,4 +28,4 @@ uart-irq-num = "153" # GIC Address gicc-paddr = "0xFF84_2000" -gicd-paddr = "0xFF84_1000" \ No newline at end of file +gicd-paddr = "0xFF84_1000"