[PATCH 1/4] i3c: master: Add helpers for DMA mapping and bounce buffer handling

Jarkko Nikula jarkko.nikula at linux.intel.com
Mon Aug 4 06:35:39 PDT 2025


On 8/1/25 5:54 PM, Frank Li wrote:
> On Thu, Jul 31, 2025 at 05:14:17PM +0300, Jarkko Nikula wrote:
>> Add helpers for I3C host controller drivers for DMA mapping/unmapping
>> and bounce buffer handling. A bounce buffer is allocated if the buffer
>> is not DMA'able or when the driver requires it for a transfer.
> 
> You'd better move some patch 2's description to this patch, to descriptor
> why need bounce buffer.
> 
>>
>> Signed-off-by: Jarkko Nikula <jarkko.nikula at linux.intel.com>
>> ---
>>   drivers/i3c/master.c       | 74 ++++++++++++++++++++++++++++++++++++++
>>   include/linux/i3c/master.h | 20 +++++++++++
>>   2 files changed, 94 insertions(+)
>>
>> diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c
>> index 2ef898a8fd80..a1daf18ea707 100644
>> --- a/drivers/i3c/master.c
>> +++ b/drivers/i3c/master.c
>> @@ -8,6 +8,7 @@
>>   #include <linux/atomic.h>
>>   #include <linux/bug.h>
>>   #include <linux/device.h>
>> +#include <linux/dma-mapping.h>
>>   #include <linux/err.h>
>>   #include <linux/export.h>
>>   #include <linux/kernel.h>
>> @@ -1727,6 +1728,79 @@ int i3c_master_do_daa(struct i3c_master_controller *master)
>>   }
>>   EXPORT_SYMBOL_GPL(i3c_master_do_daa);
>>
>> +/**
>> + * i3c_master_dma_map_single() - Map buffer for single DMA transfer
>> + * @dev: device object of a device doing DMA
>> + * @buf: destination/source buffer for DMA
>> + * @len: length of transfer
>> + * @need_bounce: true if buffer is not DMA safe and need a bounce buffer
> 
> Is it possible auto check if 'buf' dma-able?
> 
In some sense yes and I think since I3C being new, and probably 
integrated only to a modern HW, it will simplify things a bit and we 
don't need to deal with e.g. highmem etc. legacy stuff what SPI core 
needs to check for instance.

Idea is to do common checks (currently only the is_vmalloc_addr()) here 
but let drivers to tell if they have their quirk reason for a bounce buffer.

> If use struct i3c_dma __free(kfree) *dma_xfer = NULL; it simple error handle
> 
Will do.

>> +	dma_xfer->addr = dma_map_single(dev, dma_buf, len, dir);
> 
> len should be ALIGN(len, cache_line_size(), otherwise swiotlb will bounce
> again if need_bounce is true
> 
Ah, good to know.

>> +struct i3c_dma *i3c_master_dma_map_single(struct device *dev, void *ptr,
>> +					  size_t len, bool dma_safe,
>> +					  enum dma_data_direction dir);
>> +void i3c_master_dma_unmap_single(struct device *dev, struct i3c_dma *dma_xfer);
> 
> needn't dev, save it into struct i3c_dma, so we can use cleanup easily
> 
Ok.



More information about the linux-i3c mailing list