arm_tzc400.c 2.03 KB
Newer Older
1
/*
Roberto Vargas's avatar
Roberto Vargas committed
2
 * Copyright (c) 2014-2018, ARM Limited and Contributors. All rights reserved.
3
 *
dp-arm's avatar
dp-arm committed
4
 * SPDX-License-Identifier: BSD-3-Clause
5
6
7
 */

#include <arm_def.h>
8
#include <arm_spm_def.h>
9
#include <debug.h>
Roberto Vargas's avatar
Roberto Vargas committed
10
#include <plat_arm.h>
11
12
13
14
15
16
17
18
19
20
#include <platform_def.h>
#include <tzc400.h>


/* Weak definitions may be overridden in specific ARM standard platform */
#pragma weak plat_arm_security_setup


/*******************************************************************************
 * Initialize the TrustZone Controller for ARM standard platforms.
21
22
 * When booting an EL3 payload, this is simplified: we configure region 0 with
 * secure access only and do not enable any other region.
23
 ******************************************************************************/
24
void arm_tzc400_setup(const arm_tzc_regions_info_t *tzc_regions)
25
{
26
27
28
29
30
31
32
33
34
#ifndef EL3_PAYLOAD_BASE
	int region_index = 1;
	const arm_tzc_regions_info_t *p;
	const arm_tzc_regions_info_t init_tzc_regions[] = {
		ARM_TZC_REGIONS_DEF,
		{0}
	};
#endif

35
36
	INFO("Configuring TrustZone Controller\n");

37
	tzc400_init(PLAT_ARM_TZC_BASE);
38
39

	/* Disable filters. */
40
	tzc400_disable_filters();
41

42
#ifndef EL3_PAYLOAD_BASE
43
44
45
46
	if (tzc_regions == NULL)
		p = init_tzc_regions;
	else
		p = tzc_regions;
47

48
	/* Region 0 set to no access by default */
49
	tzc400_configure_region0(TZC_REGION_S_NONE, 0);
50

51
52
53
54
55
56
57
58
	/* Rest Regions set according to tzc_regions array */
	for (; p->base != 0ULL; p++) {
		tzc400_configure_region(PLAT_ARM_TZC_FILTERS, region_index,
			p->base, p->end, p->sec_attr, p->nsaid_permissions);
		region_index++;
	}

	INFO("Total %d regions set.\n", region_index);
59
60
61

#else /* if defined(EL3_PAYLOAD_BASE) */

62
63
	/* Allow Secure and Non-secure access to DRAM for EL3 payloads */
	tzc400_configure_region0(TZC_REGION_S_RDWR, PLAT_ARM_TZC_NS_DEV_ACCESS);
64

65
#endif /* EL3_PAYLOAD_BASE */
66
67
68
69
70

	/*
	 * Raise an exception if a NS device tries to access secure memory
	 * TODO: Add interrupt handling support.
	 */
71
	tzc400_set_action(TZC_ACTION_ERR);
72
73

	/* Enable filters. */
74
	tzc400_enable_filters();
75
76
77
78
}

void plat_arm_security_setup(void)
{
79
	arm_tzc400_setup(NULL);
80
}