Use explicit page pool in page table manipulation.

Change-Id: Ibc3c21f815dfae54a541581941e553f79caaaace
diff --git a/inc/hf/alloc.h b/inc/hf/alloc.h
deleted file mode 100644
index 02dde59..0000000
--- a/inc/hf/alloc.h
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * Copyright 2018 Google LLC
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#pragma once
-
-#include <stddef.h>
-
-void halloc_init(size_t base, size_t size);
-void *halloc(size_t size);
-void hfree(void *ptr);
-void *halloc_aligned(size_t size, size_t align);
-void *halloc_aligned_nosync(size_t size, size_t align);
diff --git a/inc/hf/api.h b/inc/hf/api.h
index 692fbac..94e3327 100644
--- a/inc/hf/api.h
+++ b/inc/hf/api.h
@@ -17,10 +17,12 @@
 #pragma once
 
 #include "hf/cpu.h"
+#include "hf/mpool.h"
 #include "hf/vm.h"
 
 #include "vmapi/hf/call.h"
 
+void api_init(struct mpool *ppool);
 int64_t api_vm_get_count(void);
 int64_t api_vcpu_get_count(uint32_t vm_id, const struct vcpu *current);
 struct hf_vcpu_run_return api_vcpu_run(uint32_t vm_id, uint32_t vcpu_idx,
diff --git a/inc/hf/boot_params.h b/inc/hf/boot_params.h
index 7b486d5..db57d56 100644
--- a/inc/hf/boot_params.h
+++ b/inc/hf/boot_params.h
@@ -21,6 +21,7 @@
 #include "hf/arch/cpu.h"
 
 #include "hf/mm.h"
+#include "hf/mpool.h"
 
 #define MAX_MEM_RANGES 20
 
@@ -44,5 +45,5 @@
 	paddr_t initrd_end;
 };
 
-bool plat_get_boot_params(struct boot_params *p);
-bool plat_update_boot_params(struct boot_params_update *p);
+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);
diff --git a/inc/hf/fdt_handler.h b/inc/hf/fdt_handler.h
index 531290b..3f72218 100644
--- a/inc/hf/fdt_handler.h
+++ b/inc/hf/fdt_handler.h
@@ -19,11 +19,14 @@
 #include "hf/boot_params.h"
 #include "hf/fdt.h"
 #include "hf/mm.h"
+#include "hf/mpool.h"
 
-struct fdt_header *fdt_map(paddr_t fdt_addr, struct fdt_node *n);
-bool fdt_unmap(struct fdt_header *fdt);
+struct fdt_header *fdt_map(paddr_t fdt_addr, struct fdt_node *n,
+			   struct mpool *ppool);
+bool fdt_unmap(struct fdt_header *fdt, struct mpool *ppool);
 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);
+bool fdt_patch(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 794e752..cecd2f1 100644
--- a/inc/hf/load.h
+++ b/inc/hf/load.h
@@ -23,9 +23,10 @@
 #include "hf/cpio.h"
 #include "hf/memiter.h"
 #include "hf/mm.h"
+#include "hf/mpool.h"
 
 bool load_primary(const struct memiter *cpio, size_t kernel_arg,
-		  struct memiter *initrd);
+		  struct memiter *initrd, struct mpool *ppool);
 bool load_secondary(const struct memiter *cpio,
 		    const struct boot_params *params,
-		    struct boot_params_update *update);
+		    struct boot_params_update *update, struct mpool *ppool);
diff --git a/inc/hf/mm.h b/inc/hf/mm.h
index 11a7753..472e0e3 100644
--- a/inc/hf/mm.h
+++ b/inc/hf/mm.h
@@ -24,6 +24,7 @@
 #include "hf/arch/mm.h"
 
 #include "hf/addr.h"
+#include "hf/mpool.h"
 
 /* Keep macro alignment */
 /* clang-format off */
@@ -71,24 +72,17 @@
 #define MM_MODE_SHARED  0x0040
 
 /**
- * This flag indicates that memory allocation must not use locks. This is
- * relevant in systems where interlocked operations are only available after
- * virtual memory is enabled.
- */
-#define MM_MODE_NOSYNC 0x0080
-
-/**
  * This flag indicates that the mapping is intended to be used in a first
  * stage translation table, which might have different encodings for the
  * attribute bits than the second stage table.
  */
-#define MM_MODE_STAGE1 0x0100
+#define MM_MODE_STAGE1 0x0080
 
 /**
  * This flag indicates that no TLB invalidations should be issued for the
  * changes in the page table.
  */
-#define MM_MODE_NOINVALIDATE 0x0200
+#define MM_MODE_NOINVALIDATE 0x0100
 
 /* clang-format on */
 
@@ -105,20 +99,22 @@
 	paddr_t root;
 };
 
-bool mm_ptable_init(struct mm_ptable *t, int mode);
-void mm_ptable_fini(struct mm_ptable *t, int mode);
+bool mm_ptable_init(struct mm_ptable *t, int mode, struct mpool *ppool);
+void mm_ptable_fini(struct mm_ptable *t, int mode, struct mpool *ppool);
 void mm_ptable_dump(struct mm_ptable *t, int mode);
-void mm_ptable_defrag(struct mm_ptable *t, int mode);
+void mm_ptable_defrag(struct mm_ptable *t, int mode, struct mpool *ppool);
 
 bool mm_vm_identity_map(struct mm_ptable *t, paddr_t begin, paddr_t end,
-			int mode, ipaddr_t *ipa);
-bool mm_vm_unmap(struct mm_ptable *t, paddr_t begin, paddr_t end, int mode);
-bool mm_vm_unmap_hypervisor(struct mm_ptable *t, int mode);
+			int mode, ipaddr_t *ipa, struct mpool *ppool);
+bool mm_vm_unmap(struct mm_ptable *t, paddr_t begin, paddr_t end, int mode,
+		 struct mpool *ppool);
+bool mm_vm_unmap_hypervisor(struct mm_ptable *t, int mode, struct mpool *ppool);
 bool mm_vm_is_mapped(struct mm_ptable *t, ipaddr_t ipa, int mode);
 bool mm_vm_translate(struct mm_ptable *t, ipaddr_t ipa, paddr_t *pa);
 
-bool mm_init(void);
+bool mm_init(struct mpool *ppool);
 bool mm_cpu_init(void);
-void *mm_identity_map(paddr_t begin, paddr_t end, int mode);
-bool mm_unmap(paddr_t begin, paddr_t end, int mode);
-void mm_defrag(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, int mode, struct mpool *ppool);
+void mm_defrag(struct mpool *ppool);
diff --git a/inc/hf/vm.h b/inc/hf/vm.h
index 69ceac7..6a140b8 100644
--- a/inc/hf/vm.h
+++ b/inc/hf/vm.h
@@ -18,6 +18,7 @@
 
 #include "hf/cpu.h"
 #include "hf/mm.h"
+#include "hf/mpool.h"
 
 enum mailbox_state {
 	/** There is no message in the mailbox. */
@@ -49,7 +50,7 @@
 	struct mailbox mailbox;
 };
 
-bool vm_init(uint32_t vcpu_count, struct vm **new_vm);
+bool vm_init(uint32_t vcpu_count, struct mpool *ppool, struct vm **new_vm);
 uint32_t vm_get_count(void);
 struct vm *vm_get(uint32_t id);
 void vm_start_vcpu(struct vm *vm, size_t index, ipaddr_t entry, uintreg_t arg);