From 1f7a6325fe1b628c18b51d94eeec879c38c650b8 Mon Sep 17 00:00:00 2001 From: Alexander Motin Date: Sat, 4 Sep 2021 18:22:53 -0400 Subject: [PATCH] sound(4): Remove pointless Giant from bus_dma_tag_create(). None of the drivers really implement asynchronous buffer loading, so they don't need lock there. The only question is which of them have BUS_DMA_NOWAIT flag there already, and to which it should be added. --- sys/dev/sound/isa/ad1816.c | 4 ++-- sys/dev/sound/isa/ess.c | 4 ++-- sys/dev/sound/isa/mss.c | 2 +- sys/dev/sound/isa/sb16.c | 2 +- sys/dev/sound/isa/sb8.c | 2 +- sys/dev/sound/pci/aureal.c | 4 ++-- sys/dev/sound/pci/cs4281.c | 4 ++-- sys/dev/sound/pci/csapcm.c | 4 ++-- sys/dev/sound/pci/emu10k1.c | 8 ++++---- sys/dev/sound/pci/emu10kx.c | 4 ++-- sys/dev/sound/pci/envy24.c | 10 ++++++---- sys/dev/sound/pci/fm801.c | 4 ++-- sys/dev/sound/pci/hdspe.c | 16 ++++++++-------- sys/dev/sound/pci/maestro.c | 8 ++++---- sys/dev/sound/pci/solo.c | 29 +---------------------------- sys/dev/sound/pci/t4dwave.c | 4 ++-- sys/dev/sound/pci/vibes.c | 4 ++-- sys/dev/sound/pcm/buffer.c | 2 +- 18 files changed, 45 insertions(+), 70 deletions(-) diff --git a/sys/dev/sound/isa/ad1816.c b/sys/dev/sound/isa/ad1816.c index e8d7ac7cf62f..97da82c21ff5 100644 --- a/sys/dev/sound/isa/ad1816.c +++ b/sys/dev/sound/isa/ad1816.c @@ -620,8 +620,8 @@ ad1816_attach(device_t dev) /*filter*/NULL, /*filterarg*/NULL, /*maxsize*/ad1816->bufsize, /*nsegments*/1, /*maxsegz*/0x3ffff, - /*flags*/0, /*lockfunc*/busdma_lock_mutex, - /*lockarg*/ &Giant, &ad1816->parent_dmat) != 0) { + /*flags*/0, /*lockfunc*/NULL, /*lockarg*/NULL, + &ad1816->parent_dmat) != 0) { device_printf(dev, "unable to create dma tag\n"); goto no; } diff --git a/sys/dev/sound/isa/ess.c b/sys/dev/sound/isa/ess.c index 424e757a4b00..46405ec48aac 100644 --- a/sys/dev/sound/isa/ess.c +++ b/sys/dev/sound/isa/ess.c @@ -859,8 +859,8 @@ ess_attach(device_t dev) /*filter*/NULL, /*filterarg*/NULL, /*maxsize*/sc->bufsize, /*nsegments*/1, /*maxsegz*/0x3ffff, - /*flags*/0, /*lockfunc*/busdma_lock_mutex, - /*lockarg*/&Giant, &sc->parent_dmat) != 0) { + /*flags*/0, /*lockfunc*/NULL, /*lockarg*/NULL, + &sc->parent_dmat) != 0) { device_printf(dev, "unable to create dma tag\n"); goto no; } diff --git a/sys/dev/sound/isa/mss.c b/sys/dev/sound/isa/mss.c index eacbbf85849c..745a20dbf1f0 100644 --- a/sys/dev/sound/isa/mss.c +++ b/sys/dev/sound/isa/mss.c @@ -1732,7 +1732,7 @@ mss_doattach(device_t dev, struct mss_info *mss) /*filter*/NULL, /*filterarg*/NULL, /*maxsize*/mss->bufsize, /*nsegments*/1, /*maxsegz*/0x3ffff, /*flags*/0, - /*lockfunc*/busdma_lock_mutex, /*lockarg*/&Giant, + /*lockfunc*/NULL, /*lockarg*/NULL, &mss->parent_dmat) != 0) { device_printf(dev, "unable to create dma tag\n"); goto no; diff --git a/sys/dev/sound/isa/sb16.c b/sys/dev/sound/isa/sb16.c index 73ec7c56245e..38e15a427d50 100644 --- a/sys/dev/sound/isa/sb16.c +++ b/sys/dev/sound/isa/sb16.c @@ -846,7 +846,7 @@ sb16_attach(device_t dev) /*filter*/NULL, /*filterarg*/NULL, /*maxsize*/sb->bufsize, /*nsegments*/1, /*maxsegz*/0x3ffff, /*flags*/0, - /*lockfunc*/busdma_lock_mutex, /*lockarg*/&Giant, + /*lockfunc*/NULL, /*lockarg*/NULL, &sb->parent_dmat) != 0) { device_printf(dev, "unable to create dma tag\n"); goto no; diff --git a/sys/dev/sound/isa/sb8.c b/sys/dev/sound/isa/sb8.c index 779c6631b264..3fcc1770e136 100644 --- a/sys/dev/sound/isa/sb8.c +++ b/sys/dev/sound/isa/sb8.c @@ -743,7 +743,7 @@ sb_attach(device_t dev) /*filter*/NULL, /*filterarg*/NULL, /*maxsize*/sb->bufsize, /*nsegments*/1, /*maxsegz*/0x3ffff, /*flags*/0, - /*lockfunc*/busdma_lock_mutex, /*lockarg*/&Giant, + /*lockfunc*/NULL, /*lockarg*/NULL, &sb->parent_dmat) != 0) { device_printf(dev, "unable to create dma tag\n"); goto no; diff --git a/sys/dev/sound/pci/aureal.c b/sys/dev/sound/pci/aureal.c index f4b9906e20e0..820e603192af 100644 --- a/sys/dev/sound/pci/aureal.c +++ b/sys/dev/sound/pci/aureal.c @@ -642,8 +642,8 @@ au_pci_attach(device_t dev) /*highaddr*/BUS_SPACE_MAXADDR, /*filter*/NULL, /*filterarg*/NULL, /*maxsize*/AU_BUFFSIZE, /*nsegments*/1, /*maxsegz*/0x3ffff, - /*flags*/0, /*lockfunc*/busdma_lock_mutex, - /*lockarg*/&Giant, &au->parent_dmat) != 0) { + /*flags*/0, /*lockfunc*/NULL, /*lockarg*/NULL, + &au->parent_dmat) != 0) { device_printf(dev, "unable to create dma tag\n"); goto bad; } diff --git a/sys/dev/sound/pci/cs4281.c b/sys/dev/sound/pci/cs4281.c index fe73e14edb29..b955a6284800 100644 --- a/sys/dev/sound/pci/cs4281.c +++ b/sys/dev/sound/pci/cs4281.c @@ -823,8 +823,8 @@ cs4281_pci_attach(device_t dev) /*filter*/NULL, /*filterarg*/NULL, /*maxsize*/sc->bufsz, /*nsegments*/1, /*maxsegz*/0x3ffff, - /*flags*/0, /*lockfunc*/busdma_lock_mutex, - /*lockarg*/&Giant, &sc->parent_dmat) != 0) { + /*flags*/0, /*lockfunc*/NULL, /*lockarg*/NULL, + &sc->parent_dmat) != 0) { device_printf(dev, "unable to create dma tag\n"); goto bad; } diff --git a/sys/dev/sound/pci/csapcm.c b/sys/dev/sound/pci/csapcm.c index a0b35c909931..7fd55291d876 100644 --- a/sys/dev/sound/pci/csapcm.c +++ b/sys/dev/sound/pci/csapcm.c @@ -716,8 +716,8 @@ csa_allocres(struct csa_info *csa, device_t dev) /*highaddr*/BUS_SPACE_MAXADDR, /*filter*/NULL, /*filterarg*/NULL, /*maxsize*/CS461x_BUFFSIZE, /*nsegments*/1, /*maxsegz*/0x3ffff, - /*flags*/0, /*lockfunc*/busdma_lock_mutex, - /*lockarg*/&Giant, &csa->parent_dmat) != 0) + /*flags*/0, /*lockfunc*/NULL, /*lockarg*/NULL, + &csa->parent_dmat) != 0) return (1); return (0); diff --git a/sys/dev/sound/pci/emu10k1.c b/sys/dev/sound/pci/emu10k1.c index 9ee71ed96847..c8829a4017e3 100644 --- a/sys/dev/sound/pci/emu10k1.c +++ b/sys/dev/sound/pci/emu10k1.c @@ -1328,8 +1328,8 @@ emu_malloc(struct sc_info *sc, u_int32_t sz, bus_addr_t *addr, *addr = 0; if (bus_dmamem_alloc(sc->parent_dmat, &buf, BUS_DMA_NOWAIT, map)) return NULL; - if (bus_dmamap_load(sc->parent_dmat, *map, buf, sz, emu_setmap, addr, 0) - || !*addr) { + if (bus_dmamap_load(sc->parent_dmat, *map, buf, sz, emu_setmap, addr, + BUS_DMA_NOWAIT) || !*addr) { bus_dmamem_free(sc->parent_dmat, buf, *map); return NULL; } @@ -2107,8 +2107,8 @@ emu_pci_attach(device_t dev) /*highaddr*/BUS_SPACE_MAXADDR, /*filter*/NULL, /*filterarg*/NULL, /*maxsize*/sc->bufsz, /*nsegments*/1, /*maxsegz*/0x3ffff, - /*flags*/0, /*lockfunc*/busdma_lock_mutex, - /*lockarg*/&Giant, &sc->parent_dmat) != 0) { + /*flags*/0, /*lockfunc*/NULL, /*lockarg*/NULL, + &sc->parent_dmat) != 0) { device_printf(dev, "unable to create dma tag\n"); goto bad; } diff --git a/sys/dev/sound/pci/emu10kx.c b/sys/dev/sound/pci/emu10kx.c index 5ae760845008..611af91de4d4 100644 --- a/sys/dev/sound/pci/emu10kx.c +++ b/sys/dev/sound/pci/emu10kx.c @@ -2700,8 +2700,8 @@ emu_init(struct emu_sc_info *sc) /* highaddr */ BUS_SPACE_MAXADDR, /* filter */ NULL, /* filterarg */ NULL, /* maxsize */ EMU_MAX_BUFSZ, /* nsegments */ 1, /* maxsegz */ 0x3ffff, - /* flags */ 0, /* lockfunc */ busdma_lock_mutex, - /* lockarg */ &Giant, &(sc->mem.dmat)) != 0) { + /* flags */ 0, /* lockfunc */NULL, /* lockarg */NULL, + &sc->mem.dmat) != 0) { device_printf(sc->dev, "unable to create dma tag\n"); bus_dma_tag_destroy(sc->mem.dmat); return (ENOMEM); diff --git a/sys/dev/sound/pci/envy24.c b/sys/dev/sound/pci/envy24.c index a6cb28ab6040..36f453bd9252 100644 --- a/sys/dev/sound/pci/envy24.c +++ b/sys/dev/sound/pci/envy24.c @@ -2264,12 +2264,14 @@ envy24_dmainit(struct sc_info *sc) #if(0) device_printf(sc->dev, "envy24_dmainit(): bus_dmamem_load(): sc->pmap\n"); #endif - if (bus_dmamap_load(sc->dmat, sc->pmap, sc->pbuf, sc->psize, envy24_dmapsetmap, sc, 0)) + if (bus_dmamap_load(sc->dmat, sc->pmap, sc->pbuf, sc->psize, + envy24_dmapsetmap, sc, BUS_DMA_NOWAIT)) goto bad; #if(0) device_printf(sc->dev, "envy24_dmainit(): bus_dmamem_load(): sc->rmap\n"); #endif - if (bus_dmamap_load(sc->dmat, sc->rmap, sc->rbuf, sc->rsize, envy24_dmarsetmap, sc, 0)) + if (bus_dmamap_load(sc->dmat, sc->rmap, sc->rbuf, sc->rsize, + envy24_dmarsetmap, sc, BUS_DMA_NOWAIT)) goto bad; bzero(sc->pbuf, sc->psize); bzero(sc->rbuf, sc->rsize); @@ -2534,8 +2536,8 @@ envy24_alloc_resource(struct sc_info *sc) /*filter*/NULL, /*filterarg*/NULL, /*maxsize*/BUS_SPACE_MAXSIZE_ENVY24, /*nsegments*/1, /*maxsegsz*/0x3ffff, - /*flags*/0, /*lockfunc*/busdma_lock_mutex, - /*lockarg*/&Giant, &sc->dmat) != 0) { + /*flags*/0, /*lockfunc*/NULL, /*lockarg*/NULL, + &sc->dmat) != 0) { device_printf(sc->dev, "unable to create dma tag\n"); return ENXIO; } diff --git a/sys/dev/sound/pci/fm801.c b/sys/dev/sound/pci/fm801.c index 886d50f27fe7..3a7e0877ae7a 100644 --- a/sys/dev/sound/pci/fm801.c +++ b/sys/dev/sound/pci/fm801.c @@ -632,8 +632,8 @@ fm801_pci_attach(device_t dev) /*highaddr*/BUS_SPACE_MAXADDR, /*filter*/NULL, /*filterarg*/NULL, /*maxsize*/fm801->bufsz, /*nsegments*/1, /*maxsegz*/0x3ffff, - /*flags*/0, /*lockfunc*/busdma_lock_mutex, - /*lockarg*/&Giant, &fm801->parent_dmat) != 0) { + /*flags*/0, /*lockfunc*/NULL, /*lockarg*/NULL, + &fm801->parent_dmat) != 0) { device_printf(dev, "unable to create dma tag\n"); goto oops; } diff --git a/sys/dev/sound/pci/hdspe.c b/sys/dev/sound/pci/hdspe.c index 6eb0436816a6..f91e6f6d4931 100644 --- a/sys/dev/sound/pci/hdspe.c +++ b/sys/dev/sound/pci/hdspe.c @@ -172,8 +172,8 @@ hdspe_alloc_resources(struct sc_info *sc) /*nsegments*/2, /*maxsegsz*/HDSPE_DMASEGSIZE, /*flags*/0, - /*lockfunc*/busdma_lock_mutex, - /*lockarg*/&Giant, + /*lockfunc*/NULL, + /*lockarg*/NULL, /*dmatag*/&sc->dmat) != 0) { device_printf(sc->dev, "Unable to create dma tag.\n"); return (ENXIO); @@ -182,27 +182,27 @@ hdspe_alloc_resources(struct sc_info *sc) sc->bufsize = HDSPE_DMASEGSIZE; /* pbuf (play buffer). */ - if (bus_dmamem_alloc(sc->dmat, (void **)&sc->pbuf, - BUS_DMA_NOWAIT, &sc->pmap)) { + if (bus_dmamem_alloc(sc->dmat, (void **)&sc->pbuf, BUS_DMA_WAITOK, + &sc->pmap)) { device_printf(sc->dev, "Can't alloc pbuf.\n"); return (ENXIO); } if (bus_dmamap_load(sc->dmat, sc->pmap, sc->pbuf, sc->bufsize, - hdspe_dmapsetmap, sc, 0)) { + hdspe_dmapsetmap, sc, BUS_DMA_NOWAIT)) { device_printf(sc->dev, "Can't load pbuf.\n"); return (ENXIO); } /* rbuf (rec buffer). */ - if (bus_dmamem_alloc(sc->dmat, (void **)&sc->rbuf, - BUS_DMA_NOWAIT, &sc->rmap)) { + if (bus_dmamem_alloc(sc->dmat, (void **)&sc->rbuf, BUS_DMA_WAITOK, + &sc->rmap)) { device_printf(sc->dev, "Can't alloc rbuf.\n"); return (ENXIO); } if (bus_dmamap_load(sc->dmat, sc->rmap, sc->rbuf, sc->bufsize, - hdspe_dmapsetmap, sc, 0)) { + hdspe_dmapsetmap, sc, BUS_DMA_NOWAIT)) { device_printf(sc->dev, "Can't load rbuf.\n"); return (ENXIO); } diff --git a/sys/dev/sound/pci/maestro.c b/sys/dev/sound/pci/maestro.c index ed1c9ef1cad6..3caccdb12fe9 100644 --- a/sys/dev/sound/pci/maestro.c +++ b/sys/dev/sound/pci/maestro.c @@ -1716,8 +1716,8 @@ dma_malloc(bus_dma_tag_t dmat, u_int32_t sz, bus_addr_t *phys, if (bus_dmamem_alloc(dmat, &buf, BUS_DMA_NOWAIT, map)) return NULL; - if (bus_dmamap_load(dmat, *map, buf, sz, setmap, phys, 0) != 0 || - *phys == 0) { + if (bus_dmamap_load(dmat, *map, buf, sz, setmap, phys, + BUS_DMA_NOWAIT) != 0 || *phys == 0) { bus_dmamem_free(dmat, buf, *map); return NULL; } @@ -1793,7 +1793,7 @@ agg_attach(device_t dev) /*filter*/ NULL, NULL, /*size */ ess->bufsz, 1, 0x3ffff, /*flags */ 0, - /*lock */ busdma_lock_mutex, &Giant, + /*lock */ NULL, NULL, &ess->buf_dmat) != 0) { device_printf(dev, "unable to create dma tag\n"); ret = ENOMEM; @@ -1807,7 +1807,7 @@ agg_attach(device_t dev) /*filter*/ NULL, NULL, /*size */ 3*ess->bufsz, 1, 0x3ffff, /*flags */ 0, - /*lock */ busdma_lock_mutex, &Giant, + /*lock */ NULL, NULL, &ess->stat_dmat) != 0) { device_printf(dev, "unable to create dma tag\n"); ret = ENOMEM; diff --git a/sys/dev/sound/pci/solo.c b/sys/dev/sound/pci/solo.c index 6d5b833264d6..7132a7f34dee 100644 --- a/sys/dev/sound/pci/solo.c +++ b/sys/dev/sound/pci/solo.c @@ -50,9 +50,6 @@ SND_DECLARE_FILE("$FreeBSD$"); /* more accurate clocks and split audio1/audio2 rates */ #define ESS18XX_NEWSPEED -/* 1 = INTR_MPSAFE, 0 = GIANT */ -#define ESS18XX_MPSAFE 1 - static u_int32_t ess_playfmt[] = { SND_FORMAT(AFMT_U8, 1, 0), SND_FORMAT(AFMT_U8, 2, 0), @@ -103,20 +100,12 @@ struct ess_info { unsigned int bufsz; struct ess_chinfo pch, rch; -#if ESS18XX_MPSAFE == 1 struct mtx *lock; -#endif }; -#if ESS18XX_MPSAFE == 1 #define ess_lock(_ess) snd_mtxlock((_ess)->lock) #define ess_unlock(_ess) snd_mtxunlock((_ess)->lock) #define ess_lock_assert(_ess) snd_mtxassert((_ess)->lock) -#else -#define ess_lock(_ess) -#define ess_unlock(_ess) -#define ess_lock_assert(_ess) -#endif static int ess_rd(struct ess_info *sc, int reg); static void ess_wr(struct ess_info *sc, int reg, u_int8_t val); @@ -868,12 +857,10 @@ ess_release_resources(struct ess_info *sc, device_t dev) sc->parent_dmat = 0; } -#if ESS18XX_MPSAFE == 1 if (sc->lock) { snd_mtxfree(sc->lock); sc->lock = NULL; } -#endif free(sc, M_DEVBUF); } @@ -902,14 +889,10 @@ ess_alloc_resources(struct ess_info *sc, device_t dev) sc->irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid, RF_ACTIVE | RF_SHAREABLE); -#if ESS18XX_MPSAFE == 1 sc->lock = snd_mtxcreate(device_get_nameunit(dev), "snd_solo softc"); return (sc->irq && sc->io && sc->sb && sc->vc && sc->mpu && sc->gp && sc->lock)? 0 : ENXIO; -#else - return (sc->irq && sc->io && sc->sb && sc->vc && sc->mpu && sc->gp)? 0 : ENXIO; -#endif } static int @@ -1008,13 +991,7 @@ ess_attach(device_t dev) #else sc->newspeed = 0; #endif - if (snd_setup_intr(dev, sc->irq, -#if ESS18XX_MPSAFE == 1 - INTR_MPSAFE -#else - 0 -#endif - , ess_intr, sc, &sc->ih)) { + if (snd_setup_intr(dev, sc->irq, INTR_MPSAFE, ess_intr, sc, &sc->ih)) { device_printf(dev, "unable to map interrupt\n"); goto no; } @@ -1032,11 +1009,7 @@ ess_attach(device_t dev) /*maxsize*/sc->bufsz, /*nsegments*/1, /*maxsegz*/0x3ffff, /*flags*/0, -#if ESS18XX_MPSAFE == 1 /*lockfunc*/NULL, /*lockarg*/NULL, -#else - /*lockfunc*/busdma_lock_mutex, /*lockarg*/&Giant, -#endif &sc->parent_dmat) != 0) { device_printf(dev, "unable to create dma tag\n"); goto no; diff --git a/sys/dev/sound/pci/t4dwave.c b/sys/dev/sound/pci/t4dwave.c index 08edb53b11a0..b30d269f5eef 100644 --- a/sys/dev/sound/pci/t4dwave.c +++ b/sys/dev/sound/pci/t4dwave.c @@ -913,8 +913,8 @@ tr_pci_attach(device_t dev) /*highaddr*/BUS_SPACE_MAXADDR, /*filter*/NULL, /*filterarg*/NULL, /*maxsize*/tr->bufsz, /*nsegments*/1, /*maxsegz*/tr->bufsz, - /*flags*/0, /*lockfunc*/busdma_lock_mutex, - /*lockarg*/&Giant, &tr->parent_dmat) != 0) { + /*flags*/0, /*lockfunc*/NULL, /*lockarg*/NULL, + &tr->parent_dmat) != 0) { device_printf(dev, "unable to create dma tag\n"); goto bad; } diff --git a/sys/dev/sound/pci/vibes.c b/sys/dev/sound/pci/vibes.c index a46efb061a8f..931de7300a3b 100644 --- a/sys/dev/sound/pci/vibes.c +++ b/sys/dev/sound/pci/vibes.c @@ -776,8 +776,8 @@ sv_attach(device_t dev) { /*filter*/NULL, /*filterarg*/NULL, /*maxsize*/sc->bufsz, /*nsegments*/1, /*maxsegz*/0x3ffff, /*flags*/0, - /*lockfunc*/busdma_lock_mutex, - /*lockarg*/&Giant, &sc->parent_dmat) != 0) { + /*lockfunc*/NULL, /*lockarg*/NULL, + &sc->parent_dmat) != 0) { device_printf(dev, "sv_attach: Unable to create dma tag\n"); goto fail; } diff --git a/sys/dev/sound/pcm/buffer.c b/sys/dev/sound/pcm/buffer.c index b86b67e44344..14fc098d6b33 100644 --- a/sys/dev/sound/pcm/buffer.c +++ b/sys/dev/sound/pcm/buffer.c @@ -107,7 +107,7 @@ sndbuf_alloc(struct snd_dbuf *b, bus_dma_tag_t dmatag, int dmaflags, return (ENOMEM); } if (bus_dmamap_load(b->dmatag, b->dmamap, b->buf, b->maxsize, - sndbuf_setmap, b, 0) != 0 || b->buf_addr == 0) { + sndbuf_setmap, b, BUS_DMA_NOWAIT) != 0 || b->buf_addr == 0) { sndbuf_free(b); return (ENOMEM); }