summaryrefslogtreecommitdiffstats
path: root/src/dt/common.h
diff options
context:
space:
mode:
authorMarc Kleine-Budde <mkl@pengutronix.de>2015-05-25 14:50:12 +0200
committerMarc Kleine-Budde <mkl@pengutronix.de>2015-05-25 23:52:18 +0200
commitcd3e06e67af4f52eb5fd98e26ecebb995beb4690 (patch)
treebde4b27e6fe45d1ebbe3ef0f6c4f7b89032183da /src/dt/common.h
parentaba4493455b4dc88c48e2e3fffa52bb7d9ec3ae8 (diff)
downloaddt-utils-cd3e06e67af4f52eb5fd98e26ecebb995beb4690.tar.gz
dt-utils-cd3e06e67af4f52eb5fd98e26ecebb995beb4690.tar.xz
crypto: import crypto layer from barebox
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
Diffstat (limited to 'src/dt/common.h')
-rw-r--r--src/dt/common.h195
1 files changed, 195 insertions, 0 deletions
diff --git a/src/dt/common.h b/src/dt/common.h
index 5645bad..d049ee7 100644
--- a/src/dt/common.h
+++ b/src/dt/common.h
@@ -3,8 +3,10 @@
#include <errno.h>
#include <fcntl.h>
+#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
+#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
@@ -40,11 +42,23 @@
#define dev_info(dev, fmt, arg...) pr_err(fmt, ##arg)
#define dev_dbg(dev, fmt, arg...) pr_debug(fmt, ##arg)
+#ifndef ENOTSUPP
+#define ENOTSUPP 524
+#endif
+
static inline void *xzalloc(size_t size)
{
return calloc(1, size);
}
+static inline void *xmalloc(size_t size)
+{
+ return xzalloc(size);
+}
+
+#define EXPORT_SYMBOL(sym)
+#define EXPORT_SYMBOL_GPL(sym)
+
/*
* Kernel pointers have redundant information, so we can use a
* scheme where we can return either an error code or a dentry
@@ -92,6 +106,20 @@ static inline void *ERR_CAST(const void *ptr)
return (void *) ptr;
}
+static inline char *barebox_asprintf(const char *fmt, ...) __attribute__ ((format(__printf__, 1, 2)));
+static inline char *barebox_asprintf(const char *fmt, ...)
+{
+ va_list ap;
+ char *p;
+ int ret;
+
+ va_start(ap, fmt);
+ ret = vasprintf(&p, fmt, ap);
+ va_end(ap);
+
+ return ret == -1 ? NULL : p;
+}
+
/**
* strlcpy - Copy a %NUL terminated string into a sized buffer
* @dest: Where to copy the string to
@@ -226,6 +254,15 @@ static inline int write_full(int fd, void *buf, size_t size)
return insize;
}
+static inline void *memmap(int fd, int flags)
+{
+ return (void *)-1;
+}
+
+static inline int ctrlc (void)
+{
+ return 0;
+}
#define MAX_DRIVER_NAME 32
#define DEVICE_ID_SINGLE -1
@@ -295,9 +332,37 @@ static inline int of_unregister_fixup(int (*fixup)(struct device_node *, void *)
return 0;
}
+#define __define_initcall(level,fn,id) \
+static void __attribute__ ((constructor)) __initcall_##id##_##fn() { \
+ fn(); \
+}
+
+#define core_initcall(fn) __define_initcall("1",fn,1)
+#define postcore_initcall(fn) __define_initcall("2",fn,2)
+#define console_initcall(fn) __define_initcall("3",fn,3)
+#define postconsole_initcall(fn) __define_initcall("4",fn,4)
+#define mem_initcall(fn) __define_initcall("5",fn,5)
+#define mmu_initcall(fn) __define_initcall("6",fn,6)
+#define postmmu_initcall(fn) __define_initcall("7",fn,7)
+#define coredevice_initcall(fn) __define_initcall("8",fn,8)
+#define fs_initcall(fn) __define_initcall("9",fn,9)
+#define device_initcall(fn) __define_initcall("10",fn,10)
+#define crypto_initcall(fn) __define_initcall("11",fn,11)
+#define late_initcall(fn) __define_initcall("12",fn,12)
+#define environment_initcall(fn) __define_initcall("13",fn,13)
+#define postenvironment_initcall(fn) __define_initcall("14",fn,14)
+
+typedef uint8_t u8;
+typedef uint16_t u16;
+typedef uint32_t u32;
+typedef uint64_t u64;
+
#define cpu_to_be32 __cpu_to_be32
#define be32_to_cpu __be32_to_cpu
+#define cpu_to_be64 __cpu_to_be64
+#define be64_to_cpu __be64_to_cpu
+
#define ALIGN(x, a) __ALIGN_MASK(x, (typeof(x))(a) - 1)
#define __ALIGN_MASK(x, mask) (((x) + (mask)) & ~(mask))
@@ -305,6 +370,136 @@ static inline int of_unregister_fixup(int (*fixup)(struct device_node *, void *)
#define __maybe_unused __attribute__((unused))
+static inline u16 __get_unaligned_be16(const u8 *p)
+{
+ return p[0] << 8 | p[1];
+}
+
+static inline u32 __get_unaligned_be32(const u8 *p)
+{
+ return p[0] << 24 | p[1] << 16 | p[2] << 8 | p[3];
+}
+
+static inline u64 __get_unaligned_be64(const u8 *p)
+{
+ return (u64)__get_unaligned_be32(p) << 32 |
+ __get_unaligned_be32(p + 4);
+}
+
+static inline void __put_unaligned_be16(u16 val, u8 *p)
+{
+ *p++ = val >> 8;
+ *p++ = val;
+}
+
+static inline void __put_unaligned_be32(u32 val, u8 *p)
+{
+ __put_unaligned_be16(val >> 16, p);
+ __put_unaligned_be16(val, p + 2);
+}
+
+static inline void __put_unaligned_be64(u64 val, u8 *p)
+{
+ __put_unaligned_be32(val >> 32, p);
+ __put_unaligned_be32(val, p + 4);
+}
+
+static inline u16 get_unaligned_be16(const void *p)
+{
+ return __get_unaligned_be16((const u8 *)p);
+}
+
+static inline u32 get_unaligned_be32(const void *p)
+{
+ return __get_unaligned_be32((const u8 *)p);
+}
+
+static inline u64 get_unaligned_be64(const void *p)
+{
+ return __get_unaligned_be64((const u8 *)p);
+}
+
+static inline void put_unaligned_be16(u16 val, void *p)
+{
+ __put_unaligned_be16(val, p);
+}
+
+static inline void put_unaligned_be32(u32 val, void *p)
+{
+ __put_unaligned_be32(val, p);
+}
+
+static inline void put_unaligned_be64(u64 val, void *p)
+{
+ __put_unaligned_be64(val, p);
+}
+
+/**
+ * rol32 - rotate a 32-bit value left
+ * @word: value to rotate
+ * @shift: bits to roll
+ */
+static inline __u32 rol32(__u32 word, unsigned int shift)
+{
+ return (word << shift) | (word >> (32 - shift));
+}
+
+/**
+ * ror32 - rotate a 32-bit value right
+ * @word: value to rotate
+ * @shift: bits to roll
+ */
+static inline __u32 ror32(__u32 word, unsigned int shift)
+{
+ return (word >> shift) | (word << (32 - shift));
+}
+
+#define min(x, y) ({ \
+ typeof(x) _min1 = (x); \
+ typeof(y) _min2 = (y); \
+ (void) (&_min1 == &_min2); \
+ _min1 < _min2 ? _min1 : _min2; })
+
+/*
+ * Helper macros to use CONFIG_ options in C expressions. Note that
+ * these only work with boolean and tristate options.
+ */
+
+/*
+ * Getting something that works in C and CPP for an arg that may or may
+ * not be defined is tricky. Here, if we have "#define CONFIG_BOOGER 1"
+ * we match on the placeholder define, insert the "0," for arg1 and generate
+ * the triplet (0, 1, 0). Then the last step cherry picks the 2nd arg (a one).
+ * When CONFIG_BOOGER is not defined, we generate a (... 1, 0) pair, and when
+ * the last step cherry picks the 2nd arg, we get a zero.
+ */
+#define __ARG_PLACEHOLDER_1 0,
+#define config_enabled(cfg) _config_enabled(cfg)
+#define _config_enabled(value) __config_enabled(__ARG_PLACEHOLDER_##value)
+#define __config_enabled(arg1_or_junk) ___config_enabled(arg1_or_junk 1, 0)
+#define ___config_enabled(__ignored, val, ...) val
+
+/*
+ * IS_ENABLED(CONFIG_FOO) evaluates to 1 if CONFIG_FOO is set to 'y' or 'm',
+ * 0 otherwise.
+ *
+ */
+#define IS_ENABLED(option) \
+ (config_enabled(option) || config_enabled(option##_MODULE))
+
+/*
+ * 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) config_enabled(option)
+
+/*
+ * IS_MODULE(CONFIG_FOO) evaluates to 1 if CONFIG_FOO is set to 'm', 0
+ * otherwise.
+ */
+#define IS_MODULE(option) config_enabled(option##_MODULE)
+
#endif
uint32_t crc32(uint32_t crc, const void *_buf, unsigned int len);