blob: e783c14e45d29d71b17928ada6607df10bc70c89 [file] [log] [blame]
Yann Gautiercaf575b2018-07-24 17:18:19 +02001/*
2 * Copyright (c) 2015-2018, ARM Limited and Contributors. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include <debug.h>
8#include <dt-bindings/clock/stm32mp1-clks.h>
9#include <mmio.h>
10#include <stdint.h>
11#include <stm32mp1_clk.h>
12#include <stm32mp1_dt.h>
13#include <stm32mp1_private.h>
14#include <stm32mp1_rcc.h>
15#include <tzc400.h>
16#include "platform_def.h"
17
18/*******************************************************************************
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;
25 unsigned long long ddr_base = STM32MP1_DDR_BASE;
26 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{
65 uint32_t rstsr, rst_standby;
66
67 rstsr = mmio_read_32(RCC_BASE + RCC_MP_RSTSCLRR);
68
69 /* No warning if return from (C)STANDBY */
70 rst_standby = rstsr &
71 (RCC_MP_RSTSCLRR_STDBYRSTF | RCC_MP_RSTSCLRR_CSTDBYRSTF);
72
73 if (stm32mp1_clk_is_enabled(TZC1) && (rst_standby == 0U)) {
74 WARN("TZC400 port 1 clock already enable\n");
75 }
76
77 if (stm32mp1_clk_is_enabled(TZC2) && (rst_standby == 0U)) {
78 WARN("TZC400 port 2 clock already enable\n");
79 }
80
81 if (stm32mp1_clk_enable(TZC1) != 0) {
82 ERROR("Cannot enable TZC1 clock\n");
83 panic();
84 }
85 if (stm32mp1_clk_enable(TZC2) != 0) {
86 ERROR("Cannot enable TZC2 clock\n");
87 panic();
88 }
89
90 tzc400_init(STM32MP1_TZC_BASE);
91
92 tzc400_disable_filters();
93
94 /*
95 * Region 1 set to cover Non-Secure DRAM at 0x8000_0000. Apply the
96 * same configuration to all filters in the TZC.
97 */
98 tzc400_configure_region(STM32MP1_FILTER_BIT_ALL, 1,
99 STM32MP1_DDR_BASE,
100 STM32MP1_DDR_BASE +
101 (STM32MP1_DDR_MAX_SIZE - 1U),
102 TZC_REGION_S_RDWR,
103 TZC_REGION_ACCESS_RDWR(STM32MP1_TZC_SDMMC_ID));
104
105 /* Raise an exception if a NS device tries to access secure memory */
106 tzc400_set_action(TZC_ACTION_ERR);
107
108 tzc400_enable_filters();
109}
110
111/*******************************************************************************
112 * Initialize the secure environment. At this moment only the TrustZone
113 * Controller is initialized.
114 ******************************************************************************/
115void stm32mp1_arch_security_setup(void)
116{
117 early_init_tzc400();
118}
Yann Gautier9d135e42018-07-16 19:36:06 +0200119
120/*******************************************************************************
121 * Initialize the secure environment. At this moment only the TrustZone
122 * Controller is initialized.
123 ******************************************************************************/
124void stm32mp1_security_setup(void)
125{
126 init_tzc400();
127}