linux-mips
[Top] [All Lists]

Re: [PATCH] mips: Add dma_mmap_coherent()

To: "tiwai" <tiwai@suse.de>
Subject: Re: [PATCH] mips: Add dma_mmap_coherent()
From: "Joel Soete" <soete.joel@scarlet.be>
Date: Fri, 22 Aug 2008 13:04:36 +0100
Cc: "James\.Bottomley" <James.Bottomley@HansenPartnership.com>, "linux-mips" <linux-mips@linux-mips.org>, "ralf" <ralf@linux-mips.org>, "linux-parisc" <linux-parisc@vger.kernel.org>
Envelope-id: <K6047O$07C3A675C0E02FC7BE973C0D5DEF9AAA
Original-recipient: rfc822;linux-mips@linux-mips.org
Sender: linux-mips-bounce@linux-mips.org
Hello Takashi et al.,

[snip]

> diff --git a/drivers/parisc/ccio-dma.c b/drivers/parisc/ccio-dma.c
> index b30e38f..dd2ab2c 100644
> --- a/drivers/parisc/ccio-dma.c
> +++ b/drivers/parisc/ccio-dma.c
> @@ -1014,6 +1014,19 @@ ccio_unmap_sg(struct device *dev, struct scatterlist
*sglist, int nents,
>       DBG_RUN_SG("%s() DONE (nents %d)\n", __func__, nents);
>  }
>
> +static int ccio_dma_mmap_coherent(struct device *dev,
> +                               struct vm_area_struct *vma,
> +                               void *cpu_addr, dma_addr_t handle,
> +                               size_t size)
> +{
> +     struct page *pg;
> +     pgprot_val(vma->vm_page_prot) |= _PAGE_NO_CACHE;
> +     pg = virt_to_page(cpu_addr);
> +     return remap_pfn_range(vma, vma->vm_start,
> +                            page_to_pfn(pg) + vma->vm_pgoff,
> +                            size, vma->vm_page_prot);
> +}
> +
>  static struct hppa_dma_ops ccio_ops = {
>       .dma_supported =        ccio_dma_supported,
>       .alloc_consistent =     ccio_alloc_consistent,
> @@ -1027,6 +1040,7 @@ static struct hppa_dma_ops ccio_ops = {
>       .dma_sync_single_for_device =   NULL,   /* NOP for U2/Uturn */
>       .dma_sync_sg_for_cpu =          NULL,   /* ditto */
>       .dma_sync_sg_for_device =               NULL,   /* ditto */
> +     .mmap_coherent =        ccio_dma_mmap_coherent,
>  };
>
>  #ifdef CONFIG_PROC_FS
> diff --git a/drivers/parisc/sba_iommu.c b/drivers/parisc/sba_iommu.c
> index bc73b96..403d66d 100644
> --- a/drivers/parisc/sba_iommu.c
> +++ b/drivers/parisc/sba_iommu.c
> @@ -1057,6 +1057,19 @@ sba_unmap_sg(struct device *dev, struct scatterlist
*sglist, int nents,
>
>  }
>
> +static int sba_dma_mmap_coherent(struct device *dev,
> +                              struct vm_area_struct *vma,
> +                              void *cpu_addr, dma_addr_t handle,
> +                              size_t size)
> +{
> +     struct page *pg;
> +     pgprot_val(vma->vm_page_prot) |= _PAGE_NO_CACHE;
> +     pg = virt_to_page(cpu_addr);
> +     return remap_pfn_range(vma, vma->vm_start,
> +                            page_to_pfn(pg) + vma->vm_pgoff,
> +                            size, vma->vm_page_prot);
> +}
> +
>  static struct hppa_dma_ops sba_ops = {
>       .dma_supported =        sba_dma_supported,
>       .alloc_consistent =     sba_alloc_consistent,
> @@ -1070,6 +1083,7 @@ static struct hppa_dma_ops sba_ops = {
>       .dma_sync_single_for_device =   NULL,
>       .dma_sync_sg_for_cpu =          NULL,
>       .dma_sync_sg_for_device =       NULL,
> +     .mmap_coherent =        sba_dma_mmap_coherent,
>  };
>
I build and boot successfully kernel 32bit including your patch on 2 systems
(a b2k using sba and a d380 using ccio).

I just noticed that the above code is ~ the same; otoh there is also a
iommu-helpers.h containing also common code to those 2 drivers. So may be for
easiest maintenance, could you merge and move this code in this 'helper' as
follow:
--- ./drivers/parisc/iommu-helpers.h.Orig       2008-08-01 12:57:22.000000000 
+0000
+++ ./drivers/parisc/iommu-helpers.h    2008-08-22 08:07:26.000000000 +0000
@@ -172,3 +172,16 @@
        return n_mappings;
 }

+static int iommu_dma_mmap_coherent(struct device *dev,
+                                 struct vm_area_struct *vma,
+                                 void *cpu_addr, dma_addr_t handle,
+                                 size_t size)
+{
+       struct page *pg;
+       pgprot_val(vma->vm_page_prot) |= _PAGE_NO_CACHE;
+       pg = virt_to_page(cpu_addr);
+       return remap_pfn_range(vma, vma->vm_start,
+                              page_to_pfn(pg) + vma->vm_pgoff,
+                              size, vma->vm_page_prot);
+}
+
--- ./drivers/parisc/ccio-dma.c.Orig    2008-08-22 07:49:21.000000000 +0000
+++ ./drivers/parisc/ccio-dma.c 2008-08-22 08:06:32.000000000 +0000
@@ -1005,19 +1005,6 @@
        DBG_RUN_SG("%s() DONE (nents %d)\n", __func__, nents);
 }

