Olivier Deprez | 93df21f | 2020-01-23 11:24:33 +0100 | [diff] [blame] | 1 | /* |
Imre Kis | 36286f6 | 2022-02-09 16:33:07 +0100 | [diff] [blame] | 2 | * Copyright (c) 2020-2022, ARM Limited and Contributors. All rights reserved. |
Olivier Deprez | 93df21f | 2020-01-23 11:24:33 +0100 | [diff] [blame] | 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 | const unsigned int sip_start = SP_PKG1_ID; |
| 34 | unsigned int sip_index = sip_start; |
Imre Kis | 36286f6 | 2022-02-09 16:33:07 +0100 | [diff] [blame] | 35 | #if defined(ARM_COT_dualroot) |
Manish Pandey | aff8075 | 2020-07-31 16:15:16 +0100 | [diff] [blame] | 36 | const unsigned int sip_end = sip_start + MAX_SP_IDS / 2; |
Imre Kis | 36286f6 | 2022-02-09 16:33:07 +0100 | [diff] [blame] | 37 | /* Allocating index range for platform SPs */ |
Manish Pandey | aff8075 | 2020-07-31 16:15:16 +0100 | [diff] [blame] | 38 | const unsigned int plat_start = SP_PKG5_ID; |
| 39 | unsigned int plat_index = plat_start; |
| 40 | const unsigned int plat_end = plat_start + MAX_SP_IDS / 2; |
Imre Kis | 36286f6 | 2022-02-09 16:33:07 +0100 | [diff] [blame] | 41 | bool is_plat_owned = false; |
| 42 | #endif /* ARM_COT_dualroot */ |
Olivier Deprez | 93df21f | 2020-01-23 11:24:33 +0100 | [diff] [blame] | 43 | |
| 44 | /* As libfdt use void *, we can't avoid this cast */ |
| 45 | const void *dtb = (void *)config; |
| 46 | |
| 47 | /* Assert the node offset point to "arm,sp" compatible property */ |
| 48 | const char *compatible_str = "arm,sp"; |
| 49 | |
| 50 | node = fdt_node_offset_by_compatible(dtb, -1, compatible_str); |
| 51 | if (node < 0) { |
| 52 | ERROR("FCONF: Can't find %s in dtb\n", compatible_str); |
| 53 | return node; |
| 54 | } |
| 55 | |
| 56 | fdt_for_each_subnode(sp_node, dtb, node) { |
Imre Kis | 36286f6 | 2022-02-09 16:33:07 +0100 | [diff] [blame] | 57 | if (index == MAX_SP_IDS) { |
Manish Pandey | 61ff717 | 2020-07-27 13:00:38 +0100 | [diff] [blame] | 58 | ERROR("FCONF: Reached max number of SPs\n"); |
| 59 | return -1; |
| 60 | } |
| 61 | |
Imre Kis | 36286f6 | 2022-02-09 16:33:07 +0100 | [diff] [blame] | 62 | #if defined(ARM_COT_dualroot) |
| 63 | if ((sip_index == sip_end) || (plat_index == plat_end)) { |
| 64 | ERROR("FCONF: Reached max number of plat/SiP SPs\n"); |
| 65 | return -1; |
| 66 | } |
| 67 | #endif /* ARM_COT_dualroot */ |
| 68 | |
Manish Pandey | aff8075 | 2020-07-31 16:15:16 +0100 | [diff] [blame] | 69 | /* Read UUID */ |
David Horstmann | b2df4c1 | 2021-04-08 14:50:21 +0100 | [diff] [blame] | 70 | err = fdtw_read_uuid(dtb, sp_node, "uuid", 16, |
| 71 | (uint8_t *)&uuid_helper); |
Olivier Deprez | 93df21f | 2020-01-23 11:24:33 +0100 | [diff] [blame] | 72 | if (err < 0) { |
| 73 | ERROR("FCONF: cannot read SP uuid\n"); |
| 74 | return -1; |
| 75 | } |
Ruari Phipps | 57d48a0 | 2020-08-10 15:53:45 +0100 | [diff] [blame] | 76 | |
Manish Pandey | 1fa6ecb | 2020-02-25 11:38:19 +0000 | [diff] [blame] | 77 | arm_sp.uuids[index] = uuid_helper; |
Sandrine Bailleux | 649d19b | 2021-10-22 14:44:42 +0200 | [diff] [blame] | 78 | |
| 79 | /* Read Load address */ |
| 80 | err = fdt_read_uint32(dtb, sp_node, "load-address", &val32); |
| 81 | if (err < 0) { |
| 82 | ERROR("FCONF: cannot read SP load address\n"); |
| 83 | return -1; |
| 84 | } |
| 85 | arm_sp.load_addr[index] = val32; |
| 86 | |
David Horstmann | b2df4c1 | 2021-04-08 14:50:21 +0100 | [diff] [blame] | 87 | VERBOSE("FCONF: %s UUID" |
| 88 | " %02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x" |
| 89 | " load_addr=%lx\n", |
Olivier Deprez | 93df21f | 2020-01-23 11:24:33 +0100 | [diff] [blame] | 90 | __func__, |
David Horstmann | b2df4c1 | 2021-04-08 14:50:21 +0100 | [diff] [blame] | 91 | uuid_helper.uuid_struct.time_low[0], uuid_helper.uuid_struct.time_low[1], |
| 92 | uuid_helper.uuid_struct.time_low[2], uuid_helper.uuid_struct.time_low[3], |
| 93 | uuid_helper.uuid_struct.time_mid[0], uuid_helper.uuid_struct.time_mid[1], |
| 94 | uuid_helper.uuid_struct.time_hi_and_version[0], |
| 95 | uuid_helper.uuid_struct.time_hi_and_version[1], |
| 96 | uuid_helper.uuid_struct.clock_seq_hi_and_reserved, |
| 97 | uuid_helper.uuid_struct.clock_seq_low, |
| 98 | uuid_helper.uuid_struct.node[0], uuid_helper.uuid_struct.node[1], |
| 99 | uuid_helper.uuid_struct.node[2], uuid_helper.uuid_struct.node[3], |
| 100 | uuid_helper.uuid_struct.node[4], uuid_helper.uuid_struct.node[5], |
Manish Pandey | 1fa6ecb | 2020-02-25 11:38:19 +0000 | [diff] [blame] | 101 | arm_sp.load_addr[index]); |
| 102 | |
Manish Pandey | aff8075 | 2020-07-31 16:15:16 +0100 | [diff] [blame] | 103 | /* Read owner field only for dualroot CoT */ |
| 104 | #if defined(ARM_COT_dualroot) |
| 105 | /* Owner is an optional field, no need to catch error */ |
| 106 | fdtw_read_string(dtb, sp_node, "owner", |
| 107 | arm_sp.owner[index], ARM_SP_OWNER_NAME_LEN); |
Imre Kis | 36286f6 | 2022-02-09 16:33:07 +0100 | [diff] [blame] | 108 | |
Manish Pandey | aff8075 | 2020-07-31 16:15:16 +0100 | [diff] [blame] | 109 | /* If owner is empty mark it as SiP owned */ |
| 110 | if ((strncmp(arm_sp.owner[index], "SiP", |
| 111 | ARM_SP_OWNER_NAME_LEN) == 0) || |
| 112 | (strncmp(arm_sp.owner[index], "", |
| 113 | ARM_SP_OWNER_NAME_LEN) == 0)) { |
| 114 | is_plat_owned = false; |
| 115 | } else if (strcmp(arm_sp.owner[index], "Plat") == 0) { |
| 116 | is_plat_owned = true; |
| 117 | } else { |
| 118 | ERROR("FCONF: %s is not a valid SP owner\n", |
| 119 | arm_sp.owner[index]); |
| 120 | return -1; |
| 121 | } |
| 122 | /* |
| 123 | * Add SP information in mem param descriptor and IO policies |
| 124 | * structure. |
| 125 | */ |
| 126 | if (is_plat_owned) { |
| 127 | sp_mem_params_descs[index].image_id = plat_index; |
| 128 | policies[plat_index].image_spec = |
| 129 | (uintptr_t)&arm_sp.uuids[index]; |
| 130 | policies[plat_index].dev_handle = &fip_dev_handle; |
| 131 | policies[plat_index].check = open_fip; |
| 132 | plat_index++; |
Imre Kis | 36286f6 | 2022-02-09 16:33:07 +0100 | [diff] [blame] | 133 | } else |
| 134 | #endif /* ARM_COT_dualroot */ |
| 135 | { |
Manish Pandey | aff8075 | 2020-07-31 16:15:16 +0100 | [diff] [blame] | 136 | sp_mem_params_descs[index].image_id = sip_index; |
| 137 | policies[sip_index].image_spec = |
| 138 | (uintptr_t)&arm_sp.uuids[index]; |
| 139 | policies[sip_index].dev_handle = &fip_dev_handle; |
| 140 | policies[sip_index].check = open_fip; |
| 141 | sip_index++; |
| 142 | } |
Manish Pandey | 1fa6ecb | 2020-02-25 11:38:19 +0000 | [diff] [blame] | 143 | SET_PARAM_HEAD(&sp_mem_params_descs[index].image_info, |
| 144 | PARAM_IMAGE_BINARY, VERSION_2, 0); |
| 145 | sp_mem_params_descs[index].image_info.image_max_size = |
| 146 | ARM_SP_MAX_SIZE; |
| 147 | sp_mem_params_descs[index].next_handoff_image_id = |
| 148 | INVALID_IMAGE_ID; |
| 149 | sp_mem_params_descs[index].image_info.image_base = |
| 150 | arm_sp.load_addr[index]; |
Manish Pandey | 1fa6ecb | 2020-02-25 11:38:19 +0000 | [diff] [blame] | 151 | index++; |
Olivier Deprez | 93df21f | 2020-01-23 11:24:33 +0100 | [diff] [blame] | 152 | } |
| 153 | |
| 154 | if ((sp_node < 0) && (sp_node != -FDT_ERR_NOTFOUND)) { |
Manish Pandey | 61ff717 | 2020-07-27 13:00:38 +0100 | [diff] [blame] | 155 | ERROR("%u: fdt_for_each_subnode(): %d\n", __LINE__, node); |
Olivier Deprez | 93df21f | 2020-01-23 11:24:33 +0100 | [diff] [blame] | 156 | return sp_node; |
| 157 | } |
| 158 | |
Manish Pandey | 1fa6ecb | 2020-02-25 11:38:19 +0000 | [diff] [blame] | 159 | arm_sp.number_of_sp = index; |
Olivier Deprez | 93df21f | 2020-01-23 11:24:33 +0100 | [diff] [blame] | 160 | return 0; |
| 161 | } |
| 162 | |
Madhukar Pappireddy | 8151969 | 2019-12-06 15:46:42 -0600 | [diff] [blame] | 163 | FCONF_REGISTER_POPULATOR(TB_FW, arm_sp, fconf_populate_arm_sp); |
Olivier Deprez | 93df21f | 2020-01-23 11:24:33 +0100 | [diff] [blame] | 164 | |
| 165 | #endif /* IMAGE_BL2 */ |