HSR_MATCH_MCR_MRC and its 64-bit brother make dispatching trapped sysreg
accesses simpler. The will be more use cases soon.

Signed-off-by: Jan Kiszka <jan.kis...@siemens.com>
---
 hypervisor/arch/arm/include/asm/processor.h |  8 ++++++++
 hypervisor/arch/arm/traps.c                 | 17 ++++-------------
 2 files changed, 12 insertions(+), 13 deletions(-)

diff --git a/hypervisor/arch/arm/include/asm/processor.h 
b/hypervisor/arch/arm/include/asm/processor.h
index 9be4362..dc6f9bb 100644
--- a/hypervisor/arch/arm/include/asm/processor.h
+++ b/hypervisor/arch/arm/include/asm/processor.h
@@ -145,6 +145,14 @@
 #define HSR_ICC_CV_BIT         (1 << 24)
 #define HSR_ICC_COND(icc)      ((icc) >> 20 & 0xf)
 
+#define HSR_MATCH_MCR_MRC(hsr, crn, opc1, crm, opc2)           \
+       (((hsr) & (BIT_MASK(19, 10) | BIT_MASK(4, 1))) ==       \
+        (((opc2) << 17) | ((opc1) << 14) | ((crn) << 10) | ((crm) << 1)))
+
+#define HSR_MATCH_MCRR_MRRC(hsr, opc1, crm)                    \
+       (((hsr) & (BIT_MASK(19, 16) | BIT_MASK(4, 1))) ==       \
+        (((opc1) << 16) | ((crm) << 1)))
+
 #define EXIT_REASON_UNDEF      0x1
 #define EXIT_REASON_HVC                0x2
 #define EXIT_REASON_PABT       0x3
diff --git a/hypervisor/arch/arm/traps.c b/hypervisor/arch/arm/traps.c
index 5723f05..093d2f5 100644
--- a/hypervisor/arch/arm/traps.c
+++ b/hypervisor/arch/arm/traps.c
@@ -233,14 +233,11 @@ static int arch_handle_hvc(struct trap_context *ctx)
 
 static int arch_handle_cp15_32(struct trap_context *ctx)
 {
-       u32 opc2        = ctx->hsr >> 17 & 0x7;
-       u32 opc1        = ctx->hsr >> 14 & 0x7;
-       u32 crn         = ctx->hsr >> 10 & 0xf;
        u32 rt          = ctx->hsr >> 5 & 0xf;
-       u32 crm         = ctx->hsr >> 1 & 0xf;
        u32 read        = ctx->hsr & 1;
 
-       if (opc1 == 0 && crn == 1 && crm == 0 && opc2 == 1) {
+       /* trapped by HCR.TAC */
+       if (HSR_MATCH_MCR_MRC(ctx->hsr, 1, 0, 0, 1)) { /* ACTLR */
                /* Do not let the guest disable coherency by writing ACTLR... */
                if (read) {
                        unsigned long val;
@@ -258,10 +255,8 @@ static int arch_handle_cp15_32(struct trap_context *ctx)
 static int arch_handle_cp15_64(struct trap_context *ctx)
 {
        unsigned long rt_val, rt2_val;
-       u32 opc1        = ctx->hsr >> 16 & 0x7;
        u32 rt2         = ctx->hsr >> 10 & 0xf;
        u32 rt          = ctx->hsr >> 5 & 0xf;
-       u32 crm         = ctx->hsr >> 1 & 0xf;
        u32 read        = ctx->hsr & 1;
 
        if (!read) {
@@ -270,16 +265,12 @@ static int arch_handle_cp15_64(struct trap_context *ctx)
        }
 
 #ifdef CONFIG_ARM_GIC_V3
-       /* Trapped ICC_SGI1R write */
-       if (!read && opc1 == 0 && crm == 12) {
+       /* trapped by HCR.IMO/FMO */
+       if (!read && HSR_MATCH_MCRR_MRRC(ctx->hsr, 0, 12)) { /* ICC_SGI1R */
                arch_skip_instruction(ctx);
                gicv3_handle_sgir_write((u64)rt2_val << 32 | rt_val);
                return TRAP_HANDLED;
        }
-#else
-       /* Avoid `unused' warning... */
-       crm = crm;
-       opc1 = opc1;
 #endif
 
        return TRAP_UNHANDLED;
-- 
2.1.4

-- 
You received this message because you are subscribed to the Google Groups 
"Jailhouse" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to jailhouse-dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to