blob: 80f0a83818b2714f258c94f66d6dbe21fced0c4a [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Copyright (c) by Jaroslav Kysela <perex@suse.cz>
3 * GUS's memory access via proc filesystem
4 *
5 *
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.
10 *
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.
15 *
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
19 *
20 */
21
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>
27
Takashi Iwai5e2da202005-11-17 14:36:44 +010028struct gus_proc_private {
Linus Torvalds1da177e2005-04-16 15:20:36 -070029 int rom; /* data are in ROM */
30 unsigned int address;
31 unsigned int size;
Takashi Iwai5e2da202005-11-17 14:36:44 +010032 struct snd_gus_card * gus;
33};
Linus Torvalds1da177e2005-04-16 15:20:36 -070034
Takashi Iwai5e2da202005-11-17 14:36:44 +010035static long snd_gf1_mem_proc_dump(struct snd_info_entry *entry, void *file_private_data,
Linus Torvalds1da177e2005-04-16 15:20:36 -070036 struct file *file, char __user *buf,
37 unsigned long count, unsigned long pos)
38{
39 long size;
Takashi Iwai5e2da202005-11-17 14:36:44 +010040 struct gus_proc_private *priv = entry->private_data;
41 struct snd_gus_card *gus = priv->gus;
Linus Torvalds1da177e2005-04-16 15:20:36 -070042 int err;
43
44 size = count;
45 if (pos + size > priv->size)
46 size = (long)priv->size - pos;
47 if (size > 0) {
48 if ((err = snd_gus_dram_read(gus, buf, pos, size, priv->rom)) < 0)
49 return err;
50 return size;
51 }
52 return 0;
53}
54
Takashi Iwai5e2da202005-11-17 14:36:44 +010055static long long snd_gf1_mem_proc_llseek(struct snd_info_entry *entry,
Linus Torvalds1da177e2005-04-16 15:20:36 -070056 void *private_file_data,
57 struct file *file,
58 long long offset,
59 int orig)
60{
Takashi Iwai5e2da202005-11-17 14:36:44 +010061 struct gus_proc_private *priv = entry->private_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -070062
63 switch (orig) {
Josef 'Jeff' Sipekd158da82006-09-21 11:33:14 +020064 case SEEK_SET:
Linus Torvalds1da177e2005-04-16 15:20:36 -070065 file->f_pos = offset;
66 break;
Josef 'Jeff' Sipekd158da82006-09-21 11:33:14 +020067 case SEEK_CUR:
Linus Torvalds1da177e2005-04-16 15:20:36 -070068 file->f_pos += offset;
69 break;
Josef 'Jeff' Sipekd158da82006-09-21 11:33:14 +020070 case SEEK_END: /* offset is negative */
Linus Torvalds1da177e2005-04-16 15:20:36 -070071 file->f_pos = priv->size + offset;
72 break;
73 default:
74 return -EINVAL;
75 }
76 if (file->f_pos > priv->size)
77 file->f_pos = priv->size;
78 return file->f_pos;
79}
80
Takashi Iwai5e2da202005-11-17 14:36:44 +010081static void snd_gf1_mem_proc_free(struct snd_info_entry *entry)
Linus Torvalds1da177e2005-04-16 15:20:36 -070082{
Takashi Iwai5e2da202005-11-17 14:36:44 +010083 struct gus_proc_private *priv = entry->private_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -070084 kfree(priv);
85}
86
87static struct snd_info_entry_ops snd_gf1_mem_proc_ops = {
88 .read = snd_gf1_mem_proc_dump,
89 .llseek = snd_gf1_mem_proc_llseek,
90};
91
Takashi Iwai5e2da202005-11-17 14:36:44 +010092int snd_gf1_mem_proc_init(struct snd_gus_card * gus)
Linus Torvalds1da177e2005-04-16 15:20:36 -070093{
94 int idx;
95 char name[16];
Takashi Iwai5e2da202005-11-17 14:36:44 +010096 struct gus_proc_private *priv;
97 struct snd_info_entry *entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -070098
99 for (idx = 0; idx < 4; idx++) {
100 if (gus->gf1.mem_alloc.banks_8[idx].size > 0) {
Takashi Iwai9e76a762005-09-09 14:21:17 +0200101 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102 if (priv == NULL)
103 return -ENOMEM;
104 priv->gus = gus;
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;
113 }
114 }
115 }
116 for (idx = 0; idx < 4; idx++) {
117 if (gus->gf1.rom_present & (1 << idx)) {
Takashi Iwai9e76a762005-09-09 14:21:17 +0200118 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119 if (priv == NULL)
120 return -ENOMEM;
121 priv->rom = 1;
122 priv->gus = gus;
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;
131 }
132 }
133 }
134 return 0;
135}