timer_compat.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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. struct snd_timer_info32 {
  23. u32 flags;
  24. s32 card;
  25. unsigned char id[64];
  26. unsigned char name[80];
  27. u32 reserved0;
  28. u32 resolution;
  29. unsigned char reserved[64];
  30. };
  31. static int snd_timer_user_info_compat(struct file *file,
  32. struct snd_timer_info32 __user *_info)
  33. {
  34. struct snd_timer_user *tu;
  35. struct snd_timer_info32 info;
  36. struct snd_timer *t;
  37. tu = file->private_data;
  38. if (!tu->timeri)
  39. return -EBADFD;
  40. t = tu->timeri->timer;
  41. if (!t)
  42. return -EBADFD;
  43. memset(&info, 0, sizeof(info));
  44. info.card = t->card ? t->card->number : -1;
  45. if (t->hw.flags & SNDRV_TIMER_HW_SLAVE)
  46. info.flags |= SNDRV_TIMER_FLG_SLAVE;
  47. strlcpy(info.id, t->id, sizeof(info.id));
  48. strlcpy(info.name, t->name, sizeof(info.name));
  49. info.resolution = t->hw.resolution;
  50. if (copy_to_user(_info, &info, sizeof(*_info)))
  51. return -EFAULT;
  52. return 0;
  53. }
  54. struct snd_timer_status32 {
  55. struct compat_timespec tstamp;
  56. u32 resolution;
  57. u32 lost;
  58. u32 overrun;
  59. u32 queue;
  60. unsigned char reserved[64];
  61. };
  62. static int snd_timer_user_status_compat(struct file *file,
  63. struct snd_timer_status32 __user *_status)
  64. {
  65. struct snd_timer_user *tu;
  66. struct snd_timer_status32 status;
  67. tu = file->private_data;
  68. if (!tu->timeri)
  69. return -EBADFD;
  70. memset(&status, 0, sizeof(status));
  71. status.tstamp.tv_sec = tu->tstamp.tv_sec;
  72. status.tstamp.tv_nsec = tu->tstamp.tv_nsec;
  73. status.resolution = snd_timer_resolution(tu->timeri);
  74. status.lost = tu->timeri->lost;
  75. status.overrun = tu->overrun;
  76. spin_lock_irq(&tu->qlock);
  77. status.queue = tu->qused;
  78. spin_unlock_irq(&tu->qlock);
  79. if (copy_to_user(_status, &status, sizeof(status)))
  80. return -EFAULT;
  81. return 0;
  82. }
  83. #ifdef CONFIG_X86_X32
  84. /* X32 ABI has the same struct as x86-64 */
  85. #define snd_timer_user_status_x32(file, s) \
  86. snd_timer_user_status(file, s)
  87. #endif /* CONFIG_X86_X32 */
  88. /*
  89. */
  90. enum {
  91. SNDRV_TIMER_IOCTL_INFO32 = _IOR('T', 0x11, struct snd_timer_info32),
  92. SNDRV_TIMER_IOCTL_STATUS32 = _IOW('T', 0x14, struct snd_timer_status32),
  93. #ifdef CONFIG_X86_X32
  94. SNDRV_TIMER_IOCTL_STATUS_X32 = _IOW('T', 0x14, struct snd_timer_status),
  95. #endif /* CONFIG_X86_X32 */
  96. };
  97. static long __snd_timer_user_ioctl_compat(struct file *file, unsigned int cmd,
  98. unsigned long arg)
  99. {
  100. void __user *argp = compat_ptr(arg);
  101. switch (cmd) {
  102. case SNDRV_TIMER_IOCTL_PVERSION:
  103. case SNDRV_TIMER_IOCTL_TREAD:
  104. case SNDRV_TIMER_IOCTL_GINFO:
  105. case SNDRV_TIMER_IOCTL_GPARAMS:
  106. case SNDRV_TIMER_IOCTL_GSTATUS:
  107. case SNDRV_TIMER_IOCTL_SELECT:
  108. case SNDRV_TIMER_IOCTL_PARAMS:
  109. case SNDRV_TIMER_IOCTL_START:
  110. case SNDRV_TIMER_IOCTL_START_OLD:
  111. case SNDRV_TIMER_IOCTL_STOP:
  112. case SNDRV_TIMER_IOCTL_STOP_OLD:
  113. case SNDRV_TIMER_IOCTL_CONTINUE:
  114. case SNDRV_TIMER_IOCTL_CONTINUE_OLD:
  115. case SNDRV_TIMER_IOCTL_PAUSE:
  116. case SNDRV_TIMER_IOCTL_PAUSE_OLD:
  117. case SNDRV_TIMER_IOCTL_NEXT_DEVICE:
  118. return __snd_timer_user_ioctl(file, cmd, (unsigned long)argp);
  119. case SNDRV_TIMER_IOCTL_INFO32:
  120. return snd_timer_user_info_compat(file, argp);
  121. case SNDRV_TIMER_IOCTL_STATUS32:
  122. return snd_timer_user_status_compat(file, argp);
  123. #ifdef CONFIG_X86_X32
  124. case SNDRV_TIMER_IOCTL_STATUS_X32:
  125. return snd_timer_user_status_x32(file, argp);
  126. #endif /* CONFIG_X86_X32 */
  127. }
  128. return -ENOIOCTLCMD;
  129. }
  130. static long snd_timer_user_ioctl_compat(struct file *file, unsigned int cmd,
  131. unsigned long arg)
  132. {
  133. struct snd_timer_user *tu = file->private_data;
  134. long ret;
  135. mutex_lock(&tu->ioctl_lock);
  136. ret = __snd_timer_user_ioctl_compat(file, cmd, arg);
  137. mutex_unlock(&tu->ioctl_lock);
  138. return ret;
  139. }