kbuild: fix silentoldconfig with make O=
[linux-2.6/verdex.git] / arch / x86_64 / ia32 / ia32_ioctl.c
blob419758f19ca4f4ec4da887da494b89f397f149c7
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
9 * ioctls.
12 #define INCLUDES
13 #include <linux/syscalls.h>
14 #include "compat_ioctl.c"
15 #include <asm/mtrr.h>
16 #include <asm/ia32.h>
18 #define CODE
19 #include "compat_ioctl.c"
21 #ifndef TIOCGDEV
22 #define TIOCGDEV _IOR('T',0x32, unsigned int)
23 #endif
24 static int tiocgdev(unsigned fd, unsigned cmd, unsigned int __user *ptr)
27 struct file *file;
28 struct tty_struct *real_tty;
29 int fput_needed, ret;
31 file = fget_light(fd, &fput_needed);
32 if (!file)
33 return -EBADF;
35 ret = -EINVAL;
36 if (file->f_op->ioctl != tty_ioctl)
37 goto out;
38 real_tty = (struct tty_struct *)file->private_data;
39 if (!real_tty)
40 goto out;
42 ret = put_user(new_encode_dev(tty_devnum(real_tty)), ptr);
44 out:
45 fput_light(file, fput_needed);
46 return ret;
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)
56 unsigned long val;
57 mm_segment_t oldfs = get_fs();
58 int ret;
60 switch (cmd) {
61 case RTC_IRQP_READ32:
62 set_fs(KERNEL_DS);
63 ret = sys_ioctl(fd, RTC_IRQP_READ, (unsigned long)&val);
64 set_fs(oldfs);
65 if (!ret)
66 ret = put_user(val, (unsigned int __user *) arg);
67 return ret;
69 case RTC_IRQP_SET32:
70 cmd = RTC_IRQP_SET;
71 break;
73 case RTC_EPOCH_READ32:
74 set_fs(KERNEL_DS);
75 ret = sys_ioctl(fd, RTC_EPOCH_READ, (unsigned long) &val);
76 set_fs(oldfs);
77 if (!ret)
78 ret = put_user(val, (unsigned int __user *) arg);
79 return ret;
81 case RTC_EPOCH_SET32:
82 cmd = RTC_EPOCH_SET;
83 break;
85 return sys_ioctl(fd,cmd,arg);
88 /* /proc/mtrr ioctls */
91 struct mtrr_sentry32
93 compat_ulong_t base; /* Base address */
94 compat_uint_t size; /* Size of region */
95 compat_uint_t type; /* Type of region */
98 struct mtrr_gentry32
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();
128 switch (cmd) {
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
131 SET(ADD);
132 SET(SET);
133 SET(DEL);
134 GET(GET);
135 SET(KILL);
136 SET(ADD_PAGE);
137 SET(SET_PAGE);
138 SET(DEL_PAGE);
139 GET(GET_PAGE);
140 SET(KILL_PAGE);
143 if (get) {
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;
150 } else {
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;
158 if (err) return err;
160 set_fs(KERNEL_DS);
161 err = sys_ioctl(fd, cmd, arg);
162 set_fs(oldfs);
164 if (!err && get) {
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);
170 return err;
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>
178 #define DECLARES
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 */
196 /* mtrr */
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);