mirror of
https://github.com/ARM-software/arm-trusted-firmware.git
synced 2025-04-25 06:19:56 +00:00
xlat_tables_v2: get unmap action type with helper function.
This patch introduces helper function 'xlat_tables_unmap_region_action' to get the required action type from given arguments when unmapping the specified region. it reduces cyclomatic code complexity in xlat_tables_unmap_region function. Cyclomatic complexity calculated using 'Coverity' fixes arm-software/tf-issues#673 Signed-off-by: David Pu <dpu@nvidia.com>
This commit is contained in:
parent
5ba32a7660
commit
3ff6e401f9
1 changed files with 64 additions and 49 deletions
|
@ -234,49 +234,15 @@ typedef enum {
|
|||
#if PLAT_XLAT_TABLES_DYNAMIC
|
||||
|
||||
/*
|
||||
* Recursive function that writes to the translation tables and unmaps the
|
||||
* From the given arguments, it decides which action to take when unmapping the
|
||||
* specified region.
|
||||
*/
|
||||
static void xlat_tables_unmap_region(xlat_ctx_t *ctx, mmap_region_t *mm,
|
||||
const uintptr_t table_base_va,
|
||||
uint64_t *const table_base,
|
||||
const unsigned int table_entries,
|
||||
const unsigned int level)
|
||||
static action_t xlat_tables_unmap_region_action(const mmap_region_t *mm,
|
||||
const uintptr_t table_idx_va, const uintptr_t table_idx_end_va,
|
||||
const unsigned int level, const uint64_t desc_type)
|
||||
{
|
||||
assert((level >= ctx->base_level) && (level <= XLAT_TABLE_LEVEL_MAX));
|
||||
|
||||
uint64_t *subtable;
|
||||
uint64_t desc;
|
||||
|
||||
uintptr_t table_idx_va;
|
||||
uintptr_t table_idx_end_va; /* End VA of this entry */
|
||||
|
||||
uintptr_t region_end_va = mm->base_va + mm->size - 1U;
|
||||
|
||||
unsigned int table_idx;
|
||||
|
||||
if (mm->base_va > table_base_va) {
|
||||
/* Find the first index of the table affected by the region. */
|
||||
table_idx_va = mm->base_va & ~XLAT_BLOCK_MASK(level);
|
||||
|
||||
table_idx = (unsigned int)((table_idx_va - table_base_va) >>
|
||||
XLAT_ADDR_SHIFT(level));
|
||||
|
||||
assert(table_idx < table_entries);
|
||||
} else {
|
||||
/* Start from the beginning of the table. */
|
||||
table_idx_va = table_base_va;
|
||||
table_idx = 0;
|
||||
}
|
||||
|
||||
while (table_idx < table_entries) {
|
||||
|
||||
table_idx_end_va = table_idx_va + XLAT_BLOCK_SIZE(level) - 1U;
|
||||
|
||||
desc = table_base[table_idx];
|
||||
uint64_t desc_type = desc & DESC_MASK;
|
||||
|
||||
action_t action;
|
||||
uintptr_t region_end_va = mm->base_va + mm->size - 1U;
|
||||
|
||||
if ((mm->base_va <= table_idx_va) &&
|
||||
(region_end_va >= table_idx_end_va)) {
|
||||
|
@ -326,6 +292,55 @@ static void xlat_tables_unmap_region(xlat_ctx_t *ctx, mmap_region_t *mm,
|
|||
action = ACTION_NONE;
|
||||
}
|
||||
|
||||
return action;
|
||||
}
|
||||
/*
|
||||
* Recursive function that writes to the translation tables and unmaps the
|
||||
* specified region.
|
||||
*/
|
||||
static void xlat_tables_unmap_region(xlat_ctx_t *ctx, mmap_region_t *mm,
|
||||
const uintptr_t table_base_va,
|
||||
uint64_t *const table_base,
|
||||
const unsigned int table_entries,
|
||||
const unsigned int level)
|
||||
{
|
||||
assert((level >= ctx->base_level) && (level <= XLAT_TABLE_LEVEL_MAX));
|
||||
|
||||
uint64_t *subtable;
|
||||
uint64_t desc;
|
||||
|
||||
uintptr_t table_idx_va;
|
||||
uintptr_t table_idx_end_va; /* End VA of this entry */
|
||||
|
||||
uintptr_t region_end_va = mm->base_va + mm->size - 1U;
|
||||
|
||||
unsigned int table_idx;
|
||||
|
||||
if (mm->base_va > table_base_va) {
|
||||
/* Find the first index of the table affected by the region. */
|
||||
table_idx_va = mm->base_va & ~XLAT_BLOCK_MASK(level);
|
||||
|
||||
table_idx = (unsigned int)((table_idx_va - table_base_va) >>
|
||||
XLAT_ADDR_SHIFT(level));
|
||||
|
||||
assert(table_idx < table_entries);
|
||||
} else {
|
||||
/* Start from the beginning of the table. */
|
||||
table_idx_va = table_base_va;
|
||||
table_idx = 0;
|
||||
}
|
||||
|
||||
while (table_idx < table_entries) {
|
||||
|
||||
table_idx_end_va = table_idx_va + XLAT_BLOCK_SIZE(level) - 1U;
|
||||
|
||||
desc = table_base[table_idx];
|
||||
uint64_t desc_type = desc & DESC_MASK;
|
||||
|
||||
action_t action = xlat_tables_unmap_region_action(mm,
|
||||
table_idx_va, table_idx_end_va, level,
|
||||
desc_type);
|
||||
|
||||
if (action == ACTION_WRITE_BLOCK_ENTRY) {
|
||||
|
||||
table_base[table_idx] = INVALID_DESC;
|
||||
|
|
Loading…
Add table
Reference in a new issue