The manual
ginnOS
The reference: libc, the libraries and the kernel
Loading...
Searching...
No Matches
hda.c File Reference
#include "hda.h"
#include "arch/x86/cpu/io.h"
#include "common/memory.h"
#include "drivers/pci/pci.h"
#include "drivers/pci/pci_irq.h"
#include "kernel/audio/audio.h"
#include "kernel/klog/klog.h"
#include "kernel/memory/mmio.h"
#include "kernel/memory/page.h"
#include "kernel/memory/pmm.h"
#include "kernel/time/timer.h"

Data Structures

struct  __attribute__
 ELF32 file header. More...

Macros

#define GCAP   0x00
 the Intel HDA driver (High Definition Audio Specification 1.0a).
#define GCTL   0x08
#define STATESTS   0x0E
#define INTCTL   0x20
#define INTSTS   0x24
#define CORBLBASE   0x40
#define CORBUBASE   0x44
#define CORBWP   0x48
#define CORBRP   0x4A
#define CORBCTL   0x4C
#define CORBSIZE   0x4E
#define RIRBLBASE   0x50
#define RIRBUBASE   0x54
#define RIRBWP   0x58
#define RINTCNT   0x5A
#define RIRBCTL   0x5C
#define RIRBSTS   0x5D
#define RIRBSIZE   0x5E
#define GCAP_64OK   0x0001u
#define GCTL_CRST   0x00000001u
#define INTCTL_GIE   0x80000000u
#define CORBRP_RESET   0x8000u
#define RIRBWP_RESET   0x8000u
#define RING_RUN   0x02u
#define RIRBSTS_CLEAR   0x05u
#define SD_BASE   0x80
#define SD_SIZE   0x20
#define SD_CTL0   0x00
#define SD_CTL2   0x02
#define SD_STS   0x03
#define SD_LPIB   0x04
#define SD_CBL   0x08
#define SD_LVI   0x0C
#define SD_FMT   0x12
#define SD_BDPL   0x18
#define SD_BDPU   0x1C
#define SD_SRST   0x01u
#define SD_RUN   0x02u
#define SD_IOCE   0x04u
#define SD_BCIS   0x04u
#define SD_STS_CLEAR   0x1Cu
#define VERB_GET_PARAM   0xF00
#define VERB_GET_CONN   0xF02
#define VERB_SET_SELECT   0x701
#define VERB_SET_POWER   0x705
#define VERB_SET_STREAM   0x706
#define VERB_SET_PIN_CTL   0x707
#define VERB_SET_EAPD   0x70C
#define VERB_GET_PIN_SENSE   0xF09
#define VERB_GET_CONFIG   0xF1C
#define VERB4_SET_FORMAT   0x2
#define VERB4_SET_AMP   0x3
#define PARAM_VENDOR   0x00
#define PARAM_NODE_COUNT   0x04
#define PARAM_FG_TYPE   0x05
#define PARAM_WIDGET_CAPS   0x09
#define PARAM_PCM   0x0A
#define PARAM_PIN_CAPS   0x0C
#define PARAM_IN_AMP_CAPS   0x0D
#define PARAM_CONN_LEN   0x0E
#define PARAM_OUT_AMP_CAPS   0x12
#define FG_AUDIO   0x01
#define WIDGET_TYPE(caps)
#define WIDGET_DAC   0x0
#define WIDGET_MIXER   0x2
#define WIDGET_SELECTOR   0x3
#define WIDGET_PIN   0x4
#define CAPS_IN_AMP   (1u << 1)
#define CAPS_OUT_AMP   (1u << 2)
#define CAPS_AMP_OVERRIDE   (1u << 3)
#define PIN_CAPS_PRESENCE   (1u << 2)
#define PIN_CAPS_OUTPUT   (1u << 4)
#define PIN_CAPS_EAPD   (1u << 16)
#define CONFIG_PORT(c)
#define CONFIG_DEVICE(c)
#define DEVICE_LINE_OUT   0x0
#define DEVICE_SPEAKER   0x1
#define DEVICE_HEADPHONE   0x2
#define PIN_CTL_OUT   0x40u
#define PIN_CTL_HP   0x80u
#define EAPD_ON   0x02u
#define AMP_OUT   0x8000u
#define AMP_IN   0x4000u
#define AMP_LEFT_RIGHT   0x3000u
#define AMP_MUTE   0x0080u
#define MAX_NODES   128u
#define MAX_CONN   16u
#define MAX_PATH   5u
#define MAX_PATHS   4u
#define STREAM_TAG   1u
#define PERIODS   4u
#define PERIOD_BYTES   2048u
#define SPIN_LIMIT   2000000u
#define DMA_CORB   0x0000u
#define DMA_RIRB   0x0800u
#define DMA_BDL   0x1000u
#define DMA_BUFFERS   0x2000u
#define DMA_PAGES   ((DMA_BUFFERS + PERIODS * PERIOD_BYTES + PAGE_SIZE - 1) / PAGE_SIZE)
#define FORMAT_16BIT_STEREO   0x0011u
#define RATE_COUNT   (sizeof(rates) / sizeof(rates[0]))

