diff --git a/libkernel/src/memory/address.rs b/libkernel/src/memory/address.rs index 828ecf1..449ae3e 100644 --- a/libkernel/src/memory/address.rs +++ b/libkernel/src/memory/address.rs @@ -164,10 +164,6 @@ impl Address { pub fn is_null(self) -> bool { self.inner == 0 } - - pub fn to_pfn(&self) -> PageFrame { - PageFrame::from_pfn(self.inner >> PAGE_SHIFT) - } } impl Address { @@ -294,6 +290,10 @@ impl PA { pub fn cast(self) -> TPA { TPA::from_value(self.value()) } + + pub fn to_pfn(&self) -> PageFrame { + PageFrame::from_pfn(self.inner >> PAGE_SHIFT) + } } /// Trait for translating between physical and virtual addresses. diff --git a/libkernel/src/memory/page.rs b/libkernel/src/memory/page.rs index 9e2298f..c320689 100644 --- a/libkernel/src/memory/page.rs +++ b/libkernel/src/memory/page.rs @@ -79,8 +79,10 @@ impl, T: AddressTranslator<()>> ClaimedPage Self { Self( unsafe { diff --git a/libkernel/src/memory/region.rs b/libkernel/src/memory/region.rs index cc009c2..8b83760 100644 --- a/libkernel/src/memory/region.rs +++ b/libkernel/src/memory/region.rs @@ -372,6 +372,16 @@ impl MemoryRegion { } }) } +} + +/// A memory region in physical address space. +pub type PhysMemoryRegion = MemoryRegion; + +impl PhysMemoryRegion { + /// Map the physical region to virtual space using a translator. + pub fn map_via>(self) -> VirtMemoryRegion { + VirtMemoryRegion::new(self.address.to_va::(), self.size) + } pub fn iter_pfns(self) -> impl Iterator { let mut count = 0; @@ -391,16 +401,6 @@ impl MemoryRegion { } } -/// A memory region in physical address space. -pub type PhysMemoryRegion = MemoryRegion; - -impl PhysMemoryRegion { - /// Map the physical region to virtual space using a translator. - pub fn map_via>(self) -> VirtMemoryRegion { - VirtMemoryRegion::new(self.address.to_va::(), self.size) - } -} - /// A memory region in virtual address space. pub type VirtMemoryRegion = MemoryRegion;