pcm_compat.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645
  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. /* This file included from pcm_native.c */
  7. #include <linux/compat.h>
  8. #include <linux/slab.h>
  9. static int snd_pcm_ioctl_delay_compat(struct snd_pcm_substream *substream,
  10. s32 __user *src)
  11. {
  12. snd_pcm_sframes_t delay;
  13. int err;
  14. err = snd_pcm_delay(substream, &delay);
  15. if (err)
  16. return err;
  17. if (put_user(delay, src))
  18. return -EFAULT;
  19. return 0;
  20. }
  21. static int snd_pcm_ioctl_rewind_compat(struct snd_pcm_substream *substream,
  22. u32 __user *src)
  23. {
  24. snd_pcm_uframes_t frames;
  25. int err;
  26. if (get_user(frames, src))
  27. return -EFAULT;
  28. err = snd_pcm_rewind(substream, frames);
  29. if (put_user(err, src))
  30. return -EFAULT;
  31. return err < 0 ? err : 0;
  32. }
  33. static int snd_pcm_ioctl_forward_compat(struct snd_pcm_substream *substream,
  34. u32 __user *src)
  35. {
  36. snd_pcm_uframes_t frames;
  37. int err;
  38. if (get_user(frames, src))
  39. return -EFAULT;
  40. err = snd_pcm_forward(substream, frames);
  41. if (put_user(err, src))
  42. return -EFAULT;
  43. return err < 0 ? err : 0;
  44. }
  45. struct snd_pcm_hw_params32 {
  46. u32 flags;
  47. struct snd_mask masks[SNDRV_PCM_HW_PARAM_LAST_MASK - SNDRV_PCM_HW_PARAM_FIRST_MASK + 1]; /* this must be identical */
  48. struct snd_mask mres[5]; /* reserved masks */
  49. struct snd_interval intervals[SNDRV_PCM_HW_PARAM_LAST_INTERVAL - SNDRV_PCM_HW_PARAM_FIRST_INTERVAL + 1];
  50. struct snd_interval ires[9]; /* reserved intervals */
  51. u32 rmask;
  52. u32 cmask;
  53. u32 info;
  54. u32 msbits;
  55. u32 rate_num;
  56. u32 rate_den;
  57. u32 fifo_size;
  58. unsigned char reserved[64];
  59. };
  60. struct snd_pcm_sw_params32 {
  61. s32 tstamp_mode;
  62. u32 period_step;
  63. u32 sleep_min;
  64. u32 avail_min;
  65. u32 xfer_align;
  66. u32 start_threshold;
  67. u32 stop_threshold;
  68. u32 silence_threshold;
  69. u32 silence_size;
  70. u32 boundary;
  71. u32 proto;
  72. u32 tstamp_type;
  73. unsigned char reserved[56];
  74. };
  75. static int snd_pcm_ioctl_sw_params_compat(struct snd_pcm_substream *substream,
  76. struct snd_pcm_sw_params32 __user *src)
  77. {
  78. struct snd_pcm_sw_params params;
  79. snd_pcm_uframes_t boundary;
  80. int err;
  81. memset(&params, 0, sizeof(params));
  82. if (get_user(params.tstamp_mode, &src->tstamp_mode) ||
  83. get_user(params.period_step, &src->period_step) ||
  84. get_user(params.sleep_min, &src->sleep_min) ||
  85. get_user(params.avail_min, &src->avail_min) ||
  86. get_user(params.xfer_align, &src->xfer_align) ||
  87. get_user(params.start_threshold, &src->start_threshold) ||
  88. get_user(params.stop_threshold, &src->stop_threshold) ||
  89. get_user(params.silence_threshold, &src->silence_threshold) ||
  90. get_user(params.silence_size, &src->silence_size) ||
  91. get_user(params.tstamp_type, &src->tstamp_type) ||
  92. get_user(params.proto, &src->proto))
  93. return -EFAULT;
  94. /*
  95. * Check silent_size parameter. Since we have 64bit boundary,
  96. * silence_size must be compared with the 32bit boundary.
  97. */
  98. boundary = recalculate_boundary(substream->runtime);
  99. if (boundary && params.silence_size >= boundary)
  100. params.silence_size = substream->runtime->boundary;
  101. err = snd_pcm_sw_params(substream, &params);
  102. if (err < 0)
  103. return err;
  104. if (boundary && put_user(boundary, &src->boundary))
  105. return -EFAULT;
  106. return err;
  107. }
  108. struct snd_pcm_channel_info32 {
  109. u32 channel;
  110. u32 offset;
  111. u32 first;
  112. u32 step;
  113. };
  114. static int snd_pcm_ioctl_channel_info_compat(struct snd_pcm_substream *substream,
  115. struct snd_pcm_channel_info32 __user *src)
  116. {
  117. struct snd_pcm_channel_info info;
  118. int err;
  119. if (get_user(info.channel, &src->channel) ||
  120. get_user(info.offset, &src->offset) ||
  121. get_user(info.first, &src->first) ||
  122. get_user(info.step, &src->step))
  123. return -EFAULT;
  124. err = snd_pcm_channel_info(substream, &info);
  125. if (err < 0)
  126. return err;
  127. if (put_user(info.channel, &src->channel) ||
  128. put_user(info.offset, &src->offset) ||
  129. put_user(info.first, &src->first) ||
  130. put_user(info.step, &src->step))
  131. return -EFAULT;
  132. return err;
  133. }
  134. #ifdef CONFIG_X86_X32_ABI
  135. /* X32 ABI has the same struct as x86-64 for snd_pcm_channel_info */
  136. static int snd_pcm_channel_info_user(struct snd_pcm_substream *substream,
  137. struct snd_pcm_channel_info __user *src);
  138. #define snd_pcm_ioctl_channel_info_x32(s, p) \
  139. snd_pcm_channel_info_user(s, p)
  140. #endif /* CONFIG_X86_X32_ABI */
  141. struct compat_snd_pcm_status64 {
  142. snd_pcm_state_t state;
  143. u8 rsvd[4]; /* alignment */
  144. s64 trigger_tstamp_sec;
  145. s64 trigger_tstamp_nsec;
  146. s64 tstamp_sec;
  147. s64 tstamp_nsec;
  148. u32 appl_ptr;
  149. u32 hw_ptr;
  150. s32 delay;
  151. u32 avail;
  152. u32 avail_max;
  153. u32 overrange;
  154. snd_pcm_state_t suspended_state;
  155. u32 audio_tstamp_data;
  156. s64 audio_tstamp_sec;
  157. s64 audio_tstamp_nsec;
  158. s64 driver_tstamp_sec;
  159. s64 driver_tstamp_nsec;
  160. u32 audio_tstamp_accuracy;
  161. unsigned char reserved[52-4*sizeof(s64)];
  162. } __packed;
  163. static int snd_pcm_status_user_compat64(struct snd_pcm_substream *substream,
  164. struct compat_snd_pcm_status64 __user *src,
  165. bool ext)
  166. {
  167. struct snd_pcm_status64 status;
  168. struct compat_snd_pcm_status64 compat_status64;
  169. int err;
  170. memset(&status, 0, sizeof(status));
  171. memset(&compat_status64, 0, sizeof(compat_status64));
  172. /*
  173. * with extension, parameters are read/write,
  174. * get audio_tstamp_data from user,
  175. * ignore rest of status structure
  176. */
  177. if (ext && get_user(status.audio_tstamp_data,
  178. (u32 __user *)(&src->audio_tstamp_data)))
  179. return -EFAULT;
  180. err = snd_pcm_status64(substream, &status);
  181. if (err < 0)
  182. return err;
  183. if (clear_user(src, sizeof(*src)))
  184. return -EFAULT;
  185. compat_status64 = (struct compat_snd_pcm_status64) {
  186. .state = status.state,
  187. .trigger_tstamp_sec = status.trigger_tstamp_sec,
  188. .trigger_tstamp_nsec = status.trigger_tstamp_nsec,
  189. .tstamp_sec = status.tstamp_sec,
  190. .tstamp_nsec = status.tstamp_nsec,
  191. .appl_ptr = status.appl_ptr,
  192. .hw_ptr = status.hw_ptr,
  193. .delay = status.delay,
  194. .avail = status.avail,
  195. .avail_max = status.avail_max,
  196. .overrange = status.overrange,
  197. .suspended_state = status.suspended_state,
  198. .audio_tstamp_data = status.audio_tstamp_data,
  199. .audio_tstamp_sec = status.audio_tstamp_sec,
  200. .audio_tstamp_nsec = status.audio_tstamp_nsec,
  201. .driver_tstamp_sec = status.audio_tstamp_sec,
  202. .driver_tstamp_nsec = status.audio_tstamp_nsec,
  203. .audio_tstamp_accuracy = status.audio_tstamp_accuracy,
  204. };
  205. if (copy_to_user(src, &compat_status64, sizeof(compat_status64)))
  206. return -EFAULT;
  207. return err;
  208. }
  209. /* both for HW_PARAMS and HW_REFINE */
  210. static int snd_pcm_ioctl_hw_params_compat(struct snd_pcm_substream *substream,
  211. int refine,
  212. struct snd_pcm_hw_params32 __user *data32)
  213. {
  214. struct snd_pcm_hw_params *data __free(kfree) = NULL;
  215. struct snd_pcm_runtime *runtime;
  216. int err;
  217. runtime = substream->runtime;
  218. if (!runtime)
  219. return -ENOTTY;
  220. data = kmalloc(sizeof(*data), GFP_KERNEL);
  221. if (!data)
  222. return -ENOMEM;
  223. /* only fifo_size (RO from userspace) is different, so just copy all */
  224. if (copy_from_user(data, data32, sizeof(*data32)))
  225. return -EFAULT;
  226. if (refine) {
  227. err = snd_pcm_hw_refine(substream, data);
  228. if (err < 0)
  229. return err;
  230. err = fixup_unreferenced_params(substream, data);
  231. } else {
  232. err = snd_pcm_hw_params(substream, data);
  233. }
  234. if (err < 0)
  235. return err;
  236. if (copy_to_user(data32, data, sizeof(*data32)) ||
  237. put_user(data->fifo_size, &data32->fifo_size))
  238. return -EFAULT;
  239. if (! refine) {
  240. unsigned int new_boundary = recalculate_boundary(runtime);
  241. if (new_boundary)
  242. runtime->boundary = new_boundary;
  243. }
  244. return err;
  245. }
  246. /*
  247. */
  248. struct snd_xferi32 {
  249. s32 result;
  250. u32 buf;
  251. u32 frames;
  252. };
  253. static int snd_pcm_ioctl_xferi_compat(struct snd_pcm_substream *substream,
  254. int dir, struct snd_xferi32 __user *data32)
  255. {
  256. compat_caddr_t buf;
  257. u32 frames;
  258. int err;
  259. if (! substream->runtime)
  260. return -ENOTTY;
  261. if (substream->stream != dir)
  262. return -EINVAL;
  263. if (substream->runtime->state == SNDRV_PCM_STATE_OPEN)
  264. return -EBADFD;
  265. if (get_user(buf, &data32->buf) ||
  266. get_user(frames, &data32->frames))
  267. return -EFAULT;
  268. if (dir == SNDRV_PCM_STREAM_PLAYBACK)
  269. err = snd_pcm_lib_write(substream, compat_ptr(buf), frames);
  270. else
  271. err = snd_pcm_lib_read(substream, compat_ptr(buf), frames);
  272. if (err < 0)
  273. return err;
  274. /* copy the result */
  275. if (put_user(err, &data32->result))
  276. return -EFAULT;
  277. return 0;
  278. }
  279. /* snd_xfern needs remapping of bufs */
  280. struct snd_xfern32 {
  281. s32 result;
  282. u32 bufs; /* this is void **; */
  283. u32 frames;
  284. };
  285. /*
  286. * xfern ioctl nees to copy (up to) 128 pointers on stack.
  287. * although we may pass the copied pointers through f_op->ioctl, but the ioctl
  288. * handler there expands again the same 128 pointers on stack, so it is better
  289. * to handle the function (calling pcm_readv/writev) directly in this handler.
  290. */
  291. static int snd_pcm_ioctl_xfern_compat(struct snd_pcm_substream *substream,
  292. int dir, struct snd_xfern32 __user *data32)
  293. {
  294. compat_caddr_t buf;
  295. compat_caddr_t __user *bufptr;
  296. u32 frames;
  297. void __user **bufs __free(kfree) = NULL;
  298. int err, ch, i;
  299. if (! substream->runtime)
  300. return -ENOTTY;
  301. if (substream->stream != dir)
  302. return -EINVAL;
  303. if (substream->runtime->state == SNDRV_PCM_STATE_OPEN)
  304. return -EBADFD;
  305. ch = substream->runtime->channels;
  306. if (ch > 128)
  307. return -EINVAL;
  308. if (get_user(buf, &data32->bufs) ||
  309. get_user(frames, &data32->frames))
  310. return -EFAULT;
  311. bufptr = compat_ptr(buf);
  312. bufs = kmalloc_array(ch, sizeof(void __user *), GFP_KERNEL);
  313. if (bufs == NULL)
  314. return -ENOMEM;
  315. for (i = 0; i < ch; i++) {
  316. u32 ptr;
  317. if (get_user(ptr, bufptr))
  318. return -EFAULT;
  319. bufs[i] = compat_ptr(ptr);
  320. bufptr++;
  321. }
  322. if (dir == SNDRV_PCM_STREAM_PLAYBACK)
  323. err = snd_pcm_lib_writev(substream, bufs, frames);
  324. else
  325. err = snd_pcm_lib_readv(substream, bufs, frames);
  326. if (err >= 0) {
  327. if (put_user(err, &data32->result))
  328. return -EFAULT;
  329. }
  330. return err;
  331. }
  332. #ifdef CONFIG_X86_X32_ABI
  333. /* X32 ABI has 64bit timespec and 64bit alignment */
  334. struct snd_pcm_mmap_status_x32 {
  335. snd_pcm_state_t state;
  336. s32 pad1;
  337. u32 hw_ptr;
  338. u32 pad2; /* alignment */
  339. s64 tstamp_sec;
  340. s64 tstamp_nsec;
  341. snd_pcm_state_t suspended_state;
  342. s32 pad3;
  343. s64 audio_tstamp_sec;
  344. s64 audio_tstamp_nsec;
  345. } __packed;
  346. struct snd_pcm_mmap_control_x32 {
  347. u32 appl_ptr;
  348. u32 avail_min;
  349. };
  350. struct snd_pcm_sync_ptr_x32 {
  351. u32 flags;
  352. u32 rsvd; /* alignment */
  353. union {
  354. struct snd_pcm_mmap_status_x32 status;
  355. unsigned char reserved[64];
  356. } s;
  357. union {
  358. struct snd_pcm_mmap_control_x32 control;
  359. unsigned char reserved[64];
  360. } c;
  361. } __packed;
  362. static int snd_pcm_ioctl_sync_ptr_x32(struct snd_pcm_substream *substream,
  363. struct snd_pcm_sync_ptr_x32 __user *src)
  364. {
  365. struct snd_pcm_runtime *runtime = substream->runtime;
  366. volatile struct snd_pcm_mmap_status *status;
  367. volatile struct snd_pcm_mmap_control *control;
  368. u32 sflags;
  369. struct snd_pcm_mmap_control scontrol;
  370. struct snd_pcm_mmap_status sstatus;
  371. snd_pcm_uframes_t boundary;
  372. int err;
  373. if (snd_BUG_ON(!runtime))
  374. return -EINVAL;
  375. if (get_user(sflags, &src->flags) ||
  376. get_user(scontrol.appl_ptr, &src->c.control.appl_ptr) ||
  377. get_user(scontrol.avail_min, &src->c.control.avail_min))
  378. return -EFAULT;
  379. if (sflags & SNDRV_PCM_SYNC_PTR_HWSYNC) {
  380. err = snd_pcm_hwsync(substream);
  381. if (err < 0)
  382. return err;
  383. }
  384. status = runtime->status;
  385. control = runtime->control;
  386. boundary = recalculate_boundary(runtime);
  387. if (!boundary)
  388. boundary = 0x7fffffff;
  389. scoped_guard(pcm_stream_lock_irq, substream) {
  390. /* FIXME: we should consider the boundary for the sync from app */
  391. if (!(sflags & SNDRV_PCM_SYNC_PTR_APPL))
  392. control->appl_ptr = scontrol.appl_ptr;
  393. else
  394. scontrol.appl_ptr = control->appl_ptr % boundary;
  395. if (!(sflags & SNDRV_PCM_SYNC_PTR_AVAIL_MIN))
  396. control->avail_min = scontrol.avail_min;
  397. else
  398. scontrol.avail_min = control->avail_min;
  399. sstatus.state = status->state;
  400. sstatus.hw_ptr = status->hw_ptr % boundary;
  401. sstatus.tstamp = status->tstamp;
  402. sstatus.suspended_state = status->suspended_state;
  403. sstatus.audio_tstamp = status->audio_tstamp;
  404. }
  405. if (!(sflags & SNDRV_PCM_SYNC_PTR_APPL))
  406. snd_pcm_dma_buffer_sync(substream, SNDRV_DMA_SYNC_DEVICE);
  407. if (put_user(sstatus.state, &src->s.status.state) ||
  408. put_user(sstatus.hw_ptr, &src->s.status.hw_ptr) ||
  409. put_user(sstatus.tstamp.tv_sec, &src->s.status.tstamp_sec) ||
  410. put_user(sstatus.tstamp.tv_nsec, &src->s.status.tstamp_nsec) ||
  411. put_user(sstatus.suspended_state, &src->s.status.suspended_state) ||
  412. put_user(sstatus.audio_tstamp.tv_sec, &src->s.status.audio_tstamp_sec) ||
  413. put_user(sstatus.audio_tstamp.tv_nsec, &src->s.status.audio_tstamp_nsec) ||
  414. put_user(scontrol.appl_ptr, &src->c.control.appl_ptr) ||
  415. put_user(scontrol.avail_min, &src->c.control.avail_min))
  416. return -EFAULT;
  417. return 0;
  418. }
  419. #endif /* CONFIG_X86_X32_ABI */
  420. #ifdef __BIG_ENDIAN
  421. typedef char __pad_before_u32[4];
  422. typedef char __pad_after_u32[0];
  423. #else
  424. typedef char __pad_before_u32[0];
  425. typedef char __pad_after_u32[4];
  426. #endif
  427. /* PCM 2.0.15 API definition had a bug in mmap control; it puts the avail_min
  428. * at the wrong offset due to a typo in padding type.
  429. * The bug hits only 32bit.
  430. * A workaround for incorrect read/write is needed only in 32bit compat mode.
  431. */
  432. struct __snd_pcm_mmap_control64_buggy {
  433. __pad_before_u32 __pad1;
  434. __u32 appl_ptr;
  435. __pad_before_u32 __pad2; /* SiC! here is the bug */
  436. __pad_before_u32 __pad3;
  437. __u32 avail_min;
  438. __pad_after_uframe __pad4;
  439. };
  440. static int snd_pcm_ioctl_sync_ptr_buggy(struct snd_pcm_substream *substream,
  441. struct snd_pcm_sync_ptr __user *_sync_ptr)
  442. {
  443. struct snd_pcm_runtime *runtime = substream->runtime;
  444. struct snd_pcm_sync_ptr sync_ptr;
  445. struct __snd_pcm_mmap_control64_buggy *sync_cp;
  446. volatile struct snd_pcm_mmap_status *status;
  447. volatile struct snd_pcm_mmap_control *control;
  448. int err;
  449. memset(&sync_ptr, 0, sizeof(sync_ptr));
  450. sync_cp = (struct __snd_pcm_mmap_control64_buggy *)&sync_ptr.c.control;
  451. if (get_user(sync_ptr.flags, (unsigned __user *)&(_sync_ptr->flags)))
  452. return -EFAULT;
  453. if (copy_from_user(sync_cp, &(_sync_ptr->c.control), sizeof(*sync_cp)))
  454. return -EFAULT;
  455. status = runtime->status;
  456. control = runtime->control;
  457. if (sync_ptr.flags & SNDRV_PCM_SYNC_PTR_HWSYNC) {
  458. err = snd_pcm_hwsync(substream);
  459. if (err < 0)
  460. return err;
  461. }
  462. scoped_guard(pcm_stream_lock_irq, substream) {
  463. if (!(sync_ptr.flags & SNDRV_PCM_SYNC_PTR_APPL)) {
  464. err = pcm_lib_apply_appl_ptr(substream, sync_cp->appl_ptr);
  465. if (err < 0)
  466. return err;
  467. } else {
  468. sync_cp->appl_ptr = control->appl_ptr;
  469. }
  470. if (!(sync_ptr.flags & SNDRV_PCM_SYNC_PTR_AVAIL_MIN))
  471. control->avail_min = sync_cp->avail_min;
  472. else
  473. sync_cp->avail_min = control->avail_min;
  474. sync_ptr.s.status.state = status->state;
  475. sync_ptr.s.status.hw_ptr = status->hw_ptr;
  476. sync_ptr.s.status.tstamp = status->tstamp;
  477. sync_ptr.s.status.suspended_state = status->suspended_state;
  478. sync_ptr.s.status.audio_tstamp = status->audio_tstamp;
  479. }
  480. if (!(sync_ptr.flags & SNDRV_PCM_SYNC_PTR_APPL))
  481. snd_pcm_dma_buffer_sync(substream, SNDRV_DMA_SYNC_DEVICE);
  482. if (copy_to_user(_sync_ptr, &sync_ptr, sizeof(sync_ptr)))
  483. return -EFAULT;
  484. return 0;
  485. }
  486. /*
  487. */
  488. enum {
  489. SNDRV_PCM_IOCTL_HW_REFINE32 = _IOWR('A', 0x10, struct snd_pcm_hw_params32),
  490. SNDRV_PCM_IOCTL_HW_PARAMS32 = _IOWR('A', 0x11, struct snd_pcm_hw_params32),
  491. SNDRV_PCM_IOCTL_SW_PARAMS32 = _IOWR('A', 0x13, struct snd_pcm_sw_params32),
  492. SNDRV_PCM_IOCTL_STATUS_COMPAT32 = _IOR('A', 0x20, struct snd_pcm_status32),
  493. SNDRV_PCM_IOCTL_STATUS_EXT_COMPAT32 = _IOWR('A', 0x24, struct snd_pcm_status32),
  494. SNDRV_PCM_IOCTL_DELAY32 = _IOR('A', 0x21, s32),
  495. SNDRV_PCM_IOCTL_CHANNEL_INFO32 = _IOR('A', 0x32, struct snd_pcm_channel_info32),
  496. SNDRV_PCM_IOCTL_REWIND32 = _IOW('A', 0x46, u32),
  497. SNDRV_PCM_IOCTL_FORWARD32 = _IOW('A', 0x49, u32),
  498. SNDRV_PCM_IOCTL_WRITEI_FRAMES32 = _IOW('A', 0x50, struct snd_xferi32),
  499. SNDRV_PCM_IOCTL_READI_FRAMES32 = _IOR('A', 0x51, struct snd_xferi32),
  500. SNDRV_PCM_IOCTL_WRITEN_FRAMES32 = _IOW('A', 0x52, struct snd_xfern32),
  501. SNDRV_PCM_IOCTL_READN_FRAMES32 = _IOR('A', 0x53, struct snd_xfern32),
  502. SNDRV_PCM_IOCTL_STATUS_COMPAT64 = _IOR('A', 0x20, struct compat_snd_pcm_status64),
  503. SNDRV_PCM_IOCTL_STATUS_EXT_COMPAT64 = _IOWR('A', 0x24, struct compat_snd_pcm_status64),
  504. #ifdef CONFIG_X86_X32_ABI
  505. SNDRV_PCM_IOCTL_CHANNEL_INFO_X32 = _IOR('A', 0x32, struct snd_pcm_channel_info),
  506. SNDRV_PCM_IOCTL_SYNC_PTR_X32 = _IOWR('A', 0x23, struct snd_pcm_sync_ptr_x32),
  507. #endif /* CONFIG_X86_X32_ABI */
  508. };
  509. static long snd_pcm_ioctl_compat(struct file *file, unsigned int cmd, unsigned long arg)
  510. {
  511. struct snd_pcm_file *pcm_file;
  512. struct snd_pcm_substream *substream;
  513. void __user *argp = compat_ptr(arg);
  514. pcm_file = file->private_data;
  515. if (! pcm_file)
  516. return -ENOTTY;
  517. substream = pcm_file->substream;
  518. if (! substream)
  519. return -ENOTTY;
  520. /*
  521. * When PCM is used on 32bit mode, we need to disable
  522. * mmap of the old PCM status/control records because
  523. * of the size incompatibility.
  524. */
  525. pcm_file->no_compat_mmap = 1;
  526. switch (cmd) {
  527. case SNDRV_PCM_IOCTL_PVERSION:
  528. case SNDRV_PCM_IOCTL_INFO:
  529. case SNDRV_PCM_IOCTL_TSTAMP:
  530. case SNDRV_PCM_IOCTL_TTSTAMP:
  531. case SNDRV_PCM_IOCTL_USER_PVERSION:
  532. case SNDRV_PCM_IOCTL_HWSYNC:
  533. case SNDRV_PCM_IOCTL_PREPARE:
  534. case SNDRV_PCM_IOCTL_RESET:
  535. case SNDRV_PCM_IOCTL_START:
  536. case SNDRV_PCM_IOCTL_DROP:
  537. case SNDRV_PCM_IOCTL_DRAIN:
  538. case SNDRV_PCM_IOCTL_PAUSE:
  539. case SNDRV_PCM_IOCTL_HW_FREE:
  540. case SNDRV_PCM_IOCTL_RESUME:
  541. case SNDRV_PCM_IOCTL_XRUN:
  542. case SNDRV_PCM_IOCTL_LINK:
  543. case SNDRV_PCM_IOCTL_UNLINK:
  544. case __SNDRV_PCM_IOCTL_SYNC_PTR32:
  545. return snd_pcm_common_ioctl(file, substream, cmd, argp);
  546. case __SNDRV_PCM_IOCTL_SYNC_PTR64:
  547. #ifdef CONFIG_X86_X32_ABI
  548. if (in_x32_syscall())
  549. return snd_pcm_ioctl_sync_ptr_x32(substream, argp);
  550. #endif /* CONFIG_X86_X32_ABI */
  551. return snd_pcm_ioctl_sync_ptr_buggy(substream, argp);
  552. case SNDRV_PCM_IOCTL_HW_REFINE32:
  553. return snd_pcm_ioctl_hw_params_compat(substream, 1, argp);
  554. case SNDRV_PCM_IOCTL_HW_PARAMS32:
  555. return snd_pcm_ioctl_hw_params_compat(substream, 0, argp);
  556. case SNDRV_PCM_IOCTL_SW_PARAMS32:
  557. return snd_pcm_ioctl_sw_params_compat(substream, argp);
  558. case SNDRV_PCM_IOCTL_STATUS_COMPAT32:
  559. return snd_pcm_status_user32(substream, argp, false);
  560. case SNDRV_PCM_IOCTL_STATUS_EXT_COMPAT32:
  561. return snd_pcm_status_user32(substream, argp, true);
  562. case SNDRV_PCM_IOCTL_CHANNEL_INFO32:
  563. return snd_pcm_ioctl_channel_info_compat(substream, argp);
  564. case SNDRV_PCM_IOCTL_WRITEI_FRAMES32:
  565. return snd_pcm_ioctl_xferi_compat(substream, SNDRV_PCM_STREAM_PLAYBACK, argp);
  566. case SNDRV_PCM_IOCTL_READI_FRAMES32:
  567. return snd_pcm_ioctl_xferi_compat(substream, SNDRV_PCM_STREAM_CAPTURE, argp);
  568. case SNDRV_PCM_IOCTL_WRITEN_FRAMES32:
  569. return snd_pcm_ioctl_xfern_compat(substream, SNDRV_PCM_STREAM_PLAYBACK, argp);
  570. case SNDRV_PCM_IOCTL_READN_FRAMES32:
  571. return snd_pcm_ioctl_xfern_compat(substream, SNDRV_PCM_STREAM_CAPTURE, argp);
  572. case SNDRV_PCM_IOCTL_DELAY32:
  573. return snd_pcm_ioctl_delay_compat(substream, argp);
  574. case SNDRV_PCM_IOCTL_REWIND32:
  575. return snd_pcm_ioctl_rewind_compat(substream, argp);
  576. case SNDRV_PCM_IOCTL_FORWARD32:
  577. return snd_pcm_ioctl_forward_compat(substream, argp);
  578. case SNDRV_PCM_IOCTL_STATUS_COMPAT64:
  579. return snd_pcm_status_user_compat64(substream, argp, false);
  580. case SNDRV_PCM_IOCTL_STATUS_EXT_COMPAT64:
  581. return snd_pcm_status_user_compat64(substream, argp, true);
  582. #ifdef CONFIG_X86_X32_ABI
  583. case SNDRV_PCM_IOCTL_CHANNEL_INFO_X32:
  584. return snd_pcm_ioctl_channel_info_x32(substream, argp);
  585. #endif /* CONFIG_X86_X32_ABI */
  586. }
  587. return -ENOIOCTLCMD;
  588. }