seq_oss_ioctl.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. /*
  2. * OSS compatible sequencer driver
  3. *
  4. * OSS compatible i/o control
  5. *
  6. * Copyright (C) 1998,99 Takashi Iwai <tiwai@suse.de>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. */
  22. #include "seq_oss_device.h"
  23. #include "seq_oss_readq.h"
  24. #include "seq_oss_writeq.h"
  25. #include "seq_oss_timer.h"
  26. #include "seq_oss_synth.h"
  27. #include "seq_oss_midi.h"
  28. #include "seq_oss_event.h"
  29. static int snd_seq_oss_synth_info_user(struct seq_oss_devinfo *dp, void __user *arg)
  30. {
  31. struct synth_info info;
  32. if (copy_from_user(&info, arg, sizeof(info)))
  33. return -EFAULT;
  34. if (snd_seq_oss_synth_make_info(dp, info.device, &info) < 0)
  35. return -EINVAL;
  36. if (copy_to_user(arg, &info, sizeof(info)))
  37. return -EFAULT;
  38. return 0;
  39. }
  40. static int snd_seq_oss_midi_info_user(struct seq_oss_devinfo *dp, void __user *arg)
  41. {
  42. struct midi_info info;
  43. if (copy_from_user(&info, arg, sizeof(info)))
  44. return -EFAULT;
  45. if (snd_seq_oss_midi_make_info(dp, info.device, &info) < 0)
  46. return -EINVAL;
  47. if (copy_to_user(arg, &info, sizeof(info)))
  48. return -EFAULT;
  49. return 0;
  50. }
  51. static int snd_seq_oss_oob_user(struct seq_oss_devinfo *dp, void __user *arg)
  52. {
  53. unsigned char ev[8];
  54. struct snd_seq_event tmpev;
  55. if (copy_from_user(ev, arg, 8))
  56. return -EFAULT;
  57. memset(&tmpev, 0, sizeof(tmpev));
  58. snd_seq_oss_fill_addr(dp, &tmpev, dp->addr.port, dp->addr.client);
  59. tmpev.time.tick = 0;
  60. if (! snd_seq_oss_process_event(dp, (union evrec *)ev, &tmpev)) {
  61. snd_seq_oss_dispatch(dp, &tmpev, 0, 0);
  62. }
  63. return 0;
  64. }
  65. int
  66. snd_seq_oss_ioctl(struct seq_oss_devinfo *dp, unsigned int cmd, unsigned long carg)
  67. {
  68. int dev, val;
  69. void __user *arg = (void __user *)carg;
  70. int __user *p = arg;
  71. switch (cmd) {
  72. case SNDCTL_TMR_TIMEBASE:
  73. case SNDCTL_TMR_TEMPO:
  74. case SNDCTL_TMR_START:
  75. case SNDCTL_TMR_STOP:
  76. case SNDCTL_TMR_CONTINUE:
  77. case SNDCTL_TMR_METRONOME:
  78. case SNDCTL_TMR_SOURCE:
  79. case SNDCTL_TMR_SELECT:
  80. case SNDCTL_SEQ_CTRLRATE:
  81. return snd_seq_oss_timer_ioctl(dp->timer, cmd, arg);
  82. case SNDCTL_SEQ_PANIC:
  83. snd_seq_oss_reset(dp);
  84. return -EINVAL;
  85. case SNDCTL_SEQ_SYNC:
  86. if (! is_write_mode(dp->file_mode) || dp->writeq == NULL)
  87. return 0;
  88. while (snd_seq_oss_writeq_sync(dp->writeq))
  89. ;
  90. if (signal_pending(current))
  91. return -ERESTARTSYS;
  92. return 0;
  93. case SNDCTL_SEQ_RESET:
  94. snd_seq_oss_reset(dp);
  95. return 0;
  96. case SNDCTL_SEQ_TESTMIDI:
  97. if (get_user(dev, p))
  98. return -EFAULT;
  99. return snd_seq_oss_midi_open(dp, dev, dp->file_mode);
  100. case SNDCTL_SEQ_GETINCOUNT:
  101. if (dp->readq == NULL || ! is_read_mode(dp->file_mode))
  102. return 0;
  103. return put_user(dp->readq->qlen, p) ? -EFAULT : 0;
  104. case SNDCTL_SEQ_GETOUTCOUNT:
  105. if (! is_write_mode(dp->file_mode) || dp->writeq == NULL)
  106. return 0;
  107. return put_user(snd_seq_oss_writeq_get_free_size(dp->writeq), p) ? -EFAULT : 0;
  108. case SNDCTL_SEQ_GETTIME:
  109. return put_user(snd_seq_oss_timer_cur_tick(dp->timer), p) ? -EFAULT : 0;
  110. case SNDCTL_SEQ_RESETSAMPLES:
  111. if (get_user(dev, p))
  112. return -EFAULT;
  113. return snd_seq_oss_synth_ioctl(dp, dev, cmd, carg);
  114. case SNDCTL_SEQ_NRSYNTHS:
  115. return put_user(dp->max_synthdev, p) ? -EFAULT : 0;
  116. case SNDCTL_SEQ_NRMIDIS:
  117. return put_user(dp->max_mididev, p) ? -EFAULT : 0;
  118. case SNDCTL_SYNTH_MEMAVL:
  119. if (get_user(dev, p))
  120. return -EFAULT;
  121. val = snd_seq_oss_synth_ioctl(dp, dev, cmd, carg);
  122. return put_user(val, p) ? -EFAULT : 0;
  123. case SNDCTL_FM_4OP_ENABLE:
  124. if (get_user(dev, p))
  125. return -EFAULT;
  126. snd_seq_oss_synth_ioctl(dp, dev, cmd, carg);
  127. return 0;
  128. case SNDCTL_SYNTH_INFO:
  129. case SNDCTL_SYNTH_ID:
  130. return snd_seq_oss_synth_info_user(dp, arg);
  131. case SNDCTL_SEQ_OUTOFBAND:
  132. return snd_seq_oss_oob_user(dp, arg);
  133. case SNDCTL_MIDI_INFO:
  134. return snd_seq_oss_midi_info_user(dp, arg);
  135. case SNDCTL_SEQ_THRESHOLD:
  136. if (! is_write_mode(dp->file_mode))
  137. return 0;
  138. if (get_user(val, p))
  139. return -EFAULT;
  140. if (val < 1)
  141. val = 1;
  142. if (val >= dp->writeq->maxlen)
  143. val = dp->writeq->maxlen - 1;
  144. snd_seq_oss_writeq_set_output(dp->writeq, val);
  145. return 0;
  146. case SNDCTL_MIDI_PRETIME:
  147. if (dp->readq == NULL || !is_read_mode(dp->file_mode))
  148. return 0;
  149. if (get_user(val, p))
  150. return -EFAULT;
  151. if (val <= 0)
  152. val = -1;
  153. else
  154. val = (HZ * val) / 10;
  155. dp->readq->pre_event_timeout = val;
  156. return put_user(val, p) ? -EFAULT : 0;
  157. default:
  158. if (! is_write_mode(dp->file_mode))
  159. return -EIO;
  160. return snd_seq_oss_synth_ioctl(dp, 0, cmd, carg);
  161. }
  162. return 0;
  163. }