blob: 89c502cce6c1a032cee6c521a07b69d667760cd5 [file] [log] [blame]
Vikram Kanigiri510d87b2016-01-29 12:32:58 +00001/*
Summer Qin5ce394c2018-03-12 11:28:26 +08002 * Copyright (c) 2016-2018, ARM Limited and Contributors. All rights reserved.
Vikram Kanigiri510d87b2016-01-29 12:32:58 +00003 *
dp-armfa3cf0b2017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
Vikram Kanigiri510d87b2016-01-29 12:32:58 +00005 */
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.
Vikram Kanigiri510d87b2016-01-29 12:32:58 +000015 * 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 ******************************************************************************/
Summer Qin5ce394c2018-03-12 11:28:26 +080018void arm_tzc_dmc500_setup(tzc_dmc500_driver_data_t *plat_driver_data,
19 const arm_tzc_regions_info_t *tzc_regions)
Vikram Kanigiri510d87b2016-01-29 12:32:58 +000020{
Summer Qin5ce394c2018-03-12 11:28:26 +080021#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
Vikram Kanigiri510d87b2016-01-29 12:32:58 +000030 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
Summer Qin5ce394c2018-03-12 11:28:26 +080037 if (tzc_regions == NULL)
38 p = init_tzc_regions;
39 else
40 p = tzc_regions;
41
Vikram Kanigiri510d87b2016-01-29 12:32:58 +000042 /* Region 0 set to no access by default */
43 tzc_dmc500_configure_region0(TZC_REGION_S_NONE, 0);
44
Summer Qin5ce394c2018-03-12 11:28:26 +080045 /* 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 }
Vikram Kanigiri510d87b2016-01-29 12:32:58 +000051
Summer Qin5ce394c2018-03-12 11:28:26 +080052 INFO("Total %d regions set.\n", region_index);
Vikram Kanigiri510d87b2016-01-29 12:32:58 +000053
Vikram Kanigiri510d87b2016-01-29 12:32:58 +000054#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}