VirtualBox

source: vbox/trunk/src/VBox/Devices/Audio/DevIchIntelHDA.cpp@ 33939

Last change on this file since 33939 was 33881, checked in by vboxsync, 14 years ago

Audio/HDA: clean up of Immediate Command processing.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 84.0 KB
Line 
1/* $Id: DevIchIntelHDA.cpp 33881 2010-11-09 08:08:18Z vboxsync $ */
2/** @file
3 * DevIchIntelHD - VBox ICH Intel HD Audio Controller.
4 */
5
6/*
7 * Copyright (C) 2006-2010 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18/*******************************************************************************
19* Header Files *
20*******************************************************************************/
21#define LOG_GROUP LOG_GROUP_DEV_AUDIO
22#include <VBox/pdmdev.h>
23#include <iprt/assert.h>
24#include <iprt/uuid.h>
25#include <iprt/string.h>
26#include <iprt/mem.h>
27#include <iprt/asm.h>
28
29#include "../Builtins.h"
30
31extern "C" {
32#include "audio.h"
33}
34#include "DevCodec.h"
35
36#undef LOG_VOICES
37#ifndef VBOX
38//#define USE_MIXER
39#else
40#define USE_MIXER
41#endif
42#define VBOX_WITH_INTEL_HDA
43
44#define HDA_SSM_VERSION 1
45PDMBOTHCBDECL(int) hdaMMIORead(PPDMDEVINS pDevIns, void *pvUser, RTGCPHYS GCPhysAddr, void *pv, unsigned cb);
46PDMBOTHCBDECL(int) hdaMMIOWrite(PPDMDEVINS pDevIns, void *pvUser, RTGCPHYS GCPhysAddr, void *pv, unsigned cb);
47static DECLCALLBACK(void) hdaReset (PPDMDEVINS pDevIns);
48
49/* Registers */
50#define HDA_REG_IND_NAME(x) ICH6_HDA_REG_##x
51#define HDA_REG_FIELD_NAME(reg, x) ICH6_HDA_##reg##_##x
52#define HDA_REG_FIELD_MASK(reg, x) ICH6_HDA_##reg##_##x##_MASK
53#define HDA_REG_FIELD_FLAG_MASK(reg, x) RT_BIT(ICH6_HDA_##reg##_##x##_SHIFT)
54#define HDA_REG_FIELD_SHIFT(reg, x) ICH6_HDA_##reg##_##x##_SHIFT
55#define HDA_REG_IND(pState, x) ((pState)->au32Regs[(x)])
56#define HDA_REG(pState, x) (HDA_REG_IND((pState), HDA_REG_IND_NAME(x)))
57#define HDA_REG_VALUE(pState, reg, val) (HDA_REG((pState),reg) & (((HDA_REG_FIELD_MASK(reg, val))) << (HDA_REG_FIELD_SHIFT(reg, val))))
58#define HDA_REG_FLAG_VALUE(pState, reg, val) (HDA_REG((pState),reg) & (((HDA_REG_FIELD_FLAG_MASK(reg, val)))))
59#define HDA_REG_SVALUE(pState, reg, val) (HDA_REG_VALUE(pState, reg, val) >> (HDA_REG_FIELD_SHIFT(reg, val)))
60
61#define ICH6_HDA_REG_GCAP 0 /* range 0x00-0x01*/
62#define GCAP(pState) (HDA_REG((pState), GCAP))
63
64#define ICH6_HDA_REG_VMIN 1 /* range 0x02 */
65#define VMIN(pState) (HDA_REG((pState), VMIN))
66
67#define ICH6_HDA_REG_VMAJ 2 /* range 0x03 */
68#define VMAJ(pState) (HDA_REG((pState), VMAJ))
69
70#define ICH6_HDA_REG_OUTPAY 3 /* range 0x04-0x05 */
71#define OUTPAY(pState) (HDA_REG((pState), OUTPAY))
72
73#define ICH6_HDA_REG_INPAY 4 /* range 0x06-0x07 */
74#define INPAY(pState) (HDA_REG((pState), INPAY))
75
76#define ICH6_HDA_REG_GCTL (5)
77#define ICH6_HDA_GCTL_RST_SHIFT (0)
78#define ICH6_HDA_GCTL_FSH_SHIFT (1)
79#define ICH6_HDA_GCTL_UR_SHIFT (8)
80#define GCTL(pState) (HDA_REG((pState), GCTL))
81
82#define ICH6_HDA_REG_WAKEEN 6 /* 0x0C */
83#define WAKEEN(pState) (HDA_REG((pState), WAKEEN))
84
85#define ICH6_HDA_REG_STATESTS 7 /* range 0x0E */
86#define STATESTS(pState) (HDA_REG((pState), STATESTS))
87#define ICH6_HDA_STATES_SCSF 0x7
88
89#define ICH6_HDA_REG_GSTS 8 /* range 0x10-0x11*/
90#define ICH6_HDA_GSTS_FSH_SHIFT (1)
91#define GSTS(pState) (HDA_REG(pState, GSTS))
92
93#define ICH6_HDA_REG_INTCTL 9 /* 0x20 */
94#define ICH6_HDA_INTCTL_GIE_SHIFT 31
95#define ICH6_HDA_INTCTL_CIE_SHIFT 30
96#define ICH6_HDA_INTCTL_S0_SHIFT (0)
97#define ICH6_HDA_INTCTL_S1_SHIFT (1)
98#define ICH6_HDA_INTCTL_S2_SHIFT (2)
99#define ICH6_HDA_INTCTL_S3_SHIFT (3)
100#define ICH6_HDA_INTCTL_S4_SHIFT (4)
101#define ICH6_HDA_INTCTL_S5_SHIFT (5)
102#define ICH6_HDA_INTCTL_S6_SHIFT (6)
103#define ICH6_HDA_INTCTL_S7_SHIFT (7)
104#define INTCTL(pState) (HDA_REG((pState), INTCTL))
105#define INTCTL_GIE(pState) (HDA_REG_FLAG_VALUE(pState, INTCTL, GIE))
106#define INTCTL_CIE(pState) (HDA_REG_FLAG_VALUE(pState, INTCTL, CIE))
107#define INTCTL_SX(pState, X) (HDA_REG_FLAG_VALUE((pState), INTCTL, S##X))
108#define INTCTL_SALL(pState) (INTCTL((pState)) & 0xFF)
109
110/* Note: The HDA specification defines a SSYNC register at offset 0x38. The
111 * ICH6/ICH9 datahseet defines SSYNC at offset 0x34. The Linux HDA driver matches
112 * the datasheet.
113 */
114#define ICH6_HDA_REG_SSYNC 12 /* 0x34 */
115#define SSYNC(pState) (HDA_REG((pState), SSYNC))
116
117#define ICH6_HDA_REG_INTSTS 10 /* 0x24 */
118#define ICH6_HDA_INTSTS_GIS_SHIFT (31)
119#define ICH6_HDA_INTSTS_CIS_SHIFT (30)
120#define ICH6_HDA_INTSTS_S0_SHIFT (0)
121#define ICH6_HDA_INTSTS_S1_SHIFT (1)
122#define ICH6_HDA_INTSTS_S2_SHIFT (2)
123#define ICH6_HDA_INTSTS_S3_SHIFT (3)
124#define ICH6_HDA_INTSTS_S4_SHIFT (4)
125#define ICH6_HDA_INTSTS_S5_SHIFT (5)
126#define ICH6_HDA_INTSTS_S6_SHIFT (6)
127#define ICH6_HDA_INTSTS_S7_SHIFT (7)
128#define ICH6_HDA_INTSTS_S_MASK(num) RT_BIT(HDA_REG_FIELD_SHIFT(S##num))
129#define INTSTS(pState) (HDA_REG((pState), INTSTS))
130#define INTSTS_GIS(pState) (HDA_REG_FLAG_VALUE((pState), INTSTS, GIS)
131#define INTSTS_CIS(pState) (HDA_REG_FLAG_VALUE((pState), INTSTS, CIS)
132#define INTSTS_SX(pState, X) (HDA_REG_FLAG_VALUE(pState), INTSTS, S##X)
133#define INTSTS_SANY(pState) (INTSTS((pState)) & 0xFF)
134
135#define ICH6_HDA_REG_CORBLBASE 13 /* 0x40 */
136#define CORBLBASE(pState) (HDA_REG((pState), CORBLBASE))
137#define ICH6_HDA_REG_CORBUBASE 14 /* 0x44 */
138#define CORBUBASE(pState) (HDA_REG((pState), CORBUBASE))
139#define ICH6_HDA_REG_CORBWP 15 /* 48 */
140#define ICH6_HDA_REG_CORBRP 16 /* 4A */
141#define ICH6_HDA_CORBRP_RST_SHIFT 15
142#define ICH6_HDA_CORBRP_WP_SHIFT 0
143#define ICH6_HDA_CORBRP_WP_MASK 0xFF
144
145#define CORBRP(pState) (HDA_REG(pState, CORBRP))
146#define CORBWP(pState) (HDA_REG(pState, CORBWP))
147
148#define ICH6_HDA_REG_CORBCTL 17 /* 0x4C */
149#define ICH6_HDA_CORBCTL_DMA_SHIFT (1)
150#define ICH6_HDA_CORBCTL_CMEIE_SHIFT (0)
151
152#define CORBCTL(pState) (HDA_REG(pState, CORBCTL))
153
154
155#define ICH6_HDA_REG_CORBSTS 18 /* 0x4D */
156#define CORBSTS(pState) (HDA_REG(pState, CORBSTS))
157#define ICH6_HDA_CORBSTS_CMEI_SHIFT (0)
158
159#define ICH6_HDA_REG_CORBSIZE 19 /* 0x4E */
160#define ICH6_HDA_CORBSIZE_SZ_CAP 0xF0
161#define ICH6_HDA_CORBSIZE_SZ 0x3
162#define CORBSIZE_SZ(pState) (HDA_REG(pState, ICH6_HDA_REG_CORBSIZE) & ICH6_HDA_CORBSIZE_SZ)
163#define CORBSIZE_SZ_CAP(pState) (HDA_REG(pState, ICH6_HDA_REG_CORBSIZE) & ICH6_HDA_CORBSIZE_SZ_CAP)
164/* till ich 10 sizes of CORB and RIRB are hardcoded to 256 in real hw */
165
166#define ICH6_HDA_REG_RIRLBASE 20 /* 0x50 */
167#define RIRLBASE(pState) (HDA_REG((pState), RIRLBASE))
168
169#define ICH6_HDA_REG_RIRUBASE 21 /* 0x54 */
170#define RIRUBASE(pState) (HDA_REG((pState), RIRUBASE))
171
172#define ICH6_HDA_REG_RIRBWP 22 /* 0x58 */
173#define ICH6_HDA_RIRBWP_RST_SHIFT (15)
174#define ICH6_HDA_RIRBWP_WP_MASK 0xFF
175#define RIRBWP(pState) (HDA_REG(pState, RIRBWP))
176
177#define ICH6_HDA_REG_RINTCNT 23 /* 0x5A */
178#define RINTCNT(pState) (HDA_REG((pState), RINTCNT))
179#define RINTCNT_N(pState) (RINTCNT((pState)) & 0xff)
180
181#define ICH6_HDA_REG_RIRBCTL 24 /* 0x5C */
182#define ICH6_HDA_RIRBCTL_RIC_SHIFT (0)
183#define ICH6_HDA_RIRBCTL_DMA_SHIFT (1)
184#define ICH6_HDA_ROI_DMA_SHIFT (2)
185#define RIRBCTL(pState) (HDA_REG((pState), RIRBCTL))
186#define RIRBCTL_RIRB_RIC(pState) (HDA_REG_FLAG_VALUE(pState, RIRBCTL, RIC))
187#define RIRBCTL_RIRB_DMA(pState) (HDA_REG_FLAG_VALUE((pState), RIRBCTL, DMA)
188#define RIRBCTL_ROI(pState) (HDA_REG_FLAG_VALUE((pState), RIRBCTL, ROI))
189
190#define ICH6_HDA_REG_RIRBSTS 25 /* 0x5D */
191#define ICH6_HDA_RIRBSTS_RINTFL_SHIFT (0)
192#define ICH6_HDA_RIRBSTS_RIRBOIS_SHIFT (2)
193#define RIRBSTS(pState) (HDA_REG(pState, RIRBSTS))
194#define RIRBSTS_RINTFL(pState) (HDA_REG_FLAG_VALUE(pState, RIRBSTS, RINTFL))
195#define RIRBSTS_RIRBOIS(pState) (HDA_REG_FLAG_VALUE(pState, RIRBSTS, RIRBOIS))
196
197#define ICH6_HDA_REG_RIRBSIZE 26 /* 0x5E */
198#define ICH6_HDA_RIRBSIZE_SZ_CAP 0xF0
199#define ICH6_HDA_RIRBSIZE_SZ 0x3
200
201#define RIRBSIZE_SZ(pState) (HDA_REG(pState, ICH6_HDA_REG_RIRBSIZE) & ICH6_HDA_RIRBSIZE_SZ)
202#define RIRBSIZE_SZ_CAP(pState) (HDA_REG(pState, ICH6_HDA_REG_RIRBSIZE) & ICH6_HDA_RIRBSIZE_SZ_CAP)
203
204
205#define ICH6_HDA_REG_IC 27 /* 0x60 */
206#define IC(pState) (HDA_REG(pState, IC))
207#define ICH6_HDA_REG_IR 28 /* 0x64 */
208#define IR(pState) (HDA_REG(pState, IR))
209#define ICH6_HDA_REG_IRS 29 /* 0x68 */
210#define ICH6_HDA_IRS_ICB_SHIFT (0)
211#define ICH6_HDA_IRS_IRV_SHIFT (1)
212#define IRS(pState) (HDA_REG(pState, IRS))
213#define IRS_ICB(pState) (HDA_REG_FLAG_VALUE(pState, IRS, ICB))
214#define IRS_IRV(pState) (HDA_REG_FLAG_VALUE(pState, IRS, IRV))
215
216#define ICH6_HDA_REG_DPLBASE 30 /* 0x70 */
217#define DPLBASE(pState) (HDA_REG((pState), DPLBASE))
218#define ICH6_HDA_REG_DPUBASE 31 /* 0x74 */
219#define DPUBASE(pState) (HDA_REG((pState), DPUBASE))
220#define DPBASE_ENABLED 1
221#define DPBASE_ADDR_MASK (~0x7f)
222
223#define HDA_STREAM_REG_DEF(name, num) (ICH6_HDA_REG_SD##num##name)
224#define HDA_STREAM_REG(pState, name, num) (HDA_REG((pState), N_(HDA_STREAM_REG_DEF(name, num))))
225
226#define ICH6_HDA_REG_SD0CTL 32 /* 0x80 */
227#define ICH6_HDA_REG_SD1CTL (HDA_STREAM_REG_DEF(CTL, 0) + 10) /* 0xA0 */
228#define ICH6_HDA_REG_SD2CTL (HDA_STREAM_REG_DEF(CTL, 0) + 20) /* 0xC0 */
229#define ICH6_HDA_REG_SD3CTL (HDA_STREAM_REG_DEF(CTL, 0) + 30) /* 0xE0 */
230#define ICH6_HDA_REG_SD4CTL (HDA_STREAM_REG_DEF(CTL, 0) + 40) /* 0x100 */
231#define ICH6_HDA_REG_SD5CTL (HDA_STREAM_REG_DEF(CTL, 0) + 50) /* 0x120 */
232#define ICH6_HDA_REG_SD6CTL (HDA_STREAM_REG_DEF(CTL, 0) + 60) /* 0x140 */
233#define ICH6_HDA_REG_SD7CTL (HDA_STREAM_REG_DEF(CTL, 0) + 70) /* 0x160 */
234
235#define SD(func, num) SD##num##func
236#define SDCTL(pState, num) HDA_REG((pState), SD(CTL, num))
237#define SDCTL_NUM(pState, num) ((SDCTL((pState), num) & HDA_REG_FIELD_MASK(SDCTL,NUM)) >> HDA_REG_FIELD_SHIFT(SDCTL, NUM))
238#define ICH6_HDA_SDCTL_NUM_MASK (0xF)
239#define ICH6_HDA_SDCTL_NUM_SHIFT (20)
240#define ICH6_HDA_SDCTL_DEIE_SHIFT (4)
241#define ICH6_HDA_SDCTL_FEIE_SHIFT (3)
242#define ICH6_HDA_SDCTL_ICE_SHIFT (2)
243#define ICH6_HDA_SDCTL_RUN_SHIFT (1)
244#define ICH6_HDA_SDCTL_SRST_SHIFT (0)
245
246#define ICH6_HDA_REG_SD0STS 33 /* 0x83 */
247#define ICH6_HDA_REG_SD1STS (HDA_STREAM_REG_DEF(STS, 0) + 10) /* 0xA3 */
248#define ICH6_HDA_REG_SD2STS (HDA_STREAM_REG_DEF(STS, 0) + 20) /* 0xC3 */
249#define ICH6_HDA_REG_SD3STS (HDA_STREAM_REG_DEF(STS, 0) + 30) /* 0xE3 */
250#define ICH6_HDA_REG_SD4STS (HDA_STREAM_REG_DEF(STS, 0) + 40) /* 0x103 */
251#define ICH6_HDA_REG_SD5STS (HDA_STREAM_REG_DEF(STS, 0) + 50) /* 0x123 */
252#define ICH6_HDA_REG_SD6STS (HDA_STREAM_REG_DEF(STS, 0) + 60) /* 0x143 */
253#define ICH6_HDA_REG_SD7STS (HDA_STREAM_REG_DEF(STS, 0) + 70) /* 0x163 */
254
255#define SDSTS(pState, num) HDA_REG((pState), SD(STS, num))
256#define ICH6_HDA_SDSTS_FIFORDY_SHIFT (5)
257#define ICH6_HDA_SDSTS_DE_SHIFT (4)
258#define ICH6_HDA_SDSTS_FE_SHIFT (3)
259#define ICH6_HDA_SDSTS_BCIS_SHIFT (2)
260
261#define ICH6_HDA_REG_SD0LPIB 34 /* 0x84 */
262#define ICH6_HDA_REG_SD1LPIB (HDA_STREAM_REG_DEF(LPIB, 0) + 10) /* 0xA4 */
263#define ICH6_HDA_REG_SD2LPIB (HDA_STREAM_REG_DEF(LPIB, 0) + 20) /* 0xC4 */
264#define ICH6_HDA_REG_SD3LPIB (HDA_STREAM_REG_DEF(LPIB, 0) + 30) /* 0xE4 */
265#define ICH6_HDA_REG_SD4LPIB (HDA_STREAM_REG_DEF(LPIB, 0) + 40) /* 0x104 */
266#define ICH6_HDA_REG_SD5LPIB (HDA_STREAM_REG_DEF(LPIB, 0) + 50) /* 0x124 */
267#define ICH6_HDA_REG_SD6LPIB (HDA_STREAM_REG_DEF(LPIB, 0) + 60) /* 0x144 */
268#define ICH6_HDA_REG_SD7LPIB (HDA_STREAM_REG_DEF(LPIB, 0) + 70) /* 0x164 */
269
270#define SDLPIB(pState, num) HDA_REG((pState), SD(LPIB, num))
271
272#define ICH6_HDA_REG_SD0CBL 35 /* 0x88 */
273#define ICH6_HDA_REG_SD1CBL (HDA_STREAM_REG_DEF(CBL, 0) + 10) /* 0xA8 */
274#define ICH6_HDA_REG_SD2CBL (HDA_STREAM_REG_DEF(CBL, 0) + 20) /* 0xC8 */
275#define ICH6_HDA_REG_SD3CBL (HDA_STREAM_REG_DEF(CBL, 0) + 30) /* 0xE8 */
276#define ICH6_HDA_REG_SD4CBL (HDA_STREAM_REG_DEF(CBL, 0) + 40) /* 0x108 */
277#define ICH6_HDA_REG_SD5CBL (HDA_STREAM_REG_DEF(CBL, 0) + 50) /* 0x128 */
278#define ICH6_HDA_REG_SD6CBL (HDA_STREAM_REG_DEF(CBL, 0) + 60) /* 0x148 */
279#define ICH6_HDA_REG_SD7CBL (HDA_STREAM_REG_DEF(CBL, 0) + 70) /* 0x168 */
280
281#define SDLCBL(pState, num) HDA_REG((pState), SD(CBL, num))
282
283#define ICH6_HDA_REG_SD0LVI 36 /* 0x8C */
284#define ICH6_HDA_REG_SD1LVI (HDA_STREAM_REG_DEF(LVI, 0) + 10) /* 0xAC */
285#define ICH6_HDA_REG_SD2LVI (HDA_STREAM_REG_DEF(LVI, 0) + 20) /* 0xCC */
286#define ICH6_HDA_REG_SD3LVI (HDA_STREAM_REG_DEF(LVI, 0) + 30) /* 0xEC */
287#define ICH6_HDA_REG_SD4LVI (HDA_STREAM_REG_DEF(LVI, 0) + 40) /* 0x10C */
288#define ICH6_HDA_REG_SD5LVI (HDA_STREAM_REG_DEF(LVI, 0) + 50) /* 0x12C */
289#define ICH6_HDA_REG_SD6LVI (HDA_STREAM_REG_DEF(LVI, 0) + 60) /* 0x14C */
290#define ICH6_HDA_REG_SD7LVI (HDA_STREAM_REG_DEF(LVI, 0) + 70) /* 0x16C */
291
292#define SDLVI(pState, num) HDA_REG((pState), SD(LVI, num))
293
294#define ICH6_HDA_REG_SD0FIFOW 37 /* 0x8E */
295#define ICH6_HDA_REG_SD1FIFOW (HDA_STREAM_REG_DEF(FIFOW, 0) + 10) /* 0xAE */
296#define ICH6_HDA_REG_SD2FIFOW (HDA_STREAM_REG_DEF(FIFOW, 0) + 20) /* 0xCE */
297#define ICH6_HDA_REG_SD3FIFOW (HDA_STREAM_REG_DEF(FIFOW, 0) + 30) /* 0xEE */
298#define ICH6_HDA_REG_SD4FIFOW (HDA_STREAM_REG_DEF(FIFOW, 0) + 40) /* 0x10E */
299#define ICH6_HDA_REG_SD5FIFOW (HDA_STREAM_REG_DEF(FIFOW, 0) + 50) /* 0x12E */
300#define ICH6_HDA_REG_SD6FIFOW (HDA_STREAM_REG_DEF(FIFOW, 0) + 60) /* 0x14E */
301#define ICH6_HDA_REG_SD7FIFOW (HDA_STREAM_REG_DEF(FIFOW, 0) + 70) /* 0x16E */
302
303#define ICH6_HDA_REG_SD0FIFOS 38 /* 0x90 */
304#define ICH6_HDA_REG_SD1FIFOS (HDA_STREAM_REG_DEF(FIFOS, 0) + 10) /* 0xB0 */
305#define ICH6_HDA_REG_SD2FIFOS (HDA_STREAM_REG_DEF(FIFOS, 0) + 20) /* 0xD0 */
306#define ICH6_HDA_REG_SD3FIFOS (HDA_STREAM_REG_DEF(FIFOS, 0) + 30) /* 0xF0 */
307#define ICH6_HDA_REG_SD4FIFOS (HDA_STREAM_REG_DEF(FIFOS, 0) + 40) /* 0x110 */
308#define ICH6_HDA_REG_SD5FIFOS (HDA_STREAM_REG_DEF(FIFOS, 0) + 50) /* 0x130 */
309#define ICH6_HDA_REG_SD6FIFOS (HDA_STREAM_REG_DEF(FIFOS, 0) + 60) /* 0x150 */
310#define ICH6_HDA_REG_SD7FIFOS (HDA_STREAM_REG_DEF(FIFOS, 0) + 70) /* 0x170 */
311
312#define SDFIFOS(pState, num) HDA_REG((pState), SD(FIFOS, num))
313
314#define ICH6_HDA_REG_SD0FMT 39 /* 0x92 */
315#define ICH6_HDA_REG_SD1FMT (HDA_STREAM_REG_DEF(FMT, 0) + 10) /* 0xB2 */
316#define ICH6_HDA_REG_SD2FMT (HDA_STREAM_REG_DEF(FMT, 0) + 20) /* 0xD2 */
317#define ICH6_HDA_REG_SD3FMT (HDA_STREAM_REG_DEF(FMT, 0) + 30) /* 0xF2 */
318#define ICH6_HDA_REG_SD4FMT (HDA_STREAM_REG_DEF(FMT, 0) + 40) /* 0x112 */
319#define ICH6_HDA_REG_SD5FMT (HDA_STREAM_REG_DEF(FMT, 0) + 50) /* 0x132 */
320#define ICH6_HDA_REG_SD6FMT (HDA_STREAM_REG_DEF(FMT, 0) + 60) /* 0x152 */
321#define ICH6_HDA_REG_SD7FMT (HDA_STREAM_REG_DEF(FMT, 0) + 70) /* 0x172 */
322
323#define SDFMT(pState, num) (HDA_REG((pState), SD(FMT, num)))
324#define ICH6_HDA_SDFMT_BASE_RATE_SHIFT (14)
325#define ICH6_HDA_SDFMT_MULT_SHIFT (11)
326#define ICH6_HDA_SDFMT_MULT_MASK (0x7)
327#define ICH6_HDA_SDFMT_DIV_SHIFT (8)
328#define ICH6_HDA_SDFMT_DIV_MASK (0x7)
329#define SDFMT_BASE_RATE(pState, num) ((SDFMT(pState, num) & HDA_REG_FIELD_FLAG_MASK(SDFMT, BASE_RATE)) >> HDA_REG_FIELD_SHIFT(SDFMT, BASE_RATE))
330#define SDFMT_MULT(pState, num) ((SDFMT((pState), num) & HDA_REG_FIELD_MASK(SDFMT,MULT)) >> HDA_REG_FIELD_SHIFT(SDFMT, MULT))
331#define SDFMT_DIV(pState, num) ((SDFMT((pState), num) & HDA_REG_FIELD_MASK(SDFMT,DIV)) >> HDA_REG_FIELD_SHIFT(SDFMT, DIV))
332
333#define ICH6_HDA_REG_SD0BDPL 40 /* 0x98 */
334#define ICH6_HDA_REG_SD1BDPL (HDA_STREAM_REG_DEF(BDPL, 0) + 10) /* 0xB8 */
335#define ICH6_HDA_REG_SD2BDPL (HDA_STREAM_REG_DEF(BDPL, 0) + 20) /* 0xD8 */
336#define ICH6_HDA_REG_SD3BDPL (HDA_STREAM_REG_DEF(BDPL, 0) + 30) /* 0xF8 */
337#define ICH6_HDA_REG_SD4BDPL (HDA_STREAM_REG_DEF(BDPL, 0) + 40) /* 0x118 */
338#define ICH6_HDA_REG_SD5BDPL (HDA_STREAM_REG_DEF(BDPL, 0) + 50) /* 0x138 */
339#define ICH6_HDA_REG_SD6BDPL (HDA_STREAM_REG_DEF(BDPL, 0) + 60) /* 0x158 */
340#define ICH6_HDA_REG_SD7BDPL (HDA_STREAM_REG_DEF(BDPL, 0) + 70) /* 0x178 */
341
342#define SDBDPL(pState, num) HDA_REG((pState), SD(BDPL, num))
343
344#define ICH6_HDA_REG_SD0BDPU 41 /* 0x9C */
345#define ICH6_HDA_REG_SD1BDPU (HDA_STREAM_REG_DEF(BDPU, 0) + 10) /* 0xBC */
346#define ICH6_HDA_REG_SD2BDPU (HDA_STREAM_REG_DEF(BDPU, 0) + 20) /* 0xDC */
347#define ICH6_HDA_REG_SD3BDPU (HDA_STREAM_REG_DEF(BDPU, 0) + 30) /* 0xFC */
348#define ICH6_HDA_REG_SD4BDPU (HDA_STREAM_REG_DEF(BDPU, 0) + 40) /* 0x11C */
349#define ICH6_HDA_REG_SD5BDPU (HDA_STREAM_REG_DEF(BDPU, 0) + 50) /* 0x13C */
350#define ICH6_HDA_REG_SD6BDPU (HDA_STREAM_REG_DEF(BDPU, 0) + 60) /* 0x15C */
351#define ICH6_HDA_REG_SD7BDPU (HDA_STREAM_REG_DEF(BDPU, 0) + 70) /* 0x17C */
352
353#define SDBDPU(pState, num) HDA_REG((pState), SD(BDPU, num))
354
355/* Predicates */
356
357typedef struct HDABDLEDESC
358{
359 uint64_t u64BdleCviAddr;
360 uint32_t u32BdleMaxCvi;
361 uint32_t u32BdleCvi;
362 uint32_t u32BdleCviLen;
363 uint32_t u32BdleCviPos;
364 bool fBdleCviIoc;
365} HDABDLEDESC, *PHDABDLEDESC;
366
367typedef struct INTELHDLinkState
368{
369 /** Pointer to the device instance. */
370 PPDMDEVINSR3 pDevIns;
371 /** Pointer to the connector of the attached audio driver. */
372 PPDMIAUDIOCONNECTOR pDrv;
373 /** Pointer to the attached audio driver. */
374 PPDMIBASE pDrvBase;
375 /** The base interface for LUN\#0. */
376 PDMIBASE IBase;
377 RTGCPHYS addrMMReg;
378 uint32_t au32Regs[113];
379 HDABDLEDESC stInBdle;
380 HDABDLEDESC stOutBdle;
381 HDABDLEDESC stMicBdle;
382 /* Interrupt on completion */
383 bool fCviIoc;
384 uint64_t u64CORBBase;
385 uint64_t u64RIRBBase;
386 uint64_t u64DPBase;
387 /* pointer on CORB buf */
388 uint32_t *pu32CorbBuf;
389 /* size in bytes of CORB buf */
390 uint32_t cbCorbBuf;
391 /* pointer on RIRB buf */
392 uint64_t *pu64RirbBuf;
393 /* size in bytes of RIRB buf */
394 uint32_t cbRirbBuf;
395 /* indicates if HDA in reset. */
396 bool fInReset;
397 CODECState Codec;
398 uint8_t u8Counter;
399 uint8_t u8StreamsInReset;
400} INTELHDLinkState;
401
402#define ICH6_HDASTATE_2_DEVINS(pINTELHD) ((pINTELHD)->pDevIns)
403#define PCIDEV_2_ICH6_HDASTATE(pPciDev) ((PCIINTELHDLinkState *)(pPciDev))
404
405#define ISD0FMT_TO_AUDIO_SELECTOR(pState) (AUDIO_FORMAT_SELECTOR(&(pState)->Codec, In, \
406 SDFMT_BASE_RATE(pState, 0), SDFMT_MULT(pState, 0), SDFMT_DIV(pState, 0)))
407#define OSD0FMT_TO_AUDIO_SELECTOR(pState) (AUDIO_FORMAT_SELECTOR(&(pState)->Codec, Out, \
408 SDFMT_BASE_RATE(pState, 4), SDFMT_MULT(pState, 4), SDFMT_DIV(pState, 4)))
409
410
411
412
413typedef struct PCIINTELHDLinkState
414{
415 PCIDevice dev;
416 INTELHDLinkState hda;
417} PCIINTELHDLinkState;
418
419DECLCALLBACK(int)hdaRegReadUnimplemented(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t *pu32Value);
420DECLCALLBACK(int)hdaRegWriteUnimplemented(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t pu32Value);
421DECLCALLBACK(int)hdaRegReadGCTL(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t *pu32Value);
422DECLCALLBACK(int)hdaRegWriteGCTL(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t pu32Value);
423DECLCALLBACK(int)hdaRegReadSTATESTS(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t *pu32Value);
424DECLCALLBACK(int)hdaRegWriteSTATESTS(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t pu32Value);
425DECLCALLBACK(int)hdaRegReadGCAP(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t *pu32Value);
426DECLCALLBACK(int)hdaRegReadINTSTS(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t *pu32Value);
427DECLCALLBACK(int)hdaRegWriteINTSTS(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t pu32Value);
428DECLCALLBACK(int)hdaRegWriteCORBWP(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t pu32Value);
429DECLCALLBACK(int)hdaRegWriteCORBRP(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t u32Value);
430DECLCALLBACK(int)hdaRegWriteCORBCTL(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t u32Value);
431DECLCALLBACK(int)hdaRegWriteCORBSTS(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t u32Value);
432DECLCALLBACK(int)hdaRegWriteRIRBWP(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t pu32Value);
433DECLCALLBACK(int)hdaRegWriteRIRBSTS(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t u32Value);
434DECLCALLBACK(int)hdaRegWriteIRS(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t u32Value);
435DECLCALLBACK(int)hdaRegReadIRS(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t *pu32Value);
436DECLCALLBACK(int)hdaRegWriteSDCTL(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t u32Value);
437DECLCALLBACK(int)hdaRegReadSDCTL(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t *pu32Value);
438
439DECLCALLBACK(int)hdaRegWriteSDSTS(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t u32Value);
440DECLCALLBACK(int)hdaRegWriteSDLVI(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t u32Value);
441DECLCALLBACK(int)hdaRegWriteSDBDPL(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t u32Value);
442DECLCALLBACK(int)hdaRegWriteSDBDPU(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t u32Value);
443DECLCALLBACK(int)hdaRegWriteBase(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t u32Value);
444DECLCALLBACK(int)hdaRegReadU32(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t *pu32Value);
445DECLCALLBACK(int)hdaRegWriteU32(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t pu32Value);
446DECLCALLBACK(int)hdaRegReadU24(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t *pu32Value);
447DECLCALLBACK(int)hdaRegWriteU24(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t pu32Value);
448DECLCALLBACK(int)hdaRegReadU16(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t *pu32Value);
449DECLCALLBACK(int)hdaRegWriteU16(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t pu32Value);
450DECLCALLBACK(int)hdaRegReadU8(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t *pu32Value);
451DECLCALLBACK(int)hdaRegWriteU8(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t pu32Value);
452static int hdaLookup(INTELHDLinkState* pState, uint32_t u32Offset);
453static void fetch_bd(INTELHDLinkState *pState, PHDABDLEDESC pBdle, uint64_t u64BaseDMA);
454
455/* see 302349 p 6.2*/
456const static struct stIchIntelHDRegMap
457{
458 /** Register offset in the register space. */
459 uint32_t offset;
460 /** Size in bytes. Registers of size > 4 are in fact tables. */
461 uint32_t size;
462 /** Readable bits. */
463 uint32_t readable;
464 /** Writable bits. */
465 uint32_t writable;
466 /** Read callback. */
467 int (*pfnRead)(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t *pu32Value);
468 /** Write callback. */
469 int (*pfnWrite)(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t u32Value);
470 /** Abbreviated name. */
471 const char *abbrev;
472 /** Full name. */
473 const char *name;
474} s_ichIntelHDRegMap[] =
475{
476 /* offset size read mask write mask read callback write callback abbrev full name */
477 /*------- ------- ---------- ---------- ----------------------- ------------------------ ---------- ------------------------------*/
478 { 0x00000, 0x00002, 0x0000FFFB, 0x00000000, hdaRegReadGCAP , hdaRegWriteUnimplemented, "GCAP" , "Global Capabilities" },
479 { 0x00002, 0x00001, 0x000000FF, 0x00000000, hdaRegReadU8 , hdaRegWriteUnimplemented, "VMIN" , "Minor Version" },
480 { 0x00003, 0x00001, 0x000000FF, 0x00000000, hdaRegReadU8 , hdaRegWriteUnimplemented, "VMAJ" , "Major Version" },
481 { 0x00004, 0x00002, 0x0000FFFF, 0x00000000, hdaRegReadU16 , hdaRegWriteUnimplemented, "OUTPAY" , "Output Payload Capabilities" },
482 { 0x00006, 0x00002, 0x0000FFFF, 0x00000000, hdaRegReadU16 , hdaRegWriteUnimplemented, "INPAY" , "Input Payload Capabilities" },
483 { 0x00008, 0x00004, 0x00000103, 0x00000103, hdaRegReadGCTL , hdaRegWriteGCTL , "GCTL" , "Global Control" },
484 { 0x0000c, 0x00002, 0x00007FFF, 0x00007FFF, hdaRegReadU16 , hdaRegWriteU16 , "WAKEEN" , "Wake Enable" },
485 { 0x0000e, 0x00002, 0x00000007, 0x00000007, hdaRegReadU8 , hdaRegWriteSTATESTS , "STATESTS" , "State Change Status" },
486 { 0x00010, 0x00002, 0xFFFFFFFF, 0x00000000, hdaRegReadUnimplemented, hdaRegWriteUnimplemented, "GSTS" , "Global Status" },
487 { 0x00020, 0x00004, 0xC00000FF, 0xC00000FF, hdaRegReadU32 , hdaRegWriteU32 , "INTCTL" , "Interrupt Control" },
488 { 0x00024, 0x00004, 0xC00000FF, 0x00000000, hdaRegReadINTSTS , hdaRegWriteUnimplemented, "INTSTS" , "Interrupt Status" },
489 //** @todo r=michaln: Are guests really not reading the WALCLK register at all?
490 { 0x00030, 0x00004, 0xFFFFFFFF, 0x00000000, hdaRegReadUnimplemented, hdaRegWriteUnimplemented, "WALCLK" , "Wall Clock Counter" },
491 //** @todo r=michaln: Doesn't the SSYNC register need to actually stop the stream(s)?
492 { 0x00034, 0x00004, 0x000000FF, 0x000000FF, hdaRegReadU32 , hdaRegWriteU32 , "SSYNC" , "Stream Synchronization" },
493 { 0x00040, 0x00004, 0xFFFFFF80, 0xFFFFFF80, hdaRegReadU32 , hdaRegWriteBase , "CORBLBASE" , "CORB Lower Base Address" },
494 { 0x00044, 0x00004, 0xFFFFFFFF, 0xFFFFFFFF, hdaRegReadU32 , hdaRegWriteBase , "CORBUBASE" , "CORB Upper Base Address" },
495 { 0x00048, 0x00002, 0x000000FF, 0x000000FF, hdaRegReadU16 , hdaRegWriteCORBWP , "CORBWP" , "CORB Write Pointer" },
496 { 0x0004A, 0x00002, 0x000000FF, 0x000080FF, hdaRegReadU8 , hdaRegWriteCORBRP , "CORBRP" , "CORB Read Pointer" },
497 { 0x0004C, 0x00001, 0x00000003, 0x00000003, hdaRegReadU8 , hdaRegWriteCORBCTL , "CORBCTL" , "CORB Control" },
498 { 0x0004D, 0x00001, 0x00000001, 0x00000001, hdaRegReadU8 , hdaRegWriteCORBSTS , "CORBSTS" , "CORB Status" },
499 { 0x0004E, 0x00001, 0x000000F3, 0x00000000, hdaRegReadU8 , hdaRegWriteUnimplemented, "CORBSIZE" , "CORB Size" },
500 { 0x00050, 0x00004, 0xFFFFFF80, 0xFFFFFF80, hdaRegReadU32 , hdaRegWriteBase , "RIRBLBASE" , "RIRB Lower Base Address" },
501 { 0x00054, 0x00004, 0xFFFFFFFF, 0xFFFFFFFF, hdaRegReadU32 , hdaRegWriteBase , "RIRBUBASE" , "RIRB Upper Base Address" },
502 { 0x00058, 0x00002, 0x000000FF, 0x00008000, hdaRegReadU8, hdaRegWriteRIRBWP , "RIRBWP" , "RIRB Write Pointer" },
503 { 0x0005A, 0x00002, 0x000000FF, 0x000000FF, hdaRegReadU16 , hdaRegWriteU16 , "RINTCNT" , "Response Interrupt Count" },
504 { 0x0005C, 0x00001, 0x00000007, 0x00000007, hdaRegReadU8 , hdaRegWriteU8 , "RIRBCTL" , "RIRB Control" },
505 { 0x0005D, 0x00001, 0x00000005, 0x00000005, hdaRegReadU8 , hdaRegWriteRIRBSTS , "RIRBSTS" , "RIRB Status" },
506 { 0x0005E, 0x00001, 0x000000F3, 0x00000000, hdaRegReadU8 , hdaRegWriteUnimplemented, "RIRBSIZE" , "RIRB Size" },
507 { 0x00060, 0x00004, 0xFFFFFFFF, 0xFFFFFFFF, hdaRegReadU32 , hdaRegWriteU32 , "IC" , "Immediate Command" },
508 { 0x00064, 0x00004, 0x00000000, 0xFFFFFFFF, hdaRegReadU32 , hdaRegWriteUnimplemented, "IR" , "Immediate Response" },
509 { 0x00068, 0x00004, 0x00000002, 0x00000002, hdaRegReadIRS , hdaRegWriteIRS , "IRS" , "Immediate Command Status" },
510 { 0x00070, 0x00004, 0xFFFFFFFF, 0xFFFFFF81, hdaRegReadU32 , hdaRegWriteBase , "DPLBASE" , "DMA Position Lower Base" },
511 { 0x00074, 0x00004, 0xFFFFFFFF, 0xFFFFFFFF, hdaRegReadU32 , hdaRegWriteBase , "DPUBASE" , "DMA Position Upper Base" },
512
513 { 0x00080, 0x00003, 0x00FF001F, 0x00F0001F, hdaRegReadU24 , hdaRegWriteSDCTL , "ISD0CTL" , "Input Stream Descriptor 0 (ICD0) Control" },
514 { 0x00083, 0x00001, 0x0000001C, 0x0000003C, hdaRegReadU8 , hdaRegWriteSDSTS , "ISD0STS" , "ISD0 Status" },
515 { 0x00084, 0x00004, 0xFFFFFFFF, 0x00000000, hdaRegReadU32 , hdaRegWriteU32 , "ISD0LPIB" , "ISD0 Link Position In Buffer" },
516 { 0x00088, 0x00004, 0xFFFFFFFF, 0xFFFFFFFF, hdaRegReadU32 , hdaRegWriteU32 , "ISD0CBL" , "ISD0 Cyclic Buffer Length" },
517 { 0x0008C, 0x00002, 0x0000FFFF, 0x0000FFFF, hdaRegReadU16 , hdaRegWriteSDLVI , "ISD0LVI" , "ISD0 Last Valid Index" },
518 { 0x0008E, 0x00002, 0x00000005, 0x00000005, hdaRegReadU16 , hdaRegWriteU16 , "ISD0FIFOW", "ISD0 FIFO Watermark" },
519 { 0x00090, 0x00002, 0x000000FF, 0x000000FF, hdaRegReadU16 , hdaRegWriteU16 , "ISD0FIFOS", "ISD0 FIFO Size" },
520 { 0x00092, 0x00002, 0x00007F7F, 0x00007F7F, hdaRegReadU16 , hdaRegWriteU16 , "ISD0FMT" , "ISD0 Format" },
521 { 0x00098, 0x00004, 0xFFFFFF80, 0xFFFFFF80, hdaRegReadU32 , hdaRegWriteSDBDPL , "ISD0BDPL" , "ISD0 Buffer Descriptor List Pointer-Lower Base Address" },
522 { 0x0009C, 0x00004, 0xFFFFFFFF, 0xFFFFFFFF, hdaRegReadU32 , hdaRegWriteSDBDPU , "ISD0BDPU" , "ISD0 Buffer Descriptor List Pointer-Upper Base Address" },
523
524 { 0x000A0, 0x00003, 0x00FF001F, 0x00F0001F, hdaRegReadU24 , hdaRegWriteSDCTL , "ISD1CTL" , "Input Stream Descriptor 1 (ISD1) Control" },
525 { 0x000A3, 0x00001, 0x0000001C, 0x0000003C, hdaRegReadU8 , hdaRegWriteSDSTS , "ISD1STS" , "ISD1 Status" },
526 { 0x000A4, 0x00004, 0xFFFFFFFF, 0x00000000, hdaRegReadU32 , hdaRegWriteU32 , "ISD1LPIB" , "ISD1 Link Position In Buffer" },
527 { 0x000A8, 0x00004, 0xFFFFFFFF, 0xFFFFFFFF, hdaRegReadU32 , hdaRegWriteU32 , "ISD1CBL" , "ISD1 Cyclic Buffer Length" },
528 { 0x000AC, 0x00002, 0x0000FFFF, 0x0000FFFF, hdaRegReadU16 , hdaRegWriteSDLVI , "ISD1LVI" , "ISD1 Last Valid Index" },
529 { 0x000AE, 0x00002, 0x00000005, 0x00000005, hdaRegReadU16 , hdaRegWriteU16 , "ISD1FIFOW", "ISD1 FIFO Watermark" },
530 { 0x000B0, 0x00002, 0x000000FF, 0x000000FF, hdaRegReadU16 , hdaRegWriteU16 , "ISD1FIFOS", "ISD1 FIFO Size" },
531 { 0x000B2, 0x00002, 0x00007F7F, 0x00007F7F, hdaRegReadU16 , hdaRegWriteU16 , "ISD1FMT" , "ISD1 Format" },
532 { 0x000B8, 0x00004, 0xFFFFFF80, 0xFFFFFF80, hdaRegReadU32 , hdaRegWriteSDBDPL , "ISD1BDPL" , "ISD1 Buffer Descriptor List Pointer-Lower Base Address" },
533 { 0x000BC, 0x00004, 0xFFFFFFFF, 0xFFFFFFFF, hdaRegReadU32 , hdaRegWriteSDBDPU , "ISD1BDPU" , "ISD1 Buffer Descriptor List Pointer-Upper Base Address" },
534
535 { 0x000C0, 0x00003, 0x00FF001F, 0x00F0001F, hdaRegReadU24 , hdaRegWriteSDCTL , "ISD2CTL" , "Input Stream Descriptor 2 (ISD2) Control" },
536 { 0x000C3, 0x00001, 0x0000001C, 0x0000003C, hdaRegReadU8 , hdaRegWriteSDSTS , "ISD2STS" , "ISD2 Status" },
537 { 0x000C4, 0x00004, 0xFFFFFFFF, 0x00000000, hdaRegReadU32 , hdaRegWriteU32 , "ISD2LPIB" , "ISD2 Link Position In Buffer" },
538 { 0x000C8, 0x00004, 0xFFFFFFFF, 0xFFFFFFFF, hdaRegReadU32 , hdaRegWriteU32 , "ISD2CBL" , "ISD2 Cyclic Buffer Length" },
539 { 0x000CC, 0x00002, 0x0000FFFF, 0x0000FFFF, hdaRegReadU16 , hdaRegWriteSDLVI , "ISD2LVI" , "ISD2 Last Valid Index" },
540 { 0x000CE, 0x00002, 0x00000005, 0x00000005, hdaRegReadU16 , hdaRegWriteU16 , "ISD2FIFOW", "ISD2 FIFO Watermark" },
541 { 0x000D0, 0x00002, 0x000000FF, 0x000000FF, hdaRegReadU16 , hdaRegWriteU16 , "ISD2FIFOS", "ISD2 FIFO Size" },
542 { 0x000D2, 0x00002, 0x00007F7F, 0x00007F7F, hdaRegReadU16 , hdaRegWriteU16 , "ISD2FMT" , "ISD2 Format" },
543 { 0x000D8, 0x00004, 0xFFFFFF80, 0xFFFFFF80, hdaRegReadU32 , hdaRegWriteSDBDPL , "ISD2BDPL" , "ISD2 Buffer Descriptor List Pointer-Lower Base Address" },
544 { 0x000DC, 0x00004, 0xFFFFFFFF, 0xFFFFFFFF, hdaRegReadU32 , hdaRegWriteSDBDPU , "ISD2BDPU" , "ISD2 Buffer Descriptor List Pointer-Upper Base Address" },
545
546 { 0x000E0, 0x00003, 0x00FF001F, 0x00F0001F, hdaRegReadU24 , hdaRegWriteSDCTL , "ISD3CTL" , "Input Stream Descriptor 3 (ISD3) Control" },
547 { 0x000E3, 0x00001, 0x0000001C, 0x0000003C, hdaRegReadU8 , hdaRegWriteSDSTS , "ISD3STS" , "ISD3 Status" },
548 { 0x000E4, 0x00004, 0xFFFFFFFF, 0x00000000, hdaRegReadU32 , hdaRegWriteU32 , "ISD3LPIB" , "ISD3 Link Position In Buffer" },
549 { 0x000E8, 0x00004, 0xFFFFFFFF, 0xFFFFFFFF, hdaRegReadU32 , hdaRegWriteU32 , "ISD3CBL" , "ISD3 Cyclic Buffer Length" },
550 { 0x000EC, 0x00002, 0x0000FFFF, 0x0000FFFF, hdaRegReadU16 , hdaRegWriteSDLVI , "ISD3LVI" , "ISD3 Last Valid Index" },
551 { 0x000EE, 0x00002, 0x00000005, 0x00000005, hdaRegReadU16 , hdaRegWriteU16 , "ISD3FIFOW", "ISD3 FIFO Watermark" },
552 { 0x000F0, 0x00002, 0x000000FF, 0x000000FF, hdaRegReadU16 , hdaRegWriteU16 , "ISD3FIFOS", "ISD3 FIFO Size" },
553 { 0x000F2, 0x00002, 0x00007F7F, 0x00007F7F, hdaRegReadU16 , hdaRegWriteU16 , "ISD3FMT" , "ISD3 Format" },
554 { 0x000F8, 0x00004, 0xFFFFFF80, 0xFFFFFF80, hdaRegReadU32 , hdaRegWriteSDBDPL , "ISD3BDPL" , "ISD3 Buffer Descriptor List Pointer-Lower Base Address" },
555 { 0x000FC, 0x00004, 0xFFFFFFFF, 0xFFFFFFFF, hdaRegReadU32 , hdaRegWriteSDBDPU , "ISD3BDPU" , "ISD3 Buffer Descriptor List Pointer-Upper Base Address" },
556
557 { 0x00100, 0x00003, 0x00FF001F, 0x00F0001F, hdaRegReadSDCTL , hdaRegWriteSDCTL , "OSD0CTL" , "Input Stream Descriptor 0 (OSD0) Control" },
558 { 0x00103, 0x00001, 0x0000001C, 0x0000003C, hdaRegReadU8 , hdaRegWriteSDSTS , "OSD0STS" , "OSD0 Status" },
559 { 0x00104, 0x00004, 0xFFFFFFFF, 0x00000000, hdaRegReadU32 , hdaRegWriteU32 , "OSD0LPIB" , "OSD0 Link Position In Buffer" },
560 { 0x00108, 0x00004, 0xFFFFFFFF, 0xFFFFFFFF, hdaRegReadU32 , hdaRegWriteU32 , "OSD0CBL" , "OSD0 Cyclic Buffer Length" },
561 { 0x0010C, 0x00002, 0x0000FFFF, 0x0000FFFF, hdaRegReadU16 , hdaRegWriteSDLVI , "OSD0LVI" , "OSD0 Last Valid Index" },
562 { 0x0010E, 0x00002, 0x00000005, 0x00000005, hdaRegReadU16 , hdaRegWriteU16 , "OSD0FIFOW", "OSD0 FIFO Watermark" },
563 { 0x00110, 0x00002, 0x000000FF, 0x000000FF, hdaRegReadU16 , hdaRegWriteU16 , "OSD0FIFOS", "OSD0 FIFO Size" },
564 { 0x00112, 0x00002, 0x00007F7F, 0x00007F7F, hdaRegReadU16 , hdaRegWriteU16 , "OSD0FMT" , "OSD0 Format" },
565 { 0x00118, 0x00004, 0xFFFFFF80, 0xFFFFFF80, hdaRegReadU32 , hdaRegWriteSDBDPL , "OSD0BDPL" , "OSD0 Buffer Descriptor List Pointer-Lower Base Address" },
566 { 0x0011C, 0x00004, 0xFFFFFFFF, 0xFFFFFFFF, hdaRegReadU32 , hdaRegWriteSDBDPU , "OSD0BDPU" , "OSD0 Buffer Descriptor List Pointer-Upper Base Address" },
567
568 { 0x00120, 0x00003, 0x00FF001F, 0x00F0001F, hdaRegReadU24 , hdaRegWriteSDCTL , "OSD1CTL" , "Input Stream Descriptor 0 (OSD1) Control" },
569 { 0x00123, 0x00001, 0x0000001C, 0x0000003C, hdaRegReadU8 , hdaRegWriteSDSTS , "OSD1STS" , "OSD1 Status" },
570 { 0x00124, 0x00004, 0xFFFFFFFF, 0x00000000, hdaRegReadU32 , hdaRegWriteU32 , "OSD1LPIB" , "OSD1 Link Position In Buffer" },
571 { 0x00128, 0x00004, 0xFFFFFFFF, 0xFFFFFFFF, hdaRegReadU32 , hdaRegWriteU32 , "OSD1CBL" , "OSD1 Cyclic Buffer Length" },
572 { 0x0012C, 0x00002, 0x0000FFFF, 0x0000FFFF, hdaRegReadU16 , hdaRegWriteSDLVI , "OSD1LVI" , "OSD1 Last Valid Index" },
573 { 0x0012E, 0x00002, 0x00000005, 0x00000005, hdaRegReadU16 , hdaRegWriteU16 , "OSD1FIFOW", "OSD1 FIFO Watermark" },
574 { 0x00130, 0x00002, 0x000000FF, 0x000000FF, hdaRegReadU16 , hdaRegWriteU16 , "OSD1FIFOS", "OSD1 FIFO Size" },
575 { 0x00132, 0x00002, 0x00007F7F, 0x00007F7F, hdaRegReadU16 , hdaRegWriteU16 , "OSD1FMT" , "OSD1 Format" },
576 { 0x00138, 0x00004, 0xFFFFFF80, 0xFFFFFF80, hdaRegReadU32 , hdaRegWriteSDBDPL , "OSD1BDPL" , "OSD1 Buffer Descriptor List Pointer-Lower Base Address" },
577 { 0x0013C, 0x00004, 0xFFFFFFFF, 0xFFFFFFFF, hdaRegReadU32 , hdaRegWriteSDBDPU , "OSD1BDPU" , "OSD1 Buffer Descriptor List Pointer-Upper Base Address" },
578
579 { 0x00140, 0x00003, 0x00FF001F, 0x00F0001F, hdaRegReadU24 , hdaRegWriteSDCTL , "OSD2CTL" , "Input Stream Descriptor 0 (OSD2) Control" },
580 { 0x00143, 0x00001, 0x0000001C, 0x0000003C, hdaRegReadU8 , hdaRegWriteSDSTS , "OSD2STS" , "OSD2 Status" },
581 { 0x00144, 0x00004, 0xFFFFFFFF, 0x00000000, hdaRegReadU32 , hdaRegWriteU32 , "OSD2LPIB" , "OSD2 Link Position In Buffer" },
582 { 0x00148, 0x00004, 0xFFFFFFFF, 0xFFFFFFFF, hdaRegReadU32 , hdaRegWriteU32 , "OSD2CBL" , "OSD2 Cyclic Buffer Length" },
583 { 0x0014C, 0x00002, 0x0000FFFF, 0x0000FFFF, hdaRegReadU16 , hdaRegWriteSDLVI , "OSD2LVI" , "OSD2 Last Valid Index" },
584 { 0x0014E, 0x00002, 0x00000005, 0x00000005, hdaRegReadU16 , hdaRegWriteU16 , "OSD2FIFOW", "OSD2 FIFO Watermark" },
585 { 0x00150, 0x00002, 0x000000FF, 0x000000FF, hdaRegReadU16 , hdaRegWriteU16 , "OSD2FIFOS", "OSD2 FIFO Size" },
586 { 0x00152, 0x00002, 0x00007F7F, 0x00007F7F, hdaRegReadU16 , hdaRegWriteU16 , "OSD2FMT" , "OSD2 Format" },
587 { 0x00158, 0x00004, 0xFFFFFF80, 0xFFFFFF80, hdaRegReadU32 , hdaRegWriteSDBDPL , "OSD2BDPL" , "OSD2 Buffer Descriptor List Pointer-Lower Base Address" },
588 { 0x0015C, 0x00004, 0xFFFFFFFF, 0xFFFFFFFF, hdaRegReadU32 , hdaRegWriteSDBDPU , "OSD2BDPU" , "OSD2 Buffer Descriptor List Pointer-Upper Base Address" },
589
590 { 0x00160, 0x00003, 0x00FF001F, 0x00F0001F, hdaRegReadU24 , hdaRegWriteSDCTL , "OSD3CTL" , "Input Stream Descriptor 0 (OSD3) Control" },
591 { 0x00163, 0x00001, 0x0000001C, 0x0000003C, hdaRegReadU8 , hdaRegWriteSDSTS , "OSD3STS" , "OSD3 Status" },
592 { 0x00164, 0x00004, 0xFFFFFFFF, 0x00000000, hdaRegReadU32 , hdaRegWriteU32 , "OSD3LPIB" , "OSD3 Link Position In Buffer" },
593 { 0x00168, 0x00004, 0xFFFFFFFF, 0xFFFFFFFF, hdaRegReadU32 , hdaRegWriteU32 , "OSD3CBL" , "OSD3 Cyclic Buffer Length" },
594 { 0x0016C, 0x00002, 0x0000FFFF, 0x0000FFFF, hdaRegReadU16 , hdaRegWriteSDLVI , "OSD3LVI" , "OSD3 Last Valid Index" },
595 { 0x0016E, 0x00002, 0x00000005, 0x00000005, hdaRegReadU16 , hdaRegWriteU16 , "OSD3FIFOW", "OSD3 FIFO Watermark" },
596 { 0x00170, 0x00002, 0x000000FF, 0x000000FF, hdaRegReadU16 , hdaRegWriteU16 , "OSD3FIFOS", "OSD3 FIFO Size" },
597 { 0x00172, 0x00002, 0x00007F7F, 0x00007F7F, hdaRegReadU16 , hdaRegWriteU16 , "OSD3FMT" , "OSD3 Format" },
598 { 0x00178, 0x00004, 0xFFFFFF80, 0xFFFFFF80, hdaRegReadU32 , hdaRegWriteSDBDPL , "OSD3BDPL" , "OSD3 Buffer Descriptor List Pointer-Lower Base Address" },
599 { 0x0017C, 0x00004, 0xFFFFFFFF, 0xFFFFFFFF, hdaRegReadU32 , hdaRegWriteSDBDPU , "OSD3BDPU" , "OSD3 Buffer Descriptor List Pointer-Upper Base Address" },
600};
601
602static int hdaProcessInterrupt(INTELHDLinkState* pState)
603{
604#define IS_INTERRUPT_OCCURED_AND_ENABLED(pState, num) \
605 ( INTCTL_SX((pState), num) \
606 && (SDSTS(pState, num) & HDA_REG_FIELD_FLAG_MASK(SDSTS, BCIS)))
607 bool fIrq = false;
608 if( INTCTL_CIE(pState)
609 && ( RIRBSTS_RINTFL(pState)
610 || RIRBSTS_RIRBOIS(pState)
611 || STATESTS(pState)))
612 {
613 fIrq = true;
614 }
615 if ( IS_INTERRUPT_OCCURED_AND_ENABLED(pState, 0)
616 || IS_INTERRUPT_OCCURED_AND_ENABLED(pState, 4))
617 {
618 fIrq = true;
619 }
620 if (INTCTL_GIE(pState))
621 {
622 Log(("hda: irq %s\n", fIrq ? "asserted" : "deasserted"));
623 PDMDevHlpPCISetIrq(ICH6_HDASTATE_2_DEVINS(pState), 0 , fIrq);
624 }
625 return VINF_SUCCESS;
626}
627
628static int hdaLookup(INTELHDLinkState* pState, uint32_t u32Offset)
629{
630 int index = 0;
631 //** @todo r=michaln: A linear search of an array with over 100 elements is very inefficient.
632 for (;index < (int)(sizeof(s_ichIntelHDRegMap)/sizeof(s_ichIntelHDRegMap[0])); ++index)
633 {
634 if ( u32Offset >= s_ichIntelHDRegMap[index].offset
635 && u32Offset < s_ichIntelHDRegMap[index].offset + s_ichIntelHDRegMap[index].size)
636 {
637 return index;
638 }
639 }
640 /* Aliases HDA spec 3.3.45 */
641 switch(u32Offset)
642 {
643 case 0x2084:
644 return HDA_REG_IND_NAME(SD0LPIB);
645 case 0x20A4:
646 return HDA_REG_IND_NAME(SD1LPIB);
647 case 0x20C4:
648 return HDA_REG_IND_NAME(SD2LPIB);
649 case 0x20E4:
650 return HDA_REG_IND_NAME(SD3LPIB);
651 case 0x2104:
652 return HDA_REG_IND_NAME(SD4LPIB);
653 case 0x2124:
654 return HDA_REG_IND_NAME(SD5LPIB);
655 case 0x2144:
656 return HDA_REG_IND_NAME(SD6LPIB);
657 case 0x2164:
658 return HDA_REG_IND_NAME(SD7LPIB);
659 }
660 return -1;
661}
662
663static int hdaCmdSync(INTELHDLinkState *pState, bool fLocal)
664{
665 int rc = VINF_SUCCESS;
666 if (fLocal)
667 {
668 Assert((HDA_REG_FLAG_VALUE(pState, CORBCTL, DMA)));
669 rc = PDMDevHlpPhysRead(ICH6_HDASTATE_2_DEVINS(pState), pState->u64CORBBase, pState->pu32CorbBuf, pState->cbCorbBuf);
670 if (RT_FAILURE(rc))
671 AssertRCReturn(rc, rc);
672#ifdef DEBUG_CMD_BUFFER
673 uint8_t i = 0;
674 do
675 {
676 Log(("hda: corb%02x: ", i));
677 uint8_t j = 0;
678 do
679 {
680 const char *prefix;
681 if ((i + j) == CORBRP(pState))
682 prefix = "[R]";
683 else if ((i + j) == CORBWP(pState))
684 prefix = "[W]";
685 else
686 prefix = " "; /* three spaces */
687 Log(("%s%08x", prefix, pState->pu32CorbBuf[i + j]));
688 j++;
689 } while (j < 8);
690 Log(("\n"));
691 i += 8;
692 } while(i != 0);
693#endif
694 }
695 else
696 {
697 Assert((HDA_REG_FLAG_VALUE(pState, RIRBCTL, DMA)));
698 rc = PDMDevHlpPhysWrite(ICH6_HDASTATE_2_DEVINS(pState), pState->u64RIRBBase, pState->pu64RirbBuf, pState->cbRirbBuf);
699 if (RT_FAILURE(rc))
700 AssertRCReturn(rc, rc);
701#ifdef DEBUG_CMD_BUFFER
702 uint8_t i = 0;
703 do {
704 Log(("hda: rirb%02x: ", i));
705 uint8_t j = 0;
706 do {
707 const char *prefix;
708 if ((i + j) == RIRBWP(pState))
709 prefix = "[W]";
710 else
711 prefix = " ";
712 Log((" %s%016lx", prefix, pState->pu64RirbBuf[i + j]));
713 } while (++j < 8);
714 Log(("\n"));
715 i += 8;
716 } while (i != 0);
717#endif
718 }
719 return rc;
720}
721
722static int hdaCORBCmdProcess(INTELHDLinkState *pState)
723{
724 int rc;
725 uint8_t corbRp;
726 uint8_t corbWp;
727 uint8_t rirbWp;
728
729 PFNCODECVERBPROCESSOR pfn = (PFNCODECVERBPROCESSOR)NULL;
730
731 rc = hdaCmdSync(pState, true);
732 if (RT_FAILURE(rc))
733 AssertRCReturn(rc, rc);
734 corbRp = CORBRP(pState);
735 corbWp = CORBWP(pState);
736 rirbWp = RIRBWP(pState);
737 Assert((corbWp != corbRp));
738 Log(("hda: CORB(RP:%x, WP:%x) RIRBWP:%x\n", CORBRP(pState), CORBWP(pState), RIRBWP(pState)));
739 while (corbRp != corbWp)
740 {
741 uint32_t cmd;
742 uint64_t resp;
743 corbRp++;
744 cmd = pState->pu32CorbBuf[corbRp];
745 rc = (pState)->Codec.pfnLookup(&pState->Codec, cmd, &pfn);
746 if (RT_FAILURE(rc))
747 AssertRCReturn(rc, rc);
748 Assert(pfn);
749 (rirbWp)++;
750 rc = pfn(&pState->Codec, cmd, &resp);
751 if (RT_FAILURE(rc))
752 AssertRCReturn(rc, rc);
753 Log(("hda: verb:%08x->%016lx\n", cmd, resp));
754 if ( (resp & CODEC_RESPONSE_UNSOLICITED)
755 && !HDA_REG_FLAG_VALUE(pState, GCTL, UR))
756 {
757 Log(("hda: unexpected unsolicited response.\n"));
758 pState->au32Regs[ICH6_HDA_REG_CORBRP] = corbRp;
759 return rc;
760 }
761 pState->pu64RirbBuf[rirbWp] = resp;
762 pState->u8Counter++;
763 if (pState->u8Counter == RINTCNT_N(pState))
764 break;
765 }
766 pState->au32Regs[ICH6_HDA_REG_CORBRP] = corbRp;
767 pState->au32Regs[ICH6_HDA_REG_RIRBWP] = rirbWp;
768 rc = hdaCmdSync(pState, false);
769 Log(("hda: CORB(RP:%x, WP:%x) RIRBWP:%x\n", CORBRP(pState), CORBWP(pState), RIRBWP(pState)));
770 if (RIRBCTL_RIRB_RIC(pState))
771 {
772 RIRBSTS((pState)) |= HDA_REG_FIELD_FLAG_MASK(RIRBSTS,RINTFL);
773 pState->u8Counter = 0;
774 rc = hdaProcessInterrupt(pState);
775 }
776 if (RT_FAILURE(rc))
777 AssertRCReturn(rc, rc);
778 return rc;
779}
780
781static void hdaStreamReset(INTELHDLinkState *pState, uint32_t u32Offset)
782{
783 Log(("hda: reset of stream (%x) started\n", u32Offset));
784 Log(("hda: reset of stream (%x) finished\n", u32Offset));
785}
786
787
788DECLCALLBACK(int)hdaRegReadUnimplemented(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t *pu32Value)
789{
790 *pu32Value = 0;
791 return VINF_SUCCESS;
792}
793DECLCALLBACK(int)hdaRegWriteUnimplemented(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t u32Value)
794{
795 return VINF_SUCCESS;
796}
797/* U8 */
798DECLCALLBACK(int)hdaRegReadU8(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t *pu32Value)
799{
800 Assert(((pState->au32Regs[index] & s_ichIntelHDRegMap[index].readable) & 0xffffff00) == 0);
801 return hdaRegReadU32(pState, offset, index, pu32Value);
802}
803
804DECLCALLBACK(int)hdaRegWriteU8(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t u32Value)
805{
806 Assert(((u32Value & 0xffffff00) == 0));
807 return hdaRegWriteU32(pState, offset, index, u32Value);
808}
809/* U16 */
810DECLCALLBACK(int)hdaRegReadU16(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t *pu32Value)
811{
812 Assert(((pState->au32Regs[index] & s_ichIntelHDRegMap[index].readable) & 0xffff0000) == 0);
813 return hdaRegReadU32(pState, offset, index, pu32Value);
814}
815
816DECLCALLBACK(int)hdaRegWriteU16(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t u32Value)
817{
818 Assert(((u32Value & 0xffff0000) == 0));
819 return hdaRegWriteU32(pState, offset, index, u32Value);
820}
821
822/* U24 */
823DECLCALLBACK(int)hdaRegReadU24(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t *pu32Value)
824{
825 Assert(((pState->au32Regs[index] & s_ichIntelHDRegMap[index].readable) & 0xff000000) == 0);
826 return hdaRegReadU32(pState, offset, index, pu32Value);
827}
828
829DECLCALLBACK(int)hdaRegWriteU24(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t u32Value)
830{
831 Assert(((u32Value & 0xff000000) == 0));
832 return hdaRegWriteU32(pState, offset, index, u32Value);
833}
834/* U32 */
835DECLCALLBACK(int)hdaRegReadU32(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t *pu32Value)
836{
837 *pu32Value = pState->au32Regs[index] & s_ichIntelHDRegMap[index].readable;
838 return VINF_SUCCESS;
839}
840
841DECLCALLBACK(int)hdaRegWriteU32(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t u32Value)
842{
843 pState->au32Regs[index] = (u32Value & s_ichIntelHDRegMap[index].writable)
844 | (pState->au32Regs[index] & ~s_ichIntelHDRegMap[index].writable);
845 return VINF_SUCCESS;
846}
847
848DECLCALLBACK(int)hdaRegReadGCTL(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t *pu32Value)
849{
850 return hdaRegReadU32(pState, offset, index, pu32Value);
851}
852
853DECLCALLBACK(int)hdaRegWriteGCTL(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t u32Value)
854{
855 if (u32Value & HDA_REG_FIELD_FLAG_MASK(GCTL, RST))
856 {
857 /* exit reset state */
858 GCTL(pState) |= HDA_REG_FIELD_FLAG_MASK(GCTL, RST);
859 pState->fInReset = false;
860 }
861 else
862 {
863 /* enter reset state*/
864 if ( HDA_REG_FLAG_VALUE(pState, CORBCTL, DMA)
865 || HDA_REG_FLAG_VALUE(pState, RIRBCTL, DMA))
866 {
867 Log(("hda: HDA enters in reset with DMA(RIRB:%s, CORB:%s)\n",
868 HDA_REG_FLAG_VALUE(pState, CORBCTL, DMA) ? "on" : "off",
869 HDA_REG_FLAG_VALUE(pState, RIRBCTL, DMA) ? "on" : "off"));
870 }
871 hdaReset(ICH6_HDASTATE_2_DEVINS(pState));
872 GCTL(pState) &= ~HDA_REG_FIELD_FLAG_MASK(GCTL, RST);
873 pState->fInReset = true;
874 }
875 if (u32Value & HDA_REG_FIELD_FLAG_MASK(GCTL, FSH))
876 {
877 /* Flush: GSTS:1 set, see 6.2.6*/
878 GSTS(pState) |= HDA_REG_FIELD_FLAG_MASK(GSTS, FSH); /* set the flush state */
879 /* DPLBASE and DPUBASE, should be initialized with initial value (see 6.2.6)*/
880 }
881 return VINF_SUCCESS;
882}
883
884DECLCALLBACK(int)hdaRegWriteSTATESTS(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t u32Value)
885{
886 uint32_t v = pState->au32Regs[index];
887 uint32_t nv = u32Value & ICH6_HDA_STATES_SCSF;
888 pState->au32Regs[index] = (v ^ nv) & v; /* write of 1 clears corresponding bit */
889 return VINF_SUCCESS;
890}
891
892DECLCALLBACK(int)hdaRegReadINTSTS(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t *pu32Value)
893{
894 uint32_t v = 0;
895 if ( RIRBSTS_RIRBOIS(pState)
896 || RIRBSTS_RINTFL(pState)
897 || HDA_REG_FLAG_VALUE(pState, CORBSTS, CMEI)
898 || STATESTS(pState))
899 v |= RT_BIT(30);
900#define HDA_IS_STREAM_EVENT(pState, stream) \
901 ( (SDSTS((pState),stream) & HDA_REG_FIELD_FLAG_MASK(SDSTS, DE)) \
902 || (SDSTS((pState),stream) & HDA_REG_FIELD_FLAG_MASK(SDSTS, FE)) \
903 || (SDSTS((pState),stream) & HDA_REG_FIELD_FLAG_MASK(SDSTS, BCIS)))
904#define MARK_STREAM(pState, stream, v) do {(v) |= HDA_IS_STREAM_EVENT((pState),stream) ? RT_BIT((stream)) : 0;}while(0)
905 MARK_STREAM(pState, 0, v);
906 MARK_STREAM(pState, 1, v);
907 MARK_STREAM(pState, 2, v);
908 MARK_STREAM(pState, 3, v);
909 MARK_STREAM(pState, 4, v);
910 MARK_STREAM(pState, 5, v);
911 MARK_STREAM(pState, 6, v);
912 MARK_STREAM(pState, 7, v);
913 v |= v ? RT_BIT(31) : 0;
914 *pu32Value = v;
915 return VINF_SUCCESS;
916}
917
918DECLCALLBACK(int)hdaRegReadGCAP(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t *pu32Value)
919{
920 return hdaRegReadU16(pState, offset, index, pu32Value);
921}
922
923DECLCALLBACK(int)hdaRegWriteCORBRP(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t u32Value)
924{
925 if (u32Value & HDA_REG_FIELD_FLAG_MASK(CORBRP, RST))
926 CORBRP(pState) = 0;
927 else
928 return hdaRegWriteU8(pState, offset, index, u32Value);
929 return VINF_SUCCESS;
930}
931
932DECLCALLBACK(int)hdaRegWriteCORBCTL(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t u32Value)
933{
934 int rc = hdaRegWriteU8(pState, offset, index, u32Value);
935 AssertRC(rc);
936 if ( CORBWP(pState) != CORBRP(pState)
937 && HDA_REG_FLAG_VALUE(pState, CORBCTL, DMA) != 0)
938 return hdaCORBCmdProcess(pState);
939 return rc;
940}
941
942DECLCALLBACK(int)hdaRegWriteCORBSTS(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t u32Value)
943{
944 uint32_t v = CORBSTS(pState);
945 v = (v ^ u32Value) & v;
946 CORBSTS(pState) = v;
947 return VINF_SUCCESS;
948}
949
950DECLCALLBACK(int)hdaRegWriteCORBWP(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t u32Value)
951{
952 int rc;
953 rc = hdaRegWriteU16(pState, offset, index, u32Value);
954 if (RT_FAILURE(rc))
955 AssertRCReturn(rc, rc);
956 if (CORBWP(pState) == CORBRP(pState))
957 return VINF_SUCCESS;
958 if (!HDA_REG_FLAG_VALUE(pState, CORBCTL, DMA))
959 return VINF_SUCCESS;
960 rc = hdaCORBCmdProcess(pState);
961 return rc;
962}
963
964DECLCALLBACK(int)hdaRegReadSDCTL(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t *pu32Value)
965{
966 return hdaRegReadU24(pState, offset, index, pu32Value);
967}
968#define HDA_STREAM_BITMASK(offset) (1 << (((offset) - 0x80) >> 5))
969#define HDA_IS_STREAM_IN_RESET(pState, offset) ((pState)->u8StreamsInReset & HDA_STREAM_BITMASK((offset)))
970DECLCALLBACK(int)hdaRegWriteSDCTL(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t u32Value)
971{
972 if(u32Value & HDA_REG_FIELD_FLAG_MASK(SDCTL, SRST))
973 {
974 Log(("hda: guest has initiated hw stream reset\n"));
975 pState->u8StreamsInReset |= HDA_STREAM_BITMASK(offset);
976 hdaStreamReset(pState, offset);
977 HDA_REG_IND(pState, index) &= ~HDA_REG_FIELD_FLAG_MASK(SDCTL, SRST);
978 }
979 else if (HDA_IS_STREAM_IN_RESET(pState, offset))
980 {
981 Log(("hda: guest has initiated exit of stream reset\n"));
982 pState->u8StreamsInReset &= ~HDA_STREAM_BITMASK(offset);
983 HDA_REG_IND(pState, index) &= ~HDA_REG_FIELD_FLAG_MASK(SDCTL, SRST);
984 }
985 /* @todo: use right offsets for right streams */
986 if (u32Value & HDA_REG_FIELD_FLAG_MASK(SDCTL, RUN))
987 {
988 Log(("hda: DMA(%x) switched on\n", offset));
989 if (offset == 0x80)
990 AUD_set_active_in(ISD0FMT_TO_AUDIO_SELECTOR(pState), 1);
991 if (offset == 0x100)
992 {
993 uint64_t u64BaseDMA = SDBDPL(pState, 4);
994 u64BaseDMA |= (((uint64_t)SDBDPU(pState, 4)) << 32);
995 if (u64BaseDMA)
996 AUD_set_active_out(OSD0FMT_TO_AUDIO_SELECTOR(pState), 1);
997 }
998 }
999 else
1000 {
1001 Log(("hda: DMA(%x) switched off\n", offset));
1002 if (offset == 0x80)
1003 {
1004 AUD_set_active_in(ISD0FMT_TO_AUDIO_SELECTOR(pState), 0);
1005 }
1006 if (offset == 0x100)
1007 {
1008 SDSTS(pState, 4) &= ~(1<<5);
1009 AUD_set_active_out(OSD0FMT_TO_AUDIO_SELECTOR(pState), 0);
1010 }
1011 }
1012 int rc = hdaRegWriteU24(pState, offset, index, u32Value);
1013 if (RT_FAILURE(rc))
1014 AssertRCReturn(rc, VINF_SUCCESS);
1015 return rc;
1016}
1017
1018DECLCALLBACK(int)hdaRegWriteSDSTS(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t u32Value)
1019{
1020 uint32_t v = HDA_REG_IND(pState, index);
1021 v ^= (u32Value & v);
1022 HDA_REG_IND(pState, index) = v;
1023 hdaProcessInterrupt(pState);
1024#if 0
1025 if ( v != u32Value
1026 && (INTCTL_SALL(pState) & (1 << ((offset - 0x83) >> 5))))
1027 {
1028 int rc;
1029 rc = hdaProcessInterrupt(pState);
1030 if (RT_FAILURE(rc))
1031 AssertRCReturn(rc, rc);
1032 }
1033#endif
1034 return VINF_SUCCESS;
1035}
1036DECLCALLBACK(int)hdaRegWriteSDLVI(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t u32Value)
1037{
1038 int rc = hdaRegWriteU32(pState, offset, index, u32Value);
1039 if (RT_FAILURE(rc))
1040 AssertRCReturn(rc, VINF_SUCCESS);
1041 return rc;
1042}
1043
1044DECLCALLBACK(int)hdaRegWriteSDBDPL(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t u32Value)
1045{
1046 int rc = hdaRegWriteU32(pState, offset, index, u32Value);
1047 if (RT_FAILURE(rc))
1048 AssertRCReturn(rc, VINF_SUCCESS);
1049 return rc;
1050}
1051
1052DECLCALLBACK(int)hdaRegWriteSDBDPU(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t u32Value)
1053{
1054 int rc = hdaRegWriteU32(pState, offset, index, u32Value);
1055 if (RT_FAILURE(rc))
1056 AssertRCReturn(rc, VINF_SUCCESS);
1057 return rc;
1058}
1059
1060DECLCALLBACK(int)hdaRegReadIRS(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t *pu32Value)
1061{
1062 int rc = VINF_SUCCESS;
1063 /* regarding 3.4.3 we should mark IRS as busy in case CORB is active */
1064 if ( CORBWP(pState) != CORBRP(pState)
1065 || HDA_REG_FLAG_VALUE(pState, CORBCTL, DMA))
1066 IRS(pState) = HDA_REG_FIELD_FLAG_MASK(IRS, ICB); /* busy */
1067
1068 rc = hdaRegReadU32(pState, offset, index, pu32Value);
1069 return rc;
1070}
1071
1072DECLCALLBACK(int)hdaRegWriteIRS(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t u32Value)
1073{
1074 int rc = VINF_SUCCESS;
1075 uint64_t resp;
1076 PFNCODECVERBPROCESSOR pfn = (PFNCODECVERBPROCESSOR)NULL;
1077 /*
1078 * if guest set ICB bit of IRS register HDA should process verb in IC register and
1079 * writes response in IR register and set IRV (valid in case of success) bit of IRS register.
1080 */
1081 if ( u32Value & HDA_REG_FIELD_FLAG_MASK(IRS, ICB)
1082 && !IRS_ICB(pState))
1083 {
1084 uint32_t cmd = IC(pState);
1085 if (CORBWP(pState) != CORBRP(pState))
1086 {
1087 /*
1088 * 3.4.3 defines behaviour of immediate Command status register.
1089 */
1090 LogRel(("hda: guest has tried process immediate verb (%x) with active CORB\n", cmd));
1091 return rc;
1092 }
1093 IRS(pState) = HDA_REG_FIELD_FLAG_MASK(IRS, ICB); /* busy */
1094 Log(("hda: IC:%x\n", cmd));
1095 rc = pState->Codec.pfnLookup(&pState->Codec, cmd, &pfn);
1096 if (RT_FAILURE(rc))
1097 AssertRCReturn(rc, rc);
1098 rc = pfn(&pState->Codec, cmd, &resp);
1099 if (RT_FAILURE(rc))
1100 AssertRCReturn(rc, rc);
1101 IR(pState) = (uint32_t)resp;
1102 Log(("hda: IR:%x\n", IR(pState)));
1103 IRS(pState) = HDA_REG_FIELD_FLAG_MASK(IRS, IRV); /* result is ready */
1104 IRS(pState) &= ~HDA_REG_FIELD_FLAG_MASK(IRS, ICB); /* busy is clear */
1105 return rc;
1106 }
1107 /*
1108 * when guest's read the response it should clean the IRV bit of the IRS register.
1109 */
1110 if ( u32Value & HDA_REG_FIELD_FLAG_MASK(IRS, IRV)
1111 && IRS_IRV(pState))
1112 IRS(pState) &= ~HDA_REG_FIELD_FLAG_MASK(IRS, IRV);
1113 return rc;
1114}
1115
1116DECLCALLBACK(int)hdaRegWriteRIRBWP(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t u32Value)
1117{
1118 if (u32Value & HDA_REG_FIELD_FLAG_MASK(RIRBWP, RST))
1119 {
1120 RIRBWP(pState) = 0;
1121 }
1122 /*The rest of bits are O, see 6.2.22 */
1123 return VINF_SUCCESS;
1124}
1125
1126DECLCALLBACK(int)hdaRegWriteBase(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t u32Value)
1127{
1128 int rc = hdaRegWriteU32(pState, offset, index, u32Value);
1129 if (RT_FAILURE(rc))
1130 AssertRCReturn(rc, rc);
1131 switch(index)
1132 {
1133 case ICH6_HDA_REG_CORBLBASE:
1134 pState->u64CORBBase &= 0xFFFFFFFF00000000ULL;
1135 pState->u64CORBBase |= pState->au32Regs[index];
1136 break;
1137 case ICH6_HDA_REG_CORBUBASE:
1138 pState->u64CORBBase &= 0x00000000FFFFFFFFULL;
1139 pState->u64CORBBase |= ((uint64_t)pState->au32Regs[index] << 32);
1140 break;
1141 case ICH6_HDA_REG_RIRLBASE:
1142 pState->u64RIRBBase &= 0xFFFFFFFF00000000ULL;
1143 pState->u64RIRBBase |= pState->au32Regs[index];
1144 break;
1145 case ICH6_HDA_REG_RIRUBASE:
1146 pState->u64RIRBBase &= 0x00000000FFFFFFFFULL;
1147 pState->u64RIRBBase |= ((uint64_t)pState->au32Regs[index] << 32);
1148 break;
1149 case ICH6_HDA_REG_DPLBASE:
1150 /* @todo: first bit has special meaning */
1151 pState->u64DPBase &= 0xFFFFFFFF00000000ULL;
1152 pState->u64DPBase |= pState->au32Regs[index];
1153 break;
1154 case ICH6_HDA_REG_DPUBASE:
1155 pState->u64DPBase &= 0x00000000FFFFFFFFULL;
1156 pState->u64DPBase |= ((uint64_t)pState->au32Regs[index] << 32);
1157 break;
1158 default:
1159 AssertMsgFailed(("Invalid index"));
1160 }
1161 Log(("hda: CORB base:%llx RIRB base: %llx DP base: %llx\n", pState->u64CORBBase, pState->u64RIRBBase, pState->u64DPBase));
1162 return rc;
1163}
1164
1165DECLCALLBACK(int)hdaRegWriteRIRBSTS(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t u32Value)
1166{
1167 uint8_t nv = u32Value;
1168 uint8_t v = RIRBSTS(pState);
1169 RIRBSTS(pState) = (v ^ nv) & v;
1170
1171 return hdaProcessInterrupt(pState);
1172}
1173
1174static void dump_bd(INTELHDLinkState *pState, PHDABDLEDESC pBdle, uint64_t u64BaseDMA)
1175{
1176 uint64_t addr;
1177 uint32_t len;
1178 uint32_t ioc;
1179 uint8_t bdle[16];
1180 uint32_t counter;
1181 uint32_t i;
1182 uint32_t sum = 0;
1183 Assert(pBdle && pBdle->u32BdleMaxCvi);
1184 for (i = 0; i <= pBdle->u32BdleMaxCvi; ++i)
1185 {
1186 PDMDevHlpPhysRead(ICH6_HDASTATE_2_DEVINS(pState), u64BaseDMA + i*16, bdle, 16);
1187 addr = *(uint64_t *)bdle;
1188 len = *(uint32_t *)&bdle[8];
1189 ioc = *(uint32_t *)&bdle[12];
1190 Log(("hda: %s bdle[%d] a:%lx, len:%x, ioc:%d\n", (i == pBdle->u32BdleCvi? "[C]": " "), i, addr, len, ioc));
1191 sum += len;
1192 }
1193 Log(("hda: sum: %d\n", sum));
1194 for (i = 0; i < 8; ++i)
1195 {
1196 PDMDevHlpPhysRead(ICH6_HDASTATE_2_DEVINS(pState), (pState->u64DPBase & DPBASE_ADDR_MASK) + i*8, &counter, sizeof(&counter));
1197 Log(("hda: %s stream[%d] counter=%x\n", i == SDCTL_NUM(pState, 4) || i == SDCTL_NUM(pState, 0)? "[C]": " ",
1198 i , counter));
1199 }
1200}
1201static void fetch_bd(INTELHDLinkState *pState, PHDABDLEDESC pBdle, uint64_t u64BaseDMA)
1202{
1203 uint8_t bdle[16];
1204 Assert((u64BaseDMA && pBdle && pBdle->u32BdleMaxCvi));
1205 PDMDevHlpPhysRead(ICH6_HDASTATE_2_DEVINS(pState), u64BaseDMA + pBdle->u32BdleCvi*16, bdle, 16);
1206 pBdle->u64BdleCviAddr = *(uint64_t *)bdle;
1207 pBdle->u32BdleCviLen = *(uint32_t *)&bdle[8];
1208 pBdle->fBdleCviIoc = (*(uint32_t *)&bdle[12]) & 0x1;
1209 dump_bd(pState, pBdle, u64BaseDMA);
1210}
1211
1212static uint32_t hdaReadAudio(INTELHDLinkState *pState, int avail, bool *fStop)
1213{
1214 uint8_t tmpbuf[512];
1215 uint32_t temp;
1216 uint32_t u32Rest = 0;
1217 uint32_t cbRead = 0;
1218 uint32_t to_copy = 0;
1219 /* todo: add input line detection */
1220 PHDABDLEDESC pBdle = &pState->stInBdle;
1221 SWVoiceIn *voice = ISD0FMT_TO_AUDIO_SELECTOR(pState);
1222 u32Rest = pBdle->u32BdleCviLen - pBdle->u32BdleCviPos;
1223 temp = audio_MIN(u32Rest, (uint32_t)avail);
1224 if (!temp)
1225 {
1226 *fStop = true;
1227 return cbRead;
1228 }
1229 while (temp)
1230 {
1231 int copied;
1232 to_copy = audio_MIN(temp, SDFIFOS(pState, 4) & ~((1<<4) - 1));
1233 copied = AUD_read (voice, tmpbuf, to_copy);
1234 Log (("hda: read_audio max=%x to_copy=%x copied=%x\n",
1235 avail, to_copy, copied));
1236 if (!copied)
1237 {
1238 *fStop = true;
1239 break;
1240 }
1241 PDMDevHlpPhysWrite(ICH6_HDASTATE_2_DEVINS(pState), pBdle->u64BdleCviAddr + pBdle->u32BdleCviPos, tmpbuf, copied);
1242 temp -= copied;
1243 cbRead += copied;
1244 pBdle->u32BdleCviPos += copied;
1245 }
1246 return cbRead;
1247}
1248static uint32_t hdaWriteAudio(INTELHDLinkState *pState, int avail, bool *fStop)
1249{
1250 uint8_t tmpbuf[512];
1251 uint32_t temp;
1252 uint32_t u32Rest;
1253 uint32_t written = 0;
1254 int to_copy = 0;
1255 PHDABDLEDESC pBdle = &pState->stOutBdle;
1256 u32Rest = pBdle->u32BdleCviLen - pBdle->u32BdleCviPos;
1257 temp = audio_MIN(u32Rest, (uint32_t)avail);
1258 if (!temp)
1259 {
1260 *fStop = true;
1261 return written;
1262 }
1263 temp = audio_MIN(SDFIFOS(pState, 4) & ~((1<<4) - 1), temp);
1264 while (temp)
1265 {
1266 int copied;
1267 to_copy = audio_MIN(temp, 4096U);
1268 PDMDevHlpPhysRead(ICH6_HDASTATE_2_DEVINS(pState), pBdle->u64BdleCviAddr + pBdle->u32BdleCviPos, tmpbuf, to_copy);
1269 copied = AUD_write (OSD0FMT_TO_AUDIO_SELECTOR(pState), tmpbuf, to_copy);
1270 Log (("hda: write_audio max=%x to_copy=%x copied=%x\n",
1271 avail, to_copy, copied));
1272 if (!copied)
1273 {
1274 *fStop = true;
1275 break;
1276 }
1277 temp -= copied;
1278 written += copied;
1279 pBdle->u32BdleCviPos += copied;
1280 }
1281 return written;
1282}
1283
1284DECLCALLBACK(int) hdaCodecReset(CODECState *pCodecState)
1285{
1286 INTELHDLinkState *pState = (INTELHDLinkState *)pCodecState->pHDAState;
1287 return VINF_SUCCESS;
1288}
1289
1290DECLCALLBACK(void) hdaTransfer(CODECState *pCodecState, ENMSOUNDSOURCE src, int avail)
1291{
1292 bool fStop = false;
1293 uint64_t u64BaseDMA = 0;
1294 PHDABDLEDESC pBdle = NULL;
1295 INTELHDLinkState *pState = (INTELHDLinkState *)pCodecState->pHDAState;
1296 uint32_t nBytes;
1297 uint32_t u32Ctl;
1298 uint32_t *pu32Sts;
1299 uint8_t u8Strm;
1300 uint32_t *pu32Lpib;
1301 uint32_t u32Lcbl;
1302 uint32_t u32Fifos;
1303 switch (src)
1304 {
1305 case PO_INDEX:
1306 {
1307 u8Strm = 4;
1308 u32Ctl = SDCTL(pState, 4);
1309 u64BaseDMA = SDBDPL(pState, 4);
1310 u64BaseDMA |= (((uint64_t)SDBDPU(pState, 4)) << 32);
1311 pu32Lpib = &SDLPIB(pState, 4);
1312 pu32Sts = &SDSTS(pState, 4);
1313 u32Lcbl = SDLCBL(pState, 4);
1314 pBdle = &pState->stOutBdle;
1315 pBdle->u32BdleMaxCvi = SDLVI(pState, 4);
1316 break;
1317 }
1318 case PI_INDEX:
1319 {
1320 u8Strm = 0;
1321 u32Ctl = SDCTL(pState, 0);
1322 pu32Lpib = &SDLPIB(pState, 0);
1323 pu32Sts = &SDSTS(pState, 0);
1324 u32Lcbl = SDLCBL(pState, 0);
1325 u64BaseDMA = SDBDPL(pState, 0);
1326 u64BaseDMA |= (((uint64_t)SDBDPU(pState, 0)) << 32);
1327 pBdle = &pState->stInBdle;
1328 pBdle->u32BdleMaxCvi = SDLVI(pState, 0);
1329 break;
1330 }
1331 default:
1332 return;
1333 }
1334 if ( !(u32Ctl & HDA_REG_FIELD_FLAG_MASK(SDCTL, RUN))
1335 || !avail
1336 || !u64BaseDMA)
1337 return;
1338 /* Fetch the Buffer Descriptor Entry (BDE). */
1339 *pu32Sts |= HDA_REG_FIELD_FLAG_MASK(SDSTS, FIFORDY);
1340 fetch_bd(pState, pBdle, u64BaseDMA);
1341 while( avail && !fStop)
1342 {
1343 switch (src)
1344 {
1345 case PO_INDEX:
1346 nBytes = hdaWriteAudio(pState, avail, &fStop);
1347 break;
1348 case PI_INDEX:
1349 nBytes = hdaReadAudio(pState, avail, &fStop);
1350 break;
1351 default:
1352 nBytes = 0;
1353 fStop = true;
1354 AssertMsgFailed(("Unsupported"));
1355 }
1356 /* Update the buffer position and handle Cyclic Buffer Length (CBL) wraparound. */
1357 *pu32Lpib += nBytes;
1358 avail -= nBytes;
1359 if (*pu32Lpib >= u32Lcbl)
1360 *pu32Lpib -= u32Lcbl;
1361
1362 /* Optionally write back the current DMA position. */
1363 if (pState->u64DPBase & DPBASE_ENABLED)
1364 PDMDevHlpPhysWrite(ICH6_HDASTATE_2_DEVINS(pState),
1365 (pState->u64DPBase & DPBASE_ADDR_MASK) + u8Strm*8, pu32Lpib, sizeof(*pu32Lpib));
1366
1367 /* Process end of buffer condition. */
1368 if (pBdle->u32BdleCviPos == pBdle->u32BdleCviLen)
1369 {
1370 if (pBdle->fBdleCviIoc)
1371 {
1372 *pu32Sts |= HDA_REG_FIELD_FLAG_MASK(SDSTS, BCIS);
1373 hdaProcessInterrupt(pState);
1374 }
1375 pBdle->u32BdleCviPos = 0;
1376 pBdle->u32BdleCvi++;
1377 if (pBdle->u32BdleCvi == pBdle->u32BdleMaxCvi + 1)
1378 {
1379 pBdle->u32BdleCvi = 0;
1380 }
1381 fStop = true; /* Give the guest a chance to refill (or empty) buffers. */
1382 }
1383 }
1384 *pu32Sts &= ~HDA_REG_FIELD_FLAG_MASK(SDSTS, FIFORDY);
1385}
1386
1387/**
1388 * Handle register read operation.
1389 *
1390 * Looks up and calls appropriate handler.
1391 *
1392 * @note: while implementation was detected so called "forgotten" or "hole" registers
1393 * which description is missed in RPM, datasheet or spec.
1394 *
1395 * @returns VBox status code.
1396 *
1397 * @param pState The device state structure.
1398 * @param uOffset Register offset in memory-mapped frame.
1399 * @param pv Where to fetch the value.
1400 * @param cb Number of bytes to write.
1401 * @thread EMT
1402 */
1403PDMBOTHCBDECL(int) hdaMMIORead(PPDMDEVINS pDevIns, void *pvUser, RTGCPHYS GCPhysAddr, void *pv, unsigned cb)
1404{
1405 int rc = VINF_SUCCESS;
1406 PCIINTELHDLinkState *pThis = PDMINS_2_DATA(pDevIns, PCIINTELHDLinkState *);
1407 uint32_t u32Offset = GCPhysAddr - pThis->hda.addrMMReg;
1408 int index = hdaLookup(&pThis->hda, u32Offset);
1409 if (pThis->hda.fInReset && index != ICH6_HDA_REG_GCTL)
1410 {
1411 Log(("hda: access to registers except GCTL is blocked while reset\n"));
1412 }
1413 if ( index == -1
1414 || cb > 4)
1415 {
1416 LogRel(("hda: Invalid read access @0x%x(of bytes:%d)\n", u32Offset, cb));
1417 }
1418 if (index != -1)
1419 {
1420 uint32_t mask = 0;
1421 uint32_t shift = (u32Offset - s_ichIntelHDRegMap[index].offset) % sizeof(uint32_t) * 8;
1422 uint32_t v = 0;
1423 switch(cb)
1424 {
1425 case 1: mask = 0x000000ff; break;
1426 case 2: mask = 0x0000ffff; break;
1427 case 3: mask = 0x00ffffff; break;
1428 case 4: mask = 0xffffffff; break;
1429 }
1430 mask <<= shift;
1431 rc = s_ichIntelHDRegMap[index].pfnRead(&pThis->hda, u32Offset, index, &v);
1432 *(uint32_t *)pv = (v & mask) >> shift;
1433 Log(("hda: read %s[%x/%x]\n", s_ichIntelHDRegMap[index].abbrev, v, *(uint32_t *)pv));
1434 return rc;
1435 }
1436 *(uint32_t *)pv = 0xFF;
1437 Log(("hda: hole at %X is accessed for read\n", u32Offset));
1438 return rc;
1439}
1440
1441/**
1442 * Handle register write operation.
1443 *
1444 * Looks up and calls appropriate handler.
1445 *
1446 * @returns VBox status code.
1447 *
1448 * @param pState The device state structure.
1449 * @param uOffset Register offset in memory-mapped frame.
1450 * @param pv Where to fetch the value.
1451 * @param cb Number of bytes to write.
1452 * @thread EMT
1453 */
1454PDMBOTHCBDECL(int) hdaMMIOWrite(PPDMDEVINS pDevIns, void *pvUser, RTGCPHYS GCPhysAddr, void *pv, unsigned cb)
1455{
1456 int rc = VINF_SUCCESS;
1457 PCIINTELHDLinkState *pThis = PDMINS_2_DATA(pDevIns, PCIINTELHDLinkState *);
1458 uint32_t u32Offset = GCPhysAddr - pThis->hda.addrMMReg;
1459 int index = hdaLookup(&pThis->hda, u32Offset);
1460 if (pThis->hda.fInReset && index != ICH6_HDA_REG_GCTL)
1461 {
1462 Log(("hda: access to registers except GCTL is blocked while reset\n"));
1463 }
1464 if ( index == -1
1465 || cb > 4)
1466 {
1467 LogRel(("hda: Invalid write access @0x%x(of bytes:%d)\n", u32Offset, cb));
1468 }
1469 if (index != -1)
1470 {
1471 uint32_t v = pThis->hda.au32Regs[index];
1472 uint32_t mask = 0;
1473 uint32_t shift = (u32Offset - s_ichIntelHDRegMap[index].offset) % sizeof(uint32_t) * 8;
1474 switch(cb)
1475 {
1476 case 1: mask = 0xffffff00; break;
1477 case 2: mask = 0xffff0000; break;
1478 case 3: mask = 0xff000000; break;
1479 case 4: mask = 0x00000000; break;
1480 }
1481 mask <<= shift;
1482 *(uint32_t *)pv = ((v & mask) | (*(uint32_t *)pv & ~mask)) >> shift;
1483 rc = s_ichIntelHDRegMap[index].pfnWrite(&pThis->hda, u32Offset, index, *(uint32_t *)pv);
1484 Log(("hda: write %s:(%x) %x => %x\n", s_ichIntelHDRegMap[index].abbrev, *(uint32_t *)pv, v, pThis->hda.au32Regs[index]));
1485 return rc;
1486 }
1487 Log(("hda: hole at %X is accessed for write\n", u32Offset));
1488 return rc;
1489}
1490
1491/**
1492 * Callback function for mapping a PCI I/O region.
1493 *
1494 * @return VBox status code.
1495 * @param pPciDev Pointer to PCI device.
1496 * Use pPciDev->pDevIns to get the device instance.
1497 * @param iRegion The region number.
1498 * @param GCPhysAddress Physical address of the region.
1499 * If iType is PCI_ADDRESS_SPACE_IO, this is an
1500 * I/O port, else it's a physical address.
1501 * This address is *NOT* relative
1502 * to pci_mem_base like earlier!
1503 * @param enmType One of the PCI_ADDRESS_SPACE_* values.
1504 */
1505static DECLCALLBACK(int) hdaMap (PPCIDEVICE pPciDev, int iRegion,
1506 RTGCPHYS GCPhysAddress, uint32_t cb,
1507 PCIADDRESSSPACE enmType)
1508{
1509 int rc;
1510 PPDMDEVINS pDevIns = pPciDev->pDevIns;
1511 RTIOPORT Port = (RTIOPORT)GCPhysAddress;
1512 PCIINTELHDLinkState *pThis = PCIDEV_2_ICH6_HDASTATE(pPciDev);
1513
1514 Assert(enmType == PCI_ADDRESS_SPACE_MEM);
1515 rc = PDMDevHlpMMIORegister(pPciDev->pDevIns, GCPhysAddress, cb, 0,
1516 hdaMMIOWrite, hdaMMIORead, NULL, "ICH6_HDA");
1517
1518 if (RT_FAILURE(rc))
1519 return rc;
1520
1521 pThis->hda.addrMMReg = GCPhysAddress;
1522 return VINF_SUCCESS;
1523}
1524
1525/**
1526 * Saves a state of the HDA device.
1527 *
1528 * @returns VBox status code.
1529 * @param pDevIns The device instance.
1530 * @param pSSMHandle The handle to save the state to.
1531 */
1532static DECLCALLBACK(int) hdaSaveExec (PPDMDEVINS pDevIns, PSSMHANDLE pSSMHandle)
1533{
1534 PCIINTELHDLinkState *pThis = PDMINS_2_DATA(pDevIns, PCIINTELHDLinkState *);
1535 /* Save Codec nodes states */
1536 codecSaveState(&pThis->hda.Codec, pSSMHandle);
1537 /* Save MMIO registers */
1538 SSMR3PutMem (pSSMHandle, pThis->hda.au32Regs, sizeof (pThis->hda.au32Regs));
1539 /* Save HDA dma counters */
1540 SSMR3PutMem (pSSMHandle, &pThis->hda.stOutBdle, sizeof (HDABDLEDESC));
1541 SSMR3PutMem (pSSMHandle, &pThis->hda.stMicBdle, sizeof (HDABDLEDESC));
1542 SSMR3PutMem (pSSMHandle, &pThis->hda.stInBdle, sizeof (HDABDLEDESC));
1543 return VINF_SUCCESS;
1544}
1545
1546/**
1547 * Loads a saved HDA device state.
1548 *
1549 * @returns VBox status code.
1550 * @param pDevIns The device instance.
1551 * @param pSSMHandle The handle to the saved state.
1552 * @param uVersion The data unit version number.
1553 * @param uPass The data pass.
1554 */
1555static DECLCALLBACK(int) hdaLoadExec (PPDMDEVINS pDevIns, PSSMHANDLE pSSMHandle,
1556 uint32_t uVersion, uint32_t uPass)
1557{
1558 PCIINTELHDLinkState *pThis = PDMINS_2_DATA(pDevIns, PCIINTELHDLinkState *);
1559 /* Load Codec nodes states */
1560 AssertMsgReturn (uVersion == HDA_SSM_VERSION, ("%d\n", uVersion), VERR_SSM_UNSUPPORTED_DATA_UNIT_VERSION);
1561 Assert (uPass == SSM_PASS_FINAL); NOREF(uPass);
1562
1563 codecLoadState(&pThis->hda.Codec, pSSMHandle);
1564 /* Load MMIO registers */
1565 SSMR3GetMem (pSSMHandle, pThis->hda.au32Regs, sizeof (pThis->hda.au32Regs));
1566 /* Load HDA dma counters */
1567 SSMR3GetMem (pSSMHandle, &pThis->hda.stOutBdle, sizeof (HDABDLEDESC));
1568 SSMR3GetMem (pSSMHandle, &pThis->hda.stMicBdle, sizeof (HDABDLEDESC));
1569 SSMR3GetMem (pSSMHandle, &pThis->hda.stInBdle, sizeof (HDABDLEDESC));
1570
1571 AUD_set_active_in(ISD0FMT_TO_AUDIO_SELECTOR(&pThis->hda), SDCTL(&pThis->hda, 0) & HDA_REG_FIELD_FLAG_MASK(SDCTL, RUN));
1572 AUD_set_active_out(OSD0FMT_TO_AUDIO_SELECTOR(&pThis->hda), SDCTL(&pThis->hda, 4) & HDA_REG_FIELD_FLAG_MASK(SDCTL, RUN));
1573
1574 pThis->hda.u64CORBBase = CORBLBASE(&pThis->hda);
1575 pThis->hda.u64CORBBase |= ((uint64_t)CORBUBASE(&pThis->hda)) << 32;
1576 pThis->hda.u64RIRBBase = RIRLBASE(&pThis->hda);
1577 pThis->hda.u64RIRBBase |= ((uint64_t)RIRUBASE(&pThis->hda)) << 32;
1578 pThis->hda.u64DPBase = DPLBASE(&pThis->hda);
1579 pThis->hda.u64DPBase |= ((uint64_t)DPUBASE(&pThis->hda)) << 32;
1580 return VINF_SUCCESS;
1581}
1582
1583/**
1584 * Reset notification.
1585 *
1586 * @returns VBox status.
1587 * @param pDevIns The device instance data.
1588 *
1589 * @remark The original sources didn't install a reset handler, but it seems to
1590 * make sense to me so we'll do it.
1591 */
1592static DECLCALLBACK(void) hdaReset (PPDMDEVINS pDevIns)
1593{
1594 PCIINTELHDLinkState *pThis = PDMINS_2_DATA(pDevIns, PCIINTELHDLinkState *);
1595 GCAP(&pThis->hda) = 0x4401; /* see 6.2.1 */
1596 VMIN(&pThis->hda) = 0x00; /* see 6.2.2 */
1597 VMAJ(&pThis->hda) = 0x01; /* see 6.2.3 */
1598 VMAJ(&pThis->hda) = 0x01; /* see 6.2.3 */
1599 OUTPAY(&pThis->hda) = 0x003C; /* see 6.2.4 */
1600 INPAY(&pThis->hda) = 0x001D; /* see 6.2.5 */
1601 pThis->hda.au32Regs[ICH6_HDA_REG_CORBSIZE] = 0x42; /* see 6.2.1 */
1602 pThis->hda.au32Regs[ICH6_HDA_REG_RIRBSIZE] = 0x42; /* see 6.2.1 */
1603 CORBRP(&pThis->hda) = 0x0;
1604 RIRBWP(&pThis->hda) = 0x0;
1605
1606 Log(("hda: inter HDA reset.\n"));
1607 pThis->hda.cbCorbBuf = 256 * sizeof(uint32_t);
1608
1609 if (pThis->hda.pu32CorbBuf)
1610 memset(pThis->hda.pu32CorbBuf, 0, pThis->hda.cbCorbBuf);
1611 else
1612 pThis->hda.pu32CorbBuf = (uint32_t *)RTMemAllocZ(pThis->hda.cbCorbBuf);
1613
1614 pThis->hda.cbRirbBuf = 256 * sizeof(uint64_t);
1615 if (pThis->hda.pu64RirbBuf)
1616 memset(pThis->hda.pu64RirbBuf, 0, pThis->hda.cbRirbBuf);
1617 else
1618 pThis->hda.pu64RirbBuf = (uint64_t *)RTMemAllocZ(pThis->hda.cbRirbBuf);
1619
1620 /* According to ICH6 datasheet, 0x40000 is default value for stream descriptor register 23:20
1621 * bits are reserved for stream number 18.2.33 */
1622 SDCTL(&pThis->hda, 0) = 0x40000;
1623 SDCTL(&pThis->hda, 1) = 0x40000;
1624 SDCTL(&pThis->hda, 2) = 0x40000;
1625 SDCTL(&pThis->hda, 3) = 0x40000;
1626 SDCTL(&pThis->hda, 4) = 0x40000;
1627 SDCTL(&pThis->hda, 5) = 0x40000;
1628 SDCTL(&pThis->hda, 6) = 0x40000;
1629 SDCTL(&pThis->hda, 7) = 0x40000;
1630
1631 /* ICH6 defines default values (0x77 for input and 0xBF for output descriptors) of FIFO size. 18.2.39 */
1632 SDFIFOS(&pThis->hda, 0) = 0x77;
1633 SDFIFOS(&pThis->hda, 1) = 0x77;
1634 SDFIFOS(&pThis->hda, 2) = 0x77;
1635 SDFIFOS(&pThis->hda, 3) = 0x77;
1636 SDFIFOS(&pThis->hda, 4) = 0xBF;
1637 SDFIFOS(&pThis->hda, 5) = 0xBF;
1638 SDFIFOS(&pThis->hda, 6) = 0xBF;
1639 SDFIFOS(&pThis->hda, 7) = 0xBF;
1640
1641 /* emulateion of codec "wake up" HDA spec (5.5.1 and 6.5)*/
1642 STATESTS(&pThis->hda) = 0x1;
1643
1644 Log(("hda: reset finished\n"));
1645}
1646
1647/**
1648 * @interface_method_impl{PDMIBASE,pfnQueryInterface}
1649 */
1650static DECLCALLBACK(void *) hdaQueryInterface (struct PDMIBASE *pInterface,
1651 const char *pszIID)
1652{
1653 PCIINTELHDLinkState *pThis = RT_FROM_MEMBER(pInterface, PCIINTELHDLinkState, hda.IBase);
1654 Assert(&pThis->hda.IBase == pInterface);
1655
1656 PDMIBASE_RETURN_INTERFACE(pszIID, PDMIBASE, &pThis->hda.IBase);
1657 return NULL;
1658}
1659
1660//#define HDA_AS_PCI_EXPRESS
1661
1662/**
1663 * @interface_method_impl{PDMDEVREG,pfnConstruct}
1664 */
1665static DECLCALLBACK(int) hdaConstruct (PPDMDEVINS pDevIns, int iInstance,
1666 PCFGMNODE pCfgHandle)
1667{
1668 PCIINTELHDLinkState *pThis = PDMINS_2_DATA(pDevIns, PCIINTELHDLinkState *);
1669 INTELHDLinkState *s = &pThis->hda;
1670 int rc;
1671
1672 Assert(iInstance == 0);
1673 PDMDEV_CHECK_VERSIONS_RETURN(pDevIns);
1674
1675 /*
1676 * Validations.
1677 */
1678 if (!CFGMR3AreValuesValid (pCfgHandle, "\0"))
1679 return PDMDEV_SET_ERROR (pDevIns, VERR_PDM_DEVINS_UNKNOWN_CFG_VALUES,
1680 N_ ("Invalid configuration for the INTELHD device"));
1681
1682 // ** @todo r=michaln: This device may need R0/RC enabling, especially if guests
1683 // poll some register(s).
1684
1685 /*
1686 * Initialize data (most of it anyway).
1687 */
1688 s->pDevIns = pDevIns;
1689 /* IBase */
1690 s->IBase.pfnQueryInterface = hdaQueryInterface;
1691
1692 /* PCI Device (the assertions will be removed later) */
1693#if defined(VBOX_WITH_HP_HDA)
1694 /* Linux kernel has whitelist for MSI-enabled HDA, this card seems to be there. */
1695 PCIDevSetVendorId (&pThis->dev, 0x103c); /* HP. */
1696 PCIDevSetDeviceId (&pThis->dev, 0x30f7); /* HP Pavilion dv4t-1300 */
1697#elif defined(VBOX_WITH_INTEL_HDA)
1698 PCIDevSetVendorId (&pThis->dev, 0x8086); /* 00 ro - intel. */
1699 PCIDevSetDeviceId (&pThis->dev, 0x2668); /* 02 ro - 82801 / 82801aa(?). */
1700#elif defined(VBOX_WITH_NVIDIA_HDA)
1701 PCIDevSetVendorId (&pThis->dev, 0x10de); /* nVidia */
1702 PCIDevSetDeviceId (&pThis->dev, 0x0ac0); /* HDA */
1703#else
1704# error "Please specify your HDA device vendor/device IDs"
1705#endif
1706 PCIDevSetCommand (&pThis->dev, 0x0000); /* 04 rw,ro - pcicmd. */
1707 PCIDevSetStatus (&pThis->dev, VBOX_PCI_STATUS_CAP_LIST); /* 06 rwc?,ro? - pcists. */
1708 PCIDevSetRevisionId (&pThis->dev, 0x01); /* 08 ro - rid. */
1709 PCIDevSetClassProg (&pThis->dev, 0x00); /* 09 ro - pi. */
1710 PCIDevSetClassSub (&pThis->dev, 0x03); /* 0a ro - scc; 03 == HDA. */
1711 PCIDevSetClassBase (&pThis->dev, 0x04); /* 0b ro - bcc; 04 == multimedia. */
1712 PCIDevSetHeaderType (&pThis->dev, 0x00); /* 0e ro - headtyp. */
1713 PCIDevSetBaseAddress (&pThis->dev, 0, /* 10 rw - MMIO */
1714 false /* fIoSpace */, false /* fPrefetchable */, true /* f64Bit */, 0x00000000);
1715 PCIDevSetInterruptLine (&pThis->dev, 0x00); /* 3c rw. */
1716 PCIDevSetInterruptPin (&pThis->dev, 0x01); /* 3d ro - INTA#. */
1717
1718#if defined(HDA_AS_PCI_EXPRESS)
1719 PCIDevSetCapabilityList (&pThis->dev, 0x80);
1720#elif defined(VBOX_WITH_MSI_DEVICES)
1721 PCIDevSetCapabilityList (&pThis->dev, 0x60);
1722#else
1723 PCIDevSetCapabilityList (&pThis->dev, 0x50); /* ICH6 datasheet 18.1.16 */
1724#endif
1725
1726 //** @todo r=michaln: If there are really no PCIDevSetXx for these, the meaning
1727 // of these values needs to be properly documented!
1728 /* HDCTL off 0x40 bit 0 selects signaling mode (1-HDA, 0 - Ac97) 18.1.19 */
1729 PCIDevSetByte(&pThis->dev, 0x40, 0x01);
1730
1731 /* Power Management */
1732 PCIDevSetByte(&pThis->dev, 0x50 + 0, VBOX_PCI_CAP_ID_PM);
1733 PCIDevSetByte(&pThis->dev, 0x50 + 1, 0x0); /* next */
1734 PCIDevSetWord(&pThis->dev, 0x50 + 2, VBOX_PCI_PM_CAP_DSI | 0x02 /* version, PM1.1 */ );
1735
1736#ifdef HDA_AS_PCI_EXPRESS
1737 /* PCI Express */
1738 PCIDevSetByte (&pThis->dev, 0x80 + 0, VBOX_PCI_CAP_ID_EXP); /* PCI_Express */
1739 PCIDevSetByte (&pThis->dev, 0x80 + 1, 0x60); /* next */
1740 /* Device flags */
1741 PCIDevSetWord (&pThis->dev, 0x80 + 2,
1742 /* version */ 0x1 |
1743 /* Root Complex Integrated Endpoint */ (VBOX_PCI_EXP_TYPE_ROOT_INT_EP << 4) |
1744 /* MSI */ (100) << 9
1745 );
1746 /* Device capabilities */
1747 PCIDevSetDWord (&pThis->dev, 0x80 + 4, VBOX_PCI_EXP_DEVCAP_FLRESET);
1748 /* Device control */
1749 PCIDevSetWord (&pThis->dev, 0x80 + 8, 0);
1750 /* Device status */
1751 PCIDevSetWord (&pThis->dev, 0x80 + 10, 0);
1752 /* Link caps */
1753 PCIDevSetDWord (&pThis->dev, 0x80 + 12, 0);
1754 /* Link control */
1755 PCIDevSetWord (&pThis->dev, 0x80 + 16, 0);
1756 /* Link status */
1757 PCIDevSetWord (&pThis->dev, 0x80 + 18, 0);
1758 /* Slot capabilities */
1759 PCIDevSetDWord (&pThis->dev, 0x80 + 20, 0);
1760 /* Slot control */
1761 PCIDevSetWord (&pThis->dev, 0x80 + 24, 0);
1762 /* Slot status */
1763 PCIDevSetWord (&pThis->dev, 0x80 + 26, 0);
1764 /* Root control */
1765 PCIDevSetWord (&pThis->dev, 0x80 + 28, 0);
1766 /* Root capabilities */
1767 PCIDevSetWord (&pThis->dev, 0x80 + 30, 0);
1768 /* Root status */
1769 PCIDevSetDWord (&pThis->dev, 0x80 + 32, 0);
1770 /* Device capabilities 2 */
1771 PCIDevSetDWord (&pThis->dev, 0x80 + 36, 0);
1772 /* Device control 2 */
1773 PCIDevSetQWord (&pThis->dev, 0x80 + 40, 0);
1774 /* Link control 2 */
1775 PCIDevSetQWord (&pThis->dev, 0x80 + 48, 0);
1776 /* Slot control 2 */
1777 PCIDevSetWord (&pThis->dev, 0x80 + 56, 0);
1778#endif
1779
1780 /*
1781 * Register the PCI device.
1782 */
1783 rc = PDMDevHlpPCIRegister (pDevIns, &pThis->dev);
1784 if (RT_FAILURE (rc))
1785 return rc;
1786
1787 rc = PDMDevHlpPCIIORegionRegister (pDevIns, 0, 0x4000, PCI_ADDRESS_SPACE_MEM,
1788 hdaMap);
1789 if (RT_FAILURE (rc))
1790 return rc;
1791
1792#ifdef VBOX_WITH_MSI_DEVICES
1793 PDMMSIREG aMsiReg;
1794
1795 RT_ZERO(aMsiReg);
1796 aMsiReg.cMsiVectors = 1;
1797 aMsiReg.iMsiCapOffset = 0x60;
1798 aMsiReg.iMsiNextOffset = 0x50;
1799 rc = PDMDevHlpPCIRegisterMsi(pDevIns, &aMsiReg);
1800 if (RT_FAILURE (rc))
1801 {
1802 LogRel(("Chipset cannot do MSI: %Rrc\n", rc));
1803 PCIDevSetCapabilityList (&pThis->dev, 0x50);
1804 }
1805#endif
1806
1807 rc = PDMDevHlpSSMRegister (pDevIns, HDA_SSM_VERSION, sizeof(*pThis), hdaSaveExec, hdaLoadExec);
1808 if (RT_FAILURE (rc))
1809 return rc;
1810
1811 /*
1812 * Attach driver.
1813 */
1814 rc = PDMDevHlpDriverAttach (pDevIns, 0, &s->IBase,
1815 &s->pDrvBase, "Audio Driver Port");
1816 if (rc == VERR_PDM_NO_ATTACHED_DRIVER)
1817 Log (("hda: No attached driver!\n"));
1818 else if (RT_FAILURE (rc))
1819 {
1820 AssertMsgFailed (("Failed to attach INTELHD LUN #0! rc=%Rrc\n", rc));
1821 return rc;
1822 }
1823
1824
1825
1826 pThis->hda.Codec.pHDAState = (void *)&pThis->hda;
1827 rc = codecConstruct(&pThis->hda.Codec, /* ALC885_CODEC */ STAC9220_CODEC);
1828 if (RT_FAILURE(rc))
1829 AssertRCReturn(rc, rc);
1830
1831 /* ICH6 datasheet defines 0 values for SVID and SID (18.1.14-15), which together with values returned for
1832 verb F20 should provide device/codec recognition. */
1833 Assert(pThis->hda.Codec.u16VendorId);
1834 Assert(pThis->hda.Codec.u16DeviceId);
1835 PCIDevSetSubSystemVendorId (&pThis->dev, pThis->hda.Codec.u16VendorId); /* 2c ro - intel.) */
1836 PCIDevSetSubSystemId (&pThis->dev, pThis->hda.Codec.u16DeviceId); /* 2e ro. */
1837
1838 hdaReset (pDevIns);
1839 pThis->hda.Codec.id = 0;
1840 pThis->hda.Codec.pfnTransfer = hdaTransfer;
1841 pThis->hda.Codec.pfnReset = hdaCodecReset;
1842 /*
1843 * 18.2.6,7 defines that values of this registers might be cleared on power on/reset
1844 * hdaReset shouldn't affects these registers.
1845 */
1846 WAKEEN(&pThis->hda) = 0x0;
1847 STATESTS(&pThis->hda) = 0x0;
1848
1849 return VINF_SUCCESS;
1850}
1851
1852/**
1853 * @interface_method_impl{PDMDEVREG,pfnDestruct}
1854 */
1855static DECLCALLBACK(int) hdaDestruct (PPDMDEVINS pDevIns)
1856{
1857 PCIINTELHDLinkState *pThis = PDMINS_2_DATA(pDevIns, PCIINTELHDLinkState *);
1858
1859 int rc = codecDestruct(&pThis->hda.Codec);
1860 AssertRC(rc);
1861 if (pThis->hda.pu32CorbBuf)
1862 RTMemFree(pThis->hda.pu32CorbBuf);
1863 if (pThis->hda.pu64RirbBuf)
1864 RTMemFree(pThis->hda.pu64RirbBuf);
1865 return VINF_SUCCESS;
1866}
1867
1868/**
1869 * The device registration structure.
1870 */
1871const PDMDEVREG g_DeviceICH6_HDA =
1872{
1873 /* u32Version */
1874 PDM_DEVREG_VERSION,
1875 /* szName */
1876 "hda",
1877 /* szRCMod */
1878 "",
1879 /* szR0Mod */
1880 "",
1881 /* pszDescription */
1882 "ICH IntelHD Audio Controller",
1883 /* fFlags */
1884 PDM_DEVREG_FLAGS_DEFAULT_BITS,
1885 /* fClass */
1886 PDM_DEVREG_CLASS_AUDIO,
1887 /* cMaxInstances */
1888 1,
1889 /* cbInstance */
1890 sizeof(PCIINTELHDLinkState),
1891 /* pfnConstruct */
1892 hdaConstruct,
1893 /* pfnDestruct */
1894 hdaDestruct,
1895 /* pfnRelocate */
1896 NULL,
1897 /* pfnIOCtl */
1898 NULL,
1899 /* pfnPowerOn */
1900 NULL,
1901 /* pfnReset */
1902 hdaReset,
1903 /* pfnSuspend */
1904 NULL,
1905 /* pfnResume */
1906 NULL,
1907 /* pfnAttach */
1908 NULL,
1909 /* pfnDetach */
1910 NULL,
1911 /* pfnQueryInterface. */
1912 NULL,
1913 /* pfnInitComplete */
1914 NULL,
1915 /* pfnPowerOff */
1916 NULL,
1917 /* pfnSoftReset */
1918 NULL,
1919 /* u32VersionEnd */
1920 PDM_DEVREG_VERSION
1921};
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette