From: Chris Friesen <cfriesen@nortelnetworks.com>
To: Linux kernel <linux-kernel@vger.kernel.org>
Subject: question on char driver mmap
Date: Mon, 23 Aug 2004 16:45:13 -0400 [thread overview]
Message-ID: <412A5759.7060401@nortelnetworks.com> (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
reply other threads:[~2004-08-23 20:46 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=412A5759.7060401@nortelnetworks.com \
--to=cfriesen@nortelnetworks.com \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox