X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=sound%2Fpci%2Ftrident%2Ftrident_synth.c;h=9b7dee84743bc16b367a71307677ead56d822ed8;hb=refs%2Fheads%2Fvserver;hp=a2098eab17b5ebcd8aee31e70c44caa575a5e444;hpb=5273a3df6485dc2ad6aa7ddd441b9a21970f003b;p=linux-2.6.git diff --git a/sound/pci/trident/trident_synth.c b/sound/pci/trident/trident_synth.c index a2098eab1..9b7dee847 100644 --- a/sound/pci/trident/trident_synth.c +++ b/sound/pci/trident/trident_synth.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -191,15 +192,15 @@ static unsigned short log_from_linear( unsigned short value ) * Sample handling operations */ -static void sample_start(trident_t * trident, snd_trident_voice_t * voice, snd_seq_position_t position); -static void sample_stop(trident_t * trident, snd_trident_voice_t * voice, snd_seq_stop_mode_t mode); -static void sample_freq(trident_t * trident, snd_trident_voice_t * voice, snd_seq_frequency_t freq); -static void sample_volume(trident_t * trident, snd_trident_voice_t * voice, snd_seq_ev_volume_t * volume); -static void sample_loop(trident_t * trident, snd_trident_voice_t * voice, snd_seq_ev_loop_t * loop); -static void sample_pos(trident_t * trident, snd_trident_voice_t * voice, snd_seq_position_t position); -static void sample_private1(trident_t * trident, snd_trident_voice_t * voice, unsigned char *data); +static void sample_start(struct snd_trident * trident, struct snd_trident_voice * voice, snd_seq_position_t position); +static void sample_stop(struct snd_trident * trident, struct snd_trident_voice * voice, int mode); +static void sample_freq(struct snd_trident * trident, struct snd_trident_voice * voice, snd_seq_frequency_t freq); +static void sample_volume(struct snd_trident * trident, struct snd_trident_voice * voice, struct snd_seq_ev_volume * volume); +static void sample_loop(struct snd_trident * trident, struct snd_trident_voice * voice, struct snd_seq_ev_loop * loop); +static void sample_pos(struct snd_trident * trident, struct snd_trident_voice * voice, snd_seq_position_t position); +static void sample_private1(struct snd_trident * trident, struct snd_trident_voice * voice, unsigned char *data); -static snd_trident_sample_ops_t sample_ops = +static struct snd_trident_sample_ops sample_ops = { sample_start, sample_stop, @@ -210,7 +211,7 @@ static snd_trident_sample_ops_t sample_ops = sample_private1 }; -static void snd_trident_simple_init(snd_trident_voice_t * voice) +static void snd_trident_simple_init(struct snd_trident_voice * voice) { //voice->handler_wave = interrupt_wave; //voice->handler_volume = interrupt_volume; @@ -219,10 +220,10 @@ static void snd_trident_simple_init(snd_trident_voice_t * voice) voice->sample_ops = &sample_ops; } -static void sample_start(trident_t * trident, snd_trident_voice_t * voice, snd_seq_position_t position) +static void sample_start(struct snd_trident * trident, struct snd_trident_voice * voice, snd_seq_position_t position) { - simple_instrument_t *simple; - snd_seq_kinstr_t *instr; + struct simple_instrument *simple; + struct snd_seq_kinstr *instr; unsigned long flags; unsigned int loop_start, loop_end, sample_start, sample_end, start_offset; unsigned int value; @@ -304,7 +305,7 @@ static void sample_start(trident_t * trident, snd_trident_voice_t * voice, snd_s snd_seq_instr_free_use(trident->synth.ilist, instr); } -static void sample_stop(trident_t * trident, snd_trident_voice_t * voice, snd_seq_stop_mode_t mode) +static void sample_stop(struct snd_trident * trident, struct snd_trident_voice * voice, int mode) { unsigned long flags; @@ -328,7 +329,7 @@ static void sample_stop(trident_t * trident, snd_trident_voice_t * voice, snd_se } } -static void sample_freq(trident_t * trident, snd_trident_voice_t * voice, snd_seq_frequency_t freq) +static void sample_freq(struct snd_trident * trident, struct snd_trident_voice * voice, snd_seq_frequency_t freq) { unsigned long flags; freq >>= 4; @@ -354,7 +355,7 @@ static void sample_freq(trident_t * trident, snd_trident_voice_t * voice, snd_se spin_unlock_irqrestore(&trident->reg_lock, flags); } -static void sample_volume(trident_t * trident, snd_trident_voice_t * voice, snd_seq_ev_volume_t * volume) +static void sample_volume(struct snd_trident * trident, struct snd_trident_voice * voice, struct snd_seq_ev_volume * volume) { unsigned long flags; unsigned short value; @@ -406,11 +407,11 @@ static void sample_volume(trident_t * trident, snd_trident_voice_t * voice, snd_ spin_unlock_irqrestore(&trident->reg_lock, flags); } -static void sample_loop(trident_t * trident, snd_trident_voice_t * voice, snd_seq_ev_loop_t * loop) +static void sample_loop(struct snd_trident * trident, struct snd_trident_voice * voice, struct snd_seq_ev_loop * loop) { unsigned long flags; - simple_instrument_t *simple; - snd_seq_kinstr_t *instr; + struct simple_instrument *simple; + struct snd_seq_kinstr *instr; unsigned int loop_start, loop_end; instr = snd_seq_instr_find(trident->synth.ilist, &voice->instr, 0, 1); @@ -445,11 +446,11 @@ static void sample_loop(trident_t * trident, snd_trident_voice_t * voice, snd_se snd_seq_instr_free_use(trident->synth.ilist, instr); } -static void sample_pos(trident_t * trident, snd_trident_voice_t * voice, snd_seq_position_t position) +static void sample_pos(struct snd_trident * trident, struct snd_trident_voice * voice, snd_seq_position_t position) { unsigned long flags; - simple_instrument_t *simple; - snd_seq_kinstr_t *instr; + struct simple_instrument *simple; + struct snd_seq_kinstr *instr; unsigned int value; instr = snd_seq_instr_find(trident->synth.ilist, &voice->instr, 0, 1); @@ -495,7 +496,7 @@ static void sample_pos(trident_t * trident, snd_trident_voice_t * voice, snd_seq snd_seq_instr_free_use(trident->synth.ilist, instr); } -static void sample_private1(trident_t * trident, snd_trident_voice_t * voice, unsigned char *data) +static void sample_private1(struct snd_trident * trident, struct snd_trident_voice * voice, unsigned char *data) { } @@ -503,10 +504,11 @@ static void sample_private1(trident_t * trident, snd_trident_voice_t * voice, un * Memory management / sample loading */ -static int snd_trident_simple_put_sample(void *private_data, simple_instrument_t * instr, - char *data, long len, int atomic) +static int snd_trident_simple_put_sample(void *private_data, + struct simple_instrument * instr, + char __user *data, long len, int atomic) { - trident_t *trident = snd_magic_cast(trident_t, private_data, return -ENXIO); + struct snd_trident *trident = private_data; int size = instr->size; int shift = 0; @@ -524,11 +526,11 @@ static int snd_trident_simple_put_sample(void *private_data, simple_instrument_t if (trident->synth.current_size + size > trident->synth.max_size) return -ENOMEM; - if (verify_area(VERIFY_READ, data, size)) + if (!access_ok(VERIFY_READ, data, size)) return -EFAULT; if (trident->tlb.entries) { - snd_util_memblk_t *memblk; + struct snd_util_memblk *memblk; memblk = snd_trident_synth_alloc(trident, size); if (memblk == NULL) return -ENOMEM; @@ -540,12 +542,12 @@ static int snd_trident_simple_put_sample(void *private_data, simple_instrument_t instr->address.memory = memblk->offset; } else { struct snd_dma_buffer dmab; - - if (snd_dma_alloc_pages(&trident->dma_dev, size, &dmab) < 0) + if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(trident->pci), + size, &dmab) < 0) return -ENOMEM; if (copy_from_user(dmab.area, data, size)) { - snd_dma_free_pages(&trident->dma_dev, &dmab); + snd_dma_free_pages(&dmab); return -EFAULT; } instr->address.ptr = dmab.area; @@ -556,10 +558,11 @@ static int snd_trident_simple_put_sample(void *private_data, simple_instrument_t return 0; } -static int snd_trident_simple_get_sample(void *private_data, simple_instrument_t * instr, - char *data, long len, int atomic) +static int snd_trident_simple_get_sample(void *private_data, + struct simple_instrument * instr, + char __user *data, long len, int atomic) { - //trident_t *trident = snd_magic_cast(trident_t, private_data, return -ENXIO); + //struct snd_trident *trident = private_data; int size = instr->size; int shift = 0; @@ -569,7 +572,7 @@ static int snd_trident_simple_get_sample(void *private_data, simple_instrument_t shift++; size <<= shift; - if (verify_area(VERIFY_WRITE, data, size)) + if (!access_ok(VERIFY_WRITE, data, size)) return -EFAULT; /* FIXME: not implemented yet */ @@ -577,27 +580,34 @@ static int snd_trident_simple_get_sample(void *private_data, simple_instrument_t return -EBUSY; } -static int snd_trident_simple_remove_sample(void *private_data, simple_instrument_t * instr, +static int snd_trident_simple_remove_sample(void *private_data, + struct simple_instrument * instr, int atomic) { - trident_t *trident = snd_magic_cast(trident_t, private_data, return -ENXIO); + struct snd_trident *trident = private_data; int size = instr->size; + if (instr->format & SIMPLE_WAVE_16BIT) + size <<= 1; + if (instr->format & SIMPLE_WAVE_STEREO) + size <<= 1; + if (trident->tlb.entries) { - snd_util_memblk_t *memblk = (snd_util_memblk_t*)instr->address.ptr; + struct snd_util_memblk *memblk = (struct snd_util_memblk *)instr->address.ptr; if (memblk) snd_trident_synth_free(trident, memblk); else return -EFAULT; } else { - kfree(instr->address.ptr); + struct snd_dma_buffer dmab; + dmab.dev.type = SNDRV_DMA_TYPE_DEV; + dmab.dev.dev = snd_dma_pci_data(trident->pci); + dmab.area = instr->address.ptr; + dmab.addr = instr->address.memory; + dmab.bytes = size; + snd_dma_free_pages(&dmab); } - if (instr->format & SIMPLE_WAVE_16BIT) - size <<= 1; - if (instr->format & SIMPLE_WAVE_STEREO) - size <<= 1; - trident->synth.current_size -= size; if (trident->synth.current_size < 0) /* shouldn't need this check... */ trident->synth.current_size = 0; @@ -605,13 +615,13 @@ static int snd_trident_simple_remove_sample(void *private_data, simple_instrumen return 0; } -static void select_instrument(trident_t * trident, snd_trident_voice_t * v) +static void select_instrument(struct snd_trident * trident, struct snd_trident_voice * v) { - snd_seq_kinstr_t *instr; + struct snd_seq_kinstr *instr; instr = snd_seq_instr_find(trident->synth.ilist, &v->instr, 0, 1); if (instr != NULL) { if (instr->ops) { - if (instr->ops->instr_type == snd_seq_simple_id) + if (!strcmp(instr->ops->instr_type, SNDRV_SEQ_INSTR_ID_SIMPLE)) snd_trident_simple_init(v); } snd_seq_instr_free_use(trident->synth.ilist, instr); @@ -622,7 +632,7 @@ static void select_instrument(trident_t * trident, snd_trident_voice_t * v) */ -static void event_sample(snd_seq_event_t * ev, snd_trident_port_t * p, snd_trident_voice_t * v) +static void event_sample(struct snd_seq_event * ev, struct snd_trident_port * p, struct snd_trident_voice * v) { if (v->sample_ops && v->sample_ops->sample_stop) v->sample_ops->sample_stop(p->trident, v, SAMPLE_STOP_IMMEDIATELY); @@ -636,7 +646,7 @@ static void event_sample(snd_seq_event_t * ev, snd_trident_port_t * p, snd_tride select_instrument(p->trident, v); } -static void event_cluster(snd_seq_event_t * ev, snd_trident_port_t * p, snd_trident_voice_t * v) +static void event_cluster(struct snd_seq_event * ev, struct snd_trident_port * p, struct snd_trident_voice * v) { if (v->sample_ops && v->sample_ops->sample_stop) v->sample_ops->sample_stop(p->trident, v, SAMPLE_STOP_IMMEDIATELY); @@ -644,49 +654,49 @@ static void event_cluster(snd_seq_event_t * ev, snd_trident_port_t * p, snd_trid select_instrument(p->trident, v); } -static void event_start(snd_seq_event_t * ev, snd_trident_port_t * p, snd_trident_voice_t * v) +static void event_start(struct snd_seq_event * ev, struct snd_trident_port * p, struct snd_trident_voice * v) { if (v->sample_ops && v->sample_ops->sample_start) v->sample_ops->sample_start(p->trident, v, ev->data.sample.param.position); } -static void event_stop(snd_seq_event_t * ev, snd_trident_port_t * p, snd_trident_voice_t * v) +static void event_stop(struct snd_seq_event * ev, struct snd_trident_port * p, struct snd_trident_voice * v) { if (v->sample_ops && v->sample_ops->sample_stop) v->sample_ops->sample_stop(p->trident, v, ev->data.sample.param.stop_mode); } -static void event_freq(snd_seq_event_t * ev, snd_trident_port_t * p, snd_trident_voice_t * v) +static void event_freq(struct snd_seq_event * ev, struct snd_trident_port * p, struct snd_trident_voice * v) { if (v->sample_ops && v->sample_ops->sample_freq) v->sample_ops->sample_freq(p->trident, v, ev->data.sample.param.frequency); } -static void event_volume(snd_seq_event_t * ev, snd_trident_port_t * p, snd_trident_voice_t * v) +static void event_volume(struct snd_seq_event * ev, struct snd_trident_port * p, struct snd_trident_voice * v) { if (v->sample_ops && v->sample_ops->sample_volume) v->sample_ops->sample_volume(p->trident, v, &ev->data.sample.param.volume); } -static void event_loop(snd_seq_event_t * ev, snd_trident_port_t * p, snd_trident_voice_t * v) +static void event_loop(struct snd_seq_event * ev, struct snd_trident_port * p, struct snd_trident_voice * v) { if (v->sample_ops && v->sample_ops->sample_loop) v->sample_ops->sample_loop(p->trident, v, &ev->data.sample.param.loop); } -static void event_position(snd_seq_event_t * ev, snd_trident_port_t * p, snd_trident_voice_t * v) +static void event_position(struct snd_seq_event * ev, struct snd_trident_port * p, struct snd_trident_voice * v) { if (v->sample_ops && v->sample_ops->sample_pos) v->sample_ops->sample_pos(p->trident, v, ev->data.sample.param.position); } -static void event_private1(snd_seq_event_t * ev, snd_trident_port_t * p, snd_trident_voice_t * v) +static void event_private1(struct snd_seq_event * ev, struct snd_trident_port * p, struct snd_trident_voice * v) { if (v->sample_ops && v->sample_ops->sample_private1) v->sample_ops->sample_private1(p->trident, v, (unsigned char *) &ev->data.sample.param.raw8); } -typedef void (trident_sample_event_handler_t) (snd_seq_event_t * ev, snd_trident_port_t * p, snd_trident_voice_t * v); +typedef void (trident_sample_event_handler_t) (struct snd_seq_event * ev, struct snd_trident_port * p, struct snd_trident_voice * v); static trident_sample_event_handler_t *trident_sample_event_handlers[9] = { @@ -701,11 +711,11 @@ static trident_sample_event_handler_t *trident_sample_event_handlers[9] = event_private1 }; -static void snd_trident_sample_event(snd_seq_event_t * ev, snd_trident_port_t * p) +static void snd_trident_sample_event(struct snd_seq_event * ev, struct snd_trident_port * p) { int idx, voice; - trident_t *trident = p->trident; - snd_trident_voice_t *v; + struct snd_trident *trident = p->trident; + struct snd_trident_voice *v; unsigned long flags; idx = ev->type - SNDRV_SEQ_EVENT_SAMPLE; @@ -728,10 +738,10 @@ static void snd_trident_sample_event(snd_seq_event_t * ev, snd_trident_port_t * */ -static void snd_trident_synth_free_voices(trident_t * trident, int client, int port) +static void snd_trident_synth_free_voices(struct snd_trident * trident, int client, int port) { int idx; - snd_trident_voice_t *voice; + struct snd_trident_voice *voice; for (idx = 0; idx < 32; idx++) { voice = &trident->synth.voices[idx]; @@ -740,11 +750,11 @@ static void snd_trident_synth_free_voices(trident_t * trident, int client, int p } } -static int snd_trident_synth_use(void *private_data, snd_seq_port_subscribe_t * info) +static int snd_trident_synth_use(void *private_data, struct snd_seq_port_subscribe * info) { - snd_trident_port_t *port = (snd_trident_port_t *) private_data; - trident_t *trident = port->trident; - snd_trident_voice_t *voice; + struct snd_trident_port *port = private_data; + struct snd_trident *trident = port->trident; + struct snd_trident_voice *voice; unsigned int idx; unsigned long flags; @@ -779,10 +789,10 @@ static int snd_trident_synth_use(void *private_data, snd_seq_port_subscribe_t * return 0; } -static int snd_trident_synth_unuse(void *private_data, snd_seq_port_subscribe_t * info) +static int snd_trident_synth_unuse(void *private_data, struct snd_seq_port_subscribe * info) { - snd_trident_port_t *port = (snd_trident_port_t *) private_data; - trident_t *trident = port->trident; + struct snd_trident_port *port = private_data; + struct snd_trident *trident = port->trident; unsigned long flags; spin_lock_irqsave(&trident->reg_lock, flags); @@ -795,18 +805,18 @@ static int snd_trident_synth_unuse(void *private_data, snd_seq_port_subscribe_t */ -static void snd_trident_synth_free_private_instruments(snd_trident_port_t * p, int client) +static void snd_trident_synth_free_private_instruments(struct snd_trident_port * p, int client) { - snd_seq_instr_header_t ifree; + struct snd_seq_instr_header ifree; memset(&ifree, 0, sizeof(ifree)); ifree.cmd = SNDRV_SEQ_INSTR_FREE_CMD_PRIVATE; snd_seq_instr_list_free_cond(p->trident->synth.ilist, &ifree, client, 0); } -int snd_trident_synth_event_input(snd_seq_event_t * ev, int direct, void *private_data, int atomic, int hop) +static int snd_trident_synth_event_input(struct snd_seq_event * ev, int direct, void *private_data, int atomic, int hop) { - snd_trident_port_t *p = (snd_trident_port_t *) private_data; + struct snd_trident_port *p = (struct snd_trident_port *) private_data; if (p == NULL) return -EINVAL; @@ -834,12 +844,12 @@ int snd_trident_synth_event_input(snd_seq_event_t * ev, int direct, void *privat } static void snd_trident_synth_instr_notify(void *private_data, - snd_seq_kinstr_t * instr, + struct snd_seq_kinstr * instr, int what) { int idx; - trident_t *trident = snd_magic_cast(trident_t, private_data, return); - snd_trident_voice_t *pvoice; + struct snd_trident *trident = private_data; + struct snd_trident_voice *pvoice; unsigned long flags; spin_lock_irqsave(&trident->event_lock, flags); @@ -863,16 +873,16 @@ static void snd_trident_synth_instr_notify(void *private_data, static void snd_trident_synth_free_port(void *private_data) { - snd_trident_port_t *p = (snd_trident_port_t *) private_data; + struct snd_trident_port *p = (struct snd_trident_port *) private_data; if (p) snd_midi_channel_free_set(p->chset); } -static int snd_trident_synth_create_port(trident_t * trident, int idx) +static int snd_trident_synth_create_port(struct snd_trident * trident, int idx) { - snd_trident_port_t *p; - snd_seq_port_callback_t callbacks; + struct snd_trident_port *p; + struct snd_seq_port_callback callbacks; char name[32]; char *str; int result; @@ -904,7 +914,9 @@ static int snd_trident_synth_create_port(trident_t * trident, int idx) &callbacks, SNDRV_SEQ_PORT_CAP_WRITE | SNDRV_SEQ_PORT_CAP_SUBS_WRITE, SNDRV_SEQ_PORT_TYPE_DIRECT_SAMPLE | - SNDRV_SEQ_PORT_TYPE_SYNTH, + SNDRV_SEQ_PORT_TYPE_SYNTH | + SNDRV_SEQ_PORT_TYPE_HARDWARE | + SNDRV_SEQ_PORT_TYPE_SYNTHESIZER, 16, 0, name); if (p->chset->port < 0) { @@ -920,43 +932,31 @@ static int snd_trident_synth_create_port(trident_t * trident, int idx) */ -static int snd_trident_synth_new_device(snd_seq_device_t *dev) +static int snd_trident_synth_new_device(struct snd_seq_device *dev) { - trident_t *trident; + struct snd_trident *trident; int client, i; - snd_seq_client_callback_t callbacks; - snd_seq_client_info_t cinfo; - snd_seq_port_subscribe_t sub; - snd_simple_ops_t *simpleops; + struct snd_seq_port_subscribe sub; + struct snd_simple_ops *simpleops; char *str; - trident = *(trident_t **)SNDRV_SEQ_DEVICE_ARGPTR(dev); + trident = *(struct snd_trident **)SNDRV_SEQ_DEVICE_ARGPTR(dev); if (trident == NULL) return -EINVAL; trident->synth.seq_client = -1; /* allocate new client */ - memset(&callbacks, 0, sizeof(callbacks)); - callbacks.private_data = trident; - callbacks.allow_output = callbacks.allow_input = 1; - client = trident->synth.seq_client = - snd_seq_create_kernel_client(trident->card, 1, &callbacks); - if (client < 0) - return client; - - /* change name of client */ - memset(&cinfo, 0, sizeof(cinfo)); - cinfo.client = client; - cinfo.type = KERNEL_CLIENT; str = "???"; switch (trident->device) { case TRIDENT_DEVICE_ID_DX: str = "Trident 4DWave-DX"; break; case TRIDENT_DEVICE_ID_NX: str = "Trident 4DWave-NX"; break; case TRIDENT_DEVICE_ID_SI7018: str = "SiS 7018"; break; } - sprintf(cinfo.name, str); - snd_seq_kernel_client_ctl(client, SNDRV_SEQ_IOCTL_SET_CLIENT_INFO, &cinfo); + client = trident->synth.seq_client = + snd_seq_create_kernel_client(trident->card, 1, str); + if (client < 0) + return client; for (i = 0; i < 4; i++) snd_trident_synth_create_port(trident, i); @@ -986,11 +986,11 @@ static int snd_trident_synth_new_device(snd_seq_device_t *dev) return 0; } -static int snd_trident_synth_delete_device(snd_seq_device_t *dev) +static int snd_trident_synth_delete_device(struct snd_seq_device *dev) { - trident_t *trident; + struct snd_trident *trident; - trident = *(trident_t **)SNDRV_SEQ_DEVICE_ARGPTR(dev); + trident = *(struct snd_trident **)SNDRV_SEQ_DEVICE_ARGPTR(dev); if (trident == NULL) return -EINVAL; @@ -1005,14 +1005,14 @@ static int snd_trident_synth_delete_device(snd_seq_device_t *dev) static int __init alsa_trident_synth_init(void) { - static snd_seq_dev_ops_t ops = + static struct snd_seq_dev_ops ops = { snd_trident_synth_new_device, snd_trident_synth_delete_device }; return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_TRIDENT, &ops, - sizeof(trident_t*)); + sizeof(struct snd_trident *)); } static void __exit alsa_trident_synth_exit(void)