|
@@ -1,4 +1,4 @@
|
|
-use core::{mem, ops::Deref, ptr::NonNull};
|
|
|
|
|
|
+use core::{ops::Deref, ptr::NonNull};
|
|
|
|
|
|
/// Describes a physical mapping created by `AcpiHandler::map_physical_region` and unmapped by
|
|
/// Describes a physical mapping created by `AcpiHandler::map_physical_region` and unmapped by
|
|
/// `AcpiHandler::unmap_physical_region`. The region mapped must be at least `size_of::<T>()`
|
|
/// `AcpiHandler::unmap_physical_region`. The region mapped must be at least `size_of::<T>()`
|
|
@@ -11,45 +11,7 @@ where
|
|
pub virtual_start: NonNull<T>,
|
|
pub virtual_start: NonNull<T>,
|
|
pub region_length: usize, // Can be equal or larger than size_of::<T>()
|
|
pub region_length: usize, // Can be equal or larger than size_of::<T>()
|
|
pub mapped_length: usize, // Differs from `region_length` if padding is added for alignment
|
|
pub mapped_length: usize, // Differs from `region_length` if padding is added for alignment
|
|
- /*
|
|
|
|
- * NOTE: we store an `Option<H>` here to make the implementation of `coerce_type` easier - if we can find a
|
|
|
|
- * better way, that would be better. Other than that, this should never be `None`, so is fine to unwrap.
|
|
|
|
- */
|
|
|
|
- handler: Option<H>,
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-impl<H, T> PhysicalMapping<H, T>
|
|
|
|
-where
|
|
|
|
- H: AcpiHandler,
|
|
|
|
-{
|
|
|
|
- pub fn new(
|
|
|
|
- physical_start: usize,
|
|
|
|
- virtual_start: NonNull<T>,
|
|
|
|
- region_length: usize,
|
|
|
|
- mapped_length: usize,
|
|
|
|
- handler: H,
|
|
|
|
- ) -> PhysicalMapping<H, T> {
|
|
|
|
- PhysicalMapping { physical_start, virtual_start, region_length, mapped_length, handler: Some(handler) }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- pub(crate) unsafe fn coerce_type<N>(mut self) -> PhysicalMapping<H, N> {
|
|
|
|
- /*
|
|
|
|
- * Ideally, we'd like to assert something like `self.region_length >= mem::size_of::<N>()` here, but we
|
|
|
|
- * can't as some types are actually sometimes larger than their tables, and use mechanisms such as
|
|
|
|
- * `ExtendedField` to mediate access.
|
|
|
|
- */
|
|
|
|
- assert!((self.virtual_start.as_ptr() as usize) % mem::align_of::<N>() == 0);
|
|
|
|
-
|
|
|
|
- let result = PhysicalMapping {
|
|
|
|
- physical_start: self.physical_start,
|
|
|
|
- virtual_start: NonNull::new(self.virtual_start.as_ptr() as *mut N).unwrap(),
|
|
|
|
- region_length: self.region_length,
|
|
|
|
- mapped_length: self.mapped_length,
|
|
|
|
- handler: mem::replace(&mut self.handler, None),
|
|
|
|
- };
|
|
|
|
- mem::forget(self);
|
|
|
|
- result
|
|
|
|
- }
|
|
|
|
|
|
+ pub handler: H,
|
|
}
|
|
}
|
|
|
|
|
|
impl<H, T> Deref for PhysicalMapping<H, T>
|
|
impl<H, T> Deref for PhysicalMapping<H, T>
|
|
@@ -68,7 +30,7 @@ where
|
|
H: AcpiHandler,
|
|
H: AcpiHandler,
|
|
{
|
|
{
|
|
fn drop(&mut self) {
|
|
fn drop(&mut self) {
|
|
- self.handler.as_ref().unwrap().unmap_physical_region(self)
|
|
|
|
|
|
+ self.handler.unmap_physical_region(self)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|