arm_ni.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /*
  2. * Copyright (c) 2024, ARM Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <errno.h>
  7. #include <common/debug.h>
  8. #include <plat/arm/common/plat_arm.h>
  9. #include <platform_def.h>
  10. #define NI_CHILD_NODE_COUNT 4
  11. #define NI_CHILD_POINTERS_START 8
  12. #define NI_PMU_SECURE_CTRL 0x100
  13. #define NI_PMU_SECURE_EVENT_OBSERVATION 0x108
  14. #define NI_PMU_DEBUG_ENABLE 0x110
  15. #define NI_COMP_NUM_SUBFEATURES 0x100
  16. #define NI_COMP_SUBFEATURE_TYPE_START 0x108
  17. #define NI_COMP_SUBFEATURE_SECURE_CTRL_START 0x308
  18. #define SECURE_OVERRIDE_DEFAULT BIT(0)
  19. #define SECURE_EVENT_ENABLE BIT(2)
  20. #define NA_EVENT_ENABLE BIT(3)
  21. #define PMU_ENABLE BIT(0)
  22. #define NI_NODE_MASK 0x0000ffff
  23. #define NI_NODE_TYPE(node_info) (node_info & NI_NODE_MASK)
  24. #define NI_CHILD_POINTER(i) (NI_CHILD_POINTERS_START + (i * 4))
  25. #define NI_COMP_SUBFEATURE_TYPE(i) (NI_COMP_SUBFEATURE_TYPE_START + (i * 8))
  26. #define NI_COMP_SUBFEATURE_SECURE_CTRL(i) (NI_COMP_SUBFEATURE_SECURE_CTRL_START + (i * 8))
  27. #define NI_PERIPHERAL_ID0 0xfe0
  28. #define NI_PIDR0_PART_MASK 0xff
  29. #define NI_PERIPHERAL_ID1 0xfe4
  30. #define NI_PIDR1_PART_MASK 0xf
  31. #define NI_PIDR1_PART_SHIFT 8
  32. enum ni_part {
  33. NI_700 = 0x43b,
  34. NI_710AE = 0x43d,
  35. NI_TOWER = 0x43f,
  36. };
  37. enum ni_node_type {
  38. NI_INVALID_NODE = 0,
  39. NI_VOLTAGE_DOMAIN = 1,
  40. NI_POWER_DOMAIN = 2,
  41. NI_CLOCK_DOMAIN = 3,
  42. NI_ASNI = 4,
  43. NI_AMNI = 5,
  44. NI_PMU = 6,
  45. NI_HSNI = 7,
  46. NI_HMNI = 8,
  47. NI_PMNI = 9,
  48. NI_CMNI = 14,
  49. NI_CFGNI = 15
  50. };
  51. enum ni_subfeature_type {
  52. NI_SUBFEATURE_APU = 0,
  53. NI_SUBFEATURE_ADDR_MAP = 1,
  54. NI_SUBFEATURE_FCU = 2,
  55. NI_SUBFEATURE_IDM = 3
  56. };
  57. static void ni_enable_pmu(uintptr_t pmu_addr)
  58. {
  59. mmio_setbits_32(pmu_addr + NI_PMU_DEBUG_ENABLE, PMU_ENABLE);
  60. }
  61. static void ni_enable_fcu_ns_access(uintptr_t comp_addr)
  62. {
  63. uint32_t subfeature_type;
  64. uint32_t subfeature_count;
  65. uint32_t subfeature_secure_ctrl;
  66. subfeature_count = mmio_read_32(comp_addr + NI_COMP_NUM_SUBFEATURES);
  67. for (uint32_t i = 0U; i < subfeature_count; i++) {
  68. subfeature_type =
  69. NI_NODE_TYPE(mmio_read_32(comp_addr + NI_COMP_SUBFEATURE_TYPE(i)));
  70. if (subfeature_type == NI_SUBFEATURE_FCU) {
  71. subfeature_secure_ctrl = comp_addr + NI_COMP_SUBFEATURE_SECURE_CTRL(i);
  72. mmio_setbits_32(subfeature_secure_ctrl, SECURE_OVERRIDE_DEFAULT);
  73. }
  74. }
  75. }
  76. static void ni_enable_pmu_ns_access(uintptr_t comp_addr)
  77. {
  78. mmio_setbits_32(comp_addr + NI_PMU_SECURE_CTRL, SECURE_OVERRIDE_DEFAULT);
  79. mmio_setbits_32(comp_addr + NI_PMU_SECURE_EVENT_OBSERVATION,
  80. SECURE_EVENT_ENABLE | NA_EVENT_ENABLE);
  81. }
  82. static void ni_setup_component(uintptr_t comp_addr)
  83. {
  84. uint32_t node_info;
  85. node_info = mmio_read_32(comp_addr);
  86. switch (NI_NODE_TYPE(node_info)) {
  87. case NI_ASNI:
  88. case NI_AMNI:
  89. case NI_HSNI:
  90. case NI_HMNI:
  91. case NI_PMNI:
  92. ni_enable_fcu_ns_access(comp_addr);
  93. break;
  94. case NI_PMU:
  95. ni_enable_pmu_ns_access(comp_addr);
  96. ni_enable_pmu(comp_addr);
  97. break;
  98. default:
  99. return;
  100. }
  101. }
  102. int plat_arm_ni_setup(uintptr_t global_cfg)
  103. {
  104. uintptr_t vd_addr;
  105. uintptr_t pd_addr;
  106. uintptr_t cd_addr;
  107. uintptr_t comp_addr;
  108. uint32_t vd_count;
  109. uint32_t pd_count;
  110. uint32_t cd_count;
  111. uint32_t comp_count;
  112. uint32_t part;
  113. uint32_t reg;
  114. reg = mmio_read_32(global_cfg + NI_PERIPHERAL_ID0);
  115. part = reg & NI_PIDR0_PART_MASK;
  116. reg = mmio_read_32(global_cfg + NI_PERIPHERAL_ID1);
  117. part |= ((reg & NI_PIDR1_PART_MASK) << NI_PIDR1_PART_SHIFT);
  118. if (part != NI_TOWER) {
  119. ERROR("0x%x is not supported\n", part);
  120. return -EINVAL;
  121. }
  122. vd_count = mmio_read_32(global_cfg + NI_CHILD_NODE_COUNT);
  123. for (uint32_t i = 0U; i < vd_count; i++) {
  124. vd_addr = global_cfg + mmio_read_32(global_cfg + NI_CHILD_POINTER(i));
  125. pd_count = mmio_read_32(vd_addr + NI_CHILD_NODE_COUNT);
  126. for (uint32_t j = 0U; j < pd_count; j++) {
  127. pd_addr = global_cfg + mmio_read_32(vd_addr + NI_CHILD_POINTER(j));
  128. cd_count = mmio_read_32(pd_addr + NI_CHILD_NODE_COUNT);
  129. for (uint32_t k = 0U; k < cd_count; k++) {
  130. cd_addr = global_cfg + mmio_read_32(pd_addr + NI_CHILD_POINTER(k));
  131. comp_count = mmio_read_32(cd_addr + NI_CHILD_NODE_COUNT);
  132. for (uint32_t l = 0U; l < comp_count; l++) {
  133. comp_addr = global_cfg +
  134. mmio_read_32(cd_addr + NI_CHILD_POINTER(l));
  135. ni_setup_component(comp_addr);
  136. }
  137. }
  138. }
  139. }
  140. return 0;
  141. }