[U-Boot] [PATCH 2/9] CACHE: Add cache_aligned() macro

Marek Vasut marex at denx.de
Mon Jun 25 02:17:50 CEST 2012


This macro returns 1 if the argument (address) is aligned, returns
zero otherwise. This will be used to test user-supplied address to
various commands to prevent user from loading data to/from unaligned
address when using caches.

This is made as a macro, because macros are expanded where they are
used. Therefore it can be easily instrumented to report position of
the fault.

Signed-off-by: Marek Vasut <marex at denx.de>
Cc: Wolfgang Denk <wd at denx.de>
---
 include/common.h |   18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/include/common.h b/include/common.h
index 322569e..17c64b0 100644
--- a/include/common.h
+++ b/include/common.h
@@ -730,6 +730,24 @@ void	invalidate_dcache_range(unsigned long start, unsigned long stop);
 void	invalidate_dcache_all(void);
 void	invalidate_icache_all(void);
 
+/* Test if address is cache-aligned. Returns 0 if it is, 1 otherwise. */
+#define cacheline_aligned(addr)						\
+	({								\
+	int __ret;							\
+	if (!dcache_status()) {						\
+		__ret = 1;						\
+	} else if ((addr) & (ARCH_DMA_MINALIGN - 1)) {			\
+		puts("Align load address to "				\
+			__stringify(ARCH_DMA_MINALIGN)			\
+			" bytes when using caches!\n");			\
+		__ret = 0;						\
+	} else {							\
+		__ret = 1;						\
+	}								\
+	__ret;								\
+	})
+
+
 /* arch/$(ARCH)/lib/ticks.S */
 unsigned long long get_ticks(void);
 void	wait_ticks    (unsigned long);
-- 
1.7.10



More information about the U-Boot mailing list