Functions

bool hda_init (void)
 find the first HDA controller and register it as the sound device.

Macro Definition Documentation

◆ GCAP

#define GCAP   0x00

the Intel HDA driver (High Definition Audio Specification 1.0a).

controller: the host sends codec commands (verbs) through the command output ring buffer (CORB) and reads the answers from the response input ring buffer (RIRB), both in RAM. a stream descriptor plays a cyclic buffer described by a buffer descriptor list (BDL).

codec: a tree of widgets (nodes). an output path goes from a pin complex (the jack or the speaker) through mixers and selectors to an audio output converter (DAC). the driver finds such a path for each connected output pin of the first codec that has one, powers the widgets, unmutes their amplifiers, selects the connections and sets the converters to stream 1. all the converters take the same stream, so the sound plays on every output.

playback: PERIODS buffers of PERIOD_BYTES in one cyclic buffer, with an interrupt after each. the stream loops over the buffer by itself; when the position (LPIB) has passed a period, the driver fills it again from the audio core. the refill also runs from the timer, in case the interrupt does not come.

the commands are polled; they are sent only during setup and for volume changes.

◆ GCTL

#define GCTL   0x08

◆ STATESTS

#define STATESTS   0x0E

◆ INTCTL

#define INTCTL   0x20

◆ INTSTS

#define INTSTS   0x24

◆ CORBLBASE

#define CORBLBASE   0x40

◆ CORBUBASE

#define CORBUBASE   0x44

◆ CORBWP

#define CORBWP   0x48

◆ CORBRP

#define CORBRP   0x4A

◆ CORBCTL

#define CORBCTL   0x4C

◆ CORBSIZE

#define CORBSIZE   0x4E

◆ RIRBLBASE

#define RIRBLBASE   0x50

◆ RIRBUBASE

#define RIRBUBASE   0x54

◆ RIRBWP

#define RIRBWP   0x58

◆ RINTCNT

#define RINTCNT   0x5A

◆ RIRBCTL

#define RIRBCTL   0x5C

◆ RIRBSTS

#define RIRBSTS   0x5D

◆ RIRBSIZE

#define RIRBSIZE   0x5E

◆ GCAP_64OK

#define GCAP_64OK   0x0001u

◆ GCTL_CRST

#define GCTL_CRST   0x00000001u

◆ INTCTL_GIE

#define INTCTL_GIE   0x80000000u

◆ CORBRP_RESET

#define CORBRP_RESET   0x8000u

◆ RIRBWP_RESET

#define RIRBWP_RESET   0x8000u

◆ RING_RUN

#define RING_RUN   0x02u

◆ RIRBSTS_CLEAR

#define RIRBSTS_CLEAR   0x05u

◆ SD_BASE

#define SD_BASE   0x80

◆ SD_SIZE

#define SD_SIZE   0x20

◆ SD_CTL0

#define SD_CTL0   0x00

◆ SD_CTL2

#define SD_CTL2   0x02

◆ SD_STS

#define SD_STS   0x03

◆ SD_LPIB

#define SD_LPIB   0x04

◆ SD_CBL

#define SD_CBL   0x08

◆ SD_LVI

#define SD_LVI   0x0C

◆ SD_FMT

#define SD_FMT   0x12

◆ SD_BDPL

#define SD_BDPL   0x18

◆ SD_BDPU

#define SD_BDPU   0x1C

◆ SD_SRST

#define SD_SRST   0x01u

◆ SD_RUN

#define SD_RUN   0x02u

◆ SD_IOCE

#define SD_IOCE   0x04u

◆ SD_BCIS

#define SD_BCIS   0x04u

◆ SD_STS_CLEAR

#define SD_STS_CLEAR   0x1Cu

◆ VERB_GET_PARAM

#define VERB_GET_PARAM   0xF00

◆ VERB_GET_CONN

#define VERB_GET_CONN   0xF02

◆ VERB_SET_SELECT

#define VERB_SET_SELECT   0x701

◆ VERB_SET_POWER

#define VERB_SET_POWER   0x705

◆ VERB_SET_STREAM

#define VERB_SET_STREAM   0x706

◆ VERB_SET_PIN_CTL

#define VERB_SET_PIN_CTL   0x707

◆ VERB_SET_EAPD

#define VERB_SET_EAPD   0x70C

◆ VERB_GET_PIN_SENSE

#define VERB_GET_PIN_SENSE   0xF09

