Skip to content

Commit

Permalink
hpet: remove muldiv64()
Browse files Browse the repository at this point in the history
hpet defines a clock period in femtoseconds but
then converts it to nanoseconds to use the internal
timers.

We can define the period in nanoseconds and use it
directly, this allows to remove muldiv64().

We only need to convert the period to femtoseconds
to put it in internal hpet capability register.

Signed-off-by: Laurent Vivier <lvivier@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
  • Loading branch information
vivier committed Sep 25, 2015
1 parent 352c98e commit 0a4f924
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions hw/timer/hpet.c
Expand Up @@ -126,12 +126,12 @@ static uint32_t hpet_time_after64(uint64_t a, uint64_t b)

static uint64_t ticks_to_ns(uint64_t value)
{
return (muldiv64(value, HPET_CLK_PERIOD, FS_PER_NS));
return value * HPET_CLK_PERIOD;
}

static uint64_t ns_to_ticks(uint64_t value)
{
return (muldiv64(value, FS_PER_NS, HPET_CLK_PERIOD));
return value / HPET_CLK_PERIOD;
}

static uint64_t hpet_fixup_reg(uint64_t new, uint64_t old, uint64_t mask)
Expand Down Expand Up @@ -758,7 +758,7 @@ static void hpet_realize(DeviceState *dev, Error **errp)
/* 64-bit main counter; LegacyReplacementRoute. */
s->capability = 0x8086a001ULL;
s->capability |= (s->num_timers - 1) << HPET_ID_NUM_TIM_SHIFT;
s->capability |= ((HPET_CLK_PERIOD) << 32);
s->capability |= ((uint64_t)(HPET_CLK_PERIOD * FS_PER_NS) << 32);

qdev_init_gpio_in(dev, hpet_handle_legacy_irq, 2);
qdev_init_gpio_out(dev, &s->pit_enabled, 1);
Expand Down
4 changes: 2 additions & 2 deletions include/hw/timer/hpet.h
Expand Up @@ -16,9 +16,9 @@
#include "qom/object.h"

#define HPET_BASE 0xfed00000
#define HPET_CLK_PERIOD 10000000ULL /* 10000000 femtoseconds == 10ns*/
#define HPET_CLK_PERIOD 10 /* 10 ns*/

#define FS_PER_NS 1000000
#define FS_PER_NS 1000000 /* 1000000 femtoseconds == 1 ns */
#define HPET_MIN_TIMERS 3
#define HPET_MAX_TIMERS 32

Expand Down

0 comments on commit 0a4f924

Please sign in to comment.