blob: bb66b4b5a87a9d51f48b3028cec24ab153fc440b [file] [log] [blame]
Yann Gautiercaf575b2018-07-24 17:18:19 +02001/*
Yann Gautierf9d40d52019-01-17 14:41:46 +01002 * Copyright (c) 2015-2019, ARM Limited and Contributors. All rights reserved.
Yann Gautiercaf575b2018-07-24 17:18:19 +02003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
Yann Gautiercaf575b2018-07-24 17:18:19 +02007#include <stdint.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +00008
9#include <platform_def.h>
10
11#include <common/debug.h>
12#include <drivers/arm/tzc400.h>
13#include <drivers/st/stm32mp1_clk.h>
14#include <drivers/st/stm32mp1_rcc.h>
15#include <dt-bindings/clock/stm32mp1-clks.h>
16#include <lib/mmio.h>
17
Yann Gautiercaf575b2018-07-24 17:18:19 +020018/*******************************************************************************
Yann Gautier9d135e42018-07-16 19:36:06 +020019 * Initialize the TrustZone Controller. Configure Region 0 with Secure RW access
20 * and allow Non-Secure masters full access.
21 ******************************************************************************/
22static void init_tzc400(void)
23{
24 unsigned long long region_base, region_top;
Yann Gautiera2e2a302019-02-14 11:13:39 +010025 unsigned long long ddr_base = STM32MP_DDR_BASE;
Yann Gautier9d135e42018-07-16 19:36:06 +020026 unsigned long long ddr_size = (unsigned long long)dt_get_ddr_size();
27
28 tzc400_init(STM32MP1_TZC_BASE);
29
30 tzc400_disable_filters();
31
32 /* Region 1 set to cover all DRAM at 0xC000_0000. Apply the
33 * same configuration to all filters in the TZC.
34 */
35 region_base = ddr_base;
36 region_top = ddr_base + (ddr_size - 1U);
37 tzc400_configure_region(STM32MP1_FILTER_BIT_ALL, 1,
38 region_base,
39 region_top,
40 TZC_REGION_S_RDWR,
41 TZC_REGION_ACCESS_RDWR(STM32MP1_TZC_A7_ID) |
42 TZC_REGION_ACCESS_RDWR(STM32MP1_TZC_GPU_ID) |
43 TZC_REGION_ACCESS_RDWR(STM32MP1_TZC_LCD_ID) |
44 TZC_REGION_ACCESS_RDWR(STM32MP1_TZC_MDMA_ID) |
45 TZC_REGION_ACCESS_RDWR(STM32MP1_TZC_DMA_ID) |
46 TZC_REGION_ACCESS_RDWR(STM32MP1_TZC_USB_HOST_ID) |
47 TZC_REGION_ACCESS_RDWR(STM32MP1_TZC_USB_OTG_ID) |
48 TZC_REGION_ACCESS_RDWR(STM32MP1_TZC_SDMMC_ID) |
49 TZC_REGION_ACCESS_RDWR(STM32MP1_TZC_ETH_ID) |
50 TZC_REGION_ACCESS_RDWR(STM32MP1_TZC_DAP_ID));
51
52 /* Raise an exception if a NS device tries to access secure memory */
53 tzc400_set_action(TZC_ACTION_ERR);
54
55 tzc400_enable_filters();
56}
57
58/*******************************************************************************
Yann Gautiercaf575b2018-07-24 17:18:19 +020059 * Initialize the TrustZone Controller.
60 * Early initialization create only one region with full access to secure.
61 * This setting is used before and during DDR initialization.
62 ******************************************************************************/
63static void early_init_tzc400(void)
64{
Yann Gautiera2e2a302019-02-14 11:13:39 +010065 if (stm32mp_clk_enable(TZC1) != 0) {
Yann Gautiercaf575b2018-07-24 17:18:19 +020066 ERROR("Cannot enable TZC1 clock\n");
67 panic();
68 }
Yann Gautiera2e2a302019-02-14 11:13:39 +010069 if (stm32mp_clk_enable(TZC2) != 0) {
Yann Gautiercaf575b2018-07-24 17:18:19 +020070 ERROR("Cannot enable TZC2 clock\n");
71 panic();
72 }
73
74 tzc400_init(STM32MP1_TZC_BASE);
75
76 tzc400_disable_filters();
77
78 /*
79 * Region 1 set to cover Non-Secure DRAM at 0x8000_0000. Apply the
80 * same configuration to all filters in the TZC.
81 */
82 tzc400_configure_region(STM32MP1_FILTER_BIT_ALL, 1,
Yann Gautiera2e2a302019-02-14 11:13:39 +010083 STM32MP_DDR_BASE,
84 STM32MP_DDR_BASE +
85 (STM32MP_DDR_MAX_SIZE - 1U),
Yann Gautiercaf575b2018-07-24 17:18:19 +020086 TZC_REGION_S_RDWR,
Yann Gautierf9d40d52019-01-17 14:41:46 +010087 TZC_REGION_ACCESS_RDWR(STM32MP1_TZC_A7_ID) |
Yann Gautiercaf575b2018-07-24 17:18:19 +020088 TZC_REGION_ACCESS_RDWR(STM32MP1_TZC_SDMMC_ID));
89
90 /* Raise an exception if a NS device tries to access secure memory */
91 tzc400_set_action(TZC_ACTION_ERR);
92
93 tzc400_enable_filters();
94}
95
96/*******************************************************************************
97 * Initialize the secure environment. At this moment only the TrustZone
98 * Controller is initialized.
99 ******************************************************************************/
100void stm32mp1_arch_security_setup(void)
101{
102 early_init_tzc400();
103}
Yann Gautier9d135e42018-07-16 19:36:06 +0200104
105/*******************************************************************************
106 * Initialize the secure environment. At this moment only the TrustZone
107 * Controller is initialized.
108 ******************************************************************************/
109void stm32mp1_security_setup(void)
110{
111 init_tzc400();
112}