question on char driver mmap

From: Chris Friesen
Date: Mon Aug 23 2004 - 15:53:42 EST



I have a need for a device driver to map a page of memory between interrupt handlers and userspace. It's been suggested that I use something like the following code (simplified):


unsigned long mypage;

int my_mmap(struct file *filp, struct vm_area_struct *vma)
{
unsigned long offset = vma->vm_pgoff << PAGE_SHIFT;

if (offset & ~PAGE_MASK)
return -ENXIO;

mypage = __get_free_page(GFP_KERNEL);
SetPageReserved(virt_to_page(mypage));
remap_page_range(vma->vm_start, virt_to_phys((void *) mypage),
PAGE_SIZE, vma->vm_page_prot);
return 0;
}


This seems to work. If I do this, however, do I need to hook into the munmap() file operations to handle unmapping, clearing the reserved bit, and freeing the page, or will the memory subsystem do it for me?

Thanks,

Chris
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/