pcm_compat.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740
  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 ((ch = substream->runtime->channels) > 128)
  384. return -EINVAL;
  385. if (get_user(buf, &data32->bufs) ||
  386. get_user(frames, &data32->frames))
  387. return -EFAULT;
  388. bufptr = compat_ptr(buf);
  389. bufs = kmalloc(sizeof(void __user *) * ch, GFP_KERNEL);
  390. if (bufs == NULL)
  391. return -ENOMEM;
  392. for (i = 0; i < ch; i++) {
  393. u32 ptr;
  394. if (get_user(ptr, bufptr)) {
  395. kfree(bufs);
  396. return -EFAULT;
  397. }
  398. bufs[i] = compat_ptr(ptr);
  399. bufptr++;
  400. }
  401. if (dir == SNDRV_PCM_STREAM_PLAYBACK)
  402. err = snd_pcm_lib_writev(substream, bufs, frames);
  403. else
  404. err = snd_pcm_lib_readv(substream, bufs, frames);
  405. if (err >= 0) {
  406. if (put_user(err, &data32->result))
  407. err = -EFAULT;
  408. }
  409. kfree(bufs);
  410. return err;
  411. }
  412. struct snd_pcm_mmap_status32 {
  413. s32 state;
  414. s32 pad1;
  415. u32 hw_ptr;
  416. struct compat_timespec tstamp;
  417. s32 suspended_state;
  418. struct compat_timespec audio_tstamp;
  419. } __attribute__((packed));
  420. struct snd_pcm_mmap_control32 {
  421. u32 appl_ptr;
  422. u32 avail_min;
  423. };
  424. struct snd_pcm_sync_ptr32 {
  425. u32 flags;
  426. union {
  427. struct snd_pcm_mmap_status32 status;
  428. unsigned char reserved[64];
  429. } s;
  430. union {
  431. struct snd_pcm_mmap_control32 control;
  432. unsigned char reserved[64];
  433. } c;
  434. } __attribute__((packed));
  435. static int snd_pcm_ioctl_sync_ptr_compat(struct snd_pcm_substream *substream,
  436. struct snd_pcm_sync_ptr32 __user *src)
  437. {
  438. struct snd_pcm_runtime *runtime = substream->runtime;
  439. volatile struct snd_pcm_mmap_status *status;
  440. volatile struct snd_pcm_mmap_control *control;
  441. u32 sflags;
  442. struct snd_pcm_mmap_control scontrol;
  443. struct snd_pcm_mmap_status sstatus;
  444. snd_pcm_uframes_t boundary;
  445. int err;
  446. if (snd_BUG_ON(!runtime))
  447. return -EINVAL;
  448. if (get_user(sflags, &src->flags) ||
  449. get_user(scontrol.appl_ptr, &src->c.control.appl_ptr) ||
  450. get_user(scontrol.avail_min, &src->c.control.avail_min))
  451. return -EFAULT;
  452. if (sflags & SNDRV_PCM_SYNC_PTR_HWSYNC) {
  453. err = snd_pcm_hwsync(substream);
  454. if (err < 0)
  455. return err;
  456. }
  457. status = runtime->status;
  458. control = runtime->control;
  459. boundary = recalculate_boundary(runtime);
  460. if (! boundary)
  461. boundary = 0x7fffffff;
  462. snd_pcm_stream_lock_irq(substream);
  463. /* FIXME: we should consider the boundary for the sync from app */
  464. if (!(sflags & SNDRV_PCM_SYNC_PTR_APPL))
  465. control->appl_ptr = scontrol.appl_ptr;
  466. else
  467. scontrol.appl_ptr = control->appl_ptr % boundary;
  468. if (!(sflags & SNDRV_PCM_SYNC_PTR_AVAIL_MIN))
  469. control->avail_min = scontrol.avail_min;
  470. else
  471. scontrol.avail_min = control->avail_min;
  472. sstatus.state = status->state;
  473. sstatus.hw_ptr = status->hw_ptr % boundary;
  474. sstatus.tstamp = status->tstamp;
  475. sstatus.suspended_state = status->suspended_state;
  476. sstatus.audio_tstamp = status->audio_tstamp;
  477. snd_pcm_stream_unlock_irq(substream);
  478. if (put_user(sstatus.state, &src->s.status.state) ||
  479. put_user(sstatus.hw_ptr, &src->s.status.hw_ptr) ||
  480. compat_put_timespec(&sstatus.tstamp, &src->s.status.tstamp) ||
  481. put_user(sstatus.suspended_state, &src->s.status.suspended_state) ||
  482. compat_put_timespec(&sstatus.audio_tstamp,
  483. &src->s.status.audio_tstamp) ||
  484. put_user(scontrol.appl_ptr, &src->c.control.appl_ptr) ||
  485. put_user(scontrol.avail_min, &src->c.control.avail_min))
  486. return -EFAULT;
  487. return 0;
  488. }
  489. #ifdef CONFIG_X86_X32
  490. /* X32 ABI has 64bit timespec and 64bit alignment */
  491. struct snd_pcm_mmap_status_x32 {
  492. s32 state;
  493. s32 pad1;
  494. u32 hw_ptr;
  495. u32 pad2; /* alignment */
  496. struct timespec tstamp;
  497. s32 suspended_state;
  498. struct timespec audio_tstamp;
  499. } __packed;
  500. struct snd_pcm_mmap_control_x32 {
  501. u32 appl_ptr;
  502. u32 avail_min;
  503. };
  504. struct snd_pcm_sync_ptr_x32 {
  505. u32 flags;
  506. u32 rsvd; /* alignment */
  507. union {
  508. struct snd_pcm_mmap_status_x32 status;
  509. unsigned char reserved[64];
  510. } s;
  511. union {
  512. struct snd_pcm_mmap_control_x32 control;
  513. unsigned char reserved[64];
  514. } c;
  515. } __packed;
  516. static int snd_pcm_ioctl_sync_ptr_x32(struct snd_pcm_substream *substream,
  517. struct snd_pcm_sync_ptr_x32 __user *src)
  518. {
  519. struct snd_pcm_runtime *runtime = substream->runtime;
  520. volatile struct snd_pcm_mmap_status *status;
  521. volatile struct snd_pcm_mmap_control *control;
  522. u32 sflags;
  523. struct snd_pcm_mmap_control scontrol;
  524. struct snd_pcm_mmap_status sstatus;
  525. snd_pcm_uframes_t boundary;
  526. int err;
  527. if (snd_BUG_ON(!runtime))
  528. return -EINVAL;
  529. if (get_user(sflags, &src->flags) ||
  530. get_user(scontrol.appl_ptr, &src->c.control.appl_ptr) ||
  531. get_user(scontrol.avail_min, &src->c.control.avail_min))
  532. return -EFAULT;
  533. if (sflags & SNDRV_PCM_SYNC_PTR_HWSYNC) {
  534. err = snd_pcm_hwsync(substream);
  535. if (err < 0)
  536. return err;
  537. }
  538. status = runtime->status;
  539. control = runtime->control;
  540. boundary = recalculate_boundary(runtime);
  541. if (!boundary)
  542. boundary = 0x7fffffff;
  543. snd_pcm_stream_lock_irq(substream);
  544. /* FIXME: we should consider the boundary for the sync from app */
  545. if (!(sflags & SNDRV_PCM_SYNC_PTR_APPL))
  546. control->appl_ptr = scontrol.appl_ptr;
  547. else
  548. scontrol.appl_ptr = control->appl_ptr % boundary;
  549. if (!(sflags & SNDRV_PCM_SYNC_PTR_AVAIL_MIN))
  550. control->avail_min = scontrol.avail_min;
  551. else
  552. scontrol.avail_min = control->avail_min;
  553. sstatus.state = status->state;
  554. sstatus.hw_ptr = status->hw_ptr % boundary;
  555. sstatus.tstamp = status->tstamp;
  556. sstatus.suspended_state = status->suspended_state;
  557. sstatus.audio_tstamp = status->audio_tstamp;
  558. snd_pcm_stream_unlock_irq(substream);
  559. if (put_user(sstatus.state, &src->s.status.state) ||
  560. put_user(sstatus.hw_ptr, &src->s.status.hw_ptr) ||
  561. put_timespec(&sstatus.tstamp, &src->s.status.tstamp) ||
  562. put_user(sstatus.suspended_state, &src->s.status.suspended_state) ||
  563. put_timespec(&sstatus.audio_tstamp, &src->s.status.audio_tstamp) ||
  564. put_user(scontrol.appl_ptr, &src->c.control.appl_ptr) ||
  565. put_user(scontrol.avail_min, &src->c.control.avail_min))
  566. return -EFAULT;
  567. return 0;
  568. }
  569. #endif /* CONFIG_X86_X32 */
  570. /*
  571. */
  572. enum {
  573. SNDRV_PCM_IOCTL_HW_REFINE32 = _IOWR('A', 0x10, struct snd_pcm_hw_params32),
  574. SNDRV_PCM_IOCTL_HW_PARAMS32 = _IOWR('A', 0x11, struct snd_pcm_hw_params32),
  575. SNDRV_PCM_IOCTL_SW_PARAMS32 = _IOWR('A', 0x13, struct snd_pcm_sw_params32),
  576. SNDRV_PCM_IOCTL_STATUS32 = _IOR('A', 0x20, struct snd_pcm_status32),
  577. SNDRV_PCM_IOCTL_STATUS_EXT32 = _IOWR('A', 0x24, struct snd_pcm_status32),
  578. SNDRV_PCM_IOCTL_DELAY32 = _IOR('A', 0x21, s32),
  579. SNDRV_PCM_IOCTL_CHANNEL_INFO32 = _IOR('A', 0x32, struct snd_pcm_channel_info32),
  580. SNDRV_PCM_IOCTL_REWIND32 = _IOW('A', 0x46, u32),
  581. SNDRV_PCM_IOCTL_FORWARD32 = _IOW('A', 0x49, u32),
  582. SNDRV_PCM_IOCTL_WRITEI_FRAMES32 = _IOW('A', 0x50, struct snd_xferi32),
  583. SNDRV_PCM_IOCTL_READI_FRAMES32 = _IOR('A', 0x51, struct snd_xferi32),
  584. SNDRV_PCM_IOCTL_WRITEN_FRAMES32 = _IOW('A', 0x52, struct snd_xfern32),
  585. SNDRV_PCM_IOCTL_READN_FRAMES32 = _IOR('A', 0x53, struct snd_xfern32),
  586. SNDRV_PCM_IOCTL_SYNC_PTR32 = _IOWR('A', 0x23, struct snd_pcm_sync_ptr32),
  587. #ifdef CONFIG_X86_X32
  588. SNDRV_PCM_IOCTL_CHANNEL_INFO_X32 = _IOR('A', 0x32, struct snd_pcm_channel_info),
  589. SNDRV_PCM_IOCTL_STATUS_X32 = _IOR('A', 0x20, struct snd_pcm_status_x32),
  590. SNDRV_PCM_IOCTL_STATUS_EXT_X32 = _IOWR('A', 0x24, struct snd_pcm_status_x32),
  591. SNDRV_PCM_IOCTL_SYNC_PTR_X32 = _IOWR('A', 0x23, struct snd_pcm_sync_ptr_x32),
  592. #endif /* CONFIG_X86_X32 */
  593. };
  594. static long snd_pcm_ioctl_compat(struct file *file, unsigned int cmd, unsigned long arg)
  595. {
  596. struct snd_pcm_file *pcm_file;
  597. struct snd_pcm_substream *substream;
  598. void __user *argp = compat_ptr(arg);
  599. pcm_file = file->private_data;
  600. if (! pcm_file)
  601. return -ENOTTY;
  602. substream = pcm_file->substream;
  603. if (! substream)
  604. return -ENOTTY;
  605. /*
  606. * When PCM is used on 32bit mode, we need to disable
  607. * mmap of PCM status/control records because of the size
  608. * incompatibility.
  609. */
  610. pcm_file->no_compat_mmap = 1;
  611. switch (cmd) {
  612. case SNDRV_PCM_IOCTL_PVERSION:
  613. case SNDRV_PCM_IOCTL_INFO:
  614. case SNDRV_PCM_IOCTL_TSTAMP:
  615. case SNDRV_PCM_IOCTL_TTSTAMP:
  616. case SNDRV_PCM_IOCTL_HWSYNC:
  617. case SNDRV_PCM_IOCTL_PREPARE:
  618. case SNDRV_PCM_IOCTL_RESET:
  619. case SNDRV_PCM_IOCTL_START:
  620. case SNDRV_PCM_IOCTL_DROP:
  621. case SNDRV_PCM_IOCTL_DRAIN:
  622. case SNDRV_PCM_IOCTL_PAUSE:
  623. case SNDRV_PCM_IOCTL_HW_FREE:
  624. case SNDRV_PCM_IOCTL_RESUME:
  625. case SNDRV_PCM_IOCTL_XRUN:
  626. case SNDRV_PCM_IOCTL_LINK:
  627. case SNDRV_PCM_IOCTL_UNLINK:
  628. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
  629. return snd_pcm_playback_ioctl1(file, substream, cmd, argp);
  630. else
  631. return snd_pcm_capture_ioctl1(file, substream, cmd, argp);
  632. case SNDRV_PCM_IOCTL_HW_REFINE32:
  633. return snd_pcm_ioctl_hw_params_compat(substream, 1, argp);
  634. case SNDRV_PCM_IOCTL_HW_PARAMS32:
  635. return snd_pcm_ioctl_hw_params_compat(substream, 0, argp);
  636. case SNDRV_PCM_IOCTL_SW_PARAMS32:
  637. return snd_pcm_ioctl_sw_params_compat(substream, argp);
  638. case SNDRV_PCM_IOCTL_STATUS32:
  639. return snd_pcm_status_user_compat(substream, argp, false);
  640. case SNDRV_PCM_IOCTL_STATUS_EXT32:
  641. return snd_pcm_status_user_compat(substream, argp, true);
  642. case SNDRV_PCM_IOCTL_SYNC_PTR32:
  643. return snd_pcm_ioctl_sync_ptr_compat(substream, argp);
  644. case SNDRV_PCM_IOCTL_CHANNEL_INFO32:
  645. return snd_pcm_ioctl_channel_info_compat(substream, argp);
  646. case SNDRV_PCM_IOCTL_WRITEI_FRAMES32:
  647. return snd_pcm_ioctl_xferi_compat(substream, SNDRV_PCM_STREAM_PLAYBACK, argp);
  648. case SNDRV_PCM_IOCTL_READI_FRAMES32:
  649. return snd_pcm_ioctl_xferi_compat(substream, SNDRV_PCM_STREAM_CAPTURE, argp);
  650. case SNDRV_PCM_IOCTL_WRITEN_FRAMES32:
  651. return snd_pcm_ioctl_xfern_compat(substream, SNDRV_PCM_STREAM_PLAYBACK, argp);
  652. case SNDRV_PCM_IOCTL_READN_FRAMES32:
  653. return snd_pcm_ioctl_xfern_compat(substream, SNDRV_PCM_STREAM_CAPTURE, argp);
  654. case SNDRV_PCM_IOCTL_DELAY32:
  655. return snd_pcm_ioctl_delay_compat(substream, argp);
  656. case SNDRV_PCM_IOCTL_REWIND32:
  657. return snd_pcm_ioctl_rewind_compat(substream, argp);
  658. case SNDRV_PCM_IOCTL_FORWARD32:
  659. return snd_pcm_ioctl_forward_compat(substream, argp);
  660. #ifdef CONFIG_X86_X32
  661. case SNDRV_PCM_IOCTL_STATUS_X32:
  662. return snd_pcm_status_user_x32(substream, argp, false);
  663. case SNDRV_PCM_IOCTL_STATUS_EXT_X32:
  664. return snd_pcm_status_user_x32(substream, argp, true);
  665. case SNDRV_PCM_IOCTL_SYNC_PTR_X32:
  666. return snd_pcm_ioctl_sync_ptr_x32(substream, argp);
  667. case SNDRV_PCM_IOCTL_CHANNEL_INFO_X32:
  668. return snd_pcm_ioctl_channel_info_x32(substream, argp);
  669. #endif /* CONFIG_X86_X32 */
  670. }
  671. return -ENOIOCTLCMD;
  672. }