Commit Graph

51 Commits

Author SHA1 Message Date
Ariff Abdullah
082f63835c Flush remaining malloc() cleanups (M_NOWAIT -> M_WAITOK). 2007-06-17 06:10:43 +00:00
Ariff Abdullah
e4e61333ff Last (again ?!?) major commit for RELENG_7, featuring total Giant
eradication in/from userland path, countless locking fixes, etc.

- General sleep call through msleep(9) has been converted to condvar(9)
  with better consistencies.
- Heavily guard every possible "slow path" entries (open(), close(),
  few ioctl()s, sysctls), but once it entering "fast path" (io, interrupt
  started), they are free to fly on their own.
- Rearrange locking sequences, resulting better concurrency and
  serialization. Large part doesn't even need locking at all, and will be
  removed in future. Less clutter, except in few places due to lock
  ordering.
- Anonymous mixer object creation/deletion to simplify mixer handling
  beyond typical mixer ioctls.
  Submitted by:		chibis (with modifications)
- Add few mix_[get|set|..] functions to avoid calling mixer_ioctl()
  directly using cryptic arguments.
- Locking fixes to avoid possible deadlock with (still under Giant) USB.
- Better simplex/duplex device handling.
- Recover mmap() functionality for recording, which has been lost
  since 2.2.x - 3.x (the introduction of newpcm). Full-duplex mmap still
  doesn't work (due to VM/page design), but people still can mmap
  both by opening each direction separately. mmaped playback is guarantee
  to work either way.
- New sysctl: "hw.snd.compat_linux_mmap" to allow PROT_EXEC page
  mapping, due to recent changes in linux compatibility layer which
  require it. All linux applications that using sound + mmap() (mostly games)
  require this to be enabled. Disabled by default.
- Other goodies.. too many, that will increase releng7 shareholder value
  and make users of releng6 (and below) cry ;)

* This commit should be atomic. If anything goes wrong (not counting problem
  originated from elsewhere), I will not hesitate to revert everything back
  within 12 hours. This substantial changes itself not a rocket science
  and the process has begun for almost 2 years, and lots of incremental
  changes are already in place during that period of time.
* Some issues does occur in snd_emu10kx (note the 'x') due to various
  internal locking issues and it is currently being worked on by chibis.

Tested by:	chibis (Yuriy Tsibizov), joel, Alexandre Vieira,
          	many innocent souls...
2007-06-16 03:37:28 +00:00
Warner Losh
645016c0e4 Expand USB_ATTACH_{ERROR,SUCCESS}_RETURN inline and eliminate from
usb_port.h.  They aren't needed, and are a legacy of this code's past.
2007-06-12 15:37:19 +00:00
Ariff Abdullah
bdfbdcec6a Filter/compress the amount of channel trigger. This should reduce
much of lock/unlock contentions within the interrupt handler. Most
of these drivers only need PCMTRIG_START or STOP (ABORT).

Discussed with:		scottl
2007-06-11 00:49:46 +00:00
Matt Jacob
471f8f34b5 Remove const type qualifier from a function- gcc4.2 doesn't accept it.
Reviewed by:	Ariff
2007-06-10 15:45:29 +00:00
Ruslan Ermilov
1f082787d4 Make this compile. 2007-06-09 11:07:07 +00:00
Warner Losh
8d58ce651f Expand USB_ATTACH_SETUP inline + devinfo tweaks
# looks like there's a chance that uaudio might compile on otherBSD, so leave
# those #defines alone as well as make this change in a compatible way.
2007-06-09 06:49:05 +00:00
Ariff Abdullah
e510f52136 Use standard pcm_get/setflags() rather than dereferencing softc while
enabling SD_F_SOFTPCMVOL or any flags.
2007-06-02 17:28:26 +00:00
Ariff Abdullah
bba4862c64 Last major commit and updates for RELENG_7:
- Rework the entire pcm_channel structure:
  * Remove rarely used link placeholder, instead, make each pcm_channel
    as head/link of each own/each other. Unlock - Lock sequence due to
    sleep malloc has been reduced.
  * Implement "busy" queue which will contain list of busy/active
    channels. This greatly reduce locking contention for example while
    servicing interrupt for hardware with many channels or when virtual
    channels reach its 256 peak channels.

