[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] [linux-2.6.18-xen] Make dma address conversion logic of gnttab dma arch specific.



# HG changeset patch
# User kfraser@xxxxxxxxxxxxxxxxxxxxx
# Date 1181573606 -3600
# Node ID 07a5f92187ac57ffbd107571b2019be2f53bda98
# 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.

Signed-off-by: Isaku Yamahata <yamahata@xxxxxxxxxxxxx>
---
 arch/i386/kernel/pci-dma-xen.c               |    1 
 arch/i386/kernel/swiotlb.c                   |    1 
 drivers/xen/core/gnttab.c                    |   18 +++------
 include/asm-i386/mach-xen/asm/gnttab_dma.h   |   41 +++++++++++++++++++++
 include/asm-ia64/gnttab_dma.h                |   51 +++++++++++++++++++++++++++
 include/asm-x86_64/mach-xen/asm/gnttab_dma.h |    1 
 include/xen/gnttab.h                         |    5 +-
 7 files changed, 104 insertions(+), 14 deletions(-)

diff -r d5e0eb7dd069 -r 07a5f92187ac 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 15:53:26 2007 +0100
@@ -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 07a5f92187ac 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 15:53:26 2007 +0100
@@ -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 07a5f92187ac 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 15:53:26 2007 +0100
@@ -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 07a5f92187ac 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 15:53:26 
2007 +0100
@@ -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 07a5f92187ac 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 15:53:26 2007 +0100
@@ -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 07a5f92187ac 
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 15:53:26 
2007 +0100
@@ -0,0 +1,1 @@
+#include <asm-i386/mach-xen/asm/gnttab_dma.h>
diff -r d5e0eb7dd069 -r 07a5f92187ac 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 15:53:26 2007 +0100
@@ -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)
 {
 }
 

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


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.