syncpt_hw.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Tegra host1x Syncpoints
  4. *
  5. * Copyright (c) 2010-2013, NVIDIA Corporation.
  6. */
  7. #include <linux/io.h>
  8. #include "../dev.h"
  9. #include "../syncpt.h"
  10. /*
  11. * Write the current syncpoint value back to hw.
  12. */
  13. static void syncpt_restore(struct host1x_syncpt *sp)
  14. {
  15. u32 min = host1x_syncpt_read_min(sp);
  16. struct host1x *host = sp->host;
  17. host1x_sync_writel(host, min, HOST1X_SYNC_SYNCPT(sp->id));
  18. }
  19. /*
  20. * Write the current waitbase value back to hw.
  21. */
  22. static void syncpt_restore_wait_base(struct host1x_syncpt *sp)
  23. {
  24. #if HOST1X_HW < 7
  25. struct host1x *host = sp->host;
  26. host1x_sync_writel(host, sp->base_val,
  27. HOST1X_SYNC_SYNCPT_BASE(sp->id));
  28. #endif
  29. }
  30. /*
  31. * Read waitbase value from hw.
  32. */
  33. static void syncpt_read_wait_base(struct host1x_syncpt *sp)
  34. {
  35. #if HOST1X_HW < 7
  36. struct host1x *host = sp->host;
  37. sp->base_val =
  38. host1x_sync_readl(host, HOST1X_SYNC_SYNCPT_BASE(sp->id));
  39. #endif
  40. }
  41. /*
  42. * Updates the last value read from hardware.
  43. */
  44. static u32 syncpt_load(struct host1x_syncpt *sp)
  45. {
  46. struct host1x *host = sp->host;
  47. u32 old, live;
  48. /* Loop in case there's a race writing to min_val */
  49. do {
  50. old = host1x_syncpt_read_min(sp);
  51. live = host1x_sync_readl(host, HOST1X_SYNC_SYNCPT(sp->id));
  52. } while ((u32)atomic_cmpxchg(&sp->min_val, old, live) != old);
  53. if (!host1x_syncpt_check_max(sp, live))
  54. dev_err(host->dev, "%s failed: id=%u, min=%d, max=%d\n",
  55. __func__, sp->id, host1x_syncpt_read_min(sp),
  56. host1x_syncpt_read_max(sp));
  57. return live;
  58. }
  59. /*
  60. * Write a cpu syncpoint increment to the hardware, without touching
  61. * the cache.
  62. */
  63. static int syncpt_cpu_incr(struct host1x_syncpt *sp)
  64. {
  65. struct host1x *host = sp->host;
  66. u32 reg_offset = sp->id / 32;
  67. if (!host1x_syncpt_client_managed(sp) &&
  68. host1x_syncpt_idle(sp))
  69. return -EINVAL;
  70. host1x_sync_writel(host, BIT(sp->id % 32),
  71. HOST1X_SYNC_SYNCPT_CPU_INCR(reg_offset));
  72. wmb();
  73. return 0;
  74. }
  75. /**
  76. * syncpt_assign_to_channel() - Assign syncpoint to channel
  77. * @sp: syncpoint
  78. * @ch: channel
  79. *
  80. * On chips with the syncpoint protection feature (Tegra186+), assign @sp to
  81. * @ch, preventing other channels from incrementing the syncpoints. If @ch is
  82. * NULL, unassigns the syncpoint.
  83. *
  84. * On older chips, do nothing.
  85. */
  86. static void syncpt_assign_to_channel(struct host1x_syncpt *sp,
  87. struct host1x_channel *ch)
  88. {
  89. #if HOST1X_HW >= 6
  90. struct host1x *host = sp->host;
  91. host1x_sync_writel(host,
  92. HOST1X_SYNC_SYNCPT_CH_APP_CH(ch ? ch->id : 0xff),
  93. HOST1X_SYNC_SYNCPT_CH_APP(sp->id));
  94. #endif
  95. }
  96. /**
  97. * syncpt_enable_protection() - Enable syncpoint protection
  98. * @host: host1x instance
  99. *
  100. * On chips with the syncpoint protection feature (Tegra186+), enable this
  101. * feature. On older chips, do nothing.
  102. */
  103. static void syncpt_enable_protection(struct host1x *host)
  104. {
  105. #if HOST1X_HW >= 6
  106. if (!host->hv_regs)
  107. return;
  108. host1x_hypervisor_writel(host, HOST1X_HV_SYNCPT_PROT_EN_CH_EN,
  109. HOST1X_HV_SYNCPT_PROT_EN);
  110. #endif
  111. }
  112. static const struct host1x_syncpt_ops host1x_syncpt_ops = {
  113. .restore = syncpt_restore,
  114. .restore_wait_base = syncpt_restore_wait_base,
  115. .load_wait_base = syncpt_read_wait_base,
  116. .load = syncpt_load,
  117. .cpu_incr = syncpt_cpu_incr,
  118. .assign_to_channel = syncpt_assign_to_channel,
  119. .enable_protection = syncpt_enable_protection,
  120. };