Commit Graph

520 Commits

Author SHA1 Message Date
Ariff Abdullah
9c271eba78 - Increase snddev refcount earlier while accessing through sysctl interface
to avoid possible device unregister race (impossible to reproduce, yet
  possible).
- Extra sanity check to ensure proper parent channel is being selected.
- Reset parent channel once all of its children gone.
2006-03-31 10:27:47 +00:00
Ariff Abdullah
844f9220aa Remove paranoid thread hijacking check. It cause wierd behaviour
(dangling channel - process association) especially in threaded
or fork()ed apps.
2006-03-30 06:17:03 +00:00
Ariff Abdullah
b422186846 We shouldn't really care about the return value of mixer_uninit(),
except EBUSY.
2006-03-22 20:50:04 +00:00
Ariff Abdullah
c17cb0c68f Pointer align should be generic enough to handle awkward byte size
especially for true 24bit format.
2006-03-22 00:34:17 +00:00
Ariff Abdullah
3fdb3676ba Apply more thorough fixes while dealing with device opening and closing:
- Determine open direction using 'flags', not 'mode'. This bug exist since
  past 4 years.
- Don't allow opening the same device twice, be it in a same or different
  direction.
- O_RDWR is allowed, provided that it is done by a single open (for example
  by mixer(8)) and the underlying hardware support true full-duplex operation.
- Do various paranoid checking in case other process/thread trying to hijack
  the same device twice (or more).

MFC after:	5 days
2006-03-21 06:35:48 +00:00
Ariff Abdullah
945510a039 Restore CHN_F_BUSY flag which was removed accidentally in previous commit. 2006-03-16 08:01:10 +00:00
Ariff Abdullah
7982e7a465 Fix severe 8bit integer overflow during channel creation and destruction,
especially for vchans. It turns out that channel numbering always depend
on d->devcount counter (which keep increasing), while PCMMKMINOR() truncate
everything to 8bit length. At some point the truncation cause the newly
created character device overlapped with the existence one, causing erratic
overall system behaviour and panic. Easily reproduce with something like:

	(Luckily, only root can reproduce this)

	while : ; do
		sysctl hw.snd.pcm0.vchans=200
		sysctl hw.snd.pcm0.vchans=100
	done

- Enforce channel/chardev numbering within 8bit boundary. Return E2BIG
  if necessary.
- Traverse d->channels SLIST and try to reclaim "free" counter during channel
  creation. Don't rely on d->devcount at all.
- Destroy vchans in reverse order.

Anyway, this is not the fault of vchans. It is just that vchans are so cute
and begging to be abused ;) . Don't blame her.

Old, hidden bugs.. sigh..

MFC after:	3 days
2006-03-16 04:12:49 +00:00
John Baldwin
de49f3252c Remove some dead code.
Coverity ID:	822
Found by:	Coverity Prevent
Reviewed by:	ariff
MFC after:	1 week
2006-02-23 19:23:55 +00:00
Alexander Leidinger
9d978cc757 Convert NULL checks into KASSERT (and move them before the first
dereferencing) since a NULL value would be a bug here.

Note: Both affected functions look very similar. A refactoring may
be beneficial.

CID:		483, 485
Found with:	Coverity Prevent(tm)
Discussed with:	ariff
MFC after:	5 days
2006-02-05 17:47:26 +00:00
Alexander Leidinger
c8c4c87d6a Fix some potential NULL pointer dereferences.
This is supposed to fix some Coverity Prevent errors (Ariff didn't
looked at the CID's (ENOTIME), I just told him that there are some problems
in function dsp_ioctl()).

CID:		215-218
Found with:	Coverity Prevent(tm)
Submitted by:	ariff
MFC after:	5 days
2006-01-29 16:48:41 +00:00
Ariff Abdullah
4a193ac907 Tune format scoring so (non)stereo format will get better chance
to be selected.
2006-01-29 01:32:37 +00:00
Joel Dahl
da8623eca0 Fix typos and clean up some comments.
Approved by:	ariff
2006-01-25 21:13:46 +00:00
Ariff Abdullah
14665331ab channel.c:
(1) Fix DMA alignment, based on bytes per sample.

