blob: 05e3d9f0dddb4bd3a8312837ad1983b14b01d103 [file] [log] [blame]
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +02001/*
2 * Copyright (c) 2015-2017, Renesas Electronics Corporation. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +02007#include <string.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +00008
9#include <platform_def.h>
10
11#include <common/debug.h>
12#include <drivers/io/io_driver.h>
13#include <drivers/io/io_storage.h>
14#include <drivers/io/io_semihosting.h>
15
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +020016#include "io_common.h"
17#include "io_rcar.h"
18#include "io_memdrv.h"
19#include "io_emmcdrv.h"
20#include "io_private.h"
21
22static uintptr_t emmcdrv_dev_handle;
23static uintptr_t memdrv_dev_handle;
24static uintptr_t rcar_dev_handle;
25
26static uintptr_t boot_io_drv_id;
27
28static const io_block_spec_t rcar_block_spec = {
29 .offset = FLASH0_BASE,
30 .length = FLASH0_SIZE
31};
32
33static const io_block_spec_t bl2_file_spec = {
34 .offset = BL2_IMAGE_ID,
35};
36
37static const io_block_spec_t bl31_file_spec = {
38 .offset = BL31_IMAGE_ID,
39};
40
41static const io_block_spec_t bl32_file_spec = {
42 .offset = BL32_IMAGE_ID,
43};
44
45static const io_block_spec_t bl33_file_spec = {
46 .offset = BL33_IMAGE_ID,
47};
48
49static const io_block_spec_t bl332_file_spec = {
50 .offset = BL332_IMAGE_ID,
51};
52
53static const io_block_spec_t bl333_file_spec = {
54 .offset = BL333_IMAGE_ID,
55};
56
57static const io_block_spec_t bl334_file_spec = {
58 .offset = BL334_IMAGE_ID,
59};
60
61static const io_block_spec_t bl335_file_spec = {
62 .offset = BL335_IMAGE_ID,
63};
64
65static const io_block_spec_t bl336_file_spec = {
66 .offset = BL336_IMAGE_ID,
67};
68
69static const io_block_spec_t bl337_file_spec = {
70 .offset = BL337_IMAGE_ID,
71};
72
73static const io_block_spec_t bl338_file_spec = {
74 .offset = BL338_IMAGE_ID,
75};
76
77#if TRUSTED_BOARD_BOOT
78static const io_block_spec_t trusted_key_cert_file_spec = {
79 .offset = TRUSTED_KEY_CERT_ID,
80};
81
82static const io_block_spec_t bl31_key_cert_file_spec = {
83 .offset = SOC_FW_KEY_CERT_ID,
84};
85
86static const io_block_spec_t bl32_key_cert_file_spec = {
87 .offset = TRUSTED_OS_FW_KEY_CERT_ID,
88};
89
90static const io_block_spec_t bl33_key_cert_file_spec = {
91 .offset = NON_TRUSTED_FW_KEY_CERT_ID,
92};
93
94static const io_block_spec_t bl332_key_cert_file_spec = {
95 .offset = BL332_KEY_CERT_ID,
96};
97
98static const io_block_spec_t bl333_key_cert_file_spec = {
99 .offset = BL333_KEY_CERT_ID,
100};
101
102static const io_block_spec_t bl334_key_cert_file_spec = {
103 .offset = BL334_KEY_CERT_ID,
104};
105
106static const io_block_spec_t bl335_key_cert_file_spec = {
107 .offset = BL335_KEY_CERT_ID,
108};
109
110static const io_block_spec_t bl336_key_cert_file_spec = {
111 .offset = BL336_KEY_CERT_ID,
112};
113
114static const io_block_spec_t bl337_key_cert_file_spec = {
115 .offset = BL337_KEY_CERT_ID,
116};
117
118static const io_block_spec_t bl338_key_cert_file_spec = {
119 .offset = BL338_KEY_CERT_ID,
120};
121
122static const io_block_spec_t bl31_cert_file_spec = {
123 .offset = SOC_FW_CONTENT_CERT_ID,
124};
125
126static const io_block_spec_t bl32_cert_file_spec = {
127 .offset = TRUSTED_OS_FW_CONTENT_CERT_ID,
128};
129
130static const io_block_spec_t bl33_cert_file_spec = {
131 .offset = NON_TRUSTED_FW_CONTENT_CERT_ID,
132};
133
134static const io_block_spec_t bl332_cert_file_spec = {
135 .offset = BL332_CERT_ID,
136};
137
138static const io_block_spec_t bl333_cert_file_spec = {
139 .offset = BL333_CERT_ID,
140};
141
142static const io_block_spec_t bl334_cert_file_spec = {
143 .offset = BL334_CERT_ID,
144};
145
146static const io_block_spec_t bl335_cert_file_spec = {
147 .offset = BL335_CERT_ID,
148};
149
150static const io_block_spec_t bl336_cert_file_spec = {
151 .offset = BL336_CERT_ID,
152};
153
154static const io_block_spec_t bl337_cert_file_spec = {
155 .offset = BL337_CERT_ID,
156};
157
158static const io_block_spec_t bl338_cert_file_spec = {
159 .offset = BL338_CERT_ID,
160};
161#endif
162
163static int32_t open_emmcdrv(const uintptr_t spec);
164static int32_t open_memmap(const uintptr_t spec);
165static int32_t open_rcar(const uintptr_t spec);
166
167struct plat_io_policy {
168 uintptr_t *dev_handle;
169 uintptr_t image_spec;
170 int32_t(*check) (const uintptr_t spec);
171};
172
173static const struct plat_io_policy policies[] = {
174 [FIP_IMAGE_ID] = {
175 &memdrv_dev_handle,
176 (uintptr_t) &rcar_block_spec,
177 &open_memmap},
178 [BL2_IMAGE_ID] = {
179 &rcar_dev_handle,
180 (uintptr_t) &bl2_file_spec,
181 &open_rcar},
182 [BL31_IMAGE_ID] = {
183 &rcar_dev_handle,
184 (uintptr_t) &bl31_file_spec,
185 &open_rcar},
186 [BL32_IMAGE_ID] = {
187 &rcar_dev_handle,
188 (uintptr_t) &bl32_file_spec,
189 &open_rcar},
190 [BL33_IMAGE_ID] = {
191 &rcar_dev_handle,
192 (uintptr_t) &bl33_file_spec,
193 &open_rcar},
194 [BL332_IMAGE_ID] = {
195 &rcar_dev_handle,
196 (uintptr_t) &bl332_file_spec,
197 &open_rcar},
198 [BL333_IMAGE_ID] = {
199 &rcar_dev_handle,
200 (uintptr_t) &bl333_file_spec,
201 &open_rcar},
202 [BL334_IMAGE_ID] = {
203 &rcar_dev_handle,
204 (uintptr_t) &bl334_file_spec,
205 &open_rcar},
206 [BL335_IMAGE_ID] = {
207 &rcar_dev_handle,
208 (uintptr_t) &bl335_file_spec,
209 &open_rcar},
210 [BL336_IMAGE_ID] = {
211 &rcar_dev_handle,
212 (uintptr_t) &bl336_file_spec,
213 &open_rcar},
214 [BL337_IMAGE_ID] = {
215 &rcar_dev_handle,
216 (uintptr_t) &bl337_file_spec,
217 &open_rcar},
218 [BL338_IMAGE_ID] = {
219 &rcar_dev_handle,
220 (uintptr_t) &bl338_file_spec,
221 &open_rcar},
222#if TRUSTED_BOARD_BOOT
223 [TRUSTED_KEY_CERT_ID] = {
224 &rcar_dev_handle,
225 (uintptr_t) &trusted_key_cert_file_spec,
226 &open_rcar},
227 [SOC_FW_KEY_CERT_ID] = {
228 &rcar_dev_handle,
229 (uintptr_t) &bl31_key_cert_file_spec,
230 &open_rcar},
231 [TRUSTED_OS_FW_KEY_CERT_ID] = {
232 &rcar_dev_handle,
233 (uintptr_t) &bl32_key_cert_file_spec,
234 &open_rcar},
235 [NON_TRUSTED_FW_KEY_CERT_ID] = {
236 &rcar_dev_handle,
237 (uintptr_t) &bl33_key_cert_file_spec,
238 &open_rcar},
239 [BL332_KEY_CERT_ID] = {
240 &rcar_dev_handle,
241 (uintptr_t) &bl332_key_cert_file_spec,
242 &open_rcar},
243 [BL333_KEY_CERT_ID] = {
244 &rcar_dev_handle,
245 (uintptr_t) &bl333_key_cert_file_spec,
246 &open_rcar},
247 [BL334_KEY_CERT_ID] = {
248 &rcar_dev_handle,
249 (uintptr_t) &bl334_key_cert_file_spec,
250 &open_rcar},
251 [BL335_KEY_CERT_ID] = {
252 &rcar_dev_handle,
253 (uintptr_t) &bl335_key_cert_file_spec,
254 &open_rcar},
255 [BL336_KEY_CERT_ID] = {
256 &rcar_dev_handle,
257 (uintptr_t) &bl336_key_cert_file_spec,
258 &open_rcar},
259 [BL337_KEY_CERT_ID] = {
260 &rcar_dev_handle,
261 (uintptr_t) &bl337_key_cert_file_spec,
262 &open_rcar},
263 [BL338_KEY_CERT_ID] = {
264 &rcar_dev_handle,
265 (uintptr_t) &bl338_key_cert_file_spec,
266 &open_rcar},
267 [SOC_FW_CONTENT_CERT_ID] = {
268 &rcar_dev_handle,
269 (uintptr_t) &bl31_cert_file_spec,
270 &open_rcar},
271 [TRUSTED_OS_FW_CONTENT_CERT_ID] = {
272 &rcar_dev_handle,
273 (uintptr_t) &bl32_cert_file_spec,
274 &open_rcar},
275 [NON_TRUSTED_FW_CONTENT_CERT_ID] = {
276 &rcar_dev_handle,
277 (uintptr_t) &bl33_cert_file_spec,
278 &open_rcar},
279 [BL332_CERT_ID] = {
280 &rcar_dev_handle,
281 (uintptr_t) &bl332_cert_file_spec,
282 &open_rcar},
283 [BL333_CERT_ID] = {
284 &rcar_dev_handle,
285 (uintptr_t) &bl333_cert_file_spec,
286 &open_rcar},
287 [BL334_CERT_ID] = {
288 &rcar_dev_handle,
289 (uintptr_t) &bl334_cert_file_spec,
290 &open_rcar},
291 [BL335_CERT_ID] = {
292 &rcar_dev_handle,
293 (uintptr_t) &bl335_cert_file_spec,
294 &open_rcar},
295 [BL336_CERT_ID] = {
296 &rcar_dev_handle,
297 (uintptr_t) &bl336_cert_file_spec,
298 &open_rcar},
299 [BL337_CERT_ID] = {
300 &rcar_dev_handle,
301 (uintptr_t) &bl337_cert_file_spec,
302 &open_rcar},
303 [BL338_CERT_ID] = {
304 &rcar_dev_handle,
305 (uintptr_t) &bl338_cert_file_spec,
306 &open_rcar}, {
307#else
308 {
309#endif
310 0, 0, 0}
311};
312
313static io_drv_spec_t io_drv_spec_memdrv = {
314 FLASH0_BASE,
315 FLASH0_SIZE,
316 0,
317};
318
319static io_drv_spec_t io_drv_spec_emmcdrv = {
320 0,
321 0,
322 0,
323};
324
325static struct plat_io_policy drv_policies[]
326 __attribute__ ((section(".data"))) = {
327 /* FLASH_DEV_ID */
328 {
329 &memdrv_dev_handle,
330 (uintptr_t) &io_drv_spec_memdrv, &open_memmap,},
331 /* EMMC_DEV_ID */
332 {
333 &emmcdrv_dev_handle,
334 (uintptr_t) &io_drv_spec_emmcdrv, &open_emmcdrv,}
335};
336
337static int32_t open_rcar(const uintptr_t spec)
338{
339 return io_dev_init(rcar_dev_handle, boot_io_drv_id);
340}
341
342static int32_t open_memmap(const uintptr_t spec)
343{
344 uintptr_t handle;
345 int32_t result;
346
347 result = io_dev_init(memdrv_dev_handle, 0);
348 if (result != IO_SUCCESS)
349 return result;
350
351 result = io_open(memdrv_dev_handle, spec, &handle);
352 if (result == IO_SUCCESS)
353 io_close(handle);
354
355 return result;
356}
357
358static int32_t open_emmcdrv(const uintptr_t spec)
359{
360 return io_dev_init(emmcdrv_dev_handle, 0);
361}
362
363void rcar_io_setup(void)
364{
365 const io_dev_connector_t *memmap;
366 const io_dev_connector_t *rcar;
367
368 boot_io_drv_id = FLASH_DEV_ID;
369
370 rcar_register_io_dev(&rcar);
371 rcar_register_io_dev_memdrv(&memmap);
372 io_dev_open(rcar, 0, &rcar_dev_handle);
373 io_dev_open(memmap, 0, &memdrv_dev_handle);
374}
375
376void rcar_io_emmc_setup(void)
377{
378 const io_dev_connector_t *rcar;
379 const io_dev_connector_t *emmc;
380
381 boot_io_drv_id = EMMC_DEV_ID;
382
383 rcar_register_io_dev(&rcar);
384 rcar_register_io_dev_emmcdrv(&emmc);
385 io_dev_open(rcar, 0, &rcar_dev_handle);
386 io_dev_open(emmc, 0, &emmcdrv_dev_handle);
387}
388
389int plat_get_image_source(unsigned int image_id, uintptr_t *dev_handle,
390 uintptr_t *image_spec)
391{
392 const struct plat_io_policy *policy;
393 int result;
394
395 policy = &policies[image_id];
396
397 result = policy->check(policy->image_spec);
398 if (result != IO_SUCCESS)
399 return result;
400
401 *image_spec = policy->image_spec;
402 *dev_handle = *(policy->dev_handle);
403
404 return IO_SUCCESS;
405}
406
407int32_t plat_get_drv_source(uint32_t io_drv_id, uintptr_t *dev_handle,
408 uintptr_t *image_spec)
409{
410 const struct plat_io_policy *policy;
411 int32_t result;
412
413 policy = &drv_policies[io_drv_id];
414
415 result = policy->check(policy->image_spec);
416 if (result != IO_SUCCESS)
417 return result;
418
419 *image_spec = policy->image_spec;
420 *dev_handle = *(policy->dev_handle);
421
422 return IO_SUCCESS;
423}