blob: cfdbf31852bd7c72e01dc6d48bdbc52d77ac2980 [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#include <stm32mp1_dt.h>
19#include <stm32mp1_private.h>
Yann Gautiercaf575b2018-07-24 17:18:19 +020020
21/*******************************************************************************
Yann Gautier9d135e42018-07-16 19:36:06 +020022 * Initialize the TrustZone Controller. Configure Region 0 with Secure RW access
23 * and allow Non-Secure masters full access.
24 ******************************************************************************/
25static void init_tzc400(void)
26{
27 unsigned long long region_base, region_top;
28 unsigned long long ddr_base = STM32MP1_DDR_BASE;
29 unsigned long long ddr_size = (unsigned long long)dt_get_ddr_size();
30
31 tzc400_init(STM32MP1_TZC_BASE);
32
33 tzc400_disable_filters();
34
35 /* Region 1 set to cover all DRAM at 0xC000_0000. Apply the
36 * same configuration to all filters in the TZC.
37 */
38 region_base = ddr_base;
39 region_top = ddr_base + (ddr_size - 1U);
40 tzc400_configure_region(STM32MP1_FILTER_BIT_ALL, 1,
41 region_base,
42 region_top,
43 TZC_REGION_S_RDWR,
44 TZC_REGION_ACCESS_RDWR(STM32MP1_TZC_A7_ID) |
45 TZC_REGION_ACCESS_RDWR(STM32MP1_TZC_GPU_ID) |
46 TZC_REGION_ACCESS_RDWR(STM32MP1_TZC_LCD_ID) |
47 TZC_REGION_ACCESS_RDWR(STM32MP1_TZC_MDMA_ID) |
48 TZC_REGION_ACCESS_RDWR(STM32MP1_TZC_DMA_ID) |
49 TZC_REGION_ACCESS_RDWR(STM32MP1_TZC_USB_HOST_ID) |
50 TZC_REGION_ACCESS_RDWR(STM32MP1_TZC_USB_OTG_ID) |
51 TZC_REGION_ACCESS_RDWR(STM32MP1_TZC_SDMMC_ID) |
52 TZC_REGION_ACCESS_RDWR(STM32MP1_TZC_ETH_ID) |
53 TZC_REGION_ACCESS_RDWR(STM32MP1_TZC_DAP_ID));
54
55 /* Raise an exception if a NS device tries to access secure memory */
56 tzc400_set_action(TZC_ACTION_ERR);
57
58 tzc400_enable_filters();
59}
60
61/*******************************************************************************
Yann Gautiercaf575b2018-07-24 17:18:19 +020062 * Initialize the TrustZone Controller.
63 * Early initialization create only one region with full access to secure.
64 * This setting is used before and during DDR initialization.
65 ******************************************************************************/
66static void early_init_tzc400(void)
67{
Yann Gautiercaf575b2018-07-24 17:18:19 +020068 if (stm32mp1_clk_enable(TZC1) != 0) {
69 ERROR("Cannot enable TZC1 clock\n");
70 panic();
71 }
72 if (stm32mp1_clk_enable(TZC2) != 0) {
73 ERROR("Cannot enable TZC2 clock\n");
74 panic();
75 }
76
77 tzc400_init(STM32MP1_TZC_BASE);
78
79 tzc400_disable_filters();
80
81 /*
82 * Region 1 set to cover Non-Secure DRAM at 0x8000_0000. Apply the
83 * same configuration to all filters in the TZC.
84 */
85 tzc400_configure_region(STM32MP1_FILTER_BIT_ALL, 1,
86 STM32MP1_DDR_BASE,
87 STM32MP1_DDR_BASE +
88 (STM32MP1_DDR_MAX_SIZE - 1U),
89 TZC_REGION_S_RDWR,
Yann Gautierf9d40d52019-01-17 14:41:46 +010090 TZC_REGION_ACCESS_RDWR(STM32MP1_TZC_A7_ID) |
Yann Gautiercaf575b2018-07-24 17:18:19 +020091 TZC_REGION_ACCESS_RDWR(STM32MP1_TZC_SDMMC_ID));
92
93 /* Raise an exception if a NS device tries to access secure memory */
94 tzc400_set_action(TZC_ACTION_ERR);
95
96 tzc400_enable_filters();
97}
98
99/*******************************************************************************
100 * Initialize the secure environment. At this moment only the TrustZone
101 * Controller is initialized.
102 ******************************************************************************/
103void stm32mp1_arch_security_setup(void)
104{
105 early_init_tzc400();
106}
Yann Gautier9d135e42018-07-16 19:36:06 +0200107
108/*******************************************************************************
109 * Initialize the secure environment. At this moment only the TrustZone
110 * Controller is initialized.
111 ******************************************************************************/
112void stm32mp1_security_setup(void)
113{
114 init_tzc400();
115}