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.
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
8 * These routines maintain argument size conversion between 32bit and 64bit
13 #include <linux/syscalls.h>
14 #include "compat_ioctl.c"
19 #include "compat_ioctl.c"
22 #define TIOCGDEV _IOR('T',0x32, unsigned int)
24 static int tiocgdev(unsigned fd
, unsigned cmd
, unsigned int __user
*ptr
)
27 struct file
*file
= fget(fd
);
28 struct tty_struct
*real_tty
;
32 if (file
->f_op
->ioctl
!= tty_ioctl
)
34 real_tty
= (struct tty_struct
*)file
->private_data
;
37 return put_user(new_encode_dev(tty_devnum(real_tty
)), ptr
);
40 #define RTC_IRQP_READ32 _IOR('p', 0x0b, unsigned int) /* Read IRQ rate */
41 #define RTC_IRQP_SET32 _IOW('p', 0x0c, unsigned int) /* Set IRQ rate */
42 #define RTC_EPOCH_READ32 _IOR('p', 0x0d, unsigned) /* Read epoch */
43 #define RTC_EPOCH_SET32 _IOW('p', 0x0e, unsigned) /* Set epoch */
45 static int rtc32_ioctl(unsigned fd
, unsigned cmd
, unsigned long arg
)
48 mm_segment_t oldfs
= get_fs();
54 ret
= sys_ioctl(fd
, RTC_IRQP_READ
, (unsigned long)&val
);
57 ret
= put_user(val
, (unsigned int __user
*) arg
);
64 case RTC_EPOCH_READ32
:
66 ret
= sys_ioctl(fd
, RTC_EPOCH_READ
, (unsigned long) &val
);
69 ret
= put_user(val
, (unsigned int __user
*) arg
);
76 return sys_ioctl(fd
,cmd
,arg
);
79 /* /proc/mtrr ioctls */
84 compat_ulong_t base
; /* Base address */
85 compat_uint_t size
; /* Size of region */
86 compat_uint_t type
; /* Type of region */
91 compat_ulong_t regnum
; /* Register number */
92 compat_uint_t base
; /* Base address */
93 compat_uint_t size
; /* Size of region */
94 compat_uint_t type
; /* Type of region */
97 #define MTRR_IOCTL_BASE 'M'
99 #define MTRRIOC32_ADD_ENTRY _IOW(MTRR_IOCTL_BASE, 0, struct mtrr_sentry32)
100 #define MTRRIOC32_SET_ENTRY _IOW(MTRR_IOCTL_BASE, 1, struct mtrr_sentry32)
101 #define MTRRIOC32_DEL_ENTRY _IOW(MTRR_IOCTL_BASE, 2, struct mtrr_sentry32)
102 #define MTRRIOC32_GET_ENTRY _IOWR(MTRR_IOCTL_BASE, 3, struct mtrr_gentry32)
103 #define MTRRIOC32_KILL_ENTRY _IOW(MTRR_IOCTL_BASE, 4, struct mtrr_sentry32)
104 #define MTRRIOC32_ADD_PAGE_ENTRY _IOW(MTRR_IOCTL_BASE, 5, struct mtrr_sentry32)
105 #define MTRRIOC32_SET_PAGE_ENTRY _IOW(MTRR_IOCTL_BASE, 6, struct mtrr_sentry32)
106 #define MTRRIOC32_DEL_PAGE_ENTRY _IOW(MTRR_IOCTL_BASE, 7, struct mtrr_sentry32)
107 #define MTRRIOC32_GET_PAGE_ENTRY _IOWR(MTRR_IOCTL_BASE, 8, struct mtrr_gentry32)
108 #define MTRRIOC32_KILL_PAGE_ENTRY _IOW(MTRR_IOCTL_BASE, 9, struct mtrr_sentry32)
111 static int mtrr_ioctl32(unsigned int fd
, unsigned int cmd
, unsigned long arg
)
113 struct mtrr_gentry g
;
114 struct mtrr_sentry s
;
115 int get
= 0, err
= 0;
116 struct mtrr_gentry32 __user
*g32
= (struct mtrr_gentry32 __user
*)arg
;
117 mm_segment_t oldfs
= get_fs();
120 #define SET(x) case MTRRIOC32_ ## x ## _ENTRY: cmd = MTRRIOC_ ## x ## _ENTRY; break
121 #define GET(x) case MTRRIOC32_ ## x ## _ENTRY: cmd = MTRRIOC_ ## x ## _ENTRY; get=1; break
135 err
= get_user(g
.regnum
, &g32
->regnum
);
136 err
|= get_user(g
.base
, &g32
->base
);
137 err
|= get_user(g
.size
, &g32
->size
);
138 err
|= get_user(g
.type
, &g32
->type
);
140 arg
= (unsigned long)&g
;
142 struct mtrr_sentry32 __user
*s32
= (struct mtrr_sentry32 __user
*)arg
;
143 err
= get_user(s
.base
, &s32
->base
);
144 err
|= get_user(s
.size
, &s32
->size
);
145 err
|= get_user(s
.type
, &s32
->type
);
147 arg
= (unsigned long)&s
;
152 err
= sys_ioctl(fd
, cmd
, arg
);
156 err
= put_user(g
.base
, &g32
->base
);
157 err
|= put_user(g
.size
, &g32
->size
);
158 err
|= put_user(g
.regnum
, &g32
->regnum
);
159 err
|= put_user(g
.type
, &g32
->type
);
164 #define HANDLE_IOCTL(cmd,handler) { (cmd), (ioctl_trans_handler_t)(handler) },
165 #define COMPATIBLE_IOCTL(cmd) HANDLE_IOCTL(cmd,sys_ioctl)
167 struct ioctl_trans ioctl_start
[] = {
168 #include <linux/compat_ioctl.h>
170 #include "compat_ioctl.c"
171 COMPATIBLE_IOCTL(HDIO_SET_KEEPSETTINGS
)
172 COMPATIBLE_IOCTL(HDIO_SCAN_HWIF
)
173 COMPATIBLE_IOCTL(BLKRASET
)
174 COMPATIBLE_IOCTL(0x4B50) /* KDGHWCLK - not in the kernel, but don't complain */
175 COMPATIBLE_IOCTL(0x4B51) /* KDSHWCLK - not in the kernel, but don't complain */
176 COMPATIBLE_IOCTL(FIOQSIZE
)
178 /* And these ioctls need translation */
179 HANDLE_IOCTL(TIOCGDEV
, tiocgdev
)
180 /* realtime device */
181 HANDLE_IOCTL(RTC_IRQP_READ
, rtc32_ioctl
)
182 HANDLE_IOCTL(RTC_IRQP_READ32
,rtc32_ioctl
)
183 HANDLE_IOCTL(RTC_IRQP_SET32
, rtc32_ioctl
)
184 HANDLE_IOCTL(RTC_EPOCH_READ32
, rtc32_ioctl
)
185 HANDLE_IOCTL(RTC_EPOCH_SET32
, rtc32_ioctl
)
186 /* take care of sizeof(sizeof()) breakage */
188 HANDLE_IOCTL(MTRRIOC32_ADD_ENTRY
, mtrr_ioctl32
)
189 HANDLE_IOCTL(MTRRIOC32_SET_ENTRY
, mtrr_ioctl32
)
190 HANDLE_IOCTL(MTRRIOC32_DEL_ENTRY
, mtrr_ioctl32
)
191 HANDLE_IOCTL(MTRRIOC32_GET_ENTRY
, mtrr_ioctl32
)
192 HANDLE_IOCTL(MTRRIOC32_KILL_ENTRY
, mtrr_ioctl32
)
193 HANDLE_IOCTL(MTRRIOC32_ADD_PAGE_ENTRY
, mtrr_ioctl32
)
194 HANDLE_IOCTL(MTRRIOC32_SET_PAGE_ENTRY
, mtrr_ioctl32
)
195 HANDLE_IOCTL(MTRRIOC32_DEL_PAGE_ENTRY
, mtrr_ioctl32
)
196 HANDLE_IOCTL(MTRRIOC32_GET_PAGE_ENTRY
, mtrr_ioctl32
)
197 HANDLE_IOCTL(MTRRIOC32_KILL_PAGE_ENTRY
, mtrr_ioctl32
)
200 int ioctl_table_size
= ARRAY_SIZE(ioctl_start
);