From 3b0c1b5227ab487b1963faea4d046cba4d0622ff Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Sat, 1 May 2010 20:41:57 +0000 Subject: [PATCH] * VMArea: Made memory_type private and added setter and getter methods. * Don't set the VMArea's memory type in arch_vm_set_memory_type(), but let the callers do that. * vm_set_area_memory_type(): Does nothing, if the memory type doesn't change. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@36573 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- headers/private/kernel/vm/VMArea.h | 26 ++++++++++++++++++++++++-- src/system/kernel/arch/x86/arch_vm.cpp | 6 ++---- src/system/kernel/vm/vm.cpp | 18 ++++++++++++++++-- 3 files changed, 42 insertions(+), 8 deletions(-) diff --git a/headers/private/kernel/vm/VMArea.h b/headers/private/kernel/vm/VMArea.h index 9f08378d36..c4b9ac92f0 100644 --- a/headers/private/kernel/vm/VMArea.h +++ b/headers/private/kernel/vm/VMArea.h @@ -1,5 +1,5 @@ /* - * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de. + * Copyright 2009-2010, Ingo Weinhold, ingo_weinhold@gmx.de. * Copyright 2002-2009, Axel Dörfler, axeld@pinc-software.de. * Distributed under the terms of the MIT License. * @@ -10,6 +10,8 @@ #define _KERNEL_VM_VM_AREA_H +#include + #include #include #include @@ -91,8 +93,11 @@ struct VMArea { area_id id; uint32 protection; uint16 wiring; - uint16 memory_type; +private: + uint16 memory_type; // >> shifted by MEMORY_TYPE_SHIFT + +public: VMCache* cache; vint32 no_cache_change; off_t cache_offset; @@ -108,6 +113,9 @@ struct VMArea { addr_t Base() const { return fBase; } size_t Size() const { return fSize; } + inline uint32 MemoryType() const; + inline void SetMemoryType(uint32 memoryType); + bool ContainsAddress(addr_t address) const { return address >= fBase && address <= fBase + (fSize - 1); } @@ -204,4 +212,18 @@ private: }; +uint32 +VMArea::MemoryType() const +{ + return (uint32)memory_type << MEMORY_TYPE_SHIFT; +} + + +void +VMArea::SetMemoryType(uint32 memoryType) +{ + memory_type = memoryType >> MEMORY_TYPE_SHIFT; +} + + #endif // _KERNEL_VM_VM_AREA_H diff --git a/src/system/kernel/arch/x86/arch_vm.cpp b/src/system/kernel/arch/x86/arch_vm.cpp index 6bdb4a902c..1c30dba66b 100644 --- a/src/system/kernel/arch/x86/arch_vm.cpp +++ b/src/system/kernel/arch/x86/arch_vm.cpp @@ -678,7 +678,7 @@ arch_vm_supports_protection(uint32 protection) void arch_vm_unset_memory_type(struct VMArea *area) { - if (area->memory_type == 0) + if (area->MemoryType() == 0) return; remove_memory_type_range(area->id); @@ -686,9 +686,7 @@ arch_vm_unset_memory_type(struct VMArea *area) status_t -arch_vm_set_memory_type(struct VMArea *area, addr_t physicalBase, - uint32 type) +arch_vm_set_memory_type(struct VMArea *area, addr_t physicalBase, uint32 type) { - area->memory_type = type >> MEMORY_TYPE_SHIFT; return add_memory_type_range(area->id, physicalBase, area->Size(), type); } diff --git a/src/system/kernel/vm/vm.cpp b/src/system/kernel/vm/vm.cpp index c164df433e..1f4e5ad77a 100644 --- a/src/system/kernel/vm/vm.cpp +++ b/src/system/kernel/vm/vm.cpp @@ -1444,6 +1444,8 @@ vm_map_physical_memory(team_id team, const char* name, void** _address, if (memoryType == 0) memoryType = B_MTR_UC; + area->SetMemoryType(memoryType); + status = arch_vm_set_memory_type(area, physicalAddress, memoryType); if (status != B_OK) delete_area(locker.AddressSpace(), area, false); @@ -3038,7 +3040,7 @@ dump_area_struct(VMArea* area, bool mappings) kprintf("size:\t\t0x%lx\n", area->Size()); kprintf("protection:\t0x%lx\n", area->protection); kprintf("wiring:\t\t0x%x\n", area->wiring); - kprintf("memory_type:\t0x%x\n", area->memory_type); + kprintf("memory_type:\t%#" B_PRIx32 "\n", area->MemoryType()); kprintf("cache:\t\t%p\n", area->cache); kprintf("cache_type:\t%s\n", cache_type_to_string(area->cache_type)); kprintf("cache_offset:\t0x%Lx\n", area->cache_offset); @@ -4457,7 +4459,19 @@ vm_set_area_memory_type(area_id id, addr_t physicalBase, uint32 type) if (status != B_OK) return status; - return arch_vm_set_memory_type(area, physicalBase, type); + // nothing to do, if the type doesn't change + uint32 oldType = area->MemoryType(); + if (type == oldType) + return B_OK; + + // set the physical memory type + status_t error = arch_vm_set_memory_type(area, physicalBase, type); + if (error != B_OK) + return error; + + area->SetMemoryType(type); + return B_OK; + }