I'm working on a port of a driver from NT to Linux, and was
wondering how to best go about mapping kernel memory to
user space and vice versa. mmap(2) is a possibility, but would
require a vast rework of the code, and break the ability of
the customer to use their existing code base in NT/95.
Is this possible under the current (2.2.14) VM scheme?
If so, any hints as to how to go about it? Any tricky issues?
ie:
----------------------- EXAMPLE CODE --------------------
void *device_buffer=ioremap(DEV_MEM_ADDR,DEV_MEM_SIZE);
void *user_buffer=NULL;
... ioctl(...)
{
switch (cmd) {
MAP_DEVICE_BUFFER:
/* MYTHICAL: vm_kernel_to_user(addr,size)
*/
*(void **)arg=vm_kernel_to_user(device_buffer,DEV_MEM_SIZE);
break;
MAP_USER_BUFFER:
/* MYTHICAL: vm_drop_mapping(addr)
* MYTHICAL: vm_user_to_kernel(addr,size)
*/
if (user_buffer != NULL)
vm_drop_mapping(user_buffer);
user_buffer=vm_user_to_kernel((void *)arg,USER_MEM_SIZE);
break;
...
}
}
/* Now we need to make sure to remove any mappings in the kernel
* when the process closes the device
*/
... release(...)
{
...
if (user_buffer != NULL) {
/* MYTHICAL: vm_drop_mapping(addr)
*/
vm_drop_mapping(user_buffer);
user_buffer=NULL;
}
}
-- Jason McMullan, Senior Linux Consultant, Linuxcare, Inc. 412.422.8077 tel, 412.656.3519 cell, 415.701.0792 fax jmcmullan@linuxcare.com, http://www.linuxcare.com/ Linuxcare. Support for the revolution.- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/
This archive was generated by hypermail 2b29 : Sun Apr 30 2000 - 21:00:11 EST