uniphier_bl2_setup.c 3.7 KB
Newer Older
1
/*
2
 * Copyright (c) 2017-2020, ARM Limited and Contributors. All rights reserved.
3
4
5
6
7
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */

#include <errno.h>
8

9
#include <platform_def.h>
10
11
12
13
14
15
16
17

#include <common/bl_common.h>
#include <common/debug.h>
#include <common/desc_image_load.h>
#include <common/image_decompress.h>
#include <drivers/io/io_storage.h>
#include <lib/xlat_tables/xlat_tables_v2.h>
#include <plat/common/platform.h>
18
19
20
#ifdef UNIPHIER_DECOMPRESS_GZIP
#include <tf_gunzip.h>
#endif
21
22
23

#include "uniphier.h"

24
#define UNIPHIER_IMAGE_BUF_OFFSET	0x04300000UL
25
26
#define UNIPHIER_IMAGE_BUF_SIZE		0x00100000UL

27
static uintptr_t uniphier_mem_base = UNIPHIER_MEM_BASE;
28
29
static int uniphier_bl2_kick_scp;

30
31
void bl2_el3_early_platform_setup(u_register_t x0, u_register_t x1,
				  u_register_t x2, u_register_t x3)
32
33
34
35
{
	uniphier_console_setup();
}

36
void bl2_el3_plat_arch_setup(void)
37
38
39
40
41
{
	unsigned int soc;
	int skip_scp = 0;
	int ret;

42
	uniphier_mmap_setup();
43
	enable_mmu_el3(0);
44

45
46
47
	/* add relocation offset (run-time-address - link-address) */
	uniphier_mem_base += BL_CODE_BASE - BL2_BASE;

48
49
50
51
52
53
	soc = uniphier_get_soc_id();
	if (soc == UNIPHIER_SOC_UNKNOWN) {
		ERROR("unsupported SoC\n");
		plat_error_handler(-ENOTSUP);
	}

54
	ret = uniphier_io_setup(soc, uniphier_mem_base);
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
	if (ret) {
		ERROR("failed to setup io devices\n");
		plat_error_handler(ret);
	}

	switch (uniphier_get_boot_master(soc)) {
	case UNIPHIER_BOOT_MASTER_THIS:
		INFO("Booting from this SoC\n");
		skip_scp = 1;
		break;
	case UNIPHIER_BOOT_MASTER_SCP:
		INFO("Booting from on-chip SCP\n");
		if (uniphier_scp_is_running()) {
			INFO("SCP is already running. SCP_BL2 load will be skipped.\n");
			skip_scp = 1;
		}

		/*
		 * SCP must be kicked every time even if it is already running
		 * because it polls this event after the reboot of the backend.
		 */
		uniphier_bl2_kick_scp = 1;
		break;
	case UNIPHIER_BOOT_MASTER_EXT:
		INFO("Booting from external SCP\n");
		skip_scp = 1;
		break;
	default:
		plat_error_handler(-ENOTSUP);
84
		break;
85
86
	}

87
88
89
90
91
92
	if (skip_scp) {
		struct image_info *image_info;

		image_info = uniphier_get_image_info(SCP_BL2_IMAGE_ID);
		image_info->h.attr |= IMAGE_ATTRIB_SKIP_LOADING;
	}
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
}

void bl2_platform_setup(void)
{
}

void plat_flush_next_bl_params(void)
{
	flush_bl_params_desc();
}

bl_load_info_t *plat_get_bl_image_load_info(void)
{
	return get_bl_load_info_from_mem_params_desc();
}

bl_params_t *plat_get_next_bl_params(void)
{
	return get_next_bl_params_from_mem_params_desc();
}

114
115
116
void bl2_plat_preload_setup(void)
{
#ifdef UNIPHIER_DECOMPRESS_GZIP
117
	uintptr_t buf_base = uniphier_mem_base + UNIPHIER_IMAGE_BUF_OFFSET;
118
119
	int ret;

120
	ret = mmap_add_dynamic_region(buf_base, buf_base,
121
122
123
124
125
				      UNIPHIER_IMAGE_BUF_SIZE,
				      MT_MEMORY | MT_RW | MT_NS);
	if (ret)
		plat_error_handler(ret);

126
	image_decompress_init(buf_base, UNIPHIER_IMAGE_BUF_SIZE, gunzip);
127
#endif
128
129

	uniphier_init_image_descs(uniphier_mem_base);
130
131
132
133
}

int bl2_plat_handle_pre_image_load(unsigned int image_id)
{
134
135
136
137
138
139
140
141
142
143
144
145
	struct image_info *image_info;
	int ret;

	image_info = uniphier_get_image_info(image_id);

	ret = mmap_add_dynamic_region(image_info->image_base,
				      image_info->image_base,
				      image_info->image_max_size,
				      MT_MEMORY | MT_RW | MT_NS);
	if (ret)
		return ret;

146
#ifdef UNIPHIER_DECOMPRESS_GZIP
147
	image_decompress_prepare(image_info);
148
149
150
151
#endif
	return 0;
}

152
153
int bl2_plat_handle_post_image_load(unsigned int image_id)
{
154
	struct image_info *image_info = uniphier_get_image_info(image_id);
155
156
157
158
159
160
161
162
163
164
#ifdef UNIPHIER_DECOMPRESS_GZIP
	int ret;

	if (!(image_info->h.attr & IMAGE_ATTRIB_SKIP_LOADING)) {
		ret = image_decompress(uniphier_get_image_info(image_id));
		if (ret)
			return ret;
	}
#endif

165
	if (image_id == SCP_BL2_IMAGE_ID && uniphier_bl2_kick_scp)
166
		uniphier_scp_start(image_info->image_base);
167
168
169

	return 0;
}