Re: [PATCH RFC 09/12] of: populate new device_d::dma_coherent attribute

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello Sascha,

(apologies for the late answer. Device was only debricked recently).

On 27.02.23 11:41, Sascha Hauer wrote:
>> +		coherent = dev_is_dma_coherent(dev);
>> +		if (coherent >= 0)
>> +			printf("DMA Coherent: %s\n", coherent ? "true" : "false");
> 
> '>=' doesn't seem to be quite right here.

Negative error code means here that it's unknown whether device is coherent or not.
I have reworked this for v2 to make dev_is_dma_coherent return a boolean.

>> +	/*! This particular device is dma coherent, even if the
>> +         * architecture supports non-coherent devices.
>> +	 */
>> +#ifdef CONFIG_OF_DMA_COHERENCY
>> +	bool dma_coherent:1;
>> +#endif
> 
> I think this patch could be easier when we add the dma_coherent field
> unconditionally.

There's an overhead to determining coherency from the DT, which I would like to
skip if we don't require that support, because all devices are either coherent
or aren't. This is still the case in v2, but dma_coherent is now defined
unconditionally with a DEV_DMA_COHERENCY_DEFAULT value if no OF walk happens.

>> +static inline int dev_is_dma_coherent(struct device *dev)
>> +{
>> +	if (!dev_of_node(dev))
>> +		return -EINVAL;
>> +
>> +	return __dev_is_dma_coherent(dev);
>> +}
> 
> This should return bool. Either a device is DMA coherent or not.

Or we don't know, but in that case we can fall back to the architecture
default. Fixed in v2.

> 
> You seem to assume that a device is not cache coherent when you don't
> know:
> 
> -       dma_sync_single_for_device(addr, size, dir);
> +       if (dev_is_dma_coherent(dev) <= 0)
> +               dma_sync_single_for_device(addr, size, dir);

Yes, but when printing the attribute in devinfo, I didn't want to print

DMA-Coherent: false

when actually we don't know. For v2, I only print it now when the value
differs from the default for non-OF devices.

> This assumption seems to make sense as an unnecessary cache synchronisation
> shouldn't hurt, right?

It hurts when the device turns out to be coherent. In that case, the device
may have written to the cache and we invalidate the cache thinking that
the device has written to memory. With v2 and dev_is_dma_coherent becoming
a boolean, the code is now much more readable IMO.

Thanks for the review.

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





[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux