xref: /rk3399_ARM-atf/plat/arm/common/arm_tzc_dmc500.c (revision 61f72a34250d063da67f4fc2b0eb8c3fda3376be)
1 /*
2  * Copyright (c) 2016-2018, ARM Limited and Contributors. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 #include <arm_def.h>
8 #include <assert.h>
9 #include <debug.h>
10 #include <platform_def.h>
11 #include <tzc_dmc500.h>
12 
13 /*******************************************************************************
14  * Initialize the DMC500-TrustZone Controller for ARM standard platforms.
15  * When booting an EL3 payload, this is simplified: we configure region 0 with
16  * secure access only and do not enable any other region.
17  ******************************************************************************/
18 void arm_tzc_dmc500_setup(tzc_dmc500_driver_data_t *plat_driver_data,
19 			const arm_tzc_regions_info_t *tzc_regions)
20 {
21 #ifndef EL3_PAYLOAD_BASE
22 	int region_index = 1;
23 	const arm_tzc_regions_info_t *p;
24 	const arm_tzc_regions_info_t init_tzc_regions[] = {
25 		ARM_TZC_REGIONS_DEF,
26 		{0}
27 	};
28 #endif
29 
30 	assert(plat_driver_data);
31 
32 	INFO("Configuring DMC-500 TZ Settings\n");
33 
34 	tzc_dmc500_driver_init(plat_driver_data);
35 
36 #ifndef EL3_PAYLOAD_BASE
37 	if (tzc_regions == NULL)
38 		p = init_tzc_regions;
39 	else
40 		p = tzc_regions;
41 
42 	/* Region 0 set to no access by default */
43 	tzc_dmc500_configure_region0(TZC_REGION_S_NONE, 0);
44 
45 	/* Rest Regions set according to tzc_regions array */
46 	for (; p->base != 0ULL; p++) {
47 		tzc_dmc500_configure_region(region_index, p->base, p->end,
48 					    p->sec_attr, p->nsaid_permissions);
49 		region_index++;
50 	}
51 
52 	INFO("Total %d regions set.\n", region_index);
53 
54 #else
55 	/* Allow secure access only to DRAM for EL3 payloads */
56 	tzc_dmc500_configure_region0(TZC_REGION_S_RDWR, 0);
57 #endif
58 	/*
59 	 * Raise an exception if a NS device tries to access secure memory
60 	 * TODO: Add interrupt handling support.
61 	 */
62 	tzc_dmc500_set_action(TZC_ACTION_RV_LOWERR);
63 
64 	/*
65 	 * Flush the configuration settings to have an affect. Validate
66 	 * flush by checking FILTER_EN is set on region 1 attributes
67 	 * register.
68 	 */
69 	tzc_dmc500_config_complete();
70 
71 	/*
72 	 * Wait for the flush to complete.
73 	 * TODO: Have a timeout for this loop
74 	 */
75 	while (tzc_dmc500_verify_complete())
76 		;
77 }
78