blob: 6566b15c87bdedf59b4516fb4969504ae0811e76 [file] [log] [blame]
Juan Castillo6b672f52014-09-04 14:43:09 +01001/*
Ambroise Vincentd207f562019-04-10 12:50:27 +01002 * Copyright (c) 2014-2019, ARM Limited and Contributors. All rights reserved.
Juan Castillo6b672f52014-09-04 14:43:09 +01003 *
dp-armfa3cf0b2017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
Juan Castillo6b672f52014-09-04 14:43:09 +01005 */
6
Antonio Nino Diaze0f90632018-12-14 00:18:21 +00007#include <common/debug.h>
8#include <drivers/arm/nic_400.h>
9#include <lib/mmio.h>
Antonio Nino Diaza320ecd2019-01-15 14:19:50 +000010#include <platform_def.h>
Antonio Nino Diazbd7b7402019-01-25 14:30:04 +000011#include <plat/arm/common/plat_arm.h>
12#include <plat/arm/soc/common/soc_css.h>
Ambroise Vincentd207f562019-04-10 12:50:27 +010013#include <plat/common/platform.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000014
Summer Qin13b95c22018-03-02 15:51:14 +080015#include "juno_tzmp1_def.h"
16
17#ifdef JUNO_TZMP1
18/*
19 * Protect buffer for VPU/GPU/DPU memory usage with hardware protection
20 * enabled. Propose 224MB video output, 96 MB video input and 32MB video
21 * private.
22 *
23 * Ind Memory Range Caption S_ATTR NS_ATTR
24 * 1 0x080000000 - 0x0E7FFFFFF ARM_NS_DRAM1 NONE RDWR | MEDIA_RW
25 * 2 0x0E8000000 - 0x0F5FFFFFF JUNO_MEDIA_TZC_PROT_DRAM1 NONE MEDIA_RW | AP_WR
26 * 3 0x0F6000000 - 0x0FBFFFFFF JUNO_VPU_TZC_PROT_DRAM1 RDWR VPU_PROT_RW
27 * 4 0x0FC000000 - 0x0FDFFFFFF JUNO_VPU_TZC_PRIV_DRAM1 RDWR VPU_PRIV_RW
28 * 5 0x0FE000000 - 0x0FEFFFFFF JUNO_AP_TZC_SHARE_DRAM1 NONE RDWR | MEDIA_RW
29 * 6 0x0FF000000 - 0x0FFFFFFFF ARM_AP_TZC_DRAM1 RDWR NONE
30 * 7 0x880000000 - 0x9FFFFFFFF ARM_DRAM2 NONE RDWR | MEDIA_RW
31 *
32 * Memory regions are neighbored to save limited TZC regions. Calculation
33 * started from ARM_TZC_SHARE_DRAM1 since it is known and fixed for both
34 * protected-enabled and protected-disabled settings.
35 *
36 * Video private buffer aheads of ARM_TZC_SHARE_DRAM1
37 */
Juan Castillo6b672f52014-09-04 14:43:09 +010038
Summer Qin13b95c22018-03-02 15:51:14 +080039static const arm_tzc_regions_info_t juno_tzmp1_tzc_regions[] = {
40 {ARM_AP_TZC_DRAM1_BASE, ARM_AP_TZC_DRAM1_END, TZC_REGION_S_RDWR, 0},
41 {JUNO_NS_DRAM1_PT1_BASE, JUNO_NS_DRAM1_PT1_END,
42 TZC_REGION_S_NONE, JUNO_MEDIA_TZC_NS_DEV_ACCESS},
43 {JUNO_MEDIA_TZC_PROT_DRAM1_BASE, JUNO_MEDIA_TZC_PROT_DRAM1_END,
44 TZC_REGION_S_NONE, JUNO_MEDIA_TZC_PROT_ACCESS},
45 {JUNO_VPU_TZC_PROT_DRAM1_BASE, JUNO_VPU_TZC_PROT_DRAM1_END,
46 TZC_REGION_S_RDWR, JUNO_VPU_TZC_PROT_ACCESS},
47 {JUNO_VPU_TZC_PRIV_DRAM1_BASE, JUNO_VPU_TZC_PRIV_DRAM1_END,
48 TZC_REGION_S_RDWR, JUNO_VPU_TZC_PRIV_ACCESS},
49 {JUNO_AP_TZC_SHARE_DRAM1_BASE, JUNO_AP_TZC_SHARE_DRAM1_END,
50 TZC_REGION_S_NONE, JUNO_MEDIA_TZC_NS_DEV_ACCESS},
51 {ARM_DRAM2_BASE, ARM_DRAM2_END,
52 TZC_REGION_S_NONE, JUNO_MEDIA_TZC_NS_DEV_ACCESS},
53 {},
54};
55
56/*******************************************************************************
57 * Program dp650 to configure NSAID value for protected mode.
58 ******************************************************************************/
59static void init_dp650(void)
60{
61 mmio_write_32(DP650_BASE + DP650_PROT_NSAID_OFFSET,
62 DP650_PROT_NSAID_CONFIG);
63}
Juan Castillo6b672f52014-09-04 14:43:09 +010064
65/*******************************************************************************
Summer Qin13b95c22018-03-02 15:51:14 +080066 * Program v550 to configure NSAID value for protected mode.
67 ******************************************************************************/
68static void init_v550(void)
69{
70 /*
71 * bits[31:28] is for PRIVATE,
72 * bits[27:24] is for OUTBUF,
73 * bits[23:20] is for PROTECTED.
74 */
75 mmio_write_32(V550_BASE + V550_PROTCTRL_OFFSET, V550_PROTCTRL_CONFIG);
76}
77
78#endif /* JUNO_TZMP1 */
79
80/*******************************************************************************
Robin Murphy0f1d6662015-01-09 14:30:58 +000081 * Set up the MMU-401 SSD tables. The power-on configuration has all stream IDs
82 * assigned to Non-Secure except some for the DMA-330. Assign those back to the
83 * Non-Secure world as well, otherwise EL1 may end up erroneously generating
84 * (untranslated) Secure transactions if it turns the SMMU on.
85 ******************************************************************************/
86static void init_mmu401(void)
87{
88 uint32_t reg = mmio_read_32(MMU401_DMA330_BASE + MMU401_SSD_OFFSET);
89 reg |= 0x1FF;
90 mmio_write_32(MMU401_DMA330_BASE + MMU401_SSD_OFFSET, reg);
91}
92
93/*******************************************************************************
Vikram Kanigiriaf2bc5f2015-08-03 23:58:19 +010094 * Program CSS-NIC400 to allow non-secure access to some CSS regions.
95 ******************************************************************************/
96static void css_init_nic400(void)
97{
98 /* Note: This is the NIC-400 device on the CSS */
99 mmio_write_32(PLAT_SOC_CSS_NIC400_BASE +
100 NIC400_ADDR_CTRL_SECURITY_REG(CSS_NIC400_SLAVE_BOOTSECURE),
101 ~0);
102}
103
104/*******************************************************************************
dp-armb71946b2017-02-08 12:16:42 +0000105 * Initialize debug configuration.
106 ******************************************************************************/
107static void init_debug_cfg(void)
108{
109#if !DEBUG
110 /* Set internal drive selection for SPIDEN. */
111 mmio_write_32(SSC_REG_BASE + SSC_DBGCFG_SET,
112 1U << SPIDEN_SEL_SET_SHIFT);
113
114 /* Drive SPIDEN LOW to disable invasive debug of secure state. */
115 mmio_write_32(SSC_REG_BASE + SSC_DBGCFG_CLR,
116 1U << SPIDEN_INT_CLR_SHIFT);
117#endif
118}
119
120/*******************************************************************************
Dan Handley7bef8002015-03-19 19:22:44 +0000121 * Initialize the secure environment.
Juan Castillo6b672f52014-09-04 14:43:09 +0100122 ******************************************************************************/
Dan Handley7bef8002015-03-19 19:22:44 +0000123void plat_arm_security_setup(void)
Juan Castillo6b672f52014-09-04 14:43:09 +0100124{
dp-armb71946b2017-02-08 12:16:42 +0000125 /* Initialize debug configuration */
126 init_debug_cfg();
Juan Castillo6b672f52014-09-04 14:43:09 +0100127 /* Initialize the TrustZone Controller */
Summer Qin13b95c22018-03-02 15:51:14 +0800128#ifdef JUNO_TZMP1
129 arm_tzc400_setup(juno_tzmp1_tzc_regions);
130 INFO("TZC protected shared memory base address for TZMP usecase: %p\n",
131 (void *)JUNO_AP_TZC_SHARE_DRAM1_BASE);
132 INFO("TZC protected shared memory end address for TZMP usecase: %p\n",
133 (void *)JUNO_AP_TZC_SHARE_DRAM1_END);
134#else
Summer Qin5ce394c2018-03-12 11:28:26 +0800135 arm_tzc400_setup(NULL);
Summer Qin13b95c22018-03-02 15:51:14 +0800136#endif
Vikram Kanigiriaf2bc5f2015-08-03 23:58:19 +0100137 /* Do ARM CSS internal NIC setup */
138 css_init_nic400();
Dan Handley7bef8002015-03-19 19:22:44 +0000139 /* Do ARM CSS SoC security setup */
140 soc_css_security_setup();
dp-armb71946b2017-02-08 12:16:42 +0000141 /* Initialize the SMMU SSD tables */
Robin Murphy0f1d6662015-01-09 14:30:58 +0000142 init_mmu401();
Summer Qin13b95c22018-03-02 15:51:14 +0800143#ifdef JUNO_TZMP1
144 init_dp650();
145 init_v550();
146#endif
Juan Castillo6b672f52014-09-04 14:43:09 +0100147}
Ambroise Vincentd207f562019-04-10 12:50:27 +0100148
149#if TRUSTED_BOARD_BOOT
150int plat_get_mbedtls_heap(void **heap_addr, size_t *heap_size)
151{
152 return get_mbedtls_heap_helper(heap_addr, heap_size);
153}
154#endif