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