Skip to contentSkip to conversation

arm: Steps towards EL2 support round 3

PATCH Superseded Edgar E. Iglesias 4 participants 29 messages May 13, 2015 – May 18, 2015

v1 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

cover arm: Steps towards EL2 support round 3

From: "Edgar E. Iglesias" <[email protected]>

Hi,

This is round 3 of our series towards support for EL2 for AArch64. This series depends on Gregs exception target el infrastructure patch series that is not yet upstream.

P0 - P2 are fixes without dependencies.
P3 is probably something that should be fixed in Gregs series. P4 and on add a bunch of EL2 regs and timer features.

Comments welcome!

Best regards,
Edgar

Edgar E. Iglesias (18):
target-arm: Correct accessfn for CNTP_{CT}VAL_EL0
target-arm: Correct accessfn for CNTV_TVAL_EL0
target-arm: Remove unneeded '+'
target-arm: Route timer access traps to EL1
target-arm: Add MAIR_EL2
target-arm: Add TCR_EL2
target-arm: Add SCTLR_EL2
target-arm: Add TTBR0_EL2
target-arm: Add TLBI_ALLE1{IS}
target-arm: Add TLBIALLE2
target-arm: Add TPIDR_EL2
target-arm: Add TLBI_VAE2{IS}
target-arm: Add access to PAR_EL1
target-arm: Add CNTVOFF_EL2
target-arm: Add CNTHCTL_EL2
target-arm: Pass timeridx as argument to various timer functions
target-arm: Add HYP timer
hw/arm/virt: Connect the Hypervisor timer

 hw/arm/virt.c        |   3 +
 target-arm/cpu-qom.h |   1 +
 target-arm/cpu.c     |   2 +
 target-arm/cpu.h     |   5 +-
 target-arm/helper.c  | 309 +++++++++++++++++++++++++++++++++++++++++++++------
 5 files changed, 288 insertions(+), 32 deletions(-)
Signature · 1 line
1.9.1
#1 lore raw

PATCH 1/18 target-arm: Correct accessfn for CNTP_{CT}VAL_EL0

From: "Edgar E. Iglesias" <[email protected]>

---
 target-arm/helper.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
