blob: 0ad43e43536bd87239c1a024c434a43639062c0a [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>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000014#include <dt-bindings/clock/stm32mp1-clks.h>
15#include <lib/mmio.h>
16
Yann Gautiercaf575b2018-07-24 17:18:19 +020017/*******************************************************************************
Yann Gautier9d135e42018-07-16 19:36:06 +020018 * Initialize the TrustZone Controller. Configure Region 0 with Secure RW access
19 * and allow Non-Secure masters full access.
20 ******************************************************************************/
21static void init_tzc400(void)
22{
23 unsigned long long region_base, region_top;
Yann Gautiera2e2a302019-02-14 11:13:39 +010024 unsigned long long ddr_base = STM32MP_DDR_BASE;
Yann Gautier9d135e42018-07-16 19:36:06 +020025 unsigned long long ddr_size = (unsigned long long)dt_get_ddr_size();
26
27 tzc400_init(STM32MP1_TZC_BASE);
28
29 tzc400_disable_filters();
30
31 /* Region 1 set to cover all DRAM at 0xC000_0000. Apply the
32 * same configuration to all filters in the TZC.
33 */
34 region_base = ddr_base;
35 region_top = ddr_base + (ddr_size - 1U);
36 tzc400_configure_region(STM32MP1_FILTER_BIT_ALL, 1,
37 region_base,
38 region_top,
39 TZC_REGION_S_RDWR,
40 TZC_REGION_ACCESS_RDWR(STM32MP1_TZC_A7_ID) |
41 TZC_REGION_ACCESS_RDWR(STM32MP1_TZC_GPU_ID) |
42 TZC_REGION_ACCESS_RDWR(STM32MP1_TZC_LCD_ID) |
43 TZC_REGION_ACCESS_RDWR(STM32MP1_TZC_MDMA_ID) |
Yann Gautiered342322019-02-15 17:33:27 +010044 TZC_REGION_ACCESS_RDWR(STM32MP1_TZC_M4_ID) |
Yann Gautier9d135e42018-07-16 19:36:06 +020045 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 Gautiere4a3c352019-02-14 10:53:33 +010065 stm32mp_clk_enable(TZC1);
66 stm32mp_clk_enable(TZC2);
Yann Gautiercaf575b2018-07-24 17:18:19 +020067
68 tzc400_init(STM32MP1_TZC_BASE);
69
70 tzc400_disable_filters();
71
72 /*
73 * Region 1 set to cover Non-Secure DRAM at 0x8000_0000. Apply the
74 * same configuration to all filters in the TZC.
75 */
76 tzc400_configure_region(STM32MP1_FILTER_BIT_ALL, 1,
Yann Gautiera2e2a302019-02-14 11:13:39 +010077 STM32MP_DDR_BASE,
78 STM32MP_DDR_BASE +
79 (STM32MP_DDR_MAX_SIZE - 1U),
Yann Gautiercaf575b2018-07-24 17:18:19 +020080 TZC_REGION_S_RDWR,
Yann Gautierf9d40d52019-01-17 14:41:46 +010081 TZC_REGION_ACCESS_RDWR(STM32MP1_TZC_A7_ID) |
Yann Gautiercaf575b2018-07-24 17:18:19 +020082 TZC_REGION_ACCESS_RDWR(STM32MP1_TZC_SDMMC_ID));
83
84 /* Raise an exception if a NS device tries to access secure memory */
85 tzc400_set_action(TZC_ACTION_ERR);
86
87 tzc400_enable_filters();
88}
89
90/*******************************************************************************
91 * Initialize the secure environment. At this moment only the TrustZone
92 * Controller is initialized.
93 ******************************************************************************/
94void stm32mp1_arch_security_setup(void)
95{
96 early_init_tzc400();
97}
Yann Gautier9d135e42018-07-16 19:36:06 +020098
99/*******************************************************************************
100 * Initialize the secure environment. At this moment only the TrustZone
101 * Controller is initialized.
102 ******************************************************************************/
103void stm32mp1_security_setup(void)
104{
105 init_tzc400();
106}