linux/sound/core/rawmidi.c

// SPDX-License-Identifier: GPL-2.0-or-later
/*
 *  Abstract layer for MIDI v1.0 stream
 *  Copyright (c) by Jaroslav Kysela <[email protected]>
 */

#include <sound/core.h>
#include <linux/major.h>
#include <linux/init.h>
#include <linux/sched/signal.h>
#include <linux/slab.h>
#include <linux/time.h>
#include <linux/wait.h>
#include <linux/mutex.h>
#include <linux/module.h>
#include <linux/delay.h>
#include <linux/mm.h>
#include <linux/nospec.h>
#include <sound/rawmidi.h>
#include <sound/info.h>
#include <sound/control.h>
#include <sound/minors.h>
#include <sound/initval.h>
#include <sound/ump.h>

MODULE_AUTHOR();
MODULE_DESCRIPTION();
MODULE_LICENSE();

#ifdef CONFIG_SND_OSSEMUL
static int midi_map[SNDRV_CARDS];
static int amidi_map[SNDRV_CARDS] =;
module_param_array();
MODULE_PARM_DESC();
module_param_array();
MODULE_PARM_DESC();
#endif /* CONFIG_SND_OSSEMUL */

static int snd_rawmidi_dev_free(struct snd_device *device);
static int snd_rawmidi_dev_register(struct snd_device *device);
static int snd_rawmidi_dev_disconnect(struct snd_device *device);

static LIST_HEAD(snd_rawmidi_devices);
static DEFINE_MUTEX(register_mutex);

#define rmidi_err(rmidi, fmt, args...)
#define rmidi_warn(rmidi, fmt, args...)
#define rmidi_dbg(rmidi, fmt, args...)

struct snd_rawmidi_status32 {};

#define SNDRV_RAWMIDI_IOCTL_STATUS32

struct snd_rawmidi_status64 {};

#define SNDRV_RAWMIDI_IOCTL_STATUS64

#define rawmidi_is_ump(rmidi)

static struct snd_rawmidi *snd_rawmidi_search(struct snd_card *card, int device)
{}

static inline unsigned short snd_rawmidi_file_flags(struct file *file)
{}

static inline bool __snd_rawmidi_ready(struct snd_rawmidi_runtime *runtime)
{}

static bool snd_rawmidi_ready(struct snd_rawmidi_substream *substream)
{}

static inline int snd_rawmidi_ready_append(struct snd_rawmidi_substream *substream,
					   size_t count)
{}

static void snd_rawmidi_input_event_work(struct work_struct *work)
{}

/* buffer refcount management: call with substream->lock held */
static inline void snd_rawmidi_buffer_ref(struct snd_rawmidi_runtime *runtime)
{}

static inline void snd_rawmidi_buffer_unref(struct snd_rawmidi_runtime *runtime)
{}

static void snd_rawmidi_buffer_ref_sync(struct snd_rawmidi_substream *substream)
{}

static int snd_rawmidi_runtime_create(struct snd_rawmidi_substream *substream)
{}

/* get the current alignment (either 0 or 3) */
static inline int get_align(struct snd_rawmidi_runtime *runtime)
{}

/* get the trimmed size with the current alignment */
#define get_aligned_size(runtime, size)

static int snd_rawmidi_runtime_free(struct snd_rawmidi_substream *substream)
{}

static inline void snd_rawmidi_output_trigger(struct snd_rawmidi_substream *substream, int up)
{}

static void snd_rawmidi_input_trigger(struct snd_rawmidi_substream *substream, int up)
{}

static void __reset_runtime_ptrs(struct snd_rawmidi_runtime *runtime,
				 bool is_input)
{}

static void reset_runtime_ptrs(struct snd_rawmidi_substream *substream,
			       bool is_input)
{}

int snd_rawmidi_drop_output(struct snd_rawmidi_substream *substream)
{}
EXPORT_SYMBOL();

