blob: 9b824bfc919db5baef8d1aee976218b903599c83 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Functions for the OPL4 proc file
3 * Copyright (c) 2003 by Clemens Ladisch <clemens@ladisch.de>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19
20#include "opl4_local.h"
21#include <linux/vmalloc.h>
Paul Gortmakerd81a6d72011-09-22 09:34:58 -040022#include <linux/export.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070023#include <sound/info.h>
24
25#ifdef CONFIG_PROC_FS
26
Takashi Iwaia42dd422005-11-17 14:13:47 +010027static int snd_opl4_mem_proc_open(struct snd_info_entry *entry,
Linus Torvalds1da177e2005-04-16 15:20:36 -070028 unsigned short mode, void **file_private_data)
29{
Takashi Iwaia42dd422005-11-17 14:13:47 +010030 struct snd_opl4 *opl4 = entry->private_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -070031
Ingo Molnaref9f0a42006-01-16 16:31:42 +010032 mutex_lock(&opl4->access_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -070033 if (opl4->memory_access) {
Ingo Molnaref9f0a42006-01-16 16:31:42 +010034 mutex_unlock(&opl4->access_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -070035 return -EBUSY;
36 }
37 opl4->memory_access++;
Ingo Molnaref9f0a42006-01-16 16:31:42 +010038 mutex_unlock(&opl4->access_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -070039 return 0;
40}
41
Takashi Iwaia42dd422005-11-17 14:13:47 +010042static int snd_opl4_mem_proc_release(struct snd_info_entry *entry,
Linus Torvalds1da177e2005-04-16 15:20:36 -070043 unsigned short mode, void *file_private_data)
44{
Takashi Iwaia42dd422005-11-17 14:13:47 +010045 struct snd_opl4 *opl4 = entry->private_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -070046
Ingo Molnaref9f0a42006-01-16 16:31:42 +010047 mutex_lock(&opl4->access_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -070048 opl4->memory_access--;
Ingo Molnaref9f0a42006-01-16 16:31:42 +010049 mutex_unlock(&opl4->access_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -070050 return 0;
51}
52
Takashi Iwai24e4a122010-04-13 11:22:01 +020053static ssize_t snd_opl4_mem_proc_read(struct snd_info_entry *entry,
54 void *file_private_data,
55 struct file *file, char __user *_buf,
56 size_t count, loff_t pos)
Linus Torvalds1da177e2005-04-16 15:20:36 -070057{
Takashi Iwaia42dd422005-11-17 14:13:47 +010058 struct snd_opl4 *opl4 = entry->private_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -070059 char* buf;
60
Takashi Iwaid97e1b72010-04-13 11:33:54 +020061 buf = vmalloc(count);
62 if (!buf)
63 return -ENOMEM;
64 snd_opl4_read_memory(opl4, buf, pos, count);
65 if (copy_to_user(_buf, buf, count)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070066 vfree(buf);
Takashi Iwaid97e1b72010-04-13 11:33:54 +020067 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -070068 }
Takashi Iwaid97e1b72010-04-13 11:33:54 +020069 vfree(buf);
70 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -070071}
72
Takashi Iwai24e4a122010-04-13 11:22:01 +020073static ssize_t snd_opl4_mem_proc_write(struct snd_info_entry *entry,
74 void *file_private_data,
75 struct file *file,
76 const char __user *_buf,
Takashi Iwai670ff6a2010-05-10 10:21:32 +020077 size_t count, loff_t pos)
Linus Torvalds1da177e2005-04-16 15:20:36 -070078{
Takashi Iwaia42dd422005-11-17 14:13:47 +010079 struct snd_opl4 *opl4 = entry->private_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -070080 char *buf;
81
Takashi Iwaid97e1b72010-04-13 11:33:54 +020082 buf = vmalloc(count);
83 if (!buf)
84 return -ENOMEM;
85 if (copy_from_user(buf, _buf, count)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 vfree(buf);
Takashi Iwaid97e1b72010-04-13 11:33:54 +020087 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -070088 }
Takashi Iwaid97e1b72010-04-13 11:33:54 +020089 snd_opl4_write_memory(opl4, buf, pos, count);
90 vfree(buf);
91 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -070092}
93
Linus Torvalds1da177e2005-04-16 15:20:36 -070094static struct snd_info_entry_ops snd_opl4_mem_proc_ops = {
95 .open = snd_opl4_mem_proc_open,
96 .release = snd_opl4_mem_proc_release,
97 .read = snd_opl4_mem_proc_read,
98 .write = snd_opl4_mem_proc_write,
Linus Torvalds1da177e2005-04-16 15:20:36 -070099};
100
Takashi Iwaia42dd422005-11-17 14:13:47 +0100101int snd_opl4_create_proc(struct snd_opl4 *opl4)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102{
Takashi Iwaia42dd422005-11-17 14:13:47 +0100103 struct snd_info_entry *entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104
105 entry = snd_info_create_card_entry(opl4->card, "opl4-mem", opl4->card->proc_root);
106 if (entry) {
107 if (opl4->hardware < OPL3_HW_OPL4_ML) {
108 /* OPL4 can access 4 MB external ROM/SRAM */
109 entry->mode |= S_IWUSR;
110 entry->size = 4 * 1024 * 1024;
111 } else {
112 /* OPL4-ML has 1 MB internal ROM */
113 entry->size = 1 * 1024 * 1024;
114 }
115 entry->content = SNDRV_INFO_CONTENT_DATA;
116 entry->c.ops = &snd_opl4_mem_proc_ops;
117 entry->module = THIS_MODULE;
118 entry->private_data = opl4;
119 if (snd_info_register(entry) < 0) {
120 snd_info_free_entry(entry);
121 entry = NULL;
122 }
123 }
124 opl4->proc_entry = entry;
125 return 0;
126}
127
Takashi Iwaia42dd422005-11-17 14:13:47 +0100128void snd_opl4_free_proc(struct snd_opl4 *opl4)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129{
Takashi Iwai746d4a02006-06-23 14:37:59 +0200130 snd_info_free_entry(opl4->proc_entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131}
132
133#endif /* CONFIG_PROC_FS */