- So I heard you like v chan ... O RLY?
  Welcome to Virtual **Record** Channels (vrec, rec vchans, vchans for
  recording, Rec-Chan, you decide), the ultimate solutions for your
  nagging O_RDWR full-duplex wannabe (note: flash plugins) monopolizing
  single record channel causing EBUSY.  Vrec works exactly like Vchans
  (or, should I rename it to "Vplay" :) , except that it operates on the
  opposite direction (recording). Up to 256 vrecs (like vchans) are
  possible.

  Notes:
   * Relocate dev.pcm.%d.{vchans,vchanformat,vchanrate} to each of its
     respective node/direction:
       dev.pcm.%d.play.* for "play"   (cdev = dsp%d.vp%d)
       dev.pcm.%d.rec.*  for "record" (cdev = dsp%d.vr%d)
   * Don't expect that it will magically give you ability to split
     "recording source" (eg: 1 channel for cdrom, 1 channel for mic,
     etc). Just admit that you only have a *single* recording source /
     channel. Please bug your hardware vendor instead :)

- Bump maxautovchans from 4 to 16. For a full-fledged multimedia
  desktop/workstation with too many soundservers installed (esound,
  artsd, jackd, pulse/polypaudio, ding-dong pling plong mudkip fuh fuh,
  etc), 4 seems inadequate. There will be no memory penalty here, since
  virtual channels are allocate only by demand.

- Nuke/Rework the entire statically created cdev entries. Everything is
  clonable through snd own clone manager which designed to withstand many
  kind of abusive devfs droids such as:
      * while : ; do /bin/test -e /dev/dsp ; done
      * jot 16777216 0 | while read x ; do ls /dev/dsp0.$x ; done
      * hundreds (could be thousands) concurrent threads/process opening
	"/dev/dsp" (previously, this might result EBUSY even with just
	3 contesting threads/procs).
  o Reusable clone objects (instead of creating new one like there's no
    tomorrow) after certain expiration deadline. The clone allocator will
    decide whether to reuse, share, or creating new clone.
  o Automatic garbage collector.

- Dynamic unit magic allocator. Maximum attached soundcards can be tuned
  using tunable "hw.snd.maxunit" (Default to 512). Minimum is 16, and
  maximum is 2048.

- ..other fixes, mostly related to concurrency issues.

joel@ will do the manpage updates on sound(4).

Have fun.
2007-05-31 18:43:33 +00:00
Ariff Abdullah
a9be51acfe Provide hint / tunable for possible asynchronous USB execution. Async
execution should help us avoiding potential deadlock and illegal locking
while sleeping in various mixer -> usb calls. To enable it, use
hint.uaudio.%d.async="1" or sysctl dev.uaudio.%d.async=1. Default is
disable, to remain compatible with old behaviour (with slight risk of
potential deadlock).
2007-04-02 03:25:39 +00:00
Alexander Leidinger
c2bb6a54ef Tell interested readers of the source that the return value is not
checked by intend.

Found by:	Coverity Prevent (tm)
CID:		55
Reviewed by:	ariff
2007-03-31 13:38:12 +00:00
Ariff Abdullah
7ab4fa8ee2 [stage: 9/9]
- SWAPLR quirk for (unknown, luckily it is mine) broken uaudio stick.
  Fixing by rewiring is impossible without damaging it. Luckily,
  we can fix it using "other" methods :) .
- Add uaudio_get_vendor(), _product() and _release() in uaudio.c
  (currently used by uaudio_pcm quirk).
- Implement CHANNEL_SETFRAGMENTS().
- Drop channel locking in few places where it is about to sleep
  somewhere. This should help eliminating illegal locking acquisition
  where the current thread is about to sleep, and also few deadlock
  cases. Dropping it right here is quite safe since it is already
  protected by CHN_F_BUSY flag and other threads won't bother to touch it.
  Solving other illegal locking issues are quite tricky without converting
  most usbd_do_request() calls to its equivalent _async() calls,
  which I intend to do it later after getting full test report from
  other people with different uaudio hardwares.
