pcm_compat.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646
  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
  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 */
  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;
  215. struct snd_pcm_runtime *runtime;
  216. int err;
  217. if (! (runtime = substream->runtime))
  218. return -ENOTTY;
  219. data = kmalloc(sizeof(*data), GFP_KERNEL);
  220. if (!data)
  221. return -ENOMEM;
  222. /* only fifo_size (RO from userspace) is different, so just copy all */
  223. if (copy_from_user(data, data32, sizeof(*data32))) {
  224. err = -EFAULT;
  225. goto error;
  226. }
  227. if (refine)
  228. err = snd_pcm_hw_refine(substream, data);
  229. else
  230. err = snd_pcm_hw_params(substream, data);
  231. if (err < 0)
  232. goto error;
  233. if (copy_to_user(data32, data, sizeof(*data32)) ||
  234. put_user(data->fifo_size, &data32->fifo_size)) {
  235. err = -EFAULT;
  236. goto error;
  237. }
  238. if (! refine) {
  239. unsigned int new_boundary = recalculate_boundary(runtime);
  240. if (new_boundary)
  241. runtime->boundary = new_boundary;
  242. }
  243. error:
  244. kfree(data);
  245. return err;
  246. }
  247. /*
  248. */
  249. struct snd_xferi32 {
  250. s32 result;
  251. u32 buf;
  252. u32 frames;
  253. };
  254. static int snd_pcm_ioctl_xferi_compat(struct snd_pcm_substream *substream,
  255. int dir, struct snd_xferi32 __user *data32)
  256. {
  257. compat_caddr_t buf;
  258. u32 frames;
  259. int err;
  260. if (! substream->runtime)
  261. return -ENOTTY;
  262. if (substream->stream != dir)
  263. return -EINVAL;
  264. if (substream->runtime->status->state == SNDRV_PCM_STATE_OPEN)
  265. return -EBADFD;
  266. if (get_user(buf, &data32->buf) ||
  267. get_user(frames, &data32->frames))
  268. return -EFAULT;
  269. if (dir == SNDRV_PCM_STREAM_PLAYBACK)
  270. err = snd_pcm_lib_write(substream, compat_ptr(buf), frames);
  271. else
  272. err = snd_pcm_lib_read(substream, compat_ptr(buf), frames);
  273. if (err < 0)
  274. return err;
  275. /* copy the result */
  276. if (put_user(err, &data32->result))
  277. return -EFAULT;
  278. return 0;
  279. }
  280. /* snd_xfern needs remapping of bufs */
  281. struct snd_xfern32 {
  282. s32 result;
  283. u32 bufs; /* this is void **; */
  284. u32 frames;
  285. };
  286. /*
  287. * xfern ioctl nees to copy (up to) 128 pointers on stack.
  288. * although we may pass the copied pointers through f_op->ioctl, but the ioctl
  289. * handler there expands again the same 128 pointers on stack, so it is better
  290. * to handle the function (calling pcm_readv/writev) directly in this handler.
  291. */
  292. static int snd_pcm_ioctl_xfern_compat(struct snd_pcm_substream *substream,
  293. int dir, struct snd_xfern32 __user *data32)
  294. {
  295. compat_caddr_t buf;
  296. compat_caddr_t __user *bufptr;
  297. u32 frames;
  298. void __user **bufs;
  299. int err, ch, i;
  300. if (! substream->runtime)
  301. return -ENOTTY;
  302. if (substream->stream != dir)
  303. return -EINVAL;
  304. if (substream->runtime->status->state == SNDRV_PCM_STATE_OPEN)
  305. return -EBADFD;
  306. if ((ch = substream->runtime->channels) > 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. kfree(bufs);
  319. return -EFAULT;
  320. }
  321. bufs[i] = compat_ptr(ptr);
  322. bufptr++;
  323. }
  324. if (dir == SNDRV_PCM_STREAM_PLAYBACK)
  325. err = snd_pcm_lib_writev(substream, bufs, frames);
  326. else
  327. err = snd_pcm_lib_readv(substream, bufs, frames);
  328. if (err >= 0) {
  329. if (put_user(err, &data32->result))
  330. err = -EFAULT;
  331. }
  332. kfree(bufs);
  333. return err;
  334. }
  335. #ifdef CONFIG_X86_X32
  336. /* X32 ABI has 64bit timespec and 64bit alignment */
  337. struct snd_pcm_mmap_status_x32 {
  338. snd_pcm_state_t state;
  339. s32 pad1;
  340. u32 hw_ptr;
  341. u32 pad2; /* alignment */
  342. s64 tstamp_sec;
  343. s64 tstamp_nsec;
  344. snd_pcm_state_t suspended_state;
  345. s32 pad3;
  346. s64 audio_tstamp_sec;
  347. s64 audio_tstamp_nsec;
  348. } __packed;
  349. struct snd_pcm_mmap_control_x32 {
  350. u32 appl_ptr;
  351. u32 avail_min;
  352. };
  353. struct snd_pcm_sync_ptr_x32 {
  354. u32 flags;
  355. u32 rsvd; /* alignment */
  356. union {
  357. struct snd_pcm_mmap_status_x32 status;
  358. unsigned char reserved[64];
  359. } s;
  360. union {
  361. struct snd_pcm_mmap_control_x32 control;
  362. unsigned char reserved[64];
  363. } c;
  364. } __packed;
  365. static int snd_pcm_ioctl_sync_ptr_x32(struct snd_pcm_substream *substream,
  366. struct snd_pcm_sync_ptr_x32 __user *src)
  367. {
  368. struct snd_pcm_runtime *runtime = substream->runtime;
  369. volatile struct snd_pcm_mmap_status *status;
  370. volatile struct snd_pcm_mmap_control *control;
  371. u32 sflags;
  372. struct snd_pcm_mmap_control scontrol;
  373. struct snd_pcm_mmap_status sstatus;
  374. snd_pcm_uframes_t boundary;
  375. int err;
  376. if (snd_BUG_ON(!runtime))
  377. return -EINVAL;
  378. if (get_user(sflags, &src->flags) ||
  379. get_user(scontrol.appl_ptr, &src->c.control.appl_ptr) ||
  380. get_user(scontrol.avail_min, &src->c.control.avail_min))
  381. return -EFAULT;
  382. if (sflags & SNDRV_PCM_SYNC_PTR_HWSYNC) {
  383. err = snd_pcm_hwsync(substream);
  384. if (err < 0)
  385. return err;
  386. }
  387. status = runtime->status;
  388. control = runtime->control;
  389. boundary = recalculate_boundary(runtime);
  390. if (!boundary)
  391. boundary = 0x7fffffff;
  392. snd_pcm_stream_lock_irq(substream);
  393. /* FIXME: we should consider the boundary for the sync from app */
  394. if (!(sflags & SNDRV_PCM_SYNC_PTR_APPL))
  395. control->appl_ptr = scontrol.appl_ptr;
  396. else
  397. scontrol.appl_ptr = control->appl_ptr % boundary;
  398. if (!(sflags & SNDRV_PCM_SYNC_PTR_AVAIL_MIN))
  399. control->avail_min = scontrol.avail_min;
  400. else
  401. scontrol.avail_min = control->avail_min;
  402. sstatus.state = status->state;
  403. sstatus.hw_ptr = status->hw_ptr % boundary;
  404. sstatus.tstamp = status->tstamp;
  405. sstatus.suspended_state = status->suspended_state;
  406. sstatus.audio_tstamp = status->audio_tstamp;
  407. snd_pcm_stream_unlock_irq(substream);
  408. if (put_user(sstatus.state, &src->s.status.state) ||
  409. put_user(sstatus.hw_ptr, &src->s.status.hw_ptr) ||
  410. put_user(sstatus.tstamp.tv_sec, &src->s.status.tstamp_sec) ||
  411. put_user(sstatus.tstamp.tv_nsec, &src->s.status.tstamp_nsec) ||
  412. put_user(sstatus.suspended_state, &src->s.status.suspended_state) ||
  413. put_user(sstatus.audio_tstamp.tv_sec, &src->s.status.audio_tstamp_sec) ||
  414. put_user(sstatus.audio_tstamp.tv_nsec, &src->s.status.audio_tstamp_nsec) ||
  415. put_user(scontrol.appl_ptr, &src->c.control.appl_ptr) ||
  416. put_user(scontrol.avail_min, &src->c.control.avail_min))
  417. return -EFAULT;
  418. return 0;
  419. }
  420. #endif /* CONFIG_X86_X32 */
  421. #ifdef __BIG_ENDIAN
  422. typedef char __pad_before_u32[4];
  423. typedef char __pad_after_u32[0];
  424. #else
  425. typedef char __pad_before_u32[0];
  426. typedef char __pad_after_u32[4];
  427. #endif
  428. /* PCM 2.0.15 API definition had a bug in mmap control; it puts the avail_min
  429. * at the wrong offset due to a typo in padding type.
  430. * The bug hits only 32bit.
  431. * A workaround for incorrect read/write is needed only in 32bit compat mode.
  432. */
  433. struct __snd_pcm_mmap_control64_buggy {
  434. __pad_before_u32 __pad1;
  435. __u32 appl_ptr;
  436. __pad_before_u32 __pad2; /* SiC! here is the bug */
  437. __pad_before_u32 __pad3;
  438. __u32 avail_min;
  439. __pad_after_uframe __pad4;
  440. };
  441. static int snd_pcm_ioctl_sync_ptr_buggy(struct snd_pcm_substream *substream,
  442. struct snd_pcm_sync_ptr __user *_sync_ptr)
  443. {
  444. struct snd_pcm_runtime *runtime = substream->runtime;
  445. struct snd_pcm_sync_ptr sync_ptr;
  446. struct __snd_pcm_mmap_control64_buggy *sync_cp;
  447. volatile struct snd_pcm_mmap_status *status;
  448. volatile struct snd_pcm_mmap_control *control;
  449. int err;
  450. memset(&sync_ptr, 0, sizeof(sync_ptr));
  451. sync_cp = (struct __snd_pcm_mmap_control64_buggy *)&sync_ptr.c.control;
  452. if (get_user(sync_ptr.flags, (unsigned __user *)&(_sync_ptr->flags)))
  453. return -EFAULT;
  454. if (copy_from_user(sync_cp, &(_sync_ptr->c.control), sizeof(*sync_cp)))
  455. return -EFAULT;
  456. status = runtime->status;
  457. control = runtime->control;
  458. if (sync_ptr.flags & SNDRV_PCM_SYNC_PTR_HWSYNC) {
  459. err = snd_pcm_hwsync(substream);
  460. if (err < 0)
  461. return err;
  462. }
  463. snd_pcm_stream_lock_irq(substream);
  464. if (!(sync_ptr.flags & SNDRV_PCM_SYNC_PTR_APPL)) {
  465. err = pcm_lib_apply_appl_ptr(substream, sync_cp->appl_ptr);
  466. if (err < 0) {
  467. snd_pcm_stream_unlock_irq(substream);
  468. return err;
  469. }
  470. } else {
  471. sync_cp->appl_ptr = control->appl_ptr;
  472. }
  473. if (!(sync_ptr.flags & SNDRV_PCM_SYNC_PTR_AVAIL_MIN))
  474. control->avail_min = sync_cp->avail_min;
  475. else
  476. sync_cp->avail_min = control->avail_min;
  477. sync_ptr.s.status.state = status->state;
  478. sync_ptr.s.status.hw_ptr = status->hw_ptr;
  479. sync_ptr.s.status.tstamp = status->tstamp;
  480. sync_ptr.s.status.suspended_state = status->suspended_state;
  481. sync_ptr.s.status.audio_tstamp = status->audio_tstamp;
  482. snd_pcm_stream_unlock_irq(substream);
  483. if (copy_to_user(_sync_ptr, &sync_ptr, sizeof(sync_ptr)))
  484. return -EFAULT;
  485. return 0;
  486. }
  487. /*
  488. */
  489. enum {
  490. SNDRV_PCM_IOCTL_HW_REFINE32 = _IOWR('A', 0x10, struct snd_pcm_hw_params32),
  491. SNDRV_PCM_IOCTL_HW_PARAMS32 = _IOWR('A', 0x11, struct snd_pcm_hw_params32),
  492. SNDRV_PCM_IOCTL_SW_PARAMS32 = _IOWR('A', 0x13, struct snd_pcm_sw_params32),
  493. SNDRV_PCM_IOCTL_STATUS_COMPAT32 = _IOR('A', 0x20, struct snd_pcm_status32),
  494. SNDRV_PCM_IOCTL_STATUS_EXT_COMPAT32 = _IOWR('A', 0x24, struct snd_pcm_status32),
  495. SNDRV_PCM_IOCTL_DELAY32 = _IOR('A', 0x21, s32),
  496. SNDRV_PCM_IOCTL_CHANNEL_INFO32 = _IOR('A', 0x32, struct snd_pcm_channel_info32),
  497. SNDRV_PCM_IOCTL_REWIND32 = _IOW('A', 0x46, u32),
  498. SNDRV_PCM_IOCTL_FORWARD32 = _IOW('A', 0x49, u32),
  499. SNDRV_PCM_IOCTL_WRITEI_FRAMES32 = _IOW('A', 0x50, struct snd_xferi32),
  500. SNDRV_PCM_IOCTL_READI_FRAMES32 = _IOR('A', 0x51, struct snd_xferi32),
  501. SNDRV_PCM_IOCTL_WRITEN_FRAMES32 = _IOW('A', 0x52, struct snd_xfern32),
  502. SNDRV_PCM_IOCTL_READN_FRAMES32 = _IOR('A', 0x53, struct snd_xfern32),
  503. SNDRV_PCM_IOCTL_STATUS_COMPAT64 = _IOR('A', 0x20, struct compat_snd_pcm_status64),
  504. SNDRV_PCM_IOCTL_STATUS_EXT_COMPAT64 = _IOWR('A', 0x24, struct compat_snd_pcm_status64),
  505. #ifdef CONFIG_X86_X32
  506. SNDRV_PCM_IOCTL_CHANNEL_INFO_X32 = _IOR('A', 0x32, struct snd_pcm_channel_info),
  507. SNDRV_PCM_IOCTL_SYNC_PTR_X32 = _IOWR('A', 0x23, struct snd_pcm_sync_ptr_x32),
  508. #endif /* CONFIG_X86_X32 */
  509. };
  510. static long snd_pcm_ioctl_compat(struct file *file, unsigned int cmd, unsigned long arg)
  511. {
  512. struct snd_pcm_file *pcm_file;
  513. struct snd_pcm_substream *substream;
  514. void __user *argp = compat_ptr(arg);
  515. pcm_file = file->private_data;
  516. if (! pcm_file)
  517. return -ENOTTY;
  518. substream = pcm_file->substream;
  519. if (! substream)
  520. return -ENOTTY;
  521. /*
  522. * When PCM is used on 32bit mode, we need to disable
  523. * mmap of the old PCM status/control records because
  524. * of the size incompatibility.
  525. */
  526. pcm_file->no_compat_mmap = 1;
  527. switch (cmd) {
  528. case SNDRV_PCM_IOCTL_PVERSION:
  529. case SNDRV_PCM_IOCTL_INFO:
  530. case SNDRV_PCM_IOCTL_TSTAMP:
  531. case SNDRV_PCM_IOCTL_TTSTAMP:
  532. case SNDRV_PCM_IOCTL_USER_PVERSION:
  533. case SNDRV_PCM_IOCTL_HWSYNC:
  534. case SNDRV_PCM_IOCTL_PREPARE:
  535. case SNDRV_PCM_IOCTL_RESET:
  536. case SNDRV_PCM_IOCTL_START:
  537. case SNDRV_PCM_IOCTL_DROP:
  538. case SNDRV_PCM_IOCTL_DRAIN:
  539. case SNDRV_PCM_IOCTL_PAUSE:
  540. case SNDRV_PCM_IOCTL_HW_FREE:
  541. case SNDRV_PCM_IOCTL_RESUME:
  542. case SNDRV_PCM_IOCTL_XRUN:
  543. case SNDRV_PCM_IOCTL_LINK:
  544. case SNDRV_PCM_IOCTL_UNLINK:
  545. case __SNDRV_PCM_IOCTL_SYNC_PTR32:
  546. return snd_pcm_common_ioctl(file, substream, cmd, argp);
  547. case __SNDRV_PCM_IOCTL_SYNC_PTR64:
  548. #ifdef CONFIG_X86_X32
  549. if (in_x32_syscall())
  550. return snd_pcm_ioctl_sync_ptr_x32(substream, argp);
  551. #endif /* CONFIG_X86_X32 */
  552. return snd_pcm_ioctl_sync_ptr_buggy(substream, argp);
  553. case SNDRV_PCM_IOCTL_HW_REFINE32:
  554. return snd_pcm_ioctl_hw_params_compat(substream, 1, argp);
  555. case SNDRV_PCM_IOCTL_HW_PARAMS32:
  556. return snd_pcm_ioctl_hw_params_compat(substream, 0, argp);
  557. case SNDRV_PCM_IOCTL_SW_PARAMS32:
  558. return snd_pcm_ioctl_sw_params_compat(substream, argp);
  559. case SNDRV_PCM_IOCTL_STATUS_COMPAT32:
  560. return snd_pcm_status_user32(substream, argp, false);
  561. case SNDRV_PCM_IOCTL_STATUS_EXT_COMPAT32:
  562. return snd_pcm_status_user32(substream, argp, true);
  563. case SNDRV_PCM_IOCTL_CHANNEL_INFO32:
  564. return snd_pcm_ioctl_channel_info_compat(substream, argp);
  565. case SNDRV_PCM_IOCTL_WRITEI_FRAMES32:
  566. return snd_pcm_ioctl_xferi_compat(substream, SNDRV_PCM_STREAM_PLAYBACK, argp);
  567. case SNDRV_PCM_IOCTL_READI_FRAMES32:
  568. return snd_pcm_ioctl_xferi_compat(substream, SNDRV_PCM_STREAM_CAPTURE, argp);
  569. case SNDRV_PCM_IOCTL_WRITEN_FRAMES32:
  570. return snd_pcm_ioctl_xfern_compat(substream, SNDRV_PCM_STREAM_PLAYBACK, argp);
  571. case SNDRV_PCM_IOCTL_READN_FRAMES32:
  572. return snd_pcm_ioctl_xfern_compat(substream, SNDRV_PCM_STREAM_CAPTURE, argp);
  573. case SNDRV_PCM_IOCTL_DELAY32:
  574. return snd_pcm_ioctl_delay_compat(substream, argp);
  575. case SNDRV_PCM_IOCTL_REWIND32:
  576. return snd_pcm_ioctl_rewind_compat(substream, argp);
  577. case SNDRV_PCM_IOCTL_FORWARD32:
  578. return snd_pcm_ioctl_forward_compat(substream, argp);
  579. case SNDRV_PCM_IOCTL_STATUS_COMPAT64:
  580. return snd_pcm_status_user_compat64(substream, argp, false);
  581. case SNDRV_PCM_IOCTL_STATUS_EXT_COMPAT64:
  582. return snd_pcm_status_user_compat64(substream, argp, true);
  583. #ifdef CONFIG_X86_X32
  584. case SNDRV_PCM_IOCTL_CHANNEL_INFO_X32:
  585. return snd_pcm_ioctl_channel_info_x32(substream, argp);
  586. #endif /* CONFIG_X86_X32 */
  587. }
  588. return -ENOIOCTLCMD;
  589. }