Move locking out of vcpu_on to callers.

Also introduces vcpu_lock and related functions for locking a vcpu struct.

Change-Id: I870b9fb7786f7e31ff424c9debbb0dbf72a770e4
diff --git a/inc/hf/cpu.h b/inc/hf/cpu.h
index 45dbb4f..3c5db07 100644
--- a/inc/hf/cpu.h
+++ b/inc/hf/cpu.h
@@ -93,6 +93,11 @@
 	bool regs_available;
 };
 
+/** Encapsulates a vCPU whose lock is held. */
+struct vcpu_locked {
+	struct vcpu *vcpu;
+};
+
 /* TODO: Update alignment such that cpus are in different cache lines. */
 struct cpu {
 	/** CPU identifier. Doesn't have to be contiguous. */
@@ -123,8 +128,10 @@
 void cpu_off(struct cpu *c);
 struct cpu *cpu_find(uint64_t id);
 
+struct vcpu_locked vcpu_lock(struct vcpu *vcpu);
+void vcpu_unlock(struct vcpu_locked *locked);
 void vcpu_init(struct vcpu *vcpu, struct vm *vm);
-void vcpu_on(struct vcpu *vcpu, ipaddr_t entry, uintreg_t arg);
+void vcpu_on(struct vcpu_locked vcpu, ipaddr_t entry, uintreg_t arg);
 size_t vcpu_index(const struct vcpu *vcpu);
 void vcpu_secondary_reset_and_start(struct vcpu *vcpu, ipaddr_t entry,
 				    uintreg_t arg);