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> 10 #include <common/desc_image_load.h> 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 23 bl_mem_params_node_t sp_mem_params_descs[MAX_SP_IDS]; 24 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; 31 unsigned int index = 0; 32 uint32_t val32; 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; 40 41 /* As libfdt use void *, we can't avoid this cast */ 42 const void *dtb = (void *)config; 43 44 /* Assert the node offset point to "arm,sp" compatible property */ 45 const char *compatible_str = "arm,sp"; 46 47 node = fdt_node_offset_by_compatible(dtb, -1, compatible_str); 48 if (node < 0) { 49 ERROR("FCONF: Can't find %s in dtb\n", compatible_str); 50 return node; 51 } 52 53 fdt_for_each_subnode(sp_node, dtb, node) { 54 if ((index == MAX_SP_IDS) || (sip_index == sip_end) 55 || (plat_index == plat_end)) { 56 ERROR("FCONF: Reached max number of SPs\n"); 57 return -1; 58 } 59 60 /* Read UUID */ 61 err = fdt_read_uint32_array(dtb, sp_node, "uuid", 4, 62 uuid_helper.word); 63 if (err < 0) { 64 ERROR("FCONF: cannot read SP uuid\n"); 65 return -1; 66 } 67 arm_sp.uuids[index] = uuid_helper; 68 VERBOSE("FCONF: %s UUID %x-%x-%x-%x load_addr=%lx\n", 69 __func__, 70 uuid_helper.word[0], 71 uuid_helper.word[1], 72 uuid_helper.word[2], 73 uuid_helper.word[3], 74 arm_sp.load_addr[index]); 75 76 /* Read Load address */ 77 err = fdt_read_uint32(dtb, sp_node, "load-address", &val32); 78 if (err < 0) { 79 ERROR("FCONF: cannot read SP load address\n"); 80 return -1; 81 } 82 arm_sp.load_addr[index] = val32; 83 84 /* Read owner field only for dualroot CoT */ 85 #if defined(ARM_COT_dualroot) 86 /* Owner is an optional field, no need to catch error */ 87 fdtw_read_string(dtb, sp_node, "owner", 88 arm_sp.owner[index], ARM_SP_OWNER_NAME_LEN); 89 #endif 90 /* If owner is empty mark it as SiP owned */ 91 if ((strncmp(arm_sp.owner[index], "SiP", 92 ARM_SP_OWNER_NAME_LEN) == 0) || 93 (strncmp(arm_sp.owner[index], "", 94 ARM_SP_OWNER_NAME_LEN) == 0)) { 95 is_plat_owned = false; 96 } else if (strcmp(arm_sp.owner[index], "Plat") == 0) { 97 is_plat_owned = true; 98 } else { 99 ERROR("FCONF: %s is not a valid SP owner\n", 100 arm_sp.owner[index]); 101 return -1; 102 } 103 /* 104 * Add SP information in mem param descriptor and IO policies 105 * structure. 106 */ 107 if (is_plat_owned) { 108 sp_mem_params_descs[index].image_id = plat_index; 109 policies[plat_index].image_spec = 110 (uintptr_t)&arm_sp.uuids[index]; 111 policies[plat_index].dev_handle = &fip_dev_handle; 112 policies[plat_index].check = open_fip; 113 plat_index++; 114 } else { 115 sp_mem_params_descs[index].image_id = sip_index; 116 policies[sip_index].image_spec = 117 (uintptr_t)&arm_sp.uuids[index]; 118 policies[sip_index].dev_handle = &fip_dev_handle; 119 policies[sip_index].check = open_fip; 120 sip_index++; 121 } 122 SET_PARAM_HEAD(&sp_mem_params_descs[index].image_info, 123 PARAM_IMAGE_BINARY, VERSION_2, 0); 124 sp_mem_params_descs[index].image_info.image_max_size = 125 ARM_SP_MAX_SIZE; 126 sp_mem_params_descs[index].next_handoff_image_id = 127 INVALID_IMAGE_ID; 128 sp_mem_params_descs[index].image_info.image_base = 129 arm_sp.load_addr[index]; 130 index++; 131 } 132 133 if ((sp_node < 0) && (sp_node != -FDT_ERR_NOTFOUND)) { 134 ERROR("%u: fdt_for_each_subnode(): %d\n", __LINE__, node); 135 return sp_node; 136 } 137 138 arm_sp.number_of_sp = index; 139 return 0; 140 } 141 142 FCONF_REGISTER_POPULATOR(TB_FW, arm_sp, fconf_populate_arm_sp); 143 144 #endif /* IMAGE_BL2 */ 145