Skip to contentSkip to conversation

question on char driver mmap

DISCUSSION Chris Friesen 1 participant 1 message Aug 23, 2004

lore
Share & tools
lore
#0 lore raw

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