Move VM ID from `struct mm_ptable` to `struct vm`.

The ID is a property of the VM and when it is needed along side the
ptable, both pieces of information are available.

Change-Id: I4c6165b931a4acd8128a21a9cc92880a1b47ceae
diff --git a/inc/hf/mm.h b/inc/hf/mm.h
index c96e16a..2f52cb3 100644
--- a/inc/hf/mm.h
+++ b/inc/hf/mm.h
@@ -9,7 +9,6 @@
 
 struct mm_ptable {
 	paddr_t table;
-	uint32_t id;
 };
 
 #define PAGE_SIZE (1 << PAGE_BITS)
@@ -40,7 +39,7 @@
  */
 #define MM_MODE_NOINVALIDATE 0x40
 
-bool mm_ptable_init(struct mm_ptable *t, uint32_t id, int mode);
+bool mm_ptable_init(struct mm_ptable *t, int mode);
 void mm_ptable_dump(struct mm_ptable *t, int mode);
 void mm_ptable_defrag(struct mm_ptable *t, int mode);
 bool mm_ptable_unmap_hypervisor(struct mm_ptable *t, int mode);
diff --git a/inc/hf/vm.h b/inc/hf/vm.h
index 47b1e2a..5389e97 100644
--- a/inc/hf/vm.h
+++ b/inc/hf/vm.h
@@ -18,6 +18,7 @@
 };
 
 struct vm {
+	uint32_t id;
 	struct spinlock lock;
 	uint32_t vcpu_count;
 	struct vcpu vcpus[MAX_CPUS];
diff --git a/src/mm.c b/src/mm.c
index 776f7a6..9c708cf 100644
--- a/src/mm.c
+++ b/src/mm.c
@@ -426,7 +426,7 @@
 /**
  * Initialises the given page table.
  */
-bool mm_ptable_init(struct mm_ptable *t, uint32_t id, int mode)
+bool mm_ptable_init(struct mm_ptable *t, int mode)
 {
 	size_t i;
 	pte_t *table;
@@ -448,7 +448,6 @@
 	/* TODO: halloc could return a virtual or physical address if mm not
 	 * enabled? */
 	t->table = pa_init((uintpaddr_t)table);
-	t->id = id;
 
 	return true;
 }
@@ -556,7 +555,7 @@
 	dlog("rodata: 0x%x - 0x%x\n", rodata_begin, rodata_end);
 	dlog("data: 0x%x - 0x%x\n", data_begin, data_end);
 
-	if (!mm_ptable_init(&ptable, 0, MM_MODE_NOSYNC | MM_MODE_STAGE1)) {
+	if (!mm_ptable_init(&ptable, MM_MODE_NOSYNC | MM_MODE_STAGE1)) {
 		dlog("Unable to allocate memory for page table.\n");
 		return false;
 	}
diff --git a/src/vm.c b/src/vm.c
index 963531a..d03aba8 100644
--- a/src/vm.c
+++ b/src/vm.c
@@ -10,6 +10,7 @@
 
 	memset(vm, 0, sizeof(*vm));
 
+	vm->id = id;
 	vm->vcpu_count = vcpu_count;
 	vm->rpc.state = rpc_state_idle;
 
@@ -18,7 +19,7 @@
 		vcpu_init(vm->vcpus + i, vm);
 	}
 
-	return mm_ptable_init(&vm->ptable, id, 0);
+	return mm_ptable_init(&vm->ptable, 0);
 }
 
 /* TODO: Shall we use index or id here? */
@@ -34,5 +35,5 @@
 void vm_set_current(struct vm *vm)
 {
 	arch_cpu_update(vm == &primary_vm);
-	arch_mm_set_vm(vm->ptable.id, vm->ptable.table);
+	arch_mm_set_vm(vm->id, vm->ptable.table);
 }