2019-05-27 14:55:05 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* Interface for hwdep device
|
|
|
|
*
|
|
|
|
* Copyright (C) 2004 Takashi Iwai <tiwai@suse.de>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sound/core.h>
|
|
|
|
#include <sound/hwdep.h>
|
2015-01-29 00:24:43 +08:00
|
|
|
#include <linux/uaccess.h>
|
2018-12-13 01:20:49 +08:00
|
|
|
#include <linux/nospec.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include "emux_voice.h"
|
|
|
|
|
|
|
|
#define TMP_CLIENT_ID 0x1001
|
|
|
|
|
|
|
|
/*
|
|
|
|
* load patch
|
|
|
|
*/
|
|
|
|
static int
|
2005-11-17 21:24:47 +08:00
|
|
|
snd_emux_hwdep_load_patch(struct snd_emux *emu, void __user *arg)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
int err;
|
2005-11-17 21:24:47 +08:00
|
|
|
struct soundfont_patch_info patch;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (copy_from_user(&patch, arg, sizeof(patch)))
|
|
|
|
return -EFAULT;
|
|
|
|
|
2019-03-27 00:32:02 +08:00
|
|
|
if (patch.key == GUS_PATCH)
|
|
|
|
return snd_soundfont_load_guspatch(emu->sflist, arg,
|
|
|
|
patch.len + sizeof(patch),
|
|
|
|
TMP_CLIENT_ID);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if (patch.type >= SNDRV_SFNT_LOAD_INFO &&
|
|
|
|
patch.type <= SNDRV_SFNT_PROBE_DATA) {
|
|
|
|
err = snd_soundfont_load(emu->sflist, arg, patch.len + sizeof(patch), TMP_CLIENT_ID);
|
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
} else {
|
|
|
|
if (emu->ops.load_fx)
|
|
|
|
return emu->ops.load_fx(emu, patch.type, patch.optarg, arg, patch.len + sizeof(patch));
|
|
|
|
else
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* set misc mode
|
|
|
|
*/
|
|
|
|
static int
|
2005-11-17 21:24:47 +08:00
|
|
|
snd_emux_hwdep_misc_mode(struct snd_emux *emu, void __user *arg)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2005-11-17 21:24:47 +08:00
|
|
|
struct snd_emux_misc_mode info;
|
2005-04-17 06:20:36 +08:00
|
|
|
int i;
|
|
|
|
|
|
|
|
if (copy_from_user(&info, arg, sizeof(info)))
|
|
|
|
return -EFAULT;
|
|
|
|
if (info.mode < 0 || info.mode >= EMUX_MD_END)
|
|
|
|
return -EINVAL;
|
2018-12-13 01:20:49 +08:00
|
|
|
info.mode = array_index_nospec(info.mode, EMUX_MD_END);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (info.port < 0) {
|
|
|
|
for (i = 0; i < emu->num_ports; i++)
|
|
|
|
emu->portptrs[i]->ctrls[info.mode] = info.value;
|
|
|
|
} else {
|
2018-12-13 01:20:49 +08:00
|
|
|
if (info.port < emu->num_ports) {
|
|
|
|
info.port = array_index_nospec(info.port, emu->num_ports);
|
2005-04-17 06:20:36 +08:00
|
|
|
emu->portptrs[info.port]->ctrls[info.mode] = info.value;
|
2018-12-13 01:20:49 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ioctl
|
|
|
|
*/
|
|
|
|
static int
|
2005-11-17 21:24:47 +08:00
|
|
|
snd_emux_hwdep_ioctl(struct snd_hwdep * hw, struct file *file,
|
|
|
|
unsigned int cmd, unsigned long arg)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2005-11-17 21:24:47 +08:00
|
|
|
struct snd_emux *emu = hw->private_data;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case SNDRV_EMUX_IOCTL_VERSION:
|
|
|
|
return put_user(SNDRV_EMUX_VERSION, (unsigned int __user *)arg);
|
|
|
|
case SNDRV_EMUX_IOCTL_LOAD_PATCH:
|
|
|
|
return snd_emux_hwdep_load_patch(emu, (void __user *)arg);
|
|
|
|
case SNDRV_EMUX_IOCTL_RESET_SAMPLES:
|
|
|
|
snd_soundfont_remove_samples(emu->sflist);
|
|
|
|
break;
|
|
|
|
case SNDRV_EMUX_IOCTL_REMOVE_LAST_SAMPLES:
|
|
|
|
snd_soundfont_remove_unlocked(emu->sflist);
|
|
|
|
break;
|
|
|
|
case SNDRV_EMUX_IOCTL_MEM_AVAIL:
|
|
|
|
if (emu->memhdr) {
|
|
|
|
int size = snd_util_mem_avail(emu->memhdr);
|
|
|
|
return put_user(size, (unsigned int __user *)arg);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SNDRV_EMUX_IOCTL_MISC_MODE:
|
|
|
|
return snd_emux_hwdep_misc_mode(emu, (void __user *)arg);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* register hwdep device
|
|
|
|
*/
|
|
|
|
|
|
|
|
int
|
2005-11-17 21:24:47 +08:00
|
|
|
snd_emux_init_hwdep(struct snd_emux *emu)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2005-11-17 21:24:47 +08:00
|
|
|
struct snd_hwdep *hw;
|
2005-04-17 06:20:36 +08:00
|
|
|
int err;
|
|
|
|
|
2021-06-08 22:05:37 +08:00
|
|
|
err = snd_hwdep_new(emu->card, SNDRV_EMUX_HWDEP_NAME, emu->hwdep_idx, &hw);
|
|
|
|
if (err < 0)
|
2005-04-17 06:20:36 +08:00
|
|
|
return err;
|
|
|
|
emu->hwdep = hw;
|
|
|
|
strcpy(hw->name, SNDRV_EMUX_HWDEP_NAME);
|
|
|
|
hw->iface = SNDRV_HWDEP_IFACE_EMUX_WAVETABLE;
|
|
|
|
hw->ops.ioctl = snd_emux_hwdep_ioctl;
|
2010-09-12 09:41:47 +08:00
|
|
|
/* The ioctl parameter types are compatible between 32- and
|
|
|
|
* 64-bit architectures, so use the same function. */
|
|
|
|
hw->ops.ioctl_compat = snd_emux_hwdep_ioctl;
|
2005-04-17 06:20:36 +08:00
|
|
|
hw->exclusive = 1;
|
|
|
|
hw->private_data = emu;
|
2021-06-08 22:05:37 +08:00
|
|
|
err = snd_card_register(emu->card);
|
|
|
|
if (err < 0)
|
2005-04-17 06:20:36 +08:00
|
|
|
return err;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* unregister
|
|
|
|
*/
|
|
|
|
void
|
2005-11-17 21:24:47 +08:00
|
|
|
snd_emux_delete_hwdep(struct snd_emux *emu)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
if (emu->hwdep) {
|
|
|
|
snd_device_free(emu->card, emu->hwdep);
|
|
|
|
emu->hwdep = NULL;
|
|
|
|
}
|
|
|
|
}
|