1/* 2 * Routines for Gravis UltraSound soundcards - Synthesizer 3 * Copyright (c) by Jaroslav Kysela <perex@suse.cz> 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/time.h> 24#include <sound/core.h> 25#include <sound/gus.h> 26 27/* 28 * 29 */ 30 31int snd_gus_iwffff_put_sample(void *private_data, struct iwffff_wave *wave, 32 char __user *data, long len, int atomic) 33{ 34 struct snd_gus_card *gus = private_data; 35 struct snd_gf1_mem_block *block; 36 int err; 37 38 if (wave->format & IWFFFF_WAVE_ROM) 39 return 0; /* it's probably ok - verify the address? */ 40 if (wave->format & IWFFFF_WAVE_STEREO) 41 return -EINVAL; /* not supported */ 42 block = snd_gf1_mem_alloc(&gus->gf1.mem_alloc, 43 SNDRV_GF1_MEM_OWNER_WAVE_IWFFFF, 44 NULL, wave->size, 45 wave->format & IWFFFF_WAVE_16BIT, 1, 46 wave->share_id); 47 if (block == NULL) 48 return -ENOMEM; 49 err = snd_gus_dram_write(gus, data, 50 block->ptr, wave->size); 51 if (err < 0) { 52 snd_gf1_mem_lock(&gus->gf1.mem_alloc, 0); 53 snd_gf1_mem_xfree(&gus->gf1.mem_alloc, block); 54 snd_gf1_mem_lock(&gus->gf1.mem_alloc, 1); 55 return err; 56 } 57 wave->address.memory = block->ptr; 58 return 0; 59} 60 61int snd_gus_iwffff_get_sample(void *private_data, struct iwffff_wave *wave, 62 char __user *data, long len, int atomic) 63{ 64 struct snd_gus_card *gus = private_data; 65 66 return snd_gus_dram_read(gus, data, wave->address.memory, wave->size, 67 wave->format & IWFFFF_WAVE_ROM ? 1 : 0); 68} 69 70int snd_gus_iwffff_remove_sample(void *private_data, struct iwffff_wave *wave, 71 int atomic) 72{ 73 struct snd_gus_card *gus = private_data; 74 75 if (wave->format & IWFFFF_WAVE_ROM) 76 return 0; /* it's probably ok - verify the address? */ 77 return snd_gf1_mem_free(&gus->gf1.mem_alloc, wave->address.memory); 78} 79 80/* 81 * 82 */ 83 84int snd_gus_gf1_put_sample(void *private_data, struct gf1_wave *wave, 85 char __user *data, long len, int atomic) 86{ 87 struct snd_gus_card *gus = private_data; 88 struct snd_gf1_mem_block *block; 89 int err; 90 91 if (wave->format & GF1_WAVE_STEREO) 92 return -EINVAL; /* not supported */ 93 block = snd_gf1_mem_alloc(&gus->gf1.mem_alloc, 94 SNDRV_GF1_MEM_OWNER_WAVE_GF1, 95 NULL, wave->size, 96 wave->format & GF1_WAVE_16BIT, 1, 97 wave->share_id); 98 if (block == NULL) 99 return -ENOMEM; 100 err = snd_gus_dram_write(gus, data, 101 block->ptr, wave->size); 102 if (err < 0) { 103 snd_gf1_mem_lock(&gus->gf1.mem_alloc, 0); 104 snd_gf1_mem_xfree(&gus->gf1.mem_alloc, block); 105 snd_gf1_mem_lock(&gus->gf1.mem_alloc, 1); 106 return err; 107 } 108 wave->address.memory = block->ptr; 109 return 0; 110} 111 112int snd_gus_gf1_get_sample(void *private_data, struct gf1_wave *wave, 113 char __user *data, long len, int atomic) 114{ 115 struct snd_gus_card *gus = private_data; 116 117 return snd_gus_dram_read(gus, data, wave->address.memory, wave->size, 0); 118} 119 120int snd_gus_gf1_remove_sample(void *private_data, struct gf1_wave *wave, 121 int atomic) 122{ 123 struct snd_gus_card *gus = private_data; 124 125 return snd_gf1_mem_free(&gus->gf1.mem_alloc, wave->address.memory); 126} 127 128/* 129 * 130 */ 131 132int snd_gus_simple_put_sample(void *private_data, struct simple_instrument *instr, 133 char __user *data, long len, int atomic) 134{ 135 struct snd_gus_card *gus = private_data; 136 struct snd_gf1_mem_block *block; 137 int err; 138 139 if (instr->format & SIMPLE_WAVE_STEREO) 140 return -EINVAL; /* not supported */ 141 block = snd_gf1_mem_alloc(&gus->gf1.mem_alloc, 142 SNDRV_GF1_MEM_OWNER_WAVE_SIMPLE, 143 NULL, instr->size, 144 instr->format & SIMPLE_WAVE_16BIT, 1, 145 instr->share_id); 146 if (block == NULL) 147 return -ENOMEM; 148 err = snd_gus_dram_write(gus, data, block->ptr, instr->size); 149 if (err < 0) { 150 snd_gf1_mem_lock(&gus->gf1.mem_alloc, 0); 151 snd_gf1_mem_xfree(&gus->gf1.mem_alloc, block); 152 snd_gf1_mem_lock(&gus->gf1.mem_alloc, 1); 153 return err; 154 } 155 instr->address.memory = block->ptr; 156 return 0; 157} 158 159int snd_gus_simple_get_sample(void *private_data, struct simple_instrument *instr, 160 char __user *data, long len, int atomic) 161{ 162 struct snd_gus_card *gus = private_data; 163 164 return snd_gus_dram_read(gus, data, instr->address.memory, instr->size, 0); 165} 166 167int snd_gus_simple_remove_sample(void *private_data, struct simple_instrument *instr, 168 int atomic) 169{ 170 struct snd_gus_card *gus = private_data; 171 172 return snd_gf1_mem_free(&gus->gf1.mem_alloc, instr->address.memory); 173} 174