The entry address for a VM is an IPA.

Change-Id: I9b447796789082c031c8a342a283d3050cf15ccb
diff --git a/inc/addr.h b/inc/addr.h
index 24a910c..964660b 100644
--- a/inc/addr.h
+++ b/inc/addr.h
@@ -86,6 +86,14 @@
 }
 
 /**
+ * Casts a physical address to an intermediate physical address.
+ */
+static inline ipaddr_t ipa_from_pa(paddr_t pa)
+{
+	return ipa_init(pa_addr(pa));
+}
+
+/**
  * Casts a virtual address to a physical address.
  */
 static inline paddr_t pa_from_va(vaddr_t va)
diff --git a/inc/cpu.h b/inc/cpu.h
index d5bd29b..e949db7 100644
--- a/inc/cpu.h
+++ b/inc/cpu.h
@@ -5,6 +5,7 @@
 #include <stddef.h>
 #include <stdint.h>
 
+#include "addr.h"
 #include "arch_cpu.h"
 #include "spinlock.h"
 
@@ -52,7 +53,7 @@
 size_t cpu_index(struct cpu *c);
 void cpu_irq_enable(struct cpu *c);
 void cpu_irq_disable(struct cpu *c);
-bool cpu_on(struct cpu *c, size_t entry, size_t arg);
+bool cpu_on(struct cpu *c, ipaddr_t entry, size_t arg);
 void cpu_off(struct cpu *c);
 struct cpu *cpu_find(size_t id);
 
diff --git a/inc/vm.h b/inc/vm.h
index 2fb3bbf..eb5fd2a 100644
--- a/inc/vm.h
+++ b/inc/vm.h
@@ -27,7 +27,7 @@
 };
 
 bool vm_init(struct vm *vm, uint32_t id, uint32_t vcpu_count);
-void vm_start_vcpu(struct vm *vm, size_t index, size_t entry, size_t arg,
+void vm_start_vcpu(struct vm *vm, size_t index, ipaddr_t entry, size_t arg,
 		   bool is_primary);
 void vm_set_current(struct vm *vm);
 
diff --git a/src/arch/aarch64/handler.c b/src/arch/aarch64/handler.c
index f5bdd21..bcc67e6 100644
--- a/src/arch/aarch64/handler.c
+++ b/src/arch/aarch64/handler.c
@@ -124,7 +124,7 @@
 			break;
 		}
 
-		if (cpu_on(c, arg1, arg2)) {
+		if (cpu_on(c, ipa_init(arg1), arg2)) {
 			*ret = PSCI_RETURN_ALREADY_ON;
 			break;
 		}
diff --git a/src/arch/aarch64/inc/arch_cpu.h b/src/arch/aarch64/inc/arch_cpu.h
index 933de8e..681f981 100644
--- a/src/arch/aarch64/inc/arch_cpu.h
+++ b/src/arch/aarch64/inc/arch_cpu.h
@@ -6,6 +6,8 @@
 #include <stddef.h>
 #include <stdint.h>
 
+#include "addr.h"
+
 struct arch_regs {
 	/* General purpose registers. */
 	uint64_t r[31];
@@ -91,13 +93,13 @@
 	__asm__ volatile("msr cnthctl_el2, %0" ::"r"(cnthctl));
 }
 
-static inline void arch_regs_init(struct arch_regs *r, size_t pc, size_t arg,
+static inline void arch_regs_init(struct arch_regs *r, ipaddr_t pc, size_t arg,
 				  bool is_primary)
 {
 	/* TODO: Use constant here. */
 	r->spsr = 5 |	 /* M bits, set to EL1h. */
 		  (0xf << 6); /* DAIF bits set; disable interrupts. */
-	r->pc = pc;
+	r->pc = ipa_addr(pc);
 	r->r[0] = arg;
 }
 
diff --git a/src/cpu.c b/src/cpu.c
index 6cd0a2b..d4e7900 100644
--- a/src/cpu.c
+++ b/src/cpu.c
@@ -61,7 +61,7 @@
 /**
  * Turns CPU on and returns the previous state.
  */
-bool cpu_on(struct cpu *c, size_t entry, size_t arg)
+bool cpu_on(struct cpu *c, ipaddr_t entry, size_t arg)
 {
 	bool prev;
 
diff --git a/src/load.c b/src/load.c
index 6fb7f82..9cb430e 100644
--- a/src/load.c
+++ b/src/load.c
@@ -113,7 +113,7 @@
 	}
 
 	{
-		size_t tmp = (size_t)&load_primary;
+		uintpaddr_t tmp = (uintpaddr_t)&load_primary;
 		tmp = (tmp + 0x80000 - 1) & ~(0x80000 - 1);
 		if (!vm_init(&primary_vm, 0, MAX_CPUS)) {
 			dlog("Unable to initialise primary vm\n");
@@ -137,7 +137,7 @@
 			return false;
 		}
 
-		vm_start_vcpu(&primary_vm, 0, tmp, kernel_arg, true);
+		vm_start_vcpu(&primary_vm, 0, ipa_init(tmp), kernel_arg, true);
 	}
 
 	return true;
@@ -170,6 +170,7 @@
 	     memiter_parse_str(&it, &str) && count < MAX_VMS;
 	     count++) {
 		struct memiter kernel;
+		ipaddr_t secondary_mem_begin;
 
 		if (!memiter_find_file(cpio, &str, &kernel)) {
 			dlog("Unable to load kernel for vm %u\n", count);
@@ -191,6 +192,7 @@
 			continue;
 		}
 
+		secondary_mem_begin = ipa_from_pa(*mem_end);
 		*mem_end = pa_init(pa_addr(*mem_end) - mem);
 		if (!copy_to_unmaped(*mem_end, kernel.next,
 				     kernel.limit - kernel.next)) {
@@ -231,9 +233,7 @@
 		dlog("Loaded VM%u with %u vcpus, entry at 0x%x\n", count, cpu,
 		     pa_addr(*mem_end));
 
-		// TODO: entry is a size_t which seems to be wrong, what should
-		// it be?
-		vm_start_vcpu(secondary_vm + count, 0, pa_addr(*mem_end), 0,
+		vm_start_vcpu(secondary_vm + count, 0, secondary_mem_begin, 0,
 			      false);
 	}
 
diff --git a/src/vm.c b/src/vm.c
index 66be66e..d2da22e 100644
--- a/src/vm.c
+++ b/src/vm.c
@@ -22,7 +22,7 @@
 }
 
 /* TODO: Shall we use index or id here? */
-void vm_start_vcpu(struct vm *vm, size_t index, size_t entry, size_t arg,
+void vm_start_vcpu(struct vm *vm, size_t index, ipaddr_t entry, size_t arg,
 		   bool is_primary)
 {
 	struct vcpu *vcpu = vm->vcpus + index;