* question on char driver mmap
@ 2004-08-23 20:45 Chris Friesen
0 siblings, 0 replies; only message in thread
From: Chris Friesen @ 2004-08-23 20:45 UTC (permalink / raw)
To: Linux kernel
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
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2004-08-23 20:46 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-08-23 20:45 question on char driver mmap Chris Friesen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox