tzc400: adjust filter flag if it is set to FILTER_BIT_ALL

TZC_400_REGION_ATTR_FILTER_BIT_ALL is a simple constant definition, so
it can't get the real filter number to construct the bit flag for all
existing filters. If the platform doesn't have 4 filters, passing
FILTER_BIT_ALL to tzc400_configure_region() will cause assertion or
misconfiguration. So adjust the bit flag against the real filter
number.

Signed-off-by: Heyi Guo <guoheyi@linux.alibaba.com>
Change-Id: Ie5c48303485f3b5015772961ee7c34746121ee84
This commit is contained in:
Heyi Guo 2020-05-13 18:51:49 +08:00
parent 3d66ca6d8c
commit d4c61c3878
1 changed files with 9 additions and 2 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2016-2020, ARM Limited and Contributors. All rights reserved.
* Copyright (c) 2016-2021, ARM Limited and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
@ -162,7 +162,9 @@ void tzc400_configure_region0(unsigned int sec_attr,
/*
* `tzc400_configure_region` is used to program regions into the TrustZone
* controller. A region can be associated with more than one filter. The
* associated filters are passed in as a bitmap (bit0 = filter0).
* associated filters are passed in as a bitmap (bit0 = filter0), except that
* the value TZC_400_REGION_ATTR_FILTER_BIT_ALL selects all filters, based on
* the value of tzc400.num_filters.
* NOTE:
* Region 0 is special; it is preferable to use tzc400_configure_region0
* for this region (see comment for that function).
@ -176,6 +178,11 @@ void tzc400_configure_region(unsigned int filters,
{
assert(tzc400.base != 0U);
/* Adjust filter mask by real filter number */
if (filters == TZC_400_REGION_ATTR_FILTER_BIT_ALL) {
filters = (1U << tzc400.num_filters) - 1U;
}
/* Do range checks on filters and regions. */
assert(((filters >> tzc400.num_filters) == 0U) &&
(region < tzc400.num_regions));