summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAhmad Fatoum <a.fatoum@pengutronix.de>2020-04-13 09:51:53 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2020-04-15 12:31:23 +0200
commit2eece2192d9be43edfa27158c13019123cf1140d (patch)
treee476b5d82a11dbeff093b774322bbf943e8b3c8b
parentfd0130cfe4f3db56de7094747793fef39b744a0d (diff)
downloadbarebox-2eece2192d9be43edfa27158c13019123cf1140d.tar.gz
barebox-2eece2192d9be43edfa27158c13019123cf1140d.tar.xz
include: linux/kernel.h: port DIV_ROUND_CLOSEST_ULL definition
We already have DIV_ROUND_CLOSEST, but no DIV_ROUND_CLOSEST_ULL. Import the latter for use by later commits. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rw-r--r--include/linux/kernel.h13
1 files changed, 13 insertions, 0 deletions
diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index b320f7e902..23c23a73f5 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -6,6 +6,7 @@
#include <linux/bug.h>
#include <linux/barebox-wrapper.h>
#include <linux/limits.h>
+#include <asm-generic/div64.h>
#define ALIGN(x, a) __ALIGN_MASK(x, (typeof(x))(a) - 1)
#define ALIGN_DOWN(x, a) ALIGN((x) - ((a) - 1), (a))
@@ -41,6 +42,18 @@
(((x) + ((__divisor) / 2)) / (__divisor)); \
} \
)
+/*
+ * 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; \
+} \
+)
/**
* upper_32_bits - return bits 32-63 of a number