Adding support for MOXA ART SoC. Testing port of linux-2.6.32.60-moxart.
[linux-3.6.7-moxart.git] / drivers / gpu / drm / i915 / i915_gem_execbuffer.c
blobcdf46b544d4541b76ee0a3ba4d5597b3db3a5c5d
1 /*
2 * Copyright © 2008,2010 Intel Corporation
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:
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.
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.
23 * Authors:
24 * Eric Anholt <eric@anholt.net>
25 * Chris Wilson <chris@chris-wilson.co.uk>
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 #include <linux/dma_remapping.h>
37 struct change_domains {
38 uint32_t invalidate_domains;
39 uint32_t flush_domains;
40 uint32_t flush_rings;
41 uint32_t flips;
45 * Set the next domain for the specified object. This
46 * may not actually perform the necessary flushing/invaliding though,
47 * as that may want to be batched with other set_domain operations
49 * This is (we hope) the only really tricky part of gem. The goal
50 * is fairly simple -- track which caches hold bits of the object
51 * and make sure they remain coherent. A few concrete examples may
52 * help to explain how it works. For shorthand, we use the notation
53 * (read_domains, write_domain), e.g. (CPU, CPU) to indicate the
54 * a pair of read and write domain masks.
56 * Case 1: the batch buffer
58 * 1. Allocated
59 * 2. Written by CPU
60 * 3. Mapped to GTT
61 * 4. Read by GPU
62 * 5. Unmapped from GTT
63 * 6. Freed
65 * Let's take these a step at a time
67 * 1. Allocated
68 * Pages allocated from the kernel may still have
69 * cache contents, so we set them to (CPU, CPU) always.
70 * 2. Written by CPU (using pwrite)
71 * The pwrite function calls set_domain (CPU, CPU) and
72 * this function does nothing (as nothing changes)
73 * 3. Mapped by GTT
74 * This function asserts that the object is not
75 * currently in any GPU-based read or write domains
76 * 4. Read by GPU
77 * i915_gem_execbuffer calls set_domain (COMMAND, 0).
78 * As write_domain is zero, this function adds in the
79 * current read domains (CPU+COMMAND, 0).
80 * flush_domains is set to CPU.
81 * invalidate_domains is set to COMMAND
82 * clflush is run to get data out of the CPU caches
83 * then i915_dev_set_domain calls i915_gem_flush to
84 * emit an MI_FLUSH and drm_agp_chipset_flush
85 * 5. Unmapped from GTT
86 * i915_gem_object_unbind calls set_domain (CPU, CPU)
87 * flush_domains and invalidate_domains end up both zero
88 * so no flushing/invalidating happens
89 * 6. Freed
90 * yay, done
92 * Case 2: The shared render buffer
94 * 1. Allocated
95 * 2. Mapped to GTT
96 * 3. Read/written by GPU
97 * 4. set_domain to (CPU,CPU)
98 * 5. Read/written by CPU
99 * 6. Read/written by GPU
101 * 1. Allocated
102 * Same as last example, (CPU, CPU)
103 * 2. Mapped to GTT
104 * Nothing changes (assertions find that it is not in the GPU)
105 * 3. Read/written by GPU
106 * execbuffer calls set_domain (RENDER, RENDER)
107 * flush_domains gets CPU
108 * invalidate_domains gets GPU
109 * clflush (obj)
110 * MI_FLUSH and drm_agp_chipset_flush
111 * 4. set_domain (CPU, CPU)
112 * flush_domains gets GPU
113 * invalidate_domains gets CPU
114 * wait_rendering (obj) to make sure all drawing is complete.
115 * This will include an MI_FLUSH to get the data from GPU
116 * to memory
117 * clflush (obj) to invalidate the CPU cache
118 * Another MI_FLUSH in i915_gem_flush (eliminate this somehow?)
119 * 5. Read/written by CPU
120 * cache lines are loaded and dirtied
121 * 6. Read written by GPU
122 * Same as last GPU access
124 * Case 3: The constant buffer
126 * 1. Allocated
127 * 2. Written by CPU
128 * 3. Read by GPU
129 * 4. Updated (written) by CPU again
130 * 5. Read by GPU
132 * 1. Allocated
133 * (CPU, CPU)
134 * 2. Written by CPU
135 * (CPU, CPU)
136 * 3. Read by GPU
137 * (CPU+RENDER, 0)
138 * flush_domains = CPU
139 * invalidate_domains = RENDER
140 * clflush (obj)
141 * MI_FLUSH
142 * drm_agp_chipset_flush
143 * 4. Updated (written) by CPU again
144 * (CPU, CPU)
145 * flush_domains = 0 (no previous write domain)
146 * invalidate_domains = 0 (no new read domains)
147 * 5. Read by GPU
148 * (CPU+RENDER, 0)
149 * flush_domains = CPU
150 * invalidate_domains = RENDER
151 * clflush (obj)
152 * MI_FLUSH
153 * drm_agp_chipset_flush
155 static void
156 i915_gem_object_set_to_gpu_domain(struct drm_i915_gem_object *obj,
157 struct intel_ring_buffer *ring,
158 struct change_domains *cd)
160 uint32_t invalidate_domains = 0, flush_domains = 0;
163 * If the object isn't moving to a new write domain,
164 * let the object stay in multiple read domains
166 if (obj->base.pending_write_domain == 0)
167 obj->base.pending_read_domains |= obj->base.read_domains;
170 * Flush the current write domain if
171 * the new read domains don't match. Invalidate
172 * any read domains which differ from the old
173 * write domain
175 if (obj->base.write_domain &&
176 (((obj->base.write_domain != obj->base.pending_read_domains ||
177 obj->ring != ring)) ||
178 (obj->fenced_gpu_access && !obj->pending_fenced_gpu_access))) {
179 flush_domains |= obj->base.write_domain;
180 invalidate_domains |=
181 obj->base.pending_read_domains & ~obj->base.write_domain;
184 * Invalidate any read caches which may have
185 * stale data. That is, any new read domains.
187 invalidate_domains |= obj->base.pending_read_domains & ~obj->base.read_domains;
188 if ((flush_domains | invalidate_domains) & I915_GEM_DOMAIN_CPU)
189 i915_gem_clflush_object(obj);
191 if (obj->base.pending_write_domain)
192 cd->flips |= atomic_read(&obj->pending_flip);
194 /* The actual obj->write_domain will be updated with
195 * pending_write_domain after we emit the accumulated flush for all
196 * of our domain changes in execbuffers (which clears objects'
197 * write_domains). So if we have a current write domain that we
198 * aren't changing, set pending_write_domain to that.
200 if (flush_domains == 0 && obj->base.pending_write_domain == 0)
201 obj->base.pending_write_domain = obj->base.write_domain;
203 cd->invalidate_domains |= invalidate_domains;
204 cd->flush_domains |= flush_domains;
205 if (flush_domains & I915_GEM_GPU_DOMAINS)
206 cd->flush_rings |= intel_ring_flag(obj->ring);
207 if (invalidate_domains & I915_GEM_GPU_DOMAINS)
208 cd->flush_rings |= intel_ring_flag(ring);
211 struct eb_objects {
212 int and;
213 struct hlist_head buckets[0];
216 static struct eb_objects *
217 eb_create(int size)
219 struct eb_objects *eb;
220 int count = PAGE_SIZE / sizeof(struct hlist_head) / 2;
221 while (count > size)
222 count >>= 1;
223 eb = kzalloc(count*sizeof(struct hlist_head) +
224 sizeof(struct eb_objects),
225 GFP_KERNEL);
226 if (eb == NULL)
227 return eb;
229 eb->and = count - 1;
230 return eb;
233 static void
234 eb_reset(struct eb_objects *eb)
236 memset(eb->buckets, 0, (eb->and+1)*sizeof(struct hlist_head));
239 static void
240 eb_add_object(struct eb_objects *eb, struct drm_i915_gem_object *obj)
242 hlist_add_head(&obj->exec_node,
243 &eb->buckets[obj->exec_handle & eb->and]);
246 static struct drm_i915_gem_object *
247 eb_get_object(struct eb_objects *eb, unsigned long handle)
249 struct hlist_head *head;
250 struct hlist_node *node;
251 struct drm_i915_gem_object *obj;
253 head = &eb->buckets[handle & eb->and];
254 hlist_for_each(node, head) {
255 obj = hlist_entry(node, struct drm_i915_gem_object, exec_node);
256 if (obj->exec_handle == handle)
257 return obj;
260 return NULL;
263 static void
264 eb_destroy(struct eb_objects *eb)
266 kfree(eb);
269 static inline int use_cpu_reloc(struct drm_i915_gem_object *obj)
271 return (obj->base.write_domain == I915_GEM_DOMAIN_CPU ||
272 !obj->map_and_fenceable ||
273 obj->cache_level != I915_CACHE_NONE);
276 static int
277 i915_gem_execbuffer_relocate_entry(struct drm_i915_gem_object *obj,
278 struct eb_objects *eb,
279 struct drm_i915_gem_relocation_entry *reloc)
281 struct drm_device *dev = obj->base.dev;
282 struct drm_gem_object *target_obj;
283 struct drm_i915_gem_object *target_i915_obj;
284 uint32_t target_offset;
285 int ret = -EINVAL;
287 /* we've already hold a reference to all valid objects */
288 target_obj = &eb_get_object(eb, reloc->target_handle)->base;
289 if (unlikely(target_obj == NULL))
290 return -ENOENT;
292 target_i915_obj = to_intel_bo(target_obj);
293 target_offset = target_i915_obj->gtt_offset;
295 /* Sandybridge PPGTT errata: We need a global gtt mapping for MI and
296 * pipe_control writes because the gpu doesn't properly redirect them
297 * through the ppgtt for non_secure batchbuffers. */
298 if (unlikely(IS_GEN6(dev) &&
299 reloc->write_domain == I915_GEM_DOMAIN_INSTRUCTION &&
300 !target_i915_obj->has_global_gtt_mapping)) {
301 i915_gem_gtt_bind_object(target_i915_obj,
302 target_i915_obj->cache_level);
305 /* The target buffer should have appeared before us in the
306 * exec_object list, so it should have a GTT space bound by now.
308 if (unlikely(target_offset == 0)) {
309 DRM_DEBUG("No GTT space found for object %d\n",
310 reloc->target_handle);
311 return ret;
314 /* Validate that the target is in a valid r/w GPU domain */
315 if (unlikely(reloc->write_domain & (reloc->write_domain - 1))) {
316 DRM_DEBUG("reloc with multiple write domains: "
317 "obj %p target %d offset %d "
318 "read %08x write %08x",
319 obj, reloc->target_handle,
320 (int) reloc->offset,
321 reloc->read_domains,
322 reloc->write_domain);
323 return ret;
325 if (unlikely((reloc->write_domain | reloc->read_domains)
326 & ~I915_GEM_GPU_DOMAINS)) {
327 DRM_DEBUG("reloc with read/write non-GPU domains: "
328 "obj %p target %d offset %d "
329 "read %08x write %08x",
330 obj, reloc->target_handle,
331 (int) reloc->offset,
332 reloc->read_domains,
333 reloc->write_domain);
334 return ret;
336 if (unlikely(reloc->write_domain && target_obj->pending_write_domain &&
337 reloc->write_domain != target_obj->pending_write_domain)) {
338 DRM_DEBUG("Write domain conflict: "
339 "obj %p target %d offset %d "
340 "new %08x old %08x\n",
341 obj, reloc->target_handle,
342 (int) reloc->offset,
343 reloc->write_domain,
344 target_obj->pending_write_domain);
345 return ret;
348 target_obj->pending_read_domains |= reloc->read_domains;
349 target_obj->pending_write_domain |= reloc->write_domain;
351 /* If the relocation already has the right value in it, no
352 * more work needs to be done.
354 if (target_offset == reloc->presumed_offset)
355 return 0;
357 /* Check that the relocation address is valid... */
358 if (unlikely(reloc->offset > obj->base.size - 4)) {
359 DRM_DEBUG("Relocation beyond object bounds: "
360 "obj %p target %d offset %d size %d.\n",
361 obj, reloc->target_handle,
362 (int) reloc->offset,
363 (int) obj->base.size);
364 return ret;
366 if (unlikely(reloc->offset & 3)) {
367 DRM_DEBUG("Relocation not 4-byte aligned: "
368 "obj %p target %d offset %d.\n",
369 obj, reloc->target_handle,
370 (int) reloc->offset);
371 return ret;
374 /* We can't wait for rendering with pagefaults disabled */
375 if (obj->active && in_atomic())
376 return -EFAULT;
378 reloc->delta += target_offset;
379 if (use_cpu_reloc(obj)) {
380 uint32_t page_offset = reloc->offset & ~PAGE_MASK;
381 char *vaddr;
383 ret = i915_gem_object_set_to_cpu_domain(obj, 1);
384 if (ret)
385 return ret;
387 vaddr = kmap_atomic(obj->pages[reloc->offset >> PAGE_SHIFT]);
388 *(uint32_t *)(vaddr + page_offset) = reloc->delta;
389 kunmap_atomic(vaddr);
390 } else {
391 struct drm_i915_private *dev_priv = dev->dev_private;
392 uint32_t __iomem *reloc_entry;
393 void __iomem *reloc_page;
395 ret = i915_gem_object_set_to_gtt_domain(obj, true);
396 if (ret)
397 return ret;
399 ret = i915_gem_object_put_fence(obj);
400 if (ret)
401 return ret;
403 /* Map the page containing the relocation we're going to perform. */
404 reloc->offset += obj->gtt_offset;
405 reloc_page = io_mapping_map_atomic_wc(dev_priv->mm.gtt_mapping,
406 reloc->offset & PAGE_MASK);
407 reloc_entry = (uint32_t __iomem *)
408 (reloc_page + (reloc->offset & ~PAGE_MASK));
409 iowrite32(reloc->delta, reloc_entry);
410 io_mapping_unmap_atomic(reloc_page);
413 /* and update the user's relocation entry */
414 reloc->presumed_offset = target_offset;
416 return 0;
419 static int
420 i915_gem_execbuffer_relocate_object(struct drm_i915_gem_object *obj,
421 struct eb_objects *eb)
423 #define N_RELOC(x) ((x) / sizeof(struct drm_i915_gem_relocation_entry))
424 struct drm_i915_gem_relocation_entry stack_reloc[N_RELOC(512)];
425 struct drm_i915_gem_relocation_entry __user *user_relocs;
426 struct drm_i915_gem_exec_object2 *entry = obj->exec_entry;
427 int remain, ret;
429 user_relocs = (void __user *)(uintptr_t)entry->relocs_ptr;
431 remain = entry->relocation_count;
432 while (remain) {
433 struct drm_i915_gem_relocation_entry *r = stack_reloc;
434 int count = remain;
435 if (count > ARRAY_SIZE(stack_reloc))
436 count = ARRAY_SIZE(stack_reloc);
437 remain -= count;
439 if (__copy_from_user_inatomic(r, user_relocs, count*sizeof(r[0])))
440 return -EFAULT;
442 do {
443 u64 offset = r->presumed_offset;
445 ret = i915_gem_execbuffer_relocate_entry(obj, eb, r);
446 if (ret)
447 return ret;
449 if (r->presumed_offset != offset &&
450 __copy_to_user_inatomic(&user_relocs->presumed_offset,
451 &r->presumed_offset,
452 sizeof(r->presumed_offset))) {
453 return -EFAULT;
456 user_relocs++;
457 r++;
458 } while (--count);
461 return 0;
462 #undef N_RELOC
465 static int
466 i915_gem_execbuffer_relocate_object_slow(struct drm_i915_gem_object *obj,
467 struct eb_objects *eb,
468 struct drm_i915_gem_relocation_entry *relocs)
470 const struct drm_i915_gem_exec_object2 *entry = obj->exec_entry;
471 int i, ret;
473 for (i = 0; i < entry->relocation_count; i++) {
474 ret = i915_gem_execbuffer_relocate_entry(obj, eb, &relocs[i]);
475 if (ret)
476 return ret;
479 return 0;
482 static int
483 i915_gem_execbuffer_relocate(struct drm_device *dev,
484 struct eb_objects *eb,
485 struct list_head *objects)
487 struct drm_i915_gem_object *obj;
488 int ret = 0;
490 /* This is the fast path and we cannot handle a pagefault whilst
491 * holding the struct mutex lest the user pass in the relocations
492 * contained within a mmaped bo. For in such a case we, the page
493 * fault handler would call i915_gem_fault() and we would try to
494 * acquire the struct mutex again. Obviously this is bad and so
495 * lockdep complains vehemently.
497 pagefault_disable();
498 list_for_each_entry(obj, objects, exec_list) {
499 ret = i915_gem_execbuffer_relocate_object(obj, eb);
500 if (ret)
501 break;
503 pagefault_enable();
505 return ret;
508 #define __EXEC_OBJECT_HAS_FENCE (1<<31)
510 static int
511 need_reloc_mappable(struct drm_i915_gem_object *obj)
513 struct drm_i915_gem_exec_object2 *entry = obj->exec_entry;
514 return entry->relocation_count && !use_cpu_reloc(obj);
517 static int
518 pin_and_fence_object(struct drm_i915_gem_object *obj,
519 struct intel_ring_buffer *ring)
521 struct drm_i915_gem_exec_object2 *entry = obj->exec_entry;
522 bool has_fenced_gpu_access = INTEL_INFO(ring->dev)->gen < 4;
523 bool need_fence, need_mappable;
524 int ret;
526 need_fence =
527 has_fenced_gpu_access &&
528 entry->flags & EXEC_OBJECT_NEEDS_FENCE &&
529 obj->tiling_mode != I915_TILING_NONE;
530 need_mappable = need_fence || need_reloc_mappable(obj);
532 ret = i915_gem_object_pin(obj, entry->alignment, need_mappable);
533 if (ret)
534 return ret;
536 if (has_fenced_gpu_access) {
537 if (entry->flags & EXEC_OBJECT_NEEDS_FENCE) {
538 ret = i915_gem_object_get_fence(obj);
539 if (ret)
540 goto err_unpin;
542 if (i915_gem_object_pin_fence(obj))
543 entry->flags |= __EXEC_OBJECT_HAS_FENCE;
545 obj->pending_fenced_gpu_access = true;
549 entry->offset = obj->gtt_offset;
550 return 0;
552 err_unpin:
553 i915_gem_object_unpin(obj);
554 return ret;
557 static int
558 i915_gem_execbuffer_reserve(struct intel_ring_buffer *ring,
559 struct drm_file *file,
560 struct list_head *objects)
562 drm_i915_private_t *dev_priv = ring->dev->dev_private;
563 struct drm_i915_gem_object *obj;
564 int ret, retry;
565 bool has_fenced_gpu_access = INTEL_INFO(ring->dev)->gen < 4;
566 struct list_head ordered_objects;
568 INIT_LIST_HEAD(&ordered_objects);
569 while (!list_empty(objects)) {
570 struct drm_i915_gem_exec_object2 *entry;
571 bool need_fence, need_mappable;
573 obj = list_first_entry(objects,
574 struct drm_i915_gem_object,
575 exec_list);
576 entry = obj->exec_entry;
578 need_fence =
579 has_fenced_gpu_access &&
580 entry->flags & EXEC_OBJECT_NEEDS_FENCE &&
581 obj->tiling_mode != I915_TILING_NONE;
582 need_mappable = need_fence || need_reloc_mappable(obj);
584 if (need_mappable)
585 list_move(&obj->exec_list, &ordered_objects);
586 else
587 list_move_tail(&obj->exec_list, &ordered_objects);
589 obj->base.pending_read_domains = 0;
590 obj->base.pending_write_domain = 0;
592 list_splice(&ordered_objects, objects);
594 /* Attempt to pin all of the buffers into the GTT.
595 * This is done in 3 phases:
597 * 1a. Unbind all objects that do not match the GTT constraints for
598 * the execbuffer (fenceable, mappable, alignment etc).
599 * 1b. Increment pin count for already bound objects.
600 * 2. Bind new objects.
601 * 3. Decrement pin count.
603 * This avoid unnecessary unbinding of later objects in order to makr
604 * room for the earlier objects *unless* we need to defragment.
606 retry = 0;
607 do {
608 ret = 0;
610 /* Unbind any ill-fitting objects or pin. */
611 list_for_each_entry(obj, objects, exec_list) {
612 struct drm_i915_gem_exec_object2 *entry = obj->exec_entry;
613 bool need_fence, need_mappable;
615 if (!obj->gtt_space)
616 continue;
618 need_fence =
619 has_fenced_gpu_access &&
620 entry->flags & EXEC_OBJECT_NEEDS_FENCE &&
621 obj->tiling_mode != I915_TILING_NONE;
622 need_mappable = need_fence || need_reloc_mappable(obj);
624 if ((entry->alignment && obj->gtt_offset & (entry->alignment - 1)) ||
625 (need_mappable && !obj->map_and_fenceable))
626 ret = i915_gem_object_unbind(obj);
627 else
628 ret = pin_and_fence_object(obj, ring);
629 if (ret)
630 goto err;
633 /* Bind fresh objects */
634 list_for_each_entry(obj, objects, exec_list) {
635 if (obj->gtt_space)
636 continue;
638 ret = pin_and_fence_object(obj, ring);
639 if (ret) {
640 int ret_ignore;
642 /* This can potentially raise a harmless
643 * -EINVAL if we failed to bind in the above
644 * call. It cannot raise -EINTR since we know
645 * that the bo is freshly bound and so will
646 * not need to be flushed or waited upon.
648 ret_ignore = i915_gem_object_unbind(obj);
649 (void)ret_ignore;
650 WARN_ON(obj->gtt_space);
651 break;
655 /* Decrement pin count for bound objects */
656 list_for_each_entry(obj, objects, exec_list) {
657 struct drm_i915_gem_exec_object2 *entry;
659 if (!obj->gtt_space)
660 continue;
662 entry = obj->exec_entry;
663 if (entry->flags & __EXEC_OBJECT_HAS_FENCE) {
664 i915_gem_object_unpin_fence(obj);
665 entry->flags &= ~__EXEC_OBJECT_HAS_FENCE;
668 i915_gem_object_unpin(obj);
670 /* ... and ensure ppgtt mapping exist if needed. */
671 if (dev_priv->mm.aliasing_ppgtt && !obj->has_aliasing_ppgtt_mapping) {
672 i915_ppgtt_bind_object(dev_priv->mm.aliasing_ppgtt,
673 obj, obj->cache_level);
675 obj->has_aliasing_ppgtt_mapping = 1;
679 if (ret != -ENOSPC || retry > 1)
680 return ret;
682 /* First attempt, just clear anything that is purgeable.
683 * Second attempt, clear the entire GTT.
685 ret = i915_gem_evict_everything(ring->dev, retry == 0);
686 if (ret)
687 return ret;
689 retry++;
690 } while (1);
692 err:
693 list_for_each_entry_continue_reverse(obj, objects, exec_list) {
694 struct drm_i915_gem_exec_object2 *entry;
696 if (!obj->gtt_space)
697 continue;
699 entry = obj->exec_entry;
700 if (entry->flags & __EXEC_OBJECT_HAS_FENCE) {
701 i915_gem_object_unpin_fence(obj);
702 entry->flags &= ~__EXEC_OBJECT_HAS_FENCE;
705 i915_gem_object_unpin(obj);
708 return ret;
711 static int
712 i915_gem_execbuffer_relocate_slow(struct drm_device *dev,
713 struct drm_file *file,
714 struct intel_ring_buffer *ring,
715 struct list_head *objects,
716 struct eb_objects *eb,
717 struct drm_i915_gem_exec_object2 *exec,
718 int count)
720 struct drm_i915_gem_relocation_entry *reloc;
721 struct drm_i915_gem_object *obj;
722 int *reloc_offset;
723 int i, total, ret;
725 /* We may process another execbuffer during the unlock... */
726 while (!list_empty(objects)) {
727 obj = list_first_entry(objects,
728 struct drm_i915_gem_object,
729 exec_list);
730 list_del_init(&obj->exec_list);
731 drm_gem_object_unreference(&obj->base);
734 mutex_unlock(&dev->struct_mutex);
736 total = 0;
737 for (i = 0; i < count; i++)
738 total += exec[i].relocation_count;
740 reloc_offset = drm_malloc_ab(count, sizeof(*reloc_offset));
741 reloc = drm_malloc_ab(total, sizeof(*reloc));
742 if (reloc == NULL || reloc_offset == NULL) {
743 drm_free_large(reloc);
744 drm_free_large(reloc_offset);
745 mutex_lock(&dev->struct_mutex);
746 return -ENOMEM;
749 total = 0;
750 for (i = 0; i < count; i++) {
751 struct drm_i915_gem_relocation_entry __user *user_relocs;
753 user_relocs = (void __user *)(uintptr_t)exec[i].relocs_ptr;
755 if (copy_from_user(reloc+total, user_relocs,
756 exec[i].relocation_count * sizeof(*reloc))) {
757 ret = -EFAULT;
758 mutex_lock(&dev->struct_mutex);
759 goto err;
762 reloc_offset[i] = total;
763 total += exec[i].relocation_count;
766 ret = i915_mutex_lock_interruptible(dev);
767 if (ret) {
768 mutex_lock(&dev->struct_mutex);
769 goto err;
772 /* reacquire the objects */
773 eb_reset(eb);
774 for (i = 0; i < count; i++) {
775 obj = to_intel_bo(drm_gem_object_lookup(dev, file,
776 exec[i].handle));
777 if (&obj->base == NULL) {
778 DRM_DEBUG("Invalid object handle %d at index %d\n",
779 exec[i].handle, i);
780 ret = -ENOENT;
781 goto err;
784 list_add_tail(&obj->exec_list, objects);
785 obj->exec_handle = exec[i].handle;
786 obj->exec_entry = &exec[i];
787 eb_add_object(eb, obj);
790 ret = i915_gem_execbuffer_reserve(ring, file, objects);
791 if (ret)
792 goto err;
794 list_for_each_entry(obj, objects, exec_list) {
795 int offset = obj->exec_entry - exec;
796 ret = i915_gem_execbuffer_relocate_object_slow(obj, eb,
797 reloc + reloc_offset[offset]);
798 if (ret)
799 goto err;
802 /* Leave the user relocations as are, this is the painfully slow path,
803 * and we want to avoid the complication of dropping the lock whilst
804 * having buffers reserved in the aperture and so causing spurious
805 * ENOSPC for random operations.
808 err:
809 drm_free_large(reloc);
810 drm_free_large(reloc_offset);
811 return ret;
814 static void
815 i915_gem_execbuffer_flush(struct drm_device *dev,
816 uint32_t invalidate_domains,
817 uint32_t flush_domains)
819 if (flush_domains & I915_GEM_DOMAIN_CPU)
820 intel_gtt_chipset_flush();
822 if (flush_domains & I915_GEM_DOMAIN_GTT)
823 wmb();
826 static int
827 i915_gem_execbuffer_wait_for_flips(struct intel_ring_buffer *ring, u32 flips)
829 u32 plane, flip_mask;
830 int ret;
832 /* Check for any pending flips. As we only maintain a flip queue depth
833 * of 1, we can simply insert a WAIT for the next display flip prior
834 * to executing the batch and avoid stalling the CPU.
837 for (plane = 0; flips >> plane; plane++) {
838 if (((flips >> plane) & 1) == 0)
839 continue;
841 if (plane)
842 flip_mask = MI_WAIT_FOR_PLANE_B_FLIP;
843 else
844 flip_mask = MI_WAIT_FOR_PLANE_A_FLIP;
846 ret = intel_ring_begin(ring, 2);
847 if (ret)
848 return ret;
850 intel_ring_emit(ring, MI_WAIT_FOR_EVENT | flip_mask);
851 intel_ring_emit(ring, MI_NOOP);
852 intel_ring_advance(ring);
855 return 0;
859 static int
860 i915_gem_execbuffer_move_to_gpu(struct intel_ring_buffer *ring,
861 struct list_head *objects)
863 struct drm_i915_gem_object *obj;
864 struct change_domains cd;
865 int ret;
867 memset(&cd, 0, sizeof(cd));
868 list_for_each_entry(obj, objects, exec_list)
869 i915_gem_object_set_to_gpu_domain(obj, ring, &cd);
871 if (cd.invalidate_domains | cd.flush_domains) {
872 i915_gem_execbuffer_flush(ring->dev,
873 cd.invalidate_domains,
874 cd.flush_domains);
877 if (cd.flips) {
878 ret = i915_gem_execbuffer_wait_for_flips(ring, cd.flips);
879 if (ret)
880 return ret;
883 list_for_each_entry(obj, objects, exec_list) {
884 ret = i915_gem_object_sync(obj, ring);
885 if (ret)
886 return ret;
889 /* Unconditionally invalidate gpu caches and ensure that we do flush
890 * any residual writes from the previous batch.
892 ret = i915_gem_flush_ring(ring,
893 I915_GEM_GPU_DOMAINS,
894 ring->gpu_caches_dirty ? I915_GEM_GPU_DOMAINS : 0);
895 if (ret)
896 return ret;
898 ring->gpu_caches_dirty = false;
899 return 0;
902 static bool
903 i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
905 return ((exec->batch_start_offset | exec->batch_len) & 0x7) == 0;
908 static int
909 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
910 int count)
912 int i;
914 for (i = 0; i < count; i++) {
915 char __user *ptr = (char __user *)(uintptr_t)exec[i].relocs_ptr;
916 int length; /* limited by fault_in_pages_readable() */
918 /* First check for malicious input causing overflow */
919 if (exec[i].relocation_count >
920 INT_MAX / sizeof(struct drm_i915_gem_relocation_entry))
921 return -EINVAL;
923 length = exec[i].relocation_count *
924 sizeof(struct drm_i915_gem_relocation_entry);
925 if (!access_ok(VERIFY_READ, ptr, length))
926 return -EFAULT;
928 /* we may also need to update the presumed offsets */
929 if (!access_ok(VERIFY_WRITE, ptr, length))
930 return -EFAULT;
932 if (fault_in_multipages_readable(ptr, length))
933 return -EFAULT;
936 return 0;
939 static void
940 i915_gem_execbuffer_move_to_active(struct list_head *objects,
941 struct intel_ring_buffer *ring,
942 u32 seqno)
944 struct drm_i915_gem_object *obj;
946 list_for_each_entry(obj, objects, exec_list) {
947 u32 old_read = obj->base.read_domains;
948 u32 old_write = obj->base.write_domain;
951 obj->base.read_domains = obj->base.pending_read_domains;
952 obj->base.write_domain = obj->base.pending_write_domain;
953 obj->fenced_gpu_access = obj->pending_fenced_gpu_access;
955 i915_gem_object_move_to_active(obj, ring, seqno);
956 if (obj->base.write_domain) {
957 obj->dirty = 1;
958 obj->pending_gpu_write = true;
959 list_move_tail(&obj->gpu_write_list,
960 &ring->gpu_write_list);
961 if (obj->pin_count) /* check for potential scanout */
962 intel_mark_busy(ring->dev, obj);
965 trace_i915_gem_object_change_domain(obj, old_read, old_write);
968 intel_mark_busy(ring->dev, NULL);
971 static void
972 i915_gem_execbuffer_retire_commands(struct drm_device *dev,
973 struct drm_file *file,
974 struct intel_ring_buffer *ring)
976 struct drm_i915_gem_request *request;
978 /* Unconditionally force add_request to emit a full flush. */
979 ring->gpu_caches_dirty = true;
981 /* Add a breadcrumb for the completion of the batch buffer */
982 request = kzalloc(sizeof(*request), GFP_KERNEL);
983 if (request == NULL || i915_add_request(ring, file, request)) {
984 kfree(request);
988 static int
989 i915_reset_gen7_sol_offsets(struct drm_device *dev,
990 struct intel_ring_buffer *ring)
992 drm_i915_private_t *dev_priv = dev->dev_private;
993 int ret, i;
995 if (!IS_GEN7(dev) || ring != &dev_priv->ring[RCS])
996 return 0;
998 ret = intel_ring_begin(ring, 4 * 3);
999 if (ret)
1000 return ret;
1002 for (i = 0; i < 4; i++) {
1003 intel_ring_emit(ring, MI_LOAD_REGISTER_IMM(1));
1004 intel_ring_emit(ring, GEN7_SO_WRITE_OFFSET(i));
1005 intel_ring_emit(ring, 0);
1008 intel_ring_advance(ring);
1010 return 0;
1013 static int
1014 i915_gem_do_execbuffer(struct drm_device *dev, void *data,
1015 struct drm_file *file,
1016 struct drm_i915_gem_execbuffer2 *args,
1017 struct drm_i915_gem_exec_object2 *exec)
1019 drm_i915_private_t *dev_priv = dev->dev_private;
1020 struct list_head objects;
1021 struct eb_objects *eb;
1022 struct drm_i915_gem_object *batch_obj;
1023 struct drm_clip_rect *cliprects = NULL;
1024 struct intel_ring_buffer *ring;
1025 u32 ctx_id = i915_execbuffer2_get_context_id(*args);
1026 u32 exec_start, exec_len;
1027 u32 seqno;
1028 u32 mask;
1029 int ret, mode, i;
1031 if (!i915_gem_check_execbuffer(args)) {
1032 DRM_DEBUG("execbuf with invalid offset/length\n");
1033 return -EINVAL;
1036 ret = validate_exec_list(exec, args->buffer_count);
1037 if (ret)
1038 return ret;
1040 switch (args->flags & I915_EXEC_RING_MASK) {
1041 case I915_EXEC_DEFAULT:
1042 case I915_EXEC_RENDER:
1043 ring = &dev_priv->ring[RCS];
1044 break;
1045 case I915_EXEC_BSD:
1046 ring = &dev_priv->ring[VCS];
1047 if (ctx_id != 0) {
1048 DRM_DEBUG("Ring %s doesn't support contexts\n",
1049 ring->name);
1050 return -EPERM;
1052 break;
1053 case I915_EXEC_BLT:
1054 ring = &dev_priv->ring[BCS];
1055 if (ctx_id != 0) {
1056 DRM_DEBUG("Ring %s doesn't support contexts\n",
1057 ring->name);
1058 return -EPERM;
1060 break;
1061 default:
1062 DRM_DEBUG("execbuf with unknown ring: %d\n",
1063 (int)(args->flags & I915_EXEC_RING_MASK));
1064 return -EINVAL;
1066 if (!intel_ring_initialized(ring)) {
1067 DRM_DEBUG("execbuf with invalid ring: %d\n",
1068 (int)(args->flags & I915_EXEC_RING_MASK));
1069 return -EINVAL;
1072 mode = args->flags & I915_EXEC_CONSTANTS_MASK;
1073 mask = I915_EXEC_CONSTANTS_MASK;
1074 switch (mode) {
1075 case I915_EXEC_CONSTANTS_REL_GENERAL:
1076 case I915_EXEC_CONSTANTS_ABSOLUTE:
1077 case I915_EXEC_CONSTANTS_REL_SURFACE:
1078 if (ring == &dev_priv->ring[RCS] &&
1079 mode != dev_priv->relative_constants_mode) {
1080 if (INTEL_INFO(dev)->gen < 4)
1081 return -EINVAL;
1083 if (INTEL_INFO(dev)->gen > 5 &&
1084 mode == I915_EXEC_CONSTANTS_REL_SURFACE)
1085 return -EINVAL;
1087 /* The HW changed the meaning on this bit on gen6 */
1088 if (INTEL_INFO(dev)->gen >= 6)
1089 mask &= ~I915_EXEC_CONSTANTS_REL_SURFACE;
1091 break;
1092 default:
1093 DRM_DEBUG("execbuf with unknown constants: %d\n", mode);
1094 return -EINVAL;
1097 if (args->buffer_count < 1) {
1098 DRM_DEBUG("execbuf with %d buffers\n", args->buffer_count);
1099 return -EINVAL;
1102 if (args->num_cliprects != 0) {
1103 if (ring != &dev_priv->ring[RCS]) {
1104 DRM_DEBUG("clip rectangles are only valid with the render ring\n");
1105 return -EINVAL;
1108 if (INTEL_INFO(dev)->gen >= 5) {
1109 DRM_DEBUG("clip rectangles are only valid on pre-gen5\n");
1110 return -EINVAL;
1113 if (args->num_cliprects > UINT_MAX / sizeof(*cliprects)) {
1114 DRM_DEBUG("execbuf with %u cliprects\n",
1115 args->num_cliprects);
1116 return -EINVAL;
1119 cliprects = kmalloc(args->num_cliprects * sizeof(*cliprects),
1120 GFP_KERNEL);
1121 if (cliprects == NULL) {
1122 ret = -ENOMEM;
1123 goto pre_mutex_err;
1126 if (copy_from_user(cliprects,
1127 (struct drm_clip_rect __user *)(uintptr_t)
1128 args->cliprects_ptr,
1129 sizeof(*cliprects)*args->num_cliprects)) {
1130 ret = -EFAULT;
1131 goto pre_mutex_err;
1135 ret = i915_mutex_lock_interruptible(dev);
1136 if (ret)
1137 goto pre_mutex_err;
1139 if (dev_priv->mm.suspended) {
1140 mutex_unlock(&dev->struct_mutex);
1141 ret = -EBUSY;
1142 goto pre_mutex_err;
1145 eb = eb_create(args->buffer_count);
1146 if (eb == NULL) {
1147 mutex_unlock(&dev->struct_mutex);
1148 ret = -ENOMEM;
1149 goto pre_mutex_err;
1152 /* Look up object handles */
1153 INIT_LIST_HEAD(&objects);
1154 for (i = 0; i < args->buffer_count; i++) {
1155 struct drm_i915_gem_object *obj;
1157 obj = to_intel_bo(drm_gem_object_lookup(dev, file,
1158 exec[i].handle));
1159 if (&obj->base == NULL) {
1160 DRM_DEBUG("Invalid object handle %d at index %d\n",
1161 exec[i].handle, i);
1162 /* prevent error path from reading uninitialized data */
1163 ret = -ENOENT;
1164 goto err;
1167 if (!list_empty(&obj->exec_list)) {
1168 DRM_DEBUG("Object %p [handle %d, index %d] appears more than once in object list\n",
1169 obj, exec[i].handle, i);
1170 ret = -EINVAL;
1171 goto err;
1174 list_add_tail(&obj->exec_list, &objects);
1175 obj->exec_handle = exec[i].handle;
1176 obj->exec_entry = &exec[i];
1177 eb_add_object(eb, obj);
1180 /* take note of the batch buffer before we might reorder the lists */
1181 batch_obj = list_entry(objects.prev,
1182 struct drm_i915_gem_object,
1183 exec_list);
1185 /* Move the objects en-masse into the GTT, evicting if necessary. */
1186 ret = i915_gem_execbuffer_reserve(ring, file, &objects);
1187 if (ret)
1188 goto err;
1190 /* The objects are in their final locations, apply the relocations. */
1191 ret = i915_gem_execbuffer_relocate(dev, eb, &objects);
1192 if (ret) {
1193 if (ret == -EFAULT) {
1194 ret = i915_gem_execbuffer_relocate_slow(dev, file, ring,
1195 &objects, eb,
1196 exec,
1197 args->buffer_count);
1198 BUG_ON(!mutex_is_locked(&dev->struct_mutex));
1200 if (ret)
1201 goto err;
1204 /* Set the pending read domains for the batch buffer to COMMAND */
1205 if (batch_obj->base.pending_write_domain) {
1206 DRM_DEBUG("Attempting to use self-modifying batch buffer\n");
1207 ret = -EINVAL;
1208 goto err;
1210 batch_obj->base.pending_read_domains |= I915_GEM_DOMAIN_COMMAND;
1212 ret = i915_gem_execbuffer_move_to_gpu(ring, &objects);
1213 if (ret)
1214 goto err;
1216 seqno = i915_gem_next_request_seqno(ring);
1217 for (i = 0; i < ARRAY_SIZE(ring->sync_seqno); i++) {
1218 if (seqno < ring->sync_seqno[i]) {
1219 /* The GPU can not handle its semaphore value wrapping,
1220 * so every billion or so execbuffers, we need to stall
1221 * the GPU in order to reset the counters.
1223 ret = i915_gpu_idle(dev);
1224 if (ret)
1225 goto err;
1226 i915_gem_retire_requests(dev);
1228 BUG_ON(ring->sync_seqno[i]);
1232 ret = i915_switch_context(ring, file, ctx_id);
1233 if (ret)
1234 goto err;
1236 if (ring == &dev_priv->ring[RCS] &&
1237 mode != dev_priv->relative_constants_mode) {
1238 ret = intel_ring_begin(ring, 4);
1239 if (ret)
1240 goto err;
1242 intel_ring_emit(ring, MI_NOOP);
1243 intel_ring_emit(ring, MI_LOAD_REGISTER_IMM(1));
1244 intel_ring_emit(ring, INSTPM);
1245 intel_ring_emit(ring, mask << 16 | mode);
1246 intel_ring_advance(ring);
1248 dev_priv->relative_constants_mode = mode;
1251 if (args->flags & I915_EXEC_GEN7_SOL_RESET) {
1252 ret = i915_reset_gen7_sol_offsets(dev, ring);
1253 if (ret)
1254 goto err;
1257 trace_i915_gem_ring_dispatch(ring, seqno);
1259 exec_start = batch_obj->gtt_offset + args->batch_start_offset;
1260 exec_len = args->batch_len;
1261 if (cliprects) {
1262 for (i = 0; i < args->num_cliprects; i++) {
1263 ret = i915_emit_box(dev, &cliprects[i],
1264 args->DR1, args->DR4);
1265 if (ret)
1266 goto err;
1268 ret = ring->dispatch_execbuffer(ring,
1269 exec_start, exec_len);
1270 if (ret)
1271 goto err;
1273 } else {
1274 ret = ring->dispatch_execbuffer(ring, exec_start, exec_len);
1275 if (ret)
1276 goto err;
1279 i915_gem_execbuffer_move_to_active(&objects, ring, seqno);
1280 i915_gem_execbuffer_retire_commands(dev, file, ring);
1282 err:
1283 eb_destroy(eb);
1284 while (!list_empty(&objects)) {
1285 struct drm_i915_gem_object *obj;
1287 obj = list_first_entry(&objects,
1288 struct drm_i915_gem_object,
1289 exec_list);
1290 list_del_init(&obj->exec_list);
1291 drm_gem_object_unreference(&obj->base);
1294 mutex_unlock(&dev->struct_mutex);
1296 pre_mutex_err:
1297 kfree(cliprects);
1298 return ret;
1302 * Legacy execbuffer just creates an exec2 list from the original exec object
1303 * list array and passes it to the real function.
1306 i915_gem_execbuffer(struct drm_device *dev, void *data,
1307 struct drm_file *file)
1309 struct drm_i915_gem_execbuffer *args = data;
1310 struct drm_i915_gem_execbuffer2 exec2;
1311 struct drm_i915_gem_exec_object *exec_list = NULL;
1312 struct drm_i915_gem_exec_object2 *exec2_list = NULL;
1313 int ret, i;
1315 if (args->buffer_count < 1) {
1316 DRM_DEBUG("execbuf with %d buffers\n", args->buffer_count);
1317 return -EINVAL;
1320 /* Copy in the exec list from userland */
1321 exec_list = drm_malloc_ab(sizeof(*exec_list), args->buffer_count);
1322 exec2_list = drm_malloc_ab(sizeof(*exec2_list), args->buffer_count);
1323 if (exec_list == NULL || exec2_list == NULL) {
1324 DRM_DEBUG("Failed to allocate exec list for %d buffers\n",
1325 args->buffer_count);
1326 drm_free_large(exec_list);
1327 drm_free_large(exec2_list);
1328 return -ENOMEM;
1330 ret = copy_from_user(exec_list,
1331 (struct drm_i915_relocation_entry __user *)
1332 (uintptr_t) args->buffers_ptr,
1333 sizeof(*exec_list) * args->buffer_count);
1334 if (ret != 0) {
1335 DRM_DEBUG("copy %d exec entries failed %d\n",
1336 args->buffer_count, ret);
1337 drm_free_large(exec_list);
1338 drm_free_large(exec2_list);
1339 return -EFAULT;
1342 for (i = 0; i < args->buffer_count; i++) {
1343 exec2_list[i].handle = exec_list[i].handle;
1344 exec2_list[i].relocation_count = exec_list[i].relocation_count;
1345 exec2_list[i].relocs_ptr = exec_list[i].relocs_ptr;
1346 exec2_list[i].alignment = exec_list[i].alignment;
1347 exec2_list[i].offset = exec_list[i].offset;
1348 if (INTEL_INFO(dev)->gen < 4)
1349 exec2_list[i].flags = EXEC_OBJECT_NEEDS_FENCE;
1350 else
1351 exec2_list[i].flags = 0;
1354 exec2.buffers_ptr = args->buffers_ptr;
1355 exec2.buffer_count = args->buffer_count;
1356 exec2.batch_start_offset = args->batch_start_offset;
1357 exec2.batch_len = args->batch_len;
1358 exec2.DR1 = args->DR1;
1359 exec2.DR4 = args->DR4;
1360 exec2.num_cliprects = args->num_cliprects;
1361 exec2.cliprects_ptr = args->cliprects_ptr;
1362 exec2.flags = I915_EXEC_RENDER;
1363 i915_execbuffer2_set_context_id(exec2, 0);
1365 ret = i915_gem_do_execbuffer(dev, data, file, &exec2, exec2_list);
1366 if (!ret) {
1367 /* Copy the new buffer offsets back to the user's exec list. */
1368 for (i = 0; i < args->buffer_count; i++)
1369 exec_list[i].offset = exec2_list[i].offset;
1370 /* ... and back out to userspace */
1371 ret = copy_to_user((struct drm_i915_relocation_entry __user *)
1372 (uintptr_t) args->buffers_ptr,
1373 exec_list,
1374 sizeof(*exec_list) * args->buffer_count);
1375 if (ret) {
1376 ret = -EFAULT;
1377 DRM_DEBUG("failed to copy %d exec entries "
1378 "back to user (%d)\n",
1379 args->buffer_count, ret);
1383 drm_free_large(exec_list);
1384 drm_free_large(exec2_list);
1385 return ret;
1389 i915_gem_execbuffer2(struct drm_device *dev, void *data,
1390 struct drm_file *file)
1392 struct drm_i915_gem_execbuffer2 *args = data;
1393 struct drm_i915_gem_exec_object2 *exec2_list = NULL;
1394 int ret;
1396 if (args->buffer_count < 1 ||
1397 args->buffer_count > UINT_MAX / sizeof(*exec2_list)) {
1398 DRM_DEBUG("execbuf2 with %d buffers\n", args->buffer_count);
1399 return -EINVAL;
1402 exec2_list = kmalloc(sizeof(*exec2_list)*args->buffer_count,
1403 GFP_KERNEL | __GFP_NOWARN | __GFP_NORETRY);
1404 if (exec2_list == NULL)
1405 exec2_list = drm_malloc_ab(sizeof(*exec2_list),
1406 args->buffer_count);
1407 if (exec2_list == NULL) {
1408 DRM_DEBUG("Failed to allocate exec list for %d buffers\n",
1409 args->buffer_count);
1410 return -ENOMEM;
1412 ret = copy_from_user(exec2_list,
1413 (struct drm_i915_relocation_entry __user *)
1414 (uintptr_t) args->buffers_ptr,
1415 sizeof(*exec2_list) * args->buffer_count);
1416 if (ret != 0) {
1417 DRM_DEBUG("copy %d exec entries failed %d\n",
1418 args->buffer_count, ret);
1419 drm_free_large(exec2_list);
1420 return -EFAULT;
1423 ret = i915_gem_do_execbuffer(dev, data, file, args, exec2_list);
1424 if (!ret) {
1425 /* Copy the new buffer offsets back to the user's exec list. */
1426 ret = copy_to_user((struct drm_i915_relocation_entry __user *)
1427 (uintptr_t) args->buffers_ptr,
1428 exec2_list,
1429 sizeof(*exec2_list) * args->buffer_count);
1430 if (ret) {
1431 ret = -EFAULT;
1432 DRM_DEBUG("failed to copy %d exec entries "
1433 "back to user (%d)\n",
1434 args->buffer_count, ret);
1438 drm_free_large(exec2_list);
1439 return ret;