Yann Gautier | 4b0c72a | 2018-07-16 10:54:09 +0200 | [diff] [blame] | 1 | /* |
Yann Gautier | f9d40d5 | 2019-01-17 14:41:46 +0100 | [diff] [blame] | 2 | * Copyright (c) 2015-2019, ARM Limited and Contributors. All rights reserved. |
Yann Gautier | 4b0c72a | 2018-07-16 10:54:09 +0200 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
Yann Gautier | 4b0c72a | 2018-07-16 10:54:09 +0200 | [diff] [blame] | 7 | #include <assert.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 8 | #include <string.h> |
| 9 | |
Yann Gautier | 4b0c72a | 2018-07-16 10:54:09 +0200 | [diff] [blame] | 10 | #include <platform_def.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 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> |
| 17 | #include <drivers/io/io_storage.h> |
| 18 | #include <drivers/mmc.h> |
| 19 | #include <drivers/partition/partition.h> |
| 20 | #include <drivers/st/io_mmc.h> |
| 21 | #include <drivers/st/io_stm32image.h> |
| 22 | #include <drivers/st/stm32_sdmmc2.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 23 | #include <lib/mmio.h> |
| 24 | #include <lib/utils.h> |
| 25 | #include <plat/common/platform.h> |
| 26 | |
Yann Gautier | 4b0c72a | 2018-07-16 10:54:09 +0200 | [diff] [blame] | 27 | /* IO devices */ |
| 28 | static const io_dev_connector_t *dummy_dev_con; |
| 29 | static uintptr_t dummy_dev_handle; |
| 30 | static uintptr_t dummy_dev_spec; |
| 31 | |
Yann Gautier | 8244e1d | 2018-10-15 09:36:58 +0200 | [diff] [blame] | 32 | static uintptr_t image_dev_handle; |
| 33 | |
| 34 | static io_block_spec_t gpt_block_spec = { |
| 35 | .offset = 0, |
| 36 | .length = 34 * MMC_BLOCK_SIZE, /* Size of GPT table */ |
| 37 | }; |
| 38 | |
Yann Gautier | f9af3bc | 2018-11-09 15:57:18 +0100 | [diff] [blame] | 39 | static uint32_t block_buffer[MMC_BLOCK_SIZE] __aligned(MMC_BLOCK_SIZE); |
Yann Gautier | 8244e1d | 2018-10-15 09:36:58 +0200 | [diff] [blame] | 40 | |
| 41 | static const io_block_dev_spec_t mmc_block_dev_spec = { |
| 42 | /* It's used as temp buffer in block driver */ |
| 43 | .buffer = { |
| 44 | .offset = (size_t)&block_buffer, |
| 45 | .length = MMC_BLOCK_SIZE, |
| 46 | }, |
| 47 | .ops = { |
| 48 | .read = mmc_read_blocks, |
| 49 | .write = NULL, |
| 50 | }, |
| 51 | .block_size = MMC_BLOCK_SIZE, |
| 52 | }; |
| 53 | |
| 54 | static uintptr_t storage_dev_handle; |
| 55 | static const io_dev_connector_t *mmc_dev_con; |
| 56 | |
Yann Gautier | b3386f7 | 2019-04-19 09:41:01 +0200 | [diff] [blame] | 57 | #ifdef AARCH32_SP_OPTEE |
| 58 | static const struct stm32image_part_info optee_header_partition_spec = { |
| 59 | .name = OPTEE_HEADER_IMAGE_NAME, |
| 60 | .binary_type = OPTEE_HEADER_BINARY_TYPE, |
| 61 | }; |
| 62 | |
| 63 | static const struct stm32image_part_info optee_pager_partition_spec = { |
| 64 | .name = OPTEE_PAGER_IMAGE_NAME, |
| 65 | .binary_type = OPTEE_PAGER_BINARY_TYPE, |
| 66 | }; |
| 67 | |
| 68 | static const struct stm32image_part_info optee_paged_partition_spec = { |
| 69 | .name = OPTEE_PAGED_IMAGE_NAME, |
| 70 | .binary_type = OPTEE_PAGED_BINARY_TYPE, |
| 71 | }; |
| 72 | #else |
Yann Gautier | f9d40d5 | 2019-01-17 14:41:46 +0100 | [diff] [blame] | 73 | static const io_block_spec_t bl32_block_spec = { |
| 74 | .offset = BL32_BASE, |
Yann Gautier | a2e2a30 | 2019-02-14 11:13:39 +0100 | [diff] [blame] | 75 | .length = STM32MP_BL32_SIZE |
Yann Gautier | f9d40d5 | 2019-01-17 14:41:46 +0100 | [diff] [blame] | 76 | }; |
Yann Gautier | b3386f7 | 2019-04-19 09:41:01 +0200 | [diff] [blame] | 77 | #endif |
Yann Gautier | f9d40d5 | 2019-01-17 14:41:46 +0100 | [diff] [blame] | 78 | |
| 79 | static const io_block_spec_t bl2_block_spec = { |
| 80 | .offset = BL2_BASE, |
Yann Gautier | a2e2a30 | 2019-02-14 11:13:39 +0100 | [diff] [blame] | 81 | .length = STM32MP_BL2_SIZE, |
Yann Gautier | f9d40d5 | 2019-01-17 14:41:46 +0100 | [diff] [blame] | 82 | }; |
Yann Gautier | 8244e1d | 2018-10-15 09:36:58 +0200 | [diff] [blame] | 83 | |
| 84 | static const struct stm32image_part_info bl33_partition_spec = { |
| 85 | .name = BL33_IMAGE_NAME, |
| 86 | .binary_type = BL33_BINARY_TYPE, |
| 87 | }; |
| 88 | |
Yann Gautier | f9d40d5 | 2019-01-17 14:41:46 +0100 | [diff] [blame] | 89 | enum { |
| 90 | IMG_IDX_BL33, |
Yann Gautier | b3386f7 | 2019-04-19 09:41:01 +0200 | [diff] [blame] | 91 | #ifdef AARCH32_SP_OPTEE |
| 92 | IMG_IDX_OPTEE_HEADER, |
| 93 | IMG_IDX_OPTEE_PAGER, |
| 94 | IMG_IDX_OPTEE_PAGED, |
| 95 | #endif |
Yann Gautier | f9d40d5 | 2019-01-17 14:41:46 +0100 | [diff] [blame] | 96 | IMG_IDX_NUM |
| 97 | }; |
| 98 | |
Yann Gautier | 8244e1d | 2018-10-15 09:36:58 +0200 | [diff] [blame] | 99 | static struct stm32image_device_info stm32image_dev_info_spec = { |
| 100 | .lba_size = MMC_BLOCK_SIZE, |
| 101 | .part_info[IMG_IDX_BL33] = { |
| 102 | .name = BL33_IMAGE_NAME, |
| 103 | .binary_type = BL33_BINARY_TYPE, |
| 104 | }, |
Yann Gautier | b3386f7 | 2019-04-19 09:41:01 +0200 | [diff] [blame] | 105 | #ifdef AARCH32_SP_OPTEE |
| 106 | .part_info[IMG_IDX_OPTEE_HEADER] = { |
| 107 | .name = OPTEE_HEADER_IMAGE_NAME, |
| 108 | .binary_type = OPTEE_HEADER_BINARY_TYPE, |
| 109 | }, |
| 110 | .part_info[IMG_IDX_OPTEE_PAGER] = { |
| 111 | .name = OPTEE_PAGER_IMAGE_NAME, |
| 112 | .binary_type = OPTEE_PAGER_BINARY_TYPE, |
| 113 | }, |
| 114 | .part_info[IMG_IDX_OPTEE_PAGED] = { |
| 115 | .name = OPTEE_PAGED_IMAGE_NAME, |
| 116 | .binary_type = OPTEE_PAGED_BINARY_TYPE, |
| 117 | }, |
| 118 | #endif |
Yann Gautier | 8244e1d | 2018-10-15 09:36:58 +0200 | [diff] [blame] | 119 | }; |
| 120 | |
Yann Gautier | f9d40d5 | 2019-01-17 14:41:46 +0100 | [diff] [blame] | 121 | static io_block_spec_t stm32image_block_spec = { |
| 122 | .offset = 0, |
| 123 | .length = 0, |
Yann Gautier | 4b0c72a | 2018-07-16 10:54:09 +0200 | [diff] [blame] | 124 | }; |
| 125 | |
Yann Gautier | f9d40d5 | 2019-01-17 14:41:46 +0100 | [diff] [blame] | 126 | static const io_dev_connector_t *stm32image_dev_con; |
Yann Gautier | 4b0c72a | 2018-07-16 10:54:09 +0200 | [diff] [blame] | 127 | |
| 128 | static int open_dummy(const uintptr_t spec); |
Yann Gautier | 8244e1d | 2018-10-15 09:36:58 +0200 | [diff] [blame] | 129 | static int open_image(const uintptr_t spec); |
| 130 | static int open_storage(const uintptr_t spec); |
Yann Gautier | 4b0c72a | 2018-07-16 10:54:09 +0200 | [diff] [blame] | 131 | |
| 132 | struct plat_io_policy { |
| 133 | uintptr_t *dev_handle; |
| 134 | uintptr_t image_spec; |
| 135 | int (*check)(const uintptr_t spec); |
| 136 | }; |
| 137 | |
| 138 | static const struct plat_io_policy policies[] = { |
| 139 | [BL2_IMAGE_ID] = { |
| 140 | .dev_handle = &dummy_dev_handle, |
| 141 | .image_spec = (uintptr_t)&bl2_block_spec, |
| 142 | .check = open_dummy |
| 143 | }, |
Yann Gautier | b3386f7 | 2019-04-19 09:41:01 +0200 | [diff] [blame] | 144 | #ifdef AARCH32_SP_OPTEE |
| 145 | [BL32_IMAGE_ID] = { |
| 146 | .dev_handle = &image_dev_handle, |
| 147 | .image_spec = (uintptr_t)&optee_header_partition_spec, |
| 148 | .check = open_image |
| 149 | }, |
| 150 | [BL32_EXTRA1_IMAGE_ID] = { |
| 151 | .dev_handle = &image_dev_handle, |
| 152 | .image_spec = (uintptr_t)&optee_pager_partition_spec, |
| 153 | .check = open_image |
| 154 | }, |
| 155 | [BL32_EXTRA2_IMAGE_ID] = { |
| 156 | .dev_handle = &image_dev_handle, |
| 157 | .image_spec = (uintptr_t)&optee_paged_partition_spec, |
| 158 | .check = open_image |
| 159 | }, |
| 160 | #else |
Yann Gautier | 4b0c72a | 2018-07-16 10:54:09 +0200 | [diff] [blame] | 161 | [BL32_IMAGE_ID] = { |
| 162 | .dev_handle = &dummy_dev_handle, |
| 163 | .image_spec = (uintptr_t)&bl32_block_spec, |
| 164 | .check = open_dummy |
| 165 | }, |
Yann Gautier | b3386f7 | 2019-04-19 09:41:01 +0200 | [diff] [blame] | 166 | #endif |
Yann Gautier | 8244e1d | 2018-10-15 09:36:58 +0200 | [diff] [blame] | 167 | [BL33_IMAGE_ID] = { |
| 168 | .dev_handle = &image_dev_handle, |
| 169 | .image_spec = (uintptr_t)&bl33_partition_spec, |
| 170 | .check = open_image |
| 171 | }, |
| 172 | [GPT_IMAGE_ID] = { |
| 173 | .dev_handle = &storage_dev_handle, |
| 174 | .image_spec = (uintptr_t)&gpt_block_spec, |
| 175 | .check = open_storage |
| 176 | }, |
| 177 | [STM32_IMAGE_ID] = { |
| 178 | .dev_handle = &storage_dev_handle, |
| 179 | .image_spec = (uintptr_t)&stm32image_block_spec, |
| 180 | .check = open_storage |
| 181 | } |
Yann Gautier | 4b0c72a | 2018-07-16 10:54:09 +0200 | [diff] [blame] | 182 | }; |
| 183 | |
| 184 | static int open_dummy(const uintptr_t spec) |
| 185 | { |
| 186 | return io_dev_init(dummy_dev_handle, 0); |
| 187 | } |
| 188 | |
Yann Gautier | 8244e1d | 2018-10-15 09:36:58 +0200 | [diff] [blame] | 189 | static int open_image(const uintptr_t spec) |
| 190 | { |
| 191 | return io_dev_init(image_dev_handle, 0); |
| 192 | } |
| 193 | |
| 194 | static int open_storage(const uintptr_t spec) |
| 195 | { |
| 196 | return io_dev_init(storage_dev_handle, 0); |
| 197 | } |
| 198 | |
Yann Gautier | 4b0c72a | 2018-07-16 10:54:09 +0200 | [diff] [blame] | 199 | static void print_boot_device(boot_api_context_t *boot_context) |
| 200 | { |
| 201 | switch (boot_context->boot_interface_selected) { |
| 202 | case BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_SD: |
| 203 | INFO("Using SDMMC\n"); |
| 204 | break; |
| 205 | case BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_EMMC: |
| 206 | INFO("Using EMMC\n"); |
| 207 | break; |
| 208 | default: |
| 209 | ERROR("Boot interface not found\n"); |
| 210 | panic(); |
| 211 | break; |
| 212 | } |
| 213 | |
| 214 | if (boot_context->boot_interface_instance != 0U) { |
| 215 | INFO(" Instance %d\n", boot_context->boot_interface_instance); |
| 216 | } |
Yann Gautier | 4b0c72a | 2018-07-16 10:54:09 +0200 | [diff] [blame] | 217 | } |
| 218 | |
Yann Gautier | eae3fbf | 2019-04-23 13:34:03 +0200 | [diff] [blame] | 219 | static void boot_mmc(enum mmc_device_type mmc_dev_type, |
| 220 | uint16_t boot_interface_instance) |
Yann Gautier | 4b0c72a | 2018-07-16 10:54:09 +0200 | [diff] [blame] | 221 | { |
| 222 | int io_result __unused; |
Yann Gautier | f9d40d5 | 2019-01-17 14:41:46 +0100 | [diff] [blame] | 223 | uint8_t idx; |
| 224 | struct stm32image_part_info *part; |
Yann Gautier | 8244e1d | 2018-10-15 09:36:58 +0200 | [diff] [blame] | 225 | struct stm32_sdmmc2_params params; |
| 226 | struct mmc_device_info device_info; |
Yann Gautier | f9d40d5 | 2019-01-17 14:41:46 +0100 | [diff] [blame] | 227 | const partition_entry_t *entry; |
Yann Gautier | 4b0c72a | 2018-07-16 10:54:09 +0200 | [diff] [blame] | 228 | |
Yann Gautier | eae3fbf | 2019-04-23 13:34:03 +0200 | [diff] [blame] | 229 | zeromem(&device_info, sizeof(struct mmc_device_info)); |
| 230 | zeromem(¶ms, sizeof(struct stm32_sdmmc2_params)); |
Yann Gautier | 4b0c72a | 2018-07-16 10:54:09 +0200 | [diff] [blame] | 231 | |
Yann Gautier | eae3fbf | 2019-04-23 13:34:03 +0200 | [diff] [blame] | 232 | device_info.mmc_dev_type = mmc_dev_type; |
| 233 | |
| 234 | switch (boot_interface_instance) { |
| 235 | case 1: |
| 236 | params.reg_base = STM32MP_SDMMC1_BASE; |
| 237 | break; |
| 238 | case 2: |
| 239 | params.reg_base = STM32MP_SDMMC2_BASE; |
| 240 | break; |
| 241 | case 3: |
| 242 | params.reg_base = STM32MP_SDMMC3_BASE; |
| 243 | break; |
| 244 | default: |
| 245 | WARN("SDMMC instance not found, using default\n"); |
| 246 | if (mmc_dev_type == MMC_IS_SD) { |
| 247 | params.reg_base = STM32MP_SDMMC1_BASE; |
| 248 | } else { |
| 249 | params.reg_base = STM32MP_SDMMC2_BASE; |
| 250 | } |
| 251 | break; |
Yann Gautier | 4b0c72a | 2018-07-16 10:54:09 +0200 | [diff] [blame] | 252 | } |
| 253 | |
Yann Gautier | eae3fbf | 2019-04-23 13:34:03 +0200 | [diff] [blame] | 254 | params.device_info = &device_info; |
| 255 | if (stm32_sdmmc2_mmc_init(¶ms) != 0) { |
| 256 | ERROR("SDMMC%u init failed\n", boot_interface_instance); |
| 257 | panic(); |
| 258 | } |
Yann Gautier | 4b0c72a | 2018-07-16 10:54:09 +0200 | [diff] [blame] | 259 | |
Yann Gautier | eae3fbf | 2019-04-23 13:34:03 +0200 | [diff] [blame] | 260 | /* Open MMC as a block device to read GPT table */ |
| 261 | io_result = register_io_dev_block(&mmc_dev_con); |
| 262 | if (io_result != 0) { |
| 263 | panic(); |
| 264 | } |
Yann Gautier | 8244e1d | 2018-10-15 09:36:58 +0200 | [diff] [blame] | 265 | |
Yann Gautier | eae3fbf | 2019-04-23 13:34:03 +0200 | [diff] [blame] | 266 | io_result = io_dev_open(mmc_dev_con, (uintptr_t)&mmc_block_dev_spec, |
| 267 | &storage_dev_handle); |
| 268 | assert(io_result == 0); |
Yann Gautier | 8244e1d | 2018-10-15 09:36:58 +0200 | [diff] [blame] | 269 | |
Yann Gautier | eae3fbf | 2019-04-23 13:34:03 +0200 | [diff] [blame] | 270 | partition_init(GPT_IMAGE_ID); |
Yann Gautier | 8244e1d | 2018-10-15 09:36:58 +0200 | [diff] [blame] | 271 | |
Yann Gautier | eae3fbf | 2019-04-23 13:34:03 +0200 | [diff] [blame] | 272 | io_result = io_dev_close(storage_dev_handle); |
| 273 | assert(io_result == 0); |
Yann Gautier | 8244e1d | 2018-10-15 09:36:58 +0200 | [diff] [blame] | 274 | |
Yann Gautier | eae3fbf | 2019-04-23 13:34:03 +0200 | [diff] [blame] | 275 | stm32image_dev_info_spec.device_size = |
| 276 | stm32_sdmmc2_mmc_get_device_size(); |
Yann Gautier | 8244e1d | 2018-10-15 09:36:58 +0200 | [diff] [blame] | 277 | |
Yann Gautier | eae3fbf | 2019-04-23 13:34:03 +0200 | [diff] [blame] | 278 | for (idx = 0U; idx < IMG_IDX_NUM; idx++) { |
| 279 | part = &stm32image_dev_info_spec.part_info[idx]; |
| 280 | entry = get_partition_entry(part->name); |
| 281 | if (entry == NULL) { |
| 282 | ERROR("Partition %s not found\n", part->name); |
Yann Gautier | 03f0468 | 2018-11-29 15:44:04 +0100 | [diff] [blame] | 283 | panic(); |
| 284 | } |
Yann Gautier | 8244e1d | 2018-10-15 09:36:58 +0200 | [diff] [blame] | 285 | |
Yann Gautier | eae3fbf | 2019-04-23 13:34:03 +0200 | [diff] [blame] | 286 | part->part_offset = entry->start; |
| 287 | part->bkp_offset = 0U; |
| 288 | } |
Yann Gautier | 8244e1d | 2018-10-15 09:36:58 +0200 | [diff] [blame] | 289 | |
Yann Gautier | eae3fbf | 2019-04-23 13:34:03 +0200 | [diff] [blame] | 290 | /* |
| 291 | * Re-open MMC with io_mmc, for better perfs compared to |
| 292 | * io_block. |
| 293 | */ |
| 294 | io_result = register_io_dev_mmc(&mmc_dev_con); |
| 295 | assert(io_result == 0); |
Yann Gautier | 8244e1d | 2018-10-15 09:36:58 +0200 | [diff] [blame] | 296 | |
Yann Gautier | eae3fbf | 2019-04-23 13:34:03 +0200 | [diff] [blame] | 297 | io_result = io_dev_open(mmc_dev_con, 0, &storage_dev_handle); |
| 298 | assert(io_result == 0); |
Yann Gautier | 8244e1d | 2018-10-15 09:36:58 +0200 | [diff] [blame] | 299 | |
Yann Gautier | eae3fbf | 2019-04-23 13:34:03 +0200 | [diff] [blame] | 300 | io_result = register_io_dev_stm32image(&stm32image_dev_con); |
| 301 | assert(io_result == 0); |
Yann Gautier | 8244e1d | 2018-10-15 09:36:58 +0200 | [diff] [blame] | 302 | |
Yann Gautier | eae3fbf | 2019-04-23 13:34:03 +0200 | [diff] [blame] | 303 | io_result = io_dev_open(stm32image_dev_con, |
| 304 | (uintptr_t)&stm32image_dev_info_spec, |
| 305 | &image_dev_handle); |
| 306 | assert(io_result == 0); |
| 307 | } |
Yann Gautier | 8244e1d | 2018-10-15 09:36:58 +0200 | [diff] [blame] | 308 | |
Yann Gautier | eae3fbf | 2019-04-23 13:34:03 +0200 | [diff] [blame] | 309 | void stm32mp_io_setup(void) |
| 310 | { |
| 311 | int io_result __unused; |
| 312 | boot_api_context_t *boot_context = |
| 313 | (boot_api_context_t *)stm32mp_get_boot_ctx_address(); |
Yann Gautier | f9d40d5 | 2019-01-17 14:41:46 +0100 | [diff] [blame] | 314 | |
Yann Gautier | eae3fbf | 2019-04-23 13:34:03 +0200 | [diff] [blame] | 315 | print_boot_device(boot_context); |
Yann Gautier | 8244e1d | 2018-10-15 09:36:58 +0200 | [diff] [blame] | 316 | |
Yann Gautier | eae3fbf | 2019-04-23 13:34:03 +0200 | [diff] [blame] | 317 | if ((boot_context->boot_partition_used_toboot == 1U) || |
| 318 | (boot_context->boot_partition_used_toboot == 2U)) { |
| 319 | INFO("Boot used partition fsbl%d\n", |
| 320 | boot_context->boot_partition_used_toboot); |
| 321 | } |
Yann Gautier | 8244e1d | 2018-10-15 09:36:58 +0200 | [diff] [blame] | 322 | |
Yann Gautier | eae3fbf | 2019-04-23 13:34:03 +0200 | [diff] [blame] | 323 | io_result = register_io_dev_dummy(&dummy_dev_con); |
| 324 | assert(io_result == 0); |
Yann Gautier | 8244e1d | 2018-10-15 09:36:58 +0200 | [diff] [blame] | 325 | |
Yann Gautier | eae3fbf | 2019-04-23 13:34:03 +0200 | [diff] [blame] | 326 | io_result = io_dev_open(dummy_dev_con, dummy_dev_spec, |
| 327 | &dummy_dev_handle); |
| 328 | assert(io_result == 0); |
Yann Gautier | 8244e1d | 2018-10-15 09:36:58 +0200 | [diff] [blame] | 329 | |
Yann Gautier | eae3fbf | 2019-04-23 13:34:03 +0200 | [diff] [blame] | 330 | switch (boot_context->boot_interface_selected) { |
| 331 | case BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_SD: |
| 332 | dmbsy(); |
| 333 | boot_mmc(MMC_IS_SD, boot_context->boot_interface_instance); |
| 334 | break; |
| 335 | case BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_EMMC: |
| 336 | dmbsy(); |
| 337 | boot_mmc(MMC_IS_EMMC, boot_context->boot_interface_instance); |
Yann Gautier | 8244e1d | 2018-10-15 09:36:58 +0200 | [diff] [blame] | 338 | break; |
| 339 | |
| 340 | default: |
| 341 | ERROR("Boot interface %d not supported\n", |
| 342 | boot_context->boot_interface_selected); |
| 343 | break; |
| 344 | } |
Yann Gautier | 4b0c72a | 2018-07-16 10:54:09 +0200 | [diff] [blame] | 345 | } |
| 346 | |
| 347 | /* |
| 348 | * Return an IO device handle and specification which can be used to access |
| 349 | * an image. Use this to enforce platform load policy. |
| 350 | */ |
| 351 | int plat_get_image_source(unsigned int image_id, uintptr_t *dev_handle, |
| 352 | uintptr_t *image_spec) |
| 353 | { |
| 354 | int rc; |
| 355 | const struct plat_io_policy *policy; |
| 356 | |
| 357 | assert(image_id < ARRAY_SIZE(policies)); |
| 358 | |
| 359 | policy = &policies[image_id]; |
| 360 | rc = policy->check(policy->image_spec); |
| 361 | if (rc == 0) { |
| 362 | *image_spec = policy->image_spec; |
| 363 | *dev_handle = *(policy->dev_handle); |
| 364 | } |
| 365 | |
| 366 | return rc; |
| 367 | } |