Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ocxl: Add an IOCTL so userspace knows what OCXL features are available

In order for a userspace AFU driver to call the POWER9 specific
OCXL_IOCTL_ENABLE_P9_WAIT, it needs to verify that it can actually
make that call.

Signed-off-by: Alastair D'Silva <alastair@d-silva.org>
Acked-by: Frederic Barrat <fbarrat@linux.vnet.ibm.com>
Acked-by: Andrew Donnellan <andrew.donnellan@au1.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>

authored by

Alastair D'Silva and committed by
Michael Ellerman
02a8e5bc e948e06f

+31
+25
drivers/misc/ocxl/file.c
··· 168 168 } 169 169 #endif 170 170 171 + 172 + static long afu_ioctl_get_features(struct ocxl_context *ctx, 173 + struct ocxl_ioctl_features __user *uarg) 174 + { 175 + struct ocxl_ioctl_features arg; 176 + 177 + memset(&arg, 0, sizeof(arg)); 178 + 179 + #ifdef CONFIG_PPC64 180 + if (cpu_has_feature(CPU_FTR_P9_TIDR)) 181 + arg.flags[0] |= OCXL_IOCTL_FEATURES_FLAGS0_P9_WAIT; 182 + #endif 183 + 184 + if (copy_to_user(uarg, &arg, sizeof(arg))) 185 + return -EFAULT; 186 + 187 + return 0; 188 + } 189 + 171 190 #define CMD_STR(x) (x == OCXL_IOCTL_ATTACH ? "ATTACH" : \ 172 191 x == OCXL_IOCTL_IRQ_ALLOC ? "IRQ_ALLOC" : \ 173 192 x == OCXL_IOCTL_IRQ_FREE ? "IRQ_FREE" : \ 174 193 x == OCXL_IOCTL_IRQ_SET_FD ? "IRQ_SET_FD" : \ 175 194 x == OCXL_IOCTL_GET_METADATA ? "GET_METADATA" : \ 176 195 x == OCXL_IOCTL_ENABLE_P9_WAIT ? "ENABLE_P9_WAIT" : \ 196 + x == OCXL_IOCTL_GET_FEATURES ? "GET_FEATURES" : \ 177 197 "UNKNOWN") 178 198 179 199 static long afu_ioctl(struct file *file, unsigned int cmd, ··· 258 238 (struct ocxl_ioctl_p9_wait __user *) args); 259 239 break; 260 240 #endif 241 + 242 + case OCXL_IOCTL_GET_FEATURES: 243 + rc = afu_ioctl_get_features(ctx, 244 + (struct ocxl_ioctl_features __user *) args); 245 + break; 261 246 262 247 default: 263 248 rc = -EINVAL;
+6
include/uapi/misc/ocxl.h
··· 55 55 __u64 reserved3[3]; 56 56 }; 57 57 58 + #define OCXL_IOCTL_FEATURES_FLAGS0_P9_WAIT 0x01 59 + struct ocxl_ioctl_features { 60 + __u64 flags[4]; 61 + }; 62 + 58 63 struct ocxl_ioctl_irq_fd { 59 64 __u64 irq_offset; 60 65 __s32 eventfd; ··· 75 70 #define OCXL_IOCTL_IRQ_SET_FD _IOW(OCXL_MAGIC, 0x13, struct ocxl_ioctl_irq_fd) 76 71 #define OCXL_IOCTL_GET_METADATA _IOR(OCXL_MAGIC, 0x14, struct ocxl_ioctl_metadata) 77 72 #define OCXL_IOCTL_ENABLE_P9_WAIT _IOR(OCXL_MAGIC, 0x15, struct ocxl_ioctl_p9_wait) 73 + #define OCXL_IOCTL_GET_FEATURES _IOR(OCXL_MAGIC, 0x16, struct ocxl_ioctl_features) 78 74 79 75 #endif /* _UAPI_MISC_OCXL_H */