blob: 787b3ac3d11e5fa1ef835c1ec9f8a5220636cd0b [file] [log] [blame]
Masahiro Yamada574388c2016-09-03 11:37:40 +09001/*
Masahiro Yamada75bfecb2017-12-19 11:56:05 +09002 * Copyright (c) 2017-2018, ARM Limited and Contributors. All rights reserved.
Masahiro Yamada574388c2016-09-03 11:37:40 +09003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
Masahiro Yamada574388c2016-09-03 11:37:40 +09007#include <errno.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +00008
Masahiro Yamada574388c2016-09-03 11:37:40 +09009#include <platform_def.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000010
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>
Masahiro Yamada4ff71af2018-01-26 11:42:01 +090018#ifdef UNIPHIER_DECOMPRESS_GZIP
19#include <tf_gunzip.h>
20#endif
Masahiro Yamada574388c2016-09-03 11:37:40 +090021
22#include "uniphier.h"
23
Masahiro Yamadacad2ab52018-01-30 18:49:37 +090024#define BL2_SIZE ((BL2_END) - (BL2_BASE))
25
Masahiro Yamada574388c2016-09-03 11:37:40 +090026static int uniphier_bl2_kick_scp;
27
Masahiro Yamada75bfecb2017-12-19 11:56:05 +090028void bl2_el3_early_platform_setup(u_register_t x0, u_register_t x1,
29 u_register_t x2, u_register_t x3)
Masahiro Yamada574388c2016-09-03 11:37:40 +090030{
Masahiro Yamada574388c2016-09-03 11:37:40 +090031 uniphier_console_setup();
32}
33
34static const struct mmap_region uniphier_bl2_mmap[] = {
Masahiro Yamadacad2ab52018-01-30 18:49:37 +090035 /* for BL31, BL32 */
36 MAP_REGION_FLAT(UNIPHIER_SEC_DRAM_BASE, UNIPHIER_SEC_DRAM_SIZE,
37 MT_MEMORY | MT_RW | MT_SECURE),
Masahiro Yamada574388c2016-09-03 11:37:40 +090038 /* for SCP, BL33 */
39 MAP_REGION_FLAT(UNIPHIER_NS_DRAM_BASE, UNIPHIER_NS_DRAM_SIZE,
40 MT_MEMORY | MT_RW | MT_NS),
41 { .size = 0 },
42};
43
Masahiro Yamada75bfecb2017-12-19 11:56:05 +090044void bl2_el3_plat_arch_setup(void)
Masahiro Yamada574388c2016-09-03 11:37:40 +090045{
46 unsigned int soc;
47 int skip_scp = 0;
48 int ret;
49
Masahiro Yamadacad2ab52018-01-30 18:49:37 +090050 uniphier_mmap_setup(BL2_BASE, BL2_SIZE, uniphier_bl2_mmap);
Masahiro Yamada75bfecb2017-12-19 11:56:05 +090051 enable_mmu_el3(0);
Masahiro Yamada574388c2016-09-03 11:37:40 +090052
53 soc = uniphier_get_soc_id();
54 if (soc == UNIPHIER_SOC_UNKNOWN) {
55 ERROR("unsupported SoC\n");
56 plat_error_handler(-ENOTSUP);
57 }
58
59 ret = uniphier_io_setup(soc);
60 if (ret) {
61 ERROR("failed to setup io devices\n");
62 plat_error_handler(ret);
63 }
64
65 switch (uniphier_get_boot_master(soc)) {
66 case UNIPHIER_BOOT_MASTER_THIS:
67 INFO("Booting from this SoC\n");
68 skip_scp = 1;
69 break;
70 case UNIPHIER_BOOT_MASTER_SCP:
71 INFO("Booting from on-chip SCP\n");
72 if (uniphier_scp_is_running()) {
73 INFO("SCP is already running. SCP_BL2 load will be skipped.\n");
74 skip_scp = 1;
75 }
76
77 /*
78 * SCP must be kicked every time even if it is already running
79 * because it polls this event after the reboot of the backend.
80 */
81 uniphier_bl2_kick_scp = 1;
82 break;
83 case UNIPHIER_BOOT_MASTER_EXT:
84 INFO("Booting from external SCP\n");
85 skip_scp = 1;
86 break;
87 default:
88 plat_error_handler(-ENOTSUP);
Jonathan Wrightff957ed2018-03-14 15:24:00 +000089 break;
Masahiro Yamada574388c2016-09-03 11:37:40 +090090 }
91
Masahiro Yamada4c91c802018-02-01 21:37:40 +090092 if (skip_scp) {
93 struct image_info *image_info;
94
95 image_info = uniphier_get_image_info(SCP_BL2_IMAGE_ID);
96 image_info->h.attr |= IMAGE_ATTRIB_SKIP_LOADING;
97 }
Masahiro Yamada574388c2016-09-03 11:37:40 +090098}
99
100void bl2_platform_setup(void)
101{
102}
103
104void plat_flush_next_bl_params(void)
105{
106 flush_bl_params_desc();
107}
108
109bl_load_info_t *plat_get_bl_image_load_info(void)
110{
111 return get_bl_load_info_from_mem_params_desc();
112}
113
114bl_params_t *plat_get_next_bl_params(void)
115{
116 return get_next_bl_params_from_mem_params_desc();
117}
118
Masahiro Yamada4ff71af2018-01-26 11:42:01 +0900119void bl2_plat_preload_setup(void)
120{
121#ifdef UNIPHIER_DECOMPRESS_GZIP
122 image_decompress_init(UNIPHIER_IMAGE_BUF_BASE,
123 UNIPHIER_IMAGE_BUF_SIZE,
124 gunzip);
125#endif
126}
127
128int bl2_plat_handle_pre_image_load(unsigned int image_id)
129{
130#ifdef UNIPHIER_DECOMPRESS_GZIP
131 image_decompress_prepare(uniphier_get_image_info(image_id));
132#endif
133 return 0;
134}
135
Masahiro Yamada574388c2016-09-03 11:37:40 +0900136int bl2_plat_handle_post_image_load(unsigned int image_id)
137{
Masahiro Yamada4ff71af2018-01-26 11:42:01 +0900138#ifdef UNIPHIER_DECOMPRESS_GZIP
139 struct image_info *image_info;
140 int ret;
141
142 image_info = uniphier_get_image_info(image_id);
143
144 if (!(image_info->h.attr & IMAGE_ATTRIB_SKIP_LOADING)) {
145 ret = image_decompress(uniphier_get_image_info(image_id));
146 if (ret)
147 return ret;
148 }
149#endif
150
Masahiro Yamada574388c2016-09-03 11:37:40 +0900151 if (image_id == SCP_BL2_IMAGE_ID && uniphier_bl2_kick_scp)
152 uniphier_scp_start();
153
154 return 0;
155}