diff options
author | Abner Chang <abner.chang@hpe.com> | 2020-01-07 15:08:26 +0800 |
---|---|---|
committer | Anup Patel <anup@brainfault.org> | 2020-01-09 10:08:11 +0530 |
commit | e340bbf7b5be2fbb79b2358821e77af77257db5e (patch) | |
tree | 93c8e82db7e01190093070f6f8339a32cd857ddf /include/sbi/sbi_types.h | |
parent | 049ad0b3877352527ab470eba33bc767e9b54961 (diff) |
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>
Diffstat (limited to 'include/sbi/sbi_types.h')
-rw-r--r-- | include/sbi/sbi_types.h | 28 |
1 files changed, 28 insertions, 0 deletions
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 |