handler.rs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435
  1. use core::{ops::Deref, ptr::NonNull};
  2. /// Describes a physical mapping created by `AcpiHandler::map_physical_region` and unmapped by
  3. /// `AcpiHandler::unmap_physical_region`. The region mapped must be at least `size_of::<T>()`
  4. /// bytes, but may be bigger.
  5. pub struct PhysicalMapping<T> {
  6. pub physical_start: usize,
  7. pub virtual_start: NonNull<T>,
  8. pub region_length: usize, // Can be equal or larger than size_of::<T>()
  9. pub mapped_length: usize, // Differs from `region_length` if padding is added for alignment
  10. }
  11. impl<T> Deref for PhysicalMapping<T> {
  12. type Target = T;
  13. fn deref(&self) -> &T {
  14. unsafe { self.virtual_start.as_ref() }
  15. }
  16. }
  17. /// An implementation of this trait must be provided to allow `acpi` to access platform-specific
  18. /// functionality, such as mapping regions of physical memory. You are free to implement these
  19. /// however you please, as long as they conform to the documentation of each function.
  20. pub trait AcpiHandler {
  21. /// Given a starting physical address and a size, map a region of physical memory that contains
  22. /// a `T` (but may be bigger than `size_of::<T>()`). The address doesn't have to be
  23. /// page-aligned, so the implementation may have to add padding to either end. The given
  24. /// size must be greater or equal to the size of a `T`. The virtual address the memory is
  25. /// mapped to does not matter, as long as it is accessible from `acpi`.
  26. fn map_physical_region<T>(&mut self, physical_address: usize, size: usize) -> PhysicalMapping<T>;
  27. /// Unmap the given physical mapping. Safe because we consume the mapping, and so it can't be
  28. /// used after being passed to this function.
  29. fn unmap_physical_region<T>(&mut self, region: PhysicalMapping<T>);
  30. }