blob: 7109d21fefbeb5128330474b094decb6cb00c2ff [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_END (unsigned long)(&__BL2_END__)
25#define BL2_SIZE ((BL2_END) - (BL2_BASE))
26
Masahiro Yamada574388c2016-09-03 11:37:40 +090027static int uniphier_bl2_kick_scp;
28
Masahiro Yamada75bfecb2017-12-19 11:56:05 +090029void bl2_el3_early_platform_setup(u_register_t x0, u_register_t x1,
30 u_register_t x2, u_register_t x3)
Masahiro Yamada574388c2016-09-03 11:37:40 +090031{
Masahiro Yamada574388c2016-09-03 11:37:40 +090032 uniphier_console_setup();
33}
34
35static const struct mmap_region uniphier_bl2_mmap[] = {
Masahiro Yamadacad2ab52018-01-30 18:49:37 +090036 /* for BL31, BL32 */
37 MAP_REGION_FLAT(UNIPHIER_SEC_DRAM_BASE, UNIPHIER_SEC_DRAM_SIZE,
38 MT_MEMORY | MT_RW | MT_SECURE),
Masahiro Yamada574388c2016-09-03 11:37:40 +090039 /* 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
Masahiro Yamada75bfecb2017-12-19 11:56:05 +090045void bl2_el3_plat_arch_setup(void)
Masahiro Yamada574388c2016-09-03 11:37:40 +090046{
47 unsigned int soc;
48 int skip_scp = 0;
49 int ret;
50
Masahiro Yamadacad2ab52018-01-30 18:49:37 +090051 uniphier_mmap_setup(BL2_BASE, BL2_SIZE, uniphier_bl2_mmap);
Masahiro Yamada75bfecb2017-12-19 11:56:05 +090052 enable_mmu_el3(0);
Masahiro Yamada574388c2016-09-03 11:37:40 +090053
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);
Jonathan Wrightff957ed2018-03-14 15:24:00 +000090 break;
Masahiro Yamada574388c2016-09-03 11:37:40 +090091 }
92
Masahiro Yamada4c91c802018-02-01 21:37:40 +090093 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 }
Masahiro Yamada574388c2016-09-03 11:37:40 +090099}
100
101void bl2_platform_setup(void)
102{
103}
104
105void plat_flush_next_bl_params(void)
106{
107 flush_bl_params_desc();
108}
109
110bl_load_info_t *plat_get_bl_image_load_info(void)
111{
112 return get_bl_load_info_from_mem_params_desc();
113}
114
115bl_params_t *plat_get_next_bl_params(void)
116{
117 return get_next_bl_params_from_mem_params_desc();
118}
119
Masahiro Yamada4ff71af2018-01-26 11:42:01 +0900120void 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
129int 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
Masahiro Yamada574388c2016-09-03 11:37:40 +0900137int bl2_plat_handle_post_image_load(unsigned int image_id)
138{
Masahiro Yamada4ff71af2018-01-26 11:42:01 +0900139#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
Masahiro Yamada574388c2016-09-03 11:37:40 +0900152 if (image_id == SCP_BL2_IMAGE_ID && uniphier_bl2_kick_scp)
153 uniphier_scp_start();
154
155 return 0;
156}