Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 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 Iwai | 5e2da20 | 2005-11-17 14:36:44 +0100 | [diff] [blame^] | 28 | struct gus_proc_private { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | int rom; /* data are in ROM */ |
| 30 | unsigned int address; |
| 31 | unsigned int size; |
Takashi Iwai | 5e2da20 | 2005-11-17 14:36:44 +0100 | [diff] [blame^] | 32 | struct snd_gus_card * gus; |
| 33 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | |
Takashi Iwai | 5e2da20 | 2005-11-17 14:36:44 +0100 | [diff] [blame^] | 35 | static long snd_gf1_mem_proc_dump(struct snd_info_entry *entry, void *file_private_data, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | struct file *file, char __user *buf, |
| 37 | unsigned long count, unsigned long pos) |
| 38 | { |
| 39 | long size; |
Takashi Iwai | 5e2da20 | 2005-11-17 14:36:44 +0100 | [diff] [blame^] | 40 | struct gus_proc_private *priv = entry->private_data; |
| 41 | struct snd_gus_card *gus = priv->gus; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | 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 Iwai | 5e2da20 | 2005-11-17 14:36:44 +0100 | [diff] [blame^] | 55 | static long long snd_gf1_mem_proc_llseek(struct snd_info_entry *entry, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | void *private_file_data, |
| 57 | struct file *file, |
| 58 | long long offset, |
| 59 | int orig) |
| 60 | { |
Takashi Iwai | 5e2da20 | 2005-11-17 14:36:44 +0100 | [diff] [blame^] | 61 | struct gus_proc_private *priv = entry->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | |
| 63 | switch (orig) { |
| 64 | case 0: /* SEEK_SET */ |
| 65 | file->f_pos = offset; |
| 66 | break; |
| 67 | case 1: /* SEEK_CUR */ |
| 68 | file->f_pos += offset; |
| 69 | break; |
| 70 | case 2: /* SEEK_END, offset is negative */ |
| 71 | 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 Iwai | 5e2da20 | 2005-11-17 14:36:44 +0100 | [diff] [blame^] | 81 | static void snd_gf1_mem_proc_free(struct snd_info_entry *entry) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | { |
Takashi Iwai | 5e2da20 | 2005-11-17 14:36:44 +0100 | [diff] [blame^] | 83 | struct gus_proc_private *priv = entry->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | kfree(priv); |
| 85 | } |
| 86 | |
| 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, |
| 90 | }; |
| 91 | |
Takashi Iwai | 5e2da20 | 2005-11-17 14:36:44 +0100 | [diff] [blame^] | 92 | int snd_gf1_mem_proc_init(struct snd_gus_card * gus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | { |
| 94 | int idx; |
| 95 | char name[16]; |
Takashi Iwai | 5e2da20 | 2005-11-17 14:36:44 +0100 | [diff] [blame^] | 96 | struct gus_proc_private *priv; |
| 97 | struct snd_info_entry *entry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | |
| 99 | for (idx = 0; idx < 4; idx++) { |
| 100 | if (gus->gf1.mem_alloc.banks_8[idx].size > 0) { |
Takashi Iwai | 9e76a76 | 2005-09-09 14:21:17 +0200 | [diff] [blame] | 101 | priv = kzalloc(sizeof(*priv), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | 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 Iwai | 9e76a76 | 2005-09-09 14:21:17 +0200 | [diff] [blame] | 118 | priv = kzalloc(sizeof(*priv), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | 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 | } |