pcm_compat.c 22 KB

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