Le 25/03/2019 à 06:44, Alastair D'Silva a écrit :
From: Alastair D'Silva <alast...@d-silva.org>

Most OpenCAPI operations require a valid context, so
exposing these functions to external drivers is necessary.

Signed-off-by: Alastair D'Silva <alast...@d-silva.org>
Reviewed-by: Greg Kurz <gr...@kaod.org>
---

See comment on previous patch regarding merging ocxl_context_alloc() and ocxl_context_init(), it would impact the exported symbols.

  Fred


  drivers/misc/ocxl/context.c       |  9 +++++--
  drivers/misc/ocxl/file.c          |  2 +-
  drivers/misc/ocxl/ocxl_internal.h |  6 -----
  include/misc/ocxl.h               | 45 +++++++++++++++++++++++++++++++
  4 files changed, 53 insertions(+), 9 deletions(-)

diff --git a/drivers/misc/ocxl/context.c b/drivers/misc/ocxl/context.c
index c73a859d2224..8b97b0f19db8 100644
--- a/drivers/misc/ocxl/context.c
+++ b/drivers/misc/ocxl/context.c
@@ -8,6 +8,7 @@ struct ocxl_context *ocxl_context_alloc(void)
  {
        return kzalloc(sizeof(struct ocxl_context), GFP_KERNEL);
  }
+EXPORT_SYMBOL_GPL(ocxl_context_alloc);
int ocxl_context_init(struct ocxl_context *ctx, struct ocxl_afu *afu,
                struct address_space *mapping)
@@ -43,6 +44,7 @@ int ocxl_context_init(struct ocxl_context *ctx, struct 
ocxl_afu *afu,
        ocxl_afu_get(afu);
        return 0;
  }
+EXPORT_SYMBOL_GPL(ocxl_context_init);
/*
   * Callback for when a translation fault triggers an error
@@ -63,7 +65,7 @@ static void xsl_fault_error(void *data, u64 addr, u64 dsisr)
        wake_up_all(&ctx->events_wq);
  }
-int ocxl_context_attach(struct ocxl_context *ctx, u64 amr)
+int ocxl_context_attach(struct ocxl_context *ctx, u64 amr, struct mm_struct 
*mm)
  {
        int rc;
@@ -75,7 +77,7 @@ int ocxl_context_attach(struct ocxl_context *ctx, u64 amr)
        }
rc = ocxl_link_add_pe(ctx->afu->fn->link, ctx->pasid,
-                       current->mm->context.id, ctx->tidr, amr, current->mm,
+                       mm->context.id, ctx->tidr, amr, mm,
                        xsl_fault_error, ctx);
        if (rc)
                goto out;
@@ -85,6 +87,7 @@ int ocxl_context_attach(struct ocxl_context *ctx, u64 amr)
        mutex_unlock(&ctx->status_mutex);
        return rc;
  }
+EXPORT_SYMBOL_GPL(ocxl_context_attach);
static vm_fault_t map_afu_irq(struct vm_area_struct *vma, unsigned long address,
                u64 offset, struct ocxl_context *ctx)
@@ -243,6 +246,7 @@ int ocxl_context_detach(struct ocxl_context *ctx)
        }
        return 0;
  }
+EXPORT_SYMBOL_GPL(ocxl_context_detach);
void ocxl_context_detach_all(struct ocxl_afu *afu)
  {
@@ -280,3 +284,4 @@ void ocxl_context_free(struct ocxl_context *ctx)
        ocxl_afu_put(ctx->afu);
        kfree(ctx);
  }
+EXPORT_SYMBOL_GPL(ocxl_context_free);
diff --git a/drivers/misc/ocxl/file.c b/drivers/misc/ocxl/file.c
index e6e6121cd9a3..e51578186fd4 100644
--- a/drivers/misc/ocxl/file.c
+++ b/drivers/misc/ocxl/file.c
@@ -94,7 +94,7 @@ static long afu_ioctl_attach(struct ocxl_context *ctx,
                return -EINVAL;
amr = arg.amr & mfspr(SPRN_UAMOR);
-       rc = ocxl_context_attach(ctx, amr);
+       rc = ocxl_context_attach(ctx, amr, current->mm);
        return rc;
  }
diff --git a/drivers/misc/ocxl/ocxl_internal.h b/drivers/misc/ocxl/ocxl_internal.h
index e04e547df29e..cda1e7667fc8 100644
--- a/drivers/misc/ocxl/ocxl_internal.h
+++ b/drivers/misc/ocxl/ocxl_internal.h
@@ -130,15 +130,9 @@ int ocxl_config_check_afu_index(struct pci_dev *dev,
   */
  int ocxl_link_update_pe(void *link_handle, int pasid, __u16 tid);
-struct ocxl_context *ocxl_context_alloc(void);
-int ocxl_context_init(struct ocxl_context *ctx, struct ocxl_afu *afu,
-                       struct address_space *mapping);
-int ocxl_context_attach(struct ocxl_context *ctx, u64 amr);
  int ocxl_context_mmap(struct ocxl_context *ctx,
                        struct vm_area_struct *vma);
-int ocxl_context_detach(struct ocxl_context *ctx);
  void ocxl_context_detach_all(struct ocxl_afu *afu);
-void ocxl_context_free(struct ocxl_context *ctx);
int ocxl_sysfs_register_afu(struct ocxl_afu *afu);
  void ocxl_sysfs_unregister_afu(struct ocxl_afu *afu);
diff --git a/include/misc/ocxl.h b/include/misc/ocxl.h
index 8bafd748e380..a8fe0ce4ea67 100644
--- a/include/misc/ocxl.h
+++ b/include/misc/ocxl.h
@@ -116,6 +116,51 @@ const struct ocxl_fn_config *ocxl_function_config(struct 
ocxl_fn *fn);
   */
  void ocxl_function_close(struct ocxl_fn *fn);
+// Context allocation
+
+/**
+ * Allocate space for a new OpenCAPI context
+ *
+ * Returns NULL on failure
+ */
+struct ocxl_context *ocxl_context_alloc(void);
+
+/**
+ * Initialize an OpenCAPI context
+ *
+ * @ctx: The OpenCAPI context to initialize
+ * @afu: The AFU the context belongs to
+ * @mapping: The mapping to unmap when the context is closed (may be NULL)
+ */
+int ocxl_context_init(struct ocxl_context *ctx, struct ocxl_afu *afu,
+                       struct address_space *mapping);
+
+/**
+ * Free an OpenCAPI context
+ *
+ * @ctx: The OpenCAPI context to free
+ */
+void ocxl_context_free(struct ocxl_context *ctx);
+
+/**
+ * Grant access to an MM to an OpenCAPI context
+ * @ctx: The OpenCAPI context to attach
+ * @amr: The value of the AMR register to restrict access
+ * @mm: The mm to attach to the context
+ *
+ * Returns 0 on success, negative on failure
+ */
+int ocxl_context_attach(struct ocxl_context *ctx, u64 amr,
+                               struct mm_struct *mm);
+
+/**
+ * Detach an MM from an OpenCAPI context
+ * @ctx: The OpenCAPI context to attach
+ *
+ * Returns 0 on success, negative on failure
+ */
+int ocxl_context_detach(struct ocxl_context *ctx);
+
  // AFU Metadata
/**


Reply via email to