Lines Matching +full:1 +full:eb

50 	FORCE_CPU_RELOC = 1,
106 * 1. Add a command to load the HW context. For Logical Ring Contexts, i.e.
133 * 1. Validation - Ensure all the pointers, handles and flags are valid.
259 struct i915_request *requests[MAX_ENGINE_INSTANCE + 1];
261 struct eb_vma *batches[MAX_ENGINE_INSTANCE + 1];
264 /** used for excl fence in dma_resv objects when > 1 BB submitted */
291 bool use_64bit_reloc : 1;
292 bool has_llc : 1;
293 bool has_fence : 1;
294 bool needs_unfenced : 1;
300 u64 batch_len[MAX_ENGINE_INSTANCE + 1];
316 struct i915_capture_list *capture_lists[MAX_ENGINE_INSTANCE + 1];
320 static int eb_parse(struct i915_execbuffer *eb);
321 static int eb_pin_engine(struct i915_execbuffer *eb, bool throttle);
322 static void eb_unpin_engine(struct i915_execbuffer *eb);
323 static void eb_capture_release(struct i915_execbuffer *eb);
325 static bool eb_use_cmdparser(const struct i915_execbuffer *eb) in eb_use_cmdparser() argument
327 return intel_engine_requires_cmd_parser(eb->context->engine) || in eb_use_cmdparser()
328 (intel_engine_using_cmd_parser(eb->context->engine) && in eb_use_cmdparser()
329 eb->args->batch_len); in eb_use_cmdparser()
332 static int eb_create(struct i915_execbuffer *eb) in eb_create() argument
334 if (!(eb->args->flags & I915_EXEC_HANDLE_LUT)) { in eb_create()
335 unsigned int size = 1 + ilog2(eb->buffer_count); in eb_create()
338 * Without a 1:1 association between relocation handles and in eb_create()
341 * first with 1:1 associative hash and scaling back until in eb_create()
358 if (size > 1) in eb_create()
361 eb->buckets = kzalloc(sizeof(struct hlist_head) << size, in eb_create()
363 if (eb->buckets) in eb_create()
370 eb->lut_size = size; in eb_create()
372 eb->lut_size = -eb->buffer_count; in eb_create()
438 eb_pin_vma(struct i915_execbuffer *eb, in eb_pin_vma() argument
456 err = i915_vma_pin_ww(vma, &eb->ww, 0, 0, pin_flags); in eb_pin_vma()
465 err = i915_vma_pin_ww(vma, &eb->ww, in eb_pin_vma()
500 eb_validate_vma(struct i915_execbuffer *eb, in eb_validate_vma() argument
508 GRAPHICS_VER(eb->i915) >= 12 && !IS_TIGERLAKE(eb->i915)) in eb_validate_vma()
511 if (unlikely(entry->flags & eb->invalid_flags)) in eb_validate_vma()
540 if (!eb->reloc_cache.has_fence) { in eb_validate_vma()
544 eb->reloc_cache.needs_unfenced) && in eb_validate_vma()
553 is_batch_buffer(struct i915_execbuffer *eb, unsigned int buffer_idx) in is_batch_buffer() argument
555 return eb->args->flags & I915_EXEC_BATCH_FIRST ? in is_batch_buffer()
556 buffer_idx < eb->num_batches : in is_batch_buffer()
557 buffer_idx >= eb->args->buffer_count - eb->num_batches; in is_batch_buffer()
561 eb_add_vma(struct i915_execbuffer *eb, in eb_add_vma() argument
566 struct drm_i915_private *i915 = eb->i915; in eb_add_vma()
567 struct drm_i915_gem_exec_object2 *entry = &eb->exec[i]; in eb_add_vma()
568 struct eb_vma *ev = &eb->vma[i]; in eb_add_vma()
574 if (eb->lut_size > 0) { in eb_add_vma()
577 &eb->buckets[hash_32(entry->handle, in eb_add_vma()
578 eb->lut_size)]); in eb_add_vma()
582 list_add_tail(&ev->reloc_link, &eb->relocs); in eb_add_vma()
593 if (is_batch_buffer(eb, i)) { in eb_add_vma()
597 if (eb->reloc_cache.has_fence) in eb_add_vma()
600 eb->batches[*current_batch] = ev; in eb_add_vma()
609 eb->batch_start_offset, in eb_add_vma()
610 eb->args->batch_len, in eb_add_vma()
616 if (eb->args->batch_len == 0) in eb_add_vma()
617 eb->batch_len[*current_batch] = ev->vma->size - in eb_add_vma()
618 eb->batch_start_offset; in eb_add_vma()
620 eb->batch_len[*current_batch] = eb->args->batch_len; in eb_add_vma()
621 if (unlikely(eb->batch_len[*current_batch] == 0)) { /* impossible! */ in eb_add_vma()
655 static int eb_reserve_vma(struct i915_execbuffer *eb, in eb_reserve_vma() argument
670 err = i915_vma_pin_ww(vma, &eb->ww, in eb_reserve_vma()
678 eb->args->flags |= __EXEC_HAS_RELOC; in eb_reserve_vma()
696 static bool eb_unbind(struct i915_execbuffer *eb, bool force) in eb_unbind() argument
698 const unsigned int count = eb->buffer_count; in eb_unbind()
704 INIT_LIST_HEAD(&eb->unbound); in eb_unbind()
708 struct eb_vma *ev = &eb->vma[i]; in eb_unbind()
720 list_add(&ev->bind_link, &eb->unbound); in eb_unbind()
723 list_add_tail(&ev->bind_link, &eb->unbound); in eb_unbind()
731 list_splice_tail(&last, &eb->unbound); in eb_unbind()
735 static int eb_reserve(struct i915_execbuffer *eb) in eb_reserve() argument
751 * 1. Reorder the buffers, where objects with the most restrictive in eb_reserve()
778 if (pass >= 1) in eb_reserve()
779 eb_unbind(eb, pass >= 2); in eb_reserve()
782 err = mutex_lock_interruptible(&eb->context->vm->mutex); in eb_reserve()
784 err = i915_gem_evict_vm(eb->context->vm, &eb->ww, NULL); in eb_reserve()
785 mutex_unlock(&eb->context->vm->mutex); in eb_reserve()
793 err = mutex_lock_interruptible(&eb->context->vm->mutex); in eb_reserve()
797 err = i915_gem_evict_vm(eb->context->vm, &eb->ww, &busy_bo); in eb_reserve()
798 mutex_unlock(&eb->context->vm->mutex); in eb_reserve()
800 err = i915_gem_object_lock(busy_bo, &eb->ww); in eb_reserve()
810 list_for_each_entry(ev, &eb->unbound, bind_link) { in eb_reserve()
811 err = eb_reserve_vma(eb, ev, pin_flags); in eb_reserve()
823 static int eb_select_context(struct i915_execbuffer *eb) in eb_select_context() argument
827 ctx = i915_gem_context_lookup(eb->file->driver_priv, eb->args->rsvd1); in eb_select_context()
831 eb->gem_context = ctx; in eb_select_context()
833 eb->invalid_flags |= EXEC_OBJECT_NEEDS_GTT; in eb_select_context()
838 static int __eb_add_lut(struct i915_execbuffer *eb, in __eb_add_lut() argument
841 struct i915_gem_context *ctx = eb->gem_context; in __eb_add_lut()
866 if (idr_find(&eb->file->object_idr, handle) == obj) { in __eb_add_lut()
888 static struct i915_vma *eb_lookup_vma(struct i915_execbuffer *eb, u32 handle) in eb_lookup_vma() argument
890 struct i915_address_space *vm = eb->context->vm; in eb_lookup_vma()
898 vma = radix_tree_lookup(&eb->gem_context->handles_vma, handle); in eb_lookup_vma()
905 obj = i915_gem_object_lookup(eb->file, handle); in eb_lookup_vma()
916 if (i915_gem_context_uses_protected_content(eb->gem_context) && in eb_lookup_vma()
918 err = intel_pxp_key_check(eb->i915->pxp, obj, true); in eb_lookup_vma()
931 err = __eb_add_lut(eb, handle, vma); in eb_lookup_vma()
938 } while (1); in eb_lookup_vma()
941 static int eb_lookup_vmas(struct i915_execbuffer *eb) in eb_lookup_vmas() argument
946 INIT_LIST_HEAD(&eb->relocs); in eb_lookup_vmas()
948 for (i = 0; i < eb->buffer_count; i++) { in eb_lookup_vmas()
951 vma = eb_lookup_vma(eb, eb->exec[i].handle); in eb_lookup_vmas()
957 err = eb_validate_vma(eb, &eb->exec[i], vma); in eb_lookup_vmas()
963 err = eb_add_vma(eb, &current_batch, i, vma); in eb_lookup_vmas()
970 if (i + 1 < eb->buffer_count) { in eb_lookup_vmas()
977 eb->vma[i + 1].vma = NULL; in eb_lookup_vmas()
983 eb->vma[i].flags |= __EXEC_OBJECT_USERPTR_INIT; in eb_lookup_vmas()
984 eb->args->flags |= __EXEC_USERPTR_USED; in eb_lookup_vmas()
991 eb->vma[i].vma = NULL; in eb_lookup_vmas()
995 static int eb_lock_vmas(struct i915_execbuffer *eb) in eb_lock_vmas() argument
1000 for (i = 0; i < eb->buffer_count; i++) { in eb_lock_vmas()
1001 struct eb_vma *ev = &eb->vma[i]; in eb_lock_vmas()
1004 err = i915_gem_object_lock(vma->obj, &eb->ww); in eb_lock_vmas()
1012 static int eb_validate_vmas(struct i915_execbuffer *eb) in eb_validate_vmas() argument
1017 INIT_LIST_HEAD(&eb->unbound); in eb_validate_vmas()
1019 err = eb_lock_vmas(eb); in eb_validate_vmas()
1023 for (i = 0; i < eb->buffer_count; i++) { in eb_validate_vmas()
1024 struct drm_i915_gem_exec_object2 *entry = &eb->exec[i]; in eb_validate_vmas()
1025 struct eb_vma *ev = &eb->vma[i]; in eb_validate_vmas()
1028 err = eb_pin_vma(eb, entry, ev); in eb_validate_vmas()
1035 eb->args->flags |= __EXEC_HAS_RELOC; in eb_validate_vmas()
1040 list_add_tail(&ev->bind_link, &eb->unbound); in eb_validate_vmas()
1049 err = dma_resv_reserve_fences(vma->obj->base.resv, eb->num_batches); in eb_validate_vmas()
1054 eb_vma_misplaced(&eb->exec[i], vma, ev->flags)); in eb_validate_vmas()
1057 if (!list_empty(&eb->unbound)) in eb_validate_vmas()
1058 return eb_reserve(eb); in eb_validate_vmas()
1064 eb_get_vma(const struct i915_execbuffer *eb, unsigned long handle) in eb_get_vma() argument
1066 if (eb->lut_size < 0) { in eb_get_vma()
1067 if (handle >= -eb->lut_size) in eb_get_vma()
1069 return &eb->vma[handle]; in eb_get_vma()
1074 head = &eb->buckets[hash_32(handle, eb->lut_size)]; in eb_get_vma()
1083 static void eb_release_vmas(struct i915_execbuffer *eb, bool final) in eb_release_vmas() argument
1085 const unsigned int count = eb->buffer_count; in eb_release_vmas()
1089 struct eb_vma *ev = &eb->vma[i]; in eb_release_vmas()
1101 eb_capture_release(eb); in eb_release_vmas()
1102 eb_unpin_engine(eb); in eb_release_vmas()
1105 static void eb_destroy(const struct i915_execbuffer *eb) in eb_destroy() argument
1107 if (eb->lut_size > 0) in eb_destroy()
1108 kfree(eb->buckets); in eb_destroy()
1121 cache->page = -1; in reloc_cache_init()
1192 static void reloc_cache_reset(struct reloc_cache *cache, struct i915_execbuffer *eb) in reloc_cache_reset() argument
1227 cache->page = -1; in reloc_cache_reset()
1268 struct i915_execbuffer *eb, in reloc_iomap() argument
1272 struct reloc_cache *cache = &eb->reloc_cache; in reloc_iomap()
1303 vma = i915_gem_object_ggtt_pin_ww(obj, &eb->ww, NULL, 0, 0, in reloc_iomap()
1350 struct i915_execbuffer *eb, in reloc_vaddr() argument
1353 struct reloc_cache *cache = &eb->reloc_cache; in reloc_vaddr()
1361 vaddr = reloc_iomap(vma, eb, page); in reloc_vaddr()
1393 struct i915_execbuffer *eb, in relocate_entry() argument
1398 bool wide = eb->reloc_cache.use_64bit_reloc; in relocate_entry()
1402 vaddr = reloc_vaddr(vma, eb, in relocate_entry()
1410 eb->reloc_cache.vaddr); in relocate_entry()
1423 eb_relocate_entry(struct i915_execbuffer *eb, in eb_relocate_entry() argument
1427 struct drm_i915_private *i915 = eb->i915; in eb_relocate_entry()
1432 target = eb_get_vma(eb, reloc->target_handle); in eb_relocate_entry()
1437 if (unlikely(reloc->write_domain & (reloc->write_domain - 1))) { in eb_relocate_entry()
1469 GRAPHICS_VER(eb->i915) == 6 && in eb_relocate_entry()
1473 reloc_cache_unmap(&eb->reloc_cache); in eb_relocate_entry()
1479 reloc_cache_remap(&eb->reloc_cache, ev->vma->obj); in eb_relocate_entry()
1495 ev->vma->size - (eb->reloc_cache.use_64bit_reloc ? 8 : 4))) { in eb_relocate_entry()
1522 return relocate_entry(ev->vma, reloc, eb, target->vma); in eb_relocate_entry()
1525 static int eb_relocate_vma(struct i915_execbuffer *eb, struct eb_vma *ev) in eb_relocate_vma() argument
1569 u64 offset = eb_relocate_entry(eb, ev, r); in eb_relocate_vma()
1605 reloc_cache_reset(&eb->reloc_cache, eb); in eb_relocate_vma()
1610 eb_relocate_vma_slow(struct i915_execbuffer *eb, struct eb_vma *ev) in eb_relocate_vma_slow() argument
1619 u64 offset = eb_relocate_entry(eb, ev, &relocs[i]); in eb_relocate_vma_slow()
1628 reloc_cache_reset(&eb->reloc_cache, eb); in eb_relocate_vma_slow()
1656 return __get_user(c, end - 1); in check_relocations()
1659 static int eb_copy_relocations(const struct i915_execbuffer *eb) in eb_copy_relocations() argument
1662 const unsigned int count = eb->buffer_count; in eb_copy_relocations()
1667 const unsigned int nreloc = eb->exec[i].relocation_count; in eb_copy_relocations()
1675 err = check_relocations(&eb->exec[i]); in eb_copy_relocations()
1679 urelocs = u64_to_user_ptr(eb->exec[i].relocs_ptr); in eb_copy_relocations()
1682 relocs = kvmalloc_array(1, size, GFP_KERNEL); in eb_copy_relocations()
1716 unsafe_put_user(-1, in eb_copy_relocations()
1721 eb->exec[i].relocs_ptr = (uintptr_t)relocs; in eb_copy_relocations()
1733 relocs = u64_to_ptr(typeof(*relocs), eb->exec[i].relocs_ptr); in eb_copy_relocations()
1734 if (eb->exec[i].relocation_count) in eb_copy_relocations()
1740 static int eb_prefault_relocations(const struct i915_execbuffer *eb) in eb_prefault_relocations() argument
1742 const unsigned int count = eb->buffer_count; in eb_prefault_relocations()
1748 err = check_relocations(&eb->exec[i]); in eb_prefault_relocations()
1756 static int eb_reinit_userptr(struct i915_execbuffer *eb) in eb_reinit_userptr() argument
1758 const unsigned int count = eb->buffer_count; in eb_reinit_userptr()
1762 if (likely(!(eb->args->flags & __EXEC_USERPTR_USED))) in eb_reinit_userptr()
1766 struct eb_vma *ev = &eb->vma[i]; in eb_reinit_userptr()
1781 static noinline int eb_relocate_parse_slow(struct i915_execbuffer *eb) in eb_relocate_parse_slow() argument
1794 eb_release_vmas(eb, false); in eb_relocate_parse_slow()
1795 i915_gem_ww_ctx_fini(&eb->ww); in eb_relocate_parse_slow()
1800 * 1 - we try to just prefault all the user relocation entries and in eb_relocate_parse_slow()
1811 err = eb_prefault_relocations(eb); in eb_relocate_parse_slow()
1813 err = eb_copy_relocations(eb); in eb_relocate_parse_slow()
1821 err = eb_reinit_userptr(eb); in eb_relocate_parse_slow()
1823 i915_gem_ww_ctx_init(&eb->ww, true); in eb_relocate_parse_slow()
1829 err = eb_pin_engine(eb, false); in eb_relocate_parse_slow()
1833 err = eb_validate_vmas(eb); in eb_relocate_parse_slow()
1837 GEM_BUG_ON(!eb->batches[0]); in eb_relocate_parse_slow()
1839 list_for_each_entry(ev, &eb->relocs, reloc_link) { in eb_relocate_parse_slow()
1841 err = eb_relocate_vma(eb, ev); in eb_relocate_parse_slow()
1845 err = eb_relocate_vma_slow(eb, ev); in eb_relocate_parse_slow()
1861 err = eb_parse(eb); in eb_relocate_parse_slow()
1874 eb_release_vmas(eb, false); in eb_relocate_parse_slow()
1875 err = i915_gem_ww_ctx_backoff(&eb->ww); in eb_relocate_parse_slow()
1885 const unsigned int count = eb->buffer_count; in eb_relocate_parse_slow()
1890 &eb->exec[i]; in eb_relocate_parse_slow()
1904 static int eb_relocate_parse(struct i915_execbuffer *eb) in eb_relocate_parse() argument
1910 err = eb_pin_engine(eb, throttle); in eb_relocate_parse()
1921 err = eb_validate_vmas(eb); in eb_relocate_parse()
1928 if (eb->args->flags & __EXEC_HAS_RELOC) { in eb_relocate_parse()
1931 list_for_each_entry(ev, &eb->relocs, reloc_link) { in eb_relocate_parse()
1932 err = eb_relocate_vma(eb, ev); in eb_relocate_parse()
1944 err = eb_parse(eb); in eb_relocate_parse()
1948 eb_release_vmas(eb, false); in eb_relocate_parse()
1949 err = i915_gem_ww_ctx_backoff(&eb->ww); in eb_relocate_parse()
1957 err = eb_relocate_parse_slow(eb); in eb_relocate_parse()
1966 eb->args->flags &= ~__EXEC_HAS_RELOC; in eb_relocate_parse()
1984 for ((_i) = (_eb)->num_batches - 1; (_i) >= 0; --(_i))
1987 eb_find_first_request_added(struct i915_execbuffer *eb) in eb_find_first_request_added() argument
1991 for_each_batch_add_order(eb, i) in eb_find_first_request_added()
1992 if (eb->requests[i]) in eb_find_first_request_added()
1993 return eb->requests[i]; in eb_find_first_request_added()
2003 static int eb_capture_stage(struct i915_execbuffer *eb) in eb_capture_stage() argument
2005 const unsigned int count = eb->buffer_count; in eb_capture_stage()
2009 struct eb_vma *ev = &eb->vma[i]; in eb_capture_stage()
2016 if (i915_gem_context_is_recoverable(eb->gem_context) && in eb_capture_stage()
2017 (IS_DGFX(eb->i915) || GRAPHICS_VER_FULL(eb->i915) > IP_VER(12, 0))) in eb_capture_stage()
2020 for_each_batch_create_order(eb, j) { in eb_capture_stage()
2027 capture->next = eb->capture_lists[j]; in eb_capture_stage()
2029 eb->capture_lists[j] = capture; in eb_capture_stage()
2037 static void eb_capture_commit(struct i915_execbuffer *eb) in eb_capture_commit() argument
2041 for_each_batch_create_order(eb, j) { in eb_capture_commit()
2042 struct i915_request *rq = eb->requests[j]; in eb_capture_commit()
2047 rq->capture_list = eb->capture_lists[j]; in eb_capture_commit()
2048 eb->capture_lists[j] = NULL; in eb_capture_commit()
2056 static void eb_capture_release(struct i915_execbuffer *eb) in eb_capture_release() argument
2060 for_each_batch_create_order(eb, j) { in eb_capture_release()
2061 if (eb->capture_lists[j]) { in eb_capture_release()
2062 i915_request_free_capture_list(eb->capture_lists[j]); in eb_capture_release()
2063 eb->capture_lists[j] = NULL; in eb_capture_release()
2068 static void eb_capture_list_clear(struct i915_execbuffer *eb) in eb_capture_list_clear() argument
2070 memset(eb->capture_lists, 0, sizeof(eb->capture_lists)); in eb_capture_list_clear()
2075 static int eb_capture_stage(struct i915_execbuffer *eb) in eb_capture_stage() argument
2080 static void eb_capture_commit(struct i915_execbuffer *eb) in eb_capture_commit() argument
2084 static void eb_capture_release(struct i915_execbuffer *eb) in eb_capture_release() argument
2088 static void eb_capture_list_clear(struct i915_execbuffer *eb) in eb_capture_list_clear() argument
2094 static int eb_move_to_gpu(struct i915_execbuffer *eb) in eb_move_to_gpu() argument
2096 const unsigned int count = eb->buffer_count; in eb_move_to_gpu()
2101 struct eb_vma *ev = &eb->vma[i]; in eb_move_to_gpu()
2125 * 1. Rip out the async flush code. in eb_move_to_gpu()
2139 (eb_find_first_request_added(eb), obj, in eb_move_to_gpu()
2143 for_each_batch_add_order(eb, j) { in eb_move_to_gpu()
2146 if (!eb->requests[j]) in eb_move_to_gpu()
2149 err = _i915_vma_move_to_active(vma, eb->requests[j], in eb_move_to_gpu()
2151 eb->composite_fence ? in eb_move_to_gpu()
2152 eb->composite_fence : in eb_move_to_gpu()
2153 &eb->requests[j]->fence, in eb_move_to_gpu()
2160 if (!err && (eb->args->flags & __EXEC_USERPTR_USED)) { in eb_move_to_gpu()
2162 struct eb_vma *ev = &eb->vma[i]; in eb_move_to_gpu()
2179 intel_gt_chipset_flush(eb->gt); in eb_move_to_gpu()
2180 eb_capture_commit(eb); in eb_move_to_gpu()
2185 for_each_batch_create_order(eb, j) { in eb_move_to_gpu()
2186 if (!eb->requests[j]) in eb_move_to_gpu()
2189 i915_request_set_error_once(eb->requests[j], err); in eb_move_to_gpu()
2246 shadow_batch_pin(struct i915_execbuffer *eb, in shadow_batch_pin() argument
2258 err = i915_vma_pin_ww(vma, &eb->ww, 0, 0, flags | PIN_VALIDATE); in shadow_batch_pin()
2265 static struct i915_vma *eb_dispatch_secure(struct i915_execbuffer *eb, struct i915_vma *vma) in eb_dispatch_secure() argument
2271 if (eb->batch_flags & I915_DISPATCH_SECURE) in eb_dispatch_secure()
2272 return i915_gem_object_ggtt_pin_ww(vma->obj, &eb->ww, NULL, 0, 0, PIN_VALIDATE); in eb_dispatch_secure()
2277 static int eb_parse(struct i915_execbuffer *eb) in eb_parse() argument
2279 struct drm_i915_private *i915 = eb->i915; in eb_parse()
2280 struct intel_gt_buffer_pool_node *pool = eb->batch_pool; in eb_parse()
2285 if (!eb_use_cmdparser(eb)) { in eb_parse()
2286 batch = eb_dispatch_secure(eb, eb->batches[0]->vma); in eb_parse()
2293 if (intel_context_is_parallel(eb->context)) in eb_parse()
2296 len = eb->batch_len[0]; in eb_parse()
2297 if (!CMDPARSER_USES_GGTT(eb->i915)) { in eb_parse()
2302 if (!eb->context->vm->has_read_only) { in eb_parse()
2310 if (unlikely(len < eb->batch_len[0])) /* last paranoid check of overflow */ in eb_parse()
2314 pool = intel_gt_get_buffer_pool(eb->gt, len, in eb_parse()
2318 eb->batch_pool = pool; in eb_parse()
2321 err = i915_gem_object_lock(pool->obj, &eb->ww); in eb_parse()
2325 shadow = shadow_batch_pin(eb, pool->obj, eb->context->vm, PIN_USER); in eb_parse()
2334 if (CMDPARSER_USES_GGTT(eb->i915)) { in eb_parse()
2337 shadow = shadow_batch_pin(eb, pool->obj, in eb_parse()
2338 &eb->gt->ggtt->vm, in eb_parse()
2345 eb->batch_flags |= I915_DISPATCH_SECURE; in eb_parse()
2348 batch = eb_dispatch_secure(eb, shadow); in eb_parse()
2352 err = dma_resv_reserve_fences(shadow->obj->base.resv, 1); in eb_parse()
2356 err = intel_engine_cmd_parser(eb->context->engine, in eb_parse()
2357 eb->batches[0]->vma, in eb_parse()
2358 eb->batch_start_offset, in eb_parse()
2359 eb->batch_len[0], in eb_parse()
2364 eb->batches[0] = &eb->vma[eb->buffer_count++]; in eb_parse()
2365 eb->batches[0]->vma = i915_vma_get(shadow); in eb_parse()
2366 eb->batches[0]->flags = __EXEC_OBJECT_HAS_PIN; in eb_parse()
2368 eb->trampoline = trampoline; in eb_parse()
2369 eb->batch_start_offset = 0; in eb_parse()
2373 if (intel_context_is_parallel(eb->context)) in eb_parse()
2376 eb->batches[0] = &eb->vma[eb->buffer_count++]; in eb_parse()
2377 eb->batches[0]->flags = __EXEC_OBJECT_HAS_PIN; in eb_parse()
2378 eb->batches[0]->vma = i915_vma_get(batch); in eb_parse()
2383 static int eb_request_submit(struct i915_execbuffer *eb, in eb_request_submit() argument
2393 if (eb->args->flags & I915_EXEC_GEN7_SOL_RESET) { in eb_request_submit()
2413 eb->batch_start_offset, in eb_request_submit()
2415 eb->batch_flags); in eb_request_submit()
2419 if (eb->trampoline) { in eb_request_submit()
2421 GEM_BUG_ON(eb->batch_start_offset); in eb_request_submit()
2423 i915_vma_offset(eb->trampoline) + in eb_request_submit()
2432 static int eb_submit(struct i915_execbuffer *eb) in eb_submit() argument
2437 err = eb_move_to_gpu(eb); in eb_submit()
2439 for_each_batch_create_order(eb, i) { in eb_submit()
2440 if (!eb->requests[i]) in eb_submit()
2443 trace_i915_request_queue(eb->requests[i], eb->batch_flags); in eb_submit()
2445 err = eb_request_submit(eb, eb->requests[i], in eb_submit()
2446 eb->batches[i]->vma, in eb_submit()
2447 eb->batch_len[i]); in eb_submit()
2479 static struct i915_request *eb_throttle(struct i915_execbuffer *eb, struct intel_context *ce) in eb_throttle() argument
2513 static int eb_pin_timeline(struct i915_execbuffer *eb, struct intel_context *ce, in eb_pin_timeline() argument
2533 rq = eb_throttle(eb, ce); in eb_pin_timeline()
2537 bool nonblock = eb->file->filp->f_flags & O_NONBLOCK; in eb_pin_timeline()
2564 static int eb_pin_engine(struct i915_execbuffer *eb, bool throttle) in eb_pin_engine() argument
2566 struct intel_context *ce = eb->context, *child; in eb_pin_engine()
2570 GEM_BUG_ON(eb->args->flags & __EXEC_ENGINE_PINNED); in eb_pin_engine()
2580 err = intel_context_pin_ww(ce, &eb->ww); in eb_pin_engine()
2584 err = intel_context_pin_ww(child, &eb->ww); in eb_pin_engine()
2589 err = eb_pin_timeline(eb, child, throttle); in eb_pin_engine()
2594 err = eb_pin_timeline(eb, ce, throttle); in eb_pin_engine()
2598 eb->args->flags |= __EXEC_ENGINE_PINNED; in eb_pin_engine()
2615 static void eb_unpin_engine(struct i915_execbuffer *eb) in eb_unpin_engine() argument
2617 struct intel_context *ce = eb->context, *child; in eb_unpin_engine()
2619 if (!(eb->args->flags & __EXEC_ENGINE_PINNED)) in eb_unpin_engine()
2622 eb->args->flags &= ~__EXEC_ENGINE_PINNED; in eb_unpin_engine()
2640 eb_select_legacy_ring(struct i915_execbuffer *eb) in eb_select_legacy_ring() argument
2642 struct drm_i915_private *i915 = eb->i915; in eb_select_legacy_ring()
2643 struct drm_i915_gem_execbuffer2 *args = eb->args; in eb_select_legacy_ring()
2651 return -1; in eb_select_legacy_ring()
2655 i915->engine_uabi_class_count[I915_ENGINE_CLASS_VIDEO] > 1) { in eb_select_legacy_ring()
2659 bsd_idx = gen8_dispatch_bsd_engine(i915, eb->file); in eb_select_legacy_ring()
2668 return -1; in eb_select_legacy_ring()
2677 return -1; in eb_select_legacy_ring()
2684 eb_select_engine(struct i915_execbuffer *eb) in eb_select_engine() argument
2691 if (i915_gem_context_user_engines(eb->gem_context)) in eb_select_engine()
2692 idx = eb->args->flags & I915_EXEC_RING_MASK; in eb_select_engine()
2694 idx = eb_select_legacy_ring(eb); in eb_select_engine()
2696 ce = i915_gem_context_get_engine(eb->gem_context, idx); in eb_select_engine()
2701 if (eb->buffer_count < ce->parallel.number_children + 1) { in eb_select_engine()
2705 if (eb->batch_start_offset || eb->args->batch_len) { in eb_select_engine()
2710 eb->num_batches = ce->parallel.number_children + 1; in eb_select_engine()
2715 eb->wakeref = intel_gt_pm_get(ce->engine->gt); in eb_select_engine()
2721 eb->wakeref_gt0 = intel_gt_pm_get(to_gt(gt->i915)); in eb_select_engine()
2749 eb->context = ce; in eb_select_engine()
2750 eb->gt = ce->engine->gt; in eb_select_engine()
2761 intel_gt_pm_put(to_gt(gt->i915), eb->wakeref_gt0); in eb_select_engine()
2763 intel_gt_pm_put(ce->engine->gt, eb->wakeref); in eb_select_engine()
2771 eb_put_engine(struct i915_execbuffer *eb) in eb_put_engine() argument
2775 i915_vm_put(eb->context->vm); in eb_put_engine()
2780 if (eb->gt->info.id) in eb_put_engine()
2781 intel_gt_pm_put(to_gt(eb->gt->i915), eb->wakeref_gt0); in eb_put_engine()
2782 intel_gt_pm_put(eb->context->engine->gt, eb->wakeref); in eb_put_engine()
2783 for_each_child(eb->context, child) in eb_put_engine()
2785 intel_context_put(eb->context); in eb_put_engine()
2800 add_timeline_fence_array(struct i915_execbuffer *eb, in add_timeline_fence_array() argument
2817 SIZE_MAX / sizeof(*f)) - eb->num_fences) in add_timeline_fence_array()
2828 f = krealloc(eb->fences, in add_timeline_fence_array()
2829 (eb->num_fences + nfences) * sizeof(*f), in add_timeline_fence_array()
2834 eb->fences = f; in add_timeline_fence_array()
2835 f += eb->num_fences; in add_timeline_fence_array()
2837 BUILD_BUG_ON(~(ARCH_KMALLOC_MINALIGN - 1) & in add_timeline_fence_array()
2857 syncobj = drm_syncobj_find(eb->file, user_fence.handle); in add_timeline_fence_array()
2859 drm_dbg(&eb->i915->drm, in add_timeline_fence_array()
2868 drm_dbg(&eb->i915->drm, in add_timeline_fence_array()
2878 drm_dbg(&eb->i915->drm, in add_timeline_fence_array()
2906 drm_dbg(&eb->i915->drm, in add_timeline_fence_array()
2927 eb->num_fences++; in add_timeline_fence_array()
2933 static int add_fence_array(struct i915_execbuffer *eb) in add_fence_array() argument
2935 struct drm_i915_gem_execbuffer2 *args = eb->args; in add_fence_array()
2950 SIZE_MAX / sizeof(*f) - eb->num_fences)) in add_fence_array()
2957 f = krealloc(eb->fences, in add_fence_array()
2958 (eb->num_fences + num_fences) * sizeof(*f), in add_fence_array()
2963 eb->fences = f; in add_fence_array()
2964 f += eb->num_fences; in add_fence_array()
2976 syncobj = drm_syncobj_find(eb->file, user_fence.handle); in add_fence_array()
2978 drm_dbg(&eb->i915->drm, in add_fence_array()
2986 drm_dbg(&eb->i915->drm, in add_fence_array()
2993 BUILD_BUG_ON(~(ARCH_KMALLOC_MINALIGN - 1) & in add_fence_array()
3001 eb->num_fences++; in add_fence_array()
3014 await_fence_array(struct i915_execbuffer *eb, in await_fence_array() argument
3020 for (n = 0; n < eb->num_fences; n++) { in await_fence_array()
3021 if (!eb->fences[n].dma_fence) in await_fence_array()
3024 err = i915_request_await_dma_fence(rq, eb->fences[n].dma_fence); in await_fence_array()
3032 static void signal_fence_array(const struct i915_execbuffer *eb, in signal_fence_array() argument
3037 for (n = 0; n < eb->num_fences; n++) { in signal_fence_array()
3041 syncobj = ptr_unpack_bits(eb->fences[n].syncobj, &flags, 2); in signal_fence_array()
3045 if (eb->fences[n].chain_fence) { in signal_fence_array()
3047 eb->fences[n].chain_fence, in signal_fence_array()
3049 eb->fences[n].value); in signal_fence_array()
3054 eb->fences[n].chain_fence = NULL; in signal_fence_array()
3064 struct i915_execbuffer *eb = data; in parse_timeline_fences() local
3070 return add_timeline_fence_array(eb, &timeline_fences); in parse_timeline_fences()
3082 static int eb_request_add(struct i915_execbuffer *eb, struct i915_request *rq, in eb_request_add() argument
3097 if (likely(!intel_context_is_closed(eb->context))) { in eb_request_add()
3098 attr = eb->gem_context->sched; in eb_request_add()
3106 if (intel_context_is_parallel(eb->context)) { in eb_request_add()
3128 static int eb_requests_add(struct i915_execbuffer *eb, int err) in eb_requests_add() argument
3136 for_each_batch_add_order(eb, i) { in eb_requests_add()
3137 struct i915_request *rq = eb->requests[i]; in eb_requests_add()
3141 err |= eb_request_add(eb, rq, err, i == 0); in eb_requests_add()
3153 struct i915_execbuffer *eb) in parse_execbuf2_extensions() argument
3161 if (eb->args->flags & I915_EXEC_FENCE_ARRAY) in parse_execbuf2_extensions()
3170 eb); in parse_execbuf2_extensions()
3173 static void eb_requests_get(struct i915_execbuffer *eb) in eb_requests_get() argument
3177 for_each_batch_create_order(eb, i) { in eb_requests_get()
3178 if (!eb->requests[i]) in eb_requests_get()
3181 i915_request_get(eb->requests[i]); in eb_requests_get()
3185 static void eb_requests_put(struct i915_execbuffer *eb) in eb_requests_put() argument
3189 for_each_batch_create_order(eb, i) { in eb_requests_put()
3190 if (!eb->requests[i]) in eb_requests_put()
3193 i915_request_put(eb->requests[i]); in eb_requests_put()
3198 eb_composite_fence_create(struct i915_execbuffer *eb, int out_fence_fd) in eb_composite_fence_create() argument
3205 GEM_BUG_ON(!intel_context_is_parent(eb->context)); in eb_composite_fence_create()
3207 fences = kmalloc_array(eb->num_batches, sizeof(*fences), GFP_KERNEL); in eb_composite_fence_create()
3211 for_each_batch_create_order(eb, i) { in eb_composite_fence_create()
3212 fences[i] = &eb->requests[i]->fence; in eb_composite_fence_create()
3214 &eb->requests[i]->fence.flags); in eb_composite_fence_create()
3217 fence_array = dma_fence_array_create(eb->num_batches, in eb_composite_fence_create()
3219 eb->context->parallel.fence_context, in eb_composite_fence_create()
3220 eb->context->parallel.seqno++, in eb_composite_fence_create()
3228 for_each_batch_create_order(eb, i) in eb_composite_fence_create()
3231 if (out_fence_fd != -1) { in eb_composite_fence_create()
3239 eb->composite_fence = &fence_array->base; in eb_composite_fence_create()
3245 eb_fences_add(struct i915_execbuffer *eb, struct i915_request *rq, in eb_fences_add() argument
3251 if (unlikely(eb->gem_context->syncobj)) { in eb_fences_add()
3254 fence = drm_syncobj_fence_get(eb->gem_context->syncobj); in eb_fences_add()
3262 if (eb->args->flags & I915_EXEC_FENCE_SUBMIT) in eb_fences_add()
3270 if (eb->fences) { in eb_fences_add()
3271 err = await_fence_array(eb, rq); in eb_fences_add()
3276 if (intel_context_is_parallel(eb->context)) { in eb_fences_add()
3277 out_fence = eb_composite_fence_create(eb, out_fence_fd); in eb_fences_add()
3280 } else if (out_fence_fd != -1) { in eb_fences_add()
3290 eb_find_context(struct i915_execbuffer *eb, unsigned int context_number) in eb_find_context() argument
3295 return eb->context; in eb_find_context()
3297 for_each_child(eb->context, child) in eb_find_context()
3307 eb_requests_create(struct i915_execbuffer *eb, struct dma_fence *in_fence, in eb_requests_create() argument
3313 for_each_batch_create_order(eb, i) { in eb_requests_create()
3315 eb->requests[i] = i915_request_create(eb_find_context(eb, i)); in eb_requests_create()
3316 if (IS_ERR(eb->requests[i])) { in eb_requests_create()
3317 out_fence = ERR_CAST(eb->requests[i]); in eb_requests_create()
3318 eb->requests[i] = NULL; in eb_requests_create()
3327 if (i + 1 == eb->num_batches) { in eb_requests_create()
3328 out_fence = eb_fences_add(eb, eb->requests[i], in eb_requests_create()
3339 if (eb->batches[i]->vma) in eb_requests_create()
3340 eb->requests[i]->batch_res = in eb_requests_create()
3341 i915_vma_resource_get(eb->batches[i]->vma->resource); in eb_requests_create()
3342 if (eb->batch_pool) { in eb_requests_create()
3343 GEM_BUG_ON(intel_context_is_parallel(eb->context)); in eb_requests_create()
3344 intel_gt_buffer_pool_mark_active(eb->batch_pool, in eb_requests_create()
3345 eb->requests[i]); in eb_requests_create()
3359 struct i915_execbuffer eb; in i915_gem_do_execbuffer() local
3362 int out_fence_fd = -1; in i915_gem_do_execbuffer()
3369 eb.i915 = i915; in i915_gem_do_execbuffer()
3370 eb.file = file; in i915_gem_do_execbuffer()
3371 eb.args = args; in i915_gem_do_execbuffer()
3375 eb.exec = exec; in i915_gem_do_execbuffer()
3376 eb.vma = (struct eb_vma *)(exec + args->buffer_count + 1); in i915_gem_do_execbuffer()
3377 eb.vma[0].vma = NULL; in i915_gem_do_execbuffer()
3378 eb.batch_pool = NULL; in i915_gem_do_execbuffer()
3380 eb.invalid_flags = __EXEC_OBJECT_UNKNOWN_FLAGS; in i915_gem_do_execbuffer()
3381 reloc_cache_init(&eb.reloc_cache, eb.i915); in i915_gem_do_execbuffer()
3383 eb.buffer_count = args->buffer_count; in i915_gem_do_execbuffer()
3384 eb.batch_start_offset = args->batch_start_offset; in i915_gem_do_execbuffer()
3385 eb.trampoline = NULL; in i915_gem_do_execbuffer()
3387 eb.fences = NULL; in i915_gem_do_execbuffer()
3388 eb.num_fences = 0; in i915_gem_do_execbuffer()
3390 eb_capture_list_clear(&eb); in i915_gem_do_execbuffer()
3392 memset(eb.requests, 0, sizeof(struct i915_request *) * in i915_gem_do_execbuffer()
3393 ARRAY_SIZE(eb.requests)); in i915_gem_do_execbuffer()
3394 eb.composite_fence = NULL; in i915_gem_do_execbuffer()
3396 eb.batch_flags = 0; in i915_gem_do_execbuffer()
3408 eb.batch_flags |= I915_DISPATCH_SECURE; in i915_gem_do_execbuffer()
3411 eb.batch_flags |= I915_DISPATCH_PINNED; in i915_gem_do_execbuffer()
3413 err = parse_execbuf2_extensions(args, &eb); in i915_gem_do_execbuffer()
3417 err = add_fence_array(&eb); in i915_gem_do_execbuffer()
3442 err = eb_create(&eb); in i915_gem_do_execbuffer()
3446 GEM_BUG_ON(!eb.lut_size); in i915_gem_do_execbuffer()
3448 err = eb_select_context(&eb); in i915_gem_do_execbuffer()
3452 err = eb_select_engine(&eb); in i915_gem_do_execbuffer()
3456 err = eb_lookup_vmas(&eb); in i915_gem_do_execbuffer()
3458 eb_release_vmas(&eb, true); in i915_gem_do_execbuffer()
3462 i915_gem_ww_ctx_init(&eb.ww, true); in i915_gem_do_execbuffer()
3464 err = eb_relocate_parse(&eb); in i915_gem_do_execbuffer()
3477 ww_acquire_done(&eb.ww.ctx); in i915_gem_do_execbuffer()
3478 err = eb_capture_stage(&eb); in i915_gem_do_execbuffer()
3482 out_fence = eb_requests_create(&eb, in_fence, out_fence_fd); in i915_gem_do_execbuffer()
3486 if (eb.requests[0]) in i915_gem_do_execbuffer()
3492 err = eb_submit(&eb); in i915_gem_do_execbuffer()
3495 eb_requests_get(&eb); in i915_gem_do_execbuffer()
3496 err = eb_requests_add(&eb, err); in i915_gem_do_execbuffer()
3498 if (eb.fences) in i915_gem_do_execbuffer()
3499 signal_fence_array(&eb, eb.composite_fence ? in i915_gem_do_execbuffer()
3500 eb.composite_fence : in i915_gem_do_execbuffer()
3501 &eb.requests[0]->fence); in i915_gem_do_execbuffer()
3503 if (unlikely(eb.gem_context->syncobj)) { in i915_gem_do_execbuffer()
3504 drm_syncobj_replace_fence(eb.gem_context->syncobj, in i915_gem_do_execbuffer()
3505 eb.composite_fence ? in i915_gem_do_execbuffer()
3506 eb.composite_fence : in i915_gem_do_execbuffer()
3507 &eb.requests[0]->fence); in i915_gem_do_execbuffer()
3515 out_fence_fd = -1; in i915_gem_do_execbuffer()
3521 if (!out_fence && eb.composite_fence) in i915_gem_do_execbuffer()
3522 dma_fence_put(eb.composite_fence); in i915_gem_do_execbuffer()
3524 eb_requests_put(&eb); in i915_gem_do_execbuffer()
3527 eb_release_vmas(&eb, true); in i915_gem_do_execbuffer()
3529 i915_gem_ww_ctx_fini(&eb.ww); in i915_gem_do_execbuffer()
3531 if (eb.batch_pool) in i915_gem_do_execbuffer()
3532 intel_gt_buffer_pool_put(eb.batch_pool); in i915_gem_do_execbuffer()
3534 eb_put_engine(&eb); in i915_gem_do_execbuffer()
3536 i915_gem_context_put(eb.gem_context); in i915_gem_do_execbuffer()
3538 eb_destroy(&eb); in i915_gem_do_execbuffer()
3540 if (out_fence_fd != -1) in i915_gem_do_execbuffer()
3545 put_fence_array(eb.fences, eb.num_fences); in i915_gem_do_execbuffer()
3564 return !(count < 1 || count > INT_MAX || count > SIZE_MAX / sz - 1); in check_buffer_count()