Skip to contentSkip to conversation

target-arm: Implement AArch64 OSLAR/OSLSR_EL1 sysregs

PATCH Superseded Davorin Mista 2 participants 2 messages Oct 5, 2015

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 target-arm: Implement AArch64 OSLAR/OSLSR_EL1 sysregs

Added oslar_write function to OSLAR_EL1 sysreg, using a status variable in ARMCPUState.cp15 struct (oslsr_el1). This variable is also linked to the newly added read-only OSLSR_EL1 register.

Linux reads from this register during its suspend/resume procedure.

---
Changed in v2:
-switched from using dummy registers to an actual register implementation -implemented write function for OSLAR_EL1 sysreg
-added state variable to ARMCPUState struct

Changed in v3:
-renamed variable to oslsr_el1 and moved to cp15 -renamed write frunction to oslar_write
-support both 32bit and 64bit ARM in oslar_write -moved resetvalue to the corresponding read-only register -removed "dummy" comments above registers

---
 target-arm/cpu.h    |  1 +
 target-arm/helper.c | 23 +++++++++++++++++++++--
 2 files changed, 22 insertions(+), 2 deletions(-)
target-arm/cpu.h +1 -0
index 5ea11a6..f9f9bfb 100644
@@ -399,6 +399,7 @@ typedef struct CPUARMState {
         uint64_t dbgwvr[16]; /* watchpoint value registers */
         uint64_t dbgwcr[16]; /* watchpoint control registers */
         uint64_t mdscr_el1;
+        uint64_t oslsr_el1; /* OS Lock Status */
         /* If the counter is enabled, this stores the last time the counter
          * was reset. Otherwise it stores the counter value
          */
target-arm/helper.c +21 -2
index 9d62c4c..ecc89c7 100644
@@ -3147,6 +3147,20 @@ static void dcc_write(CPUARMState *env, const ARMCPRegInfo *ri,
     putchar(value);
 }
 
+/* write to os_lock_status state variable */
+static void oslar_write(CPUARMState *env, const ARMCPRegInfo *ri, uint64_t value)
+{
+    int oslock;
+
+    if (ri->state == ARM_CP_STATE_AA32) {
+        oslock = (value == 0xC5ACCE55);
+    } else {
+        oslock = value & 1;
+    }
+
+    env->cp15.oslsr_el1 = deposit32(env->cp15.oslsr_el1, 1, 1, oslock);
+}
+
 static const ARMCPRegInfo debug_cp_reginfo[] = {
     /* DBGDRAR, DBGDSAR: always RAZ since we don't implement memory mapped
      * debug components. The AArch64 version of DBGDRAR is named MDRAR_EL1;
@@ -3176,10 +3190,15 @@ static const ARMCPRegInfo debug_cp_reginfo[] = {
       .access = PL1_R,
       .fieldoffset = offsetof(CPUARMState, cp15.mdscr_el1),
       .resetfn = arm_cp_reset_ignore },
-    /* We define a dummy WI OSLAR_EL1, because Linux writes to it. */
     { .name = "OSLAR_EL1", .state = ARM_CP_STATE_BOTH,
       .cp = 14, .opc0 = 2, .opc1 = 0, .crn = 1, .crm = 0, .opc2 = 4,
-      .access = PL1_W, .type = ARM_CP_NOP },
+      .access = PL1_W,
+      .fieldoffset = offsetof(CPUARMState, cp15.oslsr_el1),
+      .writefn = oslar_write },
+    { .name = "OSLSR_EL1", .state = ARM_CP_STATE_BOTH,
+      .cp = 14, .opc0 = 2, .opc1 = 0, .crn = 1, .crm = 1, .opc2 = 4,
+      .access = PL1_R, .resetvalue = 10,
+      .fieldoffset = offsetof(CPUARMState, cp15.oslsr_el1) },
     /* Dummy OSDLR_EL1: 32-bit Linux will read this */
     { .name = "OSDLR_EL1", .state = ARM_CP_STATE_BOTH,
       .cp = 14, .opc0 = 2, .opc1 = 0, .crn = 1, .crm = 3, .opc2 = 4,
Signature · 1 line
2.6.0
#1 lore raw
Quoted 63 lines · Davorin Mista

Added oslar_write function to OSLAR_EL1 sysreg, using a status variable in ARMCPUState.cp15 struct (oslsr_el1). This variable is also linked to the newly added read-only OSLSR_EL1 register.

Linux reads from this register during its suspend/resume procedure.

---
Changed in v2:

(quoted diff) +0 -3
-switched from using dummy registers to an actual register implementation
-implemented write function for OSLAR_EL1 sysreg
-added state variable to ARMCPUState struct

Changed in v3:

(quoted diff) +0 -6
-renamed variable to oslsr_el1 and moved to cp15
-renamed write frunction to oslar_write
-support both 32bit and 64bit ARM in oslar_write
-moved resetvalue to the corresponding read-only register
-removed "dummy" comments above registers
---
 target-arm/cpu.h    |  1 +
 target-arm/helper.c | 23 +++++++++++++++++++++--
 2 files changed, 22 insertions(+), 2 deletions(-)
target-arm/cpu.h +1 -0
index 5ea11a6..f9f9bfb 100644
@@ -399,6 +399,7 @@ typedef struct CPUARMState {
         uint64_t dbgwvr[16]; /* watchpoint value registers */
         uint64_t dbgwcr[16]; /* watchpoint control registers */
         uint64_t mdscr_el1;
+        uint64_t oslsr_el1; /* OS Lock Status */
         /* If the counter is enabled, this stores the last time the counter
          * was reset. Otherwise it stores the counter value
          */
target-arm/helper.c +14 -0
index 9d62c4c..ecc89c7 100644
@@ -3147,6 +3147,20 @@ static void dcc_write(CPUARMState *env, const ARMCPRegInfo *ri,
     putchar(value);
 }
 
+/* write to os_lock_status state variable */
+static void oslar_write(CPUARMState *env, const ARMCPRegInfo *ri, uint64_t value)
+{
+    int oslock;
+
+    if (ri->state == ARM_CP_STATE_AA32) {
+        oslock = (value == 0xC5ACCE55);
+    } else {
+        oslock = value & 1;
+    }
+
+    env->cp15.oslsr_el1 = deposit32(env->cp15.oslsr_el1, 1, 1, oslock);
+}
+
 static const ARMCPRegInfo debug_cp_reginfo[] = {
     /* DBGDRAR, DBGDSAR: always RAZ since we don't implement memory mapped
      * debug components. The AArch64 version of DBGDRAR is named MDRAR_EL1;

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

Quoted 9 lines
target-arm/helper.c +2 -2
@@ -3176,10 +3190,15 @@ static const ARMCPRegInfo debug_cp_reginfo[] = {
       .access = PL1_R,
       .fieldoffset = offsetof(CPUARMState, cp15.mdscr_el1),
       .resetfn = arm_cp_reset_ignore },
-    /* We define a dummy WI OSLAR_EL1, because Linux writes to it. */
     { .name = "OSLAR_EL1", .state = ARM_CP_STATE_BOTH,
       .cp = 14, .opc0 = 2, .opc1 = 0, .crn = 1, .crm = 0, .opc2 = 4,
-      .access = PL1_W, .type = ARM_CP_NOP },
+      .access = PL1_W,
+      .fieldoffset = offsetof(CPUARMState, cp15.oslsr_el1),

OSLAR doesn't want a fieldoffset.

Still missing .type = ARM_CP_NO_RAW. (As Alistair says, this does exist in mainline -- please make sure you write and test your patches against current git master, not any other tree.)

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

Quoted 5 lines
target-arm/helper.c +5 -0
+      .writefn = oslar_write },
+    { .name = "OSLSR_EL1", .state = ARM_CP_STATE_BOTH,
+      .cp = 14, .opc0 = 2, .opc1 = 0, .crn = 1, .crm = 1, .opc2 = 4,
+      .access = PL1_R, .resetvalue = 10,
+      .fieldoffset = offsetof(CPUARMState, cp15.oslsr_el1) },

This part is OK.

Quoted 5 lines
target-arm/helper.c +0 -1
     /* Dummy OSDLR_EL1: 32-bit Linux will read this */
     { .name = "OSDLR_EL1", .state = ARM_CP_STATE_BOTH,
       .cp = 14, .opc0 = 2, .opc1 = 0, .crn = 1, .crm = 3, .opc2 = 4,
--

2.6.0

thanks
-- PMM