• Home
  • Raw
  • Download

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
76 mutex_lock(&ctx->status_mutex); in ocxl_context_attach()
77 if (ctx->status != OPENED) { in ocxl_context_attach()
85 dev = to_pci_dev(ctx->afu->fn->dev.parent); in ocxl_context_attach()
86 rc = ocxl_link_add_pe(ctx->afu->fn->link, ctx->pasid, pidr, ctx->tidr, in ocxl_context_attach()
87 amr, pci_dev_id(dev), mm, xsl_fault_error, ctx); in ocxl_context_attach()
91 ctx->status = ATTACHED; in ocxl_context_attach()
93 mutex_unlock(&ctx->status_mutex); in ocxl_context_attach()
99 u64 offset, struct ocxl_context *ctx) in map_afu_irq() argument
102 int irq_id = ocxl_irq_offset_to_id(ctx, offset); in map_afu_irq()
104 trigger_addr = ocxl_afu_irq_get_addr(ctx, irq_id); in map_afu_irq()
112 u64 offset, struct ocxl_context *ctx) in map_pp_mmio() argument
118 if (offset >= ctx->afu->config.pp_mmio_stride) in map_pp_mmio()
121 mutex_lock(&ctx->status_mutex); in map_pp_mmio()
122 if (ctx->status != ATTACHED) { in map_pp_mmio()
123 mutex_unlock(&ctx->status_mutex); in map_pp_mmio()
129 pasid_off = ctx->pasid - ctx->afu->pasid_base; in map_pp_mmio()
130 pp_mmio_addr = ctx->afu->pp_mmio_start + in map_pp_mmio()
131 pasid_off * ctx->afu->config.pp_mmio_stride + in map_pp_mmio()
135 mutex_unlock(&ctx->status_mutex); in map_pp_mmio()
142 struct ocxl_context *ctx = vma->vm_file->private_data; in ocxl_mmap_fault() local
148 ctx->pasid, vmf->address, offset); in ocxl_mmap_fault()
150 if (offset < ctx->afu->irq_base_offset) in ocxl_mmap_fault()
151 ret = map_pp_mmio(vma, vmf->address, offset, ctx); in ocxl_mmap_fault()
153 ret = map_afu_irq(vma, vmf->address, offset, ctx); in ocxl_mmap_fault()
161 static int check_mmap_afu_irq(struct ocxl_context *ctx, in check_mmap_afu_irq() argument
164 int irq_id = ocxl_irq_offset_to_id(ctx, vma->vm_pgoff << PAGE_SHIFT); in check_mmap_afu_irq()
171 if (!ocxl_afu_irq_get_addr(ctx, irq_id)) in check_mmap_afu_irq()
187 static int check_mmap_mmio(struct ocxl_context *ctx, in check_mmap_mmio() argument
191 (ctx->afu->config.pp_mmio_stride >> PAGE_SHIFT)) in check_mmap_mmio()
196 int ocxl_context_mmap(struct ocxl_context *ctx, struct vm_area_struct *vma) in ocxl_context_mmap() argument
200 if ((vma->vm_pgoff << PAGE_SHIFT) < ctx->afu->irq_base_offset) in ocxl_context_mmap()
201 rc = check_mmap_mmio(ctx, vma); in ocxl_context_mmap()
203 rc = check_mmap_afu_irq(ctx, vma); in ocxl_context_mmap()
213 int ocxl_context_detach(struct ocxl_context *ctx) in ocxl_context_detach() argument
220 mutex_lock(&ctx->status_mutex); in ocxl_context_detach()
221 status = ctx->status; in ocxl_context_detach()
222 ctx->status = CLOSED; in ocxl_context_detach()
223 mutex_unlock(&ctx->status_mutex); in ocxl_context_detach()
227 dev = to_pci_dev(ctx->afu->fn->dev.parent); in ocxl_context_detach()
228 afu_control_pos = ctx->afu->config.dvsec_afu_control_pos; in ocxl_context_detach()
230 mutex_lock(&ctx->afu->afu_control_lock); in ocxl_context_detach()
231 rc = ocxl_config_terminate_pasid(dev, afu_control_pos, ctx->pasid); in ocxl_context_detach()
232 mutex_unlock(&ctx->afu->afu_control_lock); in ocxl_context_detach()
233 trace_ocxl_terminate_pasid(ctx->pasid, rc); in ocxl_context_detach()
251 rc = ocxl_link_remove_pe(ctx->afu->fn->link, ctx->pasid); in ocxl_context_detach()
262 struct ocxl_context *ctx; in ocxl_context_detach_all() local
266 idr_for_each_entry(&afu->contexts_idr, ctx, tmp) { in ocxl_context_detach_all()
267 ocxl_context_detach(ctx); in ocxl_context_detach_all()
275 mutex_lock(&ctx->mapping_lock); in ocxl_context_detach_all()
276 if (ctx->mapping) in ocxl_context_detach_all()
277 unmap_mapping_range(ctx->mapping, 0, 0, 1); in ocxl_context_detach_all()
278 mutex_unlock(&ctx->mapping_lock); in ocxl_context_detach_all()
283 void ocxl_context_free(struct ocxl_context *ctx) in ocxl_context_free() argument
285 mutex_lock(&ctx->afu->contexts_lock); in ocxl_context_free()
286 ctx->afu->pasid_count--; in ocxl_context_free()
287 idr_remove(&ctx->afu->contexts_idr, ctx->pasid); in ocxl_context_free()
288 mutex_unlock(&ctx->afu->contexts_lock); in ocxl_context_free()
290 ocxl_afu_irq_free_all(ctx); in ocxl_context_free()
291 idr_destroy(&ctx->irq_idr); in ocxl_context_free()
293 ocxl_afu_put(ctx->afu); in ocxl_context_free()
294 kfree(ctx); in ocxl_context_free()