blob: 1c545ebe6a5a0f875a995b1db3a1204b0b21d57e [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
Dan Carpenter21c42da2017-01-16 14:58:08 +030098 if (copy_from_user_inatomic(&submit_bo, userptr, sizeof(submit_bo))) {
Rob Clark89f82cb2016-08-22 15:15:23 -040099 pagefault_enable();
100 spin_unlock(&file->table_lock);
Dan Carpenter21c42da2017-01-16 14:58:08 +0300101 if (copy_from_user(&submit_bo, userptr, sizeof(submit_bo))) {
102 ret = -EFAULT;
Rob Clark89f82cb2016-08-22 15:15:23 -0400103 goto out;
Dan Carpenter21c42da2017-01-16 14:58:08 +0300104 }
Rob Clark89f82cb2016-08-22 15:15:23 -0400105 spin_lock(&file->table_lock);
106 pagefault_disable();
Rob Clark7198e6b2013-07-19 12:59:32 -0400107 }
108
Jordan Crousea6cb3b82016-12-20 08:54:31 -0700109 if ((submit_bo.flags & ~MSM_SUBMIT_BO_FLAGS) ||
110 !(submit_bo.flags & MSM_SUBMIT_BO_FLAGS)) {
Rob Clark19872532013-09-06 15:36:40 -0400111 DRM_ERROR("invalid flags: %x\n", submit_bo.flags);
Rob Clark7198e6b2013-07-19 12:59:32 -0400112 ret = -EINVAL;
113 goto out_unlock;
114 }
115
116 submit->bos[i].flags = submit_bo.flags;
117 /* in validate_objects() we figure out if this is true: */
118 submit->bos[i].iova = submit_bo.presumed;
119
120 /* normally use drm_gem_object_lookup(), but for bulk lookup
121 * all under single table_lock just hit object_idr directly:
122 */
123 obj = idr_find(&file->object_idr, submit_bo.handle);
124 if (!obj) {
Rob Clark19872532013-09-06 15:36:40 -0400125 DRM_ERROR("invalid handle %u at index %u\n", submit_bo.handle, i);
Rob Clark7198e6b2013-07-19 12:59:32 -0400126 ret = -EINVAL;
127 goto out_unlock;
128 }
129
130 msm_obj = to_msm_bo(obj);
131
132 if (!list_empty(&msm_obj->submit_entry)) {
Rob Clark19872532013-09-06 15:36:40 -0400133 DRM_ERROR("handle %u at index %u already on submit list\n",
Rob Clark7198e6b2013-07-19 12:59:32 -0400134 submit_bo.handle, i);
135 ret = -EINVAL;
136 goto out_unlock;
137 }
138
139 drm_gem_object_reference(obj);
140
141 submit->bos[i].obj = msm_obj;
142
143 list_add_tail(&msm_obj->submit_entry, &submit->bo_list);
144 }
145
146out_unlock:
Rob Clark89f82cb2016-08-22 15:15:23 -0400147 pagefault_enable();
Rob Clark7198e6b2013-07-19 12:59:32 -0400148 spin_unlock(&file->table_lock);
149
Rob Clark89f82cb2016-08-22 15:15:23 -0400150out:
151 submit->nr_bos = i;
152
Rob Clark7198e6b2013-07-19 12:59:32 -0400153 return ret;
154}
155
156static void submit_unlock_unpin_bo(struct msm_gem_submit *submit, int i)
157{
158 struct msm_gem_object *msm_obj = submit->bos[i].obj;
159
160 if (submit->bos[i].flags & BO_PINNED)
161 msm_gem_put_iova(&msm_obj->base, submit->gpu->id);
162
163 if (submit->bos[i].flags & BO_LOCKED)
164 ww_mutex_unlock(&msm_obj->resv->lock);
165
166 if (!(submit->bos[i].flags & BO_VALID))
167 submit->bos[i].iova = 0;
168
169 submit->bos[i].flags &= ~(BO_LOCKED | BO_PINNED);
170}
171
172/* This is where we make sure all the bo's are reserved and pin'd: */
Rob Clark340faef2016-03-14 13:56:37 -0400173static int submit_lock_objects(struct msm_gem_submit *submit)
Rob Clark7198e6b2013-07-19 12:59:32 -0400174{
175 int contended, slow_locked = -1, i, ret = 0;
176
177retry:
Rob Clark7198e6b2013-07-19 12:59:32 -0400178 for (i = 0; i < submit->nr_bos; i++) {
179 struct msm_gem_object *msm_obj = submit->bos[i].obj;
Rob Clark7198e6b2013-07-19 12:59:32 -0400180
181 if (slow_locked == i)
182 slow_locked = -1;
183
184 contended = i;
185
186 if (!(submit->bos[i].flags & BO_LOCKED)) {
187 ret = ww_mutex_lock_interruptible(&msm_obj->resv->lock,
188 &submit->ticket);
189 if (ret)
190 goto fail;
191 submit->bos[i].flags |= BO_LOCKED;
192 }
Rob Clark7198e6b2013-07-19 12:59:32 -0400193 }
194
195 ww_acquire_done(&submit->ticket);
196
197 return 0;
198
199fail:
200 for (; i >= 0; i--)
201 submit_unlock_unpin_bo(submit, i);
202
203 if (slow_locked > 0)
204 submit_unlock_unpin_bo(submit, slow_locked);
205
206 if (ret == -EDEADLK) {
207 struct msm_gem_object *msm_obj = submit->bos[contended].obj;
208 /* we lost out in a seqno race, lock and retry.. */
209 ret = ww_mutex_lock_slow_interruptible(&msm_obj->resv->lock,
210 &submit->ticket);
211 if (!ret) {
212 submit->bos[contended].flags |= BO_LOCKED;
213 slow_locked = contended;
214 goto retry;
215 }
216 }
217
218 return ret;
219}
220
Rob Clarkb6295f92016-03-15 18:26:28 -0400221static int submit_fence_sync(struct msm_gem_submit *submit)
222{
223 int i, ret = 0;
224
225 for (i = 0; i < submit->nr_bos; i++) {
226 struct msm_gem_object *msm_obj = submit->bos[i].obj;
227 bool write = submit->bos[i].flags & MSM_SUBMIT_BO_WRITE;
228
229 ret = msm_gem_sync_object(&msm_obj->base, submit->gpu->fctx, write);
230 if (ret)
231 break;
232 }
233
234 return ret;
235}
236
Rob Clark340faef2016-03-14 13:56:37 -0400237static int submit_pin_objects(struct msm_gem_submit *submit)
238{
239 int i, ret = 0;
240
241 submit->valid = true;
242
243 for (i = 0; i < submit->nr_bos; i++) {
244 struct msm_gem_object *msm_obj = submit->bos[i].obj;
Rob Clark78babc12016-11-11 12:06:46 -0500245 uint64_t iova;
Rob Clark340faef2016-03-14 13:56:37 -0400246
247 /* if locking succeeded, pin bo: */
248 ret = msm_gem_get_iova_locked(&msm_obj->base,
249 submit->gpu->id, &iova);
250
251 if (ret)
252 break;
253
254 submit->bos[i].flags |= BO_PINNED;
255
256 if (iova == submit->bos[i].iova) {
257 submit->bos[i].flags |= BO_VALID;
258 } else {
259 submit->bos[i].iova = iova;
260 /* iova changed, so address in cmdstream is not valid: */
261 submit->bos[i].flags &= ~BO_VALID;
262 submit->valid = false;
263 }
264 }
265
266 return ret;
267}
268
Rob Clark7198e6b2013-07-19 12:59:32 -0400269static int submit_bo(struct msm_gem_submit *submit, uint32_t idx,
Rob Clark78babc12016-11-11 12:06:46 -0500270 struct msm_gem_object **obj, uint64_t *iova, bool *valid)
Rob Clark7198e6b2013-07-19 12:59:32 -0400271{
272 if (idx >= submit->nr_bos) {
Rob Clark19872532013-09-06 15:36:40 -0400273 DRM_ERROR("invalid buffer index: %u (out of %u)\n",
274 idx, submit->nr_bos);
275 return -EINVAL;
Rob Clark7198e6b2013-07-19 12:59:32 -0400276 }
277
278 if (obj)
279 *obj = submit->bos[idx].obj;
280 if (iova)
281 *iova = submit->bos[idx].iova;
282 if (valid)
283 *valid = !!(submit->bos[idx].flags & BO_VALID);
284
285 return 0;
286}
287
288/* process the reloc's and patch up the cmdstream as needed: */
289static int submit_reloc(struct msm_gem_submit *submit, struct msm_gem_object *obj,
290 uint32_t offset, uint32_t nr_relocs, uint64_t relocs)
291{
292 uint32_t i, last_offset = 0;
293 uint32_t *ptr;
Jordan Crouse6490abc2016-12-20 08:54:30 -0700294 int ret = 0;
Rob Clark7198e6b2013-07-19 12:59:32 -0400295
296 if (offset % 4) {
Rob Clark19872532013-09-06 15:36:40 -0400297 DRM_ERROR("non-aligned cmdstream buffer: %u\n", offset);
Rob Clark7198e6b2013-07-19 12:59:32 -0400298 return -EINVAL;
299 }
300
301 /* For now, just map the entire thing. Eventually we probably
302 * to do it page-by-page, w/ kmap() if not vmap()d..
303 */
Rob Clark18f23042016-05-26 16:24:35 -0400304 ptr = msm_gem_get_vaddr_locked(&obj->base);
Rob Clark7198e6b2013-07-19 12:59:32 -0400305
306 if (IS_ERR(ptr)) {
307 ret = PTR_ERR(ptr);
308 DBG("failed to map: %d", ret);
309 return ret;
310 }
311
312 for (i = 0; i < nr_relocs; i++) {
313 struct drm_msm_gem_submit_reloc submit_reloc;
314 void __user *userptr =
Gustavo Padovan3ed605b2016-04-26 12:32:27 -0300315 u64_to_user_ptr(relocs + (i * sizeof(submit_reloc)));
Rob Clark78babc12016-11-11 12:06:46 -0500316 uint32_t off;
317 uint64_t iova;
Rob Clark7198e6b2013-07-19 12:59:32 -0400318 bool valid;
319
Dan Carpenter21c42da2017-01-16 14:58:08 +0300320 if (copy_from_user(&submit_reloc, userptr, sizeof(submit_reloc))) {
321 ret = -EFAULT;
Jordan Crouse6490abc2016-12-20 08:54:30 -0700322 goto out;
Dan Carpenter21c42da2017-01-16 14:58:08 +0300323 }
Rob Clark7198e6b2013-07-19 12:59:32 -0400324
325 if (submit_reloc.submit_offset % 4) {
Rob Clark19872532013-09-06 15:36:40 -0400326 DRM_ERROR("non-aligned reloc offset: %u\n",
Rob Clark7198e6b2013-07-19 12:59:32 -0400327 submit_reloc.submit_offset);
Jordan Crouse6490abc2016-12-20 08:54:30 -0700328 ret = -EINVAL;
329 goto out;
Rob Clark7198e6b2013-07-19 12:59:32 -0400330 }
331
332 /* offset in dwords: */
333 off = submit_reloc.submit_offset / 4;
334
335 if ((off >= (obj->base.size / 4)) ||
336 (off < last_offset)) {
Rob Clark19872532013-09-06 15:36:40 -0400337 DRM_ERROR("invalid offset %u at reloc %u\n", off, i);
Jordan Crouse6490abc2016-12-20 08:54:30 -0700338 ret = -EINVAL;
339 goto out;
Rob Clark7198e6b2013-07-19 12:59:32 -0400340 }
341
342 ret = submit_bo(submit, submit_reloc.reloc_idx, NULL, &iova, &valid);
343 if (ret)
Jordan Crouse6490abc2016-12-20 08:54:30 -0700344 goto out;
Rob Clark7198e6b2013-07-19 12:59:32 -0400345
346 if (valid)
347 continue;
348
349 iova += submit_reloc.reloc_offset;
350
351 if (submit_reloc.shift < 0)
352 iova >>= -submit_reloc.shift;
353 else
354 iova <<= submit_reloc.shift;
355
356 ptr[off] = iova | submit_reloc.or;
357
358 last_offset = off;
359 }
360
Jordan Crouse6490abc2016-12-20 08:54:30 -0700361out:
Rob Clark18f23042016-05-26 16:24:35 -0400362 msm_gem_put_vaddr_locked(&obj->base);
363
Jordan Crouse6490abc2016-12-20 08:54:30 -0700364 return ret;
Rob Clark7198e6b2013-07-19 12:59:32 -0400365}
366
Rob Clark40e68152016-05-03 09:50:26 -0400367static void submit_cleanup(struct msm_gem_submit *submit)
Rob Clark7198e6b2013-07-19 12:59:32 -0400368{
369 unsigned i;
370
Rob Clark7198e6b2013-07-19 12:59:32 -0400371 for (i = 0; i < submit->nr_bos; i++) {
372 struct msm_gem_object *msm_obj = submit->bos[i].obj;
373 submit_unlock_unpin_bo(submit, i);
374 list_del_init(&msm_obj->submit_entry);
375 drm_gem_object_unreference(&msm_obj->base);
376 }
Rob Clark7198e6b2013-07-19 12:59:32 -0400377
378 ww_acquire_fini(&submit->ticket);
Rob Clark7198e6b2013-07-19 12:59:32 -0400379}
380
381int msm_ioctl_gem_submit(struct drm_device *dev, void *data,
382 struct drm_file *file)
383{
384 struct msm_drm_private *priv = dev->dev_private;
385 struct drm_msm_gem_submit *args = data;
386 struct msm_file_private *ctx = file->driver_priv;
387 struct msm_gem_submit *submit;
Rob Clarkc01a9582016-02-03 13:12:31 -0500388 struct msm_gpu *gpu = priv->gpu;
Chris Wilsonf54d1862016-10-25 13:00:45 +0100389 struct dma_fence *in_fence = NULL;
Rob Clark4cd09452016-06-16 16:43:49 -0400390 struct sync_file *sync_file = NULL;
391 int out_fence_fd = -1;
Rob Clark7198e6b2013-07-19 12:59:32 -0400392 unsigned i;
393 int ret;
394
Rob Clarkc01a9582016-02-03 13:12:31 -0500395 if (!gpu)
396 return -ENXIO;
397
Rob Clark7198e6b2013-07-19 12:59:32 -0400398 /* for now, we just have 3d pipe.. eventually this would need to
399 * be more clever to dispatch to appropriate gpu module:
400 */
Rob Clarkd9c181e2016-04-23 10:08:59 -0400401 if (MSM_PIPE_ID(args->flags) != MSM_PIPE_3D0)
402 return -EINVAL;
403
404 if (MSM_PIPE_FLAGS(args->flags) & ~MSM_SUBMIT_FLAGS)
Rob Clark7198e6b2013-07-19 12:59:32 -0400405 return -EINVAL;
406
Rob Clark48f243c2017-02-25 10:36:30 -0500407 if (args->flags & MSM_SUBMIT_FENCE_FD_IN) {
408 in_fence = sync_file_get_fence(args->fence_fd);
409
410 if (!in_fence)
411 return -EINVAL;
412
413 /* TODO if we get an array-fence due to userspace merging multiple
414 * fences, we need a way to determine if all the backing fences
415 * are from our own context..
416 */
417
418 if (in_fence->context != gpu->fctx->context) {
419 ret = dma_fence_wait(in_fence, true);
420 if (ret)
421 return ret;
422 }
423 }
424
Rob Clarkb5b4c262016-05-17 15:43:35 -0400425 ret = mutex_lock_interruptible(&dev->struct_mutex);
426 if (ret)
427 return ret;
Rob Clark687f0842016-02-03 13:24:35 -0500428
Rob Clark4cd09452016-06-16 16:43:49 -0400429 if (args->flags & MSM_SUBMIT_FENCE_FD_OUT) {
430 out_fence_fd = get_unused_fd_flags(O_CLOEXEC);
431 if (out_fence_fd < 0) {
432 ret = out_fence_fd;
433 goto out_unlock;
434 }
435 }
Rob Clarkd78d3832016-08-22 15:28:38 -0400436 priv->struct_mutex_task = current;
Rob Clark4cd09452016-06-16 16:43:49 -0400437
Rob Clark6b597ce2016-06-01 14:17:40 -0400438 submit = submit_create(dev, gpu, args->nr_bos, args->nr_cmds);
Rob Clarkb5b4c262016-05-17 15:43:35 -0400439 if (!submit) {
440 ret = -ENOMEM;
441 goto out_unlock;
442 }
Rob Clark7198e6b2013-07-19 12:59:32 -0400443
444 ret = submit_lookup_objects(submit, args, file);
445 if (ret)
446 goto out;
447
Rob Clark340faef2016-03-14 13:56:37 -0400448 ret = submit_lock_objects(submit);
449 if (ret)
450 goto out;
451
Rob Clarkf0a42bb2016-06-16 16:08:19 -0400452 if (!(args->fence & MSM_SUBMIT_NO_IMPLICIT)) {
453 ret = submit_fence_sync(submit);
454 if (ret)
455 goto out;
456 }
Rob Clarkb6295f92016-03-15 18:26:28 -0400457
Rob Clark340faef2016-03-14 13:56:37 -0400458 ret = submit_pin_objects(submit);
Rob Clark7198e6b2013-07-19 12:59:32 -0400459 if (ret)
460 goto out;
461
462 for (i = 0; i < args->nr_cmds; i++) {
463 struct drm_msm_gem_submit_cmd submit_cmd;
464 void __user *userptr =
Gustavo Padovan3ed605b2016-04-26 12:32:27 -0300465 u64_to_user_ptr(args->cmds + (i * sizeof(submit_cmd)));
Rob Clark7198e6b2013-07-19 12:59:32 -0400466 struct msm_gem_object *msm_obj;
Rob Clark78babc12016-11-11 12:06:46 -0500467 uint64_t iova;
Rob Clark7198e6b2013-07-19 12:59:32 -0400468
469 ret = copy_from_user(&submit_cmd, userptr, sizeof(submit_cmd));
470 if (ret) {
471 ret = -EFAULT;
472 goto out;
473 }
474
Rob Clark93ddb0d2014-03-03 09:42:33 -0500475 /* validate input from userspace: */
476 switch (submit_cmd.type) {
477 case MSM_SUBMIT_CMD_BUF:
478 case MSM_SUBMIT_CMD_IB_TARGET_BUF:
479 case MSM_SUBMIT_CMD_CTX_RESTORE_BUF:
480 break;
481 default:
482 DRM_ERROR("invalid type: %08x\n", submit_cmd.type);
483 ret = -EINVAL;
484 goto out;
485 }
486
Rob Clark7198e6b2013-07-19 12:59:32 -0400487 ret = submit_bo(submit, submit_cmd.submit_idx,
488 &msm_obj, &iova, NULL);
489 if (ret)
490 goto out;
491
492 if (submit_cmd.size % 4) {
Rob Clark19872532013-09-06 15:36:40 -0400493 DRM_ERROR("non-aligned cmdstream buffer size: %u\n",
Rob Clark7198e6b2013-07-19 12:59:32 -0400494 submit_cmd.size);
495 ret = -EINVAL;
496 goto out;
497 }
498
Rob Clark19872532013-09-06 15:36:40 -0400499 if ((submit_cmd.size + submit_cmd.submit_offset) >=
500 msm_obj->base.size) {
501 DRM_ERROR("invalid cmdstream size: %u\n", submit_cmd.size);
Rob Clark7198e6b2013-07-19 12:59:32 -0400502 ret = -EINVAL;
503 goto out;
504 }
505
506 submit->cmd[i].type = submit_cmd.type;
507 submit->cmd[i].size = submit_cmd.size / 4;
508 submit->cmd[i].iova = iova + submit_cmd.submit_offset;
Rob Clarka7d3c952014-05-30 14:47:38 -0400509 submit->cmd[i].idx = submit_cmd.submit_idx;
Rob Clark7198e6b2013-07-19 12:59:32 -0400510
511 if (submit->valid)
512 continue;
513
514 ret = submit_reloc(submit, msm_obj, submit_cmd.submit_offset,
515 submit_cmd.nr_relocs, submit_cmd.relocs);
516 if (ret)
517 goto out;
518 }
519
520 submit->nr_cmds = i;
521
Rob Clarkf44d32c2016-06-16 16:37:38 -0400522 submit->fence = msm_fence_alloc(gpu->fctx);
523 if (IS_ERR(submit->fence)) {
524 ret = PTR_ERR(submit->fence);
525 submit->fence = NULL;
526 goto out;
527 }
528
Rob Clark4cd09452016-06-16 16:43:49 -0400529 if (args->flags & MSM_SUBMIT_FENCE_FD_OUT) {
530 sync_file = sync_file_create(submit->fence);
531 if (!sync_file) {
532 ret = -ENOMEM;
533 goto out;
534 }
535 }
536
Rob Clarkf44d32c2016-06-16 16:37:38 -0400537 msm_gpu_submit(gpu, submit, ctx);
Rob Clark7198e6b2013-07-19 12:59:32 -0400538
Rob Clarkb6295f92016-03-15 18:26:28 -0400539 args->fence = submit->fence->seqno;
Rob Clark7198e6b2013-07-19 12:59:32 -0400540
Rob Clark4cd09452016-06-16 16:43:49 -0400541 if (args->flags & MSM_SUBMIT_FENCE_FD_OUT) {
542 fd_install(out_fence_fd, sync_file->file);
543 args->fence_fd = out_fence_fd;
544 }
545
Rob Clark7198e6b2013-07-19 12:59:32 -0400546out:
Rob Clarkf0a42bb2016-06-16 16:08:19 -0400547 if (in_fence)
Chris Wilsonf54d1862016-10-25 13:00:45 +0100548 dma_fence_put(in_fence);
Rob Clark40e68152016-05-03 09:50:26 -0400549 submit_cleanup(submit);
550 if (ret)
551 msm_gem_submit_free(submit);
Rob Clarkb5b4c262016-05-17 15:43:35 -0400552out_unlock:
Rob Clark4cd09452016-06-16 16:43:49 -0400553 if (ret && (out_fence_fd >= 0))
554 put_unused_fd(out_fence_fd);
Rob Clarkd78d3832016-08-22 15:28:38 -0400555 priv->struct_mutex_task = NULL;
Rob Clarkc2703b12014-02-06 19:19:20 -0500556 mutex_unlock(&dev->struct_mutex);
Rob Clark7198e6b2013-07-19 12:59:32 -0400557 return ret;
558}