From: Roland Dreier <rdreier@cisco.com>
To: joncglenn <joncglenn@hotmail.com>
Cc: linux-kernel@vger.kernel.org
Subject: Re: Mapping PCI memory to user-space
Date: Sat, 27 Oct 2007 20:06:49 -0700 [thread overview]
Message-ID: <adaejfgx7hy.fsf@cisco.com> (raw)
In-Reply-To: <13380086.post@talk.nabble.com> (joncglenn@hotmail.com's message of "Sat, 27 Oct 2007 18:39:00 -0700 (PDT)")
> 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)
There is no relationship between the address returned from ioremap and
what you pass into io_remap_page_range(). ioremap gives you a kernel
virtual address for the PCI address you remap. io_remap_page_range()
creates a userspace mapping in the same way, and you should pass in
the PCI address exactly the same way you pass in the PCI address into
ioremap. io_remap_pfn_range() takes a PFN ("page frame number"),
which is basically the PCI address you want to map divided by
PAGE_SIZE. The main reason for using PFNs is that they allow you to
map addresses above 4G even if sizeof long is only 4.
In your code:
> dev.pcibar2 = ioremap_nocache(resource,size);
> dev.region_start = dev.pcibar2 + offset; // RAM is at some offset from base
This gives you a kernel mapping that you can use with readl(),
writel() etc to access the PCI memory from the kernel.
To map to userspace, this:
> if (io_remap_page_range(vma, phyaddr, vma->vm_start, vsize, vma->vm_page_prot))
should use phyaddr as you have it here:
> // phyaddr = physical address of PCI memory area
This is just wrong:
> unsigned long phy = __pa(dev->region_start + off);
__pa() doesn't work on addresses returned from ioremap. Just use the
same resource address you passed into ioremap.
- R.
prev parent reply other threads:[~2007-10-28 3:07 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-10-24 6:59 Mapping PCI memory to user-space joncglenn
2007-10-24 7:52 ` Jiri Slaby
2007-10-28 3:06 ` Roland Dreier [this message]
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=adaejfgx7hy.fsf@cisco.com \
--to=rdreier@cisco.com \
--cc=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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox