ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / sound / core / ioctl32 / hwdep32.c
1 /*
2  *   32bit -> 64bit ioctl wrapper for hwdep API
3  *   Copyright (c) by Takashi Iwai <tiwai@suse.de>
4  *
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.
9  *
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.
14  *
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
18  *
19  */
20
21 #include <sound/driver.h>
22 #include <linux/time.h>
23 #include <linux/fs.h>
24 #include <sound/core.h>
25 #include <sound/hwdep.h>
26 #include <asm/uaccess.h>
27 #include "ioctl32.h"
28
29 struct sndrv_hwdep_dsp_image32 {
30         u32 index;
31         unsigned char name[64];
32         u32 image;      /* pointer */
33         u32 length;
34         u32 driver_data;
35 } /* don't set packed attribute here */;
36
37 static int _snd_ioctl32_hwdep_dsp_image(unsigned int fd, unsigned int cmd, unsigned long arg, struct file *file, unsigned int native_ctl)
38 {
39         struct sndrv_hwdep_dsp_image data;
40         struct sndrv_hwdep_dsp_image data32;
41         mm_segment_t oldseg;
42         int err;
43
44         if (copy_from_user(&data32, (void*)arg, sizeof(data32)))
45                 return -EFAULT;
46         memset(&data, 0, sizeof(data));
47         data.index = data32.index;
48         memcpy(data.name, data32.name, sizeof(data.name));
49         data.image = A(data32.image);
50         data.length = data32.length;
51         data.driver_data = data32.driver_data;
52         oldseg = get_fs();
53         set_fs(KERNEL_DS);
54         err = file->f_op->ioctl(file->f_dentry->d_inode, file, native_ctl, (unsigned long)&data);
55         set_fs(oldseg);
56         return err;
57 }
58
59 DEFINE_ALSA_IOCTL_ENTRY(hwdep_dsp_image, hwdep_dsp_image, SNDRV_HWDEP_IOCTL_DSP_LOAD);
60
61 #define AP(x) snd_ioctl32_##x
62
63 enum {
64         SNDRV_HWDEP_IOCTL_DSP_LOAD32   = _IOW('H', 0x03, struct sndrv_hwdep_dsp_image32)
65 };
66
67 struct ioctl32_mapper hwdep_mappers[] = {
68         MAP_COMPAT(SNDRV_HWDEP_IOCTL_PVERSION),
69         MAP_COMPAT(SNDRV_HWDEP_IOCTL_INFO),
70         MAP_COMPAT(SNDRV_HWDEP_IOCTL_DSP_STATUS),
71         { SNDRV_HWDEP_IOCTL_DSP_LOAD32, AP(hwdep_dsp_image) },
72         { 0 },
73 };