gic600_multichip.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  1. /*
  2. * Copyright (c) 2019-2024, Arm Limited. All rights reserved.
  3. * Copyright (c) 2022-2023, NVIDIA Corporation. All rights reserved.
  4. *
  5. * SPDX-License-Identifier: BSD-3-Clause
  6. */
  7. /*
  8. * GIC-600 driver extension for multichip setup
  9. */
  10. #include <assert.h>
  11. #include <common/debug.h>
  12. #include <drivers/arm/arm_gicv3_common.h>
  13. #include <drivers/arm/gic600_multichip.h>
  14. #include <drivers/arm/gicv3.h>
  15. #include "../common/gic_common_private.h"
  16. #include "gic600_multichip_private.h"
  17. static struct gic600_multichip_data *plat_gic_multichip_data;
  18. /*******************************************************************************
  19. * Retrieve the address of the chip owner for a given SPI ID
  20. ******************************************************************************/
  21. uintptr_t gic600_multichip_gicd_base_for_spi(uint32_t spi_id)
  22. {
  23. unsigned int i;
  24. /* Find the multichip instance */
  25. for (i = 0U; i < GIC600_MAX_MULTICHIP; i++) {
  26. if ((spi_id <= plat_gic_multichip_data->spi_ids[i].spi_id_max) &&
  27. (spi_id >= plat_gic_multichip_data->spi_ids[i].spi_id_min)) {
  28. break;
  29. }
  30. }
  31. /* Ensure that plat_gic_multichip_data contains valid values */
  32. assert(i < GIC600_MAX_MULTICHIP);
  33. return plat_gic_multichip_data->spi_ids[i].gicd_base;
  34. }
  35. /*******************************************************************************
  36. * GIC-600 multichip operation related helper functions
  37. ******************************************************************************/
  38. static void gicd_dchipr_wait_for_power_update_progress(uintptr_t base)
  39. {
  40. unsigned int retry = GICD_PUP_UPDATE_RETRIES;
  41. while ((read_gicd_dchipr(base) & GICD_DCHIPR_PUP_BIT) != 0U) {
  42. if (retry-- == 0U) {
  43. ERROR("GIC-600 connection to Routing Table Owner timed "
  44. "out\n");
  45. panic();
  46. }
  47. }
  48. }
  49. /*******************************************************************************
  50. * Sets up the routing table owner.
  51. ******************************************************************************/
  52. static void set_gicd_dchipr_rt_owner(uintptr_t base, unsigned int rt_owner)
  53. {
  54. /*
  55. * Ensure that Group enables in GICD_CTLR are disabled and no pending
  56. * register writes to GICD_CTLR.
  57. */
  58. if ((gicd_read_ctlr(base) &
  59. (CTLR_ENABLE_G0_BIT | CTLR_ENABLE_G1S_BIT |
  60. CTLR_ENABLE_G1NS_BIT | GICD_CTLR_RWP_BIT)) != 0) {
  61. ERROR("GICD_CTLR group interrupts are either enabled or have "
  62. "pending writes. Cannot set RT owner.\n");
  63. panic();
  64. }
  65. /* Poll till PUP is zero before initiating write */
  66. gicd_dchipr_wait_for_power_update_progress(base);
  67. write_gicd_dchipr(base, read_gicd_dchipr(base) |
  68. (rt_owner << GICD_DCHIPR_RT_OWNER_SHIFT));
  69. /* Poll till PUP is zero to ensure write is complete */
  70. gicd_dchipr_wait_for_power_update_progress(base);
  71. }
  72. /*******************************************************************************
  73. * Configures the Chip Register to make connections to GICDs on
  74. * a multichip platform.
  75. ******************************************************************************/
  76. static void set_gicd_chipr_n(uintptr_t base,
  77. unsigned int chip_id,
  78. uint64_t chip_addr,
  79. unsigned int spi_id_min,
  80. unsigned int spi_id_max)
  81. {
  82. unsigned int spi_block_min, spi_blocks;
  83. unsigned int gicd_iidr_val = gicd_read_iidr(base);
  84. uint64_t chipr_n_val;
  85. /*
  86. * Ensure that group enables in GICD_CTLR are disabled and no pending
  87. * register writes to GICD_CTLR.
  88. */
  89. if ((gicd_read_ctlr(base) &
  90. (CTLR_ENABLE_G0_BIT | CTLR_ENABLE_G1S_BIT |
  91. CTLR_ENABLE_G1NS_BIT | GICD_CTLR_RWP_BIT)) != 0) {
  92. ERROR("GICD_CTLR group interrupts are either enabled or have "
  93. "pending writes. Cannot set CHIPR register.\n");
  94. panic();
  95. }
  96. /*
  97. * spi_id_min and spi_id_max of value 0 is used to intidicate that the
  98. * chip doesn't own any SPI block. Re-assign min and max values as SPI
  99. * id starts from 32.
  100. */
  101. if (spi_id_min == 0 && spi_id_max == 0) {
  102. spi_id_min = GIC600_SPI_ID_MIN;
  103. spi_id_max = GIC600_SPI_ID_MIN;
  104. }
  105. switch ((gicd_iidr_val & IIDR_MODEL_MASK)) {
  106. case IIDR_MODEL_ARM_GIC_600:
  107. spi_block_min = SPI_BLOCK_MIN_VALUE(spi_id_min);
  108. spi_blocks = SPI_BLOCKS_VALUE(spi_id_min, spi_id_max);
  109. chipr_n_val = GICD_CHIPR_VALUE_GIC_600(chip_addr,
  110. spi_block_min,
  111. spi_blocks);
  112. break;
  113. case IIDR_MODEL_ARM_GIC_700:
  114. /* Calculate the SPI_ID_MIN value for ESPI */
  115. if (spi_id_min >= GIC700_ESPI_ID_MIN) {
  116. spi_block_min = ESPI_BLOCK_MIN_VALUE(spi_id_min);
  117. spi_block_min += SPI_BLOCKS_VALUE(GIC700_SPI_ID_MIN,
  118. GIC700_SPI_ID_MAX);
  119. } else {
  120. spi_block_min = SPI_BLOCK_MIN_VALUE(spi_id_min);
  121. }
  122. /* Calculate the total number of blocks */
  123. spi_blocks = SPI_BLOCKS_VALUE(spi_id_min, spi_id_max);
  124. chipr_n_val = GICD_CHIPR_VALUE_GIC_700(chip_addr,
  125. spi_block_min,
  126. spi_blocks);
  127. break;
  128. default:
  129. ERROR("Unsupported GIC model 0x%x for multichip setup.\n",
  130. gicd_iidr_val);
  131. panic();
  132. break;
  133. }
  134. chipr_n_val |= GICD_CHIPRx_SOCKET_STATE;
  135. /*
  136. * Wait for DCHIPR.PUP to be zero before commencing writes to
  137. * GICD_CHIPRx.
  138. */
  139. gicd_dchipr_wait_for_power_update_progress(base);
  140. /*
  141. * Assign chip addr, spi min block, number of spi blocks and bring chip
  142. * online by setting SocketState.
  143. */
  144. write_gicd_chipr_n(base, chip_id, chipr_n_val);
  145. /*
  146. * Poll until DCHIP.PUP is zero to verify connection to rt_owner chip
  147. * is complete.
  148. */
  149. gicd_dchipr_wait_for_power_update_progress(base);
  150. /*
  151. * Ensure that write to GICD_CHIPRx is successful and the chip_n came
  152. * online.
  153. */
  154. if (read_gicd_chipr_n(base, chip_id) != chipr_n_val) {
  155. ERROR("GICD_CHIPR%u write failed\n", chip_id);
  156. panic();
  157. }
  158. /* Ensure that chip is in consistent state */
  159. if (((read_gicd_chipsr(base) & GICD_CHIPSR_RTS_MASK) >>
  160. GICD_CHIPSR_RTS_SHIFT) !=
  161. GICD_CHIPSR_RTS_STATE_CONSISTENT) {
  162. ERROR("Chip %u routing table is not in consistent state\n",
  163. chip_id);
  164. panic();
  165. }
  166. }
  167. /*******************************************************************************
  168. * Validates the GIC-600 Multichip data structure passed by the platform.
  169. ******************************************************************************/
  170. static void gic600_multichip_validate_data(
  171. struct gic600_multichip_data *multichip_data)
  172. {
  173. unsigned int i, spi_id_min, spi_id_max, blocks_of_32;
  174. unsigned int multichip_spi_blocks = 0;
  175. assert(multichip_data != NULL);
  176. if (multichip_data->chip_count > GIC600_MAX_MULTICHIP) {
  177. ERROR("GIC-600 Multichip count should not exceed %d\n",
  178. GIC600_MAX_MULTICHIP);
  179. panic();
  180. }
  181. for (i = 0U; i < multichip_data->chip_count; i++) {
  182. spi_id_min = multichip_data->spi_ids[i].spi_id_min;
  183. spi_id_max = multichip_data->spi_ids[i].spi_id_max;
  184. if ((spi_id_min != 0U) || (spi_id_max != 0U)) {
  185. /* SPI IDs range check */
  186. if (!(spi_id_min >= GIC600_SPI_ID_MIN) ||
  187. !(spi_id_max <= GIC600_SPI_ID_MAX) ||
  188. !(spi_id_min <= spi_id_max) ||
  189. !((spi_id_max - spi_id_min + 1) % 32 == 0)) {
  190. ERROR("Invalid SPI IDs {%u, %u} passed for "
  191. "Chip %u\n", spi_id_min,
  192. spi_id_max, i);
  193. panic();
  194. }
  195. /* SPI IDs overlap check */
  196. blocks_of_32 = BLOCKS_OF_32(spi_id_min, spi_id_max);
  197. if ((multichip_spi_blocks & blocks_of_32) != 0) {
  198. ERROR("SPI IDs of Chip %u overlapping\n", i);
  199. panic();
  200. }
  201. multichip_spi_blocks |= blocks_of_32;
  202. }
  203. }
  204. }
  205. /*******************************************************************************
  206. * Validates the GIC-700 Multichip data structure passed by the platform.
  207. ******************************************************************************/
  208. static void gic700_multichip_validate_data(
  209. struct gic600_multichip_data *multichip_data)
  210. {
  211. unsigned int i, spi_id_min, spi_id_max, blocks_of_32;
  212. unsigned int multichip_spi_blocks = 0U, multichip_espi_blocks = 0U;
  213. assert(multichip_data != NULL);
  214. if (multichip_data->chip_count > GIC600_MAX_MULTICHIP) {
  215. ERROR("GIC-700 Multichip count (%u) should not exceed %u\n",
  216. multichip_data->chip_count, GIC600_MAX_MULTICHIP);
  217. panic();
  218. }
  219. for (i = 0U; i < multichip_data->chip_count; i++) {
  220. spi_id_min = multichip_data->spi_ids[i].spi_id_min;
  221. spi_id_max = multichip_data->spi_ids[i].spi_id_max;
  222. if ((spi_id_min == 0U) || (spi_id_max == 0U)) {
  223. continue;
  224. }
  225. /* MIN SPI ID check */
  226. if ((spi_id_min < GIC700_SPI_ID_MIN) ||
  227. ((spi_id_min >= GIC700_SPI_ID_MAX) &&
  228. (spi_id_min < GIC700_ESPI_ID_MIN))) {
  229. ERROR("Invalid MIN SPI ID {%u} passed for "
  230. "Chip %u\n", spi_id_min, i);
  231. panic();
  232. }
  233. if ((spi_id_min > spi_id_max) ||
  234. ((spi_id_max - spi_id_min + 1) % 32 != 0)) {
  235. ERROR("Unaligned SPI IDs {%u, %u} passed for "
  236. "Chip %u\n", spi_id_min,
  237. spi_id_max, i);
  238. panic();
  239. }
  240. /* ESPI IDs range check */
  241. if ((spi_id_min >= GIC700_ESPI_ID_MIN) &&
  242. (spi_id_max > GIC700_ESPI_ID_MAX)) {
  243. ERROR("Invalid ESPI IDs {%u, %u} passed for "
  244. "Chip %u\n", spi_id_min,
  245. spi_id_max, i);
  246. panic();
  247. }
  248. /* SPI IDs range check */
  249. if (((spi_id_min < GIC700_SPI_ID_MAX) &&
  250. (spi_id_max > GIC700_SPI_ID_MAX))) {
  251. ERROR("Invalid SPI IDs {%u, %u} passed for "
  252. "Chip %u\n", spi_id_min,
  253. spi_id_max, i);
  254. panic();
  255. }
  256. /* SPI IDs overlap check */
  257. if (spi_id_max < GIC700_SPI_ID_MAX) {
  258. blocks_of_32 = BLOCKS_OF_32(spi_id_min, spi_id_max);
  259. if ((multichip_spi_blocks & blocks_of_32) != 0) {
  260. ERROR("SPI IDs of Chip %u overlapping\n", i);
  261. panic();
  262. }
  263. multichip_spi_blocks |= blocks_of_32;
  264. }
  265. /* ESPI IDs overlap check */
  266. if (spi_id_max > GIC700_ESPI_ID_MIN) {
  267. blocks_of_32 = BLOCKS_OF_32(spi_id_min - GIC700_ESPI_ID_MIN,
  268. spi_id_max - GIC700_ESPI_ID_MIN);
  269. if ((multichip_espi_blocks & blocks_of_32) != 0) {
  270. ERROR("SPI IDs of Chip %u overlapping\n", i);
  271. panic();
  272. }
  273. multichip_espi_blocks |= blocks_of_32;
  274. }
  275. }
  276. }
  277. /*******************************************************************************
  278. * Initialize GIC-600 and GIC-700 Multichip operation.
  279. ******************************************************************************/
  280. void gic600_multichip_init(struct gic600_multichip_data *multichip_data)
  281. {
  282. unsigned int i;
  283. uint32_t gicd_iidr_val = gicd_read_iidr(multichip_data->rt_owner_base);
  284. if ((gicd_iidr_val & IIDR_MODEL_MASK) == IIDR_MODEL_ARM_GIC_600) {
  285. gic600_multichip_validate_data(multichip_data);
  286. }
  287. if ((gicd_iidr_val & IIDR_MODEL_MASK) == IIDR_MODEL_ARM_GIC_700) {
  288. gic700_multichip_validate_data(multichip_data);
  289. }
  290. /*
  291. * Ensure that G0/G1S/G1NS interrupts are disabled. This also ensures
  292. * that GIC-600 Multichip configuration is done first.
  293. */
  294. if ((gicd_read_ctlr(multichip_data->rt_owner_base) &
  295. (CTLR_ENABLE_G0_BIT | CTLR_ENABLE_G1S_BIT |
  296. CTLR_ENABLE_G1NS_BIT | GICD_CTLR_RWP_BIT)) != 0) {
  297. ERROR("GICD_CTLR group interrupts are either enabled or have "
  298. "pending writes.\n");
  299. panic();
  300. }
  301. /* Ensure that the routing table owner is in disconnected state */
  302. if (((read_gicd_chipsr(multichip_data->rt_owner_base) &
  303. GICD_CHIPSR_RTS_MASK) >> GICD_CHIPSR_RTS_SHIFT) !=
  304. GICD_CHIPSR_RTS_STATE_DISCONNECTED) {
  305. ERROR("GIC-600 routing table owner is not in disconnected "
  306. "state to begin multichip configuration\n");
  307. panic();
  308. }
  309. /* Initialize the GICD which is marked as routing table owner first */
  310. set_gicd_dchipr_rt_owner(multichip_data->rt_owner_base,
  311. multichip_data->rt_owner);
  312. set_gicd_chipr_n(multichip_data->rt_owner_base, multichip_data->rt_owner,
  313. multichip_data->chip_addrs[multichip_data->rt_owner],
  314. multichip_data->
  315. spi_ids[multichip_data->rt_owner].spi_id_min,
  316. multichip_data->
  317. spi_ids[multichip_data->rt_owner].spi_id_max);
  318. for (i = 0; i < multichip_data->chip_count; i++) {
  319. if (i == multichip_data->rt_owner)
  320. continue;
  321. set_gicd_chipr_n(multichip_data->rt_owner_base, i,
  322. multichip_data->chip_addrs[i],
  323. multichip_data->spi_ids[i].spi_id_min,
  324. multichip_data->spi_ids[i].spi_id_max);
  325. }
  326. plat_gic_multichip_data = multichip_data;
  327. }
  328. /*******************************************************************************
  329. * Allow a way to query the status of the GIC600 multichip driver
  330. ******************************************************************************/
  331. bool gic600_multichip_is_initialized(void)
  332. {
  333. return (plat_gic_multichip_data != NULL);
  334. }