From mboxrd@z Thu Jan 1 00:00:00 1970 From: Yong Wu Subject: Re: [PATCH v2 2/4] iommu: Implement common IOMMU ops for DMA mapping Date: Thu, 18 Jun 2015 23:00:25 +0800 Message-ID: <1434639625.26953.12.camel@mhfsdcap03> References: Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: iommu-bounces-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org Errors-To: iommu-bounces-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org To: Robin Murphy Cc: laurent.pinchart+renesas-ryLnwIuWjnjg/C1BVhZhaw@public.gmane.org, arnd-r2nGTMty4D4@public.gmane.org, catalin.marinas-5wv7dgnIgG8@public.gmane.org, will.deacon-5wv7dgnIgG8@public.gmane.org, tomasz.figa-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org, iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org, djkurtz-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org, thunder.leizhen-hv44wF8Li93QT0dZR+AlfA@public.gmane.org, yt.shen-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org, yingjoe.chen-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org, treding-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org, linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org List-Id: iommu@lists.linux-foundation.org Hi Robin, while our drm test, we meet a problem while dma-mmap. On Thu, 2015-06-11 at 16:54 +0100, Robin Murphy wrote: > Taking inspiration from the existing arch/arm code, break out some > generic functions to interface the DMA-API to the IOMMU-API. This will > do the bulk of the heavy lifting for IOMMU-backed dma-mapping. > > Signed-off-by: Robin Murphy > --- > drivers/iommu/Kconfig | 7 + > drivers/iommu/Makefile | 1 + > drivers/iommu/dma-iommu.c | 560 ++++++++++++++++++++++++++++++++++++++++++++++ > include/linux/dma-iommu.h | 94 ++++++++ > 4 files changed, 662 insertions(+) > create mode 100644 drivers/iommu/dma-iommu.c > create mode 100644 include/linux/dma-iommu.h > [snip] > +/** > + * iommu_dma_mmap - Map a buffer into provided user VMA > + * @pages: Array representing buffer from iommu_dma_alloc() > + * @size: Size of buffer in bytes > + * @vma: VMA describing requested userspace mapping > + * > + * Maps the pages of the buffer in @pages into @vma. The caller is responsible > + * for verifying the correct size and protection of @vma beforehand. > + */ > + > +int iommu_dma_mmap(struct page **pages, size_t size, struct vm_area_struct *vma) > +{ > + unsigned long uaddr = vma->vm_start; > + unsigned int i, count = PAGE_ALIGN(size) >> PAGE_SHIFT; > + int ret = -ENXIO; > + > + for (i = vma->vm_pgoff; i < count && uaddr < vma->vm_end; i++) { Is it : for (i = 0; i < count && uaddr < vma->vm_end; i++) > + ret = vm_insert_page(vma, uaddr, pages[i]); > + if (ret) > + break; > + uaddr += PAGE_SIZE; > + } > + return ret; > +} > + From mboxrd@z Thu Jan 1 00:00:00 1970 From: yong.wu@mediatek.com (Yong Wu) Date: Thu, 18 Jun 2015 23:00:25 +0800 Subject: [PATCH v2 2/4] iommu: Implement common IOMMU ops for DMA mapping In-Reply-To: References: Message-ID: <1434639625.26953.12.camel@mhfsdcap03> To: linux-arm-kernel@lists.infradead.org List-Id: linux-arm-kernel.lists.infradead.org Hi Robin, while our drm test, we meet a problem while dma-mmap. On Thu, 2015-06-11 at 16:54 +0100, Robin Murphy wrote: > Taking inspiration from the existing arch/arm code, break out some > generic functions to interface the DMA-API to the IOMMU-API. This will > do the bulk of the heavy lifting for IOMMU-backed dma-mapping. > > Signed-off-by: Robin Murphy > --- > drivers/iommu/Kconfig | 7 + > drivers/iommu/Makefile | 1 + > drivers/iommu/dma-iommu.c | 560 ++++++++++++++++++++++++++++++++++++++++++++++ > include/linux/dma-iommu.h | 94 ++++++++ > 4 files changed, 662 insertions(+) > create mode 100644 drivers/iommu/dma-iommu.c > create mode 100644 include/linux/dma-iommu.h > [snip] > +/** > + * iommu_dma_mmap - Map a buffer into provided user VMA > + * @pages: Array representing buffer from iommu_dma_alloc() > + * @size: Size of buffer in bytes > + * @vma: VMA describing requested userspace mapping > + * > + * Maps the pages of the buffer in @pages into @vma. The caller is responsible > + * for verifying the correct size and protection of @vma beforehand. > + */ > + > +int iommu_dma_mmap(struct page **pages, size_t size, struct vm_area_struct *vma) > +{ > + unsigned long uaddr = vma->vm_start; > + unsigned int i, count = PAGE_ALIGN(size) >> PAGE_SHIFT; > + int ret = -ENXIO; > + > + for (i = vma->vm_pgoff; i < count && uaddr < vma->vm_end; i++) { Is it : for (i = 0; i < count && uaddr < vma->vm_end; i++) > + ret = vm_insert_page(vma, uaddr, pages[i]); > + if (ret) > + break; > + uaddr += PAGE_SIZE; > + } > + return ret; > +} > +