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 #define SND_SEQ_GROUP_FILTER_MASK GENMASK(SNDRV_UMP_MAX_GROUPS, 0)
18 #define SND_SEQ_GROUP_FILTER_GROUPS GENMASK(SNDRV_UMP_MAX_GROUPS, 1)
19
20 struct snd_seq_user_client {
21 struct file *file; /* file struct of client */
22 /* ... */
23 struct pid *owner;
24
25 /* fifo */
26 struct snd_seq_fifo *fifo; /* queue for incoming events */
27 int fifo_pool_size;
28 };
29
30 struct snd_seq_kernel_client {
31 /* ... */
32 struct snd_card *card;
33 };
34
35
36 struct snd_seq_client {
37 snd_seq_client_type_t type;
38 unsigned int accept_input: 1,
39 accept_output: 1;
40 unsigned int midi_version;
41 unsigned int user_pversion;
42 char name[64]; /* client name */
43 int number; /* client number */
44 unsigned int filter; /* filter flags */
45 DECLARE_BITMAP(event_filter, 256);
46 unsigned int group_filter;
47 snd_use_lock_t use_lock;
48 int event_lost;
49 /* ports */
50 int num_ports; /* number of ports */
51 struct list_head ports_list_head;
52 rwlock_t ports_lock;
53 struct mutex ports_mutex;
54 struct mutex ioctl_mutex;
55 int convert32; /* convert 32->64bit */
56 int ump_endpoint_port;
57
58 /* output pool */
59 struct snd_seq_pool *pool; /* memory pool for this client */
60
61 union {
62 struct snd_seq_user_client user;
63 struct snd_seq_kernel_client kernel;
64 } data;
65
66 /* for UMP */
67 void **ump_info;
68 };
69
70 /* usage statistics */
71 struct snd_seq_usage {
72 int cur;
73 int peak;
74 };
75
76
77 int client_init_data(void);
78 int snd_sequencer_device_init(void);
79 void snd_sequencer_device_done(void);
80
81 /* get locked pointer to client */
82 struct snd_seq_client *snd_seq_client_use_ptr(int clientid);
83
84 static inline struct snd_seq_client *
snd_seq_client_ref(struct snd_seq_client * client)85 snd_seq_client_ref(struct snd_seq_client *client)
86 {
87 snd_use_lock_use(&client->use_lock);
88 return client;
89 }
90
91 /* unlock pointer to client */
snd_seq_client_unref(struct snd_seq_client * client)92 static inline void snd_seq_client_unref(struct snd_seq_client *client)
93 {
94 snd_use_lock_free(&client->use_lock);
95 }
96
97 DEFINE_FREE(snd_seq_client, struct snd_seq_client *, if (!IS_ERR_OR_NULL(_T)) snd_seq_client_unref(_T))
98
99 /* dispatch event to client(s) */
100 int snd_seq_dispatch_event(struct snd_seq_event_cell *cell, int atomic, int hop);
101
102 int snd_seq_kernel_client_write_poll(int clientid, struct file *file, poll_table *wait);
103 int snd_seq_client_notify_subscription(int client, int port,
104 struct snd_seq_port_subscribe *info, int evtype);
105
106 int __snd_seq_deliver_single_event(struct snd_seq_client *dest,
107 struct snd_seq_client_port *dest_port,
108 struct snd_seq_event *event,
109 int atomic, int hop);
110
111 /* only for OSS sequencer */
112 int snd_seq_kernel_client_ioctl(int clientid, unsigned int cmd, void *arg);
113
114 extern int seq_client_load[15];
115
116 /* for internal use between kernel sequencer clients */
117 struct snd_seq_client *snd_seq_kernel_client_get(int client);
118 void snd_seq_kernel_client_put(struct snd_seq_client *cptr);
119
snd_seq_client_is_ump(struct snd_seq_client * c)120 static inline bool snd_seq_client_is_ump(struct snd_seq_client *c)
121 {
122 return c->midi_version != SNDRV_SEQ_CLIENT_LEGACY_MIDI;
123 }
124
snd_seq_client_is_midi2(struct snd_seq_client * c)125 static inline bool snd_seq_client_is_midi2(struct snd_seq_client *c)
126 {
127 return c->midi_version == SNDRV_SEQ_CLIENT_UMP_MIDI_2_0;
128 }
129
130 #endif
131