target-arm/helper.c +2 -1
index 752a1da..20c4abb 100644
@@ -1381,6 +1381,7 @@ static const ARMCPRegInfo generic_timer_cp_reginfo[] = {
     { .name = "CNTP_TVAL_EL0", .state = ARM_CP_STATE_AA64,
       .opc0 = 3, .opc1 = 3, .crn = 14, .crm = 2, .opc2 = 0,
       .type = ARM_CP_NO_RAW | ARM_CP_IO, .access = PL1_RW | PL0_R,
+      .accessfn = gt_ptimer_access,
       .readfn = gt_tval_read, .writefn = gt_tval_write,
     },
     { .name = "CNTV_TVAL", .cp = 15, .crn = 14, .crm = 3, .opc1 = 0, .opc2 = 0,
@@ -1429,7 +1430,7 @@ static const ARMCPRegInfo generic_timer_cp_reginfo[] = {
       .access = PL1_RW | PL0_R,
       .type = ARM_CP_IO,
       .fieldoffset = offsetof(CPUARMState, cp15.c14_timer[GTIMER_PHYS].cval),
-      .resetvalue = 0, .accessfn = gt_vtimer_access,
+      .resetvalue = 0, .accessfn = gt_ptimer_access,
       .writefn = gt_cval_write, .raw_writefn = raw_write,
     },
     { .name = "CNTV_CVAL", .cp = 15, .crm = 14, .opc1 = 3,
Signature · 1 line
1.9.1
#2 lore raw

PATCH 2/18 target-arm: Correct accessfn for CNTV_TVAL_EL0

In reply to Edgar E. Iglesias

From: "Edgar E. Iglesias" <[email protected]>

---
 target-arm/helper.c | 1 +
 1 file changed, 1 insertion(+)
target-arm/helper.c +1 -0
index 20c4abb..7139ed2 100644
@@ -1392,6 +1392,7 @@ static const ARMCPRegInfo generic_timer_cp_reginfo[] = {
     { .name = "CNTV_TVAL_EL0", .state = ARM_CP_STATE_AA64,
       .opc0 = 3, .opc1 = 3, .crn = 14, .crm = 3, .opc2 = 0,
       .type = ARM_CP_NO_RAW | ARM_CP_IO, .access = PL1_RW | PL0_R,
+      .accessfn = gt_vtimer_access,
       .readfn = gt_tval_read, .writefn = gt_tval_write,
     },
     /* The counter itself */
Signature · 1 line
1.9.1
#3 lore raw

PATCH 3/18 target-arm: Remove unneeded '+'

In reply to Edgar E. Iglesias

From: "Edgar E. Iglesias" <[email protected]>

---
 target-arm/helper.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target-arm/helper.c +1 -1
index 7139ed2..a4bab78 100644
@@ -1277,7 +1277,7 @@ static void gt_tval_write(CPUARMState *env, const ARMCPRegInfo *ri,
     int timeridx = ri->crm & 1;
 
     env->cp15.c14_timer[timeridx].cval = gt_get_countervalue(env) +
-        + sextract64(value, 0, 32);
+                                         sextract64(value, 0, 32);
     gt_recalc_timer(arm_env_get_cpu(env), timeridx);
 }
 
Signature · 1 line
1.9.1
Reviewed-by on v1 3/18
#4 lore raw

Re: [Qemu-devel] [PATCH v1 03/18] target-arm: Remove unneeded '+'

Quoted 3 lines · Edgar E. Iglesias

From: "Edgar E. Iglesias" <[email protected]>

Quoted 16 lines
---
 target-arm/helper.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target-arm/helper.c +1 -1
index 7139ed2..a4bab78 100644
@@ -1277,7 +1277,7 @@ static void gt_tval_write(CPUARMState *env, const ARMCPRegInfo *ri,
     int timeridx = ri->crm & 1;
 
     env->cp15.c14_timer[timeridx].cval = gt_get_countervalue(env) +
-        + sextract64(value, 0, 32);
+                                         sextract64(value, 0, 32);
     gt_recalc_timer(arm_env_get_cpu(env), timeridx);
 }
Signature · 1 line
Alex Bennée
#5 lore raw

PATCH 4/18 target-arm: Route timer access traps to EL1

In reply to Edgar E. Iglesias

From: "Edgar E. Iglesias" <[email protected]>

---
 target-arm/helper.c | 3 +++
 1 file changed, 3 insertions(+)
target-arm/helper.c +3 -0
index a4bab78..d849b30 100644
@@ -1147,6 +1147,7 @@ static CPAccessResult gt_cntfrq_access(CPUARMState *env, const ARMCPRegInfo *ri)
 {
     /* CNTFRQ: not visible from PL0 if both PL0PCTEN and PL0VCTEN are zero */
     if (arm_current_el(env) == 0 && !extract32(env->cp15.c14_cntkctl, 0, 2)) {
+        env->exception.target_el = 1;
         return CP_ACCESS_TRAP;
     }
     return CP_ACCESS_OK;
@@ -1157,6 +1158,7 @@ static CPAccessResult gt_counter_access(CPUARMState *env, int timeridx)
     /* CNT[PV]CT: not visible from PL0 if ELO[PV]CTEN is zero */
     if (arm_current_el(env) == 0 &&
         !extract32(env->cp15.c14_cntkctl, timeridx, 1)) {
+        env->exception.target_el = 1;
         return CP_ACCESS_TRAP;
     }
     return CP_ACCESS_OK;
@@ -1169,6 +1171,7 @@ static CPAccessResult gt_timer_access(CPUARMState *env, int timeridx)
      */
     if (arm_current_el(env) == 0 &&
         !extract32(env->cp15.c14_cntkctl, 9 - timeridx, 1)) {
+        env->exception.target_el = 1;
         return CP_ACCESS_TRAP;
     }
     return CP_ACCESS_OK;
Signature · 1 line
1.9.1
#6 lore raw

Re: [Qemu-devel] [PATCH v1 04/18] target-arm: Route timer access traps to EL1

Quoted 28 lines · Edgar E. Iglesias

From: "Edgar E. Iglesias" <[email protected]>

---
 target-arm/helper.c | 3 +++
 1 file changed, 3 insertions(+)
target-arm/helper.c +2 -0
index a4bab78..d849b30 100644
@@ -1147,6 +1147,7 @@ static CPAccessResult gt_cntfrq_access(CPUARMState *env, const ARMCPRegInfo *ri)
 {
     /* CNTFRQ: not visible from PL0 if both PL0PCTEN and PL0VCTEN are zero */
     if (arm_current_el(env) == 0 && !extract32(env->cp15.c14_cntkctl, 0, 2)) {
+        env->exception.target_el = 1;
         return CP_ACCESS_TRAP;
     }
     return CP_ACCESS_OK;
@@ -1157,6 +1158,7 @@ static CPAccessResult gt_counter_access(CPUARMState *env, int timeridx)
     /* CNT[PV]CT: not visible from PL0 if ELO[PV]CTEN is zero */
     if (arm_current_el(env) == 0 &&
         !extract32(env->cp15.c14_cntkctl, timeridx, 1)) {
+        env->exception.target_el = 1;
         return CP_ACCESS_TRAP;
     }
     return CP_ACCESS_OK;

target-arm/helper.c static CPAccessResult gt_timer_access(CPUARMState *env, int timeridx) · line 1177

Quoted 7 lines
target-arm/helper.c +1 -0
@@ -1169,6 +1171,7 @@ static CPAccessResult gt_timer_access(CPUARMState *env, int timeridx)
      */
     if (arm_current_el(env) == 0 &&
         !extract32(env->cp15.c14_cntkctl, 9 - timeridx, 1)) {
+        env->exception.target_el = 1;
         return CP_ACCESS_TRAP;
     }
     return CP_ACCESS_OK;

If EL3 is 32-bit and we're in Secure EL0 then the correct target_el is 3, not 1, so what you actually want here is exception_target_el().

More generally, this seems to be a really easy mistake to make with access functions. At the moment we come pretty close to being able to say "always set both exception.target_el and exception.syndrome in the same place in the code". So I think the correct fix is

target-arm/op_helper.c +0 -0
@@ -333,9 +333,11 @@ void HELPER(access_check_cp_reg)(CPUARMState

*env, void *rip, uint32_t syndrome)

         return;
     case CP_ACCESS_TRAP:
         env->exception.syndrome = syndrome;
+        env->target_el = exception_target_el(env);
         break;
     case CP_ACCESS_TRAP_UNCATEGORIZED:
         env->exception.syndrome = syn_uncategorized();
+        env->target_el = exception_target_el(env);
         break;
     default:
         g_assert_not_reached();

in the "Extend helpers to route exceptions" patch. If we get any registers where the correct target EL is something other than that, we should have new CP_ACCESS_* enums for them.

Then the only place where we don't set both syndrome and target_el at the same time are:
* msr_i_pstate is failing to set a syndrome
* arm_debug_excp_handler() needs to set the target_el to the debug target el
* arm_cpu_handle_mmu_fault should set the target_el
* the FIQ/IRQ/VIRQ/VFIQ paths in arm_cpu_exec_interrupt don't set syndrome, because they're interrupts and there's no syndrome info

Note that the first three of these are all bugs, which is a nice demonstration of the utility of the rule. I think I'd also like to make the FIQ&c code set exception.syndrome to an invalid value, because then we can probably write some assertions for exception entry (and also because then we're consistent about things.)

That seems like more than I really feel I can justify just fixing in target-arm.next, so I think I'll drop Greg's patches 1..3 from target-arm.next and send them out as part of a series which does the above changes.

thanks
-- PMM

#7 lore raw

Re: [Qemu-devel] [PATCH v1 04/18] target-arm: Route timer access traps to EL1

Quoted 85 lines · Peter Maydell
Quoted 28 lines · Edgar E. Iglesias

From: "Edgar E. Iglesias" <[email protected]>

---
 target-arm/helper.c | 3 +++
 1 file changed, 3 insertions(+)
target-arm/helper.c +2 -0
index a4bab78..d849b30 100644
@@ -1147,6 +1147,7 @@ static CPAccessResult gt_cntfrq_access(CPUARMState *env, const ARMCPRegInfo *ri)
 {
     /* CNTFRQ: not visible from PL0 if both PL0PCTEN and PL0VCTEN are zero */
     if (arm_current_el(env) == 0 && !extract32(env->cp15.c14_cntkctl, 0, 2)) {
+        env->exception.target_el = 1;
         return CP_ACCESS_TRAP;
     }
     return CP_ACCESS_OK;
@@ -1157,6 +1158,7 @@ static CPAccessResult gt_counter_access(CPUARMState *env, int timeridx)
     /* CNT[PV]CT: not visible from PL0 if ELO[PV]CTEN is zero */
     if (arm_current_el(env) == 0 &&
         !extract32(env->cp15.c14_cntkctl, timeridx, 1)) {
+        env->exception.target_el = 1;
         return CP_ACCESS_TRAP;
     }
     return CP_ACCESS_OK;

target-arm/helper.c static CPAccessResult gt_timer_access(CPUARMState *env, int timeridx) · line 1177

Quoted 7 lines
target-arm/helper.c +1 -0
@@ -1169,6 +1171,7 @@ static CPAccessResult gt_timer_access(CPUARMState *env, int timeridx)
      */
     if (arm_current_el(env) == 0 &&
         !extract32(env->cp15.c14_cntkctl, 9 - timeridx, 1)) {
+        env->exception.target_el = 1;
         return CP_ACCESS_TRAP;
     }
     return CP_ACCESS_OK;

If EL3 is 32-bit and we're in Secure EL0 then the correct target_el is 3, not 1, so what you actually want here is exception_target_el().

More generally, this seems to be a really easy mistake to make with access functions. At the moment we come pretty close to being able to say "always set both exception.target_el and exception.syndrome in the same place in the code". So I think the correct fix is

target-arm/op_helper.c +2 -0
@@ -333,9 +333,11 @@ void HELPER(access_check_cp_reg)(CPUARMState
 *env, void *rip, uint32_t syndrome)
         return;
     case CP_ACCESS_TRAP:
         env->exception.syndrome = syndrome;
+        env->target_el = exception_target_el(env);
         break;
     case CP_ACCESS_TRAP_UNCATEGORIZED:
         env->exception.syndrome = syn_uncategorized();
+        env->target_el = exception_target_el(env);
         break;
     default:
         g_assert_not_reached();

in the "Extend helpers to route exceptions" patch. If we get any registers where the correct target EL is something other than that, we should have new CP_ACCESS_* enums for them.

Then the only place where we don't set both syndrome and target_el at the same time are:
* msr_i_pstate is failing to set a syndrome
* arm_debug_excp_handler() needs to set the target_el to the debug target el
* arm_cpu_handle_mmu_fault should set the target_el
* the FIQ/IRQ/VIRQ/VFIQ paths in arm_cpu_exec_interrupt don't set syndrome, because they're interrupts and there's no syndrome info

Note that the first three of these are all bugs, which is a nice demonstration of the utility of the rule. I think I'd also like to make the FIQ&c code set exception.syndrome to an invalid value, because then we can probably write some assertions for exception entry (and also because then we're consistent about things.)

Quoted 5 lines

That seems like more than I really feel I can justify just fixing in target-arm.next, so I think I'll drop Greg's patches 1..3 from target-arm.next and send them out as part of a series which does the above changes.

Sounds good, thanks!

Cheers,
Edgar

#8 lore raw

PATCH 5/18 target-arm: Add MAIR_EL2

In reply to Edgar E. Iglesias

From: "Edgar E. Iglesias" <[email protected]>

---
 target-arm/helper.c | 8 ++++++++
 1 file changed, 8 insertions(+)
target-arm/helper.c +8 -0
index d849b30..168549c 100644
@@ -2520,6 +2520,10 @@ static const ARMCPRegInfo v8_el3_no_el2_cp_reginfo[] = {
       .cp = 15, .opc1 = 4, .crn = 1, .crm = 1, .opc2 = 2,
       .access = PL2_RW, .accessfn = cptr_access, .resetvalue = 0,
       .readfn = arm_cp_read_zero, .writefn = arm_cp_write_ignore },
+    { .name = "MAIR_EL2", .state = ARM_CP_STATE_AA64,
+      .opc0 = 3, .opc1 = 4, .crn = 10, .crm = 2, .opc2 = 0,
+      .access = PL2_RW,
+      .readfn = arm_cp_read_zero, .writefn = arm_cp_write_ignore },
     REGINFO_SENTINEL
 };
 
@@ -2595,6 +2599,10 @@ static const ARMCPRegInfo v8_el2_cp_reginfo[] = {
       .cp = 15, .opc1 = 4, .crn = 1, .crm = 1, .opc2 = 2,
       .access = PL2_RW, .accessfn = cptr_access, .resetvalue = 0,
       .fieldoffset = offsetof(CPUARMState, cp15.cptr_el[2]) },
+    { .name = "MAIR_EL2", .state = ARM_CP_STATE_AA64,
+      .opc0 = 3, .opc1 = 4, .crn = 10, .crm = 2, .opc2 = 0,
+      .access = PL2_RW, .fieldoffset = offsetof(CPUARMState, cp15.mair_el[2]),
+      .resetvalue = 0 },
     REGINFO_SENTINEL
 };
 
Signature · 1 line
1.9.1
#9 lore raw

Re: [Qemu-devel] [PATCH v1 05/18] target-arm: Add MAIR_EL2

Quoted 23 lines · Edgar E. Iglesias

From: "Edgar E. Iglesias" <[email protected]>

---
 target-arm/helper.c | 8 ++++++++
 1 file changed, 8 insertions(+)
target-arm/helper.c +4 -0
index d849b30..168549c 100644
@@ -2520,6 +2520,10 @@ static const ARMCPRegInfo v8_el3_no_el2_cp_reginfo[] = {
       .cp = 15, .opc1 = 4, .crn = 1, .crm = 1, .opc2 = 2,
       .access = PL2_RW, .accessfn = cptr_access, .resetvalue = 0,
       .readfn = arm_cp_read_zero, .writefn = arm_cp_write_ignore },
+    { .name = "MAIR_EL2", .state = ARM_CP_STATE_AA64,
+      .opc0 = 3, .opc1 = 4, .crn = 10, .crm = 2, .opc2 = 0,
+      .access = PL2_RW,
+      .readfn = arm_cp_read_zero, .writefn = arm_cp_write_ignore },
     REGINFO_SENTINEL
 };
 

target-arm/helper.c static const ARMCPRegInfo v8_el2_cp_reginfo[] = { · line 2608

Quoted 10 lines
target-arm/helper.c +4 -0
@@ -2595,6 +2599,10 @@ static const ARMCPRegInfo v8_el2_cp_reginfo[] = {
       .cp = 15, .opc1 = 4, .crn = 1, .crm = 1, .opc2 = 2,
       .access = PL2_RW, .accessfn = cptr_access, .resetvalue = 0,
       .fieldoffset = offsetof(CPUARMState, cp15.cptr_el[2]) },
+    { .name = "MAIR_EL2", .state = ARM_CP_STATE_AA64,
+      .opc0 = 3, .opc1 = 4, .crn = 10, .crm = 2, .opc2 = 0,
+      .access = PL2_RW, .fieldoffset = offsetof(CPUARMState, cp15.mair_el[2]),
+      .resetvalue = 0 },
     REGINFO_SENTINEL
 };
 

Hi Edgar!

This patch does not apply when trying to apply the series onto commit 968bb75c348a401b85e08d5eb1887a3e6c3185f5

    Merge: 19fbe50 5ae79fe
    Author: Peter Maydell <[email protected]>
    Date:   Tue May 12 12:11:32 2015 +0100

Git gives:

Applying: target-arm: Add MAIR_EL2
error: patch failed: target-arm/helper.c:2520
error: target-arm/helper.c: patch does not apply Patch failed at 0005 target-arm: Add MAIR_EL2

Regards,
Sergey

#10 lore raw

Re: [Qemu-devel] [PATCH v1 05/18] target-arm: Add MAIR_EL2

Quoted 37 lines · Sergey Fedorov
Quoted 23 lines · Edgar E. Iglesias

From: "Edgar E. Iglesias" <[email protected]>

---
 target-arm/helper.c | 8 ++++++++
 1 file changed, 8 insertions(+)
target-arm/helper.c +4 -0
index d849b30..168549c 100644
@@ -2520,6 +2520,10 @@ static const ARMCPRegInfo v8_el3_no_el2_cp_reginfo[] = {
       .cp = 15, .opc1 = 4, .crn = 1, .crm = 1, .opc2 = 2,
       .access = PL2_RW, .accessfn = cptr_access, .resetvalue = 0,
       .readfn = arm_cp_read_zero, .writefn = arm_cp_write_ignore },
+    { .name = "MAIR_EL2", .state = ARM_CP_STATE_AA64,
+      .opc0 = 3, .opc1 = 4, .crn = 10, .crm = 2, .opc2 = 0,
+      .access = PL2_RW,
+      .readfn = arm_cp_read_zero, .writefn = arm_cp_write_ignore },
     REGINFO_SENTINEL
 };
 

target-arm/helper.c static const ARMCPRegInfo v8_el2_cp_reginfo[] = { · line 2608

Quoted 10 lines
target-arm/helper.c +4 -0
@@ -2595,6 +2599,10 @@ static const ARMCPRegInfo v8_el2_cp_reginfo[] = {
       .cp = 15, .opc1 = 4, .crn = 1, .crm = 1, .opc2 = 2,
       .access = PL2_RW, .accessfn = cptr_access, .resetvalue = 0,
       .fieldoffset = offsetof(CPUARMState, cp15.cptr_el[2]) },
+    { .name = "MAIR_EL2", .state = ARM_CP_STATE_AA64,
+      .opc0 = 3, .opc1 = 4, .crn = 10, .crm = 2, .opc2 = 0,
+      .access = PL2_RW, .fieldoffset = offsetof(CPUARMState, cp15.mair_el[2]),
+      .resetvalue = 0 },
     REGINFO_SENTINEL
 };
 

Hi Edgar!

Quoted 2 lines

This patch does not apply when trying to apply the series onto commit 968bb75c348a401b85e08d5eb1887a3e6c3185f5

Hi Sergey,

Yes, you need Gregs target el infrastructure series applied before this series.

You can find it all here:
http://repo.or.cz/w/qemu/cris-port.git/shortlog/refs/heads/edgar/a64/el2-steps3.v1

Cheers,
Edgar

Quoted 14 lines
    Merge: 19fbe50 5ae79fe
    Author: Peter Maydell <[email protected]>
    Date:   Tue May 12 12:11:32 2015 +0100

Git gives:

Applying: target-arm: Add MAIR_EL2
error: patch failed: target-arm/helper.c:2520
error: target-arm/helper.c: patch does not apply Patch failed at 0005 target-arm: Add MAIR_EL2

Regards,
Sergey

#11 lore raw

Re: [Qemu-devel] [PATCH v1 05/18] target-arm: Add MAIR_EL2

Quoted 41 lines · Edgar E. Iglesias
Quoted 36 lines · Sergey Fedorov
Quoted 23 lines · Edgar E. Iglesias

From: "Edgar E. Iglesias" <[email protected]>

---
 target-arm/helper.c | 8 ++++++++
 1 file changed, 8 insertions(+)
target-arm/helper.c +4 -0
index d849b30..168549c 100644
@@ -2520,6 +2520,10 @@ static const ARMCPRegInfo v8_el3_no_el2_cp_reginfo[] = {
       .cp = 15, .opc1 = 4, .crn = 1, .crm = 1, .opc2 = 2,
       .access = PL2_RW, .accessfn = cptr_access, .resetvalue = 0,
       .readfn = arm_cp_read_zero, .writefn = arm_cp_write_ignore },
+    { .name = "MAIR_EL2", .state = ARM_CP_STATE_AA64,
+      .opc0 = 3, .opc1 = 4, .crn = 10, .crm = 2, .opc2 = 0,
+      .access = PL2_RW,
+      .readfn = arm_cp_read_zero, .writefn = arm_cp_write_ignore },
     REGINFO_SENTINEL
 };
 