- Fix memory leak issues during detach. This seems common to any drivers
  (notably emu10kx, csapcm?) with bridge functions.
2007-03-16 17:19:03 +00:00
Ariff Abdullah
b1d922169b Fix forever broken ua_chan_setblocksize() uninitialized return value
which causing divide by zero panic in other places (notably chn_sync()).
2007-01-26 19:14:41 +00:00
Ariff Abdullah
3ad47bdd54 Sync uaudio_sndstat_prepare_pcm() output with sndstat_prepare_pcm() to get
simmilar (debugging) output.
2007-01-26 19:06:17 +00:00
Alexander Leidinger
cea9c751eb Sync with NetBSD:
revision 1.98 is NOT merged, because FreeBSD does not support this
 		syntax.
 	revision 1.99 is NOT merged, "const poisoning" part is not applicable
 		to FreeBSD. There is no variable shadowing, GCC can't find
 		this one (but there are others)
 	revision 1.100 is NOT merged, because it was null patch (no changes)
 	revision 1.101 is NOT merged, there is no BIT() macro in FreeBSD
 	revision 1.102 is merged
 	revision 1.103 is partially merged. There is no ai.ifaceh in FreeBSD
 	revision 1.104 is NOT merged
 	revision 1.105 is merged
 	revision 1.106 is not merged, because of rev. 1.107
 	revision 1.107 is a backuout of 1.106

Submitted by:	Yuriy Tsibizov <Yuriy.Tsibizov@gfk.ru>
2007-01-06 19:08:39 +00:00
Ariff Abdullah
a580b31a54 Welcome to Once-a-year Sound Mega-Commit. Enjoy numerous updates and fixes
in every sense.

General
-------

- Multichannel safe, endian safe, format safe
   * Large part of critical pcm filters such as vchan.c, feeder_rate.c,
     feeder_volume.c, feeder_fmt.c and feeder.c has been rewritten so that
     using them does not cause the pcm data to be converted to 16bit little
     endian.
   * Macrosses for accessing pcm data safely are defined within sound.h in
     the form of PCM_READ_* / PCM_WRITE_*
   * Currently, most of them are probably limited for mono/stereo handling,
     but the future addition of true multichannel will be much easier.

- Low latency operation
  * Well, this require lot more works to do not just within sound driver,
    but we're heading towards right direction. Buffer/block sizing within
    channel.c is rewritten to calculate precise allocation for various
    combination of sample/data/rate size. As a result, applying correct
    SNDCTL_DSP_POLICY value will achive expected latency behaviour simmilar
    to what commercial 4front driver do.
  * Signal handling fix. ctrl+c of "cat /dev/zero > /dev/dsp" does not
    result long delay.
  * Eliminate sound truncation if the sound data is too small.
    DIY:
      1) Download / extract
         http://people.freebsd.org/~ariff/lowlatency/shortfiles.tar.gz
      2) Do a comparison between "cat state*.au > /dev/dsp" and
         "for x in state*.au ; do cat $x > /dev/dsp ; done"
         - there should be no "perceivable" differences.
    Double close for PR kern/31445.

  CAVEAT: Low latency come with (unbearable) price especially for poorly
          written applications. Applications that trying to act smarter
	  by requesting (wrong) blocksize/blockcount will suffer the most.
	  Fixup samples/patches can be found at:
	  http://people.freebsd.org/~ariff/ports/

- Switch minimum/maximum sampling rate limit to "1" and "2016000" (48k * 42)
  due to closer compatibility with 4front driver.
  Discussed with: marcus@ (long time ago?)

- All driver specific sysctls in the form of "hw.snd.pcm%d.*" have been
  moved to their own dev sysctl nodes, notably:
  hw.snd.pcm%d.vchans -> dev.pcm.%d.vchans
  Bump __FreeBSD_version.

