mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: Sascha Hauer <s.hauer@pengutronix.de>
Cc: barebox@lists.infradead.org
Subject: Re: [PATCH master] dma: correctly honour dma-noncoherent device tree property
Date: Tue, 26 Mar 2024 18:32:23 +0100	[thread overview]
Message-ID: <0de04927-a9a6-44b3-82f1-7a60d1e46bbf@pengutronix.de> (raw)
In-Reply-To: <ZgKkaT6jNha92DHu@pengutronix.de>

On 26.03.24 11:33, Sascha Hauer wrote:
> On Fri, Mar 22, 2024 at 03:24:24PM +0100, Ahmad Fatoum wrote:
>> Most barebox platforms are either completely cache-coherent with respect to
>> DMA or completely non-coherent. To avoid having to walk the device tree for
>> non-existent dma-coherent and dma-noncohrent properties, barebox thus
>> only does this when CONFIG_OF_DMA_COHERENCY is selected.
>>
>> CONFIG_OF_DMA_COHERENCY is to be selected by platforms that have mixed
>> coherency for DMA masters. Forgetting to select this option can be
>> annoying to debug, which is why devinfo will inform the user of default
>> DMA coherency assignments:
>>
>>   DMA Coherent: false (default)
>>
>> In order to allow devinfo to differentiate implicit default and explicit
>> device tree DMA coherency configuration, the struct device::dma_coherent
>> member is not of boolean type, but Instead an enumeration that besides
>> coherent and non-coherent also encodes a DEV_DMA_COHERENCE_DEFAULT state.
>>
>> In practice though, a boolean was saved in this dma_coherent member,
>> leading to any dma-noncoherent property being ignored and the default
>> coherency setting being taken for the node.
>>
>> By fixing the type confusion, we restore working Ethernet on the
>> StarFive JH7100, which is the only SoC we currently support that
>> requires /soc/dma-noncohrent to be set for proper operation of its DMA
>> masters.
>>
>> Fixes: fbdea8fd54fe ("of: populate new device_d::dma_coherent attribute")
>> Reported-by: Antony Pavlov <antonynpavlov@gmail.com>
>> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
>> ---
>>  drivers/of/platform.c | 34 +++++++++++++++++++++++-----------
>>  1 file changed, 23 insertions(+), 11 deletions(-)
>>
>> diff --git a/drivers/of/platform.c b/drivers/of/platform.c
>> index ec1482b27797..e2c252b1ffee 100644
>> --- a/drivers/of/platform.c
>> +++ b/drivers/of/platform.c
>> @@ -90,6 +90,21 @@ static struct device_node *of_get_next_dma_parent(const struct device_node *np)
>>  	return args.np;
>>  }
>>  
>> +static enum dev_dma_coherence of_dma_get_coherence(struct device_node *node)
>> +{
>> +	if (IS_ENABLED(CONFIG_OF_DMA_COHERENCY)) {
>> +		while (node) {
>> +			if (of_property_read_bool(node, "dma-coherent"))
>> +				return DEV_DMA_COHERENT;
>> +			if (of_property_read_bool(node, "dma-noncoherent"))
>> +				return DEV_DMA_NON_COHERENT;
>> +			node = of_get_next_dma_parent(node);
>> +		}
>> +	}
>> +
>> +	return DEV_DMA_COHERENCE_DEFAULT;
>> +}
>> +
>>  /**
>>   * of_dma_is_coherent - Check if device is coherent
>>   * @np:	device node
>> @@ -101,17 +116,14 @@ static struct device_node *of_get_next_dma_parent(const struct device_node *np)
>>   */
>>  bool of_dma_is_coherent(struct device_node *node)
>>  {
>> -	if (IS_ENABLED(CONFIG_OF_DMA_COHERENCY)) {
>> -		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);
>> -		}
>> +	switch (of_dma_get_coherence(node)) {
>> +	case DEV_DMA_COHERENT:
>> +		return true;
>> +	case DEV_DMA_NON_COHERENT:
>> +		return false;
>> +	case DEV_DMA_COHERENCE_DEFAULT:
>> +		return IS_ENABLED(CONFIG_ARCH_DMA_DEFAULT_COHERENT);
>>  	}
>> -
>> -	return IS_ENABLED(CONFIG_ARCH_DMA_DEFAULT_COHERENT);
>>  }
> 
> This brings us:
> 
> drivers/of/platform.c: In function 'of_dma_is_coherent':
> drivers/of/platform.c:127:1: warning: control reaches end of non-void function [-Wreturn-type]
> 
> what shall we return in the default case? also
> IS_ENABLED(CONFIG_ARCH_DMA_DEFAULT_COHERENT)?

Yes. Either that or BUG()/__builtin_unreachable();

Thanks,
Ahmad

> 
> Sascha
> 

-- 
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 |




      reply	other threads:[~2024-03-26 17:33 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-22 14:24 Ahmad Fatoum
2024-03-25  9:59 ` Sascha Hauer
2024-03-26 10:33 ` Sascha Hauer
2024-03-26 17:32   ` Ahmad Fatoum [this message]

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=0de04927-a9a6-44b3-82f1-7a60d1e46bbf@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=s.hauer@pengutronix.de \
    /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