Merge branch 'master' of git://git.denx.de/u-boot-spi
[oweals/u-boot.git] / include / linux / kernel.h
index 89fcae0983c1d011cc2420efe1dec837c8f3e1a7..a85c15d8dc28d31e7a1b7be06ac1b61d1f84f419 100644 (file)
@@ -16,7 +16,9 @@
 #define LLONG_MAX      ((long long)(~0ULL>>1))
 #define LLONG_MIN      (-LLONG_MAX - 1)
 #define ULLONG_MAX     (~0ULL)
+#ifndef SIZE_MAX
 #define SIZE_MAX       (~(size_t)0)
+#endif
 
 #define U8_MAX         ((u8)~0U)
 #define S8_MAX         ((s8)(U8_MAX>>1))
 #define S64_MAX                ((s64)(U64_MAX>>1))
 #define S64_MIN                ((s64)(-S64_MAX - 1))
 
+/* Aliases defined by stdint.h */
+#define UINT32_MAX     U32_MAX
+#define UINT64_MAX     U64_MAX
+
 #define STACK_MAGIC    0xdeadbeef
 
 #define REPEAT_BYTE(x) ((~0ul / 0xff) * (x))
 
 #define ALIGN(x,a)             __ALIGN_MASK((x),(typeof(x))(a)-1)
+#define ALIGN_DOWN(x, a)       ALIGN((x) - ((a) - 1), (a))
 #define __ALIGN_MASK(x,mask)   (((x)+(mask))&~(mask))
 #define PTR_ALIGN(p, a)                ((typeof(p))ALIGN((unsigned long)(p), (a)))
 #define IS_ALIGNED(x, a)               (((x) & ((typeof(x))(a) - 1)) == 0)
 #define FIELD_SIZEOF(t, f) (sizeof(((t*)0)->f))
 #define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
 
+#define DIV_ROUND_DOWN_ULL(ll, d) \
+       ({ unsigned long long _tmp = (ll); do_div(_tmp, d); _tmp; })
+
+#define DIV_ROUND_UP_ULL(ll, d)                DIV_ROUND_DOWN_ULL((ll) + (d) - 1, (d))
+
 #if BITS_PER_LONG == 32
 # define DIV_ROUND_UP_SECTOR_T(ll,d) DIV_ROUND_UP_ULL(ll, d)
 #else
                (((__x) - ((__d) / 2)) / (__d));        \
 }                                                      \
 )
+/*
+ * Same as above but for u64 dividends. divisor must be a 32-bit
+ * number.
+ */
+#define DIV_ROUND_CLOSEST_ULL(x, divisor)(             \
+{                                                      \
+       typeof(divisor) __d = divisor;                  \
+       unsigned long long _tmp = (x) + (__d) / 2;      \
+       do_div(_tmp, __d);                              \
+       _tmp;                                           \
+}                                                      \
+)
 
 /*
  * Multiplies an integer by a fraction, while avoiding unnecessary