* [PATCH 1/2] of: have of_property_match_string accept pointer to const device_node
@ 2022-12-05 13:32 Ahmad Fatoum
2022-12-05 13:32 ` [PATCH 2/2] of: platform: port Linux of_dma_is_coherent Ahmad Fatoum
2022-12-07 6:58 ` [PATCH 1/2] of: have of_property_match_string accept pointer to const device_node Sascha Hauer
0 siblings, 2 replies; 3+ messages in thread
From: Ahmad Fatoum @ 2022-12-05 13:32 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
This function need not have mutable access to the device node, so make
the parameter const to allow calling it from more places without
sacrificing cost safety.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
drivers/of/base.c | 2 +-
include/of.h | 4 ++--
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/of/base.c b/drivers/of/base.c
index 2eee1279a98d..221050a19715 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -1049,7 +1049,7 @@ EXPORT_SYMBOL_GPL(of_property_read_string);
* This function searches a string list property and returns the index
* of a specific string value.
*/
-int of_property_match_string(struct device_node *np, const char *propname,
+int of_property_match_string(const struct device_node *np, const char *propname,
const char *string)
{
struct property *prop = of_find_property(np, propname, NULL);
diff --git a/include/of.h b/include/of.h
index 052d5fcad84c..c19a17584e47 100644
--- a/include/of.h
+++ b/include/of.h
@@ -229,7 +229,7 @@ extern int of_property_read_variable_u64_array(const struct device_node *np,
extern int of_property_read_string(struct device_node *np,
const char *propname,
const char **out_string);
-extern int of_property_match_string(struct device_node *np,
+extern int of_property_match_string(const struct device_node *np,
const char *propname,
const char *string);
extern int of_property_read_string_helper(const struct device_node *np,
@@ -616,7 +616,7 @@ static inline int of_property_read_string(struct device_node *np,
return -ENOSYS;
}
-static inline int of_property_match_string(struct device_node *np,
+static inline int of_property_match_string(const struct device_node *np,
const char *propname, const char *string)
{
return -ENOSYS;
--
2.30.2
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH 2/2] of: platform: port Linux of_dma_is_coherent
2022-12-05 13:32 [PATCH 1/2] of: have of_property_match_string accept pointer to const device_node Ahmad Fatoum
@ 2022-12-05 13:32 ` Ahmad Fatoum
2022-12-07 6:58 ` [PATCH 1/2] of: have of_property_match_string accept pointer to const device_node Sascha Hauer
1 sibling, 0 replies; 3+ messages in thread
From: Ahmad Fatoum @ 2022-12-05 13:32 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
In order to correctly handle cache-coherent systems on ARM, we need to
be able to determine whether a device instantiated from DT is DMA
coherent. Port the Linux helper that does this check.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
of_dma_is_coherent is still unused, but it will be used in future.
---
arch/riscv/Kconfig | 1 +
drivers/of/Kconfig | 4 ++++
drivers/of/platform.c | 41 +++++++++++++++++++++++++++++++++++++++++
include/of_address.h | 6 ++++++
4 files changed, 52 insertions(+)
diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig
index cd7f4abf5694..afbd55aa3e6f 100644
--- a/arch/riscv/Kconfig
+++ b/arch/riscv/Kconfig
@@ -10,6 +10,7 @@ config RISCV
select COMMON_CLK_OF_PROVIDER
select CLKDEV_LOOKUP
select HAS_DMA
+ select OF_DMA_DEFAULT_COHERENT
select HAVE_PBL_IMAGE
select HAVE_PBL_MULTI_IMAGES
select HAVE_IMAGE_COMPRESSION
diff --git a/drivers/of/Kconfig b/drivers/of/Kconfig
index 7283331ba9ce..4dc40b27f442 100644
--- a/drivers/of/Kconfig
+++ b/drivers/of/Kconfig
@@ -31,6 +31,10 @@ config FEATURE_CONTROLLER_FIXUP
config OF_ADDRESS_PCI
bool
+config OF_DMA_DEFAULT_COHERENT
+ # arches should select this if DMA is coherent by default for OF devices
+ bool
+
config OF_GPIO
depends on GPIOLIB
depends on OFDEVICE
diff --git a/drivers/of/platform.c b/drivers/of/platform.c
index a9a5d4c2daf2..2b5ad08c124b 100644
--- a/drivers/of/platform.c
+++ b/drivers/of/platform.c
@@ -73,6 +73,47 @@ static void of_device_make_bus_id(struct device_d *dev)
}
}
+static struct device_node *of_get_next_dma_parent(const struct device_node *np)
+{
+ struct of_phandle_args args;
+ int ret, index;
+
+ index = of_property_match_string(np, "interconnect-names", "dma-mem");
+ if (index < 0)
+ return of_get_parent(np);
+
+ ret = of_parse_phandle_with_args(np, "interconnects",
+ "#interconnect-cells",
+ index, &args);
+ if (ret < 0)
+ return of_get_parent(np);
+
+ return args.np;
+}
+
+/**
+ * of_dma_is_coherent - Check if device is coherent
+ * @np: device node
+ *
+ * It returns true if "dma-coherent" property was found
+ * for this device in the DT, or if DMA is coherent by
+ * default for OF devices on the current platform and no
+ * "dma-noncoherent" property was found for this device.
+ */
+bool of_dma_is_coherent(struct device_node *node)
+{
+ while (node) {
+ if (of_property_read_bool(node, "dma-coherent"))
+ return true;
+ if (of_property_read_bool(node, "dma-noncoherent"))
+ return false;
+ node = of_get_next_dma_parent(node);
+ }
+
+ return IS_ENABLED(CONFIG_OF_DMA_DEFAULT_COHERENT);
+}
+EXPORT_SYMBOL_GPL(of_dma_is_coherent);
+
static void of_dma_configure(struct device_d *dev, struct device_node *np)
{
u64 dma_addr, paddr, size = 0;
diff --git a/include/of_address.h b/include/of_address.h
index 66117b1fa7f8..4e5faf6f7783 100644
--- a/include/of_address.h
+++ b/include/of_address.h
@@ -60,6 +60,8 @@ extern void __iomem *of_iomap(struct device_node *np, int index);
extern int of_dma_get_range(struct device_node *np, u64 *dma_addr, u64 *paddr,
u64 *size);
+extern bool of_dma_is_coherent(struct device_node *np);
+
#else /* CONFIG_OFTREE */
static inline u64 of_translate_address(struct device_node *dev,
@@ -109,6 +111,10 @@ static inline int of_dma_get_range(struct device_node *np, u64 *dma_addr,
return -ENOSYS;
}
+static inline bool of_dma_is_coherent(struct device_node *np)
+{
+ return false;
+}
#endif /* CONFIG_OFTREE */
#ifdef CONFIG_OF_PCI
--
2.30.2
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH 1/2] of: have of_property_match_string accept pointer to const device_node
2022-12-05 13:32 [PATCH 1/2] of: have of_property_match_string accept pointer to const device_node Ahmad Fatoum
2022-12-05 13:32 ` [PATCH 2/2] of: platform: port Linux of_dma_is_coherent Ahmad Fatoum
@ 2022-12-07 6:58 ` Sascha Hauer
1 sibling, 0 replies; 3+ messages in thread
From: Sascha Hauer @ 2022-12-07 6:58 UTC (permalink / raw)
To: Ahmad Fatoum; +Cc: barebox
On Mon, Dec 05, 2022 at 02:32:26PM +0100, Ahmad Fatoum wrote:
> This function need not have mutable access to the device node, so make
> the parameter const to allow calling it from more places without
> sacrificing cost safety.
>
> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> ---
> drivers/of/base.c | 2 +-
> include/of.h | 4 ++--
> 2 files changed, 3 insertions(+), 3 deletions(-)
Applied, thanks
Sascha
>
> diff --git a/drivers/of/base.c b/drivers/of/base.c
> index 2eee1279a98d..221050a19715 100644
> --- a/drivers/of/base.c
> +++ b/drivers/of/base.c
> @@ -1049,7 +1049,7 @@ EXPORT_SYMBOL_GPL(of_property_read_string);
> * This function searches a string list property and returns the index
> * of a specific string value.
> */
> -int of_property_match_string(struct device_node *np, const char *propname,
> +int of_property_match_string(const struct device_node *np, const char *propname,
> const char *string)
> {
> struct property *prop = of_find_property(np, propname, NULL);
> diff --git a/include/of.h b/include/of.h
> index 052d5fcad84c..c19a17584e47 100644
> --- a/include/of.h
> +++ b/include/of.h
> @@ -229,7 +229,7 @@ extern int of_property_read_variable_u64_array(const struct device_node *np,
> extern int of_property_read_string(struct device_node *np,
> const char *propname,
> const char **out_string);
> -extern int of_property_match_string(struct device_node *np,
> +extern int of_property_match_string(const struct device_node *np,
> const char *propname,
> const char *string);
> extern int of_property_read_string_helper(const struct device_node *np,
> @@ -616,7 +616,7 @@ static inline int of_property_read_string(struct device_node *np,
> return -ENOSYS;
> }
>
> -static inline int of_property_match_string(struct device_node *np,
> +static inline int of_property_match_string(const struct device_node *np,
> const char *propname, const char *string)
> {
> return -ENOSYS;
> --
> 2.30.2
>
>
>
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-12-07 6:59 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-05 13:32 [PATCH 1/2] of: have of_property_match_string accept pointer to const device_node Ahmad Fatoum
2022-12-05 13:32 ` [PATCH 2/2] of: platform: port Linux of_dma_is_coherent Ahmad Fatoum
2022-12-07 6:58 ` [PATCH 1/2] of: have of_property_match_string accept pointer to const device_node Sascha Hauer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox