FreeBSD kernel sound device code
hdac.c File Reference
#include <dev/sound/pcm/sound.h>
#include <dev/pci/pcireg.h>
#include <dev/pci/pcivar.h>
#include <sys/ctype.h>
#include <sys/endian.h>
#include <sys/taskqueue.h>
#include <dev/sound/pci/hda/hdac_private.h>
#include <dev/sound/pci/hda/hdac_reg.h>
#include <dev/sound/pci/hda/hda_reg.h>
#include <dev/sound/pci/hda/hdac.h>
Include dependency graph for hdac.c:

Go to the source code of this file.

Macros

#define HDA_DRV_TEST_REV   "20120126_0002"
 
#define hdac_lock(sc)   snd_mtxlock((sc)->lock)
 
#define hdac_unlock(sc)   snd_mtxunlock((sc)->lock)
 
#define hdac_lockassert(sc)   snd_mtxassert((sc)->lock)
 
#define HDAC_QUIRK_64BIT   (1 << 0)
 
#define HDAC_QUIRK_DMAPOS   (1 << 1)
 
#define HDAC_QUIRK_MSI   (1 << 2)
 

Functions

 SND_DECLARE_FILE ("$FreeBSD$")
 
 MALLOC_DEFINE (M_HDAC, "hdac", "HDA Controller")
 
static void hdac_intr_handler (void *)
 
static int hdac_reset (struct hdac_softc *, bool)
 
static int hdac_get_capabilities (struct hdac_softc *)
 
static void hdac_dma_cb (void *, bus_dma_segment_t *, int, int)
 
static int hdac_dma_alloc (struct hdac_softc *, struct hdac_dma *, bus_size_t)
 
static void hdac_dma_free (struct hdac_softc *, struct hdac_dma *)
 
static int hdac_mem_alloc (struct hdac_softc *)
 
static void hdac_mem_free (struct hdac_softc *)
 
static int hdac_irq_alloc (struct hdac_softc *)
 
static void hdac_irq_free (struct hdac_softc *)
 
static void hdac_corb_init (struct hdac_softc *)
 
static void hdac_rirb_init (struct hdac_softc *)
 
static void hdac_corb_start (struct hdac_softc *)
 
static void hdac_rirb_start (struct hdac_softc *)
 
static void hdac_attach2 (void *)
 
static uint32_t hdac_send_command (struct hdac_softc *, nid_t, uint32_t)
 
static int hdac_probe (device_t)
 
static int hdac_attach (device_t)
 
static int hdac_detach (device_t)
 
static int hdac_suspend (device_t)
 
static int hdac_resume (device_t)
 
static int hdac_rirb_flush (struct hdac_softc *sc)
 
static int hdac_unsolq_flush (struct hdac_softc *sc)
 
static void hdac_config_fetch (struct hdac_softc *sc, uint32_t *on, uint32_t *off)
 
static void hdac_one_intr (struct hdac_softc *sc, uint32_t intsts)
 
static void hdac_poll_callback (void *arg)
 
static void hdac_unsolq_task (void *context, int pending)
 
static int sysctl_hdac_pindump (SYSCTL_HANDLER_ARGS)
 
static int hdac_mdata_rate (uint16_t fmt)
 
static int hdac_bdata_rate (uint16_t fmt, int output)
 
static void hdac_poll_reinit (struct hdac_softc *sc)
 
static int sysctl_hdac_polling (SYSCTL_HANDLER_ARGS)
 
static bus_dma_tag_t hdac_get_dma_tag (device_t dev, device_t child)
 
static int hdac_print_child (device_t dev, device_t child)
 
static int hdac_child_location (device_t dev, device_t child, struct sbuf *sb)
 
static int hdac_child_pnpinfo_method (device_t dev, device_t child, struct sbuf *sb)
 
static int hdac_read_ivar (device_t dev, device_t child, int which, uintptr_t *result)
 
static struct mtx * hdac_get_mtx (device_t dev, device_t child)
 
static uint32_t hdac_codec_command (device_t dev, device_t child, uint32_t verb)
 
