| 
 | 1 | +/*  | 
 | 2 | + * Copyright (c) 2021 Carlo Caione <[email protected]>  | 
 | 3 | + *  | 
 | 4 | + * SPDX-License-Identifier: Apache-2.0  | 
 | 5 | + */  | 
 | 6 | + | 
 | 7 | +#include <zephyr.h>  | 
 | 8 | +#include <linker/linker-defs.h>  | 
 | 9 | +#include <sys/slist.h>  | 
 | 10 | +#include <arch/arm/aarch32/mpu/arm_mpu.h>  | 
 | 11 | +#include <ztest.h>  | 
 | 12 | +#include <string.h>  | 
 | 13 | + | 
 | 14 | +extern const struct arm_mpu_config mpu_config;  | 
 | 15 | + | 
 | 16 | +static arm_mpu_region_attr_t cacheable = REGION_RAM_ATTR(REGION_1M);  | 
 | 17 | +static arm_mpu_region_attr_t noncacheable = REGION_RAM_NOCACHE_ATTR(REGION_1M);  | 
 | 18 | + | 
 | 19 | +static void test_regions(void)  | 
 | 20 | +{  | 
 | 21 | +	int cnt = 0;  | 
 | 22 | + | 
 | 23 | +	for (size_t i = 0; i < mpu_config.num_regions; i++) {  | 
 | 24 | +		const struct arm_mpu_region *r = &mpu_config.mpu_regions[i];  | 
 | 25 | + | 
 | 26 | +		if (!strcmp(r->name, "SRAM_CACHE")) {  | 
 | 27 | +			zassert_equal(r->base, 0x20200000, "Wrong base");  | 
 | 28 | +			zassert_equal(r->attr.rasr, cacheable.rasr,  | 
 | 29 | +				      "Wrong attr for SRAM_CACHE");  | 
 | 30 | +			cnt++;  | 
 | 31 | +		} else if (!strcmp(r->name, "SRAM_NO_CACHE")) {  | 
 | 32 | +			zassert_equal(r->base, 0x20300000, "Wrong base");  | 
 | 33 | +			zassert_equal(r->attr.rasr, noncacheable.rasr,  | 
 | 34 | +				      "Wrong attr for SRAM_NO_CACHE");  | 
 | 35 | +			cnt++;  | 
 | 36 | +		} else if (!strcmp(r->name, "SRAM_DTCM_FAKE")) {  | 
 | 37 | +			zassert_equal(r->base, 0xabcdabcd, "Wrong base");  | 
 | 38 | +			zassert_equal(r->attr.rasr, cacheable.rasr,  | 
 | 39 | +				      "Wrong attr for SRAM_DTCM_FAKE");  | 
 | 40 | +			cnt++;  | 
 | 41 | +		}  | 
 | 42 | +	}  | 
 | 43 | + | 
 | 44 | +	if (cnt != 3) {  | 
 | 45 | +		/*  | 
 | 46 | +		 * SRAM0 and SRAM_NO_MPU should not create any MPU region.  | 
 | 47 | +		 * Check that.  | 
 | 48 | +		 */  | 
 | 49 | +		ztest_test_fail();  | 
 | 50 | +	}  | 
 | 51 | +}  | 
 | 52 | + | 
 | 53 | +void test_main(void)  | 
 | 54 | +{  | 
 | 55 | +	ztest_test_suite(test_c_arm_mpu_regions,  | 
 | 56 | +			ztest_unit_test(test_regions)  | 
 | 57 | +			);  | 
 | 58 | + | 
 | 59 | +	ztest_run_test_suite(test_c_arm_mpu_regions);  | 
 | 60 | +}  | 
0 commit comments