gpu: host1x: Make host1x header file public
[linux-2.6.git] / drivers / gpu / host1x / hw / channel_hw.c
blobc950bc655adebcbf4e2275ce67aaf0dd482c17fb
1 /*
2 * Tegra host1x Channel
4 * Copyright (c) 2010-2013, NVIDIA Corporation.
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.
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.
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/>.
19 #include <linux/host1x.h>
20 #include <linux/slab.h>
22 #include <trace/events/host1x.h>
24 #include "host1x_bo.h"
25 #include "channel.h"
26 #include "dev.h"
27 #include "intr.h"
28 #include "job.h"
30 #define HOST1X_CHANNEL_SIZE 16384
31 #define TRACE_MAX_LENGTH 128U
33 static void trace_write_gather(struct host1x_cdma *cdma, struct host1x_bo *bo,
34 u32 offset, u32 words)
36 void *mem = NULL;
38 if (host1x_debug_trace_cmdbuf)
39 mem = host1x_bo_mmap(bo);
41 if (mem) {
42 u32 i;
44 * Write in batches of 128 as there seems to be a limit
45 * of how much you can output to ftrace at once.
47 for (i = 0; i < words; i += TRACE_MAX_LENGTH) {
48 trace_host1x_cdma_push_gather(
49 dev_name(cdma_to_channel(cdma)->dev),
50 (u32)bo, min(words - i, TRACE_MAX_LENGTH),
51 offset + i * sizeof(u32), mem);
53 host1x_bo_munmap(bo, mem);
57 static void submit_gathers(struct host1x_job *job)
59 struct host1x_cdma *cdma = &job->channel->cdma;
60 unsigned int i;
62 for (i = 0; i < job->num_gathers; i++) {
63 struct host1x_job_gather *g = &job->gathers[i];
64 u32 op1 = host1x_opcode_gather(g->words);
65 u32 op2 = g->base + g->offset;
66 trace_write_gather(cdma, g->bo, g->offset, op1 & 0xffff);
67 host1x_cdma_push(cdma, op1, op2);
71 static int channel_submit(struct host1x_job *job)
73 struct host1x_channel *ch = job->channel;
74 struct host1x_syncpt *sp;
75 u32 user_syncpt_incrs = job->syncpt_incrs;
76 u32 prev_max = 0;
77 u32 syncval;
78 int err;
79 struct host1x_waitlist *completed_waiter = NULL;
80 struct host1x *host = dev_get_drvdata(ch->dev->parent);
82 sp = host->syncpt + job->syncpt_id;
83 trace_host1x_channel_submit(dev_name(ch->dev),
84 job->num_gathers, job->num_relocs,
85 job->num_waitchk, job->syncpt_id,
86 job->syncpt_incrs);
88 /* before error checks, return current max */
89 prev_max = job->syncpt_end = host1x_syncpt_read_max(sp);
91 /* get submit lock */
92 err = mutex_lock_interruptible(&ch->submitlock);
93 if (err)
94 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;
103 /* begin a CDMA submit */
104 err = host1x_cdma_begin(&ch->cdma, job);
105 if (err) {
106 mutex_unlock(&ch->submitlock);
107 goto error;
110 if (job->serialize) {
112 * Force serialization by inserting a host wait for the
113 * previous job to finish before this one can commence.
115 host1x_cdma_push(&ch->cdma,
116 host1x_opcode_setclass(HOST1X_CLASS_HOST1X,
117 host1x_uclass_wait_syncpt_r(), 1),
118 host1x_class_host_wait_syncpt(job->syncpt_id,
119 host1x_syncpt_read_max(sp)));
122 syncval = host1x_syncpt_incr_max(sp, user_syncpt_incrs);
124 job->syncpt_end = syncval;
126 /* add a setclass for modules that require it */
127 if (job->class)
128 host1x_cdma_push(&ch->cdma,
129 host1x_opcode_setclass(job->class, 0, 0),
130 HOST1X_OPCODE_NOP);
132 submit_gathers(job);
134 /* end CDMA submit & stash pinned hMems into sync queue */
135 host1x_cdma_end(&ch->cdma, job);
137 trace_host1x_channel_submitted(dev_name(ch->dev), prev_max, syncval);
139 /* schedule a submit complete interrupt */
140 err = host1x_intr_add_action(host, job->syncpt_id, syncval,
141 HOST1X_INTR_ACTION_SUBMIT_COMPLETE, ch,
142 completed_waiter, NULL);
143 completed_waiter = NULL;
144 WARN(err, "Failed to set submit complete interrupt");
146 mutex_unlock(&ch->submitlock);
148 return 0;
150 error:
151 kfree(completed_waiter);
152 return err;
155 static int host1x_channel_init(struct host1x_channel *ch, struct host1x *dev,
156 unsigned int index)
158 ch->id = index;
159 mutex_init(&ch->reflock);
160 mutex_init(&ch->submitlock);
162 ch->regs = dev->regs + index * HOST1X_CHANNEL_SIZE;
163 return 0;
166 static const struct host1x_channel_ops host1x_channel_ops = {
167 .init = host1x_channel_init,
168 .submit = channel_submit,