summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAbner Chang <abner.chang@hpe.com>2020-01-07 10:08:26 +0300
committerAnup Patel <anup@brainfault.org>2020-01-09 07:38:11 +0300
commite340bbf7b5be2fbb79b2358821e77af77257db5e (patch)
tree93c8e82db7e01190093070f6f8339a32cd857ddf
parent049ad0b3877352527ab470eba33bc767e9b54961 (diff)
downloadopensbi-e340bbf7b5be2fbb79b2358821e77af77257db5e.tar.xz
include: Add OPENSBI_EXTERNAL_SBI_TYPES in sbi_types.h
Add OPENSBI_EXTERNAL_SBI_TYPES macro to allow external definitions of data types and common macros. Also move some common definitions from sbi_bits.h to sbi_types.h. Signed-off-by: Abner Chang <abner.chang@hpe.com> Cc: Leif Lindholm <leif.lindholm@linaro.org> Reviewed-by: Anup Patel <anup.patel@wdc.com>
-rw-r--r--include/sbi/sbi_bits.h13
-rw-r--r--include/sbi/sbi_types.h28
2 files changed, 28 insertions, 13 deletions
diff --git a/include/sbi/sbi_bits.h b/include/sbi/sbi_bits.h
index 320966d..3963d84 100644
--- a/include/sbi/sbi_bits.h
+++ b/include/sbi/sbi_bits.h
@@ -10,23 +10,10 @@
#ifndef __SBI_BITS_H__
#define __SBI_BITS_H__
-#define likely(x) __builtin_expect((x), 1)
-#define unlikely(x) __builtin_expect((x), 0)
-
-#define ROUNDUP(a, b) ((((a)-1) / (b) + 1) * (b))
-#define ROUNDDOWN(a, b) ((a) / (b) * (b))
-
-#define MAX(a, b) ((a) > (b) ? (a) : (b))
-#define MIN(a, b) ((a) < (b) ? (a) : (b))
-#define CLAMP(a, lo, hi) MIN(MAX(a, lo), hi)
-
#define EXTRACT_FIELD(val, which) (((val) & (which)) / ((which) & ~((which)-1)))
#define INSERT_FIELD(val, which, fieldval) \
(((val) & ~(which)) | ((fieldval) * ((which) & ~((which)-1))))
-#define STR(x) XSTR(x)
-#define XSTR(x) #x
-
#define BIT_MASK(nr) (1UL << ((nr) % BITS_PER_LONG))
#define BIT_WORD(nr) ((nr) / BITS_PER_LONG)
#endif
diff --git a/include/sbi/sbi_types.h b/include/sbi/sbi_types.h
index f51d888..50b465e 100644
--- a/include/sbi/sbi_types.h
+++ b/include/sbi/sbi_types.h
@@ -10,6 +10,8 @@
#ifndef __SBI_TYPES_H__
#define __SBI_TYPES_H__
+#ifndef OPENSBI_EXTERNAL_SBI_TYPES
+
/* clang-format off */
typedef char s8;
@@ -60,6 +62,32 @@ typedef unsigned long physical_size_t;
#define __packed __attribute__((packed))
#define __noreturn __attribute__((noreturn))
+#define likely(x) __builtin_expect((x), 1)
+#define unlikely(x) __builtin_expect((x), 0)
+
+#define MAX(a, b) ((a) > (b) ? (a) : (b))
+#define MIN(a, b) ((a) < (b) ? (a) : (b))
+#define CLAMP(a, lo, hi) MIN(MAX(a, lo), hi)
+
+#define STR(x) XSTR(x)
+#define XSTR(x) #x
+
+#define ROUNDUP(a, b) ((((a)-1) / (b) + 1) * (b))
+#define ROUNDDOWN(a, b) ((a) / (b) * (b))
+
/* clang-format on */
+#else
+/* OPENSBI_EXTERNAL_SBI_TYPES could be defined in CFLAGS for using the
+ * external definitions of data types and common macros.
+ * OPENSBI_EXTERNAL_SBI_TYPES is the file name to external header file,
+ * the external build system should address the additional include
+ * directory ccordingly.
+ */
+
+#define XSTR(x) #x
+#define STR(x) XSTR(x)
+#include STR(OPENSBI_EXTERNAL_SBI_TYPES)
+#endif
+
#endif