qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Edgar E. Iglesias" <edgar.iglesias@gmail.com>
To: qemu-devel@nongnu.org, peter.maydell@linaro.org
Cc: edgar.iglesias@xilinx.com, serge.fdrv@gmail.com,
	alex.bennee@linaro.org, agraf@suse.de, greg.bellows@linaro.org
Subject: [Qemu-devel] [PATCH v1 14/18] target-arm: Add CNTVOFF_EL2
Date: Wed, 13 May 2015 16:52:39 +1000	[thread overview]
Message-ID: <1431499963-1019-15-git-send-email-edgar.iglesias@gmail.com> (raw)
In-Reply-To: <1431499963-1019-1-git-send-email-edgar.iglesias@gmail.com>

From: "Edgar E. Iglesias" <edgar.iglesias@xilinx.com>

Signed-off-by: Edgar E. Iglesias <edgar.iglesias@xilinx.com>
---
 target-arm/cpu.h    |  1 +
 target-arm/helper.c | 41 +++++++++++++++++++++++++++++++++++------
 2 files changed, 36 insertions(+), 6 deletions(-)

diff --git a/target-arm/cpu.h b/target-arm/cpu.h
index 6922e54..73a4ce8 100644
--- a/target-arm/cpu.h
+++ b/target-arm/cpu.h
@@ -355,6 +355,7 @@ typedef struct CPUARMState {
         };
         uint64_t c14_cntfrq; /* Counter Frequency register */
         uint64_t c14_cntkctl; /* Timer Control register */
+        uint64_t cntvoff_el2; /* Counter Virtual Offset register */
         ARMGenericTimer c14_timer[NUM_GTIMERS];
         uint32_t c15_cpar; /* XScale Coprocessor Access Register */
         uint32_t c15_ticonfig; /* TI925T configuration byte.  */
diff --git a/target-arm/helper.c b/target-arm/helper.c
index 5b7c195..380887a 100644
--- a/target-arm/helper.c
+++ b/target-arm/helper.c
@@ -1212,9 +1212,11 @@ static void gt_recalc_timer(ARMCPU *cpu, int timeridx)
         /* Timer enabled: calculate and set current ISTATUS, irq, and
          * reset timer to when ISTATUS next has to change
          */
+        uint64_t offset = timeridx == GTIMER_VIRT ?
+                                      cpu->env.cp15.cntvoff_el2 : 0;
         uint64_t count = gt_get_countervalue(&cpu->env);
         /* Note that this must be unsigned 64 bit arithmetic: */
-        int istatus = count >= gt->cval;
+        int istatus = (int64_t) (count - offset - gt->cval) >= 0;
         uint64_t nexttick;
 
         gt->ctl = deposit32(gt->ctl, 2, 1, istatus);