◆ VERB_GET_CONFIG

#define VERB_GET_CONFIG   0xF1C

◆ VERB4_SET_FORMAT

#define VERB4_SET_FORMAT   0x2

◆ VERB4_SET_AMP

#define VERB4_SET_AMP   0x3

◆ PARAM_VENDOR

#define PARAM_VENDOR   0x00

◆ PARAM_NODE_COUNT

#define PARAM_NODE_COUNT   0x04

◆ PARAM_FG_TYPE

#define PARAM_FG_TYPE   0x05

◆ PARAM_WIDGET_CAPS

#define PARAM_WIDGET_CAPS   0x09

◆ PARAM_PCM

#define PARAM_PCM   0x0A

◆ PARAM_PIN_CAPS

#define PARAM_PIN_CAPS   0x0C

◆ PARAM_IN_AMP_CAPS

#define PARAM_IN_AMP_CAPS   0x0D

◆ PARAM_CONN_LEN

#define PARAM_CONN_LEN   0x0E

◆ PARAM_OUT_AMP_CAPS

#define PARAM_OUT_AMP_CAPS   0x12

◆ FG_AUDIO

#define FG_AUDIO   0x01

◆ WIDGET_TYPE

#define WIDGET_TYPE ( caps)
Value:
(((caps) >> 20) & 0xFu)

◆ WIDGET_DAC

#define WIDGET_DAC   0x0

◆ WIDGET_MIXER

#define WIDGET_MIXER   0x2

◆ WIDGET_SELECTOR

#define WIDGET_SELECTOR   0x3

◆ WIDGET_PIN

#define WIDGET_PIN   0x4

◆ CAPS_IN_AMP

#define CAPS_IN_AMP   (1u << 1)

◆ CAPS_OUT_AMP

#define CAPS_OUT_AMP   (1u << 2)

◆ CAPS_AMP_OVERRIDE

#define CAPS_AMP_OVERRIDE   (1u << 3)

◆ PIN_CAPS_PRESENCE

#define PIN_CAPS_PRESENCE   (1u << 2)

◆ PIN_CAPS_OUTPUT

#define PIN_CAPS_OUTPUT   (1u << 4)

◆ PIN_CAPS_EAPD

#define PIN_CAPS_EAPD   (1u << 16)

◆ CONFIG_PORT

#define CONFIG_PORT ( c)
Value:
(((c) >> 30) & 0x3u)

◆ CONFIG_DEVICE

#define CONFIG_DEVICE ( c)
Value:
(((c) >> 20) & 0xFu)

◆ DEVICE_LINE_OUT

#define DEVICE_LINE_OUT   0x0

◆ DEVICE_SPEAKER

#define DEVICE_SPEAKER   0x1

◆ DEVICE_HEADPHONE

#define DEVICE_HEADPHONE   0x2

◆ PIN_CTL_OUT

#define PIN_CTL_OUT   0x40u

◆ PIN_CTL_HP

#define PIN_CTL_HP   0x80u

◆ EAPD_ON

#define EAPD_ON   0x02u

◆ AMP_OUT

#define AMP_OUT   0x8000u

◆ AMP_IN

#define AMP_IN   0x4000u

◆ AMP_LEFT_RIGHT

#define AMP_LEFT_RIGHT   0x3000u

◆ AMP_MUTE

#define AMP_MUTE   0x0080u

◆ MAX_NODES

#define MAX_NODES   128u

◆ MAX_CONN

#define MAX_CONN   16u

◆ MAX_PATH

#define MAX_PATH   5u

◆ MAX_PATHS

#define MAX_PATHS   4u

◆ STREAM_TAG

#define STREAM_TAG   1u

◆ PERIODS

#define PERIODS   4u

◆ PERIOD_BYTES

#define PERIOD_BYTES   2048u

◆ SPIN_LIMIT

#define SPIN_LIMIT   2000000u

◆ DMA_CORB

#define DMA_CORB   0x0000u

◆ DMA_RIRB

#define DMA_RIRB   0x0800u

◆ DMA_BDL

#define DMA_BDL   0x1000u

◆ DMA_BUFFERS

#define DMA_BUFFERS   0x2000u

◆ DMA_PAGES

#define DMA_PAGES   ((DMA_BUFFERS + PERIODS * PERIOD_BYTES + PAGE_SIZE - 1) / PAGE_SIZE)

◆ FORMAT_16BIT_STEREO

#define FORMAT_16BIT_STEREO   0x0011u

◆ RATE_COUNT

#define RATE_COUNT   (sizeof(rates) / sizeof(rates[0]))

Function Documentation

◆ hda_init()

bool hda_init ( void )

find the first HDA controller and register it as the sound device.

call after pci_init and apic_init.

Returns
true if a controller is in use.