fconf_sdei_getter.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. * Copyright (c) 2019-2020, ARM Limited and Contributors. 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_sdei_getter.h>
  11. #define PRIVATE_EVENT_NUM(i) private_events[3 * (i)]
  12. #define PRIVATE_EVENT_INTR(i) private_events[3 * (i) + 1]
  13. #define PRIVATE_EVENT_FLAGS(i) private_events[3 * (i) + 2]
  14. #define SHARED_EVENT_NUM(i) shared_events[3 * (i)]
  15. #define SHARED_EVENT_INTR(i) shared_events[3 * (i) + 1]
  16. #define SHARED_EVENT_FLAGS(i) shared_events[3 * (i) + 2]
  17. struct sdei_dyn_config_t sdei_dyn_config;
  18. int fconf_populate_sdei_dyn_config(uintptr_t config)
  19. {
  20. uint32_t i;
  21. int node, err;
  22. uint32_t private_events[PLAT_SDEI_DP_EVENT_MAX_CNT * 3];
  23. uint32_t shared_events[PLAT_SDEI_DS_EVENT_MAX_CNT * 3];
  24. const void *dtb = (void *)config;
  25. /* Check that the node offset points to compatible property */
  26. node = fdt_node_offset_by_compatible(dtb, -1, "arm,sdei-1.0");
  27. if (node < 0) {
  28. ERROR("FCONF: Can't find 'arm,sdei-1.0' compatible node in dtb\n");
  29. return node;
  30. }
  31. /* Read number of private mappings */
  32. err = fdt_read_uint32(dtb, node, "private_event_count",
  33. &sdei_dyn_config.private_ev_cnt);
  34. if (err < 0) {
  35. ERROR("FCONF: Read cell failed for 'private_event_count': %u\n",
  36. sdei_dyn_config.private_ev_cnt);
  37. return err;
  38. }
  39. /* Check if the value is in range */
  40. if (sdei_dyn_config.private_ev_cnt > PLAT_SDEI_DP_EVENT_MAX_CNT) {
  41. ERROR("FCONF: Invalid value for 'private_event_count': %u\n",
  42. sdei_dyn_config.private_ev_cnt);
  43. return -1;
  44. }
  45. /* Read private mappings */
  46. err = fdt_read_uint32_array(dtb, node, "private_events",
  47. sdei_dyn_config.private_ev_cnt * 3, private_events);
  48. if (err < 0) {
  49. ERROR("FCONF: Read cell failed for 'private_events': %d\n", err);
  50. return err;
  51. }
  52. /* Move data to fconf struct */
  53. for (i = 0; i < sdei_dyn_config.private_ev_cnt; i++) {
  54. sdei_dyn_config.private_ev_nums[i] = PRIVATE_EVENT_NUM(i);
  55. sdei_dyn_config.private_ev_intrs[i] = PRIVATE_EVENT_INTR(i);
  56. sdei_dyn_config.private_ev_flags[i] = PRIVATE_EVENT_FLAGS(i);
  57. }
  58. /* Read number of shared mappings */
  59. err = fdt_read_uint32(dtb, node, "shared_event_count",
  60. &sdei_dyn_config.shared_ev_cnt);
  61. if (err < 0) {
  62. ERROR("FCONF: Read cell failed for 'shared_event_count'\n");
  63. return err;
  64. }
  65. /* Check if the value is in range */
  66. if (sdei_dyn_config.shared_ev_cnt > PLAT_SDEI_DS_EVENT_MAX_CNT) {
  67. ERROR("FCONF: Invalid value for 'shared_event_count': %u\n",
  68. sdei_dyn_config.shared_ev_cnt);
  69. return -1;
  70. }
  71. /* Read shared mappings */
  72. err = fdt_read_uint32_array(dtb, node, "shared_events",
  73. sdei_dyn_config.shared_ev_cnt * 3, shared_events);
  74. if (err < 0) {
  75. ERROR("FCONF: Read cell failed for 'shared_events': %d\n", err);
  76. return err;
  77. }
  78. /* Move data to fconf struct */
  79. for (i = 0; i < sdei_dyn_config.shared_ev_cnt; i++) {
  80. sdei_dyn_config.shared_ev_nums[i] = SHARED_EVENT_NUM(i);
  81. sdei_dyn_config.shared_ev_intrs[i] = SHARED_EVENT_INTR(i);
  82. sdei_dyn_config.shared_ev_flags[i] = SHARED_EVENT_FLAGS(i);
  83. }
  84. return 0;
  85. }
  86. FCONF_REGISTER_POPULATOR(HW_CONFIG, sdei, fconf_populate_sdei_dyn_config);