5a1a65e4e6346e6598c2a4ca291804675cb21b13
[linux-flexiantxendom0-3.2.10.git] / arch / x86_64 / ia32 / ia32_ioctl.c
1 /* $Id: ia32_ioctl.c,v 1.25 2002/10/11 07:17:06 ak Exp $
2  * ioctl32.c: Conversion between 32bit and 64bit native ioctls.
3  *
4  * Copyright (C) 1997-2000  Jakub Jelinek  (jakub@redhat.com)
5  * Copyright (C) 1998  Eddie C. Dost  (ecd@skynet.be)
6  * Copyright (C) 2001,2002  Andi Kleen, SuSE Labs 
7  *
8  * These routines maintain argument size conversion between 32bit and 64bit
9  * ioctls.
10  */
11
12 #define INCLUDES
13 #include "compat_ioctl.c"
14 #include <asm/mtrr.h>
15 #include <asm/ia32.h>
16
17 extern asmlinkage long sys_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg);
18
19 #define CODE
20 #include "compat_ioctl.c"
21   
22 #ifndef TIOCGDEV
23 #define TIOCGDEV       _IOR('T',0x32, unsigned int)
24 #endif
25 static int tiocgdev(unsigned fd, unsigned cmd,  unsigned int *ptr) 
26
27
28         struct file *file = fget(fd);
29         struct tty_struct *real_tty;
30
31         if (!fd)
32                 return -EBADF;
33         if (file->f_op->ioctl != tty_ioctl)
34                 return -EINVAL; 
35         real_tty = (struct tty_struct *)file->private_data;
36         if (!real_tty)  
37                 return -EINVAL; 
38         return put_user(new_encode_dev(tty_devnum(real_tty)), ptr); 
39
40
41 #define RTC_IRQP_READ32 _IOR('p', 0x0b, unsigned int)    /* Read IRQ rate   */
42 #define RTC_IRQP_SET32  _IOW('p', 0x0c, unsigned int)    /* Set IRQ rate    */
43 #define RTC_EPOCH_READ32        _IOR('p', 0x0d, unsigned)        /* Read epoch      */
44 #define RTC_EPOCH_SET32         _IOW('p', 0x0e, unsigned)        /* Set epoch       */
45
46 static int rtc32_ioctl(unsigned fd, unsigned cmd, unsigned long arg) 
47
48         unsigned long val;
49         mm_segment_t oldfs = get_fs(); 
50         int ret; 
51         
52         switch (cmd) { 
53         case RTC_IRQP_READ32: 
54                 set_fs(KERNEL_DS); 
55                 ret = sys_ioctl(fd, RTC_IRQP_READ, (unsigned long)&val); 
56                 set_fs(oldfs); 
57                 if (!ret)
58                         ret = put_user(val, (unsigned int*) arg); 
59                 return ret; 
60
61         case RTC_IRQP_SET32: 
62                 cmd = RTC_EPOCH_SET; 
63                 break; 
64
65         case RTC_EPOCH_READ32:
66                 set_fs(KERNEL_DS); 
67                 ret = sys_ioctl(fd, RTC_EPOCH_READ, (unsigned long) &val); 
68                 set_fs(oldfs); 
69                 if (!ret)
70                         ret = put_user(val, (unsigned int*) arg); 
71                 return ret; 
72
73         case RTC_EPOCH_SET32:
74                 cmd = RTC_EPOCH_SET; 
75                 break; 
76         } 
77         return sys_ioctl(fd,cmd,arg); 
78
79
80 /* /proc/mtrr ioctls */
81
82
83 struct mtrr_sentry32
84 {
85     compat_ulong_t base;    /*  Base address     */
86     compat_uint_t size;    /*  Size of region   */
87     compat_uint_t type;     /*  Type of region   */
88 };
89
90 struct mtrr_gentry32
91 {
92     compat_ulong_t regnum;   /*  Register number  */
93     compat_uint_t base;    /*  Base address     */
94     compat_uint_t size;    /*  Size of region   */
95     compat_uint_t type;     /*  Type of region   */
96 };
97
98 #define MTRR_IOCTL_BASE 'M'
99
100 #define MTRRIOC32_ADD_ENTRY        _IOW(MTRR_IOCTL_BASE,  0, struct mtrr_sentry32)
101 #define MTRRIOC32_SET_ENTRY        _IOW(MTRR_IOCTL_BASE,  1, struct mtrr_sentry32)
102 #define MTRRIOC32_DEL_ENTRY        _IOW(MTRR_IOCTL_BASE,  2, struct mtrr_sentry32)
103 #define MTRRIOC32_GET_ENTRY        _IOWR(MTRR_IOCTL_BASE, 3, struct mtrr_gentry32)
104 #define MTRRIOC32_KILL_ENTRY       _IOW(MTRR_IOCTL_BASE,  4, struct mtrr_sentry32)
105 #define MTRRIOC32_ADD_PAGE_ENTRY   _IOW(MTRR_IOCTL_BASE,  5, struct mtrr_sentry32)
106 #define MTRRIOC32_SET_PAGE_ENTRY   _IOW(MTRR_IOCTL_BASE,  6, struct mtrr_sentry32)
107 #define MTRRIOC32_DEL_PAGE_ENTRY   _IOW(MTRR_IOCTL_BASE,  7, struct mtrr_sentry32)
108 #define MTRRIOC32_GET_PAGE_ENTRY   _IOWR(MTRR_IOCTL_BASE, 8, struct mtrr_gentry32)
109 #define MTRRIOC32_KILL_PAGE_ENTRY  _IOW(MTRR_IOCTL_BASE,  9, struct mtrr_sentry32)
110
111
112 static int mtrr_ioctl32(unsigned int fd, unsigned int cmd, unsigned long arg)
113
114         struct mtrr_gentry g;
115         struct mtrr_sentry s;
116         int get = 0, err = 0; 
117         struct mtrr_gentry32 *g32 = (struct mtrr_gentry32 *)arg; 
118         mm_segment_t oldfs = get_fs(); 
119
120         switch (cmd) { 
121 #define SET(x) case MTRRIOC32_ ## x ## _ENTRY: cmd = MTRRIOC_ ## x ## _ENTRY; break 
122 #define GET(x) case MTRRIOC32_ ## x ## _ENTRY: cmd = MTRRIOC_ ## x ## _ENTRY; get=1; break
123                 SET(ADD);
124                 SET(SET); 
125                 SET(DEL);
126                 GET(GET); 
127                 SET(KILL);
128                 SET(ADD_PAGE); 
129                 SET(SET_PAGE); 
130                 SET(DEL_PAGE); 
131                 GET(GET_PAGE); 
132                 SET(KILL_PAGE); 
133         } 
134         
135         if (get) { 
136                 err = get_user(g.regnum, &g32->regnum);
137                 err |= get_user(g.base, &g32->base);
138                 err |= get_user(g.size, &g32->size);
139                 err |= get_user(g.type, &g32->type); 
140
141                 arg = (unsigned long)&g; 
142         } else { 
143                 struct mtrr_sentry32 *s32 = (struct mtrr_sentry32 *)arg;
144                 err = get_user(s.base, &s32->base);
145                 err |= get_user(s.size, &s32->size);
146                 err |= get_user(s.type, &s32->type);
147
148                 arg = (unsigned long)&s; 
149         } 
150         if (err) return err;
151         
152         set_fs(KERNEL_DS); 
153         err = sys_ioctl(fd, cmd, arg); 
154         set_fs(oldfs); 
155                 
156         if (!err && get) { 
157                 err = put_user(g.base, &g32->base);
158                 err |= put_user(g.size, &g32->size);
159                 err |= put_user(g.regnum, &g32->regnum);
160                 err |= put_user(g.type, &g32->type); 
161         } 
162         return err;
163
164
165 #define HANDLE_IOCTL(cmd,handler) { (cmd), (ioctl_trans_handler_t)(handler) }, 
166 #define COMPATIBLE_IOCTL(cmd) HANDLE_IOCTL(cmd,sys_ioctl)
167
168 struct ioctl_trans ioctl_start[] = { 
169 #include <linux/compat_ioctl.h>
170 #define DECLARES
171 #include "compat_ioctl.c"
172 COMPATIBLE_IOCTL(HDIO_SET_KEEPSETTINGS)
173 COMPATIBLE_IOCTL(HDIO_SCAN_HWIF)
174 COMPATIBLE_IOCTL(BLKRASET)
175 COMPATIBLE_IOCTL(BLKFRASET)
176 COMPATIBLE_IOCTL(0x4B50)   /* KDGHWCLK - not in the kernel, but don't complain */
177 COMPATIBLE_IOCTL(0x4B51)   /* KDSHWCLK - not in the kernel, but don't complain */
178 #ifdef CONFIG_AUTOFS_FS
179 COMPATIBLE_IOCTL(AUTOFS_IOC_READY)
180 COMPATIBLE_IOCTL(AUTOFS_IOC_FAIL)
181 COMPATIBLE_IOCTL(AUTOFS_IOC_CATATONIC)
182 COMPATIBLE_IOCTL(AUTOFS_IOC_PROTOVER)
183 COMPATIBLE_IOCTL(AUTOFS_IOC_SETTIMEOUT)
184 COMPATIBLE_IOCTL(AUTOFS_IOC_EXPIRE)
185 COMPATIBLE_IOCTL(AUTOFS_IOC_EXPIRE_MULTI)
186 #endif
187 #ifdef CONFIG_RTC
188 COMPATIBLE_IOCTL(RTC_AIE_ON)
189 COMPATIBLE_IOCTL(RTC_AIE_OFF)
190 COMPATIBLE_IOCTL(RTC_UIE_ON)
191 COMPATIBLE_IOCTL(RTC_UIE_OFF)
192 COMPATIBLE_IOCTL(RTC_PIE_ON)
193 COMPATIBLE_IOCTL(RTC_PIE_OFF)
194 COMPATIBLE_IOCTL(RTC_WIE_ON)
195 COMPATIBLE_IOCTL(RTC_WIE_OFF)
196 COMPATIBLE_IOCTL(RTC_ALM_SET)
197 COMPATIBLE_IOCTL(RTC_ALM_READ)
198 COMPATIBLE_IOCTL(RTC_RD_TIME)
199 COMPATIBLE_IOCTL(RTC_SET_TIME)
200 COMPATIBLE_IOCTL(RTC_WKALM_SET)
201 COMPATIBLE_IOCTL(RTC_WKALM_RD)
202 #endif
203 COMPATIBLE_IOCTL(HCIUARTSETPROTO)
204 COMPATIBLE_IOCTL(HCIUARTGETPROTO)
205 COMPATIBLE_IOCTL(RFCOMMCREATEDEV)
206 COMPATIBLE_IOCTL(RFCOMMRELEASEDEV)
207 COMPATIBLE_IOCTL(RFCOMMGETDEVLIST)
208 COMPATIBLE_IOCTL(RFCOMMGETDEVINFO)
209 COMPATIBLE_IOCTL(RFCOMMSTEALDLC)
210 COMPATIBLE_IOCTL(BNEPCONNADD)
211 COMPATIBLE_IOCTL(BNEPCONNDEL)
212 COMPATIBLE_IOCTL(BNEPGETCONNLIST)
213 COMPATIBLE_IOCTL(BNEPGETCONNINFO)
214 COMPATIBLE_IOCTL(FIOQSIZE)
215
216 /* And these ioctls need translation */
217 HANDLE_IOCTL(TIOCGDEV, tiocgdev)
218 /* realtime device */
219 HANDLE_IOCTL(RTC_IRQP_READ,  rtc32_ioctl)
220 HANDLE_IOCTL(RTC_IRQP_READ32,rtc32_ioctl)
221 HANDLE_IOCTL(RTC_IRQP_SET32, rtc32_ioctl)
222 HANDLE_IOCTL(RTC_EPOCH_READ32, rtc32_ioctl)
223 HANDLE_IOCTL(RTC_EPOCH_SET32, rtc32_ioctl)
224 /* take care of sizeof(sizeof()) breakage */
225 /* mtrr */
226 HANDLE_IOCTL(MTRRIOC32_ADD_ENTRY, mtrr_ioctl32)
227 HANDLE_IOCTL(MTRRIOC32_SET_ENTRY, mtrr_ioctl32)
228 HANDLE_IOCTL(MTRRIOC32_DEL_ENTRY, mtrr_ioctl32)
229 HANDLE_IOCTL(MTRRIOC32_GET_ENTRY, mtrr_ioctl32)
230 HANDLE_IOCTL(MTRRIOC32_KILL_ENTRY, mtrr_ioctl32)
231 HANDLE_IOCTL(MTRRIOC32_ADD_PAGE_ENTRY, mtrr_ioctl32)
232 HANDLE_IOCTL(MTRRIOC32_SET_PAGE_ENTRY, mtrr_ioctl32)
233 HANDLE_IOCTL(MTRRIOC32_DEL_PAGE_ENTRY, mtrr_ioctl32)
234 HANDLE_IOCTL(MTRRIOC32_GET_PAGE_ENTRY, mtrr_ioctl32)
235 HANDLE_IOCTL(MTRRIOC32_KILL_PAGE_ENTRY, mtrr_ioctl32)
236 }; 
237
238 int ioctl_table_size = ARRAY_SIZE(ioctl_start);
239