All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] of: device: Allow DMA range map to be set before of_dma_configure_id
@ 2021-01-15 17:58 ` Paul Kocialkowski
  0 siblings, 0 replies; 18+ messages in thread
From: Paul Kocialkowski @ 2021-01-15 17:58 UTC (permalink / raw)
  To: devicetree, linux-kernel, linux-arm-kernel
  Cc: Rob Herring, Frank Rowand, Maxime Ripard, Chen-Yu Tsai,
	Jernej Skrabec, Daniel Vetter, Thomas Petazzoni,
	Paul Kocialkowski

A mechanism was recently introduced for the sunxi architecture where
the DMA offset for specific devices (under the MBUS) is set by a common
driver (sunxi_mbus). This driver calls dma_direct_set_offset to set
the device's dma_range_map manually.

However this information was overwritten by of_dma_configure_id, which
obtains the map from of_dma_get_range (or keeps it NULL when it fails
and the force_dma argument is true, which is the case for platform
devices).

As a result, the dma_range_map was always overwritten and the mechanism
could not correctly take effect.

This adds a check to ensure that no previous DMA range map is
overwritten and prints a warning when the map was already set while
also being available from dt. In this case, the map that was already
set is kept.

Fixes: b4bdc4fbf8d0 ("soc: sunxi: Deal with the MBUS DMA offsets in a central place")
Signed-off-by: Paul Kocialkowski <paul.kocialkowski@bootlin.com>
---
 drivers/of/device.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/drivers/of/device.c b/drivers/of/device.c
index aedfaaafd3e7..db1b8634c2c7 100644
--- a/drivers/of/device.c
+++ b/drivers/of/device.c
@@ -181,7 +181,14 @@ int of_dma_configure_id(struct device *dev, struct device_node *np,
 
 	arch_setup_dma_ops(dev, dma_start, size, iommu, coherent);
 
-	dev->dma_range_map = map;
+	if (!dev->dma_range_map) {
+		dev->dma_range_map = map;
+	} else if (map) {
+		dev_warn(dev,
+			 "DMA range map was already set, ignoring range map from dt\n");
+		kfree(map);
+	}
+
 	return 0;
 }
 EXPORT_SYMBOL_GPL(of_dma_configure_id);
-- 
2.30.0


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH 1/2] of: device: Allow DMA range map to be set before of_dma_configure_id
@ 2021-01-15 17:58 ` Paul Kocialkowski
  0 siblings, 0 replies; 18+ messages in thread
From: Paul Kocialkowski @ 2021-01-15 17:58 UTC (permalink / raw)
  To: devicetree, linux-kernel, linux-arm-kernel
  Cc: Jernej Skrabec, Daniel Vetter, Maxime Ripard, Paul Kocialkowski,
	Chen-Yu Tsai, Rob Herring, Thomas Petazzoni, Frank Rowand

A mechanism was recently introduced for the sunxi architecture where
the DMA offset for specific devices (under the MBUS) is set by a common
driver (sunxi_mbus). This driver calls dma_direct_set_offset to set
the device's dma_range_map manually.

However this information was overwritten by of_dma_configure_id, which
obtains the map from of_dma_get_range (or keeps it NULL when it fails
and the force_dma argument is true, which is the case for platform
devices).

As a result, the dma_range_map was always overwritten and the mechanism
could not correctly take effect.

This adds a check to ensure that no previous DMA range map is
overwritten and prints a warning when the map was already set while
also being available from dt. In this case, the map that was already
set is kept.

Fixes: b4bdc4fbf8d0 ("soc: sunxi: Deal with the MBUS DMA offsets in a central place")
Signed-off-by: Paul Kocialkowski <paul.kocialkowski@bootlin.com>
---
 drivers/of/device.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/drivers/of/device.c b/drivers/of/device.c
index aedfaaafd3e7..db1b8634c2c7 100644
--- a/drivers/of/device.c
+++ b/drivers/of/device.c
@@ -181,7 +181,14 @@ int of_dma_configure_id(struct device *dev, struct device_node *np,
 
 	arch_setup_dma_ops(dev, dma_start, size, iommu, coherent);
 
-	dev->dma_range_map = map;
+	if (!dev->dma_range_map) {
+		dev->dma_range_map = map;
+	} else if (map) {
+		dev_warn(dev,
+			 "DMA range map was already set, ignoring range map from dt\n");
+		kfree(map);
+	}
+
 	return 0;
 }
 EXPORT_SYMBOL_GPL(of_dma_configure_id);
-- 
2.30.0


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH 2/2] soc: sunxi: mbus: Remove DE2 display engine compatibles
  2021-01-15 17:58 ` Paul Kocialkowski
@ 2021-01-15 17:58   ` Paul Kocialkowski
  -1 siblings, 0 replies; 18+ messages in thread
From: Paul Kocialkowski @ 2021-01-15 17:58 UTC (permalink / raw)
  To: devicetree, linux-kernel, linux-arm-kernel
  Cc: Rob Herring, Frank Rowand, Maxime Ripard, Chen-Yu Tsai,
	Jernej Skrabec, Daniel Vetter, Thomas Petazzoni,
	Paul Kocialkowski

The DE2 display engine hardware takes physical addresses that do not
need PHYS_BASE subtracted. As a result, they should not be present
on the mbus driver match list. Remove them.

This was tested on the A83T, along with the patch allowing the DMA
range map to be non-NULL and restores a working display.

Fixes: b4bdc4fbf8d0 ("soc: sunxi: Deal with the MBUS DMA offsets in a central place")
Signed-off-by: Paul Kocialkowski <paul.kocialkowski@bootlin.com>
---
 drivers/soc/sunxi/sunxi_mbus.c | 5 -----
 1 file changed, 5 deletions(-)

