The macro can be used for temporary stack buffers which need to meet
a minimum alignment requirement.

This will be used by bcm2835 mailbox users, where all buffers need to
be aligned.

Signed-off-by: Andre Heider <[email protected]>
---
 include/common.h | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/include/common.h b/include/common.h
index 0f0ba08..00f1642 100644
--- a/include/common.h
+++ b/include/common.h
@@ -192,6 +192,17 @@ int run_shell(void);
 #define ARRAY_SIZE(arr)                (sizeof(arr) / sizeof((arr)[0]) + 
__must_be_array(arr))
 #define ARRAY_AND_SIZE(x)      (x), ARRAY_SIZE(x)
 
+/*
+ * The STACK_ALIGN_ARRAY macro is used to allocate a buffer on the stack that
+ * meets a minimum alignment requirement.
+ *
+ * Note that the size parameter is the number of array elements to allocate,
+ * not the number of bytes.
+ */
+#define STACK_ALIGN_ARRAY(type, name, size, align)             \
+       char __##name[sizeof(type) * (size) + (align) - 1];     \
+       type *name = (type *)ALIGN((uintptr_t)__##name, align)
+
 /**
  * container_of - cast a member of a structure out to the containing structure
  * @ptr:       the pointer to the member.
-- 
1.8.3.2


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

Reply via email to