Vikram Kanigiri | 510d87b | 2016-01-29 12:32:58 +0000 | [diff] [blame] | 1 | /* |
Summer Qin | 5ce394c | 2018-03-12 11:28:26 +0800 | [diff] [blame] | 2 | * Copyright (c) 2016-2018, ARM Limited and Contributors. All rights reserved. |
Vikram Kanigiri | 510d87b | 2016-01-29 12:32:58 +0000 | [diff] [blame] | 3 | * |
dp-arm | fa3cf0b | 2017-05-03 09:38:09 +0100 | [diff] [blame] | 4 | * SPDX-License-Identifier: BSD-3-Clause |
Vikram Kanigiri | 510d87b | 2016-01-29 12:32:58 +0000 | [diff] [blame] | 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. |
Vikram Kanigiri | 510d87b | 2016-01-29 12:32:58 +0000 | [diff] [blame] | 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 | ******************************************************************************/ |
Summer Qin | 5ce394c | 2018-03-12 11:28:26 +0800 | [diff] [blame] | 18 | void arm_tzc_dmc500_setup(tzc_dmc500_driver_data_t *plat_driver_data, |
| 19 | const arm_tzc_regions_info_t *tzc_regions) |
Vikram Kanigiri | 510d87b | 2016-01-29 12:32:58 +0000 | [diff] [blame] | 20 | { |
Summer Qin | 5ce394c | 2018-03-12 11:28:26 +0800 | [diff] [blame] | 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 | |
Vikram Kanigiri | 510d87b | 2016-01-29 12:32:58 +0000 | [diff] [blame] | 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 |
Summer Qin | 5ce394c | 2018-03-12 11:28:26 +0800 | [diff] [blame] | 37 | if (tzc_regions == NULL) |
| 38 | p = init_tzc_regions; |
| 39 | else |
| 40 | p = tzc_regions; |
| 41 | |
Vikram Kanigiri | 510d87b | 2016-01-29 12:32:58 +0000 | [diff] [blame] | 42 | /* Region 0 set to no access by default */ |
| 43 | tzc_dmc500_configure_region0(TZC_REGION_S_NONE, 0); |
| 44 | |
Summer Qin | 5ce394c | 2018-03-12 11:28:26 +0800 | [diff] [blame] | 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 | } |
Vikram Kanigiri | 510d87b | 2016-01-29 12:32:58 +0000 | [diff] [blame] | 51 | |
Summer Qin | 5ce394c | 2018-03-12 11:28:26 +0800 | [diff] [blame] | 52 | INFO("Total %d regions set.\n", region_index); |
Vikram Kanigiri | 510d87b | 2016-01-29 12:32:58 +0000 | [diff] [blame] | 53 | |
Vikram Kanigiri | 510d87b | 2016-01-29 12:32:58 +0000 | [diff] [blame] | 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 | } |