1 // SPDX-License-Identifier: GPL-2.0
3 * IOCTL interface for SCLP
5 * Copyright IBM Corp. 2012
7 * Author: Michael Holzheu <holzheu@linux.vnet.ibm.com>
10 #include <linux/compat.h>
11 #include <linux/uaccess.h>
12 #include <linux/miscdevice.h>
13 #include <linux/gfp.h>
14 #include <linux/init.h>
15 #include <linux/ioctl.h>
17 #include <asm/compat.h>
18 #include <asm/sclp_ctl.h>
24 * Supported command words
26 static unsigned int sclp_ctl_sccb_wlist
[] = {
32 * Check if command word is supported
34 static int sclp_ctl_cmdw_supported(unsigned int cmdw
)
38 for (i
= 0; i
< ARRAY_SIZE(sclp_ctl_sccb_wlist
); i
++) {
39 if (cmdw
== sclp_ctl_sccb_wlist
[i
])
45 static void __user
*u64_to_uptr(u64 value
)
48 return compat_ptr(value
);
50 return (void __user
*)(unsigned long)value
;
56 static int sclp_ctl_ioctl_sccb(void __user
*user_area
)
58 struct sclp_ctl_sccb ctl_sccb
;
59 struct sccb_header
*sccb
;
63 if (copy_from_user(&ctl_sccb
, user_area
, sizeof(ctl_sccb
)))
65 if (!sclp_ctl_cmdw_supported(ctl_sccb
.cmdw
))
67 sccb
= (void *) get_zeroed_page(GFP_KERNEL
| GFP_DMA
);
71 copy_from_user(sccb
, u64_to_uptr(ctl_sccb
.sccb
), PAGE_SIZE
);
72 if (offsetof(struct sccb_header
, length
) +
73 sizeof(sccb
->length
) > copied
|| sccb
->length
> copied
) {
77 if (sccb
->length
< 8) {
81 rc
= sclp_sync_request(ctl_sccb
.cmdw
, sccb
);
84 if (copy_to_user(u64_to_uptr(ctl_sccb
.sccb
), sccb
, sccb
->length
))
87 free_page((unsigned long) sccb
);
92 * SCLP SCCB ioctl function
94 static long sclp_ctl_ioctl(struct file
*filp
, unsigned int cmd
,
100 argp
= compat_ptr(arg
);
102 argp
= (void __user
*) arg
;
105 return sclp_ctl_ioctl_sccb(argp
);
106 default: /* unknown ioctl number */
114 static const struct file_operations sclp_ctl_fops
= {
115 .owner
= THIS_MODULE
,
116 .open
= nonseekable_open
,
117 .unlocked_ioctl
= sclp_ctl_ioctl
,
118 .compat_ioctl
= sclp_ctl_ioctl
,
123 * Misc device definition
125 static struct miscdevice sclp_ctl_device
= {
126 .minor
= MISC_DYNAMIC_MINOR
,
128 .fops
= &sclp_ctl_fops
,
130 builtin_misc_device(sclp_ctl_device
);