^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Functions for the OPL4 proc file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Copyright (c) 2003 by Clemens Ladisch <clemens@ladisch.de>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #include "opl4_local.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/vmalloc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/export.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <sound/info.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) static int snd_opl4_mem_proc_open(struct snd_info_entry *entry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) unsigned short mode, void **file_private_data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) struct snd_opl4 *opl4 = entry->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) mutex_lock(&opl4->access_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) if (opl4->memory_access) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) mutex_unlock(&opl4->access_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) opl4->memory_access++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) mutex_unlock(&opl4->access_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) static int snd_opl4_mem_proc_release(struct snd_info_entry *entry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) unsigned short mode, void *file_private_data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) struct snd_opl4 *opl4 = entry->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) mutex_lock(&opl4->access_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) opl4->memory_access--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) mutex_unlock(&opl4->access_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) static ssize_t snd_opl4_mem_proc_read(struct snd_info_entry *entry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) void *file_private_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) struct file *file, char __user *_buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) size_t count, loff_t pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) struct snd_opl4 *opl4 = entry->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) char* buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) buf = vmalloc(count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) if (!buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) snd_opl4_read_memory(opl4, buf, pos, count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) if (copy_to_user(_buf, buf, count)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) vfree(buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) vfree(buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) static ssize_t snd_opl4_mem_proc_write(struct snd_info_entry *entry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) void *file_private_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) struct file *file,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) const char __user *_buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) size_t count, loff_t pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) struct snd_opl4 *opl4 = entry->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) char *buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) buf = vmalloc(count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) if (!buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) if (copy_from_user(buf, _buf, count)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) vfree(buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) snd_opl4_write_memory(opl4, buf, pos, count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) vfree(buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) static const struct snd_info_entry_ops snd_opl4_mem_proc_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) .open = snd_opl4_mem_proc_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) .release = snd_opl4_mem_proc_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) .read = snd_opl4_mem_proc_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) .write = snd_opl4_mem_proc_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) int snd_opl4_create_proc(struct snd_opl4 *opl4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) struct snd_info_entry *entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) entry = snd_info_create_card_entry(opl4->card, "opl4-mem", opl4->card->proc_root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) if (entry) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) if (opl4->hardware < OPL3_HW_OPL4_ML) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) /* OPL4 can access 4 MB external ROM/SRAM */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) entry->mode |= 0200;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) entry->size = 4 * 1024 * 1024;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) /* OPL4-ML has 1 MB internal ROM */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) entry->size = 1 * 1024 * 1024;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) entry->content = SNDRV_INFO_CONTENT_DATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) entry->c.ops = &snd_opl4_mem_proc_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) entry->module = THIS_MODULE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) entry->private_data = opl4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) opl4->proc_entry = entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) void snd_opl4_free_proc(struct snd_opl4 *opl4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) snd_info_free_entry(opl4->proc_entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) }