blob: 0346fa1845d088f364a1cd39d44b8c5001a6bef7 [file] [log] [blame]
Dan Handley9df48042015-03-19 18:58:55 +00001/*
Roberto Vargas2ca18d92018-02-12 12:36:17 +00002 * Copyright (c) 2014-2018, ARM Limited and Contributors. All rights reserved.
Dan Handley9df48042015-03-19 18:58:55 +00003 *
dp-armfa3cf0b2017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
Dan Handley9df48042015-03-19 18:58:55 +00005 */
6
Antonio Nino Diaze0f90632018-12-14 00:18:21 +00007#include <platform_def.h>
8
9#include <common/debug.h>
10#include <drivers/arm/tzc400.h>
11
Dan Handley9df48042015-03-19 18:58:55 +000012#include <arm_def.h>
Antonio Nino Diaz7289f922017-11-09 11:34:09 +000013#include <arm_spm_def.h>
Roberto Vargas2ca18d92018-02-12 12:36:17 +000014#include <plat_arm.h>
Dan Handley9df48042015-03-19 18:58:55 +000015
16/* Weak definitions may be overridden in specific ARM standard platform */
17#pragma weak plat_arm_security_setup
18
19
20/*******************************************************************************
21 * Initialize the TrustZone Controller for ARM standard platforms.
Sandrine Bailleux03897bb2015-11-26 16:31:34 +000022 * When booting an EL3 payload, this is simplified: we configure region 0 with
23 * secure access only and do not enable any other region.
Dan Handley9df48042015-03-19 18:58:55 +000024 ******************************************************************************/
Summer Qin5ce394c2018-03-12 11:28:26 +080025void arm_tzc400_setup(const arm_tzc_regions_info_t *tzc_regions)
Dan Handley9df48042015-03-19 18:58:55 +000026{
Summer Qin5ce394c2018-03-12 11:28:26 +080027#ifndef EL3_PAYLOAD_BASE
Antonio Nino Diaz5f475792018-10-15 14:58:11 +010028 unsigned int region_index = 1U;
Summer Qin5ce394c2018-03-12 11:28:26 +080029 const arm_tzc_regions_info_t *p;
30 const arm_tzc_regions_info_t init_tzc_regions[] = {
31 ARM_TZC_REGIONS_DEF,
32 {0}
33 };
34#endif
35
Dan Handley9df48042015-03-19 18:58:55 +000036 INFO("Configuring TrustZone Controller\n");
37
Soby Mathew9c708b52016-02-26 14:23:19 +000038 tzc400_init(PLAT_ARM_TZC_BASE);
Dan Handley9df48042015-03-19 18:58:55 +000039
40 /* Disable filters. */
Soby Mathew9c708b52016-02-26 14:23:19 +000041 tzc400_disable_filters();
Dan Handley9df48042015-03-19 18:58:55 +000042
Sandrine Bailleux03897bb2015-11-26 16:31:34 +000043#ifndef EL3_PAYLOAD_BASE
Summer Qin5ce394c2018-03-12 11:28:26 +080044 if (tzc_regions == NULL)
45 p = init_tzc_regions;
46 else
47 p = tzc_regions;
Soby Mathew7e4d6652017-05-10 11:50:30 +010048
Dan Handley9df48042015-03-19 18:58:55 +000049 /* Region 0 set to no access by default */
Soby Mathew9c708b52016-02-26 14:23:19 +000050 tzc400_configure_region0(TZC_REGION_S_NONE, 0);
Dan Handley9df48042015-03-19 18:58:55 +000051
Summer Qin5ce394c2018-03-12 11:28:26 +080052 /* Rest Regions set according to tzc_regions array */
53 for (; p->base != 0ULL; p++) {
54 tzc400_configure_region(PLAT_ARM_TZC_FILTERS, region_index,
55 p->base, p->end, p->sec_attr, p->nsaid_permissions);
56 region_index++;
57 }
Dan Handley9df48042015-03-19 18:58:55 +000058
Antonio Nino Diaz5f475792018-10-15 14:58:11 +010059 INFO("Total %u regions set.\n", region_index);
Antonio Nino Diaz7289f922017-11-09 11:34:09 +000060
61#else /* if defined(EL3_PAYLOAD_BASE) */
62
Soby Mathew15b149e2017-11-13 08:29:45 +000063 /* Allow Secure and Non-secure access to DRAM for EL3 payloads */
64 tzc400_configure_region0(TZC_REGION_S_RDWR, PLAT_ARM_TZC_NS_DEV_ACCESS);
Antonio Nino Diaz7289f922017-11-09 11:34:09 +000065
Sandrine Bailleux03897bb2015-11-26 16:31:34 +000066#endif /* EL3_PAYLOAD_BASE */
Dan Handley9df48042015-03-19 18:58:55 +000067
68 /*
69 * Raise an exception if a NS device tries to access secure memory
70 * TODO: Add interrupt handling support.
71 */
Soby Mathew9c708b52016-02-26 14:23:19 +000072 tzc400_set_action(TZC_ACTION_ERR);
Dan Handley9df48042015-03-19 18:58:55 +000073
74 /* Enable filters. */
Soby Mathew9c708b52016-02-26 14:23:19 +000075 tzc400_enable_filters();
Dan Handley9df48042015-03-19 18:58:55 +000076}
77
78void plat_arm_security_setup(void)
79{
Summer Qin5ce394c2018-03-12 11:28:26 +080080 arm_tzc400_setup(NULL);
Dan Handley9df48042015-03-19 18:58:55 +000081}