blob: d0bc60576ba3b7dc73dbfbd6841d16ba3c1c06af [file] [log] [blame]
Yann Gautier4353bb22018-07-16 10:54:09 +02001/*
Yann Gautier59a1cdf2019-01-17 14:41:46 +01002 * Copyright (c) 2015-2019, ARM Limited and Contributors. All rights reserved.
Yann Gautier4353bb22018-07-16 10:54:09 +02003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
Yann Gautier4353bb22018-07-16 10:54:09 +02007#include <assert.h>
Yann Gautier4353bb22018-07-16 10:54:09 +02008#include <string.h>
Antonio Nino Diaz09d40e02018-12-14 00:18:21 +00009
10#include <platform_def.h>
11
12#include <arch_helpers.h>
13#include <common/debug.h>
14#include <drivers/io/io_block.h>
15#include <drivers/io/io_driver.h>
16#include <drivers/io/io_dummy.h>
Lionel Debieve12e21df2019-11-04 12:28:15 +010017#include <drivers/io/io_mtd.h>
Antonio Nino Diaz09d40e02018-12-14 00:18:21 +000018#include <drivers/io/io_storage.h>
19#include <drivers/mmc.h>
20#include <drivers/partition/partition.h>
Lionel Debieve12e21df2019-11-04 12:28:15 +010021#include <drivers/raw_nand.h>
Lionel Debieve57044222019-09-24 18:30:12 +020022#include <drivers/spi_nand.h>
Antonio Nino Diaz09d40e02018-12-14 00:18:21 +000023#include <drivers/st/io_mmc.h>
24#include <drivers/st/io_stm32image.h>
Lionel Debieve12e21df2019-11-04 12:28:15 +010025#include <drivers/st/stm32_fmc2_nand.h>
Lionel Debieve57044222019-09-24 18:30:12 +020026#include <drivers/st/stm32_qspi.h>
Antonio Nino Diaz09d40e02018-12-14 00:18:21 +000027#include <drivers/st/stm32_sdmmc2.h>
Antonio Nino Diaz09d40e02018-12-14 00:18:21 +000028#include <lib/mmio.h>
29#include <lib/utils.h>
30#include <plat/common/platform.h>
31
Yann Gautier4353bb22018-07-16 10:54:09 +020032/* IO devices */
33static const io_dev_connector_t *dummy_dev_con;
34static uintptr_t dummy_dev_handle;
35static uintptr_t dummy_dev_spec;
36
Yann Gautieraec7de42018-10-15 09:36:58 +020037static uintptr_t image_dev_handle;
Nicolas Le Bayon46554b62019-09-03 09:52:05 +020038static uintptr_t storage_dev_handle;
Yann Gautieraec7de42018-10-15 09:36:58 +020039
Nicolas Le Bayon46554b62019-09-03 09:52:05 +020040#if STM32MP_SDMMC || STM32MP_EMMC
Yann Gautieraec7de42018-10-15 09:36:58 +020041static io_block_spec_t gpt_block_spec = {
42 .offset = 0,
43 .length = 34 * MMC_BLOCK_SIZE, /* Size of GPT table */
44};
45
Yann Gautier3e6fab42018-11-09 15:57:18 +010046static uint32_t block_buffer[MMC_BLOCK_SIZE] __aligned(MMC_BLOCK_SIZE);
Yann Gautieraec7de42018-10-15 09:36:58 +020047
48static const io_block_dev_spec_t mmc_block_dev_spec = {
49 /* It's used as temp buffer in block driver */
50 .buffer = {
51 .offset = (size_t)&block_buffer,
52 .length = MMC_BLOCK_SIZE,
53 },
54 .ops = {
55 .read = mmc_read_blocks,
56 .write = NULL,
57 },
58 .block_size = MMC_BLOCK_SIZE,
59};
60
Yann Gautieraec7de42018-10-15 09:36:58 +020061static const io_dev_connector_t *mmc_dev_con;
Nicolas Le Bayon46554b62019-09-03 09:52:05 +020062#endif /* STM32MP_SDMMC || STM32MP_EMMC */
Yann Gautieraec7de42018-10-15 09:36:58 +020063
Lionel Debieve12e21df2019-11-04 12:28:15 +010064#if STM32MP_RAW_NAND
65static io_mtd_dev_spec_t nand_dev_spec = {
66 .ops = {
67 .init = nand_raw_init,
68 .read = nand_read,
69 },
70};
71
72static const io_dev_connector_t *nand_dev_con;
73#endif
74
Lionel Debieve57044222019-09-24 18:30:12 +020075#if STM32MP_SPI_NAND
76static io_mtd_dev_spec_t spi_nand_dev_spec = {
77 .ops = {
78 .init = spi_nand_init,
79 .read = nand_read,
80 },
81};
82
83static const io_dev_connector_t *spi_dev_con;
84#endif
85
Yann Gautier1989a192019-04-19 09:41:01 +020086#ifdef AARCH32_SP_OPTEE
87static const struct stm32image_part_info optee_header_partition_spec = {
88 .name = OPTEE_HEADER_IMAGE_NAME,
89 .binary_type = OPTEE_HEADER_BINARY_TYPE,
90};
91
92static const struct stm32image_part_info optee_pager_partition_spec = {
93 .name = OPTEE_PAGER_IMAGE_NAME,
94 .binary_type = OPTEE_PAGER_BINARY_TYPE,
95};
96
97static const struct stm32image_part_info optee_paged_partition_spec = {
98 .name = OPTEE_PAGED_IMAGE_NAME,
99 .binary_type = OPTEE_PAGED_BINARY_TYPE,
100};
101#else
Yann Gautier59a1cdf2019-01-17 14:41:46 +0100102static const io_block_spec_t bl32_block_spec = {
103 .offset = BL32_BASE,
Yann Gautier3f9c9782019-02-14 11:13:39 +0100104 .length = STM32MP_BL32_SIZE
Yann Gautier59a1cdf2019-01-17 14:41:46 +0100105};
Yann Gautier1989a192019-04-19 09:41:01 +0200106#endif
Yann Gautier59a1cdf2019-01-17 14:41:46 +0100107
108static const io_block_spec_t bl2_block_spec = {
109 .offset = BL2_BASE,
Yann Gautier3f9c9782019-02-14 11:13:39 +0100110 .length = STM32MP_BL2_SIZE,
Yann Gautier59a1cdf2019-01-17 14:41:46 +0100111};
Yann Gautieraec7de42018-10-15 09:36:58 +0200112
113static const struct stm32image_part_info bl33_partition_spec = {
114 .name = BL33_IMAGE_NAME,
115 .binary_type = BL33_BINARY_TYPE,
116};
117
Yann Gautier59a1cdf2019-01-17 14:41:46 +0100118enum {
119 IMG_IDX_BL33,
Yann Gautier1989a192019-04-19 09:41:01 +0200120#ifdef AARCH32_SP_OPTEE
121 IMG_IDX_OPTEE_HEADER,
122 IMG_IDX_OPTEE_PAGER,
123 IMG_IDX_OPTEE_PAGED,
124#endif
Yann Gautier59a1cdf2019-01-17 14:41:46 +0100125 IMG_IDX_NUM
126};
127
Nicolas Le Bayon46554b62019-09-03 09:52:05 +0200128static struct stm32image_device_info stm32image_dev_info_spec __unused = {
Yann Gautieraec7de42018-10-15 09:36:58 +0200129 .lba_size = MMC_BLOCK_SIZE,
130 .part_info[IMG_IDX_BL33] = {
131 .name = BL33_IMAGE_NAME,
132 .binary_type = BL33_BINARY_TYPE,
133 },
Yann Gautier1989a192019-04-19 09:41:01 +0200134#ifdef AARCH32_SP_OPTEE
135 .part_info[IMG_IDX_OPTEE_HEADER] = {
136 .name = OPTEE_HEADER_IMAGE_NAME,
137 .binary_type = OPTEE_HEADER_BINARY_TYPE,
138 },
139 .part_info[IMG_IDX_OPTEE_PAGER] = {
140 .name = OPTEE_PAGER_IMAGE_NAME,
141 .binary_type = OPTEE_PAGER_BINARY_TYPE,
142 },
143 .part_info[IMG_IDX_OPTEE_PAGED] = {
144 .name = OPTEE_PAGED_IMAGE_NAME,
145 .binary_type = OPTEE_PAGED_BINARY_TYPE,
146 },
147#endif
Yann Gautieraec7de42018-10-15 09:36:58 +0200148};
149
Yann Gautier59a1cdf2019-01-17 14:41:46 +0100150static io_block_spec_t stm32image_block_spec = {
151 .offset = 0,
152 .length = 0,
153};
Yann Gautieraec7de42018-10-15 09:36:58 +0200154
Nicolas Le Bayon46554b62019-09-03 09:52:05 +0200155static const io_dev_connector_t *stm32image_dev_con __unused;
Yann Gautieraec7de42018-10-15 09:36:58 +0200156
Yann Gautier4353bb22018-07-16 10:54:09 +0200157static int open_dummy(const uintptr_t spec);
Yann Gautieraec7de42018-10-15 09:36:58 +0200158static int open_image(const uintptr_t spec);
159static int open_storage(const uintptr_t spec);
Yann Gautier4353bb22018-07-16 10:54:09 +0200160
161struct plat_io_policy {
162 uintptr_t *dev_handle;
163 uintptr_t image_spec;
164 int (*check)(const uintptr_t spec);
165};
166
167static const struct plat_io_policy policies[] = {
168 [BL2_IMAGE_ID] = {
169 .dev_handle = &dummy_dev_handle,
170 .image_spec = (uintptr_t)&bl2_block_spec,
171 .check = open_dummy
172 },
Yann Gautier1989a192019-04-19 09:41:01 +0200173#ifdef AARCH32_SP_OPTEE
174 [BL32_IMAGE_ID] = {
175 .dev_handle = &image_dev_handle,
176 .image_spec = (uintptr_t)&optee_header_partition_spec,
177 .check = open_image
178 },
179 [BL32_EXTRA1_IMAGE_ID] = {
180 .dev_handle = &image_dev_handle,
181 .image_spec = (uintptr_t)&optee_pager_partition_spec,
182 .check = open_image
183 },
184 [BL32_EXTRA2_IMAGE_ID] = {
185 .dev_handle = &image_dev_handle,
186 .image_spec = (uintptr_t)&optee_paged_partition_spec,
187 .check = open_image
188 },
189#else
Yann Gautier4353bb22018-07-16 10:54:09 +0200190 [BL32_IMAGE_ID] = {
191 .dev_handle = &dummy_dev_handle,
192 .image_spec = (uintptr_t)&bl32_block_spec,
193 .check = open_dummy
194 },
Yann Gautier1989a192019-04-19 09:41:01 +0200195#endif
Yann Gautieraec7de42018-10-15 09:36:58 +0200196 [BL33_IMAGE_ID] = {
197 .dev_handle = &image_dev_handle,
198 .image_spec = (uintptr_t)&bl33_partition_spec,
199 .check = open_image
200 },
Nicolas Le Bayon46554b62019-09-03 09:52:05 +0200201#if STM32MP_SDMMC || STM32MP_EMMC
Yann Gautieraec7de42018-10-15 09:36:58 +0200202 [GPT_IMAGE_ID] = {
203 .dev_handle = &storage_dev_handle,
204 .image_spec = (uintptr_t)&gpt_block_spec,
205 .check = open_storage
206 },
Nicolas Le Bayon46554b62019-09-03 09:52:05 +0200207#endif
Yann Gautieraec7de42018-10-15 09:36:58 +0200208 [STM32_IMAGE_ID] = {
209 .dev_handle = &storage_dev_handle,
210 .image_spec = (uintptr_t)&stm32image_block_spec,
211 .check = open_storage
212 }
Yann Gautier4353bb22018-07-16 10:54:09 +0200213};
214
215static int open_dummy(const uintptr_t spec)
216{
217 return io_dev_init(dummy_dev_handle, 0);
218}
219
Yann Gautieraec7de42018-10-15 09:36:58 +0200220static int open_image(const uintptr_t spec)
221{
222 return io_dev_init(image_dev_handle, 0);
223}
224
225static int open_storage(const uintptr_t spec)
226{
227 return io_dev_init(storage_dev_handle, 0);
228}
229
Yann Gautier4353bb22018-07-16 10:54:09 +0200230static void print_boot_device(boot_api_context_t *boot_context)
231{
232 switch (boot_context->boot_interface_selected) {
233 case BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_SD:
234 INFO("Using SDMMC\n");
235 break;
236 case BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_EMMC:
237 INFO("Using EMMC\n");
238 break;
Lionel Debieve12e21df2019-11-04 12:28:15 +0100239 case BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_NAND_FMC:
240 INFO("Using FMC NAND\n");
241 break;
Lionel Debieve57044222019-09-24 18:30:12 +0200242 case BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_NAND_QSPI:
243 INFO("Using SPI NAND\n");
244 break;
Yann Gautier4353bb22018-07-16 10:54:09 +0200245 default:
246 ERROR("Boot interface not found\n");
247 panic();
248 break;
249 }
250
251 if (boot_context->boot_interface_instance != 0U) {
252 INFO(" Instance %d\n", boot_context->boot_interface_instance);
253 }
254}
255
Nicolas Le Bayon46554b62019-09-03 09:52:05 +0200256#if STM32MP_SDMMC || STM32MP_EMMC
Yann Gautier0b1aa772019-04-23 13:34:03 +0200257static void boot_mmc(enum mmc_device_type mmc_dev_type,
258 uint16_t boot_interface_instance)
Yann Gautier4353bb22018-07-16 10:54:09 +0200259{
260 int io_result __unused;
Yann Gautier59a1cdf2019-01-17 14:41:46 +0100261 uint8_t idx;
262 struct stm32image_part_info *part;
Yann Gautieraec7de42018-10-15 09:36:58 +0200263 struct stm32_sdmmc2_params params;
264 struct mmc_device_info device_info;
Yann Gautier59a1cdf2019-01-17 14:41:46 +0100265 const partition_entry_t *entry;
Yann Gautier0b1aa772019-04-23 13:34:03 +0200266
267 zeromem(&device_info, sizeof(struct mmc_device_info));
268 zeromem(&params, sizeof(struct stm32_sdmmc2_params));
269
270 device_info.mmc_dev_type = mmc_dev_type;
271
272 switch (boot_interface_instance) {
273 case 1:
274 params.reg_base = STM32MP_SDMMC1_BASE;
275 break;
276 case 2:
277 params.reg_base = STM32MP_SDMMC2_BASE;
278 break;
279 case 3:
280 params.reg_base = STM32MP_SDMMC3_BASE;
281 break;
282 default:
283 WARN("SDMMC instance not found, using default\n");
284 if (mmc_dev_type == MMC_IS_SD) {
285 params.reg_base = STM32MP_SDMMC1_BASE;
286 } else {
287 params.reg_base = STM32MP_SDMMC2_BASE;
288 }
289 break;
290 }
291
292 params.device_info = &device_info;
293 if (stm32_sdmmc2_mmc_init(&params) != 0) {
294 ERROR("SDMMC%u init failed\n", boot_interface_instance);
295 panic();
296 }
297
298 /* Open MMC as a block device to read GPT table */
299 io_result = register_io_dev_block(&mmc_dev_con);
300 if (io_result != 0) {
301 panic();
302 }
303
304 io_result = io_dev_open(mmc_dev_con, (uintptr_t)&mmc_block_dev_spec,
305 &storage_dev_handle);
306 assert(io_result == 0);
307
308 partition_init(GPT_IMAGE_ID);
309
310 io_result = io_dev_close(storage_dev_handle);
311 assert(io_result == 0);
312
313 stm32image_dev_info_spec.device_size =
314 stm32_sdmmc2_mmc_get_device_size();
315
316 for (idx = 0U; idx < IMG_IDX_NUM; idx++) {
317 part = &stm32image_dev_info_spec.part_info[idx];
318 entry = get_partition_entry(part->name);
319 if (entry == NULL) {
320 ERROR("Partition %s not found\n", part->name);
321 panic();
322 }
323
324 part->part_offset = entry->start;
325 part->bkp_offset = 0U;
326 }
327
328 /*
329 * Re-open MMC with io_mmc, for better perfs compared to
330 * io_block.
331 */
332 io_result = register_io_dev_mmc(&mmc_dev_con);
333 assert(io_result == 0);
334
335 io_result = io_dev_open(mmc_dev_con, 0, &storage_dev_handle);
336 assert(io_result == 0);
337
338 io_result = register_io_dev_stm32image(&stm32image_dev_con);
339 assert(io_result == 0);
340
341 io_result = io_dev_open(stm32image_dev_con,
342 (uintptr_t)&stm32image_dev_info_spec,
343 &image_dev_handle);
344 assert(io_result == 0);
345}
Nicolas Le Bayon46554b62019-09-03 09:52:05 +0200346#endif /* STM32MP_SDMMC || STM32MP_EMMC */
Yann Gautier0b1aa772019-04-23 13:34:03 +0200347
Lionel Debieve12e21df2019-11-04 12:28:15 +0100348#if STM32MP_RAW_NAND
349static void boot_fmc2_nand(boot_api_context_t *boot_context)
350{
351 int io_result __unused;
352 uint8_t idx;
353 struct stm32image_part_info *part;
354
355 io_result = stm32_fmc2_init();
356 assert(io_result == 0);
357
358 /* Register the IO device on this platform */
359 io_result = register_io_dev_mtd(&nand_dev_con);
360 assert(io_result == 0);
361
362 /* Open connections to device */
363 io_result = io_dev_open(nand_dev_con, (uintptr_t)&nand_dev_spec,
364 &storage_dev_handle);
365 assert(io_result == 0);
366
367 stm32image_dev_info_spec.device_size = nand_dev_spec.device_size;
368
369 idx = IMG_IDX_BL33;
370 part = &stm32image_dev_info_spec.part_info[idx];
371 part->part_offset = STM32MP_NAND_BL33_OFFSET;
372 part->bkp_offset = nand_dev_spec.erase_size;
373
374#ifdef AARCH32_SP_OPTEE
375 idx = IMG_IDX_OPTEE_HEADER;
376 part = &stm32image_dev_info_spec.part_info[idx];
377 part->part_offset = STM32MP_NAND_TEEH_OFFSET;
378 part->bkp_offset = nand_dev_spec.erase_size;
379
380 idx = IMG_IDX_OPTEE_PAGED;
381 part = &stm32image_dev_info_spec.part_info[idx];
382 part->part_offset = STM32MP_NAND_TEED_OFFSET;
383 part->bkp_offset = nand_dev_spec.erase_size;
384
385 idx = IMG_IDX_OPTEE_PAGER;
386 part = &stm32image_dev_info_spec.part_info[idx];
387 part->part_offset = STM32MP_NAND_TEEX_OFFSET;
388 part->bkp_offset = nand_dev_spec.erase_size;
389#endif
390
391 io_result = register_io_dev_stm32image(&stm32image_dev_con);
392 assert(io_result == 0);
393
394 io_result = io_dev_open(stm32image_dev_con,
395 (uintptr_t)&stm32image_dev_info_spec,
396 &image_dev_handle);
397 assert(io_result == 0);
398}
399#endif /* STM32MP_RAW_NAND */
400
Lionel Debieve57044222019-09-24 18:30:12 +0200401#if STM32MP_SPI_NAND
402static void boot_spi_nand(boot_api_context_t *boot_context)
403{
404 int io_result __unused;
405 uint8_t idx;
406 struct stm32image_part_info *part;
407
408 io_result = stm32_qspi_init();
409 assert(io_result == 0);
410
411 io_result = register_io_dev_mtd(&spi_dev_con);
412 assert(io_result == 0);
413
414 /* Open connections to device */
415 io_result = io_dev_open(spi_dev_con,
416 (uintptr_t)&spi_nand_dev_spec,
417 &storage_dev_handle);
418 assert(io_result == 0);
419
420 stm32image_dev_info_spec.device_size =
421 spi_nand_dev_spec.device_size;
422
423 idx = IMG_IDX_BL33;
424 part = &stm32image_dev_info_spec.part_info[idx];
425 part->part_offset = STM32MP_NAND_BL33_OFFSET;
426 part->bkp_offset = spi_nand_dev_spec.erase_size;
427
428#ifdef AARCH32_SP_OPTEE
429 idx = IMG_IDX_OPTEE_HEADER;
430 part = &stm32image_dev_info_spec.part_info[idx];
431 part->part_offset = STM32MP_NAND_TEEH_OFFSET;
432 part->bkp_offset = spi_nand_dev_spec.erase_size;
433
434 idx = IMG_IDX_OPTEE_PAGED;
435 part = &stm32image_dev_info_spec.part_info[idx];
436 part->part_offset = STM32MP_NAND_TEED_OFFSET;
437 part->bkp_offset = spi_nand_dev_spec.erase_size;
438
439 idx = IMG_IDX_OPTEE_PAGER;
440 part = &stm32image_dev_info_spec.part_info[idx];
441 part->part_offset = STM32MP_NAND_TEEX_OFFSET;
442 part->bkp_offset = spi_nand_dev_spec.erase_size;
443#endif
444
445 io_result = register_io_dev_stm32image(&stm32image_dev_con);
446 assert(io_result == 0);
447
448 io_result = io_dev_open(stm32image_dev_con,
449 (uintptr_t)&stm32image_dev_info_spec,
450 &image_dev_handle);
451 assert(io_result == 0);
452}
453#endif /* STM32MP_SPI_NAND */
454
Yann Gautier0b1aa772019-04-23 13:34:03 +0200455void stm32mp_io_setup(void)
456{
457 int io_result __unused;
Yann Gautier4353bb22018-07-16 10:54:09 +0200458 boot_api_context_t *boot_context =
Yann Gautier3f9c9782019-02-14 11:13:39 +0100459 (boot_api_context_t *)stm32mp_get_boot_ctx_address();
Yann Gautier4353bb22018-07-16 10:54:09 +0200460
Yann Gautier4353bb22018-07-16 10:54:09 +0200461 print_boot_device(boot_context);
462
463 if ((boot_context->boot_partition_used_toboot == 1U) ||
464 (boot_context->boot_partition_used_toboot == 2U)) {
465 INFO("Boot used partition fsbl%d\n",
466 boot_context->boot_partition_used_toboot);
467 }
468
469 io_result = register_io_dev_dummy(&dummy_dev_con);
470 assert(io_result == 0);
471
472 io_result = io_dev_open(dummy_dev_con, dummy_dev_spec,
473 &dummy_dev_handle);
474 assert(io_result == 0);
Yann Gautieraec7de42018-10-15 09:36:58 +0200475
476 switch (boot_context->boot_interface_selected) {
Nicolas Le Bayon46554b62019-09-03 09:52:05 +0200477#if STM32MP_SDMMC
Yann Gautieraec7de42018-10-15 09:36:58 +0200478 case BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_SD:
Yann Gautier0b1aa772019-04-23 13:34:03 +0200479 dmbsy();
480 boot_mmc(MMC_IS_SD, boot_context->boot_interface_instance);
481 break;
Nicolas Le Bayon46554b62019-09-03 09:52:05 +0200482#endif
483#if STM32MP_EMMC
Yann Gautieraec7de42018-10-15 09:36:58 +0200484 case BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_EMMC:
Yann Gautier59a1cdf2019-01-17 14:41:46 +0100485 dmbsy();
Yann Gautier0b1aa772019-04-23 13:34:03 +0200486 boot_mmc(MMC_IS_EMMC, boot_context->boot_interface_instance);
Yann Gautieraec7de42018-10-15 09:36:58 +0200487 break;
Nicolas Le Bayon46554b62019-09-03 09:52:05 +0200488#endif
Lionel Debieve12e21df2019-11-04 12:28:15 +0100489#if STM32MP_RAW_NAND
490 case BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_NAND_FMC:
491 dmbsy();
492 boot_fmc2_nand(boot_context);
493 break;
494#endif
Lionel Debieve57044222019-09-24 18:30:12 +0200495#if STM32MP_SPI_NAND
496 case BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_NAND_QSPI:
497 dmbsy();
498 boot_spi_nand(boot_context);
499 break;
500#endif
Yann Gautieraec7de42018-10-15 09:36:58 +0200501
502 default:
503 ERROR("Boot interface %d not supported\n",
504 boot_context->boot_interface_selected);
505 break;
506 }
Yann Gautier4353bb22018-07-16 10:54:09 +0200507}
508
509/*
510 * Return an IO device handle and specification which can be used to access
511 * an image. Use this to enforce platform load policy.
512 */
513int plat_get_image_source(unsigned int image_id, uintptr_t *dev_handle,
514 uintptr_t *image_spec)
515{
516 int rc;
517 const struct plat_io_policy *policy;
518
519 assert(image_id < ARRAY_SIZE(policies));
520
521 policy = &policies[image_id];
522 rc = policy->check(policy->image_spec);
523 if (rc == 0) {
524 *image_spec = policy->image_spec;
525 *dev_handle = *(policy->dev_handle);
526 }
527
528 return rc;
529}