@@ -1225,7 +1227,7 @@ static void gt_recalc_timer(ARMCPU *cpu, int timeridx)
             nexttick = UINT64_MAX;
         } else {
             /* Next transition is when we hit cval */
-            nexttick = gt->cval;
+            nexttick = gt->cval + offset;
         }
         /* Note that the desired next expiry time might be beyond the
          * signed-64-bit range of a QEMUTimer -- in this case we just
@@ -1257,6 +1259,11 @@ static uint64_t gt_cnt_read(CPUARMState *env, const ARMCPRegInfo *ri)
     return gt_get_countervalue(env);
 }
 
+static uint64_t gt_virt_cnt_read(CPUARMState *env, const ARMCPRegInfo *ri)
+{
+    return gt_get_countervalue(env) - env->cp15.cntvoff_el2;
+}
+
 static void gt_cval_write(CPUARMState *env, const ARMCPRegInfo *ri,
                           uint64_t value)
 {
@@ -1269,17 +1276,19 @@ static void gt_cval_write(CPUARMState *env, const ARMCPRegInfo *ri,
 static uint64_t gt_tval_read(CPUARMState *env, const ARMCPRegInfo *ri)
 {
     int timeridx = ri->crm & 1;
+    uint64_t offset = timeridx == GTIMER_VIRT ? env->cp15.cntvoff_el2 : 0;
 
     return (uint32_t)(env->cp15.c14_timer[timeridx].cval -
-                      gt_get_countervalue(env));
+                      gt_get_countervalue(env) - offset);
 }
 
 static void gt_tval_write(CPUARMState *env, const ARMCPRegInfo *ri,
                           uint64_t value)
 {
     int timeridx = ri->crm & 1;
+    uint64_t offset = timeridx == GTIMER_VIRT ? env->cp15.cntvoff_el2 : 0;
 
-    env->cp15.c14_timer[timeridx].cval = gt_get_countervalue(env) +
+    env->cp15.c14_timer[timeridx].cval = gt_get_countervalue(env) - offset +
                                          sextract64(value, 0, 32);
     gt_recalc_timer(arm_env_get_cpu(env), timeridx);
 }
@@ -1304,6 +1313,15 @@ static void gt_ctl_write(CPUARMState *env, const ARMCPRegInfo *ri,
     }
 }
 
+static void gt_cntvoff_write(CPUARMState *env, const ARMCPRegInfo *ri,
+                              uint64_t value)
+{
+    ARMCPU *cpu = arm_env_get_cpu(env);
+
+    raw_write(env, ri, value);
+    gt_recalc_timer(cpu, GTIMER_VIRT);
+}
+
 void arm_gt_ptimer_cb(void *opaque)
 {
     ARMCPU *cpu = opaque;
@@ -1413,13 +1431,13 @@ static const ARMCPRegInfo generic_timer_cp_reginfo[] = {
     { .name = "CNTVCT", .cp = 15, .crm = 14, .opc1 = 1,
       .access = PL0_R, .type = ARM_CP_64BIT | ARM_CP_NO_RAW | ARM_CP_IO,
       .accessfn = gt_vct_access,
-      .readfn = gt_cnt_read, .resetfn = arm_cp_reset_ignore,
+      .readfn = gt_virt_cnt_read, .resetfn = arm_cp_reset_ignore,
     },
     { .name = "CNTVCT_EL0", .state = ARM_CP_STATE_AA64,
       .opc0 = 3, .opc1 = 3, .crn = 14, .crm = 0, .opc2 = 2,
       .access = PL0_R, .type = ARM_CP_NO_RAW | ARM_CP_IO,
       .accessfn = gt_vct_access,
-      .readfn = gt_cnt_read, .resetfn = gt_cnt_reset,
+      .readfn = gt_virt_cnt_read, .resetfn = gt_cnt_reset,
     },
     /* Comparison value, indicating when the timer goes off */
     { .name = "CNTP_CVAL", .cp = 15, .crm = 14, .opc1 = 2,
@@ -2553,6 +2571,10 @@ static const ARMCPRegInfo v8_el3_no_el2_cp_reginfo[] = {
       .opc0 = 3, .opc1 = 4, .opc2 = 2, .crn = 13, .crm = 0,
       .access = PL2_RW,
       .readfn = arm_cp_read_zero, .writefn = arm_cp_write_ignore },
+    { .name = "CNTVOFF_EL2", .state = ARM_CP_STATE_AA64,
+      .opc0 = 3, .opc1 = 4, .crn = 14, .crm = 0, .opc2 = 3,
+      .access = PL2_RW,
+      .readfn = arm_cp_read_zero, .writefn = arm_cp_write_ignore },
     REGINFO_SENTINEL
 };
 
@@ -2661,6 +2683,13 @@ static const ARMCPRegInfo v8_el2_cp_reginfo[] = {
       .opc0 = 3, .opc1 = 4, .opc2 = 2, .crn = 13, .crm = 0,
       .access = PL2_RW, .resetvalue = 0,
       .fieldoffset = offsetof(CPUARMState, cp15.tpidr_el[2]) },
+#ifndef CONFIG_USER_ONLY
+    { .name = "CNTVOFF_EL2", .state = ARM_CP_STATE_AA64,
+      .opc0 = 3, .opc1 = 4, .crn = 14, .crm = 0, .opc2 = 3,
+      .access = PL2_RW,
+      .writefn = gt_cntvoff_write,
+      .fieldoffset = offsetof(CPUARMState, cp15.cntvoff_el2) },
+#endif
     REGINFO_SENTINEL
 };
 
