1 /*
2  * Copyright (c) 2017-2020, 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 <arch.h>
12 #include <common/desc_image_load.h>
13 
14 #include "uniphier.h"
15 
16 #define UNIPHIER_BL33_OFFSET		0x04000000UL
17 #define UNIPHIER_BL33_MAX_SIZE		0x00800000UL
18 
19 #define UNIPHIER_SCP_OFFSET		0x04800000UL
20 #define UNIPHIER_SCP_MAX_SIZE		0x00020000UL
21 
22 static struct bl_mem_params_node uniphier_image_descs[] = {
23 	{
24 		.image_id = SCP_BL2_IMAGE_ID,
25 
26 		SET_STATIC_PARAM_HEAD(image_info, PARAM_EP,
27 				      VERSION_2, image_info_t, 0),
28 		.image_info.image_base = UNIPHIER_SCP_OFFSET,
29 		.image_info.image_max_size = UNIPHIER_SCP_MAX_SIZE,
30 
31 		SET_STATIC_PARAM_HEAD(ep_info, PARAM_EP,
32 				      VERSION_2, entry_point_info_t,
33 				      NON_SECURE | NON_EXECUTABLE),
34 
35 		.next_handoff_image_id = INVALID_IMAGE_ID,
36 	},
37 	{
38 		.image_id = BL31_IMAGE_ID,
39 
40 		SET_STATIC_PARAM_HEAD(image_info, PARAM_EP,
41 				      VERSION_2, image_info_t, 0),
42 		.image_info.image_base = UNIPHIER_BL31_OFFSET,
43 		.image_info.image_max_size = UNIPHIER_BL31_MAX_SIZE,
44 
45 		SET_STATIC_PARAM_HEAD(ep_info, PARAM_EP,
46 				      VERSION_2, entry_point_info_t,
47 				      SECURE | EXECUTABLE | EP_FIRST_EXE),
48 		.ep_info.pc = UNIPHIER_BL31_OFFSET,
49 		.ep_info.spsr = SPSR_64(MODE_EL3, MODE_SP_ELX,
50 					DISABLE_ALL_EXCEPTIONS),
51 
52 #ifdef UNIPHIER_LOAD_BL32
53 		.next_handoff_image_id = BL32_IMAGE_ID,
54 #else
55 		.next_handoff_image_id = BL33_IMAGE_ID,
56 #endif
57 	},
58 #ifdef UNIPHIER_LOAD_BL32
59 	{
60 		.image_id = BL32_IMAGE_ID,
61 
62 		SET_STATIC_PARAM_HEAD(image_info, PARAM_EP,
63 				      VERSION_2, image_info_t, 0),
64 		.image_info.image_base = UNIPHIER_BL32_OFFSET,
65 		.image_info.image_max_size = UNIPHIER_BL32_MAX_SIZE,
66 
67 		SET_STATIC_PARAM_HEAD(ep_info, PARAM_EP,
68 				      VERSION_2, entry_point_info_t,
69 				      SECURE | EXECUTABLE),
70 		.ep_info.pc = UNIPHIER_BL32_OFFSET,
71 		.ep_info.spsr = SPSR_64(MODE_EL3, MODE_SP_ELX,
72 					DISABLE_ALL_EXCEPTIONS),
73 
74 		.next_handoff_image_id = BL33_IMAGE_ID,
75 	},
76 #endif
77 	{
78 		.image_id = BL33_IMAGE_ID,
79 
80 		SET_STATIC_PARAM_HEAD(image_info, PARAM_EP,
81 				      VERSION_2, image_info_t, 0),
82 		.image_info.image_base = UNIPHIER_BL33_OFFSET,
83 		.image_info.image_max_size = UNIPHIER_BL33_MAX_SIZE,
84 
85 		SET_STATIC_PARAM_HEAD(ep_info, PARAM_EP,
86 				      VERSION_2, entry_point_info_t,
87 				      NON_SECURE | EXECUTABLE),
88 		.ep_info.pc = UNIPHIER_BL33_OFFSET,
89 		.ep_info.spsr = SPSR_64(MODE_EL2, MODE_SP_ELX,
90 					DISABLE_ALL_EXCEPTIONS),
91 
92 		.next_handoff_image_id = INVALID_IMAGE_ID,
93 	},
94 };
REGISTER_BL_IMAGE_DESCS(uniphier_image_descs)95 REGISTER_BL_IMAGE_DESCS(uniphier_image_descs)
96 
97 /*
98  * image_info.image_base and ep_info.pc are the offset from the memory base.
99  * When ENABLE_PIE is set, we never know the real memory base at link-time.
100  * Fix-up the addresses by adding the run-time detected base.
101  */
102 void uniphier_init_image_descs(uintptr_t mem_base)
103 {
104 	int i;
105 
106 	for (i = 0; i < ARRAY_SIZE(uniphier_image_descs); i++) {
107 		uniphier_image_descs[i].image_info.image_base += mem_base;
108 		uniphier_image_descs[i].ep_info.pc += mem_base;
109 	}
110 }
111 
uniphier_get_image_info(unsigned int image_id)112 struct image_info *uniphier_get_image_info(unsigned int image_id)
113 {
114 	struct bl_mem_params_node *desc;
115 
116 	desc = get_bl_mem_params_node(image_id);
117 	assert(desc);
118 	return &desc->image_info;
119 }
120