1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * 32bit -> 64bit ioctl wrapper for PCM API
4 * Copyright (c) by Takashi Iwai <tiwai@suse.de>
5 */
6
7 /* This file included from pcm_native.c */
8
9 #include <linux/compat.h>
10 #include <linux/slab.h>
11
snd_pcm_ioctl_delay_compat(struct snd_pcm_substream * substream,s32 __user * src)12 static int snd_pcm_ioctl_delay_compat(struct snd_pcm_substream *substream,
13 s32 __user *src)
14 {
15 snd_pcm_sframes_t delay;
16 int err;
17
18 err = snd_pcm_delay(substream, &delay);
19 if (err)
20 return err;
21 if (put_user(delay, src))
22 return -EFAULT;
23 return 0;
24 }
25
snd_pcm_ioctl_rewind_compat(struct snd_pcm_substream * substream,u32 __user * src)26 static int snd_pcm_ioctl_rewind_compat(struct snd_pcm_substream *substream,
27 u32 __user *src)
28 {
29 snd_pcm_uframes_t frames;
30 int err;
31
32 if (get_user(frames, src))
33 return -EFAULT;
34 err = snd_pcm_rewind(substream, frames);
35 if (put_user(err, src))
36 return -EFAULT;
37 return err < 0 ? err : 0;
38 }
39
snd_pcm_ioctl_forward_compat(struct snd_pcm_substream * substream,u32 __user * src)40 static int snd_pcm_ioctl_forward_compat(struct snd_pcm_substream *substream,
41 u32 __user *src)
42 {
43 snd_pcm_uframes_t frames;
44 int err;
45
46 if (get_user(frames, src))
47 return -EFAULT;
48 err = snd_pcm_forward(substream, frames);
49 if (put_user(err, src))
50 return -EFAULT;
51 return err < 0 ? err : 0;
52 }
53
54 struct snd_pcm_hw_params32 {
55 u32 flags;
56 struct snd_mask masks[SNDRV_PCM_HW_PARAM_LAST_MASK - SNDRV_PCM_HW_PARAM_FIRST_MASK + 1]; /* this must be identical */
57 struct snd_mask mres[5]; /* reserved masks */
58 struct snd_interval intervals[SNDRV_PCM_HW_PARAM_LAST_INTERVAL - SNDRV_PCM_HW_PARAM_FIRST_INTERVAL + 1];
59 struct snd_interval ires[9]; /* reserved intervals */
60 u32 rmask;
61 u32 cmask;
62 u32 info;
63 u32 msbits;
64 u32 rate_num;
65 u32 rate_den;
66 u32 fifo_size;
67 unsigned char reserved[64];
68 };
69
70 struct snd_pcm_sw_params32 {
71 s32 tstamp_mode;
72 u32 period_step;
73 u32 sleep_min;
74 u32 avail_min;
75 u32 xfer_align;
76 u32 start_threshold;
77 u32 stop_threshold;
78 u32 silence_threshold;
79 u32 silence_size;
80 u32 boundary;
81 u32 proto;
82 u32 tstamp_type;
83 unsigned char reserved[56];
84 };
85
86 /* recalcuate the boundary within 32bit */
recalculate_boundary(struct snd_pcm_runtime * runtime)87 static snd_pcm_uframes_t recalculate_boundary(struct snd_pcm_runtime *runtime)
88 {
89 snd_pcm_uframes_t boundary;
90
91 if (! runtime->buffer_size)
92 return 0;
93 boundary = runtime->buffer_size;
94 while (boundary * 2 <= 0x7fffffffUL - runtime->buffer_size)
95 boundary *= 2;
96 return boundary;
97 }
98
snd_pcm_ioctl_sw_params_compat(struct snd_pcm_substream * substream,struct snd_pcm_sw_params32 __user * src)99 static int snd_pcm_ioctl_sw_params_compat(struct snd_pcm_substream *substream,
100 struct snd_pcm_sw_params32 __user *src)
101 {
102 struct snd_pcm_sw_params params;
103 snd_pcm_uframes_t boundary;
104 int err;
105
106 memset(¶ms, 0, sizeof(params));
107 if (get_user(params.tstamp_mode, &src->tstamp_mode) ||
108 get_user(params.period_step, &src->period_step) ||
109 get_user(params.sleep_min, &src->sleep_min) ||
110 get_user(params.avail_min, &src->avail_min) ||
111 get_user(params.xfer_align, &src->xfer_align) ||
112 get_user(params.start_threshold, &src->start_threshold) ||
113 get_user(params.stop_threshold, &src->stop_threshold) ||
114 get_user(params.silence_threshold, &src->silence_threshold) ||
115 get_user(params.silence_size, &src->silence_size) ||
116 get_user(params.tstamp_type, &src->tstamp_type) ||
117 get_user(params.proto, &src->proto))
118 return -EFAULT;
119 /*
120 * Check silent_size parameter. Since we have 64bit boundary,
121 * silence_size must be compared with the 32bit boundary.
122 */
123 boundary = recalculate_boundary(substream->runtime);
124 if (boundary && params.silence_size >= boundary)
125 params.silence_size = substream->runtime->boundary;
126 err = snd_pcm_sw_params(substream, ¶ms);
127 if (err < 0)
128 return err;
129 if (boundary && put_user(boundary, &src->boundary))
130 return -EFAULT;
131 return err;
132 }
133
134 struct snd_pcm_channel_info32 {
135 u32 channel;
136 u32 offset;
137 u32 first;
138 u32 step;
139 };
140
snd_pcm_ioctl_channel_info_compat(struct snd_pcm_substream * substream,struct snd_pcm_channel_info32 __user * src)141 static int snd_pcm_ioctl_channel_info_compat(struct snd_pcm_substream *substream,
142 struct snd_pcm_channel_info32 __user *src)
143 {
144 struct snd_pcm_channel_info info;
145 int err;
146
147 if (get_user(info.channel, &src->channel) ||
148 get_user(info.offset, &src->offset) ||
149 get_user(info.first, &src->first) ||
150 get_user(info.step, &src->step))
151 return -EFAULT;
152 err = snd_pcm_channel_info(substream, &info);
153 if (err < 0)
154 return err;
155 if (put_user(info.channel, &src->channel) ||
156 put_user(info.offset, &src->offset) ||
157 put_user(info.first, &src->first) ||
158 put_user(info.step, &src->step))
159 return -EFAULT;
160 return err;
161 }
162
163 #ifdef CONFIG_X86_X32
164 /* X32 ABI has the same struct as x86-64 for snd_pcm_channel_info */
165 static int snd_pcm_channel_info_user(struct snd_pcm_substream *substream,
166 struct snd_pcm_channel_info __user *src);
167 #define snd_pcm_ioctl_channel_info_x32(s, p) \
168 snd_pcm_channel_info_user(s, p)
169 #endif /* CONFIG_X86_X32 */
170
171 struct snd_pcm_status32 {
172 s32 state;
173 struct compat_timespec trigger_tstamp;
174 struct compat_timespec tstamp;
175 u32 appl_ptr;
176 u32 hw_ptr;
177 s32 delay;
178 u32 avail;
179 u32 avail_max;
180 u32 overrange;
181 s32 suspended_state;
182 u32 audio_tstamp_data;
183 struct compat_timespec audio_tstamp;
184 struct compat_timespec driver_tstamp;
185 u32 audio_tstamp_accuracy;
186 unsigned char reserved[52-2*sizeof(struct compat_timespec)];
187 } __attribute__((packed));
188
189
snd_pcm_status_user_compat(struct snd_pcm_substream * substream,struct snd_pcm_status32 __user * src,bool ext)190 static int snd_pcm_status_user_compat(struct snd_pcm_substream *substream,
191 struct snd_pcm_status32 __user *src,
192 bool ext)
193 {
194 struct snd_pcm_status status;
195 int err;
196
197 memset(&status, 0, sizeof(status));
198 /*
199 * with extension, parameters are read/write,
200 * get audio_tstamp_data from user,
201 * ignore rest of status structure
202 */
203 if (ext && get_user(status.audio_tstamp_data,
204 (u32 __user *)(&src->audio_tstamp_data)))
205 return -EFAULT;
206 err = snd_pcm_status(substream, &status);
207 if (err < 0)
208 return err;
209
210 if (clear_user(src, sizeof(*src)))
211 return -EFAULT;
212 if (put_user(status.state, &src->state) ||
213 compat_put_timespec(&status.trigger_tstamp, &src->trigger_tstamp) ||
214 compat_put_timespec(&status.tstamp, &src->tstamp) ||
215 put_user(status.appl_ptr, &src->appl_ptr) ||
216 put_user(status.hw_ptr, &src->hw_ptr) ||
217 put_user(status.delay, &src->delay) ||
218 put_user(status.avail, &src->avail) ||
219 put_user(status.avail_max, &src->avail_max) ||
220 put_user(status.overrange, &src->overrange) ||
221 put_user(status.suspended_state, &src->suspended_state) ||
222 put_user(status.audio_tstamp_data, &src->audio_tstamp_data) ||
223 compat_put_timespec(&status.audio_tstamp, &src->audio_tstamp) ||
224 compat_put_timespec(&status.driver_tstamp, &src->driver_tstamp) ||
225 put_user(status.audio_tstamp_accuracy, &src->audio_tstamp_accuracy))
226 return -EFAULT;
227
228 return err;
229 }
230
231 #ifdef CONFIG_X86_X32
232 /* X32 ABI has 64bit timespec and 64bit alignment */
233 struct snd_pcm_status_x32 {
234 s32 state;
235 u32 rsvd; /* alignment */
236 struct timespec trigger_tstamp;
237 struct timespec tstamp;
238 u32 appl_ptr;
239 u32 hw_ptr;
240 s32 delay;
241 u32 avail;
242 u32 avail_max;
243 u32 overrange;
244 s32 suspended_state;
245 u32 audio_tstamp_data;
246 struct timespec audio_tstamp;
247 struct timespec driver_tstamp;
248 u32 audio_tstamp_accuracy;
249 unsigned char reserved[52-2*sizeof(struct timespec)];
250 } __packed;
251
252 #define put_timespec(src, dst) copy_to_user(dst, src, sizeof(*dst))
253
snd_pcm_status_user_x32(struct snd_pcm_substream * substream,struct snd_pcm_status_x32 __user * src,bool ext)254 static int snd_pcm_status_user_x32(struct snd_pcm_substream *substream,
255 struct snd_pcm_status_x32 __user *src,
256 bool ext)
257 {
258 struct snd_pcm_status status;
259 int err;
260
261 memset(&status, 0, sizeof(status));
262 /*
263 * with extension, parameters are read/write,
264 * get audio_tstamp_data from user,
265 * ignore rest of status structure
266 */
267 if (ext && get_user(status.audio_tstamp_data,
268 (u32 __user *)(&src->audio_tstamp_data)))
269 return -EFAULT;
270 err = snd_pcm_status(substream, &status);
271 if (err < 0)
272 return err;
273
274 if (clear_user(src, sizeof(*src)))
275 return -EFAULT;
276 if (put_user(status.state, &src->state) ||
277 put_timespec(&status.trigger_tstamp, &src->trigger_tstamp) ||
278 put_timespec(&status.tstamp, &src->tstamp) ||
279 put_user(status.appl_ptr, &src->appl_ptr) ||
280 put_user(status.hw_ptr, &src->hw_ptr) ||
281 put_user(status.delay, &src->delay) ||
282 put_user(status.avail, &src->avail) ||
283 put_user(status.avail_max, &src->avail_max) ||
284 put_user(status.overrange, &src->overrange) ||
285 put_user(status.suspended_state, &src->suspended_state) ||
286 put_user(status.audio_tstamp_data, &src->audio_tstamp_data) ||
287 put_timespec(&status.audio_tstamp, &src->audio_tstamp) ||
288 put_timespec(&status.driver_tstamp, &src->driver_tstamp) ||
289 put_user(status.audio_tstamp_accuracy, &src->audio_tstamp_accuracy))
290 return -EFAULT;
291
292 return err;
293 }
294 #endif /* CONFIG_X86_X32 */
295
296 /* both for HW_PARAMS and HW_REFINE */
snd_pcm_ioctl_hw_params_compat(struct snd_pcm_substream * substream,int refine,struct snd_pcm_hw_params32 __user * data32)297 static int snd_pcm_ioctl_hw_params_compat(struct snd_pcm_substream *substream,
298 int refine,
299 struct snd_pcm_hw_params32 __user *data32)
300 {
301 struct snd_pcm_hw_params *data;
302 struct snd_pcm_runtime *runtime;
303 int err;
304
305 if (! (runtime = substream->runtime))
306 return -ENOTTY;
307
308 data = kmalloc(sizeof(*data), GFP_KERNEL);
309 if (!data)
310 return -ENOMEM;
311
312 /* only fifo_size (RO from userspace) is different, so just copy all */
313 if (copy_from_user(data, data32, sizeof(*data32))) {
314 err = -EFAULT;
315 goto error;
316 }
317
318 if (refine) {
319 err = snd_pcm_hw_refine(substream, data);
320 if (err < 0)
321 goto error;
322 err = fixup_unreferenced_params(substream, data);
323 } else {
324 err = snd_pcm_hw_params(substream, data);
325 }
326 if (err < 0)
327 goto error;
328 if (copy_to_user(data32, data, sizeof(*data32)) ||
329 put_user(data->fifo_size, &data32->fifo_size)) {
330 err = -EFAULT;
331 goto error;
332 }
333
334 if (! refine) {
335 unsigned int new_boundary = recalculate_boundary(runtime);
336 if (new_boundary)
337 runtime->boundary = new_boundary;
338 }
339 error:
340 kfree(data);
341 return err;
342 }
343
344
345 /*
346 */
347 struct snd_xferi32 {
348 s32 result;
349 u32 buf;
350 u32 frames;
351 };
352
snd_pcm_ioctl_xferi_compat(struct snd_pcm_substream * substream,int dir,struct snd_xferi32 __user * data32)353 static int snd_pcm_ioctl_xferi_compat(struct snd_pcm_substream *substream,
354 int dir, struct snd_xferi32 __user *data32)
355 {
356 compat_caddr_t buf;
357 u32 frames;
358 int err;
359
360 if (! substream->runtime)
361 return -ENOTTY;
362 if (substream->stream != dir)
363 return -EINVAL;
364 if (substream->runtime->status->state == SNDRV_PCM_STATE_OPEN)
365 return -EBADFD;
366
367 if (get_user(buf, &data32->buf) ||
368 get_user(frames, &data32->frames))
369 return -EFAULT;
370
371 if (dir == SNDRV_PCM_STREAM_PLAYBACK)
372 err = snd_pcm_lib_write(substream, compat_ptr(buf), frames);
373 else
374 err = snd_pcm_lib_read(substream, compat_ptr(buf), frames);
375 if (err < 0)
376 return err;
377 /* copy the result */
378 if (put_user(err, &data32->result))
379 return -EFAULT;
380 return 0;
381 }
382
383
384 /* snd_xfern needs remapping of bufs */
385 struct snd_xfern32 {
386 s32 result;
387 u32 bufs; /* this is void **; */
388 u32 frames;
389 };
390
391 /*
392 * xfern ioctl nees to copy (up to) 128 pointers on stack.
393 * although we may pass the copied pointers through f_op->ioctl, but the ioctl
394 * handler there expands again the same 128 pointers on stack, so it is better
395 * to handle the function (calling pcm_readv/writev) directly in this handler.
396 */
snd_pcm_ioctl_xfern_compat(struct snd_pcm_substream * substream,int dir,struct snd_xfern32 __user * data32)397 static int snd_pcm_ioctl_xfern_compat(struct snd_pcm_substream *substream,
398 int dir, struct snd_xfern32 __user *data32)
399 {
400 compat_caddr_t buf;
401 compat_caddr_t __user *bufptr;
402 u32 frames;
403 void __user **bufs;
404 int err, ch, i;
405
406 if (! substream->runtime)
407 return -ENOTTY;
408 if (substream->stream != dir)
409 return -EINVAL;
410 if (substream->runtime->status->state == SNDRV_PCM_STATE_OPEN)
411 return -EBADFD;
412
413 if ((ch = substream->runtime->channels) > 128)
414 return -EINVAL;
415 if (get_user(buf, &data32->bufs) ||
416 get_user(frames, &data32->frames))
417 return -EFAULT;
418 bufptr = compat_ptr(buf);
419 bufs = kmalloc_array(ch, sizeof(void __user *), GFP_KERNEL);
420 if (bufs == NULL)
421 return -ENOMEM;
422 for (i = 0; i < ch; i++) {
423 u32 ptr;
424 if (get_user(ptr, bufptr)) {
425 kfree(bufs);
426 return -EFAULT;
427 }
428 bufs[i] = compat_ptr(ptr);
429 bufptr++;
430 }
431 if (dir == SNDRV_PCM_STREAM_PLAYBACK)
432 err = snd_pcm_lib_writev(substream, bufs, frames);
433 else
434 err = snd_pcm_lib_readv(substream, bufs, frames);
435 if (err >= 0) {
436 if (put_user(err, &data32->result))
437 err = -EFAULT;
438 }
439 kfree(bufs);
440 return err;
441 }
442
443
444 struct snd_pcm_mmap_status32 {
445 s32 state;
446 s32 pad1;
447 u32 hw_ptr;
448 struct compat_timespec tstamp;
449 s32 suspended_state;
450 struct compat_timespec audio_tstamp;
451 } __attribute__((packed));
452
453 struct snd_pcm_mmap_control32 {
454 u32 appl_ptr;
455 u32 avail_min;
456 };
457
458 struct snd_pcm_sync_ptr32 {
459 u32 flags;
460 union {
461 struct snd_pcm_mmap_status32 status;
462 unsigned char reserved[64];
463 } s;
464 union {
465 struct snd_pcm_mmap_control32 control;
466 unsigned char reserved[64];
467 } c;
468 } __attribute__((packed));
469
snd_pcm_ioctl_sync_ptr_compat(struct snd_pcm_substream * substream,struct snd_pcm_sync_ptr32 __user * src)470 static int snd_pcm_ioctl_sync_ptr_compat(struct snd_pcm_substream *substream,
471 struct snd_pcm_sync_ptr32 __user *src)
472 {
473 struct snd_pcm_runtime *runtime = substream->runtime;
474 volatile struct snd_pcm_mmap_status *status;
475 volatile struct snd_pcm_mmap_control *control;
476 u32 sflags;
477 struct snd_pcm_mmap_control scontrol;
478 struct snd_pcm_mmap_status sstatus;
479 snd_pcm_uframes_t boundary;
480 int err;
481
482 if (snd_BUG_ON(!runtime))
483 return -EINVAL;
484
485 if (get_user(sflags, &src->flags) ||
486 get_user(scontrol.appl_ptr, &src->c.control.appl_ptr) ||
487 get_user(scontrol.avail_min, &src->c.control.avail_min))
488 return -EFAULT;
489 if (sflags & SNDRV_PCM_SYNC_PTR_HWSYNC) {
490 err = snd_pcm_hwsync(substream);
491 if (err < 0)
492 return err;
493 }
494 status = runtime->status;
495 control = runtime->control;
496 boundary = recalculate_boundary(runtime);
497 if (! boundary)
498 boundary = 0x7fffffff;
499 snd_pcm_stream_lock_irq(substream);
500 /* FIXME: we should consider the boundary for the sync from app */
501 if (!(sflags & SNDRV_PCM_SYNC_PTR_APPL))
502 control->appl_ptr = scontrol.appl_ptr;
503 else
504 scontrol.appl_ptr = control->appl_ptr % boundary;
505 if (!(sflags & SNDRV_PCM_SYNC_PTR_AVAIL_MIN))
506 control->avail_min = scontrol.avail_min;
507 else
508 scontrol.avail_min = control->avail_min;
509 sstatus.state = status->state;
510 sstatus.hw_ptr = status->hw_ptr % boundary;
511 sstatus.tstamp = status->tstamp;
512 sstatus.suspended_state = status->suspended_state;
513 sstatus.audio_tstamp = status->audio_tstamp;
514 snd_pcm_stream_unlock_irq(substream);
515 if (put_user(sstatus.state, &src->s.status.state) ||
516 put_user(sstatus.hw_ptr, &src->s.status.hw_ptr) ||
517 compat_put_timespec(&sstatus.tstamp, &src->s.status.tstamp) ||
518 put_user(sstatus.suspended_state, &src->s.status.suspended_state) ||
519 compat_put_timespec(&sstatus.audio_tstamp,
520 &src->s.status.audio_tstamp) ||
521 put_user(scontrol.appl_ptr, &src->c.control.appl_ptr) ||
522 put_user(scontrol.avail_min, &src->c.control.avail_min))
523 return -EFAULT;
524
525 return 0;
526 }
527
528 #ifdef CONFIG_X86_X32
529 /* X32 ABI has 64bit timespec and 64bit alignment */
530 struct snd_pcm_mmap_status_x32 {
531 s32 state;
532 s32 pad1;
533 u32 hw_ptr;
534 u32 pad2; /* alignment */
535 struct timespec tstamp;
536 s32 suspended_state;
537 s32 pad3;
538 struct timespec audio_tstamp;
539 } __packed;
540
541 struct snd_pcm_mmap_control_x32 {
542 u32 appl_ptr;
543 u32 avail_min;
544 };
545
546 struct snd_pcm_sync_ptr_x32 {
547 u32 flags;
548 u32 rsvd; /* alignment */
549 union {
550 struct snd_pcm_mmap_status_x32 status;
551 unsigned char reserved[64];
552 } s;
553 union {
554 struct snd_pcm_mmap_control_x32 control;
555 unsigned char reserved[64];
556 } c;
557 } __packed;
558
snd_pcm_ioctl_sync_ptr_x32(struct snd_pcm_substream * substream,struct snd_pcm_sync_ptr_x32 __user * src)559 static int snd_pcm_ioctl_sync_ptr_x32(struct snd_pcm_substream *substream,
560 struct snd_pcm_sync_ptr_x32 __user *src)
561 {
562 struct snd_pcm_runtime *runtime = substream->runtime;
563 volatile struct snd_pcm_mmap_status *status;
564 volatile struct snd_pcm_mmap_control *control;
565 u32 sflags;
566 struct snd_pcm_mmap_control scontrol;
567 struct snd_pcm_mmap_status sstatus;
568 snd_pcm_uframes_t boundary;
569 int err;
570
571 if (snd_BUG_ON(!runtime))
572 return -EINVAL;
573
574 if (get_user(sflags, &src->flags) ||
575 get_user(scontrol.appl_ptr, &src->c.control.appl_ptr) ||
576 get_user(scontrol.avail_min, &src->c.control.avail_min))
577 return -EFAULT;
578 if (sflags & SNDRV_PCM_SYNC_PTR_HWSYNC) {
579 err = snd_pcm_hwsync(substream);
580 if (err < 0)
581 return err;
582 }
583 status = runtime->status;
584 control = runtime->control;
585 boundary = recalculate_boundary(runtime);
586 if (!boundary)
587 boundary = 0x7fffffff;
588 snd_pcm_stream_lock_irq(substream);
589 /* FIXME: we should consider the boundary for the sync from app */
590 if (!(sflags & SNDRV_PCM_SYNC_PTR_APPL))
591 control->appl_ptr = scontrol.appl_ptr;
592 else
593 scontrol.appl_ptr = control->appl_ptr % boundary;
594 if (!(sflags & SNDRV_PCM_SYNC_PTR_AVAIL_MIN))
595 control->avail_min = scontrol.avail_min;
596 else
597 scontrol.avail_min = control->avail_min;
598 sstatus.state = status->state;
599 sstatus.hw_ptr = status->hw_ptr % boundary;
600 sstatus.tstamp = status->tstamp;
601 sstatus.suspended_state = status->suspended_state;
602 sstatus.audio_tstamp = status->audio_tstamp;
603 snd_pcm_stream_unlock_irq(substream);
604 if (put_user(sstatus.state, &src->s.status.state) ||
605 put_user(sstatus.hw_ptr, &src->s.status.hw_ptr) ||
606 put_timespec(&sstatus.tstamp, &src->s.status.tstamp) ||
607 put_user(sstatus.suspended_state, &src->s.status.suspended_state) ||
608 put_timespec(&sstatus.audio_tstamp, &src->s.status.audio_tstamp) ||
609 put_user(scontrol.appl_ptr, &src->c.control.appl_ptr) ||
610 put_user(scontrol.avail_min, &src->c.control.avail_min))
611 return -EFAULT;
612
613 return 0;
614 }
615 #endif /* CONFIG_X86_X32 */
616
617 /*
618 */
619 enum {
620 SNDRV_PCM_IOCTL_HW_REFINE32 = _IOWR('A', 0x10, struct snd_pcm_hw_params32),
621 SNDRV_PCM_IOCTL_HW_PARAMS32 = _IOWR('A', 0x11, struct snd_pcm_hw_params32),
622 SNDRV_PCM_IOCTL_SW_PARAMS32 = _IOWR('A', 0x13, struct snd_pcm_sw_params32),
623 SNDRV_PCM_IOCTL_STATUS32 = _IOR('A', 0x20, struct snd_pcm_status32),
624 SNDRV_PCM_IOCTL_STATUS_EXT32 = _IOWR('A', 0x24, struct snd_pcm_status32),
625 SNDRV_PCM_IOCTL_DELAY32 = _IOR('A', 0x21, s32),
626 SNDRV_PCM_IOCTL_CHANNEL_INFO32 = _IOR('A', 0x32, struct snd_pcm_channel_info32),
627 SNDRV_PCM_IOCTL_REWIND32 = _IOW('A', 0x46, u32),
628 SNDRV_PCM_IOCTL_FORWARD32 = _IOW('A', 0x49, u32),
629 SNDRV_PCM_IOCTL_WRITEI_FRAMES32 = _IOW('A', 0x50, struct snd_xferi32),
630 SNDRV_PCM_IOCTL_READI_FRAMES32 = _IOR('A', 0x51, struct snd_xferi32),
631 SNDRV_PCM_IOCTL_WRITEN_FRAMES32 = _IOW('A', 0x52, struct snd_xfern32),
632 SNDRV_PCM_IOCTL_READN_FRAMES32 = _IOR('A', 0x53, struct snd_xfern32),
633 SNDRV_PCM_IOCTL_SYNC_PTR32 = _IOWR('A', 0x23, struct snd_pcm_sync_ptr32),
634 #ifdef CONFIG_X86_X32
635 SNDRV_PCM_IOCTL_CHANNEL_INFO_X32 = _IOR('A', 0x32, struct snd_pcm_channel_info),
636 SNDRV_PCM_IOCTL_STATUS_X32 = _IOR('A', 0x20, struct snd_pcm_status_x32),
637 SNDRV_PCM_IOCTL_STATUS_EXT_X32 = _IOWR('A', 0x24, struct snd_pcm_status_x32),
638 SNDRV_PCM_IOCTL_SYNC_PTR_X32 = _IOWR('A', 0x23, struct snd_pcm_sync_ptr_x32),
639 #endif /* CONFIG_X86_X32 */
640 };
641
snd_pcm_ioctl_compat(struct file * file,unsigned int cmd,unsigned long arg)642 static long snd_pcm_ioctl_compat(struct file *file, unsigned int cmd, unsigned long arg)
643 {
644 struct snd_pcm_file *pcm_file;
645 struct snd_pcm_substream *substream;
646 void __user *argp = compat_ptr(arg);
647
648 pcm_file = file->private_data;
649 if (! pcm_file)
650 return -ENOTTY;
651 substream = pcm_file->substream;
652 if (! substream)
653 return -ENOTTY;
654
655 /*
656 * When PCM is used on 32bit mode, we need to disable
657 * mmap of PCM status/control records because of the size
658 * incompatibility.
659 */
660 pcm_file->no_compat_mmap = 1;
661
662 switch (cmd) {
663 case SNDRV_PCM_IOCTL_PVERSION:
664 case SNDRV_PCM_IOCTL_INFO:
665 case SNDRV_PCM_IOCTL_TSTAMP:
666 case SNDRV_PCM_IOCTL_TTSTAMP:
667 case SNDRV_PCM_IOCTL_USER_PVERSION:
668 case SNDRV_PCM_IOCTL_HWSYNC:
669 case SNDRV_PCM_IOCTL_PREPARE:
670 case SNDRV_PCM_IOCTL_RESET:
671 case SNDRV_PCM_IOCTL_START:
672 case SNDRV_PCM_IOCTL_DROP:
673 case SNDRV_PCM_IOCTL_DRAIN:
674 case SNDRV_PCM_IOCTL_PAUSE:
675 case SNDRV_PCM_IOCTL_HW_FREE:
676 case SNDRV_PCM_IOCTL_RESUME:
677 case SNDRV_PCM_IOCTL_XRUN:
678 case SNDRV_PCM_IOCTL_LINK:
679 case SNDRV_PCM_IOCTL_UNLINK:
680 return snd_pcm_common_ioctl(file, substream, cmd, argp);
681 case SNDRV_PCM_IOCTL_HW_REFINE32:
682 return snd_pcm_ioctl_hw_params_compat(substream, 1, argp);
683 case SNDRV_PCM_IOCTL_HW_PARAMS32:
684 return snd_pcm_ioctl_hw_params_compat(substream, 0, argp);
685 case SNDRV_PCM_IOCTL_SW_PARAMS32:
686 return snd_pcm_ioctl_sw_params_compat(substream, argp);
687 case SNDRV_PCM_IOCTL_STATUS32:
688 return snd_pcm_status_user_compat(substream, argp, false);
689 case SNDRV_PCM_IOCTL_STATUS_EXT32:
690 return snd_pcm_status_user_compat(substream, argp, true);
691 case SNDRV_PCM_IOCTL_SYNC_PTR32:
692 return snd_pcm_ioctl_sync_ptr_compat(substream, argp);
693 case SNDRV_PCM_IOCTL_CHANNEL_INFO32:
694 return snd_pcm_ioctl_channel_info_compat(substream, argp);
695 case SNDRV_PCM_IOCTL_WRITEI_FRAMES32:
696 return snd_pcm_ioctl_xferi_compat(substream, SNDRV_PCM_STREAM_PLAYBACK, argp);
697 case SNDRV_PCM_IOCTL_READI_FRAMES32:
698 return snd_pcm_ioctl_xferi_compat(substream, SNDRV_PCM_STREAM_CAPTURE, argp);
699 case SNDRV_PCM_IOCTL_WRITEN_FRAMES32:
700 return snd_pcm_ioctl_xfern_compat(substream, SNDRV_PCM_STREAM_PLAYBACK, argp);
701 case SNDRV_PCM_IOCTL_READN_FRAMES32:
702 return snd_pcm_ioctl_xfern_compat(substream, SNDRV_PCM_STREAM_CAPTURE, argp);
703 case SNDRV_PCM_IOCTL_DELAY32:
704 return snd_pcm_ioctl_delay_compat(substream, argp);
705 case SNDRV_PCM_IOCTL_REWIND32:
706 return snd_pcm_ioctl_rewind_compat(substream, argp);
707 case SNDRV_PCM_IOCTL_FORWARD32:
708 return snd_pcm_ioctl_forward_compat(substream, argp);
709 #ifdef CONFIG_X86_X32
710 case SNDRV_PCM_IOCTL_STATUS_X32:
711 return snd_pcm_status_user_x32(substream, argp, false);
712 case SNDRV_PCM_IOCTL_STATUS_EXT_X32:
713 return snd_pcm_status_user_x32(substream, argp, true);
714 case SNDRV_PCM_IOCTL_SYNC_PTR_X32:
715 return snd_pcm_ioctl_sync_ptr_x32(substream, argp);
716 case SNDRV_PCM_IOCTL_CHANNEL_INFO_X32:
717 return snd_pcm_ioctl_channel_info_x32(substream, argp);
718 #endif /* CONFIG_X86_X32 */
719 }
720
721 return -ENOIOCTLCMD;
722 }
723