int snd_rawmidi_drain_output(struct snd_rawmidi_substream *substream)
{}
EXPORT_SYMBOL();

int snd_rawmidi_drain_input(struct snd_rawmidi_substream *substream)
{}
EXPORT_SYMBOL();

/* look for an available substream for the given stream direction;
 * if a specific subdevice is given, try to assign it
 */
static int assign_substream(struct snd_rawmidi *rmidi, int subdevice,
			    int stream, int mode,
			    struct snd_rawmidi_substream **sub_ret)
{}

/* open and do ref-counting for the given substream */
static int open_substream(struct snd_rawmidi *rmidi,
			  struct snd_rawmidi_substream *substream,
			  int mode)
{}

static void close_substream(struct snd_rawmidi *rmidi,
			    struct snd_rawmidi_substream *substream,
			    int cleanup);

static int rawmidi_open_priv(struct snd_rawmidi *rmidi, int subdevice, int mode,
			     struct snd_rawmidi_file *rfile)
{}

/* called from sound/core/seq/seq_midi.c */
int snd_rawmidi_kernel_open(struct snd_rawmidi *rmidi, int subdevice,
			    int mode, struct snd_rawmidi_file *rfile)
{}
EXPORT_SYMBOL();

static int snd_rawmidi_open(struct inode *inode, struct file *file)
{}

static void close_substream(struct snd_rawmidi *rmidi,
			    struct snd_rawmidi_substream *substream,
			    int cleanup)
{}

static void rawmidi_release_priv(struct snd_rawmidi_file *rfile)
{}

/* called from sound/core/seq/seq_midi.c */
int snd_rawmidi_kernel_release(struct snd_rawmidi_file *rfile)
{}
EXPORT_SYMBOL();

static int snd_rawmidi_release(struct inode *inode, struct file *file)
{}

static int snd_rawmidi_info(struct snd_rawmidi_substream *substream,
			    struct snd_rawmidi_info *info)
{}

static int snd_rawmidi_info_user(struct snd_rawmidi_substream *substream,
				 struct snd_rawmidi_info __user *_info)
{}

static int __snd_rawmidi_info_select(struct snd_card *card,
				     struct snd_rawmidi_info *info)
{}

int snd_rawmidi_info_select(struct snd_card *card, struct snd_rawmidi_info *info)
{}
EXPORT_SYMBOL();

static int snd_rawmidi_info_select_user(struct snd_card *card,
					struct snd_rawmidi_info __user *_info)
{}

static int resize_runtime_buffer(struct snd_rawmidi_substream *substream,
				 struct snd_rawmidi_params *params,
				 bool is_input)
{}

int snd_rawmidi_output_params(struct snd_rawmidi_substream *substream,
			      struct snd_rawmidi_params *params)
{}
EXPORT_SYMBOL();

int snd_rawmidi_input_params(struct snd_rawmidi_substream *substream,
			     struct snd_rawmidi_params *params)
{}
EXPORT_SYMBOL();

static int snd_rawmidi_output_status(struct snd_rawmidi_substream *substream,
				     struct snd_rawmidi_status64 *status)
{}

static int snd_rawmidi_input_status(struct snd_rawmidi_substream *substream,
				    struct snd_rawmidi_status64 *status)
{}

static int snd_rawmidi_ioctl_status32(struct snd_rawmidi_file *rfile,
				      struct snd_rawmidi_status32 __user *argp)
{}

static int snd_rawmidi_ioctl_status64(struct snd_rawmidi_file *rfile,
				      struct snd_rawmidi_status64 __user *argp)
{}

static long snd_rawmidi_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
{}

/* ioctl to find the next device; either legacy or UMP depending on @find_ump */
static int snd_rawmidi_next_device(struct snd_card *card, int __user *argp,
				   bool find_ump)

{}

#if IS_ENABLED(CONFIG_SND_UMP)
/* inquiry of UMP endpoint and block info via control API */
static int snd_rawmidi_call_ump_ioctl(struct snd_card *card, int cmd,
				      void __user *argp)
{}
#endif