Driver specific
---------------

- Ditto for sysctls.

- snd_atiixp, snd_es137x, snd_via8233, snd_hda
  * Numerous cleanups and fixes.
  * _EXPERIMENTAL_ polling mode support using simple callout_* mechanisme.
   This was intended for pure debugging and latency measurement, but proven
   good enough in few unexpected and rare cases (such as problematic shared
   IRQ with GIANT devices - USB). Polling can be enabled/disabled through
   dev.pcm.0.polling. Disabled by default.

- snd_ich
  * Fix possible overflow during speed calibration. Delay final
    initialization (pcm_setstatus) after calibration finished.
    PR: kern/100169
    Tested by: Kevin Overman <oberman@es.net>
  * Inverted EAPD for few Nec VersaPro.
    PR: kern/104715
    Submitted by: KAWATA Masahiko <kawata@mta.biglobe.ne.jp>

Thanks to various people, notably Joel Dahl, Yuriy Tsibizov, Kevin Oberman,
those at #freebsd-azalia @ freenode and others for testing.

Joel Dahl will do the manpage update.
2006-11-26 12:24:06 +00:00
Ariff Abdullah
7699548f1b Various fixups, especially for the upcomming High Definition Audio
commit.

1) sys/dev/sound/pcm/sound.h
   sys/dev/sound/pcm/channel.c
   * Be more specific: SD_F_SOFTVOL -> SD_F_SOFTPCMVOL
2) sys/dev/sound/pcm/mixer.[ch]
   * Implement
       mix_setparentchild()
       mix_setrealdev()
       mix_getparent()
       mix_getchild()
     The purpose of these functions is implement relative volume
     adjustment, such as to tie two or more mixer device into a
     single logical device. Usefull for the upcoming HDA driver
     and few AC97 codec (such as AD1981B) where the master volume
     "vol" need to be implemented using this logical manner.
3) sys/dev/sound/pcm/ac97_patch.[ch]
   * Patch for AD1981B codec to enable (automuting) headphone jack sense.
4) sys/dev/sound/pcm/ac97.c
   * Implement proper logical master volume for AD9181B codec
     through various mix_set{parentchild,realdev}(). Tie both
     "ogain" (headphone volume) and "phone" (speaker/lineout) to
     a logical "vol".
5) sys/dev/sound/pcm/usb/uaudio_pcm.c
   * ditto, for "vol" -> { "pcm" }.

MFC after:	1 month
2006-09-28 17:29:00 +00:00
Alexander Leidinger
f3ed5ebbcf Fix the check where we want to use the end of the supported range if the
value is out of the supported range.

Noticed by:	Ed Schouten <ed@fxq.nl>
Reviewed by:	Kazuhito HONDA <kazuhito@ph.noda.tus.ac.jp>
2006-09-09 14:43:03 +00:00
Scott Long
448ddd747f Catch up to USB changes. 2006-09-07 05:21:52 +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
293b843c5e Fix some kind of "off by one"-error: the min or max sample rate the
device is able to reproduce should be usable too instead of failing
in such a case.

PR:		89269
Submitted by:	Don L. Belcher <don@siad.net>
2005-12-29 18:11:11 +00:00
Ariff Abdullah
1e558b7ecb Precision for AFMT_x24_yE and AFMT_x32_yE should be 24 and 32, respectively.
Submitted by:	Kazuhito HONDA <kazuhito@ph.noda.tus.ac.jp>
2005-12-18 16:50:06 +00:00
Alexander Leidinger
f9dff1f9fa Add support for 24/32 bit audio formats/conversion.
It may be the case that you may hear some unwanted noise while
playing back with 24/32 bit. This is a problem in the USB system.
Explanation from Hans Petter Selasky:
---snip---
The current USB sound driver only uses one isochronous
buffer, that is restarted when it is completed. This will lead to a short
period of time, +1ms, where no sound data is sent to the external USB device.
Depending on the load of your computer, this can be as much as 50ms. So the
USB sound driver must use 2 isochronous transfers. At the beginning one will
queue both. Then these are restarted on completion. This will result in a
constant-rate data stream to the external sound device, a minimum sound
buffer equal to the size of the isochronous buffer, and possibly the sound
will reach your ears with less delay. Little delay is a result of constant
data rate. Currently only my USB driver will support that. If one tries that
with the USB driver in *BSD, then it will crash at the first moment one gets
a buffer underrun.
---snip---

