UEFIStarter
a simple UEFI framework
ac97.h
Go to the documentation of this file.
1 
17 #ifndef __AC97_H
18 #define __AC97_H
19 
20 #include <UEFIStarter/pci.h>
22 
23 
24 #define AC97_BUFFER_COUNT 32
27 #define ARG_MUTE ac97_argument_list[0].value.uint64
28 #define ARG_VOLUME ac97_argument_list[1].value.dbl
29 #define ARG_SAMPLE_RATE ac97_argument_list[2].value.uint64
30 extern cmdline_argument_t ac97_argument_list[];
32 
33 
34 #define AC97_MIXER_RESET 0x00
35 #define AC97_MIXER_MASTER 0x02
36 #define AC97_MIXER_PCM_OUT 0x18
37 #define AC97_PCM_RATE_FRONT 0x2C
38 #define AC97_PCM_RATE_SURROUND 0x2E
39 #define AC97_PCM_RATE_LFE 0x30
42 //XXX when adding bus master registers, remember to add non-byte widths to getter function
43 #define AC97_DESCRIPTOR_PCM_OUT 0x10
44 #define AC97_CIV_PCM_OUT 0x14
45 #define AC97_LVI_PCM_OUT 0x15
46 #define AC97_STATUS_PCM_OUT 0x16
47 #define AC97_CONTROL_PCM_OUT 0x1B
48 #define AC97_GLOBAL_CONTROL 0x2C
55 typedef struct
56 {
57  UINT16 reset;
58  UINT16 master_vol;
59  UINT16 aux_out_vol;
60  UINT16 mono_vol;
61  UINT16 master_tone;
62  UINT16 pc_beep_vol;
63  UINT16 phone_vol;
64  UINT16 mic_vol;
65  UINT16 line_in_vol;
66  UINT16 cd_vol;
67  UINT16 video_vol;
68  UINT16 aux_in_vol;
69  UINT16 pcm_out_vol;
70  UINT16 record_select;
71  UINT16 record_gain;
72  UINT16 record_gain_mic;
73  UINT16 general_purpose;
74  UINT16 three_d_control;
75  UINT16 _reserved24;
77  union
78  {
79  UINT16 raw;
80  struct
81  {
82  UINT16 vra:1;
83  UINT16 dra:1;
84  UINT16 spdif:1;
85  UINT16 vrm:1;
86  UINT16 dsa:2;
87  UINT16 cdac:1;
88  UINT16 sdac:1;
89  UINT16 ldac:1;
90  UINT16 amap:1;
91  UINT16 rev:2;
92  UINT16 _reserved:2;
93  UINT16 id:2;
94  };
95  } extended_audio_id;
96  union
97  {
98  UINT16 raw;
99  struct
100  {
101  UINT16 vra:1;
102  UINT16 dra:1;
103  UINT16 spdif:1;
104  UINT16 vrm:1;
105  UINT16 spsa:2;
106  UINT16 cdac:1;
107  UINT16 sdac:1;
108  UINT16 ldac:1;
109  UINT16 madc:1;
110  UINT16 spcv:1;
111  UINT16 pri:1;
112  UINT16 prj:1;
113  UINT16 prk:1;
114  UINT16 prl:1;
115  UINT16 vcfg:1;
116  };
117  } extended_audio_statctrl;
123  UINT16 _unhandled3[5];
124  UINT16 _unhandled4[8];
125  UINT16 _unhandled5[8];
126  UINT16 _unhandled6[8];
127  UINT16 _unhandled7[6];
128  UINT16 vendor_id1;
129  UINT16 vendor_id2;
130 } ac97_bar_t;
131 
133 typedef struct
134 {
135  UINT32 address;
136  UINT16 length;
137  union
138  {
139  UINT16 raw;
140  struct
141  {
142  UINT16 _reserved:14;
143  UINT16 bup:1;
144  UINT16 ioc:1;
145  };
146  } control;
148 
154 typedef struct
155 {
156  ac97_buffer_descriptor_t descriptors[32];
157  INT16 *buffers[32];
159 
161 typedef struct
162 {
164  UINTN buffer_pages;
165  EFI_PHYSICAL_ADDRESS device_address;
166  void *mapping;
167  EFI_PCI_IO_PROTOCOL *pci;
169 } ac97_handle_t;
170 
172 typedef union
173 {
174  UINT16 raw;
175  struct
176  {
181  UINT16 fifo_error:1;
182  UINT16 _reserved:11;
183  };
185 
186 
187 EFI_PCI_IO_PROTOCOL *find_ac97_device();
188 void *init_ac97_handle(ac97_handle_t *handle, EFI_PCI_IO_PROTOCOL *pip);
189 void close_ac97_handle(ac97_handle_t *handle);
190 
191 
200 #define ac97_mixer_value(LEFT,RIGHT,MUTE) ((((LEFT)&0x3F)<<8)|((RIGHT)&0x3F)|((MUTE)?0x8000:0))
201 
202 EFI_STATUS write_mixer_reg(ac97_handle_t *handle, UINT32 reg, UINT16 value);
203 EFI_STATUS read_mixer_reg(ac97_handle_t *handle, UINT32 reg, UINT16 *value);
204 void print_volume_register(UINT16 *text, UINT16 value);
205 void print_volume_register_mono(UINT16 *text, UINT16 value);
206 EFI_STATUS set_ac97_cmdline_volume(ac97_handle_t *handle);
207 EFI_STATUS set_ac97_cmdline_sample_rate(ac97_handle_t *handle);
208 
209 EFI_STATUS write_busmaster_reg(ac97_handle_t *handle, UINT32 reg, UINTN value);
210 EFI_STATUS read_busmaster_reg(ac97_handle_t *handle, UINT32 reg, UINTN *value);
211 
212 EFI_STATUS flush_ac97_output(ac97_handle_t *handle);
213 EFI_STATUS ac97_play(ac97_handle_t *handle);
214 void ac97_wait_until_last_buffer_sent(ac97_handle_t *handle, UINTN timeout_in_milliseconds);
215 
216 
217 #define AC97_DUMP_VOLUME 0x00000001
218 #define AC97_DUMP_OTHER 0x80000000
219 #define AC97_DUMP_ALL -1
220 void dump_audio_registers(ac97_handle_t *handle, UINTN flags);
221 
222 
223 #endif
ac97_buffers_s16_t * buffers
ring buffer for audio output
Definition: ac97.h:163
UINT16 pcm_lr_adc_rate
offset 0x32
Definition: ac97.h:121
EFI_STATUS set_ac97_cmdline_volume(ac97_handle_t *handle)
Takes the "volume" and "mute" command-line arguments and configures the AC&#39;97 PCM OUT channel with th...
Definition: ac97.c:188
UINT16 amap
slot/DAC mappings support
Definition: ac97.h:90
UINT16 ldac
PCM LFE DAC support.
Definition: ac97.h:89
UINT16 record_select
offset 0x1A
Definition: ac97.h:70
UINT16 master_vol
offset 0x02
Definition: ac97.h:58
UINT16 prl
MIC ADC suppressed.
Definition: ac97.h:114
cmdline_argument_group_t ac97_arguments
command-line argument group for AC&#39;97
Definition: ac97.c:67
UINT16 vendor_id1
offset 0x7C
Definition: ac97.h:128
UINT16 spcv
S/PDIF configuration valid.
Definition: ac97.h:110
data type for bus master status register
Definition: ac97.h:172
UINT16 dsa
DAC slot assignments.
Definition: ac97.h:86
UINT16 rev
codec revision
Definition: ac97.h:91
UINT16 line_in_vol
offset 0x10
Definition: ac97.h:65
UINT16 aux_out_vol
offset 0x04
Definition: ac97.h:59
UINT16 _reserved24
offset 0x24
Definition: ac97.h:75
UINT16 length
length of buffer, in bytes
Definition: ac97.h:136
UINT16 cd_vol
offset 0x12
Definition: ac97.h:66
EFI_STATUS set_ac97_cmdline_sample_rate(ac97_handle_t *handle)
Takes the "sample rate" command-line argument and sets the AC&#39;97 PCM OUT channel&#39;s sample rate to tha...
Definition: ac97.c:228
void * mapping
DMA memory mapping for transferring audio data to AC&#39;97.
Definition: ac97.h:166
UINT16 vendor_id2
offset 0x7E
Definition: ac97.h:129
UINT16 powerdown_ctrlstat
offset 0x26
Definition: ac97.h:76
UINT16 record_gain
offset 0x1C
Definition: ac97.h:71
UINT16 pcm_out_vol
offset 0x18
Definition: ac97.h:69
UINT16 _reserved
(reserved)
Definition: ac97.h:142
UINT16 mic_vol
offset 0x0E
Definition: ac97.h:64
UINT16 last_valid_buffer_completion_interrupt
LVBCI.
Definition: ac97.h:179
void * init_ac97_handle(ac97_handle_t *handle, EFI_PCI_IO_PROTOCOL *pip)
Initializes an AC&#39;97 handle.
Definition: ac97.c:273
EFI_STATUS read_mixer_reg(ac97_handle_t *handle, UINT32 reg, UINT16 *value)
Reads an AC&#39;97 mixer register.
Definition: ac97.c:135
EFI_STATUS ac97_play(ac97_handle_t *handle)
Starts AC&#39;97 playback.
Definition: ac97.c:345
UINT16 dra
double-rate PCM audio support
Definition: ac97.h:83
UINT16 ioc
interrupt on completion
Definition: ac97.h:144
UINT16 _reserved
(reserved)
Definition: ac97.h:182
UINT16 aux_in_vol
offset 0x16
Definition: ac97.h:68
UINT16 general_purpose
offset 0x20
Definition: ac97.h:73
UINT16 pcm_mic_adc_rate
offset 0x34
Definition: ac97.h:122
data type for signed 16-bit integer audio buffers descriptor
Definition: ac97.h:154
EFI_PCI_IO_PROTOCOL * pci
UEFI PCI handle to use.
Definition: ac97.h:167
UINT16 record_gain_mic
offset 0x1E
Definition: ac97.h:72
EFI_PCI_IO_PROTOCOL * find_ac97_device()
Gets a PCI device handle for the AC&#39;97 device.
Definition: ac97.c:75
UINT16 prj
PCM surround DACs suppressed.
Definition: ac97.h:112
EFI_PHYSICAL_ADDRESS device_address
physical memory address to access the AC&#39;97 codec
Definition: ac97.h:165
UINT16 spsa
S/PDIF source.
Definition: ac97.h:105
UINT16 vrm
variable rate MIC input support
Definition: ac97.h:85
UINT16 buffer_completion_interrupt
BCIS.
Definition: ac97.h:180
UINT16 pc_beep_vol
offset 0x0A
Definition: ac97.h:62
UINT32 address
start of buffer
Definition: ac97.h:135
UINT16 vcfg
S/PDIF idle configuration.
Definition: ac97.h:115
Functions for accessing PCI devices.
UINT16 raw
raw access
Definition: ac97.h:79
void print_volume_register_mono(UINT16 *text, UINT16 value)
Prints a mono volume register&#39;s contents.
Definition: ac97.c:421
AC&#39;97 handle, this is the high-level handle for library use.
Definition: ac97.h:161
UINT16 pri
PCM center DAC suppressed.
Definition: ac97.h:111
UINT16 raw
raw access to buffer configuration
Definition: ac97.h:139
EFI_STATUS flush_ac97_output(ac97_handle_t *handle)
Flushes all pending AC&#39;97 memory writes.
Definition: ac97.c:333
UINT16 bup
buffer underrun policy
Definition: ac97.h:143
UINT16 spdif
S/PDIF support.
Definition: ac97.h:84
UINT16 master_tone
offset 0x08
Definition: ac97.h:61
UINT16 video_vol
offset 0x14
Definition: ac97.h:67
UINT16 _reserved
(reserved)
Definition: ac97.h:92
UINT16 current_equals_last_valid
CELV.
Definition: ac97.h:178
UINTN buffer_pages
number of memory pages allocated for audio buffers
Definition: ac97.h:164
UINT16 id
codec configuration
Definition: ac97.h:93
void print_volume_register(UINT16 *text, UINT16 value)
Prints a volume register&#39;s contents.
Definition: ac97.c:407
EFI_STATUS write_mixer_reg(ac97_handle_t *handle, UINT32 reg, UINT16 value)
Writes to an AC&#39;97 mixer register.
Definition: ac97.c:122
UINT16 vra
variable rate PCM audio support
Definition: ac97.h:82
EFI_STATUS write_busmaster_reg(ac97_handle_t *handle, UINT32 reg, UINTN value)
Writes to an AC&#39;97 bus master register.
Definition: ac97.c:164
UINT16 cdac
PCM center DAC support.
Definition: ac97.h:87
UINT16 three_d_control
offset 0x22
Definition: ac97.h:74
UINT16 sdac
PCM surround DAC support.
Definition: ac97.h:88
UINT16 fifo_error
FIFOE.
Definition: ac97.h:181
data type for AC&#39;97 buffer descriptor
Definition: ac97.h:133
UINT16 raw
raw access
Definition: ac97.h:174
EFI_STATUS read_busmaster_reg(ac97_handle_t *handle, UINT32 reg, UINTN *value)
Reads an AC&#39;97 bus master register.
Definition: ac97.c:177
model for group of command line arguments
Definition: cmdline.h:50
Data type for an AC&#39;97 "baseline audio register set".
Definition: ac97.h:55
UINT16 prk
PCM LFE DACs suppressed.
Definition: ac97.h:113
Command line parameter parser.
UINT16 dma_controller_halted
DCH.
Definition: ac97.h:177
void close_ac97_handle(ac97_handle_t *handle)
Destroys an AC&#39;97 handle.
Definition: ac97.c:316
UINT16 madc
MIC ADC ready.
Definition: ac97.h:109
UINT16 pcm_front_dac_rate
offset 0x2C
Definition: ac97.h:118
UINT16 pcm_lfe_dac_rate
offset 0x30
Definition: ac97.h:120
UINT16 pcm_surr_dac_rate
offset 0x2E
Definition: ac97.h:119
UINT16 reset
offset 0x00
Definition: ac97.h:57
void ac97_wait_until_last_buffer_sent(ac97_handle_t *handle, UINTN timeout_in_milliseconds)
Waits until the AC&#39;97 codec signaled the "last valid buffer completion" event.
Definition: ac97.c:379
UINT16 phone_vol
offset 0x0C
Definition: ac97.h:63
UINT8 max_master_vol
maximum master volume, either 31 or 63, depending on hardware
Definition: ac97.h:168
UINT16 mono_vol
offset 0x06
Definition: ac97.h:60