OpenCore  1.0.4
OpenCore Bootloader
Loading...
Searching...
No Matches
HdaRegisters.h
Go to the documentation of this file.
1/*
2 * File: HdaRegisters.h
3 *
4 * Copyright (c) 2018, 2020 John Davis
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
24
25#ifndef EFI_HDA_REGS_H
26#define EFI_HDA_REGS_H
27
28#include <Uefi.h>
29
30//
31// Global Capabilities, Status, and Control.
32//
33
34// Global Capabilities; 2 bytes.
35#define HDA_REG_GCAP 0x00
36#define HDA_REG_GCAP_64OK BIT0
37#define HDA_REG_GCAP_NSDO(a) ((UINT8)((a >> 1) & 0x3))
38#define HDA_REG_GCAP_BSS(a) ((UINT8)((a >> 3) & 0x1F))
39#define HDA_REG_GCAP_ISS(a) ((UINT8)((a >> 8) & 0xF))
40#define HDA_REG_GCAP_OSS(a) ((UINT8)((a >> 12) & 0xF))
41
42// Minor Version; 1 byte.
43#define HDA_REG_VMIN 0x02
44
45// Major Version; 1 byte.
46#define HDA_REG_VMAJ 0x03
47
48// Output Payload Capability; 2 bytes.
49#define HDA_REG_OUTPAY 0x04
50
51// Input Payload Capability; 2 bytes.
52#define HDA_REG_INPAY 0x06
53
54// Global Control; 4 bytes.
55#define HDA_REG_GCTL 0x08
56#define HDA_REG_GCTL_CRST BIT0
57#define HDA_REG_GCTL_FCNTRL BIT1
58#define HDA_REG_GCTL_UNSOL BIT8
59
60// Wake Enable; 2 bytes.
61#define HDA_REG_WAKEEN 0x0C
62
63// State Change Status; 2 bytes.
64#define HDA_REG_STATESTS 0x0E
65#define HDA_REG_STATESTS_INDEX(i) ((UINT16)(1 << (i)))
66#define HDA_REG_STATESTS_CLEAR 0xEFFF
67
68// Global Status; 2 bytes
69#define HDA_REG_GSTS 0x10
70#define HDA_REG_GSTS_FSTS BIT1
71
72// Output Stream Payload Capability; 2 bytes.
73#define HDA_REG_OUTSTRMPAY 0x18
74
75// Input Stream Payload Capability; 2 bytes.
76#define HDA_REG_INSTRMPAY 0x1A
77
78//
79// Interrupt Status and Control.
80//
81
82// Interrupt Control; 4 bytes.
83#define HDA_REG_INTCTL 0x20
84
85// Interrupt Status; 4 bytes.
86#define HDA_REG_INTSTS 0x24
87
88// Wall Clock Counter; 4 bytes.
89#define HDA_REG_WALLCLOCK 0x30
90
91// Stream Synchronization; 4 bytes.
92#define HDA_REG_SSYNC 0x38
93
94// CORB Lower Base Address; 4 bytes.
95#define HDA_REG_CORBLBASE 0x40
96
97// CORB Upper Base Address; 4 bytes.
98#define HDA_REG_CORBUBASE 0x44
99
100// CORB Write Pointer; 2 bytes.
101#define HDA_REG_CORBWP 0x48
102
103// CORB Read Pointer; 2 bytes.
104#define HDA_REG_CORBRP 0x4A
105#define HDA_REG_CORBRP_RP(a) ((UINT8)a)
106#define HDA_REG_CORBRP_RST BIT15
107
108// CORB Control; 1 byte.
109#define HDA_REG_CORBCTL 0x4C
110#define HDA_REG_CORBCTL_CMEIE BIT0
111#define HDA_REG_CORBCTL_CORBRUN BIT1
112
113// CORB Status; 1 byte.
114#define HDA_REG_CORBSTS 0x4D
115#define HDA_REG_CORBSTS_CMEI BIT0
116
117// CORB Size; 1 byte.
118#define HDA_REG_CORBSIZE 0x4E
119#define HDA_REG_CORBSIZE_MASK (BIT0 | BIT1)
120#define HDA_REG_CORBSIZE_ENT2 0 // 8 B = 2 entries.
121#define HDA_REG_CORBSIZE_ENT16 BIT0 // 64 B = 16 entries.
122#define HDA_REG_CORBSIZE_ENT256 BIT1 // 1 KB = 256 entries.
123#define HDA_REG_CORBSIZE_CORBSZCAP_2 BIT4 // 8 B = 2 entries.
124#define HDA_REG_CORBSIZE_CORBSZCAP_16 BIT5 // 64 B = 16 entries.
125#define HDA_REG_CORBSIZE_CORBSZCAP_256 BIT6 // 1 KB = 256 entries.
126
127// RIRB Lower Base Address; 4 bytes.
128#define HDA_REG_RIRBLBASE 0x50
129
130// RIRB Upper Base Address; 4 bytes.
131#define HDA_REG_RIRBUBASE 0x54
132
133// RIRB Write Pointer; 2 bytes.
134#define HDA_REG_RIRBWP 0x58
135#define HDA_REG_RIRBWP_WP(a) ((UINT8)a)
136#define HDA_REG_RIRBWP_RST BIT15
137
138// Response Interrupt Count; 2 bytes.
139#define HDA_REG_RINTCNT 0x5A
140
141// RIRB Control; 1 byte.
142#define HDA_REG_RIRBCTL 0x5C
143#define HDA_REG_RIRBCTL_RINTCTL BIT0
144#define HDA_REG_RIRBCTL_RIRBDMAEN BIT1
145#define HDA_REG_RIRBCTL_RIRBOIC BIT2
146
147// RIRB Status; 1 byte.
148#define HDA_REG_RIRBSTS 0x5D
149#define HDA_REG_RIRBSTS_RINTFL BIT0
150#define HDA_REG_RIRBSTS_RIRBOIS BIT2
151
152// RIRB Size; 1 byte.
153#define HDA_REG_RIRBSIZE 0x5E
154#define HDA_REG_RIRBSIZE_MASK (BIT0 | BIT1)
155#define HDA_REG_RIRBSIZE_ENT2 0 // 16 B = 2 entries.
156#define HDA_REG_RIRBSIZE_ENT16 BIT0 // 128 B = 16 entries.
157#define HDA_REG_RIRBSIZE_ENT256 BIT1 // 2 KB = 256 entries.
158#define HDA_REG_RIRBSIZE_RIRBSZCAP_2 BIT4 // 16 B = 2 entries.
159#define HDA_REG_RIRBSIZE_RIRBSZCAP_16 BIT5 // 128 B = 16 entries.
160#define HDA_REG_RIRBSIZE_RIRBSZCAP_256 BIT6 // 2 KB = 256 entries.
161
162// DMA Position Lower Base Address; 4 bytes.
163#define HDA_REG_DPLBASE 0x70
164#define HDA_REG_DPLBASE_EN BIT0
165
166// DMA Position Upper Base Address; 4 bytes.
167#define HDA_REG_DPUBASE 0x74
168
169//
170// Immediate Command Input and Output Registers.
171//
172
173// Immediate Command Output Interface; 4 bytes.
174#define HDA_REG_ICOI 0x60
175
176// Immediate Command Input Interface; 4 bytes.
177#define HDA_REG_ICII 0x64
178
179// Immediate Command Status; 2 bytes.
180#define HDA_REG_ICIS 0x68
181#define HDA_REG_ICIS_ICB BIT0
182#define HDA_REG_ICIS_IRV BIT1
183#define HDA_REG_ICIS_ICV BIT2
184#define HDA_REG_ICIS_IRRUNSOL BIT3
185#define HDA_REG_ICIS_IRRADD(a) ((UINT8)((a >> 4) & 0xF))
186
187//
188// Stream Descriptors.
189//
190
191// Input/Output/Bidirectional Stream Descriptor n Control; 3 bytes.
192// Byte 1.
193#define HDA_REG_SDNCTL1(n) (0x80 + (0x20 * (n)))
194#define HDA_REG_SDNCTL1_SRST BIT0
195#define HDA_REG_SDNCTL1_RUN BIT1
196#define HDA_REG_SDNCTL1_IOCE BIT2
197#define HDA_REG_SDNCTL1_FEIE BIT3
198#define HDA_REG_SDNCTL1_DEIE BIT4
199
200// Byte 2.
201#define HDA_REG_SDNCTL2(n) (0x81 + (0x20 * (n)))
202
203// Byte 3.
204#define HDA_REG_SDNCTL3(n) (0x82 + (0x20 * (n)))
205#define HDA_REG_SDNCTL3_TP BIT2
206#define HDA_REG_SDNCTL3_DIR BIT3
207#define HDA_REG_SDNCTL3_STRM_GET(a) ((UINT8)((a >> 4) & 0xF))
208#define HDA_REG_SDNCTL3_STRM_SET(a, s) ((UINT8)(((a) & 0x0F) | (((s) & 0xF)) << 4))
209
210// Input/Output/Bidirectional Stream Descriptor n Status; 1 byte.
211#define HDA_REG_SDNSTS(n) (0x83 + (0x20 * (n)))
212#define HDA_REG_SDNSTS_BCIS BIT2
213#define HDA_REG_SDNSTS_FIFOE BIT3
214#define HDA_REG_SDNSTS_DESE BIT4
215#define HDA_REG_SDNSTS_FIFORDY BIT5
216
217// Input/Output/Bidirectional Stream Descriptor n Link Position in Buffer; 4 bytes.
218#define HDA_REG_SDNLPIB(n) (0x84 + (0x20 * (n)))
219
220// Input/Output/Bidirectional Stream Descriptor n Cyclic Buffer Length; 4 bytes.
221#define HDA_REG_SDNCBL(n) (0x88 + (0x20 * (n)))
222
223// Input/Output/Bidirectional Stream Descriptor n Last Valid Index; 2 bytes.
224#define HDA_REG_SDNLVI(n) (0x8C + (0x20 * (n)))
225
226// Input/Output/Bidirectional Stream Descriptor n FIFO Size; 2 bytes.
227#define HDA_REG_SDNFIFOS(n) (0x90 + (0x20 * (n)))
228
229// Input/Output/Bidirectional Stream Descriptor n Format; 2 bytes.
230#define HDA_REG_SDNFMT(n) (0x92 + (0x20 * (n)))
231#define HDA_REG_SDNFMT_CHAN(a) ((UINT8)((a) & 0xF))
232#define HDA_REG_SDNFMT_BITS(a) ((UINT8)(((a) >> 4) & 0x3))
233#define HDA_REG_SDNFMT_BITS_8 0x0
234#define HDA_REG_SDNFMT_BITS_16 0x1
235#define HDA_REG_SDNFMT_BITS_20 0x2
236#define HDA_REG_SDNFMT_BITS_24 0x3
237#define HDA_REG_SDNFMT_BITS_32 0x4
238#define HDA_REG_SDNFMT_DIV(a) ((UINT8)(((a) >> 8) & 0x3))
239#define HDA_REG_SDNFMT_MULT(a) ((UINT8)(((a) >> 11) & 0x3))
240#define HDA_REG_SDNFMT_BASE_44KHZ BIT14
241#define HDA_REG_SDNFMT_SET(chan, bits, div, mult, base) \
242 ((UINT16)(((chan) & 0xF) | (((bits) & 0x3) << 4) | (((div) & 0x3) << 8) | \
243 (((mult) & 0x3) << 11) | ((base) ? HDA_REG_SDNFMT_BASE_44KHZ : 0)))
244
245// Input/Output/Bidirectional Stream Descriptor n BDL Pointer Lower Base Address; 4 bytes.
246#define HDA_REG_SDNBDPL(n) (0x98 + (0x20 * (n)))
247
248// Input/Output/Bidirectional Stream Descriptor n BDL Pointer Upper Base Address; 4 bytes.
249#define HDA_REG_SDNBDPU(n) (0x9C + (0x20 * (n)))
250
251// Wall Clock Counter Alias; 4 bytes.
252#define HDA_REG_WALCLKA 0x2030
253
254// Input/Output/Bidirectional Stream Descriptor n Link Position in Buffer Alias; 4 bytes.
255#define HDA_REG_SDNLPIBA(n) (0x2084 + (0x20 * (n)))
256
257//
258// Ring buffer register offsets (CORB and RIRB).
259//
260#define HDA_REG_CORB_BASE 0x40
261#define HDA_REG_RIRB_BASE 0x50
262
263#define HDA_OFFSET_RING_BASE 0x00
264#define HDA_OFFSET_RING_UBASE 0x04
265#define HDA_OFFSET_RING_WP 0x08
266#define HDA_OFFSET_RING_RP 0x0A
267
268#define HDA_OFFSET_RING_CTL 0x0C
269#define HDA_OFFSET_RING_CTL_RUN BIT1
270
271#define HDA_OFFSET_RING_STS 0x0D
272
273#define HDA_OFFSET_RING_SIZE 0x0E
274#define HDA_OFFSET_RING_SIZE_MASK (BIT0 | BIT1)
275#define HDA_OFFSET_RING_SIZE_ENT2 0 // 2 entries.
276#define HDA_OFFSET_RING_SIZE_ENT16 BIT0 // 16 entries.
277#define HDA_OFFSET_RING_SIZE_ENT256 BIT1 // 256 entries.
278#define HDA_OFFSET_RING_SIZE_SZCAP_2 BIT4 // 2 entries.
279#define HDA_OFFSET_RING_SIZE_SZCAP_16 BIT5 // 16 entries.
280#define HDA_OFFSET_RING_SIZE_SZCAP_256 BIT6 // 256 entries.
281
282#endif // EFI_HDA_REGS_H