summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--kvm/kernel/external-module-compat.h36
1 files changed, 36 insertions, 0 deletions
diff --git a/kvm/kernel/external-module-compat.h b/kvm/kernel/external-module-compat.h
index 74bc07249..b1807756d 100644
--- a/kvm/kernel/external-module-compat.h
+++ b/kvm/kernel/external-module-compat.h
@@ -13,6 +13,7 @@
#include <linux/cpu.h>
#include <asm/processor.h>
#include <linux/hrtimer.h>
+#include <asm/bitops.h>
/*
* 2.6.16 does not have GFP_NOWAIT
@@ -368,3 +369,38 @@ static inline void preempt_notifier_sys_exit(void) {}
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,21)
#define HRTIMER_MODE_ABS HRTIMER_ABS
#endif
+
+/* div64_64 is fairly new */
+#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,21)
+
+#ifdef CONFIG_64BIT
+
+static inline uint64_t div64_64(uint64_t dividend, uint64_t divisor)
+{
+ return dividend / divisor;
+}
+
+#else
+
+/* 64bit divisor, dividend and result. dynamic precision */
+static inline uint64_t div64_64(uint64_t dividend, uint64_t divisor)
+{
+ uint32_t high, d;
+
+ high = divisor >> 32;
+ if (high) {
+ unsigned int shift = fls(high);
+
+ d = divisor >> shift;
+ dividend >>= shift;
+ } else
+ d = divisor;
+
+ do_div(dividend, d);
+
+ return dividend;
+}
+
+#endif
+
+#endif