cxl: Add support for ASB_Notify on POWER9
authorChristophe Lombard <clombard@linux.vnet.ibm.com>
Thu, 11 Jan 2018 08:55:25 +0000 (09:55 +0100)
committerMichael Ellerman <mpe@ellerman.id.au>
Fri, 19 Jan 2018 12:19:37 +0000 (23:19 +1100)
The POWER9 core supports a new feature: ASB_Notify which requires the
support of the Special Purpose Register: TIDR.

The ASB_Notify command, generated by the AFU, will attempt to
wake-up the host thread identified by the particular LPID:PID:TID.

This patch assign a unique TIDR (thread id) for the current thread which
will be used in the process element entry.

Signed-off-by: Christophe Lombard <clombard@linux.vnet.ibm.com>
Reviewed-by: Philippe Bergheaud <felix@linux.vnet.ibm.com>
Acked-by: Frederic Barrat <fbarrat@linux.vnet.ibm.com>
Reviewed-by: Vaibhav Jain <vaibhav@linux.vnet.ibm.com>
Acked-by: Andrew Donnellan <andrew.donnellan@au1.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
arch/powerpc/kernel/process.c
drivers/misc/cxl/context.c
drivers/misc/cxl/cxl.h
drivers/misc/cxl/cxllib.c
drivers/misc/cxl/file.c
drivers/misc/cxl/native.c
include/uapi/misc/cxl.h

index 1563d1190da301ca6eaedbbcc1b7d6af6c4395e7..9eb78ec0ce5bd1d862210a95f76a9d665b41908e 100644 (file)
@@ -1590,6 +1590,7 @@ int set_thread_tidr(struct task_struct *t)
 
        return 0;
 }
+EXPORT_SYMBOL_GPL(set_thread_tidr);
 
 #endif /* CONFIG_PPC64 */
 
index 12a41b2753f05721350982a5041d292ed5149d08..7ff315ad369281a5d166bd7563e45763ed0ea459 100644 (file)
@@ -45,6 +45,8 @@ int cxl_context_init(struct cxl_context *ctx, struct cxl_afu *afu, bool master)
        ctx->pid = NULL; /* Set in start work ioctl */
        mutex_init(&ctx->mapping_lock);
        ctx->mapping = NULL;
+       ctx->tidr = 0;
+       ctx->assign_tidr = false;
 
        if (cxl_is_power8()) {
                spin_lock_init(&ctx->sste_lock);
index e46a4062904adce438d7be43db9fb58cedeb242a..53149fbd780e70681fdc580d9822fd84cac4e5e1 100644 (file)
@@ -630,6 +630,9 @@ struct cxl_context {
        struct list_head extra_irq_contexts;
 
        struct mm_struct *mm;
+
+       u16 tidr;
+       bool assign_tidr;
 };
 
 struct cxl_irq_info;
index dc9bc1807fdfa52aede0748308d16f5c36c6c95f..30ccba436b3b1cada1dd838632c4b8167769319f 100644 (file)
@@ -199,10 +199,11 @@ int cxllib_get_PE_attributes(struct task_struct *task,
                 */
                attr->pid = mm->context.id;
                mmput(mm);
+               attr->tid = task->thread.tidr;
        } else {
                attr->pid = 0;
+               attr->tid = 0;
        }
-       attr->tid = 0;
        return 0;
 }
 EXPORT_SYMBOL_GPL(cxllib_get_PE_attributes);
