bcm2835-sdhcid: remap mmio range as instructed by DTB

This commit is contained in:
Andrey Turkin
2024-12-18 20:16:59 +03:00
parent e5e753a426
commit 63b1d2cf8a
3 changed files with 25 additions and 6 deletions
Generated
+7 -2
View File
@@ -177,7 +177,7 @@ version = "0.1.0"
dependencies = [
"common",
"driver-block",
"fdt",
"fdt 0.2.0-alpha1",
"libredox",
"redox-daemon",
"redox-scheme",
@@ -433,6 +433,11 @@ version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "784a4df722dc6267a04af36895398f59d21d07dce47232adf31ec0ff2fa45e67"
[[package]]
name = "fdt"
version = "0.2.0-alpha1"
source = "git+https://github.com/repnop/fdt.git#059bb2383873f8001959456e36ec123228f67642"
[[package]]
name = "fuchsia-cprng"
version = "0.1.1"
@@ -947,7 +952,7 @@ dependencies = [
"bit_field",
"bitflags 1.3.2",
"common",
"fdt",
"fdt 0.1.5",
"libc",
"libredox",
"log",
+1 -1
View File
@@ -6,7 +6,7 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
fdt = "0.1.5"
fdt = { git = "https://github.com/repnop/fdt.git" }
common = { path = "../../common" }
driver-block = { path = "../driver-block" }
+17 -3
View File
@@ -1,3 +1,5 @@
#![feature(let_chains)]
use std::{
fs::File,
io::{Read, Write},
@@ -50,17 +52,29 @@ fn daemon(daemon: redox_daemon::Daemon) -> ! {
let fdt = Fdt::new(&dtb_data).unwrap();
println!("DTB model = {}", fdt.root().model());
let with = ["brcm,bcm2835-sdhcid"];
let with = ["brcm,bcm2835-sdhci"];
let compat_node = fdt.find_compatible(&with).unwrap();
let reg = compat_node.reg().unwrap().next().unwrap();
let reg_size = reg.size.unwrap();
let mut reg_addr = reg.starting_address as usize;
println!(
"DeviceMemory start = 0x{:08x}, size = 0x{:08x}",
reg.starting_address as usize, reg_size
reg_addr, reg_size
);
if let Some(mut ranges) = fdt.find_node("/soc").and_then(|f| f.ranges()) {
let range = ranges
.find(|f| f.child_bus_address <= reg_addr && reg_addr - f.child_bus_address < f.size)
.expect("Couldn't find device range in /soc/@ranges");
reg_addr = range.parent_bus_address + (reg_addr - range.child_bus_address);
println!(
"DeviceMemory remapped onto CPU address space: start = 0x{:08x}, size = 0x{:08x}",
reg_addr, reg_size
);
}
let addr = unsafe {
common::physmap(
reg.starting_address as usize,
reg_addr,
reg_size,
common::Prot::RW,
common::MemoryType::DeviceMemory,