2019-05-27 06:55:05 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* 32bit -> 64bit ioctl wrapper for raw MIDI API
|
|
|
|
* Copyright (c) by Takashi Iwai <tiwai@suse.de>
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* This file included from rawmidi.c */
|
|
|
|
|
|
|
|
#include <linux/compat.h>
|
|
|
|
|
2005-11-17 12:56:51 +00:00
|
|
|
struct snd_rawmidi_params32 {
|
2005-04-16 22:20:36 +00:00
|
|
|
s32 stream;
|
|
|
|
u32 buffer_size;
|
|
|
|
u32 avail_min;
|
|
|
|
unsigned int no_active_sensing; /* avoid bit-field */
|
2021-05-15 07:15:33 +00:00
|
|
|
unsigned int mode;
|
|
|
|
unsigned char reserved[12];
|
2023-10-25 13:23:06 +00:00
|
|
|
} __packed;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2005-11-17 12:56:51 +00:00
|
|
|
static int snd_rawmidi_ioctl_params_compat(struct snd_rawmidi_file *rfile,
|
|
|
|
struct snd_rawmidi_params32 __user *src)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2005-11-17 12:56:51 +00:00
|
|
|
struct snd_rawmidi_params params;
|
2005-04-16 22:20:36 +00:00
|
|
|
unsigned int val;
|
|
|
|
|
|
|
|
if (get_user(params.stream, &src->stream) ||
|
|
|
|
get_user(params.buffer_size, &src->buffer_size) ||
|
|
|
|
get_user(params.avail_min, &src->avail_min) ||
|
2021-05-15 07:15:33 +00:00
|
|
|
get_user(params.mode, &src->mode) ||
|
2005-04-16 22:20:36 +00:00
|
|
|
get_user(val, &src->no_active_sensing))
|
|
|
|
return -EFAULT;
|
|
|
|
params.no_active_sensing = val;
|
|
|
|
switch (params.stream) {
|
|
|
|
case SNDRV_RAWMIDI_STREAM_OUTPUT:
|
2018-04-19 16:16:15 +00:00
|
|
|
if (!rfile->output)
|
|
|
|
return -EINVAL;
|
2005-04-16 22:20:36 +00:00
|
|
|
return snd_rawmidi_output_params(rfile->output, ¶ms);
|
|
|
|
case SNDRV_RAWMIDI_STREAM_INPUT:
|
2018-04-19 16:16:15 +00:00
|
|
|
if (!rfile->input)
|
|
|
|
return -EINVAL;
|
2005-04-16 22:20:36 +00:00
|
|
|
return snd_rawmidi_input_params(rfile->input, ¶ms);
|
|
|
|
}
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2018-04-24 12:06:12 +00:00
|
|
|
struct compat_snd_rawmidi_status64 {
|
2005-04-16 22:20:36 +00:00
|
|
|
s32 stream;
|
2018-04-24 12:06:12 +00:00
|
|
|
u8 rsvd[4]; /* alignment */
|
|
|
|
s64 tstamp_sec;
|
|
|
|
s64 tstamp_nsec;
|
2005-04-16 22:20:36 +00:00
|
|
|
u32 avail;
|
|
|
|
u32 xruns;
|
|
|
|
unsigned char reserved[16];
|
2023-10-25 13:23:06 +00:00
|
|
|
} __packed;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2018-04-24 12:06:12 +00:00
|
|
|
static int snd_rawmidi_ioctl_status_compat64(struct snd_rawmidi_file *rfile,
|
|
|
|
struct compat_snd_rawmidi_status64 __user *src)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
int err;
|
2018-04-24 12:06:12 +00:00
|
|
|
struct snd_rawmidi_status64 status;
|
|
|
|
struct compat_snd_rawmidi_status64 compat_status;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
if (get_user(status.stream, &src->stream))
|
|
|
|
return -EFAULT;
|
|
|
|
|
|
|
|
switch (status.stream) {
|
|
|
|
case SNDRV_RAWMIDI_STREAM_OUTPUT:
|
2018-04-19 16:16:15 +00:00
|
|
|
if (!rfile->output)
|
|
|
|
return -EINVAL;
|
2005-04-16 22:20:36 +00:00
|
|
|
err = snd_rawmidi_output_status(rfile->output, &status);
|
|
|
|
break;
|
|
|
|
case SNDRV_RAWMIDI_STREAM_INPUT:
|
2018-04-19 16:16:15 +00:00
|
|
|
if (!rfile->input)
|
|
|
|
return -EINVAL;
|
2005-04-16 22:20:36 +00:00
|
|
|
err = snd_rawmidi_input_status(rfile->input, &status);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
|
2018-04-24 12:06:12 +00:00
|
|
|
compat_status = (struct compat_snd_rawmidi_status64) {
|
|
|
|
.stream = status.stream,
|
|
|
|
.tstamp_sec = status.tstamp_sec,
|
|
|
|
.tstamp_nsec = status.tstamp_nsec,
|
|
|
|
.avail = status.avail,
|
|
|
|
.xruns = status.xruns,
|
|
|
|
};
|
2016-02-28 10:28:08 +00:00
|
|
|
|
2018-04-24 12:06:12 +00:00
|
|
|
if (copy_to_user(src, &compat_status, sizeof(*src)))
|
2016-02-28 10:28:08 +00:00
|
|
|
return -EFAULT;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
enum {
|
2005-11-17 12:56:51 +00:00
|
|
|
SNDRV_RAWMIDI_IOCTL_PARAMS32 = _IOWR('W', 0x10, struct snd_rawmidi_params32),
|
2018-04-24 12:06:12 +00:00
|
|
|
SNDRV_RAWMIDI_IOCTL_STATUS_COMPAT32 = _IOWR('W', 0x20, struct snd_rawmidi_status32),
|
|
|
|
SNDRV_RAWMIDI_IOCTL_STATUS_COMPAT64 = _IOWR('W', 0x20, struct compat_snd_rawmidi_status64),
|
2005-04-16 22:20:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static long snd_rawmidi_ioctl_compat(struct file *file, unsigned int cmd, unsigned long arg)
|
|
|
|
{
|
2005-11-17 12:56:51 +00:00
|
|
|
struct snd_rawmidi_file *rfile;
|
2005-04-16 22:20:36 +00:00
|
|
|
void __user *argp = compat_ptr(arg);
|
|
|
|
|
|
|
|
rfile = file->private_data;
|
|
|
|
switch (cmd) {
|
|
|
|
case SNDRV_RAWMIDI_IOCTL_PVERSION:
|
|
|
|
case SNDRV_RAWMIDI_IOCTL_INFO:
|
|
|
|
case SNDRV_RAWMIDI_IOCTL_DROP:
|
|
|
|
case SNDRV_RAWMIDI_IOCTL_DRAIN:
|
ALSA: rawmidi: UMP support
This patch adds the support helpers for UMP (Universal MIDI Packet) in
ALSA core.
The basic design is that a rawmidi instance is assigned to each UMP
Endpoint. A UMP Endpoint provides a UMP stream, typically
bidirectional (but can be also uni-directional, too), which may hold
up to 16 UMP Groups, where each UMP (input/output) Group corresponds
to the traditional MIDI I/O Endpoint.
Additionally, the ALSA UMP abstraction provides the multiple UMP
Blocks that can be assigned to each UMP Endpoint. A UMP Block is a
metadata to hold the UMP Group clusters, and can represent the
functions assigned to each UMP Group. A typical implementation of UMP
Block is the Group Terminal Blocks of USB MIDI 2.0 specification.
For distinguishing from the legacy byte-stream MIDI device, a new
device "umpC*D*" will be created, instead of the standard (MIDI 1.0)
devices "midiC*D*". The UMP instance can be identified by the new
rawmidi info bit SNDRV_RAWMIDI_INFO_UMP, too.
A UMP rawmidi device reads/writes only in 4-bytes words alignment,
stored in CPU native endianness.
The transmit and receive functions take care of the input/out data
alignment, and may return zero or aligned size, and the params ioctl
may return -EINVAL when the given input/output buffer size isn't
aligned.
A few new UMP-specific ioctls are added for obtaining the new UMP
endpoint and block information.
As of this commit, no ALSA sequencer instance is attached to UMP
devices yet. They will be supported by later patches.
Along with those changes, the protocol version for rawmidi is bumped
to 2.0.3.
Reviewed-by: Jaroslav Kysela <perex@perex.cz>
Link: https://lore.kernel.org/r/20230523075358.9672-4-tiwai@suse.de
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2023-05-23 07:53:24 +00:00
|
|
|
#if IS_ENABLED(CONFIG_SND_UMP)
|
|
|
|
case SNDRV_UMP_IOCTL_ENDPOINT_INFO:
|
|
|
|
case SNDRV_UMP_IOCTL_BLOCK_INFO:
|
|
|
|
#endif
|
2005-04-16 22:20:36 +00:00
|
|
|
return snd_rawmidi_ioctl(file, cmd, (unsigned long)argp);
|
|
|
|
case SNDRV_RAWMIDI_IOCTL_PARAMS32:
|
|
|
|
return snd_rawmidi_ioctl_params_compat(rfile, argp);
|
2018-04-24 12:06:12 +00:00
|
|
|
case SNDRV_RAWMIDI_IOCTL_STATUS_COMPAT32:
|
|
|
|
return snd_rawmidi_ioctl_status32(rfile, argp);
|
|
|
|
case SNDRV_RAWMIDI_IOCTL_STATUS_COMPAT64:
|
|
|
|
return snd_rawmidi_ioctl_status_compat64(rfile, argp);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
return -ENOIOCTLCMD;
|
|
|
|
}
|