pcm_compat.c 21 KB

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