• Home
  • Raw
  • Download

Lines Matching refs:ctx

12 static void hl_ctx_fini(struct hl_ctx *ctx)  in hl_ctx_fini()  argument
14 struct hl_device *hdev = ctx->hdev; in hl_ctx_fini()
26 dma_fence_put(ctx->cs_pending[i]); in hl_ctx_fini()
28 if (ctx->asid != HL_KERNEL_ASID_ID) { in hl_ctx_fini()
35 if ((hdev->in_debug) && (hdev->compute_ctx == ctx)) in hl_ctx_fini()
38 hl_vm_ctx_fini(ctx); in hl_ctx_fini()
39 hl_asid_free(hdev, ctx->asid); in hl_ctx_fini()
41 hl_mmu_ctx_fini(ctx); in hl_ctx_fini()
47 struct hl_ctx *ctx; in hl_ctx_do_release() local
49 ctx = container_of(ref, struct hl_ctx, refcount); in hl_ctx_do_release()
51 hl_ctx_fini(ctx); in hl_ctx_do_release()
53 if (ctx->hpriv) in hl_ctx_do_release()
54 hl_hpriv_put(ctx->hpriv); in hl_ctx_do_release()
56 kfree(ctx); in hl_ctx_do_release()
62 struct hl_ctx *ctx; in hl_ctx_create() local
65 ctx = kzalloc(sizeof(*ctx), GFP_KERNEL); in hl_ctx_create()
66 if (!ctx) { in hl_ctx_create()
72 rc = idr_alloc(&mgr->ctx_handles, ctx, 1, 0, GFP_KERNEL); in hl_ctx_create()
80 ctx->handle = rc; in hl_ctx_create()
82 rc = hl_ctx_init(hdev, ctx, false); in hl_ctx_create()
87 ctx->hpriv = hpriv; in hl_ctx_create()
90 hpriv->ctx = ctx; in hl_ctx_create()
93 hdev->compute_ctx = ctx; in hl_ctx_create()
99 idr_remove(&mgr->ctx_handles, ctx->handle); in hl_ctx_create()
102 kfree(ctx); in hl_ctx_create()
107 void hl_ctx_free(struct hl_device *hdev, struct hl_ctx *ctx) in hl_ctx_free() argument
109 if (kref_put(&ctx->refcount, hl_ctx_do_release) == 1) in hl_ctx_free()
114 ctx->asid); in hl_ctx_free()
117 int hl_ctx_init(struct hl_device *hdev, struct hl_ctx *ctx, bool is_kernel_ctx) in hl_ctx_init() argument
121 ctx->hdev = hdev; in hl_ctx_init()
123 kref_init(&ctx->refcount); in hl_ctx_init()
125 ctx->cs_sequence = 1; in hl_ctx_init()
126 spin_lock_init(&ctx->cs_lock); in hl_ctx_init()
127 atomic_set(&ctx->thread_ctx_switch_token, 1); in hl_ctx_init()
128 ctx->thread_ctx_switch_wait_token = 0; in hl_ctx_init()
131 ctx->asid = HL_KERNEL_ASID_ID; /* Kernel driver gets ASID 0 */ in hl_ctx_init()
132 rc = hl_mmu_ctx_init(ctx); in hl_ctx_init()
138 ctx->asid = hl_asid_alloc(hdev); in hl_ctx_init()
139 if (!ctx->asid) { in hl_ctx_init()
144 rc = hl_vm_ctx_init(ctx); in hl_ctx_init()
155 if (ctx->asid != HL_KERNEL_ASID_ID) in hl_ctx_init()
156 hl_asid_free(hdev, ctx->asid); in hl_ctx_init()
161 void hl_ctx_get(struct hl_device *hdev, struct hl_ctx *ctx) in hl_ctx_get() argument
163 kref_get(&ctx->refcount); in hl_ctx_get()
166 int hl_ctx_put(struct hl_ctx *ctx) in hl_ctx_put() argument
168 return kref_put(&ctx->refcount, hl_ctx_do_release); in hl_ctx_put()
171 struct dma_fence *hl_ctx_get_fence(struct hl_ctx *ctx, u64 seq) in hl_ctx_get_fence() argument
173 struct hl_device *hdev = ctx->hdev; in hl_ctx_get_fence()
176 spin_lock(&ctx->cs_lock); in hl_ctx_get_fence()
178 if (seq >= ctx->cs_sequence) { in hl_ctx_get_fence()
181 seq, ctx->cs_sequence); in hl_ctx_get_fence()
182 spin_unlock(&ctx->cs_lock); in hl_ctx_get_fence()
187 if (seq + HL_MAX_PENDING_CS < ctx->cs_sequence) { in hl_ctx_get_fence()
190 seq, ctx->cs_sequence); in hl_ctx_get_fence()
191 spin_unlock(&ctx->cs_lock); in hl_ctx_get_fence()
196 ctx->cs_pending[seq & (HL_MAX_PENDING_CS - 1)]); in hl_ctx_get_fence()
197 spin_unlock(&ctx->cs_lock); in hl_ctx_get_fence()
227 struct hl_ctx *ctx; in hl_ctx_mgr_fini() local
233 idr_for_each_entry(idp, ctx, id) in hl_ctx_mgr_fini()
234 hl_ctx_free(hdev, ctx); in hl_ctx_mgr_fini()