Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-or-later */
0002 #ifndef __SOUND_RAWMIDI_H
0003 #define __SOUND_RAWMIDI_H
0004 
0005 /*
0006  *  Abstract layer for MIDI v1.0 stream
0007  *  Copyright (c) by Jaroslav Kysela <perex@perex.cz>
0008  */
0009 
0010 #include <sound/asound.h>
0011 #include <linux/interrupt.h>
0012 #include <linux/spinlock.h>
0013 #include <linux/wait.h>
0014 #include <linux/mutex.h>
0015 #include <linux/workqueue.h>
0016 #include <linux/device.h>
0017 
0018 #if IS_ENABLED(CONFIG_SND_SEQUENCER)
0019 #include <sound/seq_device.h>
0020 #endif
0021 
0022 /*
0023  *  Raw MIDI interface
0024  */
0025 
0026 #define SNDRV_RAWMIDI_DEVICES       8
0027 
0028 #define SNDRV_RAWMIDI_LFLG_OUTPUT   (1<<0)
0029 #define SNDRV_RAWMIDI_LFLG_INPUT    (1<<1)
0030 #define SNDRV_RAWMIDI_LFLG_OPEN     (3<<0)
0031 #define SNDRV_RAWMIDI_LFLG_APPEND   (1<<2)
0032 
0033 struct snd_rawmidi;
0034 struct snd_rawmidi_substream;
0035 struct snd_seq_port_info;
0036 struct pid;
0037 
0038 struct snd_rawmidi_ops {
0039     int (*open) (struct snd_rawmidi_substream * substream);
0040     int (*close) (struct snd_rawmidi_substream * substream);
0041     void (*trigger) (struct snd_rawmidi_substream * substream, int up);
0042     void (*drain) (struct snd_rawmidi_substream * substream);
0043 };
0044 
0045 struct snd_rawmidi_global_ops {
0046     int (*dev_register) (struct snd_rawmidi * rmidi);
0047     int (*dev_unregister) (struct snd_rawmidi * rmidi);
0048     void (*get_port_info)(struct snd_rawmidi *rmidi, int number,
0049                   struct snd_seq_port_info *info);
0050 };
0051 
0052 struct snd_rawmidi_runtime {
0053     struct snd_rawmidi_substream *substream;
0054     unsigned int drain: 1,  /* drain stage */
0055              oss: 1;    /* OSS compatible mode */
0056     /* midi stream buffer */
0057     unsigned char *buffer;  /* buffer for MIDI data */
0058     size_t buffer_size; /* size of buffer */
0059     size_t appl_ptr;    /* application pointer */
0060     size_t hw_ptr;      /* hardware pointer */
0061     size_t avail_min;   /* min avail for wakeup */
0062     size_t avail;       /* max used buffer for wakeup */
0063     size_t xruns;       /* over/underruns counter */
0064     int buffer_ref;     /* buffer reference count */
0065     /* misc */
0066     wait_queue_head_t sleep;
0067     /* event handler (new bytes, input only) */
0068     void (*event)(struct snd_rawmidi_substream *substream);
0069     /* defers calls to event [input] or ops->trigger [output] */
0070     struct work_struct event_work;
0071     /* private data */
0072     void *private_data;
0073     void (*private_free)(struct snd_rawmidi_substream *substream);
0074 };
0075 
0076 struct snd_rawmidi_substream {
0077     struct list_head list;      /* list of all substream for given stream */
0078     int stream;         /* direction */
0079     int number;         /* substream number */
0080     bool opened;            /* open flag */
0081     bool append;            /* append flag (merge more streams) */
0082     bool active_sensing;        /* send active sensing when close */
0083     unsigned int framing;       /* whether to frame input data */
0084     unsigned int clock_type;    /* clock source to use for input framing */
0085     int use_count;          /* use counter (for output) */
0086     size_t bytes;
0087     spinlock_t lock;
0088     struct snd_rawmidi *rmidi;
0089     struct snd_rawmidi_str *pstr;
0090     char name[32];
0091     struct snd_rawmidi_runtime *runtime;
0092     struct pid *pid;
0093     /* hardware layer */
0094     const struct snd_rawmidi_ops *ops;
0095 };
0096 
0097 struct snd_rawmidi_file {
0098     struct snd_rawmidi *rmidi;
0099     struct snd_rawmidi_substream *input;
0100     struct snd_rawmidi_substream *output;
0101     unsigned int user_pversion; /* supported protocol version */
0102 };
0103 
0104 struct snd_rawmidi_str {
0105     unsigned int substream_count;
0106     unsigned int substream_opened;
0107     struct list_head substreams;
0108 };
0109 
0110 struct snd_rawmidi {
0111     struct snd_card *card;
0112     struct list_head list;
0113     unsigned int device;        /* device number */
0114     unsigned int info_flags;    /* SNDRV_RAWMIDI_INFO_XXXX */
0115     char id[64];
0116     char name[80];
0117 
0118 #ifdef CONFIG_SND_OSSEMUL
0119     int ossreg;
0120 #endif
0121 
0122     const struct snd_rawmidi_global_ops *ops;
0123 
0124     struct snd_rawmidi_str streams[2];
0125 
0126     void *private_data;
0127     void (*private_free) (struct snd_rawmidi *rmidi);
0128 
0129     struct mutex open_mutex;
0130     wait_queue_head_t open_wait;
0131 
0132     struct device dev;
0133 
0134     struct snd_info_entry *proc_entry;
0135 
0136 #if IS_ENABLED(CONFIG_SND_SEQUENCER)
0137     struct snd_seq_device *seq_dev;
0138 #endif
0139 };
0140 
0141 /* main rawmidi functions */
0142 
0143 int snd_rawmidi_new(struct snd_card *card, char *id, int device,
0144             int output_count, int input_count,
0145             struct snd_rawmidi **rmidi);
0146 void snd_rawmidi_set_ops(struct snd_rawmidi *rmidi, int stream,
0147              const struct snd_rawmidi_ops *ops);
0148 
0149 /* callbacks */
0150 
0151 int snd_rawmidi_receive(struct snd_rawmidi_substream *substream,
0152             const unsigned char *buffer, int count);
0153 int snd_rawmidi_transmit_empty(struct snd_rawmidi_substream *substream);
0154 int snd_rawmidi_transmit_peek(struct snd_rawmidi_substream *substream,
0155                   unsigned char *buffer, int count);
0156 int snd_rawmidi_transmit_ack(struct snd_rawmidi_substream *substream, int count);
0157 int snd_rawmidi_transmit(struct snd_rawmidi_substream *substream,
0158              unsigned char *buffer, int count);
0159 int snd_rawmidi_proceed(struct snd_rawmidi_substream *substream);
0160 
0161 /* main midi functions */
0162 
0163 int snd_rawmidi_info_select(struct snd_card *card, struct snd_rawmidi_info *info);
0164 int snd_rawmidi_kernel_open(struct snd_card *card, int device, int subdevice,
0165                 int mode, struct snd_rawmidi_file *rfile);
0166 int snd_rawmidi_kernel_release(struct snd_rawmidi_file *rfile);
0167 int snd_rawmidi_output_params(struct snd_rawmidi_substream *substream,
0168                   struct snd_rawmidi_params *params);
0169 int snd_rawmidi_input_params(struct snd_rawmidi_substream *substream,
0170                  struct snd_rawmidi_params *params);
0171 int snd_rawmidi_drop_output(struct snd_rawmidi_substream *substream);
0172 int snd_rawmidi_drain_output(struct snd_rawmidi_substream *substream);
0173 int snd_rawmidi_drain_input(struct snd_rawmidi_substream *substream);
0174 long snd_rawmidi_kernel_read(struct snd_rawmidi_substream *substream,
0175                  unsigned char *buf, long count);
0176 long snd_rawmidi_kernel_write(struct snd_rawmidi_substream *substream,
0177                   const unsigned char *buf, long count);
0178 
0179 #endif /* __SOUND_RAWMIDI_H */