Louis Mayencourt | 6d2b573 | 2019-12-17 13:17:25 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2019-2020, Arm Limited. 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/fdt_wrappers.h> |
| 11 | #include <lib/fconf/fconf_dyn_cfg_getter.h> |
| 12 | #include <lib/object_pool.h> |
| 13 | #include <libfdt.h> |
| 14 | |
Alexei Fedorov | 40e7d6c | 2020-07-13 14:10:00 +0100 | [diff] [blame] | 15 | /* We currently use FW, TB_FW, SOC_FW, TOS_FW, NT_FW and HW configs */ |
Manish V Badarkhe | bb533c7 | 2020-06-11 22:17:30 +0100 | [diff] [blame] | 16 | #define MAX_DTB_INFO U(6) |
Manish V Badarkhe | 6a91e59 | 2020-07-15 05:08:37 +0100 | [diff] [blame] | 17 | /* |
| 18 | * Compile time assert if FW_CONFIG_ID is 0 which is more |
| 19 | * unlikely as 0 is a valid image ID for FIP as per the current |
| 20 | * code but still to avoid code breakage in case of unlikely |
| 21 | * event when image IDs get changed. |
| 22 | */ |
| 23 | CASSERT(FW_CONFIG_ID != U(0), assert_invalid_fw_config_id); |
Louis Mayencourt | 6d2b573 | 2019-12-17 13:17:25 +0000 | [diff] [blame] | 24 | |
| 25 | static struct dyn_cfg_dtb_info_t dtb_infos[MAX_DTB_INFO]; |
| 26 | static OBJECT_POOL_ARRAY(dtb_info_pool, dtb_infos); |
Manish V Badarkhe | 99a8e14 | 2020-06-11 22:32:11 +0100 | [diff] [blame] | 27 | |
| 28 | /* |
Manish V Badarkhe | 6a91e59 | 2020-07-15 05:08:37 +0100 | [diff] [blame] | 29 | * This function is used to alloc memory for config information from |
| 30 | * global pool and set the configuration information. |
Manish V Badarkhe | 99a8e14 | 2020-06-11 22:32:11 +0100 | [diff] [blame] | 31 | */ |
Manish V Badarkhe | 6a91e59 | 2020-07-15 05:08:37 +0100 | [diff] [blame] | 32 | void set_config_info(uintptr_t config_addr, uint32_t config_max_size, |
| 33 | unsigned int config_id) |
Manish V Badarkhe | 99a8e14 | 2020-06-11 22:32:11 +0100 | [diff] [blame] | 34 | { |
| 35 | struct dyn_cfg_dtb_info_t *dtb_info; |
| 36 | |
| 37 | dtb_info = pool_alloc(&dtb_info_pool); |
| 38 | dtb_info->config_addr = config_addr; |
| 39 | dtb_info->config_max_size = config_max_size; |
Manish V Badarkhe | 6a91e59 | 2020-07-15 05:08:37 +0100 | [diff] [blame] | 40 | dtb_info->config_id = config_id; |
Manish V Badarkhe | 99a8e14 | 2020-06-11 22:32:11 +0100 | [diff] [blame] | 41 | } |
Louis Mayencourt | 6d2b573 | 2019-12-17 13:17:25 +0000 | [diff] [blame] | 42 | |
| 43 | struct dyn_cfg_dtb_info_t *dyn_cfg_dtb_info_getter(unsigned int config_id) |
| 44 | { |
| 45 | unsigned int index; |
Louis Mayencourt | 6d2b573 | 2019-12-17 13:17:25 +0000 | [diff] [blame] | 46 | |
| 47 | /* Positions index to the proper config-id */ |
Manish V Badarkhe | 6a91e59 | 2020-07-15 05:08:37 +0100 | [diff] [blame] | 48 | for (index = 0U; index < MAX_DTB_INFO; index++) { |
Louis Mayencourt | 6d2b573 | 2019-12-17 13:17:25 +0000 | [diff] [blame] | 49 | if (dtb_infos[index].config_id == config_id) { |
Manish V Badarkhe | 6a91e59 | 2020-07-15 05:08:37 +0100 | [diff] [blame] | 50 | return &dtb_infos[index]; |
Louis Mayencourt | 6d2b573 | 2019-12-17 13:17:25 +0000 | [diff] [blame] | 51 | } |
| 52 | } |
| 53 | |
Manish V Badarkhe | 6a91e59 | 2020-07-15 05:08:37 +0100 | [diff] [blame] | 54 | WARN("FCONF: Invalid config id %u\n", config_id); |
Louis Mayencourt | 6d2b573 | 2019-12-17 13:17:25 +0000 | [diff] [blame] | 55 | |
Manish V Badarkhe | 6a91e59 | 2020-07-15 05:08:37 +0100 | [diff] [blame] | 56 | return NULL; |
Louis Mayencourt | 6d2b573 | 2019-12-17 13:17:25 +0000 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | int fconf_populate_dtb_registry(uintptr_t config) |
| 60 | { |
| 61 | int rc; |
| 62 | int node, child; |
Louis Mayencourt | 6d2b573 | 2019-12-17 13:17:25 +0000 | [diff] [blame] | 63 | |
| 64 | /* As libfdt use void *, we can't avoid this cast */ |
| 65 | const void *dtb = (void *)config; |
| 66 | |
Manish V Badarkhe | 99a8e14 | 2020-06-11 22:32:11 +0100 | [diff] [blame] | 67 | /* |
Manish V Badarkhe | 99a8e14 | 2020-06-11 22:32:11 +0100 | [diff] [blame] | 68 | * In case of BL1, fw_config dtb information is already |
| 69 | * populated in global dtb_infos array by 'set_fw_config_info' |
| 70 | * function, Below check is present to avoid re-population of |
| 71 | * fw_config information. |
| 72 | * |
| 73 | * Other BLs, satisfy below check and populate fw_config information |
| 74 | * in global dtb_infos array. |
| 75 | */ |
Manish V Badarkhe | 6a91e59 | 2020-07-15 05:08:37 +0100 | [diff] [blame] | 76 | if (dtb_infos[0].config_id == 0U) { |
| 77 | uint32_t config_max_size = fdt_totalsize(dtb); |
| 78 | set_config_info(config, config_max_size, FW_CONFIG_ID); |
Manish V Badarkhe | 99a8e14 | 2020-06-11 22:32:11 +0100 | [diff] [blame] | 79 | } |
| 80 | |
Louis Mayencourt | b26fafa | 2020-04-20 14:17:21 +0100 | [diff] [blame] | 81 | /* Find the node offset point to "fconf,dyn_cfg-dtb_registry" compatible property */ |
| 82 | const char *compatible_str = "fconf,dyn_cfg-dtb_registry"; |
Louis Mayencourt | 6d2b573 | 2019-12-17 13:17:25 +0000 | [diff] [blame] | 83 | node = fdt_node_offset_by_compatible(dtb, -1, compatible_str); |
| 84 | if (node < 0) { |
| 85 | ERROR("FCONF: Can't find %s compatible in dtb\n", compatible_str); |
| 86 | return node; |
| 87 | } |
| 88 | |
| 89 | fdt_for_each_subnode(child, dtb, node) { |
Manish V Badarkhe | 6a91e59 | 2020-07-15 05:08:37 +0100 | [diff] [blame] | 90 | uint32_t config_max_size, config_id; |
| 91 | uintptr_t config_addr; |
Andre Przywara | fe5bdf5 | 2020-03-26 11:22:37 +0000 | [diff] [blame] | 92 | uint64_t val64; |
| 93 | |
Louis Mayencourt | 6d2b573 | 2019-12-17 13:17:25 +0000 | [diff] [blame] | 94 | /* Read configuration dtb information */ |
Andre Przywara | fe5bdf5 | 2020-03-26 11:22:37 +0000 | [diff] [blame] | 95 | rc = fdt_read_uint64(dtb, child, "load-address", &val64); |
Louis Mayencourt | 6d2b573 | 2019-12-17 13:17:25 +0000 | [diff] [blame] | 96 | if (rc < 0) { |
| 97 | ERROR("FCONF: Incomplete configuration property in dtb-registry.\n"); |
| 98 | return rc; |
| 99 | } |
Manish V Badarkhe | 6a91e59 | 2020-07-15 05:08:37 +0100 | [diff] [blame] | 100 | config_addr = (uintptr_t)val64; |
Louis Mayencourt | 6d2b573 | 2019-12-17 13:17:25 +0000 | [diff] [blame] | 101 | |
Manish V Badarkhe | 6a91e59 | 2020-07-15 05:08:37 +0100 | [diff] [blame] | 102 | rc = fdt_read_uint32(dtb, child, "max-size", &config_max_size); |
Louis Mayencourt | 6d2b573 | 2019-12-17 13:17:25 +0000 | [diff] [blame] | 103 | if (rc < 0) { |
| 104 | ERROR("FCONF: Incomplete configuration property in dtb-registry.\n"); |
| 105 | return rc; |
| 106 | } |
| 107 | |
Manish V Badarkhe | 6a91e59 | 2020-07-15 05:08:37 +0100 | [diff] [blame] | 108 | rc = fdt_read_uint32(dtb, child, "id", &config_id); |
Louis Mayencourt | 6d2b573 | 2019-12-17 13:17:25 +0000 | [diff] [blame] | 109 | if (rc < 0) { |
| 110 | ERROR("FCONF: Incomplete configuration property in dtb-registry.\n"); |
| 111 | return rc; |
| 112 | } |
| 113 | |
| 114 | VERBOSE("FCONF: dyn_cfg.dtb_registry cell found with:\n"); |
Manish V Badarkhe | 6a91e59 | 2020-07-15 05:08:37 +0100 | [diff] [blame] | 115 | VERBOSE("\tload-address = %lx\n", config_addr); |
| 116 | VERBOSE("\tmax-size = 0x%x\n", config_max_size); |
| 117 | VERBOSE("\tconfig-id = %u\n", config_id); |
| 118 | |
| 119 | set_config_info(config_addr, config_max_size, config_id); |
Louis Mayencourt | 6d2b573 | 2019-12-17 13:17:25 +0000 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | if ((child < 0) && (child != -FDT_ERR_NOTFOUND)) { |
| 123 | ERROR("%d: fdt_for_each_subnode(): %d\n", __LINE__, node); |
| 124 | return child; |
| 125 | } |
| 126 | |
| 127 | return 0; |
| 128 | } |
| 129 | |
Manish V Badarkhe | 64616a5 | 2020-05-31 08:53:40 +0100 | [diff] [blame] | 130 | FCONF_REGISTER_POPULATOR(FW_CONFIG, dyn_cfg, fconf_populate_dtb_registry); |