Refactor main entry
vm_get_first_boot returns the PVM in the normal world or the
first booted SP in the secure world. The intent is that primary,
secondary physical core cold boot and CPU off resume into the
pinned vCPU from the first VM. This assumes the PVM in normal
world is the first booted VM.
Change-Id: I3f3833e2e9f1c278df8f5d480a3b16799012dd32
Signed-off-by: Olivier Deprez <olivier.deprez@arm.com>
diff --git a/src/cpu.c b/src/cpu.c
index 0a3fc6f..11eb0a3 100644
--- a/src/cpu.c
+++ b/src/cpu.c
@@ -139,7 +139,8 @@
sl_unlock(&c->lock);
if (!prev) {
- struct vm *vm = vm_find(HF_PRIMARY_VM_ID);
+ /* This returns the first booted VM (e.g. primary in the NWd) */
+ struct vm *vm = vm_get_first_boot();
struct vcpu *vcpu = vm_get_vcpu(vm, cpu_index(c));
struct vcpu_locked vcpu_locked;
diff --git a/src/load.c b/src/load.c
index 660d77c..7accc65 100644
--- a/src/load.c
+++ b/src/load.c
@@ -286,6 +286,9 @@
dlog_info("Loaded primary VM with %u vCPUs, entry at %#x.\n",
vm->vcpu_count, pa_addr(primary_begin));
+ /* Mark the primary to be the first booted VM */
+ vm_update_boot(vm);
+
vcpu_locked = vcpu_lock(vm_get_vcpu(vm, 0));
vcpu_on(vcpu_locked, primary_entry, params->kernel_arg);
vcpu_unlock(&vcpu_locked);
diff --git a/src/main.c b/src/main.c
index ea3d3b0..408a2d1 100644
--- a/src/main.c
+++ b/src/main.c
@@ -15,14 +15,16 @@
*/
struct vcpu *cpu_main(struct cpu *c)
{
+ struct vm *first_boot;
struct vcpu *vcpu;
-#if SECURE_WORLD == 1
- struct vm *first_boot = vm_get_first_boot();
+
+ /*
+ * This returns the PVM in the normal world and the first
+ * booted Secure Partition in the secure world.
+ */
+ first_boot = vm_get_first_boot();
vcpu = vm_get_vcpu(first_boot, cpu_index(c));
-#else
- vcpu = vm_get_vcpu(vm_find(HF_PRIMARY_VM_ID), cpu_index(c));
-#endif
vcpu->cpu = c;