-static int ccio_dma_mmap_coherent(struct device *dev,
-                                 struct vm_area_struct *vma,
-                                 void *cpu_addr, dma_addr_t handle,
-                                 size_t size)
-{
-       struct page *pg;
-       pgprot_val(vma->vm_page_prot) |= _PAGE_NO_CACHE;
-       pg = virt_to_page(cpu_addr);
-       return remap_pfn_range(vma, vma->vm_start,
-                              page_to_pfn(pg) + vma->vm_pgoff,
-                              size, vma->vm_page_prot);
-}
-
 static struct hppa_dma_ops ccio_ops = {
        .dma_supported =        ccio_dma_supported,
        .alloc_consistent =     ccio_alloc_consistent,
@@ -1031,7 +1018,7 @@
        .dma_sync_single_for_device =   NULL,   /* NOP for U2/Uturn */
        .dma_sync_sg_for_cpu =          NULL,   /* ditto */
        .dma_sync_sg_for_device =               NULL,   /* ditto */
-       .mmap_coherent =        ccio_dma_mmap_coherent,
+       .mmap_coherent =        iommu_dma_mmap_coherent,
 };

 #ifdef CONFIG_PROC_FS
--- ./drivers/parisc/sba_iommu.c.Orig   2008-08-22 07:49:21.000000000 +0000
+++ ./drivers/parisc/sba_iommu.c        2008-08-22 08:08:30.000000000 +0000
@@ -1057,19 +1057,6 @@

 }

-static int sba_dma_mmap_coherent(struct device *dev,
-                                struct vm_area_struct *vma,
-                                void *cpu_addr, dma_addr_t handle,
-                                size_t size)
-{
-       struct page *pg;
-       pgprot_val(vma->vm_page_prot) |= _PAGE_NO_CACHE;
-       pg = virt_to_page(cpu_addr);
-       return remap_pfn_range(vma, vma->vm_start,
-                              page_to_pfn(pg) + vma->vm_pgoff,
-                              size, vma->vm_page_prot);
-}
-
 static struct hppa_dma_ops sba_ops = {
        .dma_supported =        sba_dma_supported,
        .alloc_consistent =     sba_alloc_consistent,
@@ -1083,7 +1070,7 @@
        .dma_sync_single_for_device =   NULL,
        .dma_sync_sg_for_cpu =          NULL,
        .dma_sync_sg_for_device =       NULL,
-       .mmap_coherent =        sba_dma_mmap_coherent,
+       .mmap_coherent =        iommu_dma_mmap_coherent,
 };


=== <> ===
>
> diff --git a/include/asm-parisc/dma-mapping.h 
> b/include/asm-parisc/dma-mapping.h
> index 53af696..5b357b3 100644
> --- a/include/asm-parisc/dma-mapping.h
> +++ b/include/asm-parisc/dma-mapping.h

The small issue encountered: against latest Kyle git tree (dated 2008-07-29)
this file was moved in arch/parisc/include/asm.

> @@ -19,6 +19,9 @@ struct hppa_dma_ops {
>       void (*dma_sync_single_for_device)(struct device *dev, dma_addr_t iova,
unsigned long offset, size_t size, enum dma_data_direction direction);
>       void (*dma_sync_sg_for_cpu)(struct device *dev, struct scatterlist *sg,
int nelems, enum dma_data_direction direction);
>       void (*dma_sync_sg_for_device)(struct device *dev, struct scatterlist 
> *sg,
int nelems, enum dma_data_direction direction);
> +     int (*mmap_coherent)(struct device *dev, struct vm_area_struct *vma,
> +                          void *cpu_addr, dma_addr_t handle, size_t size);
> +
>  };
>
>  /*
> @@ -204,6 +207,15 @@ dma_cache_sync(struct device *dev, void *vaddr, size_t
size,
>               flush_kernel_dcache_range((unsigned long)vaddr, size);
>  }
>
> +static inline int
> +dma_mmap_coherent(struct device *dev, struct vm_area_struct *vma,
> +               void *cpu_addr, dma_addr_t handle, size_t size)
> +{
> +     if (!hppa_dma_ops->mmap_coherent)
> +             return -ENXIO;
> +     return hppa_dma_ops->mmap_coherent(dev, vma, cpu_addr, handle, size);
> +}
> +
>  static inline void *
>  parisc_walk_tree(struct device *dev)
>  {

Tx,
    J.

Attachment: TI2.txt
Description: Text document

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