feeder_rate.c:
	Handle strayed bytes (mostly caused by #1) better.

This DMA alignment issues are extremely hard to reproduce unless
the user happen to have a 32bit capable soundcards (ATI IXP) and
knowledgeable enough to force it to operate under pure 32bit
operations on both record and play directions.
2006-01-24 01:10:07 +00:00
Ariff Abdullah
d9bd844573 Various fixups:
feeder.h:
 feeder.c:
	- Implement scoring mechanisme to select best format for conversion.
	  This is actually part of newer format chaining procedures which
	  will be commited someday. Confusion during chaining process solved
	  by this scoring since it will try to reduce list of from/to formats
	  to a single, best format.
	  Related PR:	kern/91683
channel.c:
	- Simplify feeder building process since we have smarter format
	  chaining.

feeder_fmt.c:
	- Add few more sign conversion feeders for 24 and 32 bit format.

feeder_rate.c:
	- Force buffer / bytes allignment. Unaligned buffer may cause
	  panics during recording on pure 32bit sample format if it
	  involves feeder_rate as part of feeders chain.
	  Tested on: ATI IXP, force 32bit recording.

MFC after:	5 days
2006-01-22 15:06:49 +00:00
Ariff Abdullah
9ca45dd7dc Ruthless vchan speed workaround against the dreaded sb16 / sb16x. It appear
that nothing else using this weird 45k / 49k speed upper limit.
2006-01-20 03:46:02 +00:00
Ariff Abdullah
2fd8d3d84e Restore old compatibility of feeding directly into /dev/dsp at 8000 hz
while preserving the New World Order.

Discussed with:	[1] Michael W. Oliver <michael at gargantuan.com>
MFC after:	1 week

[1] http://lists.freebsd.org/pipermail/freebsd-multimedia/2006-January/003562.html
2006-01-16 11:07:15 +00:00
Ariff Abdullah
97efeca38d Workaround for sb16 behave poorly when running at 45000 hz while
vchan is enabled.

Reported by:	many sb16, AWE64 users.
MFC after:	1 week
2006-01-13 18:10:43 +00:00
Ariff Abdullah
e1e05d5d12 Add codec id support for Analog Device AD1986 AC'97 codec.
Submitted by:	UMENO Takashi <umeno at rr.iij4u.or.jp>
PR:		kern/80234
MFC after:	2 days
2006-01-07 05:20:46 +00:00
Ariff Abdullah
cc6882e1a4 Fix another xruns counting logic, this time, for recording. 2006-01-01 18:16:13 +00:00
Ariff Abdullah
c3ebbcbdf8 Fix LOR #174.
Tested with:	WITNESS, INVARIANTS and DIAGNOSTICS
2005-12-31 01:58:40 +00:00
Ariff Abdullah
f935ac6015 Disable frantic DMA update within few SNDCTL_DSP_* ioctl.
This should reduce huge playback / recording latency for
applications that try to act smarter and manage their own
buffering (XMMS, Skype, etc.).

Note to Skype + via8xxx users: Remove previous hackish
"hint.pcm.<unit>.via_dxs_disabled" from kernel hint and see
whether this changes cure all those annoying sound issues.
2005-12-30 07:33:28 +00:00
Ariff Abdullah
764907327e Underruns counting logic should be based on bufhard free space
and must be done after sndbuf_feed(), or any attempt to fill
up bufhard. This should fix false underruns counter.
2005-12-30 07:33:01 +00:00
Ariff Abdullah
eaf700837f Few codec such as Conexant CX20468-21 does have this control
register, although the only usable part is the mute bit.

Noticed by:	Hans Petter Selasky <hselasky@c2i.net>
2005-12-30 01:06:29 +00:00
Pyun YongHyeon
b7994e3488 Add codec ID for Avance Logic ALC203 2005-11-30 01:44:22 +00:00
Ariff Abdullah
187879feee Added mono to stereo and stereo to mono feeder functions for both
24 and 32 bit format.
2005-11-26 03:54:17 +00:00
Ariff Abdullah
b327ee5148 Added codec id for Avance Logic (ALC250) 2005-11-26 03:51:25 +00:00
Alexander Kabaev
fcf97578ff Unbreak kernel builds.
Submitted by:	arr
2005-11-15 04:19:27 +00:00
Ariff Abdullah
720289b2cd Update my email address, so people know where the exact /
proper / correct place to bug me.

Approved by:	netchild (mentor)
2005-11-14 18:37:59 +00:00
Ariff Abdullah
bd2ce91cdc From luigi:
This one simply tries to simplify the logic to select the
	buffer sizes. I am not sure it is necessary but the code
	seems a bit more readable to me. And at least i have tried
	to document how the buffer sizes are computed.

Thanks to luigi for deciphering one of the most cryptic part of
sound driver.

Submitted by:	luigi
Approved by:	netchild (mentor)
2005-11-14 18:21:23 +00:00
Ariff Abdullah
ee43f8a667 From luigi:
In SNDCTL_DSP_SETFRAGMENT, if you specify both read and
	write channels, the existing code first acts on the
	read channel, but as a side effect it updates the
	arguments (maxfrags, fragsz) passed by the caller according
	to acceptable values for the read channel, and then uses the
	modified values to act on the write channel.
	The problem with this approach is that, given a
	(maxfrags, fragsz) user-specified value, the actual
	values computed by the read and write channels may differ:
	e.g. the read channel might want to allocate more fragments
	than what the user specified because it has no side-effects
	on the delay and it helps in case of slow readers,
	whereas the write channel needs to use as few fragments
	as possible to keep the audio latency low (very important
	with telephony apps).

	This patch stores the values computed by the read channel
	into temproary variables so the write channel will use
	the actual arguments of the ioctl.

	This patch is very helpful with telephony apps such as asterisk.

Submitted by:	luigi
Approved by:	netchild (mentor)
2005-11-14 18:20:47 +00:00
Ariff Abdullah
801389376f ac97.c:
- Added new codec id for CX20468-21 and VIA1617A.
   Submitted by:	Chen Lihong <lihong.chen@gmail.com>
 - Re-enable SOUND_MIXER_IGAIN, but set the default level as 0 (mute)
   Suggested by:	luigi

mixer.c:
 - Set default value for SOUND_MIXER_IGAIN as 0 (mute) to avoid
   feedback problems on some laptops (was disabled by jhb during
   ac97.c revision 1.42).

Approved by:	netchild (mentor)
2005-11-14 18:19:33 +00:00
Ariff Abdullah
8be20fbe2a Appropriate NULL pointer checking to avoid mysterious panic during
device cloning.

Approved by:	netchild (mentor)
2005-11-03 08:19:04 +00:00
Dag-Erling Smørgrav
85cc3851ff Add some safeguards to AIOSFMT:
- Return EINVAL if play_format or rec_format is set but the corresponding
   sample rate is 0.

 - Don't try to set the playback or recording format to 0.  Previously,
   issuing an AIOSFMT ioctl with an all-zeroes snd_chan_param would
   trigger a KASSERT in chn_fmtchain(); I'm unsure about the effects on
   a kernel without INVARIANTS.  After this commit, issuing AIOSFMT with
   an all-zeroes snd_chan_param is equivalent to issuing AIOGFMT.

MFC after:	2 weeks
2005-10-30 10:03:11 +00:00
Ariff Abdullah
d45d1f2077 Fix vchan speed for hardware with discrete (non-continuous)
sampling rate:
- Improve vchan chn_setspeed() strategy. Try to avoid FEEDER_RATE
  on parent channel if the requested value is not supported
  by the hardware.
- Fix vchan default speed calculation. In any case, vchan should
  rely on parent bufsoft speed instead of bufhard since it is
  possible that the entire feeder chain might involve FEEDER_RATE.
  This is possible under extreme, rare condition if the above
  chn_setspeed() strategy failed.

Approved by:	netchild (mentor)
2005-10-18 21:33:51 +00:00
Ariff Abdullah
3f3c2c43b0 Added missing comma. This fixes compilation if we need to enable
RATE_ASSERT debug macro.

Approved by:	netchild (mentor)
2005-10-18 21:18:47 +00:00
Alexander Leidinger
d793e09c95 The cmi9739_patch function which is referenced by ac97.c (rev. 1.56) now...
Submitted by:	Ariff Abdullah <skywizard@MyBSD.org.my>
Pointy hat to:	netchild (for not committing it with rev. 1.56 of ac97.c)
2005-10-02 15:50:22 +00:00
Alexander Leidinger
28ef3fb011 sys/dev/sound/pcm/sndstat.c:
* General spl* cleanup. It doesn't serve any purpose anymore.
   * Nuke sndstat_busy(). Addition of sndstat_acquire() /
     sndstat_release() for sndstat exclusive access. [1]

sys/dev/sound/pcm/sound.c:
   * Remove duplicate SLIST_INIT()
   * Use sndstat_acquire() / release() to lock / release the entire
     sndstat during pcm_unregister(). This should fix LOR #159 [1]

sys/dev/sound/pcm/sound.h:
   * Definition of SD_F_SOFTVOL (part of feeder volume)
   * Nuke sndstat_busy(). Addition of sndstat_acquire() /
     sndstat_release() for exclusive sndstat access. [1]

Submitted by:	Ariff Abdullah <skywizard@MyBSD.org.my>
LOR:		159 [1]
Discussed with:	yongari [1]
2005-10-02 15:43:57 +00:00
Alexander Leidinger
62340837c3 General spl* cleanup. It doesn't serve any purpose anymore.
Submitted by:	Ariff Abdullah <skywizard@MyBSD.org.my>
2005-10-02 15:39:07 +00:00
Alexander Leidinger
cb44f623ec sys/dev/sound/pcm/ac97.c:
* Added codec id for CMI9761.
   * feeder_volume *whitelist* through ac97_fix_volume()

sys/dev/sound/pcm/ac97.h:
   * Added AC97_F_SOFTVOL definition.

sys/dev/sound/pcm/channel.c:
   * Slight changes for chn_setvolume() to conform with OSS.
   * FEEDER_VOLUME is now part of feeder building process.

sys/dev/sound/pcm/mixer.c:
   * General spl* cleanup. It doesn't serve any purpose anymore.
   * Main hook for feeder_volume.

Submitted by:	Ariff Abdullah <skywizard@MyBSD.org.my>
Tested by:	multimedia@
2005-10-02 15:37:40 +00:00
Alexander Leidinger
4406886f5e Soft volume implementation for audio devices without pcm mixer controller.
Submitted by:	Ariff Abdullah <skywizard@MyBSD.org.my>
Tested by:	multimedia@
2005-10-02 15:31:03 +00:00
Pyun YongHyeon
005a5d42fa Fix module unload panic which was caused by missing sx lock release.
While I'm here add KASSERT(9) to notify failure of SYSUNINIT handler.

Reported by:	Ben Kaduk < minimarmot AT gmail DOT com >
Tested by:	Ben Kaduk < minimarmot AT gmail DOT com >
2005-09-14 01:34:13 +00:00
Alexander Leidinger
831a62e7e5 - Fix the locking in dsp.c to prevent a LOR (AFAIK not on the LOR page).
- Remove an assertion in sound.c, it's not needed (and causes a panic now).
  From the conversation via mail between glebius and Ariff:
  ---snip---
  > Well, but which mutex protects now? Do we own anything else
  > in pcm_chnalloc()? I see some queue(4) macros in pcm_chnalloc(),
  > they should be protected, shouldn't they?
  Queue insertion/removal occur during
     1) driver loading (which is pretty much single thread /
        sequential) or unloading (mutex protected, bail out if there is
        any channel with refcount > 0 or busy).
     2) vchan_create()/destroy(), (which is *sigh* quite complicated), but
        somehow protected by 'master'/parent channel mutex. Other
        thread cannot add/remove vchan (or even continue traversing
        that queue) unless it can acquire parent channel mutex.
---snip---

Fix the locking in dsp.c to prevent a LOR (AFAIK not on the LOR page).

