pcm_compat.c 22 KB

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