Deleted Added
full compact
sound.h (170161) sound.h (170815)
1/*-
2 * Copyright (c) 1999 Cameron Grant <cg@freebsd.org>
3 * Copyright by Hannu Savolainen 1995
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:

--- 10 unchanged lines hidden (view full) ---

19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
26 *
1/*-
2 * Copyright (c) 1999 Cameron Grant <cg@freebsd.org>
3 * Copyright by Hannu Savolainen 1995
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:

--- 10 unchanged lines hidden (view full) ---

19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
26 *
27 * $FreeBSD: head/sys/dev/sound/pcm/sound.h 170161 2007-05-31 18:43:33Z ariff $
27 * $FreeBSD: head/sys/dev/sound/pcm/sound.h 170815 2007-06-16 03:37:28Z ariff $
28 */
29
30/*
31 * first, include kernel header files.
32 */
33
34#ifndef _OS_H_
35#define _OS_H_

--- 97 unchanged lines hidden (view full) ---

133
134#define SD_F_SIMPLEX 0x00000001
135#define SD_F_AUTOVCHAN 0x00000002
136#define SD_F_SOFTPCMVOL 0x00000004
137#define SD_F_PSWAPLR 0x00000008
138#define SD_F_RSWAPLR 0x00000010
139#define SD_F_DYING 0x00000020
140#define SD_F_SUICIDE 0x00000040
28 */
29
30/*
31 * first, include kernel header files.
32 */
33
34#ifndef _OS_H_
35#define _OS_H_

--- 97 unchanged lines hidden (view full) ---

133
134#define SD_F_SIMPLEX 0x00000001
135#define SD_F_AUTOVCHAN 0x00000002
136#define SD_F_SOFTPCMVOL 0x00000004
137#define SD_F_PSWAPLR 0x00000008
138#define SD_F_RSWAPLR 0x00000010
139#define SD_F_DYING 0x00000020
140#define SD_F_SUICIDE 0x00000040
141#define SD_F_BUSY 0x00000080
142#define SD_F_MPSAFE 0x00000100
143#define SD_F_REGISTERED 0x00000200
144
141#define SD_F_PRIO_RD 0x10000000
142#define SD_F_PRIO_WR 0x20000000
143#define SD_F_PRIO_SET (SD_F_PRIO_RD | SD_F_PRIO_WR)
144#define SD_F_DIR_SET 0x40000000
145#define SD_F_TRANSIENT 0xf0000000
146
145#define SD_F_PRIO_RD 0x10000000
146#define SD_F_PRIO_WR 0x20000000
147#define SD_F_PRIO_SET (SD_F_PRIO_RD | SD_F_PRIO_WR)
148#define SD_F_DIR_SET 0x40000000
149#define SD_F_TRANSIENT 0xf0000000
150
151#define PCM_ALIVE(x) ((x) != NULL && (x)->lock != NULL && \
152 !((x)->flags & SD_F_DYING))
153#define PCM_REGISTERED(x) (PCM_ALIVE(x) && \
154 ((x)->flags & SD_F_REGISTERED))
155
147/* many variables should be reduced to a range. Here define a macro */
148#define RANGE(var, low, high) (var) = \
149 (((var)<(low))? (low) : ((var)>(high))? (high) : (var))
150#define DSP_BUFFSIZE (8192)
151
152/*
153 * Macros for reading/writing PCM sample / int values from bytes array.
154 * Since every process is done using signed integer (and to make our life

--- 304 unchanged lines hidden (view full) ---

459#define SND_DEV_PSS SND_DEV_SNDPROC /* ? */
460#define SND_DEV_NORESET 10
461
462#define SND_DEV_DSPHW_PLAY 11 /* specific playback channel */
463#define SND_DEV_DSPHW_VPLAY 12 /* specific virtual playback channel */
464#define SND_DEV_DSPHW_REC 13 /* specific record channel */
465#define SND_DEV_DSPHW_VREC 14 /* specific virtual record channel */
466
156/* many variables should be reduced to a range. Here define a macro */
157#define RANGE(var, low, high) (var) = \
158 (((var)<(low))? (low) : ((var)>(high))? (high) : (var))
159#define DSP_BUFFSIZE (8192)
160
161/*
162 * Macros for reading/writing PCM sample / int values from bytes array.
163 * Since every process is done using signed integer (and to make our life

--- 304 unchanged lines hidden (view full) ---

468#define SND_DEV_PSS SND_DEV_SNDPROC /* ? */
469#define SND_DEV_NORESET 10
470
471#define SND_DEV_DSPHW_PLAY 11 /* specific playback channel */
472#define SND_DEV_DSPHW_VPLAY 12 /* specific virtual playback channel */
473#define SND_DEV_DSPHW_REC 13 /* specific record channel */
474#define SND_DEV_DSPHW_VREC 14 /* specific virtual record channel */
475
476#define SND_DEV_DSPHW_CD 15 /* s16le/stereo 44100Hz CD */
477
478#define SND_DEV_DSP_MMAP 16 /* OSSv4 compatible /dev/dsp_mmap */
479
480#define SND_DEV_LAST SND_DEV_DSP_MMAP
481#define SND_DEV_MAX PCMMAXDEV
482
467#define DSP_DEFAULT_SPEED 8000
468
469#define ON 1
470#define OFF 0
471
472extern int pcm_veto_load;
473extern int snd_unit;
474extern int snd_maxautovchans;

