Skip to content

Commit

Permalink
aligned buf
Browse files Browse the repository at this point in the history
  • Loading branch information
lhw2002426 committed Jul 31, 2023
1 parent d37597f commit 55bcf23
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 25 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/driver_block/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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}

29 changes: 11 additions & 18 deletions crates/driver_block/src/bcm2835sdhci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use driver_common::{BaseDriverOps, DevError, DevResult, DeviceType};
use spinlock::SpinNoIrq as Mutex;

///sdhci driver
pub struct SDHCIDriver(pub Mutex<EmmcCtl>);
pub struct SDHCIDriver(pub EmmcCtl);

impl SDHCIDriver {
///sd driver new
Expand All @@ -20,7 +20,7 @@ impl SDHCIDriver {
} else {
warn!("BCM2835 sdhci: init failed");
}
SDHCIDriver(Mutex::new(ctrl))
SDHCIDriver(ctrl)
}
}

Expand Down Expand Up @@ -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::<u32>() };
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)),
}
}
Expand All @@ -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::<u32>(), 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)),
Expand All @@ -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()
}
}
4 changes: 2 additions & 2 deletions modules/axdriver/src/drivers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ cfg_if::cfg_if! {
}
}
}

cfg_if::cfg_if! {
if #[cfg(block_dev = "mmc")]{
pub struct MmcDriver;
Expand All @@ -74,9 +75,8 @@ cfg_if::cfg_if! {
impl DriverProbe for MmcDriver {
fn probe_global() -> Option<AxDeviceEnum> {
debug!("mmc probe");
// TODO: format RAM disk
Some(AxDeviceEnum::from_block(
driver_block::bcm2835sdhci::SDHCIDriver::new(), // 16 MiB
driver_block::bcm2835sdhci::SDHCIDriver::new(),
))
}
}
Expand Down
1 change: 0 additions & 1 deletion modules/axhal/src/platform/aarch64_common/pl011.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Pl011Uart> =
SpinNoIrq::new(Pl011Uart::new(phys_to_virt(UART_BASE).as_mut_ptr()));
Expand Down
2 changes: 1 addition & 1 deletion platforms/aarch64-qemu-virt.toml
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,4 @@ uart-irq-num = "33"

# GICC Address
gicc-paddr = "0x0801_0000"
gicd-paddr = "0x0800_0000"
gicd-paddr = "0x0800_0000"
2 changes: 1 addition & 1 deletion platforms/aarch64-raspi4.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ uart-irq-num = "153"

# GIC Address
gicc-paddr = "0xFF84_2000"
gicd-paddr = "0xFF84_1000"
gicd-paddr = "0xFF84_1000"

0 comments on commit 55bcf23

Please sign in to comment.