1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Functions for the OPL4 proc file
4 * Copyright (c) 2003 by Clemens Ladisch <clemens@ladisch.de>
7 #include "opl4_local.h"
8 #include <linux/vmalloc.h>
9 #include <linux/export.h>
10 #include <sound/info.h>
12 static int snd_opl4_mem_proc_open(struct snd_info_entry
*entry
,
13 unsigned short mode
, void **file_private_data
)
15 struct snd_opl4
*opl4
= entry
->private_data
;
17 mutex_lock(&opl4
->access_mutex
);
18 if (opl4
->memory_access
) {
19 mutex_unlock(&opl4
->access_mutex
);
22 opl4
->memory_access
++;
23 mutex_unlock(&opl4
->access_mutex
);
27 static int snd_opl4_mem_proc_release(struct snd_info_entry
*entry
,
28 unsigned short mode
, void *file_private_data
)
30 struct snd_opl4
*opl4
= entry
->private_data
;
32 mutex_lock(&opl4
->access_mutex
);
33 opl4
->memory_access
--;
34 mutex_unlock(&opl4
->access_mutex
);
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
)
43 struct snd_opl4
*opl4
= entry
->private_data
;
49 snd_opl4_read_memory(opl4
, buf
, pos
, count
);
50 if (copy_to_user(_buf
, buf
, count
)) {
58 static ssize_t
snd_opl4_mem_proc_write(struct snd_info_entry
*entry
,
59 void *file_private_data
,
61 const char __user
*_buf
,
62 size_t count
, loff_t pos
)
64 struct snd_opl4
*opl4
= entry
->private_data
;
70 if (copy_from_user(buf
, _buf
, count
)) {
74 snd_opl4_write_memory(opl4
, buf
, pos
, count
);
79 static const 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
,
86 int snd_opl4_create_proc(struct snd_opl4
*opl4
)
88 struct snd_info_entry
*entry
;
90 entry
= snd_info_create_card_entry(opl4
->card
, "opl4-mem", opl4
->card
->proc_root
);
92 if (opl4
->hardware
< OPL3_HW_OPL4_ML
) {
93 /* OPL4 can access 4 MB external ROM/SRAM */
95 entry
->size
= 4 * 1024 * 1024;
97 /* OPL4-ML has 1 MB internal ROM */
98 entry
->size
= 1 * 1024 * 1024;
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
;
105 opl4
->proc_entry
= entry
;
109 void snd_opl4_free_proc(struct snd_opl4
*opl4
)
111 snd_info_free_entry(opl4
->proc_entry
);