mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: Yann Sionneau <ysionneau@kalray.eu>,
	Lucas Stach <l.stach@pengutronix.de>,
	Jules Maselbas <jmaselbas@kalray.eu>
Cc: barebox@lists.infradead.org
Subject: Re: [PATCH 3/5] kvx: Implement dma handling primitives
Date: Wed, 3 Mar 2021 10:52:13 +0100	[thread overview]
Message-ID: <65b70824-db37-8e63-c6df-52c835b4f9ea@pengutronix.de> (raw)
In-Reply-To: <df2f974e-74f5-6054-8b68-03bcad091aad@kalray.eu>

Hello Yann,

On 03.03.21 10:33, Yann Sionneau wrote:
> On 03/03/2021 10:14, Lucas Stach wrote:
>>> Right now we aren't using any driver that require dma_alloc_coherent,
>>> but we use drivers that requires dma_alloc and dma_map_single instead.
>> I would vote for a BUILD_BUG_ON_MSG in this function, so you get a
>> compile time error and you can state what needs to be done in order to
>> get rid of the failure.
> 
> If we define the function and put a BUILD_BUG_ON_MSG() inside, I am guessing that all builds will fail, right?
> 
> But we only want the builds that actually call this function to fail.
> 
> Maybe we can just define dma_alloc_coherent() as being a macro, to BUILD_BUG_ON_MSG.
> 
> Like:
> 
> #define dma_alloc_coherent(a, b) BUILD_BUG_ON_MSG(1, "dma_alloc_coherent is not supported yet on KVX. You would need to add MMU support to be able to map uncached pages")

If the macro is expanded, it will fail. Even if the code is ultimately unused because
of linker section garbage collection. You could define dma_alloc_coherent with following
body:

{
	extern void *coherent_allocation_not_implemented_on_kvx(void);
	/* You would need to add MMU support to be able to map uncached pages */
	return coherent_allocation_not_implemented_on_kvx();
}

If after linker GC, a reference to dma_alloc_coherent remains, you will get a linker
error explaining why.

Cheers,
Ahmad

> 
> What do you think?
> 
>>
>>>>>> +/*
>>>>>> + * The implementation of arch should follow the following rules:
>>>>>> + *        map        for_cpu        for_device    unmap
>>>>>> + * TO_DEV    writeback    none        writeback    none
>>>>>> + * FROM_DEV    invalidate    invalidate(*)    invalidate    invalidate(*)
>>>>>> + * BIDIR    writeback    invalidate    writeback    invalidate
>>>>>> + *
>>>>>> + * (*) - only necessary if the CPU speculatively prefetches.
>>>>>> + *
>>>>>> + * (see https://lkml.org/lkml/2018/5/18/979)
>>>>>> + */
>>>>>> +
>>>>>> +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);
>>>> Why do you need to explicitly invalidate, but not flush? Even if the
>>>> CPU speculatively prefetches, the coherency protocol should make sure
>>>> to invalidate the speculatively loaded lines, right?
>>> Since we don't have a coherent memory, here we need to invalidate L1
>>> dcache to let the CPU see deivce's writes in memory.
>>> Also every write goes through the cache, flush is not required.
>> Ah, if all your caches are write-through that makes sense. Can you add
>> a comment somewhere stating that this implementation assumes WT caches
>> on KVX? This way we can avoid the confusion Ahamd and myself fell into
>> when glancing over the code.
>>
>> Regards,
>> Lucas
>>
>>
> 
> 

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

  reply	other threads:[~2021-03-03 19:16 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
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 [this message]
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=65b70824-db37-8e63-c6df-52c835b4f9ea@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=jmaselbas@kalray.eu \
    --cc=l.stach@pengutronix.de \
    --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