root / hw / audio / ac97.c @ a8aec295
History | View | Annotate | Download (39 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 | 6b620ca3 | Paolo Bonzini | *
|
16 | 6b620ca3 | Paolo Bonzini | * Contributions after 2012-01-13 are licensed under the terms of the
|
17 | 6b620ca3 | Paolo Bonzini | * GNU GPL, version 2 or (at your option) any later version.
|
18 | e5c9a13e | balrog | */
|
19 | e5c9a13e | balrog | |
20 | 83c9f4ca | Paolo Bonzini | #include "hw/hw.h" |
21 | 0d09e41a | Paolo Bonzini | #include "hw/audio/audio.h" |
22 | e5c9a13e | balrog | #include "audio/audio.h" |
23 | 83c9f4ca | Paolo Bonzini | #include "hw/pci/pci.h" |
24 | 9c17d615 | Paolo Bonzini | #include "sysemu/dma.h" |
25 | e5c9a13e | balrog | |
26 | e5c9a13e | balrog | enum {
|
27 | e5c9a13e | balrog | AC97_Reset = 0x00,
|
28 | e5c9a13e | balrog | AC97_Master_Volume_Mute = 0x02,
|
29 | e5c9a13e | balrog | AC97_Headphone_Volume_Mute = 0x04,
|
30 | e5c9a13e | balrog | AC97_Master_Volume_Mono_Mute = 0x06,
|
31 | e5c9a13e | balrog | AC97_Master_Tone_RL = 0x08,
|
32 | e5c9a13e | balrog | AC97_PC_BEEP_Volume_Mute = 0x0A,
|
33 | e5c9a13e | balrog | AC97_Phone_Volume_Mute = 0x0C,
|
34 | e5c9a13e | balrog | AC97_Mic_Volume_Mute = 0x0E,
|
35 | e5c9a13e | balrog | AC97_Line_In_Volume_Mute = 0x10,
|
36 | e5c9a13e | balrog | AC97_CD_Volume_Mute = 0x12,
|
37 | e5c9a13e | balrog | AC97_Video_Volume_Mute = 0x14,
|
38 | e5c9a13e | balrog | AC97_Aux_Volume_Mute = 0x16,
|
39 | e5c9a13e | balrog | AC97_PCM_Out_Volume_Mute = 0x18,
|
40 | e5c9a13e | balrog | AC97_Record_Select = 0x1A,
|
41 | e5c9a13e | balrog | AC97_Record_Gain_Mute = 0x1C,
|
42 | e5c9a13e | balrog | AC97_Record_Gain_Mic_Mute = 0x1E,
|
43 | e5c9a13e | balrog | AC97_General_Purpose = 0x20,
|
44 | e5c9a13e | balrog | AC97_3D_Control = 0x22,
|
45 | e5c9a13e | balrog | AC97_AC_97_RESERVED = 0x24,
|
46 | e5c9a13e | balrog | AC97_Powerdown_Ctrl_Stat = 0x26,
|
47 | e5c9a13e | balrog | AC97_Extended_Audio_ID = 0x28,
|
48 | e5c9a13e | balrog | AC97_Extended_Audio_Ctrl_Stat = 0x2A,
|
49 | e5c9a13e | balrog | AC97_PCM_Front_DAC_Rate = 0x2C,
|
50 | e5c9a13e | balrog | AC97_PCM_Surround_DAC_Rate = 0x2E,
|
51 | e5c9a13e | balrog | AC97_PCM_LFE_DAC_Rate = 0x30,
|
52 | e5c9a13e | balrog | AC97_PCM_LR_ADC_Rate = 0x32,
|
53 | e5c9a13e | balrog | AC97_MIC_ADC_Rate = 0x34,
|
54 | e5c9a13e | balrog | AC97_6Ch_Vol_C_LFE_Mute = 0x36,
|
55 | e5c9a13e | balrog | AC97_6Ch_Vol_L_R_Surround_Mute = 0x38,
|
56 | e5c9a13e | balrog | AC97_Vendor_Reserved = 0x58,
|
57 | d044be37 | Hans de Goede | AC97_Sigmatel_Analog = 0x6c, /* We emulate a Sigmatel codec */ |
58 | d044be37 | Hans de Goede | AC97_Sigmatel_Dac2Invert = 0x6e, /* We emulate a Sigmatel codec */ |
59 | e5c9a13e | balrog | AC97_Vendor_ID1 = 0x7c,
|
60 | e5c9a13e | balrog | AC97_Vendor_ID2 = 0x7e
|
61 | e5c9a13e | balrog | }; |
62 | e5c9a13e | balrog | |
63 | e5c9a13e | balrog | #define SOFT_VOLUME
|
64 | e5c9a13e | balrog | #define SR_FIFOE 16 /* rwc */ |
65 | e5c9a13e | balrog | #define SR_BCIS 8 /* rwc */ |
66 | e5c9a13e | balrog | #define SR_LVBCI 4 /* rwc */ |
67 | e5c9a13e | balrog | #define SR_CELV 2 /* ro */ |
68 | e5c9a13e | balrog | #define SR_DCH 1 /* ro */ |
69 | e5c9a13e | balrog | #define SR_VALID_MASK ((1 << 5) - 1) |
70 | e5c9a13e | balrog | #define SR_WCLEAR_MASK (SR_FIFOE | SR_BCIS | SR_LVBCI)
|
71 | e5c9a13e | balrog | #define SR_RO_MASK (SR_DCH | SR_CELV)
|
72 | e5c9a13e | balrog | #define SR_INT_MASK (SR_FIFOE | SR_BCIS | SR_LVBCI)
|
73 | e5c9a13e | balrog | |
74 | e5c9a13e | balrog | #define CR_IOCE 16 /* rw */ |
75 | e5c9a13e | balrog | #define CR_FEIE 8 /* rw */ |
76 | e5c9a13e | balrog | #define CR_LVBIE 4 /* rw */ |
77 | e5c9a13e | balrog | #define CR_RR 2 /* rw */ |
78 | e5c9a13e | balrog | #define CR_RPBM 1 /* rw */ |
79 | e5c9a13e | balrog | #define CR_VALID_MASK ((1 << 5) - 1) |
80 | e5c9a13e | balrog | #define CR_DONT_CLEAR_MASK (CR_IOCE | CR_FEIE | CR_LVBIE)
|
81 | e5c9a13e | balrog | |
82 | e5c9a13e | balrog | #define GC_WR 4 /* rw */ |
83 | e5c9a13e | balrog | #define GC_CR 2 /* rw */ |
84 | e5c9a13e | balrog | #define GC_VALID_MASK ((1 << 6) - 1) |
85 | e5c9a13e | balrog | |
86 | e5c9a13e | balrog | #define GS_MD3 (1<<17) /* rw */ |
87 | e5c9a13e | balrog | #define GS_AD3 (1<<16) /* rw */ |
88 | e5c9a13e | balrog | #define GS_RCS (1<<15) /* rwc */ |
89 | e5c9a13e | balrog | #define GS_B3S12 (1<<14) /* ro */ |
90 | e5c9a13e | balrog | #define GS_B2S12 (1<<13) /* ro */ |
91 | e5c9a13e | balrog | #define GS_B1S12 (1<<12) /* ro */ |
92 | e5c9a13e | balrog | #define GS_S1R1 (1<<11) /* rwc */ |
93 | e5c9a13e | balrog | #define GS_S0R1 (1<<10) /* rwc */ |
94 | e5c9a13e | balrog | #define GS_S1CR (1<<9) /* ro */ |
95 | e5c9a13e | balrog | #define GS_S0CR (1<<8) /* ro */ |
96 | e5c9a13e | balrog | #define GS_MINT (1<<7) /* ro */ |
97 | e5c9a13e | balrog | #define GS_POINT (1<<6) /* ro */ |
98 | e5c9a13e | balrog | #define GS_PIINT (1<<5) /* ro */ |
99 | e5c9a13e | balrog | #define GS_RSRVD ((1<<4)|(1<<3)) |
100 | e5c9a13e | balrog | #define GS_MOINT (1<<2) /* ro */ |
101 | e5c9a13e | balrog | #define GS_MIINT (1<<1) /* ro */ |
102 | e5c9a13e | balrog | #define GS_GSCI 1 /* rwc */ |
103 | e5c9a13e | balrog | #define GS_RO_MASK (GS_B3S12| \
|
104 | e5c9a13e | balrog | GS_B2S12| \ |
105 | e5c9a13e | balrog | GS_B1S12| \ |
106 | e5c9a13e | balrog | GS_S1CR| \ |
107 | e5c9a13e | balrog | GS_S0CR| \ |
108 | e5c9a13e | balrog | GS_MINT| \ |
109 | e5c9a13e | balrog | GS_POINT| \ |
110 | e5c9a13e | balrog | GS_PIINT| \ |
111 | e5c9a13e | balrog | GS_RSRVD| \ |
112 | e5c9a13e | balrog | GS_MOINT| \ |
113 | e5c9a13e | balrog | GS_MIINT) |
114 | e5c9a13e | balrog | #define GS_VALID_MASK ((1 << 18) - 1) |
115 | e5c9a13e | balrog | #define GS_WCLEAR_MASK (GS_RCS|GS_S1R1|GS_S0R1|GS_GSCI)
|
116 | e5c9a13e | balrog | |
117 | e5c9a13e | balrog | #define BD_IOC (1<<31) |
118 | e5c9a13e | balrog | #define BD_BUP (1<<30) |
119 | e5c9a13e | balrog | |
120 | e5c9a13e | balrog | #define EACS_VRA 1 |
121 | e5c9a13e | balrog | #define EACS_VRM 8 |
122 | e5c9a13e | balrog | |
123 | e5c9a13e | balrog | #define MUTE_SHIFT 15 |
124 | e5c9a13e | balrog | |
125 | e5c9a13e | balrog | #define REC_MASK 7 |
126 | e5c9a13e | balrog | enum {
|
127 | e5c9a13e | balrog | REC_MIC = 0,
|
128 | e5c9a13e | balrog | REC_CD, |
129 | e5c9a13e | balrog | REC_VIDEO, |
130 | e5c9a13e | balrog | REC_AUX, |
131 | e5c9a13e | balrog | REC_LINE_IN, |
132 | e5c9a13e | balrog | REC_STEREO_MIX, |
133 | e5c9a13e | balrog | REC_MONO_MIX, |
134 | e5c9a13e | balrog | REC_PHONE |
135 | e5c9a13e | balrog | }; |
136 | e5c9a13e | balrog | |
137 | e5c9a13e | balrog | typedef struct BD { |
138 | e5c9a13e | balrog | uint32_t addr; |
139 | e5c9a13e | balrog | uint32_t ctl_len; |
140 | e5c9a13e | balrog | } BD; |
141 | e5c9a13e | balrog | |
142 | e5c9a13e | balrog | typedef struct AC97BusMasterRegs { |
143 | e5c9a13e | balrog | uint32_t bdbar; /* rw 0 */
|
144 | e5c9a13e | balrog | uint8_t civ; /* ro 0 */
|
145 | e5c9a13e | balrog | uint8_t lvi; /* rw 0 */
|
146 | e5c9a13e | balrog | uint16_t sr; /* rw 1 */
|
147 | e5c9a13e | balrog | uint16_t picb; /* ro 0 */
|
148 | e5c9a13e | balrog | uint8_t piv; /* ro 0 */
|
149 | e5c9a13e | balrog | uint8_t cr; /* rw 0 */
|
150 | e5c9a13e | balrog | unsigned int bd_valid; |
151 | e5c9a13e | balrog | BD bd; |
152 | e5c9a13e | balrog | } AC97BusMasterRegs; |
153 | e5c9a13e | balrog | |
154 | e5c9a13e | balrog | typedef struct AC97LinkState { |
155 | 10ee2aaa | Juan Quintela | PCIDevice dev; |
156 | e5c9a13e | balrog | QEMUSoundCard card; |
157 | 25a21c94 | Gerd Hoffmann | uint32_t use_broken_id; |
158 | e5c9a13e | balrog | uint32_t glob_cnt; |
159 | e5c9a13e | balrog | uint32_t glob_sta; |
160 | e5c9a13e | balrog | uint32_t cas; |
161 | e5c9a13e | balrog | uint32_t last_samp; |
162 | e5c9a13e | balrog | AC97BusMasterRegs bm_regs[3];
|
163 | e5c9a13e | balrog | uint8_t mixer_data[256];
|
164 | e5c9a13e | balrog | SWVoiceIn *voice_pi; |
165 | e5c9a13e | balrog | SWVoiceOut *voice_po; |
166 | e5c9a13e | balrog | SWVoiceIn *voice_mc; |
167 | 2c44375d | malc | int invalid_freq[3]; |
168 | e5c9a13e | balrog | uint8_t silence[128];
|
169 | e5c9a13e | balrog | int bup_flag;
|
170 | 83c406d9 | Avi Kivity | MemoryRegion io_nam; |
171 | 83c406d9 | Avi Kivity | MemoryRegion io_nabm; |
172 | e5c9a13e | balrog | } AC97LinkState; |
173 | e5c9a13e | balrog | |
174 | e5c9a13e | balrog | enum {
|
175 | e5c9a13e | balrog | BUP_SET = 1,
|
176 | e5c9a13e | balrog | BUP_LAST = 2
|
177 | e5c9a13e | balrog | }; |
178 | e5c9a13e | balrog | |
179 | e5c9a13e | balrog | #ifdef DEBUG_AC97
|
180 | e5c9a13e | balrog | #define dolog(...) AUD_log ("ac97", __VA_ARGS__) |
181 | e5c9a13e | balrog | #else
|
182 | e5c9a13e | balrog | #define dolog(...)
|
183 | e5c9a13e | balrog | #endif
|
184 | e5c9a13e | balrog | |
185 | e5c9a13e | balrog | #define MKREGS(prefix, start) \
|
186 | e5c9a13e | balrog | enum { \
|
187 | e5c9a13e | balrog | prefix ## _BDBAR = start, \ |
188 | e5c9a13e | balrog | prefix ## _CIV = start + 4, \ |
189 | e5c9a13e | balrog | prefix ## _LVI = start + 5, \ |
190 | e5c9a13e | balrog | prefix ## _SR = start + 6, \ |
191 | e5c9a13e | balrog | prefix ## _PICB = start + 8, \ |
192 | e5c9a13e | balrog | prefix ## _PIV = start + 10, \ |
193 | e5c9a13e | balrog | prefix ## _CR = start + 11 \ |
194 | e5c9a13e | balrog | } |
195 | e5c9a13e | balrog | |
196 | e5c9a13e | balrog | enum {
|
197 | e5c9a13e | balrog | PI_INDEX = 0,
|
198 | e5c9a13e | balrog | PO_INDEX, |
199 | e5c9a13e | balrog | MC_INDEX, |
200 | e5c9a13e | balrog | LAST_INDEX |
201 | e5c9a13e | balrog | }; |
202 | e5c9a13e | balrog | |
203 | e5c9a13e | balrog | MKREGS (PI, PI_INDEX * 16);
|
204 | e5c9a13e | balrog | MKREGS (PO, PO_INDEX * 16);
|
205 | e5c9a13e | balrog | MKREGS (MC, MC_INDEX * 16);
|
206 | e5c9a13e | balrog | |
207 | e5c9a13e | balrog | enum {
|
208 | e5c9a13e | balrog | GLOB_CNT = 0x2c,
|
209 | e5c9a13e | balrog | GLOB_STA = 0x30,
|
210 | e5c9a13e | balrog | CAS = 0x34
|
211 | e5c9a13e | balrog | }; |
212 | e5c9a13e | balrog | |
213 | e5c9a13e | balrog | #define GET_BM(index) (((index) >> 4) & 3) |
214 | e5c9a13e | balrog | |
215 | e5c9a13e | balrog | static void po_callback (void *opaque, int free); |
216 | e5c9a13e | balrog | static void pi_callback (void *opaque, int avail); |
217 | e5c9a13e | balrog | static void mc_callback (void *opaque, int avail); |
218 | e5c9a13e | balrog | |
219 | e5c9a13e | balrog | static void warm_reset (AC97LinkState *s) |
220 | e5c9a13e | balrog | { |
221 | e5c9a13e | balrog | (void) s;
|
222 | e5c9a13e | balrog | } |
223 | e5c9a13e | balrog | |
224 | e5c9a13e | balrog | static void cold_reset (AC97LinkState * s) |
225 | e5c9a13e | balrog | { |
226 | e5c9a13e | balrog | (void) s;
|
227 | e5c9a13e | balrog | } |
228 | e5c9a13e | balrog | |
229 | e5c9a13e | balrog | static void fetch_bd (AC97LinkState *s, AC97BusMasterRegs *r) |
230 | e5c9a13e | balrog | { |
231 | e5c9a13e | balrog | uint8_t b[8];
|
232 | e5c9a13e | balrog | |
233 | 93f43c48 | Eduard - Gabriel Munteanu | pci_dma_read (&s->dev, r->bdbar + r->civ * 8, b, 8); |
234 | e5c9a13e | balrog | r->bd_valid = 1;
|
235 | e5c9a13e | balrog | r->bd.addr = le32_to_cpu (*(uint32_t *) &b[0]) & ~3; |
236 | e5c9a13e | balrog | r->bd.ctl_len = le32_to_cpu (*(uint32_t *) &b[4]);
|
237 | e5c9a13e | balrog | r->picb = r->bd.ctl_len & 0xffff;
|
238 | e5c9a13e | balrog | dolog ("bd %2d addr=%#x ctl=%#06x len=%#x(%d bytes)\n",
|
239 | e5c9a13e | balrog | r->civ, r->bd.addr, r->bd.ctl_len >> 16,
|
240 | e5c9a13e | balrog | r->bd.ctl_len & 0xffff,
|
241 | e5c9a13e | balrog | (r->bd.ctl_len & 0xffff) << 1); |
242 | e5c9a13e | balrog | } |
243 | e5c9a13e | balrog | |
244 | e5c9a13e | balrog | static void update_sr (AC97LinkState *s, AC97BusMasterRegs *r, uint32_t new_sr) |
245 | e5c9a13e | balrog | { |
246 | e5c9a13e | balrog | int event = 0; |
247 | e5c9a13e | balrog | int level = 0; |
248 | e5c9a13e | balrog | uint32_t new_mask = new_sr & SR_INT_MASK; |
249 | e5c9a13e | balrog | uint32_t old_mask = r->sr & SR_INT_MASK; |
250 | e5c9a13e | balrog | uint32_t masks[] = {GS_PIINT, GS_POINT, GS_MINT}; |
251 | e5c9a13e | balrog | |
252 | e5c9a13e | balrog | if (new_mask ^ old_mask) {
|
253 | e5c9a13e | balrog | /** @todo is IRQ deasserted when only one of status bits is cleared? */
|
254 | e5c9a13e | balrog | if (!new_mask) {
|
255 | e5c9a13e | balrog | event = 1;
|
256 | e5c9a13e | balrog | level = 0;
|
257 | e5c9a13e | balrog | } |
258 | e5c9a13e | balrog | else {
|
259 | e5c9a13e | balrog | if ((new_mask & SR_LVBCI) && (r->cr & CR_LVBIE)) {
|
260 | e5c9a13e | balrog | event = 1;
|
261 | e5c9a13e | balrog | level = 1;
|
262 | e5c9a13e | balrog | } |
263 | e5c9a13e | balrog | if ((new_mask & SR_BCIS) && (r->cr & CR_IOCE)) {
|
264 | e5c9a13e | balrog | event = 1;
|
265 | e5c9a13e | balrog | level = 1;
|
266 | e5c9a13e | balrog | } |
267 | e5c9a13e | balrog | } |
268 | e5c9a13e | balrog | } |
269 | e5c9a13e | balrog | |
270 | e5c9a13e | balrog | r->sr = new_sr; |
271 | e5c9a13e | balrog | |
272 | e5c9a13e | balrog | dolog ("IOC%d LVB%d sr=%#x event=%d level=%d\n",
|
273 | e5c9a13e | balrog | r->sr & SR_BCIS, r->sr & SR_LVBCI, |
274 | e5c9a13e | balrog | r->sr, |
275 | e5c9a13e | balrog | event, level); |
276 | e5c9a13e | balrog | |
277 | e5c9a13e | balrog | if (!event)
|
278 | e5c9a13e | balrog | return;
|
279 | e5c9a13e | balrog | |
280 | e5c9a13e | balrog | if (level) {
|
281 | e5c9a13e | balrog | s->glob_sta |= masks[r - s->bm_regs]; |
282 | e5c9a13e | balrog | dolog ("set irq level=1\n");
|
283 | 10ee2aaa | Juan Quintela | qemu_set_irq (s->dev.irq[0], 1); |
284 | e5c9a13e | balrog | } |
285 | e5c9a13e | balrog | else {
|
286 | e5c9a13e | balrog | s->glob_sta &= ~masks[r - s->bm_regs]; |
287 | e5c9a13e | balrog | dolog ("set irq level=0\n");
|
288 | 10ee2aaa | Juan Quintela | qemu_set_irq (s->dev.irq[0], 0); |
289 | e5c9a13e | balrog | } |
290 | e5c9a13e | balrog | } |
291 | e5c9a13e | balrog | |
292 | e5c9a13e | balrog | static void voice_set_active (AC97LinkState *s, int bm_index, int on) |
293 | e5c9a13e | balrog | { |
294 | e5c9a13e | balrog | switch (bm_index) {
|
295 | e5c9a13e | balrog | case PI_INDEX:
|
296 | e5c9a13e | balrog | AUD_set_active_in (s->voice_pi, on); |
297 | e5c9a13e | balrog | break;
|
298 | e5c9a13e | balrog | |
299 | e5c9a13e | balrog | case PO_INDEX:
|
300 | e5c9a13e | balrog | AUD_set_active_out (s->voice_po, on); |
301 | e5c9a13e | balrog | break;
|
302 | e5c9a13e | balrog | |
303 | e5c9a13e | balrog | case MC_INDEX:
|
304 | e5c9a13e | balrog | AUD_set_active_in (s->voice_mc, on); |
305 | e5c9a13e | balrog | break;
|
306 | e5c9a13e | balrog | |
307 | e5c9a13e | balrog | default:
|
308 | e5c9a13e | balrog | AUD_log ("ac97", "invalid bm_index(%d) in voice_set_active", bm_index); |
309 | e5c9a13e | balrog | break;
|
310 | e5c9a13e | balrog | } |
311 | e5c9a13e | balrog | } |
312 | e5c9a13e | balrog | |
313 | e5c9a13e | balrog | static void reset_bm_regs (AC97LinkState *s, AC97BusMasterRegs *r) |
314 | e5c9a13e | balrog | { |
315 | e5c9a13e | balrog | dolog ("reset_bm_regs\n");
|
316 | e5c9a13e | balrog | r->bdbar = 0;
|
317 | e5c9a13e | balrog | r->civ = 0;
|
318 | e5c9a13e | balrog | r->lvi = 0;
|
319 | e5c9a13e | balrog | /** todo do we need to do that? */
|
320 | e5c9a13e | balrog | update_sr (s, r, SR_DCH); |
321 | e5c9a13e | balrog | r->picb = 0;
|
322 | e5c9a13e | balrog | r->piv = 0;
|
323 | e5c9a13e | balrog | r->cr = r->cr & CR_DONT_CLEAR_MASK; |
324 | e5c9a13e | balrog | r->bd_valid = 0;
|
325 | e5c9a13e | balrog | |
326 | e5c9a13e | balrog | voice_set_active (s, r - s->bm_regs, 0);
|
327 | e5c9a13e | balrog | memset (s->silence, 0, sizeof (s->silence)); |
328 | e5c9a13e | balrog | } |
329 | e5c9a13e | balrog | |
330 | e5c9a13e | balrog | static void mixer_store (AC97LinkState *s, uint32_t i, uint16_t v) |
331 | e5c9a13e | balrog | { |
332 | e5c9a13e | balrog | if (i + 2 > sizeof (s->mixer_data)) { |
333 | 0148d177 | Juan Quintela | dolog ("mixer_store: index %d out of bounds %zd\n",
|
334 | e5c9a13e | balrog | i, sizeof (s->mixer_data));
|
335 | e5c9a13e | balrog | return;
|
336 | e5c9a13e | balrog | } |
337 | e5c9a13e | balrog | |
338 | e5c9a13e | balrog | s->mixer_data[i + 0] = v & 0xff; |
339 | e5c9a13e | balrog | s->mixer_data[i + 1] = v >> 8; |
340 | e5c9a13e | balrog | } |
341 | e5c9a13e | balrog | |
342 | e5c9a13e | balrog | static uint16_t mixer_load (AC97LinkState *s, uint32_t i)
|
343 | e5c9a13e | balrog | { |
344 | e5c9a13e | balrog | uint16_t val = 0xffff;
|
345 | e5c9a13e | balrog | |
346 | e5c9a13e | balrog | if (i + 2 > sizeof (s->mixer_data)) { |
347 | a4e652eb | Hans de Goede | dolog ("mixer_load: index %d out of bounds %zd\n",
|
348 | e5c9a13e | balrog | i, sizeof (s->mixer_data));
|
349 | e5c9a13e | balrog | } |
350 | e5c9a13e | balrog | else {
|
351 | e5c9a13e | balrog | val = s->mixer_data[i + 0] | (s->mixer_data[i + 1] << 8); |
352 | e5c9a13e | balrog | } |
353 | e5c9a13e | balrog | |
354 | e5c9a13e | balrog | return val;
|
355 | e5c9a13e | balrog | } |
356 | e5c9a13e | balrog | |
357 | e5c9a13e | balrog | static void open_voice (AC97LinkState *s, int index, int freq) |
358 | e5c9a13e | balrog | { |
359 | 1ea879e5 | malc | struct audsettings as;
|
360 | e5c9a13e | balrog | |
361 | e5c9a13e | balrog | as.freq = freq; |
362 | e5c9a13e | balrog | as.nchannels = 2;
|
363 | e5c9a13e | balrog | as.fmt = AUD_FMT_S16; |
364 | e5c9a13e | balrog | as.endianness = 0;
|
365 | e5c9a13e | balrog | |
366 | 2c44375d | malc | if (freq > 0) { |
367 | 2c44375d | malc | s->invalid_freq[index] = 0;
|
368 | 2c44375d | malc | switch (index) {
|
369 | 2c44375d | malc | case PI_INDEX:
|
370 | 2c44375d | malc | s->voice_pi = AUD_open_in ( |
371 | 2c44375d | malc | &s->card, |
372 | 2c44375d | malc | s->voice_pi, |
373 | 2c44375d | malc | "ac97.pi",
|
374 | 2c44375d | malc | s, |
375 | 2c44375d | malc | pi_callback, |
376 | 2c44375d | malc | &as |
377 | 2c44375d | malc | ); |
378 | 2c44375d | malc | break;
|
379 | e5c9a13e | balrog | |
380 | 2c44375d | malc | case PO_INDEX:
|
381 | 2c44375d | malc | s->voice_po = AUD_open_out ( |
382 | 2c44375d | malc | &s->card, |
383 | 2c44375d | malc | s->voice_po, |
384 | 2c44375d | malc | "ac97.po",
|
385 | 2c44375d | malc | s, |
386 | 2c44375d | malc | po_callback, |
387 | 2c44375d | malc | &as |
388 | 2c44375d | malc | ); |
389 | 2c44375d | malc | break;
|
390 | e5c9a13e | balrog | |
391 | 2c44375d | malc | case MC_INDEX:
|
392 | 2c44375d | malc | s->voice_mc = AUD_open_in ( |
393 | 2c44375d | malc | &s->card, |
394 | 2c44375d | malc | s->voice_mc, |
395 | 2c44375d | malc | "ac97.mc",
|
396 | 2c44375d | malc | s, |
397 | 2c44375d | malc | mc_callback, |
398 | 2c44375d | malc | &as |
399 | 2c44375d | malc | ); |
400 | 2c44375d | malc | break;
|
401 | 2c44375d | malc | } |
402 | 2c44375d | malc | } |
403 | 2c44375d | malc | else {
|
404 | 2c44375d | malc | s->invalid_freq[index] = freq; |
405 | 2c44375d | malc | switch (index) {
|
406 | 2c44375d | malc | case PI_INDEX:
|
407 | 2c44375d | malc | AUD_close_in (&s->card, s->voice_pi); |
408 | 2c44375d | malc | s->voice_pi = NULL;
|
409 | 2c44375d | malc | break;
|
410 | 2c44375d | malc | |
411 | 2c44375d | malc | case PO_INDEX:
|
412 | 2c44375d | malc | AUD_close_out (&s->card, s->voice_po); |
413 | 2c44375d | malc | s->voice_po = NULL;
|
414 | 2c44375d | malc | break;
|
415 | 2c44375d | malc | |
416 | 2c44375d | malc | case MC_INDEX:
|
417 | 2c44375d | malc | AUD_close_in (&s->card, s->voice_mc); |
418 | 2c44375d | malc | s->voice_mc = NULL;
|
419 | 2c44375d | malc | break;
|
420 | 2c44375d | malc | } |
421 | e5c9a13e | balrog | } |
422 | e5c9a13e | balrog | } |
423 | e5c9a13e | balrog | |
424 | e5c9a13e | balrog | static void reset_voices (AC97LinkState *s, uint8_t active[LAST_INDEX]) |
425 | e5c9a13e | balrog | { |
426 | e5c9a13e | balrog | uint16_t freq; |
427 | e5c9a13e | balrog | |
428 | e5c9a13e | balrog | freq = mixer_load (s, AC97_PCM_LR_ADC_Rate); |
429 | e5c9a13e | balrog | open_voice (s, PI_INDEX, freq); |
430 | e5c9a13e | balrog | AUD_set_active_in (s->voice_pi, active[PI_INDEX]); |
431 | e5c9a13e | balrog | |
432 | e5c9a13e | balrog | freq = mixer_load (s, AC97_PCM_Front_DAC_Rate); |
433 | e5c9a13e | balrog | open_voice (s, PO_INDEX, freq); |
434 | e5c9a13e | balrog | AUD_set_active_out (s->voice_po, active[PO_INDEX]); |
435 | e5c9a13e | balrog | |
436 | e5c9a13e | balrog | freq = mixer_load (s, AC97_MIC_ADC_Rate); |
437 | e5c9a13e | balrog | open_voice (s, MC_INDEX, freq); |
438 | e5c9a13e | balrog | AUD_set_active_in (s->voice_mc, active[MC_INDEX]); |
439 | e5c9a13e | balrog | } |
440 | e5c9a13e | balrog | |
441 | 19677a38 | Marc-André Lureau | static void get_volume (uint16_t vol, uint16_t mask, int inverse, |
442 | 19677a38 | Marc-André Lureau | int *mute, uint8_t *lvol, uint8_t *rvol)
|
443 | 19677a38 | Marc-André Lureau | { |
444 | 19677a38 | Marc-André Lureau | *mute = (vol >> MUTE_SHIFT) & 1;
|
445 | 19677a38 | Marc-André Lureau | *rvol = (255 * (vol & mask)) / mask;
|
446 | 19677a38 | Marc-André Lureau | *lvol = (255 * ((vol >> 8) & mask)) / mask; |
447 | 19677a38 | Marc-André Lureau | |
448 | 19677a38 | Marc-André Lureau | if (inverse) {
|
449 | 19677a38 | Marc-André Lureau | *rvol = 255 - *rvol;
|
450 | 19677a38 | Marc-André Lureau | *lvol = 255 - *lvol;
|
451 | 19677a38 | Marc-André Lureau | } |
452 | 19677a38 | Marc-André Lureau | } |
453 | 19677a38 | Marc-André Lureau | |
454 | 19677a38 | Marc-André Lureau | static void update_combined_volume_out (AC97LinkState *s) |
455 | 19677a38 | Marc-André Lureau | { |
456 | 19677a38 | Marc-André Lureau | uint8_t lvol, rvol, plvol, prvol; |
457 | 19677a38 | Marc-André Lureau | int mute, pmute;
|
458 | 19677a38 | Marc-André Lureau | |
459 | 19677a38 | Marc-André Lureau | get_volume (mixer_load (s, AC97_Master_Volume_Mute), 0x3f, 1, |
460 | 19677a38 | Marc-André Lureau | &mute, &lvol, &rvol); |
461 | 7873bfb8 | Hans de Goede | get_volume (mixer_load (s, AC97_PCM_Out_Volume_Mute), 0x1f, 1, |
462 | 19677a38 | Marc-André Lureau | &pmute, &plvol, &prvol); |
463 | 19677a38 | Marc-André Lureau | |
464 | 19677a38 | Marc-André Lureau | mute = mute | pmute; |
465 | 19677a38 | Marc-André Lureau | lvol = (lvol * plvol) / 255;
|
466 | 19677a38 | Marc-André Lureau | rvol = (rvol * prvol) / 255;
|
467 | 19677a38 | Marc-André Lureau | |
468 | 19677a38 | Marc-André Lureau | AUD_set_volume_out (s->voice_po, mute, lvol, rvol); |
469 | 19677a38 | Marc-André Lureau | } |
470 | 19677a38 | Marc-André Lureau | |
471 | 19677a38 | Marc-André Lureau | static void update_volume_in (AC97LinkState *s) |
472 | 19677a38 | Marc-André Lureau | { |
473 | 19677a38 | Marc-André Lureau | uint8_t lvol, rvol; |
474 | 19677a38 | Marc-André Lureau | int mute;
|
475 | 19677a38 | Marc-André Lureau | |
476 | 19677a38 | Marc-André Lureau | get_volume (mixer_load (s, AC97_Record_Gain_Mute), 0x0f, 0, |
477 | 19677a38 | Marc-André Lureau | &mute, &lvol, &rvol); |
478 | 19677a38 | Marc-André Lureau | |
479 | 19677a38 | Marc-André Lureau | AUD_set_volume_in (s->voice_pi, mute, lvol, rvol); |
480 | 19677a38 | Marc-André Lureau | } |
481 | 19677a38 | Marc-André Lureau | |
482 | 19677a38 | Marc-André Lureau | static void set_volume (AC97LinkState *s, int index, uint32_t val) |
483 | 19677a38 | Marc-André Lureau | { |
484 | 7873bfb8 | Hans de Goede | switch (index) {
|
485 | 7873bfb8 | Hans de Goede | case AC97_Master_Volume_Mute:
|
486 | 7873bfb8 | Hans de Goede | val &= 0xbf3f;
|
487 | 7873bfb8 | Hans de Goede | mixer_store (s, index, val); |
488 | 19677a38 | Marc-André Lureau | update_combined_volume_out (s); |
489 | 7873bfb8 | Hans de Goede | break;
|
490 | 7873bfb8 | Hans de Goede | case AC97_PCM_Out_Volume_Mute:
|
491 | 7873bfb8 | Hans de Goede | val &= 0x9f1f;
|
492 | 7873bfb8 | Hans de Goede | mixer_store (s, index, val); |
493 | 7873bfb8 | Hans de Goede | update_combined_volume_out (s); |
494 | 7873bfb8 | Hans de Goede | break;
|
495 | 7873bfb8 | Hans de Goede | case AC97_Record_Gain_Mute:
|
496 | 7873bfb8 | Hans de Goede | val &= 0x8f0f;
|
497 | 7873bfb8 | Hans de Goede | mixer_store (s, index, val); |
498 | 19677a38 | Marc-André Lureau | update_volume_in (s); |
499 | 7873bfb8 | Hans de Goede | break;
|
500 | 19677a38 | Marc-André Lureau | } |
501 | 19677a38 | Marc-André Lureau | } |
502 | 19677a38 | Marc-André Lureau | |
503 | 19677a38 | Marc-André Lureau | static void record_select (AC97LinkState *s, uint32_t val) |
504 | 19677a38 | Marc-André Lureau | { |
505 | 19677a38 | Marc-André Lureau | uint8_t rs = val & REC_MASK; |
506 | 19677a38 | Marc-André Lureau | uint8_t ls = (val >> 8) & REC_MASK;
|
507 | 19677a38 | Marc-André Lureau | mixer_store (s, AC97_Record_Select, rs | (ls << 8));
|
508 | 19677a38 | Marc-André Lureau | } |
509 | 19677a38 | Marc-André Lureau | |
510 | e5c9a13e | balrog | static void mixer_reset (AC97LinkState *s) |
511 | e5c9a13e | balrog | { |
512 | e5c9a13e | balrog | uint8_t active[LAST_INDEX]; |
513 | e5c9a13e | balrog | |
514 | e5c9a13e | balrog | dolog ("mixer_reset\n");
|
515 | e5c9a13e | balrog | memset (s->mixer_data, 0, sizeof (s->mixer_data)); |
516 | e5c9a13e | balrog | memset (active, 0, sizeof (active)); |
517 | e5c9a13e | balrog | mixer_store (s, AC97_Reset , 0x0000); /* 6940 */ |
518 | d044be37 | Hans de Goede | mixer_store (s, AC97_Headphone_Volume_Mute , 0x0000);
|
519 | d044be37 | Hans de Goede | mixer_store (s, AC97_Master_Volume_Mono_Mute , 0x0000);
|
520 | d044be37 | Hans de Goede | mixer_store (s, AC97_Master_Tone_RL, 0x0000);
|
521 | e5c9a13e | balrog | mixer_store (s, AC97_PC_BEEP_Volume_Mute , 0x0000);
|
522 | d044be37 | Hans de Goede | mixer_store (s, AC97_Phone_Volume_Mute , 0x0000);
|
523 | d044be37 | Hans de Goede | mixer_store (s, AC97_Mic_Volume_Mute , 0x0000);
|
524 | f94e9b9b | Hans de Goede | mixer_store (s, AC97_Line_In_Volume_Mute , 0x0000);
|
525 | d044be37 | Hans de Goede | mixer_store (s, AC97_CD_Volume_Mute , 0x0000);
|
526 | d044be37 | Hans de Goede | mixer_store (s, AC97_Video_Volume_Mute , 0x0000);
|
527 | d044be37 | Hans de Goede | mixer_store (s, AC97_Aux_Volume_Mute , 0x0000);
|
528 | d044be37 | Hans de Goede | mixer_store (s, AC97_Record_Gain_Mic_Mute , 0x0000);
|
529 | e5c9a13e | balrog | mixer_store (s, AC97_General_Purpose , 0x0000);
|
530 | e5c9a13e | balrog | mixer_store (s, AC97_3D_Control , 0x0000);
|
531 | e5c9a13e | balrog | mixer_store (s, AC97_Powerdown_Ctrl_Stat , 0x000f);
|
532 | e5c9a13e | balrog | |
533 | e5c9a13e | balrog | /*
|
534 | e5c9a13e | balrog | * Sigmatel 9700 (STAC9700)
|
535 | e5c9a13e | balrog | */
|
536 | e5c9a13e | balrog | mixer_store (s, AC97_Vendor_ID1 , 0x8384);
|
537 | e5c9a13e | balrog | mixer_store (s, AC97_Vendor_ID2 , 0x7600); /* 7608 */ |
538 | e5c9a13e | balrog | |
539 | e5c9a13e | balrog | mixer_store (s, AC97_Extended_Audio_ID , 0x0809);
|
540 | e5c9a13e | balrog | mixer_store (s, AC97_Extended_Audio_Ctrl_Stat, 0x0009);
|
541 | e5c9a13e | balrog | mixer_store (s, AC97_PCM_Front_DAC_Rate , 0xbb80);
|
542 | e5c9a13e | balrog | mixer_store (s, AC97_PCM_Surround_DAC_Rate , 0xbb80);
|
543 | e5c9a13e | balrog | mixer_store (s, AC97_PCM_LFE_DAC_Rate , 0xbb80);
|
544 | e5c9a13e | balrog | mixer_store (s, AC97_PCM_LR_ADC_Rate , 0xbb80);
|
545 | e5c9a13e | balrog | mixer_store (s, AC97_MIC_ADC_Rate , 0xbb80);
|
546 | e5c9a13e | balrog | |
547 | 19677a38 | Marc-André Lureau | record_select (s, 0);
|
548 | 19677a38 | Marc-André Lureau | set_volume (s, AC97_Master_Volume_Mute, 0x8000);
|
549 | 19677a38 | Marc-André Lureau | set_volume (s, AC97_PCM_Out_Volume_Mute, 0x8808);
|
550 | f94e9b9b | Hans de Goede | set_volume (s, AC97_Record_Gain_Mute, 0x8808);
|
551 | 19677a38 | Marc-André Lureau | |
552 | e5c9a13e | balrog | reset_voices (s, active); |
553 | e5c9a13e | balrog | } |
554 | e5c9a13e | balrog | |
555 | e5c9a13e | balrog | /**
|
556 | e5c9a13e | balrog | * Native audio mixer
|
557 | e5c9a13e | balrog | * I/O Reads
|
558 | e5c9a13e | balrog | */
|
559 | e5c9a13e | balrog | static uint32_t nam_readb (void *opaque, uint32_t addr) |
560 | e5c9a13e | balrog | { |
561 | 10ee2aaa | Juan Quintela | AC97LinkState *s = opaque; |
562 | e5c9a13e | balrog | dolog ("U nam readb %#x\n", addr);
|
563 | e5c9a13e | balrog | s->cas = 0;
|
564 | e5c9a13e | balrog | return ~0U; |
565 | e5c9a13e | balrog | } |
566 | e5c9a13e | balrog | |
567 | e5c9a13e | balrog | static uint32_t nam_readw (void *opaque, uint32_t addr) |
568 | e5c9a13e | balrog | { |
569 | 10ee2aaa | Juan Quintela | AC97LinkState *s = opaque; |
570 | e5c9a13e | balrog | uint32_t val = ~0U;
|
571 | 83c406d9 | Avi Kivity | uint32_t index = addr; |
572 | e5c9a13e | balrog | s->cas = 0;
|
573 | e5c9a13e | balrog | val = mixer_load (s, index); |
574 | e5c9a13e | balrog | return val;
|
575 | e5c9a13e | balrog | } |
576 | e5c9a13e | balrog | |
577 | e5c9a13e | balrog | static uint32_t nam_readl (void *opaque, uint32_t addr) |
578 | e5c9a13e | balrog | { |
579 | 10ee2aaa | Juan Quintela | AC97LinkState *s = opaque; |
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 | 10ee2aaa | Juan Quintela | AC97LinkState *s = opaque; |
592 | e5c9a13e | balrog | dolog ("U nam writeb %#x <- %#x\n", addr, val);
|
593 | e5c9a13e | balrog | s->cas = 0;
|
594 | e5c9a13e | balrog | } |
595 | e5c9a13e | balrog | |
596 | e5c9a13e | balrog | static void nam_writew (void *opaque, uint32_t addr, uint32_t val) |
597 | e5c9a13e | balrog | { |
598 | 10ee2aaa | Juan Quintela | AC97LinkState *s = opaque; |
599 | 83c406d9 | Avi Kivity | uint32_t index = addr; |
600 | e5c9a13e | balrog | s->cas = 0;
|
601 | e5c9a13e | balrog | switch (index) {
|
602 | e5c9a13e | balrog | case AC97_Reset:
|
603 | e5c9a13e | balrog | mixer_reset (s); |
604 | e5c9a13e | balrog | break;
|
605 | e5c9a13e | balrog | case AC97_Powerdown_Ctrl_Stat:
|
606 | 847c25d0 | Hans de Goede | val &= ~0x800f;
|
607 | e5c9a13e | balrog | val |= mixer_load (s, index) & 0xf;
|
608 | e5c9a13e | balrog | mixer_store (s, index, val); |
609 | e5c9a13e | balrog | break;
|
610 | 19677a38 | Marc-André Lureau | case AC97_PCM_Out_Volume_Mute:
|
611 | 19677a38 | Marc-André Lureau | case AC97_Master_Volume_Mute:
|
612 | 19677a38 | Marc-André Lureau | case AC97_Record_Gain_Mute:
|
613 | 19677a38 | Marc-André Lureau | set_volume (s, index, val); |
614 | 19677a38 | Marc-André Lureau | break;
|
615 | 19677a38 | Marc-André Lureau | case AC97_Record_Select:
|
616 | 19677a38 | Marc-André Lureau | record_select (s, val); |
617 | 19677a38 | Marc-André Lureau | break;
|
618 | e5c9a13e | balrog | case AC97_Vendor_ID1:
|
619 | e5c9a13e | balrog | case AC97_Vendor_ID2:
|
620 | e5c9a13e | balrog | dolog ("Attempt to write vendor ID to %#x\n", val);
|
621 | e5c9a13e | balrog | break;
|
622 | e5c9a13e | balrog | case AC97_Extended_Audio_ID:
|
623 | e5c9a13e | balrog | dolog ("Attempt to write extended audio ID to %#x\n", val);
|
624 | e5c9a13e | balrog | break;
|
625 | e5c9a13e | balrog | case AC97_Extended_Audio_Ctrl_Stat:
|
626 | e5c9a13e | balrog | if (!(val & EACS_VRA)) {
|
627 | e5c9a13e | balrog | mixer_store (s, AC97_PCM_Front_DAC_Rate, 0xbb80);
|
628 | e5c9a13e | balrog | mixer_store (s, AC97_PCM_LR_ADC_Rate, 0xbb80);
|
629 | e5c9a13e | balrog | open_voice (s, PI_INDEX, 48000);
|
630 | e5c9a13e | balrog | open_voice (s, PO_INDEX, 48000);
|
631 | e5c9a13e | balrog | } |
632 | e5c9a13e | balrog | if (!(val & EACS_VRM)) {
|
633 | e5c9a13e | balrog | mixer_store (s, AC97_MIC_ADC_Rate, 0xbb80);
|
634 | e5c9a13e | balrog | open_voice (s, MC_INDEX, 48000);
|
635 | e5c9a13e | balrog | } |
636 | e5c9a13e | balrog | dolog ("Setting extended audio control to %#x\n", val);
|
637 | e5c9a13e | balrog | mixer_store (s, AC97_Extended_Audio_Ctrl_Stat, val); |
638 | e5c9a13e | balrog | break;
|
639 | e5c9a13e | balrog | case AC97_PCM_Front_DAC_Rate:
|
640 | e5c9a13e | balrog | if (mixer_load (s, AC97_Extended_Audio_Ctrl_Stat) & EACS_VRA) {
|
641 | e5c9a13e | balrog | mixer_store (s, index, val); |
642 | e5c9a13e | balrog | dolog ("Set front DAC rate to %d\n", val);
|
643 | e5c9a13e | balrog | open_voice (s, PO_INDEX, val); |
644 | e5c9a13e | balrog | } |
645 | e5c9a13e | balrog | else {
|
646 | e5c9a13e | balrog | dolog ("Attempt to set front DAC rate to %d, "
|
647 | e5c9a13e | balrog | "but VRA is not set\n",
|
648 | e5c9a13e | balrog | val); |
649 | e5c9a13e | balrog | } |
650 | e5c9a13e | balrog | break;
|
651 | e5c9a13e | balrog | case AC97_MIC_ADC_Rate:
|
652 | e5c9a13e | balrog | if (mixer_load (s, AC97_Extended_Audio_Ctrl_Stat) & EACS_VRM) {
|
653 | e5c9a13e | balrog | mixer_store (s, index, val); |
654 | e5c9a13e | balrog | dolog ("Set MIC ADC rate to %d\n", val);
|
655 | e5c9a13e | balrog | open_voice (s, MC_INDEX, val); |
656 | e5c9a13e | balrog | } |
657 | e5c9a13e | balrog | else {
|
658 | e5c9a13e | balrog | dolog ("Attempt to set MIC ADC rate to %d, "
|
659 | e5c9a13e | balrog | "but VRM is not set\n",
|
660 | e5c9a13e | balrog | val); |
661 | e5c9a13e | balrog | } |
662 | e5c9a13e | balrog | break;
|
663 | e5c9a13e | balrog | case AC97_PCM_LR_ADC_Rate:
|
664 | e5c9a13e | balrog | if (mixer_load (s, AC97_Extended_Audio_Ctrl_Stat) & EACS_VRA) {
|
665 | e5c9a13e | balrog | mixer_store (s, index, val); |
666 | e5c9a13e | balrog | dolog ("Set front LR ADC rate to %d\n", val);
|
667 | e5c9a13e | balrog | open_voice (s, PI_INDEX, val); |
668 | e5c9a13e | balrog | } |
669 | e5c9a13e | balrog | else {
|
670 | e5c9a13e | balrog | dolog ("Attempt to set LR ADC rate to %d, but VRA is not set\n",
|
671 | e5c9a13e | balrog | val); |
672 | e5c9a13e | balrog | } |
673 | e5c9a13e | balrog | break;
|
674 | d044be37 | Hans de Goede | case AC97_Headphone_Volume_Mute:
|
675 | d044be37 | Hans de Goede | case AC97_Master_Volume_Mono_Mute:
|
676 | d044be37 | Hans de Goede | case AC97_Master_Tone_RL:
|
677 | d044be37 | Hans de Goede | case AC97_PC_BEEP_Volume_Mute:
|
678 | d044be37 | Hans de Goede | case AC97_Phone_Volume_Mute:
|
679 | d044be37 | Hans de Goede | case AC97_Mic_Volume_Mute:
|
680 | f94e9b9b | Hans de Goede | case AC97_Line_In_Volume_Mute:
|
681 | d044be37 | Hans de Goede | case AC97_CD_Volume_Mute:
|
682 | d044be37 | Hans de Goede | case AC97_Video_Volume_Mute:
|
683 | d044be37 | Hans de Goede | case AC97_Aux_Volume_Mute:
|
684 | d044be37 | Hans de Goede | case AC97_Record_Gain_Mic_Mute:
|
685 | d044be37 | Hans de Goede | case AC97_General_Purpose:
|
686 | d044be37 | Hans de Goede | case AC97_3D_Control:
|
687 | d044be37 | Hans de Goede | case AC97_Sigmatel_Analog:
|
688 | d044be37 | Hans de Goede | case AC97_Sigmatel_Dac2Invert:
|
689 | d044be37 | Hans de Goede | /* None of the features in these regs are emulated, so they are RO */
|
690 | d044be37 | Hans de Goede | break;
|
691 | e5c9a13e | balrog | default:
|
692 | e5c9a13e | balrog | dolog ("U nam writew %#x <- %#x\n", addr, val);
|
693 | e5c9a13e | balrog | mixer_store (s, index, val); |
694 | e5c9a13e | balrog | break;
|
695 | e5c9a13e | balrog | } |
696 | e5c9a13e | balrog | } |
697 | e5c9a13e | balrog | |
698 | e5c9a13e | balrog | static void nam_writel (void *opaque, uint32_t addr, uint32_t val) |
699 | e5c9a13e | balrog | { |
700 | 10ee2aaa | Juan Quintela | AC97LinkState *s = opaque; |
701 | e5c9a13e | balrog | dolog ("U nam writel %#x <- %#x\n", addr, val);
|
702 | e5c9a13e | balrog | s->cas = 0;
|
703 | e5c9a13e | balrog | } |
704 | e5c9a13e | balrog | |
705 | e5c9a13e | balrog | /**
|
706 | e5c9a13e | balrog | * Native audio bus master
|
707 | e5c9a13e | balrog | * I/O Reads
|
708 | e5c9a13e | balrog | */
|
709 | e5c9a13e | balrog | static uint32_t nabm_readb (void *opaque, uint32_t addr) |
710 | e5c9a13e | balrog | { |
711 | 10ee2aaa | Juan Quintela | AC97LinkState *s = opaque; |
712 | e5c9a13e | balrog | AC97BusMasterRegs *r = NULL;
|
713 | 83c406d9 | Avi Kivity | uint32_t index = addr; |
714 | e5c9a13e | balrog | uint32_t val = ~0U;
|
715 | e5c9a13e | balrog | |
716 | e5c9a13e | balrog | switch (index) {
|
717 | e5c9a13e | balrog | case CAS:
|
718 | e5c9a13e | balrog | dolog ("CAS %d\n", s->cas);
|
719 | e5c9a13e | balrog | val = s->cas; |
720 | e5c9a13e | balrog | s->cas = 1;
|
721 | e5c9a13e | balrog | break;
|
722 | e5c9a13e | balrog | case PI_CIV:
|
723 | e5c9a13e | balrog | case PO_CIV:
|
724 | e5c9a13e | balrog | case MC_CIV:
|
725 | e5c9a13e | balrog | r = &s->bm_regs[GET_BM (index)]; |
726 | e5c9a13e | balrog | val = r->civ; |
727 | e5c9a13e | balrog | dolog ("CIV[%d] -> %#x\n", GET_BM (index), val);
|
728 | e5c9a13e | balrog | break;
|
729 | e5c9a13e | balrog | case PI_LVI:
|
730 | e5c9a13e | balrog | case PO_LVI:
|
731 | e5c9a13e | balrog | case MC_LVI:
|
732 | e5c9a13e | balrog | r = &s->bm_regs[GET_BM (index)]; |
733 | e5c9a13e | balrog | val = r->lvi; |
734 | e5c9a13e | balrog | dolog ("LVI[%d] -> %#x\n", GET_BM (index), val);
|
735 | e5c9a13e | balrog | break;
|
736 | e5c9a13e | balrog | case PI_PIV:
|
737 | e5c9a13e | balrog | case PO_PIV:
|
738 | e5c9a13e | balrog | case MC_PIV:
|
739 | e5c9a13e | balrog | r = &s->bm_regs[GET_BM (index)]; |
740 | e5c9a13e | balrog | val = r->piv; |
741 | e5c9a13e | balrog | dolog ("PIV[%d] -> %#x\n", GET_BM (index), val);
|
742 | e5c9a13e | balrog | break;
|
743 | e5c9a13e | balrog | case PI_CR:
|
744 | e5c9a13e | balrog | case PO_CR:
|
745 | e5c9a13e | balrog | case MC_CR:
|
746 | e5c9a13e | balrog | r = &s->bm_regs[GET_BM (index)]; |
747 | e5c9a13e | balrog | val = r->cr; |
748 | e5c9a13e | balrog | dolog ("CR[%d] -> %#x\n", GET_BM (index), val);
|
749 | e5c9a13e | balrog | break;
|
750 | e5c9a13e | balrog | case PI_SR:
|
751 | e5c9a13e | balrog | case PO_SR:
|
752 | e5c9a13e | balrog | case MC_SR:
|
753 | e5c9a13e | balrog | r = &s->bm_regs[GET_BM (index)]; |
754 | e5c9a13e | balrog | val = r->sr & 0xff;
|
755 | e5c9a13e | balrog | dolog ("SRb[%d] -> %#x\n", GET_BM (index), val);
|
756 | e5c9a13e | balrog | break;
|
757 | e5c9a13e | balrog | default:
|
758 | e5c9a13e | balrog | dolog ("U nabm readb %#x -> %#x\n", addr, val);
|
759 | e5c9a13e | balrog | break;
|
760 | e5c9a13e | balrog | } |
761 | e5c9a13e | balrog | return val;
|
762 | e5c9a13e | balrog | } |
763 | e5c9a13e | balrog | |
764 | e5c9a13e | balrog | static uint32_t nabm_readw (void *opaque, uint32_t addr) |
765 | e5c9a13e | balrog | { |
766 | 10ee2aaa | Juan Quintela | AC97LinkState *s = opaque; |
767 | e5c9a13e | balrog | AC97BusMasterRegs *r = NULL;
|
768 | 83c406d9 | Avi Kivity | uint32_t index = addr; |
769 | e5c9a13e | balrog | uint32_t val = ~0U;
|
770 | e5c9a13e | balrog | |
771 | e5c9a13e | balrog | switch (index) {
|
772 | e5c9a13e | balrog | case PI_SR:
|
773 | e5c9a13e | balrog | case PO_SR:
|
774 | e5c9a13e | balrog | case MC_SR:
|
775 | e5c9a13e | balrog | r = &s->bm_regs[GET_BM (index)]; |
776 | e5c9a13e | balrog | val = r->sr; |
777 | e5c9a13e | balrog | dolog ("SR[%d] -> %#x\n", GET_BM (index), val);
|
778 | e5c9a13e | balrog | break;
|
779 | e5c9a13e | balrog | case PI_PICB:
|
780 | e5c9a13e | balrog | case PO_PICB:
|
781 | e5c9a13e | balrog | case MC_PICB:
|
782 | e5c9a13e | balrog | r = &s->bm_regs[GET_BM (index)]; |
783 | e5c9a13e | balrog | val = r->picb; |
784 | e5c9a13e | balrog | dolog ("PICB[%d] -> %#x\n", GET_BM (index), val);
|
785 | e5c9a13e | balrog | break;
|
786 | e5c9a13e | balrog | default:
|
787 | e5c9a13e | balrog | dolog ("U nabm readw %#x -> %#x\n", addr, val);
|
788 | e5c9a13e | balrog | break;
|
789 | e5c9a13e | balrog | } |
790 | e5c9a13e | balrog | return val;
|
791 | e5c9a13e | balrog | } |
792 | e5c9a13e | balrog | |
793 | e5c9a13e | balrog | static uint32_t nabm_readl (void *opaque, uint32_t addr) |
794 | e5c9a13e | balrog | { |
795 | 10ee2aaa | Juan Quintela | AC97LinkState *s = opaque; |
796 | e5c9a13e | balrog | AC97BusMasterRegs *r = NULL;
|
797 | 83c406d9 | Avi Kivity | uint32_t index = addr; |
798 | e5c9a13e | balrog | uint32_t val = ~0U;
|
799 | e5c9a13e | balrog | |
800 | e5c9a13e | balrog | switch (index) {
|
801 | e5c9a13e | balrog | case PI_BDBAR:
|
802 | e5c9a13e | balrog | case PO_BDBAR:
|
803 | e5c9a13e | balrog | case MC_BDBAR:
|
804 | e5c9a13e | balrog | r = &s->bm_regs[GET_BM (index)]; |
805 | e5c9a13e | balrog | val = r->bdbar; |
806 | e5c9a13e | balrog | dolog ("BMADDR[%d] -> %#x\n", GET_BM (index), val);
|
807 | e5c9a13e | balrog | break;
|
808 | e5c9a13e | balrog | case PI_CIV:
|
809 | e5c9a13e | balrog | case PO_CIV:
|
810 | e5c9a13e | balrog | case MC_CIV:
|
811 | e5c9a13e | balrog | r = &s->bm_regs[GET_BM (index)]; |
812 | e5c9a13e | balrog | val = r->civ | (r->lvi << 8) | (r->sr << 16); |
813 | e5c9a13e | balrog | dolog ("CIV LVI SR[%d] -> %#x, %#x, %#x\n", GET_BM (index),
|
814 | e5c9a13e | balrog | r->civ, r->lvi, r->sr); |
815 | e5c9a13e | balrog | break;
|
816 | e5c9a13e | balrog | case PI_PICB:
|
817 | e5c9a13e | balrog | case PO_PICB:
|
818 | e5c9a13e | balrog | case MC_PICB:
|
819 | e5c9a13e | balrog | r = &s->bm_regs[GET_BM (index)]; |
820 | e5c9a13e | balrog | val = r->picb | (r->piv << 16) | (r->cr << 24); |
821 | e5c9a13e | balrog | dolog ("PICB PIV CR[%d] -> %#x %#x %#x %#x\n", GET_BM (index),
|
822 | e5c9a13e | balrog | val, r->picb, r->piv, r->cr); |
823 | e5c9a13e | balrog | break;
|
824 | e5c9a13e | balrog | case GLOB_CNT:
|
825 | e5c9a13e | balrog | val = s->glob_cnt; |
826 | e5c9a13e | balrog | dolog ("glob_cnt -> %#x\n", val);
|
827 | e5c9a13e | balrog | break;
|
828 | e5c9a13e | balrog | case GLOB_STA:
|
829 | e5c9a13e | balrog | val = s->glob_sta | GS_S0CR; |
830 | e5c9a13e | balrog | dolog ("glob_sta -> %#x\n", val);
|
831 | e5c9a13e | balrog | break;
|
832 | e5c9a13e | balrog | default:
|
833 | e5c9a13e | balrog | dolog ("U nabm readl %#x -> %#x\n", addr, val);
|
834 | e5c9a13e | balrog | break;
|
835 | e5c9a13e | balrog | } |
836 | e5c9a13e | balrog | return val;
|
837 | e5c9a13e | balrog | } |
838 | e5c9a13e | balrog | |
839 | e5c9a13e | balrog | /**
|
840 | e5c9a13e | balrog | * Native audio bus master
|
841 | e5c9a13e | balrog | * I/O Writes
|
842 | e5c9a13e | balrog | */
|
843 | e5c9a13e | balrog | static void nabm_writeb (void *opaque, uint32_t addr, uint32_t val) |
844 | e5c9a13e | balrog | { |
845 | 10ee2aaa | Juan Quintela | AC97LinkState *s = opaque; |
846 | e5c9a13e | balrog | AC97BusMasterRegs *r = NULL;
|
847 | 83c406d9 | Avi Kivity | uint32_t index = addr; |
848 | e5c9a13e | balrog | switch (index) {
|
849 | e5c9a13e | balrog | case PI_LVI:
|
850 | e5c9a13e | balrog | case PO_LVI:
|
851 | e5c9a13e | balrog | case MC_LVI:
|
852 | e5c9a13e | balrog | r = &s->bm_regs[GET_BM (index)]; |
853 | e5c9a13e | balrog | if ((r->cr & CR_RPBM) && (r->sr & SR_DCH)) {
|
854 | e5c9a13e | balrog | r->sr &= ~(SR_DCH | SR_CELV); |
855 | e5c9a13e | balrog | r->civ = r->piv; |
856 | e5c9a13e | balrog | r->piv = (r->piv + 1) % 32; |
857 | e5c9a13e | balrog | fetch_bd (s, r); |
858 | e5c9a13e | balrog | } |
859 | e5c9a13e | balrog | r->lvi = val % 32;
|
860 | e5c9a13e | balrog | dolog ("LVI[%d] <- %#x\n", GET_BM (index), val);
|
861 | e5c9a13e | balrog | break;
|
862 | e5c9a13e | balrog | case PI_CR:
|
863 | e5c9a13e | balrog | case PO_CR:
|
864 | e5c9a13e | balrog | case MC_CR:
|
865 | e5c9a13e | balrog | r = &s->bm_regs[GET_BM (index)]; |
866 | e5c9a13e | balrog | if (val & CR_RR) {
|
867 | e5c9a13e | balrog | reset_bm_regs (s, r); |
868 | e5c9a13e | balrog | } |
869 | e5c9a13e | balrog | else {
|
870 | e5c9a13e | balrog | r->cr = val & CR_VALID_MASK; |
871 | e5c9a13e | balrog | if (!(r->cr & CR_RPBM)) {
|
872 | e5c9a13e | balrog | voice_set_active (s, r - s->bm_regs, 0);
|
873 | e5c9a13e | balrog | r->sr |= SR_DCH; |
874 | e5c9a13e | balrog | } |
875 | e5c9a13e | balrog | else {
|
876 | e5c9a13e | balrog | r->civ = r->piv; |
877 | e5c9a13e | balrog | r->piv = (r->piv + 1) % 32; |
878 | e5c9a13e | balrog | fetch_bd (s, r); |
879 | e5c9a13e | balrog | r->sr &= ~SR_DCH; |
880 | e5c9a13e | balrog | voice_set_active (s, r - s->bm_regs, 1);
|
881 | e5c9a13e | balrog | } |
882 | e5c9a13e | balrog | } |
883 | e5c9a13e | balrog | dolog ("CR[%d] <- %#x (cr %#x)\n", GET_BM (index), val, r->cr);
|
884 | e5c9a13e | balrog | break;
|
885 | e5c9a13e | balrog | case PI_SR:
|
886 | e5c9a13e | balrog | case PO_SR:
|
887 | e5c9a13e | balrog | case MC_SR:
|
888 | e5c9a13e | balrog | r = &s->bm_regs[GET_BM (index)]; |
889 | e5c9a13e | balrog | r->sr |= val & ~(SR_RO_MASK | SR_WCLEAR_MASK); |
890 | e5c9a13e | balrog | update_sr (s, r, r->sr & ~(val & SR_WCLEAR_MASK)); |
891 | e5c9a13e | balrog | dolog ("SR[%d] <- %#x (sr %#x)\n", GET_BM (index), val, r->sr);
|
892 | e5c9a13e | balrog | break;
|
893 | e5c9a13e | balrog | default:
|
894 | e5c9a13e | balrog | dolog ("U nabm writeb %#x <- %#x\n", addr, val);
|
895 | e5c9a13e | balrog | break;
|
896 | e5c9a13e | balrog | } |
897 | e5c9a13e | balrog | } |
898 | e5c9a13e | balrog | |
899 | e5c9a13e | balrog | static void nabm_writew (void *opaque, uint32_t addr, uint32_t val) |
900 | e5c9a13e | balrog | { |
901 | 10ee2aaa | Juan Quintela | AC97LinkState *s = opaque; |
902 | e5c9a13e | balrog | AC97BusMasterRegs *r = NULL;
|
903 | 83c406d9 | Avi Kivity | uint32_t index = addr; |
904 | e5c9a13e | balrog | switch (index) {
|
905 | e5c9a13e | balrog | case PI_SR:
|
906 | e5c9a13e | balrog | case PO_SR:
|
907 | e5c9a13e | balrog | case MC_SR:
|
908 | e5c9a13e | balrog | r = &s->bm_regs[GET_BM (index)]; |
909 | e5c9a13e | balrog | r->sr |= val & ~(SR_RO_MASK | SR_WCLEAR_MASK); |
910 | e5c9a13e | balrog | update_sr (s, r, r->sr & ~(val & SR_WCLEAR_MASK)); |
911 | e5c9a13e | balrog | dolog ("SR[%d] <- %#x (sr %#x)\n", GET_BM (index), val, r->sr);
|
912 | e5c9a13e | balrog | break;
|
913 | e5c9a13e | balrog | default:
|
914 | e5c9a13e | balrog | dolog ("U nabm writew %#x <- %#x\n", addr, val);
|
915 | e5c9a13e | balrog | break;
|
916 | e5c9a13e | balrog | } |
917 | e5c9a13e | balrog | } |
918 | e5c9a13e | balrog | |
919 | e5c9a13e | balrog | static void nabm_writel (void *opaque, uint32_t addr, uint32_t val) |
920 | e5c9a13e | balrog | { |
921 | 10ee2aaa | Juan Quintela | AC97LinkState *s = opaque; |
922 | e5c9a13e | balrog | AC97BusMasterRegs *r = NULL;
|
923 | 83c406d9 | Avi Kivity | uint32_t index = addr; |
924 | e5c9a13e | balrog | switch (index) {
|
925 | e5c9a13e | balrog | case PI_BDBAR:
|
926 | e5c9a13e | balrog | case PO_BDBAR:
|
927 | e5c9a13e | balrog | case MC_BDBAR:
|
928 | e5c9a13e | balrog | r = &s->bm_regs[GET_BM (index)]; |
929 | e5c9a13e | balrog | r->bdbar = val & ~3;
|
930 | e5c9a13e | balrog | dolog ("BDBAR[%d] <- %#x (bdbar %#x)\n",
|
931 | e5c9a13e | balrog | GET_BM (index), val, r->bdbar); |
932 | e5c9a13e | balrog | break;
|
933 | e5c9a13e | balrog | case GLOB_CNT:
|
934 | e5c9a13e | balrog | if (val & GC_WR)
|
935 | e5c9a13e | balrog | warm_reset (s); |
936 | e5c9a13e | balrog | if (val & GC_CR)
|
937 | e5c9a13e | balrog | cold_reset (s); |
938 | e5c9a13e | balrog | if (!(val & (GC_WR | GC_CR)))
|
939 | e5c9a13e | balrog | s->glob_cnt = val & GC_VALID_MASK; |
940 | e5c9a13e | balrog | dolog ("glob_cnt <- %#x (glob_cnt %#x)\n", val, s->glob_cnt);
|
941 | e5c9a13e | balrog | break;
|
942 | e5c9a13e | balrog | case GLOB_STA:
|
943 | e5c9a13e | balrog | s->glob_sta &= ~(val & GS_WCLEAR_MASK); |
944 | e5c9a13e | balrog | s->glob_sta |= (val & ~(GS_WCLEAR_MASK | GS_RO_MASK)) & GS_VALID_MASK; |
945 | e5c9a13e | balrog | dolog ("glob_sta <- %#x (glob_sta %#x)\n", val, s->glob_sta);
|
946 | e5c9a13e | balrog | break;
|
947 | e5c9a13e | balrog | default:
|
948 | e5c9a13e | balrog | dolog ("U nabm writel %#x <- %#x\n", addr, val);
|
949 | e5c9a13e | balrog | break;
|
950 | e5c9a13e | balrog | } |
951 | e5c9a13e | balrog | } |
952 | e5c9a13e | balrog | |
953 | e5c9a13e | balrog | static int write_audio (AC97LinkState *s, AC97BusMasterRegs *r, |
954 | e5c9a13e | balrog | int max, int *stop) |
955 | e5c9a13e | balrog | { |
956 | e5c9a13e | balrog | uint8_t tmpbuf[4096];
|
957 | e5c9a13e | balrog | uint32_t addr = r->bd.addr; |
958 | e5c9a13e | balrog | uint32_t temp = r->picb << 1;
|
959 | e5c9a13e | balrog | uint32_t written = 0;
|
960 | e5c9a13e | balrog | int to_copy = 0; |
961 | e5c9a13e | balrog | temp = audio_MIN (temp, max); |
962 | e5c9a13e | balrog | |
963 | e5c9a13e | balrog | if (!temp) {
|
964 | e5c9a13e | balrog | *stop = 1;
|
965 | e5c9a13e | balrog | return 0; |
966 | e5c9a13e | balrog | } |
967 | e5c9a13e | balrog | |
968 | e5c9a13e | balrog | while (temp) {
|
969 | e5c9a13e | balrog | int copied;
|
970 | e5c9a13e | balrog | to_copy = audio_MIN (temp, sizeof (tmpbuf));
|
971 | 93f43c48 | Eduard - Gabriel Munteanu | pci_dma_read (&s->dev, addr, tmpbuf, to_copy); |
972 | e5c9a13e | balrog | copied = AUD_write (s->voice_po, tmpbuf, to_copy); |
973 | e5c9a13e | balrog | dolog ("write_audio max=%x to_copy=%x copied=%x\n",
|
974 | e5c9a13e | balrog | max, to_copy, copied); |
975 | e5c9a13e | balrog | if (!copied) {
|
976 | e5c9a13e | balrog | *stop = 1;
|
977 | e5c9a13e | balrog | break;
|
978 | e5c9a13e | balrog | } |
979 | e5c9a13e | balrog | temp -= copied; |
980 | e5c9a13e | balrog | addr += copied; |
981 | e5c9a13e | balrog | written += copied; |
982 | e5c9a13e | balrog | } |
983 | e5c9a13e | balrog | |
984 | e5c9a13e | balrog | if (!temp) {
|
985 | e5c9a13e | balrog | if (to_copy < 4) { |
986 | e5c9a13e | balrog | dolog ("whoops\n");
|
987 | e5c9a13e | balrog | s->last_samp = 0;
|
988 | e5c9a13e | balrog | } |
989 | e5c9a13e | balrog | else {
|
990 | e5c9a13e | balrog | s->last_samp = *(uint32_t *) &tmpbuf[to_copy - 4];
|
991 | e5c9a13e | balrog | } |
992 | e5c9a13e | balrog | } |
993 | e5c9a13e | balrog | |
994 | e5c9a13e | balrog | r->bd.addr = addr; |
995 | e5c9a13e | balrog | return written;
|
996 | e5c9a13e | balrog | } |
997 | e5c9a13e | balrog | |
998 | e5c9a13e | balrog | static void write_bup (AC97LinkState *s, int elapsed) |
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 | } |
1024 | e5c9a13e | balrog | } |
1025 | e5c9a13e | balrog | } |
1026 | e5c9a13e | balrog | |
1027 | e5c9a13e | balrog | static int read_audio (AC97LinkState *s, AC97BusMasterRegs *r, |
1028 | e5c9a13e | balrog | int max, int *stop) |
1029 | e5c9a13e | balrog | { |
1030 | e5c9a13e | balrog | uint8_t tmpbuf[4096];
|
1031 | e5c9a13e | balrog | uint32_t addr = r->bd.addr; |
1032 | e5c9a13e | balrog | uint32_t temp = r->picb << 1;
|
1033 | e5c9a13e | balrog | uint32_t nread = 0;
|
1034 | e5c9a13e | balrog | int to_copy = 0; |
1035 | e5c9a13e | balrog | SWVoiceIn *voice = (r - s->bm_regs) == MC_INDEX ? s->voice_mc : s->voice_pi; |
1036 | e5c9a13e | balrog | |
1037 | e5c9a13e | balrog | temp = audio_MIN (temp, max); |
1038 | e5c9a13e | balrog | |
1039 | e5c9a13e | balrog | if (!temp) {
|
1040 | e5c9a13e | balrog | *stop = 1;
|
1041 | e5c9a13e | balrog | return 0; |
1042 | e5c9a13e | balrog | } |
1043 | e5c9a13e | balrog | |
1044 | e5c9a13e | balrog | while (temp) {
|
1045 | e5c9a13e | balrog | int acquired;
|
1046 | e5c9a13e | balrog | to_copy = audio_MIN (temp, sizeof (tmpbuf));
|
1047 | e5c9a13e | balrog | acquired = AUD_read (voice, tmpbuf, to_copy); |
1048 | e5c9a13e | balrog | if (!acquired) {
|
1049 | e5c9a13e | balrog | *stop = 1;
|
1050 | e5c9a13e | balrog | break;
|
1051 | e5c9a13e | balrog | } |
1052 | 93f43c48 | Eduard - Gabriel Munteanu | pci_dma_write (&s->dev, addr, tmpbuf, acquired); |
1053 | e5c9a13e | balrog | temp -= acquired; |
1054 | e5c9a13e | balrog | addr += acquired; |
1055 | e5c9a13e | balrog | nread += acquired; |
1056 | e5c9a13e | balrog | } |
1057 | e5c9a13e | balrog | |
1058 | e5c9a13e | balrog | r->bd.addr = addr; |
1059 | e5c9a13e | balrog | return nread;
|
1060 | e5c9a13e | balrog | } |
1061 | e5c9a13e | balrog | |
1062 | e5c9a13e | balrog | static void transfer_audio (AC97LinkState *s, int index, int elapsed) |
1063 | e5c9a13e | balrog | { |
1064 | e5c9a13e | balrog | AC97BusMasterRegs *r = &s->bm_regs[index]; |
1065 | 7ba4cbbf | Stefan Weil | int stop = 0; |
1066 | e5c9a13e | balrog | |
1067 | 2c44375d | malc | if (s->invalid_freq[index]) {
|
1068 | 2c44375d | malc | AUD_log ("ac97", "attempt to use voice %d with invalid frequency %d\n", |
1069 | 2c44375d | malc | index, s->invalid_freq[index]); |
1070 | 2c44375d | malc | return;
|
1071 | 2c44375d | malc | } |
1072 | 2c44375d | malc | |
1073 | e5c9a13e | balrog | if (r->sr & SR_DCH) {
|
1074 | e5c9a13e | balrog | if (r->cr & CR_RPBM) {
|
1075 | e5c9a13e | balrog | switch (index) {
|
1076 | e5c9a13e | balrog | case PO_INDEX:
|
1077 | e5c9a13e | balrog | write_bup (s, elapsed); |
1078 | e5c9a13e | balrog | break;
|
1079 | e5c9a13e | balrog | } |
1080 | e5c9a13e | balrog | } |
1081 | e5c9a13e | balrog | return;
|
1082 | e5c9a13e | balrog | } |
1083 | e5c9a13e | balrog | |
1084 | e5c9a13e | balrog | while ((elapsed >> 1) && !stop) { |
1085 | e5c9a13e | balrog | int temp;
|
1086 | e5c9a13e | balrog | |
1087 | e5c9a13e | balrog | if (!r->bd_valid) {
|
1088 | e5c9a13e | balrog | dolog ("invalid bd\n");
|
1089 | e5c9a13e | balrog | fetch_bd (s, r); |
1090 | e5c9a13e | balrog | } |
1091 | e5c9a13e | balrog | |
1092 | e5c9a13e | balrog | if (!r->picb) {
|
1093 | e5c9a13e | balrog | dolog ("fresh bd %d is empty %#x %#x\n",
|
1094 | e5c9a13e | balrog | r->civ, r->bd.addr, r->bd.ctl_len); |
1095 | e5c9a13e | balrog | if (r->civ == r->lvi) {
|
1096 | e5c9a13e | balrog | r->sr |= SR_DCH; /* CELV? */
|
1097 | e5c9a13e | balrog | s->bup_flag = 0;
|
1098 | e5c9a13e | balrog | break;
|
1099 | e5c9a13e | balrog | } |
1100 | e5c9a13e | balrog | r->sr &= ~SR_CELV; |
1101 | e5c9a13e | balrog | r->civ = r->piv; |
1102 | e5c9a13e | balrog | r->piv = (r->piv + 1) % 32; |
1103 | e5c9a13e | balrog | fetch_bd (s, r); |
1104 | e5c9a13e | balrog | return;
|
1105 | e5c9a13e | balrog | } |
1106 | e5c9a13e | balrog | |
1107 | e5c9a13e | balrog | switch (index) {
|
1108 | e5c9a13e | balrog | case PO_INDEX:
|
1109 | e5c9a13e | balrog | temp = write_audio (s, r, elapsed, &stop); |
1110 | e5c9a13e | balrog | elapsed -= temp; |
1111 | e5c9a13e | balrog | r->picb -= (temp >> 1);
|
1112 | e5c9a13e | balrog | break;
|
1113 | e5c9a13e | balrog | |
1114 | e5c9a13e | balrog | case PI_INDEX:
|
1115 | e5c9a13e | balrog | case MC_INDEX:
|
1116 | e5c9a13e | balrog | temp = read_audio (s, r, elapsed, &stop); |
1117 | e5c9a13e | balrog | elapsed -= temp; |
1118 | e5c9a13e | balrog | r->picb -= (temp >> 1);
|
1119 | e5c9a13e | balrog | break;
|
1120 | e5c9a13e | balrog | } |
1121 | e5c9a13e | balrog | |
1122 | e5c9a13e | balrog | if (!r->picb) {
|
1123 | e5c9a13e | balrog | uint32_t new_sr = r->sr & ~SR_CELV; |
1124 | e5c9a13e | balrog | |
1125 | e5c9a13e | balrog | if (r->bd.ctl_len & BD_IOC) {
|
1126 | e5c9a13e | balrog | new_sr |= SR_BCIS; |
1127 | e5c9a13e | balrog | } |
1128 | e5c9a13e | balrog | |
1129 | e5c9a13e | balrog | if (r->civ == r->lvi) {
|
1130 | e5c9a13e | balrog | dolog ("Underrun civ (%d) == lvi (%d)\n", r->civ, r->lvi);
|
1131 | e5c9a13e | balrog | |
1132 | e5c9a13e | balrog | new_sr |= SR_LVBCI | SR_DCH | SR_CELV; |
1133 | e5c9a13e | balrog | stop = 1;
|
1134 | e5c9a13e | balrog | s->bup_flag = (r->bd.ctl_len & BD_BUP) ? BUP_LAST : 0;
|
1135 | e5c9a13e | balrog | } |
1136 | e5c9a13e | balrog | else {
|
1137 | e5c9a13e | balrog | r->civ = r->piv; |
1138 | e5c9a13e | balrog | r->piv = (r->piv + 1) % 32; |
1139 | e5c9a13e | balrog | fetch_bd (s, r); |
1140 | e5c9a13e | balrog | } |
1141 | e5c9a13e | balrog | |
1142 | e5c9a13e | balrog | update_sr (s, r, new_sr); |
1143 | e5c9a13e | balrog | } |
1144 | e5c9a13e | balrog | } |
1145 | e5c9a13e | balrog | } |
1146 | e5c9a13e | balrog | |
1147 | e5c9a13e | balrog | static void pi_callback (void *opaque, int avail) |
1148 | e5c9a13e | balrog | { |
1149 | e5c9a13e | balrog | transfer_audio (opaque, PI_INDEX, avail); |
1150 | e5c9a13e | balrog | } |
1151 | e5c9a13e | balrog | |
1152 | e5c9a13e | balrog | static void mc_callback (void *opaque, int avail) |
1153 | e5c9a13e | balrog | { |
1154 | e5c9a13e | balrog | transfer_audio (opaque, MC_INDEX, avail); |
1155 | e5c9a13e | balrog | } |
1156 | e5c9a13e | balrog | |
1157 | e5c9a13e | balrog | static void po_callback (void *opaque, int free) |
1158 | e5c9a13e | balrog | { |
1159 | e5c9a13e | balrog | transfer_audio (opaque, PO_INDEX, free); |
1160 | e5c9a13e | balrog | } |
1161 | e5c9a13e | balrog | |
1162 | a90ffa49 | Juan Quintela | static const VMStateDescription vmstate_ac97_bm_regs = { |
1163 | a90ffa49 | Juan Quintela | .name = "ac97_bm_regs",
|
1164 | a90ffa49 | Juan Quintela | .version_id = 1,
|
1165 | a90ffa49 | Juan Quintela | .minimum_version_id = 1,
|
1166 | a90ffa49 | Juan Quintela | .minimum_version_id_old = 1,
|
1167 | a90ffa49 | Juan Quintela | .fields = (VMStateField []) { |
1168 | cf4dc461 | malc | VMSTATE_UINT32 (bdbar, AC97BusMasterRegs), |
1169 | cf4dc461 | malc | VMSTATE_UINT8 (civ, AC97BusMasterRegs), |
1170 | cf4dc461 | malc | VMSTATE_UINT8 (lvi, AC97BusMasterRegs), |
1171 | cf4dc461 | malc | VMSTATE_UINT16 (sr, AC97BusMasterRegs), |
1172 | cf4dc461 | malc | VMSTATE_UINT16 (picb, AC97BusMasterRegs), |
1173 | cf4dc461 | malc | VMSTATE_UINT8 (piv, AC97BusMasterRegs), |
1174 | cf4dc461 | malc | VMSTATE_UINT8 (cr, AC97BusMasterRegs), |
1175 | cf4dc461 | malc | VMSTATE_UINT32 (bd_valid, AC97BusMasterRegs), |
1176 | cf4dc461 | malc | VMSTATE_UINT32 (bd.addr, AC97BusMasterRegs), |
1177 | cf4dc461 | malc | VMSTATE_UINT32 (bd.ctl_len, AC97BusMasterRegs), |
1178 | cf4dc461 | malc | VMSTATE_END_OF_LIST () |
1179 | e5c9a13e | balrog | } |
1180 | a90ffa49 | Juan Quintela | }; |
1181 | e5c9a13e | balrog | |
1182 | a90ffa49 | Juan Quintela | static int ac97_post_load (void *opaque, int version_id) |
1183 | e5c9a13e | balrog | { |
1184 | e5c9a13e | balrog | uint8_t active[LAST_INDEX]; |
1185 | e5c9a13e | balrog | AC97LinkState *s = opaque; |
1186 | e5c9a13e | balrog | |
1187 | 19677a38 | Marc-André Lureau | record_select (s, mixer_load (s, AC97_Record_Select)); |
1188 | 19677a38 | Marc-André Lureau | set_volume (s, AC97_Master_Volume_Mute, |
1189 | 19677a38 | Marc-André Lureau | mixer_load (s, AC97_Master_Volume_Mute)); |
1190 | 19677a38 | Marc-André Lureau | set_volume (s, AC97_PCM_Out_Volume_Mute, |
1191 | 19677a38 | Marc-André Lureau | mixer_load (s, AC97_PCM_Out_Volume_Mute)); |
1192 | f94e9b9b | Hans de Goede | set_volume (s, AC97_Record_Gain_Mute, |
1193 | f94e9b9b | Hans de Goede | mixer_load (s, AC97_Record_Gain_Mute)); |
1194 | 19677a38 | Marc-André Lureau | |
1195 | 7626f39f | Juan Quintela | active[PI_INDEX] = !!(s->bm_regs[PI_INDEX].cr & CR_RPBM); |
1196 | 7626f39f | Juan Quintela | active[PO_INDEX] = !!(s->bm_regs[PO_INDEX].cr & CR_RPBM); |
1197 | 7626f39f | Juan Quintela | active[MC_INDEX] = !!(s->bm_regs[MC_INDEX].cr & CR_RPBM); |
1198 | e5c9a13e | balrog | reset_voices (s, active); |
1199 | e5c9a13e | balrog | |
1200 | e5c9a13e | balrog | s->bup_flag = 0;
|
1201 | e5c9a13e | balrog | s->last_samp = 0;
|
1202 | e5c9a13e | balrog | return 0; |
1203 | e5c9a13e | balrog | } |
1204 | e5c9a13e | balrog | |
1205 | a90ffa49 | Juan Quintela | static bool is_version_2 (void *opaque, int version_id) |
1206 | a90ffa49 | Juan Quintela | { |
1207 | a90ffa49 | Juan Quintela | return version_id == 2; |
1208 | a90ffa49 | Juan Quintela | } |
1209 | a90ffa49 | Juan Quintela | |
1210 | a90ffa49 | Juan Quintela | static const VMStateDescription vmstate_ac97 = { |
1211 | a90ffa49 | Juan Quintela | .name = "ac97",
|
1212 | a90ffa49 | Juan Quintela | .version_id = 3,
|
1213 | a90ffa49 | Juan Quintela | .minimum_version_id = 2,
|
1214 | a90ffa49 | Juan Quintela | .minimum_version_id_old = 2,
|
1215 | a90ffa49 | Juan Quintela | .post_load = ac97_post_load, |
1216 | a90ffa49 | Juan Quintela | .fields = (VMStateField []) { |
1217 | cf4dc461 | malc | VMSTATE_PCI_DEVICE (dev, AC97LinkState), |
1218 | cf4dc461 | malc | VMSTATE_UINT32 (glob_cnt, AC97LinkState), |
1219 | cf4dc461 | malc | VMSTATE_UINT32 (glob_sta, AC97LinkState), |
1220 | cf4dc461 | malc | VMSTATE_UINT32 (cas, AC97LinkState), |
1221 | cf4dc461 | malc | VMSTATE_STRUCT_ARRAY (bm_regs, AC97LinkState, 3, 1, |
1222 | cf4dc461 | malc | vmstate_ac97_bm_regs, AC97BusMasterRegs), |
1223 | cf4dc461 | malc | VMSTATE_BUFFER (mixer_data, AC97LinkState), |
1224 | cf4dc461 | malc | VMSTATE_UNUSED_TEST (is_version_2, 3),
|
1225 | cf4dc461 | malc | VMSTATE_END_OF_LIST () |
1226 | a90ffa49 | Juan Quintela | } |
1227 | a90ffa49 | Juan Quintela | }; |
1228 | a90ffa49 | Juan Quintela | |
1229 | d6a6d362 | Alexander Graf | static uint64_t nam_read(void *opaque, hwaddr addr, unsigned size) |
1230 | d6a6d362 | Alexander Graf | { |
1231 | d6a6d362 | Alexander Graf | if ((addr / size) > 256) { |
1232 | d6a6d362 | Alexander Graf | return -1; |
1233 | d6a6d362 | Alexander Graf | } |
1234 | d6a6d362 | Alexander Graf | |
1235 | d6a6d362 | Alexander Graf | switch (size) {
|
1236 | d6a6d362 | Alexander Graf | case 1: |
1237 | d6a6d362 | Alexander Graf | return nam_readb(opaque, addr);
|
1238 | d6a6d362 | Alexander Graf | case 2: |
1239 | d6a6d362 | Alexander Graf | return nam_readw(opaque, addr);
|
1240 | d6a6d362 | Alexander Graf | case 4: |
1241 | d6a6d362 | Alexander Graf | return nam_readl(opaque, addr);
|
1242 | d6a6d362 | Alexander Graf | default:
|
1243 | d6a6d362 | Alexander Graf | return -1; |
1244 | d6a6d362 | Alexander Graf | } |
1245 | d6a6d362 | Alexander Graf | } |
1246 | d6a6d362 | Alexander Graf | |
1247 | d6a6d362 | Alexander Graf | static void nam_write(void *opaque, hwaddr addr, uint64_t val, |
1248 | d6a6d362 | Alexander Graf | unsigned size)
|
1249 | d6a6d362 | Alexander Graf | { |
1250 | d6a6d362 | Alexander Graf | if ((addr / size) > 256) { |
1251 | d6a6d362 | Alexander Graf | return;
|
1252 | d6a6d362 | Alexander Graf | } |
1253 | d6a6d362 | Alexander Graf | |
1254 | d6a6d362 | Alexander Graf | switch (size) {
|
1255 | d6a6d362 | Alexander Graf | case 1: |
1256 | d6a6d362 | Alexander Graf | nam_writeb(opaque, addr, val); |
1257 | d6a6d362 | Alexander Graf | break;
|
1258 | d6a6d362 | Alexander Graf | case 2: |
1259 | d6a6d362 | Alexander Graf | nam_writew(opaque, addr, val); |
1260 | d6a6d362 | Alexander Graf | break;
|
1261 | d6a6d362 | Alexander Graf | case 4: |
1262 | d6a6d362 | Alexander Graf | nam_writel(opaque, addr, val); |
1263 | d6a6d362 | Alexander Graf | break;
|
1264 | d6a6d362 | Alexander Graf | } |
1265 | d6a6d362 | Alexander Graf | } |
1266 | 83c406d9 | Avi Kivity | |
1267 | 83c406d9 | Avi Kivity | static const MemoryRegionOps ac97_io_nam_ops = { |
1268 | d6a6d362 | Alexander Graf | .read = nam_read, |
1269 | d6a6d362 | Alexander Graf | .write = nam_write, |
1270 | d6a6d362 | Alexander Graf | .impl = { |
1271 | d6a6d362 | Alexander Graf | .min_access_size = 1,
|
1272 | d6a6d362 | Alexander Graf | .max_access_size = 4,
|
1273 | d6a6d362 | Alexander Graf | }, |
1274 | d6a6d362 | Alexander Graf | .endianness = DEVICE_LITTLE_ENDIAN, |
1275 | 83c406d9 | Avi Kivity | }; |
1276 | 83c406d9 | Avi Kivity | |
1277 | d6a6d362 | Alexander Graf | static uint64_t nabm_read(void *opaque, hwaddr addr, unsigned size) |
1278 | d6a6d362 | Alexander Graf | { |
1279 | d6a6d362 | Alexander Graf | if ((addr / size) > 64) { |
1280 | d6a6d362 | Alexander Graf | return -1; |
1281 | d6a6d362 | Alexander Graf | } |
1282 | d6a6d362 | Alexander Graf | |
1283 | d6a6d362 | Alexander Graf | switch (size) {
|
1284 | d6a6d362 | Alexander Graf | case 1: |
1285 | d6a6d362 | Alexander Graf | return nabm_readb(opaque, addr);
|
1286 | d6a6d362 | Alexander Graf | case 2: |
1287 | d6a6d362 | Alexander Graf | return nabm_readw(opaque, addr);
|
1288 | d6a6d362 | Alexander Graf | case 4: |
1289 | d6a6d362 | Alexander Graf | return nabm_readl(opaque, addr);
|
1290 | d6a6d362 | Alexander Graf | default:
|
1291 | d6a6d362 | Alexander Graf | return -1; |
1292 | d6a6d362 | Alexander Graf | } |
1293 | d6a6d362 | Alexander Graf | } |
1294 | d6a6d362 | Alexander Graf | |
1295 | d6a6d362 | Alexander Graf | static void nabm_write(void *opaque, hwaddr addr, uint64_t val, |
1296 | d6a6d362 | Alexander Graf | unsigned size)
|
1297 | d6a6d362 | Alexander Graf | { |
1298 | d6a6d362 | Alexander Graf | if ((addr / size) > 64) { |
1299 | d6a6d362 | Alexander Graf | return;
|
1300 | d6a6d362 | Alexander Graf | } |
1301 | d6a6d362 | Alexander Graf | |
1302 | d6a6d362 | Alexander Graf | switch (size) {
|
1303 | d6a6d362 | Alexander Graf | case 1: |
1304 | d6a6d362 | Alexander Graf | nabm_writeb(opaque, addr, val); |
1305 | d6a6d362 | Alexander Graf | break;
|
1306 | d6a6d362 | Alexander Graf | case 2: |
1307 | d6a6d362 | Alexander Graf | nabm_writew(opaque, addr, val); |
1308 | d6a6d362 | Alexander Graf | break;
|
1309 | d6a6d362 | Alexander Graf | case 4: |
1310 | d6a6d362 | Alexander Graf | nabm_writel(opaque, addr, val); |
1311 | d6a6d362 | Alexander Graf | break;
|
1312 | d6a6d362 | Alexander Graf | } |
1313 | d6a6d362 | Alexander Graf | } |
1314 | d6a6d362 | Alexander Graf | |
1315 | 83c406d9 | Avi Kivity | |
1316 | 83c406d9 | Avi Kivity | static const MemoryRegionOps ac97_io_nabm_ops = { |
1317 | d6a6d362 | Alexander Graf | .read = nabm_read, |
1318 | d6a6d362 | Alexander Graf | .write = nabm_write, |
1319 | d6a6d362 | Alexander Graf | .impl = { |
1320 | d6a6d362 | Alexander Graf | .min_access_size = 1,
|
1321 | d6a6d362 | Alexander Graf | .max_access_size = 4,
|
1322 | d6a6d362 | Alexander Graf | }, |
1323 | d6a6d362 | Alexander Graf | .endianness = DEVICE_LITTLE_ENDIAN, |
1324 | 83c406d9 | Avi Kivity | }; |
1325 | e5c9a13e | balrog | |
1326 | e5c9a13e | balrog | static void ac97_on_reset (void *opaque) |
1327 | e5c9a13e | balrog | { |
1328 | e5c9a13e | balrog | AC97LinkState *s = opaque; |
1329 | e5c9a13e | balrog | |
1330 | e5c9a13e | balrog | reset_bm_regs (s, &s->bm_regs[0]);
|
1331 | e5c9a13e | balrog | reset_bm_regs (s, &s->bm_regs[1]);
|
1332 | e5c9a13e | balrog | reset_bm_regs (s, &s->bm_regs[2]);
|
1333 | e5c9a13e | balrog | |
1334 | e5c9a13e | balrog | /*
|
1335 | e5c9a13e | balrog | * Reset the mixer too. The Windows XP driver seems to rely on
|
1336 | e5c9a13e | balrog | * this. At least it wants to read the vendor id before it resets
|
1337 | e5c9a13e | balrog | * the codec manually.
|
1338 | e5c9a13e | balrog | */
|
1339 | e5c9a13e | balrog | mixer_reset (s); |
1340 | e5c9a13e | balrog | } |
1341 | e5c9a13e | balrog | |
1342 | 81a322d4 | Gerd Hoffmann | static int ac97_initfn (PCIDevice *dev) |
1343 | e5c9a13e | balrog | { |
1344 | 10ee2aaa | Juan Quintela | AC97LinkState *s = DO_UPCAST (AC97LinkState, dev, dev); |
1345 | 10ee2aaa | Juan Quintela | uint8_t *c = s->dev.config; |
1346 | e5c9a13e | balrog | |
1347 | 4468fb63 | Michael S. Tsirkin | /* TODO: no need to override */
|
1348 | 4468fb63 | Michael S. Tsirkin | c[PCI_COMMAND] = 0x00; /* pcicmd pci command rw, ro */ |
1349 | 4468fb63 | Michael S. Tsirkin | c[PCI_COMMAND + 1] = 0x00; |
1350 | e5c9a13e | balrog | |
1351 | 4468fb63 | Michael S. Tsirkin | /* TODO: */
|
1352 | 4468fb63 | Michael S. Tsirkin | c[PCI_STATUS] = PCI_STATUS_FAST_BACK; /* pcists pci status rwc, ro */
|
1353 | 4468fb63 | Michael S. Tsirkin | c[PCI_STATUS + 1] = PCI_STATUS_DEVSEL_MEDIUM >> 8; |
1354 | e5c9a13e | balrog | |
1355 | 4468fb63 | Michael S. Tsirkin | c[PCI_CLASS_PROG] = 0x00; /* pi programming interface ro */ |
1356 | e5c9a13e | balrog | |
1357 | 4468fb63 | Michael S. Tsirkin | /* TODO set when bar is registered. no need to override. */
|
1358 | 4468fb63 | Michael S. Tsirkin | /* nabmar native audio mixer base address rw */
|
1359 | 4468fb63 | Michael S. Tsirkin | c[PCI_BASE_ADDRESS_0] = PCI_BASE_ADDRESS_SPACE_IO; |
1360 | 4468fb63 | Michael S. Tsirkin | c[PCI_BASE_ADDRESS_0 + 1] = 0x00; |
1361 | 4468fb63 | Michael S. Tsirkin | c[PCI_BASE_ADDRESS_0 + 2] = 0x00; |
1362 | 4468fb63 | Michael S. Tsirkin | c[PCI_BASE_ADDRESS_0 + 3] = 0x00; |
1363 | 4468fb63 | Michael S. Tsirkin | |
1364 | 4468fb63 | Michael S. Tsirkin | /* TODO set when bar is registered. no need to override. */
|
1365 | 4468fb63 | Michael S. Tsirkin | /* nabmbar native audio bus mastering base address rw */
|
1366 | 4468fb63 | Michael S. Tsirkin | c[PCI_BASE_ADDRESS_0 + 4] = PCI_BASE_ADDRESS_SPACE_IO;
|
1367 | 4468fb63 | Michael S. Tsirkin | c[PCI_BASE_ADDRESS_0 + 5] = 0x00; |
1368 | 4468fb63 | Michael S. Tsirkin | c[PCI_BASE_ADDRESS_0 + 6] = 0x00; |
1369 | 4468fb63 | Michael S. Tsirkin | c[PCI_BASE_ADDRESS_0 + 7] = 0x00; |
1370 | 4468fb63 | Michael S. Tsirkin | |
1371 | 25a21c94 | Gerd Hoffmann | if (s->use_broken_id) {
|
1372 | 25a21c94 | Gerd Hoffmann | c[PCI_SUBSYSTEM_VENDOR_ID] = 0x86;
|
1373 | 25a21c94 | Gerd Hoffmann | c[PCI_SUBSYSTEM_VENDOR_ID + 1] = 0x80; |
1374 | 25a21c94 | Gerd Hoffmann | c[PCI_SUBSYSTEM_ID] = 0x00;
|
1375 | 25a21c94 | Gerd Hoffmann | c[PCI_SUBSYSTEM_ID + 1] = 0x00; |
1376 | 25a21c94 | Gerd Hoffmann | } |
1377 | 4468fb63 | Michael S. Tsirkin | |
1378 | 4468fb63 | Michael S. Tsirkin | c[PCI_INTERRUPT_LINE] = 0x00; /* intr_ln interrupt line rw */ |
1379 | 4468fb63 | Michael S. Tsirkin | c[PCI_INTERRUPT_PIN] = 0x01; /* intr_pn interrupt pin ro */ |
1380 | e5c9a13e | balrog | |
1381 | 83c406d9 | Avi Kivity | memory_region_init_io (&s->io_nam, &ac97_io_nam_ops, s, "ac97-nam", 1024); |
1382 | 83c406d9 | Avi Kivity | memory_region_init_io (&s->io_nabm, &ac97_io_nabm_ops, s, "ac97-nabm", 256); |
1383 | e824b2cc | Avi Kivity | pci_register_bar (&s->dev, 0, PCI_BASE_ADDRESS_SPACE_IO, &s->io_nam);
|
1384 | e824b2cc | Avi Kivity | pci_register_bar (&s->dev, 1, PCI_BASE_ADDRESS_SPACE_IO, &s->io_nabm);
|
1385 | a08d4367 | Jan Kiszka | qemu_register_reset (ac97_on_reset, s); |
1386 | 1a7dafce | malc | AUD_register_card ("ac97", &s->card);
|
1387 | e5c9a13e | balrog | ac97_on_reset (s); |
1388 | 81a322d4 | Gerd Hoffmann | return 0; |
1389 | d88a76d1 | Gerd Hoffmann | } |
1390 | d88a76d1 | Gerd Hoffmann | |
1391 | f90c2bcd | Alex Williamson | static void ac97_exitfn (PCIDevice *dev) |
1392 | 83c406d9 | Avi Kivity | { |
1393 | 83c406d9 | Avi Kivity | AC97LinkState *s = DO_UPCAST (AC97LinkState, dev, dev); |
1394 | 83c406d9 | Avi Kivity | |
1395 | 83c406d9 | Avi Kivity | memory_region_destroy (&s->io_nam); |
1396 | 83c406d9 | Avi Kivity | memory_region_destroy (&s->io_nabm); |
1397 | 83c406d9 | Avi Kivity | } |
1398 | 83c406d9 | Avi Kivity | |
1399 | 36cd6f6f | Paolo Bonzini | static int ac97_init (PCIBus *bus) |
1400 | d88a76d1 | Gerd Hoffmann | { |
1401 | 0c3271c5 | Anthony Liguori | pci_create_simple (bus, -1, "AC97"); |
1402 | e5c9a13e | balrog | return 0; |
1403 | e5c9a13e | balrog | } |
1404 | d88a76d1 | Gerd Hoffmann | |
1405 | 40021f08 | Anthony Liguori | static Property ac97_properties[] = {
|
1406 | cf4dc461 | malc | DEFINE_PROP_UINT32 ("use_broken_id", AC97LinkState, use_broken_id, 0), |
1407 | cf4dc461 | malc | DEFINE_PROP_END_OF_LIST (), |
1408 | 40021f08 | Anthony Liguori | }; |
1409 | 40021f08 | Anthony Liguori | |
1410 | cf4dc461 | malc | static void ac97_class_init (ObjectClass *klass, void *data) |
1411 | 40021f08 | Anthony Liguori | { |
1412 | cf4dc461 | malc | DeviceClass *dc = DEVICE_CLASS (klass); |
1413 | cf4dc461 | malc | PCIDeviceClass *k = PCI_DEVICE_CLASS (klass); |
1414 | 40021f08 | Anthony Liguori | |
1415 | 40021f08 | Anthony Liguori | k->init = ac97_initfn; |
1416 | 40021f08 | Anthony Liguori | k->exit = ac97_exitfn; |
1417 | 40021f08 | Anthony Liguori | k->vendor_id = PCI_VENDOR_ID_INTEL; |
1418 | 40021f08 | Anthony Liguori | k->device_id = PCI_DEVICE_ID_INTEL_82801AA_5; |
1419 | 40021f08 | Anthony Liguori | k->revision = 0x01;
|
1420 | 40021f08 | Anthony Liguori | k->class_id = PCI_CLASS_MULTIMEDIA_AUDIO; |
1421 | 39bffca2 | Anthony Liguori | dc->desc = "Intel 82801AA AC97 Audio";
|
1422 | 39bffca2 | Anthony Liguori | dc->vmsd = &vmstate_ac97; |
1423 | 39bffca2 | Anthony Liguori | dc->props = ac97_properties; |
1424 | 40021f08 | Anthony Liguori | } |
1425 | 40021f08 | Anthony Liguori | |
1426 | 8c43a6f0 | Andreas Färber | static const TypeInfo ac97_info = { |
1427 | 39bffca2 | Anthony Liguori | .name = "AC97",
|
1428 | 39bffca2 | Anthony Liguori | .parent = TYPE_PCI_DEVICE, |
1429 | 39bffca2 | Anthony Liguori | .instance_size = sizeof (AC97LinkState),
|
1430 | 39bffca2 | Anthony Liguori | .class_init = ac97_class_init, |
1431 | d88a76d1 | Gerd Hoffmann | }; |
1432 | d88a76d1 | Gerd Hoffmann | |
1433 | 83f7d43a | Andreas Färber | static void ac97_register_types (void) |
1434 | d88a76d1 | Gerd Hoffmann | { |
1435 | cf4dc461 | malc | type_register_static (&ac97_info); |
1436 | 36cd6f6f | Paolo Bonzini | pci_register_soundhw("ac97", "Intel 82801AA AC97 Audio", ac97_init); |
1437 | d88a76d1 | Gerd Hoffmann | } |
1438 | d88a76d1 | Gerd Hoffmann | |
1439 | 83f7d43a | Andreas Färber | type_init (ac97_register_types) |