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

#include <bl_common.h>
#include <debug.h>
#include <desc_image_load.h>
#include <errno.h>
#include <io/io_storage.h>
12
#include <image_decompress.h>
13
14
#include <platform.h>
#include <platform_def.h>
15
16
17
#ifdef UNIPHIER_DECOMPRESS_GZIP
#include <tf_gunzip.h>
#endif
18
19
20
21
#include <xlat_tables_v2.h>

#include "uniphier.h"

22
23
24
#define BL2_END			(unsigned long)(&__BL2_END__)
#define BL2_SIZE		((BL2_END) - (BL2_BASE))

25
26
static int uniphier_bl2_kick_scp;

27
28
void bl2_el3_early_platform_setup(u_register_t x0, u_register_t x1,
				  u_register_t x2, u_register_t x3)
29
30
31
32
33
{
	uniphier_console_setup();
}

static const struct mmap_region uniphier_bl2_mmap[] = {
34
35
36
	/* for BL31, BL32 */
	MAP_REGION_FLAT(UNIPHIER_SEC_DRAM_BASE, UNIPHIER_SEC_DRAM_SIZE,
			MT_MEMORY | MT_RW | MT_SECURE),
37
38
39
40
41
42
	/* for SCP, BL33 */
	MAP_REGION_FLAT(UNIPHIER_NS_DRAM_BASE, UNIPHIER_NS_DRAM_SIZE,
			MT_MEMORY | MT_RW | MT_NS),
	{ .size = 0 },
};

43
void bl2_el3_plat_arch_setup(void)
44
45
46
47
48
{
	unsigned int soc;
	int skip_scp = 0;
	int ret;

49
	uniphier_mmap_setup(BL2_BASE, BL2_SIZE, uniphier_bl2_mmap);
50
	enable_mmu_el3(0);
51
52
53
54
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
84
85
86
87

	soc = uniphier_get_soc_id();
	if (soc == UNIPHIER_SOC_UNKNOWN) {
		ERROR("unsupported SoC\n");
		plat_error_handler(-ENOTSUP);
	}

	ret = uniphier_io_setup(soc);
	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);
88
		break;
89
90
	}

91
92
93
94
95
96
	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;
	}
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
}

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();
}

118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
void bl2_plat_preload_setup(void)
{
#ifdef UNIPHIER_DECOMPRESS_GZIP
	image_decompress_init(UNIPHIER_IMAGE_BUF_BASE,
			      UNIPHIER_IMAGE_BUF_SIZE,
			      gunzip);
#endif
}

int bl2_plat_handle_pre_image_load(unsigned int image_id)
{
#ifdef UNIPHIER_DECOMPRESS_GZIP
	image_decompress_prepare(uniphier_get_image_info(image_id));
#endif
	return 0;
}

135
136
int bl2_plat_handle_post_image_load(unsigned int image_id)
{
137
138
139
140
141
142
143
144
145
146
147
148
149
#ifdef UNIPHIER_DECOMPRESS_GZIP
	struct image_info *image_info;
	int ret;

	image_info = uniphier_get_image_info(image_id);

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

150
151
152
153
154
	if (image_id == SCP_BL2_IMAGE_ID && uniphier_bl2_kick_scp)
		uniphier_scp_start();

	return 0;
}