target-arm/helper.c static const ARMCPRegInfo v8_el2_cp_reginfo[] = { · line 2608

Quoted 10 lines
target-arm/helper.c +4 -0
@@ -2595,6 +2599,10 @@ static const ARMCPRegInfo v8_el2_cp_reginfo[] = {
       .cp = 15, .opc1 = 4, .crn = 1, .crm = 1, .opc2 = 2,
       .access = PL2_RW, .accessfn = cptr_access, .resetvalue = 0,
       .fieldoffset = offsetof(CPUARMState, cp15.cptr_el[2]) },
+    { .name = "MAIR_EL2", .state = ARM_CP_STATE_AA64,
+      .opc0 = 3, .opc1 = 4, .crn = 10, .crm = 2, .opc2 = 0,
+      .access = PL2_RW, .fieldoffset = offsetof(CPUARMState, cp15.mair_el[2]),
+      .resetvalue = 0 },
     REGINFO_SENTINEL
 };
 

Hi Edgar!

Quoted 2 lines

This patch does not apply when trying to apply the series onto commit 968bb75c348a401b85e08d5eb1887a3e6c3185f5

Hi Sergey,

Quoted 7 lines

Yes, you need Gregs target el infrastructure series applied before this series.

You can find it all here:
http://repo.or.cz/w/qemu/cris-port.git/shortlog/refs/heads/edgar/a64/el2-steps3.v1

