From 7e6a81e9785f4e8d8bd7ce64935e582ef946184f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Sat, 1 Apr 2006 13:55:21 +0000 Subject: [PATCH] * Replaced map_mainmemory() functions with calls to vm_get_physical_page(). * Minor cleanup. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@16950 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../bus_managers/scsi/KernelExport_ext.h | 24 ++++------------ .../kernel/bus_managers/scsi/dma_buffer.c | 24 +++++++++------- .../kernel/bus_managers/scsi/emulation.c | 25 +++++++++-------- .../kernel/bus_managers/scsi/virtual_memory.c | 28 ++++--------------- 4 files changed, 38 insertions(+), 63 deletions(-) diff --git a/src/add-ons/kernel/bus_managers/scsi/KernelExport_ext.h b/src/add-ons/kernel/bus_managers/scsi/KernelExport_ext.h index 0c0219222d..c4b2ec11eb 100644 --- a/src/add-ons/kernel/bus_managers/scsi/KernelExport_ext.h +++ b/src/add-ons/kernel/bus_managers/scsi/KernelExport_ext.h @@ -1,7 +1,9 @@ /* -** Copyright 2002/03, Thomas Kurschel. All rights reserved. -** Distributed under the terms of the OpenBeOS License. -*/ + * Copyright 2004-2006, Axel Dörfler, axeld@pinc-software.de. All rights reserved. + * Copyright 2002/03, Thomas Kurschel. All rights reserved. + * + * Distributed under the terms of the MIT License. + */ /* Functions that are missing in kernel. @@ -26,20 +28,4 @@ status_t get_iovec_memory_map( size_t *mapped_len // actual number of bytes described by map ); -// map main memory into virtual address space -status_t map_mainmemory( - addr_t physical_addr, // physical address to map - void **virtual_addr // receives corresponding virtual address -); - -// unmap main memory from virtual address space -status_t unmap_mainmemory( - void *virtual_addr // virtual address to release -); - - -// this should be moved to SupportDefs.h -int32 atomic_exchange(vint32 *value, int32 newValue); - - #endif diff --git a/src/add-ons/kernel/bus_managers/scsi/dma_buffer.c b/src/add-ons/kernel/bus_managers/scsi/dma_buffer.c index f7bbad1efc..68bb690e55 100644 --- a/src/add-ons/kernel/bus_managers/scsi/dma_buffer.c +++ b/src/add-ons/kernel/bus_managers/scsi/dma_buffer.c @@ -1,11 +1,11 @@ /* -** Copyright 2002/03, Thomas Kurschel. All rights reserved. -** Distributed under the terms of the OpenBeOS License. -*/ + * Copyright 2004-2006, Axel Dörfler, axeld@pinc-software.de. All rights reserved. + * Copyright 2002/03, Thomas Kurschel. All rights reserved. + * + * Distributed under the terms of the MIT License. + */ /* - Part of Open SCSI bus manager - DMA buffer handling. If the peripheral driver hasn't made sure that the data of a request @@ -26,6 +26,9 @@ #include "scsi_internal.h" #include "KernelExport_ext.h" + +#include + #include @@ -111,20 +114,21 @@ scsi_copy_dma_buffer(scsi_ccb *request, uint32 size, bool to_buffer) // was allocated in kernel and is thus visible even if the thread // was changed for (; size > 0 && num_vecs > 0; ++sg_list, --num_vecs) { + addr_t virtualAddress; size_t bytes; - void *virt_addr; bytes = min( size, sg_list->size ); - if (map_mainmemory((addr_t)sg_list->address, &virt_addr) != B_OK) + if (vm_get_physical_page((addr_t)sg_list->address, &virtualAddress, + PHYSICAL_PAGE_CAN_WAIT) != B_OK) return false; if (to_buffer) - memcpy(buffer_data, virt_addr, bytes); + memcpy(buffer_data, (void *)virtualAddress, bytes); else - memcpy(virt_addr, buffer_data, bytes); + memcpy((void *)virtualAddress, buffer_data, bytes); - unmap_mainmemory(virt_addr); + vm_put_physical_page(virtualAddress); buffer_data += bytes; } diff --git a/src/add-ons/kernel/bus_managers/scsi/emulation.c b/src/add-ons/kernel/bus_managers/scsi/emulation.c index a8952e4129..a5451f3396 100644 --- a/src/add-ons/kernel/bus_managers/scsi/emulation.c +++ b/src/add-ons/kernel/bus_managers/scsi/emulation.c @@ -1,11 +1,11 @@ /* + * Copyright 2004-2006, Axel Dörfler, axeld@pinc-software.de. All rights reserved. * Copyright 2002/03, Thomas Kurschel. All rights reserved. + * * Distributed under the terms of the MIT License. */ /* - Part of Open SCSI bus manager - Emulation of SCSI commands that a device cannot handle. Some SCSI devices don't support all SCSI commands, especially @@ -15,7 +15,9 @@ #include "scsi_internal.h" -#include "KernelExport_ext.h" + +#include + #include @@ -469,21 +471,22 @@ copy_sg_data(scsi_ccb *request, uint offset, uint allocation_length, // copy one S/G entry at a time for (; size > 0 && req_size > 0 && sg_cnt > 0; ++sg_list, --sg_cnt) { size_t bytes; - addr_t virt_addr; + addr_t virtualAddress; bytes = min(size, req_size); bytes = min(bytes, sg_list->size); - if (map_mainmemory((addr_t)sg_list->address, (void *)&virt_addr) != B_OK) + if (vm_get_physical_page((addr_t)sg_list->address, (void *)&virtualAddress, + PHYSICAL_PAGE_CAN_WAIT) != B_OK) return false; SHOW_FLOW(0, "buffer = %p, virt_addr = %#lx, bytes = %lu, to_buffer = %d", - buffer, virt_addr + offset, bytes, to_buffer); + buffer, virtualAddress + offset, bytes, to_buffer); if (to_buffer) - memcpy(buffer, (void *)(virt_addr + offset), bytes); + memcpy(buffer, (void *)(virtualAddress + offset), bytes); else - memcpy((void *)(virt_addr + offset), buffer, bytes); + memcpy((void *)(virtualAddress + offset), buffer, bytes); #if 0 { @@ -493,7 +496,7 @@ copy_sg_data(scsi_ccb *request, uint offset, uint allocation_length, char byte; if (to_buffer) - byte = ((char *)virt_addr)[offset + i]; + byte = ((char *)virtualAddress)[offset + i]; else byte = ((char *)buffer)[i]; @@ -501,8 +504,8 @@ copy_sg_data(scsi_ccb *request, uint offset, uint allocation_length, } } #endif - - unmap_mainmemory((void *)virt_addr); + + vm_put_physical_page(virtualAddress); buffer = (char *)buffer + bytes; size -= bytes; diff --git a/src/add-ons/kernel/bus_managers/scsi/virtual_memory.c b/src/add-ons/kernel/bus_managers/scsi/virtual_memory.c index 0a18b3d3df..16b4d4a8cc 100644 --- a/src/add-ons/kernel/bus_managers/scsi/virtual_memory.c +++ b/src/add-ons/kernel/bus_managers/scsi/virtual_memory.c @@ -1,7 +1,9 @@ /* -** Copyright 2002/03, Thomas Kurschel. All rights reserved. -** Distributed under the terms of the OpenBeOS License. -*/ + * Copyright 2004-2006, Axel Dörfler, axeld@pinc-software.de. All rights reserved. + * Copyright 2002/03, Thomas Kurschel. All rights reserved. + * + * Distributed under the terms of the MIT License. + */ /* VM helper functions. @@ -14,7 +16,6 @@ #include "KernelExport_ext.h" #include "wrapper.h" -#include #include @@ -118,22 +119,3 @@ get_iovec_memory_map(iovec *vec, size_t vec_count, size_t vec_offset, size_t len return B_OK; } - -/** map main memory into virtual address space */ - -status_t -map_mainmemory(addr_t physicalAddress, void **_virtualAddress) -{ - return vm_get_physical_page(physicalAddress, (addr_t *)_virtualAddress, PHYSICAL_PAGE_CAN_WAIT); - // ToDo: check if CAN_WAIT is correct -} - - -/** unmap main memory from virtual address space */ - -status_t -unmap_mainmemory(void *virtualAddress) -{ - return vm_put_physical_page((addr_t)virtualAddress); -} -