timer_compat.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. /*
  2. * 32bit -> 64bit ioctl wrapper for timer 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 timer.c */
  21. #include <linux/compat.h>
  22. /*
  23. * ILP32/LP64 has different size for 'long' type. Additionally, the size
  24. * of storage alignment differs depending on architectures. Here, '__packed'
  25. * qualifier is used so that the size of this structure is multiple of 4 and
  26. * it fits to any architectures with 32 bit storage alignment.
  27. */
  28. struct snd_timer_gparams32 {
  29. struct snd_timer_id tid;
  30. u32 period_num;
  31. u32 period_den;
  32. unsigned char reserved[32];
  33. } __packed;
  34. struct snd_timer_info32 {
  35. u32 flags;
  36. s32 card;
  37. unsigned char id[64];
  38. unsigned char name[80];
  39. u32 reserved0;
  40. u32 resolution;
  41. unsigned char reserved[64];
  42. };
  43. static int snd_timer_user_gparams_compat(struct file *file,
  44. struct snd_timer_gparams32 __user *user)
  45. {
  46. struct snd_timer_gparams gparams;
  47. if (copy_from_user(&gparams.tid, &user->tid, sizeof(gparams.tid)) ||
  48. get_user(gparams.period_num, &user->period_num) ||
  49. get_user(gparams.period_den, &user->period_den))
  50. return -EFAULT;
  51. return timer_set_gparams(&gparams);
  52. }
  53. static int snd_timer_user_info_compat(struct file *file,
  54. struct snd_timer_info32 __user *_info)
  55. {
  56. struct snd_timer_user *tu;
  57. struct snd_timer_info32 info;
  58. struct snd_timer *t;
  59. tu = file->private_data;
  60. if (!tu->timeri)
  61. return -EBADFD;
  62. t = tu->timeri->timer;
  63. if (!t)
  64. return -EBADFD;
  65. memset(&info, 0, sizeof(info));
  66. info.card = t->card ? t->card->number : -1;
  67. if (t->hw.flags & SNDRV_TIMER_HW_SLAVE)
  68. info.flags |= SNDRV_TIMER_FLG_SLAVE;
  69. strlcpy(info.id, t->id, sizeof(info.id));
  70. strlcpy(info.name, t->name, sizeof(info.name));
  71. info.resolution = t->hw.resolution;
  72. if (copy_to_user(_info, &info, sizeof(*_info)))
  73. return -EFAULT;
  74. return 0;
  75. }
  76. struct snd_timer_status32 {
  77. struct compat_timespec tstamp;
  78. u32 resolution;
  79. u32 lost;
  80. u32 overrun;
  81. u32 queue;
  82. unsigned char reserved[64];
  83. };
  84. static int snd_timer_user_status_compat(struct file *file,
  85. struct snd_timer_status32 __user *_status)
  86. {
  87. struct snd_timer_user *tu;
  88. struct snd_timer_status32 status;
  89. tu = file->private_data;
  90. if (!tu->timeri)
  91. return -EBADFD;
  92. memset(&status, 0, sizeof(status));
  93. status.tstamp.tv_sec = tu->tstamp.tv_sec;
  94. status.tstamp.tv_nsec = tu->tstamp.tv_nsec;
  95. status.resolution = snd_timer_resolution(tu->timeri);
  96. status.lost = tu->timeri->lost;
  97. status.overrun = tu->overrun;
  98. spin_lock_irq(&tu->qlock);
  99. status.queue = tu->qused;
  100. spin_unlock_irq(&tu->qlock);
  101. if (copy_to_user(_status, &status, sizeof(status)))
  102. return -EFAULT;
  103. return 0;
  104. }
  105. #ifdef CONFIG_X86_X32
  106. /* X32 ABI has the same struct as x86-64 */
  107. #define snd_timer_user_status_x32(file, s) \
  108. snd_timer_user_status(file, s)
  109. #endif /* CONFIG_X86_X32 */
  110. /*
  111. */
  112. enum {
  113. SNDRV_TIMER_IOCTL_GPARAMS32 = _IOW('T', 0x04, struct snd_timer_gparams32),
  114. SNDRV_TIMER_IOCTL_INFO32 = _IOR('T', 0x11, struct snd_timer_info32),
  115. SNDRV_TIMER_IOCTL_STATUS32 = _IOW('T', 0x14, struct snd_timer_status32),
  116. #ifdef CONFIG_X86_X32
  117. SNDRV_TIMER_IOCTL_STATUS_X32 = _IOW('T', 0x14, struct snd_timer_status),
  118. #endif /* CONFIG_X86_X32 */
  119. };
  120. static long __snd_timer_user_ioctl_compat(struct file *file, unsigned int cmd,
  121. unsigned long arg)
  122. {
  123. void __user *argp = compat_ptr(arg);
  124. switch (cmd) {
  125. case SNDRV_TIMER_IOCTL_PVERSION:
  126. case SNDRV_TIMER_IOCTL_TREAD:
  127. case SNDRV_TIMER_IOCTL_GINFO:
  128. case SNDRV_TIMER_IOCTL_GSTATUS:
  129. case SNDRV_TIMER_IOCTL_SELECT:
  130. case SNDRV_TIMER_IOCTL_PARAMS:
  131. case SNDRV_TIMER_IOCTL_START:
  132. case SNDRV_TIMER_IOCTL_START_OLD:
  133. case SNDRV_TIMER_IOCTL_STOP:
  134. case SNDRV_TIMER_IOCTL_STOP_OLD:
  135. case SNDRV_TIMER_IOCTL_CONTINUE:
  136. case SNDRV_TIMER_IOCTL_CONTINUE_OLD:
  137. case SNDRV_TIMER_IOCTL_PAUSE:
  138. case SNDRV_TIMER_IOCTL_PAUSE_OLD:
  139. case SNDRV_TIMER_IOCTL_NEXT_DEVICE:
  140. return __snd_timer_user_ioctl(file, cmd, (unsigned long)argp);
  141. case SNDRV_TIMER_IOCTL_GPARAMS32:
  142. return snd_timer_user_gparams_compat(file, argp);
  143. case SNDRV_TIMER_IOCTL_INFO32:
  144. return snd_timer_user_info_compat(file, argp);
  145. case SNDRV_TIMER_IOCTL_STATUS32:
  146. return snd_timer_user_status_compat(file, argp);
  147. #ifdef CONFIG_X86_X32
  148. case SNDRV_TIMER_IOCTL_STATUS_X32:
  149. return snd_timer_user_status_x32(file, argp);
  150. #endif /* CONFIG_X86_X32 */
  151. }
  152. return -ENOIOCTLCMD;
  153. }
  154. static long snd_timer_user_ioctl_compat(struct file *file, unsigned int cmd,
  155. unsigned long arg)
  156. {
  157. struct snd_timer_user *tu = file->private_data;
  158. long ret;
  159. mutex_lock(&tu->ioctl_lock);
  160. ret = __snd_timer_user_ioctl_compat(file, cmd, arg);
  161. mutex_unlock(&tu->ioctl_lock);
  162. return ret;
  163. }