diff --git a/drivers/soc/sunxi/sunxi_mbus.c b/drivers/soc/sunxi/sunxi_mbus.c
index e9925c8487d7..d90e4a264b6f 100644
--- a/drivers/soc/sunxi/sunxi_mbus.c
+++ b/drivers/soc/sunxi/sunxi_mbus.c
@@ -23,12 +23,7 @@ static const char * const sunxi_mbus_devices[] = {
 	"allwinner,sun7i-a20-display-engine",
 	"allwinner,sun8i-a23-display-engine",
 	"allwinner,sun8i-a33-display-engine",
-	"allwinner,sun8i-a83t-display-engine",
-	"allwinner,sun8i-h3-display-engine",
-	"allwinner,sun8i-r40-display-engine",
-	"allwinner,sun8i-v3s-display-engine",
 	"allwinner,sun9i-a80-display-engine",
-	"allwinner,sun50i-a64-display-engine",
 
 	/*
 	 * And now we have the regular devices connected to the MBUS
-- 
2.30.0


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH 2/2] soc: sunxi: mbus: Remove DE2 display engine compatibles
@ 2021-01-15 17:58   ` Paul Kocialkowski
  0 siblings, 0 replies; 18+ messages in thread
From: Paul Kocialkowski @ 2021-01-15 17:58 UTC (permalink / raw)
  To: devicetree, linux-kernel, linux-arm-kernel
  Cc: Jernej Skrabec, Daniel Vetter, Maxime Ripard, Paul Kocialkowski,
	Chen-Yu Tsai, Rob Herring, Thomas Petazzoni, Frank Rowand

The DE2 display engine hardware takes physical addresses that do not
need PHYS_BASE subtracted. As a result, they should not be present
on the mbus driver match list. Remove them.

This was tested on the A83T, along with the patch allowing the DMA
range map to be non-NULL and restores a working display.

Fixes: b4bdc4fbf8d0 ("soc: sunxi: Deal with the MBUS DMA offsets in a central place")
Signed-off-by: Paul Kocialkowski <paul.kocialkowski@bootlin.com>
---
 drivers/soc/sunxi/sunxi_mbus.c | 5 -----
 1 file changed, 5 deletions(-)

diff --git a/drivers/soc/sunxi/sunxi_mbus.c b/drivers/soc/sunxi/sunxi_mbus.c
index e9925c8487d7..d90e4a264b6f 100644
--- a/drivers/soc/sunxi/sunxi_mbus.c
+++ b/drivers/soc/sunxi/sunxi_mbus.c
@@ -23,12 +23,7 @@ static const char * const sunxi_mbus_devices[] = {
 	"allwinner,sun7i-a20-display-engine",
 	"allwinner,sun8i-a23-display-engine",
 	"allwinner,sun8i-a33-display-engine",
-	"allwinner,sun8i-a83t-display-engine",
-	"allwinner,sun8i-h3-display-engine",
-	"allwinner,sun8i-r40-display-engine",
-	"allwinner,sun8i-v3s-display-engine",
 	"allwinner,sun9i-a80-display-engine",
-	"allwinner,sun50i-a64-display-engine",
 
 	/*
 	 * And now we have the regular devices connected to the MBUS
-- 
2.30.0


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* Re: [PATCH 1/2] of: device: Allow DMA range map to be set before of_dma_configure_id
  2021-01-15 17:58 ` Paul Kocialkowski
@ 2021-01-16 14:57   ` Robin Murphy
  -1 siblings, 0 replies; 18+ messages in thread
From: Robin Murphy @ 2021-01-16 14:57 UTC (permalink / raw)
  To: Paul Kocialkowski, devicetree, linux-kernel, linux-arm-kernel
  Cc: Jernej Skrabec, Daniel Vetter, Maxime Ripard, Chen-Yu Tsai,
	Rob Herring, Thomas Petazzoni, Frank Rowand

On 2021-01-15 17:58, Paul Kocialkowski wrote:
> A mechanism was recently introduced for the sunxi architecture where
> the DMA offset for specific devices (under the MBUS) is set by a common
> driver (sunxi_mbus). This driver calls dma_direct_set_offset to set
> the device's dma_range_map manually.
> 
> However this information was overwritten by of_dma_configure_id, which
> obtains the map from of_dma_get_range (or keeps it NULL when it fails
> and the force_dma argument is true, which is the case for platform
> devices).
> 
> As a result, the dma_range_map was always overwritten and the mechanism
> could not correctly take effect.
> 
> This adds a check to ensure that no previous DMA range map is
> overwritten and prints a warning when the map was already set while
> also being available from dt. In this case, the map that was already
> set is kept.

Hang on, the hard-coded offset is only intended to be installed when 
there *isn't* anything described in DT, in which case of_dma_get_range() 
should always bail out early without touching it anyway. This sounds 
like something's not quite right in the MBUS driver, so I don't think 
working around it in core code is really the right thing to do.

Do you have a case where one of the relevant devices inherits a 
"dma-ranges" via the regular hierarchy without indirecting via an 
"interconnects" reference? Currently you're only checking for the 
latter, so that would be one way things could go awry (although to be a 
problem, said "dma-ranges" would also have to encode something *other* 
than the appropriate MBUS offset, which implies an incorrect or at least 
inaccurately-structured DT as well).

Robin.

> Fixes: b4bdc4fbf8d0 ("soc: sunxi: Deal with the MBUS DMA offsets in a central place")
> Signed-off-by: Paul Kocialkowski <paul.kocialkowski@bootlin.com>
> ---
>   drivers/of/device.c | 9 ++++++++-
>   1 file changed, 8 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/of/device.c b/drivers/of/device.c
> index aedfaaafd3e7..db1b8634c2c7 100644
> --- a/drivers/of/device.c
> +++ b/drivers/of/device.c
> @@ -181,7 +181,14 @@ int of_dma_configure_id(struct device *dev, struct device_node *np,
>   
>   	arch_setup_dma_ops(dev, dma_start, size, iommu, coherent);
>   
> -	dev->dma_range_map = map;
> +	if (!dev->dma_range_map) {
> +		dev->dma_range_map = map;
> +	} else if (map) {
> +		dev_warn(dev,
> +			 "DMA range map was already set, ignoring range map from dt\n");
> +		kfree(map);
> +	}
> +
>   	return 0;
>   }
>   EXPORT_SYMBOL_GPL(of_dma_configure_id);
> 

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 1/2] of: device: Allow DMA range map to be set before of_dma_configure_id
@ 2021-01-16 14:57   ` Robin Murphy
  0 siblings, 0 replies; 18+ messages in thread
From: Robin Murphy @ 2021-01-16 14:57 UTC (permalink / raw)
  To: Paul Kocialkowski, devicetree, linux-kernel, linux-arm-kernel
  Cc: Jernej Skrabec, Daniel Vetter, Maxime Ripard, Chen-Yu Tsai,
	Rob Herring, Thomas Petazzoni, Frank Rowand

On 2021-01-15 17:58, Paul Kocialkowski wrote:
> A mechanism was recently introduced for the sunxi architecture where
> the DMA offset for specific devices (under the MBUS) is set by a common
> driver (sunxi_mbus). This driver calls dma_direct_set_offset to set
> the device's dma_range_map manually.
> 
> However this information was overwritten by of_dma_configure_id, which
> obtains the map from of_dma_get_range (or keeps it NULL when it fails
> and the force_dma argument is true, which is the case for platform
> devices).
> 
> As a result, the dma_range_map was always overwritten and the mechanism
> could not correctly take effect.
> 
> This adds a check to ensure that no previous DMA range map is
> overwritten and prints a warning when the map was already set while
> also being available from dt. In this case, the map that was already
> set is kept.

Hang on, the hard-coded offset is only intended to be installed when 
there *isn't* anything described in DT, in which case of_dma_get_range() 
should always bail out early without touching it anyway. This sounds 
like something's not quite right in the MBUS driver, so I don't think 
working around it in core code is really the right thing to do.

Do you have a case where one of the relevant devices inherits a 
"dma-ranges" via the regular hierarchy without indirecting via an 
"interconnects" reference? Currently you're only checking for the 
latter, so that would be one way things could go awry (although to be a 
problem, said "dma-ranges" would also have to encode something *other* 
than the appropriate MBUS offset, which implies an incorrect or at least 
inaccurately-structured DT as well).

Robin.

> Fixes: b4bdc4fbf8d0 ("soc: sunxi: Deal with the MBUS DMA offsets in a central place")
> Signed-off-by: Paul Kocialkowski <paul.kocialkowski@bootlin.com>
> ---
>   drivers/of/device.c | 9 ++++++++-
>   1 file changed, 8 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/of/device.c b/drivers/of/device.c
> index aedfaaafd3e7..db1b8634c2c7 100644
> --- a/drivers/of/device.c
> +++ b/drivers/of/device.c
> @@ -181,7 +181,14 @@ int of_dma_configure_id(struct device *dev, struct device_node *np,
>   
>   	arch_setup_dma_ops(dev, dma_start, size, iommu, coherent);
>   
> -	dev->dma_range_map = map;
> +	if (!dev->dma_range_map) {
> +		dev->dma_range_map = map;
> +	} else if (map) {
> +		dev_warn(dev,
> +			 "DMA range map was already set, ignoring range map from dt\n");
> +		kfree(map);
> +	}
> +
>   	return 0;
>   }
>   EXPORT_SYMBOL_GPL(of_dma_configure_id);
> 

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 1/2] of: device: Allow DMA range map to be set before of_dma_configure_id
  2021-01-16 14:57   ` Robin Murphy
@ 2021-01-16 17:07     ` Paul Kocialkowski
  -1 siblings, 0 replies; 18+ messages in thread
From: Paul Kocialkowski @ 2021-01-16 17:07 UTC (permalink / raw)
  To: Robin Murphy
  Cc: devicetree, linux-kernel, linux-arm-kernel, Jernej Skrabec,
	Daniel Vetter, Maxime Ripard, Chen-Yu Tsai, Rob Herring,
	Thomas Petazzoni, Frank Rowand

Hi Robin,

Le Sat 16 Jan 21, 14:57, Robin Murphy a écrit :
> On 2021-01-15 17:58, Paul Kocialkowski wrote:
> > A mechanism was recently introduced for the sunxi architecture where
> > the DMA offset for specific devices (under the MBUS) is set by a common
> > driver (sunxi_mbus). This driver calls dma_direct_set_offset to set
> > the device's dma_range_map manually.
> > 
> > However this information was overwritten by of_dma_configure_id, which
> > obtains the map from of_dma_get_range (or keeps it NULL when it fails
> > and the force_dma argument is true, which is the case for platform
> > devices).
> > 
> > As a result, the dma_range_map was always overwritten and the mechanism
> > could not correctly take effect.
> > 
> > This adds a check to ensure that no previous DMA range map is
> > overwritten and prints a warning when the map was already set while
> > also being available from dt. In this case, the map that was already
> > set is kept.
> 
> Hang on, the hard-coded offset is only intended to be installed when there
> *isn't* anything described in DT, in which case of_dma_get_range() should
> always bail out early without touching it anyway. This sounds like
> something's not quite right in the MBUS driver, so I don't think working
> around it in core code is really the right thing to do.

That's right, there is no practical case where the two are in conflict.
The problem that I'm solving here is that dev->dma_range_map is *always*
assigned, even when of_dma_get_range bailed and map still is NULL.

This has the effect of always overwriting what the MBUS driver does
(and leaking its memory too).

> Do you have a case where one of the relevant devices inherits a "dma-ranges"
> via the regular hierarchy without indirecting via an "interconnects"
> reference? Currently you're only checking for the latter, so that would be
> one way things could go awry (although to be a problem, said "dma-ranges"
> would also have to encode something *other* than the appropriate MBUS
> offset, which implies an incorrect or at least inaccurately-structured DT as
> well).

No, I think things are good in that regard. No messed up dt or anything like
that :)

Cheers,

Paul

> Robin.
> 
> > Fixes: b4bdc4fbf8d0 ("soc: sunxi: Deal with the MBUS DMA offsets in a central place")
> > Signed-off-by: Paul Kocialkowski <paul.kocialkowski@bootlin.com>
> > ---
> >   drivers/of/device.c | 9 ++++++++-
> >   1 file changed, 8 insertions(+), 1 deletion(-)
> > 
> > diff --git a/drivers/of/device.c b/drivers/of/device.c
> > index aedfaaafd3e7..db1b8634c2c7 100644
> > --- a/drivers/of/device.c
> > +++ b/drivers/of/device.c
> > @@ -181,7 +181,14 @@ int of_dma_configure_id(struct device *dev, struct device_node *np,
> >   	arch_setup_dma_ops(dev, dma_start, size, iommu, coherent);
> > -	dev->dma_range_map = map;
> > +	if (!dev->dma_range_map) {
> > +		dev->dma_range_map = map;
> > +	} else if (map) {
> > +		dev_warn(dev,
> > +			 "DMA range map was already set, ignoring range map from dt\n");
> > +		kfree(map);
> > +	}
> > +
> >   	return 0;
> >   }
> >   EXPORT_SYMBOL_GPL(of_dma_configure_id);
> > 

-- 
Paul Kocialkowski, Bootlin
Embedded Linux and kernel engineering
https://bootlin.com

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 1/2] of: device: Allow DMA range map to be set before of_dma_configure_id
@ 2021-01-16 17:07     ` Paul Kocialkowski
  0 siblings, 0 replies; 18+ messages in thread
From: Paul Kocialkowski @ 2021-01-16 17:07 UTC (permalink / raw)
  To: Robin Murphy
  Cc: devicetree, Jernej Skrabec, Daniel Vetter, linux-kernel,
	Maxime Ripard, Chen-Yu Tsai, Rob Herring, Thomas Petazzoni,
	Frank Rowand, linux-arm-kernel

Hi Robin,

Le Sat 16 Jan 21, 14:57, Robin Murphy a écrit :
> On 2021-01-15 17:58, Paul Kocialkowski wrote:
> > A mechanism was recently introduced for the sunxi architecture where
> > the DMA offset for specific devices (under the MBUS) is set by a common
> > driver (sunxi_mbus). This driver calls dma_direct_set_offset to set
> > the device's dma_range_map manually.
> > 
> > However this information was overwritten by of_dma_configure_id, which
> > obtains the map from of_dma_get_range (or keeps it NULL when it fails
> > and the force_dma argument is true, which is the case for platform
> > devices).
> > 
> > As a result, the dma_range_map was always overwritten and the mechanism
> > could not correctly take effect.
> > 
> > This adds a check to ensure that no previous DMA range map is
> > overwritten and prints a warning when the map was already set while
> > also being available from dt. In this case, the map that was already
> > set is kept.
> 
> Hang on, the hard-coded offset is only intended to be installed when there
> *isn't* anything described in DT, in which case of_dma_get_range() should
> always bail out early without touching it anyway. This sounds like
> something's not quite right in the MBUS driver, so I don't think working
> around it in core code is really the right thing to do.

That's right, there is no practical case where the two are in conflict.
The problem that I'm solving here is that dev->dma_range_map is *always*
assigned, even when of_dma_get_range bailed and map still is NULL.

This has the effect of always overwriting what the MBUS driver does
(and leaking its memory too).

> Do you have a case where one of the relevant devices inherits a "dma-ranges"
> via the regular hierarchy without indirecting via an "interconnects"
> reference? Currently you're only checking for the latter, so that would be
> one way things could go awry (although to be a problem, said "dma-ranges"
> would also have to encode something *other* than the appropriate MBUS
> offset, which implies an incorrect or at least inaccurately-structured DT as
> well).

No, I think things are good in that regard. No messed up dt or anything like
that :)

Cheers,

Paul

> Robin.
> 
> > Fixes: b4bdc4fbf8d0 ("soc: sunxi: Deal with the MBUS DMA offsets in a central place")
> > Signed-off-by: Paul Kocialkowski <paul.kocialkowski@bootlin.com>
> > ---
> >   drivers/of/device.c | 9 ++++++++-
> >   1 file changed, 8 insertions(+), 1 deletion(-)
> > 
> > diff --git a/drivers/of/device.c b/drivers/of/device.c
> > index aedfaaafd3e7..db1b8634c2c7 100644
> > --- a/drivers/of/device.c
> > +++ b/drivers/of/device.c
> > @@ -181,7 +181,14 @@ int of_dma_configure_id(struct device *dev, struct device_node *np,
> >   	arch_setup_dma_ops(dev, dma_start, size, iommu, coherent);
> > -	dev->dma_range_map = map;
> > +	if (!dev->dma_range_map) {
> > +		dev->dma_range_map = map;
> > +	} else if (map) {
> > +		dev_warn(dev,
> > +			 "DMA range map was already set, ignoring range map from dt\n");
> > +		kfree(map);
> > +	}
> > +
> >   	return 0;
> >   }
> >   EXPORT_SYMBOL_GPL(of_dma_configure_id);
> > 

-- 
Paul Kocialkowski, Bootlin
Embedded Linux and kernel engineering
https://bootlin.com

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 1/2] of: device: Allow DMA range map to be set before of_dma_configure_id
  2021-01-16 17:07     ` Paul Kocialkowski
@ 2021-01-18 13:27       ` Robin Murphy
  -1 siblings, 0 replies; 18+ messages in thread
From: Robin Murphy @ 2021-01-18 13:27 UTC (permalink / raw)
  To: Paul Kocialkowski
  Cc: devicetree, linux-kernel, linux-arm-kernel, Jernej Skrabec,
	Daniel Vetter, Maxime Ripard, Chen-Yu Tsai, Rob Herring,
	Thomas Petazzoni, Frank Rowand

On 2021-01-16 17:07, Paul Kocialkowski wrote:
> Hi Robin,
> 
> Le Sat 16 Jan 21, 14:57, Robin Murphy a écrit :
>> On 2021-01-15 17:58, Paul Kocialkowski wrote:
>>> A mechanism was recently introduced for the sunxi architecture where
>>> the DMA offset for specific devices (under the MBUS) is set by a common
>>> driver (sunxi_mbus). This driver calls dma_direct_set_offset to set
>>> the device's dma_range_map manually.
>>>
>>> However this information was overwritten by of_dma_configure_id, which
>>> obtains the map from of_dma_get_range (or keeps it NULL when it fails
>>> and the force_dma argument is true, which is the case for platform
>>> devices).
>>>
>>> As a result, the dma_range_map was always overwritten and the mechanism
>>> could not correctly take effect.
>>>
>>> This adds a check to ensure that no previous DMA range map is
>>> overwritten and prints a warning when the map was already set while
>>> also being available from dt. In this case, the map that was already
>>> set is kept.
>>
>> Hang on, the hard-coded offset is only intended to be installed when there
>> *isn't* anything described in DT, in which case of_dma_get_range() should
>> always bail out early without touching it anyway. This sounds like
>> something's not quite right in the MBUS driver, so I don't think working
>> around it in core code is really the right thing to do.
> 
> That's right, there is no practical case where the two are in conflict.
> The problem that I'm solving here is that dev->dma_range_map is *always*
> assigned, even when of_dma_get_range bailed and map still is NULL.
> 
> This has the effect of always overwriting what the MBUS driver does
> (and leaking its memory too).

Oh, I should have looked closer at of_dma_configure_id() itself. I was 
assuming that b4bdc4fbf8d0 had been tested and at least *could* work, 
but apparently not :/

Indeed it seems there was a fundamental oversight in e0d072782c73 
("dma-mapping: introduce DMA range map, supplanting dma_pfn_offset"), 
equivalent to the same one I previously made myself with bus_dma_mask 
and fixed in 6778be4e5209 ("of/device: Really only set bus DMA mask when 
appropriate"). I think same simpler fix is the right one for this case 
too, i.e. just move the assignment to dev->dma_range_map up under the 
"if (!ret)" condition. Assigning it this late - after the IOMMU and arch 
setup - looks wrong anyway, even if it isn't currently an issue in 
practice (in principle an IOMMU driver *could* start trying to figure 
out reserved regions around DMA windows for a device as early as its 
.of_xlate callback, even though that's not the intent of the API design).

Luckily dma_range_map hasn't been hooked up in the equivalent ACPI path 
yet, so you're off the hook for fixing that too :)

Cheers,
Robin.

>> Do you have a case where one of the relevant devices inherits a "dma-ranges"
>> via the regular hierarchy without indirecting via an "interconnects"
>> reference? Currently you're only checking for the latter, so that would be
>> one way things could go awry (although to be a problem, said "dma-ranges"
>> would also have to encode something *other* than the appropriate MBUS
>> offset, which implies an incorrect or at least inaccurately-structured DT as
>> well).
> 
> No, I think things are good in that regard. No messed up dt or anything like
> that :)
> 
> Cheers,
> 
> Paul
> 
>> Robin.
>>
>>> Fixes: b4bdc4fbf8d0 ("soc: sunxi: Deal with the MBUS DMA offsets in a central place")
>>> Signed-off-by: Paul Kocialkowski <paul.kocialkowski@bootlin.com>
>>> ---
>>>    drivers/of/device.c | 9 ++++++++-
>>>    1 file changed, 8 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/drivers/of/device.c b/drivers/of/device.c
>>> index aedfaaafd3e7..db1b8634c2c7 100644
>>> --- a/drivers/of/device.c
>>> +++ b/drivers/of/device.c
>>> @@ -181,7 +181,14 @@ int of_dma_configure_id(struct device *dev, struct device_node *np,
>>>    	arch_setup_dma_ops(dev, dma_start, size, iommu, coherent);
>>> -	dev->dma_range_map = map;
>>> +	if (!dev->dma_range_map) {
>>> +		dev->dma_range_map = map;
>>> +	} else if (map) {
>>> +		dev_warn(dev,
>>> +			 "DMA range map was already set, ignoring range map from dt\n");
>>> +		kfree(map);
>>> +	}
>>> +
>>>    	return 0;
>>>    }
>>>    EXPORT_SYMBOL_GPL(of_dma_configure_id);
>>>
> 

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 1/2] of: device: Allow DMA range map to be set before of_dma_configure_id
@ 2021-01-18 13:27       ` Robin Murphy
  0 siblings, 0 replies; 18+ messages in thread
From: Robin Murphy @ 2021-01-18 13:27 UTC (permalink / raw)
  To: Paul Kocialkowski
  Cc: devicetree, Jernej Skrabec, Daniel Vetter, linux-kernel,
	Maxime Ripard, Chen-Yu Tsai, Rob Herring, Thomas Petazzoni,
	Frank Rowand, linux-arm-kernel

On 2021-01-16 17:07, Paul Kocialkowski wrote:
> Hi Robin,
> 
> Le Sat 16 Jan 21, 14:57, Robin Murphy a écrit :
>> On 2021-01-15 17:58, Paul Kocialkowski wrote:
>>> A mechanism was recently introduced for the sunxi architecture where
>>> the DMA offset for specific devices (under the MBUS) is set by a common
>>> driver (sunxi_mbus). This driver calls dma_direct_set_offset to set
>>> the device's dma_range_map manually.
>>>
>>> However this information was overwritten by of_dma_configure_id, which
>>> obtains the map from of_dma_get_range (or keeps it NULL when it fails
>>> and the force_dma argument is true, which is the case for platform
>>> devices).
>>>
>>> As a result, the dma_range_map was always overwritten and the mechanism
>>> could not correctly take effect.
>>>
>>> This adds a check to ensure that no previous DMA range map is
>>> overwritten and prints a warning when the map was already set while
>>> also being available from dt. In this case, the map that was already
>>> set is kept.
>>
>> Hang on, the hard-coded offset is only intended to be installed when there
>> *isn't* anything described in DT, in which case of_dma_get_range() should
>> always bail out early without touching it anyway. This sounds like
>> something's not quite right in the MBUS driver, so I don't think working
>> around it in core code is really the right thing to do.
> 
> That's right, there is no practical case where the two are in conflict.
> The problem that I'm solving here is that dev->dma_range_map is *always*
> assigned, even when of_dma_get_range bailed and map still is NULL.
> 
> This has the effect of always overwriting what the MBUS driver does
> (and leaking its memory too).

Oh, I should have looked closer at of_dma_configure_id() itself. I was 
assuming that b4bdc4fbf8d0 had been tested and at least *could* work, 
but apparently not :/

Indeed it seems there was a fundamental oversight in e0d072782c73 
("dma-mapping: introduce DMA range map, supplanting dma_pfn_offset"), 
equivalent to the same one I previously made myself with bus_dma_mask 
and fixed in 6778be4e5209 ("of/device: Really only set bus DMA mask when 
appropriate"). I think same simpler fix is the right one for this case 
too, i.e. just move the assignment to dev->dma_range_map up under the 
"if (!ret)" condition. Assigning it this late - after the IOMMU and arch 
setup - looks wrong anyway, even if it isn't currently an issue in 
practice (in principle an IOMMU driver *could* start trying to figure 
out reserved regions around DMA windows for a device as early as its 
.of_xlate callback, even though that's not the intent of the API design).

Luckily dma_range_map hasn't been hooked up in the equivalent ACPI path 
yet, so you're off the hook for fixing that too :)

Cheers,
Robin.

>> Do you have a case where one of the relevant devices inherits a "dma-ranges"
>> via the regular hierarchy without indirecting via an "interconnects"
>> reference? Currently you're only checking for the latter, so that would be
>> one way things could go awry (although to be a problem, said "dma-ranges"
>> would also have to encode something *other* than the appropriate MBUS
>> offset, which implies an incorrect or at least inaccurately-structured DT as
>> well).
> 
> No, I think things are good in that regard. No messed up dt or anything like
> that :)
> 
> Cheers,
> 
> Paul
> 
>> Robin.
>>
>>> Fixes: b4bdc4fbf8d0 ("soc: sunxi: Deal with the MBUS DMA offsets in a central place")
>>> Signed-off-by: Paul Kocialkowski <paul.kocialkowski@bootlin.com>
>>> ---
>>>    drivers/of/device.c | 9 ++++++++-
>>>    1 file changed, 8 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/drivers/of/device.c b/drivers/of/device.c
>>> index aedfaaafd3e7..db1b8634c2c7 100644
>>> --- a/drivers/of/device.c
>>> +++ b/drivers/of/device.c
>>> @@ -181,7 +181,14 @@ int of_dma_configure_id(struct device *dev, struct device_node *np,
>>>    	arch_setup_dma_ops(dev, dma_start, size, iommu, coherent);
>>> -	dev->dma_range_map = map;
>>> +	if (!dev->dma_range_map) {
>>> +		dev->dma_range_map = map;
>>> +	} else if (map) {
>>> +		dev_warn(dev,
>>> +			 "DMA range map was already set, ignoring range map from dt\n");
>>> +		kfree(map);
>>> +	}
>>> +
>>>    	return 0;
>>>    }
>>>    EXPORT_SYMBOL_GPL(of_dma_configure_id);
>>>
> 

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 1/2] of: device: Allow DMA range map to be set before of_dma_configure_id
  2021-01-18 13:27       ` Robin Murphy
@ 2021-01-19  9:04         ` Paul Kocialkowski
  -1 siblings, 0 replies; 18+ messages in thread
From: Paul Kocialkowski @ 2021-01-19  9:04 UTC (permalink / raw)
  To: Robin Murphy
  Cc: devicetree, linux-kernel, linux-arm-kernel, Jernej Skrabec,
	Daniel Vetter, Maxime Ripard, Chen-Yu Tsai, Rob Herring,
	Thomas Petazzoni, Frank Rowand

[-- Attachment #1: Type: text/plain, Size: 4948 bytes --]

Hi Robin,

On Mon 18 Jan 21, 13:27, Robin Murphy wrote:
> On 2021-01-16 17:07, Paul Kocialkowski wrote:
> > Hi Robin,
> > 
> > Le Sat 16 Jan 21, 14:57, Robin Murphy a écrit :
> > > On 2021-01-15 17:58, Paul Kocialkowski wrote:
> > > > A mechanism was recently introduced for the sunxi architecture where
> > > > the DMA offset for specific devices (under the MBUS) is set by a common
> > > > driver (sunxi_mbus). This driver calls dma_direct_set_offset to set
> > > > the device's dma_range_map manually.
> > > > 
> > > > However this information was overwritten by of_dma_configure_id, which
> > > > obtains the map from of_dma_get_range (or keeps it NULL when it fails
> > > > and the force_dma argument is true, which is the case for platform
> > > > devices).
> > > > 
> > > > As a result, the dma_range_map was always overwritten and the mechanism
> > > > could not correctly take effect.
> > > > 
> > > > This adds a check to ensure that no previous DMA range map is
> > > > overwritten and prints a warning when the map was already set while
> > > > also being available from dt. In this case, the map that was already
> > > > set is kept.
> > > 
> > > Hang on, the hard-coded offset is only intended to be installed when there
> > > *isn't* anything described in DT, in which case of_dma_get_range() should
> > > always bail out early without touching it anyway. This sounds like
> > > something's not quite right in the MBUS driver, so I don't think working
> > > around it in core code is really the right thing to do.
> > 
> > That's right, there is no practical case where the two are in conflict.
> > The problem that I'm solving here is that dev->dma_range_map is *always*
> > assigned, even when of_dma_get_range bailed and map still is NULL.
> > 
> > This has the effect of always overwriting what the MBUS driver does
> > (and leaking its memory too).
> 
> Oh, I should have looked closer at of_dma_configure_id() itself. I was
> assuming that b4bdc4fbf8d0 had been tested and at least *could* work, but
> apparently not :/
> 
> Indeed it seems there was a fundamental oversight in e0d072782c73
> ("dma-mapping: introduce DMA range map, supplanting dma_pfn_offset"),
> equivalent to the same one I previously made myself with bus_dma_mask and
> fixed in 6778be4e5209 ("of/device: Really only set bus DMA mask when
> appropriate"). I think same simpler fix is the right one for this case too,
> i.e. just move the assignment to dev->dma_range_map up under the "if (!ret)"
> condition. Assigning it this late - after the IOMMU and arch setup - looks
> wrong anyway, even if it isn't currently an issue in practice (in principle
> an IOMMU driver *could* start trying to figure out reserved regions around
> DMA windows for a device as early as its .of_xlate callback, even though
> that's not the intent of the API design).

Okay sounds good, I'll resend a patch with the assignment under if (!ret)!

> Luckily dma_range_map hasn't been hooked up in the equivalent ACPI path yet,
> so you're off the hook for fixing that too :)

Good for me :)

Cheers,

Paul

> > > Do you have a case where one of the relevant devices inherits a "dma-ranges"
> > > via the regular hierarchy without indirecting via an "interconnects"
> > > reference? Currently you're only checking for the latter, so that would be
> > > one way things could go awry (although to be a problem, said "dma-ranges"
> > > would also have to encode something *other* than the appropriate MBUS
> > > offset, which implies an incorrect or at least inaccurately-structured DT as
> > > well).
> > 
> > No, I think things are good in that regard. No messed up dt or anything like
> > that :)
> > 
> > Cheers,
> > 
> > Paul
> > 
> > > Robin.
> > > 
> > > > Fixes: b4bdc4fbf8d0 ("soc: sunxi: Deal with the MBUS DMA offsets in a central place")
> > > > Signed-off-by: Paul Kocialkowski <paul.kocialkowski@bootlin.com>
> > > > ---
> > > >    drivers/of/device.c | 9 ++++++++-
> > > >    1 file changed, 8 insertions(+), 1 deletion(-)
> > > > 
> > > > diff --git a/drivers/of/device.c b/drivers/of/device.c
> > > > index aedfaaafd3e7..db1b8634c2c7 100644
> > > > --- a/drivers/of/device.c
> > > > +++ b/drivers/of/device.c
> > > > @@ -181,7 +181,14 @@ int of_dma_configure_id(struct device *dev, struct device_node *np,
> > > >    	arch_setup_dma_ops(dev, dma_start, size, iommu, coherent);
> > > > -	dev->dma_range_map = map;
> > > > +	if (!dev->dma_range_map) {
> > > > +		dev->dma_range_map = map;
> > > > +	} else if (map) {
> > > > +		dev_warn(dev,
> > > > +			 "DMA range map was already set, ignoring range map from dt\n");
> > > > +		kfree(map);
> > > > +	}
> > > > +
> > > >    	return 0;
> > > >    }
> > > >    EXPORT_SYMBOL_GPL(of_dma_configure_id);
> > > > 
> > 

-- 
Paul Kocialkowski, Bootlin
Embedded Linux and kernel engineering
https://bootlin.com

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 1/2] of: device: Allow DMA range map to be set before of_dma_configure_id
@ 2021-01-19  9:04         ` Paul Kocialkowski
  0 siblings, 0 replies; 18+ messages in thread
From: Paul Kocialkowski @ 2021-01-19  9:04 UTC (permalink / raw)
  To: Robin Murphy
  Cc: devicetree, Jernej Skrabec, Daniel Vetter, linux-kernel,
	Maxime Ripard, Chen-Yu Tsai, Rob Herring, Thomas Petazzoni,
	Frank Rowand, linux-arm-kernel


[-- Attachment #1.1: Type: text/plain, Size: 4948 bytes --]

Hi Robin,

On Mon 18 Jan 21, 13:27, Robin Murphy wrote:
> On 2021-01-16 17:07, Paul Kocialkowski wrote:
> > Hi Robin,
> > 
> > Le Sat 16 Jan 21, 14:57, Robin Murphy a écrit :
> > > On 2021-01-15 17:58, Paul Kocialkowski wrote:
> > > > A mechanism was recently introduced for the sunxi architecture where
> > > > the DMA offset for specific devices (under the MBUS) is set by a common
> > > > driver (sunxi_mbus). This driver calls dma_direct_set_offset to set
> > > > the device's dma_range_map manually.
> > > > 
> > > > However this information was overwritten by of_dma_configure_id, which
> > > > obtains the map from of_dma_get_range (or keeps it NULL when it fails
> > > > and the force_dma argument is true, which is the case for platform
> > > > devices).
> > > > 
> > > > As a result, the dma_range_map was always overwritten and the mechanism
> > > > could not correctly take effect.
> > > > 
> > > > This adds a check to ensure that no previous DMA range map is
> > > > overwritten and prints a warning when the map was already set while
> > > > also being available from dt. In this case, the map that was already
> > > > set is kept.
> > > 
> > > Hang on, the hard-coded offset is only intended to be installed when there
> > > *isn't* anything described in DT, in which case of_dma_get_range() should
> > > always bail out early without touching it anyway. This sounds like
> > > something's not quite right in the MBUS driver, so I don't think working
> > > around it in core code is really the right thing to do.
> > 
> > That's right, there is no practical case where the two are in conflict.
> > The problem that I'm solving here is that dev->dma_range_map is *always*
> > assigned, even when of_dma_get_range bailed and map still is NULL.
> > 
> > This has the effect of always overwriting what the MBUS driver does
> > (and leaking its memory too).
> 
> Oh, I should have looked closer at of_dma_configure_id() itself. I was
> assuming that b4bdc4fbf8d0 had been tested and at least *could* work, but
> apparently not :/
> 
> Indeed it seems there was a fundamental oversight in e0d072782c73
> ("dma-mapping: introduce DMA range map, supplanting dma_pfn_offset"),
> equivalent to the same one I previously made myself with bus_dma_mask and
> fixed in 6778be4e5209 ("of/device: Really only set bus DMA mask when
> appropriate"). I think same simpler fix is the right one for this case too,
> i.e. just move the assignment to dev->dma_range_map up under the "if (!ret)"
> condition. Assigning it this late - after the IOMMU and arch setup - looks
> wrong anyway, even if it isn't currently an issue in practice (in principle
> an IOMMU driver *could* start trying to figure out reserved regions around
> DMA windows for a device as early as its .of_xlate callback, even though
> that's not the intent of the API design).

Okay sounds good, I'll resend a patch with the assignment under if (!ret)!

> Luckily dma_range_map hasn't been hooked up in the equivalent ACPI path yet,
> so you're off the hook for fixing that too :)

Good for me :)

Cheers,

Paul

> > > Do you have a case where one of the relevant devices inherits a "dma-ranges"
> > > via the regular hierarchy without indirecting via an "interconnects"
> > > reference? Currently you're only checking for the latter, so that would be
> > > one way things could go awry (although to be a problem, said "dma-ranges"
> > > would also have to encode something *other* than the appropriate MBUS
> > > offset, which implies an incorrect or at least inaccurately-structured DT as
> > > well).
> > 
> > No, I think things are good in that regard. No messed up dt or anything like
> > that :)
> > 
> > Cheers,
> > 
> > Paul
> > 
> > > Robin.
> > > 
> > > > Fixes: b4bdc4fbf8d0 ("soc: sunxi: Deal with the MBUS DMA offsets in a central place")
> > > > Signed-off-by: Paul Kocialkowski <paul.kocialkowski@bootlin.com>
> > > > ---
> > > >    drivers/of/device.c | 9 ++++++++-
> > > >    1 file changed, 8 insertions(+), 1 deletion(-)
> > > > 
> > > > diff --git a/drivers/of/device.c b/drivers/of/device.c
> > > > index aedfaaafd3e7..db1b8634c2c7 100644
> > > > --- a/drivers/of/device.c
> > > > +++ b/drivers/of/device.c
> > > > @@ -181,7 +181,14 @@ int of_dma_configure_id(struct device *dev, struct device_node *np,
> > > >    	arch_setup_dma_ops(dev, dma_start, size, iommu, coherent);
> > > > -	dev->dma_range_map = map;
> > > > +	if (!dev->dma_range_map) {
> > > > +		dev->dma_range_map = map;
> > > > +	} else if (map) {
> > > > +		dev_warn(dev,
> > > > +			 "DMA range map was already set, ignoring range map from dt\n");
> > > > +		kfree(map);
> > > > +	}
> > > > +
> > > >    	return 0;
> > > >    }
> > > >    EXPORT_SYMBOL_GPL(of_dma_configure_id);
> > > > 
> > 

-- 
Paul Kocialkowski, Bootlin
Embedded Linux and kernel engineering
https://bootlin.com

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

[-- Attachment #2: Type: text/plain, Size: 176 bytes --]

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 1/2] of: device: Allow DMA range map to be set before of_dma_configure_id
  2021-01-15 17:58 ` Paul Kocialkowski
@ 2021-01-27 13:01   ` Paul Kocialkowski
  -1 siblings, 0 replies; 18+ messages in thread
From: Paul Kocialkowski @ 2021-01-27 13:01 UTC (permalink / raw)
  To: devicetree, linux-kernel, linux-arm-kernel
  Cc: Rob Herring, Frank Rowand, Maxime Ripard, Chen-Yu Tsai,
	Jernej Skrabec, Daniel Vetter, Thomas Petazzoni

[-- Attachment #1: Type: text/plain, Size: 2066 bytes --]

Hi,

On Fri 15 Jan 21, 18:58, Paul Kocialkowski wrote:
> A mechanism was recently introduced for the sunxi architecture where
> the DMA offset for specific devices (under the MBUS) is set by a common
> driver (sunxi_mbus). This driver calls dma_direct_set_offset to set
> the device's dma_range_map manually.
> 
> However this information was overwritten by of_dma_configure_id, which
> obtains the map from of_dma_get_range (or keeps it NULL when it fails
> and the force_dma argument is true, which is the case for platform
> devices).
> 
> As a result, the dma_range_map was always overwritten and the mechanism
> could not correctly take effect.
> 
> This adds a check to ensure that no previous DMA range map is
> overwritten and prints a warning when the map was already set while
> also being available from dt. In this case, the map that was already
> set is kept.

FYI this patch has been superseded by the following:
https://patchwork.kernel.org/project/linux-mediatek/patch/20210119105203.15530-1-yong.wu@mediatek.com/

Paul

> Fixes: b4bdc4fbf8d0 ("soc: sunxi: Deal with the MBUS DMA offsets in a central place")
> Signed-off-by: Paul Kocialkowski <paul.kocialkowski@bootlin.com>
> ---
>  drivers/of/device.c | 9 ++++++++-
>  1 file changed, 8 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/of/device.c b/drivers/of/device.c
> index aedfaaafd3e7..db1b8634c2c7 100644
> --- a/drivers/of/device.c
> +++ b/drivers/of/device.c
> @@ -181,7 +181,14 @@ int of_dma_configure_id(struct device *dev, struct device_node *np,
>  
>  	arch_setup_dma_ops(dev, dma_start, size, iommu, coherent);
>  
> -	dev->dma_range_map = map;
> +	if (!dev->dma_range_map) {
> +		dev->dma_range_map = map;
> +	} else if (map) {
> +		dev_warn(dev,
> +			 "DMA range map was already set, ignoring range map from dt\n");
> +		kfree(map);
> +	}
> +
>  	return 0;
>  }
>  EXPORT_SYMBOL_GPL(of_dma_configure_id);
> -- 
> 2.30.0
> 

-- 
Paul Kocialkowski, Bootlin
Embedded Linux and kernel engineering
https://bootlin.com

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 1/2] of: device: Allow DMA range map to be set before of_dma_configure_id
@ 2021-01-27 13:01   ` Paul Kocialkowski
  0 siblings, 0 replies; 18+ messages in thread
From: Paul Kocialkowski @ 2021-01-27 13:01 UTC (permalink / raw)
  To: devicetree, linux-kernel, linux-arm-kernel
  Cc: Jernej Skrabec, Daniel Vetter, Maxime Ripard, Chen-Yu Tsai,
	Rob Herring, Thomas Petazzoni, Frank Rowand


[-- Attachment #1.1: Type: text/plain, Size: 2066 bytes --]

Hi,

On Fri 15 Jan 21, 18:58, Paul Kocialkowski wrote:
> A mechanism was recently introduced for the sunxi architecture where
> the DMA offset for specific devices (under the MBUS) is set by a common
> driver (sunxi_mbus). This driver calls dma_direct_set_offset to set
> the device's dma_range_map manually.
> 
> However this information was overwritten by of_dma_configure_id, which
> obtains the map from of_dma_get_range (or keeps it NULL when it fails
> and the force_dma argument is true, which is the case for platform
> devices).
> 
> As a result, the dma_range_map was always overwritten and the mechanism
> could not correctly take effect.
> 
> This adds a check to ensure that no previous DMA range map is
> overwritten and prints a warning when the map was already set while
> also being available from dt. In this case, the map that was already
> set is kept.

FYI this patch has been superseded by the following:
https://patchwork.kernel.org/project/linux-mediatek/patch/20210119105203.15530-1-yong.wu@mediatek.com/

Paul

> Fixes: b4bdc4fbf8d0 ("soc: sunxi: Deal with the MBUS DMA offsets in a central place")
> Signed-off-by: Paul Kocialkowski <paul.kocialkowski@bootlin.com>
> ---
>  drivers/of/device.c | 9 ++++++++-
>  1 file changed, 8 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/of/device.c b/drivers/of/device.c
> index aedfaaafd3e7..db1b8634c2c7 100644
> --- a/drivers/of/device.c
> +++ b/drivers/of/device.c
> @@ -181,7 +181,14 @@ int of_dma_configure_id(struct device *dev, struct device_node *np,
>  
>  	arch_setup_dma_ops(dev, dma_start, size, iommu, coherent);
>  
> -	dev->dma_range_map = map;
> +	if (!dev->dma_range_map) {
> +		dev->dma_range_map = map;
> +	} else if (map) {
> +		dev_warn(dev,
> +			 "DMA range map was already set, ignoring range map from dt\n");
> +		kfree(map);
> +	}
> +
>  	return 0;
>  }
>  EXPORT_SYMBOL_GPL(of_dma_configure_id);
> -- 
> 2.30.0
> 

-- 
Paul Kocialkowski, Bootlin
Embedded Linux and kernel engineering
https://bootlin.com

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

[-- Attachment #2: Type: text/plain, Size: 176 bytes --]

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 2/2] soc: sunxi: mbus: Remove DE2 display engine compatibles
  2021-01-15 17:58   ` Paul Kocialkowski
@ 2021-01-27 13:03     ` Paul Kocialkowski
  -1 siblings, 0 replies; 18+ messages in thread
From: Paul Kocialkowski @ 2021-01-27 13:03 UTC (permalink / raw)
  To: devicetree, linux-kernel, linux-arm-kernel
  Cc: Rob Herring, Frank Rowand, Maxime Ripard, Chen-Yu Tsai,
	Jernej Skrabec, Daniel Vetter, Thomas Petazzoni

[-- Attachment #1: Type: text/plain, Size: 1701 bytes --]

Hi,

On Fri 15 Jan 21, 18:58, Paul Kocialkowski wrote:
> The DE2 display engine hardware takes physical addresses that do not
> need PHYS_BASE subtracted. As a result, they should not be present
> on the mbus driver match list. Remove them.
> 
> This was tested on the A83T, along with the patch allowing the DMA
> range map to be non-NULL and restores a working display.

Could we get this merged ASAP (in this RC cycle), hopefully with the patch
that superseded 1/2 from this series so that we don't end up with either
CSI or DE2 broken in the next release?

Cheers,

Paul

> Fixes: b4bdc4fbf8d0 ("soc: sunxi: Deal with the MBUS DMA offsets in a central place")
> Signed-off-by: Paul Kocialkowski <paul.kocialkowski@bootlin.com>
> ---
>  drivers/soc/sunxi/sunxi_mbus.c | 5 -----
>  1 file changed, 5 deletions(-)
> 
> diff --git a/drivers/soc/sunxi/sunxi_mbus.c b/drivers/soc/sunxi/sunxi_mbus.c
> index e9925c8487d7..d90e4a264b6f 100644
> --- a/drivers/soc/sunxi/sunxi_mbus.c
> +++ b/drivers/soc/sunxi/sunxi_mbus.c
> @@ -23,12 +23,7 @@ static const char * const sunxi_mbus_devices[] = {
>  	"allwinner,sun7i-a20-display-engine",
>  	"allwinner,sun8i-a23-display-engine",
>  	"allwinner,sun8i-a33-display-engine",
> -	"allwinner,sun8i-a83t-display-engine",
> -	"allwinner,sun8i-h3-display-engine",
> -	"allwinner,sun8i-r40-display-engine",
> -	"allwinner,sun8i-v3s-display-engine",
>  	"allwinner,sun9i-a80-display-engine",
> -	"allwinner,sun50i-a64-display-engine",
>  
>  	/*
>  	 * And now we have the regular devices connected to the MBUS
> -- 
> 2.30.0
> 

-- 
Paul Kocialkowski, Bootlin
Embedded Linux and kernel engineering
https://bootlin.com

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 2/2] soc: sunxi: mbus: Remove DE2 display engine compatibles
@ 2021-01-27 13:03     ` Paul Kocialkowski
  0 siblings, 0 replies; 18+ messages in thread
From: Paul Kocialkowski @ 2021-01-27 13:03 UTC (permalink / raw)
  To: devicetree, linux-kernel, linux-arm-kernel
  Cc: Jernej Skrabec, Daniel Vetter, Maxime Ripard, Chen-Yu Tsai,
	Rob Herring, Thomas Petazzoni, Frank Rowand


[-- Attachment #1.1: Type: text/plain, Size: 1701 bytes --]

Hi,

On Fri 15 Jan 21, 18:58, Paul Kocialkowski wrote:
> The DE2 display engine hardware takes physical addresses that do not
> need PHYS_BASE subtracted. As a result, they should not be present
> on the mbus driver match list. Remove them.
> 
> This was tested on the A83T, along with the patch allowing the DMA
> range map to be non-NULL and restores a working display.

Could we get this merged ASAP (in this RC cycle), hopefully with the patch
that superseded 1/2 from this series so that we don't end up with either
CSI or DE2 broken in the next release?

Cheers,

Paul

> Fixes: b4bdc4fbf8d0 ("soc: sunxi: Deal with the MBUS DMA offsets in a central place")
> Signed-off-by: Paul Kocialkowski <paul.kocialkowski@bootlin.com>
> ---
>  drivers/soc/sunxi/sunxi_mbus.c | 5 -----
>  1 file changed, 5 deletions(-)
> 
> diff --git a/drivers/soc/sunxi/sunxi_mbus.c b/drivers/soc/sunxi/sunxi_mbus.c
> index e9925c8487d7..d90e4a264b6f 100644
> --- a/drivers/soc/sunxi/sunxi_mbus.c
> +++ b/drivers/soc/sunxi/sunxi_mbus.c
> @@ -23,12 +23,7 @@ static const char * const sunxi_mbus_devices[] = {
>  	"allwinner,sun7i-a20-display-engine",
>  	"allwinner,sun8i-a23-display-engine",
>  	"allwinner,sun8i-a33-display-engine",
> -	"allwinner,sun8i-a83t-display-engine",
> -	"allwinner,sun8i-h3-display-engine",
> -	"allwinner,sun8i-r40-display-engine",
> -	"allwinner,sun8i-v3s-display-engine",
>  	"allwinner,sun9i-a80-display-engine",
> -	"allwinner,sun50i-a64-display-engine",
>  
>  	/*
>  	 * And now we have the regular devices connected to the MBUS
> -- 
> 2.30.0
> 

-- 
Paul Kocialkowski, Bootlin
Embedded Linux and kernel engineering
https://bootlin.com

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

[-- Attachment #2: Type: text/plain, Size: 176 bytes --]

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 2/2] soc: sunxi: mbus: Remove DE2 display engine compatibles
  2021-01-27 13:03     ` Paul Kocialkowski
@ 2021-01-28 10:23       ` Maxime Ripard
  -1 siblings, 0 replies; 18+ messages in thread
From: Maxime Ripard @ 2021-01-28 10:23 UTC (permalink / raw)
  To: Paul Kocialkowski
  Cc: devicetree, linux-kernel, linux-arm-kernel, Rob Herring,
	Frank Rowand, Chen-Yu Tsai, Jernej Skrabec, Daniel Vetter,
	Thomas Petazzoni

[-- Attachment #1: Type: text/plain, Size: 698 bytes --]

On Wed, Jan 27, 2021 at 02:03:03PM +0100, Paul Kocialkowski wrote:
> Hi,
> 
> On Fri 15 Jan 21, 18:58, Paul Kocialkowski wrote:
> > The DE2 display engine hardware takes physical addresses that do not
> > need PHYS_BASE subtracted. As a result, they should not be present
> > on the mbus driver match list. Remove them.
> > 
> > This was tested on the A83T, along with the patch allowing the DMA
> > range map to be non-NULL and restores a working display.
> 
> Could we get this merged ASAP (in this RC cycle), hopefully with the patch
> that superseded 1/2 from this series so that we don't end up with either
> CSI or DE2 broken in the next release?

I just applied it

Maxime

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 2/2] soc: sunxi: mbus: Remove DE2 display engine compatibles
@ 2021-01-28 10:23       ` Maxime Ripard
  0 siblings, 0 replies; 18+ messages in thread
From: Maxime Ripard @ 2021-01-28 10:23 UTC (permalink / raw)
  To: Paul Kocialkowski
  Cc: devicetree, Jernej Skrabec, Daniel Vetter, linux-kernel,
	Chen-Yu Tsai, Rob Herring, Thomas Petazzoni, Frank Rowand,
	linux-arm-kernel


[-- Attachment #1.1: Type: text/plain, Size: 698 bytes --]

On Wed, Jan 27, 2021 at 02:03:03PM +0100, Paul Kocialkowski wrote:
> Hi,
> 
> On Fri 15 Jan 21, 18:58, Paul Kocialkowski wrote:
> > The DE2 display engine hardware takes physical addresses that do not
> > need PHYS_BASE subtracted. As a result, they should not be present
> > on the mbus driver match list. Remove them.
> > 
> > This was tested on the A83T, along with the patch allowing the DMA
> > range map to be non-NULL and restores a working display.
> 
> Could we get this merged ASAP (in this RC cycle), hopefully with the patch
> that superseded 1/2 from this series so that we don't end up with either
> CSI or DE2 broken in the next release?

I just applied it

Maxime

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

[-- Attachment #2: Type: text/plain, Size: 176 bytes --]

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2021-01-28 10:26 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-15 17:58 [PATCH 1/2] of: device: Allow DMA range map to be set before of_dma_configure_id Paul Kocialkowski
2021-01-15 17:58 ` Paul Kocialkowski
2021-01-15 17:58 ` [PATCH 2/2] soc: sunxi: mbus: Remove DE2 display engine compatibles Paul Kocialkowski
2021-01-15 17:58   ` Paul Kocialkowski
2021-01-27 13:03   ` Paul Kocialkowski
2021-01-27 13:03     ` Paul Kocialkowski
2021-01-28 10:23     ` Maxime Ripard
2021-01-28 10:23       ` Maxime Ripard
2021-01-16 14:57 ` [PATCH 1/2] of: device: Allow DMA range map to be set before of_dma_configure_id Robin Murphy
2021-01-16 14:57   ` Robin Murphy
2021-01-16 17:07   ` Paul Kocialkowski
2021-01-16 17:07     ` Paul Kocialkowski
2021-01-18 13:27     ` Robin Murphy
2021-01-18 13:27       ` Robin Murphy
2021-01-19  9:04       ` Paul Kocialkowski
2021-01-19  9:04         ` Paul Kocialkowski
2021-01-27 13:01 ` Paul Kocialkowski
2021-01-27 13:01   ` Paul Kocialkowski

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.