Soby Mathew | 96a1c6b | 2018-01-15 14:45:33 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2018, ARM Limited and Contributors. All rights reserved. |
| 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
Roberto Vargas | 3c98ce4 | 2018-02-12 12:36:17 +0000 | [diff] [blame] | 7 | #include <arm_dyn_cfg_helpers.h> |
Soby Mathew | 96a1c6b | 2018-01-15 14:45:33 +0000 | [diff] [blame] | 8 | #include <assert.h> |
| 9 | #include <desc_image_load.h> |
| 10 | #include <fdt_wrappers.h> |
| 11 | #include <libfdt.h> |
Soby Mathew | cc36484 | 2018-02-21 01:16:39 +0000 | [diff] [blame] | 12 | #include <plat_arm.h> |
Soby Mathew | 96a1c6b | 2018-01-15 14:45:33 +0000 | [diff] [blame] | 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 | |
Soby Mathew | cc36484 | 2018-02-21 01:16:39 +0000 | [diff] [blame] | 36 | assert(dtb != NULL); |
| 37 | assert(hw_config_addr != NULL); |
| 38 | assert(hw_config_size != NULL); |
Soby Mathew | 96a1c6b | 2018-01-15 14:45:33 +0000 | [diff] [blame] | 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 | * Validate the tb_fw_config is a valid DTB file and returns the node offset |
| 68 | * to "arm,tb_fw" property. |
| 69 | * Arguments: |
| 70 | * void *dtb - pointer to the TB_FW_CONFIG in memory |
| 71 | * int *node - Returns the node offset to "arm,tb_fw" property if found. |
| 72 | * |
| 73 | * Returns 0 on success and -1 on error. |
| 74 | ******************************************************************************/ |
| 75 | int arm_dyn_tb_fw_cfg_init(void *dtb, int *node) |
| 76 | { |
Soby Mathew | cc36484 | 2018-02-21 01:16:39 +0000 | [diff] [blame] | 77 | assert(dtb != NULL); |
| 78 | assert(node != NULL); |
Soby Mathew | 96a1c6b | 2018-01-15 14:45:33 +0000 | [diff] [blame] | 79 | |
| 80 | /* Check if the pointer to DT is correct */ |
| 81 | if (fdt_check_header(dtb) != 0) { |
| 82 | WARN("Invalid DTB file passed as TB_FW_CONFIG\n"); |
| 83 | return -1; |
| 84 | } |
| 85 | |
| 86 | /* Assert the node offset point to "arm,tb_fw" compatible property */ |
| 87 | *node = fdt_node_offset_by_compatible(dtb, -1, "arm,tb_fw"); |
| 88 | if (*node < 0) { |
| 89 | WARN("The compatible property `arm,tb_fw` not found in the config\n"); |
| 90 | return -1; |
| 91 | } |
| 92 | |
| 93 | VERBOSE("Dyn cfg: Found \"arm,tb_fw\" in the config\n"); |
| 94 | return 0; |
| 95 | } |