2 * IOCTL interface for SCLP
4 * Copyright IBM Corp. 2012
9 #include <linux/compat.h>
10 #include <linux/uaccess.h>
11 #include <linux/miscdevice.h>
12 #include <linux/gfp.h>
13 #include <linux/module.h>
14 #include <linux/ioctl.h>
16 #include <asm/compat.h>
17 #include <asm/sclp_ctl.h>
23 * Supported command words
25 static unsigned int sclp_ctl_sccb_wlist[] = {
31 * Check if command word is supported
33 static int sclp_ctl_cmdw_supported(unsigned int cmdw)
37 for (i = 0; i < ARRAY_SIZE(sclp_ctl_sccb_wlist); i++) {
38 if (cmdw == sclp_ctl_sccb_wlist[i])
44 static void __user *u64_to_uptr(u64 value)
47 return compat_ptr(value);
49 return (void __user *)(unsigned long)value;
55 static int sclp_ctl_ioctl_sccb(void __user *user_area)
57 struct sclp_ctl_sccb ctl_sccb;
58 struct sccb_header *sccb;
62 if (copy_from_user(&ctl_sccb, user_area, sizeof(ctl_sccb)))
64 if (!sclp_ctl_cmdw_supported(ctl_sccb.cmdw))
66 sccb = (void *) get_zeroed_page(GFP_KERNEL | GFP_DMA);
70 copy_from_user(sccb, u64_to_uptr(ctl_sccb.sccb), PAGE_SIZE);
71 if (offsetof(struct sccb_header, length) +
72 sizeof(sccb->length) > copied || sccb->length > copied) {
76 if (sccb->length < 8) {
80 rc = sclp_sync_request(ctl_sccb.cmdw, sccb);
83 if (copy_to_user(u64_to_uptr(ctl_sccb.sccb), sccb, sccb->length))
86 free_page((unsigned long) sccb);
91 * SCLP SCCB ioctl function
93 static long sclp_ctl_ioctl(struct file *filp, unsigned int cmd,
99 argp = compat_ptr(arg);
101 argp = (void __user *) arg;
104 return sclp_ctl_ioctl_sccb(argp);
105 default: /* unknown ioctl number */
113 static const struct file_operations sclp_ctl_fops = {
114 .owner = THIS_MODULE,
115 .open = nonseekable_open,
116 .unlocked_ioctl = sclp_ctl_ioctl,
117 .compat_ioctl = sclp_ctl_ioctl,
122 * Misc device definition
124 static struct miscdevice sclp_ctl_device = {
125 .minor = MISC_DYNAMIC_MINOR,
127 .fops = &sclp_ctl_fops,
129 module_misc_device(sclp_ctl_device);