The manual
ginnOS
The reference: libc, the libraries and the kernel
Loading...
Searching...
No Matches
ac97.c File Reference
#include "ac97.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/page.h"
#include "kernel/memory/pmm.h"
#include "kernel/time/timer.h"

Data Structures

struct  __attribute__
 ELF32 file header. More...

Macros

#define NAM_RESET   0x00
 the AC'97 driver (Intel I/O Controller Hub 82801AA AC'97 programmer's reference; AC'97 component specification 2.3).
#define NAM_MASTER   0x02
#define NAM_PCM_OUT   0x18
#define NAM_EXT_ID   0x28
#define NAM_EXT_CTRL   0x2A
#define NAM_FRONT_RATE   0x2C
#define NAM_VENDOR_ID1   0x7C
#define NAM_VENDOR_ID2   0x7E
#define EXT_VRA   0x0001u
#define VOLUME_MUTE   0x8000u
#define PCM_OUT_0DB   0x0808u
#define PO_BDBAR   0x10
#define PO_CIV   0x14
#define PO_LVI   0x15
#define PO_SR   0x16
#define PO_CR   0x1B
#define GLOB_CNT   0x2C
#define GLOB_STA   0x30
#define CR_RUN   0x01u
#define CR_RESET   0x02u
#define CR_IOCE   0x10u
#define SR_DCH   0x01u
#define SR_LVBCI   0x04u
#define SR_BCIS   0x08u
#define SR_FIFOE   0x10u
#define SR_CLEAR   (SR_LVBCI | SR_BCIS | SR_FIFOE)
#define GLOB_COLD_RESET_OFF   0x02u
#define GLOB_CODEC_READY   0x100u
#define BDL_ENTRIES   32u
#define BDL_IOC   0x8000u
#define BDL_BUP   0x4000u
#define PERIODS   4u
#define PERIOD_BYTES   2048u
#define SPIN_LIMIT   10000000u
#define BUFFERS_OFFSET   0x400u

Functions

bool ac97_init (void)
 find the first AC'97 controller and register it as the sound device.

Macro Definition Documentation

◆ NAM_RESET

#define NAM_RESET   0x00

the AC'97 driver (Intel I/O Controller Hub 82801AA AC'97 programmer's reference; AC'97 component specification 2.3).

the PCM out channel reads a buffer descriptor list (BDL) of 32 entries; each entry points to a buffer and gives its length in samples. the controller plays the entries in a circle and stops after the last valid index (LVI). the driver uses PERIODS buffers: entry e plays buffer e % PERIODS. when an entry has played, the driver fills its buffer again from the audio core and moves the LVI forward, so the controller never reaches it while sound is queued.

the refill runs from the controller interrupt and from the timer (the controller has no MSI, and its INTx line may not be routed on a real machine with the I/O APIC). both run with interrupts off, so they never overlap.

◆ NAM_MASTER

#define NAM_MASTER   0x02

◆ NAM_PCM_OUT

#define NAM_PCM_OUT   0x18

◆ NAM_EXT_ID

#define NAM_EXT_ID   0x28

◆ NAM_EXT_CTRL

#define NAM_EXT_CTRL   0x2A

◆ NAM_FRONT_RATE

#define NAM_FRONT_RATE   0x2C

◆ NAM_VENDOR_ID1

#define NAM_VENDOR_ID1   0x7C

◆ NAM_VENDOR_ID2

#define NAM_VENDOR_ID2   0x7E

◆ EXT_VRA

#define EXT_VRA   0x0001u

◆ VOLUME_MUTE

#define VOLUME_MUTE   0x8000u

◆ PCM_OUT_0DB

#define PCM_OUT_0DB   0x0808u

◆ PO_BDBAR

#define PO_BDBAR   0x10

◆ PO_CIV

#define PO_CIV   0x14

◆ PO_LVI

#define PO_LVI   0x15

◆ PO_SR

#define PO_SR   0x16

◆ PO_CR

#define PO_CR   0x1B

◆ GLOB_CNT

#define GLOB_CNT   0x2C

◆ GLOB_STA

#define GLOB_STA   0x30

◆ CR_RUN

#define CR_RUN   0x01u

◆ CR_RESET

#define CR_RESET   0x02u

◆ CR_IOCE

#define CR_IOCE   0x10u

◆ SR_DCH

#define SR_DCH   0x01u

◆ SR_LVBCI

#define SR_LVBCI   0x04u

◆ SR_BCIS

#define SR_BCIS   0x08u

◆ SR_FIFOE

#define SR_FIFOE   0x10u

◆ SR_CLEAR

#define SR_CLEAR   (SR_LVBCI | SR_BCIS | SR_FIFOE)

◆ GLOB_COLD_RESET_OFF

#define GLOB_COLD_RESET_OFF   0x02u

◆ GLOB_CODEC_READY

#define GLOB_CODEC_READY   0x100u

◆ BDL_ENTRIES

#define BDL_ENTRIES   32u

◆ BDL_IOC

#define BDL_IOC   0x8000u

◆ BDL_BUP

#define BDL_BUP   0x4000u

◆ PERIODS

#define PERIODS   4u

◆ PERIOD_BYTES

#define PERIOD_BYTES   2048u

◆ SPIN_LIMIT

#define SPIN_LIMIT   10000000u

◆ BUFFERS_OFFSET

#define BUFFERS_OFFSET   0x400u

Function Documentation

◆ ac97_init()

bool ac97_init ( void )

find the first AC'97 controller and register it as the sound device.

call after pci_init and apic_init.

Returns
true if a controller is in use.