seq_queue.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * ALSA sequencer Timing queue handling
  4. * Copyright (c) 1998-1999 by Frank van de Pol <fvdpol@coil.demon.nl>
  5. *
  6. * MAJOR CHANGES
  7. * Nov. 13, 1999 Takashi Iwai <iwai@ww.uni-erlangen.de>
  8. * - Queues are allocated dynamically via ioctl.
  9. * - When owner client is deleted, all owned queues are deleted, too.
  10. * - Owner of unlocked queue is kept unmodified even if it is
  11. * manipulated by other clients.
  12. * - Owner field in SET_QUEUE_OWNER ioctl must be identical with the
  13. * caller client. i.e. Changing owner to a third client is not
  14. * allowed.
  15. *
  16. * Aug. 30, 2000 Takashi Iwai
  17. * - Queues are managed in static array again, but with better way.
  18. * The API itself is identical.
  19. * - The queue is locked when struct snd_seq_queue pointer is returned via
  20. * queueptr(). This pointer *MUST* be released afterward by
  21. * queuefree(ptr).
  22. * - Addition of experimental sync support.
  23. */
  24. #include <linux/init.h>
  25. #include <linux/slab.h>
  26. #include <sound/core.h>
  27. #include "seq_memory.h"
  28. #include "seq_queue.h"
  29. #include "seq_clientmgr.h"
  30. #include "seq_fifo.h"
  31. #include "seq_timer.h"
  32. #include "seq_info.h"
  33. /* list of allocated queues */
  34. static struct snd_seq_queue *queue_list[SNDRV_SEQ_MAX_QUEUES];
  35. static DEFINE_SPINLOCK(queue_list_lock);
  36. /* number of queues allocated */
  37. static int num_queues;
  38. int snd_seq_queue_get_cur_queues(void)
  39. {
  40. return num_queues;
  41. }
  42. /*----------------------------------------------------------------*/
  43. /* assign queue id and insert to list */
  44. static int queue_list_add(struct snd_seq_queue *q)
  45. {
  46. int i;
  47. guard(spinlock_irqsave)(&queue_list_lock);
  48. for (i = 0; i < SNDRV_SEQ_MAX_QUEUES; i++) {
  49. if (! queue_list[i]) {
  50. queue_list[i] = q;
  51. q->queue = i;
  52. num_queues++;
  53. return i;
  54. }
  55. }
  56. return -1;
  57. }
  58. static struct snd_seq_queue *queue_list_remove(int id, int client)
  59. {
  60. struct snd_seq_queue *q;
  61. guard(spinlock_irqsave)(&queue_list_lock);
  62. q = queue_list[id];
  63. if (q) {
  64. guard(spinlock)(&q->owner_lock);
  65. if (q->owner == client) {
  66. /* found */
  67. q->klocked = 1;
  68. queue_list[id] = NULL;
  69. num_queues--;
  70. return q;
  71. }
  72. }
  73. return NULL;
  74. }
  75. /*----------------------------------------------------------------*/
  76. /* create new queue (constructor) */
  77. static struct snd_seq_queue *queue_new(int owner, int locked)
  78. {
  79. struct snd_seq_queue *q;
  80. q = kzalloc_obj(*q);
  81. if (!q)
  82. return NULL;
  83. spin_lock_init(&q->owner_lock);
  84. spin_lock_init(&q->check_lock);
  85. mutex_init(&q->timer_mutex);
  86. snd_use_lock_init(&q->use_lock);
  87. q->queue = -1;
  88. q->tickq = snd_seq_prioq_new();
  89. q->timeq = snd_seq_prioq_new();
  90. q->timer = snd_seq_timer_new();
  91. if (q->tickq == NULL || q->timeq == NULL || q->timer == NULL) {
  92. snd_seq_prioq_delete(&q->tickq);
  93. snd_seq_prioq_delete(&q->timeq);
  94. snd_seq_timer_delete(&q->timer);
  95. kfree(q);
  96. return NULL;
  97. }
  98. q->owner = owner;
  99. q->locked = locked;
  100. q->klocked = 0;
  101. return q;
  102. }
  103. /* delete queue (destructor) */
  104. static void queue_delete(struct snd_seq_queue *q)
  105. {
  106. /* stop and release the timer */
  107. mutex_lock(&q->timer_mutex);
  108. snd_seq_timer_stop(q->timer);
  109. snd_seq_timer_close(q);
  110. mutex_unlock(&q->timer_mutex);
  111. /* wait until access free */
  112. snd_use_lock_sync(&q->use_lock);
  113. /* release resources... */
  114. snd_seq_prioq_delete(&q->tickq);
  115. snd_seq_prioq_delete(&q->timeq);
  116. snd_seq_timer_delete(&q->timer);
  117. kfree(q);
  118. }
  119. /*----------------------------------------------------------------*/
  120. /* delete all existing queues */
  121. void snd_seq_queues_delete(void)
  122. {
  123. int i;
  124. /* clear list */
  125. for (i = 0; i < SNDRV_SEQ_MAX_QUEUES; i++) {
  126. if (queue_list[i])
  127. queue_delete(queue_list[i]);
  128. }
  129. }
  130. static void queue_use(struct snd_seq_queue *queue, int client, int use);
  131. /* allocate a new queue -
  132. * return pointer to new queue or ERR_PTR(-errno) for error
  133. * The new queue's use_lock is set to 1. It is the caller's responsibility to
  134. * call snd_use_lock_free(&q->use_lock).
  135. */
  136. struct snd_seq_queue *snd_seq_queue_alloc(int client, int locked, unsigned int info_flags)
  137. {
  138. struct snd_seq_queue *q;
  139. q = queue_new(client, locked);
  140. if (q == NULL)
  141. return ERR_PTR(-ENOMEM);
  142. q->info_flags = info_flags;
  143. queue_use(q, client, 1);
  144. snd_use_lock_use(&q->use_lock);
  145. if (queue_list_add(q) < 0) {
  146. snd_use_lock_free(&q->use_lock);
  147. queue_delete(q);
  148. return ERR_PTR(-ENOMEM);
  149. }
  150. return q;
  151. }
  152. /* delete a queue - queue must be owned by the client */
  153. int snd_seq_queue_delete(int client, int queueid)
  154. {
  155. struct snd_seq_queue *q;
  156. if (queueid < 0 || queueid >= SNDRV_SEQ_MAX_QUEUES)
  157. return -EINVAL;
  158. q = queue_list_remove(queueid, client);
  159. if (q == NULL)
  160. return -EINVAL;
  161. queue_delete(q);
  162. return 0;
  163. }
  164. /* return pointer to queue structure for specified id */
  165. struct snd_seq_queue *queueptr(int queueid)
  166. {
  167. struct snd_seq_queue *q;
  168. if (queueid < 0 || queueid >= SNDRV_SEQ_MAX_QUEUES)
  169. return NULL;
  170. guard(spinlock_irqsave)(&queue_list_lock);
  171. q = queue_list[queueid];
  172. if (q)
  173. snd_use_lock_use(&q->use_lock);
  174. return q;
  175. }
  176. /* return the (first) queue matching with the specified name */
  177. struct snd_seq_queue *snd_seq_queue_find_name(char *name)
  178. {
  179. int i;
  180. for (i = 0; i < SNDRV_SEQ_MAX_QUEUES; i++) {
  181. struct snd_seq_queue *q __free(snd_seq_queue) =
  182. queueptr(i);
  183. if (q) {
  184. if (strncmp(q->name, name, sizeof(q->name)) == 0)
  185. return no_free_ptr(q);
  186. }
  187. }
  188. return NULL;
  189. }
  190. /* -------------------------------------------------------- */
  191. #define MAX_CELL_PROCESSES_IN_QUEUE 1000
  192. void snd_seq_check_queue(struct snd_seq_queue *q, int atomic, int hop)
  193. {
  194. struct snd_seq_event_cell *cell;
  195. snd_seq_tick_time_t cur_tick;
  196. snd_seq_real_time_t cur_time;
  197. int processed = 0;
  198. if (q == NULL)
  199. return;
  200. /* make this function non-reentrant */
  201. scoped_guard(spinlock_irqsave, &q->check_lock) {
  202. if (q->check_blocked) {
  203. q->check_again = 1;
  204. return; /* other thread is already checking queues */
  205. }
  206. q->check_blocked = 1;
  207. }
  208. __again:
  209. /* Process tick queue... */
  210. cur_tick = snd_seq_timer_get_cur_tick(q->timer);
  211. for (;;) {
  212. cell = snd_seq_prioq_cell_out(q->tickq, &cur_tick);
  213. if (!cell)
  214. break;
  215. snd_seq_dispatch_event(cell, atomic, hop);
  216. if (++processed >= MAX_CELL_PROCESSES_IN_QUEUE)
  217. goto out; /* the rest processed at the next batch */
  218. }
  219. /* Process time queue... */
  220. cur_time = snd_seq_timer_get_cur_time(q->timer, false);
  221. for (;;) {
  222. cell = snd_seq_prioq_cell_out(q->timeq, &cur_time);
  223. if (!cell)
  224. break;
  225. snd_seq_dispatch_event(cell, atomic, hop);
  226. if (++processed >= MAX_CELL_PROCESSES_IN_QUEUE)
  227. goto out; /* the rest processed at the next batch */
  228. }
  229. out:
  230. /* free lock */
  231. scoped_guard(spinlock_irqsave, &q->check_lock) {
  232. if (q->check_again) {
  233. q->check_again = 0;
  234. if (processed < MAX_CELL_PROCESSES_IN_QUEUE)
  235. goto __again;
  236. }
  237. q->check_blocked = 0;
  238. }
  239. }
  240. /* enqueue a event to singe queue */
  241. int snd_seq_enqueue_event(struct snd_seq_event_cell *cell, int atomic, int hop)
  242. {
  243. int dest, err;
  244. if (snd_BUG_ON(!cell))
  245. return -EINVAL;
  246. dest = cell->event.queue; /* destination queue */
  247. struct snd_seq_queue *q __free(snd_seq_queue) =
  248. queueptr(dest);
  249. if (q == NULL)
  250. return -EINVAL;
  251. /* handle relative time stamps, convert them into absolute */
  252. if ((cell->event.flags & SNDRV_SEQ_TIME_MODE_MASK) == SNDRV_SEQ_TIME_MODE_REL) {
  253. switch (cell->event.flags & SNDRV_SEQ_TIME_STAMP_MASK) {
  254. case SNDRV_SEQ_TIME_STAMP_TICK:
  255. cell->event.time.tick += q->timer->tick.cur_tick;
  256. break;
  257. case SNDRV_SEQ_TIME_STAMP_REAL:
  258. snd_seq_inc_real_time(&cell->event.time.time,
  259. &q->timer->cur_time);
  260. break;
  261. }
  262. cell->event.flags &= ~SNDRV_SEQ_TIME_MODE_MASK;
  263. cell->event.flags |= SNDRV_SEQ_TIME_MODE_ABS;
  264. }
  265. /* enqueue event in the real-time or midi queue */
  266. switch (cell->event.flags & SNDRV_SEQ_TIME_STAMP_MASK) {
  267. case SNDRV_SEQ_TIME_STAMP_TICK:
  268. err = snd_seq_prioq_cell_in(q->tickq, cell);
  269. break;
  270. case SNDRV_SEQ_TIME_STAMP_REAL:
  271. default:
  272. err = snd_seq_prioq_cell_in(q->timeq, cell);
  273. break;
  274. }
  275. if (err < 0)
  276. return err;
  277. /* trigger dispatching */
  278. snd_seq_check_queue(q, atomic, hop);
  279. return 0;
  280. }
  281. /*----------------------------------------------------------------*/
  282. static inline int check_access(struct snd_seq_queue *q, int client)
  283. {
  284. return (q->owner == client) || (!q->locked && !q->klocked);
  285. }
  286. /* check if the client has permission to modify queue parameters.
  287. * if it does, lock the queue
  288. */
  289. static int queue_access_lock(struct snd_seq_queue *q, int client)
  290. {
  291. int access_ok;
  292. guard(spinlock_irqsave)(&q->owner_lock);
  293. access_ok = check_access(q, client);
  294. if (access_ok)
  295. q->klocked = 1;
  296. return access_ok;
  297. }
  298. /* unlock the queue */
  299. static inline void queue_access_unlock(struct snd_seq_queue *q)
  300. {
  301. guard(spinlock_irqsave)(&q->owner_lock);
  302. q->klocked = 0;
  303. }
  304. /* exported - only checking permission */
  305. int snd_seq_queue_check_access(int queueid, int client)
  306. {
  307. struct snd_seq_queue *q __free(snd_seq_queue) = queueptr(queueid);
  308. if (! q)
  309. return 0;
  310. guard(spinlock_irqsave)(&q->owner_lock);
  311. return check_access(q, client);
  312. }
  313. /*----------------------------------------------------------------*/
  314. /*
  315. * change queue's owner and permission
  316. */
  317. int snd_seq_queue_set_owner(int queueid, int client, int locked)
  318. {
  319. struct snd_seq_queue *q __free(snd_seq_queue) = queueptr(queueid);
  320. if (q == NULL)
  321. return -EINVAL;
  322. if (!queue_access_lock(q, client))
  323. return -EPERM;
  324. scoped_guard(spinlock_irqsave, &q->owner_lock) {
  325. q->locked = locked ? 1 : 0;
  326. q->owner = client;
  327. }
  328. queue_access_unlock(q);
  329. return 0;
  330. }
  331. /*----------------------------------------------------------------*/
  332. /* open timer -
  333. * q->use mutex should be down before calling this function to avoid
  334. * confliction with snd_seq_queue_use()
  335. */
  336. int snd_seq_queue_timer_open(int queueid)
  337. {
  338. int result = 0;
  339. struct snd_seq_timer *tmr;
  340. struct snd_seq_queue *queue __free(snd_seq_queue) =
  341. queueptr(queueid);
  342. if (queue == NULL)
  343. return -EINVAL;
  344. tmr = queue->timer;
  345. result = snd_seq_timer_open(queue);
  346. if (result < 0) {
  347. snd_seq_timer_defaults(tmr);
  348. result = snd_seq_timer_open(queue);
  349. }
  350. return result;
  351. }
  352. /* close timer -
  353. * q->use mutex should be down before calling this function
  354. */
  355. int snd_seq_queue_timer_close(int queueid)
  356. {
  357. int result = 0;
  358. struct snd_seq_queue *queue __free(snd_seq_queue) =
  359. queueptr(queueid);
  360. if (queue == NULL)
  361. return -EINVAL;
  362. snd_seq_timer_close(queue);
  363. return result;
  364. }
  365. /* change queue tempo and ppq */
  366. int snd_seq_queue_timer_set_tempo(int queueid, int client,
  367. struct snd_seq_queue_tempo *info)
  368. {
  369. struct snd_seq_queue *q __free(snd_seq_queue) = queueptr(queueid);
  370. int result;
  371. if (q == NULL)
  372. return -EINVAL;
  373. if (!queue_access_lock(q, client))
  374. return -EPERM;
  375. result = snd_seq_timer_set_tempo_ppq(q->timer, info->tempo, info->ppq,
  376. info->tempo_base);
  377. if (result >= 0 && info->skew_base > 0)
  378. result = snd_seq_timer_set_skew(q->timer, info->skew_value,
  379. info->skew_base);
  380. queue_access_unlock(q);
  381. return result;
  382. }
  383. /* use or unuse this queue */
  384. static void queue_use(struct snd_seq_queue *queue, int client, int use)
  385. {
  386. if (use) {
  387. if (!test_and_set_bit(client, queue->clients_bitmap))
  388. queue->clients++;
  389. } else {
  390. if (test_and_clear_bit(client, queue->clients_bitmap))
  391. queue->clients--;
  392. }
  393. if (queue->clients) {
  394. if (use && queue->clients == 1)
  395. snd_seq_timer_defaults(queue->timer);
  396. snd_seq_timer_open(queue);
  397. } else {
  398. snd_seq_timer_close(queue);
  399. }
  400. }
  401. /* use or unuse this queue -
  402. * if it is the first client, starts the timer.
  403. * if it is not longer used by any clients, stop the timer.
  404. */
  405. int snd_seq_queue_use(int queueid, int client, int use)
  406. {
  407. struct snd_seq_queue *queue __free(snd_seq_queue) =
  408. queueptr(queueid);
  409. if (queue == NULL)
  410. return -EINVAL;
  411. guard(mutex)(&queue->timer_mutex);
  412. queue_use(queue, client, use);
  413. return 0;
  414. }
  415. /*
  416. * check if queue is used by the client
  417. * return negative value if the queue is invalid.
  418. * return 0 if not used, 1 if used.
  419. */
  420. int snd_seq_queue_is_used(int queueid, int client)
  421. {
  422. struct snd_seq_queue *q __free(snd_seq_queue) =
  423. queueptr(queueid);
  424. if (q == NULL)
  425. return -EINVAL; /* invalid queue */
  426. return test_bit(client, q->clients_bitmap) ? 1 : 0;
  427. }
  428. /*----------------------------------------------------------------*/
  429. /* final stage notification -
  430. * remove cells for no longer exist client (for non-owned queue)
  431. * or delete this queue (for owned queue)
  432. */
  433. void snd_seq_queue_client_leave(int client)
  434. {
  435. int i;
  436. /* delete own queues from queue list */
  437. for (i = 0; i < SNDRV_SEQ_MAX_QUEUES; i++) {
  438. struct snd_seq_queue *q = queue_list_remove(i, client);
  439. if (q)
  440. queue_delete(q);
  441. }
  442. /* remove cells from existing queues -
  443. * they are not owned by this client
  444. */
  445. for (i = 0; i < SNDRV_SEQ_MAX_QUEUES; i++) {
  446. struct snd_seq_queue *q __free(snd_seq_queue) = queueptr(i);
  447. if (!q)
  448. continue;
  449. if (test_bit(client, q->clients_bitmap)) {
  450. snd_seq_prioq_leave(q->tickq, client, 0);
  451. snd_seq_prioq_leave(q->timeq, client, 0);
  452. snd_seq_queue_use(q->queue, client, 0);
  453. }
  454. }
  455. }
  456. /*----------------------------------------------------------------*/
  457. /* remove cells based on flush criteria */
  458. void snd_seq_queue_remove_cells(int client, struct snd_seq_remove_events *info)
  459. {
  460. int i;
  461. for (i = 0; i < SNDRV_SEQ_MAX_QUEUES; i++) {
  462. struct snd_seq_queue *q __free(snd_seq_queue) = queueptr(i);
  463. if (!q)
  464. continue;
  465. if (test_bit(client, q->clients_bitmap) &&
  466. (! (info->remove_mode & SNDRV_SEQ_REMOVE_DEST) ||
  467. q->queue == info->queue)) {
  468. snd_seq_prioq_remove_events(q->tickq, client, info);
  469. snd_seq_prioq_remove_events(q->timeq, client, info);
  470. }
  471. }
  472. }
  473. /*----------------------------------------------------------------*/
  474. /*
  475. * send events to all subscribed ports
  476. */
  477. static void queue_broadcast_event(struct snd_seq_queue *q, struct snd_seq_event *ev,
  478. int atomic, int hop)
  479. {
  480. struct snd_seq_event sev;
  481. sev = *ev;
  482. sev.flags = SNDRV_SEQ_TIME_STAMP_TICK|SNDRV_SEQ_TIME_MODE_ABS;
  483. sev.time.tick = q->timer->tick.cur_tick;
  484. sev.queue = q->queue;
  485. sev.data.queue.queue = q->queue;
  486. /* broadcast events from Timer port */
  487. sev.source.client = SNDRV_SEQ_CLIENT_SYSTEM;
  488. sev.source.port = SNDRV_SEQ_PORT_SYSTEM_TIMER;
  489. sev.dest.client = SNDRV_SEQ_ADDRESS_SUBSCRIBERS;
  490. snd_seq_kernel_client_dispatch(SNDRV_SEQ_CLIENT_SYSTEM, &sev, atomic, hop);
  491. }
  492. /*
  493. * process a received queue-control event.
  494. * this function is exported for seq_sync.c.
  495. */
  496. static void snd_seq_queue_process_event(struct snd_seq_queue *q,
  497. struct snd_seq_event *ev,
  498. int atomic, int hop)
  499. {
  500. switch (ev->type) {
  501. case SNDRV_SEQ_EVENT_START:
  502. snd_seq_prioq_leave(q->tickq, ev->source.client, 1);
  503. snd_seq_prioq_leave(q->timeq, ev->source.client, 1);
  504. if (! snd_seq_timer_start(q->timer))
  505. queue_broadcast_event(q, ev, atomic, hop);
  506. break;
  507. case SNDRV_SEQ_EVENT_CONTINUE:
  508. if (! snd_seq_timer_continue(q->timer))
  509. queue_broadcast_event(q, ev, atomic, hop);
  510. break;
  511. case SNDRV_SEQ_EVENT_STOP:
  512. snd_seq_timer_stop(q->timer);
  513. queue_broadcast_event(q, ev, atomic, hop);
  514. break;
  515. case SNDRV_SEQ_EVENT_TEMPO:
  516. snd_seq_timer_set_tempo(q->timer, ev->data.queue.param.value);
  517. queue_broadcast_event(q, ev, atomic, hop);
  518. break;
  519. case SNDRV_SEQ_EVENT_SETPOS_TICK:
  520. if (snd_seq_timer_set_position_tick(q->timer, ev->data.queue.param.time.tick) == 0) {
  521. queue_broadcast_event(q, ev, atomic, hop);
  522. }
  523. break;
  524. case SNDRV_SEQ_EVENT_SETPOS_TIME:
  525. if (snd_seq_timer_set_position_time(q->timer, ev->data.queue.param.time.time) == 0) {
  526. queue_broadcast_event(q, ev, atomic, hop);
  527. }
  528. break;
  529. case SNDRV_SEQ_EVENT_QUEUE_SKEW:
  530. if (snd_seq_timer_set_skew(q->timer,
  531. ev->data.queue.param.skew.value,
  532. ev->data.queue.param.skew.base) == 0) {
  533. queue_broadcast_event(q, ev, atomic, hop);
  534. }
  535. break;
  536. }
  537. }
  538. /*
  539. * Queue control via timer control port:
  540. * this function is exported as a callback of timer port.
  541. */
  542. int snd_seq_control_queue(struct snd_seq_event *ev, int atomic, int hop)
  543. {
  544. if (snd_BUG_ON(!ev))
  545. return -EINVAL;
  546. struct snd_seq_queue *q __free(snd_seq_queue) =
  547. queueptr(ev->data.queue.queue);
  548. if (q == NULL)
  549. return -EINVAL;
  550. if (!queue_access_lock(q, ev->source.client))
  551. return -EPERM;
  552. snd_seq_queue_process_event(q, ev, atomic, hop);
  553. queue_access_unlock(q);
  554. return 0;
  555. }
  556. /*----------------------------------------------------------------*/
  557. #ifdef CONFIG_SND_PROC_FS
  558. /* exported to seq_info.c */
  559. void snd_seq_info_queues_read(struct snd_info_entry *entry,
  560. struct snd_info_buffer *buffer)
  561. {
  562. int i, bpm;
  563. struct snd_seq_timer *tmr;
  564. bool locked;
  565. int owner;
  566. for (i = 0; i < SNDRV_SEQ_MAX_QUEUES; i++) {
  567. struct snd_seq_queue *q __free(snd_seq_queue) = queueptr(i);
  568. if (!q)
  569. continue;
  570. tmr = q->timer;
  571. if (tmr->tempo)
  572. bpm = (60000 * tmr->tempo_base) / tmr->tempo;
  573. else
  574. bpm = 0;
  575. scoped_guard(spinlock_irq, &q->owner_lock) {
  576. locked = q->locked;
  577. owner = q->owner;
  578. }
  579. snd_iprintf(buffer, "queue %d: [%s]\n", q->queue, q->name);
  580. snd_iprintf(buffer, "owned by client : %d\n", owner);
  581. snd_iprintf(buffer, "lock status : %s\n", locked ? "Locked" : "Free");
  582. snd_iprintf(buffer, "queued time events : %d\n", snd_seq_prioq_avail(q->timeq));
  583. snd_iprintf(buffer, "queued tick events : %d\n", snd_seq_prioq_avail(q->tickq));
  584. snd_iprintf(buffer, "timer state : %s\n", tmr->running ? "Running" : "Stopped");
  585. snd_iprintf(buffer, "timer PPQ : %d\n", tmr->ppq);
  586. snd_iprintf(buffer, "current tempo : %d\n", tmr->tempo);
  587. snd_iprintf(buffer, "tempo base : %d ns\n", tmr->tempo_base);
  588. snd_iprintf(buffer, "current BPM : %d\n", bpm);
  589. snd_iprintf(buffer, "current time : %d.%09d s\n", tmr->cur_time.tv_sec, tmr->cur_time.tv_nsec);
  590. snd_iprintf(buffer, "current tick : %d\n", tmr->tick.cur_tick);
  591. snd_iprintf(buffer, "\n");
  592. }
  593. }
  594. #endif /* CONFIG_SND_PROC_FS */