fconf_nv_cntr_getter.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. * Copyright (c) 2020, Arm Limited. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <assert.h>
  7. #include <common/debug.h>
  8. #include <common/fdt_wrappers.h>
  9. #include <libfdt.h>
  10. #include <plat/arm/common/fconf_nv_cntr_getter.h>
  11. /*******************************************************************************
  12. * fconf_populate_cot_descs() - Populate available nv-counters and update global
  13. * structure.
  14. * @config[in]: Pointer to the device tree blob in memory
  15. *
  16. * Return 0 on success or an error value otherwise.
  17. ******************************************************************************/
  18. static int fconf_populate_nv_cntrs(uintptr_t config)
  19. {
  20. int rc, node, child;
  21. uint32_t id;
  22. uintptr_t reg;
  23. /* As libfdt uses void *, we can't avoid this cast */
  24. const void *dtb = (void *)config;
  25. const char *compatible_str = "arm, non-volatile-counter";
  26. node = fdt_node_offset_by_compatible(dtb, -1, compatible_str);
  27. if (node < 0) {
  28. ERROR("FCONF: Can't find %s compatible in node\n",
  29. compatible_str);
  30. return node;
  31. }
  32. fdt_for_each_subnode(child, dtb, node) {
  33. rc = fdt_read_uint32(dtb, child, "id", &id);
  34. if (rc < 0) {
  35. ERROR("FCONF: Can't find %s property in node\n", "id");
  36. return rc;
  37. }
  38. assert(id < MAX_NV_CTR_IDS);
  39. rc = fdt_get_reg_props_by_index(dtb, child, 0, &reg, NULL);
  40. if (rc < 0) {
  41. ERROR("FCONF: Can't find %s property in node\n", "reg");
  42. return rc;
  43. }
  44. nv_cntr_base_addr[id] = reg;
  45. }
  46. return 0;
  47. }
  48. FCONF_REGISTER_POPULATOR(TB_FW, nv_cntrs, fconf_populate_nv_cntrs);