summaryrefslogtreecommitdiff
path: root/hw/timer
diff options
context:
space:
mode:
authorPeter Maydell <peter.maydell@linaro.org>2016-07-12 12:34:41 +0100
committerPeter Maydell <peter.maydell@linaro.org>2016-07-12 12:34:41 +0100
commit74e1b782b34e280b06a90f61fdbac5a046cbe491 (patch)
tree4e707525686a8c338ec5b013189a5f0d586e89a3 /hw/timer
parentc1ac514a0444cae0a822dd9a0e60ac77918c102c (diff)
parentcdc46fab07a122dfcc8a1054510a68d936ae3440 (diff)
downloadqemu-74e1b782b34e280b06a90f61fdbac5a046cbe491.tar.gz
Merge remote-tracking branch 'remotes/lalrae/tags/mips-20160712' into staging
MIPS patches 2016-07-12 Changes: * support 10-bit ASIDs * MIPS64R6-generic renamed to I6400 * initial GIC support * implement RESET_BASE register in CM GCR # gpg: Signature made Tue 12 Jul 2016 11:49:50 BST # gpg: using RSA key 0x52118E3C0B29DA6B # gpg: Good signature from "Leon Alrae <leon.alrae@imgtec.com>" # Primary key fingerprint: 8DD3 2F98 5495 9D66 35D4 4FC0 5211 8E3C 0B29 DA6B * remotes/lalrae/tags/mips-20160712: target-mips: enable 10-bit ASIDs in I6400 CPU target-mips: support CP0.Config4.AE bit target-mips: change ASID type to hold more than 8 bits target-mips: add ASID mask field and replace magic values target-mips: replace MIPS64R6-generic with the real I6400 CPU model hw/mips_cmgcr: implement RESET_BASE register in CM GCR hw/mips_cpc: make VP correctly start from the reset vector target-mips: add exception base to MIPS CPU hw/mips/cps: create GIC block inside CPS hw/mips: implement Global Interrupt Controller hw/mips: implement GIC Interval Timer Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'hw/timer')
-rw-r--r--hw/timer/Makefile.objs1
-rw-r--r--hw/timer/mips_gictimer.c142
2 files changed, 143 insertions, 0 deletions
diff --git a/hw/timer/Makefile.objs b/hw/timer/Makefile.objs
index 003c14fa26..7ba8c23c75 100644
--- a/hw/timer/Makefile.objs
+++ b/hw/timer/Makefile.objs
@@ -26,6 +26,7 @@ obj-$(CONFIG_OMAP) += omap_synctimer.o
obj-$(CONFIG_PXA2XX) += pxa2xx_timer.o
obj-$(CONFIG_SH4) += sh_timer.o
obj-$(CONFIG_DIGIC) += digic-timer.o
+obj-$(CONFIG_MIPS_CPS) += mips_gictimer.o
obj-$(CONFIG_MC146818RTC) += mc146818rtc.o
diff --git a/hw/timer/mips_gictimer.c b/hw/timer/mips_gictimer.c
new file mode 100644
index 0000000000..3698889475
--- /dev/null
+++ b/hw/timer/mips_gictimer.c
@@ -0,0 +1,142 @@
+/*
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License. See the file "COPYING" in the main directory of this archive
+ * for more details.
+ *
+ * Copyright (C) 2016 Imagination Technologies
+ */
+
+#include "qemu/osdep.h"
+#include "hw/hw.h"
+#include "hw/sysbus.h"
+#include "qemu/timer.h"
+#include "hw/timer/mips_gictimer.h"
+
+#define TIMER_PERIOD 10 /* 10 ns period for 100 Mhz frequency */
+
+static void gic_vptimer_update(MIPSGICTimerState *gictimer,
+ uint32_t vp_index, uint64_t now)
+{
+ uint64_t next;
+ uint32_t wait;
+
+ wait = gictimer->vptimers[vp_index].comparelo - gictimer->sh_counterlo -
+ (uint32_t)(now / TIMER_PERIOD);
+ next = now + (uint64_t)wait * TIMER_PERIOD;
+
+ timer_mod(gictimer->vptimers[vp_index].qtimer, next);
+}
+
+static void gic_vptimer_expire(MIPSGICTimerState *gictimer, uint32_t vp_index,
+ uint64_t now)
+{
+ if (gictimer->countstop) {
+ /* timer stopped */
+ return;
+ }
+ gictimer->cb(gictimer->opaque, vp_index);
+ gic_vptimer_update(gictimer, vp_index, now);
+}
+
+static void gic_vptimer_cb(void *opaque)
+{
+ MIPSGICTimerVPState *vptimer = opaque;
+ MIPSGICTimerState *gictimer = vptimer->gictimer;
+ gic_vptimer_expire(gictimer, vptimer->vp_index,
+ qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL));
+}
+
+uint32_t mips_gictimer_get_sh_count(MIPSGICTimerState *gictimer)
+{
+ int i;
+ if (gictimer->countstop) {
+ return gictimer->sh_counterlo;
+ } else {
+ uint64_t now;
+ now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
+ for (i = 0; i < gictimer->num_vps; i++) {
+ if (timer_pending(gictimer->vptimers[i].qtimer)
+ && timer_expired(gictimer->vptimers[i].qtimer, now)) {
+ /* The timer has already expired. */
+ gic_vptimer_expire(gictimer, i, now);
+ }
+ }
+ return gictimer->sh_counterlo + (uint32_t)(now / TIMER_PERIOD);
+ }
+}
+
+void mips_gictimer_store_sh_count(MIPSGICTimerState *gictimer, uint64_t count)
+{
+ int i;
+ uint64_t now;
+
+ if (gictimer->countstop || !gictimer->vptimers[0].qtimer) {
+ gictimer->sh_counterlo = count;
+ } else {
+ /* Store new count register */
+ now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
+ gictimer->sh_counterlo = count - (uint32_t)(now / TIMER_PERIOD);
+ /* Update timer timer */
+ for (i = 0; i < gictimer->num_vps; i++) {
+ gic_vptimer_update(gictimer, i, now);
+ }
+ }
+}
+
+uint32_t mips_gictimer_get_vp_compare(MIPSGICTimerState *gictimer,
+ uint32_t vp_index)
+{
+ return gictimer->vptimers[vp_index].comparelo;
+}
+
+void mips_gictimer_store_vp_compare(MIPSGICTimerState *gictimer,
+ uint32_t vp_index, uint64_t compare)
+{
+ gictimer->vptimers[vp_index].comparelo = (uint32_t) compare;
+ gic_vptimer_update(gictimer, vp_index,
+ qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL));
+}
+
+uint8_t mips_gictimer_get_countstop(MIPSGICTimerState *gictimer)
+{
+ return gictimer->countstop;
+}
+
+void mips_gictimer_start_count(MIPSGICTimerState *gictimer)
+{
+ gictimer->countstop = 0;
+ mips_gictimer_store_sh_count(gictimer, gictimer->sh_counterlo);
+}
+
+void mips_gictimer_stop_count(MIPSGICTimerState *gictimer)
+{
+ int i;
+
+ gictimer->countstop = 1;
+ /* Store the current value */
+ gictimer->sh_counterlo +=
+ (uint32_t)(qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) / TIMER_PERIOD);
+ for (i = 0; i < gictimer->num_vps; i++) {
+ timer_del(gictimer->vptimers[i].qtimer);
+ }
+}
+
+MIPSGICTimerState *mips_gictimer_init(void *opaque, uint32_t nvps,
+ MIPSGICTimerCB *cb)
+{
+ int i;
+ MIPSGICTimerState *gictimer = g_new(MIPSGICTimerState, 1);
+ gictimer->vptimers = g_new(MIPSGICTimerVPState, nvps);
+ gictimer->countstop = 1;
+ gictimer->num_vps = nvps;
+ gictimer->opaque = opaque;
+ gictimer->cb = cb;
+ for (i = 0; i < nvps; i++) {
+ gictimer->vptimers[i].gictimer = gictimer;
+ gictimer->vptimers[i].vp_index = i;
+ gictimer->vptimers[i].qtimer = timer_new_ns(QEMU_CLOCK_VIRTUAL,
+ &gic_vptimer_cb,
+ &gictimer->vptimers[i]);
+ }
+ return gictimer;
+}