Submitted by:	Ariff Abdullah <skywizard@MyBSD.org.my>
Tested with:	INVARIANTS[1] and DIAGNOSTICS[2]
Tested by:	netchild [1,2], David Reid <david@jetnet.co.uk> [1]
2005-09-12 18:33:33 +00:00
Alexander Leidinger
97d69a9620 - channel.h
* New definition CHN_F_HAS_VCHAN.
- channel.c
  * Use CHN_F_HAS_VCHAN to mark channel with vchan capability instead
    of relying on SLIST_EMPTY(&channel->children) == true for better
    clarification and future possible usages of children (like
    'slave' channel).
  * Various fixes, including blocksize / format bps allignment,
    better 24bit seeking (mplayer, others).
  * Improve format chain building, it's now possible to record something
    to a format non-native to the soundcard through various feeder format
    converters or to higher sampling rate. This also gains another feature,
    like doing vchan mixing on non s16le soundcard such as sb8.
- sound.c
  * Increase robustness within various function that handle vchan
    creation / termination (these function need a total rewrite, but
    that would cause other major rewrite within various places too!).
    As far as its robustness can be guaranteed, leave it as is.
  * Optimize channel ordering, prefer *real* hardware playback
    channels over virtual channels. cat /dev/sndstat should look
    better.
  * Increase sndstat verbosity to include bufsoft/bufhard allocation.
- vchan.c
  * Fix LOR 119.
    - http://sources.zabbadoz.net/freebsd/lor.html#119
  * Reorder / increase robustness of vchan_create() / destroy().
    Enforce destroy_dev() during destroy operation, fix possible
    panic / dangling character device.
    - http://lists.freebsd.org/pipermail/freebsd-current/2005-May/050308.html
  * Tolerate a little bit more during mixing process, this should help
    non s16le soundcards.

Note: Recoring in a non-native rate/format may result in overruns. A friendly
      application is wavrec from audio/wavplay. The problem is under
      investigation.

Submitted by:	Ariff Abdullah <skywizard@MyBSD.org.my>
2005-09-10 18:10:31 +00:00
Alexander Leidinger
a423446c40 Release lock for a while during chn_reset() / pcm_chnalloc() operation
while malloc()ing, this fixes LOR 129.

See
 - http://lists.freebsd.org/pipermail/freebsd-current/2005-June/051157.html
 - http://lists.freebsd.org/pipermail/freebsd-current/2005-August/054620.html
 - http://sources.zabbadoz.net/freebsd/lor.html#129

Submitted by:	Ariff Abdullah <skywizard@MyBSD.org.my>
2005-09-10 17:51:38 +00:00
Alexander Leidinger
5cfcc28b60 - fake.c
* Add missing A_LAW / MU_LAW format.
- feeder.c
  * Fix format chain building. Traverse backward instead of forward
    during format chainning.
- feeder_fmt.c
  * Add missing alaw/mulaw converter.
  * Add 16 -> 24/32bit converter.
  * whitespace cleanup.
- sound.h
  * alaw / mulaw are member of AFMT_8BIT.

Submitted by:	Ariff Abdullah <skywizard@MyBSD.org.my>
2005-09-10 17:47:39 +00:00
Alexander Leidinger
8633619643 - Few buggy codecs (STAC9704, probably others) return inconsistent
ac97_rdcd() value. Enable aggresive workaround.
- Fix mixer resolution detection for 5/6 bit register, carefully not to
  overflow others.

PR:		84728
Submitted by:	Ariff Abdullah <skywizard@MyBSD.org.my>
2005-09-10 17:42:59 +00:00
Robert Watson
6a113b3de7 Merge the dev_clone and dev_clone_cred event handlers into a single
event handler, dev_clone, which accepts a credential argument.
Implementors of the event can ignore it if they're not interested,
and most do.  This avoids having multiple event handler types and
fall-back/precedence logic in devfs.

This changes the kernel API for /dev cloning, and may affect third
party packages containg cloning kernel modules.

Requested by:	phk
MFC after:	3 days
2005-08-08 19:55:32 +00:00
Alexander Leidinger
87506547d2 Whats New:
1. Support wide range sampling rate, as low as 1hz up to int32 max
   (which is, insane) through new feeder_rate, multiple precisions
   choice (32/64 bit converter). This is indeed, quite insane, but it
   does give us more room and flexibility. Plenty sysctl options to
   adjust resampling characteristics.
2. Support 24/32 bit pcm format conversion through new, much improved,
   simplified and optimized feeder_fmt.

Changes:
1. buffer.c / dsp.c / sound.h
   * Support for 24/32 AFMT.
2. feeder_rate.c
   * New implementation of sampling rate conversion with 32/64 bit
     precision, 1 - int32max hz (which is, ridiculous, yet very
     addictive).  Much improved / smarter buffer management to not
     cause any missing samples at the end of conversion process
   * Tunable sysctls for various aspect:
       hw.snd.feeder_rate_ratemin - minimum allowable sampling rate
       (default to 4000)
       hw.snd.feeder_rate_ratemax - maximum allowable sampling rate
       (default to 1102500)
       hw.snd.feeder_rate_buffersize - conversion buffer size
       (default to 8192)
       hw.snd.feeder_rate_scaling - scaling / conversion method
       (please refer to the source for explaination). Default to
       previous implementation type.
3. feeder_fmt.c / sound.h
   * New implementation, support for 24/32bit conversion, optimized,
     and simplified. Few routines has been removed (8 to xlaw, 16 to
     8). It just doesn't make sense.
4. channel.c
   * Support for 24/32 AFMT
   * Fix wrong xruns increment, causing incorrect underruns statistic
     while using vchans.
5. vchan.c
   * Support for 24/32 AFMT
   * Proper speed / rate detection especially for fixed rate ac97.
     User can override it using kernel hint:
     hint.pcm.<unit>.vchanrate="xxxx".

Notes / Issues:
        * Virtual Channels (vchans)
          Enabling vchans can really, really help to solve overrun
          issues.  This is quite understandable, because it operates
          entirely within its own buffering system without relying on
          hardware interrupt / state. Even if you don't need vchan,
          just enable single channel can help much. Few soundcards
          (notably via8233x, sblive, possibly others) have their own
          hardware multi channel, and this is unfortunately beyond
          vchan reachability.
        * The arrival of 24/32 also come with a price. Applications
          that can do 24/32bit playback need to be recompiled (notably
          mplayer).  Use (recompiled) mplayer to experiment / test /
          debug this various format using -af format=fmt. Note that
          24bit seeking in mplayer is a little bit broken, sometimes
          can cause silence or loud static noise. Pausing / seeking
          few times can solve this problem.
          You don't have to rebuild world entirely for this. Simply
          copy /usr/src/sys/sys/soundcard.h to
          /usr/include/sys/soundcard.h would suffice. Few drivers also
          need recompilation, and this can be done via
          /usr/src/sys/modules/sound/.
          Support for 24bit hardware playback is beyond the scope of
          this changes. That would require spessific hardware driver
          changes.
        * Don't expect playing 9999999999hz is a wise decision. Be
          reasonable. The new feeder_rate implemention provide
          flexibility, not insanity. You can easily chew up your CPU
          with this kind of mind instability. Please use proper
          mosquito repellent device for this obvious cracked brain
          attempt. As for testing purposes, you can use (again)
          mplayer to generate / play with different sampling rate. Use
          something like "mplayer -af resample=192000:0:0 <files>".

Submitted by:	Ariff Abdullah <skywizard@MyBSD.org.my>
Tested by:	multimedia@
2005-07-31 16:16:22 +00:00
Alexander Leidinger
fe435202da * Slightly new method to detect mixer capabilities and resolution.
This mostly to help CT4730, but apparently it does help other
  cards too (especially via8233x). This probably need further test
  and confirmation from other people with ac97 cards other than via
  / es137x.
* Aggresive dac power wake up call, again, to help CT4730 (and
  probably others).

Submitted by:	Ariff Abdullah <skywizard@MyBSD.org.my>
Tested by:	multimedia@
2005-07-31 14:28:31 +00:00
Alexander Leidinger
7233abab86 * Fix panic during driver unload on second attempt after failure on
first (device busy).
* Fix module unloading for sound.ko itself.

