Type for page table.
A page table is an array of PTEs but a pte_t pointer is overloaded and
causes confusion when reading. This new type makes it explicit that the
pointer is to a page table.
Change-Id: I167ed43098e6ab1df7c8b680604ba076dd9b74db
diff --git a/inc/hf/mm.h b/inc/hf/mm.h
index 4df8899..0f5a4a6 100644
--- a/inc/hf/mm.h
+++ b/inc/hf/mm.h
@@ -16,6 +16,8 @@
#pragma once
+#include <assert.h>
+#include <stdalign.h>
#include <stdbool.h>
#include <stdint.h>
@@ -23,12 +25,21 @@
#include "hf/addr.h"
+#define PAGE_SIZE (1 << PAGE_BITS)
+#define MM_PTE_PER_PAGE (PAGE_SIZE / sizeof(pte_t))
+
+struct mm_page_table {
+ alignas(PAGE_SIZE) pte_t entries[MM_PTE_PER_PAGE];
+};
+static_assert(sizeof(struct mm_page_table) == PAGE_SIZE,
+ "A page table must take exactly one page.");
+static_assert(alignof(struct mm_page_table) == PAGE_SIZE,
+ "A page table must be page aligned.");
+
struct mm_ptable {
paddr_t table;
};
-#define PAGE_SIZE (1 << PAGE_BITS)
-
/* The following are arch-independent page mapping modes. */
#define MM_MODE_R 0x01 /* read */
#define MM_MODE_W 0x02 /* write */