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 status_t InitPostSem() = 0; 27 28 virtual bool Lock() = 0; 29 virtual void Unlock() = 0; 30 31 virtual addr_t MappedSize() const = 0; 32 virtual size_t MaxPagesNeededToMap(addr_t start, 33 addr_t end) const = 0; 34 35 virtual status_t Map(addr_t virtualAddress, 36 phys_addr_t physicalAddress, 37 uint32 attributes, uint32 memoryType, 38 vm_page_reservation* reservation) = 0; 39 virtual status_t Unmap(addr_t start, addr_t end) = 0; 40 41 // map not locked 42 virtual status_t UnmapPage(VMArea* area, addr_t address, 43 bool updatePageQueue) = 0; 44 virtual void UnmapPages(VMArea* area, addr_t base, 45 size_t size, bool updatePageQueue); 46 virtual void UnmapArea(VMArea* area, 47 bool deletingAddressSpace, 48 bool ignoreTopCachePageFlags); 49 50 virtual status_t Query(addr_t virtualAddress, 51 phys_addr_t* _physicalAddress, 52 uint32* _flags) = 0; 53 virtual status_t QueryInterrupt(addr_t virtualAddress, 54 phys_addr_t* _physicalAddress, 55 uint32* _flags) = 0; 56 57 virtual status_t Protect(addr_t base, addr_t top, 58 uint32 attributes, uint32 memoryType) = 0; 59 status_t ProtectPage(VMArea* area, addr_t address, 60 uint32 attributes); 61 status_t ProtectArea(VMArea* area, 62 uint32 attributes); 63 64 virtual status_t ClearFlags(addr_t virtualAddress, 65 uint32 flags) = 0; 66 67 virtual bool ClearAccessedAndModified( 68 VMArea* area, addr_t address, 69 bool unmapIfUnaccessed, 70 bool& _modified) = 0; 71 72 virtual void Flush() = 0; 73 74 protected: 75 recursive_lock fLock; 76 int32 fMapCount; 77 }; 78 79 80 struct VMPhysicalPageMapper { 81 VMPhysicalPageMapper(); 82 virtual ~VMPhysicalPageMapper(); 83 84 // get/put virtual address for physical page -- will be usuable on all CPUs 85 // (usually more expensive than the *_current_cpu() versions) 86 virtual status_t GetPage(phys_addr_t physicalAddress, 87 addr_t* _virtualAddress, 88 void** _handle) = 0; 89 virtual status_t PutPage(addr_t virtualAddress, 90 void* handle) = 0; 91 92 // get/put virtual address for physical page -- thread must be pinned the 93 // whole time 94 virtual status_t GetPageCurrentCPU( 95 phys_addr_t physicalAddress, 96 addr_t* _virtualAddress, 97 void** _handle) = 0; 98 virtual status_t PutPageCurrentCPU(addr_t virtualAddress, 99 void* _handle) = 0; 100 101 // get/put virtual address for physical in KDL 102 virtual status_t GetPageDebug(phys_addr_t physicalAddress, 103 addr_t* _virtualAddress, 104 void** _handle) = 0; 105 virtual status_t PutPageDebug(addr_t virtualAddress, 106 void* handle) = 0; 107 108 // memory operations on pages 109 virtual status_t MemsetPhysical(phys_addr_t address, int value, 110 phys_size_t length) = 0; 111 virtual status_t MemcpyFromPhysical(void* to, phys_addr_t from, 112 size_t length, bool user) = 0; 113 virtual status_t MemcpyToPhysical(phys_addr_t to, 114 const void* from, size_t length, 115 bool user) = 0; 116 virtual void MemcpyPhysicalPage(phys_addr_t to, 117 phys_addr_t from) = 0; 118 }; 119 120 121 122 inline status_t 123 VMTranslationMap::ProtectPage(VMArea* area, addr_t address, uint32 attributes) 124 { 125 return Protect(address, address + B_PAGE_SIZE - 1, attributes, 126 area->MemoryType()); 127 } 128 129 130 #include <vm/VMArea.h> 131 inline status_t 132 VMTranslationMap::ProtectArea(VMArea* area, uint32 attributes) 133 { 134 return Protect(area->Base(), area->Base() + area->Size() - 1, attributes, 135 area->MemoryType()); 136 } 137 138 139 #include <arch/vm_translation_map.h> 140 141 #endif /* KERNEL_VM_VM_TRANSLATION_MAP_H */ 142