Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 1 | /* |
Summer Qin | 8072678 | 2017-04-20 16:28:39 +0100 | [diff] [blame] | 2 | * Copyright (c) 2015-2017, ARM Limited and Contributors. All rights reserved. |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 3 | * |
dp-arm | fa3cf0b | 2017-05-03 09:38:09 +0100 | [diff] [blame] | 4 | * SPDX-License-Identifier: BSD-3-Clause |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 5 | */ |
| 6 | #include <assert.h> |
| 7 | #include <debug.h> |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 8 | #include <firmware_image_package.h> |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 9 | #include <io_driver.h> |
| 10 | #include <io_fip.h> |
| 11 | #include <io_memmap.h> |
| 12 | #include <io_storage.h> |
| 13 | #include <platform_def.h> |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 14 | #include <string.h> |
Sandrine Bailleux | 7659a26 | 2016-07-05 09:55:03 +0100 | [diff] [blame] | 15 | #include <utils.h> |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 16 | |
| 17 | /* IO devices */ |
| 18 | static const io_dev_connector_t *fip_dev_con; |
| 19 | static uintptr_t fip_dev_handle; |
| 20 | static const io_dev_connector_t *memmap_dev_con; |
| 21 | static uintptr_t memmap_dev_handle; |
| 22 | |
| 23 | static const io_block_spec_t fip_block_spec = { |
| 24 | .offset = PLAT_ARM_FIP_BASE, |
| 25 | .length = PLAT_ARM_FIP_MAX_SIZE |
| 26 | }; |
| 27 | |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 28 | static const io_uuid_spec_t bl2_uuid_spec = { |
| 29 | .uuid = UUID_TRUSTED_BOOT_FIRMWARE_BL2, |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 30 | }; |
| 31 | |
Juan Castillo | a72b647 | 2015-12-10 15:49:17 +0000 | [diff] [blame] | 32 | static const io_uuid_spec_t scp_bl2_uuid_spec = { |
| 33 | .uuid = UUID_SCP_FIRMWARE_SCP_BL2, |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 34 | }; |
| 35 | |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 36 | static const io_uuid_spec_t bl31_uuid_spec = { |
| 37 | .uuid = UUID_EL3_RUNTIME_FIRMWARE_BL31, |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 38 | }; |
| 39 | |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 40 | static const io_uuid_spec_t bl32_uuid_spec = { |
| 41 | .uuid = UUID_SECURE_PAYLOAD_BL32, |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 42 | }; |
| 43 | |
Summer Qin | 8072678 | 2017-04-20 16:28:39 +0100 | [diff] [blame] | 44 | static const io_uuid_spec_t bl32_extra1_uuid_spec = { |
| 45 | .uuid = UUID_SECURE_PAYLOAD_BL32_EXTRA1, |
| 46 | }; |
| 47 | |
| 48 | static const io_uuid_spec_t bl32_extra2_uuid_spec = { |
| 49 | .uuid = UUID_SECURE_PAYLOAD_BL32_EXTRA2, |
| 50 | }; |
| 51 | |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 52 | static const io_uuid_spec_t bl33_uuid_spec = { |
| 53 | .uuid = UUID_NON_TRUSTED_FIRMWARE_BL33, |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 54 | }; |
| 55 | |
| 56 | #if TRUSTED_BOARD_BOOT |
Juan Castillo | be80120 | 2015-12-03 10:19:21 +0000 | [diff] [blame] | 57 | static const io_uuid_spec_t tb_fw_cert_uuid_spec = { |
| 58 | .uuid = UUID_TRUSTED_BOOT_FW_CERT, |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 59 | }; |
| 60 | |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 61 | static const io_uuid_spec_t trusted_key_cert_uuid_spec = { |
| 62 | .uuid = UUID_TRUSTED_KEY_CERT, |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 63 | }; |
| 64 | |
Juan Castillo | be80120 | 2015-12-03 10:19:21 +0000 | [diff] [blame] | 65 | static const io_uuid_spec_t scp_fw_key_cert_uuid_spec = { |
| 66 | .uuid = UUID_SCP_FW_KEY_CERT, |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 67 | }; |
| 68 | |
Juan Castillo | be80120 | 2015-12-03 10:19:21 +0000 | [diff] [blame] | 69 | static const io_uuid_spec_t soc_fw_key_cert_uuid_spec = { |
| 70 | .uuid = UUID_SOC_FW_KEY_CERT, |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 71 | }; |
| 72 | |
Juan Castillo | be80120 | 2015-12-03 10:19:21 +0000 | [diff] [blame] | 73 | static const io_uuid_spec_t tos_fw_key_cert_uuid_spec = { |
| 74 | .uuid = UUID_TRUSTED_OS_FW_KEY_CERT, |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 75 | }; |
| 76 | |
Juan Castillo | be80120 | 2015-12-03 10:19:21 +0000 | [diff] [blame] | 77 | static const io_uuid_spec_t nt_fw_key_cert_uuid_spec = { |
| 78 | .uuid = UUID_NON_TRUSTED_FW_KEY_CERT, |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 79 | }; |
| 80 | |
Juan Castillo | be80120 | 2015-12-03 10:19:21 +0000 | [diff] [blame] | 81 | static const io_uuid_spec_t scp_fw_cert_uuid_spec = { |
| 82 | .uuid = UUID_SCP_FW_CONTENT_CERT, |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 83 | }; |
| 84 | |
Juan Castillo | be80120 | 2015-12-03 10:19:21 +0000 | [diff] [blame] | 85 | static const io_uuid_spec_t soc_fw_cert_uuid_spec = { |
| 86 | .uuid = UUID_SOC_FW_CONTENT_CERT, |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 87 | }; |
| 88 | |
Juan Castillo | be80120 | 2015-12-03 10:19:21 +0000 | [diff] [blame] | 89 | static const io_uuid_spec_t tos_fw_cert_uuid_spec = { |
| 90 | .uuid = UUID_TRUSTED_OS_FW_CONTENT_CERT, |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 91 | }; |
| 92 | |
Juan Castillo | be80120 | 2015-12-03 10:19:21 +0000 | [diff] [blame] | 93 | static const io_uuid_spec_t nt_fw_cert_uuid_spec = { |
| 94 | .uuid = UUID_NON_TRUSTED_FW_CONTENT_CERT, |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 95 | }; |
| 96 | #endif /* TRUSTED_BOARD_BOOT */ |
| 97 | |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 98 | |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 99 | static int open_fip(const uintptr_t spec); |
| 100 | static int open_memmap(const uintptr_t spec); |
| 101 | |
| 102 | struct plat_io_policy { |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 103 | uintptr_t *dev_handle; |
| 104 | uintptr_t image_spec; |
| 105 | int (*check)(const uintptr_t spec); |
| 106 | }; |
| 107 | |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 108 | /* By default, ARM platforms load images from the FIP */ |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 109 | static const struct plat_io_policy policies[] = { |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 110 | [FIP_IMAGE_ID] = { |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 111 | &memmap_dev_handle, |
| 112 | (uintptr_t)&fip_block_spec, |
| 113 | open_memmap |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 114 | }, |
| 115 | [BL2_IMAGE_ID] = { |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 116 | &fip_dev_handle, |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 117 | (uintptr_t)&bl2_uuid_spec, |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 118 | open_fip |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 119 | }, |
Juan Castillo | a72b647 | 2015-12-10 15:49:17 +0000 | [diff] [blame] | 120 | [SCP_BL2_IMAGE_ID] = { |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 121 | &fip_dev_handle, |
Juan Castillo | a72b647 | 2015-12-10 15:49:17 +0000 | [diff] [blame] | 122 | (uintptr_t)&scp_bl2_uuid_spec, |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 123 | open_fip |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 124 | }, |
| 125 | [BL31_IMAGE_ID] = { |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 126 | &fip_dev_handle, |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 127 | (uintptr_t)&bl31_uuid_spec, |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 128 | open_fip |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 129 | }, |
| 130 | [BL32_IMAGE_ID] = { |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 131 | &fip_dev_handle, |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 132 | (uintptr_t)&bl32_uuid_spec, |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 133 | open_fip |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 134 | }, |
Summer Qin | 8072678 | 2017-04-20 16:28:39 +0100 | [diff] [blame] | 135 | [BL32_EXTRA1_IMAGE_ID] = { |
| 136 | &fip_dev_handle, |
| 137 | (uintptr_t)&bl32_extra1_uuid_spec, |
| 138 | open_fip |
| 139 | }, |
| 140 | [BL32_EXTRA2_IMAGE_ID] = { |
| 141 | &fip_dev_handle, |
| 142 | (uintptr_t)&bl32_extra2_uuid_spec, |
| 143 | open_fip |
| 144 | }, |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 145 | [BL33_IMAGE_ID] = { |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 146 | &fip_dev_handle, |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 147 | (uintptr_t)&bl33_uuid_spec, |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 148 | open_fip |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 149 | }, |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 150 | #if TRUSTED_BOARD_BOOT |
Juan Castillo | be80120 | 2015-12-03 10:19:21 +0000 | [diff] [blame] | 151 | [TRUSTED_BOOT_FW_CERT_ID] = { |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 152 | &fip_dev_handle, |
Juan Castillo | be80120 | 2015-12-03 10:19:21 +0000 | [diff] [blame] | 153 | (uintptr_t)&tb_fw_cert_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 | }, |
| 156 | [TRUSTED_KEY_CERT_ID] = { |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 157 | &fip_dev_handle, |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 158 | (uintptr_t)&trusted_key_cert_uuid_spec, |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 159 | open_fip |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 160 | }, |
Juan Castillo | be80120 | 2015-12-03 10:19:21 +0000 | [diff] [blame] | 161 | [SCP_FW_KEY_CERT_ID] = { |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 162 | &fip_dev_handle, |
Juan Castillo | be80120 | 2015-12-03 10:19:21 +0000 | [diff] [blame] | 163 | (uintptr_t)&scp_fw_key_cert_uuid_spec, |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 164 | open_fip |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 165 | }, |
Juan Castillo | be80120 | 2015-12-03 10:19:21 +0000 | [diff] [blame] | 166 | [SOC_FW_KEY_CERT_ID] = { |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 167 | &fip_dev_handle, |
Juan Castillo | be80120 | 2015-12-03 10:19:21 +0000 | [diff] [blame] | 168 | (uintptr_t)&soc_fw_key_cert_uuid_spec, |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 169 | open_fip |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 170 | }, |
Juan Castillo | be80120 | 2015-12-03 10:19:21 +0000 | [diff] [blame] | 171 | [TRUSTED_OS_FW_KEY_CERT_ID] = { |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 172 | &fip_dev_handle, |
Juan Castillo | be80120 | 2015-12-03 10:19:21 +0000 | [diff] [blame] | 173 | (uintptr_t)&tos_fw_key_cert_uuid_spec, |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 174 | open_fip |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 175 | }, |
Juan Castillo | be80120 | 2015-12-03 10:19:21 +0000 | [diff] [blame] | 176 | [NON_TRUSTED_FW_KEY_CERT_ID] = { |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 177 | &fip_dev_handle, |
Juan Castillo | be80120 | 2015-12-03 10:19:21 +0000 | [diff] [blame] | 178 | (uintptr_t)&nt_fw_key_cert_uuid_spec, |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 179 | open_fip |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 180 | }, |
Juan Castillo | be80120 | 2015-12-03 10:19:21 +0000 | [diff] [blame] | 181 | [SCP_FW_CONTENT_CERT_ID] = { |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 182 | &fip_dev_handle, |
Juan Castillo | be80120 | 2015-12-03 10:19:21 +0000 | [diff] [blame] | 183 | (uintptr_t)&scp_fw_cert_uuid_spec, |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 184 | open_fip |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 185 | }, |
Juan Castillo | be80120 | 2015-12-03 10:19:21 +0000 | [diff] [blame] | 186 | [SOC_FW_CONTENT_CERT_ID] = { |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 187 | &fip_dev_handle, |
Juan Castillo | be80120 | 2015-12-03 10:19:21 +0000 | [diff] [blame] | 188 | (uintptr_t)&soc_fw_cert_uuid_spec, |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 189 | open_fip |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 190 | }, |
Juan Castillo | be80120 | 2015-12-03 10:19:21 +0000 | [diff] [blame] | 191 | [TRUSTED_OS_FW_CONTENT_CERT_ID] = { |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 192 | &fip_dev_handle, |
Juan Castillo | be80120 | 2015-12-03 10:19:21 +0000 | [diff] [blame] | 193 | (uintptr_t)&tos_fw_cert_uuid_spec, |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 194 | open_fip |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 195 | }, |
Juan Castillo | be80120 | 2015-12-03 10:19:21 +0000 | [diff] [blame] | 196 | [NON_TRUSTED_FW_CONTENT_CERT_ID] = { |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 197 | &fip_dev_handle, |
Juan Castillo | be80120 | 2015-12-03 10:19:21 +0000 | [diff] [blame] | 198 | (uintptr_t)&nt_fw_cert_uuid_spec, |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 199 | open_fip |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 200 | }, |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 201 | #endif /* TRUSTED_BOARD_BOOT */ |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 202 | }; |
| 203 | |
| 204 | |
| 205 | /* Weak definitions may be overridden in specific ARM standard platform */ |
| 206 | #pragma weak plat_arm_io_setup |
| 207 | #pragma weak plat_arm_get_alt_image_source |
| 208 | |
| 209 | |
| 210 | static int open_fip(const uintptr_t spec) |
| 211 | { |
| 212 | int result; |
| 213 | uintptr_t local_image_handle; |
| 214 | |
| 215 | /* See if a Firmware Image Package is available */ |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 216 | result = io_dev_init(fip_dev_handle, (uintptr_t)FIP_IMAGE_ID); |
Juan Castillo | 6e76206 | 2015-11-02 10:47:01 +0000 | [diff] [blame] | 217 | if (result == 0) { |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 218 | result = io_open(fip_dev_handle, spec, &local_image_handle); |
Juan Castillo | 6e76206 | 2015-11-02 10:47:01 +0000 | [diff] [blame] | 219 | if (result == 0) { |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 220 | VERBOSE("Using FIP\n"); |
| 221 | io_close(local_image_handle); |
| 222 | } |
| 223 | } |
| 224 | return result; |
| 225 | } |
| 226 | |
| 227 | |
| 228 | static int open_memmap(const uintptr_t spec) |
| 229 | { |
| 230 | int result; |
| 231 | uintptr_t local_image_handle; |
| 232 | |
| 233 | result = io_dev_init(memmap_dev_handle, (uintptr_t)NULL); |
Juan Castillo | 6e76206 | 2015-11-02 10:47:01 +0000 | [diff] [blame] | 234 | if (result == 0) { |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 235 | result = io_open(memmap_dev_handle, spec, &local_image_handle); |
Juan Castillo | 6e76206 | 2015-11-02 10:47:01 +0000 | [diff] [blame] | 236 | if (result == 0) { |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 237 | VERBOSE("Using Memmap\n"); |
| 238 | io_close(local_image_handle); |
| 239 | } |
| 240 | } |
| 241 | return result; |
| 242 | } |
| 243 | |
| 244 | |
| 245 | void arm_io_setup(void) |
| 246 | { |
| 247 | int io_result; |
| 248 | |
| 249 | io_result = register_io_dev_fip(&fip_dev_con); |
Juan Castillo | 6e76206 | 2015-11-02 10:47:01 +0000 | [diff] [blame] | 250 | assert(io_result == 0); |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 251 | |
| 252 | io_result = register_io_dev_memmap(&memmap_dev_con); |
Juan Castillo | 6e76206 | 2015-11-02 10:47:01 +0000 | [diff] [blame] | 253 | assert(io_result == 0); |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 254 | |
| 255 | /* Open connections to devices and cache the handles */ |
| 256 | io_result = io_dev_open(fip_dev_con, (uintptr_t)NULL, |
| 257 | &fip_dev_handle); |
Juan Castillo | 6e76206 | 2015-11-02 10:47:01 +0000 | [diff] [blame] | 258 | assert(io_result == 0); |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 259 | |
| 260 | io_result = io_dev_open(memmap_dev_con, (uintptr_t)NULL, |
| 261 | &memmap_dev_handle); |
Juan Castillo | 6e76206 | 2015-11-02 10:47:01 +0000 | [diff] [blame] | 262 | assert(io_result == 0); |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 263 | |
| 264 | /* Ignore improbable errors in release builds */ |
| 265 | (void)io_result; |
| 266 | } |
| 267 | |
| 268 | void plat_arm_io_setup(void) |
| 269 | { |
| 270 | arm_io_setup(); |
| 271 | } |
| 272 | |
| 273 | int plat_arm_get_alt_image_source( |
Soren Brinkmann | 46dd170 | 2016-01-14 10:11:05 -0800 | [diff] [blame] | 274 | unsigned int image_id __unused, |
| 275 | uintptr_t *dev_handle __unused, |
| 276 | uintptr_t *image_spec __unused) |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 277 | { |
| 278 | /* By default do not try an alternative */ |
Juan Castillo | 6e76206 | 2015-11-02 10:47:01 +0000 | [diff] [blame] | 279 | return -ENOENT; |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 280 | } |
| 281 | |
| 282 | /* Return an IO device handle and specification which can be used to access |
| 283 | * an image. Use this to enforce platform load policy */ |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 284 | 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] | 285 | uintptr_t *image_spec) |
| 286 | { |
Juan Castillo | 6e76206 | 2015-11-02 10:47:01 +0000 | [diff] [blame] | 287 | int result; |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 288 | const struct plat_io_policy *policy; |
| 289 | |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 290 | assert(image_id < ARRAY_SIZE(policies)); |
| 291 | |
| 292 | policy = &policies[image_id]; |
| 293 | result = policy->check(policy->image_spec); |
Juan Castillo | 6e76206 | 2015-11-02 10:47:01 +0000 | [diff] [blame] | 294 | if (result == 0) { |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 295 | *image_spec = policy->image_spec; |
| 296 | *dev_handle = *(policy->dev_handle); |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 297 | } else { |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 298 | VERBOSE("Trying alternative IO\n"); |
| 299 | result = plat_arm_get_alt_image_source(image_id, dev_handle, |
| 300 | image_spec); |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 301 | } |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 302 | |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 303 | return result; |
| 304 | } |
Yatharth Kochar | 736a3bf | 2015-10-11 14:14:55 +0100 | [diff] [blame] | 305 | |
| 306 | /* |
| 307 | * See if a Firmware Image Package is available, |
| 308 | * by checking if TOC is valid or not. |
| 309 | */ |
| 310 | int arm_io_is_toc_valid(void) |
| 311 | { |
| 312 | int result; |
| 313 | |
| 314 | result = io_dev_init(fip_dev_handle, (uintptr_t)FIP_IMAGE_ID); |
| 315 | |
| 316 | return (result == 0); |
| 317 | } |
| 318 | |