static int snd_rawmidi_control_ioctl(struct snd_card *card,
				     struct snd_ctl_file *control,
				     unsigned int cmd,
				     unsigned long arg)
{}

static int receive_with_tstamp_framing(struct snd_rawmidi_substream *substream,
			const unsigned char *buffer, int src_count, const struct timespec64 *tstamp)
{}

static struct timespec64 get_framing_tstamp(struct snd_rawmidi_substream *substream)
{}

/**
 * snd_rawmidi_receive - receive the input data from the device
 * @substream: the rawmidi substream
 * @buffer: the buffer pointer
 * @count: the data size to read
 *
 * Reads the data from the internal buffer.
 *
 * Return: The size of read data, or a negative error code on failure.
 */
int snd_rawmidi_receive(struct snd_rawmidi_substream *substream,
			const unsigned char *buffer, int count)
{}
EXPORT_SYMBOL();

static long snd_rawmidi_kernel_read1(struct snd_rawmidi_substream *substream,
				     unsigned char __user *userbuf,
				     unsigned char *kernelbuf, long count)
{}

long snd_rawmidi_kernel_read(struct snd_rawmidi_substream *substream,
			     unsigned char *buf, long count)
{}
EXPORT_SYMBOL();

static ssize_t snd_rawmidi_read(struct file *file, char __user *buf, size_t count,
				loff_t *offset)
{}

/**
 * snd_rawmidi_transmit_empty - check whether the output buffer is empty
 * @substream: the rawmidi substream
 *
 * Return: 1 if the internal output buffer is empty, 0 if not.
 */
int snd_rawmidi_transmit_empty(struct snd_rawmidi_substream *substream)
{}
EXPORT_SYMBOL();

/*
 * __snd_rawmidi_transmit_peek - copy data from the internal buffer
 * @substream: the rawmidi substream
 * @buffer: the buffer pointer
 * @count: data size to transfer
 *
 * This is a variant of snd_rawmidi_transmit_peek() without spinlock.
 */
static int __snd_rawmidi_transmit_peek(struct snd_rawmidi_substream *substream,
				       unsigned char *buffer, int count)
{}

/**
 * snd_rawmidi_transmit_peek - copy data from the internal buffer
 * @substream: the rawmidi substream
 * @buffer: the buffer pointer
 * @count: data size to transfer
 *
 * Copies data from the internal output buffer to the given buffer.
 *
 * Call this in the interrupt handler when the midi output is ready,
 * and call snd_rawmidi_transmit_ack() after the transmission is
 * finished.
 *
 * Return: The size of copied data, or a negative error code on failure.
 */
int snd_rawmidi_transmit_peek(struct snd_rawmidi_substream *substream,
			      unsigned char *buffer, int count)
{}
EXPORT_SYMBOL();

/*
 * __snd_rawmidi_transmit_ack - acknowledge the transmission
 * @substream: the rawmidi substream
 * @count: the transferred count
 *
 * This is a variant of __snd_rawmidi_transmit_ack() without spinlock.
 */
static int __snd_rawmidi_transmit_ack(struct snd_rawmidi_substream *substream,
				      int count)
{}

/**
 * snd_rawmidi_transmit_ack - acknowledge the transmission
 * @substream: the rawmidi substream
 * @count: the transferred count
 *
 * Advances the hardware pointer for the internal output buffer with
 * the given size and updates the condition.
 * Call after the transmission is finished.
 *
 * Return: The advanced size if successful, or a negative error code on failure.
 */
int snd_rawmidi_transmit_ack(struct snd_rawmidi_substream *substream, int count)
{}
EXPORT_SYMBOL();

/**
 * snd_rawmidi_transmit - copy from the buffer to the device
 * @substream: the rawmidi substream
 * @buffer: the buffer pointer
 * @count: the data size to transfer
 *
 * Copies data from the buffer to the device and advances the pointer.
 *
 * Return: The copied size if successful, or a negative error code on failure.
 */
