fdt.rs 873 B

1234567891011121314151617181920212223242526272829303132
  1. use super::mm::ArchPhysAccess;
  2. use core::sync::atomic::{AtomicPtr, Ordering};
  3. use eonix_mm::address::{Addr, PAddr, PRange, PhysAccess};
  4. use eonix_sync_base::LazyLock;
  5. use fdt::Fdt;
  6. const FDT_PADDR: PAddr = PAddr::from_val(0x100000);
  7. pub static FDT: LazyLock<Fdt<'static>> = LazyLock::new(|| unsafe {
  8. Fdt::from_ptr(ArchPhysAccess::as_ptr(FDT_PADDR).as_ptr())
  9. .expect("Failed to parse DTB from static memory.")
  10. });
  11. pub trait FdtExt {
  12. fn harts(&self) -> impl Iterator<Item = usize>;
  13. fn hart_count(&self) -> usize {
  14. self.harts().count()
  15. }
  16. fn present_ram(&self) -> impl Iterator<Item = PRange>;
  17. }
  18. impl FdtExt for Fdt<'_> {
  19. fn harts(&self) -> impl Iterator<Item = usize> {
  20. self.cpus().map(|cpu| cpu.ids().all()).flatten()
  21. }
  22. fn present_ram(&self) -> impl Iterator<Item = PRange> {
  23. core::iter::empty()
  24. }
  25. }