blob: e72b6001d20501b64631fb67758f4af04d7aa717 [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
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>
12#include <platform.h>
13#include <platform_def.h>
14#include <xlat_tables_v2.h>
15
16#include "uniphier.h"
17
Masahiro Yamada574388c2016-09-03 11:37:40 +090018static int uniphier_bl2_kick_scp;
19
Masahiro Yamada75bfecb2017-12-19 11:56:05 +090020void bl2_el3_early_platform_setup(u_register_t x0, u_register_t x1,
21 u_register_t x2, u_register_t x3)
Masahiro Yamada574388c2016-09-03 11:37:40 +090022{
Masahiro Yamada574388c2016-09-03 11:37:40 +090023 uniphier_console_setup();
24}
25
26static const struct mmap_region uniphier_bl2_mmap[] = {
27 /* for SCP, BL33 */
28 MAP_REGION_FLAT(UNIPHIER_NS_DRAM_BASE, UNIPHIER_NS_DRAM_SIZE,
29 MT_MEMORY | MT_RW | MT_NS),
30 { .size = 0 },
31};
32
Masahiro Yamada75bfecb2017-12-19 11:56:05 +090033void bl2_el3_plat_arch_setup(void)
Masahiro Yamada574388c2016-09-03 11:37:40 +090034{
35 unsigned int soc;
36 int skip_scp = 0;
37 int ret;
38
39 uniphier_mmap_setup(UNIPHIER_SEC_DRAM_BASE, UNIPHIER_SEC_DRAM_SIZE,
40 uniphier_bl2_mmap);
Masahiro Yamada75bfecb2017-12-19 11:56:05 +090041 enable_mmu_el3(0);
Masahiro Yamada574388c2016-09-03 11:37:40 +090042
43 soc = uniphier_get_soc_id();
44 if (soc == UNIPHIER_SOC_UNKNOWN) {
45 ERROR("unsupported SoC\n");
46 plat_error_handler(-ENOTSUP);
47 }
48
49 ret = uniphier_io_setup(soc);
50 if (ret) {
51 ERROR("failed to setup io devices\n");
52 plat_error_handler(ret);
53 }
54
55 switch (uniphier_get_boot_master(soc)) {
56 case UNIPHIER_BOOT_MASTER_THIS:
57 INFO("Booting from this SoC\n");
58 skip_scp = 1;
59 break;
60 case UNIPHIER_BOOT_MASTER_SCP:
61 INFO("Booting from on-chip SCP\n");
62 if (uniphier_scp_is_running()) {
63 INFO("SCP is already running. SCP_BL2 load will be skipped.\n");
64 skip_scp = 1;
65 }
66
67 /*
68 * SCP must be kicked every time even if it is already running
69 * because it polls this event after the reboot of the backend.
70 */
71 uniphier_bl2_kick_scp = 1;
72 break;
73 case UNIPHIER_BOOT_MASTER_EXT:
74 INFO("Booting from external SCP\n");
75 skip_scp = 1;
76 break;
77 default:
78 plat_error_handler(-ENOTSUP);
79 }
80
81 if (!skip_scp) {
82 ret = uniphier_check_image(SCP_BL2_IMAGE_ID);
83 if (ret) {
84 WARN("SCP_BL2 image not found. SCP_BL2 load will be skipped.\n");
85 WARN("You must setup SCP by other means.\n");
86 skip_scp = 1;
87 uniphier_bl2_kick_scp = 0;
88 }
89 }
90
Masahiro Yamada4c91c802018-02-01 21:37:40 +090091 if (skip_scp) {
92 struct image_info *image_info;
93
94 image_info = uniphier_get_image_info(SCP_BL2_IMAGE_ID);
95 image_info->h.attr |= IMAGE_ATTRIB_SKIP_LOADING;
96 }
Masahiro Yamada574388c2016-09-03 11:37:40 +090097}
98
99void bl2_platform_setup(void)
100{
101}
102
103void plat_flush_next_bl_params(void)
104{
105 flush_bl_params_desc();
106}
107
108bl_load_info_t *plat_get_bl_image_load_info(void)
109{
110 return get_bl_load_info_from_mem_params_desc();
111}
112
113bl_params_t *plat_get_next_bl_params(void)
114{
115 return get_next_bl_params_from_mem_params_desc();
116}
117
118int bl2_plat_handle_post_image_load(unsigned int image_id)
119{
120 if (image_id == SCP_BL2_IMAGE_ID && uniphier_bl2_kick_scp)
121 uniphier_scp_start();
122
123 return 0;
124}