int snd_rawmidi_transmit(struct snd_rawmidi_substream *substream,
			 unsigned char *buffer, int count)
{}
EXPORT_SYMBOL();

/**
 * snd_rawmidi_proceed - Discard the all pending bytes and proceed
 * @substream: rawmidi substream
 *
 * Return: the number of discarded bytes
 */
int snd_rawmidi_proceed(struct snd_rawmidi_substream *substream)
{}
EXPORT_SYMBOL();

static long snd_rawmidi_kernel_write1(struct snd_rawmidi_substream *substream,
				      const unsigned char __user *userbuf,
				      const unsigned char *kernelbuf,
				      long count)
{}

long snd_rawmidi_kernel_write(struct snd_rawmidi_substream *substream,
			      const unsigned char *buf, long count)
{}
EXPORT_SYMBOL();

static ssize_t snd_rawmidi_write(struct file *file, const char __user *buf,
				 size_t count, loff_t *offset)
{}

static __poll_t snd_rawmidi_poll(struct file *file, poll_table *wait)
{}

/*
 */
#ifdef CONFIG_COMPAT
#include "rawmidi_compat.c"
#else
#define snd_rawmidi_ioctl_compat
#endif

/*
 */

static void snd_rawmidi_proc_info_read(struct snd_info_entry *entry,
				       struct snd_info_buffer *buffer)
{}

/*
 *  Register functions
 */

static const struct file_operations snd_rawmidi_f_ops =;

static int snd_rawmidi_alloc_substreams(struct snd_rawmidi *rmidi,
					struct snd_rawmidi_str *stream,
					int direction,
					int count)
{}

/* used for both rawmidi and ump */
int snd_rawmidi_init(struct snd_rawmidi *rmidi,
		     struct snd_card *card, char *id, int device,
		     int output_count, int input_count,
		     unsigned int info_flags)
{}
EXPORT_SYMBOL_GPL();

/**
 * snd_rawmidi_new - create a rawmidi instance
 * @card: the card instance
 * @id: the id string
 * @device: the device index
 * @output_count: the number of output streams
 * @input_count: the number of input streams
 * @rrawmidi: the pointer to store the new rawmidi instance
 *
 * Creates a new rawmidi instance.
 * Use snd_rawmidi_set_ops() to set the operators to the new instance.
 *
 * Return: Zero if successful, or a negative error code on failure.
 */
int snd_rawmidi_new(struct snd_card *card, char *id, int device,
		    int output_count, int input_count,
		    struct snd_rawmidi **rrawmidi)
{}
EXPORT_SYMBOL();

static void snd_rawmidi_free_substreams(struct snd_rawmidi_str *stream)
{}

/* called from ump.c, too */
int snd_rawmidi_free(struct snd_rawmidi *rmidi)
{}
EXPORT_SYMBOL_GPL();

static int snd_rawmidi_dev_free(struct snd_device *device)
{}

#if IS_ENABLED(CONFIG_SND_SEQUENCER)
static void snd_rawmidi_dev_seq_free(struct snd_seq_device *device)
{}
#endif

static int snd_rawmidi_dev_register(struct snd_device *device)
{}

static int snd_rawmidi_dev_disconnect(struct snd_device *device)
{}

/**
 * snd_rawmidi_set_ops - set the rawmidi operators
 * @rmidi: the rawmidi instance
 * @stream: the stream direction, SNDRV_RAWMIDI_STREAM_XXX
 * @ops: the operator table
 *
 * Sets the rawmidi operators for the given stream direction.
 */
void snd_rawmidi_set_ops(struct snd_rawmidi *rmidi, int stream,
			 const struct snd_rawmidi_ops *ops)
{}
EXPORT_SYMBOL();

/*
 *  ENTRY functions
 */

static int __init alsa_rawmidi_init(void)
{}

static void __exit alsa_rawmidi_exit(void)
{}

module_init()
module_exit()