lkml.org 
[lkml]   [2004]   [Aug]   [23]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
Subjectquestion on char driver mmap

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@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-03-22 14:05    [from the cache]
©2003-2011 Jasper Spaans