public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Nick Piggin <nickpiggin@yahoo.com.au>
To: Alan Cox <alan@lxorguk.ukuu.org.uk>
Cc: "Brian D. McGrew" <brian@visionpro.com>, linux-kernel@vger.kernel.org
Subject: Re: PCI Device Driver / remap_pfn_range()
Date: Tue, 18 Apr 2006 21:51:45 +1000	[thread overview]
Message-ID: <4444D2D1.3010200@yahoo.com.au> (raw)
In-Reply-To: <1145359275.18736.22.camel@localhost.localdomain>

Alan Cox wrote:
> On Maw, 2006-04-18 at 04:18 +1000, Nick Piggin wrote:
> 
>>I'm pretty sure you can't remap_pfn_range vmalloced memory because
>>it doesn't use contiguous page frames.
> 
> 
> To remap vmalloc memory you need something like this. Note that vmalloc
> memory may not be DMA accessible, vmalloc_32 memory maybe. Alternatively
> you can build your own scatter gather  lists from pages subject to
> hardware limits.
> 
> The following GPL code from various drivers shows how to do vmalloc
> mapping into an application. Having a common helper for this is a
> discussion/todo item when that area of the vm gets future adjustments
> but for now this code should do the trick:

Yep, that would be a good option, thanks Alan.

You can look through the tree at how drivers remap their rvmalloced
memory -- (here's a snippet from drivers/media/video/meye.c):

while (size > 0) {
     page = vmalloc_to_pfn((void *)pos);
     if (remap_pfn_range(vma, start, page, PAGE_SIZE, PAGE_SHARED)) {
         mutex_unlock(&meye.lock);
         return -EAGAIN;
     }
     start += PAGE_SIZE;
     pos += PAGE_SIZE;
     if (size > PAGE_SIZE)
         size -= PAGE_SIZE;
     else
         size = 0;
}

The trick is to get the underlying pfns and remap one at a time.

You could also tinker with vmalloc_to_page+vm_insert_page, although
that might not yet be the best option for an out of tree driver.

-- 
SUSE Labs, Novell Inc.
Send instant messages to your online friends http://au.messenger.yahoo.com 

      reply	other threads:[~2006-04-18 19:04 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-04-17 17:45 PCI Device Driver / remap_pfn_range() Brian D. McGrew
2006-04-17 18:18 ` Nick Piggin
2006-04-18 11:21   ` Alan Cox
2006-04-18 11:51     ` Nick Piggin [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=4444D2D1.3010200@yahoo.com.au \
    --to=nickpiggin@yahoo.com.au \
    --cc=alan@lxorguk.ukuu.org.uk \
    --cc=brian@visionpro.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