Lines Matching refs:ctx
11 struct ocxl_context *ctx;
13 ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
14 if (!ctx)
17 ctx->afu = afu;
19 pasid = idr_alloc(&afu->contexts_idr, ctx, afu->pasid_base,
23 kfree(ctx);
29 ctx->pasid = pasid;
30 ctx->status = OPENED;
31 mutex_init(&ctx->status_mutex);
32 ctx->mapping = mapping;
33 mutex_init(&ctx->mapping_lock);
34 init_waitqueue_head(&ctx->events_wq);
35 mutex_init(&ctx->xsl_error_lock);
36 mutex_init(&ctx->irq_lock);
37 idr_init(&ctx->irq_idr);
38 ctx->tidr = 0;
45 *context = ctx;
58 struct ocxl_context *ctx = (struct ocxl_context *) data;
60 mutex_lock(&ctx->xsl_error_lock);
61 ctx->xsl_error.addr = addr;
62 ctx->xsl_error.dsisr = dsisr;
63 ctx->xsl_error.count++;
64 mutex_unlock(&ctx->xsl_error_lock);
66 wake_up_all(&ctx->events_wq);
69 int ocxl_context_attach(struct ocxl_context *ctx, u64 amr, struct mm_struct *mm)
75 mutex_lock(&ctx->status_mutex);
76 if (ctx->status != OPENED) {
84 rc = ocxl_link_add_pe(ctx->afu->fn->link, ctx->pasid, pidr, ctx->tidr,
85 amr, mm, xsl_fault_error, ctx);
89 ctx->status = ATTACHED;
91 mutex_unlock(&ctx->status_mutex);
97 u64 offset, struct ocxl_context *ctx)
100 int irq_id = ocxl_irq_offset_to_id(ctx, offset);
102 trigger_addr = ocxl_afu_irq_get_addr(ctx, irq_id);
110 u64 offset, struct ocxl_context *ctx)
116 if (offset >= ctx->afu->config.pp_mmio_stride)
119 mutex_lock(&ctx->status_mutex);
120 if (ctx->status != ATTACHED) {
121 mutex_unlock(&ctx->status_mutex);
127 pasid_off = ctx->pasid - ctx->afu->pasid_base;
128 pp_mmio_addr = ctx->afu->pp_mmio_start +
129 pasid_off * ctx->afu->config.pp_mmio_stride +
133 mutex_unlock(&ctx->status_mutex);
140 struct ocxl_context *ctx = vma->vm_file->private_data;
146 ctx->pasid, vmf->address, offset);
148 if (offset < ctx->afu->irq_base_offset)
149 ret = map_pp_mmio(vma, vmf->address, offset, ctx);
151 ret = map_afu_irq(vma, vmf->address, offset, ctx);
159 static int check_mmap_afu_irq(struct ocxl_context *ctx,
162 int irq_id = ocxl_irq_offset_to_id(ctx, vma->vm_pgoff << PAGE_SHIFT);
169 if (!ocxl_afu_irq_get_addr(ctx, irq_id))
185 static int check_mmap_mmio(struct ocxl_context *ctx,
189 (ctx->afu->config.pp_mmio_stride >> PAGE_SHIFT))
194 int ocxl_context_mmap(struct ocxl_context *ctx, struct vm_area_struct *vma)
198 if ((vma->vm_pgoff << PAGE_SHIFT) < ctx->afu->irq_base_offset)
199 rc = check_mmap_mmio(ctx, vma);
201 rc = check_mmap_afu_irq(ctx, vma);
211 int ocxl_context_detach(struct ocxl_context *ctx)
218 mutex_lock(&ctx->status_mutex);
219 status = ctx->status;
220 ctx->status = CLOSED;
221 mutex_unlock(&ctx->status_mutex);
225 dev = to_pci_dev(ctx->afu->fn->dev.parent);
226 afu_control_pos = ctx->afu->config.dvsec_afu_control_pos;
228 mutex_lock(&ctx->afu->afu_control_lock);
229 rc = ocxl_config_terminate_pasid(dev, afu_control_pos, ctx->pasid);
230 mutex_unlock(&ctx->afu->afu_control_lock);
231 trace_ocxl_terminate_pasid(ctx->pasid, rc);
249 rc = ocxl_link_remove_pe(ctx->afu->fn->link, ctx->pasid);
260 struct ocxl_context *ctx;
264 idr_for_each_entry(&afu->contexts_idr, ctx, tmp) {
265 ocxl_context_detach(ctx);
273 mutex_lock(&ctx->mapping_lock);
274 if (ctx->mapping)
275 unmap_mapping_range(ctx->mapping, 0, 0, 1);
276 mutex_unlock(&ctx->mapping_lock);
281 void ocxl_context_free(struct ocxl_context *ctx)
283 mutex_lock(&ctx->afu->contexts_lock);
284 ctx->afu->pasid_count--;
285 idr_remove(&ctx->afu->contexts_idr, ctx->pasid);
286 mutex_unlock(&ctx->afu->contexts_lock);
288 ocxl_afu_irq_free_all(ctx);
289 idr_destroy(&ctx->irq_idr);
291 ocxl_afu_put(ctx->afu);
292 kfree(ctx);