Author: bonefish Date: 2009-12-02 19:05:10 +0100 (Wed, 02 Dec 2009) New Revision: 34449 Changeset: http://dev.haiku-os.org/changeset/34449/haiku Added: haiku/trunk/headers/private/kernel/vm/ haiku/trunk/headers/private/kernel/vm/VMAddressSpace.h haiku/trunk/headers/private/kernel/vm/VMCache.h haiku/trunk/headers/private/kernel/vm/vm.h haiku/trunk/headers/private/kernel/vm/vm_page.h haiku/trunk/headers/private/kernel/vm/vm_priv.h haiku/trunk/headers/private/kernel/vm/vm_translation_map.h haiku/trunk/headers/private/kernel/vm/vm_types.h haiku/trunk/src/system/kernel/vm/VMAddressSpace.cpp haiku/trunk/src/system/kernel/vm/VMCache.cpp Removed: haiku/trunk/headers/private/kernel/vm.h haiku/trunk/headers/private/kernel/vm_address_space.h haiku/trunk/headers/private/kernel/vm_cache.h haiku/trunk/headers/private/kernel/vm_page.h haiku/trunk/headers/private/kernel/vm_priv.h haiku/trunk/headers/private/kernel/vm_translation_map.h haiku/trunk/headers/private/kernel/vm_types.h haiku/trunk/src/system/kernel/vm/vm_address_space.cpp haiku/trunk/src/system/kernel/vm/vm_cache.cpp Modified: haiku/trunk/headers/private/kernel/arch/arm/arch_vm.h haiku/trunk/headers/private/kernel/arch/m68k/arch_vm.h haiku/trunk/headers/private/kernel/arch/vm_translation_map.h haiku/trunk/headers/private/kernel/file_cache.h haiku/trunk/headers/private/kernel/util/syscall_args.h haiku/trunk/src/add-ons/kernel/bus_managers/acpi/oshaiku.c haiku/trunk/src/add-ons/kernel/bus_managers/agp_gart/agp_gart.cpp haiku/trunk/src/add-ons/kernel/bus_managers/ata/ATAChannel.cpp haiku/trunk/src/add-ons/kernel/bus_managers/ata/ATAHelper.cpp haiku/trunk/src/add-ons/kernel/bus_managers/ide/emulation.c haiku/trunk/src/add-ons/kernel/bus_managers/ide/pio.c haiku/trunk/src/add-ons/kernel/bus_managers/scsi/dma_buffer.c haiku/trunk/src/add-ons/kernel/bus_managers/scsi/emulation.c haiku/trunk/src/add-ons/kernel/busses/scsi/ahci/util.c haiku/trunk/src/add-ons/kernel/drivers/graphics/vesa/vesa.cpp haiku/trunk/src/system/kernel/arch/arm/arch_debug_console.cpp haiku/trunk/src/system/kernel/arch/arm/arch_int.cpp haiku/trunk/src/system/kernel/arch/arm/arch_thread.cpp haiku/trunk/src/system/kernel/arch/arm/arch_vm.cpp haiku/trunk/src/system/kernel/arch/arm/arch_vm_translation_map.cpp haiku/trunk/src/system/kernel/arch/generic/generic_vm_physical_page_mapper.cpp haiku/trunk/src/system/kernel/arch/generic/generic_vm_physical_page_ops.cpp haiku/trunk/src/system/kernel/arch/m68k/arch_debug_console.cpp haiku/trunk/src/system/kernel/arch/m68k/arch_int.cpp haiku/trunk/src/system/kernel/arch/m68k/arch_thread.cpp haiku/trunk/src/system/kernel/arch/m68k/arch_vm.cpp haiku/trunk/src/system/kernel/arch/m68k/arch_vm_translation_map.cpp haiku/trunk/src/system/kernel/arch/m68k/arch_vm_translation_map_impl.cpp haiku/trunk/src/system/kernel/arch/mipsel/arch_debug_console.cpp haiku/trunk/src/system/kernel/arch/mipsel/arch_int.cpp haiku/trunk/src/system/kernel/arch/mipsel/arch_thread.cpp haiku/trunk/src/system/kernel/arch/mipsel/arch_vm.cpp haiku/trunk/src/system/kernel/arch/mipsel/arch_vm_translation_map.cpp haiku/trunk/src/system/kernel/arch/ppc/arch_debug_console.cpp haiku/trunk/src/system/kernel/arch/ppc/arch_int.cpp haiku/trunk/src/system/kernel/arch/ppc/arch_thread.cpp haiku/trunk/src/system/kernel/arch/ppc/arch_vm.cpp haiku/trunk/src/system/kernel/arch/ppc/arch_vm_translation_map.cpp haiku/trunk/src/system/kernel/arch/x86/arch_cpu.cpp haiku/trunk/src/system/kernel/arch/x86/arch_debug.cpp haiku/trunk/src/system/kernel/arch/x86/arch_int.cpp haiku/trunk/src/system/kernel/arch/x86/arch_smp.cpp haiku/trunk/src/system/kernel/arch/x86/arch_thread.cpp haiku/trunk/src/system/kernel/arch/x86/arch_vm.cpp haiku/trunk/src/system/kernel/arch/x86/arch_vm_translation_map.cpp haiku/trunk/src/system/kernel/arch/x86/bios.cpp haiku/trunk/src/system/kernel/arch/x86/vm86.cpp haiku/trunk/src/system/kernel/arch/x86/x86_physical_page_mapper_large_memory.cpp haiku/trunk/src/system/kernel/cache/file_cache.cpp haiku/trunk/src/system/kernel/cache/file_map.cpp haiku/trunk/src/system/kernel/cache/vnode_store.cpp haiku/trunk/src/system/kernel/cache/vnode_store.h haiku/trunk/src/system/kernel/commpage.cpp haiku/trunk/src/system/kernel/debug/BreakpointManager.cpp haiku/trunk/src/system/kernel/debug/debug.cpp haiku/trunk/src/system/kernel/debug/frame_buffer_console.cpp haiku/trunk/src/system/kernel/debug/gdb.cpp haiku/trunk/src/system/kernel/debug/system_profiler.cpp haiku/trunk/src/system/kernel/debug/tracing.cpp haiku/trunk/src/system/kernel/debug/user_debugger.cpp haiku/trunk/src/system/kernel/device_manager/IORequest.cpp haiku/trunk/src/system/kernel/device_manager/devfs.cpp haiku/trunk/src/system/kernel/elf.cpp haiku/trunk/src/system/kernel/fs/fifo.cpp haiku/trunk/src/system/kernel/fs/rootfs.cpp haiku/trunk/src/system/kernel/fs/vfs.cpp haiku/trunk/src/system/kernel/heap.cpp haiku/trunk/src/system/kernel/low_resource_manager.cpp haiku/trunk/src/system/kernel/main.cpp haiku/trunk/src/system/kernel/sem.cpp haiku/trunk/src/system/kernel/slab/Slab.cpp haiku/trunk/src/system/kernel/syscalls.cpp haiku/trunk/src/system/kernel/system_info.cpp haiku/trunk/src/system/kernel/team.cpp haiku/trunk/src/system/kernel/thread.cpp haiku/trunk/src/system/kernel/vm/Jamfile haiku/trunk/src/system/kernel/vm/VMAnonymousCache.cpp haiku/trunk/src/system/kernel/vm/VMAnonymousCache.h haiku/trunk/src/system/kernel/vm/VMAnonymousNoSwapCache.cpp haiku/trunk/src/system/kernel/vm/VMAnonymousNoSwapCache.h haiku/trunk/src/system/kernel/vm/VMDeviceCache.h haiku/trunk/src/system/kernel/vm/VMNullCache.h haiku/trunk/src/system/kernel/vm/vm.cpp haiku/trunk/src/system/kernel/vm/vm_daemons.cpp haiku/trunk/src/system/kernel/vm/vm_page.cpp Log: * Moved the VM headers into subdirectory vm/. * Renamed vm_cache.h/vm_address_space.h to VMCache.h/VMAddressSpace. Modified: haiku/trunk/headers/private/kernel/arch/arm/arch_vm.h =================================================================== --- haiku/trunk/headers/private/kernel/arch/arm/arch_vm.h 2009-12-02 16:49:22 UTC (rev 34448) +++ haiku/trunk/headers/private/kernel/arch/arm/arch_vm.h 2009-12-02 18:05:10 UTC (rev 34449) @@ -5,7 +5,7 @@ #ifndef ARCH_ARM_VM_H #define ARCH_ARM_VM_H -//#include <vm_translation_map.h> +//#include <vm/vm_translation_map.h> /* This many pages will be read/written on I/O if possible */ @@ -22,7 +22,7 @@ status_t (*arch_vm_translation_map_init)(kernel_args *args); status_t (*arch_vm_translation_map_init_post_area)(kernel_args *args); status_t (*arch_vm_translation_map_init_post_sem)(kernel_args *args); - status_t (*arch_vm_translation_map_early_map)(kernel_args *ka, addr_t virtualAddress, addr_t physicalAddress, + status_t (*arch_vm_translation_map_early_map)(kernel_args *ka, addr_t virtualAddress, addr_t physicalAddress, uint8 attributes, addr_t (*get_free_page)(kernel_args *)); status_t (*arch_vm_translation_map_early_query)(addr_t va, addr_t *out_physical);*/ // void (*m68k_set_pgdir)(void *); Modified: haiku/trunk/headers/private/kernel/arch/m68k/arch_vm.h =================================================================== --- haiku/trunk/headers/private/kernel/arch/m68k/arch_vm.h 2009-12-02 16:49:22 UTC (rev 34448) +++ haiku/trunk/headers/private/kernel/arch/m68k/arch_vm.h 2009-12-02 18:05:10 UTC (rev 34449) @@ -5,7 +5,7 @@ #ifndef ARCH_M68K_VM_H #define ARCH_M68K_VM_H -#include <vm_translation_map.h> +#include <vm/vm_translation_map.h> /* This many pages will be read/written on I/O if possible */ @@ -22,7 +22,7 @@ status_t (*arch_vm_translation_map_init)(kernel_args *args); status_t (*arch_vm_translation_map_init_post_area)(kernel_args *args); status_t (*arch_vm_translation_map_init_post_sem)(kernel_args *args); - status_t (*arch_vm_translation_map_early_map)(kernel_args *ka, addr_t virtualAddress, addr_t physicalAddress, + status_t (*arch_vm_translation_map_early_map)(kernel_args *ka, addr_t virtualAddress, addr_t physicalAddress, uint8 attributes, addr_t (*get_free_page)(kernel_args *)); status_t (*arch_vm_translation_map_early_query)(addr_t va, addr_t *out_physical); void (*m68k_set_pgdir)(void *); Modified: haiku/trunk/headers/private/kernel/arch/vm_translation_map.h =================================================================== --- haiku/trunk/headers/private/kernel/arch/vm_translation_map.h 2009-12-02 16:49:22 UTC (rev 34448) +++ haiku/trunk/headers/private/kernel/arch/vm_translation_map.h 2009-12-02 18:05:10 UTC (rev 34449) @@ -9,7 +9,7 @@ #define KERNEL_ARCH_VM_TRANSLATION_MAP_H -#include <vm_translation_map.h> +#include <vm/vm_translation_map.h> #ifdef __cplusplus Modified: haiku/trunk/headers/private/kernel/file_cache.h =================================================================== --- haiku/trunk/headers/private/kernel/file_cache.h 2009-12-02 16:49:22 UTC (rev 34448) +++ haiku/trunk/headers/private/kernel/file_cache.h 2009-12-02 18:05:10 UTC (rev 34449) @@ -7,7 +7,7 @@ #include <vfs.h> -#include <vm_types.h> +#include <vm/vm_types.h> #include <module.h> Modified: haiku/trunk/headers/private/kernel/util/syscall_args.h =================================================================== --- haiku/trunk/headers/private/kernel/util/syscall_args.h 2009-12-02 16:49:22 UTC (rev 34448) +++ haiku/trunk/headers/private/kernel/util/syscall_args.h 2009-12-02 18:05:10 UTC (rev 34449) @@ -4,8 +4,8 @@ #define _SYSCALL_ARGS_H #include <kernel.h> -//#include <vm.h> + // Hack to be able to use the IS_USER_ADDRESS macro when compiling for R5. #ifdef R5_MEMORY_LAYOUT # undef KERNEL_BASE @@ -34,4 +34,5 @@ return user_memcpy(user, &kernel, sizeof(T)); } + #endif // _SYSCALL_ARGS_H Copied: haiku/trunk/headers/private/kernel/vm/VMAddressSpace.h (from rev 34448, haiku/trunk/headers/private/kernel/vm_address_space.h) =================================================================== --- haiku/trunk/headers/private/kernel/vm/VMAddressSpace.h (rev 0) +++ haiku/trunk/headers/private/kernel/vm/VMAddressSpace.h 2009-12-02 18:05:10 UTC (rev 34449) @@ -0,0 +1,118 @@ +/* + * Copyright 2009, Ingo Weinhold, ingo_weinhold@xxxxxxx + * Copyright 2002-2008, Axel Dörfler, axeld@xxxxxxxxxxxxxxxxx All rights reserved. + * Distributed under the terms of the MIT License. + * + * Copyright 2001-2002, Travis Geiselbrecht. All rights reserved. + * Distributed under the terms of the NewOS License. + */ +#ifndef _KERNEL_VM_VM_ADDRESS_SPACE_H +#define _KERNEL_VM_VM_ADDRESS_SPACE_H + + +#include <OS.h> + +#include <vm/vm_translation_map.h> + + +struct VMArea; + + +struct VMAddressSpace { + VMAddressSpace(team_id id, addr_t base, + size_t size, bool kernel); + ~VMAddressSpace(); + + static status_t Init(); + static status_t InitPostSem(); + + team_id ID() const { return fID; } + addr_t Base() const { return fBase; } + size_t Size() const { return fSize; } + bool IsBeingDeleted() const { return fDeleting; } + + vm_translation_map& TranslationMap() { return fTranslationMap; } + + status_t ReadLock() + { return rw_lock_read_lock(&fLock); } + void ReadUnlock() + { rw_lock_read_unlock(&fLock); } + status_t WriteLock() + { return rw_lock_write_lock(&fLock); } + void WriteUnlock() + { rw_lock_write_unlock(&fLock); } + + int32 RefCount() const + { return fRefCount; } + + void Get() { atomic_add(&fRefCount, 1); } + void Put(); + void RemoveAndPut(); + + void IncrementFaultCount() + { atomic_add(&fFaultCount, 1); } + void IncrementChangeCount() + { fChangeCount++; } + + VMArea* LookupArea(addr_t address); + void RemoveArea(VMArea* area); + + static status_t Create(team_id teamID, addr_t base, size_t size, + bool kernel, + VMAddressSpace** _addressSpace); + + static team_id KernelID() + { return sKernelAddressSpace->ID(); } + static VMAddressSpace* Kernel() + { return sKernelAddressSpace; } + static VMAddressSpace* GetKernel(); + + static team_id CurrentID(); + static VMAddressSpace* GetCurrent(); + + static VMAddressSpace* Get(team_id teamID); + + VMAddressSpace*& HashTableLink() { return fHashTableLink; } + + void Dump() const; + +private: + static int _DumpCommand(int argc, char** argv); + static int _DumpListCommand(int argc, char** argv); + +public: + VMArea* areas; + +private: + struct HashDefinition; + +private: + VMAddressSpace* fHashTableLink; + addr_t fBase; + size_t fSize; + rw_lock fLock; + team_id fID; + int32 fRefCount; + int32 fFaultCount; + int32 fChangeCount; + vm_translation_map fTranslationMap; + VMArea* fAreaHint; + bool fDeleting; + static VMAddressSpace* sKernelAddressSpace; +}; + + + +#ifdef __cplusplus +extern "C" { +#endif + +status_t vm_delete_areas(struct VMAddressSpace *aspace); +#define vm_swap_address_space(from, to) arch_vm_aspace_swap(from, to) + +#ifdef __cplusplus +} +#endif + + +#endif /* _KERNEL_VM_VM_ADDRESS_SPACE_H */ Copied: haiku/trunk/headers/private/kernel/vm/VMCache.h (from rev 34448, haiku/trunk/headers/private/kernel/vm_cache.h) =================================================================== --- haiku/trunk/headers/private/kernel/vm/VMCache.h (rev 0) +++ haiku/trunk/headers/private/kernel/vm/VMCache.h 2009-12-02 18:05:10 UTC (rev 34449) @@ -0,0 +1,31 @@ +/* + * Copyright 2003-2007, Axel Dörfler, axeld@xxxxxxxxxxxxxxxxx + * Distributed under the terms of the MIT License. + * + * Copyright 2001-2002, Travis Geiselbrecht. All rights reserved. + * Distributed under the terms of the NewOS License. + */ +#ifndef _KERNEL_VM_VM_CACHE_H +#define _KERNEL_VM_VM_CACHE_H + + +#include <kernel.h> +#include <vm/vm.h> + + +struct kernel_args; + + +#ifdef __cplusplus +extern "C" { +#endif + +status_t vm_cache_init(struct kernel_args *args); +struct VMCache *vm_cache_acquire_locked_page_cache(struct vm_page *page, + bool dontWait); + +#ifdef __cplusplus +} +#endif + +#endif /* _KERNEL_VM_VM_CACHE_H */ Copied: haiku/trunk/headers/private/kernel/vm/vm.h (from rev 34448, haiku/trunk/headers/private/kernel/vm.h) =================================================================== --- haiku/trunk/headers/private/kernel/vm/vm.h (rev 0) +++ haiku/trunk/headers/private/kernel/vm/vm.h 2009-12-02 18:05:10 UTC (rev 34449) @@ -0,0 +1,157 @@ +/* + * Copyright 2002-2009, Axel Dörfler, axeld@xxxxxxxxxxxxxxxxx + * Distributed under the terms of the MIT License. + * + * Copyright 2001-2002, Travis Geiselbrecht. All rights reserved. + * Distributed under the terms of the NewOS License. + */ +#ifndef _KERNEL_VM_VM_H +#define _KERNEL_VM_VM_H + +#include <OS.h> + +#include <arch/vm.h> +#include <vm_defs.h> + + +struct iovec; +struct kernel_args; +struct team; +struct system_memory_info; +struct VMAddressSpace; +struct VMArea; +struct VMCache; +struct vm_page; +struct vnode; + + +// area creation flags +#define CREATE_AREA_DONT_WAIT 0x01 +#define CREATE_AREA_UNMAP_ADDRESS_RANGE 0x02 +#define CREATE_AREA_DONT_CLEAR 0x04 + + +#ifdef __cplusplus +extern "C" { +#endif + +// startup only +status_t vm_init(struct kernel_args *args); +status_t vm_init_post_sem(struct kernel_args *args); +status_t vm_init_post_thread(struct kernel_args *args); +status_t vm_init_post_modules(struct kernel_args *args); +void vm_free_kernel_args(struct kernel_args *args); +void vm_free_unused_boot_loader_range(addr_t start, addr_t end); +addr_t vm_allocate_early(struct kernel_args *args, size_t virtualSize, + size_t physicalSize, uint32 attributes); + +void slab_init(struct kernel_args *args, addr_t initialBase, + size_t initialSize); +void slab_init_post_sem(); +void slab_init_post_thread(); + +// to protect code regions with interrupts turned on +void permit_page_faults(void); +void forbid_page_faults(void); + +// private kernel only extension (should be moved somewhere else): +area_id create_area_etc(team_id team, const char *name, void **address, + uint32 addressSpec, uint32 size, uint32 lock, uint32 protection, + addr_t physicalAddress, uint32 flags); +area_id transfer_area(area_id id, void** _address, uint32 addressSpec, + team_id target, bool kernel); + +status_t vm_block_address_range(const char* name, void* address, addr_t size); +status_t vm_unreserve_address_range(team_id team, void *address, addr_t size); +status_t vm_reserve_address_range(team_id team, void **_address, + uint32 addressSpec, addr_t size, uint32 flags); +area_id vm_create_anonymous_area(team_id team, const char *name, void **address, + uint32 addressSpec, addr_t size, uint32 wiring, uint32 protection, + addr_t physicalAddress, uint32 flags, bool kernel); +area_id vm_map_physical_memory(team_id team, const char *name, void **address, + uint32 addressSpec, addr_t size, uint32 protection, addr_t phys_addr); +area_id vm_map_physical_memory_vecs(team_id team, const char* name, + void** _address, uint32 addressSpec, addr_t* _size, uint32 protection, + struct iovec* vecs, uint32 vecCount); +area_id vm_map_file(team_id aid, const char *name, void **address, + uint32 addressSpec, addr_t size, uint32 protection, uint32 mapping, + bool unmapAddressRange, int fd, off_t offset); +struct VMCache *vm_area_get_locked_cache(struct VMArea *area); +void vm_area_put_locked_cache(struct VMCache *cache); +area_id vm_create_null_area(team_id team, const char *name, void **address, + uint32 addressSpec, addr_t size); +area_id vm_copy_area(team_id team, const char *name, void **_address, + uint32 addressSpec, uint32 protection, area_id sourceID); +area_id vm_clone_area(team_id team, const char *name, void **address, + uint32 addressSpec, uint32 protection, uint32 mapping, + area_id sourceArea, bool kernel); +status_t vm_delete_area(team_id teamID, area_id areaID, bool kernel); +status_t vm_create_vnode_cache(struct vnode *vnode, struct VMCache **_cache); +status_t vm_set_area_memory_type(area_id id, addr_t physicalBase, uint32 type); +status_t vm_get_page_mapping(team_id team, addr_t vaddr, addr_t *paddr); +bool vm_test_map_modification(struct vm_page *page); +int32 vm_test_map_activation(struct vm_page *page, bool *_modified); +void vm_clear_map_flags(struct vm_page *page, uint32 flags); +void vm_remove_all_page_mappings(struct vm_page *page, uint32 *_flags); +bool vm_unmap_page(struct VMArea* area, addr_t virtualAddress, + bool preserveModified); +status_t vm_unmap_pages(struct VMArea *area, addr_t base, size_t length, + bool preserveModified); +status_t vm_map_page(struct VMArea *area, struct vm_page *page, addr_t address, + uint32 protection); + +status_t vm_get_physical_page(addr_t paddr, addr_t* vaddr, void** _handle); +status_t vm_put_physical_page(addr_t vaddr, void* handle); +status_t vm_get_physical_page_current_cpu(addr_t paddr, addr_t* vaddr, + void** _handle); +status_t vm_put_physical_page_current_cpu(addr_t vaddr, void* handle); +status_t vm_get_physical_page_debug(addr_t paddr, addr_t* vaddr, + void** _handle); +status_t vm_put_physical_page_debug(addr_t vaddr, void* handle); + +void vm_get_info(struct system_memory_info *info); +uint32 vm_num_page_faults(void); +off_t vm_available_memory(void); +off_t vm_available_not_needed_memory(void); +size_t vm_kernel_address_space_left(void); + +status_t vm_memset_physical(addr_t address, int value, size_t length); +status_t vm_memcpy_from_physical(void* to, addr_t from, size_t length, + bool user); +status_t vm_memcpy_to_physical(addr_t to, const void* from, size_t length, + bool user); +void vm_memcpy_physical_page(addr_t to, addr_t from); + +// user syscalls +area_id _user_create_area(const char *name, void **address, uint32 addressSpec, + size_t size, uint32 lock, uint32 protection); +status_t _user_delete_area(area_id area); + +area_id _user_map_file(const char *uname, void **uaddress, int addressSpec, + size_t size, int protection, int mapping, bool unmapAddressRange, + int fd, off_t offset); +status_t _user_unmap_memory(void *address, size_t size); +status_t _user_set_memory_protection(void* address, size_t size, + int protection); +status_t _user_sync_memory(void *address, size_t size, int flags); +status_t _user_memory_advice(void* address, size_t size, int advice); + +area_id _user_area_for(void *address); +area_id _user_find_area(const char *name); +status_t _user_get_area_info(area_id area, area_info *info); +status_t _user_get_next_area_info(team_id team, int32 *cookie, area_info *info); +status_t _user_resize_area(area_id area, size_t newSize); +area_id _user_transfer_area(area_id area, void **_address, uint32 addressSpec, + team_id target); +status_t _user_set_area_protection(area_id area, uint32 newProtection); +area_id _user_clone_area(const char *name, void **_address, uint32 addressSpec, + uint32 protection, area_id sourceArea); +status_t _user_reserve_address_range(addr_t* userAddress, uint32 addressSpec, + addr_t size); +status_t _user_unreserve_address_range(addr_t address, addr_t size); + +#ifdef __cplusplus +} +#endif + +#endif /* _KERNEL_VM_VM_H */ Copied: haiku/trunk/headers/private/kernel/vm/vm_page.h (from rev 34448, haiku/trunk/headers/private/kernel/vm_page.h) =================================================================== --- haiku/trunk/headers/private/kernel/vm/vm_page.h (rev 0) +++ haiku/trunk/headers/private/kernel/vm/vm_page.h 2009-12-02 18:05:10 UTC (rev 34449) @@ -0,0 +1,65 @@ +/* + * Copyright 2002-2009, Axel Dörfler, axeld@xxxxxxxxxxxxxxxxx + * Distributed under the terms of the MIT License. + * + * Copyright 2001-2002, Travis Geiselbrecht. All rights reserved. + * Distributed under the terms of the NewOS License. + */ +#ifndef _KERNEL_VM_VM_PAGE_H +#define _KERNEL_VM_VM_PAGE_H + + +#include <vm/vm.h> + + +struct kernel_args; + +extern int32 gMappedPagesCount; + +#ifdef __cplusplus +extern "C" { +#endif + +void vm_page_init_num_pages(struct kernel_args *args); +status_t vm_page_init(struct kernel_args *args); +status_t vm_page_init_post_area(struct kernel_args *args); +status_t vm_page_init_post_thread(struct kernel_args *args); + +status_t vm_mark_page_inuse(addr_t page); +status_t vm_mark_page_range_inuse(addr_t startPage, addr_t length); +void vm_page_free(struct VMCache *cache, struct vm_page *page); +status_t vm_page_set_state(struct vm_page *page, int state); +void vm_page_requeue(struct vm_page *page, bool tail); + +// get some data about the number of pages in the system +size_t vm_page_num_pages(void); +size_t vm_page_num_free_pages(void); +size_t vm_page_num_available_pages(void); +size_t vm_page_num_unused_pages(void); +void vm_page_get_stats(system_info *info); + +status_t vm_page_write_modified_page_range(struct VMCache *cache, + uint32 firstPage, uint32 endPage); +status_t vm_page_write_modified_pages(struct VMCache *cache); +void vm_page_schedule_write_page(struct vm_page *page); +void vm_page_schedule_write_page_range(struct VMCache *cache, + uint32 firstPage, uint32 endPage); + +void vm_page_unreserve_pages(uint32 count); +void vm_page_reserve_pages(uint32 count); +bool vm_page_try_reserve_pages(uint32 count); + +struct vm_page *vm_page_allocate_page(int pageState, bool reserved); +status_t vm_page_allocate_pages(int pageState, struct vm_page **pages, + uint32 numPages); +struct vm_page *vm_page_allocate_page_run(int state, addr_t base, + addr_t length); +struct vm_page *vm_page_allocate_page_run_no_base(int state, addr_t count); +struct vm_page *vm_page_at_index(int32 index); +struct vm_page *vm_lookup_page(addr_t pageNumber); + +#ifdef __cplusplus +} +#endif + +#endif /* _KERNEL_VM_VM_PAGE_H */ Copied: haiku/trunk/headers/private/kernel/vm/vm_priv.h (from rev 34448, haiku/trunk/headers/private/kernel/vm_priv.h) =================================================================== --- haiku/trunk/headers/private/kernel/vm/vm_priv.h (rev 0) +++ haiku/trunk/headers/private/kernel/vm/vm_priv.h 2009-12-02 18:05:10 UTC (rev 34449) @@ -0,0 +1,44 @@ +/* + * Copyright 2002-2008, Haiku. All rights reserved. + * Distributed under the terms of the MIT License. + * + * Copyright 2001-2002, Travis Geiselbrecht. All rights reserved. + * Distributed under the terms of the NewOS License. + */ +#ifndef _KERNEL_VM_VM_PRIV_H +#define _KERNEL_VM_VM_PRIV_H + + +#include <vm/vm_types.h> + + +// reserved area definitions +#define RESERVED_AREA_ID -1 +#define RESERVED_AVOID_BASE 0x01 + +// page attributes (in addition to B_READ_AREA etc.) +#define PAGE_MODIFIED 0x1000 +#define PAGE_ACCESSED 0x2000 +#define PAGE_PRESENT 0x4000 + + +#ifdef __cplusplus +extern "C" { +#endif + +// Should only be used by vm internals +status_t vm_page_fault(addr_t address, addr_t faultAddress, bool isWrite, + bool isUser, addr_t *newip); +void vm_unreserve_memory(size_t bytes); +status_t vm_try_reserve_memory(size_t bytes, bigtime_t timeout); +void vm_schedule_page_scanner(uint32 target); +status_t vm_daemon_init(void); + +const char *page_state_to_string(int state); + // for debugging purposes only + +#ifdef __cplusplus +} +#endif + +#endif /* _KERNEL_VM_VM_PRIV_H */ Copied: haiku/trunk/headers/private/kernel/vm/vm_translation_map.h (from rev 34448, haiku/trunk/headers/private/kernel/vm_translation_map.h) =================================================================== --- haiku/trunk/headers/private/kernel/vm/vm_translation_map.h (rev 0) +++ haiku/trunk/headers/private/kernel/vm/vm_translation_map.h 2009-12-02 18:05:10 UTC (rev 34449) @@ -0,0 +1,76 @@ +/* + * Copyright 2002-2007, Haiku. All rights reserved. + * Distributed under the terms of the MIT License. + * + * Copyright 2001-2002, Travis Geiselbrecht. All rights reserved. + * Distributed under the terms of the NewOS License. + */ +#ifndef KERNEL_VM_VM_TRANSLATION_MAP_H +#define KERNEL_VM_VM_TRANSLATION_MAP_H + + +#include <kernel.h> +#include <lock.h> + + +struct kernel_args; + + +typedef struct vm_translation_map { + struct vm_translation_map *next; + struct vm_translation_map_ops *ops; + recursive_lock lock; + int32 map_count; + struct vm_translation_map_arch_info *arch_data; +} vm_translation_map; + + +// table of operations the vm may want to do to this mapping +typedef struct vm_translation_map_ops { + void (*destroy)(vm_translation_map *map); + status_t (*lock)(vm_translation_map *map); + status_t (*unlock)(vm_translation_map *map); + size_t (*map_max_pages_need)(vm_translation_map *map, addr_t start, addr_t end); + status_t (*map)(vm_translation_map *map, addr_t va, addr_t pa, + uint32 attributes); + status_t (*unmap)(vm_translation_map *map, addr_t start, addr_t end); + status_t (*query)(vm_translation_map *map, addr_t va, addr_t *_outPhysical, + uint32 *_outFlags); + status_t (*query_interrupt)(vm_translation_map *map, addr_t va, + addr_t *_outPhysical, uint32 *_outFlags); + addr_t (*get_mapped_size)(vm_translation_map*); + status_t (*protect)(vm_translation_map *map, addr_t base, addr_t top, + uint32 attributes); + status_t (*clear_flags)(vm_translation_map *map, addr_t va, uint32 flags); + void (*flush)(vm_translation_map *map); + + // get/put virtual address for physical page -- will be usuable on all CPUs + // (usually more expensive than the *_current_cpu() versions) + status_t (*get_physical_page)(addr_t physicalAddress, + addr_t *_virtualAddress, void **handle); + status_t (*put_physical_page)(addr_t virtualAddress, void *handle); + + // get/put virtual address for physical page -- thread must be pinned the + // whole time + status_t (*get_physical_page_current_cpu)(addr_t physicalAddress, + addr_t *_virtualAddress, void **handle); + status_t (*put_physical_page_current_cpu)(addr_t virtualAddress, + void *handle); + + // get/put virtual address for physical in KDL + status_t (*get_physical_page_debug)(addr_t physicalAddress, + addr_t *_virtualAddress, void **handle); + status_t (*put_physical_page_debug)(addr_t virtualAddress, void *handle); + + // memory operations on pages + status_t (*memset_physical)(addr_t address, int value, size_t length); + status_t (*memcpy_from_physical)(void* to, addr_t from, size_t length, + bool user); + status_t (*memcpy_to_physical)(addr_t to, const void* from, size_t length, + bool user); + void (*memcpy_physical_page)(addr_t to, addr_t from); +} vm_translation_map_ops; + +#include <arch/vm_translation_map.h> + +#endif /* KERNEL_VM_VM_TRANSLATION_MAP_H */ Copied: haiku/trunk/headers/private/kernel/vm/vm_types.h (from rev 34448, haiku/trunk/headers/private/kernel/vm_types.h) =================================================================== --- haiku/trunk/headers/private/kernel/vm/vm_types.h (rev 0) +++ haiku/trunk/headers/private/kernel/vm/vm_types.h 2009-12-02 18:05:10 UTC (rev 34449) @@ -0,0 +1,317 @@ +/* + * Copyright 2009, Ingo Weinhold, ingo_weinhold@xxxxxxx + * Copyright 2002-2009, Axel Dörfler, axeld@xxxxxxxxxxxxxxxxx + * Distributed under the terms of the MIT License. + * + * Copyright 2001-2002, Travis Geiselbrecht. All rights reserved. + * Distributed under the terms of the NewOS License. + */ +#ifndef _KERNEL_VM_VM_TYPES_H +#define _KERNEL_VM_VM_TYPES_H + + +#include <arch/vm_types.h> +#include <arch/vm_translation_map.h> +#include <condition_variable.h> +#include <kernel.h> +#include <lock.h> +#include <util/DoublyLinkedQueue.h> +#include <util/SplayTree.h> + +#include <sys/uio.h> + +#include "kernel_debug_config.h" + + +class AsyncIOCallback; +struct vm_page_mapping; +struct VMCache; +typedef DoublyLinkedListLink<vm_page_mapping> vm_page_mapping_link; + + +typedef struct vm_page_mapping { + vm_page_mapping_link page_link; + vm_page_mapping_link area_link; + struct vm_page *page; + struct VMArea *area; +} vm_page_mapping; + +class DoublyLinkedPageLink { + public: + inline vm_page_mapping_link *operator()(vm_page_mapping *element) const + { + return &element->page_link; + } + + inline const vm_page_mapping_link *operator()( + const vm_page_mapping *element) const + { + return &element->page_link; + } +}; + +class DoublyLinkedAreaLink { + public: + inline vm_page_mapping_link *operator()(vm_page_mapping *element) const + { + return &element->area_link; + } + + inline const vm_page_mapping_link *operator()( + const vm_page_mapping *element) const + { + return &element->area_link; + } +}; + +typedef class DoublyLinkedQueue<vm_page_mapping, DoublyLinkedPageLink> + vm_page_mappings; +typedef class DoublyLinkedQueue<vm_page_mapping, DoublyLinkedAreaLink> + VMAreaMappings; + +typedef uint32 page_num_t; + +struct vm_page { + struct vm_page* queue_prev; + struct vm_page* queue_next; + + addr_t physical_page_number; + + VMCache* cache; + page_num_t cache_offset; + // in page size units + + SplayTreeLink<vm_page> cache_link; + vm_page* cache_next; + + vm_page_mappings mappings; + +#if DEBUG_PAGE_QUEUE + void* queue; +#endif + +#if DEBUG_PAGE_CACHE_TRANSITIONS + uint32 debug_flags; + struct vm_page* collided_page; +#endif + + uint8 type : 2; + uint8 state : 3; + + uint8 is_cleared : 1; + // is currently only used in vm_page_allocate_page_run() + uint8 busy_writing : 1; + uint8 merge_swap : 1; + // used in VMAnonymousCache::Merge() + + int8 usage_count; + uint16 wired_count; +}; + +enum { + PAGE_TYPE_PHYSICAL = 0, + PAGE_TYPE_DUMMY, + PAGE_TYPE_GUARD +}; + +enum { + PAGE_STATE_ACTIVE = 0, + PAGE_STATE_INACTIVE, + PAGE_STATE_BUSY, + PAGE_STATE_MODIFIED, + PAGE_STATE_FREE, + PAGE_STATE_CLEAR, + PAGE_STATE_WIRED, + PAGE_STATE_UNUSED +}; + +enum { + CACHE_TYPE_RAM = 0, + CACHE_TYPE_VNODE, + CACHE_TYPE_DEVICE, + CACHE_TYPE_NULL +}; + +struct VMCachePagesTreeDefinition { + typedef page_num_t KeyType; + typedef vm_page NodeType; + + static page_num_t GetKey(const NodeType* node) + { + return node->cache_offset; + } + + static SplayTreeLink<NodeType>* GetLink(NodeType* node) + { + return &node->cache_link; + } + + static int Compare(page_num_t key, const NodeType* node) + { + return key == node->cache_offset ? 0 + : (key < node->cache_offset ? -1 : 1); + } + + static NodeType** GetListLink(NodeType* node) + { + return &node->cache_next; + } +}; + +typedef IteratableSplayTree<VMCachePagesTreeDefinition> VMCachePagesTree; + +struct VMCache { +public: + VMCache(); + virtual ~VMCache(); + + status_t Init(uint32 cacheType); + + virtual void Delete(); + + bool Lock() + { return mutex_lock(&fLock) == B_OK; } + bool TryLock() + { return mutex_trylock(&fLock) == B_OK; } + bool SwitchLock(mutex* from) + { return mutex_switch_lock(from, &fLock) + == B_OK; } + void Unlock(); + void AssertLocked() + { ASSERT_LOCKED_MUTEX(&fLock); } + + void AcquireRefLocked(); + void AcquireRef(); + void ReleaseRefLocked(); + void ReleaseRef(); + void ReleaseRefAndUnlock() + { ReleaseRefLocked(); Unlock(); } + + vm_page* LookupPage(off_t offset); + void InsertPage(vm_page* page, off_t offset); + void RemovePage(vm_page* page); + + void AddConsumer(VMCache* consumer); + + status_t InsertAreaLocked(VMArea* area); + status_t RemoveArea(VMArea* area); + + status_t WriteModified(); + status_t SetMinimalCommitment(off_t commitment); + status_t Resize(off_t newSize); + + status_t FlushAndRemoveAllPages(); + + // for debugging only + mutex* GetLock() + { return &fLock; } + int32 RefCount() const + { return fRefCount; } + + // backing store operations + virtual status_t Commit(off_t size); + virtual bool HasPage(off_t offset); + + virtual status_t Read(off_t offset, const iovec *vecs, size_t count, + uint32 flags, size_t *_numBytes); + virtual status_t Write(off_t offset, const iovec *vecs, size_t count, + uint32 flags, size_t *_numBytes); + virtual status_t WriteAsync(off_t offset, const iovec* vecs, + size_t count, size_t numBytes, uint32 flags, + AsyncIOCallback* callback); + virtual bool CanWritePage(off_t offset); + + virtual int32 MaxPagesPerWrite() const + { return -1; } // no restriction + virtual int32 MaxPagesPerAsyncWrite() const + { return -1; } // no restriction + + virtual status_t Fault(struct VMAddressSpace *aspace, + off_t offset); + + virtual void Merge(VMCache* source); + + virtual status_t AcquireUnreferencedStoreRef(); + virtual void AcquireStoreRef(); + virtual void ReleaseStoreRef(); + +private: + inline bool _IsMergeable() const; + + void _MergeWithOnlyConsumer(); + void _RemoveConsumer(VMCache* consumer); + + +public: + struct VMArea* areas; + struct list_link consumer_link; + struct list consumers; + // list of caches that use this cache as a source + VMCachePagesTree pages; + VMCache* source; + off_t virtual_base; + off_t virtual_end; + off_t committed_size; + // TODO: Remove! + uint32 page_count; + uint32 temporary : 1; + uint32 scan_skip : 1; + uint32 type : 6; + +#if DEBUG_CACHE_LIST + struct VMCache* debug_previous; + struct VMCache* debug_next; +#endif + +private: + int32 fRefCount; + mutex fLock; +}; + + +#if DEBUG_CACHE_LIST +extern VMCache* gDebugCacheList; +#endif + + +class VMCacheFactory { +public: + static status_t CreateAnonymousCache(VMCache*& cache, + bool canOvercommit, int32 numPrecommittedPages, + int32 numGuardPages, bool swappable); + static status_t CreateVnodeCache(VMCache*& cache, + struct vnode* vnode); + static status_t CreateDeviceCache(VMCache*& cache, + addr_t baseAddress); + static status_t CreateNullCache(VMCache*& cache); +}; + + +struct VMArea { + char* name; + area_id id; + addr_t base; + addr_t size; + uint32 protection; + uint16 wiring; + uint16 memory_type; + + VMCache* cache; + vint32 no_cache_change; + off_t cache_offset; + uint32 cache_type; + VMAreaMappings mappings; + uint8* page_protections; + + struct VMAddressSpace* address_space; + struct VMArea* address_space_next; + struct VMArea* cache_next; + struct VMArea* cache_prev; + struct VMArea* hash_next; + + bool ContainsAddress(addr_t address) const + { return address >= base && address <= base + (size - 1); } +}; + + +#endif // _KERNEL_VM_VM_TYPES_H Modified: haiku/trunk/src/add-ons/kernel/bus_managers/acpi/oshaiku.c =================================================================== --- haiku/trunk/src/add-ons/kernel/bus_managers/acpi/oshaiku.c 2009-12-02 16:49:22 UTC (rev 34448) +++ haiku/trunk/src/add-ons/kernel/bus_managers/acpi/oshaiku.c 2009-12-02 18:05:10 UTC (rev 34449) @@ -130,7 +130,7 @@ #include <dpc.h> #include <PCI.h> -#include <vm.h> +#include <vm/vm.h> extern pci_module_info *gPCIManager; Modified: haiku/trunk/src/add-ons/kernel/bus_managers/agp_gart/agp_gart.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/bus_managers/agp_gart/agp_gart.cpp 2009-12-02 16:49:22 UTC (rev 34448) +++ haiku/trunk/src/add-ons/kernel/bus_managers/agp_gart/agp_gart.cpp 2009-12-02 18:05:10 UTC (rev 34449) @@ -33,8 +33,8 @@ #include <util/OpenHashTable.h> #ifdef __HAIKU__ # include <kernel/lock.h> -# include <vm_page.h> -# include <vm_types.h> +# include <vm/vm_page.h> +# include <vm/vm_types.h> #endif #include <lock.h> Modified: haiku/trunk/src/add-ons/kernel/bus_managers/ata/ATAChannel.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/bus_managers/ata/ATAChannel.cpp 2009-12-02 16:49:22 UTC (rev 34448) +++ haiku/trunk/src/add-ons/kernel/bus_managers/ata/ATAChannel.cpp 2009-12-02 18:05:10 UTC (rev 34449) @@ -129,17 +129,17 @@ ata_task_file taskFile; taskFile.chs.sector_count = 0x5a; taskFile.chs.sector_number = 0xa5; - if (_WriteRegs(&taskFile, ATA_MASK_SECTOR_COUNT + if (_WriteRegs(&taskFile, ATA_MASK_SECTOR_COUNT | ATA_MASK_SECTOR_NUMBER) != B_OK) { TRACE_ERROR("_DevicePresent: writing registers failed\n"); return false; } - if (_ReadRegs(&taskFile, ATA_MASK_SECTOR_COUNT + if (_ReadRegs(&taskFile, ATA_MASK_SECTOR_COUNT | ATA_MASK_SECTOR_NUMBER) != B_OK) { TRACE_ERROR("_DevicePresent: reading registers failed\n"); return false; } - bool present = (taskFile.chs.sector_count == 0x5a && + bool present = (taskFile.chs.sector_count == 0x5a && taskFile.chs.sector_number == 0xa5); TRACE_ALWAYS("_DevicePresent: device %i, presence %d\n", device, present); [... truncated: 2963 lines follow ...]