Re: [RFC PATCH 1/3] dma-mapping: introduce a new dma api dma_addr_to_phys_addr()

From: Laurentiu Tudor
Date: Tue Oct 22 2019 - 09:53:21 EST



On 22.10.2019 16:25, Robin Murphy wrote:
> On 22/10/2019 13:55, Laurentiu Tudor wrote:
>> From: Laurentiu Tudor <laurentiu.tudor@xxxxxxx>
>>
>> Introduce a new dma map op called dma_addr_to_phys_addr() that converts
>> a dma address to the physical address backing it up and add wrapper for
>> it.
>
> I'd really love it if there was a name which could encapsulate that this
> is *only* for extreme special cases of constrained descriptors/pagetable
> entries/etc. where there's simply no practical way to keep track of a
> CPU address alongside the DMA address, and the only option is this
> potentially-arbitrarily-complex operation (I mean, on some systems it
> may end up taking locks and poking hardware).
>
> Either way it's tricky - much as I don't like adding an interface which
> is ripe for drivers to misuse, I also really don't want hacks like
> bdf95923086f shoved into other APIs to compensate, so on balance I'd
> probably consider this proposal ever so slightly the lesser evil.
>
>> Signed-off-by: Laurentiu Tudor <laurentiu.tudor@xxxxxxx>
>> ---
>> Â include/linux/dma-mapping.h | 21 +++++++++++++++++++++
>> Â 1 file changed, 21 insertions(+)
>>
>> diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
>> index 4a1c4fca475a..5965d159c9a9 100644
>> --- a/include/linux/dma-mapping.h
>> +++ b/include/linux/dma-mapping.h
>> @@ -132,6 +132,8 @@ struct dma_map_ops {
>> ÂÂÂÂÂ u64 (*get_required_mask)(struct device *dev);
>> ÂÂÂÂÂ size_t (*max_mapping_size)(struct device *dev);
>> ÂÂÂÂÂ unsigned long (*get_merge_boundary)(struct device *dev);
>> +ÂÂÂ phys_addr_t (*dma_addr_to_phys_addr)(struct device *dev,
>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ dma_addr_t dma_handle);
>
> I'd be inclined to name the internal callback something a bit snappier
> like .get_phys_addr.

Alright. Want me to also rename the wrapper to something like
dma_get_phys_addr()? Sounds a bit nicer to me.

>> Â };
>> Â #define DMA_MAPPING_ERRORÂÂÂÂÂÂÂ (~(dma_addr_t)0)
>> @@ -442,6 +444,19 @@ static inline int dma_mapping_error(struct device
>> *dev, dma_addr_t dma_addr)
>> ÂÂÂÂÂ return 0;
>> Â }
>> +static inline phys_addr_t dma_addr_to_phys_addr(struct device *dev,
>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ dma_addr_t dma_handle)
>> +{
>> +ÂÂÂ const struct dma_map_ops *ops = get_dma_ops(dev);
>> +
>> +ÂÂÂ if (dma_is_direct(ops))
>> +ÂÂÂÂÂÂÂ return (phys_addr_t)dma_handle;
>
> Well that's not right, is it - remember why you had that namespace
> collision? ;)
>

Ugh, correct. Don't know what I was thinking. Will rework the check.

---
Thanks & Best Regards, Laurentiu