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 | |
| 15 | /* We currently use TB_FW, SOC_FW, TOS_FW, NS_fw and HW configs */ |
| 16 | #define MAX_DTB_INFO U(5) |
| 17 | |
| 18 | static struct dyn_cfg_dtb_info_t dtb_infos[MAX_DTB_INFO]; |
| 19 | static OBJECT_POOL_ARRAY(dtb_info_pool, dtb_infos); |
| 20 | |
| 21 | struct dyn_cfg_dtb_info_t *dyn_cfg_dtb_info_getter(unsigned int config_id) |
| 22 | { |
| 23 | unsigned int index; |
| 24 | struct dyn_cfg_dtb_info_t *info; |
| 25 | |
| 26 | /* Positions index to the proper config-id */ |
| 27 | for (index = 0; index < MAX_DTB_INFO; index++) { |
| 28 | if (dtb_infos[index].config_id == config_id) { |
| 29 | info = &dtb_infos[index]; |
| 30 | break; |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | if (index == MAX_DTB_INFO) { |
| 35 | WARN("FCONF: Invalid config id %u\n", config_id); |
| 36 | info = NULL; |
| 37 | } |
| 38 | |
| 39 | return info; |
| 40 | } |
| 41 | |
| 42 | int fconf_populate_dtb_registry(uintptr_t config) |
| 43 | { |
| 44 | int rc; |
| 45 | int node, child; |
| 46 | struct dyn_cfg_dtb_info_t *dtb_info; |
| 47 | |
| 48 | /* As libfdt use void *, we can't avoid this cast */ |
| 49 | const void *dtb = (void *)config; |
| 50 | |
| 51 | /* Find the node offset point to "arm,dyn_cfg-dtb_registry" compatible property */ |
| 52 | const char *compatible_str = "arm,dyn_cfg-dtb_registry"; |
| 53 | node = fdt_node_offset_by_compatible(dtb, -1, compatible_str); |
| 54 | if (node < 0) { |
| 55 | ERROR("FCONF: Can't find %s compatible in dtb\n", compatible_str); |
| 56 | return node; |
| 57 | } |
| 58 | |
| 59 | fdt_for_each_subnode(child, dtb, node) { |
| 60 | dtb_info = pool_alloc(&dtb_info_pool); |
| 61 | |
| 62 | /* Read configuration dtb information */ |
| 63 | rc = fdtw_read_cells(dtb, child, "load-address", 2, &dtb_info->config_addr); |
| 64 | if (rc < 0) { |
| 65 | ERROR("FCONF: Incomplete configuration property in dtb-registry.\n"); |
| 66 | return rc; |
| 67 | } |
| 68 | |
| 69 | rc = fdtw_read_cells(dtb, child, "max-size", 1, &dtb_info->config_max_size); |
| 70 | if (rc < 0) { |
| 71 | ERROR("FCONF: Incomplete configuration property in dtb-registry.\n"); |
| 72 | return rc; |
| 73 | } |
| 74 | |
| 75 | rc = fdtw_read_cells(dtb, child, "id", 1, &dtb_info->config_id); |
| 76 | if (rc < 0) { |
| 77 | ERROR("FCONF: Incomplete configuration property in dtb-registry.\n"); |
| 78 | return rc; |
| 79 | } |
| 80 | |
| 81 | VERBOSE("FCONF: dyn_cfg.dtb_registry cell found with:\n"); |
| 82 | VERBOSE("\tload-address = %lx\n", dtb_info->config_addr); |
| 83 | VERBOSE("\tmax-size = 0x%zx\n", dtb_info->config_max_size); |
| 84 | VERBOSE("\tconfig-id = %u\n", dtb_info->config_id); |
| 85 | } |
| 86 | |
| 87 | if ((child < 0) && (child != -FDT_ERR_NOTFOUND)) { |
| 88 | ERROR("%d: fdt_for_each_subnode(): %d\n", __LINE__, node); |
| 89 | return child; |
| 90 | } |
| 91 | |
| 92 | return 0; |
| 93 | } |
| 94 | |
Madhukar Pappireddy | 8151969 | 2019-12-06 15:46:42 -0600 | [diff] [blame] | 95 | FCONF_REGISTER_POPULATOR(TB_FW, dyn_cfg, fconf_populate_dtb_registry); |