2 * Copyright (c) by Jaroslav Kysela <perex@suse.cz>
3 * GUS's memory access via proc filesystem
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include <sound/driver.h>
23 #include <linux/slab.h>
24 #include <sound/core.h>
25 #include <sound/gus.h>
26 #include <sound/info.h>
28 typedef struct gus_proc_private
{
29 int rom
; /* data are in ROM */
35 static long snd_gf1_mem_proc_dump(snd_info_entry_t
*entry
, void *file_private_data
,
36 struct file
*file
, char __user
*buf
,
37 unsigned long count
, unsigned long pos
)
40 gus_proc_private_t
*priv
= entry
->private_data
;
41 snd_gus_card_t
*gus
= priv
->gus
;
45 if (pos
+ size
> priv
->size
)
46 size
= (long)priv
->size
- pos
;
48 if ((err
= snd_gus_dram_read(gus
, buf
, pos
, size
, priv
->rom
)) < 0)
55 static long long snd_gf1_mem_proc_llseek(snd_info_entry_t
*entry
,
56 void *private_file_data
,
61 gus_proc_private_t
*priv
= entry
->private_data
;
64 case 0: /* SEEK_SET */
67 case 1: /* SEEK_CUR */
68 file
->f_pos
+= offset
;
70 case 2: /* SEEK_END, offset is negative */
71 file
->f_pos
= priv
->size
+ offset
;
76 if (file
->f_pos
> priv
->size
)
77 file
->f_pos
= priv
->size
;
81 static void snd_gf1_mem_proc_free(snd_info_entry_t
*entry
)
83 gus_proc_private_t
*priv
= entry
->private_data
;
87 static struct snd_info_entry_ops snd_gf1_mem_proc_ops
= {
88 .read
= snd_gf1_mem_proc_dump
,
89 .llseek
= snd_gf1_mem_proc_llseek
,
92 int snd_gf1_mem_proc_init(snd_gus_card_t
* gus
)
96 gus_proc_private_t
*priv
;
97 snd_info_entry_t
*entry
;
99 for (idx
= 0; idx
< 4; idx
++) {
100 if (gus
->gf1
.mem_alloc
.banks_8
[idx
].size
> 0) {
101 priv
= kcalloc(1, sizeof(*priv
), GFP_KERNEL
);
105 sprintf(name
, "gus-ram-%i", idx
);
106 if (! snd_card_proc_new(gus
->card
, name
, &entry
)) {
107 entry
->content
= SNDRV_INFO_CONTENT_DATA
;
108 entry
->private_data
= priv
;
109 entry
->private_free
= snd_gf1_mem_proc_free
;
110 entry
->c
.ops
= &snd_gf1_mem_proc_ops
;
111 priv
->address
= gus
->gf1
.mem_alloc
.banks_8
[idx
].address
;
112 priv
->size
= entry
->size
= gus
->gf1
.mem_alloc
.banks_8
[idx
].size
;
116 for (idx
= 0; idx
< 4; idx
++) {
117 if (gus
->gf1
.rom_present
& (1 << idx
)) {
118 priv
= kcalloc(1, sizeof(*priv
), GFP_KERNEL
);
123 sprintf(name
, "gus-rom-%i", idx
);
124 if (! snd_card_proc_new(gus
->card
, name
, &entry
)) {
125 entry
->content
= SNDRV_INFO_CONTENT_DATA
;
126 entry
->private_data
= priv
;
127 entry
->private_free
= snd_gf1_mem_proc_free
;
128 entry
->c
.ops
= &snd_gf1_mem_proc_ops
;
129 priv
->address
= idx
* 4096 * 1024;
130 priv
->size
= entry
->size
= gus
->gf1
.rom_memory
;