From: "Haw-Yuan Yang" Subject: Re: Physical address mapping to user space in dom0 problem Date: Sun, 18 Mar 2007 13:11:04 -0700 Message-ID: <63c711180703181311o44c8a906vae38f8157743af9b@mail.gmail.com> References: <63c711180703171452m3ade426ej937673758407724a@mail.gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============2041685062==" Return-path: In-Reply-To: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Mime-version: 1.0 Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: Keir Fraser Cc: xen-devel@lists.xensource.com List-Id: xen-devel@lists.xenproject.org --===============2041685062== Content-Type: multipart/alternative; boundary="----=_Part_85953_18459489.1174248664640" ------=_Part_85953_18459489.1174248664640 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline Thanks, It works. Here is what I have in the mmap handler: if the physical address is MMIO io_remap_pfn_range(MMIO_address) else remap_pfn_range(virt_to_phys(cpu-ptr-returned-by-pci-alloc-consistent) hyang On 3/18/07, Keir Fraser wrote: > > > > > On 17/3/07 21:52, "Haw-Yuan Yang" wrote: > > I knew that pci_alloc_consistent() will return both kernel virtual address > and physical address. If I pass the physical address (dma_handler) to mmap, > it return -1. However if I pass the kernel virtual address to mmap, I got a > pointer point to the worng memory. > > > Oh, I see the problem. You can only mmap() MMIO regions using /dev/mem > when running on Xen. Could your device (which you already implement ioctl() > for) also implement mmap() itself? Then you can simply > remap_pfn_range(virt_to_phys(cpu-ptr-returned-by-pci-alloc-consistent)). > This would be a neater interface to userspace for your device anyway, imo. > > -- Keir > ------=_Part_85953_18459489.1174248664640 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline
Thanks, It works.
 
Here is what I have in the mmap handler:
 
if  the physical address is MMIO
    io_remap_pfn_range(MMIO_address)
else
   remap_pfn_range(virt_to_phys(cpu-ptr-returned-by-pci-alloc-consistent)   
 
hyang
 
 
On 3/18/07, Keir Fraser <keir@xensource.com> wrote:



On 17/3/07 21:52, "Haw-Yuan Yang" < hawyuan@gmail.com> wrote:

I knew that pci_alloc_consistent() will return both kernel virtual address and physical address. If I pass the physical address (dma_handler) to mmap, it return -1. However if I pass the kernel virtual address to mmap, I got a pointer point to the worng memory.

Oh, I see the problem. You can only mmap() MMIO regions using /dev/mem when running on Xen. Could your device (which you already implement ioctl() for) also implement mmap() itself? Then you can simply remap_pfn_range(virt_to_phys(cpu-ptr-returned-by-pci-alloc-consistent)). This would be a neater interface to userspace for your device anyway, imo.

 -- Keir

------=_Part_85953_18459489.1174248664640-- --===============2041685062== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel --===============2041685062==--