xref: /linux/sound/core/seq/seq_clientmgr.h (revision d2d247e35eeea8331150d7708211a013aabccb5b)
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*
3  *   ALSA sequencer Client Manager
4  *   Copyright (c) 1998-1999 by Frank van de Pol <fvdpol@coil.demon.nl>
5  */
6 #ifndef __SND_SEQ_CLIENTMGR_H
7 #define __SND_SEQ_CLIENTMGR_H
8 
9 #include <sound/seq_kernel.h>
10 #include <linux/bitops.h>
11 #include "seq_fifo.h"
12 #include "seq_ports.h"
13 #include "seq_lock.h"
14 
15 /* client manager */
16 
17 struct snd_seq_user_client {
18 	struct file *file;	/* file struct of client */
19 	/* ... */
20 	struct pid *owner;
21 
22 	/* fifo */
23 	struct snd_seq_fifo *fifo;	/* queue for incoming events */
24 	int fifo_pool_size;
25 };
26 
27 struct snd_seq_kernel_client {
28 	/* ... */
29 	struct snd_card *card;
30 };
31 
32 
33 struct snd_seq_client {
34 	snd_seq_client_type_t type;
35 	unsigned int accept_input: 1,
36 		accept_output: 1;
37 	unsigned int midi_version;
38 	unsigned int user_pversion;
39 	char name[64];		/* client name */
40 	int number;		/* client number */
41 	unsigned int filter;	/* filter flags */
42 	DECLARE_BITMAP(event_filter, 256);
43 	snd_use_lock_t use_lock;
44 	int event_lost;
45 	/* ports */
46 	int num_ports;		/* number of ports */
47 	struct list_head ports_list_head;
48 	rwlock_t ports_lock;
49 	struct mutex ports_mutex;
50 	struct mutex ioctl_mutex;
51 	int convert32;		/* convert 32->64bit */
52 	int ump_endpoint_port;
53 
54 	/* output pool */
55 	struct snd_seq_pool *pool;		/* memory pool for this client */
56 
57 	union {
58 		struct snd_seq_user_client user;
59 		struct snd_seq_kernel_client kernel;
60 	} data;
61 
62 	/* for UMP */
63 	void **ump_info;
64 };
65 
66 /* usage statistics */
67 struct snd_seq_usage {
68 	int cur;
69 	int peak;
70 };
71 
72 
73 int client_init_data(void);
74 int snd_sequencer_device_init(void);
75 void snd_sequencer_device_done(void);
76 
77 /* get locked pointer to client */
78 struct snd_seq_client *snd_seq_client_use_ptr(int clientid);
79 
80 /* unlock pointer to client */
81 #define snd_seq_client_unlock(client) snd_use_lock_free(&(client)->use_lock)
82 
83 /* dispatch event to client(s) */
84 int snd_seq_dispatch_event(struct snd_seq_event_cell *cell, int atomic, int hop);
85 
86 int snd_seq_kernel_client_write_poll(int clientid, struct file *file, poll_table *wait);
87 int snd_seq_client_notify_subscription(int client, int port,
88 				       struct snd_seq_port_subscribe *info, int evtype);
89 
90 int __snd_seq_deliver_single_event(struct snd_seq_client *dest,
91 				   struct snd_seq_client_port *dest_port,
92 				   struct snd_seq_event *event,
93 				   int atomic, int hop);
94 
95 /* only for OSS sequencer */
96 bool snd_seq_client_ioctl_lock(int clientid);
97 void snd_seq_client_ioctl_unlock(int clientid);
98 
99 extern int seq_client_load[15];
100 
101 /* for internal use between kernel sequencer clients */
102 struct snd_seq_client *snd_seq_kernel_client_get(int client);
103 void snd_seq_kernel_client_put(struct snd_seq_client *cptr);
104 
105 static inline bool snd_seq_client_is_ump(struct snd_seq_client *c)
106 {
107 	return c->midi_version != SNDRV_SEQ_CLIENT_LEGACY_MIDI;
108 }
109 
110 static inline bool snd_seq_client_is_midi2(struct snd_seq_client *c)
111 {
112 	return c->midi_version == SNDRV_SEQ_CLIENT_UMP_MIDI_2_0;
113 }
114 
115 #endif
116