Submitted by:	Ariff Abdullah <skywizard@MyBSD.org.my>
Tested by:	multimedia@
2005-07-31 10:55:24 +00:00
Marius Strobl
169d14035a Wrap the calls to the ISA DMA specific sndbuf_dma*() functions of
sys/dev/sound/isa/sndbuf_dma.c (compilation depending on device isa)
in #ifdef DEV_ISA so sound(4) can be compiled without isa(4).

MFC after:	1 month
2005-06-10 21:33:14 +00:00
Scott Long
c5cb8d604c Fix the output ports on the AD1988 codec. From the submitter:
Affects to people WITH an AD1888 codec, the system will output to the port
labeled "speaker" instead of microphone.  System will work the same in
multiple operating systems.

If people are currently using their systems with this codec they will need
to swap their output ports.

I have _not_ checked audio input or line input (basically, I have checked
nothing other than line-out).

I believe this is an appropriate change, it makes us consistent with
documentation, and other operating systems.  Furthermore, this feature
(playing) is the vast majority of sound activities, so if this makes is
right for playback and wrong for recording... playback is more important,
and we can fix recoding in the future without worries of screwing people
again in the future (since we'll be "right" on the playback).

Submitted by: David Cross
2005-04-10 14:45:27 +00:00
Poul-Henning Kamp
f4f6abcb4e Explicitly hold a reference to the cdev we have just cloned. This
closes the race where the cdev was reclaimed before it ever made it
back to devfs lookup.
2005-03-31 12:19:44 +00:00
Poul-Henning Kamp
e70377df79 Use dynamic major number allocation. 2005-02-27 22:16:30 +00:00
Warner Losh
098ca2bda9 Start each of the license/copyright comments with /*-, minor shuffle of lines 2005-01-06 01:43:34 +00:00
Pyun YongHyeon
cea54ee291 Plug possible memory leak in sound DMA buffer handling. It also
changes return code to ENOMEM in case of allocation failure.

Approved by:	jake (mentor), scottl (co-mentor)
Reviewed by:	truckman, matk
2004-10-15 03:50:04 +00:00
Don Lewis
ca219d048a Convert sndstat_lock from a mutex to an sx lock. sndstat_read()
holds sndstat_lock across a call to uiomove(), which is not legal
to do with a  mutex because of the possibility that the data transfer
could sleep because of a page fault.  It is not possible to just
unlock the mutex for the uiomove() call without introducing another
locking mechanism to prevent the body of sndstat_read() from being
re-entered.  Converting sndstat_lock to an sx lock is the least
complicated change.

This is a candidate for RELENG_5.

LOR:		030
MFC after:	4 days
2004-09-10 09:37:06 +00:00
Seigo Tanimura
0739ea1de2 Rename the sound device drivers:
- `sound'
  The generic sound driver, always required.

- `snd_*'
  Device-dependent drivers, named after the sound module names.
  Configure accordingly to your hardware.

In addition, rename the `snd_pcm' module to `sound' in order to sync
with the driver names.

Suggested by:	cg
2004-07-16 04:00:08 +00:00
Marcel Moolenaar
b8c48216b1 Remove DDB. The one user of this macro has been changed to use BVDDB.
Yes, DDB is unrelated to the debugger with the same acronym. Hence,
the change.
2004-07-10 21:13:28 +00:00
Alexander Leidinger
a92c890fd1 Implement SNDCTL_DSP_SETDUPLEX. This may fix sound apps which want to
use full duplex mode.

Approved by:	matk
2004-07-02 15:31:44 +00:00
Josef El-Rayes
ae6d3a22dc Fix uninitialized variable, that breaks the build.
Approved by: hmp
Reviewed by: chris
Pointy hat to: josef (for ignoring warning)
2004-06-25 16:34:33 +00:00
Josef El-Rayes
8ba7f5cfee Change the possibility to configure pcm(4) via boot/loader.conf
to use boot/device.hints now

As discussed on cvs-src@

Reviewed by:	Hiten Pandya <hmp@backplane.com>
2004-06-24 17:41:20 +00:00
Josef El-Rayes
9d12118e78 Enable pcm to read kenv variables to set default values for
mixer channels.

e.g.: pcm0.line=0

to muten input line per default.

Approved by:    cg
Reviewed by:    le, stefanf
Requested by:   Eugene Grosbein <eugen@grosbein.pp.ru> (implicitly)
PR:             kern/63771
2004-06-20 15:38:11 +00:00
Poul-Henning Kamp
f3732fd15b Second half of the dev_t cleanup.
The big lines are:
	NODEV -> NULL
	NOUDEV -> NODEV
	udev_t -> dev_t
	udev2dev() -> findcdev()

Various minor adjustments including handling of userland access to kernel
space struct cdev etc.
2004-06-17 17:16:53 +00:00
Poul-Henning Kamp
89c9c53da0 Do the dreaded s/dev_t/struct cdev */
Bump __FreeBSD_version accordingly.
2004-06-16 09:47:26 +00:00
Don Lewis
144a53875b Nuke a cryptic and useless diagnostic printf(). 2004-06-07 12:25:14 +00:00
MIHIRA Sanpei Yoshiro
e5728f83a0 Add support CS4294
PR:		kern/66280
Submitted by:	Christian Brueffer <chris@unixpages.org>
2004-05-08 03:41:40 +00:00
Brian Feldman
35ce92de2d Don't do malloc(M_WAITOK) for sound buffers while locks are held. 2004-04-29 02:51:59 +00:00
Brian Feldman
8fb9a995cf The newpcm headers currently #define away INTR_MPSAFE and INTR_TYPE_AV
because they bogusly check for defined(INTR_MPSAFE) -- something which
never was a #define.  Correct the definitions.

This make INTR_TYPE_AV finally get used instead of the lower-priority
INTR_TYPE_TTY, so it's quite possible some improvement will be had
on sound driver performance.  It would also make all the drivers
marked INTR_MPSAFE actually run without Giant (which does seem to
work for me), but:
	INTR_MPSAFE HAS BEEN REMOVED FROM EVERY SOUND DRIVER!
It needs to be re-added on a case-by-case basis since there is no one
who will vouch for which sound drivers, if any, willy actually operate
correctly without Giant, since there hasn't been testing because of
this bug disabling INTR_MPSAFE.

Found by:	"Yuriy Tsibizov" <Yuriy.Tsibizov@gfk.ru>
2004-04-14 14:57:49 +00:00
Mathew Kanner
0d8ed52ea5 Augment /dev/sndstat with the module names, if applicable.
Approved by:	  tanimura (mentor)
2004-03-06 15:52:42 +00:00
Don Lewis
a3193a9ca3 Create a new mutex type for virtual channels. This allows us to get
rid of the MTX_DUPOK flag on channel mutexes, which allows witness to
do a better job of lock order checking.  Nuke snd_chnmtxcreate() since
it is no longer needed.

Tested by:	matk
2004-02-28 19:47:02 +00:00
Don Lewis
466f31e55b Lock channels only as necessary in dsp_ioctl(), and only lock one
channel at a time unless it is actually necessary to lock both.
This avoids problems with lock order reversal and malloc() calls
with a mutex held when lower level code unlocks a channel, calls malloc(),
and relocks the channel.  This also avoids the cost of some  unnecessary
locking and unlocking.

Tested by:	matk
2004-02-28 19:42:48 +00:00
Poul-Henning Kamp
dc08ffec87 Device megapatch 4/6:
Introduce d_version field in struct cdevsw, this must always be
initialized to D_VERSION.

Flip sense of D_NOGIANT flag to D_NEEDGIANT, this involves removing
four D_NOGIANT flags and adding 145 D_NEEDGIANT flags.
2004-02-21 21:10:55 +00:00
Mathew Kanner
0a2a8111d2 Fix a glitch in my last commit and revert to using selwakeuppri
Noticed by:	tanimura
Noticed by:	truckman
2004-02-20 01:24:57 +00:00
Mathew Kanner
e0b6c8a1da Fix a long-standing bug where select on vchans doesn't work
(never wake up) by iterating over them when they exist.

Approved by:	tanimura (mentor)
2004-02-19 01:07:15 +00:00
Don Lewis
12e524a290 Change KASSERT() in feed_vchan16() into an explicit test and call to
panic() so that the buffer overflow just beyond this point is always
caught, even when the code is not compiled with INVARIANTS.

Change chn_setblocksize() buffer reallocation code to attempt to avoid
the feed_vchan16() buffer overflow by attempting to always keep the
bufsoft buffer at least as large as the bufhard buffer.

Print a diagnositic message
	Danger! %s bufsoft size increasing from %d to %d after CHANNEL_SETBLOCKSIZE()
if our best attempts fail.  If feed_vchan16() were to be called by
the interrupt handler while locks are dropped in chn_setblocksize()
to increase the size bufsoft to match the size of bufhard, the panic()
code in feed_vchan16() will be triggered.  If the diagnostic message
is printed, it is a warning that a panic is possible if the system
were to see events in an "unlucky" order.

Change the locking code to avoid the need for MTX_RECURSIVE mutexes.

Add the MTX_DUPOK option to the channel mutexes and change the locking
sequence to always lock the parent channel before its children to avoid
the possibility of deadlock.

Actually implement locking assertions for the channel mutexes and fix
the problems found by the resulting assertion violations.

Clean up the locking code in dsp_ioctl().

Allocate the channel buffers using the malloc() M_WAITOK option instead
of M_NOWAIT so that buffer allocation won't fail.  Drop locks across
the malloc() calls.

Add/modify KASSERTS() in attempt to detect problems early.

Abuse layering by adding a pointer to the snd_dbuf structure that points
back to the pcm_channel that owns it.  This allows sndbuf_resize() to do
proper locking without having to change the its API, which is used by
the hardware drivers.

Don't dereference a NULL pointer when setting hw.snd.maxautovchans
if a hardware driver is not loaded.  Noticed by Ryan Sommers
<ryans at gamersimpact.com>.

Tested by:	Stefan Ehmann <shoesoft AT gmx.net>
Tested by:	matk (Mathew Kanner)
Tested by:	Gordon Bergling <gbergling AT 0xfce3.net>
2004-01-28 08:02:15 +00:00
Mathew Kanner
e7245381b9 Fix a panic in dsp_clone when trying to access a sound
device that doesn't exists.  I'm using my discretion and
committing without mentor approval since Seigo is away.

Noticed by:	Maxime Henrion <mux@freebsd.org>
2004-01-25 22:46:22 +00:00
Mathew Kanner
3c6b655dff Sync with DFBSD v.1.16. Add new codecs IDs, fix some spelling.
Approved by:    des (interim mentor)
2004-01-23 16:38:54 +00:00
Mathew Kanner
222d2384ef Reduce latency when using the SNDCTL_DSP_RESET ioctl by calling
chn_resetbuf().

Submited by:	Pyun YongHyeon <yongari@kt-is.co.kr>
Approved by:	tanimura (mentor)
2004-01-20 05:30:09 +00:00
Mathew Kanner
5ee30e277a Fix a panic when kldloading a sound driver. Do this by replacing the
link-list of dev_t's with named variables.  Remove used code.

Approved by:		tanimura (mentor)
2004-01-20 03:58:57 +00:00
Poul-Henning Kamp
4555065861 As previously announced: discontinue use of makedev() call in soundcode.
This takes us a lot closer to refcounting dev_t.

This patch originally by cg@ with a few minor changes by me.

It is largely untested, but has been HEADSUP'ed twice, so presumably
people have not found any issues with it.

Submitted by:	cg@
2004-01-17 10:37:11 +00:00
Don Lewis
55a3845131 The last argument to mtx_init() should be MTX_DEF, not 0. This is not a
functional change since MTX_DEF happens to be defined as 0.
2003-12-08 01:08:03 +00:00
Mathew Kanner
bc38932a58 Fix some locking violations by creating seperate mutex classes
for play and record channels.

Approved by:	seigo (mentor)
Approved by:	scottl (re)
2003-12-05 02:08:13 +00:00
Mathew Kanner
8e2d74a486 Fix a panic due to holding a lock over calls to uiomove.
Pointed out by:	Artur Poplawski
Explained by:	Don Lewis (truckman)
Approved by:	tanimura (mentor)
Approved by:	scottl	(re)
2003-11-27 19:51:44 +00:00
Jun Kuriyama
94ed763dee Add ID for ALC658 CODEC.
Tested on:	GIGABYTE GA-8S655FX-L
Reviewed by:	orion
2003-11-11 22:15:17 +00:00
Scott Long
42c3555cff Fix sound LOR problems:
dsp_open: rearrange to only hold one lock at a time

dsp_close: ditto

mixer_hwvol_init: delete locking, the only consumer seems to
be the ess driver and it only call it a creation time, I
think the device will be stable across the sleepable malloc.

cmi interrupt routine: Release locks while caller chn_intr,
either this or do what emu10k1 does which is have no locks
at in the interrupt handler.

Submitted by:	mat@cnd.mcgill.ca
2003-11-11 05:38:28 +00:00
Seigo Tanimura
512824f8f7 - Implement selwakeuppri() which allows raising the priority of a
thread being waken up.  The thread waken up can run at a priority as
  high as after tsleep().

- Replace selwakeup()s with selwakeuppri()s and pass appropriate
  priorities.

- Add cv_broadcastpri() which raises the priority of the broadcast
  threads.  Used by selwakeuppri() if collision occurs.

Not objected in:	-arch, -current
2003-11-09 09:17:26 +00:00
Dag-Erling Smørgrav
5197cdc1aa Recognize the Avance Logic ALC655 codec found on some ICH4/5-based
motherboards, such as the Gigabyte I848P.

PR:		kern/54176
Submitted by:	Chris Keladis <chris@cmc.optus.net.au>
Forgotten by:	orion
2003-10-12 11:51:24 +00:00
Cameron Grant
3f22597838 update my email address. 2003-09-07 16:28:03 +00:00
Orion Hodson
6f0182bd0c Add Creative EV1938.
Submitted by:	David Xu <davidxu@FreeBSD.org>
PR:		kern/54810
2003-08-29 03:24:08 +00:00
Orion Hodson
cfd5696d22 When present use ogain instead of master for surround sound channels.
The latter has lead to reports of broken audio.

Do not swap ogain and master when headphones detected.
2003-08-23 21:39:51 +00:00
Ian Dowse
72d173fa8f Fix an off-by-one error in feed_monotostereo16() that caused the
first sample in the buffer to be ignored. The bug caused a repetitive
glitch in one of the stereo channels when playing mono sound on
configurations that use the monotostereo16 feeder.

Reviewed by:	orion
2003-08-23 12:18:30 +00:00
Orion Hodson
49fd69053e Additional VT1616 id.
Submitted by: Greg Lewis
2003-08-21 23:22:51 +00:00
Orion Hodson
a52604cf48 Apply Rudolf Cejka's patch for:
o AD1980 hook.
o ac97_fix_auxout.

and:

o Associate AC97_MIX_AUXOUT with SOUND_MIXER_OGAIN rather than
SOUND_MIXER_MONITOR.

o Add ac97_fix_tone to remove tone controls from mixer if invalid.
2003-08-21 15:50:32 +00:00
Orion Hodson
daa738f848 Add patch for AD198x.
Submitted by: Oleg Sharoiko, Rudolf Cejka.
2003-08-21 15:44:55 +00:00
Cameron Grant
a527dbc77c handle locking when creating or destroying vchans better 2003-08-18 23:20:39 +00:00
Cameron Grant
a5dc588839 try to make really sshort sounds actually play 2003-08-18 23:18:47 +00:00
Cameron Grant
b9c6d8cdcf modify comments 2003-08-15 02:31:13 +00:00
Diomidis Spinellis
5987356569 Change gcc-specific aggregate initialization member specifiers
into C9X initializer designators.

Reviewed by:	schweikh (mentor)
MFC after:	4 weeks
2003-08-05 07:23:35 +00:00
Cameron Grant
eaa69ee9a9 * add a function to display a complete feeder chain on the console, for
debugging.

* set the parent of non-format feeders, so that sndstat doesn't miss out
things like feeder_rate.

MFC:		1 week
2003-07-07 17:40:02 +00:00
Matthew N. Dodd
f1e875be01 Set a lower bound on fragment size rather than returning a failure
when the user specifies a maximum fragment size < 2.

This is the behavior that Linux provides and fixes the problem I've
observed in Tribes2 where sounds effects are delayed by 1/2 a second.
2003-06-26 13:13:18 +00:00
Orion Hodson
4f3204ef22 Fix lock order reversal when opening device and chn_reset fails.
Submitted by: Jan-Espen Pettersen <sigsegv@leakingmemory.org>
Tested by: Georg Funk <georgfunk@web.de>
2003-05-01 16:31:21 +00:00
John Baldwin
6faa2f6d6e Comment out the mixer entry for igain for the mic 20dB boost for now since
it can cause feedback problems on some laptops.

Reviewed by:	orion
2003-04-23 16:49:53 +00:00
Orion Hodson
61a0da1de5 Add eMicro codec ids. 2003-04-21 04:48:40 +00:00
Orion Hodson
96524a52b6 Use SOUND_MIXER_IGAIN to toggle 20dB mic boost for want of a better
place for it.

Assorted comments.

Submitted by: luigi
2003-04-21 03:47:28 +00:00
Orion Hodson
6635978f23 Additional malloc failure checks. 2003-04-20 17:08:56 +00:00
Orion Hodson
ba548c643a Additional codec ids. 2003-04-04 07:37:25 +00:00
Jake Burkholder
227f9a1c58 - Add vm_paddr_t, a physical address type. This is required for systems
where physical addresses larger than virtual addresses, such as i386s
  with PAE.
- Use this to represent physical addresses in the MI vm system and in the
  i386 pmap code.  This also changes the paddr parameter to d_mmap_t.
- Fix printf formats to handle physical addresses >4G in the i386 memory
  detection code, and due to kvtop returning vm_paddr_t instead of u_long.

Note that this is a name change only; vm_paddr_t is still the same as
vm_offset_t on all currently supported platforms.

Sponsored by:	DARPA, Network Associates Laboratories
Discussed with:	re, phk (cdevsw change)
2003-03-25 00:07:06 +00:00
Orion Hodson
9963235abc Correct vendor id for ALC101. 2003-03-20 18:17:39 +00:00
Orion Hodson
b2a0f525e6 Correct CS4205 base vendor id.
Reported by:    Christophe Juniet and Mark Santcroos.
2003-03-12 15:11:25 +00:00
Orion Hodson
a7576e2e4b Back out last commit, which is fine in theory, but ignores the fact
that a lock is held whilst the allocations are made (M_WAITOK -> M_NOWAIT).
2003-03-05 14:48:28 +00:00
Poul-Henning Kamp
7ac40f5f59 Gigacommit to improve device-driver source compatibility between
branches:

Initialize struct cdevsw using C99 sparse initializtion and remove
all initializations to default values.

This patch is automatically generated and has been tested by compiling
LINT with all the fields in struct cdevsw in reverse order on alpha,
sparc64 and i386.

Approved by:    re(scottl)
2003-03-03 12:15:54 +00:00
Orion Hodson
19921b23b5 o Move vendor ids into separate table.
o Add assorted vendor and codec ids.
2003-02-28 18:04:52 +00:00
Scott Long
4bc7efe837 Add the ID for the CS4205 codec found in Dell laptops. Obtained from
the CS4205 spec.
2003-02-27 03:51:43 +00:00
Olivier Houchard
7ee68e82e7 Add SigmaTel STAC9750 entry.
Submitted by:	Paulius Bulotas <paulius.bulotas@microlink.lt>
2003-02-26 18:39:04 +00:00
Orion Hodson
a4273e83bc Replicate OSS behaviour when rate settings fails.
PR:	kern/26563
2003-02-26 14:38:19 +00:00
Maxime Henrion
07159f9c56 Cleanup of the d_mmap_t interface.
- Get rid of the useless atop() / pmap_phys_address() detour.  The
  device mmap handlers must now give back the physical address
  without atop()'ing it.
- Don't borrow the physical address of the mapping in the returned
  int.  Now we properly pass a vm_offset_t * and expect it to be
  filled by the mmap handler when the mapping was successful.  The
  mmap handler must now return 0 when successful, any other value
  is considered as an error.  Previously, returning -1 was the only
  way to fail.  This change thus accidentally fixes some devices
  which were bogusly returning errno constants which would have been
  considered as addresses by the device pager.
- Garbage collect the poorly named pmap_phys_address() now that it's
  no longer used.
- Convert all the d_mmap_t consumers to the new API.

I'm still not sure wheter we need a __FreeBSD_version bump for this,
since and we didn't guarantee API/ABI stability until 5.1-RELEASE.

Discussed with:		alc, phk, jake
Reviewed by:		peter
Compile-tested on:	LINT (i386), GENERIC (alpha and sparc64)
Runtime-tested on:	i386
2003-02-25 03:21:22 +00:00
Brian Feldman
3fbe138ca9 It seems that sound(4)'s feeder routines don't need to allocate memory
without waiting, since they are called from a system-call context only.
This appears to fix all sorts of problems with open("/dev/dsp", O_WRONLY)
randomly returning ENXIO.

Found by:	cognet
2003-02-23 20:49:45 +00:00
Olivier Houchard
38cc994207 Implement a "sndbuf_getbufaddr" function and use it instead of vtophys().
Reviewed by:	orion
2003-02-20 17:31:12 +00:00
Warner Losh
a163d034fa Back out M_* changes, per decision of the TRB.
Approved by: trb
2003-02-19 05:47:46 +00:00
Brian Feldman
d00d7d5c39 Sound devices were being leaked by dsp_open() not actually releasing the
channels it allocates if chn_reset() on them resulted in failure.
ARROW'D!
2003-02-11 16:58:54 +00:00
Yoshihiro Takahashi
3febcc57ec - Clean up ISA DMA supports.
- Rename all sndbuf_isadma* functions to sndbuf_dma* and move them into
  sys/dev/sound/isa/sndbuf_dma.c.

No response from:	sound
2003-02-07 14:05:34 +00:00
Orion Hodson
63679b6573 Fix comment typo.
Sync with userland test framework which now deals better with pcm feeder kobj
emulation.

Reduce max rate from 96kHz to 48kHz as userland tests found a few bad
points about 90kHz and we don't care about operating up there for now.
2003-02-06 17:32:02 +00:00
Orion Hodson
faea679930 Avoid zero padding when feeding read channels. chn_rdfeed has no way
of knowing data size transformations of feeder chain and in some cases
this means too much data is pulled through chain, eg converting input
stream from 16bits to 8bits on 16bit only h/w.

PR: kern/37831
Submitted by: Harti Brandt <brandt@fokus.fraunhofer.de>
2003-02-03 15:02:28 +00:00
Orion Hodson
ac224567bf Remove mono encodings from vchan format and mixer description. Fixes
mono formats at 44.1kHz playing at double speed when vchans are
enabled.
2003-02-03 03:20:27 +00:00
Orion Hodson
a825c6e59e Print ac97 name/id on normal boot.
Fix typo reported in pr misc/47794.
2003-02-03 01:38:43 +00:00
Alfred Perlstein
c023201af1 remove MIN now that it's a standard kernel define 2003-02-02 13:21:05 +00:00
Orion Hodson
456922d5f2 o Constrain inputs to 25Hz granularity so interpolator can operate
between any pair of values in range 4-96kHz.  Thanks to Ken Marks for
discovering there were problems with the previous version.

o Use a non-recursive gcd routine.
2003-01-30 16:32:56 +00:00
Orion Hodson
f9eb140935 Add ac97_patch.[ch] that provide space for ac97 codec specific patches. 2003-01-25 16:54:05 +00:00
Alfred Perlstein
44956c9863 Remove M_TRYWAIT/M_WAITOK/M_WAIT. Callers should use 0.
Merge M_NOWAIT/M_DONTWAIT into a single flag M_NOWAIT.
2003-01-21 08:56:16 +00:00
Orion Hodson
4a532ff091 Re-implemention of the interpolation code used for sample rate
conversion.  The new version has improved interpolation accuracy and
maintains the timing relationship between the input and output signals
exactly.

Approved by:	cg
2003-01-20 00:54:24 +00:00
Olivier Houchard
e550089d43 Don't call destroy_dev it a channel has children.
vchan creation doesn't lead to /dev entry creation if the new vchan is the
first child of a channel,
This fix a panic that happens when loading a sound driver module, creating
vchans and unloading the driver.

Approved by:	cg
MFC after:	3 days
2003-01-14 17:13:52 +00:00
Orion Hodson
916aaded05 Add Realtek ALC650 id.
Submitted by:	"Mikko S. Hyvarinen" <morphy@morphy.iki.fi>
MFC after:	5 days
2003-01-13 17:43:49 +00:00
Brian Feldman
a8be3e63ce Fix the duplicate unlock of the pcm read channel in certain cases.
Reviewed by:	cg
2003-01-05 07:32:33 +00:00
Cameron Grant
00acb1337e (hopefully) fix build breakage some people are seeing
Approved by:	re
2002-11-26 18:16:27 +00:00
Cameron Grant
67beb5a5c8 various fixes to eliminate locking warnings
Approved by:	re
Reviewed by:	orion
2002-11-25 17:17:43 +00:00
Olivier Houchard
e33bee0756 Call pcm_chn_destroy() in pcm_killchan() so that channel mutexes are destroyed and struct pcm_channel freed.
Reviewed by:	cg
MFC after:	3 days
2002-11-04 19:12:02 +00:00
Bruce Evans
ab85003bf5 Fixed breakage from removing the used include of <sys/buf.h> in the
previous commit:
Include <sys/mutex.h> and its prerequisite <sys/lock.h> instead of
depending on namespace pollution in <sys/buf.h>.  Only do this in the
__FreeBSD_version > 500000 case although the __FreeBSD_version < 500000
case has already rotted.
2002-09-15 08:21:14 +00:00
Poul-Henning Kamp
296bbb4cfb FreeBSD -current doesn't need <sys/buf.h> or <sys/bio.h>. 2002-09-14 18:58:36 +00:00
Orion Hodson
47d5a0f3e5 Marginally simplify dsp_open error handling by adding an early test to
determine liklihood of opening device in requested directions.  Makes for
simpler error handling and change should close kern/35004.

PR: kern/35004.
2002-08-28 15:19:30 +00:00
Nick Sayer
47172de8a2 Be sure to unregister from sndstat on unregister. Gets rid of phantom
sndstat output after removing uaudio.
2002-08-24 19:13:11 +00:00
Orion Hodson
108082c42e s/AC97_MIX_PHONES/AC97_MIX_AUXOUT/ to match ac97r2.{2,3}.
Attempt to determine what function of AUX_OUT is: "True line level
out", "Headphone out", or "4-Channel out" and frig OSS mixer label
accordingly.

Addresses problem raised by Randy Bush on -multimedia of not being
able to hear audio on ich2 m/b which was eventually found to be
because the mixer monitor value was 0.  On this h/w the label
"monitor" should now be presented as the marginally more intuitive
"ogain".
2002-08-23 06:19:28 +00:00
Archie Cobbs
4a6a94d8d8 Replace (ab)uses of "NULL" where "0" is really meant. 2002-08-22 21:24:01 +00:00
Orion Hodson
2296709020 Back out last commit. Needs slightly more subtle handling. 2002-08-20 08:02:56 +00:00
Orion Hodson
42e67fd3e7 Apply reference counting patch. Fixes problem of two applications
opening the device, eg one read only and one write only, and the
reference count being non-zero when both exit rendering device
permanently busy.

PR:		kern/35004
Submitted by:	Bill Wells
MFC after:	3 days
2002-08-18 14:17:06 +00:00
Brian Feldman
ca33ae2367 Fix some of the places where sound(4) can sleep with a lock held. (Help
courtesy of fenner).
2002-07-25 04:49:45 +00:00
Alexander Kabaev
61698e0ca1 Fix the sound driver vchan support to work when hw.snd.maxautovchans
has been specified through /boot/loader.conf as opposed to setting it
in /etc/sysctl.conf. Only PCMDIR_PLAY channel can be used as a parent
of virtual channel. Do not initialize a new vchan for a given physical
channel if other physical channel already has one created.

PR:	31597
Approved by:	obrien (mentor)
2002-07-23 14:50:51 +00:00
Orion Hodson
7cf0e77a00 Move lock in pcm_chn_add() to after malloc.
PR:             kern/40157
Submitted by:   Dan Lukes <dan@obluda.cz>
2002-07-22 02:38:20 +00:00
Mark Murray
64d85ef750 Use semicolons at the end of function-like macros for the sake of
consistency, style and future cleanliness.
2002-07-15 13:03:10 +00:00
Bruce Evans
e788f79698 Fixed printf format errors which apparently crept in while -Wformat was
disabled for gcc-3.
2002-05-25 11:18:03 +00:00
Peter Wemm
9cfd8eb371 Try and solve some cases of labels at end of compound statements that gcc
now objects to (as it should, it is not legal C).
2002-05-19 06:31:56 +00:00
David E. O'Brien
90a78bd0ba makeobjops.awk is stricter on syntax than the perl version. 2002-05-01 03:52:40 +00:00
David E. O'Brien
82303b6b14 Remove the trailing ^M's. makeobjops.awk does not like them. 2002-05-01 03:07:40 +00:00
Cameron Grant
21ed9908a2 add a missing \n to an unregister failure message 2002-04-28 22:59:45 +00:00
Orion Hodson
c6d4b83ad1 Add ac97_reset function that polls ready bits in power register. One
component in tweaks required for the ICH3 controller in the thinkpad
x22 reported by Colin Perkins on -multimedia.
2002-04-26 15:27:56 +00:00
John Baldwin
2c823989e1 Fix a warning due to the code assuming sizeof(int) == sizeof(void *) which
is not true on the alpha.  I think that other parts of this code also make
this implicit assumption as well.
2002-04-11 15:31:01 +00:00
John Baldwin
6008862bc2 Change callers of mtx_init() to pass in an appropriate lock type name. In
most cases NULL is passed, but in some cases such as network driver locks
(which use the MTX_NETWORK_LOCK macro) and UMA zone locks, a name is used.

Tested on:	i386, alpha, sparc64
2002-04-04 21:03:38 +00:00
John Baldwin
489c22ebb8 Add lock type arguments to callers of snd_mtxcreate(). 2002-04-04 20:56:47 +00:00
John Baldwin
2c69ba8741 Change snd_mtxcreate() to accept a lock type as an extra argument that is
passed to mtx_init().
2002-04-04 20:54:27 +00:00
Alfred Perlstein
85f190e4d1 Fixes to make select/poll mpsafe.
Problem:
  selwakeup required calling pfind which would cause lock order
  reversals with the allproc_lock and the per-process filedesc lock.
Solution:
  Instead of recording the pid of the select()'ing process into the
  selinfo structure, actually record a pointer to the thread.  To
  avoid dereferencing a bad address all the selinfo structures that
  are in use by a thread are kept in a list hung off the thread
  (protected by sellock).  When a selwakeup occurs the selinfo is
  removed from that threads list, it is also removed on the way out
  of select or poll where the thread will traverse its list removing
  all the selinfos from its own list.

Problem:
  Previously the PROC_LOCK was used to provide the mutual exclusion
  needed to ensure proper locking, this couldn't work because there
  was a single condvar used for select and poll and condvars can
  only be used with a single mutex.
Solution:
  Introduce a global mutex 'sellock' which is used to provide mutual
  exclusion when recording events to wait on as well as performing
  notification when an event occurs.

Interesting note:
  schedlock is required to manipulate the per-thread TDF_SELECT
  flag, however if given its own field it would not need schedlock,
  also because TDF_SELECT is only manipulated under sellock one
  doesn't actually use schedlock for syncronization, only to protect
  against corruption.

Proc locks are no longer used in select/poll.

Portions contributed by: davidc
2002-03-14 01:32:30 +00:00
Dag-Erling Smørgrav
a0eed7bc1c Add a sysctl, sysctl hw.snd.report_soft_formats, that controls whether the
AIOGCAP ioctl reports software-emulated formats.  It defaults to on.  People
who use performance-sensitive audio software and do not want it to pick a
software-emulated audio format instead of one supported by their hardware
should turn it off.

This unbreaks isdnphone(1) on systems with PCM-only sound cards.

Approved by:	cg
2002-02-24 00:49:43 +00:00
Cameron Grant
b8a3639565 * improve error handling
* be more specific in verbose boot messages
* allow the feeder subsystem to veto pcm* attaching if there is an error
  initialising the root feeder
* don't free/malloc a new tmpbuf when resizing a snd_dbuf to the same size as
  it currently is
* store the feeder description in the feeder structure instead of mallocing
  space for it
2002-01-26 22:13:24 +00:00
Scott Long
436c9b651a Fix code that had rotted behind debugging macros.
Approved by:	cg (in principle)
MFC after:	2 weeks
2002-01-25 04:14:12 +00:00
Cameron Grant
be27d718c0 a buffer offset equal to the buffer size is illegal too, fix assertion in
sndbuf_getbufofs()
2002-01-25 02:39:34 +00:00
Cameron Grant
f8db81f347 cosmetic change, free b instead of c->bufhard for consistency within
chn_kill()
2002-01-25 02:36:22 +00:00
Cameron Grant
4c68642adb improve sndstat output of feederchains so it can be understood without
reading the feeder sourcecode
2002-01-23 06:02:15 +00:00
Cameron Grant
4e60be3473 print warnings if a pcm*.buffersize hint is out of range or a non-power-of-2 2002-01-23 05:49:41 +00:00
Cameron Grant
23bc171b29 fix some comments accidentally hit by search/replace several revisions ago 2002-01-23 05:41:35 +00:00
Cameron Grant
0dd4f3508e set the speeds the right way round for recording using the rate feeder 2002-01-23 05:35:12 +00:00
Cameron Grant
1e59d53c22 add more error checking in chn_init() and chn_reset() 2002-01-23 05:21:27 +00:00
Cameron Grant
79e6a82b48 make the feederchain builder work for recording. this has not been tested
extensively as none of my testboxes have speakers or an audio source at
present, but the chains built look correct and reading /dev/audio (ulaw,
translated from signed 16 bit little-endian) gives values within the
expected range for silence.
2002-01-23 05:10:56 +00:00
Cameron Grant
f6126456ef don't bother checking if an unsigned parameter is less than 0 in a KASSERT 2002-01-23 04:50:51 +00:00
Cameron Grant
095159ecd1 add more error checking to open of /dev/dsp* and /dev/audio* - if the
default format for the chosen subdevice cannot be obtained return an error
instead of returning success with an indeteterminate format selected.

note that this should never happen once the feederchain builder works for
recording.
2002-01-23 04:44:03 +00:00
Cameron Grant
1c72c53f4e don't allow mmap beyond the end of the buffer
Submitted by:	Philippe Anel <philippe.anel@noos.fr> (partially)
2002-01-23 04:32:18 +00:00
Cameron Grant
193d571957 make mmapped vchans work 2001-12-23 13:10:29 +00:00
Cameron Grant
b83a42d36f fix mmapped playback
remove dead debugging code
2001-12-21 22:34:01 +00:00
Guido van Rooij
b60e55dbd0 Get rid of irritating (bogus) message:
pcm0: ac97 codec failed to reset extended mode (0, got 80)
This was due to not masking off the correct extended function bits
in the read value from the extended status reg.

MFC after:	2 days
2001-12-10 20:27:18 +00:00
David E. O'Brien
6e551fb628 Update to C99, s/__FUNCTION__/__func__/,
also don't use ANSI string concatenation.
2001-12-10 08:09:49 +00:00
Orion Hodson
647fbfebc5 Emit a warning if invalid mode passed to ac97_setextmode.
MFC after:	3 days
2001-11-21 04:08:10 +00:00
Cameron Grant
16a33022e7 fix SNDCTL_DSP_GETISPACE behaviour 2001-10-24 12:40:54 +00:00
Cameron Grant
8309fd9aef improve recording behaviour 2001-10-24 12:33:21 +00:00
John Baldwin
ed01445d8f Use the passed in thread to selrecord() instead of curthread. 2001-09-21 22:46:54 +00:00
Cameron Grant
a67fe5c1d6 change tracking of channel counts.
add method for retrieving "buffersize" hints for pcm devices, adjusted for
specified minimum, maximum and default values.
2001-09-18 14:50:52 +00:00
Cameron Grant
a3a1ce3024 add a tunable/sysctl, hw.snd.targetirqrate, to modify the default target
irq rate for apps that do not set a blocksize.
2001-09-18 14:45:09 +00:00
Cameron Grant
5d91ad679d add a method for retrieving codec capabilities 2001-09-18 14:34:59 +00:00
George C A Reid
5c25132af5 - Correctly increment the channel refcount in dsp_open() such that it is
no longer possible to unload the driver module while sound is playing
  (which resulted in a panic).
- Fix a similar problem with the sndstat device that I found while looking
  at the above.
- Append a newline character to error messages in pcm_unregister()

Reviewed by:	cg
MFC after:	10 days
2001-09-14 20:26:03 +00:00
Julian Elischer
b40ce4165d KSE Milestone 2
Note ALL MODULES MUST BE RECOMPILED
make the kernel aware that there are smaller units of scheduling than the
process. (but only allow one thread per process at this time).
This is functionally equivalent to teh previousl -current except
that there is a thread associated with each process.

Sorry john! (your next MFC will be a doosie!)

Reviewed by: peter@freebsd.org, dillon@freebsd.org

X-MFC after:    ha ha ha ha
2001-09-12 08:38:13 +00:00
Cameron Grant
506a5308bc add a method for recording of specific channels for devices with more than
one hardware record channel.  new devices, /dev/dsprX.Y where X is unit
number and Y is channel index.
2001-09-05 16:28:41 +00:00
Cameron Grant
c2e6dd76ce don't try to dump nonexistent data when recording 2001-09-05 14:49:44 +00:00
Cameron Grant
edecdda7b9 tweaks to reduce latency/pauses in output 2001-08-29 09:17:43 +00:00
Cameron Grant
a32858897e add some extra diagnostic info to sndstat output. 2001-08-29 02:49:54 +00:00
Cameron Grant
4f4449e01c now we have the rate feeder, we don't need to constrain the default channel
speed.  however, continue to do so for record channels until the feederchain
builder is fixed.
2001-08-27 01:02:13 +00:00
Cameron Grant
4132a3b206 the feederchain builder is currently broken for recording channels. disable
it until it is fixed.  this limits recording to native formats and speeds
only.
2001-08-23 12:27:27 +00:00
Cameron Grant
334326a17f handle bogus values passed to SOUND_PCM_WRITE_CHANNELS/SNDCTL_DSP_CHANNELS
ioctls better- if 0 is passed, return the current setting.  if 1 or 2 are
passed, behave accordingly.  treat values >2 as 2.

PR:		kern/29964
2001-08-23 12:21:12 +00:00
Cameron Grant
92f39b2c05 MFS: make SNDCTL_DSP_SETTRIGGER work 2001-08-23 11:58:38 +00:00
Cameron Grant
1662598f0c MFS: allow multiple opens of mixer devices 2001-08-23 11:56:07 +00:00
Cameron Grant
67b1dce3bc many changes:
* add new channels to the end of the list so channels used in order of
addition

* de-globalise definition of struct snddev_info and provide accessor
functions where necessary.

* move the $FreeBSD$ tag in each .c file into a macro and allow the
/dev/sndstat handler to display these when set to maximum verbosity to aid
debugging.

* allow each device to register its own sndstat handler to reduce the amount
of groping sndstat must do in foreign structs.
2001-08-23 11:30:52 +00:00
Cameron Grant
cbe7d6a3ed remove obsolete typedefs.
only define INTR_TYPE_AV if it is not already defined.
2001-07-03 12:53:09 +00:00
Brian Feldman
bc0e6469ff Correct obviously wrong mistakes. 2001-07-02 23:47:23 +00:00
Matt Jacob
5640e0ac5a make it compile again in -current 2001-07-02 17:36:11 +00:00