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] [PATCH][Linux] gnttab: make dma address conversion logic

To: Keir Fraser <Keir.Fraser@xxxxxxxxxxxx>
Subject: Re: [Xen-devel] [PATCH][Linux] gnttab: make dma address conversion logic of gnttab dma arch specific.
From: Isaku Yamahata <yamahata@xxxxxxxxxxxxx>
Date: Mon, 11 Jun 2007 17:18:00 +0900
Cc: xen-devel@xxxxxxxxxxxxxxxxxxx, Herbert Xu <herbert@xxxxxxxxxxxxxxxxxxx>, xen-ia64-devel@xxxxxxxxxxxxxxxxxxx
Delivery-date: Mon, 11 Jun 2007 01:16:05 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxx
In-reply-to: <C292C397.8DB5%Keir.Fraser@xxxxxxxxxxxx>
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> <C292C397.8DB5%Keir.Fraser@xxxxxxxxxxxx>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
User-agent: Mutt/1.4.2.1i
On Mon, Jun 11, 2007 at 09:17:11AM +0100, Keir Fraser wrote:
> I don't spot a sign-off on this specific patch. Apart from that, I'll check
> it in when Herbert acks it.

Sorry. Here is my signed-off.

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

> 
>  -- Keir
> 
> On 11/6/07 08:35, "Isaku Yamahata" <yamahata@xxxxxxxxxxxxx> 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
> > 
> > # HG changeset patch
> > # User yamahata@xxxxxxxxxxxxx
> > # Date 1181545986 -32400
> > # Node ID 69e2dd4e06c405a92717c5f1818f5096e1dc0bcd
> > # 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
> > 
> > diff -r d5e0eb7dd069 -r 69e2dd4e06c4 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 16:13:06 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__
> > @@ -58,6 +59,12 @@ static int __init pci_iommu_init(void)
> >  /* Must execute after PCI subsystem */
> >  fs_initcall(pci_iommu_init);
> >  #endif
> > +
> > +/* this should be in somewhere appropriate */
> > +int gnttab_dma_local_pfn(struct page *page)
> > +{
> > + return pfn_valid(mfn_to_local_pfn(pfn_to_mfn(page_to_pfn(page))));
> > +}
> >  
> >  struct dma_coherent_mem {
> > void  *virt_base;
> > diff -r d5e0eb7dd069 -r 69e2dd4e06c4 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 16:13:06 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 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))
> > +{
> > 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 (local_pfn && (*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 69e2dd4e06c4
> > 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 16:13:06 2007
> > +0900
> > @@ -0,0 +1,37 @@
> > +/*
> > + * 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
> > +
> > +int gnttab_dma_local_pfn(struct page *page);
> > +
> > +static inline maddr_t gnttab_dma_map_page(struct page *page)
> > +{
> > + __gnttab_dma_map_page(page, &gnttab_dma_local_pfn);
> > + 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 69e2dd4e06c4 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 16:13:06 2007 +0900
> > @@ -0,0 +1,46 @@
> > +/*
> > + * 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
> > +
> > +/* caller must get dma address after calling this function */
> > +static inline void gnttab_dma_use_page(struct page *page)
> > +{
> > + __gnttab_dma_map_page(page, NULL);
> > +}
> > +
> > +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 69e2dd4e06c4 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 16:13:06 2007 +0900
> > @@ -103,9 +103,9 @@ 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,
> > +      int (*local_pfn)(struct page *page));
> > +static inline void __gnttab_dma_unmap_page(struct page *page)
> >  {
> >  }
> >  
> > 
> 
> 
> 
> _______________________________________________
> Xen-devel mailing list
> Xen-devel@xxxxxxxxxxxxxxxxxxx
> http://lists.xensource.com/xen-devel
> 

-- 
yamahata

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