mirror of
https://github.com/ARM-software/arm-trusted-firmware.git
synced 2025-04-24 13:55: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
|
@ -233,6 +233,67 @@ typedef enum {
|
||||||
|
|
||||||
#if PLAT_XLAT_TABLES_DYNAMIC
|
#if PLAT_XLAT_TABLES_DYNAMIC
|
||||||
|
|
||||||
|
/*
|
||||||
|
* From the given arguments, it decides which action to take when unmapping the
|
||||||
|
* specified region.
|
||||||
|
*/
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
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)) {
|
||||||
|
/* Region covers all block */
|
||||||
|
|
||||||
|
if (level == 3U) {
|
||||||
|
/*
|
||||||
|
* Last level, only page descriptors allowed,
|
||||||
|
* erase it.
|
||||||
|
*/
|
||||||
|
assert(desc_type == PAGE_DESC);
|
||||||
|
|
||||||
|
action = ACTION_WRITE_BLOCK_ENTRY;
|
||||||
|
} else {
|
||||||
|
/*
|
||||||
|
* Other levels can have table descriptors. If
|
||||||
|
* so, recurse into it and erase descriptors
|
||||||
|
* inside it as needed. If there is a block
|
||||||
|
* descriptor, just erase it. If an invalid
|
||||||
|
* descriptor is found, this table isn't
|
||||||
|
* actually mapped, which shouldn't happen.
|
||||||
|
*/
|
||||||
|
if (desc_type == TABLE_DESC) {
|
||||||
|
action = ACTION_RECURSE_INTO_TABLE;
|
||||||
|
} else {
|
||||||
|
assert(desc_type == BLOCK_DESC);
|
||||||
|
action = ACTION_WRITE_BLOCK_ENTRY;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if ((mm->base_va <= table_idx_end_va) ||
|
||||||
|
(region_end_va >= table_idx_va)) {
|
||||||
|
/*
|
||||||
|
* Region partially covers block.
|
||||||
|
*
|
||||||
|
* It can't happen in level 3.
|
||||||
|
*
|
||||||
|
* There must be a table descriptor here, if not there
|
||||||
|
* was a problem when mapping the region.
|
||||||
|
*/
|
||||||
|
assert(level < 3U);
|
||||||
|
assert(desc_type == TABLE_DESC);
|
||||||
|
|
||||||
|
action = ACTION_RECURSE_INTO_TABLE;
|
||||||
|
} else {
|
||||||
|
/* The region doesn't cover the block at all */
|
||||||
|
action = ACTION_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return action;
|
||||||
|
}
|
||||||
/*
|
/*
|
||||||
* Recursive function that writes to the translation tables and unmaps the
|
* Recursive function that writes to the translation tables and unmaps the
|
||||||
* specified region.
|
* specified region.
|
||||||
|
@ -276,55 +337,9 @@ static void xlat_tables_unmap_region(xlat_ctx_t *ctx, mmap_region_t *mm,
|
||||||
desc = table_base[table_idx];
|
desc = table_base[table_idx];
|
||||||
uint64_t desc_type = desc & DESC_MASK;
|
uint64_t desc_type = desc & DESC_MASK;
|
||||||
|
|
||||||
action_t action;
|
action_t action = xlat_tables_unmap_region_action(mm,
|
||||||
|
table_idx_va, table_idx_end_va, level,
|
||||||
if ((mm->base_va <= table_idx_va) &&
|
desc_type);
|
||||||
(region_end_va >= table_idx_end_va)) {
|
|
||||||
/* Region covers all block */
|
|
||||||
|
|
||||||
if (level == 3U) {
|
|
||||||
/*
|
|
||||||
* Last level, only page descriptors allowed,
|
|
||||||
* erase it.
|
|
||||||
*/
|
|
||||||
assert(desc_type == PAGE_DESC);
|
|
||||||
|
|
||||||
action = ACTION_WRITE_BLOCK_ENTRY;
|
|
||||||
} else {
|
|
||||||
/*
|
|
||||||
* Other levels can have table descriptors. If
|
|
||||||
* so, recurse into it and erase descriptors
|
|
||||||
* inside it as needed. If there is a block
|
|
||||||
* descriptor, just erase it. If an invalid
|
|
||||||
* descriptor is found, this table isn't
|
|
||||||
* actually mapped, which shouldn't happen.
|
|
||||||
*/
|
|
||||||
if (desc_type == TABLE_DESC) {
|
|
||||||
action = ACTION_RECURSE_INTO_TABLE;
|
|
||||||
} else {
|
|
||||||
assert(desc_type == BLOCK_DESC);
|
|
||||||
action = ACTION_WRITE_BLOCK_ENTRY;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
} else if ((mm->base_va <= table_idx_end_va) ||
|
|
||||||
(region_end_va >= table_idx_va)) {
|
|
||||||
/*
|
|
||||||
* Region partially covers block.
|
|
||||||
*
|
|
||||||
* It can't happen in level 3.
|
|
||||||
*
|
|
||||||
* There must be a table descriptor here, if not there
|
|
||||||
* was a problem when mapping the region.
|
|
||||||
*/
|
|
||||||
assert(level < 3U);
|
|
||||||
assert(desc_type == TABLE_DESC);
|
|
||||||
|
|
||||||
action = ACTION_RECURSE_INTO_TABLE;
|
|
||||||
} else {
|
|
||||||
/* The region doesn't cover the block at all */
|
|
||||||
action = ACTION_NONE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (action == ACTION_WRITE_BLOCK_ENTRY) {
|
if (action == ACTION_WRITE_BLOCK_ENTRY) {
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue