diff options
author | Cameron Grant <cg@FreeBSD.org> | 2000-09-01 20:09:24 +0000 |
---|---|---|
committer | Cameron Grant <cg@FreeBSD.org> | 2000-09-01 20:09:24 +0000 |
commit | 33dbf14a176a5bdcd78deec75616b8ede1937e96 (patch) | |
tree | de613fdf24f49d54b13e2071271879602e1f83e8 /sys | |
parent | 84a563762067d9b4f4bfa534c936519173acdd89 (diff) | |
download | src-33dbf14a176a5bdcd78deec75616b8ede1937e96.tar.gz src-33dbf14a176a5bdcd78deec75616b8ede1937e96.zip |
change mixer api slightly
change channel interface - kobj implementation coming soonish
make pcm_makelinks not panic if modular
add pcm_unregister()
these changes support newpcm kld unloading, but this is only implemented
by ds1.c
Notes
Notes:
svn path=/head/; revision=65340
Diffstat (limited to 'sys')
-rw-r--r-- | sys/dev/sound/isa/ad1816.c | 20 | ||||
-rw-r--r-- | sys/dev/sound/isa/ess.c | 20 | ||||
-rw-r--r-- | sys/dev/sound/isa/mss.c | 29 | ||||
-rw-r--r-- | sys/dev/sound/isa/sb.c | 20 | ||||
-rw-r--r-- | sys/dev/sound/isa/sb16.c | 20 | ||||
-rw-r--r-- | sys/dev/sound/isa/sb8.c | 20 | ||||
-rw-r--r-- | sys/dev/sound/pci/aureal.c | 11 | ||||
-rw-r--r-- | sys/dev/sound/pci/csapcm.c | 12 | ||||
-rw-r--r-- | sys/dev/sound/pci/ds1.c | 76 | ||||
-rw-r--r-- | sys/dev/sound/pci/emu10k1.c | 36 | ||||
-rw-r--r-- | sys/dev/sound/pci/es137x.c | 25 | ||||
-rw-r--r-- | sys/dev/sound/pci/fm801.c | 156 | ||||
-rw-r--r-- | sys/dev/sound/pci/neomagic.c | 23 | ||||
-rw-r--r-- | sys/dev/sound/pci/solo.c | 20 | ||||
-rw-r--r-- | sys/dev/sound/pci/t4dwave.c | 12 | ||||
-rw-r--r-- | sys/dev/sound/pci/via82c686.c | 12 | ||||
-rw-r--r-- | sys/dev/sound/pcm/ac97.c | 21 | ||||
-rw-r--r-- | sys/dev/sound/pcm/ac97.h | 1 | ||||
-rw-r--r-- | sys/dev/sound/pcm/channel.c | 26 | ||||
-rw-r--r-- | sys/dev/sound/pcm/channel.h | 2 | ||||
-rw-r--r-- | sys/dev/sound/pcm/datatypes.h | 16 | ||||
-rw-r--r-- | sys/dev/sound/pcm/mixer.c | 41 | ||||
-rw-r--r-- | sys/dev/sound/pcm/mixer.h | 11 | ||||
-rw-r--r-- | sys/dev/sound/pcm/sound.c | 245 | ||||
-rw-r--r-- | sys/dev/sound/pcm/sound.h | 1 |
25 files changed, 627 insertions, 249 deletions
diff --git a/sys/dev/sound/isa/ad1816.c b/sys/dev/sound/isa/ad1816.c index ec7a61ebfe93..3cebbe30ebdc 100644 --- a/sys/dev/sound/isa/ad1816.c +++ b/sys/dev/sound/isa/ad1816.c @@ -67,10 +67,11 @@ static int ad1816mix_init(snd_mixer *m); static int ad1816mix_set(snd_mixer *m, unsigned dev, unsigned left, unsigned right); static int ad1816mix_setrecsrc(snd_mixer *m, u_int32_t src); static snd_mixer ad1816_mixer = { - "ad1816 mixer", - ad1816mix_init, - ad1816mix_set, - ad1816mix_setrecsrc, + "ad1816 mixer", + ad1816mix_init, + NULL, + ad1816mix_set, + ad1816mix_setrecsrc, }; static devclass_t pcm_devclass; @@ -108,6 +109,14 @@ static pcm_channel ad1816_chantemplate = { ad1816chan_trigger, ad1816chan_getptr, ad1816chan_getcaps, + NULL, /* free */ + NULL, /* nop1 */ + NULL, /* nop2 */ + NULL, /* nop3 */ + NULL, /* nop4 */ + NULL, /* nop5 */ + NULL, /* nop6 */ + NULL, /* nop7 */ }; #define AD1816_MUTE 31 /* value for mute */ @@ -566,7 +575,6 @@ static int ad1816_attach(device_t dev) { struct ad1816_info *ad1816; - snddev_info *d = device_get_softc(dev); void *ih; char status[SND_STATUSLEN]; @@ -581,7 +589,7 @@ ad1816_attach(device_t dev) if (!ad1816_alloc_resources(ad1816, dev)) goto no; ad1816_init(ad1816, dev); - mixer_init(d, &ad1816_mixer, ad1816); + mixer_init(dev, &ad1816_mixer, ad1816); bus_setup_intr(dev, ad1816->irq, INTR_TYPE_TTY, ad1816_intr, ad1816, &ih); if (bus_dma_tag_create(/*parent*/NULL, /*alignment*/2, /*boundary*/0, /*lowaddr*/BUS_SPACE_MAXADDR_24BIT, diff --git a/sys/dev/sound/isa/ess.c b/sys/dev/sound/isa/ess.c index 2252cd9f268d..abef6889cdbd 100644 --- a/sys/dev/sound/isa/ess.c +++ b/sys/dev/sound/isa/ess.c @@ -92,6 +92,14 @@ static pcm_channel ess_chantemplate = { esschan_trigger, esschan_getptr, esschan_getcaps, + NULL, /* free */ + NULL, /* nop1 */ + NULL, /* nop2 */ + NULL, /* nop3 */ + NULL, /* nop4 */ + NULL, /* nop5 */ + NULL, /* nop6 */ + NULL, /* nop7 */ }; struct ess_info; @@ -139,10 +147,11 @@ static int essmix_set(snd_mixer *m, unsigned dev, unsigned left, unsigned right) static int essmix_setrecsrc(snd_mixer *m, u_int32_t src); static snd_mixer ess_mixer = { - "ESS mixer", - essmix_init, - essmix_set, - essmix_setrecsrc, + "ESS mixer", + essmix_init, + NULL, + essmix_set, + essmix_setrecsrc, }; static devclass_t pcm_devclass; @@ -365,7 +374,6 @@ ess_alloc_resources(struct ess_info *sc, device_t dev) static int ess_doattach(device_t dev, struct ess_info *sc) { - snddev_info *d = device_get_softc(dev); void *ih; char status[SND_STATUSLEN], buf[64]; int ver; @@ -374,7 +382,7 @@ ess_doattach(device_t dev, struct ess_info *sc) goto no; if (ess_reset_dsp(sc)) goto no; - mixer_init(d, &ess_mixer, sc); + mixer_init(dev, &ess_mixer, sc); sc->duplex = 0; sc->newspeed = 0; diff --git a/sys/dev/sound/isa/mss.c b/sys/dev/sound/isa/mss.c index 71f9dd5aa8c5..93347c50b72f 100644 --- a/sys/dev/sound/isa/mss.c +++ b/sys/dev/sound/isa/mss.c @@ -108,20 +108,22 @@ static int mssmix_init(snd_mixer *m); static int mssmix_set(snd_mixer *m, unsigned dev, unsigned left, unsigned right); static int mssmix_setrecsrc(snd_mixer *m, u_int32_t src); static snd_mixer mss_mixer = { - "MSS mixer", - mssmix_init, - mssmix_set, - mssmix_setrecsrc, + "MSS mixer", + mssmix_init, + NULL, + mssmix_set, + mssmix_setrecsrc, }; static int ymmix_init(snd_mixer *m); static int ymmix_set(snd_mixer *m, unsigned dev, unsigned left, unsigned right); static int ymmix_setrecsrc(snd_mixer *m, u_int32_t src); static snd_mixer yamaha_mixer = { - "OPL3-SAx mixer", - ymmix_init, - ymmix_set, - ymmix_setrecsrc, + "OPL3-SAx mixer", + ymmix_init, + NULL, + ymmix_set, + ymmix_setrecsrc, }; static devclass_t pcm_devclass; @@ -178,6 +180,14 @@ static pcm_channel mss_chantemplate = { msschan_trigger, msschan_getptr, msschan_getcaps, + NULL, /* free */ + NULL, /* nop1 */ + NULL, /* nop2 */ + NULL, /* nop3 */ + NULL, /* nop4 */ + NULL, /* nop5 */ + NULL, /* nop6 */ + NULL, /* nop7 */ }; #define MD_AD1848 0x91 @@ -862,7 +872,6 @@ ymf_test(device_t dev, struct mss_info *mss) static int mss_doattach(device_t dev, struct mss_info *mss) { - snddev_info *d = device_get_softc(dev); void *ih; int flags = device_get_flags(dev); char status[SND_STATUSLEN]; @@ -902,7 +911,7 @@ mss_doattach(device_t dev, struct mss_info *mss) io_wr(mss, 0, bits); printf("drq/irq conf %x\n", io_rd(mss, 0)); } - mixer_init(d, (mss->bd_id == MD_YM0020)? &yamaha_mixer : &mss_mixer, mss); + mixer_init(dev, (mss->bd_id == MD_YM0020)? &yamaha_mixer : &mss_mixer, mss); switch (mss->bd_id) { case MD_OPTI931: bus_setup_intr(dev, mss->irq, INTR_TYPE_TTY, opti931_intr, mss, &ih); diff --git a/sys/dev/sound/isa/sb.c b/sys/dev/sound/isa/sb.c index d9753115ad68..21c3e6fa12da 100644 --- a/sys/dev/sound/isa/sb.c +++ b/sys/dev/sound/isa/sb.c @@ -107,6 +107,14 @@ static pcm_channel sb_chantemplate = { sbchan_trigger, sbchan_getptr, sbchan_getcaps, + NULL, /* free */ + NULL, /* nop1 */ + NULL, /* nop2 */ + NULL, /* nop3 */ + NULL, /* nop4 */ + NULL, /* nop5 */ + NULL, /* nop6 */ + NULL, /* nop7 */ }; struct sb_info; @@ -152,10 +160,11 @@ static int sbmix_set(snd_mixer *m, unsigned dev, unsigned left, unsigned right); static int sbmix_setrecsrc(snd_mixer *m, u_int32_t src); static snd_mixer sb_mixer = { - "SoundBlaster mixer", - sbmix_init, - sbmix_set, - sbmix_setrecsrc, + "SoundBlaster mixer", + sbmix_init, + NULL, + sbmix_set, + sbmix_setrecsrc, }; static devclass_t pcm_devclass; @@ -412,7 +421,6 @@ sb16_swap(void *v, int dir) static int sb_doattach(device_t dev, struct sb_info *sb) { - snddev_info *d = device_get_softc(dev); void *ih; char status[SND_STATUSLEN]; int bs = DSP_BUFFSIZE; @@ -421,7 +429,7 @@ sb_doattach(device_t dev, struct sb_info *sb) goto no; if (sb_reset_dsp(sb)) goto no; - mixer_init(d, &sb_mixer, sb); + mixer_init(dev, &sb_mixer, sb); bus_setup_intr(dev, sb->irq, INTR_TYPE_TTY, sb_intr, sb, &ih); if ((sb->bd_flags & BD_F_SB16) && !(sb->bd_flags & BD_F_SB16X)) diff --git a/sys/dev/sound/isa/sb16.c b/sys/dev/sound/isa/sb16.c index d9753115ad68..21c3e6fa12da 100644 --- a/sys/dev/sound/isa/sb16.c +++ b/sys/dev/sound/isa/sb16.c @@ -107,6 +107,14 @@ static pcm_channel sb_chantemplate = { sbchan_trigger, sbchan_getptr, sbchan_getcaps, + NULL, /* free */ + NULL, /* nop1 */ + NULL, /* nop2 */ + NULL, /* nop3 */ + NULL, /* nop4 */ + NULL, /* nop5 */ + NULL, /* nop6 */ + NULL, /* nop7 */ }; struct sb_info; @@ -152,10 +160,11 @@ static int sbmix_set(snd_mixer *m, unsigned dev, unsigned left, unsigned right); static int sbmix_setrecsrc(snd_mixer *m, u_int32_t src); static snd_mixer sb_mixer = { - "SoundBlaster mixer", - sbmix_init, - sbmix_set, - sbmix_setrecsrc, + "SoundBlaster mixer", + sbmix_init, + NULL, + sbmix_set, + sbmix_setrecsrc, }; static devclass_t pcm_devclass; @@ -412,7 +421,6 @@ sb16_swap(void *v, int dir) static int sb_doattach(device_t dev, struct sb_info *sb) { - snddev_info *d = device_get_softc(dev); void *ih; char status[SND_STATUSLEN]; int bs = DSP_BUFFSIZE; @@ -421,7 +429,7 @@ sb_doattach(device_t dev, struct sb_info *sb) goto no; if (sb_reset_dsp(sb)) goto no; - mixer_init(d, &sb_mixer, sb); + mixer_init(dev, &sb_mixer, sb); bus_setup_intr(dev, sb->irq, INTR_TYPE_TTY, sb_intr, sb, &ih); if ((sb->bd_flags & BD_F_SB16) && !(sb->bd_flags & BD_F_SB16X)) diff --git a/sys/dev/sound/isa/sb8.c b/sys/dev/sound/isa/sb8.c index d9753115ad68..21c3e6fa12da 100644 --- a/sys/dev/sound/isa/sb8.c +++ b/sys/dev/sound/isa/sb8.c @@ -107,6 +107,14 @@ static pcm_channel sb_chantemplate = { sbchan_trigger, sbchan_getptr, sbchan_getcaps, + NULL, /* free */ + NULL, /* nop1 */ + NULL, /* nop2 */ + NULL, /* nop3 */ + NULL, /* nop4 */ + NULL, /* nop5 */ + NULL, /* nop6 */ + NULL, /* nop7 */ }; struct sb_info; @@ -152,10 +160,11 @@ static int sbmix_set(snd_mixer *m, unsigned dev, unsigned left, unsigned right); static int sbmix_setrecsrc(snd_mixer *m, u_int32_t src); static snd_mixer sb_mixer = { - "SoundBlaster mixer", - sbmix_init, - sbmix_set, - sbmix_setrecsrc, + "SoundBlaster mixer", + sbmix_init, + NULL, + sbmix_set, + sbmix_setrecsrc, }; static devclass_t pcm_devclass; @@ -412,7 +421,6 @@ sb16_swap(void *v, int dir) static int sb_doattach(device_t dev, struct sb_info *sb) { - snddev_info *d = device_get_softc(dev); void *ih; char status[SND_STATUSLEN]; int bs = DSP_BUFFSIZE; @@ -421,7 +429,7 @@ sb_doattach(device_t dev, struct sb_info *sb) goto no; if (sb_reset_dsp(sb)) goto no; - mixer_init(d, &sb_mixer, sb); + mixer_init(dev, &sb_mixer, sb); bus_setup_intr(dev, sb->irq, INTR_TYPE_TTY, sb_intr, sb, &ih); if ((sb->bd_flags & BD_F_SB16) && !(sb->bd_flags & BD_F_SB16X)) diff --git a/sys/dev/sound/pci/aureal.c b/sys/dev/sound/pci/aureal.c index 5b5e47c15dc8..9a9dd0a00b86 100644 --- a/sys/dev/sound/pci/aureal.c +++ b/sys/dev/sound/pci/aureal.c @@ -73,6 +73,14 @@ static pcm_channel au_chantemplate = { auchan_trigger, auchan_getptr, auchan_getcaps, + NULL, /* free */ + NULL, /* nop1 */ + NULL, /* nop2 */ + NULL, /* nop3 */ + NULL, /* nop4 */ + NULL, /* nop5 */ + NULL, /* nop6 */ + NULL, /* nop7 */ }; /* -------------------------------------------------------------------- */ @@ -551,7 +559,6 @@ au_pci_probe(device_t dev) static int au_pci_attach(device_t dev) { - snddev_info *d; u_int32_t data; struct au_info *au; int type[10]; @@ -644,7 +651,7 @@ au_pci_attach(device_t dev) codec = ac97_create(dev, au, NULL, au_rdcd, au_wrcd); if (codec == NULL) goto bad; - if (mixer_init(d, &ac97_mixer, codec) == -1) goto bad; + if (mixer_init(dev, &ac97_mixer, codec) == -1) goto bad; if (bus_dma_tag_create(/*parent*/NULL, /*alignment*/2, /*boundary*/0, /*lowaddr*/BUS_SPACE_MAXADDR_32BIT, diff --git a/sys/dev/sound/pci/csapcm.c b/sys/dev/sound/pci/csapcm.c index f0ea0a3cad47..2c9e5ca2bc1b 100644 --- a/sys/dev/sound/pci/csapcm.c +++ b/sys/dev/sound/pci/csapcm.c @@ -125,6 +125,14 @@ static pcm_channel csa_chantemplate = { csachan_trigger, csachan_getptr, csachan_getcaps, + NULL, /* free */ + NULL, /* nop1 */ + NULL, /* nop2 */ + NULL, /* nop3 */ + NULL, /* nop4 */ + NULL, /* nop5 */ + NULL, /* nop6 */ + NULL, /* nop7 */ }; /* -------------------------------------------------------------------- */ @@ -780,7 +788,6 @@ pcmcsa_probe(device_t dev) static int pcmcsa_attach(device_t dev) { - snddev_info *devinfo; struct csa_info *csa; csa_res *resp; int unit; @@ -788,7 +795,6 @@ pcmcsa_attach(device_t dev) struct ac97_info *codec; struct sndcard_func *func; - devinfo = device_get_softc(dev); csa = malloc(sizeof(*csa), M_DEVBUF, M_NOWAIT); if (csa == NULL) return (ENOMEM); @@ -820,7 +826,7 @@ pcmcsa_attach(device_t dev) codec = ac97_create(dev, csa, NULL, csa_rdcd, csa_wrcd); if (codec == NULL) return (ENXIO); - if (mixer_init(devinfo, &ac97_mixer, codec) == -1) + if (mixer_init(dev, &ac97_mixer, codec) == -1) return (ENXIO); snprintf(status, SND_STATUSLEN, "at irq %ld", rman_get_start(resp->irq)); diff --git a/sys/dev/sound/pci/ds1.c b/sys/dev/sound/pci/ds1.c index 81ecaa7724b0..1d210647e013 100644 --- a/sys/dev/sound/pci/ds1.c +++ b/sys/dev/sound/pci/ds1.c @@ -109,6 +109,7 @@ struct sc_info { bus_space_tag_t st; bus_space_handle_t sh; bus_dma_tag_t parent_dmat; + bus_dmamap_t map; struct resource *reg, *irq; int regid, irqid; @@ -216,6 +217,14 @@ static pcm_channel ds_pchantemplate = { ds1pchan_trigger, ds1pchan_getptr, ds1pchan_getcaps, + NULL, /* free */ + NULL, /* nop1 */ + NULL, /* nop2 */ + NULL, /* nop3 */ + NULL, /* nop4 */ + NULL, /* nop5 */ + NULL, /* nop6 */ + NULL, /* nop7 */ }; static pcm_channel ds_rchantemplate = { @@ -227,6 +236,14 @@ static pcm_channel ds_rchantemplate = { ds1rchan_trigger, ds1rchan_getptr, ds1rchan_getcaps, + NULL, /* free */ + NULL, /* nop1 */ + NULL, /* nop2 */ + NULL, /* nop3 */ + NULL, /* nop4 */ + NULL, /* nop5 */ + NULL, /* nop6 */ + NULL, /* nop7 */ }; /* -------------------------------------------------------------------- */ @@ -778,7 +795,6 @@ ds_init(struct sc_info *sc) u_int32_t *ci, r, pcs, rcs, ecs, ws, memsz, cb; u_int8_t *t; void *buf; - bus_dmamap_t map; ci = ds_devs[sc->type].mcode; @@ -821,9 +837,9 @@ ds_init(struct sc_info *sc) memsz += (64 + 1) * 4; if (sc->regbase == NULL) { - if (bus_dmamem_alloc(sc->parent_dmat, &buf, BUS_DMA_NOWAIT, &map)) + if (bus_dmamem_alloc(sc->parent_dmat, &buf, BUS_DMA_NOWAIT, &sc->map)) return -1; - if (bus_dmamap_load(sc->parent_dmat, map, buf, memsz, ds_setmap, sc, 0) + if (bus_dmamap_load(sc->parent_dmat, sc->map, buf, memsz, ds_setmap, sc, 0) || !sc->ctrlbase) { device_printf(sc->dev, "pcs=%d, rcs=%d, ecs=%d, ws=%d, memsz=%d\n", pcs, rcs, ecs, ws, memsz); @@ -868,6 +884,27 @@ ds_init(struct sc_info *sc) } static int +ds_uninit(struct sc_info *sc) +{ + ds_wr(sc, YDSXGR_NATIVEDACOUTVOL, 0x00000000, 4); + ds_wr(sc, YDSXGR_NATIVEADCINVOL, 0, 4); + ds_wr(sc, YDSXGR_NATIVEDACINVOL, 0, 4); + ds_enadsp(sc, 0); + ds_wr(sc, YDSXGR_MODE, 0x00010000, 4); + ds_wr(sc, YDSXGR_MAPOFREC, 0x00000000, 4); + ds_wr(sc, YDSXGR_MAPOFEFFECT, 0x00000000, 4); + ds_wr(sc, YDSXGR_PLAYCTRLBASE, 0x00000000, 4); + ds_wr(sc, YDSXGR_RECCTRLBASE, 0x00000000, 4); + ds_wr(sc, YDSXGR_EFFCTRLBASE, 0x00000000, 4); + ds_wr(sc, YDSXGR_GLOBALCTRL, 0, 2); + + bus_dmamap_unload(sc->parent_dmat, sc->map); + bus_dmamem_free(sc->parent_dmat, sc->regbase, sc->map); + + return 0; +} + +static int ds_finddev(u_int32_t dev, u_int32_t subdev) { int i; @@ -898,14 +935,12 @@ ds_pci_probe(device_t dev) static int ds_pci_attach(device_t dev) { - snddev_info *d; u_int32_t data; u_int32_t subdev, i; struct sc_info *sc; struct ac97_info *codec; char status[SND_STATUSLEN]; - d = device_get_softc(dev); if ((sc = malloc(sizeof(*sc), M_DEVBUF, M_NOWAIT)) == NULL) { device_printf(dev, "cannot allocate softc\n"); return ENXIO; @@ -952,7 +987,7 @@ ds_pci_attach(device_t dev) codec = ac97_create(dev, sc, ds_initcd, ds_rdcd, ds_wrcd); if (codec == NULL) goto bad; - mixer_init(d, &ac97_mixer, codec); + mixer_init(dev, &ac97_mixer, codec); sc->irqid = 0; sc->irq = bus_alloc_resource(dev, SYS_RES_IRQ, &sc->irqid, @@ -990,28 +1025,49 @@ bad: static int ds_pci_resume(device_t dev) { - snddev_info *d; struct sc_info *sc; - d = device_get_softc(dev); sc = pcm_getdevinfo(dev); if (ds_init(sc) == -1) { device_printf(dev, "unable to reinitialize the card\n"); return ENXIO; } - if (mixer_reinit(d) == -1) { + if (mixer_reinit(dev) == -1) { device_printf(dev, "unable to reinitialize the mixer\n"); return ENXIO; } return 0; } +static int +ds_pci_detach(device_t dev) +{ + int r; + struct sc_info *sc; + + r = pcm_unregister(dev); + if (r) + return r; + + sc = pcm_getdevinfo(dev); + ds_uninit(sc); + if (sc->reg) + bus_release_resource(dev, SYS_RES_MEMORY, sc->regid, sc->reg); + if (sc->ih) + bus_teardown_intr(dev, sc->irq, sc->ih); + if (sc->irq) + bus_release_resource(dev, SYS_RES_IRQ, sc->irqid, sc->irq); + free(sc, M_DEVBUF); + return 0; +} + static device_method_t ds1_methods[] = { /* Device interface */ DEVMETHOD(device_probe, ds_pci_probe), DEVMETHOD(device_attach, ds_pci_attach), - DEVMETHOD(device_resume, ds_pci_resume), + DEVMETHOD(device_detach, ds_pci_detach), + DEVMETHOD(device_resume, ds_pci_resume), { 0, 0 } }; diff --git a/sys/dev/sound/pci/emu10k1.c b/sys/dev/sound/pci/emu10k1.c index 584c2a7b7aed..c9e0e0f432c3 100644 --- a/sys/dev/sound/pci/emu10k1.c +++ b/sys/dev/sound/pci/emu10k1.c @@ -113,6 +113,7 @@ struct sc_info { /* channel interface */ static void *emupchan_init(void *devinfo, snd_dbuf *b, pcm_channel *c, int dir); +static int emupchan_free(void *data); static int emupchan_setdir(void *data, int dir); static int emupchan_setformat(void *data, u_int32_t format); static int emupchan_setspeed(void *data, u_int32_t speed); @@ -140,9 +141,7 @@ static int emu_init(struct sc_info *); static void emu_intr(void *); static void *emu_malloc(struct sc_info *sc, u_int32_t sz); static void *emu_memalloc(struct sc_info *sc, u_int32_t sz); -#ifdef notyet static int emu_memfree(struct sc_info *sc, void *buf); -#endif static int emu_memstart(struct sc_info *sc, void *buf); #ifdef EMUDEBUG static void emu_vdump(struct sc_info *sc, struct emu_voice *v); @@ -195,6 +194,14 @@ static pcm_channel emu_chantemplate = { emupchan_trigger, emupchan_getptr, emupchan_getcaps, + emupchan_free, /* free */ + NULL, /* nop1 */ + NULL, /* nop2 */ + NULL, /* nop3 */ + NULL, /* nop4 */ + NULL, /* nop5 */ + NULL, /* nop6 */ + NULL, /* nop7 */ }; static pcm_channel emur_chantemplate = { @@ -206,6 +213,14 @@ static pcm_channel emur_chantemplate = { emurchan_trigger, emurchan_getptr, emurchan_getcaps, + NULL, /* free */ + NULL, /* nop1 */ + NULL, /* nop2 */ + NULL, /* nop3 */ + NULL, /* nop4 */ + NULL, /* nop5 */ + NULL, /* nop6 */ + NULL, /* nop7 */ }; static int adcspeed[8] = {48000, 44100, 32000, 24000, 22050, 16000, 11025, 8000}; @@ -676,6 +691,15 @@ emupchan_init(void *devinfo, snd_dbuf *b, pcm_channel *c, int dir) } static int +emupchan_free(void *data) +{ + struct sc_pchinfo *ch = data; + struct sc_info *sc = ch->parent; + + return emu_memfree(sc, ch->buffer->buf); +} + +static int emupchan_setdir(void *data, int dir) { return 0; @@ -709,7 +733,7 @@ static int emupchan_trigger(void *data, int go) { struct sc_pchinfo *ch = data; - struct sc_info *sc = ch->parent; + struct sc_info *sc = ch->parent; if (go == PCMTRIG_EMLDMAWR || go == PCMTRIG_EMLDMARD) return 0; @@ -1039,7 +1063,6 @@ emu_memalloc(struct sc_info *sc, u_int32_t sz) return buf; } -#ifdef notyet static int emu_memfree(struct sc_info *sc, void *buf) { @@ -1064,7 +1087,6 @@ emu_memfree(struct sc_info *sc, void *buf) free(blk, M_DEVBUF); return 0; } -#endif static int emu_memstart(struct sc_info *sc, void *buf) @@ -1341,14 +1363,12 @@ emu_pci_probe(device_t dev) static int emu_pci_attach(device_t dev) { - snddev_info *d; u_int32_t data; struct sc_info *sc; struct ac97_info *codec; int i, mapped; char status[SND_STATUSLEN]; - d = device_get_softc(dev); if ((sc = malloc(sizeof(*sc), M_DEVBUF, M_NOWAIT)) == NULL) { device_printf(dev, "cannot allocate softc\n"); return ENXIO; @@ -1405,7 +1425,7 @@ emu_pci_attach(device_t dev) codec = ac97_create(dev, sc, NULL, emu_rdcd, emu_wrcd); if (codec == NULL) goto bad; - if (mixer_init(d, &ac97_mixer, codec) == -1) goto bad; + if (mixer_init(dev, &ac97_mixer, codec) == -1) goto bad; sc->irqid = 0; sc->irq = bus_alloc_resource(dev, SYS_RES_IRQ, &sc->irqid, diff --git a/sys/dev/sound/pci/es137x.c b/sys/dev/sound/pci/es137x.c index b4ce4da4581e..544ad8350f5c 100644 --- a/sys/dev/sound/pci/es137x.c +++ b/sys/dev/sound/pci/es137x.c @@ -149,6 +149,14 @@ static pcm_channel es1370_chantemplate = { eschan_trigger, eschan_getptr, eschan_getcaps, + NULL, /* free */ + NULL, /* nop1 */ + NULL, /* nop2 */ + NULL, /* nop3 */ + NULL, /* nop4 */ + NULL, /* nop5 */ + NULL, /* nop6 */ + NULL, /* nop7 */ }; static pcm_channel es1371_chantemplate = { @@ -160,6 +168,14 @@ static pcm_channel es1371_chantemplate = { eschan_trigger, eschan_getptr, eschan_getcaps, + NULL, /* free */ + NULL, /* nop1 */ + NULL, /* nop2 */ + NULL, /* nop3 */ + NULL, /* nop4 */ + NULL, /* nop5 */ + NULL, /* nop6 */ + NULL, /* nop7 */ }; /* -------------------------------------------------------------------- */ @@ -173,6 +189,7 @@ static int es1370_mixsetrecsrc(snd_mixer *m, u_int32_t src); static snd_mixer es1370_mixer = { "AudioPCI 1370 mixer", es1370_mixinit, + NULL, es1370_mixset, es1370_mixsetrecsrc, }; @@ -742,7 +759,6 @@ es_pci_probe(device_t dev) static int es_pci_attach(device_t dev) { - snddev_info *d; u_int32_t data; struct es_info *es = 0; int type = 0; @@ -756,7 +772,6 @@ es_pci_attach(device_t dev) struct ac97_info *codec; pcm_channel *ct = NULL; - d = device_get_softc(dev); if ((es = malloc(sizeof *es, M_DEVBUF, M_NOWAIT)) == NULL) { device_printf(dev, "cannot allocate softc\n"); return ENXIO; @@ -797,7 +812,7 @@ es_pci_attach(device_t dev) } if (pci_get_devid(dev) == ES1371_PCI_ID || - pci_get_devid(dev) == ES1371_PCI_ID2 || + pci_get_devid(dev) == ES1371_PCI_ID2 || pci_get_devid(dev) == ES1371_PCI_ID3) { if(-1 == es1371_init(es, pci_get_revid(dev))) { device_printf(dev, "unable to initialize the card\n"); @@ -808,14 +823,14 @@ es_pci_attach(device_t dev) /* our init routine does everything for us */ /* set to NULL; flag mixer_init not to run the ac97_init */ /* ac97_mixer.init = NULL; */ - if (mixer_init(d, &ac97_mixer, codec) == -1) goto bad; + if (mixer_init(dev, &ac97_mixer, codec) == -1) goto bad; ct = &es1371_chantemplate; } else if (pci_get_devid(dev) == ES1370_PCI_ID) { if (-1 == es1370_init(es)) { device_printf(dev, "unable to initialize the card\n"); goto bad; } - mixer_init(d, &es1370_mixer, es); + mixer_init(dev, &es1370_mixer, es); ct = &es1370_chantemplate; } else goto bad; diff --git a/sys/dev/sound/pci/fm801.c b/sys/dev/sound/pci/fm801.c index 98ddfa26eb84..8188a1d2fdd2 100644 --- a/sys/dev/sound/pci/fm801.c +++ b/sys/dev/sound/pci/fm801.c @@ -139,6 +139,14 @@ static pcm_channel fm801_chantemplate = { fm801ch_trigger, fm801ch_getptr, fm801ch_getcaps, + NULL, /* free */ + NULL, /* nop1 */ + NULL, /* nop2 */ + NULL, /* nop3 */ + NULL, /* nop4 */ + NULL, /* nop5 */ + NULL, /* nop6 */ + NULL, /* nop7 */ }; struct fm801_info; @@ -241,7 +249,7 @@ fm801_rdcd(void *devinfo, int regno) { struct fm801_info *fm801 = (struct fm801_info *)devinfo; int i; - + for (i = 0; i < TIMO && fm801_rd(fm801,FM_CODEC_CMD,2) & FM_CODEC_CMD_BUSY; i++) { DELAY(10000); DPRINT("fm801 rdcd: 1 - DELAY\n"); @@ -250,7 +258,7 @@ fm801_rdcd(void *devinfo, int regno) printf("fm801 rdcd: codec busy\n"); return 0; } - + fm801_wr(fm801,FM_CODEC_CMD, regno|FM_CODEC_CMD_READ,2); for (i = 0; i < TIMO && !(fm801_rd(fm801,FM_CODEC_CMD,2) & FM_CODEC_CMD_VALID); i++) @@ -262,7 +270,7 @@ fm801_rdcd(void *devinfo, int regno) printf("fm801 rdcd: write codec invalid\n"); return 0; } - + return fm801_rd(fm801,FM_CODEC_DATA,2); } @@ -271,11 +279,11 @@ fm801_wrcd(void *devinfo, int regno, u_int32_t data) { struct fm801_info *fm801 = (struct fm801_info *)devinfo; int i; - + DPRINT("fm801_wrcd reg 0x%x val 0x%x\n",regno, data); -/* +/* if(regno == AC97_REG_RECSEL) return; -*/ +*/ /* Poll until codec is ready */ for (i = 0; i < TIMO && fm801_rd(fm801,FM_CODEC_CMD,2) & FM_CODEC_CMD_BUSY; i++) { DELAY(10000); @@ -285,10 +293,10 @@ fm801_wrcd(void *devinfo, int regno, u_int32_t data) printf("fm801 wrcd: read codec busy\n"); return; } - + fm801_wr(fm801,FM_CODEC_DATA,data, 2); fm801_wr(fm801,FM_CODEC_CMD, regno,2); - + /* wait until codec is ready */ for (i = 0; i < TIMO && fm801_rd(fm801,FM_CODEC_CMD,2) & FM_CODEC_CMD_BUSY; i++) { DELAY(10000); @@ -302,8 +310,8 @@ fm801_wrcd(void *devinfo, int regno, u_int32_t data) return; } -/* - * The interrupt handler +/* + * The interrupt handler */ static void fm801_intr(void *p) @@ -312,11 +320,11 @@ fm801_intr(void *p) u_int32_t intsrc = fm801_rd(fm801, FM_INTSTATUS, 2); struct fm801_chinfo *ch = &(fm801->pch); snd_dbuf *b = ch->buffer; - + DPRINT("\nfm801_intr intsrc 0x%x ", intsrc); DPRINT("rp %d, rl %d, fp %d fl %d, size=%d\n", b->rp,b->rl, b->fp,b->fl, b->blksz); - + if(intsrc & FM_INTSTATUS_PLAY) { fm801->play_flip++; if(fm801->play_flip & 1) { @@ -325,7 +333,7 @@ fm801_intr(void *p) fm801_wr(fm801, FM_PLAY_DMABUF2, fm801->play_nextblk,4); chn_intr(fm801->pch.channel); } - + if(intsrc & FM_INTSTATUS_REC) { fm801->rec_flip++; if(fm801->rec_flip & 1) { @@ -334,17 +342,17 @@ fm801_intr(void *p) fm801_wr(fm801, FM_REC_DMABUF2, fm801->rec_nextblk,4); chn_intr(fm801->rch.channel); } - + if ( intsrc & FM_INTSTATUS_MPU ) { /* This is a TODOish thing... */ fm801_wr(fm801, FM_INTSTATUS, intsrc & FM_INTSTATUS_MPU,2); } - + if ( intsrc & FM_INTSTATUS_VOL ) { /* This is a TODOish thing... */ fm801_wr(fm801, FM_INTSTATUS, intsrc & FM_INTSTATUS_VOL,2); } - + DPRINT("fm801_intr clear\n\n"); fm801_wr(fm801, FM_INTSTATUS, intsrc & (FM_INTSTATUS_PLAY | FM_INTSTATUS_REC), 2); } @@ -356,20 +364,20 @@ static int fm801_init(struct fm801_info *fm801) { u_int32_t k1; - + /* reset codec */ fm801_wr(fm801, FM_CODEC_CTL, 0x0020,2); DELAY(100000); fm801_wr(fm801, FM_CODEC_CTL, 0x0000,2); DELAY(100000); - + fm801_wr(fm801, FM_PCM_VOLUME, 0x0808,2); fm801_wr(fm801, FM_FM_VOLUME, 0x0808,2); fm801_wr(fm801, FM_I2S_VOLUME, 0x0808,2); fm801_wr(fm801, 0x40,0x107f,2); /* enable legacy audio */ - + fm801_wr((void *)fm801, FM_RECORD_SOURCE, 0x0000,2); - + /* Unmask playback, record and mpu interrupts, mask the rest */ k1 = fm801_rd((void *)fm801, FM_INTMASK,2); fm801_wr(fm801, FM_INTMASK, @@ -378,7 +386,7 @@ fm801_init(struct fm801_info *fm801) fm801_wr(fm801, FM_INTSTATUS, FM_INTSTATUS_PLAY | FM_INTSTATUS_REC | FM_INTSTATUS_MPU | FM_INTSTATUS_VOL,2); - + DPRINT("FM801 init Ok\n"); return 0; } @@ -386,28 +394,26 @@ fm801_init(struct fm801_info *fm801) static int fm801_pci_attach(device_t dev) { - snddev_info *d; u_int32_t data; struct ac97_info *codec; struct fm801_info *fm801; int i; int mapped = 0; char status[SND_STATUSLEN]; - - d = device_get_softc(dev); + if ((fm801 = (struct fm801_info *)malloc(sizeof(*fm801),M_DEVBUF, M_NOWAIT)) == NULL) { device_printf(dev, "cannot allocate softc\n"); return ENXIO; } - + bzero(fm801, sizeof(*fm801)); fm801->type = pci_get_devid(dev); - + data = pci_read_config(dev, PCIR_COMMAND, 2); data |= (PCIM_CMD_PORTEN|PCIM_CMD_MEMEN|PCIM_CMD_BUSMASTEREN); pci_write_config(dev, PCIR_COMMAND, data, 2); data = pci_read_config(dev, PCIR_COMMAND, 2); - + for (i = 0; (mapped == 0) && (i < PCI_MAXMAPS_0); i++) { fm801->regid = PCIR_MAPS + i*4; fm801->regtype = SYS_RES_MEMORY; @@ -419,7 +425,7 @@ fm801_pci_attach(device_t dev) fm801->reg = bus_alloc_resource(dev, fm801->regtype, &fm801->regid, 0, ~0, 1, RF_ACTIVE); } - + if(fm801->reg) { fm801->st = rman_get_bustag(fm801->reg); fm801->sh = rman_get_bushandle(fm801->reg); @@ -431,13 +437,13 @@ fm801_pci_attach(device_t dev) device_printf(dev, "unable to map register space\n"); goto oops; } - + fm801_init(fm801); - + codec = ac97_create(dev, (void *)fm801, NULL, fm801_rdcd, fm801_wrcd); if (codec == NULL) goto oops; - if (mixer_init(d, &ac97_mixer, codec) == -1) goto oops; + if (mixer_init(dev, &ac97_mixer, codec) == -1) goto oops; fm801->irqid = 0; fm801->irq = bus_alloc_resource(dev, SYS_RES_IRQ, &fm801->irqid, @@ -448,7 +454,7 @@ fm801_pci_attach(device_t dev) device_printf(dev, "unable to map interrupt\n"); goto oops; } - + if (bus_dma_tag_create(/*parent*/NULL, /*alignment*/2, /*boundary*/0, /*lowaddr*/BUS_SPACE_MAXADDR_32BIT, /*highaddr*/BUS_SPACE_MAXADDR, @@ -458,7 +464,7 @@ fm801_pci_attach(device_t dev) device_printf(dev, "unable to create dma tag\n"); goto oops; } - + snprintf(status, 64, "at %s 0x%lx irq %ld", (fm801->regtype == SYS_RES_IOPORT)? "io" : "memory", rman_get_start(fm801->reg), rman_get_start(fm801->irq)); @@ -471,8 +477,8 @@ fm801_pci_attach(device_t dev) fm801_save(fm801); return 0; - -oops: + +oops: printf("Forte Media FM801 initialization failed\n"); if (fm801->reg) bus_release_resource(dev, fm801->regtype, fm801->regid, fm801->reg); if (fm801->ih) bus_teardown_intr(dev, fm801->irq, fm801->ih); @@ -506,7 +512,7 @@ fm801ch_init(void *devinfo, snd_dbuf *b, pcm_channel *c, int dir) { struct fm801_info *fm801 = (struct fm801_info *)devinfo; struct fm801_chinfo *ch = (dir == PCMDIR_PLAY)? &fm801->pch : &fm801->rch; - + DPRINT("fm801ch_init, direction = %d\n", dir); ch->parent = fm801; ch->channel = c; @@ -530,25 +536,25 @@ fm801ch_setformat(void *data, u_int32_t format) { struct fm801_chinfo *ch = data; struct fm801_info *fm801 = ch->parent; - + DPRINT("fm801ch_setformat 0x%x : %s, %s, %s, %s\n", format, (format & AFMT_STEREO)?"stereo":"mono", (format & (AFMT_S16_LE | AFMT_S16_BE | AFMT_U16_LE | AFMT_U16_BE)) ? "16bit":"8bit", (format & AFMT_SIGNED)? "signed":"unsigned", (format & AFMT_BIGENDIAN)?"bigendiah":"littleendian" ); - + if(ch->dir == PCMDIR_PLAY) { fm801->play_fmt = (format & AFMT_STEREO)? FM_PLAY_STEREO : 0; fm801->play_fmt |= (format & AFMT_16BIT) ? FM_PLAY_16BIT : 0; return 0; } - + if(ch->dir == PCMDIR_REC ) { fm801->rec_fmt = (format & AFMT_STEREO)? FM_REC_STEREO:0; fm801->rec_fmt |= (format & AFMT_16BIT) ? FM_PLAY_16BIT : 0; return 0; } - + return 0; } @@ -556,17 +562,17 @@ struct { int limit; int rate; } fm801_rates[11] = { - { 6600, 5500 }, - { 8750, 8000 }, - { 10250, 9600 }, - { 13200, 11025 }, - { 17500, 16000 }, - { 20500, 19200 }, - { 26500, 22050 }, - { 35000, 32000 }, - { 41000, 38400 }, - { 46000, 44100 }, - { 48000, 48000 }, + { 6600, 5500 }, + { 8750, 8000 }, + { 10250, 9600 }, + { 13200, 11025 }, + { 17500, 16000 }, + { 20500, 19200 }, + { 26500, 22050 }, + { 35000, 32000 }, + { 41000, 38400 }, + { 46000, 44100 }, + { 48000, 48000 }, /* anything above -> 48000 */ }; @@ -576,24 +582,24 @@ fm801ch_setspeed(void *data, u_int32_t speed) struct fm801_chinfo *ch = data; struct fm801_info *fm801 = ch->parent; register int i; - - + + for (i = 0; i < 10 && fm801_rates[i].limit <= speed; i++) ; - + if(ch->dir == PCMDIR_PLAY) { fm801->pch.spd = fm801_rates[i].rate; fm801->play_shift = (i<<8); fm801->play_shift &= FM_PLAY_RATE_MASK; } - + if(ch->dir == PCMDIR_REC ) { fm801->rch.spd = fm801_rates[i].rate; fm801->rec_shift = (i<<8); fm801->rec_shift &= FM_REC_RATE_MASK; } - + ch->spd = fm801_rates[i].rate; - + return fm801_rates[i].rate; } @@ -602,17 +608,17 @@ fm801ch_setblocksize(void *data, u_int32_t blocksize) { struct fm801_chinfo *ch = data; struct fm801_info *fm801 = ch->parent; - + if(ch->dir == PCMDIR_PLAY) { if(fm801->play_flip) return fm801->play_blksize; fm801->play_blksize = blocksize; } - + if(ch->dir == PCMDIR_REC) { if(fm801->rec_flip) return fm801->rec_blksize; fm801->rec_blksize = blocksize; } - + DPRINT("fm801ch_setblocksize %d (dir %d)\n",blocksize, ch->dir); return blocksize; @@ -626,18 +632,18 @@ fm801ch_trigger(void *data, int go) u_int32_t baseaddr = vtophys(ch->buffer->buf); snd_dbuf *b = ch->buffer; u_int32_t k1; - + DPRINT("fm801ch_trigger go %d , ", go); DPRINT("rp %d, rl %d, fp %d fl %d, dl %d, blksize=%d\n", b->rp,b->rl, b->fp,b->fl, b->dl, b->blksz); - + if (go == PCMTRIG_EMLDMAWR || go == PCMTRIG_EMLDMARD) { return 0; } - + if (ch->dir == PCMDIR_PLAY) { if (go == PCMTRIG_START) { - + fm801->play_start = baseaddr; fm801->play_nextblk = fm801->play_start + fm801->play_blksize; fm801->play_flip = 0; @@ -645,7 +651,7 @@ fm801ch_trigger(void *data, int go) fm801_wr(fm801, FM_PLAY_DMABUF1,fm801->play_start,4); fm801_wr(fm801, FM_PLAY_DMABUF2,fm801->play_nextblk,4); fm801_wr(fm801, FM_PLAY_CTL, - FM_PLAY_START | FM_PLAY_STOPNOW | fm801->play_fmt | fm801->play_shift, + FM_PLAY_START | FM_PLAY_STOPNOW | fm801->play_fmt | fm801->play_shift, 2 ); } else { fm801->play_flip = 0; @@ -662,8 +668,8 @@ fm801ch_trigger(void *data, int go) fm801_wr(fm801, FM_REC_DMALEN, fm801->rec_blksize - 1, 2); fm801_wr(fm801, FM_REC_DMABUF1,fm801->rec_start,4); fm801_wr(fm801, FM_REC_DMABUF2,fm801->rec_nextblk,4); - fm801_wr(fm801, FM_REC_CTL, - FM_REC_START | FM_REC_STOPNOW | fm801->rec_fmt | fm801->rec_shift, + fm801_wr(fm801, FM_REC_CTL, + FM_REC_START | FM_REC_STOPNOW | fm801->rec_fmt | fm801->rec_shift, 2 ); } else { fm801->rec_flip = 0; @@ -673,7 +679,7 @@ fm801ch_trigger(void *data, int go) FM_REC_BUF1_LAST | FM_REC_BUF2_LAST, 2); } } - + return 0; } @@ -685,21 +691,21 @@ fm801ch_getptr(void *data) struct fm801_info *fm801 = ch->parent; int result = 0; snd_dbuf *b = ch->buffer; - + if (ch->dir == PCMDIR_PLAY) { - result = fm801_rd(fm801, - (fm801->play_flip&1) ? + result = fm801_rd(fm801, + (fm801->play_flip&1) ? FM_PLAY_DMABUF2:FM_PLAY_DMABUF1, 4) - fm801->play_start; } - + if (ch->dir == PCMDIR_REC) { result = fm801_rd(fm801, (fm801->rec_flip&1) ? FM_REC_DMABUF2:FM_REC_DMABUF1, 4) - fm801->rec_start; - } - + } + DPRINT("fm801ch_getptr:%d, rp %d, rl %d, fp %d fl %d\n", - result, b->rp,b->rl, b->fp,b->fl); + result, b->rp,b->rl, b->fp,b->fl); return result; } diff --git a/sys/dev/sound/pci/neomagic.c b/sys/dev/sound/pci/neomagic.c index f7a864ffaca4..99eece841e4a 100644 --- a/sys/dev/sound/pci/neomagic.c +++ b/sys/dev/sound/pci/neomagic.c @@ -78,6 +78,7 @@ struct sc_info { /* channel interface */ static void *nmchan_init(void *devinfo, snd_dbuf *b, pcm_channel *c, int dir); +static int nmchan_free(void *data); static int nmchan_setdir(void *data, int dir); static int nmchan_setformat(void *data, u_int32_t format); static int nmchan_setspeed(void *data, u_int32_t speed); @@ -143,6 +144,14 @@ static pcm_channel nm_chantemplate = { nmchan_trigger, nmchan_getptr, nmchan_getcaps, + nmchan_free, /* free */ + NULL, /* nop1 */ + NULL, /* nop2 */ + NULL, /* nop3 */ + NULL, /* nop4 */ + NULL, /* nop5 */ + NULL, /* nop6 */ + NULL, /* nop7 */ }; /* -------------------------------------------------------------------- */ @@ -364,6 +373,12 @@ nmchan_init(void *devinfo, snd_dbuf *b, pcm_channel *c, int dir) } static int +nmchan_free(void *data) +{ + return 0; +} + +static int nmchan_setdir(void *data, int dir) { return 0; @@ -582,13 +597,11 @@ nm_pci_probe(device_t dev) static int nm_pci_attach(device_t dev) { - snddev_info *d; u_int32_t data; struct sc_info *sc; struct ac97_info *codec; char status[SND_STATUSLEN]; - d = device_get_softc(dev); if ((sc = malloc(sizeof(*sc), M_DEVBUF, M_NOWAIT)) == NULL) { device_printf(dev, "cannot allocate softc\n"); return ENXIO; @@ -622,7 +635,7 @@ nm_pci_attach(device_t dev) codec = ac97_create(dev, sc, nm_initcd, nm_rdcd, nm_wrcd); if (codec == NULL) goto bad; - if (mixer_init(d, &ac97_mixer, codec) == -1) goto bad; + if (mixer_init(dev, &ac97_mixer, codec) == -1) goto bad; sc->irqid = 0; sc->irq = bus_alloc_resource(dev, SYS_RES_IRQ, &sc->irqid, @@ -656,10 +669,8 @@ bad: static int nm_pci_resume(device_t dev) { - snddev_info *d; struct sc_info *sc; - d = device_get_softc(dev); sc = pcm_getdevinfo(dev); /* Reinit audio device */ @@ -668,7 +679,7 @@ nm_pci_resume(device_t dev) return ENXIO; } /* Reinit mixer */ - if (mixer_reinit(d) == -1) { + if (mixer_reinit(dev) == -1) { device_printf(dev, "unable to reinitialize the mixer\n"); return ENXIO; } diff --git a/sys/dev/sound/pci/solo.c b/sys/dev/sound/pci/solo.c index cd698687ec4c..58161db65fae 100644 --- a/sys/dev/sound/pci/solo.c +++ b/sys/dev/sound/pci/solo.c @@ -90,6 +90,14 @@ static pcm_channel ess_chantemplate = { esschan_trigger, esschan_getptr, esschan_getcaps, + NULL, /* free */ + NULL, /* nop1 */ + NULL, /* nop2 */ + NULL, /* nop3 */ + NULL, /* nop4 */ + NULL, /* nop5 */ + NULL, /* nop6 */ + NULL, /* nop7 */ }; struct ess_info; @@ -138,10 +146,11 @@ static int essmix_set(snd_mixer *m, unsigned dev, unsigned left, unsigned right) static int essmix_setrecsrc(snd_mixer *m, u_int32_t src); static snd_mixer ess_mixer = { - "ESS mixer", - essmix_init, - essmix_set, - essmix_setrecsrc, + "ESS mixer", + essmix_init, + NULL, + essmix_set, + essmix_setrecsrc, }; static devclass_t pcm_devclass; @@ -908,7 +917,6 @@ ess_probe(device_t dev) static int ess_attach(device_t dev) { - snddev_info *d = device_get_softc(dev); struct ess_info *sc; void *ih; char status[SND_STATUSLEN]; @@ -935,7 +943,7 @@ ess_attach(device_t dev) if (ess_reset_dsp(sc)) goto no; - mixer_init(d, &ess_mixer, sc); + mixer_init(dev, &ess_mixer, sc); port_wr(sc->io, 0x7, 0xb0, 1); /* enable irqs */ #ifdef ESS18XX_DUPLEX diff --git a/sys/dev/sound/pci/t4dwave.c b/sys/dev/sound/pci/t4dwave.c index 83b38aadcdce..f65bdb4cfc90 100644 --- a/sys/dev/sound/pci/t4dwave.c +++ b/sys/dev/sound/pci/t4dwave.c @@ -150,6 +150,14 @@ static pcm_channel tr_chantemplate = { trchan_trigger, trchan_getptr, trchan_getcaps, + NULL, /* free */ + NULL, /* nop1 */ + NULL, /* nop2 */ + NULL, /* nop3 */ + NULL, /* nop4 */ + NULL, /* nop5 */ + NULL, /* nop6 */ + NULL, /* nop7 */ }; /* -------------------------------------------------------------------- */ @@ -601,7 +609,6 @@ tr_pci_probe(device_t dev) static int tr_pci_attach(device_t dev) { - snddev_info *d; u_int32_t data; struct tr_info *tr; struct ac97_info *codec; @@ -609,7 +616,6 @@ tr_pci_attach(device_t dev) int mapped; char status[SND_STATUSLEN]; - d = device_get_softc(dev); if ((tr = malloc(sizeof(*tr), M_DEVBUF, M_NOWAIT)) == NULL) { device_printf(dev, "cannot allocate softc\n"); return ENXIO; @@ -655,7 +661,7 @@ tr_pci_attach(device_t dev) codec = ac97_create(dev, tr, NULL, tr_rdcd, tr_wrcd); if (codec == NULL) goto bad; - if (mixer_init(d, &ac97_mixer, codec) == -1) goto bad; + if (mixer_init(dev, &ac97_mixer, codec) == -1) goto bad; tr->irqid = 0; tr->irq = bus_alloc_resource(dev, SYS_RES_IRQ, &tr->irqid, diff --git a/sys/dev/sound/pci/via82c686.c b/sys/dev/sound/pci/via82c686.c index 5c9c6c51b377..14fe9bf3c707 100644 --- a/sys/dev/sound/pci/via82c686.c +++ b/sys/dev/sound/pci/via82c686.c @@ -112,6 +112,14 @@ static pcm_channel via_chantemplate = { viachan_trigger, viachan_getptr, viachan_getcaps, + NULL, /* free */ + NULL, /* nop1 */ + NULL, /* nop2 */ + NULL, /* nop3 */ + NULL, /* nop4 */ + NULL, /* nop5 */ + NULL, /* nop6 */ + NULL, /* nop7 */ }; @@ -137,7 +145,6 @@ void dma_cb(void *p, bus_dma_segment_t *bds, int a, int b) static int via_attach(device_t dev) { - snddev_info *d; struct via_info *via = 0; struct ac97_info *codec; char status[SND_STATUSLEN]; @@ -152,7 +159,6 @@ via_attach(device_t dev) u_int16_t v; bus_dmamap_t sgd_dma_map; - d = device_get_softc(dev); if ((via = malloc(sizeof *via, M_DEVBUF, M_NOWAIT)) == NULL) { device_printf(dev, "cannot allocate softc\n"); return ENXIO; @@ -199,7 +205,7 @@ via_attach(device_t dev) via_read_codec, via_write_codec); if (!codec) goto bad; - mixer_init(d, &ac97_mixer, codec); + mixer_init(dev, &ac97_mixer, codec); /* * The mixer init resets the codec. So enabling VRA must be done diff --git a/sys/dev/sound/pcm/ac97.c b/sys/dev/sound/pcm/ac97.c index 8432769934bf..296e80009ce6 100644 --- a/sys/dev/sound/pcm/ac97.c +++ b/sys/dev/sound/pcm/ac97.c @@ -386,6 +386,12 @@ ac97_create(device_t dev, void *devinfo, ac97_init *init, ac97_read *rd, ac97_wr return codec; } +void +ac97_destroy(struct ac97_info *codec) +{ + free(codec, M_DEVBUF); +} + static int ac97mix_init(snd_mixer *m) { @@ -400,6 +406,20 @@ ac97mix_init(snd_mixer *m) } static int +ac97mix_uninit(snd_mixer *m) +{ + struct ac97_info *codec = mix_getdevinfo(m); + if (codec == NULL) + return -1; + /* + if (ac97_uninitmixer(codec)) + return -1; + */ + ac97_destroy(codec); + return 0; +} + +static int ac97mix_set(snd_mixer *m, unsigned dev, unsigned left, unsigned right) { struct ac97_info *codec = mix_getdevinfo(m); @@ -424,6 +444,7 @@ ac97mix_setrecsrc(snd_mixer *m, u_int32_t src) snd_mixer ac97_mixer = { "AC97 mixer", ac97mix_init, + ac97mix_uninit, ac97mix_set, ac97mix_setrecsrc, }; diff --git a/sys/dev/sound/pcm/ac97.h b/sys/dev/sound/pcm/ac97.h index 11ff139c4849..0697cea1f5cf 100644 --- a/sys/dev/sound/pcm/ac97.h +++ b/sys/dev/sound/pcm/ac97.h @@ -72,6 +72,7 @@ struct ac97_info; struct ac97_info *ac97_create(device_t dev, void *devinfo, ac97_init *init, ac97_read *rd, ac97_write *wr); +void ac97_destroy(struct ac97_info *codec); int ac97_setrate(struct ac97_info *codec, int which, int rate); int ac97_setextmode(struct ac97_info *codec, u_int16_t mode); diff --git a/sys/dev/sound/pcm/channel.c b/sys/dev/sound/pcm/channel.c index 2e292b7f789e..af3386282d03 100644 --- a/sys/dev/sound/pcm/channel.c +++ b/sys/dev/sound/pcm/channel.c @@ -850,13 +850,20 @@ chn_dma_setmap(void *arg, bus_dma_segment_t *segs, int nseg, int error) int chn_allocbuf(snd_dbuf *b, bus_dma_tag_t parent_dmat) { - if (bus_dmamem_alloc(parent_dmat, (void **)&b->buf, + b->parent_dmat = parent_dmat; + if (bus_dmamem_alloc(b->parent_dmat, (void **)&b->buf, BUS_DMA_NOWAIT, &b->dmamap)) return -1; - if (bus_dmamap_load(parent_dmat, b->dmamap, b->buf, + if (bus_dmamap_load(b->parent_dmat, b->dmamap, b->buf, b->bufsize, chn_dma_setmap, b, 0)) return -1; return 0; } +void +chn_freebuf(snd_dbuf *b) +{ + bus_dmamem_free(b->parent_dmat, b->buf, b->dmamap); +} + static void buf_clear(snd_dbuf *b, u_int32_t fmt, int length) { @@ -1152,6 +1159,21 @@ chn_init(pcm_channel *c, void *devinfo, int dir) } int +chn_kill(pcm_channel *c) +{ + chn_trigger(c, PCMTRIG_ABORT); + while (chn_removefeeder(c) == 0); + free(c->feeder->desc, M_DEVBUF); + free(c->feeder, M_DEVBUF); + if (c->free) + c->free(c->devinfo); + else + chn_freebuf(&c->buffer); + c->flags |= CHN_F_DEAD; + return 0; +} + +int chn_setdir(pcm_channel *c, int dir) { int r; diff --git a/sys/dev/sound/pcm/channel.h b/sys/dev/sound/pcm/channel.h index 3f6a359ea70f..26857a6b3c4f 100644 --- a/sys/dev/sound/pcm/channel.h +++ b/sys/dev/sound/pcm/channel.h @@ -34,6 +34,7 @@ int chn_flush(pcm_channel *c); int chn_poll(pcm_channel *c, int ev, struct proc *p); int chn_init(pcm_channel *c, void *devinfo, int dir); +int chn_kill(pcm_channel *c); int chn_setdir(pcm_channel *c, int dir); int chn_reset(pcm_channel *c, u_int32_t fmt); int chn_setvolume(pcm_channel *c, int left, int right); @@ -46,6 +47,7 @@ pcmchan_caps *chn_getcaps(pcm_channel *c); u_int32_t chn_getformats(pcm_channel *c); int chn_allocbuf(snd_dbuf *b, bus_dma_tag_t parent_dmat); +void chn_freebuf(snd_dbuf *b); void chn_resetbuf(pcm_channel *c); void chn_intr(pcm_channel *c); void chn_checkunderflow(pcm_channel *c); diff --git a/sys/dev/sound/pcm/datatypes.h b/sys/dev/sound/pcm/datatypes.h index 6f831e5e82a5..c6343a573579 100644 --- a/sys/dev/sound/pcm/datatypes.h +++ b/sys/dev/sound/pcm/datatypes.h @@ -36,14 +36,17 @@ typedef struct _pcm_channel pcm_channel; typedef int (mix_set_t)(snd_mixer *m, unsigned dev, unsigned left, unsigned right); typedef int (mix_recsrc_t)(snd_mixer *m, u_int32_t src); typedef int (mix_init_t)(snd_mixer *m); +typedef int (mix_uninit_t)(snd_mixer *m); struct _snd_mixer { char name[64]; mix_init_t *init; + mix_uninit_t *uninit; mix_set_t *set; mix_recsrc_t *setrecsrc; void *devinfo; + int busy; u_int32_t devs; u_int32_t recdevs; u_int32_t recsrc; @@ -70,6 +73,7 @@ struct _snd_dbuf { int fmt, blksz, blkcnt; int underflow, overrun; bus_dmamap_t dmamap; + bus_dma_tag_t parent_dmat; struct selinfo sel; }; @@ -116,6 +120,7 @@ typedef int (pcmchan_setspeed_t)(void *data, u_int32_t speed); typedef int (pcmchan_setblocksize_t)(void *data, u_int32_t blocksize); typedef int (pcmchan_trigger_t)(void *data, int go); typedef int (pcmchan_getptr_t)(void *data); +typedef int (pcmchan_free_t)(void *data); typedef pcmchan_caps *(pcmchan_getcaps_t)(void *data); struct _pcm_channel { @@ -127,6 +132,15 @@ struct _pcm_channel { pcmchan_trigger_t *trigger; pcmchan_getptr_t *getptr; pcmchan_getcaps_t *getcaps; + pcmchan_free_t *free; + void *nop1; + void *nop2; + void *nop3; + void *nop4; + void *nop5; + void *nop6; + void *nop7; + pcm_feeder *feeder; struct pcm_feederdesc *feederdesc; u_int32_t align; @@ -149,7 +163,7 @@ typedef void (pcm_swap_t)(void *data, int dir); struct _snddev_info { pcm_channel *play, *rec, **aplay, **arec, fakechan; int *ref; - unsigned playcount, reccount, chancount; + unsigned playcount, reccount, chancount, maxchans; snd_mixer mixer; u_long magic; unsigned flags; diff --git a/sys/dev/sound/pcm/mixer.c b/sys/dev/sound/pcm/mixer.c index 68e45d970a9a..77d3e66e93f4 100644 --- a/sys/dev/sound/pcm/mixer.c +++ b/sys/dev/sound/pcm/mixer.c @@ -45,8 +45,9 @@ static u_int16_t snd_mixerdefaults[SOUND_MIXER_NRDEVICES] = { }; int -mixer_init(snddev_info *d, snd_mixer *m, void *devinfo) +mixer_init(device_t dev, snd_mixer *m, void *devinfo) { + snddev_info *d = device_get_softc(dev); if (d == NULL) return -1; d->mixer = *m; d->mixer.devinfo = devinfo; @@ -63,9 +64,23 @@ mixer_init(snddev_info *d, snd_mixer *m, void *devinfo) } int -mixer_reinit(snddev_info *d) +mixer_uninit(device_t dev) { int i; + snddev_info *d = device_get_softc(dev); + if (d == NULL) return -1; + for (i = 0; i < SOUND_MIXER_NRDEVICES; i++) + mixer_set(d, i, 0); + mixer_setrecsrc(d, SOUND_MASK_MIC); + if (d->mixer.uninit != NULL) d->mixer.uninit(&d->mixer); + return 0; +} + +int +mixer_reinit(device_t dev) +{ + int i; + snddev_info *d = device_get_softc(dev); if (d == NULL) return -1; if (d->mixer.init != NULL && d->mixer.init(&d->mixer) == 0) { for (i = 0; i < SOUND_MIXER_NRDEVICES; i++) @@ -75,7 +90,7 @@ mixer_reinit(snddev_info *d) } else return -1; } -int +static int mixer_set(snddev_info *d, unsigned dev, unsigned lev) { if (d == NULL || d->mixer.set == NULL) return -1; @@ -88,7 +103,7 @@ mixer_set(snddev_info *d, unsigned dev, unsigned lev) } else return -1; } -int +static int mixer_get(snddev_info *d, int dev) { if (d == NULL) return -1; @@ -97,7 +112,7 @@ mixer_get(snddev_info *d, int dev) else return -1; } -int +static int mixer_setrecsrc(snddev_info *d, u_int32_t src) { if (d == NULL || d->mixer.setrecsrc == NULL) return -1; @@ -107,7 +122,7 @@ mixer_setrecsrc(snddev_info *d, u_int32_t src) return 0; } -int +static int mixer_getrecsrc(snddev_info *d) { if (d == NULL) return -1; @@ -154,6 +169,20 @@ mixer_ioctl(snddev_info *d, u_long cmd, caddr_t arg) return ENXIO; } +int +mixer_busy(snddev_info *d, int busy) +{ + if (d == NULL) return -1; + d->mixer.busy = busy; +} + +int +mixer_isbusy(snddev_info *d) +{ + if (d == NULL) return -1; + return d->mixer.busy; +} + void mix_setdevs(snd_mixer *m, u_int32_t v) { diff --git a/sys/dev/sound/pcm/mixer.h b/sys/dev/sound/pcm/mixer.h index a0487d51fd0c..eb1946b291a5 100644 --- a/sys/dev/sound/pcm/mixer.h +++ b/sys/dev/sound/pcm/mixer.h @@ -26,13 +26,12 @@ * $FreeBSD$ */ -extern int mixer_init(snddev_info *d, snd_mixer *m, void *devinfo); -extern int mixer_reinit(snddev_info *d); -extern int mixer_set(snddev_info *d, unsigned dev, unsigned lev); -extern int mixer_get(snddev_info *d, int dev); -extern int mixer_setrecsrc(snddev_info *d, u_int32_t src); -extern int mixer_getrecsrc(snddev_info *d); +extern int mixer_init(device_t dev, snd_mixer *m, void *devinfo); +extern int mixer_uninit(device_t dev); +extern int mixer_reinit(device_t dev); extern int mixer_ioctl(snddev_info *d, u_long cmd, caddr_t arg); +extern int mixer_busy(snddev_info *d, int busy); +extern int mixer_isbusy(snddev_info *d); extern void change_bits(mixer_tab *t, u_char *regval, int dev, int chn, int newval); diff --git a/sys/dev/sound/pcm/sound.c b/sys/dev/sound/pcm/sound.c index b27e2d007e70..bd9434a408de 100644 --- a/sys/dev/sound/pcm/sound.c +++ b/sys/dev/sound/pcm/sound.c @@ -31,12 +31,11 @@ #include <sys/sysctl.h> #include "opt_devfs.h" +static dev_t status_dev = 0; static int status_isopen = 0; static int status_init(char *buf, int size); static int status_read(struct uio *buf); -MODULE_VERSION(snd_pcm, PCM_MODVER); - static d_open_t sndopen; static d_close_t sndclose; static d_ioctl_t sndioctl; @@ -94,42 +93,133 @@ int snd_unit; TUNABLE_INT_DECL("hw.sndunit", 0, snd_unit); #endif -static snddev_info * -gsd(int unit) +#ifdef DEVFS +static void +pcm_makelinks(void *dummy) { - return devclass_get_softc(pcm_devclass, unit); + int unit; + dev_t pdev; + static dev_t dsp = 0, dspW = 0, audio = 0, mixer = 0; + + if (pcm_devclass == NULL) + return; + if (dsp) { + destroy_dev(dsp); + dsp = 0; + } + if (dspW) { + destroy_dev(dspW); + dspW = 0; + } + if (audio) { + destroy_dev(audio); + audio = 0; + } + if (mixer) { + destroy_dev(mixer); + mixer = 0; + } + + unit = snd_unit; + if (unit < 0 || unit > devclass_get_maxunit(pcm_devclass)) + return; + if (devclass_get_softc(pcm_devclass, unit) == NULL) + return; + + pdev = makedev(CDEV_MAJOR, PCMMKMINOR(unit, SND_DEV_DSP, 0)); + dsp = make_dev_alias(pdev, "dsp"); + pdev = makedev(CDEV_MAJOR, PCMMKMINOR(unit, SND_DEV_DSP16, 0)); + dspW = make_dev_alias(pdev, "dspW"); + pdev = makedev(CDEV_MAJOR, PCMMKMINOR(unit, SND_DEV_AUDIO, 0)); + audio = make_dev_alias(pdev, "audio"); + pdev = makedev(CDEV_MAJOR, PCMMKMINOR(unit, SND_DEV_CTL, 0)); + mixer = make_dev_alias(pdev, "mixer"); } +static int +sysctl_hw_sndunit(SYSCTL_HANDLER_ARGS) +{ + int error, unit; + + unit = snd_unit; + error = sysctl_handle_int(oidp, &unit, sizeof(unit), req); + if (error == 0 && req->newptr != NULL) { + snd_unit = unit; + pcm_makelinks(NULL); + } + return (error); +} +SYSCTL_PROC(_hw, OID_AUTO, sndunit, CTLTYPE_INT | CTLFLAG_RW, + 0, sizeof(int), sysctl_hw_sndunit, "I", ""); +#endif + int pcm_addchan(device_t dev, int dir, pcm_channel *templ, void *devinfo) { - int unit = device_get_unit(dev); + int unit = device_get_unit(dev), idx; snddev_info *d = device_get_softc(dev); - pcm_channel *ch; + pcm_channel *chns, *ch; + char *dirs; + + dirs = ((dir == PCMDIR_PLAY)? "play" : "record"); + chns = ((dir == PCMDIR_PLAY)? d->play : d->rec); + idx = ((dir == PCMDIR_PLAY)? d->playcount++ : d->reccount++); - if (((dir == PCMDIR_PLAY)? d->play : d->rec) == NULL) { - device_printf(dev, "bad channel add (%s)\n", - (dir == PCMDIR_PLAY)? "play" : "record"); + if (chns == NULL) { + device_printf(dev, "bad channel add (%s:%d)\n", dirs, idx); return 1; } - ch = (dir == PCMDIR_PLAY)? &d->play[d->playcount] : &d->rec[d->reccount]; + ch = &chns[idx]; *ch = *templ; ch->parent = d; if (chn_init(ch, devinfo, dir)) { - device_printf(dev, "chn_init() for %s:%d failed\n", - (dir == PCMDIR_PLAY)? "play" : "record", - (dir == PCMDIR_PLAY)? d->playcount : d->reccount); + device_printf(dev, "chn_init() for (%s:%d) failed\n", dirs, idx); return 1; } - if (dir == PCMDIR_PLAY) d->playcount++; else d->reccount++; make_dev(&snd_cdevsw, PCMMKMINOR(unit, SND_DEV_DSP, d->chancount), UID_ROOT, GID_WHEEL, 0666, "dsp%d.%d", unit, d->chancount); - make_dev(&snd_cdevsw, PCMMKMINOR(unit, SND_DEV_AUDIO, d->chancount), - UID_ROOT, GID_WHEEL, 0666, "audio%d.%d", unit, d->chancount); make_dev(&snd_cdevsw, PCMMKMINOR(unit, SND_DEV_DSP16, d->chancount), UID_ROOT, GID_WHEEL, 0666, "dspW%d.%d", unit, d->chancount); + make_dev(&snd_cdevsw, PCMMKMINOR(unit, SND_DEV_AUDIO, d->chancount), + UID_ROOT, GID_WHEEL, 0666, "audio%d.%d", unit, d->chancount); /* XXX SND_DEV_NORESET? */ d->chancount++; +#ifdef DEVFS + if (d->chancount == d->maxchans) + pcm_makelinks(NULL); +#endif + return 0; +} + +static int +pcm_killchan(device_t dev, int dir) +{ + int unit = device_get_unit(dev), idx; + snddev_info *d = device_get_softc(dev); + pcm_channel *chns, *ch; + char *dirs; + dev_t pdev; + + dirs = ((dir == PCMDIR_PLAY)? "play" : "record"); + chns = ((dir == PCMDIR_PLAY)? d->play : d->rec); + idx = ((dir == PCMDIR_PLAY)? --d->playcount : --d->reccount); + + if (chns == NULL || idx < 0) { + device_printf(dev, "bad channel kill (%s:%d)\n", dirs, idx); + return 1; + } + ch = &chns[idx]; + if (chn_kill(ch)) { + device_printf(dev, "chn_kill() for (%s:%d) failed\n", dirs, idx); + return 1; + } + d->chancount--; + pdev = makedev(CDEV_MAJOR, PCMMKMINOR(unit, SND_DEV_DSP, d->chancount)); + destroy_dev(pdev); + pdev = makedev(CDEV_MAJOR, PCMMKMINOR(unit, SND_DEV_DSP16, d->chancount)); + destroy_dev(pdev); + pdev = makedev(CDEV_MAJOR, PCMMKMINOR(unit, SND_DEV_AUDIO, d->chancount)); + destroy_dev(pdev); return 0; } @@ -168,6 +258,7 @@ pcm_setswap(device_t dev, pcm_swap_t *swap) snddev_info *d = device_get_softc(dev); d->swap = swap; } + /* This is the generic init routine */ int pcm_register(device_t dev, void *devinfo, int numplay, int numrec) @@ -177,7 +268,7 @@ pcm_register(device_t dev, void *devinfo, int numplay, int numrec) if (!pcm_devclass) { pcm_devclass = device_get_devclass(dev); - make_dev(&snd_cdevsw, PCMMKMINOR(0, SND_DEV_STATUS, 0), + status_dev = make_dev(&snd_cdevsw, PCMMKMINOR(0, SND_DEV_STATUS, 0), UID_ROOT, GID_WHEEL, 0444, "sndstat"); } make_dev(&snd_cdevsw, PCMMKMINOR(unit, SND_DEV_CTL, 0), @@ -185,6 +276,7 @@ pcm_register(device_t dev, void *devinfo, int numplay, int numrec) d->dev = dev; d->devinfo = devinfo; d->chancount = d->playcount = d->reccount = 0; + d->maxchans = numplay + numrec; sz = (numplay + numrec) * sizeof(pcm_channel *); if (sz > 0) { @@ -232,67 +324,44 @@ no: if (d->play) free(d->play, M_DEVBUF); if (d->arec) free(d->arec, M_DEVBUF); if (d->rec) free(d->rec, M_DEVBUF); + if (d->ref) free(d->ref, M_DEVBUF); return ENXIO; } -#ifdef DEVFS -static void -pcm_makelinks(void *dummy) +int +pcm_unregister(device_t dev) { - int unit; + int r, i, unit = device_get_unit(dev); + snddev_info *d = device_get_softc(dev); dev_t pdev; - static dev_t dsp = 0, dspW = 0, audio = 0, mixer = 0; - unit = snd_unit; - if (unit > devclass_get_maxunit(pcm_devclass)) - unit = -1; + r = 0; + for (i = 0; i < d->chancount; i++) + if (d->ref[i]) r = EBUSY; + if (r) return r; + if (mixer_isbusy(d) || status_isopen) return EBUSY; - if (dsp) { - destroy_dev(dsp); - dsp = 0; - } - if (dspW) { - destroy_dev(dspW); - dspW = 0; - } - if (audio) { - destroy_dev(audio); - audio = 0; - } - if (mixer) { - destroy_dev(mixer); - mixer = 0; - } + pdev = makedev(CDEV_MAJOR, PCMMKMINOR(unit, SND_DEV_CTL, 0)); + destroy_dev(pdev); + mixer_uninit(dev); - if (unit >= 0) { - pdev = makedev(CDEV_MAJOR, PCMMKMINOR(unit, SND_DEV_DSP, 0)); - dsp = make_dev_alias(pdev, "dsp"); - pdev = makedev(CDEV_MAJOR, PCMMKMINOR(unit, SND_DEV_DSP16, 0)); - dspW = make_dev_alias(pdev, "dspW"); - pdev = makedev(CDEV_MAJOR, PCMMKMINOR(unit, SND_DEV_AUDIO, 0)); - audio = make_dev_alias(pdev, "audio"); - pdev = makedev(CDEV_MAJOR, PCMMKMINOR(unit, SND_DEV_CTL, 0)); - mixer = make_dev_alias(pdev, "mixer"); - } -} -SYSINIT(pcm_makelinks, SI_SUB_MOUNT_ROOT, SI_ORDER_ANY, pcm_makelinks, NULL); + while (d->playcount > 0) + pcm_killchan(dev, PCMDIR_PLAY); + while (d->reccount > 0) + pcm_killchan(dev, PCMDIR_REC); + d->magic = 0; -static int -sysctl_hw_sndunit(SYSCTL_HANDLER_ARGS) -{ - int error, unit; + if (d->aplay) free(d->aplay, M_DEVBUF); + if (d->play) free(d->play, M_DEVBUF); + if (d->arec) free(d->arec, M_DEVBUF); + if (d->rec) free(d->rec, M_DEVBUF); + if (d->ref) free(d->ref, M_DEVBUF); - unit = snd_unit; - error = sysctl_handle_int(oidp, &unit, sizeof(unit), req); - if (error == 0 && req->newptr != NULL) { - snd_unit = unit; - pcm_makelinks(NULL); - } - return (error); -} -SYSCTL_PROC(_hw, OID_AUTO, sndunit, CTLTYPE_INT | CTLFLAG_RW, - 0, sizeof(int), sysctl_hw_sndunit, "I", ""); +#ifdef DEVFS + pcm_makelinks(NULL); #endif + return 0; +} /* * a small utility function which, given a device number, returns @@ -302,6 +371,7 @@ SYSCTL_PROC(_hw, OID_AUTO, sndunit, CTLTYPE_INT | CTLFLAG_RW, static snddev_info * get_snddev_info(dev_t i_dev, int *unit, int *dev, int *chan) { + snddev_info *sc; int u, d, c; u = PCMUNIT(i_dev); @@ -313,13 +383,16 @@ get_snddev_info(dev_t i_dev, int *unit, int *dev, int *chan) if (chan) *chan = c; if (u < 0) return NULL; - switch(d) { + sc = devclass_get_softc(pcm_devclass, u); + if (sc == NULL || sc->magic == 0) return NULL; + + switch(d) { case SND_DEV_CTL: /* /dev/mixer handled by pcm */ case SND_DEV_STATUS: /* /dev/sndstat handled by pcm */ case SND_DEV_DSP: case SND_DEV_DSP16: case SND_DEV_AUDIO: - return gsd(u); + return sc; case SND_DEV_SEQ: /* XXX when enabled... */ case SND_DEV_SEQ2: @@ -347,7 +420,7 @@ sndopen(dev_t i_dev, int flags, int mode, struct proc *p) return 0; case SND_DEV_CTL: - return d? 0 : ENXIO; + return d? mixer_busy(d, 1) : ENXIO; case SND_DEV_AUDIO: case SND_DEV_DSP: @@ -375,7 +448,7 @@ sndclose(dev_t i_dev, int flags, int mode, struct proc *p) return 0; case SND_DEV_CTL: - return d? 0 : ENXIO; + return d? mixer_busy(d, 0) : ENXIO; case SND_DEV_AUDIO: case SND_DEV_DSP: @@ -521,7 +594,7 @@ status_init(char *buf, int size) "Installed devices:\n", __DATE__, __TIME__); for (i = 0; i <= devclass_get_maxunit(pcm_devclass); i++) { - d = gsd(i); + d = devclass_get_softc(pcm_devclass, i); if (!d) continue; dev = devclass_get_device(pcm_devclass, i); if (1) { @@ -558,3 +631,29 @@ status_read(struct uio *buf) bufptr += l; return (l > 0)? uiomove(status_buf + bufptr - l, l, buf) : 0; } + +static int +sndpcm_modevent(module_t mod, int type, void *data) +{ + + switch (type) { + case MOD_LOAD: + break; + case MOD_UNLOAD: + if (status_dev) + destroy_dev(status_dev); + status_dev = 0; + break; + default: + break; + } + return 0; +} + +static moduledata_t sndpcm_mod = { + "snd_pcm", + sndpcm_modevent, + NULL +}; +DECLARE_MODULE(snd_pcm, sndpcm_mod, SI_SUB_DRIVERS, SI_ORDER_MIDDLE); +MODULE_VERSION(snd_pcm, PCM_MODVER); diff --git a/sys/dev/sound/pcm/sound.h b/sys/dev/sound/pcm/sound.h index 0e5092678537..4bc388eec406 100644 --- a/sys/dev/sound/pcm/sound.h +++ b/sys/dev/sound/pcm/sound.h @@ -165,6 +165,7 @@ int fkchan_setup(pcm_channel *c); int pcm_addchan(device_t dev, int dir, pcm_channel *templ, void *devinfo); int pcm_register(device_t dev, void *devinfo, int numplay, int numrec); +int pcm_unregister(device_t dev); int pcm_setstatus(device_t dev, char *str); u_int32_t pcm_getflags(device_t dev); void pcm_setflags(device_t dev, u_int32_t val); |