blob: 9bf866a60df55d42f24bbafc113e680ccefa4dc9 [file] [log] [blame]
Masahiro Yamadad8e919c2016-09-03 11:37:40 +09001/*
Masahiro Yamada247fc042017-12-19 11:56:05 +09002 * Copyright (c) 2017-2018, ARM Limited and Contributors. All rights reserved.
Masahiro Yamadad8e919c2016-09-03 11:37:40 +09003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include <bl_common.h>
8#include <debug.h>
9#include <desc_image_load.h>
10#include <errno.h>
11#include <io/io_storage.h>
Masahiro Yamada8951b052018-01-26 11:42:01 +090012#include <image_decompress.h>
Masahiro Yamadad8e919c2016-09-03 11:37:40 +090013#include <platform.h>
14#include <platform_def.h>
Masahiro Yamada8951b052018-01-26 11:42:01 +090015#ifdef UNIPHIER_DECOMPRESS_GZIP
16#include <tf_gunzip.h>
17#endif
Masahiro Yamadad8e919c2016-09-03 11:37:40 +090018#include <xlat_tables_v2.h>
19
20#include "uniphier.h"
21
Masahiro Yamadad8e919c2016-09-03 11:37:40 +090022static int uniphier_bl2_kick_scp;
23
Masahiro Yamada247fc042017-12-19 11:56:05 +090024void bl2_el3_early_platform_setup(u_register_t x0, u_register_t x1,
25 u_register_t x2, u_register_t x3)
Masahiro Yamadad8e919c2016-09-03 11:37:40 +090026{
Masahiro Yamadad8e919c2016-09-03 11:37:40 +090027 uniphier_console_setup();
28}
29
30static const struct mmap_region uniphier_bl2_mmap[] = {
31 /* for SCP, BL33 */
32 MAP_REGION_FLAT(UNIPHIER_NS_DRAM_BASE, UNIPHIER_NS_DRAM_SIZE,
33 MT_MEMORY | MT_RW | MT_NS),
34 { .size = 0 },
35};
36
Masahiro Yamada247fc042017-12-19 11:56:05 +090037void bl2_el3_plat_arch_setup(void)
Masahiro Yamadad8e919c2016-09-03 11:37:40 +090038{
39 unsigned int soc;
40 int skip_scp = 0;
41 int ret;
42
43 uniphier_mmap_setup(UNIPHIER_SEC_DRAM_BASE, UNIPHIER_SEC_DRAM_SIZE,
44 uniphier_bl2_mmap);
Masahiro Yamada247fc042017-12-19 11:56:05 +090045 enable_mmu_el3(0);
Masahiro Yamadad8e919c2016-09-03 11:37:40 +090046
47 soc = uniphier_get_soc_id();
48 if (soc == UNIPHIER_SOC_UNKNOWN) {
49 ERROR("unsupported SoC\n");
50 plat_error_handler(-ENOTSUP);
51 }
52
53 ret = uniphier_io_setup(soc);
54 if (ret) {
55 ERROR("failed to setup io devices\n");
56 plat_error_handler(ret);
57 }
58
59 switch (uniphier_get_boot_master(soc)) {
60 case UNIPHIER_BOOT_MASTER_THIS:
61 INFO("Booting from this SoC\n");
62 skip_scp = 1;
63 break;
64 case UNIPHIER_BOOT_MASTER_SCP:
65 INFO("Booting from on-chip SCP\n");
66 if (uniphier_scp_is_running()) {
67 INFO("SCP is already running. SCP_BL2 load will be skipped.\n");
68 skip_scp = 1;
69 }
70
71 /*
72 * SCP must be kicked every time even if it is already running
73 * because it polls this event after the reboot of the backend.
74 */
75 uniphier_bl2_kick_scp = 1;
76 break;
77 case UNIPHIER_BOOT_MASTER_EXT:
78 INFO("Booting from external SCP\n");
79 skip_scp = 1;
80 break;
81 default:
82 plat_error_handler(-ENOTSUP);
83 }
84
85 if (!skip_scp) {
86 ret = uniphier_check_image(SCP_BL2_IMAGE_ID);
87 if (ret) {
88 WARN("SCP_BL2 image not found. SCP_BL2 load will be skipped.\n");
89 WARN("You must setup SCP by other means.\n");
90 skip_scp = 1;
91 uniphier_bl2_kick_scp = 0;
92 }
93 }
94
Masahiro Yamada0ac60c02018-02-01 21:37:40 +090095 if (skip_scp) {
96 struct image_info *image_info;
97
98 image_info = uniphier_get_image_info(SCP_BL2_IMAGE_ID);
99 image_info->h.attr |= IMAGE_ATTRIB_SKIP_LOADING;
100 }
Masahiro Yamadad8e919c2016-09-03 11:37:40 +0900101}
102
103void bl2_platform_setup(void)
104{
105}
106
107void plat_flush_next_bl_params(void)
108{
109 flush_bl_params_desc();
110}
111
112bl_load_info_t *plat_get_bl_image_load_info(void)
113{
114 return get_bl_load_info_from_mem_params_desc();
115}
116
117bl_params_t *plat_get_next_bl_params(void)
118{
119 return get_next_bl_params_from_mem_params_desc();
120}
121
Masahiro Yamada8951b052018-01-26 11:42:01 +0900122void bl2_plat_preload_setup(void)
123{
124#ifdef UNIPHIER_DECOMPRESS_GZIP
125 image_decompress_init(UNIPHIER_IMAGE_BUF_BASE,
126 UNIPHIER_IMAGE_BUF_SIZE,
127 gunzip);
128#endif
129}
130
131int bl2_plat_handle_pre_image_load(unsigned int image_id)
132{
133#ifdef UNIPHIER_DECOMPRESS_GZIP
134 image_decompress_prepare(uniphier_get_image_info(image_id));
135#endif
136 return 0;
137}
138
Masahiro Yamadad8e919c2016-09-03 11:37:40 +0900139int bl2_plat_handle_post_image_load(unsigned int image_id)
140{
Masahiro Yamada8951b052018-01-26 11:42:01 +0900141#ifdef UNIPHIER_DECOMPRESS_GZIP
142 struct image_info *image_info;
143 int ret;
144
145 image_info = uniphier_get_image_info(image_id);
146
147 if (!(image_info->h.attr & IMAGE_ATTRIB_SKIP_LOADING)) {
148 ret = image_decompress(uniphier_get_image_info(image_id));
149 if (ret)
150 return ret;
151 }
152#endif
153
Masahiro Yamadad8e919c2016-09-03 11:37:40 +0900154 if (image_id == SCP_BL2_IMAGE_ID && uniphier_bl2_kick_scp)
155 uniphier_scp_start();
156
157 return 0;
158}