static int hdac_find_stream (struct hdac_softc *sc, int dir, int stream)
 
static int hdac_stream_alloc (device_t dev, device_t child, int dir, int format, int stripe, uint32_t **dmapos)
 
static void hdac_stream_free (device_t dev, device_t child, int dir, int stream)
 
static int hdac_stream_start (device_t dev, device_t child, int dir, int stream, bus_addr_t buf, int blksz, int blkcnt)
 
static void hdac_stream_stop (device_t dev, device_t child, int dir, int stream)
 
static void hdac_stream_reset (device_t dev, device_t child, int dir, int stream)
 
static uint32_t hdac_stream_getptr (device_t dev, device_t child, int dir, int stream)
 
static int hdac_unsol_alloc (device_t dev, device_t child, int tag)
 
static void hdac_unsol_free (device_t dev, device_t child, int tag)
 
 DRIVER_MODULE (snd_hda, pci, hdac_driver, hdac_devclass, NULL, NULL)
 

Variables

struct {
   const char *   key
 
   uint32_t   value
 
hdac_quirks_tab []
 
struct {
   uint32_t   model
 
   const char *   desc
 
   char   quirks_on
 
   char   quirks_off
 
hdac_devices []
 
struct {
   uint16_t   vendor
 
   uint8_t   reg
 
   uint8_t   mask
 
