| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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> | 
| Paul Gortmaker | d81a6d7 | 2011-09-22 09:34:58 -0400 | [diff] [blame] | 22 | #include <linux/export.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | #include <sound/info.h> | 
|  | 24 |  | 
|  | 25 | #ifdef CONFIG_PROC_FS | 
|  | 26 |  | 
| Takashi Iwai | a42dd42 | 2005-11-17 14:13:47 +0100 | [diff] [blame] | 27 | static int snd_opl4_mem_proc_open(struct snd_info_entry *entry, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | unsigned short mode, void **file_private_data) | 
|  | 29 | { | 
| Takashi Iwai | a42dd42 | 2005-11-17 14:13:47 +0100 | [diff] [blame] | 30 | struct snd_opl4 *opl4 = entry->private_data; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 |  | 
| Ingo Molnar | ef9f0a4 | 2006-01-16 16:31:42 +0100 | [diff] [blame] | 32 | mutex_lock(&opl4->access_mutex); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | if (opl4->memory_access) { | 
| Ingo Molnar | ef9f0a4 | 2006-01-16 16:31:42 +0100 | [diff] [blame] | 34 | mutex_unlock(&opl4->access_mutex); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | return -EBUSY; | 
|  | 36 | } | 
|  | 37 | opl4->memory_access++; | 
| Ingo Molnar | ef9f0a4 | 2006-01-16 16:31:42 +0100 | [diff] [blame] | 38 | mutex_unlock(&opl4->access_mutex); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | return 0; | 
|  | 40 | } | 
|  | 41 |  | 
| Takashi Iwai | a42dd42 | 2005-11-17 14:13:47 +0100 | [diff] [blame] | 42 | static int snd_opl4_mem_proc_release(struct snd_info_entry *entry, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | unsigned short mode, void *file_private_data) | 
|  | 44 | { | 
| Takashi Iwai | a42dd42 | 2005-11-17 14:13:47 +0100 | [diff] [blame] | 45 | struct snd_opl4 *opl4 = entry->private_data; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 |  | 
| Ingo Molnar | ef9f0a4 | 2006-01-16 16:31:42 +0100 | [diff] [blame] | 47 | mutex_lock(&opl4->access_mutex); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | opl4->memory_access--; | 
| Ingo Molnar | ef9f0a4 | 2006-01-16 16:31:42 +0100 | [diff] [blame] | 49 | mutex_unlock(&opl4->access_mutex); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | return 0; | 
|  | 51 | } | 
|  | 52 |  | 
| Takashi Iwai | 24e4a12 | 2010-04-13 11:22:01 +0200 | [diff] [blame] | 53 | static 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | { | 
| Takashi Iwai | a42dd42 | 2005-11-17 14:13:47 +0100 | [diff] [blame] | 58 | struct snd_opl4 *opl4 = entry->private_data; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | char* buf; | 
|  | 60 |  | 
| Takashi Iwai | d97e1b7 | 2010-04-13 11:33:54 +0200 | [diff] [blame] | 61 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | vfree(buf); | 
| Takashi Iwai | d97e1b7 | 2010-04-13 11:33:54 +0200 | [diff] [blame] | 67 | return -EFAULT; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | } | 
| Takashi Iwai | d97e1b7 | 2010-04-13 11:33:54 +0200 | [diff] [blame] | 69 | vfree(buf); | 
|  | 70 | return count; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | } | 
|  | 72 |  | 
| Takashi Iwai | 24e4a12 | 2010-04-13 11:22:01 +0200 | [diff] [blame] | 73 | static 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 Iwai | 670ff6a | 2010-05-10 10:21:32 +0200 | [diff] [blame] | 77 | size_t count, loff_t pos) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | { | 
| Takashi Iwai | a42dd42 | 2005-11-17 14:13:47 +0100 | [diff] [blame] | 79 | struct snd_opl4 *opl4 = entry->private_data; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | char *buf; | 
|  | 81 |  | 
| Takashi Iwai | d97e1b7 | 2010-04-13 11:33:54 +0200 | [diff] [blame] | 82 | buf = vmalloc(count); | 
|  | 83 | if (!buf) | 
|  | 84 | return -ENOMEM; | 
|  | 85 | if (copy_from_user(buf, _buf, count)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | vfree(buf); | 
| Takashi Iwai | d97e1b7 | 2010-04-13 11:33:54 +0200 | [diff] [blame] | 87 | return -EFAULT; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | } | 
| Takashi Iwai | d97e1b7 | 2010-04-13 11:33:54 +0200 | [diff] [blame] | 89 | snd_opl4_write_memory(opl4, buf, pos, count); | 
|  | 90 | vfree(buf); | 
|  | 91 | return count; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | } | 
|  | 93 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | static 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | }; | 
|  | 100 |  | 
| Takashi Iwai | a42dd42 | 2005-11-17 14:13:47 +0100 | [diff] [blame] | 101 | int snd_opl4_create_proc(struct snd_opl4 *opl4) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | { | 
| Takashi Iwai | a42dd42 | 2005-11-17 14:13:47 +0100 | [diff] [blame] | 103 | struct snd_info_entry *entry; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 |  | 
|  | 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 Iwai | a42dd42 | 2005-11-17 14:13:47 +0100 | [diff] [blame] | 128 | void snd_opl4_free_proc(struct snd_opl4 *opl4) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | { | 
| Takashi Iwai | 746d4a0 | 2006-06-23 14:37:59 +0200 | [diff] [blame] | 130 | snd_info_free_entry(opl4->proc_entry); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | } | 
|  | 132 |  | 
|  | 133 | #endif /* CONFIG_PROC_FS */ |