Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
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> | |
22 | #include <sound/info.h> | |
23 | ||
24 | #ifdef CONFIG_PROC_FS | |
25 | ||
a42dd420 | 26 | static int snd_opl4_mem_proc_open(struct snd_info_entry *entry, |
1da177e4 LT |
27 | unsigned short mode, void **file_private_data) |
28 | { | |
a42dd420 | 29 | struct snd_opl4 *opl4 = entry->private_data; |
1da177e4 | 30 | |
ef9f0a42 | 31 | mutex_lock(&opl4->access_mutex); |
1da177e4 | 32 | if (opl4->memory_access) { |
ef9f0a42 | 33 | mutex_unlock(&opl4->access_mutex); |
1da177e4 LT |
34 | return -EBUSY; |
35 | } | |
36 | opl4->memory_access++; | |
ef9f0a42 | 37 | mutex_unlock(&opl4->access_mutex); |
1da177e4 LT |
38 | return 0; |
39 | } | |
40 | ||
a42dd420 | 41 | static int snd_opl4_mem_proc_release(struct snd_info_entry *entry, |
1da177e4 LT |
42 | unsigned short mode, void *file_private_data) |
43 | { | |
a42dd420 | 44 | struct snd_opl4 *opl4 = entry->private_data; |
1da177e4 | 45 | |
ef9f0a42 | 46 | mutex_lock(&opl4->access_mutex); |
1da177e4 | 47 | opl4->memory_access--; |
ef9f0a42 | 48 | mutex_unlock(&opl4->access_mutex); |
1da177e4 LT |
49 | return 0; |
50 | } | |
51 | ||
24e4a121 TI |
52 | static ssize_t snd_opl4_mem_proc_read(struct snd_info_entry *entry, |
53 | void *file_private_data, | |
54 | struct file *file, char __user *_buf, | |
55 | size_t count, loff_t pos) | |
1da177e4 | 56 | { |
a42dd420 | 57 | struct snd_opl4 *opl4 = entry->private_data; |
1da177e4 LT |
58 | long size; |
59 | char* buf; | |
60 | ||
61 | size = count; | |
62 | if (pos + size > entry->size) | |
63 | size = entry->size - pos; | |
64 | if (size > 0) { | |
65 | buf = vmalloc(size); | |
66 | if (!buf) | |
67 | return -ENOMEM; | |
68 | snd_opl4_read_memory(opl4, buf, pos, size); | |
69 | if (copy_to_user(_buf, buf, size)) { | |
70 | vfree(buf); | |
71 | return -EFAULT; | |
72 | } | |
73 | vfree(buf); | |
74 | return size; | |
75 | } | |
76 | return 0; | |
77 | } | |
78 | ||
24e4a121 TI |
79 | static ssize_t snd_opl4_mem_proc_write(struct snd_info_entry *entry, |
80 | void *file_private_data, | |
81 | struct file *file, | |
82 | const char __user *_buf, | |
83 | size_t count, size_t pos) | |
1da177e4 | 84 | { |
a42dd420 | 85 | struct snd_opl4 *opl4 = entry->private_data; |
1da177e4 LT |
86 | long size; |
87 | char *buf; | |
88 | ||
89 | size = count; | |
90 | if (pos + size > entry->size) | |
91 | size = entry->size - pos; | |
92 | if (size > 0) { | |
93 | buf = vmalloc(size); | |
94 | if (!buf) | |
95 | return -ENOMEM; | |
96 | if (copy_from_user(buf, _buf, size)) { | |
97 | vfree(buf); | |
98 | return -EFAULT; | |
99 | } | |
100 | snd_opl4_write_memory(opl4, buf, pos, size); | |
101 | vfree(buf); | |
102 | return size; | |
103 | } | |
104 | return 0; | |
105 | } | |
106 | ||
24e4a121 TI |
107 | static loff_t snd_opl4_mem_proc_llseek(struct snd_info_entry *entry, |
108 | void *file_private_data, | |
109 | struct file *file, | |
110 | loff_t offset, int orig) | |
1da177e4 LT |
111 | { |
112 | switch (orig) { | |
dd47a338 | 113 | case SEEK_SET: |
1da177e4 LT |
114 | file->f_pos = offset; |
115 | break; | |
dd47a338 | 116 | case SEEK_CUR: |
1da177e4 LT |
117 | file->f_pos += offset; |
118 | break; | |
dd47a338 | 119 | case SEEK_END: /* offset is negative */ |
1da177e4 LT |
120 | file->f_pos = entry->size + offset; |
121 | break; | |
122 | default: | |
123 | return -EINVAL; | |
124 | } | |
125 | if (file->f_pos > entry->size) | |
126 | file->f_pos = entry->size; | |
127 | return file->f_pos; | |
128 | } | |
129 | ||
130 | static struct snd_info_entry_ops snd_opl4_mem_proc_ops = { | |
131 | .open = snd_opl4_mem_proc_open, | |
132 | .release = snd_opl4_mem_proc_release, | |
133 | .read = snd_opl4_mem_proc_read, | |
134 | .write = snd_opl4_mem_proc_write, | |
135 | .llseek = snd_opl4_mem_proc_llseek, | |
136 | }; | |
137 | ||
a42dd420 | 138 | int snd_opl4_create_proc(struct snd_opl4 *opl4) |
1da177e4 | 139 | { |
a42dd420 | 140 | struct snd_info_entry *entry; |
1da177e4 LT |
141 | |
142 | entry = snd_info_create_card_entry(opl4->card, "opl4-mem", opl4->card->proc_root); | |
143 | if (entry) { | |
144 | if (opl4->hardware < OPL3_HW_OPL4_ML) { | |
145 | /* OPL4 can access 4 MB external ROM/SRAM */ | |
146 | entry->mode |= S_IWUSR; | |
147 | entry->size = 4 * 1024 * 1024; | |
148 | } else { | |
149 | /* OPL4-ML has 1 MB internal ROM */ | |
150 | entry->size = 1 * 1024 * 1024; | |
151 | } | |
152 | entry->content = SNDRV_INFO_CONTENT_DATA; | |
153 | entry->c.ops = &snd_opl4_mem_proc_ops; | |
154 | entry->module = THIS_MODULE; | |
155 | entry->private_data = opl4; | |
156 | if (snd_info_register(entry) < 0) { | |
157 | snd_info_free_entry(entry); | |
158 | entry = NULL; | |
159 | } | |
160 | } | |
161 | opl4->proc_entry = entry; | |
162 | return 0; | |
163 | } | |
164 | ||
a42dd420 | 165 | void snd_opl4_free_proc(struct snd_opl4 *opl4) |
1da177e4 | 166 | { |
746d4a02 | 167 | snd_info_free_entry(opl4->proc_entry); |
1da177e4 LT |
168 | } |
169 | ||
170 | #endif /* CONFIG_PROC_FS */ |