Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2015, ARM Limited and Contributors. All rights reserved. |
| 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions are met: |
| 6 | * |
| 7 | * Redistributions of source code must retain the above copyright notice, this |
| 8 | * list of conditions and the following disclaimer. |
| 9 | * |
| 10 | * Redistributions in binary form must reproduce the above copyright notice, |
| 11 | * this list of conditions and the following disclaimer in the documentation |
| 12 | * and/or other materials provided with the distribution. |
| 13 | * |
| 14 | * Neither the name of ARM nor the names of its contributors may be used |
| 15 | * to endorse or promote products derived from this software without specific |
| 16 | * prior written permission. |
| 17 | * |
| 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
| 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 28 | * POSSIBILITY OF SUCH DAMAGE. |
| 29 | */ |
| 30 | #include <assert.h> |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 31 | #include <bl_common.h> /* For ARRAY_SIZE */ |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 32 | #include <debug.h> |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 33 | #include <firmware_image_package.h> |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 34 | #include <io_driver.h> |
| 35 | #include <io_fip.h> |
| 36 | #include <io_memmap.h> |
| 37 | #include <io_storage.h> |
| 38 | #include <platform_def.h> |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 39 | #include <string.h> |
| 40 | |
| 41 | /* IO devices */ |
| 42 | static const io_dev_connector_t *fip_dev_con; |
| 43 | static uintptr_t fip_dev_handle; |
| 44 | static const io_dev_connector_t *memmap_dev_con; |
| 45 | static uintptr_t memmap_dev_handle; |
| 46 | |
| 47 | static const io_block_spec_t fip_block_spec = { |
| 48 | .offset = PLAT_ARM_FIP_BASE, |
| 49 | .length = PLAT_ARM_FIP_MAX_SIZE |
| 50 | }; |
| 51 | |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 52 | static const io_uuid_spec_t bl2_uuid_spec = { |
| 53 | .uuid = UUID_TRUSTED_BOOT_FIRMWARE_BL2, |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 54 | }; |
| 55 | |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 56 | static const io_uuid_spec_t bl30_uuid_spec = { |
| 57 | .uuid = UUID_SCP_FIRMWARE_BL30, |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 58 | }; |
| 59 | |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 60 | static const io_uuid_spec_t bl31_uuid_spec = { |
| 61 | .uuid = UUID_EL3_RUNTIME_FIRMWARE_BL31, |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 62 | }; |
| 63 | |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 64 | static const io_uuid_spec_t bl32_uuid_spec = { |
| 65 | .uuid = UUID_SECURE_PAYLOAD_BL32, |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 66 | }; |
| 67 | |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 68 | static const io_uuid_spec_t bl33_uuid_spec = { |
| 69 | .uuid = UUID_NON_TRUSTED_FIRMWARE_BL33, |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 70 | }; |
| 71 | |
| 72 | #if TRUSTED_BOARD_BOOT |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 73 | static const io_uuid_spec_t bl2_cert_uuid_spec = { |
| 74 | .uuid = UUID_TRUSTED_BOOT_FIRMWARE_BL2_CERT, |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 75 | }; |
| 76 | |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 77 | static const io_uuid_spec_t trusted_key_cert_uuid_spec = { |
| 78 | .uuid = UUID_TRUSTED_KEY_CERT, |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 79 | }; |
| 80 | |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 81 | static const io_uuid_spec_t bl30_key_cert_uuid_spec = { |
| 82 | .uuid = UUID_SCP_FIRMWARE_BL30_KEY_CERT, |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 83 | }; |
| 84 | |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 85 | static const io_uuid_spec_t bl31_key_cert_uuid_spec = { |
| 86 | .uuid = UUID_EL3_RUNTIME_FIRMWARE_BL31_KEY_CERT, |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 87 | }; |
| 88 | |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 89 | static const io_uuid_spec_t bl32_key_cert_uuid_spec = { |
| 90 | .uuid = UUID_SECURE_PAYLOAD_BL32_KEY_CERT, |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 91 | }; |
| 92 | |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 93 | static const io_uuid_spec_t bl33_key_cert_uuid_spec = { |
| 94 | .uuid = UUID_NON_TRUSTED_FIRMWARE_BL33_KEY_CERT, |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 95 | }; |
| 96 | |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 97 | static const io_uuid_spec_t bl30_cert_uuid_spec = { |
| 98 | .uuid = UUID_SCP_FIRMWARE_BL30_CERT, |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 99 | }; |
| 100 | |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 101 | static const io_uuid_spec_t bl31_cert_uuid_spec = { |
| 102 | .uuid = UUID_EL3_RUNTIME_FIRMWARE_BL31_CERT, |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 103 | }; |
| 104 | |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 105 | static const io_uuid_spec_t bl32_cert_uuid_spec = { |
| 106 | .uuid = UUID_SECURE_PAYLOAD_BL32_CERT, |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 107 | }; |
| 108 | |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 109 | static const io_uuid_spec_t bl33_cert_uuid_spec = { |
| 110 | .uuid = UUID_NON_TRUSTED_FIRMWARE_BL33_CERT, |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 111 | }; |
| 112 | #endif /* TRUSTED_BOARD_BOOT */ |
| 113 | |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 114 | |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 115 | static int open_fip(const uintptr_t spec); |
| 116 | static int open_memmap(const uintptr_t spec); |
| 117 | |
| 118 | struct plat_io_policy { |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 119 | uintptr_t *dev_handle; |
| 120 | uintptr_t image_spec; |
| 121 | int (*check)(const uintptr_t spec); |
| 122 | }; |
| 123 | |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 124 | /* By default, ARM platforms load images from the FIP */ |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 125 | static const struct plat_io_policy policies[] = { |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 126 | [FIP_IMAGE_ID] = { |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 127 | &memmap_dev_handle, |
| 128 | (uintptr_t)&fip_block_spec, |
| 129 | open_memmap |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 130 | }, |
| 131 | [BL2_IMAGE_ID] = { |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 132 | &fip_dev_handle, |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 133 | (uintptr_t)&bl2_uuid_spec, |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 134 | open_fip |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 135 | }, |
| 136 | [BL30_IMAGE_ID] = { |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 137 | &fip_dev_handle, |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 138 | (uintptr_t)&bl30_uuid_spec, |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 139 | open_fip |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 140 | }, |
| 141 | [BL31_IMAGE_ID] = { |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 142 | &fip_dev_handle, |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 143 | (uintptr_t)&bl31_uuid_spec, |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 144 | open_fip |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 145 | }, |
| 146 | [BL32_IMAGE_ID] = { |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 147 | &fip_dev_handle, |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 148 | (uintptr_t)&bl32_uuid_spec, |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 149 | open_fip |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 150 | }, |
| 151 | [BL33_IMAGE_ID] = { |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 152 | &fip_dev_handle, |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 153 | (uintptr_t)&bl33_uuid_spec, |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 154 | open_fip |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 155 | }, |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 156 | #if TRUSTED_BOARD_BOOT |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 157 | [BL2_CERT_ID] = { |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 158 | &fip_dev_handle, |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 159 | (uintptr_t)&bl2_cert_uuid_spec, |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 160 | open_fip |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 161 | }, |
| 162 | [TRUSTED_KEY_CERT_ID] = { |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 163 | &fip_dev_handle, |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 164 | (uintptr_t)&trusted_key_cert_uuid_spec, |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 165 | open_fip |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 166 | }, |
| 167 | [BL30_KEY_CERT_ID] = { |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 168 | &fip_dev_handle, |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 169 | (uintptr_t)&bl30_key_cert_uuid_spec, |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 170 | open_fip |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 171 | }, |
| 172 | [BL31_KEY_CERT_ID] = { |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 173 | &fip_dev_handle, |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 174 | (uintptr_t)&bl31_key_cert_uuid_spec, |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 175 | open_fip |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 176 | }, |
| 177 | [BL32_KEY_CERT_ID] = { |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 178 | &fip_dev_handle, |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 179 | (uintptr_t)&bl32_key_cert_uuid_spec, |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 180 | open_fip |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 181 | }, |
| 182 | [BL33_KEY_CERT_ID] = { |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 183 | &fip_dev_handle, |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 184 | (uintptr_t)&bl33_key_cert_uuid_spec, |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 185 | open_fip |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 186 | }, |
| 187 | [BL30_CERT_ID] = { |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 188 | &fip_dev_handle, |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 189 | (uintptr_t)&bl30_cert_uuid_spec, |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 190 | open_fip |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 191 | }, |
| 192 | [BL31_CERT_ID] = { |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 193 | &fip_dev_handle, |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 194 | (uintptr_t)&bl31_cert_uuid_spec, |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 195 | open_fip |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 196 | }, |
| 197 | [BL32_CERT_ID] = { |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 198 | &fip_dev_handle, |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 199 | (uintptr_t)&bl32_cert_uuid_spec, |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 200 | open_fip |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 201 | }, |
| 202 | [BL33_CERT_ID] = { |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 203 | &fip_dev_handle, |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 204 | (uintptr_t)&bl33_cert_uuid_spec, |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 205 | open_fip |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 206 | }, |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 207 | #endif /* TRUSTED_BOARD_BOOT */ |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 208 | }; |
| 209 | |
| 210 | |
| 211 | /* Weak definitions may be overridden in specific ARM standard platform */ |
| 212 | #pragma weak plat_arm_io_setup |
| 213 | #pragma weak plat_arm_get_alt_image_source |
| 214 | |
| 215 | |
| 216 | static int open_fip(const uintptr_t spec) |
| 217 | { |
| 218 | int result; |
| 219 | uintptr_t local_image_handle; |
| 220 | |
| 221 | /* See if a Firmware Image Package is available */ |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 222 | result = io_dev_init(fip_dev_handle, (uintptr_t)FIP_IMAGE_ID); |
Juan Castillo | 6e76206 | 2015-11-02 10:47:01 +0000 | [diff] [blame] | 223 | if (result == 0) { |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 224 | result = io_open(fip_dev_handle, spec, &local_image_handle); |
Juan Castillo | 6e76206 | 2015-11-02 10:47:01 +0000 | [diff] [blame] | 225 | if (result == 0) { |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 226 | VERBOSE("Using FIP\n"); |
| 227 | io_close(local_image_handle); |
| 228 | } |
| 229 | } |
| 230 | return result; |
| 231 | } |
| 232 | |
| 233 | |
| 234 | static int open_memmap(const uintptr_t spec) |
| 235 | { |
| 236 | int result; |
| 237 | uintptr_t local_image_handle; |
| 238 | |
| 239 | result = io_dev_init(memmap_dev_handle, (uintptr_t)NULL); |
Juan Castillo | 6e76206 | 2015-11-02 10:47:01 +0000 | [diff] [blame] | 240 | if (result == 0) { |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 241 | result = io_open(memmap_dev_handle, spec, &local_image_handle); |
Juan Castillo | 6e76206 | 2015-11-02 10:47:01 +0000 | [diff] [blame] | 242 | if (result == 0) { |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 243 | VERBOSE("Using Memmap\n"); |
| 244 | io_close(local_image_handle); |
| 245 | } |
| 246 | } |
| 247 | return result; |
| 248 | } |
| 249 | |
| 250 | |
| 251 | void arm_io_setup(void) |
| 252 | { |
| 253 | int io_result; |
| 254 | |
| 255 | io_result = register_io_dev_fip(&fip_dev_con); |
Juan Castillo | 6e76206 | 2015-11-02 10:47:01 +0000 | [diff] [blame] | 256 | assert(io_result == 0); |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 257 | |
| 258 | io_result = register_io_dev_memmap(&memmap_dev_con); |
Juan Castillo | 6e76206 | 2015-11-02 10:47:01 +0000 | [diff] [blame] | 259 | assert(io_result == 0); |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 260 | |
| 261 | /* Open connections to devices and cache the handles */ |
| 262 | io_result = io_dev_open(fip_dev_con, (uintptr_t)NULL, |
| 263 | &fip_dev_handle); |
Juan Castillo | 6e76206 | 2015-11-02 10:47:01 +0000 | [diff] [blame] | 264 | assert(io_result == 0); |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 265 | |
| 266 | io_result = io_dev_open(memmap_dev_con, (uintptr_t)NULL, |
| 267 | &memmap_dev_handle); |
Juan Castillo | 6e76206 | 2015-11-02 10:47:01 +0000 | [diff] [blame] | 268 | assert(io_result == 0); |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 269 | |
| 270 | /* Ignore improbable errors in release builds */ |
| 271 | (void)io_result; |
| 272 | } |
| 273 | |
| 274 | void plat_arm_io_setup(void) |
| 275 | { |
| 276 | arm_io_setup(); |
| 277 | } |
| 278 | |
| 279 | int plat_arm_get_alt_image_source( |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 280 | unsigned int image_id __attribute__((unused)), |
| 281 | uintptr_t *dev_handle __attribute__((unused)), |
| 282 | uintptr_t *image_spec __attribute__((unused))) |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 283 | { |
| 284 | /* By default do not try an alternative */ |
Juan Castillo | 6e76206 | 2015-11-02 10:47:01 +0000 | [diff] [blame] | 285 | return -ENOENT; |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 286 | } |
| 287 | |
| 288 | /* Return an IO device handle and specification which can be used to access |
| 289 | * an image. Use this to enforce platform load policy */ |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 290 | int plat_get_image_source(unsigned int image_id, uintptr_t *dev_handle, |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 291 | uintptr_t *image_spec) |
| 292 | { |
Juan Castillo | 6e76206 | 2015-11-02 10:47:01 +0000 | [diff] [blame] | 293 | int result; |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 294 | const struct plat_io_policy *policy; |
| 295 | |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 296 | assert(image_id < ARRAY_SIZE(policies)); |
| 297 | |
| 298 | policy = &policies[image_id]; |
| 299 | result = policy->check(policy->image_spec); |
Juan Castillo | 6e76206 | 2015-11-02 10:47:01 +0000 | [diff] [blame] | 300 | if (result == 0) { |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 301 | *image_spec = policy->image_spec; |
| 302 | *dev_handle = *(policy->dev_handle); |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 303 | } else { |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 304 | VERBOSE("Trying alternative IO\n"); |
| 305 | result = plat_arm_get_alt_image_source(image_id, dev_handle, |
| 306 | image_spec); |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 307 | } |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 308 | |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 309 | return result; |
| 310 | } |
Yatharth Kochar | 736a3bf | 2015-10-11 14:14:55 +0100 | [diff] [blame] | 311 | |
| 312 | /* |
| 313 | * See if a Firmware Image Package is available, |
| 314 | * by checking if TOC is valid or not. |
| 315 | */ |
| 316 | int arm_io_is_toc_valid(void) |
| 317 | { |
| 318 | int result; |
| 319 | |
| 320 | result = io_dev_init(fip_dev_handle, (uintptr_t)FIP_IMAGE_ID); |
| 321 | |
| 322 | return (result == 0); |
| 323 | } |
| 324 | |