Add locking for the hypervisor's page table.

Bug: 133217279

Change-Id: I04216838006b02b03a8f3f900d4dbd18521d5db2
diff --git a/inc/hf/boot_params.h b/inc/hf/boot_params.h
index 8c9220b..591e353 100644
--- a/inc/hf/boot_params.h
+++ b/inc/hf/boot_params.h
@@ -47,5 +47,7 @@
 	paddr_t initrd_end;
 };
 
-bool plat_get_boot_params(struct boot_params *p, struct mpool *ppool);
-bool plat_update_boot_params(struct boot_params_update *p, struct mpool *ppool);
+bool plat_get_boot_params(struct mm_stage1_locked stage1_locked,
+			  struct boot_params *p, struct mpool *ppool);
+bool plat_update_boot_params(struct mm_stage1_locked stage1_locked,
+			     struct boot_params_update *p, struct mpool *ppool);
diff --git a/inc/hf/fdt_handler.h b/inc/hf/fdt_handler.h
index a454713..bcb8c8b 100644
--- a/inc/hf/fdt_handler.h
+++ b/inc/hf/fdt_handler.h
@@ -21,14 +21,16 @@
 #include "hf/mm.h"
 #include "hf/mpool.h"
 
-struct fdt_header *fdt_map(paddr_t fdt_addr, struct fdt_node *n,
+struct fdt_header *fdt_map(struct mm_stage1_locked stage1_locked,
+			   paddr_t fdt_addr, struct fdt_node *n,
 			   struct mpool *ppool);
-bool fdt_unmap(struct fdt_header *fdt, struct mpool *ppool);
+bool fdt_unmap(struct mm_stage1_locked stage1_locked, struct fdt_header *fdt,
+	       struct mpool *ppool);
 void fdt_find_cpus(const struct fdt_node *root, uint64_t *cpu_ids,
 		   size_t *cpu_count);
 void fdt_find_memory_ranges(const struct fdt_node *root, struct boot_params *p);
 bool fdt_find_initrd(struct fdt_node *n, paddr_t *begin, paddr_t *end);
 
 /** Apply an update to the FDT. */
-bool fdt_patch(paddr_t fdt_addr, struct boot_params_update *p,
-	       struct mpool *ppool);
+bool fdt_patch(struct mm_stage1_locked stage1_locked, paddr_t fdt_addr,
+	       struct boot_params_update *p, struct mpool *ppool);
diff --git a/inc/hf/load.h b/inc/hf/load.h
index f0b13b7..2d9394a 100644
--- a/inc/hf/load.h
+++ b/inc/hf/load.h
@@ -25,8 +25,10 @@
 #include "hf/mm.h"
 #include "hf/mpool.h"
 
-bool load_primary(const struct memiter *cpio, uintreg_t kernel_arg,
+bool load_primary(struct mm_stage1_locked stage1_locked,
+		  const struct memiter *cpio, uintreg_t kernel_arg,
 		  struct memiter *initrd, struct mpool *ppool);
-bool load_secondary(const struct memiter *cpio,
+bool load_secondary(struct mm_stage1_locked stage1_locked,
+		    const struct memiter *cpio,
 		    const struct boot_params *params,
 		    struct boot_params_update *update, struct mpool *ppool);
diff --git a/inc/hf/mm.h b/inc/hf/mm.h
index ed595a7..b34fb2c 100644
--- a/inc/hf/mm.h
+++ b/inc/hf/mm.h
@@ -86,6 +86,11 @@
 	paddr_t root;
 };
 
+/** Represents the curretly locked stage-1 page table of the hypervisor. */
+struct mm_stage1_locked {
+	struct mm_ptable *ptable;
+};
+
 void mm_vm_enable_invalidation(void);
 
 bool mm_vm_init(struct mm_ptable *t, struct mpool *ppool);
@@ -100,9 +105,13 @@
 bool mm_vm_get_mode(struct mm_ptable *t, ipaddr_t begin, ipaddr_t end,
 		    int *mode);
 
+struct mm_stage1_locked mm_lock_stage1(void);
+void mm_unlock_stage1(struct mm_stage1_locked *lock);
+void *mm_identity_map(struct mm_stage1_locked stage1_locked, paddr_t begin,
+		      paddr_t end, int mode, struct mpool *ppool);
+bool mm_unmap(struct mm_stage1_locked stage1_locked, paddr_t begin, paddr_t end,
+	      struct mpool *ppool);
+void mm_defrag(struct mm_stage1_locked stage1_locked, struct mpool *ppool);
+
 bool mm_init(struct mpool *ppool);
 bool mm_cpu_init(void);
-void *mm_identity_map(paddr_t begin, paddr_t end, int mode,
-		      struct mpool *ppool);
-bool mm_unmap(paddr_t begin, paddr_t end, struct mpool *ppool);
-void mm_defrag(struct mpool *ppool);
diff --git a/inc/hf/plat/console.h b/inc/hf/plat/console.h
index 604ac26..dbce103 100644
--- a/inc/hf/plat/console.h
+++ b/inc/hf/plat/console.h
@@ -16,6 +16,7 @@
 
 #pragma once
 
+#include "hf/mm.h"
 #include "hf/mpool.h"
 #include "hf/vm.h"
 
@@ -23,7 +24,8 @@
 void plat_console_init(void);
 
 /** Initialises any memory mappings that the console driver needs. */
-void plat_console_mm_init(struct mpool *ppool);
+void plat_console_mm_init(struct mm_stage1_locked stage1_locked,
+			  struct mpool *ppool);
 
 /** Initialises any per-VM memory mappings that the console driver needs. */
 void plat_console_vm_mm_init(struct vm *vm, struct mpool *ppool);