Skip to content

Commit b1db551

Browse files
Christophe Lombardmpe
authored andcommitted
cxl: Add support for ASB_Notify on POWER9
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 <[email protected]> Reviewed-by: Philippe Bergheaud <[email protected]> Acked-by: Frederic Barrat <[email protected]> Reviewed-by: Vaibhav Jain <[email protected]> Acked-by: Andrew Donnellan <[email protected]> Signed-off-by: Michael Ellerman <[email protected]>
1 parent 074db39 commit b1db551

File tree

7 files changed

+39
-8
lines changed

7 files changed

+39
-8
lines changed

arch/powerpc/kernel/process.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1590,6 +1590,7 @@ int set_thread_tidr(struct task_struct *t)
15901590

15911591
return 0;
15921592
}
1593+
EXPORT_SYMBOL_GPL(set_thread_tidr);
15931594

15941595
#endif /* CONFIG_PPC64 */
15951596

drivers/misc/cxl/context.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ int cxl_context_init(struct cxl_context *ctx, struct cxl_afu *afu, bool master)
4545
ctx->pid = NULL; /* Set in start work ioctl */
4646
mutex_init(&ctx->mapping_lock);
4747
ctx->mapping = NULL;
48+
ctx->tidr = 0;
49+
ctx->assign_tidr = false;
4850

4951
if (cxl_is_power8()) {
5052
spin_lock_init(&ctx->sste_lock);

drivers/misc/cxl/cxl.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,9 @@ struct cxl_context {
630630
struct list_head extra_irq_contexts;
631631

632632
struct mm_struct *mm;
633+
634+
u16 tidr;
635+
bool assign_tidr;
633636
};
634637

635638
struct cxl_irq_info;

drivers/misc/cxl/cxllib.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,10 +199,11 @@ int cxllib_get_PE_attributes(struct task_struct *task,
199199
*/
200200
attr->pid = mm->context.id;
201201
mmput(mm);
202+
attr->tid = task->thread.tidr;
202203
} else {
203204
attr->pid = 0;
205+
attr->tid = 0;
204206
}
205-
attr->tid = 0;
206207
return 0;
207208
}
208209
EXPORT_SYMBOL_GPL(cxllib_get_PE_attributes);

drivers/misc/cxl/file.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ static long afu_ioctl_start_work(struct cxl_context *ctx,
173173
* flags are set it's invalid
174174
*/
175175
if (work.reserved1 || work.reserved2 || work.reserved3 ||
176-
work.reserved4 || work.reserved5 || work.reserved6 ||
176+
work.reserved4 || work.reserved5 ||
177177
(work.flags & ~CXL_START_WORK_ALL)) {
178178
rc = -EINVAL;
179179
goto out;
@@ -186,12 +186,16 @@ static long afu_ioctl_start_work(struct cxl_context *ctx,
186186
rc = -EINVAL;
187187
goto out;
188188
}
189+
189190
if ((rc = afu_register_irqs(ctx, work.num_interrupts)))
190191
goto out;
191192

192193
if (work.flags & CXL_START_WORK_AMR)
193194
amr = work.amr & mfspr(SPRN_UAMOR);
194195

196+
if (work.flags & CXL_START_WORK_TID)
197+
ctx->assign_tidr = true;
198+
195199
ctx->mmio_err_ff = !!(work.flags & CXL_START_WORK_ERR_FF);
196200

197201
/*
@@ -263,8 +267,15 @@ static long afu_ioctl_start_work(struct cxl_context *ctx,
263267
goto out;
264268
}
265269

266-
ctx->status = STARTED;
267270
rc = 0;
271+
if (work.flags & CXL_START_WORK_TID) {
272+
work.tid = ctx->tidr;
273+
if (copy_to_user(uwork, &work, sizeof(work)))
274+
rc = -EFAULT;
275+
}
276+
277+
ctx->status = STARTED;
278+
268279
out:
269280
mutex_unlock(&ctx->status_mutex);
270281
return rc;

drivers/misc/cxl/native.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <linux/uaccess.h>
1717
#include <linux/delay.h>
1818
#include <asm/synch.h>
19+
#include <asm/switch_to.h>
1920
#include <misc/cxl-base.h>
2021

2122
#include "cxl.h"
@@ -655,6 +656,7 @@ static void update_ivtes_directed(struct cxl_context *ctx)
655656
static int process_element_entry_psl9(struct cxl_context *ctx, u64 wed, u64 amr)
656657
{
657658
u32 pid;
659+
int rc;
658660

659661
cxl_assign_psn_space(ctx);
660662

@@ -673,7 +675,16 @@ static int process_element_entry_psl9(struct cxl_context *ctx, u64 wed, u64 amr)
673675
pid = ctx->mm->context.id;
674676
}
675677

676-
ctx->elem->common.tid = 0;
678+
/* Assign a unique TIDR (thread id) for the current thread */
679+
if (!(ctx->tidr) && (ctx->assign_tidr)) {
680+
rc = set_thread_tidr(current);
681+
if (rc)
682+
return -ENODEV;
683+
ctx->tidr = current->thread.tidr;
684+
pr_devel("%s: current tidr: %d\n", __func__, ctx->tidr);
685+
}
686+
687+
ctx->elem->common.tid = cpu_to_be32(ctx->tidr);
677688
ctx->elem->common.pid = cpu_to_be32(pid);
678689

679690
ctx->elem->sr = cpu_to_be64(calculate_sr(ctx));

include/uapi/misc/cxl.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,22 @@ struct cxl_ioctl_start_work {
2020
__u64 work_element_descriptor;
2121
__u64 amr;
2222
__s16 num_interrupts;
23-
__s16 reserved1;
24-
__s32 reserved2;
23+
__u16 tid;
24+
__s32 reserved1;
25+
__u64 reserved2;
2526
__u64 reserved3;
2627
__u64 reserved4;
2728
__u64 reserved5;
28-
__u64 reserved6;
2929
};
3030

3131
#define CXL_START_WORK_AMR 0x0000000000000001ULL
3232
#define CXL_START_WORK_NUM_IRQS 0x0000000000000002ULL
3333
#define CXL_START_WORK_ERR_FF 0x0000000000000004ULL
34+
#define CXL_START_WORK_TID 0x0000000000000008ULL
3435
#define CXL_START_WORK_ALL (CXL_START_WORK_AMR |\
3536
CXL_START_WORK_NUM_IRQS |\
36-
CXL_START_WORK_ERR_FF)
37+
CXL_START_WORK_ERR_FF |\
38+
CXL_START_WORK_TID)
3739

3840

3941
/* Possible modes that an afu can be in */

0 commit comments

Comments
 (0)