]> git.sesse.net Git - bcachefs-tools-debian/blobdiff - include/linux/kernel.h
New upstream release
[bcachefs-tools-debian] / include / linux / kernel.h
index 10d94c5eca5f453303ae368f78f9f7622ffaa490..35a7207e0495c08d950a991abbebebdf03b9a782 100644 (file)
 #include <linux/bug.h>
 #include <linux/byteorder.h>
 #include <linux/compiler.h>
+#include <linux/math.h>
 
-#define IS_ENABLED(opt)                0
+#define BIT(nr)                        (1UL << (nr))
+#define BIT_ULL(nr)            (1ULL << (nr))
+
+#define __ARG_PLACEHOLDER_1 0,
+#define __take_second_arg(__ignored, val, ...) val
+
+#define __and(x, y)                    ___and(x, y)
+#define ___and(x, y)                   ____and(__ARG_PLACEHOLDER_##x, y)
+#define ____and(arg1_or_junk, y)       __take_second_arg(arg1_or_junk y, 0)
+
+#define __or(x, y)                     ___or(x, y)
+#define ___or(x, y)                    ____or(__ARG_PLACEHOLDER_##x, y)
+#define ____or(arg1_or_junk, y)                __take_second_arg(arg1_or_junk 1, y)
+
+#define __is_defined(x)                        ___is_defined(x)
+#define ___is_defined(val)             ____is_defined(__ARG_PLACEHOLDER_##val)
+#define ____is_defined(arg1_or_junk)   __take_second_arg(arg1_or_junk 1, 0)
+
+/*
+ * IS_BUILTIN(CONFIG_FOO) evaluates to 1 if CONFIG_FOO is set to 'y', 0
+ * otherwise. For boolean options, this is equivalent to
+ * IS_ENABLED(CONFIG_FOO).
+ */
+#define IS_BUILTIN(option) __is_defined(option)
+
+/*
+ * IS_MODULE(CONFIG_FOO) evaluates to 1 if CONFIG_FOO is set to 'm', 0
+ * otherwise.
+ */
+#define IS_MODULE(option) __is_defined(option##_MODULE)
+
+/*
+ * IS_REACHABLE(CONFIG_FOO) evaluates to 1 if the currently compiled
+ * code can call a function defined in code compiled based on CONFIG_FOO.
+ * This is similar to IS_ENABLED(), but returns false when invoked from
+ * built-in code when CONFIG_FOO is set to 'm'.
+ */
+#define IS_REACHABLE(option) __or(IS_BUILTIN(option), \
+                               __and(IS_MODULE(option), __is_defined(MODULE)))
+
+/*
+ * IS_ENABLED(CONFIG_FOO) evaluates to 1 if CONFIG_FOO is set to 'y' or 'm',
+ * 0 otherwise.
+ */
+#define IS_ENABLED(option) __or(IS_BUILTIN(option), IS_MODULE(option))
 #define EXPORT_SYMBOL(sym)
 
 #define U8_MAX         ((u8)~0U)
@@ -37,8 +82,6 @@
 #define __must_be_array(a)     BUILD_BUG_ON_ZERO(__same_type((a), &(a)[0]))
 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr))
 
-#define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
-
 #ifndef offsetof
 #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
 #endif
        (type *)((char *)__mptr - offsetof(type, member)); })
 #endif
 
-#define __round_mask(x, y) ((__typeof__(x))((y)-1))
-#define round_up(x, y) ((((x)-1) | __round_mask(x, y))+1)
-#define round_down(x, y) ((x) & ~__round_mask(x, y))
-
-#define roundup(x, y)                                  \
-({                                                     \
-       const typeof(y) __y = y;                        \
-       (((x) + (__y - 1)) / __y) * __y;                \
-})
+#define __struct_group(TAG, NAME, ATTRS, MEMBERS...) \
+       union { \
+               struct { MEMBERS } ATTRS; \
+               struct TAG { MEMBERS } ATTRS NAME; \
+       }
+#define struct_group(NAME, MEMBERS...) \
+       __struct_group(/* no tag */, NAME, /* no attrs */, MEMBERS)
 
 #define max(x, y) ({                           \
        typeof(x) _max1 = (x);                  \
 
 #define might_sleep()
 
-#define cpu_relax()            do {} while (0)
-#define cpu_relax_lowlatency() do {} while (0)
+#define cpu_relax()            barrier()
+#define cpu_relax_lowlatency() barrier()
 
 #define panic(fmt, ...)                                        \
 do {                                                   \
@@ -198,6 +239,19 @@ static inline int __must_check kstrtos32(const char *s, unsigned int base, s32 *
        return kstrtoint(s, base, res);
 }
 
+struct printbuf;
+extern void prt_u64(struct printbuf *out, u64 num);
+
+extern __printf(2, 0) void prt_vprintf(struct printbuf *out, const char *fmt, va_list args);
+extern __printf(2, 3) void prt_printf(struct printbuf *out, const char *fmt, ...);
+
+static const char hex_asc[] = "0123456789abcdef";
+#define hex_asc_lo(x)  hex_asc[((x) & 0x0f)]
+#define hex_asc_hi(x)  hex_asc[((x) & 0xf0) >> 4]
+static const char hex_asc_upper[] = "0123456789ABCDEF";
+#define hex_asc_upper_lo(x)    hex_asc_upper[((x) & 0x0f)]
+#define hex_asc_upper_hi(x)    hex_asc_upper[((x) & 0xf0) >> 4]
+
 /* The hash is always the low bits of hash_len */
 #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
  #define HASH_LEN_DECLARE u32 hash; u32 len
@@ -219,4 +273,9 @@ struct qstr {
 
 #define POISON_FREE 0x6b
 
+static inline void dump_stack(void) {}
+
+#define unsafe_memcpy(dst, src, bytes, justification)          \
+       memcpy(dst, src, bytes)
+
 #endif