--- 85 unchanged lines hidden (view full) ---

560 struct {
561 struct {
562 SLIST_HEAD(, pcm_channel) head;
563 struct {
564 SLIST_HEAD(, pcm_channel) head;
565 } busy;
566 } pcm;
567 } channels;
483#define DSP_DEFAULT_SPEED 8000
484
485#define ON 1
486#define OFF 0
487
488extern int pcm_veto_load;
489extern int snd_unit;
490extern int snd_maxautovchans;

--- 85 unchanged lines hidden (view full) ---

576 struct {
577 struct {
578 SLIST_HEAD(, pcm_channel) head;
579 struct {
580 SLIST_HEAD(, pcm_channel) head;
581 } busy;
582 } pcm;
583 } channels;
584 TAILQ_HEAD(dsp_cdevinfo_linkhead, dsp_cdevinfo) dsp_cdevinfo_pool;
568 struct snd_clone *clones;
569 struct pcm_channel *fakechan;
570 unsigned devcount, playcount, reccount, pvchancount, rvchancount ;
571 unsigned flags;
572 int inprog;
573 unsigned int bufsz;
574 void *devinfo;
575 device_t dev;
576 char status[SND_STATUSLEN];
577 struct mtx *lock;
578 struct cdev *mixer_dev;
579 uint32_t pvchanrate, pvchanformat;
580 uint32_t rvchanrate, rvchanformat;
581 struct sysctl_ctx_list play_sysctl_ctx, rec_sysctl_ctx;
582 struct sysctl_oid *play_sysctl_tree, *rec_sysctl_tree;
585 struct snd_clone *clones;
586 struct pcm_channel *fakechan;
587 unsigned devcount, playcount, reccount, pvchancount, rvchancount ;
588 unsigned flags;
589 int inprog;
590 unsigned int bufsz;
591 void *devinfo;
592 device_t dev;
593 char status[SND_STATUSLEN];
594 struct mtx *lock;
595 struct cdev *mixer_dev;
596 uint32_t pvchanrate, pvchanformat;
597 uint32_t rvchanrate, rvchanformat;
598 struct sysctl_ctx_list play_sysctl_ctx, rec_sysctl_ctx;
599 struct sysctl_oid *play_sysctl_tree, *rec_sysctl_tree;
600 struct cv cv;
583};
584
585void sound_oss_sysinfo(oss_sysinfo *);
586
587#ifdef PCM_DEBUG_MTX
588#define pcm_lock(d) mtx_lock(((struct snddev_info *)(d))->lock)
589#define pcm_unlock(d) mtx_unlock(((struct snddev_info *)(d))->lock)
590#else
591void pcm_lock(struct snddev_info *d);
592void pcm_unlock(struct snddev_info *d);
593#endif
594
601};
602
603void sound_oss_sysinfo(oss_sysinfo *);
604
605#ifdef PCM_DEBUG_MTX
606#define pcm_lock(d) mtx_lock(((struct snddev_info *)(d))->lock)
607#define pcm_unlock(d) mtx_unlock(((struct snddev_info *)(d))->lock)
608#else
609void pcm_lock(struct snddev_info *d);
610void pcm_unlock(struct snddev_info *d);
611#endif
612
613/*
614 * For PCM_CV_[WAIT | ACQUIRE | RELEASE], be sure to surround these
615 * with pcm_lock/unlock() sequence, or I'll come to gnaw upon you!
616 */
617#ifdef SND_DIAGNOSTIC
618#define PCM_WAIT(x) do { \
619 if (mtx_owned((x)->lock) == 0) \
620 panic("%s(%d): [PCM WAIT] Mutex not owned!", \
621 __func__, __LINE__); \
622 while ((x)->flags & SD_F_BUSY) { \
623 if (snd_verbose > 3) \
624 device_printf((x)->dev, \
625 "%s(%d): [PCM WAIT] calling cv_wait().\n", \
626 __func__, __LINE__); \
627 cv_wait(&(x)->cv, (x)->lock); \
628 } \
629} while(0)
630
631#define PCM_ACQUIRE(x) do { \
632 if (mtx_owned((x)->lock) == 0) \
633 panic("%s(%d): [PCM ACQUIRE] Mutex not owned!", \
634 __func__, __LINE__); \
635 if ((x)->flags & SD_F_BUSY) \
636 panic("%s(%d): [PCM ACQUIRE] " \
637 "Trying to acquire BUSY cv!", __func__, __LINE__); \
638 (x)->flags |= SD_F_BUSY; \
639} while(0)
640
641#define PCM_RELEASE(x) do { \
642 if (mtx_owned((x)->lock) == 0) \
643 panic("%s(%d): [PCM RELEASE] Mutex not owned!", \
644 __func__, __LINE__); \
645 if ((x)->flags & SD_F_BUSY) { \
646 (x)->flags &= ~SD_F_BUSY; \
647 if ((x)->cv.cv_waiters != 0) { \
648 if ((x)->cv.cv_waiters > 1 && snd_verbose > 3) \
649 device_printf((x)->dev, \
650 "%s(%d): [PCM RELEASE] " \
651 "cv_waiters=%d > 1!\n", \
652 __func__, __LINE__, \
653 (x)->cv.cv_waiters); \
654 cv_broadcast(&(x)->cv); \
655 } \
656 } else \
657 panic("%s(%d): [PCM RELEASE] Releasing non-BUSY cv!", \
658 __func__, __LINE__); \
659} while(0)
660
661/* Quick version, for shorter path. */
662#define PCM_ACQUIRE_QUICK(x) do { \
663 if (mtx_owned((x)->lock) != 0) \
664 panic("%s(%d): [PCM ACQUIRE QUICK] Mutex owned!", \
665 __func__, __LINE__); \
666 pcm_lock(x); \
667 PCM_WAIT(x); \
668 PCM_ACQUIRE(x); \
669 pcm_unlock(x); \
670} while(0)
671
672#define PCM_RELEASE_QUICK(x) do { \
673 if (mtx_owned((x)->lock) != 0) \
674 panic("%s(%d): [PCM RELEASE QUICK] Mutex owned!", \
675 __func__, __LINE__); \
676 pcm_lock(x); \
677 PCM_RELEASE(x); \
678 pcm_unlock(x); \
679} while(0)
680
681#define PCM_BUSYASSERT(x) do { \
682 if (!((x) != NULL && ((x)->flags & SD_F_BUSY))) \
683 panic("%s(%d): [PCM BUSYASSERT] " \
684 "Failed, snddev_info=%p", __func__, __LINE__, x); \
685} while(0)
686
687#define PCM_GIANT_ENTER(x) do { \
688 int _pcm_giant = 0; \
689 if (mtx_owned((x)->lock) != 0) \
690 panic("%s(%d): [GIANT ENTER] PCM lock owned!", \
691 __func__, __LINE__); \
692 if (mtx_owned(&Giant) != 0 && snd_verbose > 3) \
693 device_printf((x)->dev, \
694 "%s(%d): [GIANT ENTER] Giant owned!\n", \
695 __func__, __LINE__); \
696 if (!((x)->flags & SD_F_MPSAFE) && mtx_owned(&Giant) == 0) \
697 do { \
698 mtx_lock(&Giant); \
699 _pcm_giant = 1; \
700 } while(0)
701
702#define PCM_GIANT_EXIT(x) do { \
703 if (mtx_owned((x)->lock) != 0) \
704 panic("%s(%d): [GIANT EXIT] PCM lock owned!", \
705 __func__, __LINE__); \
706 if (!(_pcm_giant == 0 || _pcm_giant == 1)) \
707 panic("%s(%d): [GIANT EXIT] _pcm_giant screwed!", \
708 __func__, __LINE__); \
709 if ((x)->flags & SD_F_MPSAFE) { \
710 if (_pcm_giant == 1) \
711 panic("%s(%d): [GIANT EXIT] MPSAFE Giant?", \
712 __func__, __LINE__); \
713 if (mtx_owned(&Giant) != 0 && snd_verbose > 3) \
714 device_printf((x)->dev, \
715 "%s(%d): [GIANT EXIT] Giant owned!\n", \
716 __func__, __LINE__); \
717 } \
718 if (_pcm_giant != 0) { \
719 if (mtx_owned(&Giant) == 0) \
720 panic("%s(%d): [GIANT EXIT] Giant not owned!", \
721 __func__, __LINE__); \
722 _pcm_giant = 0; \
723 mtx_unlock(&Giant); \
724 } \
725} while(0)
726#else /* SND_DIAGNOSTIC */
727#define PCM_WAIT(x) do { \
728 mtx_assert((x)->lock, MA_OWNED); \
729 while ((x)->flags & SD_F_BUSY) \
730 cv_wait(&(x)->cv, (x)->lock); \
731} while(0)
732
733#define PCM_ACQUIRE(x) do { \
734 mtx_assert((x)->lock, MA_OWNED); \
735 KASSERT(!((x)->flags & SD_F_BUSY), \
736 ("%s(%d): [PCM ACQUIRE] Trying to acquire BUSY cv!", \
737 __func__, __LINE__)); \
738 (x)->flags |= SD_F_BUSY; \
739} while(0)
740
741#define PCM_RELEASE(x) do { \
742 mtx_assert((x)->lock, MA_OWNED); \
743 KASSERT((x)->flags & SD_F_BUSY, \
744 ("%s(%d): [PCM RELEASE] Releasing non-BUSY cv!", \
745 __func__, __LINE__)); \
746 (x)->flags &= ~SD_F_BUSY; \
747 if ((x)->cv.cv_waiters != 0) \
748 cv_broadcast(&(x)->cv); \
749} while(0)
750
751/* Quick version, for shorter path. */
752#define PCM_ACQUIRE_QUICK(x) do { \
753 mtx_assert((x)->lock, MA_NOTOWNED); \
754 pcm_lock(x); \
755 PCM_WAIT(x); \
756 PCM_ACQUIRE(x); \
757 pcm_unlock(x); \
758} while(0)
759
760#define PCM_RELEASE_QUICK(x) do { \
761 mtx_assert((x)->lock, MA_NOTOWNED); \
762 pcm_lock(x); \
763 PCM_RELEASE(x); \
764 pcm_unlock(x); \
765} while(0)
766
767#define PCM_BUSYASSERT(x) KASSERT(x != NULL && \
768 ((x)->flags & SD_F_BUSY), \
769 ("%s(%d): [PCM BUSYASSERT] " \
770 "Failed, snddev_info=%p", \
771 __func__, __LINE__, x))
772
773#define PCM_GIANT_ENTER(x) do { \
774 int _pcm_giant = 0; \
775 mtx_assert((x)->lock, MA_NOTOWNED); \
776 if (!((x)->flags & SD_F_MPSAFE) && mtx_owned(&Giant) == 0) \
777 do { \
778 mtx_lock(&Giant); \
779 _pcm_giant = 1; \
780 } while(0)
781
782#define PCM_GIANT_EXIT(x) do { \
783 mtx_assert((x)->lock, MA_NOTOWNED); \
784 KASSERT(_pcm_giant == 0 || _pcm_giant == 1, \
785 ("%s(%d): [GIANT EXIT] _pcm_giant screwed!", \
786 __func__, __LINE__)); \
787 KASSERT(!((x)->flags & SD_F_MPSAFE) || \
788 (((x)->flags & SD_F_MPSAFE) && _pcm_giant == 0), \
789 ("%s(%d): [GIANT EXIT] MPSAFE Giant?", \
790 __func__, __LINE__)); \
791 if (_pcm_giant != 0) { \
792 mtx_assert(&Giant, MA_OWNED); \
793 _pcm_giant = 0; \
794 mtx_unlock(&Giant); \
795 } \
796} while(0)
797#endif /* !SND_DIAGNOSTIC */
798
799#define PCM_GIANT_LEAVE(x) \
800 PCM_GIANT_EXIT(x); \
801} while(0)
802
595#ifdef KLD_MODULE
596#define PCM_KLDSTRING(a) ("kld " # a)
597#else
598#define PCM_KLDSTRING(a) ""
599#endif
600
601#endif /* _KERNEL */
602
603#endif /* _OS_H_ */
803#ifdef KLD_MODULE
804#define PCM_KLDSTRING(a) ("kld " # a)
805#else
806#define PCM_KLDSTRING(a) ""
807#endif
808
809#endif /* _KERNEL */
810
811#endif /* _OS_H_ */