Cheers,
Edgar

Thanks!

Quoted 14 lines
Quoted 14 lines
    Merge: 19fbe50 5ae79fe
    Author: Peter Maydell <[email protected]>
    Date:   Tue May 12 12:11:32 2015 +0100

Git gives:

Applying: target-arm: Add MAIR_EL2
error: patch failed: target-arm/helper.c:2520
error: target-arm/helper.c: patch does not apply Patch failed at 0005 target-arm: Add MAIR_EL2

Regards,
Sergey

#12 lore raw

Re: [Qemu-devel] [PATCH v1 05/18] target-arm: Add MAIR_EL2

In reply to Edgar E. Iglesias
Quoted 12 lines · Edgar E. Iglesias

From: "Edgar E. Iglesias" <[email protected]>

---
 target-arm/helper.c | 8 ++++++++
 1 file changed, 8 insertions(+)
target-arm/helper.c +0 -0
index d849b30..168549c 100644

target-arm/helper.c static const ARMCPRegInfo v8_el3_no_el2_cp_reginfo[] = { · line 2526

Quoted 7 lines
target-arm/helper.c +4 -0
@@ -2520,6 +2520,10 @@ static const ARMCPRegInfo v8_el3_no_el2_cp_reginfo[] = {
       .cp = 15, .opc1 = 4, .crn = 1, .crm = 1, .opc2 = 2,
       .access = PL2_RW, .accessfn = cptr_access, .resetvalue = 0,
       .readfn = arm_cp_read_zero, .writefn = arm_cp_write_ignore },
+    { .name = "MAIR_EL2", .state = ARM_CP_STATE_AA64,
+      .opc0 = 3, .opc1 = 4, .crn = 10, .crm = 2, .opc2 = 0,
+      .access = PL2_RW,
+      .readfn = arm_cp_read_zero, .writefn = arm_cp_write_ignore },

This has a 32-bit counterpart (which you can probably implement via STATE_BOTH). Using ARM_CP_CONST is a better way to implement a RAZ/WI register than providing read/write functions.

target-arm/helper.c static const ARMCPRegInfo v8_el2_cp_reginfo[] = { · line 2605

Quoted 11 lines
target-arm/helper.c +4 -0
     REGINFO_SENTINEL
 };
 
@@ -2595,6 +2599,10 @@ static const ARMCPRegInfo v8_el2_cp_reginfo[] = {
       .cp = 15, .opc1 = 4, .crn = 1, .crm = 1, .opc2 = 2,
       .access = PL2_RW, .accessfn = cptr_access, .resetvalue = 0,
       .fieldoffset = offsetof(CPUARMState, cp15.cptr_el[2]) },
+    { .name = "MAIR_EL2", .state = ARM_CP_STATE_AA64,
+      .opc0 = 3, .opc1 = 4, .crn = 10, .crm = 2, .opc2 = 0,
+      .access = PL2_RW, .fieldoffset = offsetof(CPUARMState, cp15.mair_el[2]),
+      .resetvalue = 0 },

Again, 32-bit counterpart.

target-arm/helper.c static const ARMCPRegInfo v8_el2_cp_reginfo[] = { · line 2607

Quoted 2 lines
target-arm/helper.c +0 -0
     REGINFO_SENTINEL
 };

-- PMM

#13 lore raw

PATCH 6/18 target-arm: Add TCR_EL2

In reply to Edgar E. Iglesias

From: "Edgar E. Iglesias" <[email protected]>

---
 target-arm/helper.c | 9 +++++++++
 1 file changed, 9 insertions(+)
target-arm/helper.c +9 -0
index 168549c..025e334 100644
@@ -2524,6 +2524,10 @@ static const ARMCPRegInfo v8_el3_no_el2_cp_reginfo[] = {
       .opc0 = 3, .opc1 = 4, .crn = 10, .crm = 2, .opc2 = 0,
       .access = PL2_RW,
       .readfn = arm_cp_read_zero, .writefn = arm_cp_write_ignore },
+    { .name = "TCR_EL2", .state = ARM_CP_STATE_AA64,
+      .opc0 = 3, .opc1 = 4, .crn = 2, .crm = 0, .opc2 = 2,
+      .access = PL2_RW,
+      .readfn = arm_cp_read_zero, .writefn = arm_cp_write_ignore },
     REGINFO_SENTINEL
 };
 
@@ -2603,6 +2607,11 @@ static const ARMCPRegInfo v8_el2_cp_reginfo[] = {
       .opc0 = 3, .opc1 = 4, .crn = 10, .crm = 2, .opc2 = 0,
       .access = PL2_RW, .fieldoffset = offsetof(CPUARMState, cp15.mair_el[2]),
       .resetvalue = 0 },
+    { .name = "TCR_EL2", .state = ARM_CP_STATE_AA64,
+      .opc0 = 3, .opc1 = 4, .crn = 2, .crm = 0, .opc2 = 2,
+      .access = PL2_RW, .writefn = vmsa_tcr_el1_write,
+      .resetfn = vmsa_ttbcr_reset, .raw_writefn = raw_write,
+      .fieldoffset = offsetof(CPUARMState, cp15.tcr_el[2]) },
     REGINFO_SENTINEL
 };
 
Signature · 1 line
1.9.1
#14 lore raw

Re: [Qemu-devel] [PATCH v1 06/18] target-arm: Add TCR_EL2

Quoted 23 lines · Edgar E. Iglesias

From: "Edgar E. Iglesias" <[email protected]>

---
 target-arm/helper.c | 9 +++++++++
 1 file changed, 9 insertions(+)
target-arm/helper.c +4 -0
index 168549c..025e334 100644
@@ -2524,6 +2524,10 @@ static const ARMCPRegInfo v8_el3_no_el2_cp_reginfo[] = {
       .opc0 = 3, .opc1 = 4, .crn = 10, .crm = 2, .opc2 = 0,
       .access = PL2_RW,
       .readfn = arm_cp_read_zero, .writefn = arm_cp_write_ignore },
+    { .name = "TCR_EL2", .state = ARM_CP_STATE_AA64,
+      .opc0 = 3, .opc1 = 4, .crn = 2, .crm = 0, .opc2 = 2,
+      .access = PL2_RW,
+      .readfn = arm_cp_read_zero, .writefn = arm_cp_write_ignore },
     REGINFO_SENTINEL
 };
 

target-arm/helper.c static const ARMCPRegInfo v8_el2_cp_reginfo[] = { · line 2616

Quoted 10 lines
target-arm/helper.c +5 -0
@@ -2603,6 +2607,11 @@ static const ARMCPRegInfo v8_el2_cp_reginfo[] = {
       .opc0 = 3, .opc1 = 4, .crn = 10, .crm = 2, .opc2 = 0,
       .access = PL2_RW, .fieldoffset = offsetof(CPUARMState, cp15.mair_el[2]),
       .resetvalue = 0 },
+    { .name = "TCR_EL2", .state = ARM_CP_STATE_AA64,
+      .opc0 = 3, .opc1 = 4, .crn = 2, .crm = 0, .opc2 = 2,
+      .access = PL2_RW, .writefn = vmsa_tcr_el1_write,
+      .resetfn = vmsa_ttbcr_reset, .raw_writefn = raw_write,
+      .fieldoffset = offsetof(CPUARMState, cp15.tcr_el[2]) },
     REGINFO_SENTINEL
 };

Same remarks about 32-bit counterparts and best way to do RAZ/WI apply here.

-- PMM

#15 lore raw

PATCH 7/18 target-arm: Add SCTLR_EL2

In reply to Edgar E. Iglesias

From: "Edgar E. Iglesias" <[email protected]>

---
 target-arm/helper.c | 8 ++++++++
 1 file changed, 8 insertions(+)
target-arm/helper.c +8 -0
index 025e334..c44cbb4 100644
@@ -2528,6 +2528,10 @@ static const ARMCPRegInfo v8_el3_no_el2_cp_reginfo[] = {
       .opc0 = 3, .opc1 = 4, .crn = 2, .crm = 0, .opc2 = 2,
       .access = PL2_RW,
       .readfn = arm_cp_read_zero, .writefn = arm_cp_write_ignore },
