1 /* 2 * Copyright 2002-2010, Haiku. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Copyright 2001-2002, Travis Geiselbrecht. All rights reserved. 6 * Distributed under the terms of the NewOS License. 7 */ 8 #ifndef KERNEL_VM_VM_TRANSLATION_MAP_H 9 #define KERNEL_VM_VM_TRANSLATION_MAP_H 10 11 12 #include <kernel.h> 13 #include <lock.h> 14 15 #include <vm/VMArea.h> 16 17 18 struct kernel_args; 19 struct vm_page_reservation; 20 21 22 struct VMTranslationMap { 23 VMTranslationMap(); 24 virtual ~VMTranslationMap(); 25 26 virtual bool Lock() = 0; 27 virtual void Unlock() = 0; 28 29 virtual addr_t MappedSize() const = 0; 30 virtual size_t MaxPagesNeededToMap(addr_t start, 31 addr_t end) const = 0; 32 33 virtual status_t Map(addr_t virtualAddress, 34 phys_addr_t physicalAddress, 35 uint32 attributes, uint32 memoryType, 36 vm_page_reservation* reservation) = 0; 37 virtual status_t Unmap(addr_t start, addr_t end) = 0; 38 39 virtual status_t DebugMarkRangePresent(addr_t start, addr_t end, 40 bool markPresent); 41 42 // map not locked 43 virtual status_t UnmapPage(VMArea* area, addr_t address, 44 bool updatePageQueue) = 0; 45 virtual void UnmapPages(VMArea* area, addr_t base, 46 size_t size, bool updatePageQueue); 47 virtual void UnmapArea(VMArea* area, 48 bool deletingAddressSpace, 49 bool ignoreTopCachePageFlags); 50 51 virtual status_t Query(addr_t virtualAddress, 52 phys_addr_t* _physicalAddress, 53 uint32* _flags) = 0; 54 virtual status_t QueryInterrupt(addr_t virtualAddress, 55 phys_addr_t* _physicalAddress, 56 uint32* _flags) = 0; 57 58 virtual status_t Protect(addr_t base, addr_t top, 59 uint32 attributes, uint32 memoryType) = 0; 60 status_t ProtectPage(VMArea* area, addr_t address, 61 uint32 attributes); 62 status_t ProtectArea(VMArea* area, 63 uint32 attributes); 64 65 virtual status_t ClearFlags(addr_t virtualAddress, 66 uint32 flags) = 0; 67 68 virtual bool ClearAccessedAndModified( 69 VMArea* area, addr_t address, 70 bool unmapIfUnaccessed, 71 bool& _modified) = 0; 72 73 virtual void Flush() = 0; 74 75 protected: 76 void PageUnmapped(VMArea* area, 77 page_num_t pageNumber, bool accessed, 78 bool modified, bool updatePageQueue); 79 void UnaccessedPageUnmapped(VMArea* area, 80 page_num_t pageNumber); 81 82 protected: 83 recursive_lock fLock; 84 int32 fMapCount; 85 }; 86 87 88 struct VMPhysicalPageMapper { 89 VMPhysicalPageMapper(); 90 virtual ~VMPhysicalPageMapper(); 91 92 // get/put virtual address for physical page -- will be usuable on all CPUs 93 // (usually more expensive than the *_current_cpu() versions) 94 virtual status_t GetPage(phys_addr_t physicalAddress, 95 addr_t* _virtualAddress, 96 void** _handle) = 0; 97 virtual status_t PutPage(addr_t virtualAddress, 98 void* handle) = 0; 99 100 // get/put virtual address for physical page -- thread must be pinned the 101 // whole time 102 virtual status_t GetPageCurrentCPU( 103 phys_addr_t physicalAddress, 104 addr_t* _virtualAddress, 105 void** _handle) = 0; 106 virtual status_t PutPageCurrentCPU(addr_t virtualAddress, 107 void* _handle) = 0; 108 109 // get/put virtual address for physical in KDL 110 virtual status_t GetPageDebug(phys_addr_t physicalAddress, 111 addr_t* _virtualAddress, 112 void** _handle) = 0; 113 virtual status_t PutPageDebug(addr_t virtualAddress, 114 void* handle) = 0; 115 116 // memory operations on pages 117 virtual status_t MemsetPhysical(phys_addr_t address, int value, 118 phys_size_t length) = 0; 119 virtual status_t MemcpyFromPhysical(void* to, phys_addr_t from, 120 size_t length, bool user) = 0; 121 virtual status_t MemcpyToPhysical(phys_addr_t to, 122 const void* from, size_t length, 123 bool user) = 0; 124 virtual void MemcpyPhysicalPage(phys_addr_t to, 125 phys_addr_t from) = 0; 126 }; 127 128 129 130 inline status_t 131 VMTranslationMap::ProtectPage(VMArea* area, addr_t address, uint32 attributes) 132 { 133 return Protect(address, address + B_PAGE_SIZE - 1, attributes, 134 area->MemoryType()); 135 } 136 137 138 #include <vm/VMArea.h> 139 inline status_t 140 VMTranslationMap::ProtectArea(VMArea* area, uint32 attributes) 141 { 142 return Protect(area->Base(), area->Base() + area->Size() - 1, attributes, 143 area->MemoryType()); 144 } 145 146 147 #include <arch/vm_translation_map.h> 148 149 #endif /* KERNEL_VM_VM_TRANSLATION_MAP_H */ 150