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