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