intr_hw.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Tegra host1x Interrupt Management
  4. *
  5. * Copyright (C) 2010 Google, Inc.
  6. * Copyright (c) 2010-2013, NVIDIA Corporation.
  7. */
  8. #include <linux/io.h>
  9. #include "../intr.h"
  10. #include "../dev.h"
  11. static void process_32_syncpts(struct host1x *host, unsigned long val, u32 reg_offset)
  12. {
  13. unsigned int id;
  14. if (!val)
  15. return;
  16. host1x_sync_writel(host, val, HOST1X_SYNC_SYNCPT_THRESH_INT_DISABLE(reg_offset));
  17. host1x_sync_writel(host, val, HOST1X_SYNC_SYNCPT_THRESH_CPU0_INT_STATUS(reg_offset));
  18. for_each_set_bit(id, &val, 32)
  19. host1x_intr_handle_interrupt(host, reg_offset * 32 + id);
  20. }
  21. static irqreturn_t syncpt_thresh_isr(int irq, void *dev_id)
  22. {
  23. struct host1x_intr_irq_data *irq_data = dev_id;
  24. struct host1x *host = irq_data->host;
  25. unsigned long reg;
  26. unsigned int i;
  27. #if !defined(CONFIG_64BIT)
  28. for (i = irq_data->offset; i < DIV_ROUND_UP(host->info->nb_pts, 32);
  29. i += host->num_syncpt_irqs) {
  30. reg = host1x_sync_readl(host,
  31. HOST1X_SYNC_SYNCPT_THRESH_CPU0_INT_STATUS(i));
  32. process_32_syncpts(host, reg, i);
  33. }
  34. #elif HOST1X_HW == 6 || HOST1X_HW == 7
  35. /*
  36. * Tegra186 and Tegra194 have the first INT_STATUS register not 64-bit aligned,
  37. * and only have one interrupt line.
  38. */
  39. reg = host1x_sync_readl(host, HOST1X_SYNC_SYNCPT_THRESH_CPU0_INT_STATUS(0));
  40. process_32_syncpts(host, reg, 0);
  41. for (i = 1; i < (host->info->nb_pts / 32) - 1; i += 2) {
  42. reg = host1x_sync_readq(host,
  43. HOST1X_SYNC_SYNCPT_THRESH_CPU0_INT_STATUS(i));
  44. process_32_syncpts(host, lower_32_bits(reg), i);
  45. process_32_syncpts(host, upper_32_bits(reg), i + 1);
  46. }
  47. reg = host1x_sync_readl(host, HOST1X_SYNC_SYNCPT_THRESH_CPU0_INT_STATUS(i));
  48. process_32_syncpts(host, reg, i);
  49. #else
  50. /* All 64-bit capable SoCs have number of syncpoints divisible by 64 */
  51. for (i = irq_data->offset; i < DIV_ROUND_UP(host->info->nb_pts, 64);
  52. i += host->num_syncpt_irqs) {
  53. reg = host1x_sync_readq(host,
  54. HOST1X_SYNC_SYNCPT_THRESH_CPU0_INT_STATUS(i * 2));
  55. process_32_syncpts(host, lower_32_bits(reg), i * 2 + 0);
  56. process_32_syncpts(host, upper_32_bits(reg), i * 2 + 1);
  57. }
  58. #endif
  59. return IRQ_HANDLED;
  60. }
  61. static void host1x_intr_disable_all_syncpt_intrs(struct host1x *host)
  62. {
  63. unsigned int i;
  64. for (i = 0; i < DIV_ROUND_UP(host->info->nb_pts, 32); ++i) {
  65. host1x_sync_writel(host, 0xffffffffu,
  66. HOST1X_SYNC_SYNCPT_THRESH_INT_DISABLE(i));
  67. host1x_sync_writel(host, 0xffffffffu,
  68. HOST1X_SYNC_SYNCPT_THRESH_CPU0_INT_STATUS(i));
  69. }
  70. }
  71. static int
  72. host1x_intr_init_host_sync(struct host1x *host, u32 cpm)
  73. {
  74. #if HOST1X_HW < 6
  75. /* disable the ip_busy_timeout. this prevents write drops */
  76. host1x_sync_writel(host, 0, HOST1X_SYNC_IP_BUSY_TIMEOUT);
  77. /*
  78. * increase the auto-ack timout to the maximum value. 2d will hang
  79. * otherwise on Tegra2.
  80. */
  81. host1x_sync_writel(host, 0xff, HOST1X_SYNC_CTXSW_TIMEOUT_CFG);
  82. /* update host clocks per usec */
  83. host1x_sync_writel(host, cpm, HOST1X_SYNC_USEC_CLK);
  84. #endif
  85. #if HOST1X_HW >= 8
  86. u32 id;
  87. /*
  88. * Program threshold interrupt destination among 8 lines per VM,
  89. * per syncpoint. For each group of 64 syncpoints (corresponding to two
  90. * interrupt status registers), direct to one interrupt line, going
  91. * around in a round robin fashion.
  92. */
  93. for (id = 0; id < host->info->nb_pts; id++) {
  94. u32 reg_offset = id / 64;
  95. u32 irq_index = reg_offset % host->num_syncpt_irqs;
  96. host1x_sync_writel(host, irq_index, HOST1X_SYNC_SYNCPT_INTR_DEST(id));
  97. }
  98. #endif
  99. return 0;
  100. }
  101. static void host1x_intr_set_syncpt_threshold(struct host1x *host,
  102. unsigned int id,
  103. u32 thresh)
  104. {
  105. host1x_sync_writel(host, thresh, HOST1X_SYNC_SYNCPT_INT_THRESH(id));
  106. }
  107. static void host1x_intr_enable_syncpt_intr(struct host1x *host,
  108. unsigned int id)
  109. {
  110. host1x_sync_writel(host, BIT(id % 32),
  111. HOST1X_SYNC_SYNCPT_THRESH_INT_ENABLE_CPU0(id / 32));
  112. }
  113. static void host1x_intr_disable_syncpt_intr(struct host1x *host,
  114. unsigned int id)
  115. {
  116. host1x_sync_writel(host, BIT(id % 32),
  117. HOST1X_SYNC_SYNCPT_THRESH_INT_DISABLE(id / 32));
  118. host1x_sync_writel(host, BIT(id % 32),
  119. HOST1X_SYNC_SYNCPT_THRESH_CPU0_INT_STATUS(id / 32));
  120. }
  121. static const struct host1x_intr_ops host1x_intr_ops = {
  122. .init_host_sync = host1x_intr_init_host_sync,
  123. .set_syncpt_threshold = host1x_intr_set_syncpt_threshold,
  124. .enable_syncpt_intr = host1x_intr_enable_syncpt_intr,
  125. .disable_syncpt_intr = host1x_intr_disable_syncpt_intr,
  126. .disable_all_syncpt_intrs = host1x_intr_disable_all_syncpt_intrs,
  127. .isr = syncpt_thresh_isr,
  128. };