WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

[Xen-devel] Re: Reversing the DMA handle

To: Keir Fraser <keir@xxxxxxxxxxxxx>
Subject: [Xen-devel] Re: Reversing the DMA handle
From: Pete Zaitcev <zaitcev@xxxxxxxxxx>
Date: Wed, 10 Jan 2007 19:21:02 -0800
Cc: xen-devel@xxxxxxxxxxxxxxxxxxx, zaitcev@xxxxxxxxxx
Delivery-date: Wed, 10 Jan 2007 19:22:06 -0800
Envelope-to: www-data@xxxxxxxxxxxxxxxxxx
In-reply-to: <C1CA78A1.7631%keir@xxxxxxxxxxxxx>
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
Organization: Red Hat, Inc.
References: <20070109171710.b4cf6ec6.zaitcev@xxxxxxxxxx> <C1CA78A1.7631%keir@xxxxxxxxxxxxx>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
On Wed, 10 Jan 2007 11:04:01 +0000, Keir Fraser <keir@xxxxxxxxxxxxx> wrote:
> On 10/1/07 01:17, "Pete Zaitcev" <zaitcev@xxxxxxxxxx> wrote:

> > My question is: how to find PFN under Xen if DMA address is known,
> > on x86_64 and i386?
> 
> Use mfn_to_local_pfn() which is safe to call from any context. [...]
> Of course you may then want to do further translation if that happens to be
> in the swiotlb aperture.

Keir, thanks a lot, that worked perfectly.

The SWIOTLB is something I can't understand still. The code sure looks
like returning physical addresses to be used as DMA handles, just like
any usual routines do:

void *
swiotlb_alloc_coherent(struct device *hwdev, size_t size,
                       dma_addr_t *dma_handle, gfp_t flags)
{
....
        ret = (void *)__get_free_pages(flags, order);
        dev_addr = virt_to_phys(ret);
        *dma_handle = dev_addr;

And the code in pci-dma.c does:

void *
dma_alloc_coherent(struct device *dev, size_t size, dma_addr_t *dma_handle,
                   gfp_t gfp)
        memory = dma_alloc_pages(dev, gfp, get_order(size));
                        *dma_handle = virt_to_bus(memory);

The virt_to_bus and virt_to_phys are the same on x86_64.

So this is a kind of a mystery, but I'll think about it and maybe
ask at linux-kernel.

Thanks,
-- Pete

diff -urp -X dontdiff linux-2.6.17-1.2647.fc6/drivers/usb/mon/mon_dma.c 
linux-2.6.17-1.2647.fc6.z1/drivers/usb/mon/mon_dma.c
--- linux-2.6.17-1.2647.fc6/drivers/usb/mon/mon_dma.c   2006-09-24 
19:10:42.000000000 -0700
+++ linux-2.6.17-1.2647.fc6.z1/drivers/usb/mon/mon_dma.c        2007-01-10 
17:30:33.000000000 -0800
@@ -19,21 +19,25 @@
 #if defined(__i386__) || defined(__x86_64__) /* CONFIG_ARCH_I386 doesn't exit 
*/
 #define MON_HAS_UNMAP 1
 
-#define phys_to_page(phys)     pfn_to_page((phys) >> PAGE_SHIFT)
-
 char mon_dmapeek(unsigned char *dst, dma_addr_t dma_addr, int len)
 {
        struct page *pg;
        unsigned long flags;
        unsigned char *map;
        unsigned char *ptr;
+       unsigned long mfn;
 
        /*
         * On i386, a DMA handle is the "physical" address of a page.
         * In other words, the bus address is equal to physical address.
-        * There is no IOMMU.
+        * But sometimes IOMMUs are present (Calgary, AMD's x86_64, SWIOTLB).
+        * Also, Xen introduces "machine" address, which is used for DMA.
+        * We handle Xen, but not IOMMUs yet.
         */
-       pg = phys_to_page(dma_addr);
+       mfn = mfn_to_local_pfn(dma_addr >> PAGE_SHIFT);
+       if (!pfn_valid(mfn))
+               return 'X';
+       pg = pfn_to_page(mfn);
 
        /*
         * We are called from hardware IRQs in case of callbacks.

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel

<Prev in Thread] Current Thread [Next in Thread>