Lines Matching refs:Arch

21 pub struct PageTable<Arch> {
28 phantom: PhantomData<Arch>,
32 impl<Arch: MemoryManagementArch> PageTable<Arch> {
54 Arch::table(table_kind), in top_level_table()
55 Arch::PAGE_LEVELS - 1, in top_level_table()
80 return Arch::phys_2_virt(self.phys).unwrap(); in virt()
85 if i < Arch::PAGE_ENTRY_NUM { in entry_base()
86 let shift = self.level * Arch::PAGE_ENTRY_SHIFT + Arch::PAGE_SHIFT; in entry_base()
95 if i < Arch::PAGE_ENTRY_NUM { in entry_virt()
96 return Some(self.virt().add(i * Arch::PAGE_ENTRY_SIZE)); in entry_virt()
103 pub unsafe fn entry(&self, i: usize) -> Option<PageEntry<Arch>> { in entry() argument
105 return Some(PageEntry::new(Arch::read::<usize>(entry_virt))); in entry()
109 pub unsafe fn set_entry(&self, i: usize, entry: PageEntry<Arch>) -> Option<()> { in set_entry()
111 Arch::write::<usize>(entry_virt, entry.data()); in set_entry()
123 if unsafe { Arch::read::<usize>(etv) } != 0 { in entry_mapped()
140 let addr = VirtAddr::new(addr.data() & Arch::PAGE_ADDRESS_MASK); in index_of()
141 let shift = self.level * Arch::PAGE_ENTRY_SHIFT + Arch::PAGE_SHIFT; in index_of()
168 pub struct PageEntry<Arch> {
170 phantom: PhantomData<Arch>,
173 impl<Arch> Debug for PageEntry<Arch> {
179 impl<Arch: MemoryManagementArch> PageEntry<Arch> {
201 let paddr = PhysAddr::new(self.data & Arch::PAGE_ADDRESS_MASK); in address()
211 pub fn flags(&self) -> PageFlags<Arch> { in flags() argument
212 unsafe { PageFlags::from_data(self.data & Arch::ENTRY_FLAGS_MASK) } in flags()
216 pub fn set_flags(&mut self, flags: PageFlags<Arch>) { in set_flags() argument
217 self.data = (self.data & !Arch::ENTRY_FLAGS_MASK) | flags.data(); in set_flags()
222 return self.data & Arch::ENTRY_FLAG_PRESENT != 0; in present()
228 pub struct PageFlags<Arch> {
230 phantom: PhantomData<Arch>,
234 impl<Arch: MemoryManagementArch> PageFlags<Arch> {
239 Arch::ENTRY_FLAG_DEFAULT_PAGE in new()
240 | Arch::ENTRY_FLAG_READONLY in new()
241 | Arch::ENTRY_FLAG_NO_EXEC, in new()
261 pub fn from_prot_flags(prot_flags: ProtFlags, user: bool) -> PageFlags<Arch> { in from_prot_flags() argument
262 let flags: PageFlags<Arch> = PageFlags::new() in from_prot_flags()
293 let r = Self::from_data(Arch::ENTRY_FLAG_DEFAULT_TABLE | Arch::ENTRY_FLAG_READWRITE); in new_page_table()
330 return self.has_flag(Arch::ENTRY_FLAG_PRESENT); in present()
339 return self.update_flags(Arch::ENTRY_FLAG_USER, value); in set_user()
345 return self.has_flag(Arch::ENTRY_FLAG_USER); in has_user()
360 .update_flags(Arch::ENTRY_FLAG_READONLY, !value) in set_write()
361 .update_flags(Arch::ENTRY_FLAG_READWRITE, value); in set_write()
368 return self.data & (Arch::ENTRY_FLAG_READWRITE | Arch::ENTRY_FLAG_READONLY) in has_write()
369 == Arch::ENTRY_FLAG_READWRITE; in has_write()
386 .update_flags(Arch::ENTRY_FLAG_NO_EXEC, !value) in set_execute()
387 .update_flags(Arch::ENTRY_FLAG_EXEC, value); in set_execute()
394 return self.data & (Arch::ENTRY_FLAG_EXEC | Arch::ENTRY_FLAG_NO_EXEC) in has_execute()
395 == Arch::ENTRY_FLAG_EXEC; in has_execute()
405 return self.update_flags(Arch::ENTRY_FLAG_CACHE_DISABLE, value); in set_page_cache_disable()
415 return self.has_flag(Arch::ENTRY_FLAG_CACHE_DISABLE); in has_page_cache_disable()
425 return self.update_flags(Arch::ENTRY_FLAG_WRITE_THROUGH, value); in set_page_write_through()
435 return self.has_flag(Arch::ENTRY_FLAG_WRITE_THROUGH); in has_page_write_through()
450 impl<Arch: MemoryManagementArch> fmt::Debug for PageFlags<Arch> {
464 pub struct PageMapper<Arch, F> {
471 phantom: PhantomData<fn() -> Arch>,
474 impl<Arch: MemoryManagementArch, F: FrameAllocator> PageMapper<Arch, F> {
498 let table_vaddr = Arch::phys_2_virt(table_paddr)?; in create()
499 Arch::write_bytes(table_vaddr, 0, Arch::PAGE_SIZE); in create()
506 let table_paddr = Arch::table(table_kind); in current()
513 return unsafe { self.table().phys() == Arch::table(self.table_kind) }; in is_current()
519 Arch::set_table(self.table_kind, self.table_paddr); in make_current()
524 pub fn table(&self) -> PageTable<Arch> { in table() argument
527 PageTable::new(VirtAddr::new(0), self.table_paddr, Arch::PAGE_LEVELS - 1) in table()
548 flags: PageFlags<Arch>, in map() argument
549 ) -> Option<PageFlush<Arch>> { in map() argument
561 flags: PageFlags<Arch>, in map_phys() argument
562 ) -> Option<PageFlush<Arch>> { in map_phys() argument
564 if !(virt.check_aligned(Arch::PAGE_SIZE) && phys.check_aligned(Arch::PAGE_SIZE)) { in map_phys()
572 let virt = VirtAddr::new(virt.data() & (!Arch::PAGE_NEGATIVE_MASK)); in map_phys()
581 assert!(i < Arch::PAGE_ENTRY_NUM); in map_phys()
633 flags: PageFlags<Arch>, in map_linearly() argument
634 ) -> Option<(VirtAddr, PageFlush<Arch>)> { in map_linearly() argument
635 let virt: VirtAddr = Arch::phys_2_virt(phys)?; in map_linearly()
653 flags: PageFlags<Arch>, in remap() argument
654 ) -> Option<PageFlush<Arch>> { in remap() argument
674 pub fn translate(&self, virt: VirtAddr) -> Option<(PhysAddr, PageFlags<Arch>)> { in translate() argument
675 let entry: PageEntry<Arch> = self.visit(virt, |p1, i| unsafe { p1.entry(i) })??; in translate()
692 pub unsafe fn unmap(&mut self, virt: VirtAddr, unmap_parents: bool) -> Option<PageFlush<Arch>> { in unmap() argument
712 ) -> Option<(PhysAddr, PageFlags<Arch>, PageFlush<Arch>)> { in unmap_phys() argument
713 if !virt.check_aligned(Arch::PAGE_SIZE) { in unmap_phys()
720 .map(|(paddr, flags)| (paddr, flags, PageFlush::<Arch>::new(virt))); in unmap_phys()
727 f: impl FnOnce(&mut PageTable<Arch>, usize) -> T, in visit() argument
755 unsafe fn unmap_phys_inner<Arch: MemoryManagementArch>( in unmap_phys_inner()
757 table: &mut PageTable<Arch>, in unmap_phys_inner() argument
760 ) -> Option<(PhysAddr, PageFlags<Arch>)> { in unmap_phys_inner() argument
781 let x = (0..Arch::PAGE_ENTRY_NUM) in unmap_phys_inner()
795 impl<Arch, F: Debug> Debug for PageMapper<Arch, F> {
805 pub trait Flusher<Arch> {
807 fn consume(&mut self, flush: PageFlush<Arch>); in consume() argument
813 pub struct PageFlush<Arch> {
815 phantom: PhantomData<Arch>,
818 impl<Arch: MemoryManagementArch> PageFlush<Arch> {
827 unsafe { Arch::invalidate_page(self.virt) }; in flush()
839 pub struct PageFlushAll<Arch: MemoryManagementArch> {
840 phantom: PhantomData<fn() -> Arch>,
844 impl<Arch: MemoryManagementArch> PageFlushAll<Arch> {
852 unsafe { Arch::invalidate_all() }; in flush()
861 impl<Arch: MemoryManagementArch> Flusher<Arch> for PageFlushAll<Arch> {
863 fn consume(&mut self, flush: PageFlush<Arch>) { in consume() argument
868 impl<Arch: MemoryManagementArch, T: Flusher<Arch> + ?Sized> Flusher<Arch> for &mut T {
870 fn consume(&mut self, flush: PageFlush<Arch>) { in consume() argument
871 <T as Flusher<Arch>>::consume(self, flush); in consume()
875 impl<Arch: MemoryManagementArch> Flusher<Arch> for () {
876 fn consume(&mut self, _flush: PageFlush<Arch>) {} in consume() argument
879 impl<Arch: MemoryManagementArch> Drop for PageFlushAll<Arch> {
882 Arch::invalidate_all(); in drop()