+    { .name = "SCTLR_EL2", .state = ARM_CP_STATE_AA64,
+      .opc0 = 3, .opc1 = 4, .crn = 1, .crm = 0, .opc2 = 0,
+      .access = PL2_RW,
+      .readfn = arm_cp_read_zero, .writefn = arm_cp_write_ignore },
     REGINFO_SENTINEL
 };
 
@@ -2612,6 +2616,10 @@ static const ARMCPRegInfo v8_el2_cp_reginfo[] = {
       .access = PL2_RW, .writefn = vmsa_tcr_el1_write,
       .resetfn = vmsa_ttbcr_reset, .raw_writefn = raw_write,
       .fieldoffset = offsetof(CPUARMState, cp15.tcr_el[2]) },
+    { .name = "SCTLR_EL2", .state = ARM_CP_STATE_AA64,
+      .opc0 = 3, .opc1 = 4, .crn = 1, .crm = 0, .opc2 = 0,
+      .access = PL2_RW, .raw_writefn = raw_write, .writefn = sctlr_write,
+      .fieldoffset = offsetof(CPUARMState, cp15.sctlr_el[2]) },
     REGINFO_SENTINEL
 };
 
Signature · 1 line
1.9.1
#16 lore raw

PATCH 8/18 target-arm: Add TTBR0_EL2

In reply to Edgar E. Iglesias

From: "Edgar E. Iglesias" <[email protected]>

---
 target-arm/helper.c | 8 ++++++++
 1 file changed, 8 insertions(+)
target-arm/helper.c +8 -0
index c44cbb4..ace933c 100644
@@ -2532,6 +2532,10 @@ static const ARMCPRegInfo v8_el3_no_el2_cp_reginfo[] = {
       .opc0 = 3, .opc1 = 4, .crn = 1, .crm = 0, .opc2 = 0,
       .access = PL2_RW,
       .readfn = arm_cp_read_zero, .writefn = arm_cp_write_ignore },
+    { .name = "TTBR0_EL2", .state = ARM_CP_STATE_AA64,
+      .opc0 = 3, .opc1 = 4, .crn = 2, .crm = 0, .opc2 = 0,
+      .access = PL2_RW,
+      .readfn = arm_cp_read_zero, .writefn = arm_cp_write_ignore },
     REGINFO_SENTINEL
 };
 
@@ -2620,6 +2624,10 @@ static const ARMCPRegInfo v8_el2_cp_reginfo[] = {
       .opc0 = 3, .opc1 = 4, .crn = 1, .crm = 0, .opc2 = 0,
       .access = PL2_RW, .raw_writefn = raw_write, .writefn = sctlr_write,
       .fieldoffset = offsetof(CPUARMState, cp15.sctlr_el[2]) },
+    { .name = "TTBR0_EL2", .state = ARM_CP_STATE_AA64,
+      .opc0 = 3, .opc1 = 4, .crn = 2, .crm = 0, .opc2 = 0,
+      .access = PL2_RW, .writefn = vmsa_ttbr_write, .resetvalue = 0,
+      .fieldoffset = offsetof(CPUARMState, cp15.ttbr0_el[2]) },
     REGINFO_SENTINEL
 };
 
Signature · 1 line
1.9.1
#17 lore raw

PATCH 9/18 target-arm: Add TLBI_ALLE1{IS}

In reply to Edgar E. Iglesias

From: "Edgar E. Iglesias" <[email protected]>

---
 target-arm/helper.c | 8 ++++++++
 1 file changed, 8 insertions(+)
target-arm/helper.c +8 -0
index ace933c..830c9d4 100644
@@ -2366,6 +2366,14 @@ static const ARMCPRegInfo v8_cp_reginfo[] = {
       .opc0 = 1, .opc1 = 0, .crn = 7, .crm = 14, .opc2 = 2,
       .access = PL1_W, .type = ARM_CP_NOP },
     /* TLBI operations */
+    { .name = "TLBI_ALLE1", .state = ARM_CP_STATE_AA64,
+      .opc0 = 1, .opc1 = 4, .crn = 8, .crm = 7, .opc2 = 4,
+      .access = PL2_W, .type = ARM_CP_NO_RAW,
+      .writefn = tlbiall_write },
+    { .name = "TLBI_ALLE1IS", .state = ARM_CP_STATE_AA64,
+      .opc0 = 1, .opc1 = 4, .crn = 8, .crm = 3, .opc2 = 4,
+      .access = PL2_W, .type = ARM_CP_NO_RAW,
+      .writefn = tlbiall_write },
     { .name = "TLBI_VMALLE1IS", .state = ARM_CP_STATE_AA64,
       .opc0 = 1, .opc1 = 0, .crn = 8, .crm = 3, .opc2 = 0,
       .access = PL1_W, .type = ARM_CP_NO_RAW,
Signature · 1 line
1.9.1
#18 lore raw

PATCH 10/18 target-arm: Add TLBIALLE2

In reply to Edgar E. Iglesias

From: "Edgar E. Iglesias" <[email protected]>

---
 target-arm/helper.c | 4 ++++
 1 file changed, 4 insertions(+)
target-arm/helper.c +4 -0
index 830c9d4..8e96b14 100644
@@ -2636,6 +2636,10 @@ static const ARMCPRegInfo v8_el2_cp_reginfo[] = {
       .opc0 = 3, .opc1 = 4, .crn = 2, .crm = 0, .opc2 = 0,
       .access = PL2_RW, .writefn = vmsa_ttbr_write, .resetvalue = 0,
       .fieldoffset = offsetof(CPUARMState, cp15.ttbr0_el[2]) },
+    { .name = "TLBIALLE2", .state = ARM_CP_STATE_AA64,
+      .opc0 = 1, .opc1 = 4, .crn = 8, .crm = 7, .opc2 = 0,
+      .type = ARM_CP_NO_RAW, .access = PL2_W,
+      .writefn = tlbiall_write },
     REGINFO_SENTINEL
 };
 
Signature · 1 line
1.9.1
#19 lore raw

PATCH 11/18 target-arm: Add TPIDR_EL2

In reply to Edgar E. Iglesias

From: "Edgar E. Iglesias" <[email protected]>

---
 target-arm/helper.c | 8 ++++++++
 1 file changed, 8 insertions(+)
target-arm/helper.c +8 -0
index 8e96b14..d57e0af 100644
@@ -2544,6 +2544,10 @@ static const ARMCPRegInfo v8_el3_no_el2_cp_reginfo[] = {
       .opc0 = 3, .opc1 = 4, .crn = 2, .crm = 0, .opc2 = 0,
       .access = PL2_RW,
       .readfn = arm_cp_read_zero, .writefn = arm_cp_write_ignore },
+    { .name = "TPIDR_EL2", .state = ARM_CP_STATE_AA64,
+      .opc0 = 3, .opc1 = 4, .opc2 = 2, .crn = 13, .crm = 0,
+      .access = PL2_RW,
+      .readfn = arm_cp_read_zero, .writefn = arm_cp_write_ignore },
     REGINFO_SENTINEL
 };
 
@@ -2640,6 +2644,10 @@ static const ARMCPRegInfo v8_el2_cp_reginfo[] = {
       .opc0 = 1, .opc1 = 4, .crn = 8, .crm = 7, .opc2 = 0,
       .type = ARM_CP_NO_RAW, .access = PL2_W,
       .writefn = tlbiall_write },
+    { .name = "TPIDR_EL2", .state = ARM_CP_STATE_AA64,
+      .opc0 = 3, .opc1 = 4, .opc2 = 2, .crn = 13, .crm = 0,
+      .access = PL2_RW, .resetvalue = 0,
+      .fieldoffset = offsetof(CPUARMState, cp15.tpidr_el[2]) },
     REGINFO_SENTINEL
 };
 
Signature · 1 line
1.9.1
#20 lore raw

PATCH 12/18 target-arm: Add TLBI_VAE2{IS}

In reply to Edgar E. Iglesias

From: "Edgar E. Iglesias" <[email protected]>

---
 target-arm/helper.c | 8 ++++++++
 1 file changed, 8 insertions(+)
target-arm/helper.c +8 -0
index d57e0af..7ad9133 100644
@@ -2644,6 +2644,14 @@ static const ARMCPRegInfo v8_el2_cp_reginfo[] = {
       .opc0 = 1, .opc1 = 4, .crn = 8, .crm = 7, .opc2 = 0,
       .type = ARM_CP_NO_RAW, .access = PL2_W,
       .writefn = tlbiall_write },
