iommu.lists.linux-foundation.org archive mirror
 help / color / mirror / Atom feed
From: Christoph Hellwig <hch-jcswGhMUV9g@public.gmane.org>
To: Chris Zankel <chris-YvXeqwSYzG2sTnJN9+BGXg@public.gmane.org>,
	Max Filippov <jcmvbkbc-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Cc: linux-xtensa-PjhNF2WwrV/0Sa2dR60CXw@public.gmane.org,
	iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org
Subject: [PATCH 3/3] xtensa: use dma_direct_{alloc,free}_pages
Date: Thu, 20 Sep 2018 19:15:40 +0200	[thread overview]
Message-ID: <20180920171540.2657-4-hch@lst.de> (raw)
In-Reply-To: <20180920171540.2657-1-hch-jcswGhMUV9g@public.gmane.org>

Use the generic helpers for dma allocation instead of opencoding them
with slightly less bells and whistles.

Signed-off-by: Christoph Hellwig <hch-jcswGhMUV9g@public.gmane.org>
---
 arch/xtensa/kernel/pci-dma.c | 48 ++++++++++--------------------------
 1 file changed, 13 insertions(+), 35 deletions(-)

diff --git a/arch/xtensa/kernel/pci-dma.c b/arch/xtensa/kernel/pci-dma.c
index a764d894ffdd..a74ca0dd728a 100644
--- a/arch/xtensa/kernel/pci-dma.c
+++ b/arch/xtensa/kernel/pci-dma.c
@@ -141,56 +141,34 @@ void __attribute__((weak)) *platform_vaddr_to_cached(void *p)
  * Note: We assume that the full memory space is always mapped to 'kseg'
  *	 Otherwise we have to use page attributes (not implemented).
  */
-
-void *arch_dma_alloc(struct device *dev, size_t size, dma_addr_t *handle,
-		gfp_t flag, unsigned long attrs)
+void *arch_dma_alloc(struct device *dev, size_t size, dma_addr_t *dma_handle,
+		gfp_t gfp, unsigned long attrs)
 {
-	unsigned long count = PAGE_ALIGN(size) >> PAGE_SHIFT;
-	struct page *page = NULL;
-
-	/* ignore region speicifiers */
-
-	flag &= ~(__GFP_DMA | __GFP_HIGHMEM);
-
-	if (dev == NULL || (dev->coherent_dma_mask < 0xffffffff))
-		flag |= GFP_DMA;
-
-	if (gfpflags_allow_blocking(flag))
-		page = dma_alloc_from_contiguous(dev, count, get_order(size),
-						 flag & __GFP_NOWARN);
+	void *vaddr;
 
-	if (!page)
-		page = alloc_pages(flag, get_order(size));
-
-	if (!page)
+	vaddr = dma_direct_alloc_pages(dev, size, dma_handle, gfp, attrs);
+	if (!vaddr)
 		return NULL;
 
-	*handle = phys_to_dma(dev, page_to_phys(page));
+	if (attrs & DMA_ATTR_NO_KERNEL_MAPPING)
+		return virt_to_page(vaddr); /* just a random cookie */
 
-	if (attrs & DMA_ATTR_NO_KERNEL_MAPPING) {
-		return page;
-	}
-
-	BUG_ON(!platform_vaddr_cached(page_address(page)));
-	__invalidate_dcache_range((unsigned long)page_address(page), size);
-	return platform_vaddr_to_uncached(page_address(page));
+	BUG_ON(!platform_vaddr_cached(vaddr));
+	__invalidate_dcache_range((unsigned long)vaddr, size);
+	return platform_vaddr_to_uncached(vaddr);
 }
 
 void arch_dma_free(struct device *dev, size_t size, void *vaddr,
 		dma_addr_t dma_handle, unsigned long attrs)
 {
-	unsigned long count = PAGE_ALIGN(size) >> PAGE_SHIFT;
-	struct page *page;
-
 	if (attrs & DMA_ATTR_NO_KERNEL_MAPPING) {
-		page = vaddr;
+		vaddr = page_to_virt((struct page *)vaddr); /* decode cookie */
 	} else if (platform_vaddr_uncached(vaddr)) {
-		page = virt_to_page(platform_vaddr_to_cached(vaddr));
+		vaddr = platform_vaddr_to_cached(vaddr);
 	} else {
 		WARN_ON_ONCE(1);
 		return;
 	}
 
-	if (!dma_release_from_contiguous(dev, page, count))
-		__free_pages(page, get_order(size));
+	dma_direct_free_pages(dev, size, vaddr, dma_handle, attrs);
 }
-- 
2.18.0

      parent reply	other threads:[~2018-09-20 17:15 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-20 17:15 xtensa dma-mapping tidyups Christoph Hellwig
     [not found] ` <20180920171540.2657-1-hch-jcswGhMUV9g@public.gmane.org>
2018-09-20 17:15   ` [PATCH 1/3] xtensa: remove partial support for DMA buffers in high memory Christoph Hellwig
     [not found]     ` <20180920171540.2657-2-hch-jcswGhMUV9g@public.gmane.org>
2018-09-20 17:44       ` Max Filippov
     [not found]         ` <CAMo8BfKyW+3t+L+oQ+nDyEs8KcASPC8CeUP3QPoANQC=XKP9hg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2018-09-20 18:08           ` Christoph Hellwig
     [not found]             ` <20180920180833.GB27677-jcswGhMUV9g@public.gmane.org>
2018-09-20 19:08               ` Max Filippov
     [not found]                 ` <20180921065100.GA14246@lst.de>
     [not found]                   ` <20180921065100.GA14246-jcswGhMUV9g@public.gmane.org>
2018-09-21 16:40                     ` Michał Nazarewicz
2018-09-21 17:42                     ` Max Filippov
2018-09-20 17:15   ` [PATCH 2/3] xtensa: remove ZONE_DMA Christoph Hellwig
2018-09-20 17:15   ` Christoph Hellwig [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180920171540.2657-4-hch@lst.de \
    --to=hch-jcswghmuv9g@public.gmane.org \
    --cc=chris-YvXeqwSYzG2sTnJN9+BGXg@public.gmane.org \
    --cc=iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org \
    --cc=jcmvbkbc-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
    --cc=linux-xtensa-PjhNF2WwrV/0Sa2dR60CXw@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).