xref: /rk3399_ARM-atf/plat/socionext/uniphier/uniphier_bl2_setup.c (revision c948f77136c42a92d0bb660543a3600c36dcf7f1)
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 <errno.h>
8 
9 #include <platform_def.h>
10 
11 #include <common/bl_common.h>
12 #include <common/debug.h>
13 #include <common/desc_image_load.h>
14 #include <common/image_decompress.h>
15 #include <drivers/io/io_storage.h>
16 #include <lib/xlat_tables/xlat_tables_v2.h>
17 #include <plat/common/platform.h>
18 #ifdef UNIPHIER_DECOMPRESS_GZIP
19 #include <tf_gunzip.h>
20 #endif
21 
22 #include "uniphier.h"
23 
24 #define BL2_END			(unsigned long)(&__BL2_END__)
25 #define BL2_SIZE		((BL2_END) - (BL2_BASE))
26 
27 static int uniphier_bl2_kick_scp;
28 
29 void bl2_el3_early_platform_setup(u_register_t x0, u_register_t x1,
30 				  u_register_t x2, u_register_t x3)
31 {
32 	uniphier_console_setup();
33 }
34 
35 static const struct mmap_region uniphier_bl2_mmap[] = {
36 	/* for BL31, BL32 */
37 	MAP_REGION_FLAT(UNIPHIER_SEC_DRAM_BASE, UNIPHIER_SEC_DRAM_SIZE,
38 			MT_MEMORY | MT_RW | MT_SECURE),
39 	/* for SCP, BL33 */
40 	MAP_REGION_FLAT(UNIPHIER_NS_DRAM_BASE, UNIPHIER_NS_DRAM_SIZE,
41 			MT_MEMORY | MT_RW | MT_NS),
42 	{ .size = 0 },
43 };
44 
45 void bl2_el3_plat_arch_setup(void)
46 {
47 	unsigned int soc;
48 	int skip_scp = 0;
49 	int ret;
50 
51 	uniphier_mmap_setup(BL2_BASE, BL2_SIZE, uniphier_bl2_mmap);
52 	enable_mmu_el3(0);
53 
54 	soc = uniphier_get_soc_id();
55 	if (soc == UNIPHIER_SOC_UNKNOWN) {
56 		ERROR("unsupported SoC\n");
57 		plat_error_handler(-ENOTSUP);
58 	}
59 
60 	ret = uniphier_io_setup(soc);
61 	if (ret) {
62 		ERROR("failed to setup io devices\n");
63 		plat_error_handler(ret);
64 	}
65 
66 	switch (uniphier_get_boot_master(soc)) {
67 	case UNIPHIER_BOOT_MASTER_THIS:
68 		INFO("Booting from this SoC\n");
69 		skip_scp = 1;
70 		break;
71 	case UNIPHIER_BOOT_MASTER_SCP:
72 		INFO("Booting from on-chip SCP\n");
73 		if (uniphier_scp_is_running()) {
74 			INFO("SCP is already running. SCP_BL2 load will be skipped.\n");
75 			skip_scp = 1;
76 		}
77 
78 		/*
79 		 * SCP must be kicked every time even if it is already running
80 		 * because it polls this event after the reboot of the backend.
81 		 */
82 		uniphier_bl2_kick_scp = 1;
83 		break;
84 	case UNIPHIER_BOOT_MASTER_EXT:
85 		INFO("Booting from external SCP\n");
86 		skip_scp = 1;
87 		break;
88 	default:
89 		plat_error_handler(-ENOTSUP);
90 		break;
91 	}
92 
93 	if (skip_scp) {
94 		struct image_info *image_info;
95 
96 		image_info = uniphier_get_image_info(SCP_BL2_IMAGE_ID);
97 		image_info->h.attr |= IMAGE_ATTRIB_SKIP_LOADING;
98 	}
99 }
100 
101 void bl2_platform_setup(void)
102 {
103 }
104 
105 void plat_flush_next_bl_params(void)
106 {
107 	flush_bl_params_desc();
108 }
109 
110 bl_load_info_t *plat_get_bl_image_load_info(void)
111 {
112 	return get_bl_load_info_from_mem_params_desc();
113 }
114 
115 bl_params_t *plat_get_next_bl_params(void)
116 {
117 	return get_next_bl_params_from_mem_params_desc();
118 }
119 
120 void bl2_plat_preload_setup(void)
121 {
122 #ifdef UNIPHIER_DECOMPRESS_GZIP
123 	image_decompress_init(UNIPHIER_IMAGE_BUF_BASE,
124 			      UNIPHIER_IMAGE_BUF_SIZE,
125 			      gunzip);
126 #endif
127 }
128 
129 int bl2_plat_handle_pre_image_load(unsigned int image_id)
130 {
131 #ifdef UNIPHIER_DECOMPRESS_GZIP
132 	image_decompress_prepare(uniphier_get_image_info(image_id));
133 #endif
134 	return 0;
135 }
136 
137 int bl2_plat_handle_post_image_load(unsigned int image_id)
138 {
139 #ifdef UNIPHIER_DECOMPRESS_GZIP
140 	struct image_info *image_info;
141 	int ret;
142 
143 	image_info = uniphier_get_image_info(image_id);
144 
145 	if (!(image_info->h.attr & IMAGE_ATTRIB_SKIP_LOADING)) {
146 		ret = image_decompress(uniphier_get_image_info(image_id));
147 		if (ret)
148 			return ret;
149 	}
150 #endif
151 
152 	if (image_id == SCP_BL2_IMAGE_ID && uniphier_bl2_kick_scp)
153 		uniphier_scp_start();
154 
155 	return 0;
156 }
157