xref: /rk3399_ARM-atf/plat/arm/board/juno/juno_security.c (revision 57f782019a0007670625414517cb94c4ab2aaa58)
185135283SDan Handley /*
285135283SDan Handley  * Copyright (c) 2014-2015, ARM Limited and Contributors. All rights reserved.
385135283SDan Handley  *
485135283SDan Handley  * Redistribution and use in source and binary forms, with or without
585135283SDan Handley  * modification, are permitted provided that the following conditions are met:
685135283SDan Handley  *
785135283SDan Handley  * Redistributions of source code must retain the above copyright notice, this
885135283SDan Handley  * list of conditions and the following disclaimer.
985135283SDan Handley  *
1085135283SDan Handley  * Redistributions in binary form must reproduce the above copyright notice,
1185135283SDan Handley  * this list of conditions and the following disclaimer in the documentation
1285135283SDan Handley  * and/or other materials provided with the distribution.
1385135283SDan Handley  *
1485135283SDan Handley  * Neither the name of ARM nor the names of its contributors may be used
1585135283SDan Handley  * to endorse or promote products derived from this software without specific
1685135283SDan Handley  * prior written permission.
1785135283SDan Handley  *
1885135283SDan Handley  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
1985135283SDan Handley  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2085135283SDan Handley  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2185135283SDan Handley  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
2285135283SDan Handley  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2385135283SDan Handley  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2485135283SDan Handley  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2585135283SDan Handley  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2685135283SDan Handley  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2785135283SDan Handley  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2885135283SDan Handley  * POSSIBILITY OF SUCH DAMAGE.
2985135283SDan Handley  */
3085135283SDan Handley 
3185135283SDan Handley #include <mmio.h>
32883852caSVikram Kanigiri #include <nic_400.h>
3385135283SDan Handley #include <plat_arm.h>
3485135283SDan Handley #include <soc_css.h>
3585135283SDan Handley #include "juno_def.h"
3685135283SDan Handley 
3785135283SDan Handley 
3885135283SDan Handley /*******************************************************************************
3985135283SDan Handley  * Set up the MMU-401 SSD tables. The power-on configuration has all stream IDs
4085135283SDan Handley  * assigned to Non-Secure except some for the DMA-330. Assign those back to the
4185135283SDan Handley  * Non-Secure world as well, otherwise EL1 may end up erroneously generating
4285135283SDan Handley  * (untranslated) Secure transactions if it turns the SMMU on.
4385135283SDan Handley  ******************************************************************************/
4485135283SDan Handley static void init_mmu401(void)
4585135283SDan Handley {
4685135283SDan Handley 	uint32_t reg = mmio_read_32(MMU401_DMA330_BASE + MMU401_SSD_OFFSET);
4785135283SDan Handley 	reg |= 0x1FF;
4885135283SDan Handley 	mmio_write_32(MMU401_DMA330_BASE + MMU401_SSD_OFFSET, reg);
4985135283SDan Handley }
5085135283SDan Handley 
5185135283SDan Handley /*******************************************************************************
52883852caSVikram Kanigiri  * Program CSS-NIC400 to allow non-secure access to some CSS regions.
53883852caSVikram Kanigiri  ******************************************************************************/
54883852caSVikram Kanigiri static void css_init_nic400(void)
55883852caSVikram Kanigiri {
56883852caSVikram Kanigiri 	/* Note: This is the NIC-400 device on the CSS */
57883852caSVikram Kanigiri 	mmio_write_32(PLAT_SOC_CSS_NIC400_BASE +
58883852caSVikram Kanigiri 		NIC400_ADDR_CTRL_SECURITY_REG(CSS_NIC400_SLAVE_BOOTSECURE),
59883852caSVikram Kanigiri 		~0);
60883852caSVikram Kanigiri }
61883852caSVikram Kanigiri 
62883852caSVikram Kanigiri /*******************************************************************************
6385135283SDan Handley  * Initialize the secure environment.
6485135283SDan Handley  ******************************************************************************/
6585135283SDan Handley void plat_arm_security_setup(void)
6685135283SDan Handley {
6785135283SDan Handley 	/* Initialize the TrustZone Controller */
68*57f78201SSoby Mathew 	arm_tzc400_setup();
69883852caSVikram Kanigiri 	/* Do ARM CSS internal NIC setup */
70883852caSVikram Kanigiri 	css_init_nic400();
7185135283SDan Handley 	/* Do ARM CSS SoC security setup */
7285135283SDan Handley 	soc_css_security_setup();
7385135283SDan Handley 	/* Initialize the SMMU SSD tables*/
7485135283SDan Handley 	init_mmu401();
7585135283SDan Handley }
76