root / hw / ac97.c @ bf5b7423
History | View | Annotate | Download (36.7 kB)
1 | e5c9a13e | balrog | /*
|
---|---|---|---|
2 | e5c9a13e | balrog | * Copyright (C) 2006 InnoTek Systemberatung GmbH
|
3 | e5c9a13e | balrog | *
|
4 | e5c9a13e | balrog | * This file is part of VirtualBox Open Source Edition (OSE), as
|
5 | e5c9a13e | balrog | * available from http://www.virtualbox.org. This file is free software;
|
6 | e5c9a13e | balrog | * you can redistribute it and/or modify it under the terms of the GNU
|
7 | e5c9a13e | balrog | * General Public License as published by the Free Software Foundation,
|
8 | e5c9a13e | balrog | * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
|
9 | e5c9a13e | balrog | * distribution. VirtualBox OSE is distributed in the hope that it will
|
10 | e5c9a13e | balrog | * be useful, but WITHOUT ANY WARRANTY of any kind.
|
11 | e5c9a13e | balrog | *
|
12 | e5c9a13e | balrog | * If you received this file as part of a commercial VirtualBox
|
13 | e5c9a13e | balrog | * distribution, then only the terms of your commercial VirtualBox
|
14 | e5c9a13e | balrog | * license agreement apply instead of the previous paragraph.
|
15 | e5c9a13e | balrog | */
|
16 | e5c9a13e | balrog | |
17 | e5c9a13e | balrog | #include "hw.h" |
18 | e5c9a13e | balrog | #include "audiodev.h" |
19 | e5c9a13e | balrog | #include "audio/audio.h" |
20 | e5c9a13e | balrog | #include "pci.h" |
21 | e5c9a13e | balrog | |
22 | e5c9a13e | balrog | enum {
|
23 | e5c9a13e | balrog | AC97_Reset = 0x00,
|
24 | e5c9a13e | balrog | AC97_Master_Volume_Mute = 0x02,
|
25 | e5c9a13e | balrog | AC97_Headphone_Volume_Mute = 0x04,
|
26 | e5c9a13e | balrog | AC97_Master_Volume_Mono_Mute = 0x06,
|
27 | e5c9a13e | balrog | AC97_Master_Tone_RL = 0x08,
|
28 | e5c9a13e | balrog | AC97_PC_BEEP_Volume_Mute = 0x0A,
|
29 | e5c9a13e | balrog | AC97_Phone_Volume_Mute = 0x0C,
|
30 | e5c9a13e | balrog | AC97_Mic_Volume_Mute = 0x0E,
|
31 | e5c9a13e | balrog | AC97_Line_In_Volume_Mute = 0x10,
|
32 | e5c9a13e | balrog | AC97_CD_Volume_Mute = 0x12,
|
33 | e5c9a13e | balrog | AC97_Video_Volume_Mute = 0x14,
|
34 | e5c9a13e | balrog | AC97_Aux_Volume_Mute = 0x16,
|
35 | e5c9a13e | balrog | AC97_PCM_Out_Volume_Mute = 0x18,
|
36 | e5c9a13e | balrog | AC97_Record_Select = 0x1A,
|
37 | e5c9a13e | balrog | AC97_Record_Gain_Mute = 0x1C,
|
38 | e5c9a13e | balrog | AC97_Record_Gain_Mic_Mute = 0x1E,
|
39 | e5c9a13e | balrog | AC97_General_Purpose = 0x20,
|
40 | e5c9a13e | balrog | AC97_3D_Control = 0x22,
|
41 | e5c9a13e | balrog | AC97_AC_97_RESERVED = 0x24,
|
42 | e5c9a13e | balrog | AC97_Powerdown_Ctrl_Stat = 0x26,
|
43 | e5c9a13e | balrog | AC97_Extended_Audio_ID = 0x28,
|
44 | e5c9a13e | balrog | AC97_Extended_Audio_Ctrl_Stat = 0x2A,
|
45 | e5c9a13e | balrog | AC97_PCM_Front_DAC_Rate = 0x2C,
|
46 | e5c9a13e | balrog | AC97_PCM_Surround_DAC_Rate = 0x2E,
|
47 | e5c9a13e | balrog | AC97_PCM_LFE_DAC_Rate = 0x30,
|
48 | e5c9a13e | balrog | AC97_PCM_LR_ADC_Rate = 0x32,
|
49 | e5c9a13e | balrog | AC97_MIC_ADC_Rate = 0x34,
|
50 | e5c9a13e | balrog | AC97_6Ch_Vol_C_LFE_Mute = 0x36,
|
51 | e5c9a13e | balrog | AC97_6Ch_Vol_L_R_Surround_Mute = 0x38,
|
52 | e5c9a13e | balrog | AC97_Vendor_Reserved = 0x58,
|
53 | e5c9a13e | balrog | AC97_Vendor_ID1 = 0x7c,
|
54 | e5c9a13e | balrog | AC97_Vendor_ID2 = 0x7e
|
55 | e5c9a13e | balrog | }; |
56 | e5c9a13e | balrog | |
57 | e5c9a13e | balrog | #define SOFT_VOLUME
|
58 | e5c9a13e | balrog | #define SR_FIFOE 16 /* rwc */ |
59 | e5c9a13e | balrog | #define SR_BCIS 8 /* rwc */ |
60 | e5c9a13e | balrog | #define SR_LVBCI 4 /* rwc */ |
61 | e5c9a13e | balrog | #define SR_CELV 2 /* ro */ |
62 | e5c9a13e | balrog | #define SR_DCH 1 /* ro */ |
63 | e5c9a13e | balrog | #define SR_VALID_MASK ((1 << 5) - 1) |
64 | e5c9a13e | balrog | #define SR_WCLEAR_MASK (SR_FIFOE | SR_BCIS | SR_LVBCI)
|
65 | e5c9a13e | balrog | #define SR_RO_MASK (SR_DCH | SR_CELV)
|
66 | e5c9a13e | balrog | #define SR_INT_MASK (SR_FIFOE | SR_BCIS | SR_LVBCI)
|
67 | e5c9a13e | balrog | |
68 | e5c9a13e | balrog | #define CR_IOCE 16 /* rw */ |
69 | e5c9a13e | balrog | #define CR_FEIE 8 /* rw */ |
70 | e5c9a13e | balrog | #define CR_LVBIE 4 /* rw */ |
71 | e5c9a13e | balrog | #define CR_RR 2 /* rw */ |
72 | e5c9a13e | balrog | #define CR_RPBM 1 /* rw */ |
73 | e5c9a13e | balrog | #define CR_VALID_MASK ((1 << 5) - 1) |
74 | e5c9a13e | balrog | #define CR_DONT_CLEAR_MASK (CR_IOCE | CR_FEIE | CR_LVBIE)
|
75 | e5c9a13e | balrog | |
76 | e5c9a13e | balrog | #define GC_WR 4 /* rw */ |
77 | e5c9a13e | balrog | #define GC_CR 2 /* rw */ |
78 | e5c9a13e | balrog | #define GC_VALID_MASK ((1 << 6) - 1) |
79 | e5c9a13e | balrog | |
80 | e5c9a13e | balrog | #define GS_MD3 (1<<17) /* rw */ |
81 | e5c9a13e | balrog | #define GS_AD3 (1<<16) /* rw */ |
82 | e5c9a13e | balrog | #define GS_RCS (1<<15) /* rwc */ |
83 | e5c9a13e | balrog | #define GS_B3S12 (1<<14) /* ro */ |
84 | e5c9a13e | balrog | #define GS_B2S12 (1<<13) /* ro */ |
85 | e5c9a13e | balrog | #define GS_B1S12 (1<<12) /* ro */ |
86 | e5c9a13e | balrog | #define GS_S1R1 (1<<11) /* rwc */ |
87 | e5c9a13e | balrog | #define GS_S0R1 (1<<10) /* rwc */ |
88 | e5c9a13e | balrog | #define GS_S1CR (1<<9) /* ro */ |
89 | e5c9a13e | balrog | #define GS_S0CR (1<<8) /* ro */ |
90 | e5c9a13e | balrog | #define GS_MINT (1<<7) /* ro */ |
91 | e5c9a13e | balrog | #define GS_POINT (1<<6) /* ro */ |
92 | e5c9a13e | balrog | #define GS_PIINT (1<<5) /* ro */ |
93 | e5c9a13e | balrog | #define GS_RSRVD ((1<<4)|(1<<3)) |
94 | e5c9a13e | balrog | #define GS_MOINT (1<<2) /* ro */ |
95 | e5c9a13e | balrog | #define GS_MIINT (1<<1) /* ro */ |
96 | e5c9a13e | balrog | #define GS_GSCI 1 /* rwc */ |
97 | e5c9a13e | balrog | #define GS_RO_MASK (GS_B3S12| \
|
98 | e5c9a13e | balrog | GS_B2S12| \ |
99 | e5c9a13e | balrog | GS_B1S12| \ |
100 | e5c9a13e | balrog | GS_S1CR| \ |
101 | e5c9a13e | balrog | GS_S0CR| \ |
102 | e5c9a13e | balrog | GS_MINT| \ |
103 | e5c9a13e | balrog | GS_POINT| \ |
104 | e5c9a13e | balrog | GS_PIINT| \ |
105 | e5c9a13e | balrog | GS_RSRVD| \ |
106 | e5c9a13e | balrog | GS_MOINT| \ |
107 | e5c9a13e | balrog | GS_MIINT) |
108 | e5c9a13e | balrog | #define GS_VALID_MASK ((1 << 18) - 1) |
109 | e5c9a13e | balrog | #define GS_WCLEAR_MASK (GS_RCS|GS_S1R1|GS_S0R1|GS_GSCI)
|
110 | e5c9a13e | balrog | |
111 | e5c9a13e | balrog | #define BD_IOC (1<<31) |
112 | e5c9a13e | balrog | #define BD_BUP (1<<30) |
113 | e5c9a13e | balrog | |
114 | e5c9a13e | balrog | #define EACS_VRA 1 |
115 | e5c9a13e | balrog | #define EACS_VRM 8 |
116 | e5c9a13e | balrog | |
117 | e5c9a13e | balrog | #define VOL_MASK 0x1f |
118 | e5c9a13e | balrog | #define MUTE_SHIFT 15 |
119 | e5c9a13e | balrog | |
120 | e5c9a13e | balrog | #define REC_MASK 7 |
121 | e5c9a13e | balrog | enum {
|
122 | e5c9a13e | balrog | REC_MIC = 0,
|
123 | e5c9a13e | balrog | REC_CD, |
124 | e5c9a13e | balrog | REC_VIDEO, |
125 | e5c9a13e | balrog | REC_AUX, |
126 | e5c9a13e | balrog | REC_LINE_IN, |
127 | e5c9a13e | balrog | REC_STEREO_MIX, |
128 | e5c9a13e | balrog | REC_MONO_MIX, |
129 | e5c9a13e | balrog | REC_PHONE |
130 | e5c9a13e | balrog | }; |
131 | e5c9a13e | balrog | |
132 | e5c9a13e | balrog | typedef struct BD { |
133 | e5c9a13e | balrog | uint32_t addr; |
134 | e5c9a13e | balrog | uint32_t ctl_len; |
135 | e5c9a13e | balrog | } BD; |
136 | e5c9a13e | balrog | |
137 | e5c9a13e | balrog | typedef struct AC97BusMasterRegs { |
138 | e5c9a13e | balrog | uint32_t bdbar; /* rw 0 */
|
139 | e5c9a13e | balrog | uint8_t civ; /* ro 0 */
|
140 | e5c9a13e | balrog | uint8_t lvi; /* rw 0 */
|
141 | e5c9a13e | balrog | uint16_t sr; /* rw 1 */
|
142 | e5c9a13e | balrog | uint16_t picb; /* ro 0 */
|
143 | e5c9a13e | balrog | uint8_t piv; /* ro 0 */
|
144 | e5c9a13e | balrog | uint8_t cr; /* rw 0 */
|
145 | e5c9a13e | balrog | unsigned int bd_valid; |
146 | e5c9a13e | balrog | BD bd; |
147 | e5c9a13e | balrog | } AC97BusMasterRegs; |
148 | e5c9a13e | balrog | |
149 | e5c9a13e | balrog | typedef struct AC97LinkState { |
150 | e5c9a13e | balrog | PCIDevice *pci_dev; |
151 | e5c9a13e | balrog | QEMUSoundCard card; |
152 | e5c9a13e | balrog | uint32_t glob_cnt; |
153 | e5c9a13e | balrog | uint32_t glob_sta; |
154 | e5c9a13e | balrog | uint32_t cas; |
155 | e5c9a13e | balrog | uint32_t last_samp; |
156 | e5c9a13e | balrog | AC97BusMasterRegs bm_regs[3];
|
157 | e5c9a13e | balrog | uint8_t mixer_data[256];
|
158 | e5c9a13e | balrog | SWVoiceIn *voice_pi; |
159 | e5c9a13e | balrog | SWVoiceOut *voice_po; |
160 | e5c9a13e | balrog | SWVoiceIn *voice_mc; |
161 | e5c9a13e | balrog | uint8_t silence[128];
|
162 | e5c9a13e | balrog | uint32_t base[2];
|
163 | e5c9a13e | balrog | int bup_flag;
|
164 | e5c9a13e | balrog | } AC97LinkState; |
165 | e5c9a13e | balrog | |
166 | e5c9a13e | balrog | enum {
|
167 | e5c9a13e | balrog | BUP_SET = 1,
|
168 | e5c9a13e | balrog | BUP_LAST = 2
|
169 | e5c9a13e | balrog | }; |
170 | e5c9a13e | balrog | |
171 | e5c9a13e | balrog | #ifdef DEBUG_AC97
|
172 | e5c9a13e | balrog | #define dolog(...) AUD_log ("ac97", __VA_ARGS__) |
173 | e5c9a13e | balrog | #else
|
174 | e5c9a13e | balrog | #define dolog(...)
|
175 | e5c9a13e | balrog | #endif
|
176 | e5c9a13e | balrog | |
177 | e5c9a13e | balrog | typedef struct PCIAC97LinkState { |
178 | e5c9a13e | balrog | PCIDevice dev; |
179 | e5c9a13e | balrog | AC97LinkState ac97; |
180 | e5c9a13e | balrog | } PCIAC97LinkState; |
181 | e5c9a13e | balrog | |
182 | e5c9a13e | balrog | #define MKREGS(prefix, start) \
|
183 | e5c9a13e | balrog | enum { \
|
184 | e5c9a13e | balrog | prefix ## _BDBAR = start, \ |
185 | e5c9a13e | balrog | prefix ## _CIV = start + 4, \ |
186 | e5c9a13e | balrog | prefix ## _LVI = start + 5, \ |
187 | e5c9a13e | balrog | prefix ## _SR = start + 6, \ |
188 | e5c9a13e | balrog | prefix ## _PICB = start + 8, \ |
189 | e5c9a13e | balrog | prefix ## _PIV = start + 10, \ |
190 | e5c9a13e | balrog | prefix ## _CR = start + 11 \ |
191 | e5c9a13e | balrog | } |
192 | e5c9a13e | balrog | |
193 | e5c9a13e | balrog | enum {
|
194 | e5c9a13e | balrog | PI_INDEX = 0,
|
195 | e5c9a13e | balrog | PO_INDEX, |
196 | e5c9a13e | balrog | MC_INDEX, |
197 | e5c9a13e | balrog | LAST_INDEX |
198 | e5c9a13e | balrog | }; |
199 | e5c9a13e | balrog | |
200 | e5c9a13e | balrog | MKREGS (PI, PI_INDEX * 16);
|
201 | e5c9a13e | balrog | MKREGS (PO, PO_INDEX * 16);
|
202 | e5c9a13e | balrog | MKREGS (MC, MC_INDEX * 16);
|
203 | e5c9a13e | balrog | |
204 | e5c9a13e | balrog | enum {
|
205 | e5c9a13e | balrog | GLOB_CNT = 0x2c,
|
206 | e5c9a13e | balrog | GLOB_STA = 0x30,
|
207 | e5c9a13e | balrog | CAS = 0x34
|
208 | e5c9a13e | balrog | }; |
209 | e5c9a13e | balrog | |
210 | e5c9a13e | balrog | #define GET_BM(index) (((index) >> 4) & 3) |
211 | e5c9a13e | balrog | |
212 | e5c9a13e | balrog | static void po_callback (void *opaque, int free); |
213 | e5c9a13e | balrog | static void pi_callback (void *opaque, int avail); |
214 | e5c9a13e | balrog | static void mc_callback (void *opaque, int avail); |
215 | e5c9a13e | balrog | |
216 | e5c9a13e | balrog | static void warm_reset (AC97LinkState *s) |
217 | e5c9a13e | balrog | { |
218 | e5c9a13e | balrog | (void) s;
|
219 | e5c9a13e | balrog | } |
220 | e5c9a13e | balrog | |
221 | e5c9a13e | balrog | static void cold_reset (AC97LinkState * s) |
222 | e5c9a13e | balrog | { |
223 | e5c9a13e | balrog | (void) s;
|
224 | e5c9a13e | balrog | } |
225 | e5c9a13e | balrog | |
226 | e5c9a13e | balrog | static void fetch_bd (AC97LinkState *s, AC97BusMasterRegs *r) |
227 | e5c9a13e | balrog | { |
228 | e5c9a13e | balrog | uint8_t b[8];
|
229 | e5c9a13e | balrog | |
230 | e5c9a13e | balrog | cpu_physical_memory_read (r->bdbar + r->civ * 8, b, 8); |
231 | e5c9a13e | balrog | r->bd_valid = 1;
|
232 | e5c9a13e | balrog | r->bd.addr = le32_to_cpu (*(uint32_t *) &b[0]) & ~3; |
233 | e5c9a13e | balrog | r->bd.ctl_len = le32_to_cpu (*(uint32_t *) &b[4]);
|
234 | e5c9a13e | balrog | r->picb = r->bd.ctl_len & 0xffff;
|
235 | e5c9a13e | balrog | dolog ("bd %2d addr=%#x ctl=%#06x len=%#x(%d bytes)\n",
|
236 | e5c9a13e | balrog | r->civ, r->bd.addr, r->bd.ctl_len >> 16,
|
237 | e5c9a13e | balrog | r->bd.ctl_len & 0xffff,
|
238 | e5c9a13e | balrog | (r->bd.ctl_len & 0xffff) << 1); |
239 | e5c9a13e | balrog | } |
240 | e5c9a13e | balrog | |
241 | e5c9a13e | balrog | static void update_sr (AC97LinkState *s, AC97BusMasterRegs *r, uint32_t new_sr) |
242 | e5c9a13e | balrog | { |
243 | e5c9a13e | balrog | int event = 0; |
244 | e5c9a13e | balrog | int level = 0; |
245 | e5c9a13e | balrog | uint32_t new_mask = new_sr & SR_INT_MASK; |
246 | e5c9a13e | balrog | uint32_t old_mask = r->sr & SR_INT_MASK; |
247 | e5c9a13e | balrog | uint32_t masks[] = {GS_PIINT, GS_POINT, GS_MINT}; |
248 | e5c9a13e | balrog | |
249 | e5c9a13e | balrog | if (new_mask ^ old_mask) {
|
250 | e5c9a13e | balrog | /** @todo is IRQ deasserted when only one of status bits is cleared? */
|
251 | e5c9a13e | balrog | if (!new_mask) {
|
252 | e5c9a13e | balrog | event = 1;
|
253 | e5c9a13e | balrog | level = 0;
|
254 | e5c9a13e | balrog | } |
255 | e5c9a13e | balrog | else {
|
256 | e5c9a13e | balrog | if ((new_mask & SR_LVBCI) && (r->cr & CR_LVBIE)) {
|
257 | e5c9a13e | balrog | event = 1;
|
258 | e5c9a13e | balrog | level = 1;
|
259 | e5c9a13e | balrog | } |
260 | e5c9a13e | balrog | if ((new_mask & SR_BCIS) && (r->cr & CR_IOCE)) {
|
261 | e5c9a13e | balrog | event = 1;
|
262 | e5c9a13e | balrog | level = 1;
|
263 | e5c9a13e | balrog | } |
264 | e5c9a13e | balrog | } |
265 | e5c9a13e | balrog | } |
266 | e5c9a13e | balrog | |
267 | e5c9a13e | balrog | r->sr = new_sr; |
268 | e5c9a13e | balrog | |
269 | e5c9a13e | balrog | dolog ("IOC%d LVB%d sr=%#x event=%d level=%d\n",
|
270 | e5c9a13e | balrog | r->sr & SR_BCIS, r->sr & SR_LVBCI, |
271 | e5c9a13e | balrog | r->sr, |
272 | e5c9a13e | balrog | event, level); |
273 | e5c9a13e | balrog | |
274 | e5c9a13e | balrog | if (!event)
|
275 | e5c9a13e | balrog | return;
|
276 | e5c9a13e | balrog | |
277 | e5c9a13e | balrog | if (level) {
|
278 | e5c9a13e | balrog | s->glob_sta |= masks[r - s->bm_regs]; |
279 | e5c9a13e | balrog | dolog ("set irq level=1\n");
|
280 | e5c9a13e | balrog | qemu_set_irq(s->pci_dev->irq[0], 1); |
281 | e5c9a13e | balrog | } |
282 | e5c9a13e | balrog | else {
|
283 | e5c9a13e | balrog | s->glob_sta &= ~masks[r - s->bm_regs]; |
284 | e5c9a13e | balrog | dolog ("set irq level=0\n");
|
285 | e5c9a13e | balrog | qemu_set_irq(s->pci_dev->irq[0], 0); |
286 | e5c9a13e | balrog | } |
287 | e5c9a13e | balrog | } |
288 | e5c9a13e | balrog | |
289 | e5c9a13e | balrog | static void voice_set_active (AC97LinkState *s, int bm_index, int on) |
290 | e5c9a13e | balrog | { |
291 | e5c9a13e | balrog | switch (bm_index) {
|
292 | e5c9a13e | balrog | case PI_INDEX:
|
293 | e5c9a13e | balrog | AUD_set_active_in (s->voice_pi, on); |
294 | e5c9a13e | balrog | break;
|
295 | e5c9a13e | balrog | |
296 | e5c9a13e | balrog | case PO_INDEX:
|
297 | e5c9a13e | balrog | AUD_set_active_out (s->voice_po, on); |
298 | e5c9a13e | balrog | break;
|
299 | e5c9a13e | balrog | |
300 | e5c9a13e | balrog | case MC_INDEX:
|
301 | e5c9a13e | balrog | AUD_set_active_in (s->voice_mc, on); |
302 | e5c9a13e | balrog | break;
|
303 | e5c9a13e | balrog | |
304 | e5c9a13e | balrog | default:
|
305 | e5c9a13e | balrog | AUD_log ("ac97", "invalid bm_index(%d) in voice_set_active", bm_index); |
306 | e5c9a13e | balrog | break;
|
307 | e5c9a13e | balrog | } |
308 | e5c9a13e | balrog | } |
309 | e5c9a13e | balrog | |
310 | e5c9a13e | balrog | static void reset_bm_regs (AC97LinkState *s, AC97BusMasterRegs *r) |
311 | e5c9a13e | balrog | { |
312 | e5c9a13e | balrog | dolog ("reset_bm_regs\n");
|
313 | e5c9a13e | balrog | r->bdbar = 0;
|
314 | e5c9a13e | balrog | r->civ = 0;
|
315 | e5c9a13e | balrog | r->lvi = 0;
|
316 | e5c9a13e | balrog | /** todo do we need to do that? */
|
317 | e5c9a13e | balrog | update_sr (s, r, SR_DCH); |
318 | e5c9a13e | balrog | r->picb = 0;
|
319 | e5c9a13e | balrog | r->piv = 0;
|
320 | e5c9a13e | balrog | r->cr = r->cr & CR_DONT_CLEAR_MASK; |
321 | e5c9a13e | balrog | r->bd_valid = 0;
|
322 | e5c9a13e | balrog | |
323 | e5c9a13e | balrog | voice_set_active (s, r - s->bm_regs, 0);
|
324 | e5c9a13e | balrog | memset (s->silence, 0, sizeof (s->silence)); |
325 | e5c9a13e | balrog | } |
326 | e5c9a13e | balrog | |
327 | e5c9a13e | balrog | static void mixer_store (AC97LinkState *s, uint32_t i, uint16_t v) |
328 | e5c9a13e | balrog | { |
329 | e5c9a13e | balrog | if (i + 2 > sizeof (s->mixer_data)) { |
330 | e5c9a13e | balrog | dolog ("mixer_store: index %d out of bounds %d\n",
|
331 | e5c9a13e | balrog | i, sizeof (s->mixer_data));
|
332 | e5c9a13e | balrog | return;
|
333 | e5c9a13e | balrog | } |
334 | e5c9a13e | balrog | |
335 | e5c9a13e | balrog | s->mixer_data[i + 0] = v & 0xff; |
336 | e5c9a13e | balrog | s->mixer_data[i + 1] = v >> 8; |
337 | e5c9a13e | balrog | } |
338 | e5c9a13e | balrog | |
339 | e5c9a13e | balrog | static uint16_t mixer_load (AC97LinkState *s, uint32_t i)
|
340 | e5c9a13e | balrog | { |
341 | e5c9a13e | balrog | uint16_t val = 0xffff;
|
342 | e5c9a13e | balrog | |
343 | e5c9a13e | balrog | if (i + 2 > sizeof (s->mixer_data)) { |
344 | e5c9a13e | balrog | dolog ("mixer_store: index %d out of bounds %d\n",
|
345 | e5c9a13e | balrog | i, sizeof (s->mixer_data));
|
346 | e5c9a13e | balrog | } |
347 | e5c9a13e | balrog | else {
|
348 | e5c9a13e | balrog | val = s->mixer_data[i + 0] | (s->mixer_data[i + 1] << 8); |
349 | e5c9a13e | balrog | } |
350 | e5c9a13e | balrog | |
351 | e5c9a13e | balrog | return val;
|
352 | e5c9a13e | balrog | } |
353 | e5c9a13e | balrog | |
354 | e5c9a13e | balrog | static void open_voice (AC97LinkState *s, int index, int freq) |
355 | e5c9a13e | balrog | { |
356 | e5c9a13e | balrog | audsettings_t as; |
357 | e5c9a13e | balrog | |
358 | e5c9a13e | balrog | as.freq = freq; |
359 | e5c9a13e | balrog | as.nchannels = 2;
|
360 | e5c9a13e | balrog | as.fmt = AUD_FMT_S16; |
361 | e5c9a13e | balrog | as.endianness = 0;
|
362 | e5c9a13e | balrog | |
363 | e5c9a13e | balrog | switch (index) {
|
364 | e5c9a13e | balrog | case PI_INDEX:
|
365 | e5c9a13e | balrog | s->voice_pi = AUD_open_in ( |
366 | e5c9a13e | balrog | &s->card, |
367 | e5c9a13e | balrog | s->voice_pi, |
368 | e5c9a13e | balrog | "ac97.pi",
|
369 | e5c9a13e | balrog | s, |
370 | e5c9a13e | balrog | pi_callback, |
371 | e5c9a13e | balrog | &as |
372 | e5c9a13e | balrog | ); |
373 | e5c9a13e | balrog | break;
|
374 | e5c9a13e | balrog | |
375 | e5c9a13e | balrog | case PO_INDEX:
|
376 | e5c9a13e | balrog | s->voice_po = AUD_open_out ( |
377 | e5c9a13e | balrog | &s->card, |
378 | e5c9a13e | balrog | s->voice_po, |
379 | e5c9a13e | balrog | "ac97.po",
|
380 | e5c9a13e | balrog | s, |
381 | e5c9a13e | balrog | po_callback, |
382 | e5c9a13e | balrog | &as |
383 | e5c9a13e | balrog | ); |
384 | e5c9a13e | balrog | break;
|
385 | e5c9a13e | balrog | |
386 | e5c9a13e | balrog | case MC_INDEX:
|
387 | e5c9a13e | balrog | s->voice_mc = AUD_open_in ( |
388 | e5c9a13e | balrog | &s->card, |
389 | e5c9a13e | balrog | s->voice_mc, |
390 | e5c9a13e | balrog | "ac97.mc",
|
391 | e5c9a13e | balrog | s, |
392 | e5c9a13e | balrog | mc_callback, |
393 | e5c9a13e | balrog | &as |
394 | e5c9a13e | balrog | ); |
395 | e5c9a13e | balrog | break;
|
396 | e5c9a13e | balrog | } |
397 | e5c9a13e | balrog | } |
398 | e5c9a13e | balrog | |
399 | e5c9a13e | balrog | static void reset_voices (AC97LinkState *s, uint8_t active[LAST_INDEX]) |
400 | e5c9a13e | balrog | { |
401 | e5c9a13e | balrog | uint16_t freq; |
402 | e5c9a13e | balrog | |
403 | e5c9a13e | balrog | freq = mixer_load (s, AC97_PCM_LR_ADC_Rate); |
404 | e5c9a13e | balrog | open_voice (s, PI_INDEX, freq); |
405 | e5c9a13e | balrog | AUD_set_active_in (s->voice_pi, active[PI_INDEX]); |
406 | e5c9a13e | balrog | |
407 | e5c9a13e | balrog | freq = mixer_load (s, AC97_PCM_Front_DAC_Rate); |
408 | e5c9a13e | balrog | open_voice (s, PO_INDEX, freq); |
409 | e5c9a13e | balrog | AUD_set_active_out (s->voice_po, active[PO_INDEX]); |
410 | e5c9a13e | balrog | |
411 | e5c9a13e | balrog | freq = mixer_load (s, AC97_MIC_ADC_Rate); |
412 | e5c9a13e | balrog | open_voice (s, MC_INDEX, freq); |
413 | e5c9a13e | balrog | AUD_set_active_in (s->voice_mc, active[MC_INDEX]); |
414 | e5c9a13e | balrog | } |
415 | e5c9a13e | balrog | |
416 | e5c9a13e | balrog | #ifdef USE_MIXER
|
417 | e5c9a13e | balrog | static void set_volume (AC97LinkState *s, int index, |
418 | e5c9a13e | balrog | audmixerctl_t mt, uint32_t val) |
419 | e5c9a13e | balrog | { |
420 | e5c9a13e | balrog | int mute = (val >> MUTE_SHIFT) & 1; |
421 | e5c9a13e | balrog | uint8_t rvol = VOL_MASK - (val & VOL_MASK); |
422 | e5c9a13e | balrog | uint8_t lvol = VOL_MASK - ((val >> 8) & VOL_MASK);
|
423 | e5c9a13e | balrog | rvol = 255 * rvol / VOL_MASK;
|
424 | e5c9a13e | balrog | lvol = 255 * lvol / VOL_MASK;
|
425 | e5c9a13e | balrog | |
426 | e5c9a13e | balrog | #ifdef SOFT_VOLUME
|
427 | e5c9a13e | balrog | if (index == AC97_Master_Volume_Mute) {
|
428 | e5c9a13e | balrog | AUD_set_volume_out (s->voice_po, mute, lvol, rvol); |
429 | e5c9a13e | balrog | } |
430 | e5c9a13e | balrog | else {
|
431 | e5c9a13e | balrog | AUD_set_volume (mt, &mute, &lvol, &rvol); |
432 | e5c9a13e | balrog | } |
433 | e5c9a13e | balrog | #else
|
434 | e5c9a13e | balrog | AUD_set_volume (mt, &mute, &lvol, &rvol); |
435 | e5c9a13e | balrog | #endif
|
436 | e5c9a13e | balrog | |
437 | e5c9a13e | balrog | rvol = VOL_MASK - ((VOL_MASK * rvol) / 255);
|
438 | e5c9a13e | balrog | lvol = VOL_MASK - ((VOL_MASK * lvol) / 255);
|
439 | e5c9a13e | balrog | mixer_store (s, index, val); |
440 | e5c9a13e | balrog | } |
441 | e5c9a13e | balrog | |
442 | e5c9a13e | balrog | static audrecsource_t ac97_to_aud_record_source (uint8_t i)
|
443 | e5c9a13e | balrog | { |
444 | e5c9a13e | balrog | switch (i) {
|
445 | e5c9a13e | balrog | case REC_MIC:
|
446 | e5c9a13e | balrog | return AUD_REC_MIC;
|
447 | e5c9a13e | balrog | |
448 | e5c9a13e | balrog | case REC_CD:
|
449 | e5c9a13e | balrog | return AUD_REC_CD;
|
450 | e5c9a13e | balrog | |
451 | e5c9a13e | balrog | case REC_VIDEO:
|
452 | e5c9a13e | balrog | return AUD_REC_VIDEO;
|
453 | e5c9a13e | balrog | |
454 | e5c9a13e | balrog | case REC_AUX:
|
455 | e5c9a13e | balrog | return AUD_REC_AUX;
|
456 | e5c9a13e | balrog | |
457 | e5c9a13e | balrog | case REC_LINE_IN:
|
458 | e5c9a13e | balrog | return AUD_REC_LINE_IN;
|
459 | e5c9a13e | balrog | |
460 | e5c9a13e | balrog | case REC_PHONE:
|
461 | e5c9a13e | balrog | return AUD_REC_PHONE;
|
462 | e5c9a13e | balrog | |
463 | e5c9a13e | balrog | default:
|
464 | e5c9a13e | balrog | dolog ("Unknown record source %d, using MIC\n", i);
|
465 | e5c9a13e | balrog | return AUD_REC_MIC;
|
466 | e5c9a13e | balrog | } |
467 | e5c9a13e | balrog | } |
468 | e5c9a13e | balrog | |
469 | e5c9a13e | balrog | static uint8_t aud_to_ac97_record_source (audrecsource_t rs)
|
470 | e5c9a13e | balrog | { |
471 | e5c9a13e | balrog | switch (rs) {
|
472 | e5c9a13e | balrog | case AUD_REC_MIC:
|
473 | e5c9a13e | balrog | return REC_MIC;
|
474 | e5c9a13e | balrog | |
475 | e5c9a13e | balrog | case AUD_REC_CD:
|
476 | e5c9a13e | balrog | return REC_CD;
|
477 | e5c9a13e | balrog | |
478 | e5c9a13e | balrog | case AUD_REC_VIDEO:
|
479 | e5c9a13e | balrog | return REC_VIDEO;
|
480 | e5c9a13e | balrog | |
481 | e5c9a13e | balrog | case AUD_REC_AUX:
|
482 | e5c9a13e | balrog | return REC_AUX;
|
483 | e5c9a13e | balrog | |
484 | e5c9a13e | balrog | case AUD_REC_LINE_IN:
|
485 | e5c9a13e | balrog | return REC_LINE_IN;
|
486 | e5c9a13e | balrog | |
487 | e5c9a13e | balrog | case AUD_REC_PHONE:
|
488 | e5c9a13e | balrog | return REC_PHONE;
|
489 | e5c9a13e | balrog | |
490 | e5c9a13e | balrog | default:
|
491 | e5c9a13e | balrog | dolog ("Unknown audio recording source %d using MIC\n", rs);
|
492 | e5c9a13e | balrog | return REC_MIC;
|
493 | e5c9a13e | balrog | } |
494 | e5c9a13e | balrog | } |
495 | e5c9a13e | balrog | |
496 | e5c9a13e | balrog | static void record_select (AC97LinkState *s, uint32_t val) |
497 | e5c9a13e | balrog | { |
498 | e5c9a13e | balrog | uint8_t rs = val & REC_MASK; |
499 | e5c9a13e | balrog | uint8_t ls = (val >> 8) & REC_MASK;
|
500 | e5c9a13e | balrog | audrecsource_t ars = ac97_to_aud_record_source (rs); |
501 | e5c9a13e | balrog | audrecsource_t als = ac97_to_aud_record_source (ls); |
502 | e5c9a13e | balrog | AUD_set_record_source (&als, &ars); |
503 | e5c9a13e | balrog | rs = aud_to_ac97_record_source (ars); |
504 | e5c9a13e | balrog | ls = aud_to_ac97_record_source (als); |
505 | e5c9a13e | balrog | mixer_store (s, AC97_Record_Select, rs | (ls << 8));
|
506 | e5c9a13e | balrog | } |
507 | e5c9a13e | balrog | #endif
|
508 | e5c9a13e | balrog | |
509 | e5c9a13e | balrog | static void mixer_reset (AC97LinkState *s) |
510 | e5c9a13e | balrog | { |
511 | e5c9a13e | balrog | uint8_t active[LAST_INDEX]; |
512 | e5c9a13e | balrog | |
513 | e5c9a13e | balrog | dolog ("mixer_reset\n");
|
514 | e5c9a13e | balrog | memset (s->mixer_data, 0, sizeof (s->mixer_data)); |
515 | e5c9a13e | balrog | memset (active, 0, sizeof (active)); |
516 | e5c9a13e | balrog | mixer_store (s, AC97_Reset , 0x0000); /* 6940 */ |
517 | e5c9a13e | balrog | mixer_store (s, AC97_Master_Volume_Mono_Mute , 0x8000);
|
518 | e5c9a13e | balrog | mixer_store (s, AC97_PC_BEEP_Volume_Mute , 0x0000);
|
519 | e5c9a13e | balrog | |
520 | e5c9a13e | balrog | mixer_store (s, AC97_Phone_Volume_Mute , 0x8008);
|
521 | e5c9a13e | balrog | mixer_store (s, AC97_Mic_Volume_Mute , 0x8008);
|
522 | e5c9a13e | balrog | mixer_store (s, AC97_CD_Volume_Mute , 0x8808);
|
523 | e5c9a13e | balrog | mixer_store (s, AC97_Aux_Volume_Mute , 0x8808);
|
524 | e5c9a13e | balrog | mixer_store (s, AC97_Record_Gain_Mic_Mute , 0x8000);
|
525 | e5c9a13e | balrog | mixer_store (s, AC97_General_Purpose , 0x0000);
|
526 | e5c9a13e | balrog | mixer_store (s, AC97_3D_Control , 0x0000);
|
527 | e5c9a13e | balrog | mixer_store (s, AC97_Powerdown_Ctrl_Stat , 0x000f);
|
528 | e5c9a13e | balrog | |
529 | e5c9a13e | balrog | /*
|
530 | e5c9a13e | balrog | * Sigmatel 9700 (STAC9700)
|
531 | e5c9a13e | balrog | */
|
532 | e5c9a13e | balrog | mixer_store (s, AC97_Vendor_ID1 , 0x8384);
|
533 | e5c9a13e | balrog | mixer_store (s, AC97_Vendor_ID2 , 0x7600); /* 7608 */ |
534 | e5c9a13e | balrog | |
535 | e5c9a13e | balrog | mixer_store (s, AC97_Extended_Audio_ID , 0x0809);
|
536 | e5c9a13e | balrog | mixer_store (s, AC97_Extended_Audio_Ctrl_Stat, 0x0009);
|
537 | e5c9a13e | balrog | mixer_store (s, AC97_PCM_Front_DAC_Rate , 0xbb80);
|
538 | e5c9a13e | balrog | mixer_store (s, AC97_PCM_Surround_DAC_Rate , 0xbb80);
|
539 | e5c9a13e | balrog | mixer_store (s, AC97_PCM_LFE_DAC_Rate , 0xbb80);
|
540 | e5c9a13e | balrog | mixer_store (s, AC97_PCM_LR_ADC_Rate , 0xbb80);
|
541 | e5c9a13e | balrog | mixer_store (s, AC97_MIC_ADC_Rate , 0xbb80);
|
542 | e5c9a13e | balrog | |
543 | e5c9a13e | balrog | #ifdef USE_MIXER
|
544 | e5c9a13e | balrog | record_select (s, 0);
|
545 | e5c9a13e | balrog | set_volume (s, AC97_Master_Volume_Mute, AUD_MIXER_VOLUME , 0x8000);
|
546 | e5c9a13e | balrog | set_volume (s, AC97_PCM_Out_Volume_Mute, AUD_MIXER_PCM , 0x8808);
|
547 | e5c9a13e | balrog | set_volume (s, AC97_Line_In_Volume_Mute, AUD_MIXER_LINE_IN, 0x8808);
|
548 | e5c9a13e | balrog | #endif
|
549 | e5c9a13e | balrog | reset_voices (s, active); |
550 | e5c9a13e | balrog | } |
551 | e5c9a13e | balrog | |
552 | e5c9a13e | balrog | /**
|
553 | e5c9a13e | balrog | * Native audio mixer
|
554 | e5c9a13e | balrog | * I/O Reads
|
555 | e5c9a13e | balrog | */
|
556 | e5c9a13e | balrog | static uint32_t nam_readb (void *opaque, uint32_t addr) |
557 | e5c9a13e | balrog | { |
558 | e5c9a13e | balrog | PCIAC97LinkState *d = opaque; |
559 | e5c9a13e | balrog | AC97LinkState *s = &d->ac97; |
560 | e5c9a13e | balrog | dolog ("U nam readb %#x\n", addr);
|
561 | e5c9a13e | balrog | s->cas = 0;
|
562 | e5c9a13e | balrog | return ~0U; |
563 | e5c9a13e | balrog | } |
564 | e5c9a13e | balrog | |
565 | e5c9a13e | balrog | static uint32_t nam_readw (void *opaque, uint32_t addr) |
566 | e5c9a13e | balrog | { |
567 | e5c9a13e | balrog | PCIAC97LinkState *d = opaque; |
568 | e5c9a13e | balrog | AC97LinkState *s = &d->ac97; |
569 | e5c9a13e | balrog | uint32_t val = ~0U;
|
570 | e5c9a13e | balrog | uint32_t index = addr - s->base[0];
|
571 | e5c9a13e | balrog | s->cas = 0;
|
572 | e5c9a13e | balrog | val = mixer_load (s, index); |
573 | e5c9a13e | balrog | return val;
|
574 | e5c9a13e | balrog | } |
575 | e5c9a13e | balrog | |
576 | e5c9a13e | balrog | static uint32_t nam_readl (void *opaque, uint32_t addr) |
577 | e5c9a13e | balrog | { |
578 | e5c9a13e | balrog | PCIAC97LinkState *d = opaque; |
579 | e5c9a13e | balrog | AC97LinkState *s = &d->ac97; |
580 | e5c9a13e | balrog | dolog ("U nam readl %#x\n", addr);
|
581 | e5c9a13e | balrog | s->cas = 0;
|
582 | e5c9a13e | balrog | return ~0U; |
583 | e5c9a13e | balrog | } |
584 | e5c9a13e | balrog | |
585 | e5c9a13e | balrog | /**
|
586 | e5c9a13e | balrog | * Native audio mixer
|
587 | e5c9a13e | balrog | * I/O Writes
|
588 | e5c9a13e | balrog | */
|
589 | e5c9a13e | balrog | static void nam_writeb (void *opaque, uint32_t addr, uint32_t val) |
590 | e5c9a13e | balrog | { |
591 | e5c9a13e | balrog | PCIAC97LinkState *d = opaque; |
592 | e5c9a13e | balrog | AC97LinkState *s = &d->ac97; |
593 | e5c9a13e | balrog | dolog ("U nam writeb %#x <- %#x\n", addr, val);
|
594 | e5c9a13e | balrog | s->cas = 0;
|
595 | e5c9a13e | balrog | } |
596 | e5c9a13e | balrog | |
597 | e5c9a13e | balrog | static void nam_writew (void *opaque, uint32_t addr, uint32_t val) |
598 | e5c9a13e | balrog | { |
599 | e5c9a13e | balrog | PCIAC97LinkState *d = opaque; |
600 | e5c9a13e | balrog | AC97LinkState *s = &d->ac97; |
601 | e5c9a13e | balrog | uint32_t index = addr - s->base[0];
|
602 | e5c9a13e | balrog | s->cas = 0;
|
603 | e5c9a13e | balrog | switch (index) {
|
604 | e5c9a13e | balrog | case AC97_Reset:
|
605 | e5c9a13e | balrog | mixer_reset (s); |
606 | e5c9a13e | balrog | break;
|
607 | e5c9a13e | balrog | case AC97_Powerdown_Ctrl_Stat:
|
608 | e5c9a13e | balrog | val &= ~0xf;
|
609 | e5c9a13e | balrog | val |= mixer_load (s, index) & 0xf;
|
610 | e5c9a13e | balrog | mixer_store (s, index, val); |
611 | e5c9a13e | balrog | break;
|
612 | e5c9a13e | balrog | #ifdef USE_MIXER
|
613 | e5c9a13e | balrog | case AC97_Master_Volume_Mute:
|
614 | e5c9a13e | balrog | set_volume (s, index, AUD_MIXER_VOLUME, val); |
615 | e5c9a13e | balrog | break;
|
616 | e5c9a13e | balrog | case AC97_PCM_Out_Volume_Mute:
|
617 | e5c9a13e | balrog | set_volume (s, index, AUD_MIXER_PCM, val); |
618 | e5c9a13e | balrog | break;
|
619 | e5c9a13e | balrog | case AC97_Line_In_Volume_Mute:
|
620 | e5c9a13e | balrog | set_volume (s, index, AUD_MIXER_LINE_IN, val); |
621 | e5c9a13e | balrog | break;
|
622 | e5c9a13e | balrog | case AC97_Record_Select:
|
623 | e5c9a13e | balrog | record_select (s, val); |
624 | e5c9a13e | balrog | break;
|
625 | e5c9a13e | balrog | #endif
|
626 | e5c9a13e | balrog | case AC97_Vendor_ID1:
|
627 | e5c9a13e | balrog | case AC97_Vendor_ID2:
|
628 | e5c9a13e | balrog | dolog ("Attempt to write vendor ID to %#x\n", val);
|
629 | e5c9a13e | balrog | break;
|
630 | e5c9a13e | balrog | case AC97_Extended_Audio_ID:
|
631 | e5c9a13e | balrog | dolog ("Attempt to write extended audio ID to %#x\n", val);
|
632 | e5c9a13e | balrog | break;
|
633 | e5c9a13e | balrog | case AC97_Extended_Audio_Ctrl_Stat:
|
634 | e5c9a13e | balrog | if (!(val & EACS_VRA)) {
|
635 | e5c9a13e | balrog | mixer_store (s, AC97_PCM_Front_DAC_Rate, 0xbb80);
|
636 | e5c9a13e | balrog | mixer_store (s, AC97_PCM_LR_ADC_Rate, 0xbb80);
|
637 | e5c9a13e | balrog | open_voice (s, PI_INDEX, 48000);
|
638 | e5c9a13e | balrog | open_voice (s, PO_INDEX, 48000);
|
639 | e5c9a13e | balrog | } |
640 | e5c9a13e | balrog | if (!(val & EACS_VRM)) {
|
641 | e5c9a13e | balrog | mixer_store (s, AC97_MIC_ADC_Rate, 0xbb80);
|
642 | e5c9a13e | balrog | open_voice (s, MC_INDEX, 48000);
|
643 | e5c9a13e | balrog | } |
644 | e5c9a13e | balrog | dolog ("Setting extended audio control to %#x\n", val);
|
645 | e5c9a13e | balrog | mixer_store (s, AC97_Extended_Audio_Ctrl_Stat, val); |
646 | e5c9a13e | balrog | break;
|
647 | e5c9a13e | balrog | case AC97_PCM_Front_DAC_Rate:
|
648 | e5c9a13e | balrog | if (mixer_load (s, AC97_Extended_Audio_Ctrl_Stat) & EACS_VRA) {
|
649 | e5c9a13e | balrog | mixer_store (s, index, val); |
650 | e5c9a13e | balrog | dolog ("Set front DAC rate to %d\n", val);
|
651 | e5c9a13e | balrog | open_voice (s, PO_INDEX, val); |
652 | e5c9a13e | balrog | } |
653 | e5c9a13e | balrog | else {
|
654 | e5c9a13e | balrog | dolog ("Attempt to set front DAC rate to %d, "
|
655 | e5c9a13e | balrog | "but VRA is not set\n",
|
656 | e5c9a13e | balrog | val); |
657 | e5c9a13e | balrog | } |
658 | e5c9a13e | balrog | break;
|
659 | e5c9a13e | balrog | case AC97_MIC_ADC_Rate:
|
660 | e5c9a13e | balrog | if (mixer_load (s, AC97_Extended_Audio_Ctrl_Stat) & EACS_VRM) {
|
661 | e5c9a13e | balrog | mixer_store (s, index, val); |
662 | e5c9a13e | balrog | dolog ("Set MIC ADC rate to %d\n", val);
|
663 | e5c9a13e | balrog | open_voice (s, MC_INDEX, val); |
664 | e5c9a13e | balrog | } |
665 | e5c9a13e | balrog | else {
|
666 | e5c9a13e | balrog | dolog ("Attempt to set MIC ADC rate to %d, "
|
667 | e5c9a13e | balrog | "but VRM is not set\n",
|
668 | e5c9a13e | balrog | val); |
669 | e5c9a13e | balrog | } |
670 | e5c9a13e | balrog | break;
|
671 | e5c9a13e | balrog | case AC97_PCM_LR_ADC_Rate:
|
672 | e5c9a13e | balrog | if (mixer_load (s, AC97_Extended_Audio_Ctrl_Stat) & EACS_VRA) {
|
673 | e5c9a13e | balrog | mixer_store (s, index, val); |
674 | e5c9a13e | balrog | dolog ("Set front LR ADC rate to %d\n", val);
|
675 | e5c9a13e | balrog | open_voice (s, PI_INDEX, val); |
676 | e5c9a13e | balrog | } |
677 | e5c9a13e | balrog | else {
|
678 | e5c9a13e | balrog | dolog ("Attempt to set LR ADC rate to %d, but VRA is not set\n",
|
679 | e5c9a13e | balrog | val); |
680 | e5c9a13e | balrog | } |
681 | e5c9a13e | balrog | break;
|
682 | e5c9a13e | balrog | default:
|
683 | e5c9a13e | balrog | dolog ("U nam writew %#x <- %#x\n", addr, val);
|
684 | e5c9a13e | balrog | mixer_store (s, index, val); |
685 | e5c9a13e | balrog | break;
|
686 | e5c9a13e | balrog | } |
687 | e5c9a13e | balrog | } |
688 | e5c9a13e | balrog | |
689 | e5c9a13e | balrog | static void nam_writel (void *opaque, uint32_t addr, uint32_t val) |
690 | e5c9a13e | balrog | { |
691 | e5c9a13e | balrog | PCIAC97LinkState *d = opaque; |
692 | e5c9a13e | balrog | AC97LinkState *s = &d->ac97; |
693 | e5c9a13e | balrog | dolog ("U nam writel %#x <- %#x\n", addr, val);
|
694 | e5c9a13e | balrog | s->cas = 0;
|
695 | e5c9a13e | balrog | } |
696 | e5c9a13e | balrog | |
697 | e5c9a13e | balrog | /**
|
698 | e5c9a13e | balrog | * Native audio bus master
|
699 | e5c9a13e | balrog | * I/O Reads
|
700 | e5c9a13e | balrog | */
|
701 | e5c9a13e | balrog | static uint32_t nabm_readb (void *opaque, uint32_t addr) |
702 | e5c9a13e | balrog | { |
703 | e5c9a13e | balrog | PCIAC97LinkState *d = opaque; |
704 | e5c9a13e | balrog | AC97LinkState *s = &d->ac97; |
705 | e5c9a13e | balrog | AC97BusMasterRegs *r = NULL;
|
706 | e5c9a13e | balrog | uint32_t index = addr - s->base[1];
|
707 | e5c9a13e | balrog | uint32_t val = ~0U;
|
708 | e5c9a13e | balrog | |
709 | e5c9a13e | balrog | switch (index) {
|
710 | e5c9a13e | balrog | case CAS:
|
711 | e5c9a13e | balrog | dolog ("CAS %d\n", s->cas);
|
712 | e5c9a13e | balrog | val = s->cas; |
713 | e5c9a13e | balrog | s->cas = 1;
|
714 | e5c9a13e | balrog | break;
|
715 | e5c9a13e | balrog | case PI_CIV:
|
716 | e5c9a13e | balrog | case PO_CIV:
|
717 | e5c9a13e | balrog | case MC_CIV:
|
718 | e5c9a13e | balrog | r = &s->bm_regs[GET_BM (index)]; |
719 | e5c9a13e | balrog | val = r->civ; |
720 | e5c9a13e | balrog | dolog ("CIV[%d] -> %#x\n", GET_BM (index), val);
|
721 | e5c9a13e | balrog | break;
|
722 | e5c9a13e | balrog | case PI_LVI:
|
723 | e5c9a13e | balrog | case PO_LVI:
|
724 | e5c9a13e | balrog | case MC_LVI:
|
725 | e5c9a13e | balrog | r = &s->bm_regs[GET_BM (index)]; |
726 | e5c9a13e | balrog | val = r->lvi; |
727 | e5c9a13e | balrog | dolog ("LVI[%d] -> %#x\n", GET_BM (index), val);
|
728 | e5c9a13e | balrog | break;
|
729 | e5c9a13e | balrog | case PI_PIV:
|
730 | e5c9a13e | balrog | case PO_PIV:
|
731 | e5c9a13e | balrog | case MC_PIV:
|
732 | e5c9a13e | balrog | r = &s->bm_regs[GET_BM (index)]; |
733 | e5c9a13e | balrog | val = r->piv; |
734 | e5c9a13e | balrog | dolog ("PIV[%d] -> %#x\n", GET_BM (index), val);
|
735 | e5c9a13e | balrog | break;
|
736 | e5c9a13e | balrog | case PI_CR:
|
737 | e5c9a13e | balrog | case PO_CR:
|
738 | e5c9a13e | balrog | case MC_CR:
|
739 | e5c9a13e | balrog | r = &s->bm_regs[GET_BM (index)]; |
740 | e5c9a13e | balrog | val = r->cr; |
741 | e5c9a13e | balrog | dolog ("CR[%d] -> %#x\n", GET_BM (index), val);
|
742 | e5c9a13e | balrog | break;
|
743 | e5c9a13e | balrog | case PI_SR:
|
744 | e5c9a13e | balrog | case PO_SR:
|
745 | e5c9a13e | balrog | case MC_SR:
|
746 | e5c9a13e | balrog | r = &s->bm_regs[GET_BM (index)]; |
747 | e5c9a13e | balrog | val = r->sr & 0xff;
|
748 | e5c9a13e | balrog | dolog ("SRb[%d] -> %#x\n", GET_BM (index), val);
|
749 | e5c9a13e | balrog | break;
|
750 | e5c9a13e | balrog | default:
|
751 | e5c9a13e | balrog | dolog ("U nabm readb %#x -> %#x\n", addr, val);
|
752 | e5c9a13e | balrog | break;
|
753 | e5c9a13e | balrog | } |
754 | e5c9a13e | balrog | return val;
|
755 | e5c9a13e | balrog | } |
756 | e5c9a13e | balrog | |
757 | e5c9a13e | balrog | static uint32_t nabm_readw (void *opaque, uint32_t addr) |
758 | e5c9a13e | balrog | { |
759 | e5c9a13e | balrog | PCIAC97LinkState *d = opaque; |
760 | e5c9a13e | balrog | AC97LinkState *s = &d->ac97; |
761 | e5c9a13e | balrog | AC97BusMasterRegs *r = NULL;
|
762 | e5c9a13e | balrog | uint32_t index = addr - s->base[1];
|
763 | e5c9a13e | balrog | uint32_t val = ~0U;
|
764 | e5c9a13e | balrog | |
765 | e5c9a13e | balrog | switch (index) {
|
766 | e5c9a13e | balrog | case PI_SR:
|
767 | e5c9a13e | balrog | case PO_SR:
|
768 | e5c9a13e | balrog | case MC_SR:
|
769 | e5c9a13e | balrog | r = &s->bm_regs[GET_BM (index)]; |
770 | e5c9a13e | balrog | val = r->sr; |
771 | e5c9a13e | balrog | dolog ("SR[%d] -> %#x\n", GET_BM (index), val);
|
772 | e5c9a13e | balrog | break;
|
773 | e5c9a13e | balrog | case PI_PICB:
|
774 | e5c9a13e | balrog | case PO_PICB:
|
775 | e5c9a13e | balrog | case MC_PICB:
|
776 | e5c9a13e | balrog | r = &s->bm_regs[GET_BM (index)]; |
777 | e5c9a13e | balrog | val = r->picb; |
778 | e5c9a13e | balrog | dolog ("PICB[%d] -> %#x\n", GET_BM (index), val);
|
779 | e5c9a13e | balrog | break;
|
780 | e5c9a13e | balrog | default:
|
781 | e5c9a13e | balrog | dolog ("U nabm readw %#x -> %#x\n", addr, val);
|
782 | e5c9a13e | balrog | break;
|
783 | e5c9a13e | balrog | } |
784 | e5c9a13e | balrog | return val;
|
785 | e5c9a13e | balrog | } |
786 | e5c9a13e | balrog | |
787 | e5c9a13e | balrog | static uint32_t nabm_readl (void *opaque, uint32_t addr) |
788 | e5c9a13e | balrog | { |
789 | e5c9a13e | balrog | PCIAC97LinkState *d = opaque; |
790 | e5c9a13e | balrog | AC97LinkState *s = &d->ac97; |
791 | e5c9a13e | balrog | AC97BusMasterRegs *r = NULL;
|
792 | e5c9a13e | balrog | uint32_t index = addr - s->base[1];
|
793 | e5c9a13e | balrog | uint32_t val = ~0U;
|
794 | e5c9a13e | balrog | |
795 | e5c9a13e | balrog | switch (index) {
|
796 | e5c9a13e | balrog | case PI_BDBAR:
|
797 | e5c9a13e | balrog | case PO_BDBAR:
|
798 | e5c9a13e | balrog | case MC_BDBAR:
|
799 | e5c9a13e | balrog | r = &s->bm_regs[GET_BM (index)]; |
800 | e5c9a13e | balrog | val = r->bdbar; |
801 | e5c9a13e | balrog | dolog ("BMADDR[%d] -> %#x\n", GET_BM (index), val);
|
802 | e5c9a13e | balrog | break;
|
803 | e5c9a13e | balrog | case PI_CIV:
|
804 | e5c9a13e | balrog | case PO_CIV:
|
805 | e5c9a13e | balrog | case MC_CIV:
|
806 | e5c9a13e | balrog | r = &s->bm_regs[GET_BM (index)]; |
807 | e5c9a13e | balrog | val = r->civ | (r->lvi << 8) | (r->sr << 16); |
808 | e5c9a13e | balrog | dolog ("CIV LVI SR[%d] -> %#x, %#x, %#x\n", GET_BM (index),
|
809 | e5c9a13e | balrog | r->civ, r->lvi, r->sr); |
810 | e5c9a13e | balrog | break;
|
811 | e5c9a13e | balrog | case PI_PICB:
|
812 | e5c9a13e | balrog | case PO_PICB:
|
813 | e5c9a13e | balrog | case MC_PICB:
|
814 | e5c9a13e | balrog | r = &s->bm_regs[GET_BM (index)]; |
815 | e5c9a13e | balrog | val = r->picb | (r->piv << 16) | (r->cr << 24); |
816 | e5c9a13e | balrog | dolog ("PICB PIV CR[%d] -> %#x %#x %#x %#x\n", GET_BM (index),
|
817 | e5c9a13e | balrog | val, r->picb, r->piv, r->cr); |
818 | e5c9a13e | balrog | break;
|
819 | e5c9a13e | balrog | case GLOB_CNT:
|
820 | e5c9a13e | balrog | val = s->glob_cnt; |
821 | e5c9a13e | balrog | dolog ("glob_cnt -> %#x\n", val);
|
822 | e5c9a13e | balrog | break;
|
823 | e5c9a13e | balrog | case GLOB_STA:
|
824 | e5c9a13e | balrog | val = s->glob_sta | GS_S0CR; |
825 | e5c9a13e | balrog | dolog ("glob_sta -> %#x\n", val);
|
826 | e5c9a13e | balrog | break;
|
827 | e5c9a13e | balrog | default:
|
828 | e5c9a13e | balrog | dolog ("U nabm readl %#x -> %#x\n", addr, val);
|
829 | e5c9a13e | balrog | break;
|
830 | e5c9a13e | balrog | } |
831 | e5c9a13e | balrog | return val;
|
832 | e5c9a13e | balrog | } |
833 | e5c9a13e | balrog | |
834 | e5c9a13e | balrog | /**
|
835 | e5c9a13e | balrog | * Native audio bus master
|
836 | e5c9a13e | balrog | * I/O Writes
|
837 | e5c9a13e | balrog | */
|
838 | e5c9a13e | balrog | static void nabm_writeb (void *opaque, uint32_t addr, uint32_t val) |
839 | e5c9a13e | balrog | { |
840 | e5c9a13e | balrog | PCIAC97LinkState *d = opaque; |
841 | e5c9a13e | balrog | AC97LinkState *s = &d->ac97; |
842 | e5c9a13e | balrog | AC97BusMasterRegs *r = NULL;
|
843 | e5c9a13e | balrog | uint32_t index = addr - s->base[1];
|
844 | e5c9a13e | balrog | switch (index) {
|
845 | e5c9a13e | balrog | case PI_LVI:
|
846 | e5c9a13e | balrog | case PO_LVI:
|
847 | e5c9a13e | balrog | case MC_LVI:
|
848 | e5c9a13e | balrog | r = &s->bm_regs[GET_BM (index)]; |
849 | e5c9a13e | balrog | if ((r->cr & CR_RPBM) && (r->sr & SR_DCH)) {
|
850 | e5c9a13e | balrog | r->sr &= ~(SR_DCH | SR_CELV); |
851 | e5c9a13e | balrog | r->civ = r->piv; |
852 | e5c9a13e | balrog | r->piv = (r->piv + 1) % 32; |
853 | e5c9a13e | balrog | fetch_bd (s, r); |
854 | e5c9a13e | balrog | } |
855 | e5c9a13e | balrog | r->lvi = val % 32;
|
856 | e5c9a13e | balrog | dolog ("LVI[%d] <- %#x\n", GET_BM (index), val);
|
857 | e5c9a13e | balrog | break;
|
858 | e5c9a13e | balrog | case PI_CR:
|
859 | e5c9a13e | balrog | case PO_CR:
|
860 | e5c9a13e | balrog | case MC_CR:
|
861 | e5c9a13e | balrog | r = &s->bm_regs[GET_BM (index)]; |
862 | e5c9a13e | balrog | if (val & CR_RR) {
|
863 | e5c9a13e | balrog | reset_bm_regs (s, r); |
864 | e5c9a13e | balrog | } |
865 | e5c9a13e | balrog | else {
|
866 | e5c9a13e | balrog | r->cr = val & CR_VALID_MASK; |
867 | e5c9a13e | balrog | if (!(r->cr & CR_RPBM)) {
|
868 | e5c9a13e | balrog | voice_set_active (s, r - s->bm_regs, 0);
|
869 | e5c9a13e | balrog | r->sr |= SR_DCH; |
870 | e5c9a13e | balrog | } |
871 | e5c9a13e | balrog | else {
|
872 | e5c9a13e | balrog | r->civ = r->piv; |
873 | e5c9a13e | balrog | r->piv = (r->piv + 1) % 32; |
874 | e5c9a13e | balrog | fetch_bd (s, r); |
875 | e5c9a13e | balrog | r->sr &= ~SR_DCH; |
876 | e5c9a13e | balrog | voice_set_active (s, r - s->bm_regs, 1);
|
877 | e5c9a13e | balrog | } |
878 | e5c9a13e | balrog | } |
879 | e5c9a13e | balrog | dolog ("CR[%d] <- %#x (cr %#x)\n", GET_BM (index), val, r->cr);
|
880 | e5c9a13e | balrog | break;
|
881 | e5c9a13e | balrog | case PI_SR:
|
882 | e5c9a13e | balrog | case PO_SR:
|
883 | e5c9a13e | balrog | case MC_SR:
|
884 | e5c9a13e | balrog | r = &s->bm_regs[GET_BM (index)]; |
885 | e5c9a13e | balrog | r->sr |= val & ~(SR_RO_MASK | SR_WCLEAR_MASK); |
886 | e5c9a13e | balrog | update_sr (s, r, r->sr & ~(val & SR_WCLEAR_MASK)); |
887 | e5c9a13e | balrog | dolog ("SR[%d] <- %#x (sr %#x)\n", GET_BM (index), val, r->sr);
|
888 | e5c9a13e | balrog | break;
|
889 | e5c9a13e | balrog | default:
|
890 | e5c9a13e | balrog | dolog ("U nabm writeb %#x <- %#x\n", addr, val);
|
891 | e5c9a13e | balrog | break;
|
892 | e5c9a13e | balrog | } |
893 | e5c9a13e | balrog | } |
894 | e5c9a13e | balrog | |
895 | e5c9a13e | balrog | static void nabm_writew (void *opaque, uint32_t addr, uint32_t val) |
896 | e5c9a13e | balrog | { |
897 | e5c9a13e | balrog | PCIAC97LinkState *d = opaque; |
898 | e5c9a13e | balrog | AC97LinkState *s = &d->ac97; |
899 | e5c9a13e | balrog | AC97BusMasterRegs *r = NULL;
|
900 | e5c9a13e | balrog | uint32_t index = addr - s->base[1];
|
901 | e5c9a13e | balrog | switch (index) {
|
902 | e5c9a13e | balrog | case PI_SR:
|
903 | e5c9a13e | balrog | case PO_SR:
|
904 | e5c9a13e | balrog | case MC_SR:
|
905 | e5c9a13e | balrog | r = &s->bm_regs[GET_BM (index)]; |
906 | e5c9a13e | balrog | r->sr |= val & ~(SR_RO_MASK | SR_WCLEAR_MASK); |
907 | e5c9a13e | balrog | update_sr (s, r, r->sr & ~(val & SR_WCLEAR_MASK)); |
908 | e5c9a13e | balrog | dolog ("SR[%d] <- %#x (sr %#x)\n", GET_BM (index), val, r->sr);
|
909 | e5c9a13e | balrog | break;
|
910 | e5c9a13e | balrog | default:
|
911 | e5c9a13e | balrog | dolog ("U nabm writew %#x <- %#x\n", addr, val);
|
912 | e5c9a13e | balrog | break;
|
913 | e5c9a13e | balrog | } |
914 | e5c9a13e | balrog | } |
915 | e5c9a13e | balrog | |
916 | e5c9a13e | balrog | static void nabm_writel (void *opaque, uint32_t addr, uint32_t val) |
917 | e5c9a13e | balrog | { |
918 | e5c9a13e | balrog | PCIAC97LinkState *d = opaque; |
919 | e5c9a13e | balrog | AC97LinkState *s = &d->ac97; |
920 | e5c9a13e | balrog | AC97BusMasterRegs *r = NULL;
|
921 | e5c9a13e | balrog | uint32_t index = addr - s->base[1];
|
922 | e5c9a13e | balrog | switch (index) {
|
923 | e5c9a13e | balrog | case PI_BDBAR:
|
924 | e5c9a13e | balrog | case PO_BDBAR:
|
925 | e5c9a13e | balrog | case MC_BDBAR:
|
926 | e5c9a13e | balrog | r = &s->bm_regs[GET_BM (index)]; |
927 | e5c9a13e | balrog | r->bdbar = val & ~3;
|
928 | e5c9a13e | balrog | dolog ("BDBAR[%d] <- %#x (bdbar %#x)\n",
|
929 | e5c9a13e | balrog | GET_BM (index), val, r->bdbar); |
930 | e5c9a13e | balrog | break;
|
931 | e5c9a13e | balrog | case GLOB_CNT:
|
932 | e5c9a13e | balrog | if (val & GC_WR)
|
933 | e5c9a13e | balrog | warm_reset (s); |
934 | e5c9a13e | balrog | if (val & GC_CR)
|
935 | e5c9a13e | balrog | cold_reset (s); |
936 | e5c9a13e | balrog | if (!(val & (GC_WR | GC_CR)))
|
937 | e5c9a13e | balrog | s->glob_cnt = val & GC_VALID_MASK; |
938 | e5c9a13e | balrog | dolog ("glob_cnt <- %#x (glob_cnt %#x)\n", val, s->glob_cnt);
|
939 | e5c9a13e | balrog | break;
|
940 | e5c9a13e | balrog | case GLOB_STA:
|
941 | e5c9a13e | balrog | s->glob_sta &= ~(val & GS_WCLEAR_MASK); |
942 | e5c9a13e | balrog | s->glob_sta |= (val & ~(GS_WCLEAR_MASK | GS_RO_MASK)) & GS_VALID_MASK; |
943 | e5c9a13e | balrog | dolog ("glob_sta <- %#x (glob_sta %#x)\n", val, s->glob_sta);
|
944 | e5c9a13e | balrog | break;
|
945 | e5c9a13e | balrog | default:
|
946 | e5c9a13e | balrog | dolog ("U nabm writel %#x <- %#x\n", addr, val);
|
947 | e5c9a13e | balrog | break;
|
948 | e5c9a13e | balrog | } |
949 | e5c9a13e | balrog | } |
950 | e5c9a13e | balrog | |
951 | e5c9a13e | balrog | static int write_audio (AC97LinkState *s, AC97BusMasterRegs *r, |
952 | e5c9a13e | balrog | int max, int *stop) |
953 | e5c9a13e | balrog | { |
954 | e5c9a13e | balrog | uint8_t tmpbuf[4096];
|
955 | e5c9a13e | balrog | uint32_t addr = r->bd.addr; |
956 | e5c9a13e | balrog | uint32_t temp = r->picb << 1;
|
957 | e5c9a13e | balrog | uint32_t written = 0;
|
958 | e5c9a13e | balrog | int to_copy = 0; |
959 | e5c9a13e | balrog | temp = audio_MIN (temp, max); |
960 | e5c9a13e | balrog | |
961 | e5c9a13e | balrog | if (!temp) {
|
962 | e5c9a13e | balrog | *stop = 1;
|
963 | e5c9a13e | balrog | return 0; |
964 | e5c9a13e | balrog | } |
965 | e5c9a13e | balrog | |
966 | e5c9a13e | balrog | while (temp) {
|
967 | e5c9a13e | balrog | int copied;
|
968 | e5c9a13e | balrog | to_copy = audio_MIN (temp, sizeof (tmpbuf));
|
969 | e5c9a13e | balrog | cpu_physical_memory_read (addr, tmpbuf, to_copy); |
970 | e5c9a13e | balrog | copied = AUD_write (s->voice_po, tmpbuf, to_copy); |
971 | e5c9a13e | balrog | dolog ("write_audio max=%x to_copy=%x copied=%x\n",
|
972 | e5c9a13e | balrog | max, to_copy, copied); |
973 | e5c9a13e | balrog | if (!copied) {
|
974 | e5c9a13e | balrog | *stop = 1;
|
975 | e5c9a13e | balrog | break;
|
976 | e5c9a13e | balrog | } |
977 | e5c9a13e | balrog | temp -= copied; |
978 | e5c9a13e | balrog | addr += copied; |
979 | e5c9a13e | balrog | written += copied; |
980 | e5c9a13e | balrog | } |
981 | e5c9a13e | balrog | |
982 | e5c9a13e | balrog | if (!temp) {
|
983 | e5c9a13e | balrog | if (to_copy < 4) { |
984 | e5c9a13e | balrog | dolog ("whoops\n");
|
985 | e5c9a13e | balrog | s->last_samp = 0;
|
986 | e5c9a13e | balrog | } |
987 | e5c9a13e | balrog | else {
|
988 | e5c9a13e | balrog | s->last_samp = *(uint32_t *) &tmpbuf[to_copy - 4];
|
989 | e5c9a13e | balrog | } |
990 | e5c9a13e | balrog | } |
991 | e5c9a13e | balrog | |
992 | e5c9a13e | balrog | r->bd.addr = addr; |
993 | e5c9a13e | balrog | return written;
|
994 | e5c9a13e | balrog | } |
995 | e5c9a13e | balrog | |
996 | e5c9a13e | balrog | static void write_bup (AC97LinkState *s, int elapsed) |
997 | e5c9a13e | balrog | { |
998 | e5c9a13e | balrog | int written = 0; |
999 | e5c9a13e | balrog | |
1000 | e5c9a13e | balrog | dolog ("write_bup\n");
|
1001 | e5c9a13e | balrog | if (!(s->bup_flag & BUP_SET)) {
|
1002 | e5c9a13e | balrog | if (s->bup_flag & BUP_LAST) {
|
1003 | e5c9a13e | balrog | int i;
|
1004 | e5c9a13e | balrog | uint8_t *p = s->silence; |
1005 | e5c9a13e | balrog | for (i = 0; i < sizeof (s->silence) / 4; i++, p += 4) { |
1006 | e5c9a13e | balrog | *(uint32_t *) p = s->last_samp; |
1007 | e5c9a13e | balrog | } |
1008 | e5c9a13e | balrog | } |
1009 | e5c9a13e | balrog | else {
|
1010 | e5c9a13e | balrog | memset (s->silence, 0, sizeof (s->silence)); |
1011 | e5c9a13e | balrog | } |
1012 | e5c9a13e | balrog | s->bup_flag |= BUP_SET; |
1013 | e5c9a13e | balrog | } |
1014 | e5c9a13e | balrog | |
1015 | e5c9a13e | balrog | while (elapsed) {
|
1016 | e5c9a13e | balrog | int temp = audio_MIN (elapsed, sizeof (s->silence)); |
1017 | e5c9a13e | balrog | while (temp) {
|
1018 | e5c9a13e | balrog | int copied = AUD_write (s->voice_po, s->silence, temp);
|
1019 | e5c9a13e | balrog | if (!copied)
|
1020 | e5c9a13e | balrog | return;
|
1021 | e5c9a13e | balrog | temp -= copied; |
1022 | e5c9a13e | balrog | elapsed -= copied; |
1023 | e5c9a13e | balrog | written += copied; |
1024 | e5c9a13e | balrog | } |
1025 | e5c9a13e | balrog | } |
1026 | e5c9a13e | balrog | } |
1027 | e5c9a13e | balrog | |
1028 | e5c9a13e | balrog | static int read_audio (AC97LinkState *s, AC97BusMasterRegs *r, |
1029 | e5c9a13e | balrog | int max, int *stop) |
1030 | e5c9a13e | balrog | { |
1031 | e5c9a13e | balrog | uint8_t tmpbuf[4096];
|
1032 | e5c9a13e | balrog | uint32_t addr = r->bd.addr; |
1033 | e5c9a13e | balrog | uint32_t temp = r->picb << 1;
|
1034 | e5c9a13e | balrog | uint32_t nread = 0;
|
1035 | e5c9a13e | balrog | int to_copy = 0; |
1036 | e5c9a13e | balrog | SWVoiceIn *voice = (r - s->bm_regs) == MC_INDEX ? s->voice_mc : s->voice_pi; |
1037 | e5c9a13e | balrog | |
1038 | e5c9a13e | balrog | temp = audio_MIN (temp, max); |
1039 | e5c9a13e | balrog | |
1040 | e5c9a13e | balrog | if (!temp) {
|
1041 | e5c9a13e | balrog | *stop = 1;
|
1042 | e5c9a13e | balrog | return 0; |
1043 | e5c9a13e | balrog | } |
1044 | e5c9a13e | balrog | |
1045 | e5c9a13e | balrog | while (temp) {
|
1046 | e5c9a13e | balrog | int acquired;
|
1047 | e5c9a13e | balrog | to_copy = audio_MIN (temp, sizeof (tmpbuf));
|
1048 | e5c9a13e | balrog | acquired = AUD_read (voice, tmpbuf, to_copy); |
1049 | e5c9a13e | balrog | if (!acquired) {
|
1050 | e5c9a13e | balrog | *stop = 1;
|
1051 | e5c9a13e | balrog | break;
|
1052 | e5c9a13e | balrog | } |
1053 | e5c9a13e | balrog | cpu_physical_memory_write (addr, tmpbuf, acquired); |
1054 | e5c9a13e | balrog | temp -= acquired; |
1055 | e5c9a13e | balrog | addr += acquired; |
1056 | e5c9a13e | balrog | nread += acquired; |
1057 | e5c9a13e | balrog | } |
1058 | e5c9a13e | balrog | |
1059 | e5c9a13e | balrog | r->bd.addr = addr; |
1060 | e5c9a13e | balrog | return nread;
|
1061 | e5c9a13e | balrog | } |
1062 | e5c9a13e | balrog | |
1063 | e5c9a13e | balrog | static void transfer_audio (AC97LinkState *s, int index, int elapsed) |
1064 | e5c9a13e | balrog | { |
1065 | e5c9a13e | balrog | AC97BusMasterRegs *r = &s->bm_regs[index]; |
1066 | e5c9a13e | balrog | int written = 0, stop = 0; |
1067 | e5c9a13e | balrog | |
1068 | e5c9a13e | balrog | if (r->sr & SR_DCH) {
|
1069 | e5c9a13e | balrog | if (r->cr & CR_RPBM) {
|
1070 | e5c9a13e | balrog | switch (index) {
|
1071 | e5c9a13e | balrog | case PO_INDEX:
|
1072 | e5c9a13e | balrog | write_bup (s, elapsed); |
1073 | e5c9a13e | balrog | break;
|
1074 | e5c9a13e | balrog | } |
1075 | e5c9a13e | balrog | } |
1076 | e5c9a13e | balrog | return;
|
1077 | e5c9a13e | balrog | } |
1078 | e5c9a13e | balrog | |
1079 | e5c9a13e | balrog | while ((elapsed >> 1) && !stop) { |
1080 | e5c9a13e | balrog | int temp;
|
1081 | e5c9a13e | balrog | |
1082 | e5c9a13e | balrog | if (!r->bd_valid) {
|
1083 | e5c9a13e | balrog | dolog ("invalid bd\n");
|
1084 | e5c9a13e | balrog | fetch_bd (s, r); |
1085 | e5c9a13e | balrog | } |
1086 | e5c9a13e | balrog | |
1087 | e5c9a13e | balrog | if (!r->picb) {
|
1088 | e5c9a13e | balrog | dolog ("fresh bd %d is empty %#x %#x\n",
|
1089 | e5c9a13e | balrog | r->civ, r->bd.addr, r->bd.ctl_len); |
1090 | e5c9a13e | balrog | if (r->civ == r->lvi) {
|
1091 | e5c9a13e | balrog | r->sr |= SR_DCH; /* CELV? */
|
1092 | e5c9a13e | balrog | s->bup_flag = 0;
|
1093 | e5c9a13e | balrog | break;
|
1094 | e5c9a13e | balrog | } |
1095 | e5c9a13e | balrog | r->sr &= ~SR_CELV; |
1096 | e5c9a13e | balrog | r->civ = r->piv; |
1097 | e5c9a13e | balrog | r->piv = (r->piv + 1) % 32; |
1098 | e5c9a13e | balrog | fetch_bd (s, r); |
1099 | e5c9a13e | balrog | return;
|
1100 | e5c9a13e | balrog | } |
1101 | e5c9a13e | balrog | |
1102 | e5c9a13e | balrog | switch (index) {
|
1103 | e5c9a13e | balrog | case PO_INDEX:
|
1104 | e5c9a13e | balrog | temp = write_audio (s, r, elapsed, &stop); |
1105 | e5c9a13e | balrog | written += temp; |
1106 | e5c9a13e | balrog | elapsed -= temp; |
1107 | e5c9a13e | balrog | r->picb -= (temp >> 1);
|
1108 | e5c9a13e | balrog | break;
|
1109 | e5c9a13e | balrog | |
1110 | e5c9a13e | balrog | case PI_INDEX:
|
1111 | e5c9a13e | balrog | case MC_INDEX:
|
1112 | e5c9a13e | balrog | temp = read_audio (s, r, elapsed, &stop); |
1113 | e5c9a13e | balrog | elapsed -= temp; |
1114 | e5c9a13e | balrog | r->picb -= (temp >> 1);
|
1115 | e5c9a13e | balrog | break;
|
1116 | e5c9a13e | balrog | } |
1117 | e5c9a13e | balrog | |
1118 | e5c9a13e | balrog | if (!r->picb) {
|
1119 | e5c9a13e | balrog | uint32_t new_sr = r->sr & ~SR_CELV; |
1120 | e5c9a13e | balrog | |
1121 | e5c9a13e | balrog | if (r->bd.ctl_len & BD_IOC) {
|
1122 | e5c9a13e | balrog | new_sr |= SR_BCIS; |
1123 | e5c9a13e | balrog | } |
1124 | e5c9a13e | balrog | |
1125 | e5c9a13e | balrog | if (r->civ == r->lvi) {
|
1126 | e5c9a13e | balrog | dolog ("Underrun civ (%d) == lvi (%d)\n", r->civ, r->lvi);
|
1127 | e5c9a13e | balrog | |
1128 | e5c9a13e | balrog | new_sr |= SR_LVBCI | SR_DCH | SR_CELV; |
1129 | e5c9a13e | balrog | stop = 1;
|
1130 | e5c9a13e | balrog | s->bup_flag = (r->bd.ctl_len & BD_BUP) ? BUP_LAST : 0;
|
1131 | e5c9a13e | balrog | } |
1132 | e5c9a13e | balrog | else {
|
1133 | e5c9a13e | balrog | r->civ = r->piv; |
1134 | e5c9a13e | balrog | r->piv = (r->piv + 1) % 32; |
1135 | e5c9a13e | balrog | fetch_bd (s, r); |
1136 | e5c9a13e | balrog | } |
1137 | e5c9a13e | balrog | |
1138 | e5c9a13e | balrog | update_sr (s, r, new_sr); |
1139 | e5c9a13e | balrog | } |
1140 | e5c9a13e | balrog | } |
1141 | e5c9a13e | balrog | } |
1142 | e5c9a13e | balrog | |
1143 | e5c9a13e | balrog | static void pi_callback (void *opaque, int avail) |
1144 | e5c9a13e | balrog | { |
1145 | e5c9a13e | balrog | transfer_audio (opaque, PI_INDEX, avail); |
1146 | e5c9a13e | balrog | } |
1147 | e5c9a13e | balrog | |
1148 | e5c9a13e | balrog | static void mc_callback (void *opaque, int avail) |
1149 | e5c9a13e | balrog | { |
1150 | e5c9a13e | balrog | transfer_audio (opaque, MC_INDEX, avail); |
1151 | e5c9a13e | balrog | } |
1152 | e5c9a13e | balrog | |
1153 | e5c9a13e | balrog | static void po_callback (void *opaque, int free) |
1154 | e5c9a13e | balrog | { |
1155 | e5c9a13e | balrog | transfer_audio (opaque, PO_INDEX, free); |
1156 | e5c9a13e | balrog | } |
1157 | e5c9a13e | balrog | |
1158 | e5c9a13e | balrog | static void ac97_save (QEMUFile *f, void *opaque) |
1159 | e5c9a13e | balrog | { |
1160 | e5c9a13e | balrog | size_t i; |
1161 | e5c9a13e | balrog | uint8_t active[LAST_INDEX]; |
1162 | e5c9a13e | balrog | AC97LinkState *s = opaque; |
1163 | e5c9a13e | balrog | |
1164 | e5c9a13e | balrog | qemu_put_be32s (f, &s->glob_cnt); |
1165 | e5c9a13e | balrog | qemu_put_be32s (f, &s->glob_sta); |
1166 | e5c9a13e | balrog | qemu_put_be32s (f, &s->cas); |
1167 | e5c9a13e | balrog | |
1168 | e5c9a13e | balrog | for (i = 0; i < sizeof (s->bm_regs) / sizeof (s->bm_regs[0]); ++i) { |
1169 | e5c9a13e | balrog | AC97BusMasterRegs *r = &s->bm_regs[i]; |
1170 | e5c9a13e | balrog | qemu_put_be32s (f, &r->bdbar); |
1171 | e5c9a13e | balrog | qemu_put_8s (f, &r->civ); |
1172 | e5c9a13e | balrog | qemu_put_8s (f, &r->lvi); |
1173 | e5c9a13e | balrog | qemu_put_be16s (f, &r->sr); |
1174 | e5c9a13e | balrog | qemu_put_be16s (f, &r->picb); |
1175 | e5c9a13e | balrog | qemu_put_8s (f, &r->piv); |
1176 | e5c9a13e | balrog | qemu_put_8s (f, &r->cr); |
1177 | e5c9a13e | balrog | qemu_put_be32s (f, &r->bd_valid); |
1178 | e5c9a13e | balrog | qemu_put_be32s (f, &r->bd.addr); |
1179 | e5c9a13e | balrog | qemu_put_be32s (f, &r->bd.ctl_len); |
1180 | e5c9a13e | balrog | } |
1181 | e5c9a13e | balrog | qemu_put_buffer (f, s->mixer_data, sizeof (s->mixer_data));
|
1182 | e5c9a13e | balrog | |
1183 | e5c9a13e | balrog | active[PI_INDEX] = AUD_is_active_in (s->voice_pi) ? 1 : 0; |
1184 | e5c9a13e | balrog | active[PO_INDEX] = AUD_is_active_out (s->voice_po) ? 1 : 0; |
1185 | e5c9a13e | balrog | active[MC_INDEX] = AUD_is_active_in (s->voice_mc) ? 1 : 0; |
1186 | e5c9a13e | balrog | qemu_put_buffer (f, active, sizeof (active));
|
1187 | e5c9a13e | balrog | } |
1188 | e5c9a13e | balrog | |
1189 | e5c9a13e | balrog | static int ac97_load (QEMUFile *f, void *opaque, int version_id) |
1190 | e5c9a13e | balrog | { |
1191 | e5c9a13e | balrog | size_t i; |
1192 | e5c9a13e | balrog | uint8_t active[LAST_INDEX]; |
1193 | e5c9a13e | balrog | AC97LinkState *s = opaque; |
1194 | e5c9a13e | balrog | |
1195 | e5c9a13e | balrog | if (version_id != 1) |
1196 | e5c9a13e | balrog | return -EINVAL;
|
1197 | e5c9a13e | balrog | |
1198 | e5c9a13e | balrog | qemu_get_be32s (f, &s->glob_cnt); |
1199 | e5c9a13e | balrog | qemu_get_be32s (f, &s->glob_sta); |
1200 | e5c9a13e | balrog | qemu_get_be32s (f, &s->cas); |
1201 | e5c9a13e | balrog | |
1202 | e5c9a13e | balrog | for (i = 0; i < sizeof (s->bm_regs) / sizeof (s->bm_regs[0]); ++i) { |
1203 | e5c9a13e | balrog | AC97BusMasterRegs *r = &s->bm_regs[i]; |
1204 | e5c9a13e | balrog | qemu_get_be32s (f, &r->bdbar); |
1205 | e5c9a13e | balrog | qemu_get_8s (f, &r->civ); |
1206 | e5c9a13e | balrog | qemu_get_8s (f, &r->lvi); |
1207 | e5c9a13e | balrog | qemu_get_be16s (f, &r->sr); |
1208 | e5c9a13e | balrog | qemu_get_be16s (f, &r->picb); |
1209 | e5c9a13e | balrog | qemu_get_8s (f, &r->piv); |
1210 | e5c9a13e | balrog | qemu_get_8s (f, &r->cr); |
1211 | e5c9a13e | balrog | qemu_get_be32s (f, &r->bd_valid); |
1212 | e5c9a13e | balrog | qemu_get_be32s (f, &r->bd.addr); |
1213 | e5c9a13e | balrog | qemu_get_be32s (f, &r->bd.ctl_len); |
1214 | e5c9a13e | balrog | } |
1215 | e5c9a13e | balrog | qemu_get_buffer (f, s->mixer_data, sizeof (s->mixer_data));
|
1216 | e5c9a13e | balrog | qemu_get_buffer (f, active, sizeof (active));
|
1217 | e5c9a13e | balrog | |
1218 | e5c9a13e | balrog | #ifdef USE_MIXER
|
1219 | e5c9a13e | balrog | record_select (s, mixer_load (s, AC97_Record_Select)); |
1220 | e5c9a13e | balrog | #define V_(a, b) set_volume (s, a, b, mixer_load (s, a))
|
1221 | e5c9a13e | balrog | V_ (AC97_Master_Volume_Mute, AUD_MIXER_VOLUME); |
1222 | e5c9a13e | balrog | V_ (AC97_PCM_Out_Volume_Mute, AUD_MIXER_PCM); |
1223 | e5c9a13e | balrog | V_ (AC97_Line_In_Volume_Mute, AUD_MIXER_LINE_IN); |
1224 | e5c9a13e | balrog | #undef V_
|
1225 | e5c9a13e | balrog | #endif
|
1226 | e5c9a13e | balrog | reset_voices (s, active); |
1227 | e5c9a13e | balrog | |
1228 | e5c9a13e | balrog | s->bup_flag = 0;
|
1229 | e5c9a13e | balrog | s->last_samp = 0;
|
1230 | e5c9a13e | balrog | return 0; |
1231 | e5c9a13e | balrog | } |
1232 | e5c9a13e | balrog | |
1233 | e5c9a13e | balrog | static void ac97_map (PCIDevice *pci_dev, int region_num, |
1234 | e5c9a13e | balrog | uint32_t addr, uint32_t size, int type)
|
1235 | e5c9a13e | balrog | { |
1236 | e5c9a13e | balrog | PCIAC97LinkState *d = (PCIAC97LinkState *) pci_dev; |
1237 | e5c9a13e | balrog | AC97LinkState *s = &d->ac97; |
1238 | e5c9a13e | balrog | |
1239 | e5c9a13e | balrog | if (!region_num) {
|
1240 | e5c9a13e | balrog | s->base[0] = addr;
|
1241 | e5c9a13e | balrog | register_ioport_read (addr, 256 * 1, 1, nam_readb, d); |
1242 | e5c9a13e | balrog | register_ioport_read (addr, 256 * 2, 2, nam_readw, d); |
1243 | e5c9a13e | balrog | register_ioport_read (addr, 256 * 4, 4, nam_readl, d); |
1244 | e5c9a13e | balrog | register_ioport_write (addr, 256 * 1, 1, nam_writeb, d); |
1245 | e5c9a13e | balrog | register_ioport_write (addr, 256 * 2, 2, nam_writew, d); |
1246 | e5c9a13e | balrog | register_ioport_write (addr, 256 * 4, 4, nam_writel, d); |
1247 | e5c9a13e | balrog | } |
1248 | e5c9a13e | balrog | else {
|
1249 | e5c9a13e | balrog | s->base[1] = addr;
|
1250 | e5c9a13e | balrog | register_ioport_read (addr, 64 * 1, 1, nabm_readb, d); |
1251 | e5c9a13e | balrog | register_ioport_read (addr, 64 * 2, 2, nabm_readw, d); |
1252 | e5c9a13e | balrog | register_ioport_read (addr, 64 * 4, 4, nabm_readl, d); |
1253 | e5c9a13e | balrog | register_ioport_write (addr, 64 * 1, 1, nabm_writeb, d); |
1254 | e5c9a13e | balrog | register_ioport_write (addr, 64 * 2, 2, nabm_writew, d); |
1255 | e5c9a13e | balrog | register_ioport_write (addr, 64 * 4, 4, nabm_writel, d); |
1256 | e5c9a13e | balrog | } |
1257 | e5c9a13e | balrog | } |
1258 | e5c9a13e | balrog | |
1259 | e5c9a13e | balrog | static void ac97_on_reset (void *opaque) |
1260 | e5c9a13e | balrog | { |
1261 | e5c9a13e | balrog | AC97LinkState *s = opaque; |
1262 | e5c9a13e | balrog | |
1263 | e5c9a13e | balrog | reset_bm_regs (s, &s->bm_regs[0]);
|
1264 | e5c9a13e | balrog | reset_bm_regs (s, &s->bm_regs[1]);
|
1265 | e5c9a13e | balrog | reset_bm_regs (s, &s->bm_regs[2]);
|
1266 | e5c9a13e | balrog | |
1267 | e5c9a13e | balrog | /*
|
1268 | e5c9a13e | balrog | * Reset the mixer too. The Windows XP driver seems to rely on
|
1269 | e5c9a13e | balrog | * this. At least it wants to read the vendor id before it resets
|
1270 | e5c9a13e | balrog | * the codec manually.
|
1271 | e5c9a13e | balrog | */
|
1272 | e5c9a13e | balrog | mixer_reset (s); |
1273 | e5c9a13e | balrog | } |
1274 | e5c9a13e | balrog | |
1275 | e5c9a13e | balrog | int ac97_init (PCIBus *bus, AudioState *audio)
|
1276 | e5c9a13e | balrog | { |
1277 | e5c9a13e | balrog | PCIAC97LinkState *d; |
1278 | e5c9a13e | balrog | AC97LinkState *s; |
1279 | e5c9a13e | balrog | uint8_t *c; |
1280 | e5c9a13e | balrog | |
1281 | e5c9a13e | balrog | if (!bus) {
|
1282 | e5c9a13e | balrog | AUD_log ("ac97", "No PCI bus\n"); |
1283 | e5c9a13e | balrog | return -1; |
1284 | e5c9a13e | balrog | } |
1285 | e5c9a13e | balrog | |
1286 | e5c9a13e | balrog | if (!audio) {
|
1287 | e5c9a13e | balrog | AUD_log ("ac97", "No audio state\n"); |
1288 | e5c9a13e | balrog | return -1; |
1289 | e5c9a13e | balrog | } |
1290 | e5c9a13e | balrog | |
1291 | e5c9a13e | balrog | d = (PCIAC97LinkState *) pci_register_device (bus, "AC97",
|
1292 | e5c9a13e | balrog | sizeof (PCIAC97LinkState),
|
1293 | e5c9a13e | balrog | -1, NULL, NULL); |
1294 | e5c9a13e | balrog | |
1295 | e5c9a13e | balrog | if (!d) {
|
1296 | e5c9a13e | balrog | AUD_log ("ac97", "Failed to register PCI device\n"); |
1297 | e5c9a13e | balrog | return -1; |
1298 | e5c9a13e | balrog | } |
1299 | e5c9a13e | balrog | |
1300 | e5c9a13e | balrog | s = &d->ac97; |
1301 | e5c9a13e | balrog | s->pci_dev = &d->dev; |
1302 | e5c9a13e | balrog | c = d->dev.config; |
1303 | e5c9a13e | balrog | c[0x00] = 0x86; /* vid vendor id intel ro */ |
1304 | e5c9a13e | balrog | c[0x01] = 0x80; /* intel */ |
1305 | e5c9a13e | balrog | |
1306 | e5c9a13e | balrog | c[0x02] = 0x15; /* did device id 82801 ro */ |
1307 | e5c9a13e | balrog | c[0x03] = 0x24; /* 82801aa */ |
1308 | e5c9a13e | balrog | |
1309 | e5c9a13e | balrog | c[0x04] = 0x00; /* pcicmd pci command rw, ro */ |
1310 | e5c9a13e | balrog | c[0x05] = 0x00; |
1311 | e5c9a13e | balrog | |
1312 | e5c9a13e | balrog | c[0x06] = 0x80; /* pcists pci status rwc, ro */ |
1313 | e5c9a13e | balrog | c[0x07] = 0x02; |
1314 | e5c9a13e | balrog | |
1315 | e5c9a13e | balrog | c[0x08] = 0x01; /* rid revision ro */ |
1316 | e5c9a13e | balrog | c[0x09] = 0x00; /* pi programming interface ro */ |
1317 | e5c9a13e | balrog | c[0x0a] = 0x01; /* scc sub class code ro */ |
1318 | e5c9a13e | balrog | c[0x0b] = 0x04; /* bcc base class code ro */ |
1319 | e5c9a13e | balrog | c[0x0e] = 0x00; /* headtyp header type ro */ |
1320 | e5c9a13e | balrog | |
1321 | e5c9a13e | balrog | c[0x10] = 0x01; /* nabmar native audio mixer base |
1322 | e5c9a13e | balrog | address rw */
|
1323 | e5c9a13e | balrog | c[0x11] = 0x00; |
1324 | e5c9a13e | balrog | c[0x12] = 0x00; |
1325 | e5c9a13e | balrog | c[0x13] = 0x00; |
1326 | e5c9a13e | balrog | |
1327 | e5c9a13e | balrog | c[0x14] = 0x01; /* nabmbar native audio bus mastering |
1328 | e5c9a13e | balrog | base address rw */
|
1329 | e5c9a13e | balrog | c[0x15] = 0x00; |
1330 | e5c9a13e | balrog | c[0x16] = 0x00; |
1331 | e5c9a13e | balrog | c[0x17] = 0x00; |
1332 | e5c9a13e | balrog | |
1333 | e5c9a13e | balrog | c[0x2c] = 0x86; /* svid subsystem vendor id rwo */ |
1334 | e5c9a13e | balrog | c[0x2d] = 0x80; |
1335 | e5c9a13e | balrog | |
1336 | e5c9a13e | balrog | c[0x2e] = 0x00; /* sid subsystem id rwo */ |
1337 | e5c9a13e | balrog | c[0x2f] = 0x00; |
1338 | e5c9a13e | balrog | |
1339 | e5c9a13e | balrog | c[0x3c] = 0x00; /* intr_ln interrupt line rw */ |
1340 | e5c9a13e | balrog | c[0x3d] = 0x01; /* intr_pn interrupt pin ro */ |
1341 | e5c9a13e | balrog | |
1342 | e5c9a13e | balrog | pci_register_io_region (&d->dev, 0, 256 * 4, PCI_ADDRESS_SPACE_IO, ac97_map); |
1343 | e5c9a13e | balrog | pci_register_io_region (&d->dev, 1, 64 * 4, PCI_ADDRESS_SPACE_IO, ac97_map); |
1344 | e5c9a13e | balrog | register_savevm ("ac97", 0, 1, ac97_save, ac97_load, s); |
1345 | e5c9a13e | balrog | qemu_register_reset (ac97_on_reset, s); |
1346 | e5c9a13e | balrog | AUD_register_card (audio, "ac97", &s->card);
|
1347 | e5c9a13e | balrog | ac97_on_reset (s); |
1348 | e5c9a13e | balrog | return 0; |
1349 | e5c9a13e | balrog | } |