lib/xlat_tables_v2/xlat_tables_core.c
/*
 * Removes the region with given base Virtual Address and size from the given
 * context.
 *
 * Returns:
 *        0: Success.
 *   EINVAL: Invalid values were used as arguments (region not found).
 *    EPERM: Tried to remove a static region.
 */
Removes the region with given base Virtual Address and size from the given
context.

Success.
EINVAL: Invalid values were used as arguments (region not found).
EPERM: Tried to remove a static region.
Removes the region with given base Virtual Address and size from the given context . Success . EINVAL : Invalid values were used as arguments ( region not found ) . EPERM : Tried to remove a static region .
int mmap_remove_dynamic_region_ctx(xlat_ctx_t *ctx, uintptr_t base_va,
				   size_t size)
{
	mmap_region_t *mm = ctx->mmap;
	const mmap_region_t *mm_last = mm + ctx->mmap_num;
	int update_max_va_needed = 0;
	int update_max_pa_needed = 0;
	assert(mm[ctx->mmap_num].size == 0U);
	while (mm->size != 0U) {
		if ((mm->base_va == base_va) && (mm->size == size))
			break;
		++mm;
	}
	if (mm->size == 0U)
		return -EINVAL;
	if ((mm->attr & MT_DYNAMIC) == 0U)
		return -EPERM;
	if ((mm->base_va + mm->size - 1U) == ctx->max_va)
		update_max_va_needed = 1;
	if ((mm->base_pa + mm->size - 1U) == ctx->max_pa)
		update_max_pa_needed = 1;
	if (ctx->initialized != 0) {
		xlat_tables_unmap_region(ctx, mm, 0U, ctx->base_table,
					 ctx->base_table_entries,
					 ctx->base_level);
		xlat_arch_tlbi_va_sync();
	}
	(void)memmove(mm, mm + 1U, (uintptr_t)mm_last - (uintptr_t)mm);
	if (update_max_va_needed == 1) {
		ctx->max_va = 0U;
		mm = ctx->mmap;
		while (mm->size != 0U) {
			if ((mm->base_va + mm->size - 1U) > ctx->max_va)
				ctx->max_va = mm->base_va + mm->size - 1U;
			++mm;
		}
	}
	if (update_max_pa_needed == 1) {
		ctx->max_pa = 0U;
		mm = ctx->mmap;
		while (mm->size != 0U) {
			if ((mm->base_pa + mm->size - 1U) > ctx->max_pa)
				ctx->max_pa = mm->base_pa + mm->size - 1U;
			++mm;
		}
	}
	return 0;
}
int mmap_remove_dynamic_region_ctx ( xlat_ctx_t * ctx , uintptr_t base_va , size_t size ) { mmap_region_t * mm = ctx -> mmap ; const mmap_region_t * mm_last = mm + ctx -> mmap_num ; int update_max_va_needed = 0 ; int update_max_pa_needed = 0 ; assert ( mm [ ctx -> mmap_num ] . size == 0U ) ; while ( mm -> size != 0U ) { if ( ( mm -> base_va == base_va ) && ( mm -> size == size ) ) break ; ++ mm ; } if ( mm -> size == 0U ) return - EINVAL ; if ( ( mm -> attr & MT_DYNAMIC ) == 0U ) return - EPERM ; if ( ( mm -> base_va + mm -> size - 1U ) == ctx -> max_va ) update_max_va_needed = 1 ; if ( ( mm -> base_pa + mm -> size - 1U ) == ctx -> max_pa ) update_max_pa_needed = 1 ; if ( ctx -> initialized != 0 ) { xlat_tables_unmap_region ( ctx , mm , 0U , ctx -> base_table , ctx -> base_table_entries , ctx -> base_level ) ; xlat_arch_tlbi_va_sync ( ) ; } ( void ) memmove ( mm , mm + 1U , ( uintptr_t ) mm_last - ( uintptr_t ) mm ) ; if ( update_max_va_needed == 1 ) { ctx -> max_va = 0U ; mm = ctx -> mmap ; while ( mm -> size != 0U ) { if ( ( mm -> base_va + mm -> size - 1U ) > ctx -> max_va ) ctx -> max_va = mm -> base_va + mm -> size - 1U ; ++ mm ; } } if ( update_max_pa_needed == 1 ) { ctx -> max_pa = 0U ; mm = ctx -> mmap ; while ( mm -> size != 0U ) { if ( ( mm -> base_pa + mm -> size - 1U ) > ctx -> max_pa ) ctx -> max_pa = mm -> base_pa + mm -> size - 1U ; ++ mm ; } } return 0 ; }
Removes the region with given base Virtual Address and size from the given
 context.
Removes the region with given base Virtual Address and size from the given context .
/* Check sanity of mmap array. */ /* Check that the region was found */ /* If the region is static it can't be removed */ /* Check if this region is using the top VAs or PAs. */ /* Update the translation tables if needed */ /* Remove this region by moving the rest down by one place. */ /* Check if we need to update the max VAs and PAs */