1 /* 2 * Copyright (c) 2018, ARM Limited and Contributors. All rights reserved. 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 */ 6 7 #include <arm_dyn_cfg_helpers.h> 8 #include <assert.h> 9 #include <desc_image_load.h> 10 #include <fdt_wrappers.h> 11 #include <libfdt.h> 12 #include <plat_arm.h> 13 14 /******************************************************************************* 15 * Helper to read the `hw_config` property in config DTB. This function 16 * expects the following properties to be present in the config DTB. 17 * name : hw_config_addr size : 2 cells 18 * name : hw_config_max_size size : 1 cell 19 * 20 * Arguments: 21 * void *dtb - pointer to the TB_FW_CONFIG in memory 22 * int node - The node offset to appropriate node in the 23 * DTB. 24 * uint64_t *hw_config_addr - Returns the `hw_config` load address if read 25 * is successful. 26 * uint32_t *hw_config_size - Returns the `hw_config` size if read is 27 * successful. 28 * 29 * Returns 0 on success and -1 on error. 30 ******************************************************************************/ 31 int arm_dyn_get_hwconfig_info(void *dtb, int node, 32 uint64_t *hw_config_addr, uint32_t *hw_config_size) 33 { 34 int err; 35 36 assert(dtb != NULL); 37 assert(hw_config_addr != NULL); 38 assert(hw_config_size != NULL); 39 40 /* Check if the pointer to DT is correct */ 41 assert(fdt_check_header(dtb) == 0); 42 43 /* Assert the node offset point to "arm,tb_fw" compatible property */ 44 assert(node == fdt_node_offset_by_compatible(dtb, -1, "arm,tb_fw")); 45 46 err = fdtw_read_cells(dtb, node, "hw_config_addr", 2, 47 (void *) hw_config_addr); 48 if (err < 0) { 49 WARN("Read cell failed for hw_config_addr\n"); 50 return -1; 51 } 52 53 err = fdtw_read_cells(dtb, node, "hw_config_max_size", 1, 54 (void *) hw_config_size); 55 if (err < 0) { 56 WARN("Read cell failed for hw_config_max_size\n"); 57 return -1; 58 } 59 60 VERBOSE("Dyn cfg: Read hw_config address from TB_FW_CONFIG 0x%p %p\n", 61 hw_config_addr, hw_config_size); 62 63 return 0; 64 } 65 66 /******************************************************************************* 67 * Helper to read the `disable_auth` property in config DTB. This function 68 * expects the following properties to be present in the config DTB. 69 * name : disable_auth size : 1 cell 70 * 71 * Arguments: 72 * void *dtb - pointer to the TB_FW_CONFIG in memory 73 * int node - The node offset to appropriate node in the 74 * DTB. 75 * uint64_t *disable_auth - The value of `disable_auth` property on 76 * successful read. Must be 0 or 1. 77 * 78 * Returns 0 on success and -1 on error. 79 ******************************************************************************/ 80 int arm_dyn_get_disable_auth(void *dtb, int node, uint32_t *disable_auth) 81 { 82 int err; 83 84 assert(dtb != NULL); 85 assert(disable_auth != NULL); 86 87 /* Check if the pointer to DT is correct */ 88 assert(fdt_check_header(dtb) == 0); 89 90 /* Assert the node offset point to "arm,tb_fw" compatible property */ 91 assert(node == fdt_node_offset_by_compatible(dtb, -1, "arm,tb_fw")); 92 93 /* Locate the disable_auth cell and read the value */ 94 err = fdtw_read_cells(dtb, node, "disable_auth", 1, disable_auth); 95 if (err < 0) { 96 WARN("Read cell failed for `disable_auth`\n"); 97 return -1; 98 } 99 100 /* Check if the value is boolean */ 101 if (*disable_auth != 0 && *disable_auth != 1) { 102 WARN("Invalid value for `disable_auth` cell %d\n", *disable_auth); 103 return -1; 104 } 105 106 VERBOSE("Dyn cfg: `disable_auth` cell found with value = %d\n", 107 *disable_auth); 108 return 0; 109 } 110 111 /******************************************************************************* 112 * Validate the tb_fw_config is a valid DTB file and returns the node offset 113 * to "arm,tb_fw" property. 114 * Arguments: 115 * void *dtb - pointer to the TB_FW_CONFIG in memory 116 * int *node - Returns the node offset to "arm,tb_fw" property if found. 117 * 118 * Returns 0 on success and -1 on error. 119 ******************************************************************************/ 120 int arm_dyn_tb_fw_cfg_init(void *dtb, int *node) 121 { 122 assert(dtb != NULL); 123 assert(node != NULL); 124 125 /* Check if the pointer to DT is correct */ 126 if (fdt_check_header(dtb) != 0) { 127 WARN("Invalid DTB file passed as TB_FW_CONFIG\n"); 128 return -1; 129 } 130 131 /* Assert the node offset point to "arm,tb_fw" compatible property */ 132 *node = fdt_node_offset_by_compatible(dtb, -1, "arm,tb_fw"); 133 if (*node < 0) { 134 WARN("The compatible property `arm,tb_fw` not found in the config\n"); 135 return -1; 136 } 137 138 VERBOSE("Dyn cfg: Found \"arm,tb_fw\" in the config\n"); 139 return 0; 140 } 141