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)
28 struct tty_struct *real_tty;
31 file = fget_light(fd, &fput_needed);
36 if (file->f_op->ioctl != tty_ioctl)
38 real_tty = (struct tty_struct *)file->private_data;
42 ret = put_user(new_encode_dev(tty_devnum(real_tty)), ptr);
45 fput_light(file, fput_needed);
49 #define RTC_IRQP_READ32 _IOR('p', 0x0b, unsigned int) /* Read IRQ rate */
50 #define RTC_IRQP_SET32 _IOW('p', 0x0c, unsigned int) /* Set IRQ rate */
51 #define RTC_EPOCH_READ32 _IOR('p', 0x0d, unsigned) /* Read epoch */
52 #define RTC_EPOCH_SET32 _IOW('p', 0x0e, unsigned) /* Set epoch */
54 static int rtc32_ioctl(unsigned fd, unsigned cmd, unsigned long arg)
57 mm_segment_t oldfs = get_fs();
63 ret = sys_ioctl(fd, RTC_IRQP_READ, (unsigned long)&val);
66 ret = put_user(val, (unsigned int __user *) arg);
73 case RTC_EPOCH_READ32:
75 ret = sys_ioctl(fd, RTC_EPOCH_READ, (unsigned long) &val);
78 ret = put_user(val, (unsigned int __user *) arg);
85 return sys_ioctl(fd,cmd,arg);
88 /* /proc/mtrr ioctls */
93 compat_ulong_t base; /* Base address */
94 compat_uint_t size; /* Size of region */
95 compat_uint_t type; /* Type of region */
100 compat_ulong_t regnum; /* Register number */
101 compat_uint_t base; /* Base address */
102 compat_uint_t size; /* Size of region */
103 compat_uint_t type; /* Type of region */
106 #define MTRR_IOCTL_BASE 'M'
108 #define MTRRIOC32_ADD_ENTRY _IOW(MTRR_IOCTL_BASE, 0, struct mtrr_sentry32)
109 #define MTRRIOC32_SET_ENTRY _IOW(MTRR_IOCTL_BASE, 1, struct mtrr_sentry32)
110 #define MTRRIOC32_DEL_ENTRY _IOW(MTRR_IOCTL_BASE, 2, struct mtrr_sentry32)
111 #define MTRRIOC32_GET_ENTRY _IOWR(MTRR_IOCTL_BASE, 3, struct mtrr_gentry32)
112 #define MTRRIOC32_KILL_ENTRY _IOW(MTRR_IOCTL_BASE, 4, struct mtrr_sentry32)
113 #define MTRRIOC32_ADD_PAGE_ENTRY _IOW(MTRR_IOCTL_BASE, 5, struct mtrr_sentry32)
114 #define MTRRIOC32_SET_PAGE_ENTRY _IOW(MTRR_IOCTL_BASE, 6, struct mtrr_sentry32)
115 #define MTRRIOC32_DEL_PAGE_ENTRY _IOW(MTRR_IOCTL_BASE, 7, struct mtrr_sentry32)
116 #define MTRRIOC32_GET_PAGE_ENTRY _IOWR(MTRR_IOCTL_BASE, 8, struct mtrr_gentry32)
117 #define MTRRIOC32_KILL_PAGE_ENTRY _IOW(MTRR_IOCTL_BASE, 9, struct mtrr_sentry32)
120 static int mtrr_ioctl32(unsigned int fd, unsigned int cmd, unsigned long arg)
122 struct mtrr_gentry g;
123 struct mtrr_sentry s;
124 int get = 0, err = 0;
125 struct mtrr_gentry32 __user *g32 = (struct mtrr_gentry32 __user *)arg;
126 mm_segment_t oldfs = get_fs();
129 #define SET(x) case MTRRIOC32_ ## x ## _ENTRY: cmd = MTRRIOC_ ## x ## _ENTRY; break
130 #define GET(x) case MTRRIOC32_ ## x ## _ENTRY: cmd = MTRRIOC_ ## x ## _ENTRY; get=1; break
144 err = get_user(g.regnum, &g32->regnum);
145 err |= get_user(g.base, &g32->base);
146 err |= get_user(g.size, &g32->size);
147 err |= get_user(g.type, &g32->type);
149 arg = (unsigned long)&g;
151 struct mtrr_sentry32 __user *s32 = (struct mtrr_sentry32 __user *)arg;
152 err = get_user(s.base, &s32->base);
153 err |= get_user(s.size, &s32->size);
154 err |= get_user(s.type, &s32->type);
156 arg = (unsigned long)&s;
161 err = sys_ioctl(fd, cmd, arg);
165 err = put_user(g.base, &g32->base);
166 err |= put_user(g.size, &g32->size);
167 err |= put_user(g.regnum, &g32->regnum);
168 err |= put_user(g.type, &g32->type);
173 #define HANDLE_IOCTL(cmd,handler) { (cmd), (ioctl_trans_handler_t)(handler) },
174 #define COMPATIBLE_IOCTL(cmd) HANDLE_IOCTL(cmd,sys_ioctl)
176 struct ioctl_trans ioctl_start[] = {
177 #include <linux/compat_ioctl.h>
179 #include "compat_ioctl.c"
180 COMPATIBLE_IOCTL(HDIO_SET_KEEPSETTINGS)
181 COMPATIBLE_IOCTL(HDIO_SCAN_HWIF)
182 COMPATIBLE_IOCTL(BLKRASET)
183 COMPATIBLE_IOCTL(0x4B50) /* KDGHWCLK - not in the kernel, but don't complain */
184 COMPATIBLE_IOCTL(0x4B51) /* KDSHWCLK - not in the kernel, but don't complain */
185 COMPATIBLE_IOCTL(FIOQSIZE)
187 /* And these ioctls need translation */
188 HANDLE_IOCTL(TIOCGDEV, tiocgdev)
189 /* realtime device */
190 HANDLE_IOCTL(RTC_IRQP_READ, rtc32_ioctl)
191 HANDLE_IOCTL(RTC_IRQP_READ32,rtc32_ioctl)
192 HANDLE_IOCTL(RTC_IRQP_SET32, rtc32_ioctl)
193 HANDLE_IOCTL(RTC_EPOCH_READ32, rtc32_ioctl)
194 HANDLE_IOCTL(RTC_EPOCH_SET32, rtc32_ioctl)
195 /* take care of sizeof(sizeof()) breakage */
197 HANDLE_IOCTL(MTRRIOC32_ADD_ENTRY, mtrr_ioctl32)
198 HANDLE_IOCTL(MTRRIOC32_SET_ENTRY, mtrr_ioctl32)
199 HANDLE_IOCTL(MTRRIOC32_DEL_ENTRY, mtrr_ioctl32)
200 HANDLE_IOCTL(MTRRIOC32_GET_ENTRY, mtrr_ioctl32)
201 HANDLE_IOCTL(MTRRIOC32_KILL_ENTRY, mtrr_ioctl32)
202 HANDLE_IOCTL(MTRRIOC32_ADD_PAGE_ENTRY, mtrr_ioctl32)
203 HANDLE_IOCTL(MTRRIOC32_SET_PAGE_ENTRY, mtrr_ioctl32)
204 HANDLE_IOCTL(MTRRIOC32_DEL_PAGE_ENTRY, mtrr_ioctl32)
205 HANDLE_IOCTL(MTRRIOC32_GET_PAGE_ENTRY, mtrr_ioctl32)
206 HANDLE_IOCTL(MTRRIOC32_KILL_PAGE_ENTRY, mtrr_ioctl32)
209 int ioctl_table_size = ARRAY_SIZE(ioctl_start);