pcm_compat.c 22 KB

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