xref: /rk3399_ARM-atf/plat/arm/common/arm_bl1_setup.c (revision 0af559a833e9cb1be1e1295d00e22ecab1d3f5be)
1b4315306SDan Handley /*
26355f234SVikram Kanigiri  * Copyright (c) 2015-2016, ARM Limited and Contributors. All rights reserved.
3b4315306SDan Handley  *
4b4315306SDan Handley  * Redistribution and use in source and binary forms, with or without
5b4315306SDan Handley  * modification, are permitted provided that the following conditions are met:
6b4315306SDan Handley  *
7b4315306SDan Handley  * Redistributions of source code must retain the above copyright notice, this
8b4315306SDan Handley  * list of conditions and the following disclaimer.
9b4315306SDan Handley  *
10b4315306SDan Handley  * Redistributions in binary form must reproduce the above copyright notice,
11b4315306SDan Handley  * this list of conditions and the following disclaimer in the documentation
12b4315306SDan Handley  * and/or other materials provided with the distribution.
13b4315306SDan Handley  *
14b4315306SDan Handley  * Neither the name of ARM nor the names of its contributors may be used
15b4315306SDan Handley  * to endorse or promote products derived from this software without specific
16b4315306SDan Handley  * prior written permission.
17b4315306SDan Handley  *
18b4315306SDan Handley  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19b4315306SDan Handley  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20b4315306SDan Handley  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21b4315306SDan Handley  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22b4315306SDan Handley  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23b4315306SDan Handley  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24b4315306SDan Handley  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25b4315306SDan Handley  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26b4315306SDan Handley  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27b4315306SDan Handley  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28b4315306SDan Handley  * POSSIBILITY OF SUCH DAMAGE.
29b4315306SDan Handley  */
30b4315306SDan Handley 
31b4315306SDan Handley #include <arch.h>
32b4315306SDan Handley #include <arm_def.h>
33b4315306SDan Handley #include <bl_common.h>
34b4315306SDan Handley #include <console.h>
35b4315306SDan Handley #include <platform_def.h>
36b4315306SDan Handley #include <plat_arm.h>
377b4c1405SJuan Castillo #include <sp805.h>
38af419dd6SSandrine Bailleux #include <utils.h>
39af419dd6SSandrine Bailleux #include <xlat_tables.h>
403ae8a360SSandrine Bailleux #include "../../../bl1/bl1_private.h"
41b4315306SDan Handley 
42b4315306SDan Handley 
43b4315306SDan Handley #if USE_COHERENT_MEM
44b4315306SDan Handley /*
45b4315306SDan Handley  * The next 2 constants identify the extents of the coherent memory region.
46b4315306SDan Handley  * These addresses are used by the MMU setup code and therefore they must be
47b4315306SDan Handley  * page-aligned.  It is the responsibility of the linker script to ensure that
48b4315306SDan Handley  * __COHERENT_RAM_START__ and __COHERENT_RAM_END__ linker symbols refer to
49b4315306SDan Handley  * page-aligned addresses.
50b4315306SDan Handley  */
51b4315306SDan Handley #define BL1_COHERENT_RAM_BASE (unsigned long)(&__COHERENT_RAM_START__)
52b4315306SDan Handley #define BL1_COHERENT_RAM_LIMIT (unsigned long)(&__COHERENT_RAM_END__)
53b4315306SDan Handley #endif
54b4315306SDan Handley 
55b4315306SDan Handley 
56b4315306SDan Handley /* Weak definitions may be overridden in specific ARM standard platform */
57b4315306SDan Handley #pragma weak bl1_early_platform_setup
58b4315306SDan Handley #pragma weak bl1_plat_arch_setup
59b4315306SDan Handley #pragma weak bl1_platform_setup
60b4315306SDan Handley #pragma weak bl1_plat_sec_mem_layout
61b4315306SDan Handley 
62b4315306SDan Handley 
63b4315306SDan Handley /* Data structure which holds the extents of the trusted SRAM for BL1*/
64b4315306SDan Handley static meminfo_t bl1_tzram_layout;
65b4315306SDan Handley 
66b4315306SDan Handley meminfo_t *bl1_plat_sec_mem_layout(void)
67b4315306SDan Handley {
68b4315306SDan Handley 	return &bl1_tzram_layout;
69b4315306SDan Handley }
70b4315306SDan Handley 
71b4315306SDan Handley /*******************************************************************************
72b4315306SDan Handley  * BL1 specific platform actions shared between ARM standard platforms.
73b4315306SDan Handley  ******************************************************************************/
74b4315306SDan Handley void arm_bl1_early_platform_setup(void)
75b4315306SDan Handley {
76b4315306SDan Handley 	const size_t bl1_size = BL1_RAM_LIMIT - BL1_RAM_BASE;
77b4315306SDan Handley 
787b4c1405SJuan Castillo #if !ARM_DISABLE_TRUSTED_WDOG
797b4c1405SJuan Castillo 	/* Enable watchdog */
807b4c1405SJuan Castillo 	sp805_start(ARM_SP805_TWDG_BASE, ARM_TWDG_LOAD_VAL);
817b4c1405SJuan Castillo #endif
827b4c1405SJuan Castillo 
83b4315306SDan Handley 	/* Initialize the console to provide early debug support */
84b4315306SDan Handley 	console_init(PLAT_ARM_BOOT_UART_BASE, PLAT_ARM_BOOT_UART_CLK_IN_HZ,
85b4315306SDan Handley 			ARM_CONSOLE_BAUDRATE);
86b4315306SDan Handley 
87b4315306SDan Handley 	/* Allow BL1 to see the whole Trusted RAM */
88b4315306SDan Handley 	bl1_tzram_layout.total_base = ARM_BL_RAM_BASE;
89b4315306SDan Handley 	bl1_tzram_layout.total_size = ARM_BL_RAM_SIZE;
90b4315306SDan Handley 
91b4315306SDan Handley 	/* Calculate how much RAM BL1 is using and how much remains free */
92b4315306SDan Handley 	bl1_tzram_layout.free_base = ARM_BL_RAM_BASE;
93b4315306SDan Handley 	bl1_tzram_layout.free_size = ARM_BL_RAM_SIZE;
94b4315306SDan Handley 	reserve_mem(&bl1_tzram_layout.free_base,
95b4315306SDan Handley 		    &bl1_tzram_layout.free_size,
96b4315306SDan Handley 		    BL1_RAM_BASE,
97b4315306SDan Handley 		    bl1_size);
98b4315306SDan Handley }
99b4315306SDan Handley 
100b4315306SDan Handley void bl1_early_platform_setup(void)
101b4315306SDan Handley {
102b4315306SDan Handley 	arm_bl1_early_platform_setup();
103b4315306SDan Handley 
104b4315306SDan Handley 	/*
1056355f234SVikram Kanigiri 	 * Initialize Interconnect for this cluster during cold boot.
106b4315306SDan Handley 	 * No need for locks as no other CPU is active.
107b4315306SDan Handley 	 */
1086355f234SVikram Kanigiri 	plat_arm_interconnect_init();
109b4315306SDan Handley 	/*
1106355f234SVikram Kanigiri 	 * Enable Interconnect coherency for the primary CPU's cluster.
111b4315306SDan Handley 	 */
1126355f234SVikram Kanigiri 	plat_arm_interconnect_enter_coherency();
113b4315306SDan Handley }
114b4315306SDan Handley 
115b4315306SDan Handley /******************************************************************************
116b4315306SDan Handley  * Perform the very early platform specific architecture setup shared between
117b4315306SDan Handley  * ARM standard platforms. This only does basic initialization. Later
118b4315306SDan Handley  * architectural setup (bl1_arch_setup()) does not do anything platform
119b4315306SDan Handley  * specific.
120b4315306SDan Handley  *****************************************************************************/
121b4315306SDan Handley void arm_bl1_plat_arch_setup(void)
122b4315306SDan Handley {
123b5fa6563SSandrine Bailleux 	arm_setup_page_tables(bl1_tzram_layout.total_base,
124b4315306SDan Handley 			      bl1_tzram_layout.total_size,
125*0af559a8SSandrine Bailleux 			      BL_CODE_BASE,
126*0af559a8SSandrine Bailleux 			      BL1_CODE_LIMIT,
127*0af559a8SSandrine Bailleux 			      BL1_RO_DATA_BASE,
128*0af559a8SSandrine Bailleux 			      BL1_RO_DATA_LIMIT
129b4315306SDan Handley #if USE_COHERENT_MEM
130b4315306SDan Handley 			      , BL1_COHERENT_RAM_BASE,
131b4315306SDan Handley 			      BL1_COHERENT_RAM_LIMIT
132b4315306SDan Handley #endif
133b4315306SDan Handley 			     );
134b5fa6563SSandrine Bailleux 	enable_mmu_el3(0);
135b4315306SDan Handley }
136b4315306SDan Handley 
137b4315306SDan Handley void bl1_plat_arch_setup(void)
138b4315306SDan Handley {
139b4315306SDan Handley 	arm_bl1_plat_arch_setup();
140b4315306SDan Handley }
141b4315306SDan Handley 
142b4315306SDan Handley /*
143b4315306SDan Handley  * Perform the platform specific architecture setup shared between
144b4315306SDan Handley  * ARM standard platforms.
145b4315306SDan Handley  */
146b4315306SDan Handley void arm_bl1_platform_setup(void)
147b4315306SDan Handley {
148b4315306SDan Handley 	/* Initialise the IO layer and register platform IO devices */
149b4315306SDan Handley 	plat_arm_io_setup();
150b4315306SDan Handley }
151b4315306SDan Handley 
152b4315306SDan Handley void bl1_platform_setup(void)
153b4315306SDan Handley {
154b4315306SDan Handley 	arm_bl1_platform_setup();
155b4315306SDan Handley }
156b4315306SDan Handley 
1574c117f6cSSandrine Bailleux void bl1_plat_prepare_exit(entry_point_info_t *ep_info)
1584c117f6cSSandrine Bailleux {
1597b4c1405SJuan Castillo #if !ARM_DISABLE_TRUSTED_WDOG
1607b4c1405SJuan Castillo 	/* Disable watchdog before leaving BL1 */
1617b4c1405SJuan Castillo 	sp805_stop(ARM_SP805_TWDG_BASE);
1627b4c1405SJuan Castillo #endif
1637b4c1405SJuan Castillo 
1644c117f6cSSandrine Bailleux #ifdef EL3_PAYLOAD_BASE
1654c117f6cSSandrine Bailleux 	/*
1664c117f6cSSandrine Bailleux 	 * Program the EL3 payload's entry point address into the CPUs mailbox
1674c117f6cSSandrine Bailleux 	 * in order to release secondary CPUs from their holding pen and make
1684c117f6cSSandrine Bailleux 	 * them jump there.
1694c117f6cSSandrine Bailleux 	 */
1704c117f6cSSandrine Bailleux 	arm_program_trusted_mailbox(ep_info->pc);
1714c117f6cSSandrine Bailleux 	dsbsy();
1724c117f6cSSandrine Bailleux 	sev();
1734c117f6cSSandrine Bailleux #endif
1744c117f6cSSandrine Bailleux }
175