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