1 /* 2 * Copyright (c) 2025, Arm Limited and Contributors. All rights reserved. 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 */ 6 7 #include <common/debug.h> 8 #include <common/fdt_wrappers.h> 9 #include <drivers/arm/gicv3.h> 10 11 #include <fconf_hw_config_getter.h> 12 13 struct gicv3_config_t gicv3_config; 14 15 int fconf_populate_gicv3_config(uintptr_t config) 16 { 17 int err; 18 int node; 19 uintptr_t addr; 20 21 /* Necessary to work with libfdt APIs */ 22 const void *hw_config_dtb = (const void *)config; 23 24 /* 25 * Find the offset of the node containing "arm,gic-v3" compatible property. 26 * Populating fconf strucutures dynamically is not supported for legacy 27 * systems which use GICv2 IP. Simply skip extracting GIC properties. 28 */ 29 node = fdt_node_offset_by_compatible(hw_config_dtb, -1, "arm,gic-v3"); 30 if (node < 0) { 31 WARN("FCONF: Unable to locate node with arm,gic-v3 compatible property\n"); 32 return 0; 33 } 34 /* The GICv3 DT binding holds at least two address/size pairs, 35 * the first describing the distributor, the second the redistributors. 36 * See: bindings/interrupt-controller/arm,gic-v3.yaml 37 */ 38 err = fdt_get_reg_props_by_index(hw_config_dtb, node, 0, &addr, NULL); 39 if (err < 0) { 40 ERROR("FCONF: Failed to read GICD reg property of GIC node\n"); 41 return err; 42 } 43 gicv3_config.gicd_base = addr; 44 45 err = fdt_get_reg_props_by_index(hw_config_dtb, node, 1, &addr, NULL); 46 if (err < 0) { 47 ERROR("FCONF: Failed to read GICR reg property of GIC node\n"); 48 } else { 49 gicv3_config.gicr_base = addr; 50 } 51 52 return err; 53 } 54 FCONF_REGISTER_POPULATOR(HW_CONFIG, gicv3_config, fconf_populate_gicv3_config); 55