Unify the arch headers.
The arch interface is defined in common headers and each arch has its
own implementation.
Change-Id: I2d783fcd951f2a51458d9c2d4adc5bf72200dde7
diff --git a/inc/hf/addr.h b/inc/hf/addr.h
index b67e1c2..c37601d 100644
--- a/inc/hf/addr.h
+++ b/inc/hf/addr.h
@@ -19,7 +19,7 @@
#include <stddef.h>
#include <stdint.h>
-#include "hf/arch/addr.h"
+#include "hf/arch/types.h"
/** An opaque type for a physical address. */
typedef struct {
diff --git a/inc/hf/arch.h b/inc/hf/arch/barriers.h
similarity index 61%
copy from inc/hf/arch.h
copy to inc/hf/arch/barriers.h
index a07b180..a22d1d1 100644
--- a/inc/hf/arch.h
+++ b/inc/hf/arch/barriers.h
@@ -16,6 +16,20 @@
#pragma once
-#include "hf/cpu.h"
+/**
+ * Ensures all explicit memory accesses before this point are completed before
+ * any later memory accesses are performed.
+ */
+void dmb(void);
-void arch_putchar(char c);
+/**
+ * Ensure all explicit memory access and management instructions have completed
+ * before continuing.
+ */
+void dsb(void);
+
+/**
+ * Flushes the instruction pipeline so that instructions are fetched from
+ * memory.
+ */
+void isb(void);
diff --git a/inc/hf/arch.h b/inc/hf/arch/console.h
similarity index 92%
rename from inc/hf/arch.h
rename to inc/hf/arch/console.h
index a07b180..94cbaba 100644
--- a/inc/hf/arch.h
+++ b/inc/hf/arch/console.h
@@ -16,6 +16,5 @@
#pragma once
-#include "hf/cpu.h"
-
+/** Put a single character on the console. */
void arch_putchar(char c);
diff --git a/inc/hf/arch/cpu.h b/inc/hf/arch/cpu.h
new file mode 100644
index 0000000..24f00c0
--- /dev/null
+++ b/inc/hf/arch/cpu.h
@@ -0,0 +1,56 @@
+/*
+ * 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 <stdbool.h>
+#include <stddef.h>
+#include <stdint.h>
+
+#include "hf/addr.h"
+
+/**
+ * Disables interrutps.
+ */
+void arch_irq_disable(void);
+
+/**
+ * Enables interrupts.
+ */
+void arch_irq_enable(void);
+
+/**
+ * Initializes the register state for a VM.
+ */
+void arch_regs_init(struct arch_regs *r, bool is_primary, uint64_t vmid,
+ paddr_t table, uint32_t index);
+
+/**
+ * Updates the given registers so that when a vcpu runs, it starts off at the
+ * given address (pc) with the given argument.
+ *
+ * This function must only be called on an arch_regs that is known not be in use
+ * by any other physical CPU.
+ */
+void arch_regs_set_pc_arg(struct arch_regs *r, ipaddr_t pc, uintreg_t arg);
+
+/**
+ * Updates the register holding the return value of a function.
+ *
+ * This function must only be called on an arch_regs that is known not be in use
+ * by any other physical CPU.
+ */
+void arch_regs_set_retval(struct arch_regs *r, uintreg_t v);
diff --git a/inc/hf/arch/mm.h b/inc/hf/arch/mm.h
new file mode 100644
index 0000000..0939498
--- /dev/null
+++ b/inc/hf/arch/mm.h
@@ -0,0 +1,139 @@
+/*
+ * 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 <stdbool.h>
+#include <stddef.h>
+
+#include "hf/addr.h"
+
+/*
+ * A page table entry (PTE) will take one of the following forms:
+ *
+ * 1. absent : There is no mapping.
+ * 2. invalid block : Represents a block that is not in the address space.
+ * 3. valid block : Represents a block that is in the address space.
+ * 4. table : Represents a reference to a table of PTEs.
+ */
+
+/**
+ * Creates an absent PTE.
+ */
+pte_t arch_mm_absent_pte(uint8_t level);
+
+/**
+ * Createa a table PTE.
+ */
+pte_t arch_mm_table_pte(uint8_t level, paddr_t pa);
+
+/**
+ * Creates a block PTE.
+ */
+pte_t arch_mm_block_pte(uint8_t level, paddr_t pa, uint64_t attrs);
+
+/**
+ * Chceks whether a block is allowed at the given level of the page table.
+ */
+bool arch_mm_is_block_allowed(uint8_t level);
+
+/**
+ * Determines if a PTE is present i.e. it contains information and therefore
+ * needs to exist in the page table. Any non-absent PTE is present.
+ */
+bool arch_mm_pte_is_present(pte_t pte, uint8_t level);
+
+/**
+ * Determines if a PTE is valid i.e. it can affect the address space. Tables and
+ * valid blocks fall into this category. Invalid blocks do not as they hold
+ * information about blocks that are not in the address space.
+ */
+bool arch_mm_pte_is_valid(pte_t pte, uint8_t level);
+
+/**
+ * Determines if a PTE is a block and represents an address range, valid or
+ * invalid.
+ */
+bool arch_mm_pte_is_block(pte_t pte, uint8_t level);
+
+/**
+ * Determines if a PTE represents a reference to a table of PTEs.
+ */
+bool arch_mm_pte_is_table(pte_t pte, uint8_t level);
+
+/**
+ * Clears the bits of an address that are ignored by the page table. In effect,
+ * the address is rounded down to the start of the corresponding PTE range.
+ */
+paddr_t arch_mm_clear_pa(paddr_t pa);
+
+/**
+ * Extracts the start address if the PTE range.
+ */
+paddr_t arch_mm_block_from_pte(pte_t pte, uint8_t level);
+
+/**
+ * Extracts the address of the table referenced by the PTE/.
+ */
+paddr_t arch_mm_table_from_pte(pte_t pte, uint8_t level);
+
+/**
+ * Extracts the atrobutes of the PTE.
+ */
+uint64_t arch_mm_pte_attrs(pte_t pte, uint8_t level);
+
+/**
+ * Merge the attributes of a block into those of its containing table.
+ */
+uint64_t arch_mm_combine_table_entry_attrs(uint64_t table_attrs,
+ uint64_t block_attrs);
+
+/**
+ * Invalidates hte given range of stage-1 TLB.
+ */
+void arch_mm_invalidate_stage1_range(vaddr_t va_begin, vaddr_t va_end);
+
+/**
+ * Invalidates hte given range of stage-2 TLB.
+ */
+void arch_mm_invalidate_stage2_range(ipaddr_t va_begin, ipaddr_t va_end);
+
+/**
+ * Writes the given range of virtual memory back to the point of unification so
+ * all cores and devices will see the updated values.
+ */
+void arch_mm_write_back_dcache(void *base, size_t size);
+
+/**
+ * Gets teh maximum level allowed in the page table for the given mode.
+ */
+uint8_t arch_mm_max_level(int mode);
+
+/**
+ * Gets the number of concatenated page tables used at the root for the given
+ * mode.
+ */
+uint8_t arch_mm_root_table_count(int mode);
+
+/**
+ * Converts the mode into attributes for a block PTE.
+ */
+uint64_t arch_mm_mode_to_attrs(int mode);
+
+/**
+ * Initialized the arch specific memory management state.
+ */
+bool arch_mm_init(paddr_t table, bool first);