blob: b456bc538b90cacccca4e4fa49d456a338f2bdcd [file] [log] [blame]
Masahiro Yamada574388c2016-09-03 11:37:40 +09001/*
Masahiro Yamada501b88b2019-07-26 20:04:28 +09002 * Copyright (c) 2017-2019, 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 <assert.h>
8#include <errno.h>
Antonio Nino Diaz4b32e622018-08-16 16:52:57 +01009#include <stdint.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000010
11#include <platform_def.h>
12
13#include <drivers/io/io_block.h>
14#include <drivers/io/io_driver.h>
15#include <drivers/io/io_fip.h>
16#include <drivers/io/io_memmap.h>
17#include <lib/utils_def.h>
18#include <lib/xlat_tables/xlat_tables_v2.h>
19#include <tools_share/firmware_image_package.h>
Masahiro Yamada574388c2016-09-03 11:37:40 +090020
21#include "uniphier.h"
22
Masahiro Yamadadb72b0c2018-02-02 15:55:13 +090023#define UNIPHIER_ROM_REGION_BASE 0x00000000ULL
24#define UNIPHIER_ROM_REGION_SIZE 0x10000000ULL
Masahiro Yamada574388c2016-09-03 11:37:40 +090025
Masahiro Yamadadb72b0c2018-02-02 15:55:13 +090026#define UNIPHIER_OCM_REGION_BASE 0x30000000ULL
27#define UNIPHIER_OCM_REGION_SIZE 0x00040000ULL
Masahiro Yamada8f642922018-01-30 19:30:39 +090028
Masahiro Yamada574388c2016-09-03 11:37:40 +090029static const io_dev_connector_t *uniphier_fip_dev_con;
30static uintptr_t uniphier_fip_dev_handle;
31
32static const io_dev_connector_t *uniphier_backend_dev_con;
33static uintptr_t uniphier_backend_dev_handle;
34
35static io_block_spec_t uniphier_fip_spec = {
36 /* .offset will be set by the io_setup func */
37 .length = 0x00200000,
38};
39
40static const io_uuid_spec_t uniphier_bl2_spec = {
41 .uuid = UUID_TRUSTED_BOOT_FIRMWARE_BL2,
42};
43
44static const io_uuid_spec_t uniphier_scp_spec = {
45 .uuid = UUID_SCP_FIRMWARE_SCP_BL2,
46};
47
48static const io_uuid_spec_t uniphier_bl31_spec = {
49 .uuid = UUID_EL3_RUNTIME_FIRMWARE_BL31,
50};
51
52static const io_uuid_spec_t uniphier_bl32_spec = {
53 .uuid = UUID_SECURE_PAYLOAD_BL32,
54};
55
56static const io_uuid_spec_t uniphier_bl33_spec = {
57 .uuid = UUID_NON_TRUSTED_FIRMWARE_BL33,
58};
59
60#if TRUSTED_BOARD_BOOT
61static const io_uuid_spec_t uniphier_tb_fw_cert_spec = {
62 .uuid = UUID_TRUSTED_BOOT_FW_CERT,
63};
64
65static const io_uuid_spec_t uniphier_trusted_key_cert_spec = {
66 .uuid = UUID_TRUSTED_KEY_CERT,
67};
68
69static const io_uuid_spec_t uniphier_scp_fw_key_cert_spec = {
70 .uuid = UUID_SCP_FW_KEY_CERT,
71};
72
73static const io_uuid_spec_t uniphier_soc_fw_key_cert_spec = {
74 .uuid = UUID_SOC_FW_KEY_CERT,
75};
76
77static const io_uuid_spec_t uniphier_tos_fw_key_cert_spec = {
78 .uuid = UUID_TRUSTED_OS_FW_KEY_CERT,
79};
80
81static const io_uuid_spec_t uniphier_nt_fw_key_cert_spec = {
82 .uuid = UUID_NON_TRUSTED_FW_KEY_CERT,
83};
84
85static const io_uuid_spec_t uniphier_scp_fw_cert_spec = {
86 .uuid = UUID_SCP_FW_CONTENT_CERT,
87};
88
89static const io_uuid_spec_t uniphier_soc_fw_cert_spec = {
90 .uuid = UUID_SOC_FW_CONTENT_CERT,
91};
92
93static const io_uuid_spec_t uniphier_tos_fw_cert_spec = {
94 .uuid = UUID_TRUSTED_OS_FW_CONTENT_CERT,
95};
96
97static const io_uuid_spec_t uniphier_nt_fw_cert_spec = {
98 .uuid = UUID_NON_TRUSTED_FW_CONTENT_CERT,
99};
100#endif /* TRUSTED_BOARD_BOOT */
101
102struct uniphier_io_policy {
103 uintptr_t *dev_handle;
104 uintptr_t image_spec;
105 uintptr_t init_params;
106};
107
108static const struct uniphier_io_policy uniphier_io_policies[] = {
109 [FIP_IMAGE_ID] = {
110 .dev_handle = &uniphier_backend_dev_handle,
111 .image_spec = (uintptr_t)&uniphier_fip_spec,
112 },
113 [BL2_IMAGE_ID] = {
114 .dev_handle = &uniphier_fip_dev_handle,
115 .image_spec = (uintptr_t)&uniphier_bl2_spec,
116 .init_params = FIP_IMAGE_ID,
117 },
118 [SCP_BL2_IMAGE_ID] = {
119 .dev_handle = &uniphier_fip_dev_handle,
120 .image_spec = (uintptr_t)&uniphier_scp_spec,
121 .init_params = FIP_IMAGE_ID,
122 },
123 [BL31_IMAGE_ID] = {
124 .dev_handle = &uniphier_fip_dev_handle,
125 .image_spec = (uintptr_t)&uniphier_bl31_spec,
126 .init_params = FIP_IMAGE_ID,
127 },
128 [BL32_IMAGE_ID] = {
129 .dev_handle = &uniphier_fip_dev_handle,
130 .image_spec = (uintptr_t)&uniphier_bl32_spec,
131 .init_params = FIP_IMAGE_ID,
132 },
133 [BL33_IMAGE_ID] = {
134 .dev_handle = &uniphier_fip_dev_handle,
135 .image_spec = (uintptr_t)&uniphier_bl33_spec,
136 .init_params = FIP_IMAGE_ID,
137 },
138#if TRUSTED_BOARD_BOOT
139 [TRUSTED_BOOT_FW_CERT_ID] = {
140 .dev_handle = &uniphier_fip_dev_handle,
141 .image_spec = (uintptr_t)&uniphier_tb_fw_cert_spec,
142 .init_params = FIP_IMAGE_ID,
143 },
144 [TRUSTED_KEY_CERT_ID] = {
145 .dev_handle = &uniphier_fip_dev_handle,
146 .image_spec = (uintptr_t)&uniphier_trusted_key_cert_spec,
147 .init_params = FIP_IMAGE_ID,
148 },
149 [SCP_FW_KEY_CERT_ID] = {
150 .dev_handle = &uniphier_fip_dev_handle,
151 .image_spec = (uintptr_t)&uniphier_scp_fw_key_cert_spec,
152 .init_params = FIP_IMAGE_ID,
153 },
154 [SOC_FW_KEY_CERT_ID] = {
155 .dev_handle = &uniphier_fip_dev_handle,
156 .image_spec = (uintptr_t)&uniphier_soc_fw_key_cert_spec,
157 .init_params = FIP_IMAGE_ID,
158 },
159 [TRUSTED_OS_FW_KEY_CERT_ID] = {
160 .dev_handle = &uniphier_fip_dev_handle,
161 .image_spec = (uintptr_t)&uniphier_tos_fw_key_cert_spec,
162 .init_params = FIP_IMAGE_ID,
163 },
164 [NON_TRUSTED_FW_KEY_CERT_ID] = {
165 .dev_handle = &uniphier_fip_dev_handle,
166 .image_spec = (uintptr_t)&uniphier_nt_fw_key_cert_spec,
167 .init_params = FIP_IMAGE_ID,
168 },
169 [SCP_FW_CONTENT_CERT_ID] = {
170 .dev_handle = &uniphier_fip_dev_handle,
171 .image_spec = (uintptr_t)&uniphier_scp_fw_cert_spec,
172 .init_params = FIP_IMAGE_ID,
173 },
174 [SOC_FW_CONTENT_CERT_ID] = {
175 .dev_handle = &uniphier_fip_dev_handle,
176 .image_spec = (uintptr_t)&uniphier_soc_fw_cert_spec,
177 .init_params = FIP_IMAGE_ID,
178 },
179 [TRUSTED_OS_FW_CONTENT_CERT_ID] = {
180 .dev_handle = &uniphier_fip_dev_handle,
181 .image_spec = (uintptr_t)&uniphier_tos_fw_cert_spec,
182 .init_params = FIP_IMAGE_ID,
183 },
184 [NON_TRUSTED_FW_CONTENT_CERT_ID] = {
185 .dev_handle = &uniphier_fip_dev_handle,
186 .image_spec = (uintptr_t)&uniphier_nt_fw_cert_spec,
187 .init_params = FIP_IMAGE_ID,
188 },
189#endif
190};
191
192static int uniphier_io_block_setup(size_t fip_offset, uintptr_t block_dev_spec)
193{
194 int ret;
195
196 uniphier_fip_spec.offset = fip_offset;
197
198 ret = register_io_dev_block(&uniphier_backend_dev_con);
199 if (ret)
200 return ret;
201
202 return io_dev_open(uniphier_backend_dev_con, block_dev_spec,
203 &uniphier_backend_dev_handle);
204}
205
206static int uniphier_io_memmap_setup(size_t fip_offset)
207{
208 int ret;
209
210 uniphier_fip_spec.offset = fip_offset;
211
212 ret = mmap_add_dynamic_region(fip_offset, fip_offset,
213 uniphier_fip_spec.length,
214 MT_RO_DATA | MT_SECURE);
215 if (ret)
216 return ret;
217
218 ret = register_io_dev_memmap(&uniphier_backend_dev_con);
219 if (ret)
220 return ret;
221
222 return io_dev_open(uniphier_backend_dev_con, 0,
223 &uniphier_backend_dev_handle);
224}
225
226static int uniphier_io_fip_setup(void)
227{
228 int ret;
229
230 ret = register_io_dev_fip(&uniphier_fip_dev_con);
231 if (ret)
232 return ret;
233
234 return io_dev_open(uniphier_fip_dev_con, 0, &uniphier_fip_dev_handle);
235}
236
237static int uniphier_io_emmc_setup(unsigned int soc_id)
238{
239 uintptr_t block_dev_spec;
240 int ret;
241
242 ret = uniphier_emmc_init(&block_dev_spec);
243 if (ret)
244 return ret;
245
246 return uniphier_io_block_setup(0x20000, block_dev_spec);
247}
248
249static int uniphier_io_nand_setup(unsigned int soc_id)
250{
251 uintptr_t block_dev_spec;
252 int ret;
253
254 ret = uniphier_nand_init(&block_dev_spec);
255 if (ret)
256 return ret;
257
258 return uniphier_io_block_setup(0x20000, block_dev_spec);
259}
260
261static int uniphier_io_nor_setup(unsigned int soc_id)
262{
263 return uniphier_io_memmap_setup(0x70000);
264}
265
266static int uniphier_io_usb_setup(unsigned int soc_id)
267{
268 uintptr_t block_dev_spec;
269 int ret;
270
271 /* use ROM API for loading images from USB storage */
272 ret = mmap_add_dynamic_region(UNIPHIER_ROM_REGION_BASE,
273 UNIPHIER_ROM_REGION_BASE,
274 UNIPHIER_ROM_REGION_SIZE,
275 MT_CODE | MT_SECURE);
276 if (ret)
277 return ret;
278
Masahiro Yamada8f642922018-01-30 19:30:39 +0900279 /*
280 * on-chip SRAM region: should be DEVICE attribute because the USB
281 * load functions provided by the ROM use this memory region as a work
282 * area, but do not cater to cache coherency.
283 */
284 ret = mmap_add_dynamic_region(UNIPHIER_OCM_REGION_BASE,
285 UNIPHIER_OCM_REGION_BASE,
286 UNIPHIER_OCM_REGION_SIZE,
287 MT_DEVICE | MT_RW | MT_SECURE);
288 if (ret)
289 return ret;
290
Masahiro Yamada574388c2016-09-03 11:37:40 +0900291 ret = uniphier_usb_init(soc_id, &block_dev_spec);
292 if (ret)
293 return ret;
294
295 return uniphier_io_block_setup(0x20000, block_dev_spec);
296}
297
298static int (* const uniphier_io_setup_table[])(unsigned int) = {
299 [UNIPHIER_BOOT_DEVICE_EMMC] = uniphier_io_emmc_setup,
300 [UNIPHIER_BOOT_DEVICE_NAND] = uniphier_io_nand_setup,
301 [UNIPHIER_BOOT_DEVICE_NOR] = uniphier_io_nor_setup,
302 [UNIPHIER_BOOT_DEVICE_USB] = uniphier_io_usb_setup,
303};
304
305int uniphier_io_setup(unsigned int soc_id)
306{
307 int (*io_setup)(unsigned int soc_id);
308 unsigned int boot_dev;
309 int ret;
310
311 boot_dev = uniphier_get_boot_device(soc_id);
312 if (boot_dev == UNIPHIER_BOOT_DEVICE_RSV)
313 return -EINVAL;
314
315 io_setup = uniphier_io_setup_table[boot_dev];
316 ret = io_setup(soc_id);
317 if (ret)
318 return ret;
319
320 ret = uniphier_io_fip_setup();
321 if (ret)
322 return ret;
323
324 return 0;
325}
326
327int plat_get_image_source(unsigned int image_id, uintptr_t *dev_handle,
328 uintptr_t *image_spec)
329{
330 uintptr_t init_params;
331
332 assert(image_id < ARRAY_SIZE(uniphier_io_policies));
333
Masahiro Yamada501b88b2019-07-26 20:04:28 +0900334 *dev_handle = *uniphier_io_policies[image_id].dev_handle;
Masahiro Yamada574388c2016-09-03 11:37:40 +0900335 *image_spec = uniphier_io_policies[image_id].image_spec;
336 init_params = uniphier_io_policies[image_id].init_params;
337
338 return io_dev_init(*dev_handle, init_params);
339}