seq_queue.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /*
  2. * ALSA sequencer Queue handling
  3. * Copyright (c) 1998-1999 by Frank van de Pol <fvdpol@coil.demon.nl>
  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. #ifndef __SND_SEQ_QUEUE_H
  21. #define __SND_SEQ_QUEUE_H
  22. #include "seq_memory.h"
  23. #include "seq_prioq.h"
  24. #include "seq_timer.h"
  25. #include "seq_lock.h"
  26. #include <linux/interrupt.h>
  27. #include <linux/list.h>
  28. #include <linux/bitops.h>
  29. #define SEQ_QUEUE_NO_OWNER (-1)
  30. struct snd_seq_queue {
  31. int queue; /* queue number */
  32. char name[64]; /* name of this queue */
  33. struct snd_seq_prioq *tickq; /* midi tick event queue */
  34. struct snd_seq_prioq *timeq; /* real-time event queue */
  35. struct snd_seq_timer *timer; /* time keeper for this queue */
  36. int owner; /* client that 'owns' the timer */
  37. unsigned int locked:1, /* timer is only accesibble by owner if set */
  38. klocked:1, /* kernel lock (after START) */
  39. check_again:1,
  40. check_blocked:1;
  41. unsigned int flags; /* status flags */
  42. unsigned int info_flags; /* info for sync */
  43. spinlock_t owner_lock;
  44. spinlock_t check_lock;
  45. /* clients which uses this queue (bitmap) */
  46. DECLARE_BITMAP(clients_bitmap, SNDRV_SEQ_MAX_CLIENTS);
  47. unsigned int clients; /* users of this queue */
  48. struct mutex timer_mutex;
  49. snd_use_lock_t use_lock;
  50. };
  51. /* get the number of current queues */
  52. int snd_seq_queue_get_cur_queues(void);
  53. /* init queues structure */
  54. int snd_seq_queues_init(void);
  55. /* delete queues */
  56. void snd_seq_queues_delete(void);
  57. /* create new queue (constructor) */
  58. int snd_seq_queue_alloc(int client, int locked, unsigned int flags);
  59. /* delete queue (destructor) */
  60. int snd_seq_queue_delete(int client, int queueid);
  61. /* notification that client has left the system */
  62. void snd_seq_queue_client_termination(int client);
  63. /* final stage */
  64. void snd_seq_queue_client_leave(int client);
  65. /* enqueue a event received from one the clients */
  66. int snd_seq_enqueue_event(struct snd_seq_event_cell *cell, int atomic, int hop);
  67. /* Remove events */
  68. void snd_seq_queue_client_leave_cells(int client);
  69. void snd_seq_queue_remove_cells(int client, struct snd_seq_remove_events *info);
  70. /* return pointer to queue structure for specified id */
  71. struct snd_seq_queue *queueptr(int queueid);
  72. /* unlock */
  73. #define queuefree(q) snd_use_lock_free(&(q)->use_lock)
  74. /* return the (first) queue matching with the specified name */
  75. struct snd_seq_queue *snd_seq_queue_find_name(char *name);
  76. /* check single queue and dispatch events */
  77. void snd_seq_check_queue(struct snd_seq_queue *q, int atomic, int hop);
  78. /* access to queue's parameters */
  79. int snd_seq_queue_check_access(int queueid, int client);
  80. int snd_seq_queue_timer_set_tempo(int queueid, int client, struct snd_seq_queue_tempo *info);
  81. int snd_seq_queue_set_owner(int queueid, int client, int locked);
  82. int snd_seq_queue_set_locked(int queueid, int client, int locked);
  83. int snd_seq_queue_timer_open(int queueid);
  84. int snd_seq_queue_timer_close(int queueid);
  85. int snd_seq_queue_use(int queueid, int client, int use);
  86. int snd_seq_queue_is_used(int queueid, int client);
  87. int snd_seq_control_queue(struct snd_seq_event *ev, int atomic, int hop);
  88. /*
  89. * 64bit division - for sync stuff..
  90. */
  91. #if defined(i386) || defined(i486)
  92. #define udiv_qrnnd(q, r, n1, n0, d) \
  93. __asm__ ("divl %4" \
  94. : "=a" ((u32)(q)), \
  95. "=d" ((u32)(r)) \
  96. : "0" ((u32)(n0)), \
  97. "1" ((u32)(n1)), \
  98. "rm" ((u32)(d)))
  99. #define u64_div(x,y,q) do {u32 __tmp; udiv_qrnnd(q, __tmp, (x)>>32, x, y);} while (0)
  100. #define u64_mod(x,y,r) do {u32 __tmp; udiv_qrnnd(__tmp, q, (x)>>32, x, y);} while (0)
  101. #define u64_divmod(x,y,q,r) udiv_qrnnd(q, r, (x)>>32, x, y)
  102. #else
  103. #define u64_div(x,y,q) ((q) = (u32)((u64)(x) / (u64)(y)))
  104. #define u64_mod(x,y,r) ((r) = (u32)((u64)(x) % (u64)(y)))
  105. #define u64_divmod(x,y,q,r) (u64_div(x,y,q), u64_mod(x,y,r))
  106. #endif
  107. #endif