Changes in 4.9.298 Bluetooth: bfusb: fix division by zero in send path USB: core: Fix bug in resuming hub's handling of wakeup requests USB: Fix "slab-out-of-bounds Write" bug in usb_hcd_poll_rh_status mfd: intel-lpss: Fix too early PM enablement in the ACPI ->probe() can: gs_usb: fix use of uninitialized variable, detach device on reception of invalid USB data can: gs_usb: gs_can_start_xmit(): zero-initialize hf->{flags,reserved} random: fix data race on crng_node_pool random: fix data race on crng init time staging: wlan-ng: Avoid bitwise vs logical OR warning in hfa384x_usb_throttlefn() drm/i915: Avoid bitwise vs logical OR warning in snb_wm_latency_quirk() media: uvcvideo: fix division by zero at stream start rtlwifi: rtl8192cu: Fix WARNING when calling local_irq_restore() with interrupts enabled HID: uhid: Fix worker destroying device without any protection HID: wacom: Avoid using stale array indicies to read contact count nfc: llcp: fix NULL error pointer dereference on sendmsg() after failed bind() rtc: cmos: take rtc_lock while reading from CMOS media: flexcop-usb: fix control-message timeouts media: mceusb: fix control-message timeouts media: em28xx: fix control-message timeouts media: cpia2: fix control-message timeouts media: s2255: fix control-message timeouts media: dib0700: fix undefined behavior in tuner shutdown media: redrat3: fix control-message timeouts media: pvrusb2: fix control-message timeouts media: stk1160: fix control-message timeouts can: softing_cs: softingcs_probe(): fix memleak on registration failure PCI: Add function 1 DMA alias quirk for Marvell 88SE9125 SATA controller shmem: fix a race between shmem_unused_huge_shrink and shmem_evict_inode Bluetooth: cmtp: fix possible panic when cmtp_init_sockets() fails wcn36xx: Indicate beacon not connection loss on MISSED_BEACON_IND Bluetooth: stop proccessing malicious adv data media: dmxdev: fix UAF when dvb_register_device() fails crypto: qce - fix uaf on qce_ahash_register_one tty: serial: atmel: Check return code of dmaengine_submit() tty: serial: atmel: Call dma_async_issue_pending() netfilter: bridge: add support for pppoe filtering arm64: dts: qcom: msm8916: fix MMC controller aliases drm/amdgpu: Fix a NULL pointer dereference in amdgpu_connector_lcd_native_mode() drm/radeon/radeon_kms: Fix a NULL pointer dereference in radeon_driver_open_kms() serial: amba-pl011: do not request memory region twice floppy: Fix hang in watchdog when disk is ejected media: dib8000: Fix a memleak in dib8000_init() media: saa7146: mxb: Fix a NULL pointer dereference in mxb_attach() media: si2157: Fix "warm" tuner state detection media: msi001: fix possible null-ptr-deref in msi001_probe() usb: ftdi-elan: fix memory leak on device disconnect pcmcia: rsrc_nonstatic: Fix a NULL pointer dereference in __nonstatic_find_io_region() pcmcia: rsrc_nonstatic: Fix a NULL pointer dereference in nonstatic_find_mem_region() ppp: ensure minimum packet size in ppp_write() fsl/fman: Check for null pointer after calling devm_ioremap spi: spi-meson-spifc: Add missing pm_runtime_disable() in meson_spifc_probe can: softing: softing_startstop(): fix set but not used variable warning can: xilinx_can: xcan_probe(): check for error irq pcmcia: fix setting of kthread task states net: mcs7830: handle usb read errors properly ext4: avoid trim error on fs with small groups ALSA: jack: Add missing rwsem around snd_ctl_remove() calls ALSA: PCM: Add missing rwsem around snd_ctl_remove() calls ALSA: hda: Add missing rwsem around snd_ctl_remove() calls RDMA/hns: Validate the pkey index powerpc/prom_init: Fix improper check of prom_getprop() ALSA: oss: fix compile error when OSS_DEBUG is enabled char/mwave: Adjust io port register size scsi: ufs: Fix race conditions related to driver data RDMA/core: Let ib_find_gid() continue search even after empty entry dmaengine: pxa/mmp: stop referencing config->slave_id ASoC: samsung: idma: Check of ioremap return value misc: lattice-ecp3-config: Fix task hung when firmware load failed mips: lantiq: add support for clk_set_parent() mips: bcm63xx: add support for clk_set_parent() RDMA/cxgb4: Set queue pair state when being queried Bluetooth: Fix debugfs entry leak in hci_register_dev() fs: dlm: filter user dlm messages for kernel locks ar5523: Fix null-ptr-deref with unexpected WDCMSG_TARGET_START reply usb: gadget: f_fs: Use stream_open() for endpoint files HID: apple: Do not reset quirks when the Fn key is not found media: b2c2: Add missing check in flexcop_pci_isr: gpiolib: acpi: Do not set the IRQ type if the IRQ is already in use HSI: core: Fix return freed object in hsi_new_client mwifiex: Fix skb_over_panic in mwifiex_usb_recv() floppy: Add max size check for user space request media: saa7146: hexium_orion: Fix a NULL pointer dereference in hexium_attach() media: m920x: don't use stack on USB reads iwlwifi: mvm: synchronize with FW after multicast commands ath10k: Fix tx hanging net: bonding: debug: avoid printing debug logs when bond is not notifying peers media: igorplugusb: receiver overflow should be reported media: saa7146: hexium_gemini: Fix a NULL pointer dereference in hexium_attach() usb: hub: Add delay for SuperSpeed hub resume to let links transit to U0 ath9k: Fix out-of-bound memcpy in ath9k_hif_usb_rx_stream um: registers: Rename function names to avoid conflicts and build problems jffs2: GC deadlock reading a page that is used in jffs2_write_begin() ACPICA: Utilities: Avoid deleting the same object twice in a row ACPICA: Executer: Fix the REFCLASS_REFOF case in acpi_ex_opcode_1A_0T_1R() btrfs: remove BUG_ON() in find_parent_nodes() btrfs: remove BUG_ON(!eie) in find_parent_nodes net: mdio: Demote probed message to debug print dm btree: add a defensive bounds check to insert_at() dm space map common: add bounds check to sm_ll_lookup_bitmap() serial: pl010: Drop CR register reset on set_termios serial: core: Keep mctrl register state and cached copy in sync parisc: Avoid calling faulthandler_disabled() twice powerpc/6xx: add missing of_node_put powerpc/powernv: add missing of_node_put powerpc/cell: add missing of_node_put powerpc/btext: add missing of_node_put i2c: i801: Don't silently correct invalid transfer size powerpc/smp: Move setup_profiling_timer() under CONFIG_PROFILING i2c: mpc: Correct I2C reset procedure w1: Misuse of get_user()/put_user() reported by sparse ALSA: seq: Set upper limit of processed events i2c: designware-pci: Fix to change data types of hcnt and lcnt parameters MIPS: Octeon: Fix build errors using clang scsi: sr: Don't use GFP_DMA ASoC: mediatek: mt8173: fix device_node leak power: bq25890: Enable continuous conversion for ADC at charging ubifs: Error path in ubifs_remount_rw() seems to wrongly free write buffers iwlwifi: mvm: Increase the scan timeout guard to 30 seconds ext4: set csum seed in tmp inode while migrating to extents ext4: Fix BUG_ON in ext4_bread when write quota data ext4: don't use the orphan list when migrating an inode fuse: fix bad inode fuse: fix live lock in fuse_iget() drm/radeon: fix error handling in radeon_driver_open_kms RDMA/hns: Modify the mapping attribute of doorbell to device RDMA/rxe: Fix a typo in opcode name powerpc/fsl/dts: Enable WA for erratum A-009885 on fman3l MDIO buses net/fsl: xgmac_mdio: Fix incorrect iounmap when removing module parisc: pdc_stable: Fix memory leak in pdcs_register_pathentries af_unix: annote lockless accesses to unix_tot_inflight & gc_in_progress net: axienet: Wait for PhyRstCmplt after core reset net: axienet: fix number of TX ring slots for available check netns: add schedule point in ops_exit_list() libcxgb: Don't accidentally set RTO_ONLINK in cxgb_find_route() dmaengine: at_xdmac: Don't start transactions at tx_submit level dmaengine: at_xdmac: Print debug message after realeasing the lock dmaengine: at_xdmac: Fix lld view setting dmaengine: at_xdmac: Fix at_xdmac_lld struct definition net_sched: restore "mpu xxx" handling bcmgenet: add WOL IRQ check scripts/dtc: dtx_diff: remove broken example from help text lib82596: Fix IRQ check in sni_82596_probe Revert "gup: document and work around "COW can break either way" issue" gup: document and work around "COW can break either way" issue drm/ttm/nouveau: don't call tt destroy callback on alloc failure. gianfar: simplify FCS handling and fix memory leak gianfar: fix jumbo packets+napi+rx overrun crash cipso,calipso: resolve a number of problems with the DOI refcounts rbtree: cache leftmost node internally lib/timerqueue: Rely on rbtree semantics for next timer mm: add follow_pte_pmd() KVM: do not assume PTE is writable after follow_pfn KVM: Use kvm_pfn_t for local PFN variable in hva_to_pfn_remapped() KVM: do not allow mapping valid but non-reference-counted pages Linux 4.9.298 Signed-off-by: Greg Kroah-Hartman <gregkh@google.com> Change-Id: Ifcea82a702a0906d9090c89785363c2d5423f652
820 lines
20 KiB
C
820 lines
20 KiB
C
/*
|
|
* ALSA sequencer Timing queue handling
|
|
* Copyright (c) 1998-1999 by Frank van de Pol <fvdpol@coil.demon.nl>
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program; if not, write to the Free Software
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
*
|
|
* MAJOR CHANGES
|
|
* Nov. 13, 1999 Takashi Iwai <iwai@ww.uni-erlangen.de>
|
|
* - Queues are allocated dynamically via ioctl.
|
|
* - When owner client is deleted, all owned queues are deleted, too.
|
|
* - Owner of unlocked queue is kept unmodified even if it is
|
|
* manipulated by other clients.
|
|
* - Owner field in SET_QUEUE_OWNER ioctl must be identical with the
|
|
* caller client. i.e. Changing owner to a third client is not
|
|
* allowed.
|
|
*
|
|
* Aug. 30, 2000 Takashi Iwai
|
|
* - Queues are managed in static array again, but with better way.
|
|
* The API itself is identical.
|
|
* - The queue is locked when struct snd_seq_queue pointer is returned via
|
|
* queueptr(). This pointer *MUST* be released afterward by
|
|
* queuefree(ptr).
|
|
* - Addition of experimental sync support.
|
|
*/
|
|
|
|
#include <linux/init.h>
|
|
#include <linux/slab.h>
|
|
#include <sound/core.h>
|
|
|
|
#include "seq_memory.h"
|
|
#include "seq_queue.h"
|
|
#include "seq_clientmgr.h"
|
|
#include "seq_fifo.h"
|
|
#include "seq_timer.h"
|
|
#include "seq_info.h"
|
|
|
|
/* list of allocated queues */
|
|
static struct snd_seq_queue *queue_list[SNDRV_SEQ_MAX_QUEUES];
|
|
static DEFINE_SPINLOCK(queue_list_lock);
|
|
/* number of queues allocated */
|
|
static int num_queues;
|
|
|
|
int snd_seq_queue_get_cur_queues(void)
|
|
{
|
|
return num_queues;
|
|
}
|
|
|
|
/*----------------------------------------------------------------*/
|
|
|
|
/* assign queue id and insert to list */
|
|
static int queue_list_add(struct snd_seq_queue *q)
|
|
{
|
|
int i;
|
|
unsigned long flags;
|
|
|
|
spin_lock_irqsave(&queue_list_lock, flags);
|
|
for (i = 0; i < SNDRV_SEQ_MAX_QUEUES; i++) {
|
|
if (! queue_list[i]) {
|
|
queue_list[i] = q;
|
|
q->queue = i;
|
|
num_queues++;
|
|
spin_unlock_irqrestore(&queue_list_lock, flags);
|
|
return i;
|
|
}
|
|
}
|
|
spin_unlock_irqrestore(&queue_list_lock, flags);
|
|
return -1;
|
|
}
|
|
|
|
static struct snd_seq_queue *queue_list_remove(int id, int client)
|
|
{
|
|
struct snd_seq_queue *q;
|
|
unsigned long flags;
|
|
|
|
spin_lock_irqsave(&queue_list_lock, flags);
|
|
q = queue_list[id];
|
|
if (q) {
|
|
spin_lock(&q->owner_lock);
|
|
if (q->owner == client) {
|
|
/* found */
|
|
q->klocked = 1;
|
|
spin_unlock(&q->owner_lock);
|
|
queue_list[id] = NULL;
|
|
num_queues--;
|
|
spin_unlock_irqrestore(&queue_list_lock, flags);
|
|
return q;
|
|
}
|
|
spin_unlock(&q->owner_lock);
|
|
}
|
|
spin_unlock_irqrestore(&queue_list_lock, flags);
|
|
return NULL;
|
|
}
|
|
|
|
/*----------------------------------------------------------------*/
|
|
|
|
/* create new queue (constructor) */
|
|
static struct snd_seq_queue *queue_new(int owner, int locked)
|
|
{
|
|
struct snd_seq_queue *q;
|
|
|
|
q = kzalloc(sizeof(*q), GFP_KERNEL);
|
|
if (!q)
|
|
return NULL;
|
|
|
|
spin_lock_init(&q->owner_lock);
|
|
spin_lock_init(&q->check_lock);
|
|
mutex_init(&q->timer_mutex);
|
|
snd_use_lock_init(&q->use_lock);
|
|
q->queue = -1;
|
|
|
|
q->tickq = snd_seq_prioq_new();
|
|
q->timeq = snd_seq_prioq_new();
|
|
q->timer = snd_seq_timer_new();
|
|
if (q->tickq == NULL || q->timeq == NULL || q->timer == NULL) {
|
|
snd_seq_prioq_delete(&q->tickq);
|
|
snd_seq_prioq_delete(&q->timeq);
|
|
snd_seq_timer_delete(&q->timer);
|
|
kfree(q);
|
|
return NULL;
|
|
}
|
|
|
|
q->owner = owner;
|
|
q->locked = locked;
|
|
q->klocked = 0;
|
|
|
|
return q;
|
|
}
|
|
|
|
/* delete queue (destructor) */
|
|
static void queue_delete(struct snd_seq_queue *q)
|
|
{
|
|
/* stop and release the timer */
|
|
mutex_lock(&q->timer_mutex);
|
|
snd_seq_timer_stop(q->timer);
|
|
snd_seq_timer_close(q);
|
|
mutex_unlock(&q->timer_mutex);
|
|
/* wait until access free */
|
|
snd_use_lock_sync(&q->use_lock);
|
|
/* release resources... */
|
|
snd_seq_prioq_delete(&q->tickq);
|
|
snd_seq_prioq_delete(&q->timeq);
|
|
snd_seq_timer_delete(&q->timer);
|
|
|
|
kfree(q);
|
|
}
|
|
|
|
|
|
/*----------------------------------------------------------------*/
|
|
|
|
/* setup queues */
|
|
int __init snd_seq_queues_init(void)
|
|
{
|
|
/*
|
|
memset(queue_list, 0, sizeof(queue_list));
|
|
num_queues = 0;
|
|
*/
|
|
return 0;
|
|
}
|
|
|
|
/* delete all existing queues */
|
|
void __exit snd_seq_queues_delete(void)
|
|
{
|
|
int i;
|
|
|
|
/* clear list */
|
|
for (i = 0; i < SNDRV_SEQ_MAX_QUEUES; i++) {
|
|
if (queue_list[i])
|
|
queue_delete(queue_list[i]);
|
|
}
|
|
}
|
|
|
|
static void queue_use(struct snd_seq_queue *queue, int client, int use);
|
|
|
|
/* allocate a new queue -
|
|
* return pointer to new queue or ERR_PTR(-errno) for error
|
|
* The new queue's use_lock is set to 1. It is the caller's responsibility to
|
|
* call snd_use_lock_free(&q->use_lock).
|
|
*/
|
|
struct snd_seq_queue *snd_seq_queue_alloc(int client, int locked, unsigned int info_flags)
|
|
{
|
|
struct snd_seq_queue *q;
|
|
|
|
q = queue_new(client, locked);
|
|
if (q == NULL)
|
|
return ERR_PTR(-ENOMEM);
|
|
q->info_flags = info_flags;
|
|
queue_use(q, client, 1);
|
|
snd_use_lock_use(&q->use_lock);
|
|
if (queue_list_add(q) < 0) {
|
|
snd_use_lock_free(&q->use_lock);
|
|
queue_delete(q);
|
|
return ERR_PTR(-ENOMEM);
|
|
}
|
|
return q;
|
|
}
|
|
|
|
/* delete a queue - queue must be owned by the client */
|
|
int snd_seq_queue_delete(int client, int queueid)
|
|
{
|
|
struct snd_seq_queue *q;
|
|
|
|
if (queueid < 0 || queueid >= SNDRV_SEQ_MAX_QUEUES)
|
|
return -EINVAL;
|
|
q = queue_list_remove(queueid, client);
|
|
if (q == NULL)
|
|
return -EINVAL;
|
|
queue_delete(q);
|
|
|
|
return 0;
|
|
}
|
|
|
|
|
|
/* return pointer to queue structure for specified id */
|
|
struct snd_seq_queue *queueptr(int queueid)
|
|
{
|
|
struct snd_seq_queue *q;
|
|
unsigned long flags;
|
|
|
|
if (queueid < 0 || queueid >= SNDRV_SEQ_MAX_QUEUES)
|
|
return NULL;
|
|
spin_lock_irqsave(&queue_list_lock, flags);
|
|
q = queue_list[queueid];
|
|
if (q)
|
|
snd_use_lock_use(&q->use_lock);
|
|
spin_unlock_irqrestore(&queue_list_lock, flags);
|
|
return q;
|
|
}
|
|
|
|
/* return the (first) queue matching with the specified name */
|
|
struct snd_seq_queue *snd_seq_queue_find_name(char *name)
|
|
{
|
|
int i;
|
|
struct snd_seq_queue *q;
|
|
|
|
for (i = 0; i < SNDRV_SEQ_MAX_QUEUES; i++) {
|
|
if ((q = queueptr(i)) != NULL) {
|
|
if (strncmp(q->name, name, sizeof(q->name)) == 0)
|
|
return q;
|
|
queuefree(q);
|
|
}
|
|
}
|
|
return NULL;
|
|
}
|
|
|
|
|
|
/* -------------------------------------------------------- */
|
|
|
|
#define MAX_CELL_PROCESSES_IN_QUEUE 1000
|
|
|
|
void snd_seq_check_queue(struct snd_seq_queue *q, int atomic, int hop)
|
|
{
|
|
unsigned long flags;
|
|
struct snd_seq_event_cell *cell;
|
|
snd_seq_tick_time_t cur_tick;
|
|
snd_seq_real_time_t cur_time;
|
|
int processed = 0;
|
|
|
|
if (q == NULL)
|
|
return;
|
|
|
|
/* make this function non-reentrant */
|
|
spin_lock_irqsave(&q->check_lock, flags);
|
|
if (q->check_blocked) {
|
|
q->check_again = 1;
|
|
spin_unlock_irqrestore(&q->check_lock, flags);
|
|
return; /* other thread is already checking queues */
|
|
}
|
|
q->check_blocked = 1;
|
|
spin_unlock_irqrestore(&q->check_lock, flags);
|
|
|
|
__again:
|
|
/* Process tick queue... */
|
|
cur_tick = snd_seq_timer_get_cur_tick(q->timer);
|
|
for (;;) {
|
|
cell = snd_seq_prioq_cell_out(q->tickq, &cur_tick);
|
|
if (!cell)
|
|
break;
|
|
snd_seq_dispatch_event(cell, atomic, hop);
|
|
if (++processed >= MAX_CELL_PROCESSES_IN_QUEUE)
|
|
goto out; /* the rest processed at the next batch */
|
|
}
|
|
|
|
/* Process time queue... */
|
|
cur_time = snd_seq_timer_get_cur_time(q->timer, false);
|
|
for (;;) {
|
|
cell = snd_seq_prioq_cell_out(q->timeq, &cur_time);
|
|
if (!cell)
|
|
break;
|
|
snd_seq_dispatch_event(cell, atomic, hop);
|
|
if (++processed >= MAX_CELL_PROCESSES_IN_QUEUE)
|
|
goto out; /* the rest processed at the next batch */
|
|
}
|
|
|
|
out:
|
|
/* free lock */
|
|
spin_lock_irqsave(&q->check_lock, flags);
|
|
if (q->check_again) {
|
|
q->check_again = 0;
|
|
if (processed < MAX_CELL_PROCESSES_IN_QUEUE) {
|
|
spin_unlock_irqrestore(&q->check_lock, flags);
|
|
goto __again;
|
|
}
|
|
}
|
|
q->check_blocked = 0;
|
|
spin_unlock_irqrestore(&q->check_lock, flags);
|
|
}
|
|
|
|
|
|
/* enqueue a event to singe queue */
|
|
int snd_seq_enqueue_event(struct snd_seq_event_cell *cell, int atomic, int hop)
|
|
{
|
|
int dest, err;
|
|
struct snd_seq_queue *q;
|
|
|
|
if (snd_BUG_ON(!cell))
|
|
return -EINVAL;
|
|
dest = cell->event.queue; /* destination queue */
|
|
q = queueptr(dest);
|
|
if (q == NULL)
|
|
return -EINVAL;
|
|
/* handle relative time stamps, convert them into absolute */
|
|
if ((cell->event.flags & SNDRV_SEQ_TIME_MODE_MASK) == SNDRV_SEQ_TIME_MODE_REL) {
|
|
switch (cell->event.flags & SNDRV_SEQ_TIME_STAMP_MASK) {
|
|
case SNDRV_SEQ_TIME_STAMP_TICK:
|
|
cell->event.time.tick += q->timer->tick.cur_tick;
|
|
break;
|
|
|
|
case SNDRV_SEQ_TIME_STAMP_REAL:
|
|
snd_seq_inc_real_time(&cell->event.time.time,
|
|
&q->timer->cur_time);
|
|
break;
|
|
}
|
|
cell->event.flags &= ~SNDRV_SEQ_TIME_MODE_MASK;
|
|
cell->event.flags |= SNDRV_SEQ_TIME_MODE_ABS;
|
|
}
|
|
/* enqueue event in the real-time or midi queue */
|
|
switch (cell->event.flags & SNDRV_SEQ_TIME_STAMP_MASK) {
|
|
case SNDRV_SEQ_TIME_STAMP_TICK:
|
|
err = snd_seq_prioq_cell_in(q->tickq, cell);
|
|
break;
|
|
|
|
case SNDRV_SEQ_TIME_STAMP_REAL:
|
|
default:
|
|
err = snd_seq_prioq_cell_in(q->timeq, cell);
|
|
break;
|
|
}
|
|
|
|
if (err < 0) {
|
|
queuefree(q); /* unlock */
|
|
return err;
|
|
}
|
|
|
|
/* trigger dispatching */
|
|
snd_seq_check_queue(q, atomic, hop);
|
|
|
|
queuefree(q); /* unlock */
|
|
|
|
return 0;
|
|
}
|
|
|
|
|
|
/*----------------------------------------------------------------*/
|
|
|
|
static inline int check_access(struct snd_seq_queue *q, int client)
|
|
{
|
|
return (q->owner == client) || (!q->locked && !q->klocked);
|
|
}
|
|
|
|
/* check if the client has permission to modify queue parameters.
|
|
* if it does, lock the queue
|
|
*/
|
|
static int queue_access_lock(struct snd_seq_queue *q, int client)
|
|
{
|
|
unsigned long flags;
|
|
int access_ok;
|
|
|
|
spin_lock_irqsave(&q->owner_lock, flags);
|
|
access_ok = check_access(q, client);
|
|
if (access_ok)
|
|
q->klocked = 1;
|
|
spin_unlock_irqrestore(&q->owner_lock, flags);
|
|
return access_ok;
|
|
}
|
|
|
|
/* unlock the queue */
|
|
static inline void queue_access_unlock(struct snd_seq_queue *q)
|
|
{
|
|
unsigned long flags;
|
|
|
|
spin_lock_irqsave(&q->owner_lock, flags);
|
|
q->klocked = 0;
|
|
spin_unlock_irqrestore(&q->owner_lock, flags);
|
|
}
|
|
|
|
/* exported - only checking permission */
|
|
int snd_seq_queue_check_access(int queueid, int client)
|
|
{
|
|
struct snd_seq_queue *q = queueptr(queueid);
|
|
int access_ok;
|
|
unsigned long flags;
|
|
|
|
if (! q)
|
|
return 0;
|
|
spin_lock_irqsave(&q->owner_lock, flags);
|
|
access_ok = check_access(q, client);
|
|
spin_unlock_irqrestore(&q->owner_lock, flags);
|
|
queuefree(q);
|
|
return access_ok;
|
|
}
|
|
|
|
/*----------------------------------------------------------------*/
|
|
|
|
/*
|
|
* change queue's owner and permission
|
|
*/
|
|
int snd_seq_queue_set_owner(int queueid, int client, int locked)
|
|
{
|
|
struct snd_seq_queue *q = queueptr(queueid);
|
|
unsigned long flags;
|
|
|
|
if (q == NULL)
|
|
return -EINVAL;
|
|
|
|
if (! queue_access_lock(q, client)) {
|
|
queuefree(q);
|
|
return -EPERM;
|
|
}
|
|
|
|
spin_lock_irqsave(&q->owner_lock, flags);
|
|
q->locked = locked ? 1 : 0;
|
|
q->owner = client;
|
|
spin_unlock_irqrestore(&q->owner_lock, flags);
|
|
queue_access_unlock(q);
|
|
queuefree(q);
|
|
|
|
return 0;
|
|
}
|
|
|
|
|
|
/*----------------------------------------------------------------*/
|
|
|
|
/* open timer -
|
|
* q->use mutex should be down before calling this function to avoid
|
|
* confliction with snd_seq_queue_use()
|
|
*/
|
|
int snd_seq_queue_timer_open(int queueid)
|
|
{
|
|
int result = 0;
|
|
struct snd_seq_queue *queue;
|
|
struct snd_seq_timer *tmr;
|
|
|
|
queue = queueptr(queueid);
|
|
if (queue == NULL)
|
|
return -EINVAL;
|
|
tmr = queue->timer;
|
|
if ((result = snd_seq_timer_open(queue)) < 0) {
|
|
snd_seq_timer_defaults(tmr);
|
|
result = snd_seq_timer_open(queue);
|
|
}
|
|
queuefree(queue);
|
|
return result;
|
|
}
|
|
|
|
/* close timer -
|
|
* q->use mutex should be down before calling this function
|
|
*/
|
|
int snd_seq_queue_timer_close(int queueid)
|
|
{
|
|
struct snd_seq_queue *queue;
|
|
int result = 0;
|
|
|
|
queue = queueptr(queueid);
|
|
if (queue == NULL)
|
|
return -EINVAL;
|
|
snd_seq_timer_close(queue);
|
|
queuefree(queue);
|
|
return result;
|
|
}
|
|
|
|
/* change queue tempo and ppq */
|
|
int snd_seq_queue_timer_set_tempo(int queueid, int client,
|
|
struct snd_seq_queue_tempo *info)
|
|
{
|
|
struct snd_seq_queue *q = queueptr(queueid);
|
|
int result;
|
|
|
|
if (q == NULL)
|
|
return -EINVAL;
|
|
if (! queue_access_lock(q, client)) {
|
|
queuefree(q);
|
|
return -EPERM;
|
|
}
|
|
|
|
result = snd_seq_timer_set_tempo(q->timer, info->tempo);
|
|
if (result >= 0)
|
|
result = snd_seq_timer_set_ppq(q->timer, info->ppq);
|
|
if (result >= 0 && info->skew_base > 0)
|
|
result = snd_seq_timer_set_skew(q->timer, info->skew_value,
|
|
info->skew_base);
|
|
queue_access_unlock(q);
|
|
queuefree(q);
|
|
return result;
|
|
}
|
|
|
|
/* use or unuse this queue */
|
|
static void queue_use(struct snd_seq_queue *queue, int client, int use)
|
|
{
|
|
if (use) {
|
|
if (!test_and_set_bit(client, queue->clients_bitmap))
|
|
queue->clients++;
|
|
} else {
|
|
if (test_and_clear_bit(client, queue->clients_bitmap))
|
|
queue->clients--;
|
|
}
|
|
if (queue->clients) {
|
|
if (use && queue->clients == 1)
|
|
snd_seq_timer_defaults(queue->timer);
|
|
snd_seq_timer_open(queue);
|
|
} else {
|
|
snd_seq_timer_close(queue);
|
|
}
|
|
}
|
|
|
|
/* use or unuse this queue -
|
|
* if it is the first client, starts the timer.
|
|
* if it is not longer used by any clients, stop the timer.
|
|
*/
|
|
int snd_seq_queue_use(int queueid, int client, int use)
|
|
{
|
|
struct snd_seq_queue *queue;
|
|
|
|
queue = queueptr(queueid);
|
|
if (queue == NULL)
|
|
return -EINVAL;
|
|
mutex_lock(&queue->timer_mutex);
|
|
queue_use(queue, client, use);
|
|
mutex_unlock(&queue->timer_mutex);
|
|
queuefree(queue);
|
|
return 0;
|
|
}
|
|
|
|
/*
|
|
* check if queue is used by the client
|
|
* return negative value if the queue is invalid.
|
|
* return 0 if not used, 1 if used.
|
|
*/
|
|
int snd_seq_queue_is_used(int queueid, int client)
|
|
{
|
|
struct snd_seq_queue *q;
|
|
int result;
|
|
|
|
q = queueptr(queueid);
|
|
if (q == NULL)
|
|
return -EINVAL; /* invalid queue */
|
|
result = test_bit(client, q->clients_bitmap) ? 1 : 0;
|
|
queuefree(q);
|
|
return result;
|
|
}
|
|
|
|
|
|
/*----------------------------------------------------------------*/
|
|
|
|
/* notification that client has left the system -
|
|
* stop the timer on all queues owned by this client
|
|
*/
|
|
void snd_seq_queue_client_termination(int client)
|
|
{
|
|
unsigned long flags;
|
|
int i;
|
|
struct snd_seq_queue *q;
|
|
bool matched;
|
|
|
|
for (i = 0; i < SNDRV_SEQ_MAX_QUEUES; i++) {
|
|
if ((q = queueptr(i)) == NULL)
|
|
continue;
|
|
spin_lock_irqsave(&q->owner_lock, flags);
|
|
matched = (q->owner == client);
|
|
if (matched)
|
|
q->klocked = 1;
|
|
spin_unlock_irqrestore(&q->owner_lock, flags);
|
|
if (matched) {
|
|
if (q->timer->running)
|
|
snd_seq_timer_stop(q->timer);
|
|
snd_seq_timer_reset(q->timer);
|
|
}
|
|
queuefree(q);
|
|
}
|
|
}
|
|
|
|
/* final stage notification -
|
|
* remove cells for no longer exist client (for non-owned queue)
|
|
* or delete this queue (for owned queue)
|
|
*/
|
|
void snd_seq_queue_client_leave(int client)
|
|
{
|
|
int i;
|
|
struct snd_seq_queue *q;
|
|
|
|
/* delete own queues from queue list */
|
|
for (i = 0; i < SNDRV_SEQ_MAX_QUEUES; i++) {
|
|
if ((q = queue_list_remove(i, client)) != NULL)
|
|
queue_delete(q);
|
|
}
|
|
|
|
/* remove cells from existing queues -
|
|
* they are not owned by this client
|
|
*/
|
|
for (i = 0; i < SNDRV_SEQ_MAX_QUEUES; i++) {
|
|
if ((q = queueptr(i)) == NULL)
|
|
continue;
|
|
if (test_bit(client, q->clients_bitmap)) {
|
|
snd_seq_prioq_leave(q->tickq, client, 0);
|
|
snd_seq_prioq_leave(q->timeq, client, 0);
|
|
snd_seq_queue_use(q->queue, client, 0);
|
|
}
|
|
queuefree(q);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/*----------------------------------------------------------------*/
|
|
|
|
/* remove cells from all queues */
|
|
void snd_seq_queue_client_leave_cells(int client)
|
|
{
|
|
int i;
|
|
struct snd_seq_queue *q;
|
|
|
|
for (i = 0; i < SNDRV_SEQ_MAX_QUEUES; i++) {
|
|
if ((q = queueptr(i)) == NULL)
|
|
continue;
|
|
snd_seq_prioq_leave(q->tickq, client, 0);
|
|
snd_seq_prioq_leave(q->timeq, client, 0);
|
|
queuefree(q);
|
|
}
|
|
}
|
|
|
|
/* remove cells based on flush criteria */
|
|
void snd_seq_queue_remove_cells(int client, struct snd_seq_remove_events *info)
|
|
{
|
|
int i;
|
|
struct snd_seq_queue *q;
|
|
|
|
for (i = 0; i < SNDRV_SEQ_MAX_QUEUES; i++) {
|
|
if ((q = queueptr(i)) == NULL)
|
|
continue;
|
|
if (test_bit(client, q->clients_bitmap) &&
|
|
(! (info->remove_mode & SNDRV_SEQ_REMOVE_DEST) ||
|
|
q->queue == info->queue)) {
|
|
snd_seq_prioq_remove_events(q->tickq, client, info);
|
|
snd_seq_prioq_remove_events(q->timeq, client, info);
|
|
}
|
|
queuefree(q);
|
|
}
|
|
}
|
|
|
|
/*----------------------------------------------------------------*/
|
|
|
|
/*
|
|
* send events to all subscribed ports
|
|
*/
|
|
static void queue_broadcast_event(struct snd_seq_queue *q, struct snd_seq_event *ev,
|
|
int atomic, int hop)
|
|
{
|
|
struct snd_seq_event sev;
|
|
|
|
sev = *ev;
|
|
|
|
sev.flags = SNDRV_SEQ_TIME_STAMP_TICK|SNDRV_SEQ_TIME_MODE_ABS;
|
|
sev.time.tick = q->timer->tick.cur_tick;
|
|
sev.queue = q->queue;
|
|
sev.data.queue.queue = q->queue;
|
|
|
|
/* broadcast events from Timer port */
|
|
sev.source.client = SNDRV_SEQ_CLIENT_SYSTEM;
|
|
sev.source.port = SNDRV_SEQ_PORT_SYSTEM_TIMER;
|
|
sev.dest.client = SNDRV_SEQ_ADDRESS_SUBSCRIBERS;
|
|
snd_seq_kernel_client_dispatch(SNDRV_SEQ_CLIENT_SYSTEM, &sev, atomic, hop);
|
|
}
|
|
|
|
/*
|
|
* process a received queue-control event.
|
|
* this function is exported for seq_sync.c.
|
|
*/
|
|
static void snd_seq_queue_process_event(struct snd_seq_queue *q,
|
|
struct snd_seq_event *ev,
|
|
int atomic, int hop)
|
|
{
|
|
switch (ev->type) {
|
|
case SNDRV_SEQ_EVENT_START:
|
|
snd_seq_prioq_leave(q->tickq, ev->source.client, 1);
|
|
snd_seq_prioq_leave(q->timeq, ev->source.client, 1);
|
|
if (! snd_seq_timer_start(q->timer))
|
|
queue_broadcast_event(q, ev, atomic, hop);
|
|
break;
|
|
|
|
case SNDRV_SEQ_EVENT_CONTINUE:
|
|
if (! snd_seq_timer_continue(q->timer))
|
|
queue_broadcast_event(q, ev, atomic, hop);
|
|
break;
|
|
|
|
case SNDRV_SEQ_EVENT_STOP:
|
|
snd_seq_timer_stop(q->timer);
|
|
queue_broadcast_event(q, ev, atomic, hop);
|
|
break;
|
|
|
|
case SNDRV_SEQ_EVENT_TEMPO:
|
|
snd_seq_timer_set_tempo(q->timer, ev->data.queue.param.value);
|
|
queue_broadcast_event(q, ev, atomic, hop);
|
|
break;
|
|
|
|
case SNDRV_SEQ_EVENT_SETPOS_TICK:
|
|
if (snd_seq_timer_set_position_tick(q->timer, ev->data.queue.param.time.tick) == 0) {
|
|
queue_broadcast_event(q, ev, atomic, hop);
|
|
}
|
|
break;
|
|
|
|
case SNDRV_SEQ_EVENT_SETPOS_TIME:
|
|
if (snd_seq_timer_set_position_time(q->timer, ev->data.queue.param.time.time) == 0) {
|
|
queue_broadcast_event(q, ev, atomic, hop);
|
|
}
|
|
break;
|
|
case SNDRV_SEQ_EVENT_QUEUE_SKEW:
|
|
if (snd_seq_timer_set_skew(q->timer,
|
|
ev->data.queue.param.skew.value,
|
|
ev->data.queue.param.skew.base) == 0) {
|
|
queue_broadcast_event(q, ev, atomic, hop);
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
|
|
|
|
/*
|
|
* Queue control via timer control port:
|
|
* this function is exported as a callback of timer port.
|
|
*/
|
|
int snd_seq_control_queue(struct snd_seq_event *ev, int atomic, int hop)
|
|
{
|
|
struct snd_seq_queue *q;
|
|
|
|
if (snd_BUG_ON(!ev))
|
|
return -EINVAL;
|
|
q = queueptr(ev->data.queue.queue);
|
|
|
|
if (q == NULL)
|
|
return -EINVAL;
|
|
|
|
if (! queue_access_lock(q, ev->source.client)) {
|
|
queuefree(q);
|
|
return -EPERM;
|
|
}
|
|
|
|
snd_seq_queue_process_event(q, ev, atomic, hop);
|
|
|
|
queue_access_unlock(q);
|
|
queuefree(q);
|
|
return 0;
|
|
}
|
|
|
|
|
|
/*----------------------------------------------------------------*/
|
|
|
|
#ifdef CONFIG_SND_PROC_FS
|
|
/* exported to seq_info.c */
|
|
void snd_seq_info_queues_read(struct snd_info_entry *entry,
|
|
struct snd_info_buffer *buffer)
|
|
{
|
|
int i, bpm;
|
|
struct snd_seq_queue *q;
|
|
struct snd_seq_timer *tmr;
|
|
bool locked;
|
|
int owner;
|
|
|
|
for (i = 0; i < SNDRV_SEQ_MAX_QUEUES; i++) {
|
|
if ((q = queueptr(i)) == NULL)
|
|
continue;
|
|
|
|
tmr = q->timer;
|
|
if (tmr->tempo)
|
|
bpm = 60000000 / tmr->tempo;
|
|
else
|
|
bpm = 0;
|
|
|
|
spin_lock_irq(&q->owner_lock);
|
|
locked = q->locked;
|
|
owner = q->owner;
|
|
spin_unlock_irq(&q->owner_lock);
|
|
|
|
snd_iprintf(buffer, "queue %d: [%s]\n", q->queue, q->name);
|
|
snd_iprintf(buffer, "owned by client : %d\n", owner);
|
|
snd_iprintf(buffer, "lock status : %s\n", locked ? "Locked" : "Free");
|
|
snd_iprintf(buffer, "queued time events : %d\n", snd_seq_prioq_avail(q->timeq));
|
|
snd_iprintf(buffer, "queued tick events : %d\n", snd_seq_prioq_avail(q->tickq));
|
|
snd_iprintf(buffer, "timer state : %s\n", tmr->running ? "Running" : "Stopped");
|
|
snd_iprintf(buffer, "timer PPQ : %d\n", tmr->ppq);
|
|
snd_iprintf(buffer, "current tempo : %d\n", tmr->tempo);
|
|
snd_iprintf(buffer, "current BPM : %d\n", bpm);
|
|
snd_iprintf(buffer, "current time : %d.%09d s\n", tmr->cur_time.tv_sec, tmr->cur_time.tv_nsec);
|
|
snd_iprintf(buffer, "current tick : %d\n", tmr->tick.cur_tick);
|
|
snd_iprintf(buffer, "\n");
|
|
queuefree(q);
|
|
}
|
|
}
|
|
#endif /* CONFIG_SND_PROC_FS */
|
|
|