Index: isa/ad1816.c =================================================================== RCS file: /cvs/src/sys/dev/sound/isa/ad1816.c,v retrieving revision 1.7 diff -u -r1.7 ad1816.c --- isa/ad1816.c 4 Jan 2007 21:47:02 -0000 1.7 +++ isa/ad1816.c 15 Jun 2007 02:01:46 -0000 @@ -58,7 +58,7 @@ int drq2_rid; void *ih; bus_dma_tag_t parent_dmat; - struct spinlock *lock; + sndlock_t lock; unsigned int bufsize; struct ad1816_chinfo pch, rch; Index: isa/mss.c =================================================================== RCS file: /cvs/src/sys/dev/sound/isa/mss.c,v retrieving revision 1.10 diff -u -r1.10 mss.c --- isa/mss.c 4 Jan 2007 21:47:02 -0000 1.10 +++ isa/mss.c 15 Jun 2007 02:02:04 -0000 @@ -70,7 +70,7 @@ int drq2_rid; void *ih; bus_dma_tag_t parent_dmat; - struct spinlock *lock; + sndlock_t lock; char mss_indexed_regs[MSS_INDEXED_REGS]; char opl_indexed_regs[OPL_INDEXED_REGS]; Index: isa/sbc.c =================================================================== RCS file: /cvs/src/sys/dev/sound/isa/sbc.c,v retrieving revision 1.9 diff -u -r1.9 sbc.c --- isa/sbc.c 4 Jan 2007 21:47:02 -0000 1.9 +++ isa/sbc.c 15 Jun 2007 02:02:13 -0000 @@ -69,7 +69,7 @@ void *ih[IRQ_MAX]; - struct spinlock *lock; + sndlock_t lock; u_int32_t bd_ver; }; Index: pci/als4000.c =================================================================== RCS file: /cvs/src/sys/dev/sound/pci/als4000.c,v retrieving revision 1.10 diff -u -r1.10 als4000.c --- pci/als4000.c 4 Jan 2007 21:47:02 -0000 1.10 +++ pci/als4000.c 15 Jun 2007 02:02:23 -0000 @@ -78,7 +78,7 @@ struct resource *reg, *irq; int regid, irqid; void *ih; - struct spinlock *lock; + sndlock_t lock; unsigned int bufsz; struct sc_chinfo pch, rch; Index: pci/atiixp.c =================================================================== RCS file: /cvs/src/sys/dev/sound/pci/atiixp.c,v retrieving revision 1.3 diff -u -r1.3 atiixp.c --- pci/atiixp.c 13 May 2007 18:33:58 -0000 1.3 +++ pci/atiixp.c 15 Jun 2007 02:12:51 -0000 @@ -114,7 +114,7 @@ uint32_t dma_segs; int registered_channels; - struct spinlock *lock; + sndlock_t lock; }; #define atiixp_rd(_sc, _reg) \ @@ -747,7 +747,7 @@ /* wait for the interrupts to happen */ timeout = 100; while (--timeout) { - msleep(sc, sc->lock, 0, "ixpslp", 1); + snd_mtxsleep(sc, sc->lock, 0, "ixpslp", 1); if (sc->codec_not_ready_bits) break; } Index: pci/aureal.c =================================================================== RCS file: /cvs/src/sys/dev/sound/pci/aureal.c,v retrieving revision 1.10 diff -u -r1.10 aureal.c --- pci/aureal.c 4 Jan 2007 21:47:02 -0000 1.10 +++ pci/aureal.c 15 Jun 2007 02:02:29 -0000 @@ -76,7 +76,7 @@ bus_space_handle_t sh[3]; bus_dma_tag_t parent_dmat; - struct spinlock *lock; + sndlock_t lock; u_int32_t x[32], y[128]; char z[128]; Index: pci/cmi.c =================================================================== RCS file: /cvs/src/sys/dev/sound/pci/cmi.c,v retrieving revision 1.9 diff -u -r1.9 cmi.c --- pci/cmi.c 4 Jan 2007 21:47:02 -0000 1.9 +++ pci/cmi.c 15 Jun 2007 02:02:34 -0000 @@ -110,7 +110,7 @@ struct resource *reg, *irq; int regid, irqid; void *ih; - struct spinlock *lock; + sndlock_t lock; int spdif_enabled; unsigned int bufsz; Index: pci/ds1.c =================================================================== RCS file: /cvs/src/sys/dev/sound/pci/ds1.c,v retrieving revision 1.8 diff -u -r1.8 ds1.c --- pci/ds1.c 4 Jan 2007 21:47:02 -0000 1.8 +++ pci/ds1.c 15 Jun 2007 02:02:42 -0000 @@ -119,7 +119,7 @@ struct resource *reg, *irq; int regid, irqid; void *ih; - struct spinlock *lock; + sndlock_t lock; void *regbase; u_int32_t *pbase, pbankbase, pbanksize; Index: pci/emu10k1.c =================================================================== RCS file: /cvs/src/sys/dev/sound/pci/emu10k1.c,v retrieving revision 1.12 diff -u -r1.12 emu10k1.c --- pci/emu10k1.c 4 Jan 2007 21:47:02 -0000 1.12 +++ pci/emu10k1.c 15 Jun 2007 02:02:47 -0000 @@ -130,7 +130,7 @@ struct resource *reg, *irq; void *ih; - struct spinlock *lock; + sndlock_t lock; unsigned int bufsz; int timer, timerinterval; Index: pci/es137x.c =================================================================== RCS file: /cvs/src/sys/dev/sound/pci/es137x.c,v retrieving revision 1.9 diff -u -r1.9 es137x.c --- pci/es137x.c 4 Jan 2007 21:47:02 -0000 1.9 +++ pci/es137x.c 15 Jun 2007 02:02:50 -0000 @@ -194,7 +194,7 @@ uint32_t sctrl; uint32_t escfg; struct es_chinfo ch[ES_NCHANS]; - struct spinlock *lock; + sndlock_t lock; }; #define ES_LOCK(sc) snd_mtxlock((sc)->lock) Index: pci/ich.c =================================================================== RCS file: /cvs/src/sys/dev/sound/pci/ich.c,v retrieving revision 1.14 diff -u -r1.14 ich.c --- pci/ich.c 8 Jan 2007 01:38:02 -0000 1.14 +++ pci/ich.c 15 Jun 2007 02:03:59 -0000 @@ -176,7 +176,7 @@ uint16_t devid; uint32_t flags; #define IGNORE_PCR 0x01 - struct spinlock *ich_lock; + sndlock_t ich_lock; }; /* -------------------------------------------------------------------- */ Index: pci/maestro.c =================================================================== RCS file: /cvs/src/sys/dev/sound/pci/maestro.c,v retrieving revision 1.9 diff -u -r1.9 maestro.c --- pci/maestro.c 4 Jan 2007 21:47:02 -0000 1.9 +++ pci/maestro.c 15 Jun 2007 02:13:06 -0000 @@ -161,7 +161,7 @@ /* FreeBSD SMPng related */ #ifdef USING_MUTEX - struct spinlock *lock; /* mutual exclusion */ + sndlock_t lock; #endif /* FreeBSD newpcm related */ struct ac97_info *codec; @@ -288,7 +288,7 @@ if (timo == 0) timo = 1; #ifdef USING_MUTEX - msleep(sc, sc->lock, 0, wmesg, timo); + snd_mtxsleep(sc, sc->lock, 0, wmesg, timo); #else tsleep(sc, PWAIT, wmesg, timo); #endif Index: pci/maestro3.c =================================================================== RCS file: /cvs/src/sys/dev/sound/pci/maestro3.c,v retrieving revision 1.10 diff -u -r1.10 maestro3.c --- pci/maestro3.c 4 Jan 2007 21:47:02 -0000 1.10 +++ pci/maestro3.c 15 Jun 2007 02:04:16 -0000 @@ -148,7 +148,7 @@ unsigned int bufsz; u_int16_t *savemem; - struct spinlock *sc_lock; + sndlock_t sc_lock; }; #define M3_LOCK(_sc) snd_mtxlock((_sc)->sc_lock) Index: pci/solo.c =================================================================== RCS file: /cvs/src/sys/dev/sound/pci/solo.c,v retrieving revision 1.9 diff -u -r1.9 solo.c --- pci/solo.c 4 Jan 2007 21:47:02 -0000 1.9 +++ pci/solo.c 15 Jun 2007 02:04:26 -0000 @@ -100,7 +100,7 @@ struct ess_chinfo pch, rch; #if ESS18XX_MPSAFE == 1 - struct spinlock *lock; + sndlock_t lock; #endif }; Index: pci/t4dwave.c =================================================================== RCS file: /cvs/src/sys/dev/sound/pci/t4dwave.c,v retrieving revision 1.9 diff -u -r1.9 t4dwave.c --- pci/t4dwave.c 4 Jan 2007 21:47:02 -0000 1.9 +++ pci/t4dwave.c 15 Jun 2007 02:04:30 -0000 @@ -94,7 +94,7 @@ int regtype, regid, irqid; void *ih; - struct spinlock *lock; + sndlock_t lock; u_int32_t playchns; unsigned int bufsz; Index: pci/via8233.c =================================================================== RCS file: /cvs/src/sys/dev/sound/pci/via8233.c,v retrieving revision 1.8 diff -u -r1.8 via8233.c --- pci/via8233.c 4 Jan 2007 21:47:02 -0000 1.8 +++ pci/via8233.c 15 Jun 2007 02:04:33 -0000 @@ -111,7 +111,7 @@ struct via_dma_op *sgd_table; u_int16_t codec_caps; u_int16_t n_dxs_registered; - struct spinlock *lock; + sndlock_t lock; }; static u_int32_t via_fmt[] = { Index: pci/via82c686.c =================================================================== RCS file: /cvs/src/sys/dev/sound/pci/via82c686.c,v retrieving revision 1.8 diff -u -r1.8 via82c686.c --- pci/via82c686.c 4 Jan 2007 21:47:02 -0000 1.8 +++ pci/via82c686.c 15 Jun 2007 02:04:36 -0000 @@ -89,7 +89,7 @@ struct via_chinfo pch, rch; struct via_dma_op *sgd_table; u_int16_t codec_caps; - struct spinlock *lock; + sndlock_t lock; }; static u_int32_t via_fmt[] = { Index: pci/gnu/emu10k1-alsa.h =================================================================== RCS file: /cvs/src/sys/dev/sound/pci/gnu/emu10k1-alsa.h,v retrieving revision 1.1 diff -u -r1.1 emu10k1-alsa.h --- pci/gnu/emu10k1-alsa.h 4 Jan 2007 21:47:03 -0000 1.1 +++ pci/gnu/emu10k1-alsa.h 15 Jun 2007 02:03:42 -0000 @@ -910,7 +910,7 @@ struct list_head gpr_ctl; /* GPR controls */ struct semaphore lock; snd_emu10k1_fx8010_pcm_t pcm[8]; - spinlock_t irq_lock; + sndlock_t irq_lock; snd_emu10k1_fx8010_irq_t *irq_handlers; } snd_emu10k1_fx8010_t; @@ -922,9 +922,9 @@ snd_rawmidi_substream_t *substream_input; snd_rawmidi_substream_t *substream_output; unsigned int midi_mode; - spinlock_t input_lock; - spinlock_t output_lock; - spinlock_t open_lock; + sndlock_t input_lock; + sndlock_t output_lock; + sndlock_t open_lock; int tx_enable, rx_enable; int port; int ipr_tx, ipr_rx; @@ -958,7 +958,7 @@ struct list_head mapped_order_link_head; void **page_ptr_table; unsigned long *page_addr_table; - spinlock_t memblk_lock; + sndlock_t memblk_lock; unsigned int spdif_bits[3]; /* s/pdif out setup */ @@ -974,13 +974,13 @@ snd_pcm_t *pcm_efx; snd_pcm_t *pcm_fx8010; - spinlock_t synth_lock; + sndlock_t synth_lock; void *synth; int (*get_synth_voice)(emu10k1_t *emu); - spinlock_t reg_lock; - spinlock_t emu_lock; - spinlock_t voice_lock; + sndlock_t reg_lock; + sndlock_t emu_lock; + sndlock_t voice_lock; struct semaphore ptb_lock; emu10k1_voice_t voices[64]; Index: pci/hda/hdac_private.h =================================================================== RCS file: /cvs/src/sys/dev/sound/pci/hda/hdac_private.h,v retrieving revision 1.2 diff -u -r1.2 hdac_private.h --- pci/hda/hdac_private.h 20 Jan 2007 21:32:36 -0000 1.2 +++ pci/hda/hdac_private.h 15 Jun 2007 02:03:54 -0000 @@ -278,7 +278,7 @@ struct hdac_softc { device_t dev; device_t hdabus; - struct spinlock *lock; + sndlock_t lock; struct intr_config_hook intrhook; Index: pcm/ac97.c =================================================================== RCS file: /cvs/src/sys/dev/sound/pcm/ac97.c,v retrieving revision 1.23 diff -u -r1.23 ac97.c --- pcm/ac97.c 4 Jan 2007 21:47:03 -0000 1.23 +++ pcm/ac97.c 15 Jun 2007 02:04:39 -0000 @@ -59,7 +59,7 @@ u_int32_t flags; struct ac97mixtable_entry mix[32]; char name[AC97_NAMELEN]; - struct spinlock *lock; + sndlock_t lock; }; struct ac97_vendorid { Index: pcm/channel.c =================================================================== RCS file: /cvs/src/sys/dev/sound/pcm/channel.c,v retrieving revision 1.12 diff -u -r1.12 channel.c --- pcm/channel.c 14 Jun 2007 21:48:36 -0000 1.12 +++ pcm/channel.c 15 Jun 2007 02:13:13 -0000 @@ -162,7 +162,7 @@ CHN_LOCKASSERT(c); #ifdef USING_MUTEX - ret = msleep(bs, c->lock, PCATCH, str, timeout); + ret = snd_mtxsleep(bs, c->lock, PCATCH, str, timeout); #else ret = tsleep(bs, PRIBIO | PCATCH, str, timeout); #endif Index: pcm/channel.h =================================================================== RCS file: /cvs/src/sys/dev/sound/pcm/channel.h,v retrieving revision 1.5 diff -u -r1.5 channel.h --- pcm/channel.h 4 Jan 2007 21:47:03 -0000 1.5 +++ pcm/channel.h 15 Jun 2007 02:05:24 -0000 @@ -63,7 +63,7 @@ void *devinfo; device_t dev; char name[CHN_NAMELEN]; - struct spinlock *lock; + sndlock_t lock; SLIST_HEAD(, pcmchan_children) children; }; @@ -104,8 +104,8 @@ void chn_unlock(struct pcm_channel *c); #ifdef USING_MUTEX -#define CHN_LOCK(c) spin_lock_wr((struct spinlock *)((c)->lock)) -#define CHN_UNLOCK(c) spin_unlock_wr((struct spinlock *)((c)->lock)) +#define CHN_LOCK(c) snd_mtxlock(((c)->lock)) +#define CHN_UNLOCK(c) snd_mtxunlock(((c)->lock)) #define CHN_LOCKASSERT(c) #else #define CHN_LOCK(c) Index: pcm/mixer.c =================================================================== RCS file: /cvs/src/sys/dev/sound/pcm/mixer.c,v retrieving revision 1.15 diff -u -r1.15 mixer.c --- pcm/mixer.c 14 Jun 2007 21:48:36 -0000 1.15 +++ pcm/mixer.c 15 Jun 2007 02:05:35 -0000 @@ -52,7 +52,7 @@ u_int32_t recsrc; u_int16_t level[32]; char name[MIXER_NAMELEN]; - struct spinlock *lock; + sndlock_t lock; }; static u_int16_t snd_mixerdefaults[SOUND_MIXER_NRDEVICES] = { Index: pcm/sound.c =================================================================== RCS file: /cvs/src/sys/dev/sound/pcm/sound.c,v retrieving revision 1.9 diff -u -r1.9 sound.c --- pcm/sound.c 14 Jun 2007 21:48:36 -0000 1.9 +++ pcm/sound.c 15 Jun 2007 02:18:23 -0000 @@ -73,12 +73,12 @@ snd_mtxcreate(const char *desc, const char *type) { #ifdef USING_MUTEX - struct spinlock *m; + struct lock *m; m = kmalloc(sizeof(*m), M_DEVBUF, M_WAITOK | M_ZERO); if (m == NULL) return NULL; - spin_init(m); + lockinit(m, __DECONST(char *, type), 0, LK_CANRECURSE); return m; #else return (void *)0xcafebabe; @@ -89,11 +89,9 @@ snd_mtxfree(void *m) { #ifdef USING_MUTEX - struct spinlock *mtx = m; + struct lock *lk = m; - /* mtx_assert(mtx, MA_OWNED); */ - spin_uninit(mtx); - kfree(mtx, M_DEVBUF); + kfree(lk, M_DEVBUF); #endif } @@ -102,18 +100,18 @@ { #ifdef USING_MUTEX #ifdef INVARIANTS - /* XXX can't assert spinlocks */ + /* XXX */ #endif #endif } -/* + void snd_mtxlock(void *m) { #ifdef USING_MUTEX - struct spinlock *mtx = m; + struct lock *lk = m; - spin_lock_wr(mtx); + lockmgr(lk, LK_EXCLUSIVE | LK_RETRY); #endif } @@ -121,12 +119,28 @@ snd_mtxunlock(void *m) { #ifdef USING_MUTEX - struct spinlock *mtx = m; + struct lock *lk = m; - spin_unlock_wr(mtx); + lockmgr(lk, LK_RELEASE); #endif } -*/ + +int +snd_mtxsleep(void *addr, sndlock_t lock, int flags, const char *wmesg, int timo) +{ + int r; + + crit_enter(); + tsleep_interlock(addr); + snd_mtxunlock(lock); + r = tsleep(addr, flags, wmesg, timo); + snd_mtxlock(lock); + crit_exit(); + return(r); +} + + + int snd_setup_intr(device_t dev, struct resource *res, int flags, driver_intr_t hand, void *param, void **cookiep) { Index: pcm/sound.h =================================================================== RCS file: /cvs/src/sys/dev/sound/pcm/sound.h,v retrieving revision 1.11 diff -u -r1.11 sound.h --- pcm/sound.h 14 Jun 2007 21:48:36 -0000 1.11 +++ pcm/sound.h 15 Jun 2007 02:14:55 -0000 @@ -74,8 +74,8 @@ #undef USING_MUTEX #undef USING_DEVFS -#include -#include +#include /* lockmgr locks */ +typedef struct lock *sndlock_t; /* opaque lock structure */ #define USING_MUTEX #define INTR_TYPE_AV 0 @@ -242,8 +242,9 @@ void *snd_mtxcreate(const char *desc, const char *type); void snd_mtxfree(void *m); void snd_mtxassert(void *m); -#define snd_mtxlock(m) spin_lock_wr(m) -#define snd_mtxunlock(m) spin_unlock_wr(m) +void snd_mtxlock(void *m); +void snd_mtxunlock(void *m); +int snd_mtxsleep(void *, sndlock_t, int, const char *, int); int sysctl_hw_snd_vchans(SYSCTL_HANDLER_ARGS); @@ -304,14 +305,14 @@ char status[SND_STATUSLEN]; struct sysctl_ctx_list sysctl_tree; struct sysctl_oid *sysctl_tree_top; - struct spinlock *lock; + sndlock_t lock; struct cdev *mixer_dev; }; #ifdef PCM_DEBUG_MTX -#define pcm_lock(d) spin_lock_wr(((struct snddev_info *)(d))->lock) -#define pcm_unlock(d) spin_unlock_wr(((struct snddev_info *)(d))->lock) +#define pcm_lock(d) snd_mtxlock(((struct snddev_info *)(d))->lock) +#define pcm_unlock(d) snd_mtxunlock(((struct snddev_info *)(d))->lock) #else void pcm_lock(struct snddev_info *d); void pcm_unlock(struct snddev_info *d);