Skip to content

Commit

Permalink
cxl: Add support for ASB_Notify on POWER9
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Christophe Lombard authored and Michael Ellerman committed Jan 19, 2018
1 parent 074db39 commit b1db551
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 8 deletions.
1 change: 1 addition & 0 deletions arch/powerpc/kernel/process.c
Original file line number Diff line number Diff line change
Expand Up @@ -1590,6 +1590,7 @@ int set_thread_tidr(struct task_struct *t)

return 0;
}
EXPORT_SYMBOL_GPL(set_thread_tidr);

#endif /* CONFIG_PPC64 */

Expand Down
2 changes: 2 additions & 0 deletions drivers/misc/cxl/context.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions drivers/misc/cxl/cxl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion drivers/misc/cxl/cxllib.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
15 changes: 13 additions & 2 deletions drivers/misc/cxl/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);

/*
Expand Down Expand Up @@ -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;
Expand Down
13 changes: 12 additions & 1 deletion drivers/misc/cxl/native.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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);

Expand All @@ -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));
Expand Down
10 changes: 6 additions & 4 deletions include/uapi/misc/cxl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down

0 comments on commit b1db551

Please sign in to comment.