Sound drivers probe and attach in almost the same way as any hardware driver module. You might want to look at the ISA or PCI specific sections of the handbook for more information.
However, sound drivers differ in some ways:
They declare themselves as pcm
class devices, with a
struct snddev_info
device private
structure:
static driver_t xxx_driver = { "pcm", xxx_methods, sizeof(struct snddev_info) }; DRIVER_MODULE(snd_xxxpci, pci, xxx_driver, pcm_devclass, 0, 0); MODULE_DEPEND(snd_xxxpci, snd_pcm, PCM_MINVER, PCM_PREFVER,PCM_MAXVER);
Most sound drivers
need to store additional private information about their
device. A private data structure is usually allocated in
the attach routine. Its address is passed to
pcm
by the calls to
pcm_register()
and
mixer_init()
.
pcm
later passes back this address
as a parameter in calls to the sound driver
interfaces.
The sound driver attach routine should declare its MIXER
or AC97 interface to pcm
by calling
mixer_init()
. For a MIXER interface,
this causes in turn a call to xxxmixer_init()
.
The sound driver attach routine declares its general
CHANNEL configuration to pcm
by
calling pcm_register(dev, sc, nplay,
nrec)
, where sc
is the address
for the device data structure, used in further calls from
pcm
, and nplay
and nrec
are the number of play and
record channels.
The sound driver attach routine declares each of its
channel objects by calls to
pcm_addchan()
. This sets up the
channel glue in pcm
and causes in
turn a call to
xxxchannel_init()
.
The sound driver detach routine should call
pcm_unregister()
before releasing its
resources.
There are two possible methods to handle non-PnP devices:
Use a device_identify()
method
(example: sound/isa/es1888.c
). The
device_identify()
method probes for the
hardware at known addresses and, if it finds a supported
device, creates a new pcm device which is then passed to
probe/attach.
Use a custom kernel configuration with appropriate hints
for pcm devices (example:
sound/isa/mss.c
).
pcm
drivers should implement
device_suspend
,
device_resume
and
device_shutdown
routines, so that power
management and module unloading function correctly.
All FreeBSD documents are available for download at http://ftp.FreeBSD.org/pub/FreeBSD/doc/
Questions that are not answered by the
documentation may be
sent to <[email protected]>.
Send questions about this document to <[email protected]>.