blob: b83e70021aea70b78fc66a5917279650f68c99e4 [file] [log] [blame]
Masahiro Yamada574388c2016-09-03 11:37:40 +09001/*
2 * Copyright (c) 2017, ARM Limited and Contributors. All rights reserved.
3 *
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
18static meminfo_t uniphier_bl2_tzram_layout __aligned(CACHE_WRITEBACK_GRANULE);
19static int uniphier_bl2_kick_scp;
20
21void bl2_early_platform_setup(meminfo_t *mem_layout)
22{
23 uniphier_bl2_tzram_layout = *mem_layout;
24
25 uniphier_console_setup();
26}
27
28static const struct mmap_region uniphier_bl2_mmap[] = {
29 /* for SCP, BL33 */
30 MAP_REGION_FLAT(UNIPHIER_NS_DRAM_BASE, UNIPHIER_NS_DRAM_SIZE,
31 MT_MEMORY | MT_RW | MT_NS),
32 { .size = 0 },
33};
34
35void bl2_plat_arch_setup(void)
36{
37 unsigned int soc;
38 int skip_scp = 0;
39 int ret;
40
41 uniphier_mmap_setup(UNIPHIER_SEC_DRAM_BASE, UNIPHIER_SEC_DRAM_SIZE,
42 uniphier_bl2_mmap);
43 enable_mmu_el1(0);
44
45 soc = uniphier_get_soc_id();
46 if (soc == UNIPHIER_SOC_UNKNOWN) {
47 ERROR("unsupported SoC\n");
48 plat_error_handler(-ENOTSUP);
49 }
50
51 ret = uniphier_io_setup(soc);
52 if (ret) {
53 ERROR("failed to setup io devices\n");
54 plat_error_handler(ret);
55 }
56
57 switch (uniphier_get_boot_master(soc)) {
58 case UNIPHIER_BOOT_MASTER_THIS:
59 INFO("Booting from this SoC\n");
60 skip_scp = 1;
61 break;
62 case UNIPHIER_BOOT_MASTER_SCP:
63 INFO("Booting from on-chip SCP\n");
64 if (uniphier_scp_is_running()) {
65 INFO("SCP is already running. SCP_BL2 load will be skipped.\n");
66 skip_scp = 1;
67 }
68
69 /*
70 * SCP must be kicked every time even if it is already running
71 * because it polls this event after the reboot of the backend.
72 */
73 uniphier_bl2_kick_scp = 1;
74 break;
75 case UNIPHIER_BOOT_MASTER_EXT:
76 INFO("Booting from external SCP\n");
77 skip_scp = 1;
78 break;
79 default:
80 plat_error_handler(-ENOTSUP);
81 }
82
83 if (!skip_scp) {
84 ret = uniphier_check_image(SCP_BL2_IMAGE_ID);
85 if (ret) {
86 WARN("SCP_BL2 image not found. SCP_BL2 load will be skipped.\n");
87 WARN("You must setup SCP by other means.\n");
88 skip_scp = 1;
89 uniphier_bl2_kick_scp = 0;
90 }
91 }
92
93 if (skip_scp)
94 uniphier_image_descs_fixup();
95}
96
97void bl2_platform_setup(void)
98{
99}
100
101void plat_flush_next_bl_params(void)
102{
103 flush_bl_params_desc();
104}
105
106bl_load_info_t *plat_get_bl_image_load_info(void)
107{
108 return get_bl_load_info_from_mem_params_desc();
109}
110
111bl_params_t *plat_get_next_bl_params(void)
112{
113 return get_next_bl_params_from_mem_params_desc();
114}
115
116int bl2_plat_handle_post_image_load(unsigned int image_id)
117{
118 if (image_id == SCP_BL2_IMAGE_ID && uniphier_bl2_kick_scp)
119 uniphier_scp_start();
120
121 return 0;
122}