From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from bay0-omc3-s37.bay0.hotmail.com (bay0-omc3-s37.bay0.hotmail.com [65.54.246.237]) by ozlabs.org (Postfix) with ESMTP id 9A782DDE45 for ; Fri, 9 May 2008 04:42:12 +1000 (EST) Message-ID: Content-Type: multipart/alternative; boundary="_9477b6e8-e42b-4bc8-bc0d-67739e52e665_" From: MingLiu To: Dave Cogley , Subject: RE: mmap problem in device driver and application program. Date: Thu, 8 May 2008 18:42:10 +0000 In-Reply-To: <1210266109.3755.8.camel@localhost.localdomain> References: <1210266109.3755.8.camel@localhost.localdomain> MIME-Version: 1.0 List-Id: Linux on Embedded PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , --_9477b6e8-e42b-4bc8-bc0d-67739e52e665_ Content-Type: text/plain; charset="gb2312" Content-Transfer-Encoding: 8bit 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 Photo gallery 数码相机的超级伴侣,轻松管理和编辑照片,还能制作全景美图! http://get.live.cn/product/photo.html --_9477b6e8-e42b-4bc8-bc0d-67739e52e665_ Content-Type: text/html; charset="gb2312" Content-Transfer-Encoding: 8bit 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 轻松交流和共享! 立即体验! --_9477b6e8-e42b-4bc8-bc0d-67739e52e665_--