Submitted by:	Kazuhito HONDA <kazuhito@ph.noda.tus.ac.jp>
Mono-recording still not tested by:	julian
2005-11-13 14:20:26 +00:00
Alexander Leidinger
f84e94870d Emulate pcm mixer controller for any uaudio device without it.
Submitted by:	Ariff Abdullah <skywizard@MyBSD.org.my>
2005-10-02 15:51:19 +00:00
Alexander Leidinger
edffb4c891 Add the KLD to the sndstat info. 2005-09-18 15:38:40 +00:00
Alexander Leidinger
c61957b5fb Merge NetBSD fixes (except for 1.97 there should be no functional change):
1.94: ansify and KNF (NetBSD KNF).
	1.95: Fix DPRINTF (bug from change in 1.94).
	1.96: NetBSD specific.
	1.97: Fix memory leak reported by Ted Unangst as bug #3 on tech-kern.

Obtained from:	NetBSD
2005-09-18 15:13:06 +00:00
Alexander Leidinger
caad740808 Fix a bug in volume calculation, this sometimes gives a USB audio device an
unexpected value (when the volume is high).

Submitted by:	Kazuhito HONDA <kazuhito@ph.noda.tus.ac.jp>
2005-09-11 09:15:42 +00:00
Julian Elischer
7f05203a38 Add code from Kazuhito HONDA that allows the user to see
the available modes in /dev/sndstat.
e.g.
pcm1: <USB Audio> at addr ? (0p/1r/0v channels duplex)
        mode 1:(input) 1ch, 16/16bit, pcm, 44100Hz
	mode 2:(input) 1ch, 16/16bit, pcm, 22050Hz
	mode 3:(input) 1ch, 16/16bit, pcm, 11025Hz
	mode 4:(input) 1ch, 16/16bit, pcm, 8000Hz
2005-04-27 17:16:27 +00:00
Mathew Kanner
fe862a9b36 Fix a bug where we call pcm_getbuffersize twice.
Pointed out by:	Kazuhito HONDA <kazuhito at ph dot noda dot tus dot ac dot jp>
2005-04-17 16:26:08 +00:00
Mathew Kanner
ece089c054 De-dma the uaudio <-> pcm bridge. We were not capable of doing DMA from
this buffer anyway so the constraint that it had to be DMA capable only
caused pain when devices failed to aquire the memory.  Use a regular
malloc instead with sndbuf_setup.

Approved by:    tanimura (mentor)
2005-04-17 15:26:51 +00:00
Julian Elischer
0224b85a14 On record only devices, don't fail if we don't have a play channel.
MFC after: 3 days
2005-04-17 07:42:28 +00:00
Julian Elischer
b7fd00d97c The maximum allowable alloc is 16K not (16K-1).
This whole section is actually overly restrictive and
another patch is in the works.
2005-04-13 16:39:22 +00:00
Warner Losh
d2b677bb1a Use BUS_PROBE_DEFAULT in preference to 0 and BUS_PROBE_LOW_PRIORITY in
preference to some random negative number to allow other drivers a
bite at the apple.
2005-03-01 08:58:06 +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
Julian Elischer
587161d920 Allow selection of a recording source on USB audio devices.
PR:		75316
Submitted by:	Kazuhito HONDA <kazuhito at ph dot noda dot tus dot ac dot jp>
Obtained from:	NetBSD plus changes
MFC after:	2 weeks
2004-12-25 08:55:52 +00:00
Julian Elischer
65046f8612 Allow recording on at least some USB audio devices.
PR:		75311
Submitted by:	Kazuhito HONDA <kazuhito at ph dot noda dot tus dot ac dot jp>
Obtained from:	NetBSD plus changes
MFC after:	2 weeks
2004-12-25 08:51:47 +00:00
Julian Elischer
2baaf9c206 Allow volume control on more channels/inputs
PR:		75276
Submitted by:	Kazuhito HONDA <kazuhito at ph dot noda dot tus dot ac dot jp>
Obtained from:	NetBSD  with changes
MFC after:	2 weeks
2004-12-25 08:46:03 +00:00
Julian Elischer
d28a81455e MFNetBSD:
One of a set of patches submitted by  Kazuhito HONDA
	to make the usb audio driver a lot more capable.

