From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: Jules Maselbas <jmaselbas@kalray.eu>, barebox@lists.infradead.org
Cc: Yann Sionneau <ysionneau@kalray.eu>
Subject: Re: [PATCH 3/5] kvx: Implement dma handling primitives
Date: Tue, 2 Mar 2021 09:44:47 +0100 [thread overview]
Message-ID: <dc78b73b-3e38-adbb-362a-4a58dbee1103@pengutronix.de> (raw)
In-Reply-To: <04c18498-970c-9a69-ebf7-97bf85d2f961@pengutronix.de>
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@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2021-03-02 8:46 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-01 15:58 [PATCH 1/5] kvx: Implement setjmp/longjmp/initjmp Jules Maselbas
2021-03-01 15:58 ` [PATCH 2/5] kvx: Implement dcache invalidation primitive Jules Maselbas
2021-03-02 8:40 ` Ahmad Fatoum
2021-03-02 11:44 ` Jules Maselbas
2021-03-01 15:58 ` [PATCH 3/5] kvx: Implement dma handling primitives Jules Maselbas
2021-03-02 8:37 ` Ahmad Fatoum
2021-03-02 8:44 ` Ahmad Fatoum [this message]
2021-03-02 10:14 ` Lucas Stach
2021-03-02 10:58 ` Jules Maselbas
2021-03-03 9:14 ` Lucas Stach
2021-03-03 9:33 ` Yann Sionneau
2021-03-03 9:52 ` Ahmad Fatoum
2021-03-01 15:58 ` [PATCH 4/5] kvx: Request enough privilege to boot Linux Jules Maselbas
2021-03-01 15:58 ` [PATCH 5/5] kvx: lib: dtb: Remove unused variable Jules Maselbas
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=dc78b73b-3e38-adbb-362a-4a58dbee1103@pengutronix.de \
--to=a.fatoum@pengutronix.de \
--cc=barebox@lists.infradead.org \
--cc=jmaselbas@kalray.eu \
--cc=ysionneau@kalray.eu \
/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