blob: 254357dcb1c6e91d591d1982cf86a4650bf184d3 [file] [log] [blame]
Juan Castillo6b672f52014-09-04 14:43:09 +01001/*
2 * Copyright (c) 2014, ARM Limited and Contributors. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6 *
7 * Redistributions of source code must retain the above copyright notice, this
8 * list of conditions and the following disclaimer.
9 *
10 * Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 *
14 * Neither the name of ARM nor the names of its contributors may be used
15 * to endorse or promote products derived from this software without specific
16 * prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
29 */
30
31#include <debug.h>
Robin Murphy0f1d6662015-01-09 14:30:58 +000032#include <mmio.h>
Juan Castillo6b672f52014-09-04 14:43:09 +010033#include <tzc400.h>
34#include "juno_def.h"
35
36/*******************************************************************************
37 * Initialize the TrustZone Controller. Configure Region 0 with Secure RW access
38 * and allow Non-Secure masters full access
39 ******************************************************************************/
40static void init_tzc400(void)
41{
42 tzc_init(TZC400_BASE);
43
44 /* Disable filters. */
45 tzc_disable_filters();
46
Juan Castillo921b8772014-09-05 17:29:38 +010047 /* Region 1 set to cover Non-Secure DRAM at 0x8000_0000. Apply the
48 * same configuration to all filters in the TZC. */
49 tzc_configure_region(REG_ATTR_FILTER_BIT_ALL, 1,
50 DRAM_NS_BASE, DRAM_NS_BASE + DRAM_NS_SIZE - 1,
51 TZC_REGION_S_NONE,
52 TZC_REGION_ACCESS_RDWR(TZC400_NSAID_CCI400) |
53 TZC_REGION_ACCESS_RDWR(TZC400_NSAID_PCIE) |
54 TZC_REGION_ACCESS_RDWR(TZC400_NSAID_HDLCD0) |
55 TZC_REGION_ACCESS_RDWR(TZC400_NSAID_HDLCD1) |
56 TZC_REGION_ACCESS_RDWR(TZC400_NSAID_USB) |
57 TZC_REGION_ACCESS_RDWR(TZC400_NSAID_DMA330) |
58 TZC_REGION_ACCESS_RDWR(TZC400_NSAID_THINLINKS) |
59 TZC_REGION_ACCESS_RDWR(TZC400_NSAID_AP) |
60 TZC_REGION_ACCESS_RDWR(TZC400_NSAID_GPU) |
61 TZC_REGION_ACCESS_RDWR(TZC400_NSAID_CORESIGHT));
62
63 /* Region 2 set to cover Secure DRAM */
64 tzc_configure_region(REG_ATTR_FILTER_BIT_ALL, 2,
65 DRAM_SEC_BASE, DRAM_SEC_BASE + DRAM_SEC_SIZE - 1,
Juan Castillo6b672f52014-09-04 14:43:09 +010066 TZC_REGION_S_RDWR,
Juan Castillo921b8772014-09-05 17:29:38 +010067 0);
68
69 /* Region 3 set to cover DRAM used by SCP for DDR retraining */
70 tzc_configure_region(REG_ATTR_FILTER_BIT_ALL, 3,
71 DRAM_SCP_BASE, DRAM_SCP_BASE + DRAM_SCP_SIZE - 1,
72 TZC_REGION_S_NONE,
73 TZC_REGION_ACCESS_RDWR(TZC400_NSAID_SCP));
74
75 /* Region 4 set to cover Non-Secure DRAM at 0x8_8000_0000 */
76 tzc_configure_region(REG_ATTR_FILTER_BIT_ALL, 4,
77 DRAM2_BASE, DRAM2_BASE + DRAM2_SIZE - 1,
78 TZC_REGION_S_NONE,
Juan Castillo6b672f52014-09-04 14:43:09 +010079 TZC_REGION_ACCESS_RDWR(TZC400_NSAID_CCI400) |
80 TZC_REGION_ACCESS_RDWR(TZC400_NSAID_PCIE) |
81 TZC_REGION_ACCESS_RDWR(TZC400_NSAID_HDLCD0) |
82 TZC_REGION_ACCESS_RDWR(TZC400_NSAID_HDLCD1) |
83 TZC_REGION_ACCESS_RDWR(TZC400_NSAID_USB) |
84 TZC_REGION_ACCESS_RDWR(TZC400_NSAID_DMA330) |
85 TZC_REGION_ACCESS_RDWR(TZC400_NSAID_THINLINKS) |
86 TZC_REGION_ACCESS_RDWR(TZC400_NSAID_AP) |
87 TZC_REGION_ACCESS_RDWR(TZC400_NSAID_GPU) |
Juan Castillo6b672f52014-09-04 14:43:09 +010088 TZC_REGION_ACCESS_RDWR(TZC400_NSAID_CORESIGHT));
89
90 /* Raise an exception if a NS device tries to access secure memory */
91 tzc_set_action(TZC_ACTION_ERR);
92
93 /* Enable filters. */
94 tzc_enable_filters();
95}
96
97/*******************************************************************************
Robin Murphy0f1d6662015-01-09 14:30:58 +000098 * Set up the MMU-401 SSD tables. The power-on configuration has all stream IDs
99 * assigned to Non-Secure except some for the DMA-330. Assign those back to the
100 * Non-Secure world as well, otherwise EL1 may end up erroneously generating
101 * (untranslated) Secure transactions if it turns the SMMU on.
102 ******************************************************************************/
103static void init_mmu401(void)
104{
105 uint32_t reg = mmio_read_32(MMU401_DMA330_BASE + MMU401_SSD_OFFSET);
106 reg |= 0x1FF;
107 mmio_write_32(MMU401_DMA330_BASE + MMU401_SSD_OFFSET, reg);
108}
109
110/*******************************************************************************
Juan Castillo6b672f52014-09-04 14:43:09 +0100111 * Initialize the secure environment. At this moment only the TrustZone
112 * Controller is initialized.
113 ******************************************************************************/
114void plat_security_setup(void)
115{
116 /* Initialize the TrustZone Controller */
117 init_tzc400();
Robin Murphy0f1d6662015-01-09 14:30:58 +0000118 /* Initialize the SMMU SSD tables*/
119 init_mmu401();
Juan Castillo6b672f52014-09-04 14:43:09 +0100120}