PR:	75274
Submitted by:	Kazuhito HONDA (kazuhito at ph dot noda dot tus dot ac dot jp)
Obtained from:	NetBSD (indirectly)
MFC after:	2 weeks
2004-12-25 06:20:49 +00:00
Poul-Henning Kamp
ba7cd7b68a Don't include vnode.h 2004-12-22 17:31:10 +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
Takanori Watanabe
92fae6e79e Devclass have to be shared with same 'pcm' devclass, or
unit management will corrupt.
2004-05-31 11:38:46 +00:00
Scott Long
f6b1c44d1f Mega busdma API commit.
Add two new arguments to bus_dma_tag_create(): lockfunc and lockfuncarg.
Lockfunc allows a driver to provide a function for managing its locking
semantics while using busdma.  At the moment, this is used for the
asynchronous busdma_swi and callback mechanism.  Two lockfunc implementations
are provided: busdma_lock_mutex() performs standard mutex operations on the
mutex that is specified from lockfuncarg.  dftl_lock() is a panic
implementation and is defaulted to when NULL, NULL are passed to
bus_dma_tag_create().  The only time that NULL, NULL should ever be used is
when the driver ensures that bus_dmamap_load() will not be deferred.
Drivers that do not provide their own locking can pass
busdma_lock_mutex,&Giant args in order to preserve the former behaviour.

sparc64 and powerpc do not provide real busdma_swi functions, so this is
largely a noop on those platforms.  The busdma_swi on is64 is not properly
locked yet, so warnings will be emitted on this platform when busdma
callback deferrals happen.

If anyone gets panics or warnings from dflt_lock() being called, please
let me know right away.

Reviewed by:	tmm, gibbs
2003-07-01 15:52:06 +00:00
Cameron Grant
0586ff0d84 if the list of supported formats is empty, fail the attach instead of
panicing later.  this is a band-aid pending further investigation.

MFC After:	7 days
Approved by:	re
2002-11-25 17:03:39 +00:00
Josef Karthauser
8ecdcb3ff3 Packed structures are defined differently in older gcc's, like the one
currently in -stable.  Put the exception into usb.h instead of having it
hard coded in the sound code.
2002-11-06 21:37:21 +00:00
Bruce Evans
760e2cb04a Fixed editing errors in rev.1.4 which manifested as printf format errors
at compile time and probably as panics at runtime.
2002-08-25 01:32:22 +00:00
Josef Karthauser
3b7efc56d0 Use the hw.usb sysctl tree instead of debug.usb.
Requested by:	imp
2002-08-08 12:05:51 +00:00
Josef Karthauser
528d1a7fbc Replace the FOO_DEBUG definitions with USB_DEBUG, and switch the
debugging levels to off by default.  Now that debug levels can be
tweaked by sysctl we don't need to go through hoops to get the
different usb parts to produce debug data.
2002-07-31 14:34:36 +00:00
Josef Karthauser
6ada40b009 Make this compile with the debugging options switched on. 2002-07-31 14:27:40 +00:00
Josef Karthauser
0e6b196686 Get bored with hard coded debug level variables and introduce a debug.usb
sysctl tree for tweaking them real-time.

Reviewed by:	iedowse
2002-07-31 13:33:55 +00:00
Peter Wemm
7c65416558 Make this compile.
uaudio.c:1822: warning: `uaudio_ctl_get' defined but not used
2002-07-22 00:11:35 +00:00