2 * 32bit -> 64bit ioctl wrapper for PCM 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 pcm_native.c */
23 #include <linux/compat.h>
25 static int snd_pcm_ioctl_delay_compat(snd_pcm_substream_t
*substream
,
28 snd_pcm_sframes_t delay
;
32 fs
= snd_enter_user();
33 err
= snd_pcm_delay(substream
, &delay
);
37 if (put_user(delay
, src
))
42 static int snd_pcm_ioctl_rewind_compat(snd_pcm_substream_t
*substream
,
45 snd_pcm_uframes_t frames
;
48 if (get_user(frames
, src
))
50 if (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
)
51 err
= snd_pcm_playback_rewind(substream
, frames
);
53 err
= snd_pcm_capture_rewind(substream
, frames
);
54 if (put_user(err
, src
))
56 return err
< 0 ? err
: 0;
59 static int snd_pcm_ioctl_forward_compat(snd_pcm_substream_t
*substream
,
62 snd_pcm_uframes_t frames
;
65 if (get_user(frames
, src
))
67 if (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
)
68 err
= snd_pcm_playback_forward(substream
, frames
);
70 err
= snd_pcm_capture_forward(substream
, frames
);
71 if (put_user(err
, src
))
73 return err
< 0 ? err
: 0;
76 struct sndrv_pcm_hw_params32
{
78 struct sndrv_mask masks
[SNDRV_PCM_HW_PARAM_LAST_MASK
- SNDRV_PCM_HW_PARAM_FIRST_MASK
+ 1]; /* this must be identical */
79 struct sndrv_mask mres
[5]; /* reserved masks */
80 struct sndrv_interval intervals
[SNDRV_PCM_HW_PARAM_LAST_INTERVAL
- SNDRV_PCM_HW_PARAM_FIRST_INTERVAL
+ 1];
81 struct sndrv_interval ires
[9]; /* reserved intervals */
89 unsigned char reserved
[64];
92 struct sndrv_pcm_sw_params32
{
100 u32 silence_threshold
;
103 unsigned char reserved
[64];
106 static int snd_pcm_ioctl_sw_params_compat(snd_pcm_substream_t
*substream
,
107 struct sndrv_pcm_sw_params32 __user
*src
)
109 snd_pcm_sw_params_t params
;
112 memset(¶ms
, 0, sizeof(params
));
113 if (get_user(params
.tstamp_mode
, &src
->tstamp_mode
) ||
114 get_user(params
.period_step
, &src
->period_step
) ||
115 get_user(params
.sleep_min
, &src
->sleep_min
) ||
116 get_user(params
.avail_min
, &src
->avail_min
) ||
117 get_user(params
.xfer_align
, &src
->xfer_align
) ||
118 get_user(params
.start_threshold
, &src
->start_threshold
) ||
119 get_user(params
.stop_threshold
, &src
->stop_threshold
) ||
120 get_user(params
.silence_threshold
, &src
->silence_threshold
) ||
121 get_user(params
.silence_size
, &src
->silence_size
))
123 err
= snd_pcm_sw_params(substream
, ¶ms
);
126 if (put_user(params
.boundary
, &src
->boundary
))
131 struct sndrv_pcm_channel_info32
{
138 static int snd_pcm_ioctl_channel_info_compat(snd_pcm_substream_t
*substream
,
139 struct sndrv_pcm_channel_info32 __user
*src
)
141 snd_pcm_channel_info_t info
;
144 if (get_user(info
.channel
, &src
->channel
) ||
145 get_user(info
.offset
, &src
->offset
) ||
146 get_user(info
.first
, &src
->first
) ||
147 get_user(info
.step
, &src
->step
))
149 err
= snd_pcm_channel_info(substream
, &info
);
152 if (put_user(info
.channel
, &src
->channel
) ||
153 put_user(info
.offset
, &src
->offset
) ||
154 put_user(info
.first
, &src
->first
) ||
155 put_user(info
.step
, &src
->step
))
160 struct sndrv_pcm_status32
{
162 struct compat_timespec trigger_tstamp
;
163 struct compat_timespec tstamp
;
171 unsigned char reserved
[60];
172 } __attribute__((packed
));
175 static int snd_pcm_status_user_compat(snd_pcm_substream_t
*substream
,
176 struct sndrv_pcm_status32 __user
*src
)
178 snd_pcm_status_t status
;
181 err
= snd_pcm_status(substream
, &status
);
185 if (put_user(status
.state
, &src
->state
) ||
186 put_user(status
.trigger_tstamp
.tv_sec
, &src
->trigger_tstamp
.tv_sec
) ||
187 put_user(status
.trigger_tstamp
.tv_nsec
, &src
->trigger_tstamp
.tv_nsec
) ||
188 put_user(status
.tstamp
.tv_sec
, &src
->tstamp
.tv_sec
) ||
189 put_user(status
.tstamp
.tv_nsec
, &src
->tstamp
.tv_nsec
) ||
190 put_user(status
.appl_ptr
, &src
->appl_ptr
) ||
191 put_user(status
.hw_ptr
, &src
->hw_ptr
) ||
192 put_user(status
.delay
, &src
->delay
) ||
193 put_user(status
.avail
, &src
->avail
) ||
194 put_user(status
.avail_max
, &src
->avail_max
) ||
195 put_user(status
.overrange
, &src
->overrange
) ||
196 put_user(status
.suspended_state
, &src
->suspended_state
))
202 /* recalcuate the boundary within 32bit */
203 static void recalculate_boundary(snd_pcm_runtime_t
*runtime
)
205 if (! runtime
->buffer_size
)
207 runtime
->boundary
= runtime
->buffer_size
;
208 while (runtime
->boundary
* 2 <= 0x7fffffffUL
- runtime
->buffer_size
)
209 runtime
->boundary
*= 2;
212 /* both for HW_PARAMS and HW_REFINE */
213 static int snd_pcm_ioctl_hw_params_compat(snd_pcm_substream_t
*substream
,
215 struct sndrv_pcm_hw_params32 __user
*data32
)
217 struct sndrv_pcm_hw_params
*data
;
218 snd_pcm_runtime_t
*runtime
;
221 if (! (runtime
= substream
->runtime
))
224 data
= kmalloc(sizeof(*data
), GFP_KERNEL
);
227 /* only fifo_size is different, so just copy all */
228 if (copy_from_user(data
, data32
, sizeof(*data32
))) {
233 err
= snd_pcm_hw_refine(substream
, data
);
235 err
= snd_pcm_hw_params(substream
, data
);
238 if (copy_to_user(data32
, data
, sizeof(*data32
)) ||
239 put_user(data
->fifo_size
, &data32
->fifo_size
)) {
245 recalculate_boundary(runtime
);
254 struct sndrv_xferi32
{
260 static int snd_pcm_ioctl_xferi_compat(snd_pcm_substream_t
*substream
,
261 int dir
, struct sndrv_xferi32 __user
*data32
)
267 if (! substream
->runtime
)
269 if (substream
->stream
!= dir
)
271 if (substream
->runtime
->status
->state
== SNDRV_PCM_STATE_OPEN
)
274 if (get_user(buf
, &data32
->buf
) ||
275 get_user(frames
, &data32
->frames
))
278 if (dir
== SNDRV_PCM_STREAM_PLAYBACK
)
279 err
= snd_pcm_lib_write(substream
, compat_ptr(buf
), frames
);
281 err
= snd_pcm_lib_read(substream
, compat_ptr(buf
), frames
);
284 /* copy the result */
285 if (put_user(err
, &data32
->result
))
291 /* snd_xfern needs remapping of bufs */
292 struct sndrv_xfern32
{
294 u32 bufs
; /* this is void **; */
299 * xfern ioctl nees to copy (up to) 128 pointers on stack.
300 * although we may pass the copied pointers through f_op->ioctl, but the ioctl
301 * handler there expands again the same 128 pointers on stack, so it is better
302 * to handle the function (calling pcm_readv/writev) directly in this handler.
304 static int snd_pcm_ioctl_xfern_compat(snd_pcm_substream_t
*substream
,
305 int dir
, struct sndrv_xfern32 __user
*data32
)
308 compat_caddr_t __user
*bufptr
;
313 if (! substream
->runtime
)
315 if (substream
->stream
!= dir
)
318 if ((ch
= substream
->runtime
->channels
) > 128)
320 if (get_user(buf
, &data32
->bufs
) ||
321 get_user(frames
, &data32
->frames
))
323 bufptr
= compat_ptr(buf
);
324 bufs
= kmalloc(sizeof(void __user
*) * ch
, GFP_KERNEL
);
327 for (i
= 0; i
< ch
; i
++) {
329 if (get_user(ptr
, bufptr
)) {
333 bufs
[ch
] = compat_ptr(ptr
);
336 if (dir
== SNDRV_PCM_STREAM_PLAYBACK
)
337 err
= snd_pcm_lib_writev(substream
, bufs
, frames
);
339 err
= snd_pcm_lib_readv(substream
, bufs
, frames
);
341 if (put_user(err
, &data32
->result
))
349 struct sndrv_pcm_mmap_status32
{
353 struct compat_timespec tstamp
;
355 } __attribute__((packed
));
357 struct sndrv_pcm_mmap_control32
{
362 struct sndrv_pcm_sync_ptr32
{
365 struct sndrv_pcm_mmap_status32 status
;
366 unsigned char reserved
[64];
369 struct sndrv_pcm_mmap_control32 control
;
370 unsigned char reserved
[64];
372 } __attribute__((packed
));
374 static int snd_pcm_ioctl_sync_ptr_compat(snd_pcm_substream_t
*substream
,
375 struct sndrv_pcm_sync_ptr32 __user
*src
)
377 snd_pcm_runtime_t
*runtime
= substream
->runtime
;
378 volatile struct sndrv_pcm_mmap_status
*status
;
379 volatile struct sndrv_pcm_mmap_control
*control
;
381 struct sndrv_pcm_mmap_control scontrol
;
382 struct sndrv_pcm_mmap_status sstatus
;
385 snd_assert(runtime
, return -EINVAL
);
387 if (get_user(sflags
, &src
->flags
) ||
388 get_user(scontrol
.appl_ptr
, &src
->c
.control
.appl_ptr
) ||
389 get_user(scontrol
.avail_min
, &src
->c
.control
.avail_min
))
391 if (sflags
& SNDRV_PCM_SYNC_PTR_HWSYNC
) {
392 err
= snd_pcm_hwsync(substream
);
396 status
= runtime
->status
;
397 control
= runtime
->control
;
398 snd_pcm_stream_lock_irq(substream
);
399 if (!(sflags
& SNDRV_PCM_SYNC_PTR_APPL
))
400 control
->appl_ptr
= scontrol
.appl_ptr
;
402 scontrol
.appl_ptr
= control
->appl_ptr
;
403 if (!(sflags
& SNDRV_PCM_SYNC_PTR_AVAIL_MIN
))
404 control
->avail_min
= scontrol
.avail_min
;
406 scontrol
.avail_min
= control
->avail_min
;
407 sstatus
.state
= status
->state
;
408 sstatus
.hw_ptr
= status
->hw_ptr
;
409 sstatus
.tstamp
= status
->tstamp
;
410 sstatus
.suspended_state
= status
->suspended_state
;
411 snd_pcm_stream_unlock_irq(substream
);
412 if (put_user(sstatus
.state
, &src
->s
.status
.state
) ||
413 put_user(sstatus
.hw_ptr
, &src
->s
.status
.hw_ptr
) ||
414 put_user(sstatus
.tstamp
.tv_sec
, &src
->s
.status
.tstamp
.tv_sec
) ||
415 put_user(sstatus
.tstamp
.tv_nsec
, &src
->s
.status
.tstamp
.tv_nsec
) ||
416 put_user(sstatus
.suspended_state
, &src
->s
.status
.suspended_state
) ||
417 put_user(scontrol
.appl_ptr
, &src
->c
.control
.appl_ptr
) ||
418 put_user(scontrol
.avail_min
, &src
->c
.control
.avail_min
))
428 SNDRV_PCM_IOCTL_HW_REFINE32
= _IOWR('A', 0x10, struct sndrv_pcm_hw_params32
),
429 SNDRV_PCM_IOCTL_HW_PARAMS32
= _IOWR('A', 0x11, struct sndrv_pcm_hw_params32
),
430 SNDRV_PCM_IOCTL_SW_PARAMS32
= _IOWR('A', 0x13, struct sndrv_pcm_sw_params32
),
431 SNDRV_PCM_IOCTL_STATUS32
= _IOR('A', 0x20, struct sndrv_pcm_status32
),
432 SNDRV_PCM_IOCTL_DELAY32
= _IOR('A', 0x21, s32
),
433 SNDRV_PCM_IOCTL_CHANNEL_INFO32
= _IOR('A', 0x32, struct sndrv_pcm_channel_info32
),
434 SNDRV_PCM_IOCTL_REWIND32
= _IOW('A', 0x46, u32
),
435 SNDRV_PCM_IOCTL_FORWARD32
= _IOW('A', 0x49, u32
),
436 SNDRV_PCM_IOCTL_WRITEI_FRAMES32
= _IOW('A', 0x50, struct sndrv_xferi32
),
437 SNDRV_PCM_IOCTL_READI_FRAMES32
= _IOR('A', 0x51, struct sndrv_xferi32
),
438 SNDRV_PCM_IOCTL_WRITEN_FRAMES32
= _IOW('A', 0x52, struct sndrv_xfern32
),
439 SNDRV_PCM_IOCTL_READN_FRAMES32
= _IOR('A', 0x53, struct sndrv_xfern32
),
440 SNDRV_PCM_IOCTL_SYNC_PTR32
= _IOWR('A', 0x23, struct sndrv_pcm_sync_ptr32
),
444 static long snd_pcm_ioctl_compat(struct file
*file
, unsigned int cmd
, unsigned long arg
)
446 snd_pcm_file_t
*pcm_file
;
447 snd_pcm_substream_t
*substream
;
448 void __user
*argp
= compat_ptr(arg
);
450 pcm_file
= file
->private_data
;
453 substream
= pcm_file
->substream
;
458 * When PCM is used on 32bit mode, we need to disable
459 * mmap of PCM status/control records because of the size
462 substream
->no_mmap_ctrl
= 1;
465 case SNDRV_PCM_IOCTL_PVERSION
:
466 case SNDRV_PCM_IOCTL_INFO
:
467 case SNDRV_PCM_IOCTL_TSTAMP
:
468 case SNDRV_PCM_IOCTL_HWSYNC
:
469 case SNDRV_PCM_IOCTL_PREPARE
:
470 case SNDRV_PCM_IOCTL_RESET
:
471 case SNDRV_PCM_IOCTL_START
:
472 case SNDRV_PCM_IOCTL_DROP
:
473 case SNDRV_PCM_IOCTL_DRAIN
:
474 case SNDRV_PCM_IOCTL_PAUSE
:
475 case SNDRV_PCM_IOCTL_HW_FREE
:
476 case SNDRV_PCM_IOCTL_RESUME
:
477 case SNDRV_PCM_IOCTL_XRUN
:
478 case SNDRV_PCM_IOCTL_LINK
:
479 case SNDRV_PCM_IOCTL_UNLINK
:
480 if (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
)
481 return snd_pcm_playback_ioctl1(substream
, cmd
, argp
);
483 return snd_pcm_capture_ioctl1(substream
, cmd
, argp
);
484 case SNDRV_PCM_IOCTL_HW_REFINE32
:
485 return snd_pcm_ioctl_hw_params_compat(substream
, 1, argp
);
486 case SNDRV_PCM_IOCTL_HW_PARAMS32
:
487 return snd_pcm_ioctl_hw_params_compat(substream
, 0, argp
);
488 case SNDRV_PCM_IOCTL_SW_PARAMS32
:
489 return snd_pcm_ioctl_sw_params_compat(substream
, argp
);
490 case SNDRV_PCM_IOCTL_STATUS32
:
491 return snd_pcm_status_user_compat(substream
, argp
);
492 case SNDRV_PCM_IOCTL_SYNC_PTR32
:
493 return snd_pcm_ioctl_sync_ptr_compat(substream
, argp
);
494 case SNDRV_PCM_IOCTL_CHANNEL_INFO32
:
495 return snd_pcm_ioctl_channel_info_compat(substream
, argp
);
496 case SNDRV_PCM_IOCTL_WRITEI_FRAMES32
:
497 return snd_pcm_ioctl_xferi_compat(substream
, SNDRV_PCM_STREAM_PLAYBACK
, argp
);
498 case SNDRV_PCM_IOCTL_READI_FRAMES32
:
499 return snd_pcm_ioctl_xferi_compat(substream
, SNDRV_PCM_STREAM_CAPTURE
, argp
);
500 case SNDRV_PCM_IOCTL_WRITEN_FRAMES32
:
501 return snd_pcm_ioctl_xfern_compat(substream
, SNDRV_PCM_STREAM_PLAYBACK
, argp
);
502 case SNDRV_PCM_IOCTL_READN_FRAMES32
:
503 return snd_pcm_ioctl_xfern_compat(substream
, SNDRV_PCM_STREAM_CAPTURE
, argp
);
504 case SNDRV_PCM_IOCTL_DELAY32
:
505 return snd_pcm_ioctl_delay_compat(substream
, argp
);
506 case SNDRV_PCM_IOCTL_REWIND32
:
507 return snd_pcm_ioctl_rewind_compat(substream
, argp
);
508 case SNDRV_PCM_IOCTL_FORWARD32
:
509 return snd_pcm_ioctl_forward_compat(substream
, argp
);