-- 
1.9.1

  parent reply	other threads:[~2015-05-13  7:05 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-13  6:52 [Qemu-devel] [PATCH v1 00/18] arm: Steps towards EL2 support round 3 Edgar E. Iglesias
2015-05-13  6:52 ` [Qemu-devel] [PATCH v1 01/18] target-arm: Correct accessfn for CNTP_{CT}VAL_EL0 Edgar E. Iglesias
2015-05-13  6:52 ` [Qemu-devel] [PATCH v1 02/18] target-arm: Correct accessfn for CNTV_TVAL_EL0 Edgar E. Iglesias
2015-05-13  6:52 ` [Qemu-devel] [PATCH v1 03/18] target-arm: Remove unneeded '+' Edgar E. Iglesias
2015-05-14  9:11   ` Alex Bennée
2015-05-13  6:52 ` [Qemu-devel] [PATCH v1 04/18] target-arm: Route timer access traps to EL1 Edgar E. Iglesias
2015-05-18 18:41   ` Peter Maydell
2015-05-18 23:27     ` Edgar E. Iglesias
2015-05-13  6:52 ` [Qemu-devel] [PATCH v1 05/18] target-arm: Add MAIR_EL2 Edgar E. Iglesias
2015-05-13  7:52   ` Sergey Fedorov
2015-05-13 11:05     ` Edgar E. Iglesias
2015-05-13 11:09       ` Sergey Fedorov
2015-05-18 18:49   ` Peter Maydell
2015-05-13  6:52 ` [Qemu-devel] [PATCH v1 06/18] target-arm: Add TCR_EL2 Edgar E. Iglesias
2015-05-18 18:51   ` Peter Maydell
2015-05-13  6:52 ` [Qemu-devel] [PATCH v1 07/18] target-arm: Add SCTLR_EL2 Edgar E. Iglesias
2015-05-13  6:52 ` [Qemu-devel] [PATCH v1 08/18] target-arm: Add TTBR0_EL2 Edgar E. Iglesias
2015-05-13  6:52 ` [Qemu-devel] [PATCH v1 09/18] target-arm: Add TLBI_ALLE1{IS} Edgar E. Iglesias
2015-05-13  6:52 ` [Qemu-devel] [PATCH v1 10/18] target-arm: Add TLBIALLE2 Edgar E. Iglesias
2015-05-13  6:52 ` [Qemu-devel] [PATCH v1 11/18] target-arm: Add TPIDR_EL2 Edgar E. Iglesias
2015-05-13  6:52 ` [Qemu-devel] [PATCH v1 12/18] target-arm: Add TLBI_VAE2{IS} Edgar E. Iglesias
2015-05-13  6:52 ` [Qemu-devel] [PATCH v1 13/18] target-arm: Add access to PAR_EL1 Edgar E. Iglesias
2015-05-13  6:52 ` Edgar E. Iglesias [this message]
2015-05-13  6:52 ` [Qemu-devel] [PATCH v1 15/18] target-arm: Add CNTHCTL_EL2 Edgar E. Iglesias
2015-05-13  6:52 ` [Qemu-devel] [PATCH v1 16/18] target-arm: Pass timeridx as argument to various timer functions Edgar E. Iglesias
2015-05-13  6:52 ` [Qemu-devel] [PATCH v1 17/18] target-arm: Add HYP timer Edgar E. Iglesias
2015-05-13  6:52 ` [Qemu-devel] [PATCH v1 18/18] hw/arm/virt: Connect the Hypervisor timer Edgar E. Iglesias
2015-05-18 18:53 ` [Qemu-devel] [PATCH v1 00/18] arm: Steps towards EL2 support round 3 Peter Maydell
2015-05-18 23:38   ` Edgar E. Iglesias

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1431499963-1019-15-git-send-email-edgar.iglesias@gmail.com \
    --to=edgar.iglesias@gmail.com \
    --cc=agraf@suse.de \
    --cc=alex.bennee@linaro.org \
    --cc=edgar.iglesias@xilinx.com \
    --cc=greg.bellows@linaro.org \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=serge.fdrv@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).