From: joncglenn <joncglenn@hotmail.com>
To: linux-kernel@vger.kernel.org
Subject: Mapping PCI memory to user-space
Date: Tue, 23 Oct 2007 23:59:06 -0700 (PDT) [thread overview]
Message-ID: <13380086.post@talk.nabble.com> (raw)
I am writing a driver to map a PCI board memory space (pcibar2) into a
user-space vma via 'mmap'. What is the relationship between the address
returned from ioremap and the type of address needed in the
'io_remap_page_range' or 'remap_pfn_range' functions? How about the
following? (I am developing under RHEL4 and a 2.6.9 kernel)
In the 'init' part of the driver:
dev.pcibar2 = ioremap_nocache(resource,size);
dev.region_start = dev.pcibar2 + offset; // RAM is at some offset
from base
dev.region_size = <some size>
In the mydriver_mmap function:
static ssize_t mydriver_mmap (struct file *filp,
struct vm_area_struct
*vma)
{
// off = convert vm_pgoff back to user-space mmap 'off' value
// phyaddr = physical address of PCI memory area
// vsize = total size of area user wants to map
// psize = total avail size in device
struct mydriver_dev *dev = filp->private_data;
unsigned long off = vma->vm_pgoff << PAGE_SHIFT;
unsigned long phy = __pa(dev->region_start + off);
unsigned long vsize = vma->vm_end - vma->vm_start;
unsigned long psize = dev->region_size - off;
if (vsize > psize)
return -EINVAL; /* spans too high */
if (io_remap_page_range(vma, phyaddr, vma->vm_start, vsize,
vma->vm_page_prot))
return -EAGAIN;
vma->vm_ops = &mydriver_vm_ops;
vma->vm_flags |= VM_IO | VM_RESERVED;
mydriver_vma_open(vma);
return 0;
}
--
View this message in context: http://www.nabble.com/Mapping-PCI-memory-to-user-space-tf4682416.html#a13380086
Sent from the linux-kernel mailing list archive at Nabble.com.
next reply other threads:[~2007-10-24 6:59 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-10-24 6:59 joncglenn [this message]
2007-10-24 7:52 ` Mapping PCI memory to user-space Jiri Slaby
2007-10-28 3:06 ` Roland Dreier
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=13380086.post@talk.nabble.com \
--to=joncglenn@hotmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.