blob: 166e84e4f0d48f80eacb992c3ccc8964af89b28d [file] [log] [blame]
Rob Clark7198e6b2013-07-19 12:59:32 -04001/*
2 * Copyright (C) 2013 Red Hat
3 * Author: Rob Clark <robdclark@gmail.com>
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 as published by
7 * the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along with
15 * this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
Rob Clarkf0a42bb2016-06-16 16:08:19 -040018#include <linux/sync_file.h>
19
Rob Clark7198e6b2013-07-19 12:59:32 -040020#include "msm_drv.h"
21#include "msm_gpu.h"
22#include "msm_gem.h"
23
24/*
25 * Cmdstream submission:
26 */
27
Rob Clark7198e6b2013-07-19 12:59:32 -040028/* make sure these don't conflict w/ MSM_SUBMIT_BO_x */
Rob Clark340faef2016-03-14 13:56:37 -040029#define BO_VALID 0x8000 /* is current addr in cmdstream correct/valid? */
Rob Clark7198e6b2013-07-19 12:59:32 -040030#define BO_LOCKED 0x4000
31#define BO_PINNED 0x2000
32
Rob Clark7198e6b2013-07-19 12:59:32 -040033static struct msm_gem_submit *submit_create(struct drm_device *dev,
Rob Clark6b597ce2016-06-01 14:17:40 -040034 struct msm_gpu *gpu, int nr_bos, int nr_cmds)
Rob Clark7198e6b2013-07-19 12:59:32 -040035{
36 struct msm_gem_submit *submit;
Rob Clark6b597ce2016-06-01 14:17:40 -040037 int sz = sizeof(*submit) + (nr_bos * sizeof(submit->bos[0])) +
38 (nr_cmds * sizeof(*submit->cmd));
Rob Clark7198e6b2013-07-19 12:59:32 -040039
40 submit = kmalloc(sz, GFP_TEMPORARY | __GFP_NOWARN | __GFP_NORETRY);
Rob Clark6860b562016-05-03 09:49:40 -040041 if (!submit)
42 return NULL;
Rob Clark7198e6b2013-07-19 12:59:32 -040043
Rob Clark6860b562016-05-03 09:49:40 -040044 submit->dev = dev;
45 submit->gpu = gpu;
Rob Clarkba344af2016-05-24 18:43:26 -040046 submit->fence = NULL;
Rob Clark4816b622016-05-03 10:10:15 -040047 submit->pid = get_pid(task_pid(current));
Rob Clark6b597ce2016-06-01 14:17:40 -040048 submit->cmd = (void *)&submit->bos[nr_bos];
Rob Clark7198e6b2013-07-19 12:59:32 -040049
Rob Clark6860b562016-05-03 09:49:40 -040050 /* initially, until copy_from_user() and bo lookup succeeds: */
51 submit->nr_bos = 0;
52 submit->nr_cmds = 0;
53
Rob Clarkba344af2016-05-24 18:43:26 -040054 INIT_LIST_HEAD(&submit->node);
Rob Clark6860b562016-05-03 09:49:40 -040055 INIT_LIST_HEAD(&submit->bo_list);
56 ww_acquire_init(&submit->ticket, &reservation_ww_class);
Rob Clark7198e6b2013-07-19 12:59:32 -040057
58 return submit;
59}
60
Rob Clark40e68152016-05-03 09:50:26 -040061void msm_gem_submit_free(struct msm_gem_submit *submit)
62{
Chris Wilsonf54d1862016-10-25 13:00:45 +010063 dma_fence_put(submit->fence);
Rob Clark40e68152016-05-03 09:50:26 -040064 list_del(&submit->node);
Rob Clark4816b622016-05-03 10:10:15 -040065 put_pid(submit->pid);
Rob Clark40e68152016-05-03 09:50:26 -040066 kfree(submit);
67}
68
Rob Clark89f82cb2016-08-22 15:15:23 -040069static inline unsigned long __must_check
70copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
71{
72 if (access_ok(VERIFY_READ, from, n))
73 return __copy_from_user_inatomic(to, from, n);
74 return -EFAULT;
75}
76
Rob Clark7198e6b2013-07-19 12:59:32 -040077static int submit_lookup_objects(struct msm_gem_submit *submit,
78 struct drm_msm_gem_submit *args, struct drm_file *file)
79{
80 unsigned i;
81 int ret = 0;
82
83 spin_lock(&file->table_lock);
Rob Clark89f82cb2016-08-22 15:15:23 -040084 pagefault_disable();
Rob Clark7198e6b2013-07-19 12:59:32 -040085
86 for (i = 0; i < args->nr_bos; i++) {
87 struct drm_msm_gem_submit_bo submit_bo;
88 struct drm_gem_object *obj;
89 struct msm_gem_object *msm_obj;
90 void __user *userptr =
Gustavo Padovan3ed605b2016-04-26 12:32:27 -030091 u64_to_user_ptr(args->bos + (i * sizeof(submit_bo)));
Rob Clark7198e6b2013-07-19 12:59:32 -040092
Rob Clarka9e26ca2016-06-01 14:02:51 -040093 /* make sure we don't have garbage flags, in case we hit
94 * error path before flags is initialized:
95 */
96 submit->bos[i].flags = 0;
97
Rob Clark89f82cb2016-08-22 15:15:23 -040098 ret = copy_from_user_inatomic(&submit_bo, userptr, sizeof(submit_bo));
99 if (unlikely(ret)) {
100 pagefault_enable();
101 spin_unlock(&file->table_lock);
102 ret = copy_from_user(&submit_bo, userptr, sizeof(submit_bo));
103 if (ret)
104 goto out;
105 spin_lock(&file->table_lock);
106 pagefault_disable();
Rob Clark7198e6b2013-07-19 12:59:32 -0400107 }
108
Rob Clark93ddb0d2014-03-03 09:42:33 -0500109 if (submit_bo.flags & ~MSM_SUBMIT_BO_FLAGS) {
Rob Clark19872532013-09-06 15:36:40 -0400110 DRM_ERROR("invalid flags: %x\n", submit_bo.flags);
Rob Clark7198e6b2013-07-19 12:59:32 -0400111 ret = -EINVAL;
112 goto out_unlock;
113 }
114
115 submit->bos[i].flags = submit_bo.flags;
116 /* in validate_objects() we figure out if this is true: */
117 submit->bos[i].iova = submit_bo.presumed;
118
119 /* normally use drm_gem_object_lookup(), but for bulk lookup
120 * all under single table_lock just hit object_idr directly:
121 */
122 obj = idr_find(&file->object_idr, submit_bo.handle);
123 if (!obj) {
Rob Clark19872532013-09-06 15:36:40 -0400124 DRM_ERROR("invalid handle %u at index %u\n", submit_bo.handle, i);
Rob Clark7198e6b2013-07-19 12:59:32 -0400125 ret = -EINVAL;
126 goto out_unlock;
127 }
128
129 msm_obj = to_msm_bo(obj);
130
131 if (!list_empty(&msm_obj->submit_entry)) {
Rob Clark19872532013-09-06 15:36:40 -0400132 DRM_ERROR("handle %u at index %u already on submit list\n",
Rob Clark7198e6b2013-07-19 12:59:32 -0400133 submit_bo.handle, i);
134 ret = -EINVAL;
135 goto out_unlock;
136 }
137
138 drm_gem_object_reference(obj);
139
140 submit->bos[i].obj = msm_obj;
141
142 list_add_tail(&msm_obj->submit_entry, &submit->bo_list);
143 }
144
145out_unlock:
Rob Clark89f82cb2016-08-22 15:15:23 -0400146 pagefault_enable();
Rob Clark7198e6b2013-07-19 12:59:32 -0400147 spin_unlock(&file->table_lock);
148
Rob Clark89f82cb2016-08-22 15:15:23 -0400149out:
150 submit->nr_bos = i;
151
Rob Clark7198e6b2013-07-19 12:59:32 -0400152 return ret;
153}
154
155static void submit_unlock_unpin_bo(struct msm_gem_submit *submit, int i)
156{
157 struct msm_gem_object *msm_obj = submit->bos[i].obj;
158
159 if (submit->bos[i].flags & BO_PINNED)
160 msm_gem_put_iova(&msm_obj->base, submit->gpu->id);
161
162 if (submit->bos[i].flags & BO_LOCKED)
163 ww_mutex_unlock(&msm_obj->resv->lock);
164
165 if (!(submit->bos[i].flags & BO_VALID))
166 submit->bos[i].iova = 0;
167
168 submit->bos[i].flags &= ~(BO_LOCKED | BO_PINNED);
169}
170
171/* This is where we make sure all the bo's are reserved and pin'd: */
Rob Clark340faef2016-03-14 13:56:37 -0400172static int submit_lock_objects(struct msm_gem_submit *submit)
Rob Clark7198e6b2013-07-19 12:59:32 -0400173{
174 int contended, slow_locked = -1, i, ret = 0;
175
176retry:
Rob Clark7198e6b2013-07-19 12:59:32 -0400177 for (i = 0; i < submit->nr_bos; i++) {
178 struct msm_gem_object *msm_obj = submit->bos[i].obj;
Rob Clark7198e6b2013-07-19 12:59:32 -0400179
180 if (slow_locked == i)
181 slow_locked = -1;
182
183 contended = i;
184
185 if (!(submit->bos[i].flags & BO_LOCKED)) {
186 ret = ww_mutex_lock_interruptible(&msm_obj->resv->lock,
187 &submit->ticket);
188 if (ret)
189 goto fail;
190 submit->bos[i].flags |= BO_LOCKED;
191 }
Rob Clark7198e6b2013-07-19 12:59:32 -0400192 }
193
194 ww_acquire_done(&submit->ticket);
195
196 return 0;
197
198fail:
199 for (; i >= 0; i--)
200 submit_unlock_unpin_bo(submit, i);
201
202 if (slow_locked > 0)
203 submit_unlock_unpin_bo(submit, slow_locked);
204
205 if (ret == -EDEADLK) {
206 struct msm_gem_object *msm_obj = submit->bos[contended].obj;
207 /* we lost out in a seqno race, lock and retry.. */
208 ret = ww_mutex_lock_slow_interruptible(&msm_obj->resv->lock,
209 &submit->ticket);
210 if (!ret) {
211 submit->bos[contended].flags |= BO_LOCKED;
212 slow_locked = contended;
213 goto retry;
214 }
215 }
216
217 return ret;
218}
219
Rob Clarkb6295f92016-03-15 18:26:28 -0400220static int submit_fence_sync(struct msm_gem_submit *submit)
221{
222 int i, ret = 0;
223
224 for (i = 0; i < submit->nr_bos; i++) {
225 struct msm_gem_object *msm_obj = submit->bos[i].obj;
226 bool write = submit->bos[i].flags & MSM_SUBMIT_BO_WRITE;
227
228 ret = msm_gem_sync_object(&msm_obj->base, submit->gpu->fctx, write);
229 if (ret)
230 break;
231 }
232
233 return ret;
234}
235
Rob Clark340faef2016-03-14 13:56:37 -0400236static int submit_pin_objects(struct msm_gem_submit *submit)
237{
238 int i, ret = 0;
239
240 submit->valid = true;
241
242 for (i = 0; i < submit->nr_bos; i++) {
243 struct msm_gem_object *msm_obj = submit->bos[i].obj;
Rob Clark78babc12016-11-11 12:06:46 -0500244 uint64_t iova;
Rob Clark340faef2016-03-14 13:56:37 -0400245
246 /* if locking succeeded, pin bo: */
247 ret = msm_gem_get_iova_locked(&msm_obj->base,
248 submit->gpu->id, &iova);
249
250 if (ret)
251 break;
252
253 submit->bos[i].flags |= BO_PINNED;
254
255 if (iova == submit->bos[i].iova) {
256 submit->bos[i].flags |= BO_VALID;
257 } else {
258 submit->bos[i].iova = iova;
259 /* iova changed, so address in cmdstream is not valid: */
260 submit->bos[i].flags &= ~BO_VALID;
261 submit->valid = false;
262 }
263 }
264
265 return ret;
266}
267
Rob Clark7198e6b2013-07-19 12:59:32 -0400268static int submit_bo(struct msm_gem_submit *submit, uint32_t idx,
Rob Clark78babc12016-11-11 12:06:46 -0500269 struct msm_gem_object **obj, uint64_t *iova, bool *valid)
Rob Clark7198e6b2013-07-19 12:59:32 -0400270{
271 if (idx >= submit->nr_bos) {
Rob Clark19872532013-09-06 15:36:40 -0400272 DRM_ERROR("invalid buffer index: %u (out of %u)\n",
273 idx, submit->nr_bos);
274 return -EINVAL;
Rob Clark7198e6b2013-07-19 12:59:32 -0400275 }
276
277 if (obj)
278 *obj = submit->bos[idx].obj;
279 if (iova)
280 *iova = submit->bos[idx].iova;
281 if (valid)
282 *valid = !!(submit->bos[idx].flags & BO_VALID);
283
284 return 0;
285}
286
287/* process the reloc's and patch up the cmdstream as needed: */
288static int submit_reloc(struct msm_gem_submit *submit, struct msm_gem_object *obj,
289 uint32_t offset, uint32_t nr_relocs, uint64_t relocs)
290{
291 uint32_t i, last_offset = 0;
292 uint32_t *ptr;
293 int ret;
294
295 if (offset % 4) {
Rob Clark19872532013-09-06 15:36:40 -0400296 DRM_ERROR("non-aligned cmdstream buffer: %u\n", offset);
Rob Clark7198e6b2013-07-19 12:59:32 -0400297 return -EINVAL;
298 }
299
300 /* For now, just map the entire thing. Eventually we probably
301 * to do it page-by-page, w/ kmap() if not vmap()d..
302 */
Rob Clark18f23042016-05-26 16:24:35 -0400303 ptr = msm_gem_get_vaddr_locked(&obj->base);
Rob Clark7198e6b2013-07-19 12:59:32 -0400304
305 if (IS_ERR(ptr)) {
306 ret = PTR_ERR(ptr);
307 DBG("failed to map: %d", ret);
308 return ret;
309 }
310
311 for (i = 0; i < nr_relocs; i++) {
312 struct drm_msm_gem_submit_reloc submit_reloc;
313 void __user *userptr =
Gustavo Padovan3ed605b2016-04-26 12:32:27 -0300314 u64_to_user_ptr(relocs + (i * sizeof(submit_reloc)));
Rob Clark78babc12016-11-11 12:06:46 -0500315 uint32_t off;
316 uint64_t iova;
Rob Clark7198e6b2013-07-19 12:59:32 -0400317 bool valid;
318
319 ret = copy_from_user(&submit_reloc, userptr, sizeof(submit_reloc));
320 if (ret)
321 return -EFAULT;
322
323 if (submit_reloc.submit_offset % 4) {
Rob Clark19872532013-09-06 15:36:40 -0400324 DRM_ERROR("non-aligned reloc offset: %u\n",
Rob Clark7198e6b2013-07-19 12:59:32 -0400325 submit_reloc.submit_offset);
326 return -EINVAL;
327 }
328
329 /* offset in dwords: */
330 off = submit_reloc.submit_offset / 4;
331
332 if ((off >= (obj->base.size / 4)) ||
333 (off < last_offset)) {
Rob Clark19872532013-09-06 15:36:40 -0400334 DRM_ERROR("invalid offset %u at reloc %u\n", off, i);
Rob Clark7198e6b2013-07-19 12:59:32 -0400335 return -EINVAL;
336 }
337
338 ret = submit_bo(submit, submit_reloc.reloc_idx, NULL, &iova, &valid);
339 if (ret)
340 return ret;
341
342 if (valid)
343 continue;
344
345 iova += submit_reloc.reloc_offset;
346
347 if (submit_reloc.shift < 0)
348 iova >>= -submit_reloc.shift;
349 else
350 iova <<= submit_reloc.shift;
351
352 ptr[off] = iova | submit_reloc.or;
353
354 last_offset = off;
355 }
356
Rob Clark18f23042016-05-26 16:24:35 -0400357 msm_gem_put_vaddr_locked(&obj->base);
358
Rob Clark7198e6b2013-07-19 12:59:32 -0400359 return 0;
360}
361
Rob Clark40e68152016-05-03 09:50:26 -0400362static void submit_cleanup(struct msm_gem_submit *submit)
Rob Clark7198e6b2013-07-19 12:59:32 -0400363{
364 unsigned i;
365
Rob Clark7198e6b2013-07-19 12:59:32 -0400366 for (i = 0; i < submit->nr_bos; i++) {
367 struct msm_gem_object *msm_obj = submit->bos[i].obj;
368 submit_unlock_unpin_bo(submit, i);
369 list_del_init(&msm_obj->submit_entry);
370 drm_gem_object_unreference(&msm_obj->base);
371 }
Rob Clark7198e6b2013-07-19 12:59:32 -0400372
373 ww_acquire_fini(&submit->ticket);
Rob Clark7198e6b2013-07-19 12:59:32 -0400374}
375
376int msm_ioctl_gem_submit(struct drm_device *dev, void *data,
377 struct drm_file *file)
378{
379 struct msm_drm_private *priv = dev->dev_private;
380 struct drm_msm_gem_submit *args = data;
381 struct msm_file_private *ctx = file->driver_priv;
382 struct msm_gem_submit *submit;
Rob Clarkc01a9582016-02-03 13:12:31 -0500383 struct msm_gpu *gpu = priv->gpu;
Chris Wilsonf54d1862016-10-25 13:00:45 +0100384 struct dma_fence *in_fence = NULL;
Rob Clark4cd09452016-06-16 16:43:49 -0400385 struct sync_file *sync_file = NULL;
386 int out_fence_fd = -1;
Rob Clark7198e6b2013-07-19 12:59:32 -0400387 unsigned i;
388 int ret;
389
Rob Clarkc01a9582016-02-03 13:12:31 -0500390 if (!gpu)
391 return -ENXIO;
392
Rob Clark7198e6b2013-07-19 12:59:32 -0400393 /* for now, we just have 3d pipe.. eventually this would need to
394 * be more clever to dispatch to appropriate gpu module:
395 */
Rob Clarkd9c181e2016-04-23 10:08:59 -0400396 if (MSM_PIPE_ID(args->flags) != MSM_PIPE_3D0)
397 return -EINVAL;
398
399 if (MSM_PIPE_FLAGS(args->flags) & ~MSM_SUBMIT_FLAGS)
Rob Clark7198e6b2013-07-19 12:59:32 -0400400 return -EINVAL;
401
Rob Clarkb5b4c262016-05-17 15:43:35 -0400402 ret = mutex_lock_interruptible(&dev->struct_mutex);
403 if (ret)
404 return ret;
Rob Clark687f0842016-02-03 13:24:35 -0500405
Rob Clark4cd09452016-06-16 16:43:49 -0400406 if (args->flags & MSM_SUBMIT_FENCE_FD_OUT) {
407 out_fence_fd = get_unused_fd_flags(O_CLOEXEC);
408 if (out_fence_fd < 0) {
409 ret = out_fence_fd;
410 goto out_unlock;
411 }
412 }
Rob Clarkd78d3832016-08-22 15:28:38 -0400413 priv->struct_mutex_task = current;
Rob Clark4cd09452016-06-16 16:43:49 -0400414
Rob Clark6b597ce2016-06-01 14:17:40 -0400415 submit = submit_create(dev, gpu, args->nr_bos, args->nr_cmds);
Rob Clarkb5b4c262016-05-17 15:43:35 -0400416 if (!submit) {
417 ret = -ENOMEM;
418 goto out_unlock;
419 }
Rob Clark7198e6b2013-07-19 12:59:32 -0400420
421 ret = submit_lookup_objects(submit, args, file);
422 if (ret)
423 goto out;
424
Rob Clark340faef2016-03-14 13:56:37 -0400425 ret = submit_lock_objects(submit);
426 if (ret)
427 goto out;
428
Rob Clarkf0a42bb2016-06-16 16:08:19 -0400429 if (args->flags & MSM_SUBMIT_FENCE_FD_IN) {
430 in_fence = sync_file_get_fence(args->fence_fd);
431
432 if (!in_fence) {
433 ret = -EINVAL;
434 goto out;
435 }
436
437 /* TODO if we get an array-fence due to userspace merging multiple
438 * fences, we need a way to determine if all the backing fences
439 * are from our own context..
440 */
441
442 if (in_fence->context != gpu->fctx->context) {
Chris Wilsonf54d1862016-10-25 13:00:45 +0100443 ret = dma_fence_wait(in_fence, true);
Rob Clarkf0a42bb2016-06-16 16:08:19 -0400444 if (ret)
445 goto out;
446 }
447
448 }
449
450 if (!(args->fence & MSM_SUBMIT_NO_IMPLICIT)) {
451 ret = submit_fence_sync(submit);
452 if (ret)
453 goto out;
454 }
Rob Clarkb6295f92016-03-15 18:26:28 -0400455
Rob Clark340faef2016-03-14 13:56:37 -0400456 ret = submit_pin_objects(submit);
Rob Clark7198e6b2013-07-19 12:59:32 -0400457 if (ret)
458 goto out;
459
460 for (i = 0; i < args->nr_cmds; i++) {
461 struct drm_msm_gem_submit_cmd submit_cmd;
462 void __user *userptr =
Gustavo Padovan3ed605b2016-04-26 12:32:27 -0300463 u64_to_user_ptr(args->cmds + (i * sizeof(submit_cmd)));
Rob Clark7198e6b2013-07-19 12:59:32 -0400464 struct msm_gem_object *msm_obj;
Rob Clark78babc12016-11-11 12:06:46 -0500465 uint64_t iova;
Rob Clark7198e6b2013-07-19 12:59:32 -0400466
467 ret = copy_from_user(&submit_cmd, userptr, sizeof(submit_cmd));
468 if (ret) {
469 ret = -EFAULT;
470 goto out;
471 }
472
Rob Clark93ddb0d2014-03-03 09:42:33 -0500473 /* validate input from userspace: */
474 switch (submit_cmd.type) {
475 case MSM_SUBMIT_CMD_BUF:
476 case MSM_SUBMIT_CMD_IB_TARGET_BUF:
477 case MSM_SUBMIT_CMD_CTX_RESTORE_BUF:
478 break;
479 default:
480 DRM_ERROR("invalid type: %08x\n", submit_cmd.type);
481 ret = -EINVAL;
482 goto out;
483 }
484
Rob Clark7198e6b2013-07-19 12:59:32 -0400485 ret = submit_bo(submit, submit_cmd.submit_idx,
486 &msm_obj, &iova, NULL);
487 if (ret)
488 goto out;
489
490 if (submit_cmd.size % 4) {
Rob Clark19872532013-09-06 15:36:40 -0400491 DRM_ERROR("non-aligned cmdstream buffer size: %u\n",
Rob Clark7198e6b2013-07-19 12:59:32 -0400492 submit_cmd.size);
493 ret = -EINVAL;
494 goto out;
495 }
496
Rob Clark19872532013-09-06 15:36:40 -0400497 if ((submit_cmd.size + submit_cmd.submit_offset) >=
498 msm_obj->base.size) {
499 DRM_ERROR("invalid cmdstream size: %u\n", submit_cmd.size);
Rob Clark7198e6b2013-07-19 12:59:32 -0400500 ret = -EINVAL;
501 goto out;
502 }
503
504 submit->cmd[i].type = submit_cmd.type;
505 submit->cmd[i].size = submit_cmd.size / 4;
506 submit->cmd[i].iova = iova + submit_cmd.submit_offset;
Rob Clarka7d3c952014-05-30 14:47:38 -0400507 submit->cmd[i].idx = submit_cmd.submit_idx;
Rob Clark7198e6b2013-07-19 12:59:32 -0400508
509 if (submit->valid)
510 continue;
511
512 ret = submit_reloc(submit, msm_obj, submit_cmd.submit_offset,
513 submit_cmd.nr_relocs, submit_cmd.relocs);
514 if (ret)
515 goto out;
516 }
517
518 submit->nr_cmds = i;
519
Rob Clarkf44d32c2016-06-16 16:37:38 -0400520 submit->fence = msm_fence_alloc(gpu->fctx);
521 if (IS_ERR(submit->fence)) {
522 ret = PTR_ERR(submit->fence);
523 submit->fence = NULL;
524 goto out;
525 }
526
Rob Clark4cd09452016-06-16 16:43:49 -0400527 if (args->flags & MSM_SUBMIT_FENCE_FD_OUT) {
528 sync_file = sync_file_create(submit->fence);
529 if (!sync_file) {
530 ret = -ENOMEM;
531 goto out;
532 }
533 }
534
Rob Clarkf44d32c2016-06-16 16:37:38 -0400535 msm_gpu_submit(gpu, submit, ctx);
Rob Clark7198e6b2013-07-19 12:59:32 -0400536
Rob Clarkb6295f92016-03-15 18:26:28 -0400537 args->fence = submit->fence->seqno;
Rob Clark7198e6b2013-07-19 12:59:32 -0400538
Rob Clark4cd09452016-06-16 16:43:49 -0400539 if (args->flags & MSM_SUBMIT_FENCE_FD_OUT) {
540 fd_install(out_fence_fd, sync_file->file);
541 args->fence_fd = out_fence_fd;
542 }
543
Rob Clark7198e6b2013-07-19 12:59:32 -0400544out:
Rob Clarkf0a42bb2016-06-16 16:08:19 -0400545 if (in_fence)
Chris Wilsonf54d1862016-10-25 13:00:45 +0100546 dma_fence_put(in_fence);
Rob Clark40e68152016-05-03 09:50:26 -0400547 submit_cleanup(submit);
548 if (ret)
549 msm_gem_submit_free(submit);
Rob Clarkb5b4c262016-05-17 15:43:35 -0400550out_unlock:
Rob Clark4cd09452016-06-16 16:43:49 -0400551 if (ret && (out_fence_fd >= 0))
552 put_unused_fd(out_fence_fd);
Rob Clarkd78d3832016-08-22 15:28:38 -0400553 priv->struct_mutex_task = NULL;
Rob Clarkc2703b12014-02-06 19:19:20 -0500554 mutex_unlock(&dev->struct_mutex);
Rob Clark7198e6b2013-07-19 12:59:32 -0400555 return ret;
556}