KVM: ARM: Power State Coordination Interface implementation
[linux-2.6-block.git] / arch / arm / kvm / arm.c
index 8680b9ffd2aea6d2dfe9c5dd76257daf0afd884f..2d30e3afdaf99a01c764b0ac1e557c63f7a639b2 100644 (file)
@@ -43,6 +43,7 @@
 #include <asm/kvm_mmu.h>
 #include <asm/kvm_emulate.h>
 #include <asm/kvm_coproc.h>
+#include <asm/kvm_psci.h>
 #include <asm/opcodes.h>
 
 #ifdef REQUIRES_VIRT
@@ -160,6 +161,7 @@ int kvm_dev_ioctl_check_extension(long ext)
        case KVM_CAP_SYNC_MMU:
        case KVM_CAP_DESTROY_MEMORY_REGION_WORKS:
        case KVM_CAP_ONE_REG:
+       case KVM_CAP_ARM_PSCI:
                r = 1;
                break;
        case KVM_CAP_COALESCED_MMIO:
@@ -443,14 +445,18 @@ static int handle_hvc(struct kvm_vcpu *vcpu, struct kvm_run *run)
        trace_kvm_hvc(*vcpu_pc(vcpu), *vcpu_reg(vcpu, 0),
                      vcpu->arch.hsr & HSR_HVC_IMM_MASK);
 
+       if (kvm_psci_call(vcpu))
+               return 1;
+
        kvm_inject_undefined(vcpu);
        return 1;
 }
 
 static int handle_smc(struct kvm_vcpu *vcpu, struct kvm_run *run)
 {
-       /* We don't support SMC; don't do that. */
-       kvm_debug("smc: at %08x", *vcpu_pc(vcpu));
+       if (kvm_psci_call(vcpu))
+               return 1;
+
        kvm_inject_undefined(vcpu);
        return 1;
 }
@@ -589,9 +595,26 @@ static int kvm_vcpu_first_run_init(struct kvm_vcpu *vcpu)
                return 0;
 
        vcpu->arch.has_run_once = true;
+
+       /*
+        * Handle the "start in power-off" case by calling into the
+        * PSCI code.
+        */
+       if (test_and_clear_bit(KVM_ARM_VCPU_POWER_OFF, vcpu->arch.features)) {
+               *vcpu_reg(vcpu, 0) = KVM_PSCI_FN_CPU_OFF;
+               kvm_psci_call(vcpu);
+       }
+
        return 0;
 }
 
+static void vcpu_pause(struct kvm_vcpu *vcpu)
+{
+       wait_queue_head_t *wq = kvm_arch_vcpu_wq(vcpu);
+
+       wait_event_interruptible(*wq, !vcpu->arch.pause);
+}
+
 /**
  * kvm_arch_vcpu_ioctl_run - the main VCPU run function to execute guest code
  * @vcpu:      The VCPU pointer
@@ -635,6 +658,9 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *run)
 
                update_vttbr(vcpu->kvm);
 
+               if (vcpu->arch.pause)
+                       vcpu_pause(vcpu);
+
                local_irq_disable();
 
                /*