xref: /rk3399_ARM-atf/plat/arm/common/tsp/arm_tsp_setup.c (revision 9018b7b8401ab106228842140b53502ee64f1432)
1 /*
2  * Copyright (c) 2015-2025, Arm Limited and Contributors. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 #include <assert.h>
8 
9 #include <platform_def.h>
10 
11 #include <bl32/tsp/platform_tsp.h>
12 #include <common/bl_common.h>
13 #include <common/debug.h>
14 #include <drivers/arm/pl011.h>
15 #include <drivers/console.h>
16 #include <plat/arm/common/plat_arm.h>
17 #include <plat/common/platform.h>
18 
19 /* Weak definitions may be overridden in specific ARM standard platform */
20 #pragma weak tsp_early_platform_setup
21 #pragma weak tsp_platform_setup
22 #pragma weak tsp_plat_arch_setup
23 
24 #define MAP_BL_TSP_TOTAL	MAP_REGION_FLAT(			\
25 					BL32_BASE,			\
26 					BL32_END - BL32_BASE,		\
27 					MT_MEMORY | MT_RW | MT_SECURE)
28 
29 /*******************************************************************************
30  * Initialize the UART
31  ******************************************************************************/
32 static console_t arm_tsp_runtime_console;
33 
34 void arm_tsp_early_platform_setup(u_register_t arg0, u_register_t arg1,
35 			      u_register_t arg2, u_register_t arg3)
36 {
37 	/*
38 	 * Initialize a different console than already in use to display
39 	 * messages from TSP
40 	 */
41 	int rc = console_pl011_register(PLAT_ARM_TSP_UART_BASE,
42 					PLAT_ARM_TSP_UART_CLK_IN_HZ,
43 					ARM_CONSOLE_BAUDRATE,
44 					&arm_tsp_runtime_console);
45 	if (rc == 0) {
46 		panic();
47 	}
48 
49 	console_set_scope(&arm_tsp_runtime_console,
50 			  CONSOLE_FLAG_BOOT | CONSOLE_FLAG_RUNTIME);
51 }
52 
53 void tsp_early_platform_setup(u_register_t arg0, u_register_t arg1,
54 			      u_register_t arg2, u_register_t arg3)
55 {
56 	arm_tsp_early_platform_setup(arg0, arg1, arg2, arg3);
57 }
58 
59 /*******************************************************************************
60  * Perform platform specific setup placeholder
61  ******************************************************************************/
62 void tsp_platform_setup(void)
63 {
64 	/*
65 	 * On GICv2 the driver must be initialised before calling the plat_ic_*
66 	 * functions as they need the data structures. Higher versions don't.
67 	 */
68 #if USE_GIC_DRIVER == 2
69 	gic_init(plat_my_core_pos());
70 #endif
71 }
72 
73 /*******************************************************************************
74  * Perform the very early platform specific architectural setup here. At the
75  * moment this is only initializes the MMU
76  ******************************************************************************/
77 void tsp_plat_arch_setup(void)
78 {
79 #if USE_COHERENT_MEM
80 	/* Ensure ARM platforms don't use coherent memory in TSP */
81 	assert((BL_COHERENT_RAM_END - BL_COHERENT_RAM_BASE) == 0U);
82 #endif
83 
84 	const mmap_region_t bl_regions[] = {
85 		MAP_BL_TSP_TOTAL,
86 		ARM_MAP_BL_RO,
87 		{0}
88 	};
89 
90 	setup_page_tables(bl_regions, plat_arm_get_mmap());
91 	enable_mmu_el1(0);
92 
93 #if PLAT_RO_XLAT_TABLES
94 	arm_xlat_make_tables_readonly();
95 #endif
96 }
97