[PATCH] fix semaphore handling in __unregister_chrdev_region
[linux/fpc-iii.git] / sound / isa / gus / gus_instr.c
blob591a9a17feb520d1616f343c2ad97e8fb80783d8
1 /*
2 * Routines for Gravis UltraSound soundcards - Synthesizer
3 * Copyright (c) by Jaroslav Kysela <perex@suse.cz>
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/time.h>
24 #include <sound/core.h>
25 #include <sound/gus.h>
31 int snd_gus_iwffff_put_sample(void *private_data, iwffff_wave_t *wave,
32 char __user *data, long len, int atomic)
34 snd_gus_card_t *gus = private_data;
35 snd_gf1_mem_block_t *block;
36 int err;
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;
57 wave->address.memory = block->ptr;
58 return 0;
61 int snd_gus_iwffff_get_sample(void *private_data, iwffff_wave_t *wave,
62 char __user *data, long len, int atomic)
64 snd_gus_card_t *gus = private_data;
66 return snd_gus_dram_read(gus, data, wave->address.memory, wave->size,
67 wave->format & IWFFFF_WAVE_ROM ? 1 : 0);
70 int snd_gus_iwffff_remove_sample(void *private_data, iwffff_wave_t *wave,
71 int atomic)
73 snd_gus_card_t *gus = private_data;
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);
84 int snd_gus_gf1_put_sample(void *private_data, gf1_wave_t *wave,
85 char __user *data, long len, int atomic)
87 snd_gus_card_t *gus = private_data;
88 snd_gf1_mem_block_t *block;
89 int err;
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;
108 wave->address.memory = block->ptr;
109 return 0;
112 int snd_gus_gf1_get_sample(void *private_data, gf1_wave_t *wave,
113 char __user *data, long len, int atomic)
115 snd_gus_card_t *gus = private_data;
117 return snd_gus_dram_read(gus, data, wave->address.memory, wave->size, 0);
120 int snd_gus_gf1_remove_sample(void *private_data, gf1_wave_t *wave,
121 int atomic)
123 snd_gus_card_t *gus = private_data;
125 return snd_gf1_mem_free(&gus->gf1.mem_alloc, wave->address.memory);
132 int snd_gus_simple_put_sample(void *private_data, simple_instrument_t *instr,
133 char __user *data, long len, int atomic)
135 snd_gus_card_t *gus = private_data;
136 snd_gf1_mem_block_t *block;
137 int err;
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;
155 instr->address.memory = block->ptr;
156 return 0;
159 int snd_gus_simple_get_sample(void *private_data, simple_instrument_t *instr,
160 char __user *data, long len, int atomic)
162 snd_gus_card_t *gus = private_data;
164 return snd_gus_dram_read(gus, data, instr->address.memory, instr->size, 0);
167 int snd_gus_simple_remove_sample(void *private_data, simple_instrument_t *instr,
168 int atomic)
170 snd_gus_card_t *gus = private_data;
172 return snd_gf1_mem_free(&gus->gf1.mem_alloc, instr->address.memory);