2 * 32bit -> 64bit ioctl helpers
3 * Copyright (c) by Takashi Iwai <tiwai@suse.de>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 * This file registers the converters from 32-bit ioctls to 64-bit ones.
21 * The converter assumes that a 32-bit user-pointer can be casted by A(x)
22 * macro to a valid 64-bit pointer which is accessible via copy_from/to_user.
26 #ifndef __ALSA_IOCTL32_H
27 #define __ALSA_IOCTL32_H
31 #include <asm/ppc32.h>
34 #define A(__x) ((void *)(unsigned long)(__x))
38 #define TO_PTR(x) A(x)
40 #define COPY(x) (dst->x = src->x)
41 #define CPTR(x) (dst->x = (typeof(dst->x))A(src->x))
43 #define convert_from_32(type, dstp, srcp)\
45 struct sndrv_##type *dst = dstp;\
46 struct sndrv_##type##32 *src = srcp;\
47 CVT_##sndrv_##type();\
50 #define convert_to_32(type, dstp, srcp)\
52 struct sndrv_##type *src = srcp;\
53 struct sndrv_##type##32 *dst = dstp;\
54 CVT_##sndrv_##type();\
58 #define DEFINE_ALSA_IOCTL(type) \
59 static int _snd_ioctl32_##type(unsigned int fd, unsigned int cmd, unsigned long arg, struct file *file, unsigned int native_ctl)\
61 struct sndrv_##type##32 data32;\
62 struct sndrv_##type data;\
65 if (copy_from_user(&data32, (void*)arg, sizeof(data32)))\
67 memset(&data, 0, sizeof(data));\
68 convert_from_32(type, &data, &data32);\
71 err = file->f_op->ioctl(file->f_dentry->d_inode, file, native_ctl, (unsigned long)&data);\
75 if (native_ctl & (_IOC_READ << _IOC_DIRSHIFT)) {\
76 convert_to_32(type, &data32, &data);\
77 if (copy_to_user((void*)arg, &data32, sizeof(data32)))\
83 #define DEFINE_ALSA_IOCTL_BIG(type) \
84 static int _snd_ioctl32_##type(unsigned int fd, unsigned int cmd, unsigned long arg, struct file *file, unsigned int native_ctl)\
86 struct sndrv_##type##32 *data32;\
87 struct sndrv_##type *data;\
90 data32 = kmalloc(sizeof(*data32), GFP_KERNEL); \
91 data = kmalloc(sizeof(*data), GFP_KERNEL); \
92 if (data32 == NULL || data == NULL) { \
96 if (copy_from_user(data32, (void*)arg, sizeof(*data32))) { \
100 memset(data, 0, sizeof(*data));\
101 convert_from_32(type, data, data32);\
104 err = file->f_op->ioctl(file->f_dentry->d_inode, file, native_ctl, (unsigned long)data);\
109 if (native_ctl & (_IOC_READ << _IOC_DIRSHIFT)) {\
110 convert_to_32(type, data32, data);\
111 if (copy_to_user((void*)arg, data32, sizeof(*data32)))\
122 #define DEFINE_ALSA_IOCTL_ENTRY(name,type,native_ctl) \
123 static int snd_ioctl32_##name(unsigned int fd, unsigned int cmd, unsigned long arg, struct file *file) {\
124 return _snd_ioctl32_##type(fd, cmd, arg, file, native_ctl);\
127 #define MAP_COMPAT(ctl) { ctl, snd_ioctl32_compat }
129 struct ioctl32_mapper {
131 int (*handler)(unsigned int, unsigned int, unsigned long, struct file * filp);
135 int snd_ioctl32_compat(unsigned int, unsigned int, unsigned long, struct file *);
137 int snd_ioctl32_register(struct ioctl32_mapper *mappers);
138 void snd_ioctl32_unregister(struct ioctl32_mapper *mappers);
140 #endif /* __ALSA_IOCTL32_H */