kernel/arch/riscv64/fdt.rs
1use crate::device::fdt::FdtManager;
2
3/// Read the RISC-V timebase frequency (Hz) from the device tree.
4///
5/// The standard location is the `/cpus` node property `timebase-frequency`.
6/// Returns `None` if FDT is unavailable or the property is missing/invalid.
7pub fn timebase_frequency_hz_from_fdt() -> Option<u64> {
8 let fdt = FdtManager::get_manager().get_fdt()?;
9 let cpus = fdt.find_node("/cpus")?;
10
11 let prop = cpus.property("timebase-frequency")?;
12 match prop.value.len() {
13 4 => Some(u32::from_be_bytes(prop.value[0..4].try_into().unwrap()) as u64),
14 8 => Some(u64::from_be_bytes(prop.value[0..8].try_into().unwrap())),
15 _ => None,
16 }
17}