index 76c0b0ca9388c05840a6c6644b70163d64eb378b..93fd381f648489b6215ffed4b3a65a8c9f7c4422 100644 (file)
@@ -173,7 +173,7 @@ static long afu_ioctl_start_work(struct cxl_context *ctx,
         * flags are set it's invalid
         */
        if (work.reserved1 || work.reserved2 || work.reserved3 ||
-           work.reserved4 || work.reserved5 || work.reserved6 ||
+           work.reserved4 || work.reserved5 ||
            (work.flags & ~CXL_START_WORK_ALL)) {
                rc = -EINVAL;
                goto out;
@@ -186,12 +186,16 @@ static long afu_ioctl_start_work(struct cxl_context *ctx,
                rc =  -EINVAL;
                goto out;
        }
+
        if ((rc = afu_register_irqs(ctx, work.num_interrupts)))
                goto out;
 
        if (work.flags & CXL_START_WORK_AMR)
                amr = work.amr & mfspr(SPRN_UAMOR);
 
+       if (work.flags & CXL_START_WORK_TID)
+               ctx->assign_tidr = true;
+
        ctx->mmio_err_ff = !!(work.flags & CXL_START_WORK_ERR_FF);
 
        /*
@@ -263,8 +267,15 @@ static long afu_ioctl_start_work(struct cxl_context *ctx,
                goto out;
        }
 
-       ctx->status = STARTED;
        rc = 0;
+       if (work.flags & CXL_START_WORK_TID) {
+               work.tid = ctx->tidr;
+               if (copy_to_user(uwork, &work, sizeof(work)))
+                       rc = -EFAULT;
+       }
+
+       ctx->status = STARTED;
+
 out:
        mutex_unlock(&ctx->status_mutex);
        return rc;
index 02b6b45b4c204d8eb166c613ec560b550722ab1b..1b3d7c65ea3fe2a7f22307630302e29cd69f7b66 100644 (file)
@@ -16,6 +16,7 @@
 #include <linux/uaccess.h>
 #include <linux/delay.h>
 #include <asm/synch.h>
+#include <asm/switch_to.h>
 #include <misc/cxl-base.h>
 
 #include "cxl.h"
@@ -655,6 +656,7 @@ static void update_ivtes_directed(struct cxl_context *ctx)
 static int process_element_entry_psl9(struct cxl_context *ctx, u64 wed, u64 amr)
 {
        u32 pid;
+       int rc;
 
        cxl_assign_psn_space(ctx);
 
@@ -673,7 +675,16 @@ static int process_element_entry_psl9(struct cxl_context *ctx, u64 wed, u64 amr)
                pid = ctx->mm->context.id;
        }
 
-       ctx->elem->common.tid = 0;
+       /* Assign a unique TIDR (thread id) for the current thread */
+       if (!(ctx->tidr) && (ctx->assign_tidr)) {
+               rc = set_thread_tidr(current);
+               if (rc)
+                       return -ENODEV;
+               ctx->tidr = current->thread.tidr;
+               pr_devel("%s: current tidr: %d\n", __func__, ctx->tidr);
+       }
+
+       ctx->elem->common.tid = cpu_to_be32(ctx->tidr);
        ctx->elem->common.pid = cpu_to_be32(pid);
 
        ctx->elem->sr = cpu_to_be64(calculate_sr(ctx));
index 49e8fd08855a68886109890bf7fa7506fd318e5e..56376d3907d83c3bf3c79bc73448dfd16d2d83f0 100644 (file)
@@ -20,20 +20,22 @@ struct cxl_ioctl_start_work {
        __u64 work_element_descriptor;
        __u64 amr;
        __s16 num_interrupts;
-       __s16 reserved1;
-       __s32 reserved2;
+       __u16 tid;
+       __s32 reserved1;
+       __u64 reserved2;
        __u64 reserved3;
        __u64 reserved4;
        __u64 reserved5;
-       __u64 reserved6;
 };
 
 #define CXL_START_WORK_AMR             0x0000000000000001ULL
 #define CXL_START_WORK_NUM_IRQS                0x0000000000000002ULL
 #define CXL_START_WORK_ERR_FF          0x0000000000000004ULL
+#define CXL_START_WORK_TID             0x0000000000000008ULL
 #define CXL_START_WORK_ALL             (CXL_START_WORK_AMR |\
                                         CXL_START_WORK_NUM_IRQS |\
-                                        CXL_START_WORK_ERR_FF)
+                                        CXL_START_WORK_ERR_FF |\
+                                        CXL_START_WORK_TID)
 
 
 /* Possible modes that an afu can be in */