xref: /rk3399_ARM-atf/plat/ti/k3/common/k3_bl31_setup.c (revision a546d25b1e1af0d6b9dea272fb6950d46a4cf56d)
1 /*
2  * Copyright (c) 2017-2018, ARM Limited and Contributors. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 #include <arch.h>
8 #include <arch_helpers.h>
9 #include <assert.h>
10 #include <bl_common.h>
11 #include <debug.h>
12 #include <platform_def.h>
13 #include <string.h>
14 
15 /*
16  * Placeholder variables for maintaining information about the next image(s)
17  */
18 static entry_point_info_t bl32_image_ep_info;
19 static entry_point_info_t bl33_image_ep_info;
20 
21 /*******************************************************************************
22  * Gets SPSR for BL33 entry
23  ******************************************************************************/
24 static uint32_t k3_get_spsr_for_bl33_entry(void)
25 {
26 	unsigned long el_status;
27 	unsigned int mode;
28 	uint32_t spsr;
29 
30 	/* Figure out what mode we enter the non-secure world in */
31 	el_status = read_id_aa64pfr0_el1() >> ID_AA64PFR0_EL2_SHIFT;
32 	el_status &= ID_AA64PFR0_ELX_MASK;
33 
34 	mode = (el_status) ? MODE_EL2 : MODE_EL1;
35 
36 	spsr = SPSR_64(mode, MODE_SP_ELX, DISABLE_ALL_EXCEPTIONS);
37 	return spsr;
38 }
39 
40 /*******************************************************************************
41  * Perform any BL3-1 early platform setup, such as console init and deciding on
42  * memory layout.
43  ******************************************************************************/
44 void bl31_early_platform_setup(bl31_params_t *from_bl2,
45 			       void *plat_params_from_bl2)
46 {
47 	/* There are no parameters from BL2 if BL31 is a reset vector */
48 	assert(from_bl2 == NULL);
49 	assert(plat_params_from_bl2 == NULL);
50 
51 #ifdef BL32_BASE
52 	/* Populate entry point information for BL32 */
53 	SET_PARAM_HEAD(&bl32_image_ep_info, PARAM_EP, VERSION_1, 0);
54 	bl32_image_ep_info.pc = BL32_BASE;
55 	bl32_image_ep_info.spsr = SPSR_64(MODE_EL1, MODE_SP_ELX,
56 					  DISABLE_ALL_EXCEPTIONS);
57 	SET_SECURITY_STATE(bl32_image_ep_info.h.attr, SECURE);
58 #endif
59 
60 	/* Populate entry point information for BL33 */
61 	SET_PARAM_HEAD(&bl33_image_ep_info, PARAM_EP, VERSION_1, 0);
62 	bl33_image_ep_info.pc = PRELOADED_BL33_BASE;
63 	bl33_image_ep_info.spsr = k3_get_spsr_for_bl33_entry();
64 	SET_SECURITY_STATE(bl33_image_ep_info.h.attr, NON_SECURE);
65 
66 #ifdef K3_HW_CONFIG_BASE
67 	/*
68 	 * According to the file ``Documentation/arm64/booting.txt`` of the
69 	 * Linux kernel tree, Linux expects the physical address of the device
70 	 * tree blob (DTB) in x0, while x1-x3 are reserved for future use and
71 	 * must be 0.
72 	 */
73 	bl33_image_ep_info.args.arg0 = (u_register_t)K3_HW_CONFIG_BASE;
74 	bl33_image_ep_info.args.arg1 = 0U;
75 	bl33_image_ep_info.args.arg2 = 0U;
76 	bl33_image_ep_info.args.arg3 = 0U;
77 #endif
78 }
79 
80 void bl31_early_platform_setup2(u_register_t arg0, u_register_t arg1,
81 				u_register_t arg2, u_register_t arg3)
82 {
83 	bl31_early_platform_setup((void *)arg0, (void *)arg1);
84 }
85 
86 void bl31_plat_arch_setup(void)
87 {
88 	/* TODO: Initialize the MMU tables */
89 }
90 
91 void bl31_platform_setup(void)
92 {
93 	/* TODO: Initialize the GIC CPU and distributor interfaces */
94 }
95 
96 void platform_mem_init(void)
97 {
98 	/* Do nothing for now... */
99 }
100 
101 /*
102  * Empty function to prevent the console from being uninitialized after BL33 is
103  * started and allow us to see messages from BL31.
104  */
105 void bl31_plat_runtime_setup(void)
106 {
107 }
108 
109 /*******************************************************************************
110  * Return a pointer to the 'entry_point_info' structure of the next image
111  * for the security state specified. BL3-3 corresponds to the non-secure
112  * image type while BL3-2 corresponds to the secure image type. A NULL
113  * pointer is returned if the image does not exist.
114  ******************************************************************************/
115 entry_point_info_t *bl31_plat_get_next_image_ep_info(uint32_t type)
116 {
117 	entry_point_info_t *next_image_info;
118 
119 	assert(sec_state_is_valid(type));
120 	next_image_info = (type == NON_SECURE) ? &bl33_image_ep_info :
121 						 &bl32_image_ep_info;
122 	/*
123 	 * None of the images on the ARM development platforms can have 0x0
124 	 * as the entrypoint
125 	 */
126 	if (next_image_info->pc)
127 		return next_image_info;
128 
129 	NOTICE("Requested nonexistent image\n");
130 	return NULL;
131 }
132