|
ginnOS
The reference: libc, the libraries and the kernel
|
#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. | |
| #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.
| #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])) |
| bool hda_init | ( | void | ) |
find the first HDA controller and register it as the sound device.
call after pci_init and apic_init.