From 901f1930e117a09793b2f4feff24d104bea5c577 Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Fri, 17 Oct 2008 16:32:12 +0000 Subject: [PATCH] * Moved memset_physical() to vm.cpp and made it available in the kernel. * Added memcpy_to_physical(). git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@28219 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- headers/private/kernel/vm.h | 4 ++ src/system/kernel/cache/vnode_store.cpp | 24 ---------- src/system/kernel/vm/vm.cpp | 64 +++++++++++++++++++++++++ 3 files changed, 68 insertions(+), 24 deletions(-) diff --git a/headers/private/kernel/vm.h b/headers/private/kernel/vm.h index 726489b218..200397c257 100644 --- a/headers/private/kernel/vm.h +++ b/headers/private/kernel/vm.h @@ -99,6 +99,10 @@ uint32 vm_num_page_faults(void); off_t vm_available_memory(void); off_t vm_available_not_needed_memory(void); +status_t memset_physical(addr_t address, int value, size_t length); +status_t memcpy_to_physical(addr_t to, const void* from, size_t length, + bool user); + // user syscalls area_id _user_create_area(const char *name, void **address, uint32 addressSpec, size_t size, uint32 lock, uint32 protection); diff --git a/src/system/kernel/cache/vnode_store.cpp b/src/system/kernel/cache/vnode_store.cpp index 1c3dfa880d..0a2a0c614c 100644 --- a/src/system/kernel/cache/vnode_store.cpp +++ b/src/system/kernel/cache/vnode_store.cpp @@ -16,30 +16,6 @@ #include "io_requests.h" -static inline status_t -memset_physical(addr_t address, int value, size_t length) -{ - while (length > 0) { - addr_t pageOffset = address % B_PAGE_SIZE; - addr_t virtualAddress; - status_t error = vm_get_physical_page(address - pageOffset, - &virtualAddress, 0); - if (error != B_OK) - return error; - - size_t toSet = min_c(length, B_PAGE_SIZE - pageOffset); - memset((void*)(virtualAddress + pageOffset), value, toSet); - - vm_put_physical_page(virtualAddress); - - length -= toSet; - address += toSet; - } - - return B_OK; -} - - status_t VMVnodeCache::Init(struct vnode *vnode) { diff --git a/src/system/kernel/vm/vm.cpp b/src/system/kernel/vm/vm.cpp index 8a4e91e6d0..ccd814da6f 100644 --- a/src/system/kernel/vm/vm.cpp +++ b/src/system/kernel/vm/vm.cpp @@ -5162,6 +5162,70 @@ vm_resize_area(area_id areaID, size_t newSize, bool kernel) } +status_t +memset_physical(addr_t address, int value, size_t length) +{ + ThreadCPUPinner _(thread_get_current_thread()); + + while (length > 0) { + addr_t pageOffset = address % B_PAGE_SIZE; + addr_t virtualAddress; + status_t error = vm_get_physical_page(address - pageOffset, + &virtualAddress, 0); + if (error != B_OK) + return error; + + size_t toSet = min_c(length, B_PAGE_SIZE - pageOffset); + memset((void*)(virtualAddress + pageOffset), value, toSet); + + vm_put_physical_page(virtualAddress); + + length -= toSet; + address += toSet; + } + + return B_OK; +} + + +status_t +memcpy_to_physical(addr_t to, const void* _from, size_t length, bool user) +{ + const uint8* from = (const uint8*)_from; + addr_t pageOffset = to % B_PAGE_SIZE; + + ThreadCPUPinner _(thread_get_current_thread()); + + while (length > 0) { + size_t toCopy = min_c(length, B_PAGE_SIZE - pageOffset); + + addr_t virtualAddress; + status_t error = vm_get_physical_page(to - pageOffset, &virtualAddress, + 0); + if (error != B_OK) + return error; + + if (user) { + error = user_memcpy((void*)(virtualAddress + pageOffset), from, + toCopy); + } else + memcpy((void*)(virtualAddress + pageOffset), from, toCopy); + + vm_put_physical_page(virtualAddress); + + if (error != B_OK) + return error; + + to += toCopy; + from += toCopy; + length -= toCopy; + pageOffset = 0; + } + + return B_OK; +} + + // #pragma mark - kernel public API