diff options
author | Michael Holzheu <holzheu@linux.vnet.ibm.com> | 2013-06-06 03:52:08 -0400 |
---|---|---|
committer | Martin Schwidefsky <schwidefsky@de.ibm.com> | 2013-06-26 15:10:13 -0400 |
commit | d475f942b1dd6a897dac3ad4ed98d6994b275378 (patch) | |
tree | 43f599275ef7ac5350ea25f8f1eeb2690d6dc4e4 /drivers/s390/char/sclp_ctl.c | |
parent | e9a8f32a98a6099b009ea7da4f299bb5427db126 (diff) |
s390/sclp: Add SCLP character device driver
Add a character misc device "sclp_ctl" that allows to run SCCBs
from user space using the SCLP_CTL_SCCB ioctl.
Signed-off-by: Michael Holzheu <holzheu@linux.vnet.ibm.com>
Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
Diffstat (limited to 'drivers/s390/char/sclp_ctl.c')
-rw-r--r-- | drivers/s390/char/sclp_ctl.c | 145 |
1 files changed, 145 insertions, 0 deletions
diff --git a/drivers/s390/char/sclp_ctl.c b/drivers/s390/char/sclp_ctl.c new file mode 100644 index 000000000000..abe8ef13d148 --- /dev/null +++ b/drivers/s390/char/sclp_ctl.c | |||
@@ -0,0 +1,145 @@ | |||
1 | /* | ||
2 | * IOCTL interface for SCLP | ||
3 | * | ||
4 | * Copyright IBM Corp. 2012 | ||
5 | * | ||
6 | * Author: Michael Holzheu <holzheu@linux.vnet.ibm.com> | ||
7 | */ | ||
8 | |||
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> | ||
15 | #include <linux/fs.h> | ||
16 | #include <linux/compat.h> | ||
17 | #include <asm/compat.h> | ||
18 | #include <asm/sclp_ctl.h> | ||
19 | #include <asm/sclp.h> | ||
20 | |||
21 | #include "sclp.h" | ||
22 | |||
23 | /* | ||
24 | * Supported command words | ||
25 | */ | ||
26 | static unsigned int sclp_ctl_sccb_wlist[] = { | ||
27 | 0x00400002, | ||
28 | 0x00410002, | ||
29 | }; | ||
30 | |||
31 | /* | ||
32 | * Check if command word is supported | ||
33 | */ | ||
34 | static int sclp_ctl_cmdw_supported(unsigned int cmdw) | ||
35 | { | ||
36 | int i; | ||
37 | |||
38 | for (i = 0; i < ARRAY_SIZE(sclp_ctl_sccb_wlist); i++) { | ||
39 | if (cmdw == sclp_ctl_sccb_wlist[i]) | ||
40 | return 1; | ||
41 | } | ||
42 | return 0; | ||
43 | } | ||
44 | |||
45 | static void __user *u64_to_uptr(u64 value) | ||
46 | { | ||
47 | if (is_compat_task()) | ||
48 | return compat_ptr(value); | ||
49 | else | ||
50 | return (void __user *)(unsigned long)value; | ||
51 | } | ||
52 | |||
53 | /* | ||
54 | * Start SCLP request | ||
55 | */ | ||
56 | static int sclp_ctl_ioctl_sccb(void __user *user_area) | ||
57 | { | ||
58 | struct sclp_ctl_sccb ctl_sccb; | ||
59 | struct sccb_header *sccb; | ||
60 | int rc; | ||
61 | |||
62 | if (copy_from_user(&ctl_sccb, user_area, sizeof(ctl_sccb))) | ||
63 | return -EFAULT; | ||
64 | if (!sclp_ctl_cmdw_supported(ctl_sccb.cmdw)) | ||
65 | return -EOPNOTSUPP; | ||
66 | sccb = (void *) get_zeroed_page(GFP_KERNEL | GFP_DMA); | ||
67 | if (!sccb) | ||
68 | return -ENOMEM; | ||
69 | if (copy_from_user(sccb, u64_to_uptr(ctl_sccb.sccb), sizeof(*sccb))) { | ||
70 | rc = -EFAULT; | ||
71 | goto out_free; | ||
72 | } | ||
73 | if (sccb->length > PAGE_SIZE || sccb->length < 8) | ||
74 | return -EINVAL; | ||
75 | if (copy_from_user(sccb, u64_to_uptr(ctl_sccb.sccb), sccb->length)) { | ||
76 | rc = -EFAULT; | ||
77 | goto out_free; | ||
78 | } | ||
79 | rc = sclp_sync_request(ctl_sccb.cmdw, sccb); | ||
80 | if (rc) | ||
81 | goto out_free; | ||
82 | if (copy_to_user(u64_to_uptr(ctl_sccb.sccb), sccb, sccb->length)) | ||
83 | rc = -EFAULT; | ||
84 | out_free: | ||
85 | free_page((unsigned long) sccb); | ||
86 | return rc; | ||
87 | } | ||
88 | |||
89 | /* | ||
90 | * SCLP SCCB ioctl function | ||
91 | */ | ||
92 | static long sclp_ctl_ioctl(struct file *filp, unsigned int cmd, | ||
93 | unsigned long arg) | ||
94 | { | ||
95 | void __user *argp; | ||
96 | |||
97 | if (is_compat_task()) | ||
98 | argp = compat_ptr(arg); | ||
99 | else | ||
100 | argp = (void __user *) arg; | ||
101 | switch (cmd) { | ||
102 | case SCLP_CTL_SCCB: | ||
103 | return sclp_ctl_ioctl_sccb(argp); | ||
104 | default: /* unknown ioctl number */ | ||
105 | return -ENOTTY; | ||
106 | } | ||
107 | } | ||
108 | |||
109 | /* | ||
110 | * File operations | ||
111 | */ | ||
112 | static const struct file_operations sclp_ctl_fops = { | ||
113 | .owner = THIS_MODULE, | ||
114 | .open = nonseekable_open, | ||
115 | .unlocked_ioctl = sclp_ctl_ioctl, | ||
116 | .compat_ioctl = sclp_ctl_ioctl, | ||
117 | .llseek = no_llseek, | ||
118 | }; | ||
119 | |||
120 | /* | ||
121 | * Misc device definition | ||
122 | */ | ||
123 | static struct miscdevice sclp_ctl_device = { | ||
124 | .minor = MISC_DYNAMIC_MINOR, | ||
125 | .name = "sclp", | ||
126 | .fops = &sclp_ctl_fops, | ||
127 | }; | ||
128 | |||
129 | /* | ||
130 | * Register sclp_ctl misc device | ||
131 | */ | ||
132 | static int __init sclp_ctl_init(void) | ||
133 | { | ||
134 | return misc_register(&sclp_ctl_device); | ||
135 | } | ||
136 | module_init(sclp_ctl_init); | ||
137 | |||
138 | /* | ||
139 | * Deregister sclp_ctl misc device | ||
140 | */ | ||
141 | static void __exit sclp_ctl_exit(void) | ||
142 | { | ||
143 | misc_deregister(&sclp_ctl_device); | ||
144 | } | ||
145 | module_exit(sclp_ctl_exit); | ||