2 * Copyright 2002-2010, Haiku. All rights reserved.
3 * Distributed under the terms of the MIT License.
5 * Copyright 2001-2002, Travis Geiselbrecht. All rights reserved.
6 * Distributed under the terms of the NewOS License.
8 #ifndef KERNEL_VM_VM_TRANSLATION_MAP_H
9 #define KERNEL_VM_VM_TRANSLATION_MAP_H
15 #include <vm/VMArea.h>
19 struct vm_page_reservation
;
22 struct VMTranslationMap
{
23 struct ReverseMappingInfoCallback
;
27 virtual ~VMTranslationMap();
29 virtual bool Lock() = 0;
30 virtual void Unlock() = 0;
32 virtual addr_t
MappedSize() const = 0;
33 virtual size_t MaxPagesNeededToMap(addr_t start
,
34 addr_t end
) const = 0;
36 virtual status_t
Map(addr_t virtualAddress
,
37 phys_addr_t physicalAddress
,
38 uint32 attributes
, uint32 memoryType
,
39 vm_page_reservation
* reservation
) = 0;
40 virtual status_t
Unmap(addr_t start
, addr_t end
) = 0;
42 virtual status_t
DebugMarkRangePresent(addr_t start
, addr_t end
,
46 virtual status_t
UnmapPage(VMArea
* area
, addr_t address
,
47 bool updatePageQueue
) = 0;
48 virtual void UnmapPages(VMArea
* area
, addr_t base
,
49 size_t size
, bool updatePageQueue
);
50 virtual void UnmapArea(VMArea
* area
,
51 bool deletingAddressSpace
,
52 bool ignoreTopCachePageFlags
);
54 virtual status_t
Query(addr_t virtualAddress
,
55 phys_addr_t
* _physicalAddress
,
57 virtual status_t
QueryInterrupt(addr_t virtualAddress
,
58 phys_addr_t
* _physicalAddress
,
61 virtual status_t
Protect(addr_t base
, addr_t top
,
62 uint32 attributes
, uint32 memoryType
) = 0;
63 status_t
ProtectPage(VMArea
* area
, addr_t address
,
65 status_t
ProtectArea(VMArea
* area
,
68 virtual status_t
ClearFlags(addr_t virtualAddress
,
71 virtual bool ClearAccessedAndModified(
72 VMArea
* area
, addr_t address
,
73 bool unmapIfUnaccessed
,
76 virtual void Flush() = 0;
78 // backends for KDL commands
79 virtual void DebugPrintMappingInfo(addr_t virtualAddress
);
80 virtual bool DebugGetReverseMappingInfo(
81 phys_addr_t physicalAddress
,
82 ReverseMappingInfoCallback
& callback
);
85 void PageUnmapped(VMArea
* area
,
86 page_num_t pageNumber
, bool accessed
,
87 bool modified
, bool updatePageQueue
);
88 void UnaccessedPageUnmapped(VMArea
* area
,
89 page_num_t pageNumber
);
97 struct VMTranslationMap::ReverseMappingInfoCallback
{
98 virtual ~ReverseMappingInfoCallback();
100 virtual bool HandleVirtualAddress(addr_t virtualAddress
) = 0;
104 struct VMPhysicalPageMapper
{
105 VMPhysicalPageMapper();
106 virtual ~VMPhysicalPageMapper();
108 // get/put virtual address for physical page -- will be usuable on all CPUs
109 // (usually more expensive than the *_current_cpu() versions)
110 virtual status_t
GetPage(phys_addr_t physicalAddress
,
111 addr_t
* _virtualAddress
,
113 virtual status_t
PutPage(addr_t virtualAddress
,
116 // get/put virtual address for physical page -- thread must be pinned the
118 virtual status_t
GetPageCurrentCPU(
119 phys_addr_t physicalAddress
,
120 addr_t
* _virtualAddress
,
122 virtual status_t
PutPageCurrentCPU(addr_t virtualAddress
,
125 // get/put virtual address for physical in KDL
126 virtual status_t
GetPageDebug(phys_addr_t physicalAddress
,
127 addr_t
* _virtualAddress
,
129 virtual status_t
PutPageDebug(addr_t virtualAddress
,
132 // memory operations on pages
133 virtual status_t
MemsetPhysical(phys_addr_t address
, int value
,
134 phys_size_t length
) = 0;
135 virtual status_t
MemcpyFromPhysical(void* to
, phys_addr_t from
,
136 size_t length
, bool user
) = 0;
137 virtual status_t
MemcpyToPhysical(phys_addr_t to
,
138 const void* from
, size_t length
,
140 virtual void MemcpyPhysicalPage(phys_addr_t to
,
141 phys_addr_t from
) = 0;
147 VMTranslationMap::ProtectPage(VMArea
* area
, addr_t address
, uint32 attributes
)
149 return Protect(address
, address
+ B_PAGE_SIZE
- 1, attributes
,
154 #include <vm/VMArea.h>
156 VMTranslationMap::ProtectArea(VMArea
* area
, uint32 attributes
)
158 return Protect(area
->Base(), area
->Base() + area
->Size() - 1, attributes
,
163 #include <arch/vm_translation_map.h>
165 #endif /* KERNEL_VM_VM_TRANSLATION_MAP_H */