xref: /rk3399_ARM-atf/plat/arm/common/arm_bl1_setup.c (revision 7b56928a122f4ba19b5f3d6b834590de2e82a978)
1b4315306SDan Handley /*
2c228956aSSoby Mathew  * Copyright (c) 2015-2018, ARM Limited and Contributors. All rights reserved.
3b4315306SDan Handley  *
482cb2c1aSdp-arm  * SPDX-License-Identifier: BSD-3-Clause
5b4315306SDan Handley  */
6b4315306SDan Handley 
7b4315306SDan Handley #include <arch.h>
8b4315306SDan Handley #include <arm_def.h>
93b211ff5SAntonio Nino Diaz #include <arm_xlat_tables.h>
101af540efSRoberto Vargas #include <bl1.h>
11b4315306SDan Handley #include <bl_common.h>
12b4315306SDan Handley #include <console.h>
13b4315306SDan Handley #include <plat_arm.h>
141af540efSRoberto Vargas #include <platform.h>
154adb10c1SIsla Mitchell #include <platform_def.h>
167b4c1405SJuan Castillo #include <sp805.h>
17af419dd6SSandrine Bailleux #include <utils.h>
183ae8a360SSandrine Bailleux #include "../../../bl1/bl1_private.h"
19b4315306SDan Handley 
20b4315306SDan Handley /* Weak definitions may be overridden in specific ARM standard platform */
21b4315306SDan Handley #pragma weak bl1_early_platform_setup
22b4315306SDan Handley #pragma weak bl1_plat_arch_setup
23b4315306SDan Handley #pragma weak bl1_platform_setup
24b4315306SDan Handley #pragma weak bl1_plat_sec_mem_layout
2507570d59SYatharth Kochar #pragma weak bl1_plat_prepare_exit
26b4315306SDan Handley 
27b4315306SDan Handley 
28b4315306SDan Handley /* Data structure which holds the extents of the trusted SRAM for BL1*/
29b4315306SDan Handley static meminfo_t bl1_tzram_layout;
30b4315306SDan Handley 
31b4315306SDan Handley meminfo_t *bl1_plat_sec_mem_layout(void)
32b4315306SDan Handley {
33b4315306SDan Handley 	return &bl1_tzram_layout;
34b4315306SDan Handley }
35b4315306SDan Handley 
36b4315306SDan Handley /*******************************************************************************
37b4315306SDan Handley  * BL1 specific platform actions shared between ARM standard platforms.
38b4315306SDan Handley  ******************************************************************************/
39b4315306SDan Handley void arm_bl1_early_platform_setup(void)
40b4315306SDan Handley {
41b4315306SDan Handley 
427b4c1405SJuan Castillo #if !ARM_DISABLE_TRUSTED_WDOG
437b4c1405SJuan Castillo 	/* Enable watchdog */
447b4c1405SJuan Castillo 	sp805_start(ARM_SP805_TWDG_BASE, ARM_TWDG_LOAD_VAL);
457b4c1405SJuan Castillo #endif
467b4c1405SJuan Castillo 
47b4315306SDan Handley 	/* Initialize the console to provide early debug support */
48b4315306SDan Handley 	console_init(PLAT_ARM_BOOT_UART_BASE, PLAT_ARM_BOOT_UART_CLK_IN_HZ,
49b4315306SDan Handley 			ARM_CONSOLE_BAUDRATE);
50b4315306SDan Handley 
51b4315306SDan Handley 	/* Allow BL1 to see the whole Trusted RAM */
52b4315306SDan Handley 	bl1_tzram_layout.total_base = ARM_BL_RAM_BASE;
53b4315306SDan Handley 	bl1_tzram_layout.total_size = ARM_BL_RAM_SIZE;
54b4315306SDan Handley 
55a8aa7fecSYatharth Kochar #if !LOAD_IMAGE_V2
56b4315306SDan Handley 	/* Calculate how much RAM BL1 is using and how much remains free */
57b4315306SDan Handley 	bl1_tzram_layout.free_base = ARM_BL_RAM_BASE;
58b4315306SDan Handley 	bl1_tzram_layout.free_size = ARM_BL_RAM_SIZE;
59b4315306SDan Handley 	reserve_mem(&bl1_tzram_layout.free_base,
60b4315306SDan Handley 		    &bl1_tzram_layout.free_size,
61b4315306SDan Handley 		    BL1_RAM_BASE,
62a8aa7fecSYatharth Kochar 		    BL1_RAM_LIMIT - BL1_RAM_BASE);
63a8aa7fecSYatharth Kochar #endif /* LOAD_IMAGE_V2 */
64b4315306SDan Handley }
65b4315306SDan Handley 
66b4315306SDan Handley void bl1_early_platform_setup(void)
67b4315306SDan Handley {
68b4315306SDan Handley 	arm_bl1_early_platform_setup();
69b4315306SDan Handley 
70b4315306SDan Handley 	/*
716355f234SVikram Kanigiri 	 * Initialize Interconnect for this cluster during cold boot.
72b4315306SDan Handley 	 * No need for locks as no other CPU is active.
73b4315306SDan Handley 	 */
746355f234SVikram Kanigiri 	plat_arm_interconnect_init();
75b4315306SDan Handley 	/*
766355f234SVikram Kanigiri 	 * Enable Interconnect coherency for the primary CPU's cluster.
77b4315306SDan Handley 	 */
786355f234SVikram Kanigiri 	plat_arm_interconnect_enter_coherency();
79b4315306SDan Handley }
80b4315306SDan Handley 
81b4315306SDan Handley /******************************************************************************
82b4315306SDan Handley  * Perform the very early platform specific architecture setup shared between
83b4315306SDan Handley  * ARM standard platforms. This only does basic initialization. Later
84b4315306SDan Handley  * architectural setup (bl1_arch_setup()) does not do anything platform
85b4315306SDan Handley  * specific.
86b4315306SDan Handley  *****************************************************************************/
87b4315306SDan Handley void arm_bl1_plat_arch_setup(void)
88b4315306SDan Handley {
89b5fa6563SSandrine Bailleux 	arm_setup_page_tables(bl1_tzram_layout.total_base,
90b4315306SDan Handley 			      bl1_tzram_layout.total_size,
910af559a8SSandrine Bailleux 			      BL_CODE_BASE,
92ecdc898dSMasahiro Yamada 			      BL1_CODE_END,
930af559a8SSandrine Bailleux 			      BL1_RO_DATA_BASE,
94ecdc898dSMasahiro Yamada 			      BL1_RO_DATA_END
95b4315306SDan Handley #if USE_COHERENT_MEM
9647497053SMasahiro Yamada 			      , BL_COHERENT_RAM_BASE,
9747497053SMasahiro Yamada 			      BL_COHERENT_RAM_END
98b4315306SDan Handley #endif
99b4315306SDan Handley 			     );
10083fc4a93SYatharth Kochar #ifdef AARCH32
10183fc4a93SYatharth Kochar 	enable_mmu_secure(0);
10283fc4a93SYatharth Kochar #else
103b5fa6563SSandrine Bailleux 	enable_mmu_el3(0);
10483fc4a93SYatharth Kochar #endif /* AARCH32 */
105b4315306SDan Handley }
106b4315306SDan Handley 
107b4315306SDan Handley void bl1_plat_arch_setup(void)
108b4315306SDan Handley {
109b4315306SDan Handley 	arm_bl1_plat_arch_setup();
110b4315306SDan Handley }
111b4315306SDan Handley 
112b4315306SDan Handley /*
113b4315306SDan Handley  * Perform the platform specific architecture setup shared between
114b4315306SDan Handley  * ARM standard platforms.
115b4315306SDan Handley  */
116b4315306SDan Handley void arm_bl1_platform_setup(void)
117b4315306SDan Handley {
118b4315306SDan Handley 	/* Initialise the IO layer and register platform IO devices */
119b4315306SDan Handley 	plat_arm_io_setup();
120c228956aSSoby Mathew #if LOAD_IMAGE_V2
121c228956aSSoby Mathew 	arm_load_tb_fw_config();
122c228956aSSoby Mathew #endif
123b4315306SDan Handley }
124b4315306SDan Handley 
125b4315306SDan Handley void bl1_platform_setup(void)
126b4315306SDan Handley {
127b4315306SDan Handley 	arm_bl1_platform_setup();
128b4315306SDan Handley }
129b4315306SDan Handley 
1304c117f6cSSandrine Bailleux void bl1_plat_prepare_exit(entry_point_info_t *ep_info)
1314c117f6cSSandrine Bailleux {
1327b4c1405SJuan Castillo #if !ARM_DISABLE_TRUSTED_WDOG
1337b4c1405SJuan Castillo 	/* Disable watchdog before leaving BL1 */
1347b4c1405SJuan Castillo 	sp805_stop(ARM_SP805_TWDG_BASE);
1357b4c1405SJuan Castillo #endif
1367b4c1405SJuan Castillo 
1374c117f6cSSandrine Bailleux #ifdef EL3_PAYLOAD_BASE
1384c117f6cSSandrine Bailleux 	/*
1394c117f6cSSandrine Bailleux 	 * Program the EL3 payload's entry point address into the CPUs mailbox
1404c117f6cSSandrine Bailleux 	 * in order to release secondary CPUs from their holding pen and make
1414c117f6cSSandrine Bailleux 	 * them jump there.
1424c117f6cSSandrine Bailleux 	 */
1434c117f6cSSandrine Bailleux 	arm_program_trusted_mailbox(ep_info->pc);
1444c117f6cSSandrine Bailleux 	dsbsy();
1454c117f6cSSandrine Bailleux 	sev();
1464c117f6cSSandrine Bailleux #endif
1474c117f6cSSandrine Bailleux }
148*7b56928aSSoby Mathew 
149*7b56928aSSoby Mathew /*******************************************************************************
150*7b56928aSSoby Mathew  * The following function checks if Firmware update is needed,
151*7b56928aSSoby Mathew  * by checking if TOC in FIP image is valid or not.
152*7b56928aSSoby Mathew  ******************************************************************************/
153*7b56928aSSoby Mathew unsigned int bl1_plat_get_next_image_id(void)
154*7b56928aSSoby Mathew {
155*7b56928aSSoby Mathew 	if (!arm_io_is_toc_valid())
156*7b56928aSSoby Mathew 		return NS_BL1U_IMAGE_ID;
157*7b56928aSSoby Mathew 
158*7b56928aSSoby Mathew 	return BL2_IMAGE_ID;
159*7b56928aSSoby Mathew }
160