timer_compat.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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. snd_assert(tu->timeri != NULL, return -ENXIO);
  39. t = tu->timeri->timer;
  40. snd_assert(t != NULL, return -ENXIO);
  41. memset(&info, 0, sizeof(info));
  42. info.card = t->card ? t->card->number : -1;
  43. if (t->hw.flags & SNDRV_TIMER_HW_SLAVE)
  44. info.flags |= SNDRV_TIMER_FLG_SLAVE;
  45. strlcpy(info.id, t->id, sizeof(info.id));
  46. strlcpy(info.name, t->name, sizeof(info.name));
  47. info.resolution = t->hw.resolution;
  48. if (copy_to_user(_info, &info, sizeof(*_info)))
  49. return -EFAULT;
  50. return 0;
  51. }
  52. struct snd_timer_status32 {
  53. struct compat_timespec tstamp;
  54. u32 resolution;
  55. u32 lost;
  56. u32 overrun;
  57. u32 queue;
  58. unsigned char reserved[64];
  59. };
  60. static int snd_timer_user_status_compat(struct file *file,
  61. struct snd_timer_status32 __user *_status)
  62. {
  63. struct snd_timer_user *tu;
  64. struct snd_timer_status status;
  65. tu = file->private_data;
  66. snd_assert(tu->timeri != NULL, return -ENXIO);
  67. memset(&status, 0, sizeof(status));
  68. status.tstamp = tu->tstamp;
  69. status.resolution = snd_timer_resolution(tu->timeri);
  70. status.lost = tu->timeri->lost;
  71. status.overrun = tu->overrun;
  72. spin_lock_irq(&tu->qlock);
  73. status.queue = tu->qused;
  74. spin_unlock_irq(&tu->qlock);
  75. if (copy_to_user(_status, &status, sizeof(status)))
  76. return -EFAULT;
  77. return 0;
  78. }
  79. /*
  80. */
  81. enum {
  82. SNDRV_TIMER_IOCTL_INFO32 = _IOR('T', 0x11, struct snd_timer_info32),
  83. SNDRV_TIMER_IOCTL_STATUS32 = _IOW('T', 0x14, struct snd_timer_status32),
  84. };
  85. static long snd_timer_user_ioctl_compat(struct file *file, unsigned int cmd, unsigned long arg)
  86. {
  87. void __user *argp = compat_ptr(arg);
  88. switch (cmd) {
  89. case SNDRV_TIMER_IOCTL_PVERSION:
  90. case SNDRV_TIMER_IOCTL_TREAD:
  91. case SNDRV_TIMER_IOCTL_GINFO:
  92. case SNDRV_TIMER_IOCTL_GPARAMS:
  93. case SNDRV_TIMER_IOCTL_GSTATUS:
  94. case SNDRV_TIMER_IOCTL_SELECT:
  95. case SNDRV_TIMER_IOCTL_PARAMS:
  96. case SNDRV_TIMER_IOCTL_START:
  97. case SNDRV_TIMER_IOCTL_START_OLD:
  98. case SNDRV_TIMER_IOCTL_STOP:
  99. case SNDRV_TIMER_IOCTL_STOP_OLD:
  100. case SNDRV_TIMER_IOCTL_CONTINUE:
  101. case SNDRV_TIMER_IOCTL_CONTINUE_OLD:
  102. case SNDRV_TIMER_IOCTL_PAUSE:
  103. case SNDRV_TIMER_IOCTL_PAUSE_OLD:
  104. case SNDRV_TIMER_IOCTL_NEXT_DEVICE:
  105. return snd_timer_user_ioctl(file, cmd, (unsigned long)argp);
  106. case SNDRV_TIMER_IOCTL_INFO32:
  107. return snd_timer_user_info_compat(file, argp);
  108. case SNDRV_TIMER_IOCTL_STATUS32:
  109. return snd_timer_user_status_compat(file, argp);
  110. }
  111. return -ENOIOCTLCMD;
  112. }