• Home
  • Raw
  • Download

Lines Matching refs:ctx

35 int cxl_context_init(struct cxl_context *ctx, struct cxl_afu *afu, bool master)  in cxl_context_init()  argument
39 ctx->afu = afu; in cxl_context_init()
40 ctx->master = master; in cxl_context_init()
41 ctx->pid = NULL; /* Set in start work ioctl */ in cxl_context_init()
42 mutex_init(&ctx->mapping_lock); in cxl_context_init()
43 ctx->mapping = NULL; in cxl_context_init()
44 ctx->tidr = 0; in cxl_context_init()
45 ctx->assign_tidr = false; in cxl_context_init()
48 spin_lock_init(&ctx->sste_lock); in cxl_context_init()
57 i = cxl_alloc_sst(ctx); in cxl_context_init()
62 INIT_WORK(&ctx->fault_work, cxl_handle_fault); in cxl_context_init()
64 init_waitqueue_head(&ctx->wq); in cxl_context_init()
65 spin_lock_init(&ctx->lock); in cxl_context_init()
67 ctx->irq_bitmap = NULL; in cxl_context_init()
68 ctx->pending_irq = false; in cxl_context_init()
69 ctx->pending_fault = false; in cxl_context_init()
70 ctx->pending_afu_err = false; in cxl_context_init()
72 INIT_LIST_HEAD(&ctx->irq_names); in cxl_context_init()
82 ctx->irqs.range[i] = 0; in cxl_context_init()
84 mutex_init(&ctx->status_mutex); in cxl_context_init()
86 ctx->status = OPENED; in cxl_context_init()
94 i = idr_alloc(&ctx->afu->contexts_idr, ctx, 0, in cxl_context_init()
95 ctx->afu->num_procs, GFP_NOWAIT); in cxl_context_init()
101 ctx->pe = i; in cxl_context_init()
103 ctx->elem = &ctx->afu->native->spa[i]; in cxl_context_init()
104 ctx->external_pe = ctx->pe; in cxl_context_init()
106 ctx->external_pe = -1; /* assigned when attaching */ in cxl_context_init()
108 ctx->pe_inserted = false; in cxl_context_init()
118 void cxl_context_set_mapping(struct cxl_context *ctx, in cxl_context_set_mapping() argument
121 mutex_lock(&ctx->mapping_lock); in cxl_context_set_mapping()
122 ctx->mapping = mapping; in cxl_context_set_mapping()
123 mutex_unlock(&ctx->mapping_lock); in cxl_context_set_mapping()
129 struct cxl_context *ctx = vma->vm_file->private_data; in cxl_mmap_fault() local
136 __func__, ctx->pe, vmf->address, offset); in cxl_mmap_fault()
138 if (ctx->afu->current_mode == CXL_MODE_DEDICATED) { in cxl_mmap_fault()
139 area = ctx->afu->psn_phys; in cxl_mmap_fault()
140 if (offset >= ctx->afu->adapter->ps_size) in cxl_mmap_fault()
143 area = ctx->psn_phys; in cxl_mmap_fault()
144 if (offset >= ctx->psn_size) in cxl_mmap_fault()
148 mutex_lock(&ctx->status_mutex); in cxl_mmap_fault()
150 if (ctx->status != STARTED) { in cxl_mmap_fault()
151 mutex_unlock(&ctx->status_mutex); in cxl_mmap_fault()
153 if (ctx->mmio_err_ff) { in cxl_mmap_fault()
154 if (!ctx->ff_page) { in cxl_mmap_fault()
155 ctx->ff_page = alloc_page(GFP_USER); in cxl_mmap_fault()
156 if (!ctx->ff_page) in cxl_mmap_fault()
158 memset(page_address(ctx->ff_page), 0xff, PAGE_SIZE); in cxl_mmap_fault()
160 get_page(ctx->ff_page); in cxl_mmap_fault()
161 vmf->page = ctx->ff_page; in cxl_mmap_fault()
170 mutex_unlock(&ctx->status_mutex); in cxl_mmap_fault()
182 int cxl_context_iomap(struct cxl_context *ctx, struct vm_area_struct *vma) in cxl_context_iomap() argument
187 if (ctx->afu->current_mode == CXL_MODE_DEDICATED) { in cxl_context_iomap()
188 if (start + len > ctx->afu->adapter->ps_size) in cxl_context_iomap()
196 if (ctx->master && !ctx->afu->psa) { in cxl_context_iomap()
202 if (!ctx->afu->enabled) in cxl_context_iomap()
206 if (start + len > ctx->psn_size) in cxl_context_iomap()
210 if ((ctx->master && !ctx->afu->psa) || (!ctx->afu->pp_psa)) { in cxl_context_iomap()
216 if (!ctx->afu->enabled) in cxl_context_iomap()
221 ctx->psn_phys, ctx->pe , ctx->master); in cxl_context_iomap()
234 int __detach_context(struct cxl_context *ctx) in __detach_context() argument
238 mutex_lock(&ctx->status_mutex); in __detach_context()
239 status = ctx->status; in __detach_context()
240 ctx->status = CLOSED; in __detach_context()
241 mutex_unlock(&ctx->status_mutex); in __detach_context()
248 WARN_ON(cxl_ops->detach_process(ctx) && in __detach_context()
249 cxl_ops->link_ok(ctx->afu->adapter, ctx->afu)); in __detach_context()
250 flush_work(&ctx->fault_work); /* Only needed for dedicated process */ in __detach_context()
257 cxl_ops->irq_wait(ctx); in __detach_context()
260 put_pid(ctx->pid); in __detach_context()
265 cxl_adapter_context_put(ctx->afu->adapter); in __detach_context()
268 cxl_context_mm_count_put(ctx); in __detach_context()
269 if (ctx->mm) in __detach_context()
270 mm_context_remove_copro(ctx->mm); in __detach_context()
271 ctx->mm = NULL; in __detach_context()
282 void cxl_context_detach(struct cxl_context *ctx) in cxl_context_detach() argument
286 rc = __detach_context(ctx); in cxl_context_detach()
290 afu_release_irqs(ctx, ctx); in cxl_context_detach()
291 wake_up_all(&ctx->wq); in cxl_context_detach()
299 struct cxl_context *ctx; in cxl_context_detach_all() local
303 idr_for_each_entry(&afu->contexts_idr, ctx, tmp) { in cxl_context_detach_all()
308 cxl_context_detach(ctx); in cxl_context_detach_all()
316 mutex_lock(&ctx->mapping_lock); in cxl_context_detach_all()
317 if (ctx->mapping) in cxl_context_detach_all()
318 unmap_mapping_range(ctx->mapping, 0, 0, 1); in cxl_context_detach_all()
319 mutex_unlock(&ctx->mapping_lock); in cxl_context_detach_all()
326 struct cxl_context *ctx = container_of(rcu, struct cxl_context, rcu); in reclaim_ctx() local
329 free_page((u64)ctx->sstp); in reclaim_ctx()
330 if (ctx->ff_page) in reclaim_ctx()
331 __free_page(ctx->ff_page); in reclaim_ctx()
332 ctx->sstp = NULL; in reclaim_ctx()
334 bitmap_free(ctx->irq_bitmap); in reclaim_ctx()
337 cxl_afu_put(ctx->afu); in reclaim_ctx()
339 kfree(ctx); in reclaim_ctx()
342 void cxl_context_free(struct cxl_context *ctx) in cxl_context_free() argument
344 if (ctx->kernelapi && ctx->mapping) in cxl_context_free()
345 cxl_release_mapping(ctx); in cxl_context_free()
346 mutex_lock(&ctx->afu->contexts_lock); in cxl_context_free()
347 idr_remove(&ctx->afu->contexts_idr, ctx->pe); in cxl_context_free()
348 mutex_unlock(&ctx->afu->contexts_lock); in cxl_context_free()
349 call_rcu(&ctx->rcu, reclaim_ctx); in cxl_context_free()
352 void cxl_context_mm_count_get(struct cxl_context *ctx) in cxl_context_mm_count_get() argument
354 if (ctx->mm) in cxl_context_mm_count_get()
355 mmgrab(ctx->mm); in cxl_context_mm_count_get()
358 void cxl_context_mm_count_put(struct cxl_context *ctx) in cxl_context_mm_count_put() argument
360 if (ctx->mm) in cxl_context_mm_count_put()
361 mmdrop(ctx->mm); in cxl_context_mm_count_put()