Re: [PATCH 3/5] kvx: Implement dma handling primitives

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

 



On 02.03.21 09:37, Ahmad Fatoum wrote:
> Hello Jules, Yann,
> 
>> +void dma_sync_single_for_device(dma_addr_t addr, size_t size,
>> +				enum dma_data_direction dir)
>> +{
>> +	switch (dir) {
>> +	case DMA_FROM_DEVICE:
>> +		kvx_dcache_invalidate_mem_area(addr, size);
>> +		break;
>> +	case DMA_TO_DEVICE:
>> +	case DMA_BIDIRECTIONAL:
>> +		/* allow device to read buffer written by CPU */
>> +		wmb();
> 
> If the interconnect was indeed coherent, like dma_alloc_coherent
> above hints, you wouldn't need any barriers here..?

Wrong context. You wouldn't need the cache invalidation* above.

> 
>> +		break;
>> +	default:
>> +		BUG();
>> +	}
>> +}
>> +
>> +void dma_sync_single_for_cpu(dma_addr_t addr, size_t size,
>> +				enum dma_data_direction dir)
>> +{
>> +	switch (dir) {
>> +	case DMA_FROM_DEVICE:
>> +	case DMA_TO_DEVICE:
>> +		break;
>> +	case DMA_BIDIRECTIONAL:
>> +		kvx_dcache_invalidate_mem_area(addr, size);
>> +		break;
>> +	default:
>> +		BUG();
>> +	}
>> +}
>> +
>> +#define KVX_DDR_ALIAS_OFFSET \
>> +	(KVX_DDR_64BIT_RAM_WINDOW_BA - KVX_DDR_32BIT_RAM_WINDOW_BA)
>> +#define KVX_DDR_ALIAS_WINDOW \
>> +	(KVX_DDR_64BIT_RAM_WINDOW_BA + KVX_DDR_ALIAS_OFFSET)
>> +
>> +/* Local smem is aliased between 0 and 16MB */
>> +#define KVX_SMEM_LOCAL_ALIAS 0x1000000ULL
>> +
>> +dma_addr_t dma_map_single(struct device_d *dev, void *ptr, size_t size,
>> +			  enum dma_data_direction dir)
>> +{
>> +	uintptr_t addr = (uintptr_t) ptr;
>> +
>> +	dma_sync_single_for_device(addr, size, dir);
>> +
>> +	/* Local smem alias should never be used for dma */
>> +	if (addr < KVX_SMEM_LOCAL_ALIAS)
>> +		return addr + (1 + kvx_cluster_id()) * KVX_SMEM_LOCAL_ALIAS;
>> +
>> +	if (dev->dma_mask && addr <= dev->dma_mask)
>> +		return addr;
>> +
>> +	if (addr >= KVX_DDR_ALIAS_WINDOW)
>> +		return DMA_ERROR_CODE;
>> +
>> +	addr -= KVX_DDR_ALIAS_OFFSET;
>> +	if (dev->dma_mask && addr > dev->dma_mask)
>> +		return DMA_ERROR_CODE;
>> +
>> +	return addr;
>> +}
>> +
>> +void dma_unmap_single(struct device_d *dev, dma_addr_t addr, size_t size,
>> +		      enum dma_data_direction dir)
>> +{
>> +	dma_sync_single_for_cpu(addr, size, dir);
>> +}
>>
> 

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

_______________________________________________
barebox mailing list
barebox@xxxxxxxxxxxxxxxxxxx
http://lists.infradead.org/mailman/listinfo/barebox



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

  Powered by Linux