   uint8_t   enable
 
hdac_pcie_snoop []
 
static device_method_t hdac_methods []
 
static driver_t hdac_driver
 
static devclass_t hdac_devclass
 

Macro Definition Documentation

◆ HDA_DRV_TEST_REV

#define HDA_DRV_TEST_REV   "20120126_0002"

Definition at line 52 of file hdac.c.

◆ hdac_lock

#define hdac_lock (   sc)    snd_mtxlock((sc)->lock)

Definition at line 56 of file hdac.c.

◆ hdac_lockassert

#define hdac_lockassert (   sc)    snd_mtxassert((sc)->lock)

Definition at line 58 of file hdac.c.

◆ HDAC_QUIRK_64BIT

#define HDAC_QUIRK_64BIT   (1 << 0)

Definition at line 60 of file hdac.c.

◆ HDAC_QUIRK_DMAPOS

#define HDAC_QUIRK_DMAPOS   (1 << 1)

Definition at line 61 of file hdac.c.

◆ HDAC_QUIRK_MSI

#define HDAC_QUIRK_MSI   (1 << 2)

Definition at line 62 of file hdac.c.

◆ hdac_unlock

#define hdac_unlock (   sc)    snd_mtxunlock((sc)->lock)

Definition at line 57 of file hdac.c.

Function Documentation

◆ DRIVER_MODULE()

DRIVER_MODULE ( snd_hda  ,
pci  ,
hdac_driver  ,
hdac_devclass  ,
NULL  ,
NULL   
)

◆ hdac_attach()

◆ hdac_attach2()

◆ hdac_bdata_rate()

static int hdac_bdata_rate ( uint16_t  fmt,
int  output 
)
static

Definition at line 1429 of file hdac.c.

References fmt, and rate.

Referenced by hdac_stream_alloc().

Here is the caller graph for this function:

◆ hdac_child_location()

static int hdac_child_location ( device_t  dev,
device_t  child,
struct sbuf *  sb 
)
static

Definition at line 1789 of file hdac.c.

References child.

◆ hdac_child_pnpinfo_method()

static int hdac_child_pnpinfo_method ( device_t  dev,
device_t  child,
struct sbuf *  sb 
)
static

◆ hdac_codec_command()

static uint32_t hdac_codec_command ( device_t  dev,
device_t  child,
uint32_t  verb 
)
static

Definition at line 1858 of file hdac.c.

References child, dev, hdac_send_command(), and verb.

Here is the call graph for this function:

◆ hdac_config_fetch()

static void hdac_config_fetch ( struct hdac_softc sc,
uint32_t *  on,
uint32_t *  off 
)
static

Definition at line 255 of file hdac.c.

References hdac_softc::dev, HDA_BOOTVERBOSE, hdac_quirks_tab, k, key, and len.

Referenced by hdac_attach().

Here is the caller graph for this function:

◆ hdac_corb_init()

◆ hdac_corb_start()

static void hdac_corb_start ( struct hdac_softc sc)
static

Definition at line 916 of file hdac.c.

References HDAC_CORBCTL, HDAC_CORBCTL_CORBRUN, HDAC_READ_1, HDAC_WRITE_1, and hdac_softc::mem.

Referenced by hdac_attach2(), and hdac_resume().

Here is the caller graph for this function:

◆ hdac_detach()

◆ hdac_dma_alloc()

static int hdac_dma_alloc ( struct hdac_softc sc,
struct hdac_dma dma,
bus_size_t  size 
)
static

Definition at line 590 of file hdac.c.

References hdac_softc::dev, hdac_dma::dma_map, hdac_dma::dma_paddr, hdac_dma::dma_size, hdac_dma::dma_tag, hdac_dma::dma_vaddr, hdac_softc::flags, HDA_BOOTHVERBOSE, HDA_DMA_ALIGNMENT, hdac_dma_cb(), hdac_dma_free(), HDAC_F_DMA_NOCACHE, size, and hdac_softc::support_64bit.

Referenced by hdac_attach().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ hdac_dma_cb()

static void hdac_dma_cb ( void *  callback_arg,
bus_dma_segment_t *  segs,
int  nseg,
int  error 
)
static

Definition at line 573 of file hdac.c.

References hdac_dma::dma_paddr, and error.

Referenced by hdac_dma_alloc().

Here is the caller graph for this function:

◆ hdac_dma_free()

static void hdac_dma_free ( struct hdac_softc sc,
struct hdac_dma dma 
)
static

Definition at line 672 of file hdac.c.

References hdac_dma::dma_map, hdac_dma::dma_paddr, hdac_dma::dma_size, hdac_dma::dma_tag, and hdac_dma::dma_vaddr.

Referenced by hdac_attach(), hdac_detach(), and hdac_dma_alloc().

Here is the caller graph for this function:

◆ hdac_find_stream()

static int hdac_find_stream ( struct hdac_softc sc,
int  dir,
int  stream 
)
static

◆ hdac_get_capabilities()

◆ hdac_get_dma_tag()

static bus_dma_tag_t hdac_get_dma_tag ( device_t  dev,
device_t  child 
)
static

Definition at line 1769 of file hdac.c.

References hdac_softc::chan_dmat, and dev.

◆ hdac_get_mtx()

static struct mtx * hdac_get_mtx ( device_t  dev,
device_t  child 
)
static

Definition at line 1850 of file hdac.c.

References dev, and hdac_softc::lock.

◆ hdac_intr_handler()

static void hdac_intr_handler ( void *  context)
static

Definition at line 370 of file hdac.c.

References HDAC_INTSTS, HDAC_INTSTS_GIS, hdac_lock, hdac_one_intr(), HDAC_READ_4, hdac_unlock, and hdac_softc::mem.

Referenced by hdac_irq_alloc(), and hdac_poll_callback().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ hdac_irq_alloc()

static int hdac_irq_alloc ( struct hdac_softc sc)
static

Definition at line 741 of file hdac.c.

References hdac_softc::dev, hdac_intr_handler(), hdac_irq_free(), HDAC_QUIRK_MSI, hdac_softc::irq, irq, and hdac_softc::quirks_off.

Referenced by hdac_attach().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ hdac_irq_free()

static void hdac_irq_free ( struct hdac_softc sc)
static

Definition at line 784 of file hdac.c.

References hdac_softc::dev, hdac_softc::irq, and irq.

Referenced by hdac_attach(), hdac_detach(), and hdac_irq_alloc().

Here is the caller graph for this function:

◆ hdac_mdata_rate()

static int hdac_mdata_rate ( uint16_t  fmt)
static

Definition at line 1412 of file hdac.c.

References fmt, and rate.

Referenced by hdac_poll_reinit().

Here is the caller graph for this function:

◆ hdac_mem_alloc()

static int hdac_mem_alloc ( struct hdac_softc sc)
static

Definition at line 699 of file hdac.c.

References hdac_softc::dev, hdac_softc::mem, hdac_mem::mem_handle, hdac_mem::mem_res, hdac_mem::mem_rid, hdac_mem::mem_tag, and PCIR_BAR.

Referenced by hdac_attach().

Here is the caller graph for this function:

◆ hdac_mem_free()

static void hdac_mem_free ( struct hdac_softc sc)
static

Definition at line 724 of file hdac.c.

References hdac_softc::dev, hdac_softc::mem, hdac_mem::mem_res, and hdac_mem::mem_rid.

Referenced by hdac_attach(), and hdac_detach().

Here is the caller graph for this function:

◆ hdac_one_intr()

static void hdac_one_intr ( struct hdac_softc sc,
uint32_t  intsts 
)
static

◆ hdac_poll_callback()

static void hdac_poll_callback ( void *  arg)
static

Definition at line 397 of file hdac.c.

References hdac_intr_handler(), hdac_lock, hdac_poll_callback(), hdac_unlock, hdac_softc::poll_callout, hdac_softc::poll_ival, and hdac_softc::polling.

Referenced by hdac_poll_callback(), and hdac_poll_reinit().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ hdac_poll_reinit()

static void hdac_poll_reinit ( struct hdac_softc sc)
static

◆ hdac_print_child()

static int hdac_print_child ( device_t  dev,
device_t  child 
)
static

Definition at line 1777 of file hdac.c.

References child, and dev.

◆ hdac_probe()

static int hdac_probe ( device_t  dev)
static

Definition at line 1063 of file hdac.c.

References desc, dev, HDA_DEV_MATCH, hdac_devices, model, PCIC_MULTIMEDIA, PCIS_MULTIMEDIA_HDA, and subclass.

◆ hdac_read_ivar()

◆ hdac_reset()

static int hdac_reset ( struct hdac_softc sc,
bool  wakeup 
)
static

◆ hdac_resume()

static int hdac_resume ( device_t  dev)
static

◆ hdac_rirb_flush()

◆ hdac_rirb_init()

◆ hdac_rirb_start()

static void hdac_rirb_start ( struct hdac_softc sc)
static

Definition at line 931 of file hdac.c.

References HDAC_READ_1, HDAC_RIRBCTL, HDAC_RIRBCTL_RIRBDMAEN, HDAC_WRITE_1, and hdac_softc::mem.

Referenced by hdac_attach2(), and hdac_resume().

Here is the caller graph for this function:

◆ hdac_send_command()

static uint32_t hdac_send_command ( struct hdac_softc sc,
nid_t  cad,
uint32_t  verb 
)
static

◆ hdac_stream_alloc()

static int hdac_stream_alloc ( device_t  dev,
device_t  child,
int  dir,
int  format,
int  stripe,
uint32_t **  dmapos 
)
static

◆ hdac_stream_free()

static void hdac_stream_free ( device_t  dev,
device_t  child,
int  dir,
int  stream 
)
static

◆ hdac_stream_getptr()

static uint32_t hdac_stream_getptr ( device_t  dev,
device_t  child,
int  dir,
int  stream 
)
static

Definition at line 2109 of file hdac.c.

References dev, dir, hdac_find_stream(), HDAC_READ_4, HDAC_SDLPIB, hdac_softc::mem, and stream.

Here is the call graph for this function:

◆ hdac_stream_reset()

static void hdac_stream_reset ( device_t  dev,
device_t  child,
int  dir,
int  stream 
)
static

Definition at line 2071 of file hdac.c.

References dev, dir, hdac_find_stream(), HDAC_READ_1, HDAC_SDCTL0, HDAC_SDCTL_SRST, HDAC_WRITE_1, hdac_softc::mem, and stream.

Here is the call graph for this function:

◆ hdac_stream_start()

◆ hdac_stream_stop()

static void hdac_stream_stop ( device_t  dev,
device_t  child,
int  dir,
int  stream 
)
static

◆ hdac_suspend()

static int hdac_suspend ( device_t  dev)
static

Definition at line 1635 of file hdac.c.

References dev, HDA_BOOTHVERBOSE, hdac_lock, hdac_reset(), hdac_unlock, hdac_softc::poll_callout, and hdac_softc::unsolq_task.

Referenced by sysctl_hdac_pindump().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ hdac_unsol_alloc()

static int hdac_unsol_alloc ( device_t  dev,
device_t  child,
int  tag 
)
static

Definition at line 2123 of file hdac.c.

References dev, hdac_poll_reinit(), tag, and hdac_softc::unsol_registered.

Here is the call graph for this function:

◆ hdac_unsol_free()

static void hdac_unsol_free ( device_t  dev,
device_t  child,
int  tag 
)
static

Definition at line 2133 of file hdac.c.

References dev, hdac_poll_reinit(), and hdac_softc::unsol_registered.

Here is the call graph for this function:

◆ hdac_unsolq_flush()

static int hdac_unsolq_flush ( struct hdac_softc sc)
static

◆ hdac_unsolq_task()

static void hdac_unsolq_task ( void *  context,
int  pending 
)
static

Definition at line 1106 of file hdac.c.

References hdac_lock, hdac_unlock, and hdac_unsolq_flush().

Referenced by hdac_attach().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ MALLOC_DEFINE()

MALLOC_DEFINE ( M_HDAC  ,
"hdac"  ,
"HDA Controller"   
)

◆ SND_DECLARE_FILE()

SND_DECLARE_FILE ( "$FreeBSD$"  )

◆ sysctl_hdac_pindump()

static int sysctl_hdac_pindump ( SYSCTL_HANDLER_ARGS  )
static

Definition at line 1368 of file hdac.c.

References dev, free, hdac_lock, hdac_resume(), hdac_suspend(), hdac_unlock, req, and val.

Referenced by hdac_attach2().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sysctl_hdac_polling()

static int sysctl_hdac_polling ( SYSCTL_HANDLER_ARGS  )
static

Definition at line 1475 of file hdac.c.

References dev, HDAC_INTCTL, HDAC_INTCTL_GIE, hdac_lock, hdac_poll_reinit(), HDAC_READ_4, hdac_unlock, HDAC_WRITE_4, hdac_softc::mem, hdac_softc::poll_callout, hdac_softc::polling, req, and val.

Referenced by hdac_attach2().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ desc

const char* desc

Definition at line 77 of file hdac.c.

Referenced by hdac_probe().

◆ enable

◆ hdac_devclass

devclass_t hdac_devclass
static

Definition at line 2173 of file hdac.c.

◆ 

const struct { ... } hdac_devices[]

Referenced by hdac_attach(), and hdac_probe().

◆ hdac_driver

driver_t hdac_driver
static
Initial value:
= {
"hdac",
sizeof(struct hdac_softc),
}
static device_method_t hdac_methods[]
Definition: hdac.c:2141

Definition at line 2167 of file hdac.c.

◆ hdac_methods

device_method_t hdac_methods[]
static
Initial value:
= {
DEVMETHOD(device_probe, hdac_probe),
DEVMETHOD(device_attach, hdac_attach),
DEVMETHOD(device_detach, hdac_detach),
DEVMETHOD(device_suspend, hdac_suspend),
DEVMETHOD(device_resume, hdac_resume),
DEVMETHOD(bus_get_dma_tag, hdac_get_dma_tag),
DEVMETHOD(bus_print_child, hdac_print_child),
DEVMETHOD(bus_child_location, hdac_child_location),
DEVMETHOD(bus_child_pnpinfo, hdac_child_pnpinfo_method),
DEVMETHOD(bus_read_ivar, hdac_read_ivar),
DEVMETHOD_END
}
static int hdac_probe(device_t)
Definition: hdac.c:1063
static int hdac_attach(device_t)
Definition: hdac.c:1125
static int hdac_child_location(device_t dev, device_t child, struct sbuf *sb)
Definition: hdac.c:1789
static int hdac_read_ivar(device_t dev, device_t child, int which, uintptr_t *result)
Definition: hdac.c:1810
static int hdac_stream_start(device_t dev, device_t child, int dir, int stream, bus_addr_t buf, int blksz, int blkcnt)
Definition: hdac.c:1979
static int hdac_unsol_alloc(device_t dev, device_t child, int tag)
Definition: hdac.c:2123
static int hdac_child_pnpinfo_method(device_t dev, device_t child, struct sbuf *sb)
Definition: hdac.c:1797
static uint32_t hdac_stream_getptr(device_t dev, device_t child, int dir, int stream)
Definition: hdac.c:2109
static void hdac_stream_free(device_t dev, device_t child, int dir, int stream)
Definition: hdac.c:1961
static int hdac_detach(device_t)
Definition: hdac.c:1729
static int hdac_resume(device_t)
Definition: hdac.c:1665
static int hdac_suspend(device_t)
Definition: hdac.c:1635
static void hdac_stream_reset(device_t dev, device_t child, int dir, int stream)
Definition: hdac.c:2071
static int hdac_stream_alloc(device_t dev, device_t child, int dir, int format, int stripe, uint32_t **dmapos)
Definition: hdac.c:1901
static void hdac_stream_stop(device_t dev, device_t child, int dir, int stream)
Definition: hdac.c:2043
static int hdac_print_child(device_t dev, device_t child)
Definition: hdac.c:1777
static struct mtx * hdac_get_mtx(device_t dev, device_t child)
Definition: hdac.c:1850
static uint32_t hdac_codec_command(device_t dev, device_t child, uint32_t verb)
Definition: hdac.c:1858
static bus_dma_tag_t hdac_get_dma_tag(device_t dev, device_t child)
Definition: hdac.c:1769
static void hdac_unsol_free(device_t dev, device_t child, int tag)
Definition: hdac.c:2133

Definition at line 2141 of file hdac.c.

◆ 

const struct { ... } hdac_pcie_snoop[]
Initial value:
= {
{ INTEL_VENDORID, 0x00, 0x00, 0x00 },
{ ATI_VENDORID, 0x42, 0xf8, 0x02 },
{ AMD_VENDORID, 0x42, 0xf8, 0x02 },
{ NVIDIA_VENDORID, 0x4e, 0xf0, 0x0f },
}
#define NVIDIA_VENDORID
Definition: hdac.h:109
#define INTEL_VENDORID
Definition: hdac.h:45
#define ATI_VENDORID
Definition: hdac.h:146
#define AMD_VENDORID
Definition: hdac.h:176

Referenced by hdac_attach().

◆ 

const struct { ... } hdac_quirks_tab[]
Initial value:
= {
{ "64bit", HDAC_QUIRK_64BIT },
{ "dmapos", HDAC_QUIRK_DMAPOS },
{ "msi", HDAC_QUIRK_MSI },
}
#define HDAC_QUIRK_MSI
Definition: hdac.c:62
#define HDAC_QUIRK_DMAPOS
Definition: hdac.c:61
#define HDAC_QUIRK_64BIT
Definition: hdac.c:60

Referenced by hdac_config_fetch().

◆ key

const char* key

Definition at line 65 of file hdac.c.

Referenced by hdac_config_fetch().

◆ mask

◆ model

uint32_t model

Definition at line 76 of file hdac.c.

Referenced by hdac_attach(), and hdac_probe().

◆ quirks_off

char quirks_off

Definition at line 79 of file hdac.c.

Referenced by hdaa_local_patch(), and hdaa_sysctl_quirks().

◆ quirks_on

char quirks_on

Definition at line 78 of file hdac.c.

Referenced by hdaa_local_patch().

◆ reg

◆ value

uint32_t value

Definition at line 66 of file hdac.c.

◆ vendor

uint16_t vendor

Definition at line 210 of file hdac.c.

Referenced by hdac_attach().