linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Florian Fainelli <f.fainelli@gmail.com>
To: linux-mips@linux-mips.org
Cc: Florian Fainelli <florian.fainelli@broadcom.com>,
	Florian Fainelli <f.fainelli@gmail.com>,
	Ralf Baechle <ralf@linux-mips.org>,
	Kevin Cernekee <cernekee@gmail.com>,
	James Hogan <jhogan@kernel.org>,
	Paul Burton <paul.burton@mips.com>,
	Matt Redfearn <matt.redfearn@mips.com>,
	"Maciej W. Rozycki" <macro@mips.com>,
	Huacai Chen <chenhc@lemote.com>,
	Kate Stewart <kstewart@linuxfoundation.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Marcin Nowakowski <marcin.nowakowski@mips.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	"Eric W. Biederman" <ebiederm@xmission.com>,
	Ingo Molnar <mingo@kernel.org>,
	David Howells <dhowells@redhat.com>,
	Kees Cook <keescook@chromium.org>, Thomas Meyer <thomas@m3y3r.de>,
	"Bryan O'Donoghue" <pure.logic@nexus-software.ie>,
	Robin Murphy <robin.murphy@arm.com>,
	Michal Hocko <mhocko@suse.com>,
	Lucas Stach <l.stach@pengutronix.de>,
	Vladimir Murzin <vladimir.murzin@arm.com>,
	Bart Van Assche <bart.vanassche@sandisk.com>,
	linux-kernel@vger.kernel.org (open list)
Subject: [PATCH RFC 2/6] MIPS: Allow platforms to override mapping/unmapping coherent
Date: Tue, 23 Jan 2018 17:47:02 -0800	[thread overview]
Message-ID: <1516758426-8127-3-git-send-email-f.fainelli@gmail.com> (raw)
In-Reply-To: <1516758426-8127-1-git-send-email-f.fainelli@gmail.com>

From: Florian Fainelli <florian.fainelli@broadcom.com>

In preparation for allowing support for Broadcom's eXtended Kseg0/1
feature, allow platforms to override how coherent DMA mappings are done
by providing plat_map_coherent() and plat_unmap_coherent() hooks, which
default to the current implementation with CAC/UNCAC unless changed.

Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
---
 arch/mips/include/asm/mach-generic/dma-coherence.h | 16 ++++++++++++++++
 arch/mips/mm/dma-default.c                         | 10 +++++++---
 2 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/arch/mips/include/asm/mach-generic/dma-coherence.h b/arch/mips/include/asm/mach-generic/dma-coherence.h
index e6e7dfa15801..42a1546e7d10 100644
--- a/arch/mips/include/asm/mach-generic/dma-coherence.h
+++ b/arch/mips/include/asm/mach-generic/dma-coherence.h
@@ -98,4 +98,20 @@ static inline phys_addr_t dma_to_phys(struct device *dev, dma_addr_t daddr)
 #endif
 #endif /* CONFIG_SWIOTLB */
 
+#ifndef plat_map_coherent
+static inline int plat_map_coherent(dma_addr_t handle, void *cac_va, size_t size,
+				    void **uncac_va, gfp_t gfp)
+{
+	*uncac_va = UNCAC_ADDR(cac_va);
+	return 0;
+}
+#endif
+
+#ifndef plat_unmap_coherent
+static inline void *plat_unmap_coherent(void *addr)
+{
+	return CAC_ADDR(addr);
+}
+#endif
+
 #endif /* __ASM_MACH_GENERIC_DMA_COHERENCE_H */
diff --git a/arch/mips/mm/dma-default.c b/arch/mips/mm/dma-default.c
index e3e94d05f0fd..f82f00dcc841 100644
--- a/arch/mips/mm/dma-default.c
+++ b/arch/mips/mm/dma-default.c
@@ -151,7 +151,11 @@ static void *mips_dma_alloc_coherent(struct device *dev, size_t size,
 	if (!(attrs & DMA_ATTR_NON_CONSISTENT) &&
 	    !plat_device_is_coherent(dev)) {
 		dma_cache_wback_inv((unsigned long) ret, size);
-		ret = UNCAC_ADDR(ret);
+		if (plat_map_coherent(*dma_handle, ret, PFN_ALIGN(size),
+				      &ret, gfp)) {
+			free_pages((unsigned long)ret, size);
+			ret = NULL;
+		}
 	}
 
 	return ret;
@@ -167,7 +171,7 @@ static void mips_dma_free_coherent(struct device *dev, size_t size, void *vaddr,
 	plat_unmap_dma_mem(dev, dma_handle, size, DMA_BIDIRECTIONAL);
 
 	if (!(attrs & DMA_ATTR_NON_CONSISTENT) && !plat_device_is_coherent(dev))
-		addr = CAC_ADDR(addr);
+		addr = (unsigned long)plat_unmap_coherent(vaddr);
 
 	page = virt_to_page((void *) addr);
 
@@ -187,7 +191,7 @@ static int mips_dma_mmap(struct device *dev, struct vm_area_struct *vma,
 	int ret = -ENXIO;
 
 	if (!plat_device_is_coherent(dev))
-		addr = CAC_ADDR(addr);
+		addr = (unsigned long)plat_unmap_coherent((void *)addr);
 
 	pfn = page_to_pfn(virt_to_page((void *)addr));
 
-- 
2.7.4

  parent reply	other threads:[~2018-01-24  1:47 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-24  1:47 [PATCH RFC 0/6] MIPS: Broadcom eXtended KSEG0/1 support Florian Fainelli
2018-01-24  1:47 ` [PATCH RFC 1/6] MIPS: Allow board to override TLB initialization Florian Fainelli
2018-01-24  1:47 ` Florian Fainelli [this message]
2018-01-24  1:47 ` [PATCH RFC 3/6] MIPS: BMIPS: Avoid referencing CKSEG1 Florian Fainelli
2018-02-02 17:38   ` Maciej W. Rozycki
2018-01-24  1:47 ` [PATCH RFC 4/6] MIPS: Prepare for supporting eXtended KSEG0/1 Florian Fainelli
2018-01-24  1:47 ` [PATCH RFC 5/6] MIPS: BMIPS: Handshake with CFE Florian Fainelli
2018-01-24  1:47 ` [PATCH RFC 6/6] MIPS: BMIPS: Add support for eXtended KSEG0/1 (XKS01) Florian Fainelli
2018-01-26  8:31 ` [PATCH RFC 0/6] MIPS: Broadcom eXtended KSEG0/1 support Steven J. Hill
2018-01-29 20:10   ` Florian Fainelli

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=1516758426-8127-3-git-send-email-f.fainelli@gmail.com \
    --to=f.fainelli@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=bart.vanassche@sandisk.com \
    --cc=cernekee@gmail.com \
    --cc=chenhc@lemote.com \
    --cc=dhowells@redhat.com \
    --cc=ebiederm@xmission.com \
    --cc=florian.fainelli@broadcom.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jhogan@kernel.org \
    --cc=keescook@chromium.org \
    --cc=kstewart@linuxfoundation.org \
    --cc=l.stach@pengutronix.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mips@linux-mips.org \
    --cc=macro@mips.com \
    --cc=marcin.nowakowski@mips.com \
    --cc=matt.redfearn@mips.com \
    --cc=mhocko@suse.com \
    --cc=mingo@kernel.org \
    --cc=paul.burton@mips.com \
    --cc=pure.logic@nexus-software.ie \
    --cc=ralf@linux-mips.org \
    --cc=robin.murphy@arm.com \
    --cc=thomas@m3y3r.de \
    --cc=vladimir.murzin@arm.com \
    /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).