blob: 07df85b92ebfe3f36476fd7b9459efaef58e048a [file] [log] [blame]
Terje Bergstrom65793242013-03-22 16:34:03 +02001/*
2 * Tegra host1x Command DMA
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
19
20#include <asm/cacheflush.h>
21#include <linux/device.h>
22#include <linux/dma-mapping.h>
Thierry Reding35d747a2013-09-24 16:30:32 +020023#include <linux/host1x.h>
Terje Bergstrom65793242013-03-22 16:34:03 +020024#include <linux/interrupt.h>
25#include <linux/kernel.h>
26#include <linux/kfifo.h>
27#include <linux/slab.h>
28#include <trace/events/host1x.h>
29
30#include "cdma.h"
31#include "channel.h"
32#include "dev.h"
33#include "debug.h"
Terje Bergstrom65793242013-03-22 16:34:03 +020034#include "job.h"
35
36/*
37 * push_buffer
38 *
39 * The push buffer is a circular array of words to be fetched by command DMA.
40 * Note that it works slightly differently to the sync queue; fence == pos
41 * means that the push buffer is full, not empty.
42 */
43
Thierry Redinge1f338c2019-02-01 14:28:30 +010044/*
45 * Typically the commands written into the push buffer are a pair of words. We
46 * use slots to represent each of these pairs and to simplify things. Note the
47 * strange number of slots allocated here. 512 slots will fit exactly within a
48 * single memory page. We also need one additional word at the end of the push
49 * buffer for the RESTART opcode that will instruct the CDMA to jump back to
50 * the beginning of the push buffer. With 512 slots, this means that we'll use
51 * 2 memory pages and waste 4092 bytes of the second page that will never be
52 * used.
53 */
54#define HOST1X_PUSHBUFFER_SLOTS 511
Terje Bergstrom65793242013-03-22 16:34:03 +020055
56/*
57 * Clean up push buffer resources
58 */
59static void host1x_pushbuffer_destroy(struct push_buffer *pb)
60{
61 struct host1x_cdma *cdma = pb_to_cdma(pb);
62 struct host1x *host1x = cdma_to_host1x(cdma);
63
Emil Goode2f8a6da2018-05-16 12:22:04 +020064 if (!pb->mapped)
Mikko Perttunen404bfb72016-12-14 13:16:14 +020065 return;
66
67 if (host1x->domain) {
68 iommu_unmap(host1x->domain, pb->dma, pb->alloc_size);
69 free_iova(&host1x->iova, iova_pfn(&host1x->iova, pb->dma));
70 }
71
72 dma_free_wc(host1x->dev, pb->alloc_size, pb->mapped, pb->phys);
Terje Bergstrom65793242013-03-22 16:34:03 +020073
74 pb->mapped = NULL;
75 pb->phys = 0;
76}
77
78/*
79 * Init push buffer resources
80 */
81static int host1x_pushbuffer_init(struct push_buffer *pb)
82{
83 struct host1x_cdma *cdma = pb_to_cdma(pb);
84 struct host1x *host1x = cdma_to_host1x(cdma);
Mikko Perttunen404bfb72016-12-14 13:16:14 +020085 struct iova *alloc;
86 u32 size;
87 int err;
Terje Bergstrom65793242013-03-22 16:34:03 +020088
89 pb->mapped = NULL;
90 pb->phys = 0;
Mikko Perttunen404bfb72016-12-14 13:16:14 +020091 pb->size = HOST1X_PUSHBUFFER_SLOTS * 8;
92
93 size = pb->size + 4;
Terje Bergstrom65793242013-03-22 16:34:03 +020094
95 /* initialize buffer pointers */
Mikko Perttunen404bfb72016-12-14 13:16:14 +020096 pb->fence = pb->size - 8;
Terje Bergstrom65793242013-03-22 16:34:03 +020097 pb->pos = 0;
98
Mikko Perttunen404bfb72016-12-14 13:16:14 +020099 if (host1x->domain) {
100 unsigned long shift;
101
102 size = iova_align(&host1x->iova, size);
103
104 pb->mapped = dma_alloc_wc(host1x->dev, size, &pb->phys,
105 GFP_KERNEL);
106 if (!pb->mapped)
107 return -ENOMEM;
108
109 shift = iova_shift(&host1x->iova);
110 alloc = alloc_iova(&host1x->iova, size >> shift,
111 host1x->iova_end >> shift, true);
112 if (!alloc) {
113 err = -ENOMEM;
114 goto iommu_free_mem;
115 }
116
117 pb->dma = iova_dma_addr(&host1x->iova, alloc);
118 err = iommu_map(host1x->domain, pb->dma, pb->phys, size,
119 IOMMU_READ);
120 if (err)
121 goto iommu_free_iova;
122 } else {
123 pb->mapped = dma_alloc_wc(host1x->dev, size, &pb->phys,
124 GFP_KERNEL);
125 if (!pb->mapped)
126 return -ENOMEM;
127
128 pb->dma = pb->phys;
129 }
130
131 pb->alloc_size = size;
Terje Bergstrom65793242013-03-22 16:34:03 +0200132
133 host1x_hw_pushbuffer_init(host1x, pb);
134
135 return 0;
136
Mikko Perttunen404bfb72016-12-14 13:16:14 +0200137iommu_free_iova:
138 __free_iova(&host1x->iova, alloc);
139iommu_free_mem:
Dmitry Osipenko27db6a02018-04-23 12:54:56 +0300140 dma_free_wc(host1x->dev, size, pb->mapped, pb->phys);
Mikko Perttunen404bfb72016-12-14 13:16:14 +0200141
142 return err;
Terje Bergstrom65793242013-03-22 16:34:03 +0200143}
144
145/*
146 * Push two words to the push buffer
147 * Caller must ensure push buffer is not full
148 */
149static void host1x_pushbuffer_push(struct push_buffer *pb, u32 op1, u32 op2)
150{
Thierry Redingebb24752016-06-23 11:21:51 +0200151 u32 *p = (u32 *)((void *)pb->mapped + pb->pos);
152
153 WARN_ON(pb->pos == pb->fence);
Terje Bergstrom65793242013-03-22 16:34:03 +0200154 *(p++) = op1;
155 *(p++) = op2;
Thierry Redinge1f338c2019-02-01 14:28:30 +0100156 pb->pos += 8;
157
158 if (pb->pos >= pb->size)
159 pb->pos -= pb->size;
Terje Bergstrom65793242013-03-22 16:34:03 +0200160}
161
162/*
163 * Pop a number of two word slots from the push buffer
164 * Caller must ensure push buffer is not empty
165 */
166static void host1x_pushbuffer_pop(struct push_buffer *pb, unsigned int slots)
167{
168 /* Advance the next write position */
Thierry Redinge1f338c2019-02-01 14:28:30 +0100169 pb->fence += slots * 8;
170
171 if (pb->fence >= pb->size)
172 pb->fence -= pb->size;
Terje Bergstrom65793242013-03-22 16:34:03 +0200173}
174
175/*
176 * Return the number of two word slots free in the push buffer
177 */
178static u32 host1x_pushbuffer_space(struct push_buffer *pb)
179{
Thierry Redinge1f338c2019-02-01 14:28:30 +0100180 unsigned int fence = pb->fence;
181
182 if (pb->fence < pb->pos)
183 fence += pb->size;
184
185 return (fence - pb->pos) / 8;
Terje Bergstrom65793242013-03-22 16:34:03 +0200186}
187
188/*
189 * Sleep (if necessary) until the requested event happens
190 * - CDMA_EVENT_SYNC_QUEUE_EMPTY : sync queue is completely empty.
191 * - Returns 1
192 * - CDMA_EVENT_PUSH_BUFFER_SPACE : there is space in the push buffer
193 * - Return the amount of space (> 0)
194 * Must be called with the cdma lock held.
195 */
196unsigned int host1x_cdma_wait_locked(struct host1x_cdma *cdma,
197 enum cdma_event event)
198{
199 for (;;) {
Thierry Reding0b8070d12016-06-23 11:35:50 +0200200 struct push_buffer *pb = &cdma->push_buffer;
Terje Bergstrom65793242013-03-22 16:34:03 +0200201 unsigned int space;
202
Thierry Reding0b8070d12016-06-23 11:35:50 +0200203 switch (event) {
204 case CDMA_EVENT_SYNC_QUEUE_EMPTY:
Terje Bergstrom65793242013-03-22 16:34:03 +0200205 space = list_empty(&cdma->sync_queue) ? 1 : 0;
Thierry Reding0b8070d12016-06-23 11:35:50 +0200206 break;
207
208 case CDMA_EVENT_PUSH_BUFFER_SPACE:
Terje Bergstrom65793242013-03-22 16:34:03 +0200209 space = host1x_pushbuffer_space(pb);
Thierry Reding0b8070d12016-06-23 11:35:50 +0200210 break;
211
212 default:
Terje Bergstrom65793242013-03-22 16:34:03 +0200213 WARN_ON(1);
214 return -EINVAL;
215 }
216
217 if (space)
218 return space;
219
220 trace_host1x_wait_cdma(dev_name(cdma_to_channel(cdma)->dev),
221 event);
222
223 /* If somebody has managed to already start waiting, yield */
224 if (cdma->event != CDMA_EVENT_NONE) {
225 mutex_unlock(&cdma->lock);
226 schedule();
227 mutex_lock(&cdma->lock);
228 continue;
229 }
Thierry Reding0b8070d12016-06-23 11:35:50 +0200230
Terje Bergstrom65793242013-03-22 16:34:03 +0200231 cdma->event = event;
232
233 mutex_unlock(&cdma->lock);
Arnd Bergmann0747a672018-12-10 22:51:04 +0100234 wait_for_completion(&cdma->complete);
Terje Bergstrom65793242013-03-22 16:34:03 +0200235 mutex_lock(&cdma->lock);
236 }
Thierry Reding0b8070d12016-06-23 11:35:50 +0200237
Terje Bergstrom65793242013-03-22 16:34:03 +0200238 return 0;
239}
240
241/*
Thierry Reding5a5fccb2019-02-01 14:28:24 +0100242 * Sleep (if necessary) until the push buffer has enough free space.
243 *
244 * Must be called with the cdma lock held.
245 */
246int host1x_cdma_wait_pushbuffer_space(struct host1x *host1x,
247 struct host1x_cdma *cdma,
248 unsigned int needed)
249{
250 while (true) {
251 struct push_buffer *pb = &cdma->push_buffer;
252 unsigned int space;
253
254 space = host1x_pushbuffer_space(pb);
255 if (space >= needed)
256 break;
257
258 trace_host1x_wait_cdma(dev_name(cdma_to_channel(cdma)->dev),
259 CDMA_EVENT_PUSH_BUFFER_SPACE);
260
261 host1x_hw_cdma_flush(host1x, cdma);
262
263 /* If somebody has managed to already start waiting, yield */
264 if (cdma->event != CDMA_EVENT_NONE) {
265 mutex_unlock(&cdma->lock);
266 schedule();
267 mutex_lock(&cdma->lock);
268 continue;
269 }
270
271 cdma->event = CDMA_EVENT_PUSH_BUFFER_SPACE;
272
273 mutex_unlock(&cdma->lock);
274 wait_for_completion(&cdma->complete);
275 mutex_lock(&cdma->lock);
276 }
277
278 return 0;
279}
280/*
Terje Bergstrom65793242013-03-22 16:34:03 +0200281 * Start timer that tracks the time spent by the job.
282 * Must be called with the cdma lock held.
283 */
284static void cdma_start_timer_locked(struct host1x_cdma *cdma,
285 struct host1x_job *job)
286{
287 struct host1x *host = cdma_to_host1x(cdma);
288
289 if (cdma->timeout.client) {
290 /* timer already started */
291 return;
292 }
293
294 cdma->timeout.client = job->client;
295 cdma->timeout.syncpt = host1x_syncpt_get(host, job->syncpt_id);
296 cdma->timeout.syncpt_val = job->syncpt_end;
297 cdma->timeout.start_ktime = ktime_get();
298
299 schedule_delayed_work(&cdma->timeout.wq,
300 msecs_to_jiffies(job->timeout));
301}
302
303/*
304 * Stop timer when a buffer submission completes.
305 * Must be called with the cdma lock held.
306 */
307static void stop_cdma_timer_locked(struct host1x_cdma *cdma)
308{
309 cancel_delayed_work(&cdma->timeout.wq);
Thierry Redingbf3d41c2018-05-16 14:12:33 +0200310 cdma->timeout.client = NULL;
Terje Bergstrom65793242013-03-22 16:34:03 +0200311}
312
313/*
314 * For all sync queue entries that have already finished according to the
315 * current sync point registers:
316 * - unpin & unref their mems
317 * - pop their push buffer slots
318 * - remove them from the sync queue
319 * This is normally called from the host code's worker thread, but can be
320 * called manually if necessary.
321 * Must be called with the cdma lock held.
322 */
323static void update_cdma_locked(struct host1x_cdma *cdma)
324{
325 bool signal = false;
326 struct host1x *host1x = cdma_to_host1x(cdma);
327 struct host1x_job *job, *n;
328
329 /* If CDMA is stopped, queue is cleared and we can return */
330 if (!cdma->running)
331 return;
332
333 /*
334 * Walk the sync queue, reading the sync point registers as necessary,
335 * to consume as many sync queue entries as possible without blocking
336 */
337 list_for_each_entry_safe(job, n, &cdma->sync_queue, list) {
338 struct host1x_syncpt *sp =
339 host1x_syncpt_get(host1x, job->syncpt_id);
340
341 /* Check whether this syncpt has completed, and bail if not */
342 if (!host1x_syncpt_is_expired(sp, job->syncpt_end)) {
343 /* Start timer on next pending syncpt */
344 if (job->timeout)
345 cdma_start_timer_locked(cdma, job);
Thierry Reding0b8070d12016-06-23 11:35:50 +0200346
Terje Bergstrom65793242013-03-22 16:34:03 +0200347 break;
348 }
349
350 /* Cancel timeout, when a buffer completes */
351 if (cdma->timeout.client)
352 stop_cdma_timer_locked(cdma);
353
354 /* Unpin the memory */
355 host1x_job_unpin(job);
356
357 /* Pop push buffer slots */
358 if (job->num_slots) {
359 struct push_buffer *pb = &cdma->push_buffer;
Thierry Reding6df633d2016-06-23 11:33:31 +0200360
Terje Bergstrom65793242013-03-22 16:34:03 +0200361 host1x_pushbuffer_pop(pb, job->num_slots);
Thierry Reding0b8070d12016-06-23 11:35:50 +0200362
Terje Bergstrom65793242013-03-22 16:34:03 +0200363 if (cdma->event == CDMA_EVENT_PUSH_BUFFER_SPACE)
364 signal = true;
365 }
366
367 list_del(&job->list);
368 host1x_job_put(job);
369 }
370
371 if (cdma->event == CDMA_EVENT_SYNC_QUEUE_EMPTY &&
372 list_empty(&cdma->sync_queue))
373 signal = true;
374
375 if (signal) {
376 cdma->event = CDMA_EVENT_NONE;
Arnd Bergmann0747a672018-12-10 22:51:04 +0100377 complete(&cdma->complete);
Terje Bergstrom65793242013-03-22 16:34:03 +0200378 }
379}
380
381void host1x_cdma_update_sync_queue(struct host1x_cdma *cdma,
382 struct device *dev)
383{
Terje Bergstrom65793242013-03-22 16:34:03 +0200384 struct host1x *host1x = cdma_to_host1x(cdma);
Thierry Reding0b8070d12016-06-23 11:35:50 +0200385 u32 restart_addr, syncpt_incrs, syncpt_val;
386 struct host1x_job *job = NULL;
Terje Bergstrom65793242013-03-22 16:34:03 +0200387
388 syncpt_val = host1x_syncpt_load(cdma->timeout.syncpt);
389
390 dev_dbg(dev, "%s: starting cleanup (thresh %d)\n",
391 __func__, syncpt_val);
392
393 /*
394 * Move the sync_queue read pointer to the first entry that hasn't
395 * completed based on the current HW syncpt value. It's likely there
396 * won't be any (i.e. we're still at the head), but covers the case
397 * where a syncpt incr happens just prior/during the teardown.
398 */
399
400 dev_dbg(dev, "%s: skip completed buffers still in sync_queue\n",
401 __func__);
402
403 list_for_each_entry(job, &cdma->sync_queue, list) {
404 if (syncpt_val < job->syncpt_end)
405 break;
406
407 host1x_job_dump(dev, job);
408 }
409
410 /*
411 * Walk the sync_queue, first incrementing with the CPU syncpts that
412 * are partially executed (the first buffer) or fully skipped while
413 * still in the current context (slots are also NOP-ed).
414 *
415 * At the point contexts are interleaved, syncpt increments must be
416 * done inline with the pushbuffer from a GATHER buffer to maintain
417 * the order (slots are modified to be a GATHER of syncpt incrs).
418 *
419 * Note: save in restart_addr the location where the timed out buffer
420 * started in the PB, so we can start the refetch from there (with the
421 * modified NOP-ed PB slots). This lets things appear to have completed
422 * properly for this buffer and resources are freed.
423 */
424
425 dev_dbg(dev, "%s: perform CPU incr on pending same ctx buffers\n",
426 __func__);
427
428 if (!list_empty(&cdma->sync_queue))
429 restart_addr = job->first_get;
430 else
431 restart_addr = cdma->last_pos;
432
433 /* do CPU increments as long as this context continues */
434 list_for_each_entry_from(job, &cdma->sync_queue, list) {
435 /* different context, gets us out of this loop */
436 if (job->client != cdma->timeout.client)
437 break;
438
439 /* won't need a timeout when replayed */
440 job->timeout = 0;
441
442 syncpt_incrs = job->syncpt_end - syncpt_val;
443 dev_dbg(dev, "%s: CPU incr (%d)\n", __func__, syncpt_incrs);
444
445 host1x_job_dump(dev, job);
446
447 /* safe to use CPU to incr syncpts */
448 host1x_hw_cdma_timeout_cpu_incr(host1x, cdma, job->first_get,
449 syncpt_incrs, job->syncpt_end,
450 job->num_slots);
451
452 syncpt_val += syncpt_incrs;
453 }
454
Thierry Reding6df633d2016-06-23 11:33:31 +0200455 /*
456 * The following sumbits from the same client may be dependent on the
Terje Bergstrom65793242013-03-22 16:34:03 +0200457 * failed submit and therefore they may fail. Force a small timeout
Thierry Reding6df633d2016-06-23 11:33:31 +0200458 * to make the queue cleanup faster.
459 */
Terje Bergstrom65793242013-03-22 16:34:03 +0200460
461 list_for_each_entry_from(job, &cdma->sync_queue, list)
462 if (job->client == cdma->timeout.client)
463 job->timeout = min_t(unsigned int, job->timeout, 500);
464
465 dev_dbg(dev, "%s: finished sync_queue modification\n", __func__);
466
467 /* roll back DMAGET and start up channel again */
468 host1x_hw_cdma_resume(host1x, cdma, restart_addr);
469}
470
471/*
472 * Create a cdma
473 */
474int host1x_cdma_init(struct host1x_cdma *cdma)
475{
476 int err;
477
478 mutex_init(&cdma->lock);
Arnd Bergmann0747a672018-12-10 22:51:04 +0100479 init_completion(&cdma->complete);
Terje Bergstrom65793242013-03-22 16:34:03 +0200480
481 INIT_LIST_HEAD(&cdma->sync_queue);
482
483 cdma->event = CDMA_EVENT_NONE;
484 cdma->running = false;
485 cdma->torndown = false;
486
487 err = host1x_pushbuffer_init(&cdma->push_buffer);
488 if (err)
489 return err;
Thierry Reding0b8070d12016-06-23 11:35:50 +0200490
Terje Bergstrom65793242013-03-22 16:34:03 +0200491 return 0;
492}
493
494/*
495 * Destroy a cdma
496 */
497int host1x_cdma_deinit(struct host1x_cdma *cdma)
498{
499 struct push_buffer *pb = &cdma->push_buffer;
500 struct host1x *host1x = cdma_to_host1x(cdma);
501
502 if (cdma->running) {
503 pr_warn("%s: CDMA still running\n", __func__);
504 return -EBUSY;
505 }
506
507 host1x_pushbuffer_destroy(pb);
508 host1x_hw_cdma_timeout_destroy(host1x, cdma);
509
510 return 0;
511}
512
513/*
514 * Begin a cdma submit
515 */
516int host1x_cdma_begin(struct host1x_cdma *cdma, struct host1x_job *job)
517{
518 struct host1x *host1x = cdma_to_host1x(cdma);
519
520 mutex_lock(&cdma->lock);
521
522 if (job->timeout) {
523 /* init state on first submit with timeout value */
524 if (!cdma->timeout.initialized) {
525 int err;
Thierry Reding6df633d2016-06-23 11:33:31 +0200526
Terje Bergstrom65793242013-03-22 16:34:03 +0200527 err = host1x_hw_cdma_timeout_init(host1x, cdma,
528 job->syncpt_id);
529 if (err) {
530 mutex_unlock(&cdma->lock);
531 return err;
532 }
533 }
534 }
Thierry Reding0b8070d12016-06-23 11:35:50 +0200535
Terje Bergstrom65793242013-03-22 16:34:03 +0200536 if (!cdma->running)
537 host1x_hw_cdma_start(host1x, cdma);
538
539 cdma->slots_free = 0;
540 cdma->slots_used = 0;
541 cdma->first_get = cdma->push_buffer.pos;
542
543 trace_host1x_cdma_begin(dev_name(job->channel->dev));
544 return 0;
545}
546
547/*
548 * Push two words into a push buffer slot
549 * Blocks as necessary if the push buffer is full.
550 */
551void host1x_cdma_push(struct host1x_cdma *cdma, u32 op1, u32 op2)
552{
553 struct host1x *host1x = cdma_to_host1x(cdma);
554 struct push_buffer *pb = &cdma->push_buffer;
555 u32 slots_free = cdma->slots_free;
556
Terje Bergstrom62364512013-03-22 16:34:04 +0200557 if (host1x_debug_trace_cmdbuf)
558 trace_host1x_cdma_push(dev_name(cdma_to_channel(cdma)->dev),
559 op1, op2);
560
Terje Bergstrom65793242013-03-22 16:34:03 +0200561 if (slots_free == 0) {
562 host1x_hw_cdma_flush(host1x, cdma);
563 slots_free = host1x_cdma_wait_locked(cdma,
564 CDMA_EVENT_PUSH_BUFFER_SPACE);
565 }
Thierry Reding0b8070d12016-06-23 11:35:50 +0200566
Terje Bergstrom65793242013-03-22 16:34:03 +0200567 cdma->slots_free = slots_free - 1;
568 cdma->slots_used++;
569 host1x_pushbuffer_push(pb, op1, op2);
570}
571
572/*
Thierry Reding5a5fccb2019-02-01 14:28:24 +0100573 * Push four words into two consecutive push buffer slots. Note that extra
574 * care needs to be taken not to split the two slots across the end of the
575 * push buffer. Otherwise the RESTART opcode at the end of the push buffer
576 * that ensures processing will restart at the beginning will break up the
577 * four words.
578 *
579 * Blocks as necessary if the push buffer is full.
580 */
581void host1x_cdma_push_wide(struct host1x_cdma *cdma, u32 op1, u32 op2,
582 u32 op3, u32 op4)
583{
584 struct host1x_channel *channel = cdma_to_channel(cdma);
585 struct host1x *host1x = cdma_to_host1x(cdma);
586 struct push_buffer *pb = &cdma->push_buffer;
587 unsigned int needed = 2, extra = 0, i;
588 unsigned int space = cdma->slots_free;
589
590 if (host1x_debug_trace_cmdbuf)
591 trace_host1x_cdma_push_wide(dev_name(channel->dev), op1, op2,
592 op3, op4);
593
594 /* compute number of extra slots needed for padding */
595 if (pb->pos + 16 > pb->size) {
596 extra = (pb->size - pb->pos) / 8;
597 needed += extra;
598 }
599
600 host1x_cdma_wait_pushbuffer_space(host1x, cdma, needed);
601 space = host1x_pushbuffer_space(pb);
602
603 cdma->slots_free = space - needed;
604 cdma->slots_used += needed;
605
606 /*
607 * Note that we rely on the fact that this is only used to submit wide
608 * gather opcodes, which consist of 3 words, and they are padded with
609 * a NOP to avoid having to deal with fractional slots (a slot always
610 * represents 2 words). The fourth opcode passed to this function will
611 * therefore always be a NOP.
612 *
613 * This works around a slight ambiguity when it comes to opcodes. For
614 * all current host1x incarnations the NOP opcode uses the exact same
615 * encoding (0x20000000), so we could hard-code the value here, but a
616 * new incarnation may change it and break that assumption.
617 */
618 for (i = 0; i < extra; i++)
619 host1x_pushbuffer_push(pb, op4, op4);
620
621 host1x_pushbuffer_push(pb, op1, op2);
622 host1x_pushbuffer_push(pb, op3, op4);
623}
624
625/*
Terje Bergstrom65793242013-03-22 16:34:03 +0200626 * End a cdma submit
627 * Kick off DMA, add job to the sync queue, and a number of slots to be freed
628 * from the pushbuffer. The handles for a submit must all be pinned at the same
629 * time, but they can be unpinned in smaller chunks.
630 */
631void host1x_cdma_end(struct host1x_cdma *cdma,
632 struct host1x_job *job)
633{
634 struct host1x *host1x = cdma_to_host1x(cdma);
635 bool idle = list_empty(&cdma->sync_queue);
636
637 host1x_hw_cdma_flush(host1x, cdma);
638
639 job->first_get = cdma->first_get;
640 job->num_slots = cdma->slots_used;
641 host1x_job_get(job);
642 list_add_tail(&job->list, &cdma->sync_queue);
643
644 /* start timer on idle -> active transitions */
645 if (job->timeout && idle)
646 cdma_start_timer_locked(cdma, job);
647
648 trace_host1x_cdma_end(dev_name(job->channel->dev));
649 mutex_unlock(&cdma->lock);
650}
651
652/*
653 * Update cdma state according to current sync point values
654 */
655void host1x_cdma_update(struct host1x_cdma *cdma)
656{
657 mutex_lock(&cdma->lock);
658 update_cdma_locked(cdma);
659 mutex_unlock(&cdma->lock);
660}