From e340bbf7b5be2fbb79b2358821e77af77257db5e Mon Sep 17 00:00:00 2001 From: Abner Chang Date: Tue, 7 Jan 2020 15:08:26 +0800 Subject: 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 Cc: Leif Lindholm Reviewed-by: Anup Patel --- include/sbi/sbi_bits.h | 13 ------------- include/sbi/sbi_types.h | 28 ++++++++++++++++++++++++++++ 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 -- cgit v1.2.3