diff options
author | Antonio Nino Diaz <antonio.ninodiaz@arm.com> | 2016-12-08 16:03:46 +0000 |
---|---|---|
committer | Antonio Nino Diaz <antonio.ninodiaz@arm.com> | 2016-12-13 15:35:15 +0000 |
commit | d3d6c6e3e9860024cda8766dbcf62f8022a68002 (patch) | |
tree | 221928bee02be9984273850108c2eec894a2647d | |
parent | 1b5fa6ef1082ffb9979df4aad91525eda571eb50 (diff) |
Assert correct granularity when mapping a PA
Each translation table level entry can only map a given virtual
address onto physical addresses of the same granularity. For example,
with the current configuration, a level 2 entry maps blocks of 2 MB,
so the physical address must be aligned to 2 MB. If the address is not
aligned, the MMU will just ignore the lower bits.
This patch adds an assertion to make sure that physical addresses are
always aligned to the correct boundary.
Change-Id: I0ab43df71829d45cdbe323301b3053e08ca99c2c
Signed-off-by: Antonio Nino Diaz <antonio.ninodiaz@arm.com>
-rw-r--r-- | include/lib/xlat_tables.h | 5 | ||||
-rw-r--r-- | lib/xlat_tables/xlat_tables_common.c | 3 |
2 files changed, 8 insertions, 0 deletions
diff --git a/include/lib/xlat_tables.h b/include/lib/xlat_tables.h index 0e9800ab..f4476183 100644 --- a/include/lib/xlat_tables.h +++ b/include/lib/xlat_tables.h @@ -93,6 +93,11 @@ #define L2_XLAT_ADDRESS_SHIFT (L3_XLAT_ADDRESS_SHIFT + XLAT_TABLE_ENTRIES_SHIFT) #define L1_XLAT_ADDRESS_SHIFT (L2_XLAT_ADDRESS_SHIFT + XLAT_TABLE_ENTRIES_SHIFT) #define L0_XLAT_ADDRESS_SHIFT (L1_XLAT_ADDRESS_SHIFT + XLAT_TABLE_ENTRIES_SHIFT) +#define XLAT_ADDR_SHIFT(level) (PAGE_SIZE_SHIFT + \ + ((XLAT_TABLE_LEVEL_MAX - (level)) * XLAT_TABLE_ENTRIES_SHIFT)) + +#define XLAT_BLOCK_SIZE(level) ((u_register_t)1 << XLAT_ADDR_SHIFT(level)) +#define XLAT_BLOCK_MASK(level) (XLAT_BLOCK_SIZE(level) - 1) /* * AP[1] bit is ignored by hardware and is diff --git a/lib/xlat_tables/xlat_tables_common.c b/lib/xlat_tables/xlat_tables_common.c index ebbc9161..808aa33a 100644 --- a/lib/xlat_tables/xlat_tables_common.c +++ b/lib/xlat_tables/xlat_tables_common.c @@ -198,6 +198,9 @@ static uint64_t mmap_desc(unsigned attr, unsigned long long addr_pa, uint64_t desc; int mem_type; + /* Make sure that the granularity is fine enough to map this address. */ + assert((addr_pa & XLAT_BLOCK_MASK(level)) == 0); + desc = addr_pa; /* * There are different translation table descriptors for level 3 and the |