mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: rcz@pengutronix.de, mfe@pengutronix.de,
	Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 1/4] dma: define __dma_aligned attribute
Date: Thu, 21 Sep 2023 11:56:46 +0200	[thread overview]
Message-ID: <20230921095649.310666-1-a.fatoum@pengutronix.de> (raw)

Unlike the kernel, we always map barebox stack 1:1, so DMA to barebox
stack is ok if care is taken for alignment. Otherwise, cache maintenance
may end up clobbering data unintentionally.

Provide a __dma_aligned attribute for use in such situations and use the
already existing DMA_ALIGNMENT as alignment.

To be able to do that, we need to make sure that the default DMA_ALIGNMENT
is only defined when architectures don't define their own dma_alloc. If
they do, they are responsible to define their own DMA_ALIGNMENT as well.

The new attribute is intentionally not called __cacheline_aligned,
because it differs functionally: We care about the cache line size of
the outer cache, while in Linux __cacheline_aligned is for L1 cache.
A __dma_aligned wouldn't make sense for Linux as it would be too easy to
abuse (e.g. placing it on VMAP_STACK), but for barebox, we do this at
many places and an attribute would increase readability and even safety.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 include/dma.h | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/include/dma.h b/include/dma.h
index 2a09b747d1e2..469c482e7a3a 100644
--- a/include/dma.h
+++ b/include/dma.h
@@ -17,17 +17,19 @@
 
 #define DMA_ADDRESS_BROKEN	NULL
 
+#ifndef dma_alloc
 #ifndef DMA_ALIGNMENT
 #define DMA_ALIGNMENT	32
 #endif
 
-#ifndef dma_alloc
 static inline void *dma_alloc(size_t size)
 {
 	return xmemalign(DMA_ALIGNMENT, ALIGN(size, DMA_ALIGNMENT));
 }
 #endif
 
+#define __dma_aligned __attribute__((__aligned__((DMA_ALIGNMENT))))
+
 #ifndef dma_free
 static inline void dma_free(void *mem)
 {
-- 
2.39.2




             reply	other threads:[~2023-09-21  9:58 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-21  9:56 Ahmad Fatoum [this message]
2023-09-21  9:56 ` [PATCH 2/4] ARM: dma: define DMA_ALIGNMENT instead of defining dma_alloc Ahmad Fatoum
2023-09-21 10:35   ` Marco Felsch
2023-09-21  9:56 ` [PATCH 3/4] hab: habv4: align config/state at 64 byte boundary Ahmad Fatoum
2023-09-21  9:56 ` [PATCH 4/4] hab: habv4: apply sizeof() to correct object Ahmad Fatoum
2023-09-21 10:35 ` [PATCH 1/4] dma: define __dma_aligned attribute Ahmad Fatoum

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=20230921095649.310666-1-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=mfe@pengutronix.de \
    --cc=rcz@pengutronix.de \
    /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