1 /* 2 * Copyright 2022 Haiku, Inc. All Rights Reserved. 3 * Distributed under the terms of the MIT License. 4 */ 5 #ifndef VMSA_V8_TRANSLATION_MAP_H 6 #define VMSA_V8_TRANSLATION_MAP_H 7 8 9 #include <arch_cpu_defs.h> 10 #include <vm/VMTranslationMap.h> 11 12 13 struct VMSAv8TranslationMap : public VMTranslationMap { 14 public: 15 VMSAv8TranslationMap( 16 bool kernel, phys_addr_t pageTable, int pageBits, int vaBits, int minBlockLevel); 17 ~VMSAv8TranslationMap(); 18 19 virtual bool Lock(); 20 virtual void Unlock(); 21 22 virtual addr_t MappedSize() const; 23 virtual size_t MaxPagesNeededToMap(addr_t start, 24 addr_t end) const; 25 26 virtual status_t Map(addr_t virtualAddress, 27 phys_addr_t physicalAddress, 28 uint32 attributes, uint32 memoryType, 29 vm_page_reservation* reservation); 30 virtual status_t Unmap(addr_t start, addr_t end); 31 32 virtual status_t UnmapPage(VMArea* area, addr_t address, 33 bool updatePageQueue); 34 /* 35 virtual void UnmapPages(VMArea* area, addr_t base, 36 size_t size, bool updatePageQueue); 37 virtual void UnmapArea(VMArea* area, 38 bool deletingAddressSpace, 39 bool ignoreTopCachePageFlags); 40 */ 41 42 virtual status_t Query(addr_t virtualAddress, 43 phys_addr_t* _physicalAddress, 44 uint32* _flags); 45 virtual status_t QueryInterrupt(addr_t virtualAddress, 46 phys_addr_t* _physicalAddress, 47 uint32* _flags); 48 49 virtual status_t Protect(addr_t base, addr_t top, 50 uint32 attributes, uint32 memoryType); 51 52 virtual status_t ClearFlags(addr_t virtualAddress, 53 uint32 flags); 54 55 virtual bool ClearAccessedAndModified( 56 VMArea* area, addr_t address, 57 bool unmapIfUnaccessed, 58 bool& _modified); 59 60 virtual void Flush(); 61 62 enum HWFeature { 63 HW_ACCESS = 0x1, 64 HW_DIRTY = 0x2 65 }; 66 67 static uint32_t fHwFeature; 68 static uint64_t fMair; 69 70 static uint64_t GetMemoryAttr(uint32 attributes, uint32 memoryType, bool isKernel); 71 static int CalcStartLevel(int vaBits, int pageBits); 72 73 private: 74 bool fIsKernel; 75 phys_addr_t fPageTable; 76 int fPageBits; 77 int fVaBits; 78 int fMinBlockLevel; 79 80 int fInitialLevel; 81 82 enum class VMAction { MAP, SET_ATTR, CLEAR_FLAGS, UNMAP }; 83 84 uint64_t tmp_pte; // todo: remove kludge 85 86 private: 87 static uint8_t MairIndex(uint8_t type); 88 uint64_t ClearAttrFlags(uint64_t attr, uint32 flags); 89 uint64_t MoveAttrFlags(uint64_t newAttr, uint64_t oldAttr); 90 bool ValidateVa(addr_t va); 91 uint64_t* TableFromPa(phys_addr_t pa); 92 uint64_t MakeBlock(phys_addr_t pa, int level, uint64_t attr); 93 void FreeTable(phys_addr_t ptPa, int level); 94 phys_addr_t MakeTable(phys_addr_t ptPa, int level, int index, vm_page_reservation* reservation); 95 void MapRange(phys_addr_t ptPa, int level, addr_t va, phys_addr_t pa, size_t size, 96 VMAction action, uint64_t attr, vm_page_reservation* reservation); 97 bool WalkTable(phys_addr_t ptPa, int level, addr_t va, phys_addr_t* pa, uint64_t* attr); 98 }; 99 100 101 #endif 102