2 * 32bit -> 64bit ioctl wrapper for raw MIDI API
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
21 /* This file included from rawmidi.c */
23 #include <linux/compat.h>
25 struct snd_rawmidi_params32
{
29 unsigned int no_active_sensing
; /* avoid bit-field */
30 unsigned char reserved
[16];
31 } __attribute__((packed
));
33 static int snd_rawmidi_ioctl_params_compat(struct snd_rawmidi_file
*rfile
,
34 struct snd_rawmidi_params32 __user
*src
)
36 struct snd_rawmidi_params params
;
39 if (rfile
->output
== NULL
)
41 if (get_user(params
.stream
, &src
->stream
) ||
42 get_user(params
.buffer_size
, &src
->buffer_size
) ||
43 get_user(params
.avail_min
, &src
->avail_min
) ||
44 get_user(val
, &src
->no_active_sensing
))
46 params
.no_active_sensing
= val
;
47 switch (params
.stream
) {
48 case SNDRV_RAWMIDI_STREAM_OUTPUT
:
49 return snd_rawmidi_output_params(rfile
->output
, ¶ms
);
50 case SNDRV_RAWMIDI_STREAM_INPUT
:
51 return snd_rawmidi_input_params(rfile
->input
, ¶ms
);
56 struct snd_rawmidi_status32
{
58 struct compat_timespec tstamp
;
61 unsigned char reserved
[16];
62 } __attribute__((packed
));
64 static int snd_rawmidi_ioctl_status_compat(struct snd_rawmidi_file
*rfile
,
65 struct snd_rawmidi_status32 __user
*src
)
68 struct snd_rawmidi_status status
;
70 if (rfile
->output
== NULL
)
72 if (get_user(status
.stream
, &src
->stream
))
75 switch (status
.stream
) {
76 case SNDRV_RAWMIDI_STREAM_OUTPUT
:
77 err
= snd_rawmidi_output_status(rfile
->output
, &status
);
79 case SNDRV_RAWMIDI_STREAM_INPUT
:
80 err
= snd_rawmidi_input_status(rfile
->input
, &status
);
88 if (put_user(status
.tstamp
.tv_sec
, &src
->tstamp
.tv_sec
) ||
89 put_user(status
.tstamp
.tv_nsec
, &src
->tstamp
.tv_nsec
) ||
90 put_user(status
.avail
, &src
->avail
) ||
91 put_user(status
.xruns
, &src
->xruns
))
98 /* X32 ABI has 64bit timespec and 64bit alignment */
99 struct snd_rawmidi_status_x32
{
101 u32 rsvd
; /* alignment */
102 struct timespec tstamp
;
105 unsigned char reserved
[16];
106 } __attribute__((packed
));
108 #define put_timespec(src, dst) copy_to_user(dst, src, sizeof(*dst))
110 static int snd_rawmidi_ioctl_status_x32(struct snd_rawmidi_file
*rfile
,
111 struct snd_rawmidi_status_x32 __user
*src
)
114 struct snd_rawmidi_status status
;
116 if (rfile
->output
== NULL
)
118 if (get_user(status
.stream
, &src
->stream
))
121 switch (status
.stream
) {
122 case SNDRV_RAWMIDI_STREAM_OUTPUT
:
123 err
= snd_rawmidi_output_status(rfile
->output
, &status
);
125 case SNDRV_RAWMIDI_STREAM_INPUT
:
126 err
= snd_rawmidi_input_status(rfile
->input
, &status
);
134 if (put_timespec(&status
.tstamp
, &src
->tstamp
) ||
135 put_user(status
.avail
, &src
->avail
) ||
136 put_user(status
.xruns
, &src
->xruns
))
141 #endif /* CONFIG_X86_X32 */
144 SNDRV_RAWMIDI_IOCTL_PARAMS32
= _IOWR('W', 0x10, struct snd_rawmidi_params32
),
145 SNDRV_RAWMIDI_IOCTL_STATUS32
= _IOWR('W', 0x20, struct snd_rawmidi_status32
),
146 #ifdef CONFIG_X86_X32
147 SNDRV_RAWMIDI_IOCTL_STATUS_X32
= _IOWR('W', 0x20, struct snd_rawmidi_status_x32
),
148 #endif /* CONFIG_X86_X32 */
151 static long snd_rawmidi_ioctl_compat(struct file
*file
, unsigned int cmd
, unsigned long arg
)
153 struct snd_rawmidi_file
*rfile
;
154 void __user
*argp
= compat_ptr(arg
);
156 rfile
= file
->private_data
;
158 case SNDRV_RAWMIDI_IOCTL_PVERSION
:
159 case SNDRV_RAWMIDI_IOCTL_INFO
:
160 case SNDRV_RAWMIDI_IOCTL_DROP
:
161 case SNDRV_RAWMIDI_IOCTL_DRAIN
:
162 return snd_rawmidi_ioctl(file
, cmd
, (unsigned long)argp
);
163 case SNDRV_RAWMIDI_IOCTL_PARAMS32
:
164 return snd_rawmidi_ioctl_params_compat(rfile
, argp
);
165 case SNDRV_RAWMIDI_IOCTL_STATUS32
:
166 return snd_rawmidi_ioctl_status_compat(rfile
, argp
);
167 #ifdef CONFIG_X86_X32
168 case SNDRV_RAWMIDI_IOCTL_STATUS_X32
:
169 return snd_rawmidi_ioctl_status_x32(rfile
, argp
);
170 #endif /* CONFIG_X86_X32 */