From: dillon.minfei@gmail.com
To: robh+dt@kernel.org, mcoquelin.stm32@gmail.com,
alexandre.torgue@st.com, linux@armlinux.org.uk,
vladimir.murzin@arm.com, kstewart@linuxfoundation.org,
allison@lohutok.net, info@metux.net, tglx@linutronix.de
Cc: devicetree@vger.kernel.org, dillon min <dillon.minfei@gmail.com>,
linux-stm32@st-md-mailman.stormreply.com,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org
Subject: [PATCH 2/2] arm-nommu: Add use_reserved_mem() to check if device support reserved memory
Date: Mon, 8 Jun 2020 16:30:38 +0800 [thread overview]
Message-ID: <1591605038-8682-3-git-send-email-dillon.minfei@gmail.com> (raw)
In-Reply-To: <1591605038-8682-1-git-send-email-dillon.minfei@gmail.com>
From: dillon min <dillon.minfei@gmail.com>
Currently, we use dma direct to request coherent memory for driver on armv7m
platform if 'cacheid' is zero, but dma_direct_can_mmap() is return false,
dma_direct_mmap() return -ENXIO for CONFIG_MMU undefined platform.
so we have to back to use 'arm_nommu_dma_ops', add use_reserved_mem() to check
if device support global or device corherent memory. if yes, then call
set_dma_ops()
Signed-off-by: dillon min <dillon.minfei@gmail.com>
---
arch/arm/mm/dma-mapping-nommu.c | 28 +++++++++++++++++++++++++++-
1 file changed, 27 insertions(+), 1 deletion(-)
diff --git a/arch/arm/mm/dma-mapping-nommu.c b/arch/arm/mm/dma-mapping-nommu.c
index 287ef898a55e..e1c213fec152 100644
--- a/arch/arm/mm/dma-mapping-nommu.c
+++ b/arch/arm/mm/dma-mapping-nommu.c
@@ -14,6 +14,7 @@
#include <asm/cacheflush.h>
#include <asm/outercache.h>
#include <asm/cp15.h>
+#include <linux/of.h>
#include "dma.h"
@@ -188,6 +189,31 @@ const struct dma_map_ops arm_nommu_dma_ops = {
};
EXPORT_SYMBOL(arm_nommu_dma_ops);
+static bool use_reserved_mem(struct device *dev)
+{
+ struct device_node *np;
+
+ np = of_find_node_by_path("/reserved-memory/linux,dma");
+
+ if (np &&
+ of_device_is_compatible(np, "shared-dma-pool") &&
+ of_property_read_bool(np, "no-map") &&
+ of_property_read_bool(np, "linux,dma-default")) {
+ /* has global corherent mem support */
+ of_node_put(np);
+ return true;
+ }
+
+ np = of_parse_phandle(dev->of_node, "memory-region", 0);
+ if (np) {
+ /* has dev corherent mem support */
+ of_node_put(np);
+ return true;
+ }
+
+ return false;
+}
+
void arch_setup_dma_ops(struct device *dev, u64 dma_base, u64 size,
const struct iommu_ops *iommu, bool coherent)
{
@@ -206,6 +232,6 @@ void arch_setup_dma_ops(struct device *dev, u64 dma_base, u64 size,
dev->archdata.dma_coherent = (get_cr() & CR_M) ? coherent : true;
}
- if (!dev->archdata.dma_coherent)
+ if (!dev->archdata.dma_coherent || use_reserved_mem(dev))
set_dma_ops(dev, &arm_nommu_dma_ops);
}
--
2.7.4
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next prev parent reply other threads:[~2020-06-08 8:31 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-08 8:30 [PATCH 0/2] Use 'arm_nommu_dma_ops' to handle dma memroy if device offer consistent dma memory region dillon.minfei
2020-06-08 8:30 ` [PATCH 1/2] ARM: dts: stm32: Setup 4M bytes reserved memory for mmap dillon.minfei
2020-06-09 15:58 ` dillon min
2020-06-08 8:30 ` dillon.minfei [this message]
2020-06-09 14:08 ` [PATCH 2/2] arm-nommu: Add use_reserved_mem() to check if device support reserved memory Vladimir Murzin
2020-06-09 15:22 ` dillon min
2020-06-09 15:36 ` Christoph Hellwig
2020-06-09 15:43 ` Vladimir Murzin
2020-06-09 16:25 ` Vladimir Murzin
2020-06-09 17:34 ` Christoph Hellwig
2020-06-10 2:24 ` dillon min
2020-06-10 7:24 ` Christoph Hellwig
2020-06-10 8:19 ` Vladimir Murzin
2020-06-11 15:45 ` Vladimir Murzin
2020-06-12 2:15 ` dillon min
2020-06-09 15:58 ` [PATCH 0/2] Use 'arm_nommu_dma_ops' to handle dma memroy if device offer consistent dma memory region dillon min
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=1591605038-8682-3-git-send-email-dillon.minfei@gmail.com \
--to=dillon.minfei@gmail.com \
--cc=alexandre.torgue@st.com \
--cc=allison@lohutok.net \
--cc=devicetree@vger.kernel.org \
--cc=info@metux.net \
--cc=kstewart@linuxfoundation.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-stm32@st-md-mailman.stormreply.com \
--cc=linux@armlinux.org.uk \
--cc=mcoquelin.stm32@gmail.com \
--cc=robh+dt@kernel.org \
--cc=tglx@linutronix.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).