channel_hw.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. /*
  2. * Tegra host1x Channel
  3. *
  4. * Copyright (c) 2010-2013, NVIDIA Corporation.
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms and conditions of the GNU General Public License,
  8. * version 2, as published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope it will be useful, but WITHOUT
  11. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  13. * more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #include <linux/host1x.h>
  19. #include <linux/slab.h>
  20. #include <trace/events/host1x.h>
  21. #include "../channel.h"
  22. #include "../dev.h"
  23. #include "../intr.h"
  24. #include "../job.h"
  25. #define HOST1X_CHANNEL_SIZE 16384
  26. #define TRACE_MAX_LENGTH 128U
  27. static void trace_write_gather(struct host1x_cdma *cdma, struct host1x_bo *bo,
  28. u32 offset, u32 words)
  29. {
  30. struct device *dev = cdma_to_channel(cdma)->dev;
  31. void *mem = NULL;
  32. if (host1x_debug_trace_cmdbuf)
  33. mem = host1x_bo_mmap(bo);
  34. if (mem) {
  35. u32 i;
  36. /*
  37. * Write in batches of 128 as there seems to be a limit
  38. * of how much you can output to ftrace at once.
  39. */
  40. for (i = 0; i < words; i += TRACE_MAX_LENGTH) {
  41. u32 num_words = min(words - i, TRACE_MAX_LENGTH);
  42. offset += i * sizeof(u32);
  43. trace_host1x_cdma_push_gather(dev_name(dev), bo,
  44. num_words, offset,
  45. mem);
  46. }
  47. host1x_bo_munmap(bo, mem);
  48. }
  49. }
  50. static void submit_gathers(struct host1x_job *job)
  51. {
  52. struct host1x_cdma *cdma = &job->channel->cdma;
  53. unsigned int i;
  54. for (i = 0; i < job->num_gathers; i++) {
  55. struct host1x_job_gather *g = &job->gathers[i];
  56. u32 op1 = host1x_opcode_gather(g->words);
  57. u32 op2 = g->base + g->offset;
  58. trace_write_gather(cdma, g->bo, g->offset, op1 & 0xffff);
  59. host1x_cdma_push(cdma, op1, op2);
  60. }
  61. }
  62. static inline void synchronize_syncpt_base(struct host1x_job *job)
  63. {
  64. struct host1x *host = dev_get_drvdata(job->channel->dev->parent);
  65. struct host1x_syncpt *sp = host->syncpt + job->syncpt_id;
  66. u32 id, value;
  67. value = host1x_syncpt_read_max(sp);
  68. id = sp->base->id;
  69. host1x_cdma_push(&job->channel->cdma,
  70. host1x_opcode_setclass(HOST1X_CLASS_HOST1X,
  71. HOST1X_UCLASS_LOAD_SYNCPT_BASE, 1),
  72. HOST1X_UCLASS_LOAD_SYNCPT_BASE_BASE_INDX_F(id) |
  73. HOST1X_UCLASS_LOAD_SYNCPT_BASE_VALUE_F(value));
  74. }
  75. static int channel_submit(struct host1x_job *job)
  76. {
  77. struct host1x_channel *ch = job->channel;
  78. struct host1x_syncpt *sp;
  79. u32 user_syncpt_incrs = job->syncpt_incrs;
  80. u32 prev_max = 0;
  81. u32 syncval;
  82. int err;
  83. struct host1x_waitlist *completed_waiter = NULL;
  84. struct host1x *host = dev_get_drvdata(ch->dev->parent);
  85. sp = host->syncpt + job->syncpt_id;
  86. trace_host1x_channel_submit(dev_name(ch->dev),
  87. job->num_gathers, job->num_relocs,
  88. job->num_waitchk, job->syncpt_id,
  89. job->syncpt_incrs);
  90. /* before error checks, return current max */
  91. prev_max = job->syncpt_end = host1x_syncpt_read_max(sp);
  92. /* get submit lock */
  93. err = mutex_lock_interruptible(&ch->submitlock);
  94. if (err)
  95. goto error;
  96. completed_waiter = kzalloc(sizeof(*completed_waiter), GFP_KERNEL);
  97. if (!completed_waiter) {
  98. mutex_unlock(&ch->submitlock);
  99. err = -ENOMEM;
  100. goto error;
  101. }
  102. /* begin a CDMA submit */
  103. err = host1x_cdma_begin(&ch->cdma, job);
  104. if (err) {
  105. mutex_unlock(&ch->submitlock);
  106. goto error;
  107. }
  108. if (job->serialize) {
  109. /*
  110. * Force serialization by inserting a host wait for the
  111. * previous job to finish before this one can commence.
  112. */
  113. host1x_cdma_push(&ch->cdma,
  114. host1x_opcode_setclass(HOST1X_CLASS_HOST1X,
  115. host1x_uclass_wait_syncpt_r(), 1),
  116. host1x_class_host_wait_syncpt(job->syncpt_id,
  117. host1x_syncpt_read_max(sp)));
  118. }
  119. /* Synchronize base register to allow using it for relative waiting */
  120. if (sp->base)
  121. synchronize_syncpt_base(job);
  122. syncval = host1x_syncpt_incr_max(sp, user_syncpt_incrs);
  123. job->syncpt_end = syncval;
  124. /* add a setclass for modules that require it */
  125. if (job->class)
  126. host1x_cdma_push(&ch->cdma,
  127. host1x_opcode_setclass(job->class, 0, 0),
  128. HOST1X_OPCODE_NOP);
  129. submit_gathers(job);
  130. /* end CDMA submit & stash pinned hMems into sync queue */
  131. host1x_cdma_end(&ch->cdma, job);
  132. trace_host1x_channel_submitted(dev_name(ch->dev), prev_max, syncval);
  133. /* schedule a submit complete interrupt */
  134. err = host1x_intr_add_action(host, job->syncpt_id, syncval,
  135. HOST1X_INTR_ACTION_SUBMIT_COMPLETE, ch,
  136. completed_waiter, NULL);
  137. completed_waiter = NULL;
  138. WARN(err, "Failed to set submit complete interrupt");
  139. mutex_unlock(&ch->submitlock);
  140. return 0;
  141. error:
  142. kfree(completed_waiter);
  143. return err;
  144. }
  145. static int host1x_channel_init(struct host1x_channel *ch, struct host1x *dev,
  146. unsigned int index)
  147. {
  148. ch->id = index;
  149. mutex_init(&ch->reflock);
  150. mutex_init(&ch->submitlock);
  151. ch->regs = dev->regs + index * HOST1X_CHANNEL_SIZE;
  152. return 0;
  153. }
  154. static const struct host1x_channel_ops host1x_channel_ops = {
  155. .init = host1x_channel_init,
  156. .submit = channel_submit,
  157. };