timer_compat.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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 (snd_BUG_ON(!tu->timeri))
  39. return -ENXIO;
  40. t = tu->timeri->timer;
  41. if (snd_BUG_ON(!t))
  42. return -ENXIO;
  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_status status;
  67. tu = file->private_data;
  68. if (snd_BUG_ON(!tu->timeri))
  69. return -ENXIO;
  70. memset(&status, 0, sizeof(status));
  71. status.tstamp = tu->tstamp;
  72. status.resolution = snd_timer_resolution(tu->timeri);
  73. status.lost = tu->timeri->lost;
  74. status.overrun = tu->overrun;
  75. spin_lock_irq(&tu->qlock);
  76. status.queue = tu->qused;
  77. spin_unlock_irq(&tu->qlock);
  78. if (copy_to_user(_status, &status, sizeof(status)))
  79. return -EFAULT;
  80. return 0;
  81. }
  82. /*
  83. */
  84. enum {
  85. SNDRV_TIMER_IOCTL_INFO32 = _IOR('T', 0x11, struct snd_timer_info32),
  86. SNDRV_TIMER_IOCTL_STATUS32 = _IOW('T', 0x14, struct snd_timer_status32),
  87. };
  88. static long snd_timer_user_ioctl_compat(struct file *file, unsigned int cmd, unsigned long arg)
  89. {
  90. void __user *argp = compat_ptr(arg);
  91. switch (cmd) {
  92. case SNDRV_TIMER_IOCTL_PVERSION:
  93. case SNDRV_TIMER_IOCTL_TREAD:
  94. case SNDRV_TIMER_IOCTL_GINFO:
  95. case SNDRV_TIMER_IOCTL_GPARAMS:
  96. case SNDRV_TIMER_IOCTL_GSTATUS:
  97. case SNDRV_TIMER_IOCTL_SELECT:
  98. case SNDRV_TIMER_IOCTL_PARAMS:
  99. case SNDRV_TIMER_IOCTL_START:
  100. case SNDRV_TIMER_IOCTL_START_OLD:
  101. case SNDRV_TIMER_IOCTL_STOP:
  102. case SNDRV_TIMER_IOCTL_STOP_OLD:
  103. case SNDRV_TIMER_IOCTL_CONTINUE:
  104. case SNDRV_TIMER_IOCTL_CONTINUE_OLD:
  105. case SNDRV_TIMER_IOCTL_PAUSE:
  106. case SNDRV_TIMER_IOCTL_PAUSE_OLD:
  107. case SNDRV_TIMER_IOCTL_NEXT_DEVICE:
  108. return snd_timer_user_ioctl(file, cmd, (unsigned long)argp);
  109. case SNDRV_TIMER_IOCTL_INFO32:
  110. return snd_timer_user_info_compat(file, argp);
  111. case SNDRV_TIMER_IOCTL_STATUS32:
  112. return snd_timer_user_status_compat(file, argp);
  113. }
  114. return -ENOIOCTLCMD;
  115. }