[PATCH RFC 11/12] dma: provide of_dma_coherent_fixup helper

Ahmad Fatoum a.fatoum at pengutronix.de
Tue Feb 21 00:05:23 PST 2023


Upstream DT changing dma-coherency setting can break booting newer
kernels. TO allows newer bareboxes to both boot old and new kernels add
a new DT fixup helper that may be called from board code after enabling
cache coherence.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 drivers/dma/Makefile    |  1 +
 drivers/dma/of_fixups.c | 16 ++++++++++++++++
 include/of_address.h    |  8 ++++++++
 3 files changed, 25 insertions(+)
 create mode 100644 drivers/dma/of_fixups.c

diff --git a/drivers/dma/Makefile b/drivers/dma/Makefile
index 39829cab5008..a3c1d52e05c3 100644
--- a/drivers/dma/Makefile
+++ b/drivers/dma/Makefile
@@ -1,3 +1,4 @@
 # SPDX-License-Identifier: GPL-2.0-only
 obj-$(CONFIG_MXS_APBH_DMA)	+= apbh_dma.o
 obj-$(CONFIG_HAS_DMA)		+= map.o
+obj-$(CONFIG_OFTREE)		+= of_fixups.o
diff --git a/drivers/dma/of_fixups.c b/drivers/dma/of_fixups.c
new file mode 100644
index 000000000000..27dc24e287ee
--- /dev/null
+++ b/drivers/dma/of_fixups.c
@@ -0,0 +1,16 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#include <of.h>
+#include <of_address.h>
+
+int of_dma_coherent_fixup(struct device_node *root, void *data)
+{
+	struct device_node *soc;
+
+	soc = of_find_node_by_path_from(root, "/soc");
+	if (!soc)
+		return -ENOENT;
+
+	of_property_write_bool(soc, "dma-noncoherent", false);
+	return of_property_write_bool(soc, "dma-coherent", true);
+}
diff --git a/include/of_address.h b/include/of_address.h
index 4e5faf6f7783..4f425e0803eb 100644
--- a/include/of_address.h
+++ b/include/of_address.h
@@ -62,6 +62,8 @@ extern int of_dma_get_range(struct device_node *np, u64 *dma_addr, u64 *paddr,
 
 extern bool of_dma_is_coherent(struct device_node *np);
 
+extern int of_dma_coherent_fixup(struct device_node *np, void *unused);
+
 #else /* CONFIG_OFTREE */
 
 static inline u64 of_translate_address(struct device_node *dev,
@@ -115,6 +117,12 @@ static inline bool of_dma_is_coherent(struct device_node *np)
 {
 	return false;
 }
+
+static inline int of_dma_coherent_fixup(struct device_node *np, void *unused)
+{
+	return 0;
+}
+
 #endif /* CONFIG_OFTREE */
 
 #ifdef CONFIG_OF_PCI
-- 
2.30.2




More information about the barebox mailing list