aboutsummaryrefslogtreecommitdiffstats
path: root/arch/x86/kvm/i8254.c
diff options
context:
space:
mode:
authorPaolo Bonzini <pbonzini@redhat.com>2016-03-04 03:28:41 -0500
committerPaolo Bonzini <pbonzini@redhat.com>2016-03-04 16:39:17 -0500
commit0e4d44151af7c8fca3d15c27d9b97d4ac41c102b (patch)
treee006d787abbb877a8283c28c4dc794ee73f6b0d0 /arch/x86/kvm/i8254.c
parente23d3fef83df8e303fded0ab55b379beec0dd604 (diff)
KVM: i8254: drop local copy of mul_u64_u32_div
A function that does the same as i8254.c's muldiv64 has been added (for KVM's own use, in fact!) in include/linux/math64.h. Use it instead of muldiv64. Reviewed-by: Radim Krčmář <rkrcmar@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'arch/x86/kvm/i8254.c')
-rw-r--r--arch/x86/kvm/i8254.c26
1 files changed, 3 insertions, 23 deletions
diff --git a/arch/x86/kvm/i8254.c b/arch/x86/kvm/i8254.c
index 219ef855aae5..a4bf5b45d65a 100644
--- a/arch/x86/kvm/i8254.c
+++ b/arch/x86/kvm/i8254.c
@@ -51,26 +51,6 @@
51#define RW_STATE_WORD0 3 51#define RW_STATE_WORD0 3
52#define RW_STATE_WORD1 4 52#define RW_STATE_WORD1 4
53 53
54/* Compute with 96 bit intermediate result: (a*b)/c */
55static u64 muldiv64(u64 a, u32 b, u32 c)
56{
57 union {
58 u64 ll;
59 struct {
60 u32 low, high;
61 } l;
62 } u, res;
63 u64 rl, rh;
64
65 u.ll = a;
66 rl = (u64)u.l.low * (u64)b;
67 rh = (u64)u.l.high * (u64)b;
68 rh += (rl >> 32);
69 res.l.high = div64_u64(rh, c);
70 res.l.low = div64_u64(((mod_64(rh, c) << 32) + (rl & 0xffffffff)), c);
71 return res.ll;
72}
73
74static void pit_set_gate(struct kvm_pit *pit, int channel, u32 val) 54static void pit_set_gate(struct kvm_pit *pit, int channel, u32 val)
75{ 55{
76 struct kvm_kpit_channel_state *c = &pit->pit_state.channels[channel]; 56 struct kvm_kpit_channel_state *c = &pit->pit_state.channels[channel];
@@ -139,7 +119,7 @@ static int pit_get_count(struct kvm_pit *pit, int channel)
139 int counter; 119 int counter;
140 120
141 t = kpit_elapsed(pit, c, channel); 121 t = kpit_elapsed(pit, c, channel);
142 d = muldiv64(t, KVM_PIT_FREQ, NSEC_PER_SEC); 122 d = mul_u64_u32_div(t, KVM_PIT_FREQ, NSEC_PER_SEC);
143 123
144 switch (c->mode) { 124 switch (c->mode) {
145 case 0: 125 case 0:
@@ -166,7 +146,7 @@ static int pit_get_out(struct kvm_pit *pit, int channel)
166 int out; 146 int out;
167 147
168 t = kpit_elapsed(pit, c, channel); 148 t = kpit_elapsed(pit, c, channel);
169 d = muldiv64(t, KVM_PIT_FREQ, NSEC_PER_SEC); 149 d = mul_u64_u32_div(t, KVM_PIT_FREQ, NSEC_PER_SEC);
170 150
171 switch (c->mode) { 151 switch (c->mode) {
172 default: 152 default:
@@ -338,7 +318,7 @@ static void create_pit_timer(struct kvm_pit *pit, u32 val, int is_period)
338 ps->flags & KVM_PIT_FLAGS_HPET_LEGACY) 318 ps->flags & KVM_PIT_FLAGS_HPET_LEGACY)
339 return; 319 return;
340 320
341 interval = muldiv64(val, NSEC_PER_SEC, KVM_PIT_FREQ); 321 interval = mul_u64_u32_div(val, NSEC_PER_SEC, KVM_PIT_FREQ);
342 322
343 pr_debug("create pit timer, interval is %llu nsec\n", interval); 323 pr_debug("create pit timer, interval is %llu nsec\n", interval);
344 324