Yann Gautier | caf575b | 2018-07-24 17:18:19 +0200 | [diff] [blame] | 1 | /* |
Yann Gautier | cd40f32 | 2020-02-26 13:36:07 +0100 | [diff] [blame] | 2 | * Copyright (c) 2015-2020, ARM Limited and Contributors. All rights reserved. |
Yann Gautier | caf575b | 2018-07-24 17:18:19 +0200 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
Yann Gautier | caf575b | 2018-07-24 17:18:19 +0200 | [diff] [blame] | 7 | #include <stdint.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 8 | |
| 9 | #include <platform_def.h> |
| 10 | |
| 11 | #include <common/debug.h> |
| 12 | #include <drivers/arm/tzc400.h> |
| 13 | #include <drivers/st/stm32mp1_clk.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 14 | #include <dt-bindings/clock/stm32mp1-clks.h> |
| 15 | #include <lib/mmio.h> |
| 16 | |
Yann Gautier | e3de4c0 | 2019-04-18 15:32:10 +0200 | [diff] [blame] | 17 | #define TZC_REGION_NSEC_ALL_ACCESS_RDWR \ |
| 18 | TZC_REGION_ACCESS_RDWR(STM32MP1_TZC_A7_ID) | \ |
| 19 | TZC_REGION_ACCESS_RDWR(STM32MP1_TZC_GPU_ID) | \ |
| 20 | TZC_REGION_ACCESS_RDWR(STM32MP1_TZC_LCD_ID) | \ |
| 21 | TZC_REGION_ACCESS_RDWR(STM32MP1_TZC_MDMA_ID) | \ |
| 22 | TZC_REGION_ACCESS_RDWR(STM32MP1_TZC_M4_ID) | \ |
| 23 | TZC_REGION_ACCESS_RDWR(STM32MP1_TZC_DMA_ID) | \ |
| 24 | TZC_REGION_ACCESS_RDWR(STM32MP1_TZC_USB_HOST_ID) | \ |
| 25 | TZC_REGION_ACCESS_RDWR(STM32MP1_TZC_USB_OTG_ID) | \ |
| 26 | TZC_REGION_ACCESS_RDWR(STM32MP1_TZC_SDMMC_ID) | \ |
| 27 | TZC_REGION_ACCESS_RDWR(STM32MP1_TZC_ETH_ID) | \ |
| 28 | TZC_REGION_ACCESS_RDWR(STM32MP1_TZC_DAP_ID) |
| 29 | |
Yann Gautier | caf575b | 2018-07-24 17:18:19 +0200 | [diff] [blame] | 30 | /******************************************************************************* |
Yann Gautier | 9d135e4 | 2018-07-16 19:36:06 +0200 | [diff] [blame] | 31 | * Initialize the TrustZone Controller. Configure Region 0 with Secure RW access |
| 32 | * and allow Non-Secure masters full access. |
| 33 | ******************************************************************************/ |
| 34 | static void init_tzc400(void) |
| 35 | { |
| 36 | unsigned long long region_base, region_top; |
Yann Gautier | a2e2a30 | 2019-02-14 11:13:39 +0100 | [diff] [blame] | 37 | unsigned long long ddr_base = STM32MP_DDR_BASE; |
Yann Gautier | cd40f32 | 2020-02-26 13:36:07 +0100 | [diff] [blame] | 38 | unsigned long long ddr_ns_size = |
| 39 | (unsigned long long)stm32mp_get_ddr_ns_size(); |
| 40 | unsigned long long ddr_ns_top = ddr_base + (ddr_ns_size - 1U); |
Yann Gautier | 9d135e4 | 2018-07-16 19:36:06 +0200 | [diff] [blame] | 41 | |
| 42 | tzc400_init(STM32MP1_TZC_BASE); |
| 43 | |
| 44 | tzc400_disable_filters(); |
| 45 | |
Yann Gautier | b3386f7 | 2019-04-19 09:41:01 +0200 | [diff] [blame] | 46 | /* |
| 47 | * Region 1 set to cover all non-secure DRAM at 0xC000_0000. Apply the |
| 48 | * same configuration to all filters in the TZC. |
| 49 | */ |
| 50 | region_base = ddr_base; |
Yann Gautier | cd40f32 | 2020-02-26 13:36:07 +0100 | [diff] [blame] | 51 | region_top = ddr_ns_top; |
Yann Gautier | b3386f7 | 2019-04-19 09:41:01 +0200 | [diff] [blame] | 52 | tzc400_configure_region(STM32MP1_FILTER_BIT_ALL, 1, |
| 53 | region_base, |
| 54 | region_top, |
| 55 | TZC_REGION_S_NONE, |
| 56 | TZC_REGION_NSEC_ALL_ACCESS_RDWR); |
| 57 | |
Yann Gautier | cd40f32 | 2020-02-26 13:36:07 +0100 | [diff] [blame] | 58 | #ifdef AARCH32_SP_OPTEE |
Yann Gautier | b3386f7 | 2019-04-19 09:41:01 +0200 | [diff] [blame] | 59 | /* Region 2 set to cover all secure DRAM. */ |
| 60 | region_base = region_top + 1U; |
Yann Gautier | cd40f32 | 2020-02-26 13:36:07 +0100 | [diff] [blame] | 61 | region_top += STM32MP_DDR_S_SIZE; |
Yann Gautier | b3386f7 | 2019-04-19 09:41:01 +0200 | [diff] [blame] | 62 | tzc400_configure_region(STM32MP1_FILTER_BIT_ALL, 2, |
| 63 | region_base, |
| 64 | region_top, |
| 65 | TZC_REGION_S_RDWR, |
| 66 | 0); |
| 67 | |
| 68 | /* Region 3 set to cover non-secure shared memory DRAM. */ |
| 69 | region_base = region_top + 1U; |
Yann Gautier | cd40f32 | 2020-02-26 13:36:07 +0100 | [diff] [blame] | 70 | region_top += STM32MP_DDR_SHMEM_SIZE; |
Yann Gautier | b3386f7 | 2019-04-19 09:41:01 +0200 | [diff] [blame] | 71 | tzc400_configure_region(STM32MP1_FILTER_BIT_ALL, 3, |
| 72 | region_base, |
| 73 | region_top, |
| 74 | TZC_REGION_S_NONE, |
| 75 | TZC_REGION_NSEC_ALL_ACCESS_RDWR); |
Yann Gautier | b3386f7 | 2019-04-19 09:41:01 +0200 | [diff] [blame] | 76 | #endif |
Yann Gautier | 9d135e4 | 2018-07-16 19:36:06 +0200 | [diff] [blame] | 77 | |
| 78 | /* Raise an exception if a NS device tries to access secure memory */ |
| 79 | tzc400_set_action(TZC_ACTION_ERR); |
| 80 | |
| 81 | tzc400_enable_filters(); |
| 82 | } |
| 83 | |
| 84 | /******************************************************************************* |
Yann Gautier | caf575b | 2018-07-24 17:18:19 +0200 | [diff] [blame] | 85 | * Initialize the TrustZone Controller. |
| 86 | * Early initialization create only one region with full access to secure. |
| 87 | * This setting is used before and during DDR initialization. |
| 88 | ******************************************************************************/ |
| 89 | static void early_init_tzc400(void) |
| 90 | { |
Yann Gautier | e4a3c35 | 2019-02-14 10:53:33 +0100 | [diff] [blame] | 91 | stm32mp_clk_enable(TZC1); |
| 92 | stm32mp_clk_enable(TZC2); |
Yann Gautier | caf575b | 2018-07-24 17:18:19 +0200 | [diff] [blame] | 93 | |
| 94 | tzc400_init(STM32MP1_TZC_BASE); |
| 95 | |
| 96 | tzc400_disable_filters(); |
| 97 | |
Yann Gautier | e3de4c0 | 2019-04-18 15:32:10 +0200 | [diff] [blame] | 98 | /* Region 1 set to cover Non-Secure DRAM at 0xC000_0000 */ |
Yann Gautier | caf575b | 2018-07-24 17:18:19 +0200 | [diff] [blame] | 99 | tzc400_configure_region(STM32MP1_FILTER_BIT_ALL, 1, |
Yann Gautier | a2e2a30 | 2019-02-14 11:13:39 +0100 | [diff] [blame] | 100 | STM32MP_DDR_BASE, |
| 101 | STM32MP_DDR_BASE + |
| 102 | (STM32MP_DDR_MAX_SIZE - 1U), |
Yann Gautier | e3de4c0 | 2019-04-18 15:32:10 +0200 | [diff] [blame] | 103 | TZC_REGION_S_NONE, |
Yann Gautier | f9d40d5 | 2019-01-17 14:41:46 +0100 | [diff] [blame] | 104 | TZC_REGION_ACCESS_RDWR(STM32MP1_TZC_A7_ID) | |
Yann Gautier | caf575b | 2018-07-24 17:18:19 +0200 | [diff] [blame] | 105 | TZC_REGION_ACCESS_RDWR(STM32MP1_TZC_SDMMC_ID)); |
| 106 | |
| 107 | /* Raise an exception if a NS device tries to access secure memory */ |
| 108 | tzc400_set_action(TZC_ACTION_ERR); |
| 109 | |
| 110 | tzc400_enable_filters(); |
| 111 | } |
| 112 | |
| 113 | /******************************************************************************* |
| 114 | * Initialize the secure environment. At this moment only the TrustZone |
| 115 | * Controller is initialized. |
| 116 | ******************************************************************************/ |
| 117 | void stm32mp1_arch_security_setup(void) |
| 118 | { |
| 119 | early_init_tzc400(); |
| 120 | } |
Yann Gautier | 9d135e4 | 2018-07-16 19:36:06 +0200 | [diff] [blame] | 121 | |
| 122 | /******************************************************************************* |
| 123 | * Initialize the secure environment. At this moment only the TrustZone |
| 124 | * Controller is initialized. |
| 125 | ******************************************************************************/ |
| 126 | void stm32mp1_security_setup(void) |
| 127 | { |
| 128 | init_tzc400(); |
| 129 | } |