KVM: PPC: Move ONE_REG AltiVec support to powerpc
authorMihai Caraman <mihai.caraman@freescale.com>
Wed, 20 Aug 2014 13:36:25 +0000 (16:36 +0300)
committerAlexander Graf <agraf@suse.de>
Mon, 22 Sep 2014 08:11:33 +0000 (10:11 +0200)
Move ONE_REG AltiVec support to powerpc generic layer.

Signed-off-by: Mihai Caraman <mihai.caraman@freescale.com>
Signed-off-by: Alexander Graf <agraf@suse.de>
arch/powerpc/include/uapi/asm/kvm.h
arch/powerpc/kvm/book3s.c
arch/powerpc/kvm/powerpc.c

index 3ca357a7a26a9b1071694eae50a37eb50bad9192..ab4d4732c492ebc4dd9514733cbb8461af0dbf87 100644 (file)
@@ -476,6 +476,11 @@ struct kvm_get_htab_header {
 
 /* FP and vector status/control registers */
 #define KVM_REG_PPC_FPSCR      (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x80)
+/*
+ * VSCR register is documented as a 32-bit register in the ISA, but it can
+ * only be accesses via a vector register. Expose VSCR as a 32-bit register
+ * even though the kernel represents it as a 128-bit vector.
+ */
 #define KVM_REG_PPC_VSCR       (KVM_REG_PPC | KVM_REG_SIZE_U32 | 0x81)
 
 /* Virtual processor areas */
index 26868e207ff079dc6e5abb6350d2db2cf1f7a287..1b5adda2a2247381d9b589bbd0de69eb11326cfe 100644 (file)
@@ -558,25 +558,6 @@ int kvmppc_get_one_reg(struct kvm_vcpu *vcpu, u64 id,
                case KVM_REG_PPC_FPSCR:
                        *val = get_reg_val(id, vcpu->arch.fp.fpscr);
                        break;
-#ifdef CONFIG_ALTIVEC
-               case KVM_REG_PPC_VR0 ... KVM_REG_PPC_VR31:
-                       if (!cpu_has_feature(CPU_FTR_ALTIVEC)) {
-                               r = -ENXIO;
-                               break;
-                       }
-                       val->vval = vcpu->arch.vr.vr[id - KVM_REG_PPC_VR0];
-                       break;
-               case KVM_REG_PPC_VSCR:
-                       if (!cpu_has_feature(CPU_FTR_ALTIVEC)) {
-                               r = -ENXIO;
-                               break;
-                       }
-                       *val = get_reg_val(id, vcpu->arch.vr.vscr.u[3]);
-                       break;
-               case KVM_REG_PPC_VRSAVE:
-                       *val = get_reg_val(id, vcpu->arch.vrsave);
-                       break;
-#endif /* CONFIG_ALTIVEC */
 #ifdef CONFIG_VSX
                case KVM_REG_PPC_VSR0 ... KVM_REG_PPC_VSR31:
                        if (cpu_has_feature(CPU_FTR_VSX)) {
@@ -653,29 +634,6 @@ int kvmppc_set_one_reg(struct kvm_vcpu *vcpu, u64 id,
                case KVM_REG_PPC_FPSCR:
                        vcpu->arch.fp.fpscr = set_reg_val(id, *val);
                        break;
-#ifdef CONFIG_ALTIVEC
-               case KVM_REG_PPC_VR0 ... KVM_REG_PPC_VR31:
-                       if (!cpu_has_feature(CPU_FTR_ALTIVEC)) {
-                               r = -ENXIO;
-                               break;
-                       }
-                       vcpu->arch.vr.vr[id - KVM_REG_PPC_VR0] = val->vval;
-                       break;
-               case KVM_REG_PPC_VSCR:
-                       if (!cpu_has_feature(CPU_FTR_ALTIVEC)) {
-                               r = -ENXIO;
-                               break;
-                       }
-                       vcpu->arch.vr.vscr.u[3] = set_reg_val(id, *val);
-                       break;
-               case KVM_REG_PPC_VRSAVE:
-                       if (!cpu_has_feature(CPU_FTR_ALTIVEC)) {
-                               r = -ENXIO;
-                               break;
-                       }
-                       vcpu->arch.vrsave = set_reg_val(id, *val);
-                       break;
-#endif /* CONFIG_ALTIVEC */
 #ifdef CONFIG_VSX
                case KVM_REG_PPC_VSR0 ... KVM_REG_PPC_VSR31:
                        if (cpu_has_feature(CPU_FTR_VSX)) {
index 8a26126db482db137b0a78589d6f42f33a33a61c..0c7d1917c23de681c2d8c2001aaec8cbcc281b0d 100644 (file)
@@ -921,6 +921,29 @@ int kvm_vcpu_ioctl_get_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg)
        if (r == -EINVAL) {
                r = 0;
                switch (reg->id) {
+#ifdef CONFIG_ALTIVEC
+               case KVM_REG_PPC_VR0 ... KVM_REG_PPC_VR31:
+                       if (!cpu_has_feature(CPU_FTR_ALTIVEC)) {
+                               r = -ENXIO;
+                               break;
+                       }
+                       vcpu->arch.vr.vr[reg->id - KVM_REG_PPC_VR0] = val.vval;
+                       break;
+               case KVM_REG_PPC_VSCR:
+                       if (!cpu_has_feature(CPU_FTR_ALTIVEC)) {
+                               r = -ENXIO;
+                               break;
+                       }
+                       vcpu->arch.vr.vscr.u[3] = set_reg_val(reg->id, val);
+                       break;
+               case KVM_REG_PPC_VRSAVE:
+                       if (!cpu_has_feature(CPU_FTR_ALTIVEC)) {
+                               r = -ENXIO;
+                               break;
+                       }
+                       vcpu->arch.vrsave = set_reg_val(reg->id, val);
+                       break;
+#endif /* CONFIG_ALTIVEC */
                default:
                        r = -EINVAL;
                        break;
@@ -953,6 +976,25 @@ int kvm_vcpu_ioctl_set_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg)
        if (r == -EINVAL) {
                r = 0;
                switch (reg->id) {
+#ifdef CONFIG_ALTIVEC
+               case KVM_REG_PPC_VR0 ... KVM_REG_PPC_VR31:
+                       if (!cpu_has_feature(CPU_FTR_ALTIVEC)) {
+                               r = -ENXIO;
+                               break;
+                       }
+                       val.vval = vcpu->arch.vr.vr[reg->id - KVM_REG_PPC_VR0];
+                       break;
+               case KVM_REG_PPC_VSCR:
+                       if (!cpu_has_feature(CPU_FTR_ALTIVEC)) {
+                               r = -ENXIO;
+                               break;
+                       }
+                       val = get_reg_val(reg->id, vcpu->arch.vr.vscr.u[3]);
+                       break;
+               case KVM_REG_PPC_VRSAVE:
+                       val = get_reg_val(reg->id, vcpu->arch.vrsave);
+                       break;
+#endif /* CONFIG_ALTIVEC */
                default:
                        r = -EINVAL;
                        break;