Lines Matching refs:ctx
15 struct hl_encaps_signals_mgr *mgr = &handle->ctx->sig_mgr; in encaps_handle_do_release()
25 hl_ctx_put(handle->ctx); in encaps_handle_do_release()
81 static void hl_ctx_fini(struct hl_ctx *ctx) in hl_ctx_fini() argument
83 struct hl_device *hdev = ctx->hdev; in hl_ctx_fini()
89 hl_hw_block_mem_fini(ctx); in hl_ctx_fini()
100 hl_fence_put(ctx->cs_pending[i]); in hl_ctx_fini()
102 kfree(ctx->cs_pending); in hl_ctx_fini()
104 if (ctx->asid != HL_KERNEL_ASID_ID) { in hl_ctx_fini()
105 dev_dbg(hdev->dev, "closing user context %d\n", ctx->asid); in hl_ctx_fini()
112 hl_device_set_debug_mode(hdev, ctx, false); in hl_ctx_fini()
114 hdev->asic_funcs->ctx_fini(ctx); in hl_ctx_fini()
116 hl_dec_ctx_fini(ctx); in hl_ctx_fini()
118 hl_cb_va_pool_fini(ctx); in hl_ctx_fini()
119 hl_vm_ctx_fini(ctx); in hl_ctx_fini()
120 hl_asid_free(hdev, ctx->asid); in hl_ctx_fini()
121 hl_encaps_sig_mgr_fini(hdev, &ctx->sig_mgr); in hl_ctx_fini()
124 hdev->asic_funcs->ctx_fini(ctx); in hl_ctx_fini()
125 hl_vm_ctx_fini(ctx); in hl_ctx_fini()
126 hl_mmu_ctx_fini(ctx); in hl_ctx_fini()
132 struct hl_ctx *ctx; in hl_ctx_do_release() local
134 ctx = container_of(ref, struct hl_ctx, refcount); in hl_ctx_do_release()
136 hl_ctx_fini(ctx); in hl_ctx_do_release()
138 if (ctx->hpriv) { in hl_ctx_do_release()
139 struct hl_fpriv *hpriv = ctx->hpriv; in hl_ctx_do_release()
142 hpriv->ctx = NULL; in hl_ctx_do_release()
148 kfree(ctx); in hl_ctx_do_release()
154 struct hl_ctx *ctx; in hl_ctx_create() local
157 ctx = kzalloc(sizeof(*ctx), GFP_KERNEL); in hl_ctx_create()
158 if (!ctx) { in hl_ctx_create()
164 rc = idr_alloc(&ctx_mgr->handles, ctx, 1, 0, GFP_KERNEL); in hl_ctx_create()
172 ctx->handle = rc; in hl_ctx_create()
174 rc = hl_ctx_init(hdev, ctx, false); in hl_ctx_create()
179 ctx->hpriv = hpriv; in hl_ctx_create()
182 hpriv->ctx = ctx; in hl_ctx_create()
191 idr_remove(&ctx_mgr->handles, ctx->handle); in hl_ctx_create()
194 kfree(ctx); in hl_ctx_create()
199 int hl_ctx_init(struct hl_device *hdev, struct hl_ctx *ctx, bool is_kernel_ctx) in hl_ctx_init() argument
203 ctx->hdev = hdev; in hl_ctx_init()
205 kref_init(&ctx->refcount); in hl_ctx_init()
207 ctx->cs_sequence = 1; in hl_ctx_init()
208 spin_lock_init(&ctx->cs_lock); in hl_ctx_init()
209 atomic_set(&ctx->thread_ctx_switch_token, 1); in hl_ctx_init()
210 ctx->thread_ctx_switch_wait_token = 0; in hl_ctx_init()
211 ctx->cs_pending = kcalloc(hdev->asic_prop.max_pending_cs, in hl_ctx_init()
214 if (!ctx->cs_pending) in hl_ctx_init()
217 INIT_LIST_HEAD(&ctx->outcome_store.used_list); in hl_ctx_init()
218 INIT_LIST_HEAD(&ctx->outcome_store.free_list); in hl_ctx_init()
219 hash_init(ctx->outcome_store.outcome_map); in hl_ctx_init()
220 for (i = 0; i < ARRAY_SIZE(ctx->outcome_store.nodes_pool); ++i) in hl_ctx_init()
221 list_add(&ctx->outcome_store.nodes_pool[i].list_link, in hl_ctx_init()
222 &ctx->outcome_store.free_list); in hl_ctx_init()
224 hl_hw_block_mem_init(ctx); in hl_ctx_init()
227 ctx->asid = HL_KERNEL_ASID_ID; /* Kernel driver gets ASID 0 */ in hl_ctx_init()
228 rc = hl_vm_ctx_init(ctx); in hl_ctx_init()
235 rc = hdev->asic_funcs->ctx_init(ctx); in hl_ctx_init()
241 ctx->asid = hl_asid_alloc(hdev); in hl_ctx_init()
242 if (!ctx->asid) { in hl_ctx_init()
248 rc = hl_vm_ctx_init(ctx); in hl_ctx_init()
255 rc = hl_cb_va_pool_init(ctx); in hl_ctx_init()
262 rc = hdev->asic_funcs->ctx_init(ctx); in hl_ctx_init()
268 hl_encaps_sig_mgr_init(&ctx->sig_mgr); in hl_ctx_init()
270 dev_dbg(hdev->dev, "create user context %d\n", ctx->asid); in hl_ctx_init()
276 hl_cb_va_pool_fini(ctx); in hl_ctx_init()
278 hl_vm_ctx_fini(ctx); in hl_ctx_init()
280 if (ctx->asid != HL_KERNEL_ASID_ID) in hl_ctx_init()
281 hl_asid_free(hdev, ctx->asid); in hl_ctx_init()
283 hl_hw_block_mem_fini(ctx); in hl_ctx_init()
284 kfree(ctx->cs_pending); in hl_ctx_init()
289 static int hl_ctx_get_unless_zero(struct hl_ctx *ctx) in hl_ctx_get_unless_zero() argument
291 return kref_get_unless_zero(&ctx->refcount); in hl_ctx_get_unless_zero()
294 void hl_ctx_get(struct hl_ctx *ctx) in hl_ctx_get() argument
296 kref_get(&ctx->refcount); in hl_ctx_get()
299 int hl_ctx_put(struct hl_ctx *ctx) in hl_ctx_put() argument
301 return kref_put(&ctx->refcount, hl_ctx_do_release); in hl_ctx_put()
306 struct hl_ctx *ctx = NULL; in hl_get_compute_ctx() local
313 ctx = hpriv->ctx; in hl_get_compute_ctx()
314 if (ctx && !hl_ctx_get_unless_zero(ctx)) in hl_get_compute_ctx()
315 ctx = NULL; in hl_get_compute_ctx()
326 return ctx; in hl_get_compute_ctx()
340 static struct hl_fence *hl_ctx_get_fence_locked(struct hl_ctx *ctx, u64 seq) in hl_ctx_get_fence_locked() argument
342 struct asic_fixed_properties *asic_prop = &ctx->hdev->asic_prop; in hl_ctx_get_fence_locked()
345 if (seq >= ctx->cs_sequence) in hl_ctx_get_fence_locked()
348 if (seq + asic_prop->max_pending_cs < ctx->cs_sequence) in hl_ctx_get_fence_locked()
351 fence = ctx->cs_pending[seq & (asic_prop->max_pending_cs - 1)]; in hl_ctx_get_fence_locked()
356 struct hl_fence *hl_ctx_get_fence(struct hl_ctx *ctx, u64 seq) in hl_ctx_get_fence() argument
360 spin_lock(&ctx->cs_lock); in hl_ctx_get_fence()
362 fence = hl_ctx_get_fence_locked(ctx, seq); in hl_ctx_get_fence()
364 spin_unlock(&ctx->cs_lock); in hl_ctx_get_fence()
379 int hl_ctx_get_fences(struct hl_ctx *ctx, u64 *seq_arr, in hl_ctx_get_fences() argument
385 spin_lock(&ctx->cs_lock); in hl_ctx_get_fences()
390 *fence = hl_ctx_get_fence_locked(ctx, seq); in hl_ctx_get_fences()
393 dev_err(ctx->hdev->dev, in hl_ctx_get_fences()
401 spin_unlock(&ctx->cs_lock); in hl_ctx_get_fences()
434 struct hl_ctx *ctx; in hl_ctx_mgr_fini() local
440 idr_for_each_entry(idp, ctx, id) in hl_ctx_mgr_fini()
441 kref_put(&ctx->refcount, hl_ctx_do_release); in hl_ctx_mgr_fini()