2019-05-27 14:55:05 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* Functions for the OPL4 proc file
|
|
|
|
* Copyright (c) 2003 by Clemens Ladisch <clemens@ladisch.de>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "opl4_local.h"
|
|
|
|
#include <linux/vmalloc.h>
|
2011-09-22 21:34:58 +08:00
|
|
|
#include <linux/export.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <sound/info.h>
|
|
|
|
|
2005-11-17 21:13:47 +08:00
|
|
|
static int snd_opl4_mem_proc_open(struct snd_info_entry *entry,
|
2005-04-17 06:20:36 +08:00
|
|
|
unsigned short mode, void **file_private_data)
|
|
|
|
{
|
2005-11-17 21:13:47 +08:00
|
|
|
struct snd_opl4 *opl4 = entry->private_data;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-01-16 23:31:42 +08:00
|
|
|
mutex_lock(&opl4->access_mutex);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (opl4->memory_access) {
|
2006-01-16 23:31:42 +08:00
|
|
|
mutex_unlock(&opl4->access_mutex);
|
2005-04-17 06:20:36 +08:00
|
|
|
return -EBUSY;
|
|
|
|
}
|
|
|
|
opl4->memory_access++;
|
2006-01-16 23:31:42 +08:00
|
|
|
mutex_unlock(&opl4->access_mutex);
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-11-17 21:13:47 +08:00
|
|
|
static int snd_opl4_mem_proc_release(struct snd_info_entry *entry,
|
2005-04-17 06:20:36 +08:00
|
|
|
unsigned short mode, void *file_private_data)
|
|
|
|
{
|
2005-11-17 21:13:47 +08:00
|
|
|
struct snd_opl4 *opl4 = entry->private_data;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-01-16 23:31:42 +08:00
|
|
|
mutex_lock(&opl4->access_mutex);
|
2005-04-17 06:20:36 +08:00
|
|
|
opl4->memory_access--;
|
2006-01-16 23:31:42 +08:00
|
|
|
mutex_unlock(&opl4->access_mutex);
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-04-13 17:22:01 +08:00
|
|
|
static ssize_t snd_opl4_mem_proc_read(struct snd_info_entry *entry,
|
|
|
|
void *file_private_data,
|
|
|
|
struct file *file, char __user *_buf,
|
|
|
|
size_t count, loff_t pos)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2005-11-17 21:13:47 +08:00
|
|
|
struct snd_opl4 *opl4 = entry->private_data;
|
2005-04-17 06:20:36 +08:00
|
|
|
char* buf;
|
|
|
|
|
2010-04-13 17:33:54 +08:00
|
|
|
buf = vmalloc(count);
|
|
|
|
if (!buf)
|
|
|
|
return -ENOMEM;
|
|
|
|
snd_opl4_read_memory(opl4, buf, pos, count);
|
|
|
|
if (copy_to_user(_buf, buf, count)) {
|
2005-04-17 06:20:36 +08:00
|
|
|
vfree(buf);
|
2010-04-13 17:33:54 +08:00
|
|
|
return -EFAULT;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2010-04-13 17:33:54 +08:00
|
|
|
vfree(buf);
|
|
|
|
return count;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2010-04-13 17:22:01 +08:00
|
|
|
static ssize_t snd_opl4_mem_proc_write(struct snd_info_entry *entry,
|
|
|
|
void *file_private_data,
|
|
|
|
struct file *file,
|
|
|
|
const char __user *_buf,
|
2010-05-10 16:21:32 +08:00
|
|
|
size_t count, loff_t pos)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2005-11-17 21:13:47 +08:00
|
|
|
struct snd_opl4 *opl4 = entry->private_data;
|
2005-04-17 06:20:36 +08:00
|
|
|
char *buf;
|
|
|
|
|
2010-04-13 17:33:54 +08:00
|
|
|
buf = vmalloc(count);
|
|
|
|
if (!buf)
|
|
|
|
return -ENOMEM;
|
|
|
|
if (copy_from_user(buf, _buf, count)) {
|
2005-04-17 06:20:36 +08:00
|
|
|
vfree(buf);
|
2010-04-13 17:33:54 +08:00
|
|
|
return -EFAULT;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2010-04-13 17:33:54 +08:00
|
|
|
snd_opl4_write_memory(opl4, buf, pos, count);
|
|
|
|
vfree(buf);
|
|
|
|
return count;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2020-01-03 16:16:44 +08:00
|
|
|
static const struct snd_info_entry_ops snd_opl4_mem_proc_ops = {
|
2005-04-17 06:20:36 +08:00
|
|
|
.open = snd_opl4_mem_proc_open,
|
|
|
|
.release = snd_opl4_mem_proc_release,
|
|
|
|
.read = snd_opl4_mem_proc_read,
|
|
|
|
.write = snd_opl4_mem_proc_write,
|
|
|
|
};
|
|
|
|
|
2005-11-17 21:13:47 +08:00
|
|
|
int snd_opl4_create_proc(struct snd_opl4 *opl4)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2005-11-17 21:13:47 +08:00
|
|
|
struct snd_info_entry *entry;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
entry = snd_info_create_card_entry(opl4->card, "opl4-mem", opl4->card->proc_root);
|
|
|
|
if (entry) {
|
|
|
|
if (opl4->hardware < OPL3_HW_OPL4_ML) {
|
|
|
|
/* OPL4 can access 4 MB external ROM/SRAM */
|
2018-05-24 03:20:59 +08:00
|
|
|
entry->mode |= 0200;
|
2005-04-17 06:20:36 +08:00
|
|
|
entry->size = 4 * 1024 * 1024;
|
|
|
|
} else {
|
|
|
|
/* OPL4-ML has 1 MB internal ROM */
|
|
|
|
entry->size = 1 * 1024 * 1024;
|
|
|
|
}
|
|
|
|
entry->content = SNDRV_INFO_CONTENT_DATA;
|
|
|
|
entry->c.ops = &snd_opl4_mem_proc_ops;
|
|
|
|
entry->module = THIS_MODULE;
|
|
|
|
entry->private_data = opl4;
|
|
|
|
}
|
|
|
|
opl4->proc_entry = entry;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-11-17 21:13:47 +08:00
|
|
|
void snd_opl4_free_proc(struct snd_opl4 *opl4)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2006-06-23 20:37:59 +08:00
|
|
|
snd_info_free_entry(opl4->proc_entry);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|