Merge branch 'release' of git://git.kernel.org/pub/scm/linux/kernel/git/lenb/linux...
[pandora-kernel.git] / drivers / s390 / block / dasd_cmb.c
1 /*
2  * Linux on zSeries Channel Measurement Facility support
3  *  (dasd device driver interface)
4  *
5  * Copyright 2000,2003 IBM Corporation
6  *
7  * Author: Arnd Bergmann <arndb@de.ibm.com>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2, or (at your option)
12  * any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22  */
23 #include <linux/init.h>
24 #include <linux/module.h>
25 #include <asm/ccwdev.h>
26 #include <asm/cmb.h>
27
28 #include "dasd_int.h"
29
30 static int
31 dasd_ioctl_cmf_enable(struct block_device *bdev, int no, long args)
32 {
33         struct dasd_device *device;
34
35         device = bdev->bd_disk->private_data;
36         if (!device)
37                 return -EINVAL;
38
39         return enable_cmf(device->cdev);
40 }
41
42 static int
43 dasd_ioctl_cmf_disable(struct block_device *bdev, int no, long args)
44 {
45         struct dasd_device *device;
46
47         device = bdev->bd_disk->private_data;
48         if (!device)
49                 return -EINVAL;
50
51         return disable_cmf(device->cdev);
52 }
53
54 static int
55 dasd_ioctl_readall_cmb(struct block_device *bdev, int no, long args)
56 {
57         struct dasd_device *device;
58         struct cmbdata __user *udata;
59         struct cmbdata data;
60         size_t size;
61         int ret;
62
63         device = bdev->bd_disk->private_data;
64         if (!device)
65                 return -EINVAL;
66         udata = (void __user *) args;
67         size = _IOC_SIZE(no);
68
69         if (!access_ok(VERIFY_WRITE, udata, size))
70                 return -EFAULT;
71         ret = cmf_readall(device->cdev, &data);
72         if (ret)
73                 return ret;
74         if (copy_to_user(udata, &data, min(size, sizeof(*udata))))
75                 return -EFAULT;
76         return 0;
77 }
78
79 /* module initialization below here. dasd already provides a mechanism
80  * to dynamically register ioctl functions, so we simply use this. */
81 static inline int
82 ioctl_reg(unsigned int no, dasd_ioctl_fn_t handler)
83 {
84         return dasd_ioctl_no_register(THIS_MODULE, no, handler);
85 }
86
87 static inline void
88 ioctl_unreg(unsigned int no, dasd_ioctl_fn_t handler)
89 {
90         dasd_ioctl_no_unregister(THIS_MODULE, no, handler);
91 }
92
93 static void
94 dasd_cmf_exit(void)
95 {
96         ioctl_unreg(BIODASDCMFENABLE,  dasd_ioctl_cmf_enable);
97         ioctl_unreg(BIODASDCMFDISABLE, dasd_ioctl_cmf_disable);
98         ioctl_unreg(BIODASDREADALLCMB, dasd_ioctl_readall_cmb);
99 }
100
101 static int __init
102 dasd_cmf_init(void)
103 {
104         int ret;
105         ret = ioctl_reg (BIODASDCMFENABLE, dasd_ioctl_cmf_enable);
106         if (ret)
107                 goto err;
108         ret = ioctl_reg (BIODASDCMFDISABLE, dasd_ioctl_cmf_disable);
109         if (ret)
110                 goto err;
111         ret = ioctl_reg (BIODASDREADALLCMB, dasd_ioctl_readall_cmb);
112         if (ret)
113                 goto err;
114
115         return 0;
116 err:
117         dasd_cmf_exit();
118
119         return ret;
120 }
121
122 module_init(dasd_cmf_init);
123 module_exit(dasd_cmf_exit);
124
125 MODULE_AUTHOR("Arnd Bergmann <arndb@de.ibm.com>");
126 MODULE_LICENSE("GPL");
127 MODULE_DESCRIPTION("channel measurement facility interface for dasd\n"
128                    "Copyright 2003 IBM Corporation\n");