+    { .name = "TLBI_VAE2", .state = ARM_CP_STATE_AA64,
+      .opc0 = 1, .opc1 = 4, .crn = 8, .crm = 7, .opc2 = 1,
+      .type = ARM_CP_NO_RAW, .access = PL2_W,
+      .writefn = tlbi_aa64_vaa_write },
+    { .name = "TLBI_VAE2IS", .state = ARM_CP_STATE_AA64,
+      .opc0 = 1, .opc1 = 4, .crn = 8, .crm = 3, .opc2 = 1,
+      .type = ARM_CP_NO_RAW, .access = PL2_W,
+      .writefn = tlbi_aa64_vaa_write },
     { .name = "TPIDR_EL2", .state = ARM_CP_STATE_AA64,
       .opc0 = 3, .opc1 = 4, .opc2 = 2, .crn = 13, .crm = 0,
       .access = PL2_RW, .resetvalue = 0,
Signature · 1 line
1.9.1
#21 lore raw

PATCH 13/18 target-arm: Add access to PAR_EL1

In reply to Edgar E. Iglesias

From: "Edgar E. Iglesias" <[email protected]>

---
 target-arm/helper.c | 5 +++++
 1 file changed, 5 insertions(+)
target-arm/helper.c +5 -0
index 7ad9133..5b7c195 100644
@@ -2436,6 +2436,11 @@ static const ARMCPRegInfo v8_cp_reginfo[] = {
     { .name = "AT_S1E0W", .state = ARM_CP_STATE_AA64,
       .opc0 = 1, .opc1 = 0, .crn = 7, .crm = 8, .opc2 = 3,
       .access = PL1_W, .type = ARM_CP_NO_RAW, .writefn = ats_write64 },
+    { .name = "PAR_EL1", .state = ARM_CP_STATE_AA64,
+      .opc0 = 3, .opc1 = 0, .crn = 7, .crm = 4, .opc2 = 0,
+      .access = PL1_RW, .resetvalue = 0,
+      .fieldoffset = offsetof(CPUARMState, cp15.par_el[1]),
+      .writefn = par_write },
 #endif
     /* TLB invalidate last level of translation table walk */
     { .name = "TLBIMVALIS", .cp = 15, .opc1 = 0, .crn = 8, .crm = 3, .opc2 = 5,
Signature · 1 line
1.9.1
#22 lore raw

PATCH 14/18 target-arm: Add CNTVOFF_EL2

In reply to Edgar E. Iglesias

From: "Edgar E. Iglesias" <[email protected]>

---
 target-arm/cpu.h    |  1 +
 target-arm/helper.c | 41 +++++++++++++++++++++++++++++++++++------
 2 files changed, 36 insertions(+), 6 deletions(-)
target-arm/cpu.h +1 -0
index 6922e54..73a4ce8 100644
@@ -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.  */
target-arm/helper.c +35 -6

105 lines not on this page · raw message

Signature · 1 line
1.9.1
#23 lore raw

PATCH 15/18 target-arm: Add CNTHCTL_EL2

In reply to Edgar E. Iglesias

From: "Edgar E. Iglesias" <[email protected]>

---
 target-arm/cpu.h    |  1 +
 target-arm/helper.c | 33 +++++++++++++++++++++++++++++++--
 2 files changed, 32 insertions(+), 2 deletions(-)
target-arm/cpu.h +1 -0
index 73a4ce8..059c200 100644
@@ -355,6 +355,7 @@ typedef struct CPUARMState {
         };
         uint64_t c14_cntfrq; /* Counter Frequency register */
         uint64_t c14_cntkctl; /* Timer Control register */
+        uint32_t cnthctl_el2; /* Counter/Timer Hyp Control register */
         uint64_t cntvoff_el2; /* Counter Virtual Offset register */
         ARMGenericTimer c14_timer[NUM_GTIMERS];
         uint32_t c15_cpar; /* XScale Coprocessor Access Register */
target-arm/helper.c +31 -2
index 380887a..4c1d6c7 100644
@@ -1155,8 +1155,18 @@ static CPAccessResult gt_cntfrq_access(CPUARMState *env, const ARMCPRegInfo *ri)
 
 static CPAccessResult gt_counter_access(CPUARMState *env, int timeridx)
 {
+    unsigned int cur_el = arm_current_el(env);
+    bool secure = arm_is_secure(env);
+
+    if (arm_feature(env, ARM_FEATURE_EL2) &&
+        timeridx == GTIMER_PHYS && !secure && cur_el < 2 &&
+        !extract32(env->cp15.cnthctl_el2, 0, 1)) {
+        env->exception.target_el = 2;
+        return CP_ACCESS_TRAP;
+    }
+
     /* CNT[PV]CT: not visible from PL0 if ELO[PV]CTEN is zero */
-    if (arm_current_el(env) == 0 &&
+    if (cur_el == 0 &&
         !extract32(env->cp15.c14_cntkctl, timeridx, 1)) {
         env->exception.target_el = 1;
         return CP_ACCESS_TRAP;
@@ -1166,10 +1176,21 @@ static CPAccessResult gt_counter_access(CPUARMState *env, int timeridx)
 
 static CPAccessResult gt_timer_access(CPUARMState *env, int timeridx)
 {
+    unsigned int cur_el = arm_current_el(env);
+    bool secure = arm_is_secure(env);
+
+    if (arm_feature(env, ARM_FEATURE_EL2)) {
+        if (timeridx == GTIMER_PHYS && !secure && cur_el < 2 &&
+            !extract32(env->cp15.cnthctl_el2, 1, 1)) {
+            env->exception.target_el = 2;
+            return CP_ACCESS_TRAP;
+        }
+    }
+
     /* CNT[PV]_CVAL, CNT[PV]_CTL, CNT[PV]_TVAL: not visible from PL0 if
      * EL0[PV]TEN is zero.
      */
-    if (arm_current_el(env) == 0 &&
+    if (cur_el == 0 &&
         !extract32(env->cp15.c14_cntkctl, 9 - timeridx, 1)) {
         env->exception.target_el = 1;
         return CP_ACCESS_TRAP;
@@ -2571,6 +2592,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 = "CNTHCTL_EL2", .state = ARM_CP_STATE_AA64,
+      .opc0 = 3, .opc1 = 4, .crn = 14, .crm = 1, .opc2 = 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,
@@ -2684,6 +2709,10 @@ static const ARMCPRegInfo v8_el2_cp_reginfo[] = {
       .access = PL2_RW, .resetvalue = 0,
       .fieldoffset = offsetof(CPUARMState, cp15.tpidr_el[2]) },
 #ifndef CONFIG_USER_ONLY
+    { .name = "CNTHCTL_EL2", .state = ARM_CP_STATE_AA64,
+      .opc0 = 3, .opc1 = 4, .crn = 14, .crm = 1, .opc2 = 0,
+      .access = PL2_RW,
+      .fieldoffset = offsetof(CPUARMState, cp15.cnthctl_el2) },
     { .name = "CNTVOFF_EL2", .state = ARM_CP_STATE_AA64,
       .opc0 = 3, .opc1 = 4, .crn = 14, .crm = 0, .opc2 = 3,
       .access = PL2_RW,
Signature · 1 line
1.9.1
#24 lore raw

PATCH 16/18 target-arm: Pass timeridx as argument to various timer functions

In reply to Edgar E. Iglesias

From: "Edgar E. Iglesias" <[email protected]>

---
 target-arm/helper.c | 98 +++++++++++++++++++++++++++++++++++++++++------------
 1 file changed, 76 insertions(+), 22 deletions(-)
target-arm/helper.c +76 -22
index 4c1d6c7..d29b1fc 100644
@@ -1267,10 +1267,9 @@ static void gt_recalc_timer(ARMCPU *cpu, int timeridx)
     }
 }
 
-static void gt_cnt_reset(CPUARMState *env, const ARMCPRegInfo *ri)
+static void gt_cnt_reset(CPUARMState *env, const ARMCPRegInfo *ri, int timeridx)
 {
     ARMCPU *cpu = arm_env_get_cpu(env);
-    int timeridx = ri->opc1 & 1;
 
     timer_del(cpu->gt_timer[timeridx]);
 }
@@ -1286,17 +1285,16 @@ static uint64_t gt_virt_cnt_read(CPUARMState *env, const ARMCPRegInfo *ri)
 }
 
 static void gt_cval_write(CPUARMState *env, const ARMCPRegInfo *ri,
+                          int timeridx,
                           uint64_t value)
 {
-    int timeridx = ri->opc1 & 1;
-
     env->cp15.c14_timer[timeridx].cval = value;
     gt_recalc_timer(arm_env_get_cpu(env), timeridx);
 }
 
-static uint64_t gt_tval_read(CPUARMState *env, const ARMCPRegInfo *ri)
+static uint64_t gt_tval_read(CPUARMState *env, const ARMCPRegInfo *ri,
+                             int timeridx)
 {
-    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 -
@@ -1304,9 +1302,9 @@ static uint64_t gt_tval_read(CPUARMState *env, const ARMCPRegInfo *ri)
 }
 
 static void gt_tval_write(CPUARMState *env, const ARMCPRegInfo *ri,
+                          int timeridx,
                           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) - offset +
@@ -1315,10 +1313,10 @@ static void gt_tval_write(CPUARMState *env, const ARMCPRegInfo *ri,
 }
 
 static void gt_ctl_write(CPUARMState *env, const ARMCPRegInfo *ri,
+                         int timeridx,
                          uint64_t value)
 {
     ARMCPU *cpu = arm_env_get_cpu(env);
-    int timeridx = ri->crm & 1;
     uint32_t oldval = env->cp15.c14_timer[timeridx].ctl;
 
     env->cp15.c14_timer[timeridx].ctl = deposit64(oldval, 0, 2, value);
@@ -1334,6 +1332,62 @@ static void gt_ctl_write(CPUARMState *env, const ARMCPRegInfo *ri,
     }
 }
 
+static void gt_phys_cnt_reset(CPUARMState *env, const ARMCPRegInfo *ri)
+{
+    gt_cnt_reset(env, ri, GTIMER_PHYS);
+}
+
+static void gt_phys_cval_write(CPUARMState *env, const ARMCPRegInfo *ri,
+                               uint64_t value)
+{
+    gt_cval_write(env, ri, GTIMER_PHYS, value);
+}
+
+static uint64_t gt_phys_tval_read(CPUARMState *env, const ARMCPRegInfo *ri)
+{
+    return gt_tval_read(env, ri, GTIMER_PHYS);
+}
+
+static void gt_phys_tval_write(CPUARMState *env, const ARMCPRegInfo *ri,
+                               uint64_t value)
+{
+    gt_tval_write(env, ri, GTIMER_PHYS, value);
+}
+
+static void gt_phys_ctl_write(CPUARMState *env, const ARMCPRegInfo *ri,
+                              uint64_t value)
+{
+    gt_ctl_write(env, ri, GTIMER_PHYS, value);
+}
+
+static void gt_virt_cnt_reset(CPUARMState *env, const ARMCPRegInfo *ri)
+{
+    gt_cnt_reset(env, ri, GTIMER_VIRT);
+}
+
+static void gt_virt_cval_write(CPUARMState *env, const ARMCPRegInfo *ri,
+                               uint64_t value)
+{
+    gt_cval_write(env, ri, GTIMER_VIRT, value);
+}
+
+static uint64_t gt_virt_tval_read(CPUARMState *env, const ARMCPRegInfo *ri)
+{
+    return gt_tval_read(env, ri, GTIMER_VIRT);
+}
+
+static void gt_virt_tval_write(CPUARMState *env, const ARMCPRegInfo *ri,
+                               uint64_t value)
+{
+    gt_tval_write(env, ri, GTIMER_VIRT, value);
+}
+
+static void gt_virt_ctl_write(CPUARMState *env, const ARMCPRegInfo *ri,
+                              uint64_t value)
+{
+    gt_ctl_write(env, ri, GTIMER_VIRT, value);
+}
+
 static void gt_cntvoff_write(CPUARMState *env, const ARMCPRegInfo *ri,
                               uint64_t value)
 {
@@ -1388,7 +1442,7 @@ static const ARMCPRegInfo generic_timer_cp_reginfo[] = {
       .fieldoffset = offsetoflow32(CPUARMState,
                                    cp15.c14_timer[GTIMER_PHYS].ctl),
       .resetfn = arm_cp_reset_ignore,
-      .writefn = gt_ctl_write, .raw_writefn = raw_write,
+      .writefn = gt_phys_ctl_write, .raw_writefn = raw_write,
     },
     { .name = "CNTP_CTL_EL0", .state = ARM_CP_STATE_AA64,
       .opc0 = 3, .opc1 = 3, .crn = 14, .crm = 2, .opc2 = 1,
@@ -1396,7 +1450,7 @@ static const ARMCPRegInfo generic_timer_cp_reginfo[] = {
       .accessfn = gt_ptimer_access,
       .fieldoffset = offsetof(CPUARMState, cp15.c14_timer[GTIMER_PHYS].ctl),
       .resetvalue = 0,
-      .writefn = gt_ctl_write, .raw_writefn = raw_write,
+      .writefn = gt_phys_ctl_write, .raw_writefn = raw_write,
     },
     { .name = "CNTV_CTL", .cp = 15, .crn = 14, .crm = 3, .opc1 = 0, .opc2 = 1,
       .type = ARM_CP_IO | ARM_CP_ALIAS, .access = PL1_RW | PL0_R,
@@ -1404,7 +1458,7 @@ static const ARMCPRegInfo generic_timer_cp_reginfo[] = {
       .fieldoffset = offsetoflow32(CPUARMState,
                                    cp15.c14_timer[GTIMER_VIRT].ctl),
       .resetfn = arm_cp_reset_ignore,
-      .writefn = gt_ctl_write, .raw_writefn = raw_write,
+      .writefn = gt_virt_ctl_write, .raw_writefn = raw_write,
     },
     { .name = "CNTV_CTL_EL0", .state = ARM_CP_STATE_AA64,
       .opc0 = 3, .opc1 = 3, .crn = 14, .crm = 3, .opc2 = 1,
@@ -1412,30 +1466,30 @@ static const ARMCPRegInfo generic_timer_cp_reginfo[] = {
       .accessfn = gt_vtimer_access,
       .fieldoffset = offsetof(CPUARMState, cp15.c14_timer[GTIMER_VIRT].ctl),
       .resetvalue = 0,
-      .writefn = gt_ctl_write, .raw_writefn = raw_write,
+      .writefn = gt_virt_ctl_write, .raw_writefn = raw_write,
     },
     /* TimerValue views: a 32 bit downcounting view of the underlying state */
     { .name = "CNTP_TVAL", .cp = 15, .crn = 14, .crm = 2, .opc1 = 0, .opc2 = 0,
       .type = ARM_CP_NO_RAW | ARM_CP_IO, .access = PL1_RW | PL0_R,
       .accessfn = gt_ptimer_access,
-      .readfn = gt_tval_read, .writefn = gt_tval_write,
+      .readfn = gt_phys_tval_read, .writefn = gt_phys_tval_write,
     },
     { .name = "CNTP_TVAL_EL0", .state = ARM_CP_STATE_AA64,
       .opc0 = 3, .opc1 = 3, .crn = 14, .crm = 2, .opc2 = 0,
       .type = ARM_CP_NO_RAW | ARM_CP_IO, .access = PL1_RW | PL0_R,
       .accessfn = gt_ptimer_access,
-      .readfn = gt_tval_read, .writefn = gt_tval_write,
+      .readfn = gt_phys_tval_read, .writefn = gt_phys_tval_write,
     },
     { .name = "CNTV_TVAL", .cp = 15, .crn = 14, .crm = 3, .opc1 = 0, .opc2 = 0,
       .type = ARM_CP_NO_RAW | ARM_CP_IO, .access = PL1_RW | PL0_R,
       .accessfn = gt_vtimer_access,
-      .readfn = gt_tval_read, .writefn = gt_tval_write,
+      .readfn = gt_virt_tval_read, .writefn = gt_virt_tval_write,
     },
     { .name = "CNTV_TVAL_EL0", .state = ARM_CP_STATE_AA64,
       .opc0 = 3, .opc1 = 3, .crn = 14, .crm = 3, .opc2 = 0,
       .type = ARM_CP_NO_RAW | ARM_CP_IO, .access = PL1_RW | PL0_R,
       .accessfn = gt_vtimer_access,
-      .readfn = gt_tval_read, .writefn = gt_tval_write,
+      .readfn = gt_virt_tval_read, .writefn = gt_virt_tval_write,
     },
     /* The counter itself */
     { .name = "CNTPCT", .cp = 15, .crm = 14, .opc1 = 0,
@@ -1447,7 +1501,7 @@ static const ARMCPRegInfo generic_timer_cp_reginfo[] = {
       .opc0 = 3, .opc1 = 3, .crn = 14, .crm = 0, .opc2 = 1,
       .access = PL0_R, .type = ARM_CP_NO_RAW | ARM_CP_IO,
       .accessfn = gt_pct_access,
-      .readfn = gt_cnt_read, .resetfn = gt_cnt_reset,
+      .readfn = gt_cnt_read, .resetfn = gt_phys_cnt_reset,
     },
     { .name = "CNTVCT", .cp = 15, .crm = 14, .opc1 = 1,
       .access = PL0_R, .type = ARM_CP_64BIT | ARM_CP_NO_RAW | ARM_CP_IO,
@@ -1458,7 +1512,7 @@ static const ARMCPRegInfo generic_timer_cp_reginfo[] = {
       .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_virt_cnt_read, .resetfn = gt_cnt_reset,
+      .readfn = gt_virt_cnt_read, .resetfn = gt_virt_cnt_reset,
     },
     /* Comparison value, indicating when the timer goes off */
     { .name = "CNTP_CVAL", .cp = 15, .crm = 14, .opc1 = 2,
@@ -1466,7 +1520,7 @@ static const ARMCPRegInfo generic_timer_cp_reginfo[] = {
       .type = ARM_CP_64BIT | ARM_CP_IO | ARM_CP_ALIAS,
       .fieldoffset = offsetof(CPUARMState, cp15.c14_timer[GTIMER_PHYS].cval),
       .accessfn = gt_ptimer_access, .resetfn = arm_cp_reset_ignore,
-      .writefn = gt_cval_write, .raw_writefn = raw_write,
+      .writefn = gt_phys_cval_write, .raw_writefn = raw_write,
     },
     { .name = "CNTP_CVAL_EL0", .state = ARM_CP_STATE_AA64,
       .opc0 = 3, .opc1 = 3, .crn = 14, .crm = 2, .opc2 = 2,
@@ -1474,14 +1528,14 @@ static const ARMCPRegInfo generic_timer_cp_reginfo[] = {
       .type = ARM_CP_IO,
       .fieldoffset = offsetof(CPUARMState, cp15.c14_timer[GTIMER_PHYS].cval),
       .resetvalue = 0, .accessfn = gt_ptimer_access,
-      .writefn = gt_cval_write, .raw_writefn = raw_write,
+      .writefn = gt_phys_cval_write, .raw_writefn = raw_write,
     },
     { .name = "CNTV_CVAL", .cp = 15, .crm = 14, .opc1 = 3,
       .access = PL1_RW | PL0_R,
       .type = ARM_CP_64BIT | ARM_CP_IO | ARM_CP_ALIAS,
       .fieldoffset = offsetof(CPUARMState, cp15.c14_timer[GTIMER_VIRT].cval),
       .accessfn = gt_vtimer_access, .resetfn = arm_cp_reset_ignore,
-      .writefn = gt_cval_write, .raw_writefn = raw_write,
+      .writefn = gt_virt_cval_write, .raw_writefn = raw_write,
     },
     { .name = "CNTV_CVAL_EL0", .state = ARM_CP_STATE_AA64,
       .opc0 = 3, .opc1 = 3, .crn = 14, .crm = 3, .opc2 = 2,
@@ -1489,7 +1543,7 @@ static const ARMCPRegInfo generic_timer_cp_reginfo[] = {
       .type = ARM_CP_IO,
       .fieldoffset = offsetof(CPUARMState, cp15.c14_timer[GTIMER_VIRT].cval),
       .resetvalue = 0, .accessfn = gt_vtimer_access,
-      .writefn = gt_cval_write, .raw_writefn = raw_write,
+      .writefn = gt_virt_cval_write, .raw_writefn = raw_write,
     },
     REGINFO_SENTINEL
 };
Signature · 1 line
1.9.1
#25 lore raw

PATCH 17/18 target-arm: Add HYP timer

In reply to Edgar E. Iglesias

From: "Edgar E. Iglesias" <[email protected]>

---
 target-arm/cpu-qom.h |  1 +
 target-arm/cpu.c     |  2 ++
 target-arm/cpu.h     |  3 ++-
 target-arm/helper.c  | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 69 insertions(+), 1 deletion(-)
target-arm/cpu-qom.h +1 -0
index ed5a644..3aaa7b6 100644
@@ -214,6 +214,7 @@ int arm_cpu_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg);
 /* Callback functions for the generic timer's timers. */
 void arm_gt_ptimer_cb(void *opaque);
 void arm_gt_vtimer_cb(void *opaque);
+void arm_gt_htimer_cb(void *opaque);
 
 #ifdef TARGET_AARCH64
 int aarch64_cpu_gdb_read_register(CPUState *cpu, uint8_t *buf, int reg);
target-arm/cpu.c +2 -0
index e9b77c6..1647ef0 100644
@@ -409,6 +409,8 @@ static void arm_cpu_initfn(Object *obj)
                                                 arm_gt_ptimer_cb, cpu);
     cpu->gt_timer[GTIMER_VIRT] = timer_new(QEMU_CLOCK_VIRTUAL, GTIMER_SCALE,
                                                 arm_gt_vtimer_cb, cpu);
+    cpu->gt_timer[GTIMER_HYP] = timer_new(QEMU_CLOCK_VIRTUAL, GTIMER_SCALE,
+                                                arm_gt_htimer_cb, cpu);
     qdev_init_gpio_out(DEVICE(cpu), cpu->gt_timer_outputs,
                        ARRAY_SIZE(cpu->gt_timer_outputs));
 #endif
target-arm/cpu.h +2 -1
index 059c200..b47fb84 100644
@@ -113,7 +113,8 @@ typedef struct ARMGenericTimer {
 
 #define GTIMER_PHYS 0
 #define GTIMER_VIRT 1
-#define NUM_GTIMERS 2
+#define GTIMER_HYP  2
+#define NUM_GTIMERS 3
 
 typedef struct {
     uint64_t raw_tcr;
target-arm/helper.c +64 -0

88 lines not on this page · raw message

Signature · 1 line
1.9.1
#26 lore raw

PATCH 18/18 hw/arm/virt: Connect the Hypervisor timer

In reply to Edgar E. Iglesias

From: "Edgar E. Iglesias" <[email protected]>

---
 hw/arm/virt.c | 3 +++
 1 file changed, 3 insertions(+)
hw/arm/virt.c +3 -0
index a7f9a10..76b6b2e 100644
@@ -384,6 +384,9 @@ static uint32_t create_gic(const VirtBoardInfo *vbi, qemu_irq *pic)
         /* virtual timer */
         qdev_connect_gpio_out(cpudev, 1,
                               qdev_get_gpio_in(gicdev, ppibase + 27));
+        /* Hypervisor timer.  */
+        qdev_connect_gpio_out(cpudev, 2,
+                              qdev_get_gpio_in(gicdev, ppibase + 26));
 
         sysbus_connect_irq(gicbusdev, i, qdev_get_gpio_in(cpudev, ARM_CPU_IRQ));
         sysbus_connect_irq(gicbusdev, i + smp_cpus,
Signature · 1 line
1.9.1
#27 lore raw
In reply to Edgar E. Iglesias
Quoted 11 lines · Edgar E. Iglesias

From: "Edgar E. Iglesias" <[email protected]>

Hi,

This is round 3 of our series towards support for EL2 for AArch64. This series depends on Gregs exception target el infrastructure patch series that is not yet upstream.

P0 - P2 are fixes without dependencies.
P3 is probably something that should be fixed in Gregs series. P4 and on add a bunch of EL2 regs and timer features.

(Your patch numbering here is off by one.)

Thanks; I've applied 1..3 to target-arm.next; 4 I think we should fix in a different way, so I'll send out a respin of Greg's patches with some fixes as described in that mail. I haven't looked at the ones beyond patch 6 or so for the moment.

-- PMM

#28 lore raw
Quoted 13 lines · Peter Maydell
Quoted 11 lines · Edgar E. Iglesias

From: "Edgar E. Iglesias" <[email protected]>

Hi,

This is round 3 of our series towards support for EL2 for AArch64. This series depends on Gregs exception target el infrastructure patch series that is not yet upstream.

P0 - P2 are fixes without dependencies.
P3 is probably something that should be fixed in Gregs series. P4 and on add a bunch of EL2 regs and timer features.

Quoted 6 lines

(Your patch numbering here is off by one.)

Thanks; I've applied 1..3 to target-arm.next; 4 I think we should fix in a different way, so I'll send out a respin of Greg's patches with some fixes as described in that mail. I haven't looked at the ones beyond patch 6 or so for the moment.

Thanks, I'll fix up your comments universally and send out a v2.

Thanks,
Edgar