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

Re: [Xen-devel] Re: [PATCH][Linux] gnttab: make dma address conversion l

To: Herbert Xu <herbert@xxxxxxxxxxxxxxxxxxx>
Subject: Re: [Xen-devel] Re: [PATCH][Linux] gnttab: make dma address conversion logic of gnttab dma arch specific.
From: Isaku Yamahata <yamahata@xxxxxxxxxxxxx>
Date: Mon, 11 Jun 2007 18:03:31 +0900
Cc: xen-devel@xxxxxxxxxxxxxxxxxxx, xen-ia64-devel@xxxxxxxxxxxxxxxxxxx
Delivery-date: Mon, 11 Jun 2007 02:01:48 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxx
In-reply-to: <20070611082320.GA18660@xxxxxxxxxxxxxxxxxxx>
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>
References: <20070611073527.GD3845%yamahata@xxxxxxxxxxxxx> <20070611082320.GA18660@xxxxxxxxxxxxxxxxxxx>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
User-agent: Mutt/1.4.2.1i
On Mon, Jun 11, 2007 at 06:23:20PM +1000, Herbert Xu wrote:
> On Mon, Jun 11, 2007 at 04:35:27PM +0900, Isaku Yamahata wrote:
> > This patch is cleaned up of the patch which was sent as
> > http://lists.xensource.com/archives/html/xen-devel/2007-06/msg00324.html
> 
> Thanks for the patch! I completely agree with your idea of making
> this architecture-specific but I have question about the implementaiton.
> 
> > diff -r d5e0eb7dd069 -r 69e2dd4e06c4 drivers/xen/core/gnttab.c
> > --- a/drivers/xen/core/gnttab.c     Sun Jun 10 19:50:32 2007 +0100
> > +++ b/drivers/xen/core/gnttab.c     Mon Jun 11 16:13:06 2007 +0900
> > @@ -593,20 +593,18 @@ EXPORT_SYMBOL(gnttab_copy_grant_page);
> >   *
> >   * All other pages are simply returned as is.
> >   */
> > -maddr_t gnttab_dma_map_page(struct page *page)
> > -{
> > -   maddr_t maddr = page_to_bus(page);
> > +void __gnttab_dma_map_page(struct page *page,
> > +                      int (*local_pfn)(struct page *page))
> 
> Do we really need a callback here? In other words when would a
> single architecture need to have two different values for local_pfn
> here?

No at this moment. So I removed the callback.
Is this what you want?

thanks,

# HG changeset patch
# User yamahata@xxxxxxxxxxxxx
# Date 1181552280 -32400
# Node ID 237ea82bc95bb8d9985e07cf319436e89a832591
# Parent  d5e0eb7dd069c0ffc1854da81aa143ccfb0ad66e
make dma address conversion logic of gnttab dma arch specific.
gnttab_dma_map_page() and gnttab_dma_unmap_page() uses machine address
with dma address interchangebly.
However it doesn't work with auto translated mode enabled (i.e. on ia64)
because

- bus address space(dma_addr_t) is different from machine address
  space(maddr_t).
  With the terminology in xen/include/public/mm.h,
  dma_addr_t is maddr and maddr_t is gmaddr.
  So they should be handled differently with auto translated physmap mode
  enabled.

- dma address conversion depends on dma api implementation and
  its paravirtualization.
  "pfn_valid(mfn_to_local_pfn(maddr >> PAGE_SHIFT)" check in
  gnttab_dma_map_page() doesn't make sense with auto translate physmap
  mode enabled.

To address those issues, split those logic from gnttab_dma_map_page() and
gnttab_dma_unmap_page(), and put it into arch specific files.
This patch doesn't change the already existing x86 logic.
PATCHNAME: make_dma_address_conversion_logic_of_gnttab_dma_arch_specific

Signed-off-by: Isaku Yamahata <yamahata@xxxxxxxxxxxxx>

diff -r d5e0eb7dd069 -r 237ea82bc95b arch/i386/kernel/pci-dma-xen.c
--- a/arch/i386/kernel/pci-dma-xen.c    Sun Jun 10 19:50:32 2007 +0100
+++ b/arch/i386/kernel/pci-dma-xen.c    Mon Jun 11 17:58:00 2007 +0900
@@ -19,6 +19,7 @@
 #include <asm/swiotlb.h>
 #include <asm/tlbflush.h>
 #include <asm-i386/mach-xen/asm/swiotlb.h>
+#include <asm-i386/mach-xen/asm/gnttab_dma.h>
 #include <asm/bug.h>
 
 #ifdef __x86_64__
diff -r d5e0eb7dd069 -r 237ea82bc95b arch/i386/kernel/swiotlb.c
--- a/arch/i386/kernel/swiotlb.c        Sun Jun 10 19:50:32 2007 +0100
+++ b/arch/i386/kernel/swiotlb.c        Mon Jun 11 17:58:00 2007 +0900
@@ -27,6 +27,7 @@
 #include <asm/uaccess.h>
 #include <xen/gnttab.h>
 #include <xen/interface/memory.h>
+#include <asm-i386/mach-xen/asm/gnttab_dma.h>
 
 int swiotlb;
 EXPORT_SYMBOL(swiotlb);
diff -r d5e0eb7dd069 -r 237ea82bc95b drivers/xen/core/gnttab.c
--- a/drivers/xen/core/gnttab.c Sun Jun 10 19:50:32 2007 +0100
+++ b/drivers/xen/core/gnttab.c Mon Jun 11 17:58:00 2007 +0900
@@ -43,6 +43,7 @@
 #include <asm/io.h>
 #include <xen/interface/memory.h>
 #include <xen/driver_util.h>
+#include <asm/gnttab_dma.h>
 
 #ifdef HAVE_XEN_PLATFORM_COMPAT_H
 #include <xen/platform-compat.h>
@@ -593,20 +594,17 @@ EXPORT_SYMBOL(gnttab_copy_grant_page);
  *
  * All other pages are simply returned as is.
  */
-maddr_t gnttab_dma_map_page(struct page *page)
-{
-       maddr_t maddr = page_to_bus(page);
+void __gnttab_dma_map_page(struct page *page)
+{
        unsigned int seq;
 
-       if (!PageForeign(page))
-               return maddr;
+       if (!is_running_on_xen() || !PageForeign(page))
+               return;
 
        do {
                seq = read_seqbegin(&gnttab_dma_lock);
-               maddr = page_to_bus(page);
-
-               /* Has it become a local MFN? */
-               if (pfn_valid(mfn_to_local_pfn(maddr >> PAGE_SHIFT)))
+
+               if (gnttab_dma_local_pfn(page))
                        break;
 
                atomic_set(&page->_mapcount, 0);
@@ -614,8 +612,6 @@ maddr_t gnttab_dma_map_page(struct page 
                /* Make _mapcount visible before read_seqretry. */
                smp_mb();
        } while (unlikely(read_seqretry(&gnttab_dma_lock, seq)));
-
-       return maddr;
 }
 
 int gnttab_resume(void)
diff -r d5e0eb7dd069 -r 237ea82bc95b include/asm-i386/mach-xen/asm/gnttab_dma.h
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/include/asm-i386/mach-xen/asm/gnttab_dma.h        Mon Jun 11 17:58:00 
2007 +0900
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2007 Herbert Xu <herbert@xxxxxxxxxxxxxxxxxxx>
+ * Copyright (c) 2007 Isaku Yamahata <yamahata at valinux co jp>
+ *                    VA Linux Systems Japan K.K.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#ifndef _ASM_I386_GNTTAB_DMA_H
+#define _ASM_I386_GNTTAB_DMA_H
+
+static inline int gnttab_dma_local_pfn(struct page *page)
+{
+       /* Has it become a local MFN? */
+       return pfn_valid(mfn_to_local_pfn(pfn_to_mfn(page_to_pfn(page))));
+}
+
+static inline maddr_t gnttab_dma_map_page(struct page *page)
+{
+       __gnttab_dma_map_page(page);
+       return page_to_bus(page);
+}
+
+static inline void gnttab_dma_unmap_page(maddr_t maddr)
+{
+       __gnttab_dma_unmap_page(virt_to_page(bus_to_virt(maddr)));
+}
+
+#endif /* _ASM_I386_GNTTAB_DMA_H */
diff -r d5e0eb7dd069 -r 237ea82bc95b include/asm-ia64/gnttab_dma.h
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/include/asm-ia64/gnttab_dma.h     Mon Jun 11 17:58:00 2007 +0900
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2007 Herbert Xu <herbert@xxxxxxxxxxxxxxxxxxx>
+ * Copyright (c) 2007 Isaku Yamahata <yamahata at valinux co jp>
+ *                    VA Linux Systems Japan K.K.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#ifndef _ASM_IA64_GNTTAB_DMA_H
+#define _ASM_IA64_GNTTAB_DMA_H
+
+static inline int gnttab_dma_local_pfn(struct page *page)
+{
+       return 0;
+}
+
+/* caller must get dma address after calling this function */
+static inline void gnttab_dma_use_page(struct page *page)
+{
+       __gnttab_dma_map_page(page);
+}
+
+static inline dma_addr_t gnttab_dma_map_page(struct page *page)
+{
+       gnttab_dma_use_page(page);
+       return page_to_bus(page);
+}
+
+static inline dma_addr_t gnttab_dma_map_virt(void *ptr)
+{
+       return gnttab_dma_map_page(virt_to_page(ptr)) + offset_in_page(ptr);
+}
+
+static inline void gnttab_dma_unmap_page(dma_addr_t dma_address)
+{
+       __gnttab_dma_unmap_page(virt_to_page(bus_to_virt(dma_address)));
+}
+
+#endif /* _ASM_IA64_GNTTAB_DMA_H */
diff -r d5e0eb7dd069 -r 237ea82bc95b 
include/asm-x86_64/mach-xen/asm/gnttab_dma.h
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/include/asm-x86_64/mach-xen/asm/gnttab_dma.h      Mon Jun 11 17:58:00 
2007 +0900
@@ -0,0 +1,1 @@
+#include <asm-i386/mach-xen/asm/gnttab_dma.h>
diff -r d5e0eb7dd069 -r 237ea82bc95b include/xen/gnttab.h
--- a/include/xen/gnttab.h      Sun Jun 10 19:50:32 2007 +0100
+++ b/include/xen/gnttab.h      Mon Jun 11 17:58:00 2007 +0900
@@ -103,9 +103,8 @@ void gnttab_grant_foreign_transfer_ref(g
                                       unsigned long pfn);
 
 int gnttab_copy_grant_page(grant_ref_t ref, struct page **pagep);
-maddr_t gnttab_dma_map_page(struct page *page);
-
-static inline void gnttab_dma_unmap_page(maddr_t mfn)
+void __gnttab_dma_map_page(struct page *page);
+static inline void __gnttab_dma_unmap_page(struct page *page)
 {
 }
 


-- 
yamahata

Attachment: 41_237ea82bc95b_make_dma_address_conversion_logic_of_gnttab_dma_arch_specific.patch
Description: Text Data

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