forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-10 ee930fffee469d076998274a2ca55e13dc1efb67
kernel/drivers/misc/ocxl/context.c
....@@ -4,15 +4,15 @@
44 #include "trace.h"
55 #include "ocxl_internal.h"
66
7
-struct ocxl_context *ocxl_context_alloc(void)
8
-{
9
- return kzalloc(sizeof(struct ocxl_context), GFP_KERNEL);
10
-}
11
-
12
-int ocxl_context_init(struct ocxl_context *ctx, struct ocxl_afu *afu,
7
+int ocxl_context_alloc(struct ocxl_context **context, struct ocxl_afu *afu,
138 struct address_space *mapping)
149 {
1510 int pasid;
11
+ struct ocxl_context *ctx;
12
+
13
+ ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
14
+ if (!ctx)
15
+ return -ENOMEM;
1616
1717 ctx->afu = afu;
1818 mutex_lock(&afu->contexts_lock);
....@@ -20,6 +20,7 @@
2020 afu->pasid_base + afu->pasid_max, GFP_KERNEL);
2121 if (pasid < 0) {
2222 mutex_unlock(&afu->contexts_lock);
23
+ kfree(ctx);
2324 return pasid;
2425 }
2526 afu->pasid_count++;
....@@ -41,8 +42,10 @@
4142 * duration of the life of the context
4243 */
4344 ocxl_afu_get(afu);
45
+ *context = ctx;
4446 return 0;
4547 }
48
+EXPORT_SYMBOL_GPL(ocxl_context_alloc);
4649
4750 /*
4851 * Callback for when a translation fault triggers an error
....@@ -63,9 +66,10 @@
6366 wake_up_all(&ctx->events_wq);
6467 }
6568
66
-int ocxl_context_attach(struct ocxl_context *ctx, u64 amr)
69
+int ocxl_context_attach(struct ocxl_context *ctx, u64 amr, struct mm_struct *mm)
6770 {
6871 int rc;
72
+ unsigned long pidr = 0;
6973
7074 // Locks both status & tidr
7175 mutex_lock(&ctx->status_mutex);
....@@ -74,9 +78,11 @@
7478 goto out;
7579 }
7680
77
- rc = ocxl_link_add_pe(ctx->afu->fn->link, ctx->pasid,
78
- current->mm->context.id, ctx->tidr, amr, current->mm,
79
- xsl_fault_error, ctx);
81
+ if (mm)
82
+ pidr = mm->context.id;
83
+
84
+ rc = ocxl_link_add_pe(ctx->afu->fn->link, ctx->pasid, pidr, ctx->tidr,
85
+ amr, mm, xsl_fault_error, ctx);
8086 if (rc)
8187 goto out;
8288
....@@ -85,13 +91,15 @@
8591 mutex_unlock(&ctx->status_mutex);
8692 return rc;
8793 }
94
+EXPORT_SYMBOL_GPL(ocxl_context_attach);
8895
8996 static vm_fault_t map_afu_irq(struct vm_area_struct *vma, unsigned long address,
9097 u64 offset, struct ocxl_context *ctx)
9198 {
9299 u64 trigger_addr;
100
+ int irq_id = ocxl_irq_offset_to_id(ctx, offset);
93101
94
- trigger_addr = ocxl_afu_irq_get_addr(ctx, offset);
102
+ trigger_addr = ocxl_afu_irq_get_addr(ctx, irq_id);
95103 if (!trigger_addr)
96104 return VM_FAULT_SIGBUS;
97105
....@@ -151,12 +159,14 @@
151159 static int check_mmap_afu_irq(struct ocxl_context *ctx,
152160 struct vm_area_struct *vma)
153161 {
162
+ int irq_id = ocxl_irq_offset_to_id(ctx, vma->vm_pgoff << PAGE_SHIFT);
163
+
154164 /* only one page */
155165 if (vma_pages(vma) != 1)
156166 return -EINVAL;
157167
158168 /* check offset validty */
159
- if (!ocxl_afu_irq_get_addr(ctx, vma->vm_pgoff << PAGE_SHIFT))
169
+ if (!ocxl_afu_irq_get_addr(ctx, irq_id))
160170 return -EINVAL;
161171
162172 /*
....@@ -238,11 +248,12 @@
238248 }
239249 rc = ocxl_link_remove_pe(ctx->afu->fn->link, ctx->pasid);
240250 if (rc) {
241
- dev_warn(&ctx->afu->dev,
251
+ dev_warn(&dev->dev,
242252 "Couldn't remove PE entry cleanly: %d\n", rc);
243253 }
244254 return 0;
245255 }
256
+EXPORT_SYMBOL_GPL(ocxl_context_detach);
246257
247258 void ocxl_context_detach_all(struct ocxl_afu *afu)
248259 {
....@@ -276,7 +287,8 @@
276287
277288 ocxl_afu_irq_free_all(ctx);
278289 idr_destroy(&ctx->irq_idr);
279
- /* reference to the AFU taken in ocxl_context_init */
290
+ /* reference to the AFU taken in ocxl_context_alloc() */
280291 ocxl_afu_put(ctx->afu);
281292 kfree(ctx);
282293 }
294
+EXPORT_SYMBOL_GPL(ocxl_context_free);