linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Dave Cogley <dcogley@uslinc.com>
To: linuxppc-embedded@ozlabs.org
Subject: RE: mmap problem in device driver and application program.
Date: Fri, 09 May 2008 13:55:52 -0700	[thread overview]
Message-ID: <1210366552.3755.21.camel@localhost.localdomain> (raw)
In-Reply-To: <BAY138-W36C7249F532D111A1DC508B2D00@phx.gbl>

> Shall I use virt_to_phys? dma_addr is already exactly physical address
> which is used to initiate DMA transfers. 

Is the physical memory outside of the reach of the kernel? If it is
under control of the kernel memory management you will need to ioremap
it. This will return a kernel virtual address which will need to be
converted to a physical address and further convert to a page number.
remap_pfn_range only works on page numbers not physical addresses.

So I guess it would look something like this:

int foo_mmap(struct file* filep, struct vm_area_struct* vma)
{
	unsigned long dma_addr = ioremap(0x03000000);
	unsigned long dma_size = 0x00200000;
	unsigned long pfn;

	// convert the DMA address to page number
	pfn = virt_to_phys(dma_addr) >> PAGE_SHIFT;

	...
}

If you are using memory that is not under the kernel's memory management
you will need to use something other than remap_pfn_range.

Dave

On Thu, 2008-05-08 at 18:42 +0000, MingLiu wrote:
> Dear Dave,
>  
> Thanks for your answer first. However I am very confused. It seems
> that I understand the memory-mapping-related functions completely
> wrong. Here comes more questions. 
> 
> 
> > The address you are passing to mmap is where the pointer will be
> mapped
> > in virtual address space. You need to determine the DMA memory
> address
> > page number down in the actual mmap call.
> > 
> > int foo_mmap(struct file* filep, struct vm_area_struct* vma)
> > {
> > unsigned long dma_addr = 0x03000000;
> > unsigned long dma_size = 0x00200000;
> > unsigned long pfn;
> > 
> > // convert the DMA address to page number
> > pfn = virt_to_phys(dma_addr) >> PAGE_SHIFT;
> 
> Shall I use virt_to_phys? dma_addr is already exactly physical address
> which is used to initiate DMA transfers. 
>  
> > // remap our page frame to the vma offset
> > remap_pfn_range(vma, vma->vm_start, pfn, 
> > dma_size, vma->vm_page_prot);
> > }
> > 
> > Change the address parameter from 0x03000000 to 0:
> > 
> > lut_mem_base = (unsigned int *) mmap(0, LUT_SIZE_IN_BYTE, 
> > PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
> 
> Previously I used "remap_page_range(vma, vma->vm_start, physical_addr,
> vm_size, vma->vm_page_prot)" in the device driver, where physical_addr
> is 0x03000000. In the application program, I used "lut_mem_base =
> (unsigned int *) mmap(0, LUT_SIZE_IN_BYTE, PROT_READ | PROT_WRITE,
> MAP_SHARED, fd, 0);". I think it is correct but it doesn't work. I
> heard that in the new kernels, remap_page_range is not supported any
> more. However when I compile the driver, nothing was shown to complain
> that. I am using 2.6.10 kernel. Any hint for this?
>  
> Thank you for your help to make me understand. 
>  
> BR
> Ming
> 
> 
> ______________________________________________________________________
> 使用新一代 Windows Live Messenger 轻松交流和共享! 立即体验!

  reply	other threads:[~2008-05-09 20:55 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-05-08 15:33 mmap problem in device driver and application program MingLiu
2008-05-08 17:01 ` Dave Cogley
2008-05-08 18:42   ` MingLiu
2008-05-09 20:55     ` Dave Cogley [this message]
2008-05-13  9:11       ` MingLiu
2008-05-13 17:51         ` Howard, Marc
2008-05-14  6:18         ` Johan Borkhuis
2008-05-26 10:08         ` Misbah khan

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=1210366552.3755.21.camel@localhost.localdomain \
    --to=dcogley@uslinc.com \
    --cc=linuxppc-embedded@ozlabs.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;
as well as URLs for NNTP newsgroup(s).