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; |
| 32 | const unsigned int sp_start_index = MAX_NUMBER_IDS - MAX_SP_IDS; |
Olivier Deprez | 93df21f | 2020-01-23 11:24:33 +0100 | [diff] [blame] | 33 | |
| 34 | /* As libfdt use void *, we can't avoid this cast */ |
| 35 | const void *dtb = (void *)config; |
| 36 | |
| 37 | /* Assert the node offset point to "arm,sp" compatible property */ |
| 38 | const char *compatible_str = "arm,sp"; |
| 39 | |
| 40 | node = fdt_node_offset_by_compatible(dtb, -1, compatible_str); |
| 41 | if (node < 0) { |
| 42 | ERROR("FCONF: Can't find %s in dtb\n", compatible_str); |
| 43 | return node; |
| 44 | } |
| 45 | |
| 46 | fdt_for_each_subnode(sp_node, dtb, node) { |
| 47 | err = fdtw_read_array(dtb, sp_node, "uuid", 4, |
| 48 | &uuid_helper.word); |
| 49 | if (err < 0) { |
| 50 | ERROR("FCONF: cannot read SP uuid\n"); |
| 51 | return -1; |
| 52 | } |
| 53 | |
Manish Pandey | 1fa6ecb | 2020-02-25 11:38:19 +0000 | [diff] [blame] | 54 | arm_sp.uuids[index] = uuid_helper; |
Olivier Deprez | 93df21f | 2020-01-23 11:24:33 +0100 | [diff] [blame] | 55 | |
| 56 | err = fdtw_read_cells(dtb, sp_node, "load-address", 1, |
Manish Pandey | 1fa6ecb | 2020-02-25 11:38:19 +0000 | [diff] [blame] | 57 | &arm_sp.load_addr[index]); |
Olivier Deprez | 93df21f | 2020-01-23 11:24:33 +0100 | [diff] [blame] | 58 | if (err < 0) { |
| 59 | ERROR("FCONF: cannot read SP load address\n"); |
| 60 | return -1; |
| 61 | } |
| 62 | |
| 63 | VERBOSE("FCONF: %s UUID %x-%x-%x-%x load_addr=%lx\n", |
| 64 | __func__, |
| 65 | uuid_helper.word[0], |
| 66 | uuid_helper.word[1], |
| 67 | uuid_helper.word[2], |
| 68 | uuid_helper.word[3], |
Manish Pandey | 1fa6ecb | 2020-02-25 11:38:19 +0000 | [diff] [blame] | 69 | arm_sp.load_addr[index]); |
| 70 | |
| 71 | /* Add SP information in mem param descriptor */ |
| 72 | sp_mem_params_descs[index].image_id = sp_start_index + index; |
| 73 | SET_PARAM_HEAD(&sp_mem_params_descs[index].image_info, |
| 74 | PARAM_IMAGE_BINARY, VERSION_2, 0); |
| 75 | sp_mem_params_descs[index].image_info.image_max_size = |
| 76 | ARM_SP_MAX_SIZE; |
| 77 | sp_mem_params_descs[index].next_handoff_image_id = |
| 78 | INVALID_IMAGE_ID; |
| 79 | sp_mem_params_descs[index].image_info.image_base = |
| 80 | arm_sp.load_addr[index]; |
Olivier Deprez | 93df21f | 2020-01-23 11:24:33 +0100 | [diff] [blame] | 81 | |
Manish Pandey | 1fa6ecb | 2020-02-25 11:38:19 +0000 | [diff] [blame] | 82 | /* Add SP information in IO policies structure */ |
| 83 | policies[sp_start_index + index].image_spec = |
| 84 | (uintptr_t)&arm_sp.uuids[index]; |
| 85 | policies[sp_start_index + index].dev_handle = &fip_dev_handle; |
| 86 | policies[sp_start_index + index].check = open_fip; |
Olivier Deprez | 93df21f | 2020-01-23 11:24:33 +0100 | [diff] [blame] | 87 | |
Manish Pandey | 1fa6ecb | 2020-02-25 11:38:19 +0000 | [diff] [blame] | 88 | index++; |
| 89 | |
| 90 | if (index >= MAX_SP_IDS) { |
Olivier Deprez | 93df21f | 2020-01-23 11:24:33 +0100 | [diff] [blame] | 91 | ERROR("FCONF: reached max number of SPs\n"); |
| 92 | return -1; |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | if ((sp_node < 0) && (sp_node != -FDT_ERR_NOTFOUND)) { |
| 97 | ERROR("%d: fdt_for_each_subnode(): %d\n", __LINE__, node); |
| 98 | return sp_node; |
| 99 | } |
| 100 | |
Manish Pandey | 1fa6ecb | 2020-02-25 11:38:19 +0000 | [diff] [blame] | 101 | arm_sp.number_of_sp = index; |
Olivier Deprez | 93df21f | 2020-01-23 11:24:33 +0100 | [diff] [blame] | 102 | return 0; |
| 103 | } |
| 104 | |
Madhukar Pappireddy | 8151969 | 2019-12-06 15:46:42 -0600 | [diff] [blame] | 105 | FCONF_REGISTER_POPULATOR(TB_FW, arm_sp, fconf_populate_arm_sp); |
Olivier Deprez | 93df21f | 2020-01-23 11:24:33 +0100 | [diff] [blame] | 106 | |
| 107 | #endif /* IMAGE_BL2 */ |