blob: f57536a70a3aa39891d9f7b946f3e325beaab2fd [file] [log] [blame]
Chris Wilson54cf91d2010-11-25 18:00:26 +00001/*
2 * Copyright © 2008,2010 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 *
23 * Authors:
24 * Eric Anholt <eric@anholt.net>
25 * Chris Wilson <chris@chris-wilson.co.uk>
26 *
27 */
28
29#include "drmP.h"
30#include "drm.h"
31#include "i915_drm.h"
32#include "i915_drv.h"
33#include "i915_trace.h"
34#include "intel_drv.h"
35
36struct change_domains {
37 uint32_t invalidate_domains;
38 uint32_t flush_domains;
39 uint32_t flush_rings;
40};
41
42/*
43 * Set the next domain for the specified object. This
44 * may not actually perform the necessary flushing/invaliding though,
45 * as that may want to be batched with other set_domain operations
46 *
47 * This is (we hope) the only really tricky part of gem. The goal
48 * is fairly simple -- track which caches hold bits of the object
49 * and make sure they remain coherent. A few concrete examples may
50 * help to explain how it works. For shorthand, we use the notation
51 * (read_domains, write_domain), e.g. (CPU, CPU) to indicate the
52 * a pair of read and write domain masks.
53 *
54 * Case 1: the batch buffer
55 *
56 * 1. Allocated
57 * 2. Written by CPU
58 * 3. Mapped to GTT
59 * 4. Read by GPU
60 * 5. Unmapped from GTT
61 * 6. Freed
62 *
63 * Let's take these a step at a time
64 *
65 * 1. Allocated
66 * Pages allocated from the kernel may still have
67 * cache contents, so we set them to (CPU, CPU) always.
68 * 2. Written by CPU (using pwrite)
69 * The pwrite function calls set_domain (CPU, CPU) and
70 * this function does nothing (as nothing changes)
71 * 3. Mapped by GTT
72 * This function asserts that the object is not
73 * currently in any GPU-based read or write domains
74 * 4. Read by GPU
75 * i915_gem_execbuffer calls set_domain (COMMAND, 0).
76 * As write_domain is zero, this function adds in the
77 * current read domains (CPU+COMMAND, 0).
78 * flush_domains is set to CPU.
79 * invalidate_domains is set to COMMAND
80 * clflush is run to get data out of the CPU caches
81 * then i915_dev_set_domain calls i915_gem_flush to
82 * emit an MI_FLUSH and drm_agp_chipset_flush
83 * 5. Unmapped from GTT
84 * i915_gem_object_unbind calls set_domain (CPU, CPU)
85 * flush_domains and invalidate_domains end up both zero
86 * so no flushing/invalidating happens
87 * 6. Freed
88 * yay, done
89 *
90 * Case 2: The shared render buffer
91 *
92 * 1. Allocated
93 * 2. Mapped to GTT
94 * 3. Read/written by GPU
95 * 4. set_domain to (CPU,CPU)
96 * 5. Read/written by CPU
97 * 6. Read/written by GPU
98 *
99 * 1. Allocated
100 * Same as last example, (CPU, CPU)
101 * 2. Mapped to GTT
102 * Nothing changes (assertions find that it is not in the GPU)
103 * 3. Read/written by GPU
104 * execbuffer calls set_domain (RENDER, RENDER)
105 * flush_domains gets CPU
106 * invalidate_domains gets GPU
107 * clflush (obj)
108 * MI_FLUSH and drm_agp_chipset_flush
109 * 4. set_domain (CPU, CPU)
110 * flush_domains gets GPU
111 * invalidate_domains gets CPU
112 * wait_rendering (obj) to make sure all drawing is complete.
113 * This will include an MI_FLUSH to get the data from GPU
114 * to memory
115 * clflush (obj) to invalidate the CPU cache
116 * Another MI_FLUSH in i915_gem_flush (eliminate this somehow?)
117 * 5. Read/written by CPU
118 * cache lines are loaded and dirtied
119 * 6. Read written by GPU
120 * Same as last GPU access
121 *
122 * Case 3: The constant buffer
123 *
124 * 1. Allocated
125 * 2. Written by CPU
126 * 3. Read by GPU
127 * 4. Updated (written) by CPU again
128 * 5. Read by GPU
129 *
130 * 1. Allocated
131 * (CPU, CPU)
132 * 2. Written by CPU
133 * (CPU, CPU)
134 * 3. Read by GPU
135 * (CPU+RENDER, 0)
136 * flush_domains = CPU
137 * invalidate_domains = RENDER
138 * clflush (obj)
139 * MI_FLUSH
140 * drm_agp_chipset_flush
141 * 4. Updated (written) by CPU again
142 * (CPU, CPU)
143 * flush_domains = 0 (no previous write domain)
144 * invalidate_domains = 0 (no new read domains)
145 * 5. Read by GPU
146 * (CPU+RENDER, 0)
147 * flush_domains = CPU
148 * invalidate_domains = RENDER
149 * clflush (obj)
150 * MI_FLUSH
151 * drm_agp_chipset_flush
152 */
153static void
154i915_gem_object_set_to_gpu_domain(struct drm_i915_gem_object *obj,
155 struct intel_ring_buffer *ring,
156 struct change_domains *cd)
157{
158 uint32_t invalidate_domains = 0, flush_domains = 0;
159
160 /*
161 * If the object isn't moving to a new write domain,
162 * let the object stay in multiple read domains
163 */
164 if (obj->base.pending_write_domain == 0)
165 obj->base.pending_read_domains |= obj->base.read_domains;
166
167 /*
168 * Flush the current write domain if
169 * the new read domains don't match. Invalidate
170 * any read domains which differ from the old
171 * write domain
172 */
173 if (obj->base.write_domain &&
174 (((obj->base.write_domain != obj->base.pending_read_domains ||
175 obj->ring != ring)) ||
176 (obj->fenced_gpu_access && !obj->pending_fenced_gpu_access))) {
177 flush_domains |= obj->base.write_domain;
178 invalidate_domains |=
179 obj->base.pending_read_domains & ~obj->base.write_domain;
180 }
181 /*
182 * Invalidate any read caches which may have
183 * stale data. That is, any new read domains.
184 */
185 invalidate_domains |= obj->base.pending_read_domains & ~obj->base.read_domains;
186 if ((flush_domains | invalidate_domains) & I915_GEM_DOMAIN_CPU)
187 i915_gem_clflush_object(obj);
188
189 /* blow away mappings if mapped through GTT */
190 if ((flush_domains | invalidate_domains) & I915_GEM_DOMAIN_GTT)
191 i915_gem_release_mmap(obj);
192
193 /* The actual obj->write_domain will be updated with
194 * pending_write_domain after we emit the accumulated flush for all
195 * of our domain changes in execbuffers (which clears objects'
196 * write_domains). So if we have a current write domain that we
197 * aren't changing, set pending_write_domain to that.
198 */
199 if (flush_domains == 0 && obj->base.pending_write_domain == 0)
200 obj->base.pending_write_domain = obj->base.write_domain;
201
202 cd->invalidate_domains |= invalidate_domains;
203 cd->flush_domains |= flush_domains;
204 if (flush_domains & I915_GEM_GPU_DOMAINS)
205 cd->flush_rings |= obj->ring->id;
206 if (invalidate_domains & I915_GEM_GPU_DOMAINS)
207 cd->flush_rings |= ring->id;
208}
209
210static int
211i915_gem_execbuffer_relocate_entry(struct drm_i915_gem_object *obj,
212 struct drm_file *file_priv,
213 struct drm_i915_gem_exec_object2 *entry,
214 struct drm_i915_gem_relocation_entry *reloc)
215{
216 struct drm_device *dev = obj->base.dev;
217 struct drm_gem_object *target_obj;
218 uint32_t target_offset;
219 int ret = -EINVAL;
220
221 target_obj = drm_gem_object_lookup(dev, file_priv,
222 reloc->target_handle);
223 if (target_obj == NULL)
224 return -ENOENT;
225
226 target_offset = to_intel_bo(target_obj)->gtt_offset;
227
228#if WATCH_RELOC
229 DRM_INFO("%s: obj %p offset %08x target %d "
230 "read %08x write %08x gtt %08x "
231 "presumed %08x delta %08x\n",
232 __func__,
233 obj,
234 (int) reloc->offset,
235 (int) reloc->target_handle,
236 (int) reloc->read_domains,
237 (int) reloc->write_domain,
238 (int) target_offset,
239 (int) reloc->presumed_offset,
240 reloc->delta);
241#endif
242
243 /* The target buffer should have appeared before us in the
244 * exec_object list, so it should have a GTT space bound by now.
245 */
246 if (target_offset == 0) {
247 DRM_ERROR("No GTT space found for object %d\n",
248 reloc->target_handle);
249 goto err;
250 }
251
252 /* Validate that the target is in a valid r/w GPU domain */
253 if (reloc->write_domain & (reloc->write_domain - 1)) {
254 DRM_ERROR("reloc with multiple write domains: "
255 "obj %p target %d offset %d "
256 "read %08x write %08x",
257 obj, reloc->target_handle,
258 (int) reloc->offset,
259 reloc->read_domains,
260 reloc->write_domain);
261 goto err;
262 }
263 if (reloc->write_domain & I915_GEM_DOMAIN_CPU ||
264 reloc->read_domains & I915_GEM_DOMAIN_CPU) {
265 DRM_ERROR("reloc with read/write CPU domains: "
266 "obj %p target %d offset %d "
267 "read %08x write %08x",
268 obj, reloc->target_handle,
269 (int) reloc->offset,
270 reloc->read_domains,
271 reloc->write_domain);
272 goto err;
273 }
274 if (reloc->write_domain && target_obj->pending_write_domain &&
275 reloc->write_domain != target_obj->pending_write_domain) {
276 DRM_ERROR("Write domain conflict: "
277 "obj %p target %d offset %d "
278 "new %08x old %08x\n",
279 obj, reloc->target_handle,
280 (int) reloc->offset,
281 reloc->write_domain,
282 target_obj->pending_write_domain);
283 goto err;
284 }
285
286 target_obj->pending_read_domains |= reloc->read_domains;
287 target_obj->pending_write_domain |= reloc->write_domain;
288
289 /* If the relocation already has the right value in it, no
290 * more work needs to be done.
291 */
292 if (target_offset == reloc->presumed_offset)
293 goto out;
294
295 /* Check that the relocation address is valid... */
296 if (reloc->offset > obj->base.size - 4) {
297 DRM_ERROR("Relocation beyond object bounds: "
298 "obj %p target %d offset %d size %d.\n",
299 obj, reloc->target_handle,
300 (int) reloc->offset,
301 (int) obj->base.size);
302 goto err;
303 }
304 if (reloc->offset & 3) {
305 DRM_ERROR("Relocation not 4-byte aligned: "
306 "obj %p target %d offset %d.\n",
307 obj, reloc->target_handle,
308 (int) reloc->offset);
309 goto err;
310 }
311
312 /* and points to somewhere within the target object. */
313 if (reloc->delta >= target_obj->size) {
314 DRM_ERROR("Relocation beyond target object bounds: "
315 "obj %p target %d delta %d size %d.\n",
316 obj, reloc->target_handle,
317 (int) reloc->delta,
318 (int) target_obj->size);
319 goto err;
320 }
321
322 reloc->delta += target_offset;
323 if (obj->base.write_domain == I915_GEM_DOMAIN_CPU) {
324 uint32_t page_offset = reloc->offset & ~PAGE_MASK;
325 char *vaddr;
326
327 vaddr = kmap_atomic(obj->pages[reloc->offset >> PAGE_SHIFT]);
328 *(uint32_t *)(vaddr + page_offset) = reloc->delta;
329 kunmap_atomic(vaddr);
330 } else {
331 struct drm_i915_private *dev_priv = dev->dev_private;
332 uint32_t __iomem *reloc_entry;
333 void __iomem *reloc_page;
334
335 ret = i915_gem_object_set_to_gtt_domain(obj, 1);
336 if (ret)
337 goto err;
338
339 /* Map the page containing the relocation we're going to perform. */
340 reloc->offset += obj->gtt_offset;
341 reloc_page = io_mapping_map_atomic_wc(dev_priv->mm.gtt_mapping,
342 reloc->offset & PAGE_MASK);
343 reloc_entry = (uint32_t __iomem *)
344 (reloc_page + (reloc->offset & ~PAGE_MASK));
345 iowrite32(reloc->delta, reloc_entry);
346 io_mapping_unmap_atomic(reloc_page);
347 }
348
349 /* and update the user's relocation entry */
350 reloc->presumed_offset = target_offset;
351
352out:
353 ret = 0;
354err:
355 drm_gem_object_unreference(target_obj);
356 return ret;
357}
358
359static int
360i915_gem_execbuffer_relocate_object(struct drm_i915_gem_object *obj,
361 struct drm_file *file_priv,
362 struct drm_i915_gem_exec_object2 *entry)
363{
364 struct drm_i915_gem_relocation_entry __user *user_relocs;
365 int i, ret;
366
367 user_relocs = (void __user *)(uintptr_t)entry->relocs_ptr;
368 for (i = 0; i < entry->relocation_count; i++) {
369 struct drm_i915_gem_relocation_entry reloc;
370
371 if (__copy_from_user_inatomic(&reloc,
372 user_relocs+i,
373 sizeof(reloc)))
374 return -EFAULT;
375
376 ret = i915_gem_execbuffer_relocate_entry(obj, file_priv, entry, &reloc);
377 if (ret)
378 return ret;
379
380 if (__copy_to_user_inatomic(&user_relocs[i].presumed_offset,
381 &reloc.presumed_offset,
382 sizeof(reloc.presumed_offset)))
383 return -EFAULT;
384 }
385
386 return 0;
387}
388
389static int
390i915_gem_execbuffer_relocate_object_slow(struct drm_i915_gem_object *obj,
391 struct drm_file *file_priv,
392 struct drm_i915_gem_exec_object2 *entry,
393 struct drm_i915_gem_relocation_entry *relocs)
394{
395 int i, ret;
396
397 for (i = 0; i < entry->relocation_count; i++) {
398 ret = i915_gem_execbuffer_relocate_entry(obj, file_priv, entry, &relocs[i]);
399 if (ret)
400 return ret;
401 }
402
403 return 0;
404}
405
406static int
407i915_gem_execbuffer_relocate(struct drm_device *dev,
408 struct drm_file *file,
Chris Wilson432e58e2010-11-25 19:32:06 +0000409 struct list_head *objects,
410 struct drm_i915_gem_exec_object2 *exec)
Chris Wilson54cf91d2010-11-25 18:00:26 +0000411{
Chris Wilson432e58e2010-11-25 19:32:06 +0000412 struct drm_i915_gem_object *obj;
413 int ret;
Chris Wilson54cf91d2010-11-25 18:00:26 +0000414
Chris Wilson432e58e2010-11-25 19:32:06 +0000415 list_for_each_entry(obj, objects, exec_list) {
Chris Wilson54cf91d2010-11-25 18:00:26 +0000416 obj->base.pending_read_domains = 0;
417 obj->base.pending_write_domain = 0;
Chris Wilson432e58e2010-11-25 19:32:06 +0000418 ret = i915_gem_execbuffer_relocate_object(obj, file, exec++);
Chris Wilson54cf91d2010-11-25 18:00:26 +0000419 if (ret)
420 return ret;
421 }
422
423 return 0;
424}
425
426static int
427i915_gem_execbuffer_reserve(struct drm_device *dev,
428 struct drm_file *file,
Chris Wilson432e58e2010-11-25 19:32:06 +0000429 struct list_head *objects,
430 struct drm_i915_gem_exec_object2 *exec)
Chris Wilson54cf91d2010-11-25 18:00:26 +0000431{
Chris Wilson432e58e2010-11-25 19:32:06 +0000432 struct drm_i915_gem_object *obj;
433 struct drm_i915_gem_exec_object2 *entry;
434 int ret, retry;
Chris Wilson54cf91d2010-11-25 18:00:26 +0000435
436 /* Attempt to pin all of the buffers into the GTT.
437 * This is done in 3 phases:
438 *
439 * 1a. Unbind all objects that do not match the GTT constraints for
440 * the execbuffer (fenceable, mappable, alignment etc).
441 * 1b. Increment pin count for already bound objects.
442 * 2. Bind new objects.
443 * 3. Decrement pin count.
444 *
445 * This avoid unnecessary unbinding of later objects in order to makr
446 * room for the earlier objects *unless* we need to defragment.
447 */
448 retry = 0;
449 do {
450 ret = 0;
451
452 /* Unbind any ill-fitting objects or pin. */
Chris Wilson432e58e2010-11-25 19:32:06 +0000453 entry = exec;
454 list_for_each_entry(obj, objects, exec_list) {
Chris Wilson54cf91d2010-11-25 18:00:26 +0000455 bool need_fence, need_mappable;
456
Chris Wilson432e58e2010-11-25 19:32:06 +0000457 if (!obj->gtt_space) {
458 entry++;
Chris Wilson54cf91d2010-11-25 18:00:26 +0000459 continue;
Chris Wilson432e58e2010-11-25 19:32:06 +0000460 }
Chris Wilson54cf91d2010-11-25 18:00:26 +0000461
462 need_fence =
463 entry->flags & EXEC_OBJECT_NEEDS_FENCE &&
464 obj->tiling_mode != I915_TILING_NONE;
465 need_mappable =
466 entry->relocation_count ? true : need_fence;
467
468 if ((entry->alignment && obj->gtt_offset & (entry->alignment - 1)) ||
469 (need_mappable && !obj->map_and_fenceable))
470 ret = i915_gem_object_unbind(obj);
471 else
472 ret = i915_gem_object_pin(obj,
473 entry->alignment,
474 need_mappable);
Chris Wilson432e58e2010-11-25 19:32:06 +0000475 if (ret)
Chris Wilson54cf91d2010-11-25 18:00:26 +0000476 goto err;
Chris Wilson432e58e2010-11-25 19:32:06 +0000477
478 entry++;
Chris Wilson54cf91d2010-11-25 18:00:26 +0000479 }
480
481 /* Bind fresh objects */
Chris Wilson432e58e2010-11-25 19:32:06 +0000482 entry = exec;
483 list_for_each_entry(obj, objects, exec_list) {
Chris Wilson54cf91d2010-11-25 18:00:26 +0000484 bool need_fence;
485
486 need_fence =
487 entry->flags & EXEC_OBJECT_NEEDS_FENCE &&
488 obj->tiling_mode != I915_TILING_NONE;
489
490 if (!obj->gtt_space) {
491 bool need_mappable =
492 entry->relocation_count ? true : need_fence;
493
494 ret = i915_gem_object_pin(obj,
495 entry->alignment,
496 need_mappable);
497 if (ret)
498 break;
499 }
500
501 if (need_fence) {
502 ret = i915_gem_object_get_fence_reg(obj, true);
503 if (ret)
504 break;
505
Chris Wilson54cf91d2010-11-25 18:00:26 +0000506 }
Chris Wilson432e58e2010-11-25 19:32:06 +0000507 obj->pending_fenced_gpu_access = need_fence;
Chris Wilson54cf91d2010-11-25 18:00:26 +0000508
509 entry->offset = obj->gtt_offset;
Chris Wilson432e58e2010-11-25 19:32:06 +0000510 entry++;
Chris Wilson54cf91d2010-11-25 18:00:26 +0000511 }
512
Chris Wilson432e58e2010-11-25 19:32:06 +0000513 /* Decrement pin count for bound objects */
514 list_for_each_entry(obj, objects, exec_list) {
Chris Wilson54cf91d2010-11-25 18:00:26 +0000515 if (obj->gtt_space)
516 i915_gem_object_unpin(obj);
517 }
518
519 if (ret != -ENOSPC || retry > 1)
520 return ret;
521
522 /* First attempt, just clear anything that is purgeable.
523 * Second attempt, clear the entire GTT.
524 */
525 ret = i915_gem_evict_everything(dev, retry == 0);
526 if (ret)
527 return ret;
528
529 retry++;
530 } while (1);
Chris Wilson432e58e2010-11-25 19:32:06 +0000531
532err:
Chris Wilson602606a2010-11-28 15:31:02 +0000533 obj = list_entry(obj->exec_list.prev,
534 struct drm_i915_gem_object,
535 exec_list);
Chris Wilson432e58e2010-11-25 19:32:06 +0000536 while (objects != &obj->exec_list) {
537 if (obj->gtt_space)
538 i915_gem_object_unpin(obj);
539
540 obj = list_entry(obj->exec_list.prev,
541 struct drm_i915_gem_object,
542 exec_list);
543 }
544
545 return ret;
Chris Wilson54cf91d2010-11-25 18:00:26 +0000546}
547
548static int
549i915_gem_execbuffer_relocate_slow(struct drm_device *dev,
550 struct drm_file *file,
Chris Wilson432e58e2010-11-25 19:32:06 +0000551 struct list_head *objects,
552 struct drm_i915_gem_exec_object2 *exec,
Chris Wilson54cf91d2010-11-25 18:00:26 +0000553 int count)
554{
555 struct drm_i915_gem_relocation_entry *reloc;
Chris Wilson432e58e2010-11-25 19:32:06 +0000556 struct drm_i915_gem_object *obj;
Chris Wilson54cf91d2010-11-25 18:00:26 +0000557 int i, total, ret;
558
Chris Wilson54cf91d2010-11-25 18:00:26 +0000559 mutex_unlock(&dev->struct_mutex);
560
561 total = 0;
562 for (i = 0; i < count; i++)
Chris Wilson432e58e2010-11-25 19:32:06 +0000563 total += exec[i].relocation_count;
Chris Wilson54cf91d2010-11-25 18:00:26 +0000564
565 reloc = drm_malloc_ab(total, sizeof(*reloc));
566 if (reloc == NULL) {
567 mutex_lock(&dev->struct_mutex);
568 return -ENOMEM;
569 }
570
571 total = 0;
572 for (i = 0; i < count; i++) {
573 struct drm_i915_gem_relocation_entry __user *user_relocs;
574
Chris Wilson432e58e2010-11-25 19:32:06 +0000575 user_relocs = (void __user *)(uintptr_t)exec[i].relocs_ptr;
Chris Wilson54cf91d2010-11-25 18:00:26 +0000576
577 if (copy_from_user(reloc+total, user_relocs,
Chris Wilson432e58e2010-11-25 19:32:06 +0000578 exec[i].relocation_count * sizeof(*reloc))) {
Chris Wilson54cf91d2010-11-25 18:00:26 +0000579 ret = -EFAULT;
580 mutex_lock(&dev->struct_mutex);
581 goto err;
582 }
583
Chris Wilson432e58e2010-11-25 19:32:06 +0000584 total += exec[i].relocation_count;
Chris Wilson54cf91d2010-11-25 18:00:26 +0000585 }
586
587 ret = i915_mutex_lock_interruptible(dev);
588 if (ret) {
589 mutex_lock(&dev->struct_mutex);
590 goto err;
591 }
592
Chris Wilson432e58e2010-11-25 19:32:06 +0000593 ret = i915_gem_execbuffer_reserve(dev, file, objects, exec);
Chris Wilson54cf91d2010-11-25 18:00:26 +0000594 if (ret)
595 goto err;
596
597 total = 0;
Chris Wilson432e58e2010-11-25 19:32:06 +0000598 list_for_each_entry(obj, objects, exec_list) {
Chris Wilson54cf91d2010-11-25 18:00:26 +0000599 obj->base.pending_read_domains = 0;
600 obj->base.pending_write_domain = 0;
601 ret = i915_gem_execbuffer_relocate_object_slow(obj, file,
Chris Wilson432e58e2010-11-25 19:32:06 +0000602 exec,
Chris Wilson54cf91d2010-11-25 18:00:26 +0000603 reloc + total);
604 if (ret)
605 goto err;
606
Chris Wilson432e58e2010-11-25 19:32:06 +0000607 total += exec->relocation_count;
608 exec++;
Chris Wilson54cf91d2010-11-25 18:00:26 +0000609 }
610
611 /* Leave the user relocations as are, this is the painfully slow path,
612 * and we want to avoid the complication of dropping the lock whilst
613 * having buffers reserved in the aperture and so causing spurious
614 * ENOSPC for random operations.
615 */
616
617err:
618 drm_free_large(reloc);
619 return ret;
620}
621
622static void
623i915_gem_execbuffer_flush(struct drm_device *dev,
624 uint32_t invalidate_domains,
625 uint32_t flush_domains,
626 uint32_t flush_rings)
627{
628 drm_i915_private_t *dev_priv = dev->dev_private;
629
630 if (flush_domains & I915_GEM_DOMAIN_CPU)
631 intel_gtt_chipset_flush();
632
633 if ((flush_domains | invalidate_domains) & I915_GEM_GPU_DOMAINS) {
634 if (flush_rings & RING_RENDER)
635 i915_gem_flush_ring(dev, &dev_priv->render_ring,
636 invalidate_domains, flush_domains);
637 if (flush_rings & RING_BSD)
638 i915_gem_flush_ring(dev, &dev_priv->bsd_ring,
639 invalidate_domains, flush_domains);
640 if (flush_rings & RING_BLT)
641 i915_gem_flush_ring(dev, &dev_priv->blt_ring,
642 invalidate_domains, flush_domains);
643 }
644}
645
646
647static int
Chris Wilson432e58e2010-11-25 19:32:06 +0000648i915_gem_execbuffer_move_to_gpu(struct intel_ring_buffer *ring,
649 struct list_head *objects)
Chris Wilson54cf91d2010-11-25 18:00:26 +0000650{
Chris Wilson432e58e2010-11-25 19:32:06 +0000651 struct drm_i915_gem_object *obj;
Chris Wilson54cf91d2010-11-25 18:00:26 +0000652 struct change_domains cd;
Chris Wilson432e58e2010-11-25 19:32:06 +0000653 int ret;
Chris Wilson54cf91d2010-11-25 18:00:26 +0000654
655 cd.invalidate_domains = 0;
656 cd.flush_domains = 0;
657 cd.flush_rings = 0;
Chris Wilson432e58e2010-11-25 19:32:06 +0000658 list_for_each_entry(obj, objects, exec_list)
659 i915_gem_object_set_to_gpu_domain(obj, ring, &cd);
Chris Wilson54cf91d2010-11-25 18:00:26 +0000660
661 if (cd.invalidate_domains | cd.flush_domains) {
662#if WATCH_EXEC
663 DRM_INFO("%s: invalidate_domains %08x flush_domains %08x\n",
664 __func__,
665 cd.invalidate_domains,
666 cd.flush_domains);
667#endif
Chris Wilson432e58e2010-11-25 19:32:06 +0000668 i915_gem_execbuffer_flush(ring->dev,
Chris Wilson54cf91d2010-11-25 18:00:26 +0000669 cd.invalidate_domains,
670 cd.flush_domains,
671 cd.flush_rings);
672 }
673
Chris Wilson432e58e2010-11-25 19:32:06 +0000674 list_for_each_entry(obj, objects, exec_list) {
Chris Wilson54cf91d2010-11-25 18:00:26 +0000675 /* XXX replace with semaphores */
676 if (obj->ring && ring != obj->ring) {
677 ret = i915_gem_object_wait_rendering(obj, true);
678 if (ret)
679 return ret;
680 }
681 }
682
683 return 0;
684}
685
Chris Wilson432e58e2010-11-25 19:32:06 +0000686static bool
687i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
Chris Wilson54cf91d2010-11-25 18:00:26 +0000688{
Chris Wilson432e58e2010-11-25 19:32:06 +0000689 return ((exec->batch_start_offset | exec->batch_len) & 0x7) == 0;
Chris Wilson54cf91d2010-11-25 18:00:26 +0000690}
691
692static int
693validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
694 int count)
695{
696 int i;
697
698 for (i = 0; i < count; i++) {
699 char __user *ptr = (char __user *)(uintptr_t)exec[i].relocs_ptr;
700 int length; /* limited by fault_in_pages_readable() */
701
702 /* First check for malicious input causing overflow */
703 if (exec[i].relocation_count >
704 INT_MAX / sizeof(struct drm_i915_gem_relocation_entry))
705 return -EINVAL;
706
707 length = exec[i].relocation_count *
708 sizeof(struct drm_i915_gem_relocation_entry);
709 if (!access_ok(VERIFY_READ, ptr, length))
710 return -EFAULT;
711
712 /* we may also need to update the presumed offsets */
713 if (!access_ok(VERIFY_WRITE, ptr, length))
714 return -EFAULT;
715
716 if (fault_in_pages_readable(ptr, length))
717 return -EFAULT;
718 }
719
720 return 0;
721}
722
Chris Wilson432e58e2010-11-25 19:32:06 +0000723static int
724i915_gem_execbuffer_wait_for_flips(struct intel_ring_buffer *ring,
725 struct list_head *objects)
726{
727 struct drm_i915_gem_object *obj;
728 int flips;
729
730 /* Check for any pending flips. As we only maintain a flip queue depth
731 * of 1, we can simply insert a WAIT for the next display flip prior
732 * to executing the batch and avoid stalling the CPU.
733 */
734 flips = 0;
735 list_for_each_entry(obj, objects, exec_list) {
736 if (obj->base.write_domain)
737 flips |= atomic_read(&obj->pending_flip);
738 }
739 if (flips) {
740 int plane, flip_mask, ret;
741
742 for (plane = 0; flips >> plane; plane++) {
743 if (((flips >> plane) & 1) == 0)
744 continue;
745
746 if (plane)
747 flip_mask = MI_WAIT_FOR_PLANE_B_FLIP;
748 else
749 flip_mask = MI_WAIT_FOR_PLANE_A_FLIP;
750
751 ret = intel_ring_begin(ring, 2);
752 if (ret)
753 return ret;
754
755 intel_ring_emit(ring, MI_WAIT_FOR_EVENT | flip_mask);
756 intel_ring_emit(ring, MI_NOOP);
757 intel_ring_advance(ring);
758 }
759 }
760
761 return 0;
762}
763
764static void
765i915_gem_execbuffer_move_to_active(struct list_head *objects,
766 struct intel_ring_buffer *ring)
767{
768 struct drm_i915_gem_object *obj;
769
770 list_for_each_entry(obj, objects, exec_list) {
771 obj->base.read_domains = obj->base.pending_read_domains;
772 obj->base.write_domain = obj->base.pending_write_domain;
773 obj->fenced_gpu_access = obj->pending_fenced_gpu_access;
774
775 i915_gem_object_move_to_active(obj, ring);
776 if (obj->base.write_domain) {
777 obj->dirty = 1;
778 list_move_tail(&obj->gpu_write_list,
779 &ring->gpu_write_list);
780 intel_mark_busy(ring->dev, obj);
781 }
782
783 trace_i915_gem_object_change_domain(obj,
784 obj->base.read_domains,
785 obj->base.write_domain);
786 }
787}
788
Chris Wilson54cf91d2010-11-25 18:00:26 +0000789static void
790i915_gem_execbuffer_retire_commands(struct drm_device *dev,
Chris Wilson432e58e2010-11-25 19:32:06 +0000791 struct drm_file *file,
Chris Wilson54cf91d2010-11-25 18:00:26 +0000792 struct intel_ring_buffer *ring)
793{
Chris Wilson432e58e2010-11-25 19:32:06 +0000794 struct drm_i915_gem_request *request;
795 u32 flush_domains;
Chris Wilson54cf91d2010-11-25 18:00:26 +0000796
Chris Wilson432e58e2010-11-25 19:32:06 +0000797 /*
798 * Ensure that the commands in the batch buffer are
799 * finished before the interrupt fires.
800 *
801 * The sampler always gets flushed on i965 (sigh).
802 */
803 flush_domains = 0;
Chris Wilson54cf91d2010-11-25 18:00:26 +0000804 if (INTEL_INFO(dev)->gen >= 4)
805 flush_domains |= I915_GEM_DOMAIN_SAMPLER;
806
807 ring->flush(ring, I915_GEM_DOMAIN_COMMAND, flush_domains);
Chris Wilson54cf91d2010-11-25 18:00:26 +0000808
Chris Wilson432e58e2010-11-25 19:32:06 +0000809 /* Add a breadcrumb for the completion of the batch buffer */
810 request = kzalloc(sizeof(*request), GFP_KERNEL);
811 if (request == NULL || i915_add_request(dev, file, request, ring)) {
812 i915_gem_next_request_seqno(dev, ring);
813 kfree(request);
814 }
815}
Chris Wilson54cf91d2010-11-25 18:00:26 +0000816
817static int
818i915_gem_do_execbuffer(struct drm_device *dev, void *data,
819 struct drm_file *file,
820 struct drm_i915_gem_execbuffer2 *args,
Chris Wilson432e58e2010-11-25 19:32:06 +0000821 struct drm_i915_gem_exec_object2 *exec)
Chris Wilson54cf91d2010-11-25 18:00:26 +0000822{
823 drm_i915_private_t *dev_priv = dev->dev_private;
Chris Wilson432e58e2010-11-25 19:32:06 +0000824 struct list_head objects;
Chris Wilson54cf91d2010-11-25 18:00:26 +0000825 struct drm_i915_gem_object *batch_obj;
826 struct drm_clip_rect *cliprects = NULL;
Chris Wilson54cf91d2010-11-25 18:00:26 +0000827 struct intel_ring_buffer *ring;
Chris Wilsonc4e7a412010-11-30 14:10:25 +0000828 u32 exec_start, exec_len;
Chris Wilson432e58e2010-11-25 19:32:06 +0000829 int ret, i;
Chris Wilson54cf91d2010-11-25 18:00:26 +0000830
Chris Wilson432e58e2010-11-25 19:32:06 +0000831 if (!i915_gem_check_execbuffer(args)) {
832 DRM_ERROR("execbuf with invalid offset/length\n");
833 return -EINVAL;
834 }
835
836 ret = validate_exec_list(exec, args->buffer_count);
Chris Wilson54cf91d2010-11-25 18:00:26 +0000837 if (ret)
838 return ret;
839
840#if WATCH_EXEC
841 DRM_INFO("buffers_ptr %d buffer_count %d len %08x\n",
842 (int) args->buffers_ptr, args->buffer_count, args->batch_len);
843#endif
844 switch (args->flags & I915_EXEC_RING_MASK) {
845 case I915_EXEC_DEFAULT:
846 case I915_EXEC_RENDER:
847 ring = &dev_priv->render_ring;
848 break;
849 case I915_EXEC_BSD:
850 if (!HAS_BSD(dev)) {
851 DRM_ERROR("execbuf with invalid ring (BSD)\n");
852 return -EINVAL;
853 }
854 ring = &dev_priv->bsd_ring;
855 break;
856 case I915_EXEC_BLT:
857 if (!HAS_BLT(dev)) {
858 DRM_ERROR("execbuf with invalid ring (BLT)\n");
859 return -EINVAL;
860 }
861 ring = &dev_priv->blt_ring;
862 break;
863 default:
864 DRM_ERROR("execbuf with unknown ring: %d\n",
865 (int)(args->flags & I915_EXEC_RING_MASK));
866 return -EINVAL;
867 }
868
869 if (args->buffer_count < 1) {
870 DRM_ERROR("execbuf with %d buffers\n", args->buffer_count);
871 return -EINVAL;
872 }
Chris Wilson54cf91d2010-11-25 18:00:26 +0000873
874 if (args->num_cliprects != 0) {
Chris Wilsonc4e7a412010-11-30 14:10:25 +0000875 if (ring != &dev_priv->render_ring) {
876 DRM_ERROR("clip rectangles are only valid with the render ring\n");
877 return -EINVAL;
878 }
879
Chris Wilson432e58e2010-11-25 19:32:06 +0000880 cliprects = kmalloc(args->num_cliprects * sizeof(*cliprects),
Chris Wilson54cf91d2010-11-25 18:00:26 +0000881 GFP_KERNEL);
882 if (cliprects == NULL) {
883 ret = -ENOMEM;
884 goto pre_mutex_err;
885 }
886
Chris Wilson432e58e2010-11-25 19:32:06 +0000887 if (copy_from_user(cliprects,
888 (struct drm_clip_rect __user *)(uintptr_t)
889 args->cliprects_ptr,
890 sizeof(*cliprects)*args->num_cliprects)) {
Chris Wilson54cf91d2010-11-25 18:00:26 +0000891 ret = -EFAULT;
892 goto pre_mutex_err;
893 }
894 }
895
Chris Wilson54cf91d2010-11-25 18:00:26 +0000896 ret = i915_mutex_lock_interruptible(dev);
897 if (ret)
898 goto pre_mutex_err;
899
900 if (dev_priv->mm.suspended) {
901 mutex_unlock(&dev->struct_mutex);
902 ret = -EBUSY;
903 goto pre_mutex_err;
904 }
905
906 /* Look up object handles */
Chris Wilson432e58e2010-11-25 19:32:06 +0000907 INIT_LIST_HEAD(&objects);
Chris Wilson54cf91d2010-11-25 18:00:26 +0000908 for (i = 0; i < args->buffer_count; i++) {
909 struct drm_i915_gem_object *obj;
910
Chris Wilson432e58e2010-11-25 19:32:06 +0000911 obj = to_intel_bo(drm_gem_object_lookup(dev, file,
912 exec[i].handle));
Chris Wilson54cf91d2010-11-25 18:00:26 +0000913 if (obj == NULL) {
914 DRM_ERROR("Invalid object handle %d at index %d\n",
Chris Wilson432e58e2010-11-25 19:32:06 +0000915 exec[i].handle, i);
Chris Wilson54cf91d2010-11-25 18:00:26 +0000916 /* prevent error path from reading uninitialized data */
Chris Wilson54cf91d2010-11-25 18:00:26 +0000917 ret = -ENOENT;
918 goto err;
919 }
Chris Wilson54cf91d2010-11-25 18:00:26 +0000920
Chris Wilson432e58e2010-11-25 19:32:06 +0000921 if (!list_empty(&obj->exec_list)) {
922 DRM_ERROR("Object %p [handle %d, index %d] appears more than once in object list\n",
923 obj, exec[i].handle, i);
Chris Wilson54cf91d2010-11-25 18:00:26 +0000924 ret = -EINVAL;
925 goto err;
926 }
Chris Wilson432e58e2010-11-25 19:32:06 +0000927
928 list_add_tail(&obj->exec_list, &objects);
Chris Wilson54cf91d2010-11-25 18:00:26 +0000929 }
930
931 /* Move the objects en-masse into the GTT, evicting if necessary. */
Chris Wilson432e58e2010-11-25 19:32:06 +0000932 ret = i915_gem_execbuffer_reserve(dev, file, &objects, exec);
Chris Wilson54cf91d2010-11-25 18:00:26 +0000933 if (ret)
934 goto err;
935
936 /* The objects are in their final locations, apply the relocations. */
Chris Wilson432e58e2010-11-25 19:32:06 +0000937 ret = i915_gem_execbuffer_relocate(dev, file, &objects, exec);
Chris Wilson54cf91d2010-11-25 18:00:26 +0000938 if (ret) {
939 if (ret == -EFAULT) {
940 ret = i915_gem_execbuffer_relocate_slow(dev, file,
Chris Wilson432e58e2010-11-25 19:32:06 +0000941 &objects, exec,
Chris Wilson54cf91d2010-11-25 18:00:26 +0000942 args->buffer_count);
943 BUG_ON(!mutex_is_locked(&dev->struct_mutex));
944 }
945 if (ret)
946 goto err;
947 }
948
949 /* Set the pending read domains for the batch buffer to COMMAND */
Chris Wilson432e58e2010-11-25 19:32:06 +0000950 batch_obj = list_entry(objects.prev,
951 struct drm_i915_gem_object,
952 exec_list);
Chris Wilson54cf91d2010-11-25 18:00:26 +0000953 if (batch_obj->base.pending_write_domain) {
954 DRM_ERROR("Attempting to use self-modifying batch buffer\n");
955 ret = -EINVAL;
956 goto err;
957 }
958 batch_obj->base.pending_read_domains |= I915_GEM_DOMAIN_COMMAND;
959
Chris Wilson432e58e2010-11-25 19:32:06 +0000960 ret = i915_gem_execbuffer_move_to_gpu(ring, &objects);
Chris Wilson54cf91d2010-11-25 18:00:26 +0000961 if (ret)
962 goto err;
963
Chris Wilson432e58e2010-11-25 19:32:06 +0000964 ret = i915_gem_execbuffer_wait_for_flips(ring, &objects);
965 if (ret)
Chris Wilson54cf91d2010-11-25 18:00:26 +0000966 goto err;
Chris Wilson54cf91d2010-11-25 18:00:26 +0000967
Chris Wilsonc4e7a412010-11-30 14:10:25 +0000968 exec_start = batch_obj->gtt_offset + args->batch_start_offset;
969 exec_len = args->batch_len;
970 if (cliprects) {
971 for (i = 0; i < args->num_cliprects; i++) {
972 ret = i915_emit_box(dev, &cliprects[i],
973 args->DR1, args->DR4);
974 if (ret)
975 goto err;
976
977 ret = ring->dispatch_execbuffer(ring,
978 exec_start, exec_len);
979 if (ret)
980 goto err;
981 }
982 } else {
983 ret = ring->dispatch_execbuffer(ring, exec_start, exec_len);
984 if (ret)
985 goto err;
986 }
Chris Wilson54cf91d2010-11-25 18:00:26 +0000987
Chris Wilson432e58e2010-11-25 19:32:06 +0000988 i915_gem_execbuffer_move_to_active(&objects, ring);
989 i915_gem_execbuffer_retire_commands(dev, file, ring);
Chris Wilson54cf91d2010-11-25 18:00:26 +0000990
991err:
Chris Wilson432e58e2010-11-25 19:32:06 +0000992 while (!list_empty(&objects)) {
993 struct drm_i915_gem_object *obj;
994
995 obj = list_first_entry(&objects,
996 struct drm_i915_gem_object,
997 exec_list);
998 list_del_init(&obj->exec_list);
999 drm_gem_object_unreference(&obj->base);
Chris Wilson54cf91d2010-11-25 18:00:26 +00001000 }
1001
1002 mutex_unlock(&dev->struct_mutex);
1003
1004pre_mutex_err:
Chris Wilson54cf91d2010-11-25 18:00:26 +00001005 kfree(cliprects);
Chris Wilson54cf91d2010-11-25 18:00:26 +00001006 return ret;
1007}
1008
1009/*
1010 * Legacy execbuffer just creates an exec2 list from the original exec object
1011 * list array and passes it to the real function.
1012 */
1013int
1014i915_gem_execbuffer(struct drm_device *dev, void *data,
1015 struct drm_file *file)
1016{
1017 struct drm_i915_gem_execbuffer *args = data;
1018 struct drm_i915_gem_execbuffer2 exec2;
1019 struct drm_i915_gem_exec_object *exec_list = NULL;
1020 struct drm_i915_gem_exec_object2 *exec2_list = NULL;
1021 int ret, i;
1022
1023#if WATCH_EXEC
1024 DRM_INFO("buffers_ptr %d buffer_count %d len %08x\n",
1025 (int) args->buffers_ptr, args->buffer_count, args->batch_len);
1026#endif
1027
1028 if (args->buffer_count < 1) {
1029 DRM_ERROR("execbuf with %d buffers\n", args->buffer_count);
1030 return -EINVAL;
1031 }
1032
1033 /* Copy in the exec list from userland */
1034 exec_list = drm_malloc_ab(sizeof(*exec_list), args->buffer_count);
1035 exec2_list = drm_malloc_ab(sizeof(*exec2_list), args->buffer_count);
1036 if (exec_list == NULL || exec2_list == NULL) {
1037 DRM_ERROR("Failed to allocate exec list for %d buffers\n",
1038 args->buffer_count);
1039 drm_free_large(exec_list);
1040 drm_free_large(exec2_list);
1041 return -ENOMEM;
1042 }
1043 ret = copy_from_user(exec_list,
1044 (struct drm_i915_relocation_entry __user *)
1045 (uintptr_t) args->buffers_ptr,
1046 sizeof(*exec_list) * args->buffer_count);
1047 if (ret != 0) {
1048 DRM_ERROR("copy %d exec entries failed %d\n",
1049 args->buffer_count, ret);
1050 drm_free_large(exec_list);
1051 drm_free_large(exec2_list);
1052 return -EFAULT;
1053 }
1054
1055 for (i = 0; i < args->buffer_count; i++) {
1056 exec2_list[i].handle = exec_list[i].handle;
1057 exec2_list[i].relocation_count = exec_list[i].relocation_count;
1058 exec2_list[i].relocs_ptr = exec_list[i].relocs_ptr;
1059 exec2_list[i].alignment = exec_list[i].alignment;
1060 exec2_list[i].offset = exec_list[i].offset;
1061 if (INTEL_INFO(dev)->gen < 4)
1062 exec2_list[i].flags = EXEC_OBJECT_NEEDS_FENCE;
1063 else
1064 exec2_list[i].flags = 0;
1065 }
1066
1067 exec2.buffers_ptr = args->buffers_ptr;
1068 exec2.buffer_count = args->buffer_count;
1069 exec2.batch_start_offset = args->batch_start_offset;
1070 exec2.batch_len = args->batch_len;
1071 exec2.DR1 = args->DR1;
1072 exec2.DR4 = args->DR4;
1073 exec2.num_cliprects = args->num_cliprects;
1074 exec2.cliprects_ptr = args->cliprects_ptr;
1075 exec2.flags = I915_EXEC_RENDER;
1076
1077 ret = i915_gem_do_execbuffer(dev, data, file, &exec2, exec2_list);
1078 if (!ret) {
1079 /* Copy the new buffer offsets back to the user's exec list. */
1080 for (i = 0; i < args->buffer_count; i++)
1081 exec_list[i].offset = exec2_list[i].offset;
1082 /* ... and back out to userspace */
1083 ret = copy_to_user((struct drm_i915_relocation_entry __user *)
1084 (uintptr_t) args->buffers_ptr,
1085 exec_list,
1086 sizeof(*exec_list) * args->buffer_count);
1087 if (ret) {
1088 ret = -EFAULT;
1089 DRM_ERROR("failed to copy %d exec entries "
1090 "back to user (%d)\n",
1091 args->buffer_count, ret);
1092 }
1093 }
1094
1095 drm_free_large(exec_list);
1096 drm_free_large(exec2_list);
1097 return ret;
1098}
1099
1100int
1101i915_gem_execbuffer2(struct drm_device *dev, void *data,
1102 struct drm_file *file)
1103{
1104 struct drm_i915_gem_execbuffer2 *args = data;
1105 struct drm_i915_gem_exec_object2 *exec2_list = NULL;
1106 int ret;
1107
1108#if WATCH_EXEC
1109 DRM_INFO("buffers_ptr %d buffer_count %d len %08x\n",
1110 (int) args->buffers_ptr, args->buffer_count, args->batch_len);
1111#endif
1112
1113 if (args->buffer_count < 1) {
1114 DRM_ERROR("execbuf2 with %d buffers\n", args->buffer_count);
1115 return -EINVAL;
1116 }
1117
1118 exec2_list = drm_malloc_ab(sizeof(*exec2_list), args->buffer_count);
1119 if (exec2_list == NULL) {
1120 DRM_ERROR("Failed to allocate exec list for %d buffers\n",
1121 args->buffer_count);
1122 return -ENOMEM;
1123 }
1124 ret = copy_from_user(exec2_list,
1125 (struct drm_i915_relocation_entry __user *)
1126 (uintptr_t) args->buffers_ptr,
1127 sizeof(*exec2_list) * args->buffer_count);
1128 if (ret != 0) {
1129 DRM_ERROR("copy %d exec entries failed %d\n",
1130 args->buffer_count, ret);
1131 drm_free_large(exec2_list);
1132 return -EFAULT;
1133 }
1134
1135 ret = i915_gem_do_execbuffer(dev, data, file, args, exec2_list);
1136 if (!ret) {
1137 /* Copy the new buffer offsets back to the user's exec list. */
1138 ret = copy_to_user((struct drm_i915_relocation_entry __user *)
1139 (uintptr_t) args->buffers_ptr,
1140 exec2_list,
1141 sizeof(*exec2_list) * args->buffer_count);
1142 if (ret) {
1143 ret = -EFAULT;
1144 DRM_ERROR("failed to copy %d exec entries "
1145 "back to user (%d)\n",
1146 args->buffer_count, ret);
1147 }
1148 }
1149
1150 drm_free_large(exec2_list);
1151 return ret;
1152}
1153