Lines Matching +full:1 +full:eb
51 FORCE_CPU_RELOC = 1,
107 * 1. Add a command to load the HW context. For Logical Ring Contexts, i.e.
134 * 1. Validation - Ensure all the pointers, handles and flags are valid.
258 struct i915_request *requests[MAX_ENGINE_INSTANCE + 1];
260 struct eb_vma *batches[MAX_ENGINE_INSTANCE + 1];
263 /** used for excl fence in dma_resv objects when > 1 BB submitted */
290 bool use_64bit_reloc : 1;
291 bool has_llc : 1;
292 bool has_fence : 1;
293 bool needs_unfenced : 1;
299 u64 batch_len[MAX_ENGINE_INSTANCE + 1];
315 struct i915_capture_list *capture_lists[MAX_ENGINE_INSTANCE + 1];
319 static int eb_parse(struct i915_execbuffer *eb);
320 static int eb_pin_engine(struct i915_execbuffer *eb, bool throttle);
321 static void eb_unpin_engine(struct i915_execbuffer *eb);
322 static void eb_capture_release(struct i915_execbuffer *eb);
324 static inline bool eb_use_cmdparser(const struct i915_execbuffer *eb) in eb_use_cmdparser() argument
326 return intel_engine_requires_cmd_parser(eb->context->engine) || in eb_use_cmdparser()
327 (intel_engine_using_cmd_parser(eb->context->engine) && in eb_use_cmdparser()
328 eb->args->batch_len); in eb_use_cmdparser()
331 static int eb_create(struct i915_execbuffer *eb) in eb_create() argument
333 if (!(eb->args->flags & I915_EXEC_HANDLE_LUT)) { in eb_create()
334 unsigned int size = 1 + ilog2(eb->buffer_count); in eb_create()
337 * Without a 1:1 association between relocation handles and in eb_create()
340 * first with 1:1 assocative hash and scaling back until in eb_create()
357 if (size > 1) in eb_create()
360 eb->buckets = kzalloc(sizeof(struct hlist_head) << size, in eb_create()
362 if (eb->buckets) in eb_create()
369 eb->lut_size = size; in eb_create()
371 eb->lut_size = -eb->buffer_count; in eb_create()
437 eb_pin_vma(struct i915_execbuffer *eb, in eb_pin_vma() argument
455 err = i915_vma_pin_ww(vma, &eb->ww, 0, 0, pin_flags); in eb_pin_vma()
464 err = i915_vma_pin_ww(vma, &eb->ww, in eb_pin_vma()
499 eb_validate_vma(struct i915_execbuffer *eb, in eb_validate_vma() argument
507 GRAPHICS_VER(eb->i915) >= 12 && !IS_TIGERLAKE(eb->i915)) in eb_validate_vma()
510 if (unlikely(entry->flags & eb->invalid_flags)) in eb_validate_vma()
539 if (!eb->reloc_cache.has_fence) { in eb_validate_vma()
543 eb->reloc_cache.needs_unfenced) && in eb_validate_vma()
552 is_batch_buffer(struct i915_execbuffer *eb, unsigned int buffer_idx) in is_batch_buffer() argument
554 return eb->args->flags & I915_EXEC_BATCH_FIRST ? in is_batch_buffer()
555 buffer_idx < eb->num_batches : in is_batch_buffer()
556 buffer_idx >= eb->args->buffer_count - eb->num_batches; in is_batch_buffer()
560 eb_add_vma(struct i915_execbuffer *eb, in eb_add_vma() argument
565 struct drm_i915_private *i915 = eb->i915; in eb_add_vma()
566 struct drm_i915_gem_exec_object2 *entry = &eb->exec[i]; in eb_add_vma()
567 struct eb_vma *ev = &eb->vma[i]; in eb_add_vma()
573 if (eb->lut_size > 0) { in eb_add_vma()
576 &eb->buckets[hash_32(entry->handle, in eb_add_vma()
577 eb->lut_size)]); in eb_add_vma()
581 list_add_tail(&ev->reloc_link, &eb->relocs); in eb_add_vma()
592 if (is_batch_buffer(eb, i)) { in eb_add_vma()
596 if (eb->reloc_cache.has_fence) in eb_add_vma()
599 eb->batches[*current_batch] = ev; in eb_add_vma()
608 eb->batch_start_offset, in eb_add_vma()
609 eb->args->batch_len, in eb_add_vma()
615 if (eb->args->batch_len == 0) in eb_add_vma()
616 eb->batch_len[*current_batch] = ev->vma->size - in eb_add_vma()
617 eb->batch_start_offset; in eb_add_vma()
619 eb->batch_len[*current_batch] = eb->args->batch_len; in eb_add_vma()
620 if (unlikely(eb->batch_len[*current_batch] == 0)) { /* impossible! */ in eb_add_vma()
654 static int eb_reserve_vma(struct i915_execbuffer *eb, in eb_reserve_vma() argument
669 err = i915_vma_pin_ww(vma, &eb->ww, in eb_reserve_vma()
677 eb->args->flags |= __EXEC_HAS_RELOC; in eb_reserve_vma()
695 static bool eb_unbind(struct i915_execbuffer *eb, bool force) in eb_unbind() argument
697 const unsigned int count = eb->buffer_count; in eb_unbind()
703 INIT_LIST_HEAD(&eb->unbound); in eb_unbind()
707 struct eb_vma *ev = &eb->vma[i]; in eb_unbind()
719 list_add(&ev->bind_link, &eb->unbound); in eb_unbind()
722 list_add_tail(&ev->bind_link, &eb->unbound); in eb_unbind()
730 list_splice_tail(&last, &eb->unbound); in eb_unbind()
734 static int eb_reserve(struct i915_execbuffer *eb) in eb_reserve() argument
750 * 1. Reorder the buffers, where objects with the most restrictive in eb_reserve()
777 if (pass >= 1) in eb_reserve()
778 eb_unbind(eb, pass >= 2); in eb_reserve()
781 err = mutex_lock_interruptible(&eb->context->vm->mutex); in eb_reserve()
783 err = i915_gem_evict_vm(eb->context->vm, &eb->ww, NULL); in eb_reserve()
784 mutex_unlock(&eb->context->vm->mutex); in eb_reserve()
792 err = mutex_lock_interruptible(&eb->context->vm->mutex); in eb_reserve()
796 err = i915_gem_evict_vm(eb->context->vm, &eb->ww, &busy_bo); in eb_reserve()
797 mutex_unlock(&eb->context->vm->mutex); in eb_reserve()
799 err = i915_gem_object_lock(busy_bo, &eb->ww); in eb_reserve()
809 list_for_each_entry(ev, &eb->unbound, bind_link) { in eb_reserve()
810 err = eb_reserve_vma(eb, ev, pin_flags); in eb_reserve()
822 static int eb_select_context(struct i915_execbuffer *eb) in eb_select_context() argument
826 ctx = i915_gem_context_lookup(eb->file->driver_priv, eb->args->rsvd1); in eb_select_context()
830 eb->gem_context = ctx; in eb_select_context()
832 eb->invalid_flags |= EXEC_OBJECT_NEEDS_GTT; in eb_select_context()
837 static int __eb_add_lut(struct i915_execbuffer *eb, in __eb_add_lut() argument
840 struct i915_gem_context *ctx = eb->gem_context; in __eb_add_lut()
865 if (idr_find(&eb->file->object_idr, handle) == obj) { in __eb_add_lut()
887 static struct i915_vma *eb_lookup_vma(struct i915_execbuffer *eb, u32 handle) in eb_lookup_vma() argument
889 struct i915_address_space *vm = eb->context->vm; in eb_lookup_vma()
897 vma = radix_tree_lookup(&eb->gem_context->handles_vma, handle); in eb_lookup_vma()
904 obj = i915_gem_object_lookup(eb->file, handle); in eb_lookup_vma()
915 if (i915_gem_context_uses_protected_content(eb->gem_context) && in eb_lookup_vma()
917 err = intel_pxp_key_check(eb->i915->pxp, obj, true); in eb_lookup_vma()
930 err = __eb_add_lut(eb, handle, vma); in eb_lookup_vma()
937 } while (1); in eb_lookup_vma()
940 static int eb_lookup_vmas(struct i915_execbuffer *eb) in eb_lookup_vmas() argument
945 INIT_LIST_HEAD(&eb->relocs); in eb_lookup_vmas()
947 for (i = 0; i < eb->buffer_count; i++) { in eb_lookup_vmas()
950 vma = eb_lookup_vma(eb, eb->exec[i].handle); in eb_lookup_vmas()
956 err = eb_validate_vma(eb, &eb->exec[i], vma); in eb_lookup_vmas()
962 err = eb_add_vma(eb, ¤t_batch, i, vma); in eb_lookup_vmas()
969 if (i + 1 < eb->buffer_count) { in eb_lookup_vmas()
976 eb->vma[i + 1].vma = NULL; in eb_lookup_vmas()
982 eb->vma[i].flags |= __EXEC_OBJECT_USERPTR_INIT; in eb_lookup_vmas()
983 eb->args->flags |= __EXEC_USERPTR_USED; in eb_lookup_vmas()
990 eb->vma[i].vma = NULL; in eb_lookup_vmas()
994 static int eb_lock_vmas(struct i915_execbuffer *eb) in eb_lock_vmas() argument
999 for (i = 0; i < eb->buffer_count; i++) { in eb_lock_vmas()
1000 struct eb_vma *ev = &eb->vma[i]; in eb_lock_vmas()
1003 err = i915_gem_object_lock(vma->obj, &eb->ww); in eb_lock_vmas()
1011 static int eb_validate_vmas(struct i915_execbuffer *eb) in eb_validate_vmas() argument
1016 INIT_LIST_HEAD(&eb->unbound); in eb_validate_vmas()
1018 err = eb_lock_vmas(eb); in eb_validate_vmas()
1022 for (i = 0; i < eb->buffer_count; i++) { in eb_validate_vmas()
1023 struct drm_i915_gem_exec_object2 *entry = &eb->exec[i]; in eb_validate_vmas()
1024 struct eb_vma *ev = &eb->vma[i]; in eb_validate_vmas()
1027 err = eb_pin_vma(eb, entry, ev); in eb_validate_vmas()
1034 eb->args->flags |= __EXEC_HAS_RELOC; in eb_validate_vmas()
1039 list_add_tail(&ev->bind_link, &eb->unbound); in eb_validate_vmas()
1048 err = dma_resv_reserve_fences(vma->obj->base.resv, eb->num_batches); in eb_validate_vmas()
1053 eb_vma_misplaced(&eb->exec[i], vma, ev->flags)); in eb_validate_vmas()
1056 if (!list_empty(&eb->unbound)) in eb_validate_vmas()
1057 return eb_reserve(eb); in eb_validate_vmas()
1063 eb_get_vma(const struct i915_execbuffer *eb, unsigned long handle) in eb_get_vma() argument
1065 if (eb->lut_size < 0) { in eb_get_vma()
1066 if (handle >= -eb->lut_size) in eb_get_vma()
1068 return &eb->vma[handle]; in eb_get_vma()
1073 head = &eb->buckets[hash_32(handle, eb->lut_size)]; in eb_get_vma()
1082 static void eb_release_vmas(struct i915_execbuffer *eb, bool final) in eb_release_vmas() argument
1084 const unsigned int count = eb->buffer_count; in eb_release_vmas()
1088 struct eb_vma *ev = &eb->vma[i]; in eb_release_vmas()
1100 eb_capture_release(eb); in eb_release_vmas()
1101 eb_unpin_engine(eb); in eb_release_vmas()
1104 static void eb_destroy(const struct i915_execbuffer *eb) in eb_destroy() argument
1106 if (eb->lut_size > 0) in eb_destroy()
1107 kfree(eb->buckets); in eb_destroy()
1120 cache->page = -1; in reloc_cache_init()
1191 static void reloc_cache_reset(struct reloc_cache *cache, struct i915_execbuffer *eb) in reloc_cache_reset() argument
1226 cache->page = -1; in reloc_cache_reset()
1267 struct i915_execbuffer *eb, in reloc_iomap() argument
1271 struct reloc_cache *cache = &eb->reloc_cache; in reloc_iomap()
1302 vma = i915_gem_object_ggtt_pin_ww(obj, &eb->ww, NULL, 0, 0, in reloc_iomap()
1349 struct i915_execbuffer *eb, in reloc_vaddr() argument
1352 struct reloc_cache *cache = &eb->reloc_cache; in reloc_vaddr()
1360 vaddr = reloc_iomap(vma, eb, page); in reloc_vaddr()
1392 struct i915_execbuffer *eb, in relocate_entry() argument
1397 bool wide = eb->reloc_cache.use_64bit_reloc; in relocate_entry()
1401 vaddr = reloc_vaddr(vma, eb, in relocate_entry()
1409 eb->reloc_cache.vaddr); in relocate_entry()
1422 eb_relocate_entry(struct i915_execbuffer *eb, in eb_relocate_entry() argument
1426 struct drm_i915_private *i915 = eb->i915; in eb_relocate_entry()
1431 target = eb_get_vma(eb, reloc->target_handle); in eb_relocate_entry()
1436 if (unlikely(reloc->write_domain & (reloc->write_domain - 1))) { in eb_relocate_entry()
1468 GRAPHICS_VER(eb->i915) == 6 && in eb_relocate_entry()
1472 reloc_cache_unmap(&eb->reloc_cache); in eb_relocate_entry()
1478 reloc_cache_remap(&eb->reloc_cache, ev->vma->obj); in eb_relocate_entry()
1494 ev->vma->size - (eb->reloc_cache.use_64bit_reloc ? 8 : 4))) { in eb_relocate_entry()
1521 return relocate_entry(ev->vma, reloc, eb, target->vma); in eb_relocate_entry()
1524 static int eb_relocate_vma(struct i915_execbuffer *eb, struct eb_vma *ev) in eb_relocate_vma() argument
1568 u64 offset = eb_relocate_entry(eb, ev, r); in eb_relocate_vma()
1604 reloc_cache_reset(&eb->reloc_cache, eb); in eb_relocate_vma()
1609 eb_relocate_vma_slow(struct i915_execbuffer *eb, struct eb_vma *ev) in eb_relocate_vma_slow() argument
1618 u64 offset = eb_relocate_entry(eb, ev, &relocs[i]); in eb_relocate_vma_slow()
1627 reloc_cache_reset(&eb->reloc_cache, eb); in eb_relocate_vma_slow()
1655 return __get_user(c, end - 1); in check_relocations()
1658 static int eb_copy_relocations(const struct i915_execbuffer *eb) in eb_copy_relocations() argument
1661 const unsigned int count = eb->buffer_count; in eb_copy_relocations()
1666 const unsigned int nreloc = eb->exec[i].relocation_count; in eb_copy_relocations()
1674 err = check_relocations(&eb->exec[i]); in eb_copy_relocations()
1678 urelocs = u64_to_user_ptr(eb->exec[i].relocs_ptr); in eb_copy_relocations()
1681 relocs = kvmalloc_array(size, 1, GFP_KERNEL); in eb_copy_relocations()
1715 unsafe_put_user(-1, in eb_copy_relocations()
1720 eb->exec[i].relocs_ptr = (uintptr_t)relocs; in eb_copy_relocations()
1732 relocs = u64_to_ptr(typeof(*relocs), eb->exec[i].relocs_ptr); in eb_copy_relocations()
1733 if (eb->exec[i].relocation_count) in eb_copy_relocations()
1739 static int eb_prefault_relocations(const struct i915_execbuffer *eb) in eb_prefault_relocations() argument
1741 const unsigned int count = eb->buffer_count; in eb_prefault_relocations()
1747 err = check_relocations(&eb->exec[i]); in eb_prefault_relocations()
1755 static int eb_reinit_userptr(struct i915_execbuffer *eb) in eb_reinit_userptr() argument
1757 const unsigned int count = eb->buffer_count; in eb_reinit_userptr()
1761 if (likely(!(eb->args->flags & __EXEC_USERPTR_USED))) in eb_reinit_userptr()
1765 struct eb_vma *ev = &eb->vma[i]; in eb_reinit_userptr()
1780 static noinline int eb_relocate_parse_slow(struct i915_execbuffer *eb) in eb_relocate_parse_slow() argument
1793 eb_release_vmas(eb, false); in eb_relocate_parse_slow()
1794 i915_gem_ww_ctx_fini(&eb->ww); in eb_relocate_parse_slow()
1799 * 1 - we try to just prefault all the user relocation entries and in eb_relocate_parse_slow()
1810 err = eb_prefault_relocations(eb); in eb_relocate_parse_slow()
1812 err = eb_copy_relocations(eb); in eb_relocate_parse_slow()
1820 err = eb_reinit_userptr(eb); in eb_relocate_parse_slow()
1822 i915_gem_ww_ctx_init(&eb->ww, true); in eb_relocate_parse_slow()
1828 err = eb_pin_engine(eb, false); in eb_relocate_parse_slow()
1832 err = eb_validate_vmas(eb); in eb_relocate_parse_slow()
1836 GEM_BUG_ON(!eb->batches[0]); in eb_relocate_parse_slow()
1838 list_for_each_entry(ev, &eb->relocs, reloc_link) { in eb_relocate_parse_slow()
1840 err = eb_relocate_vma(eb, ev); in eb_relocate_parse_slow()
1844 err = eb_relocate_vma_slow(eb, ev); in eb_relocate_parse_slow()
1860 err = eb_parse(eb); in eb_relocate_parse_slow()
1873 eb_release_vmas(eb, false); in eb_relocate_parse_slow()
1874 err = i915_gem_ww_ctx_backoff(&eb->ww); in eb_relocate_parse_slow()
1884 const unsigned int count = eb->buffer_count; in eb_relocate_parse_slow()
1889 &eb->exec[i]; in eb_relocate_parse_slow()
1903 static int eb_relocate_parse(struct i915_execbuffer *eb) in eb_relocate_parse() argument
1909 err = eb_pin_engine(eb, throttle); in eb_relocate_parse()
1920 err = eb_validate_vmas(eb); in eb_relocate_parse()
1927 if (eb->args->flags & __EXEC_HAS_RELOC) { in eb_relocate_parse()
1930 list_for_each_entry(ev, &eb->relocs, reloc_link) { in eb_relocate_parse()
1931 err = eb_relocate_vma(eb, ev); in eb_relocate_parse()
1943 err = eb_parse(eb); in eb_relocate_parse()
1947 eb_release_vmas(eb, false); in eb_relocate_parse()
1948 err = i915_gem_ww_ctx_backoff(&eb->ww); in eb_relocate_parse()
1956 err = eb_relocate_parse_slow(eb); in eb_relocate_parse()
1965 eb->args->flags &= ~__EXEC_HAS_RELOC; in eb_relocate_parse()
1983 for ((_i) = (_eb)->num_batches - 1; (_i) >= 0; --(_i))
1986 eb_find_first_request_added(struct i915_execbuffer *eb) in eb_find_first_request_added() argument
1990 for_each_batch_add_order(eb, i) in eb_find_first_request_added()
1991 if (eb->requests[i]) in eb_find_first_request_added()
1992 return eb->requests[i]; in eb_find_first_request_added()
2002 static int eb_capture_stage(struct i915_execbuffer *eb) in eb_capture_stage() argument
2004 const unsigned int count = eb->buffer_count; in eb_capture_stage()
2008 struct eb_vma *ev = &eb->vma[i]; in eb_capture_stage()
2015 if (i915_gem_context_is_recoverable(eb->gem_context) && in eb_capture_stage()
2016 (IS_DGFX(eb->i915) || GRAPHICS_VER_FULL(eb->i915) > IP_VER(12, 0))) in eb_capture_stage()
2019 for_each_batch_create_order(eb, j) { in eb_capture_stage()
2026 capture->next = eb->capture_lists[j]; in eb_capture_stage()
2028 eb->capture_lists[j] = capture; in eb_capture_stage()
2036 static void eb_capture_commit(struct i915_execbuffer *eb) in eb_capture_commit() argument
2040 for_each_batch_create_order(eb, j) { in eb_capture_commit()
2041 struct i915_request *rq = eb->requests[j]; in eb_capture_commit()
2046 rq->capture_list = eb->capture_lists[j]; in eb_capture_commit()
2047 eb->capture_lists[j] = NULL; in eb_capture_commit()
2055 static void eb_capture_release(struct i915_execbuffer *eb) in eb_capture_release() argument
2059 for_each_batch_create_order(eb, j) { in eb_capture_release()
2060 if (eb->capture_lists[j]) { in eb_capture_release()
2061 i915_request_free_capture_list(eb->capture_lists[j]); in eb_capture_release()
2062 eb->capture_lists[j] = NULL; in eb_capture_release()
2067 static void eb_capture_list_clear(struct i915_execbuffer *eb) in eb_capture_list_clear() argument
2069 memset(eb->capture_lists, 0, sizeof(eb->capture_lists)); in eb_capture_list_clear()
2074 static int eb_capture_stage(struct i915_execbuffer *eb) in eb_capture_stage() argument
2079 static void eb_capture_commit(struct i915_execbuffer *eb) in eb_capture_commit() argument
2083 static void eb_capture_release(struct i915_execbuffer *eb) in eb_capture_release() argument
2087 static void eb_capture_list_clear(struct i915_execbuffer *eb) in eb_capture_list_clear() argument
2093 static int eb_move_to_gpu(struct i915_execbuffer *eb) in eb_move_to_gpu() argument
2095 const unsigned int count = eb->buffer_count; in eb_move_to_gpu()
2100 struct eb_vma *ev = &eb->vma[i]; in eb_move_to_gpu()
2124 * 1. Rip out the async flush code. in eb_move_to_gpu()
2138 (eb_find_first_request_added(eb), obj, in eb_move_to_gpu()
2142 for_each_batch_add_order(eb, j) { in eb_move_to_gpu()
2145 if (!eb->requests[j]) in eb_move_to_gpu()
2148 err = _i915_vma_move_to_active(vma, eb->requests[j], in eb_move_to_gpu()
2150 eb->composite_fence ? in eb_move_to_gpu()
2151 eb->composite_fence : in eb_move_to_gpu()
2152 &eb->requests[j]->fence, in eb_move_to_gpu()
2159 if (!err && (eb->args->flags & __EXEC_USERPTR_USED)) { in eb_move_to_gpu()
2160 read_lock(&eb->i915->mm.notifier_lock); in eb_move_to_gpu()
2163 * count is always at least 1, otherwise __EXEC_USERPTR_USED in eb_move_to_gpu()
2167 struct eb_vma *ev = &eb->vma[i]; in eb_move_to_gpu()
2178 read_unlock(&eb->i915->mm.notifier_lock); in eb_move_to_gpu()
2186 intel_gt_chipset_flush(eb->gt); in eb_move_to_gpu()
2187 eb_capture_commit(eb); in eb_move_to_gpu()
2192 for_each_batch_create_order(eb, j) { in eb_move_to_gpu()
2193 if (!eb->requests[j]) in eb_move_to_gpu()
2196 i915_request_set_error_once(eb->requests[j], err); in eb_move_to_gpu()
2253 shadow_batch_pin(struct i915_execbuffer *eb, in shadow_batch_pin() argument
2265 err = i915_vma_pin_ww(vma, &eb->ww, 0, 0, flags | PIN_VALIDATE); in shadow_batch_pin()
2272 static struct i915_vma *eb_dispatch_secure(struct i915_execbuffer *eb, struct i915_vma *vma) in eb_dispatch_secure() argument
2278 if (eb->batch_flags & I915_DISPATCH_SECURE) in eb_dispatch_secure()
2279 return i915_gem_object_ggtt_pin_ww(vma->obj, &eb->ww, NULL, 0, 0, PIN_VALIDATE); in eb_dispatch_secure()
2284 static int eb_parse(struct i915_execbuffer *eb) in eb_parse() argument
2286 struct drm_i915_private *i915 = eb->i915; in eb_parse()
2287 struct intel_gt_buffer_pool_node *pool = eb->batch_pool; in eb_parse()
2292 if (!eb_use_cmdparser(eb)) { in eb_parse()
2293 batch = eb_dispatch_secure(eb, eb->batches[0]->vma); in eb_parse()
2300 if (intel_context_is_parallel(eb->context)) in eb_parse()
2303 len = eb->batch_len[0]; in eb_parse()
2304 if (!CMDPARSER_USES_GGTT(eb->i915)) { in eb_parse()
2309 if (!eb->context->vm->has_read_only) { in eb_parse()
2317 if (unlikely(len < eb->batch_len[0])) /* last paranoid check of overflow */ in eb_parse()
2321 pool = intel_gt_get_buffer_pool(eb->gt, len, in eb_parse()
2325 eb->batch_pool = pool; in eb_parse()
2328 err = i915_gem_object_lock(pool->obj, &eb->ww); in eb_parse()
2332 shadow = shadow_batch_pin(eb, pool->obj, eb->context->vm, PIN_USER); in eb_parse()
2341 if (CMDPARSER_USES_GGTT(eb->i915)) { in eb_parse()
2344 shadow = shadow_batch_pin(eb, pool->obj, in eb_parse()
2345 &eb->gt->ggtt->vm, in eb_parse()
2352 eb->batch_flags |= I915_DISPATCH_SECURE; in eb_parse()
2355 batch = eb_dispatch_secure(eb, shadow); in eb_parse()
2359 err = dma_resv_reserve_fences(shadow->obj->base.resv, 1); in eb_parse()
2363 err = intel_engine_cmd_parser(eb->context->engine, in eb_parse()
2364 eb->batches[0]->vma, in eb_parse()
2365 eb->batch_start_offset, in eb_parse()
2366 eb->batch_len[0], in eb_parse()
2371 eb->batches[0] = &eb->vma[eb->buffer_count++]; in eb_parse()
2372 eb->batches[0]->vma = i915_vma_get(shadow); in eb_parse()
2373 eb->batches[0]->flags = __EXEC_OBJECT_HAS_PIN; in eb_parse()
2375 eb->trampoline = trampoline; in eb_parse()
2376 eb->batch_start_offset = 0; in eb_parse()
2380 if (intel_context_is_parallel(eb->context)) in eb_parse()
2383 eb->batches[0] = &eb->vma[eb->buffer_count++]; in eb_parse()
2384 eb->batches[0]->flags = __EXEC_OBJECT_HAS_PIN; in eb_parse()
2385 eb->batches[0]->vma = i915_vma_get(batch); in eb_parse()
2390 static int eb_request_submit(struct i915_execbuffer *eb, in eb_request_submit() argument
2400 if (eb->args->flags & I915_EXEC_GEN7_SOL_RESET) { in eb_request_submit()
2420 eb->batch_start_offset, in eb_request_submit()
2422 eb->batch_flags); in eb_request_submit()
2426 if (eb->trampoline) { in eb_request_submit()
2428 GEM_BUG_ON(eb->batch_start_offset); in eb_request_submit()
2430 i915_vma_offset(eb->trampoline) + in eb_request_submit()
2439 static int eb_submit(struct i915_execbuffer *eb) in eb_submit() argument
2444 err = eb_move_to_gpu(eb); in eb_submit()
2446 for_each_batch_create_order(eb, i) { in eb_submit()
2447 if (!eb->requests[i]) in eb_submit()
2450 trace_i915_request_queue(eb->requests[i], eb->batch_flags); in eb_submit()
2452 err = eb_request_submit(eb, eb->requests[i], in eb_submit()
2453 eb->batches[i]->vma, in eb_submit()
2454 eb->batch_len[i]); in eb_submit()
2486 static struct i915_request *eb_throttle(struct i915_execbuffer *eb, struct intel_context *ce) in eb_throttle() argument
2520 static int eb_pin_timeline(struct i915_execbuffer *eb, struct intel_context *ce, in eb_pin_timeline() argument
2540 rq = eb_throttle(eb, ce); in eb_pin_timeline()
2544 bool nonblock = eb->file->filp->f_flags & O_NONBLOCK; in eb_pin_timeline()
2571 static int eb_pin_engine(struct i915_execbuffer *eb, bool throttle) in eb_pin_engine() argument
2573 struct intel_context *ce = eb->context, *child; in eb_pin_engine()
2577 GEM_BUG_ON(eb->args->flags & __EXEC_ENGINE_PINNED); in eb_pin_engine()
2587 err = intel_context_pin_ww(ce, &eb->ww); in eb_pin_engine()
2591 err = intel_context_pin_ww(child, &eb->ww); in eb_pin_engine()
2596 err = eb_pin_timeline(eb, child, throttle); in eb_pin_engine()
2601 err = eb_pin_timeline(eb, ce, throttle); in eb_pin_engine()
2605 eb->args->flags |= __EXEC_ENGINE_PINNED; in eb_pin_engine()
2622 static void eb_unpin_engine(struct i915_execbuffer *eb) in eb_unpin_engine() argument
2624 struct intel_context *ce = eb->context, *child; in eb_unpin_engine()
2626 if (!(eb->args->flags & __EXEC_ENGINE_PINNED)) in eb_unpin_engine()
2629 eb->args->flags &= ~__EXEC_ENGINE_PINNED; in eb_unpin_engine()
2647 eb_select_legacy_ring(struct i915_execbuffer *eb) in eb_select_legacy_ring() argument
2649 struct drm_i915_private *i915 = eb->i915; in eb_select_legacy_ring()
2650 struct drm_i915_gem_execbuffer2 *args = eb->args; in eb_select_legacy_ring()
2658 return -1; in eb_select_legacy_ring()
2662 i915->engine_uabi_class_count[I915_ENGINE_CLASS_VIDEO] > 1) { in eb_select_legacy_ring()
2666 bsd_idx = gen8_dispatch_bsd_engine(i915, eb->file); in eb_select_legacy_ring()
2675 return -1; in eb_select_legacy_ring()
2684 return -1; in eb_select_legacy_ring()
2691 eb_select_engine(struct i915_execbuffer *eb) in eb_select_engine() argument
2698 if (i915_gem_context_user_engines(eb->gem_context)) in eb_select_engine()
2699 idx = eb->args->flags & I915_EXEC_RING_MASK; in eb_select_engine()
2701 idx = eb_select_legacy_ring(eb); in eb_select_engine()
2703 ce = i915_gem_context_get_engine(eb->gem_context, idx); in eb_select_engine()
2708 if (eb->buffer_count < ce->parallel.number_children + 1) { in eb_select_engine()
2712 if (eb->batch_start_offset || eb->args->batch_len) { in eb_select_engine()
2717 eb->num_batches = ce->parallel.number_children + 1; in eb_select_engine()
2756 eb->context = ce; in eb_select_engine()
2757 eb->gt = ce->engine->gt; in eb_select_engine()
2778 eb_put_engine(struct i915_execbuffer *eb) in eb_put_engine() argument
2782 i915_vm_put(eb->context->vm); in eb_put_engine()
2787 if (eb->gt->info.id) in eb_put_engine()
2788 intel_gt_pm_put(to_gt(eb->gt->i915)); in eb_put_engine()
2789 intel_gt_pm_put(eb->gt); in eb_put_engine()
2790 for_each_child(eb->context, child) in eb_put_engine()
2792 intel_context_put(eb->context); in eb_put_engine()
2807 add_timeline_fence_array(struct i915_execbuffer *eb, in add_timeline_fence_array() argument
2824 SIZE_MAX / sizeof(*f)) - eb->num_fences) in add_timeline_fence_array()
2835 f = krealloc(eb->fences, in add_timeline_fence_array()
2836 (eb->num_fences + nfences) * sizeof(*f), in add_timeline_fence_array()
2841 eb->fences = f; in add_timeline_fence_array()
2842 f += eb->num_fences; in add_timeline_fence_array()
2844 BUILD_BUG_ON(~(ARCH_KMALLOC_MINALIGN - 1) & in add_timeline_fence_array()
2864 syncobj = drm_syncobj_find(eb->file, user_fence.handle); in add_timeline_fence_array()
2866 drm_dbg(&eb->i915->drm, in add_timeline_fence_array()
2875 drm_dbg(&eb->i915->drm, in add_timeline_fence_array()
2885 drm_dbg(&eb->i915->drm, in add_timeline_fence_array()
2913 drm_dbg(&eb->i915->drm, in add_timeline_fence_array()
2934 eb->num_fences++; in add_timeline_fence_array()
2940 static int add_fence_array(struct i915_execbuffer *eb) in add_fence_array() argument
2942 struct drm_i915_gem_execbuffer2 *args = eb->args; in add_fence_array()
2957 SIZE_MAX / sizeof(*f) - eb->num_fences)) in add_fence_array()
2964 f = krealloc(eb->fences, in add_fence_array()
2965 (eb->num_fences + num_fences) * sizeof(*f), in add_fence_array()
2970 eb->fences = f; in add_fence_array()
2971 f += eb->num_fences; in add_fence_array()
2983 syncobj = drm_syncobj_find(eb->file, user_fence.handle); in add_fence_array()
2985 drm_dbg(&eb->i915->drm, in add_fence_array()
2993 drm_dbg(&eb->i915->drm, in add_fence_array()
3000 BUILD_BUG_ON(~(ARCH_KMALLOC_MINALIGN - 1) & in add_fence_array()
3008 eb->num_fences++; in add_fence_array()
3021 await_fence_array(struct i915_execbuffer *eb, in await_fence_array() argument
3027 for (n = 0; n < eb->num_fences; n++) { in await_fence_array()
3028 if (!eb->fences[n].dma_fence) in await_fence_array()
3031 err = i915_request_await_dma_fence(rq, eb->fences[n].dma_fence); in await_fence_array()
3039 static void signal_fence_array(const struct i915_execbuffer *eb, in signal_fence_array() argument
3044 for (n = 0; n < eb->num_fences; n++) { in signal_fence_array()
3048 syncobj = ptr_unpack_bits(eb->fences[n].syncobj, &flags, 2); in signal_fence_array()
3052 if (eb->fences[n].chain_fence) { in signal_fence_array()
3054 eb->fences[n].chain_fence, in signal_fence_array()
3056 eb->fences[n].value); in signal_fence_array()
3061 eb->fences[n].chain_fence = NULL; in signal_fence_array()
3071 struct i915_execbuffer *eb = data; in parse_timeline_fences() local
3077 return add_timeline_fence_array(eb, &timeline_fences); in parse_timeline_fences()
3089 static int eb_request_add(struct i915_execbuffer *eb, struct i915_request *rq, in eb_request_add() argument
3104 if (likely(!intel_context_is_closed(eb->context))) { in eb_request_add()
3105 attr = eb->gem_context->sched; in eb_request_add()
3113 if (intel_context_is_parallel(eb->context)) { in eb_request_add()
3135 static int eb_requests_add(struct i915_execbuffer *eb, int err) in eb_requests_add() argument
3143 for_each_batch_add_order(eb, i) { in eb_requests_add()
3144 struct i915_request *rq = eb->requests[i]; in eb_requests_add()
3148 err |= eb_request_add(eb, rq, err, i == 0); in eb_requests_add()
3160 struct i915_execbuffer *eb) in parse_execbuf2_extensions() argument
3168 if (eb->args->flags & I915_EXEC_FENCE_ARRAY) in parse_execbuf2_extensions()
3177 eb); in parse_execbuf2_extensions()
3180 static void eb_requests_get(struct i915_execbuffer *eb) in eb_requests_get() argument
3184 for_each_batch_create_order(eb, i) { in eb_requests_get()
3185 if (!eb->requests[i]) in eb_requests_get()
3188 i915_request_get(eb->requests[i]); in eb_requests_get()
3192 static void eb_requests_put(struct i915_execbuffer *eb) in eb_requests_put() argument
3196 for_each_batch_create_order(eb, i) { in eb_requests_put()
3197 if (!eb->requests[i]) in eb_requests_put()
3200 i915_request_put(eb->requests[i]); in eb_requests_put()
3205 eb_composite_fence_create(struct i915_execbuffer *eb, int out_fence_fd) in eb_composite_fence_create() argument
3212 GEM_BUG_ON(!intel_context_is_parent(eb->context)); in eb_composite_fence_create()
3214 fences = kmalloc_array(eb->num_batches, sizeof(*fences), GFP_KERNEL); in eb_composite_fence_create()
3218 for_each_batch_create_order(eb, i) { in eb_composite_fence_create()
3219 fences[i] = &eb->requests[i]->fence; in eb_composite_fence_create()
3221 &eb->requests[i]->fence.flags); in eb_composite_fence_create()
3224 fence_array = dma_fence_array_create(eb->num_batches, in eb_composite_fence_create()
3226 eb->context->parallel.fence_context, in eb_composite_fence_create()
3227 eb->context->parallel.seqno++, in eb_composite_fence_create()
3235 for_each_batch_create_order(eb, i) in eb_composite_fence_create()
3238 if (out_fence_fd != -1) { in eb_composite_fence_create()
3246 eb->composite_fence = &fence_array->base; in eb_composite_fence_create()
3252 eb_fences_add(struct i915_execbuffer *eb, struct i915_request *rq, in eb_fences_add() argument
3258 if (unlikely(eb->gem_context->syncobj)) { in eb_fences_add()
3261 fence = drm_syncobj_fence_get(eb->gem_context->syncobj); in eb_fences_add()
3269 if (eb->args->flags & I915_EXEC_FENCE_SUBMIT) in eb_fences_add()
3277 if (eb->fences) { in eb_fences_add()
3278 err = await_fence_array(eb, rq); in eb_fences_add()
3283 if (intel_context_is_parallel(eb->context)) { in eb_fences_add()
3284 out_fence = eb_composite_fence_create(eb, out_fence_fd); in eb_fences_add()
3287 } else if (out_fence_fd != -1) { in eb_fences_add()
3297 eb_find_context(struct i915_execbuffer *eb, unsigned int context_number) in eb_find_context() argument
3302 return eb->context; in eb_find_context()
3304 for_each_child(eb->context, child) in eb_find_context()
3314 eb_requests_create(struct i915_execbuffer *eb, struct dma_fence *in_fence, in eb_requests_create() argument
3320 for_each_batch_create_order(eb, i) { in eb_requests_create()
3322 eb->requests[i] = i915_request_create(eb_find_context(eb, i)); in eb_requests_create()
3323 if (IS_ERR(eb->requests[i])) { in eb_requests_create()
3324 out_fence = ERR_CAST(eb->requests[i]); in eb_requests_create()
3325 eb->requests[i] = NULL; in eb_requests_create()
3334 if (i + 1 == eb->num_batches) { in eb_requests_create()
3335 out_fence = eb_fences_add(eb, eb->requests[i], in eb_requests_create()
3346 if (eb->batches[i]->vma) in eb_requests_create()
3347 eb->requests[i]->batch_res = in eb_requests_create()
3348 i915_vma_resource_get(eb->batches[i]->vma->resource); in eb_requests_create()
3349 if (eb->batch_pool) { in eb_requests_create()
3350 GEM_BUG_ON(intel_context_is_parallel(eb->context)); in eb_requests_create()
3351 intel_gt_buffer_pool_mark_active(eb->batch_pool, in eb_requests_create()
3352 eb->requests[i]); in eb_requests_create()
3366 struct i915_execbuffer eb; in i915_gem_do_execbuffer() local
3369 int out_fence_fd = -1; in i915_gem_do_execbuffer()
3376 eb.i915 = i915; in i915_gem_do_execbuffer()
3377 eb.file = file; in i915_gem_do_execbuffer()
3378 eb.args = args; in i915_gem_do_execbuffer()
3382 eb.exec = exec; in i915_gem_do_execbuffer()
3383 eb.vma = (struct eb_vma *)(exec + args->buffer_count + 1); in i915_gem_do_execbuffer()
3384 eb.vma[0].vma = NULL; in i915_gem_do_execbuffer()
3385 eb.batch_pool = NULL; in i915_gem_do_execbuffer()
3387 eb.invalid_flags = __EXEC_OBJECT_UNKNOWN_FLAGS; in i915_gem_do_execbuffer()
3388 reloc_cache_init(&eb.reloc_cache, eb.i915); in i915_gem_do_execbuffer()
3390 eb.buffer_count = args->buffer_count; in i915_gem_do_execbuffer()
3391 eb.batch_start_offset = args->batch_start_offset; in i915_gem_do_execbuffer()
3392 eb.trampoline = NULL; in i915_gem_do_execbuffer()
3394 eb.fences = NULL; in i915_gem_do_execbuffer()
3395 eb.num_fences = 0; in i915_gem_do_execbuffer()
3397 eb_capture_list_clear(&eb); in i915_gem_do_execbuffer()
3399 memset(eb.requests, 0, sizeof(struct i915_request *) * in i915_gem_do_execbuffer()
3400 ARRAY_SIZE(eb.requests)); in i915_gem_do_execbuffer()
3401 eb.composite_fence = NULL; in i915_gem_do_execbuffer()
3403 eb.batch_flags = 0; in i915_gem_do_execbuffer()
3415 eb.batch_flags |= I915_DISPATCH_SECURE; in i915_gem_do_execbuffer()
3418 eb.batch_flags |= I915_DISPATCH_PINNED; in i915_gem_do_execbuffer()
3420 err = parse_execbuf2_extensions(args, &eb); in i915_gem_do_execbuffer()
3424 err = add_fence_array(&eb); in i915_gem_do_execbuffer()
3449 err = eb_create(&eb); in i915_gem_do_execbuffer()
3453 GEM_BUG_ON(!eb.lut_size); in i915_gem_do_execbuffer()
3455 err = eb_select_context(&eb); in i915_gem_do_execbuffer()
3459 err = eb_select_engine(&eb); in i915_gem_do_execbuffer()
3463 err = eb_lookup_vmas(&eb); in i915_gem_do_execbuffer()
3465 eb_release_vmas(&eb, true); in i915_gem_do_execbuffer()
3469 i915_gem_ww_ctx_init(&eb.ww, true); in i915_gem_do_execbuffer()
3471 err = eb_relocate_parse(&eb); in i915_gem_do_execbuffer()
3484 ww_acquire_done(&eb.ww.ctx); in i915_gem_do_execbuffer()
3485 err = eb_capture_stage(&eb); in i915_gem_do_execbuffer()
3489 out_fence = eb_requests_create(&eb, in_fence, out_fence_fd); in i915_gem_do_execbuffer()
3493 if (eb.requests[0]) in i915_gem_do_execbuffer()
3499 err = eb_submit(&eb); in i915_gem_do_execbuffer()
3502 eb_requests_get(&eb); in i915_gem_do_execbuffer()
3503 err = eb_requests_add(&eb, err); in i915_gem_do_execbuffer()
3505 if (eb.fences) in i915_gem_do_execbuffer()
3506 signal_fence_array(&eb, eb.composite_fence ? in i915_gem_do_execbuffer()
3507 eb.composite_fence : in i915_gem_do_execbuffer()
3508 &eb.requests[0]->fence); in i915_gem_do_execbuffer()
3510 if (unlikely(eb.gem_context->syncobj)) { in i915_gem_do_execbuffer()
3511 drm_syncobj_replace_fence(eb.gem_context->syncobj, in i915_gem_do_execbuffer()
3512 eb.composite_fence ? in i915_gem_do_execbuffer()
3513 eb.composite_fence : in i915_gem_do_execbuffer()
3514 &eb.requests[0]->fence); in i915_gem_do_execbuffer()
3522 out_fence_fd = -1; in i915_gem_do_execbuffer()
3528 if (!out_fence && eb.composite_fence) in i915_gem_do_execbuffer()
3529 dma_fence_put(eb.composite_fence); in i915_gem_do_execbuffer()
3531 eb_requests_put(&eb); in i915_gem_do_execbuffer()
3534 eb_release_vmas(&eb, true); in i915_gem_do_execbuffer()
3536 i915_gem_ww_ctx_fini(&eb.ww); in i915_gem_do_execbuffer()
3538 if (eb.batch_pool) in i915_gem_do_execbuffer()
3539 intel_gt_buffer_pool_put(eb.batch_pool); in i915_gem_do_execbuffer()
3541 eb_put_engine(&eb); in i915_gem_do_execbuffer()
3543 i915_gem_context_put(eb.gem_context); in i915_gem_do_execbuffer()
3545 eb_destroy(&eb); in i915_gem_do_execbuffer()
3547 if (out_fence_fd != -1) in i915_gem_do_execbuffer()
3552 put_fence_array(eb.fences, eb.num_fences); in i915_gem_do_execbuffer()
3571 return !(count < 1 || count > INT_MAX || count > SIZE_MAX / sz - 1); in check_buffer_count()