Olivier Deprez | 93df21f | 2020-01-23 11:24:33 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2020, ARM Limited and Contributors. All rights reserved. |
| 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
| 7 | #include <assert.h> |
| 8 | |
| 9 | #include <common/debug.h> |
Manish Pandey | 1fa6ecb | 2020-02-25 11:38:19 +0000 | [diff] [blame] | 10 | #include <common/desc_image_load.h> |
Olivier Deprez | 93df21f | 2020-01-23 11:24:33 +0100 | [diff] [blame] | 11 | #include <common/fdt_wrappers.h> |
| 12 | #include <drivers/io/io_storage.h> |
| 13 | #include <lib/object_pool.h> |
| 14 | #include <libfdt.h> |
| 15 | #include <plat/arm/common/arm_fconf_getter.h> |
| 16 | #include <plat/arm/common/arm_fconf_io_storage.h> |
| 17 | #include <plat/arm/common/fconf_arm_sp_getter.h> |
| 18 | #include <platform_def.h> |
| 19 | #include <tools_share/firmware_image_package.h> |
| 20 | |
| 21 | #ifdef IMAGE_BL2 |
| 22 | |
Manish Pandey | 1fa6ecb | 2020-02-25 11:38:19 +0000 | [diff] [blame] | 23 | bl_mem_params_node_t sp_mem_params_descs[MAX_SP_IDS]; |
| 24 | |
Olivier Deprez | 93df21f | 2020-01-23 11:24:33 +0100 | [diff] [blame] | 25 | struct arm_sp_t arm_sp; |
| 26 | |
| 27 | int fconf_populate_arm_sp(uintptr_t config) |
| 28 | { |
| 29 | int sp_node, node, err; |
| 30 | union uuid_helper_t uuid_helper; |
Manish Pandey | 1fa6ecb | 2020-02-25 11:38:19 +0000 | [diff] [blame] | 31 | unsigned int index = 0; |
Andre Przywara | fe5bdf5 | 2020-03-26 11:22:37 +0000 | [diff] [blame] | 32 | uint32_t val32; |
Manish Pandey | aff8075 | 2020-07-31 16:15:16 +0100 | [diff] [blame] | 33 | bool is_plat_owned = false; |
| 34 | const unsigned int sip_start = SP_PKG1_ID; |
| 35 | unsigned int sip_index = sip_start; |
| 36 | const unsigned int sip_end = sip_start + MAX_SP_IDS / 2; |
| 37 | const unsigned int plat_start = SP_PKG5_ID; |
| 38 | unsigned int plat_index = plat_start; |
| 39 | const unsigned int plat_end = plat_start + MAX_SP_IDS / 2; |
Ruari Phipps | 57d48a0 | 2020-08-10 15:53:45 +0100 | [diff] [blame] | 40 | unsigned int j; |
Olivier Deprez | 93df21f | 2020-01-23 11:24:33 +0100 | [diff] [blame] | 41 | |
| 42 | /* As libfdt use void *, we can't avoid this cast */ |
| 43 | const void *dtb = (void *)config; |
| 44 | |
| 45 | /* Assert the node offset point to "arm,sp" compatible property */ |
| 46 | const char *compatible_str = "arm,sp"; |
| 47 | |
| 48 | node = fdt_node_offset_by_compatible(dtb, -1, compatible_str); |
| 49 | if (node < 0) { |
| 50 | ERROR("FCONF: Can't find %s in dtb\n", compatible_str); |
| 51 | return node; |
| 52 | } |
| 53 | |
| 54 | fdt_for_each_subnode(sp_node, dtb, node) { |
Manish Pandey | aff8075 | 2020-07-31 16:15:16 +0100 | [diff] [blame] | 55 | if ((index == MAX_SP_IDS) || (sip_index == sip_end) |
| 56 | || (plat_index == plat_end)) { |
Manish Pandey | 61ff717 | 2020-07-27 13:00:38 +0100 | [diff] [blame] | 57 | ERROR("FCONF: Reached max number of SPs\n"); |
| 58 | return -1; |
| 59 | } |
| 60 | |
Manish Pandey | aff8075 | 2020-07-31 16:15:16 +0100 | [diff] [blame] | 61 | /* Read UUID */ |
Andre Przywara | 6cf6a1b | 2020-03-30 23:21:13 +0100 | [diff] [blame] | 62 | err = fdt_read_uint32_array(dtb, sp_node, "uuid", 4, |
| 63 | uuid_helper.word); |
Olivier Deprez | 93df21f | 2020-01-23 11:24:33 +0100 | [diff] [blame] | 64 | if (err < 0) { |
| 65 | ERROR("FCONF: cannot read SP uuid\n"); |
| 66 | return -1; |
| 67 | } |
Ruari Phipps | 57d48a0 | 2020-08-10 15:53:45 +0100 | [diff] [blame] | 68 | |
| 69 | /* Convert uuid from big endian to little endian */ |
| 70 | for (j = 0U; j < 4U; j++) { |
| 71 | uuid_helper.word[j] = |
| 72 | ((uuid_helper.word[j] >> 24U) & 0xff) | |
| 73 | ((uuid_helper.word[j] << 8U) & 0xff0000) | |
| 74 | ((uuid_helper.word[j] >> 8U) & 0xff00) | |
| 75 | ((uuid_helper.word[j] << 24U) & 0xff000000); |
| 76 | } |
| 77 | |
Manish Pandey | 1fa6ecb | 2020-02-25 11:38:19 +0000 | [diff] [blame] | 78 | arm_sp.uuids[index] = uuid_helper; |
Olivier Deprez | 93df21f | 2020-01-23 11:24:33 +0100 | [diff] [blame] | 79 | VERBOSE("FCONF: %s UUID %x-%x-%x-%x load_addr=%lx\n", |
| 80 | __func__, |
| 81 | uuid_helper.word[0], |
| 82 | uuid_helper.word[1], |
| 83 | uuid_helper.word[2], |
| 84 | uuid_helper.word[3], |
Manish Pandey | 1fa6ecb | 2020-02-25 11:38:19 +0000 | [diff] [blame] | 85 | arm_sp.load_addr[index]); |
| 86 | |
Manish Pandey | aff8075 | 2020-07-31 16:15:16 +0100 | [diff] [blame] | 87 | /* Read Load address */ |
| 88 | err = fdt_read_uint32(dtb, sp_node, "load-address", &val32); |
| 89 | if (err < 0) { |
| 90 | ERROR("FCONF: cannot read SP load address\n"); |
| 91 | return -1; |
| 92 | } |
| 93 | arm_sp.load_addr[index] = val32; |
| 94 | |
| 95 | /* Read owner field only for dualroot CoT */ |
| 96 | #if defined(ARM_COT_dualroot) |
| 97 | /* Owner is an optional field, no need to catch error */ |
| 98 | fdtw_read_string(dtb, sp_node, "owner", |
| 99 | arm_sp.owner[index], ARM_SP_OWNER_NAME_LEN); |
| 100 | #endif |
| 101 | /* If owner is empty mark it as SiP owned */ |
| 102 | if ((strncmp(arm_sp.owner[index], "SiP", |
| 103 | ARM_SP_OWNER_NAME_LEN) == 0) || |
| 104 | (strncmp(arm_sp.owner[index], "", |
| 105 | ARM_SP_OWNER_NAME_LEN) == 0)) { |
| 106 | is_plat_owned = false; |
| 107 | } else if (strcmp(arm_sp.owner[index], "Plat") == 0) { |
| 108 | is_plat_owned = true; |
| 109 | } else { |
| 110 | ERROR("FCONF: %s is not a valid SP owner\n", |
| 111 | arm_sp.owner[index]); |
| 112 | return -1; |
| 113 | } |
| 114 | /* |
| 115 | * Add SP information in mem param descriptor and IO policies |
| 116 | * structure. |
| 117 | */ |
| 118 | if (is_plat_owned) { |
| 119 | sp_mem_params_descs[index].image_id = plat_index; |
| 120 | policies[plat_index].image_spec = |
| 121 | (uintptr_t)&arm_sp.uuids[index]; |
| 122 | policies[plat_index].dev_handle = &fip_dev_handle; |
| 123 | policies[plat_index].check = open_fip; |
| 124 | plat_index++; |
| 125 | } else { |
| 126 | sp_mem_params_descs[index].image_id = sip_index; |
| 127 | policies[sip_index].image_spec = |
| 128 | (uintptr_t)&arm_sp.uuids[index]; |
| 129 | policies[sip_index].dev_handle = &fip_dev_handle; |
| 130 | policies[sip_index].check = open_fip; |
| 131 | sip_index++; |
| 132 | } |
Manish Pandey | 1fa6ecb | 2020-02-25 11:38:19 +0000 | [diff] [blame] | 133 | SET_PARAM_HEAD(&sp_mem_params_descs[index].image_info, |
| 134 | PARAM_IMAGE_BINARY, VERSION_2, 0); |
| 135 | sp_mem_params_descs[index].image_info.image_max_size = |
| 136 | ARM_SP_MAX_SIZE; |
| 137 | sp_mem_params_descs[index].next_handoff_image_id = |
| 138 | INVALID_IMAGE_ID; |
| 139 | sp_mem_params_descs[index].image_info.image_base = |
| 140 | arm_sp.load_addr[index]; |
Manish Pandey | 1fa6ecb | 2020-02-25 11:38:19 +0000 | [diff] [blame] | 141 | index++; |
Olivier Deprez | 93df21f | 2020-01-23 11:24:33 +0100 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | if ((sp_node < 0) && (sp_node != -FDT_ERR_NOTFOUND)) { |
Manish Pandey | 61ff717 | 2020-07-27 13:00:38 +0100 | [diff] [blame] | 145 | ERROR("%u: fdt_for_each_subnode(): %d\n", __LINE__, node); |
Olivier Deprez | 93df21f | 2020-01-23 11:24:33 +0100 | [diff] [blame] | 146 | return sp_node; |
| 147 | } |
| 148 | |
Manish Pandey | 1fa6ecb | 2020-02-25 11:38:19 +0000 | [diff] [blame] | 149 | arm_sp.number_of_sp = index; |
Olivier Deprez | 93df21f | 2020-01-23 11:24:33 +0100 | [diff] [blame] | 150 | return 0; |
| 151 | } |
| 152 | |
Madhukar Pappireddy | 8151969 | 2019-12-06 15:46:42 -0600 | [diff] [blame] | 153 | FCONF_REGISTER_POPULATOR(TB_FW, arm_sp, fconf_populate_arm_sp); |
Olivier Deprez | 93df21f | 2020-01-23 11:24:33 +0100 | [diff] [blame] | 154 | |
| 155 | #endif /* IMAGE_BL2 */ |