VirtualBox

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

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

Audio/HDA: Assert->LogRel for special guests.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 82.8 KB
Line 
1/* $Id: DevIchIntelHDA.cpp 33435 2010-10-25 16:08:30Z 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 harcoded 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 completition */
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)hdaRegWriteSDCTL(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t u32Value);
436DECLCALLBACK(int)hdaRegReadSDCTL(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t *pu32Value);
437
438DECLCALLBACK(int)hdaRegWriteSDSTS(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t u32Value);
439DECLCALLBACK(int)hdaRegWriteSDLVI(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t u32Value);
440DECLCALLBACK(int)hdaRegWriteSDBDPL(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t u32Value);
441DECLCALLBACK(int)hdaRegWriteSDBDPU(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t u32Value);
442DECLCALLBACK(int)hdaRegWriteBase(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t u32Value);
443DECLCALLBACK(int)hdaRegReadU32(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t *pu32Value);
444DECLCALLBACK(int)hdaRegWriteU32(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t pu32Value);
445DECLCALLBACK(int)hdaRegReadU24(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t *pu32Value);
446DECLCALLBACK(int)hdaRegWriteU24(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t pu32Value);
447DECLCALLBACK(int)hdaRegReadU16(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t *pu32Value);
448DECLCALLBACK(int)hdaRegWriteU16(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t pu32Value);
449DECLCALLBACK(int)hdaRegReadU8(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t *pu32Value);
450DECLCALLBACK(int)hdaRegWriteU8(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t pu32Value);
451static int hdaLookup(INTELHDLinkState* pState, uint32_t u32Offset);
452static void fetch_bd(INTELHDLinkState *pState, PHDABDLEDESC pBdle, uint64_t u64BaseDMA);
453
454/* see 302349 p 6.2*/
455const static struct stIchIntelHDRegMap
456{
457 /** Register offset in the register space. */
458 uint32_t offset;
459 /** Size in bytes. Registers of size > 4 are in fact tables. */
460 uint32_t size;
461 /** Readable bits. */
462 uint32_t readable;
463 /** Writable bits. */
464 uint32_t writable;
465 /** Read callback. */
466 int (*pfnRead)(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t *pu32Value);
467 /** Write callback. */
468 int (*pfnWrite)(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t u32Value);
469 /** Abbreviated name. */
470 const char *abbrev;
471 /** Full name. */
472 const char *name;
473} s_ichIntelHDRegMap[] =
474{
475 /* offset size read mask write mask read callback write callback abbrev full name */
476 /*------- ------- ---------- ---------- ----------------------- ------------------------ ---------- ------------------------------*/
477 { 0x00000, 0x00002, 0x0000FFFB, 0x00000000, hdaRegReadGCAP , hdaRegWriteUnimplemented, "GCAP" , "Global Capabilities" },
478 { 0x00002, 0x00001, 0x000000FF, 0x00000000, hdaRegReadU8 , hdaRegWriteUnimplemented, "VMIN" , "Minor Version" },
479 { 0x00003, 0x00001, 0x000000FF, 0x00000000, hdaRegReadU8 , hdaRegWriteUnimplemented, "VMAJ" , "Major Version" },
480 { 0x00004, 0x00002, 0x0000FFFF, 0x00000000, hdaRegReadU16 , hdaRegWriteUnimplemented, "OUTPAY" , "Output Payload Capabilities" },
481 { 0x00006, 0x00002, 0x0000FFFF, 0x00000000, hdaRegReadU16 , hdaRegWriteUnimplemented, "INPAY" , "Input Payload Capabilities" },
482 { 0x00008, 0x00004, 0x00000103, 0x00000103, hdaRegReadGCTL , hdaRegWriteGCTL , "GCTL" , "Global Control" },
483 { 0x0000c, 0x00002, 0x00007FFF, 0x00007FFF, hdaRegReadU16 , hdaRegWriteU16 , "WAKEEN" , "Wake Enable" },
484 { 0x0000e, 0x00002, 0x00000007, 0x00000007, hdaRegReadU8 , hdaRegWriteSTATESTS , "STATESTS" , "State Change Status" },
485 { 0x00010, 0x00002, 0xFFFFFFFF, 0x00000000, hdaRegReadUnimplemented, hdaRegWriteUnimplemented, "GSTS" , "Global Status" },
486 { 0x00020, 0x00004, 0xC00000FF, 0xC00000FF, hdaRegReadU32 , hdaRegWriteU32 , "INTCTL" , "Interrupt Control" },
487 { 0x00024, 0x00004, 0xC00000FF, 0x00000000, hdaRegReadINTSTS , hdaRegWriteUnimplemented, "INTSTS" , "Interrupt Status" },
488 //** @todo r=michaln: Are guests really not reading the WALCLK register at all?
489 { 0x00030, 0x00004, 0xFFFFFFFF, 0x00000000, hdaRegReadUnimplemented, hdaRegWriteUnimplemented, "WALCLK" , "Wall Clock Counter" },
490 //** @todo r=michaln: Doesn't the SSYNC register need to actually stop the stream(s)?
491 { 0x00034, 0x00004, 0x000000FF, 0x000000FF, hdaRegReadU32 , hdaRegWriteU32 , "SSYNC" , "Stream Synchronization" },
492 { 0x00040, 0x00004, 0xFFFFFF80, 0xFFFFFF80, hdaRegReadU32 , hdaRegWriteBase , "CORBLBASE" , "CORB Lower Base Address" },
493 { 0x00044, 0x00004, 0xFFFFFFFF, 0xFFFFFFFF, hdaRegReadU32 , hdaRegWriteBase , "CORBUBASE" , "CORB Upper Base Address" },
494 { 0x00048, 0x00002, 0x000000FF, 0x000000FF, hdaRegReadU16 , hdaRegWriteCORBWP , "CORBWP" , "CORB Write Pointer" },
495 { 0x0004A, 0x00002, 0x000000FF, 0x000080FF, hdaRegReadU8 , hdaRegWriteCORBRP , "CORBRP" , "CORB Read Pointer" },
496 { 0x0004C, 0x00001, 0x00000003, 0x00000003, hdaRegReadU8 , hdaRegWriteCORBCTL , "CORBCTL" , "CORB Control" },
497 { 0x0004D, 0x00001, 0x00000001, 0x00000001, hdaRegReadU8 , hdaRegWriteCORBSTS , "CORBSTS" , "CORB Status" },
498 { 0x0004E, 0x00001, 0x000000F3, 0x00000000, hdaRegReadU8 , hdaRegWriteUnimplemented, "CORBSIZE" , "CORB Size" },
499 { 0x00050, 0x00004, 0xFFFFFF80, 0xFFFFFF80, hdaRegReadU32 , hdaRegWriteBase , "RIRBLBASE" , "RIRB Lower Base Address" },
500 { 0x00054, 0x00004, 0xFFFFFFFF, 0xFFFFFFFF, hdaRegReadU32 , hdaRegWriteBase , "RIRBUBASE" , "RIRB Upper Base Address" },
501 { 0x00058, 0x00002, 0x000000FF, 0x00008000, hdaRegReadU8, hdaRegWriteRIRBWP , "RIRBWP" , "RIRB Write Pointer" },
502 { 0x0005A, 0x00002, 0x000000FF, 0x000000FF, hdaRegReadU16 , hdaRegWriteU16 , "RINTCNT" , "Response Interrupt Count" },
503 { 0x0005C, 0x00001, 0x00000007, 0x00000007, hdaRegReadU8 , hdaRegWriteU8 , "RIRBCTL" , "RIRB Control" },
504 { 0x0005D, 0x00001, 0x00000005, 0x00000005, hdaRegReadU8 , hdaRegWriteRIRBSTS , "RIRBSTS" , "RIRB Status" },
505 { 0x0005E, 0x00001, 0x000000F3, 0x00000000, hdaRegReadU8 , hdaRegWriteUnimplemented, "RIRBSIZE" , "RIRB Size" },
506 { 0x00060, 0x00004, 0xFFFFFFFF, 0xFFFFFFFF, hdaRegReadU32 , hdaRegWriteU32 , "IC" , "Immediate Command" },
507 { 0x00064, 0x00004, 0x00000000, 0xFFFFFFFF, hdaRegReadU32 , hdaRegWriteUnimplemented, "IR" , "Immediate Response" },
508 { 0x00068, 0x00004, 0x00000002, 0x00000002, hdaRegReadU16 , hdaRegWriteIRS , "IRS" , "Immediate Command Status" },
509 { 0x00070, 0x00004, 0xFFFFFFFF, 0xFFFFFF81, hdaRegReadU32 , hdaRegWriteBase , "DPLBASE" , "DMA Position Lower Base" },
510 { 0x00074, 0x00004, 0xFFFFFFFF, 0xFFFFFFFF, hdaRegReadU32 , hdaRegWriteBase , "DPUBASE" , "DMA Position Upper Base" },
511
512 { 0x00080, 0x00003, 0x00FF001F, 0x00F0001F, hdaRegReadU24 , hdaRegWriteSDCTL , "ISD0CTL" , "Input Stream Descriptor 0 (ICD0) Control" },
513 { 0x00083, 0x00001, 0x0000001C, 0x0000003C, hdaRegReadU8 , hdaRegWriteSDSTS , "ISD0STS" , "ISD0 Status" },
514 { 0x00084, 0x00004, 0xFFFFFFFF, 0x00000000, hdaRegReadU32 , hdaRegWriteU32 , "ISD0LPIB" , "ISD0 Link Position In Buffer" },
515 { 0x00088, 0x00004, 0xFFFFFFFF, 0xFFFFFFFF, hdaRegReadU32 , hdaRegWriteU32 , "ISD0CBL" , "ISD0 Cyclic Buffer Length" },
516 { 0x0008C, 0x00002, 0x0000FFFF, 0x0000FFFF, hdaRegReadU16 , hdaRegWriteSDLVI , "ISD0LVI" , "ISD0 Last Valid Index" },
517 { 0x0008E, 0x00002, 0x00000005, 0x00000005, hdaRegReadU16 , hdaRegWriteU16 , "ISD0FIFOW", "ISD0 FIFO Watermark" },
518 { 0x00090, 0x00002, 0x000000FF, 0x000000FF, hdaRegReadU16 , hdaRegWriteU16 , "ISD0FIFOS", "ISD0 FIFO Size" },
519 { 0x00092, 0x00002, 0x00007F7F, 0x00007F7F, hdaRegReadU16 , hdaRegWriteU16 , "ISD0FMT" , "ISD0 Format" },
520 { 0x00098, 0x00004, 0xFFFFFF80, 0xFFFFFF80, hdaRegReadU32 , hdaRegWriteSDBDPL , "ISD0BDPL" , "ISD0 Buffer Descriptor List Pointer-Lower Base Address" },
521 { 0x0009C, 0x00004, 0xFFFFFFFF, 0xFFFFFFFF, hdaRegReadU32 , hdaRegWriteSDBDPU , "ISD0BDPU" , "ISD0 Buffer Descriptor List Pointer-Upper Base Address" },
522
523 { 0x000A0, 0x00003, 0x00FF001F, 0x00F0001F, hdaRegReadU24 , hdaRegWriteSDCTL , "ISD1CTL" , "Input Stream Descriptor 1 (ISD1) Control" },
524 { 0x000A3, 0x00001, 0x0000001C, 0x0000003C, hdaRegReadU8 , hdaRegWriteSDSTS , "ISD1STS" , "ISD1 Status" },
525 { 0x000A4, 0x00004, 0xFFFFFFFF, 0x00000000, hdaRegReadU32 , hdaRegWriteU32 , "ISD1LPIB" , "ISD1 Link Position In Buffer" },
526 { 0x000A8, 0x00004, 0xFFFFFFFF, 0xFFFFFFFF, hdaRegReadU32 , hdaRegWriteU32 , "ISD1CBL" , "ISD1 Cyclic Buffer Length" },
527 { 0x000AC, 0x00002, 0x0000FFFF, 0x0000FFFF, hdaRegReadU16 , hdaRegWriteSDLVI , "ISD1LVI" , "ISD1 Last Valid Index" },
528 { 0x000AE, 0x00002, 0x00000005, 0x00000005, hdaRegReadU16 , hdaRegWriteU16 , "ISD1FIFOW", "ISD1 FIFO Watermark" },
529 { 0x000B0, 0x00002, 0x000000FF, 0x000000FF, hdaRegReadU16 , hdaRegWriteU16 , "ISD1FIFOS", "ISD1 FIFO Size" },
530 { 0x000B2, 0x00002, 0x00007F7F, 0x00007F7F, hdaRegReadU16 , hdaRegWriteU16 , "ISD1FMT" , "ISD1 Format" },
531 { 0x000B8, 0x00004, 0xFFFFFF80, 0xFFFFFF80, hdaRegReadU32 , hdaRegWriteSDBDPL , "ISD1BDPL" , "ISD1 Buffer Descriptor List Pointer-Lower Base Address" },
532 { 0x000BC, 0x00004, 0xFFFFFFFF, 0xFFFFFFFF, hdaRegReadU32 , hdaRegWriteSDBDPU , "ISD1BDPU" , "ISD1 Buffer Descriptor List Pointer-Upper Base Address" },
533
534 { 0x000C0, 0x00003, 0x00FF001F, 0x00F0001F, hdaRegReadU24 , hdaRegWriteSDCTL , "ISD2CTL" , "Input Stream Descriptor 2 (ISD2) Control" },
535 { 0x000C3, 0x00001, 0x0000001C, 0x0000003C, hdaRegReadU8 , hdaRegWriteSDSTS , "ISD2STS" , "ISD2 Status" },
536 { 0x000C4, 0x00004, 0xFFFFFFFF, 0x00000000, hdaRegReadU32 , hdaRegWriteU32 , "ISD2LPIB" , "ISD2 Link Position In Buffer" },
537 { 0x000C8, 0x00004, 0xFFFFFFFF, 0xFFFFFFFF, hdaRegReadU32 , hdaRegWriteU32 , "ISD2CBL" , "ISD2 Cyclic Buffer Length" },
538 { 0x000CC, 0x00002, 0x0000FFFF, 0x0000FFFF, hdaRegReadU16 , hdaRegWriteSDLVI , "ISD2LVI" , "ISD2 Last Valid Index" },
539 { 0x000CE, 0x00002, 0x00000005, 0x00000005, hdaRegReadU16 , hdaRegWriteU16 , "ISD2FIFOW", "ISD2 FIFO Watermark" },
540 { 0x000D0, 0x00002, 0x000000FF, 0x000000FF, hdaRegReadU16 , hdaRegWriteU16 , "ISD2FIFOS", "ISD2 FIFO Size" },
541 { 0x000D2, 0x00002, 0x00007F7F, 0x00007F7F, hdaRegReadU16 , hdaRegWriteU16 , "ISD2FMT" , "ISD2 Format" },
542 { 0x000D8, 0x00004, 0xFFFFFF80, 0xFFFFFF80, hdaRegReadU32 , hdaRegWriteSDBDPL , "ISD2BDPL" , "ISD2 Buffer Descriptor List Pointer-Lower Base Address" },
543 { 0x000DC, 0x00004, 0xFFFFFFFF, 0xFFFFFFFF, hdaRegReadU32 , hdaRegWriteSDBDPU , "ISD2BDPU" , "ISD2 Buffer Descriptor List Pointer-Upper Base Address" },
544
545 { 0x000E0, 0x00003, 0x00FF001F, 0x00F0001F, hdaRegReadU24 , hdaRegWriteSDCTL , "ISD3CTL" , "Input Stream Descriptor 3 (ISD3) Control" },
546 { 0x000E3, 0x00001, 0x0000001C, 0x0000003C, hdaRegReadU8 , hdaRegWriteSDSTS , "ISD3STS" , "ISD3 Status" },
547 { 0x000E4, 0x00004, 0xFFFFFFFF, 0x00000000, hdaRegReadU32 , hdaRegWriteU32 , "ISD3LPIB" , "ISD3 Link Position In Buffer" },
548 { 0x000E8, 0x00004, 0xFFFFFFFF, 0xFFFFFFFF, hdaRegReadU32 , hdaRegWriteU32 , "ISD3CBL" , "ISD3 Cyclic Buffer Length" },
549 { 0x000EC, 0x00002, 0x0000FFFF, 0x0000FFFF, hdaRegReadU16 , hdaRegWriteSDLVI , "ISD3LVI" , "ISD3 Last Valid Index" },
550 { 0x000EE, 0x00002, 0x00000005, 0x00000005, hdaRegReadU16 , hdaRegWriteU16 , "ISD3FIFOW", "ISD3 FIFO Watermark" },
551 { 0x000F0, 0x00002, 0x000000FF, 0x000000FF, hdaRegReadU16 , hdaRegWriteU16 , "ISD3FIFOS", "ISD3 FIFO Size" },
552 { 0x000F2, 0x00002, 0x00007F7F, 0x00007F7F, hdaRegReadU16 , hdaRegWriteU16 , "ISD3FMT" , "ISD3 Format" },
553 { 0x000F8, 0x00004, 0xFFFFFF80, 0xFFFFFF80, hdaRegReadU32 , hdaRegWriteSDBDPL , "ISD3BDPL" , "ISD3 Buffer Descriptor List Pointer-Lower Base Address" },
554 { 0x000FC, 0x00004, 0xFFFFFFFF, 0xFFFFFFFF, hdaRegReadU32 , hdaRegWriteSDBDPU , "ISD3BDPU" , "ISD3 Buffer Descriptor List Pointer-Upper Base Address" },
555
556 { 0x00100, 0x00003, 0x00FF001F, 0x00F0001F, hdaRegReadSDCTL , hdaRegWriteSDCTL , "OSD0CTL" , "Input Stream Descriptor 0 (OSD0) Control" },
557 { 0x00103, 0x00001, 0x0000001C, 0x0000003C, hdaRegReadU8 , hdaRegWriteSDSTS , "OSD0STS" , "OSD0 Status" },
558 { 0x00104, 0x00004, 0xFFFFFFFF, 0x00000000, hdaRegReadU32 , hdaRegWriteU32 , "OSD0LPIB" , "OSD0 Link Position In Buffer" },
559 { 0x00108, 0x00004, 0xFFFFFFFF, 0xFFFFFFFF, hdaRegReadU32 , hdaRegWriteU32 , "OSD0CBL" , "OSD0 Cyclic Buffer Length" },
560 { 0x0010C, 0x00002, 0x0000FFFF, 0x0000FFFF, hdaRegReadU16 , hdaRegWriteSDLVI , "OSD0LVI" , "OSD0 Last Valid Index" },
561 { 0x0010E, 0x00002, 0x00000005, 0x00000005, hdaRegReadU16 , hdaRegWriteU16 , "OSD0FIFOW", "OSD0 FIFO Watermark" },
562 { 0x00110, 0x00002, 0x000000FF, 0x000000FF, hdaRegReadU16 , hdaRegWriteU16 , "OSD0FIFOS", "OSD0 FIFO Size" },
563 { 0x00112, 0x00002, 0x00007F7F, 0x00007F7F, hdaRegReadU16 , hdaRegWriteU16 , "OSD0FMT" , "OSD0 Format" },
564 { 0x00118, 0x00004, 0xFFFFFF80, 0xFFFFFF80, hdaRegReadU32 , hdaRegWriteSDBDPL , "OSD0BDPL" , "OSD0 Buffer Descriptor List Pointer-Lower Base Address" },
565 { 0x0011C, 0x00004, 0xFFFFFFFF, 0xFFFFFFFF, hdaRegReadU32 , hdaRegWriteSDBDPU , "OSD0BDPU" , "OSD0 Buffer Descriptor List Pointer-Upper Base Address" },
566
567 { 0x00120, 0x00003, 0x00FF001F, 0x00F0001F, hdaRegReadU24 , hdaRegWriteSDCTL , "OSD1CTL" , "Input Stream Descriptor 0 (OSD1) Control" },
568 { 0x00123, 0x00001, 0x0000001C, 0x0000003C, hdaRegReadU8 , hdaRegWriteSDSTS , "OSD1STS" , "OSD1 Status" },
569 { 0x00124, 0x00004, 0xFFFFFFFF, 0x00000000, hdaRegReadU32 , hdaRegWriteU32 , "OSD1LPIB" , "OSD1 Link Position In Buffer" },
570 { 0x00128, 0x00004, 0xFFFFFFFF, 0xFFFFFFFF, hdaRegReadU32 , hdaRegWriteU32 , "OSD1CBL" , "OSD1 Cyclic Buffer Length" },
571 { 0x0012C, 0x00002, 0x0000FFFF, 0x0000FFFF, hdaRegReadU16 , hdaRegWriteSDLVI , "OSD1LVI" , "OSD1 Last Valid Index" },
572 { 0x0012E, 0x00002, 0x00000005, 0x00000005, hdaRegReadU16 , hdaRegWriteU16 , "OSD1FIFOW", "OSD1 FIFO Watermark" },
573 { 0x00130, 0x00002, 0x000000FF, 0x000000FF, hdaRegReadU16 , hdaRegWriteU16 , "OSD1FIFOS", "OSD1 FIFO Size" },
574 { 0x00132, 0x00002, 0x00007F7F, 0x00007F7F, hdaRegReadU16 , hdaRegWriteU16 , "OSD1FMT" , "OSD1 Format" },
575 { 0x00138, 0x00004, 0xFFFFFF80, 0xFFFFFF80, hdaRegReadU32 , hdaRegWriteSDBDPL , "OSD1BDPL" , "OSD1 Buffer Descriptor List Pointer-Lower Base Address" },
576 { 0x0013C, 0x00004, 0xFFFFFFFF, 0xFFFFFFFF, hdaRegReadU32 , hdaRegWriteSDBDPU , "OSD1BDPU" , "OSD1 Buffer Descriptor List Pointer-Upper Base Address" },
577
578 { 0x00140, 0x00003, 0x00FF001F, 0x00F0001F, hdaRegReadU24 , hdaRegWriteSDCTL , "OSD2CTL" , "Input Stream Descriptor 0 (OSD2) Control" },
579 { 0x00143, 0x00001, 0x0000001C, 0x0000003C, hdaRegReadU8 , hdaRegWriteSDSTS , "OSD2STS" , "OSD2 Status" },
580 { 0x00144, 0x00004, 0xFFFFFFFF, 0x00000000, hdaRegReadU32 , hdaRegWriteU32 , "OSD2LPIB" , "OSD2 Link Position In Buffer" },
581 { 0x00148, 0x00004, 0xFFFFFFFF, 0xFFFFFFFF, hdaRegReadU32 , hdaRegWriteU32 , "OSD2CBL" , "OSD2 Cyclic Buffer Length" },
582 { 0x0014C, 0x00002, 0x0000FFFF, 0x0000FFFF, hdaRegReadU16 , hdaRegWriteSDLVI , "OSD2LVI" , "OSD2 Last Valid Index" },
583 { 0x0014E, 0x00002, 0x00000005, 0x00000005, hdaRegReadU16 , hdaRegWriteU16 , "OSD2FIFOW", "OSD2 FIFO Watermark" },
584 { 0x00150, 0x00002, 0x000000FF, 0x000000FF, hdaRegReadU16 , hdaRegWriteU16 , "OSD2FIFOS", "OSD2 FIFO Size" },
585 { 0x00152, 0x00002, 0x00007F7F, 0x00007F7F, hdaRegReadU16 , hdaRegWriteU16 , "OSD2FMT" , "OSD2 Format" },
586 { 0x00158, 0x00004, 0xFFFFFF80, 0xFFFFFF80, hdaRegReadU32 , hdaRegWriteSDBDPL , "OSD2BDPL" , "OSD2 Buffer Descriptor List Pointer-Lower Base Address" },
587 { 0x0015C, 0x00004, 0xFFFFFFFF, 0xFFFFFFFF, hdaRegReadU32 , hdaRegWriteSDBDPU , "OSD2BDPU" , "OSD2 Buffer Descriptor List Pointer-Upper Base Address" },
588
589 { 0x00160, 0x00003, 0x00FF001F, 0x00F0001F, hdaRegReadU24 , hdaRegWriteSDCTL , "OSD3CTL" , "Input Stream Descriptor 0 (OSD3) Control" },
590 { 0x00163, 0x00001, 0x0000001C, 0x0000003C, hdaRegReadU8 , hdaRegWriteSDSTS , "OSD3STS" , "OSD3 Status" },
591 { 0x00164, 0x00004, 0xFFFFFFFF, 0x00000000, hdaRegReadU32 , hdaRegWriteU32 , "OSD3LPIB" , "OSD3 Link Position In Buffer" },
592 { 0x00168, 0x00004, 0xFFFFFFFF, 0xFFFFFFFF, hdaRegReadU32 , hdaRegWriteU32 , "OSD3CBL" , "OSD3 Cyclic Buffer Length" },
593 { 0x0016C, 0x00002, 0x0000FFFF, 0x0000FFFF, hdaRegReadU16 , hdaRegWriteSDLVI , "OSD3LVI" , "OSD3 Last Valid Index" },
594 { 0x0016E, 0x00002, 0x00000005, 0x00000005, hdaRegReadU16 , hdaRegWriteU16 , "OSD3FIFOW", "OSD3 FIFO Watermark" },
595 { 0x00170, 0x00002, 0x000000FF, 0x000000FF, hdaRegReadU16 , hdaRegWriteU16 , "OSD3FIFOS", "OSD3 FIFO Size" },
596 { 0x00172, 0x00002, 0x00007F7F, 0x00007F7F, hdaRegReadU16 , hdaRegWriteU16 , "OSD3FMT" , "OSD3 Format" },
597 { 0x00178, 0x00004, 0xFFFFFF80, 0xFFFFFF80, hdaRegReadU32 , hdaRegWriteSDBDPL , "OSD3BDPL" , "OSD3 Buffer Descriptor List Pointer-Lower Base Address" },
598 { 0x0017C, 0x00004, 0xFFFFFFFF, 0xFFFFFFFF, hdaRegReadU32 , hdaRegWriteSDBDPU , "OSD3BDPU" , "OSD3 Buffer Descriptor List Pointer-Upper Base Address" },
599};
600
601static int hdaProcessInterrupt(INTELHDLinkState* pState)
602{
603#define IS_INTERRUPT_OCCURED_AND_ENABLED(pState, num) \
604 ( INTCTL_SX((pState), num) \
605 && (SDSTS(pState, num) & HDA_REG_FIELD_FLAG_MASK(SDSTS, BCIS)))
606 bool fIrq = false;
607 if( INTCTL_CIE(pState)
608 && ( RIRBSTS_RINTFL(pState)
609 || RIRBSTS_RIRBOIS(pState)
610 || STATESTS(pState)))
611 {
612 fIrq = true;
613 }
614 if ( IS_INTERRUPT_OCCURED_AND_ENABLED(pState, 0)
615 || IS_INTERRUPT_OCCURED_AND_ENABLED(pState, 4))
616 {
617 fIrq = true;
618 }
619 if (INTCTL_GIE(pState))
620 {
621 Log(("hda: irq %s\n", fIrq ? "asserted" : "deasserted"));
622 PDMDevHlpPCISetIrq(ICH6_HDASTATE_2_DEVINS(pState), 0 , fIrq);
623 }
624 return VINF_SUCCESS;
625}
626
627static int hdaLookup(INTELHDLinkState* pState, uint32_t u32Offset)
628{
629 int index = 0;
630 //** @todo r=michaln: A linear search of an array with over 100 elements is very inefficient.
631 for (;index < (int)(sizeof(s_ichIntelHDRegMap)/sizeof(s_ichIntelHDRegMap[0])); ++index)
632 {
633 if ( u32Offset >= s_ichIntelHDRegMap[index].offset
634 && u32Offset < s_ichIntelHDRegMap[index].offset + s_ichIntelHDRegMap[index].size)
635 {
636 return index;
637 }
638 }
639 /* Aliases HDA spec 3.3.45 */
640 switch(u32Offset)
641 {
642 case 0x2084:
643 return HDA_REG_IND_NAME(SD0LPIB);
644 case 0x20A4:
645 return HDA_REG_IND_NAME(SD1LPIB);
646 case 0x20C4:
647 return HDA_REG_IND_NAME(SD2LPIB);
648 case 0x20E4:
649 return HDA_REG_IND_NAME(SD3LPIB);
650 case 0x2104:
651 return HDA_REG_IND_NAME(SD4LPIB);
652 case 0x2124:
653 return HDA_REG_IND_NAME(SD5LPIB);
654 case 0x2144:
655 return HDA_REG_IND_NAME(SD6LPIB);
656 case 0x2164:
657 return HDA_REG_IND_NAME(SD7LPIB);
658 }
659 return -1;
660}
661
662static int hdaCmdSync(INTELHDLinkState *pState, bool fLocal)
663{
664 int rc = VINF_SUCCESS;
665 if (fLocal)
666 {
667 Assert((HDA_REG_FLAG_VALUE(pState, CORBCTL, DMA)));
668 rc = PDMDevHlpPhysRead(ICH6_HDASTATE_2_DEVINS(pState), pState->u64CORBBase, pState->pu32CorbBuf, pState->cbCorbBuf);
669 if (RT_FAILURE(rc))
670 AssertRCReturn(rc, rc);
671#ifdef DEBUG_CMD_BUFFER
672 uint8_t i = 0;
673 do
674 {
675 Log(("hda: corb%02x: ", i));
676 uint8_t j = 0;
677 do
678 {
679 const char *prefix;
680 if ((i + j) == CORBRP(pState))
681 prefix = "[R]";
682 else if ((i + j) == CORBWP(pState))
683 prefix = "[W]";
684 else
685 prefix = " "; /* three spaces */
686 Log(("%s%08x", prefix, pState->pu32CorbBuf[i + j]));
687 j++;
688 } while (j < 8);
689 Log(("\n"));
690 i += 8;
691 } while(i != 0);
692#endif
693 }
694 else
695 {
696 Assert((HDA_REG_FLAG_VALUE(pState, RIRBCTL, DMA)));
697 rc = PDMDevHlpPhysWrite(ICH6_HDASTATE_2_DEVINS(pState), pState->u64RIRBBase, pState->pu64RirbBuf, pState->cbRirbBuf);
698 if (RT_FAILURE(rc))
699 AssertRCReturn(rc, rc);
700#ifdef DEBUG_CMD_BUFFER
701 uint8_t i = 0;
702 do {
703 Log(("hda: rirb%02x: ", i));
704 uint8_t j = 0;
705 do {
706 const char *prefix;
707 if ((i + j) == RIRBWP(pState))
708 prefix = "[W]";
709 else
710 prefix = " ";
711 Log((" %s%016lx", prefix, pState->pu64RirbBuf[i + j]));
712 } while (++j < 8);
713 Log(("\n"));
714 i += 8;
715 } while (i != 0);
716#endif
717 }
718 return rc;
719}
720
721static int hdaCORBCmdProcess(INTELHDLinkState *pState)
722{
723 int rc;
724 uint8_t corbRp;
725 uint8_t corbWp;
726 uint8_t rirbWp;
727
728 PFNCODECVERBPROCESSOR pfn = (PFNCODECVERBPROCESSOR)NULL;
729
730 rc = hdaCmdSync(pState, true);
731 if (RT_FAILURE(rc))
732 AssertRCReturn(rc, rc);
733 corbRp = CORBRP(pState);
734 corbWp = CORBWP(pState);
735 rirbWp = RIRBWP(pState);
736 Assert((corbWp != corbRp));
737 Log(("hda: CORB(RP:%x, WP:%x) RIRBWP:%x\n", CORBRP(pState), CORBWP(pState), RIRBWP(pState)));
738 while (corbRp != corbWp)
739 {
740 uint32_t cmd;
741 uint64_t resp;
742 corbRp++;
743 cmd = pState->pu32CorbBuf[corbRp];
744 rc = (pState)->Codec.pfnLookup(&pState->Codec, cmd, &pfn);
745 if (RT_FAILURE(rc))
746 AssertRCReturn(rc, rc);
747 Assert(pfn);
748 (rirbWp)++;
749 rc = pfn(&pState->Codec, cmd, &resp);
750 if (RT_FAILURE(rc))
751 AssertRCReturn(rc, rc);
752 Log(("hda: verb:%08x->%016lx\n", cmd, resp));
753 if ( (resp & CODEC_RESPONSE_UNSOLICITED)
754 && !HDA_REG_FLAG_VALUE(pState, GCTL, UR))
755 {
756 Log(("hda: unexpected unsolicited response.\n"));
757 pState->au32Regs[ICH6_HDA_REG_CORBRP] = corbRp;
758 return rc;
759 }
760 pState->pu64RirbBuf[rirbWp] = resp;
761 pState->u8Counter++;
762 if (pState->u8Counter == RINTCNT_N(pState))
763 break;
764 }
765 pState->au32Regs[ICH6_HDA_REG_CORBRP] = corbRp;
766 pState->au32Regs[ICH6_HDA_REG_RIRBWP] = rirbWp;
767 rc = hdaCmdSync(pState, false);
768 Log(("hda: CORB(RP:%x, WP:%x) RIRBWP:%x\n", CORBRP(pState), CORBWP(pState), RIRBWP(pState)));
769 if (RIRBCTL_RIRB_RIC(pState))
770 {
771 RIRBSTS((pState)) |= HDA_REG_FIELD_FLAG_MASK(RIRBSTS,RINTFL);
772 pState->u8Counter = 0;
773 rc = hdaProcessInterrupt(pState);
774 }
775 if (RT_FAILURE(rc))
776 AssertRCReturn(rc, rc);
777 return rc;
778}
779
780static void hdaStreamReset(INTELHDLinkState *pState, uint32_t u32Offset)
781{
782 Log(("hda: reset of stream (%x) started\n", u32Offset));
783 Log(("hda: reset of stream (%x) finished\n", u32Offset));
784}
785
786
787DECLCALLBACK(int)hdaRegReadUnimplemented(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t *pu32Value)
788{
789 *pu32Value = 0;
790 return VINF_SUCCESS;
791}
792DECLCALLBACK(int)hdaRegWriteUnimplemented(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t u32Value)
793{
794 return VINF_SUCCESS;
795}
796/* U8 */
797DECLCALLBACK(int)hdaRegReadU8(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t *pu32Value)
798{
799 Assert(((pState->au32Regs[index] & s_ichIntelHDRegMap[index].readable) & 0xffffff00) == 0);
800 return hdaRegReadU32(pState, offset, index, pu32Value);
801}
802
803DECLCALLBACK(int)hdaRegWriteU8(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t u32Value)
804{
805 Assert(((u32Value & 0xffffff00) == 0));
806 return hdaRegWriteU32(pState, offset, index, u32Value);
807}
808/* U16 */
809DECLCALLBACK(int)hdaRegReadU16(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t *pu32Value)
810{
811 Assert(((pState->au32Regs[index] & s_ichIntelHDRegMap[index].readable) & 0xffff0000) == 0);
812 return hdaRegReadU32(pState, offset, index, pu32Value);
813}
814
815DECLCALLBACK(int)hdaRegWriteU16(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t u32Value)
816{
817 Assert(((u32Value & 0xffff0000) == 0));
818 return hdaRegWriteU32(pState, offset, index, u32Value);
819}
820
821/* U24 */
822DECLCALLBACK(int)hdaRegReadU24(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t *pu32Value)
823{
824 Assert(((pState->au32Regs[index] & s_ichIntelHDRegMap[index].readable) & 0xff000000) == 0);
825 return hdaRegReadU32(pState, offset, index, pu32Value);
826}
827
828DECLCALLBACK(int)hdaRegWriteU24(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t u32Value)
829{
830 Assert(((u32Value & 0xff000000) == 0));
831 return hdaRegWriteU32(pState, offset, index, u32Value);
832}
833/* U32 */
834DECLCALLBACK(int)hdaRegReadU32(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t *pu32Value)
835{
836 *pu32Value = pState->au32Regs[index] & s_ichIntelHDRegMap[index].readable;
837 return VINF_SUCCESS;
838}
839
840DECLCALLBACK(int)hdaRegWriteU32(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t u32Value)
841{
842 pState->au32Regs[index] = (u32Value & s_ichIntelHDRegMap[index].writable)
843 | (pState->au32Regs[index] & ~s_ichIntelHDRegMap[index].writable);
844 return VINF_SUCCESS;
845}
846
847DECLCALLBACK(int)hdaRegReadGCTL(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t *pu32Value)
848{
849 return hdaRegReadU32(pState, offset, index, pu32Value);
850}
851
852DECLCALLBACK(int)hdaRegWriteGCTL(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t u32Value)
853{
854 if (u32Value & HDA_REG_FIELD_FLAG_MASK(GCTL, RST))
855 {
856 /* exit reset state */
857 GCTL(pState) |= HDA_REG_FIELD_FLAG_MASK(GCTL, RST);
858 pState->fInReset = false;
859 }
860 else
861 {
862 /* enter reset state*/
863 if ( HDA_REG_FLAG_VALUE(pState, CORBCTL, DMA)
864 || HDA_REG_FLAG_VALUE(pState, RIRBCTL, DMA))
865 {
866 Log(("hda: HDA enters in reset with DMA(RIRB:%s, CORB:%s)\n",
867 HDA_REG_FLAG_VALUE(pState, CORBCTL, DMA) ? "on" : "off",
868 HDA_REG_FLAG_VALUE(pState, RIRBCTL, DMA) ? "on" : "off"));
869 }
870 hdaReset(ICH6_HDASTATE_2_DEVINS(pState));
871 GCTL(pState) &= ~HDA_REG_FIELD_FLAG_MASK(GCTL, RST);
872 pState->fInReset = true;
873 }
874 if (u32Value & HDA_REG_FIELD_FLAG_MASK(GCTL, FSH))
875 {
876 /* Flush: GSTS:1 set, see 6.2.6*/
877 GSTS(pState) |= HDA_REG_FIELD_FLAG_MASK(GSTS, FSH); /* set the flush state */
878 /* DPLBASE and DPUBASE, should be initialized with initial value (see 6.2.6)*/
879 }
880 return VINF_SUCCESS;
881}
882
883DECLCALLBACK(int)hdaRegWriteSTATESTS(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t u32Value)
884{
885 uint32_t v = pState->au32Regs[index];
886 uint32_t nv = u32Value & ICH6_HDA_STATES_SCSF;
887 pState->au32Regs[index] = (v ^ nv) & v; /* write of 1 clears corresponding bit */
888 return VINF_SUCCESS;
889}
890
891DECLCALLBACK(int)hdaRegReadINTSTS(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t *pu32Value)
892{
893 uint32_t v = 0;
894 if ( RIRBSTS_RIRBOIS(pState)
895 || RIRBSTS_RINTFL(pState)
896 || HDA_REG_FLAG_VALUE(pState, CORBSTS, CMEI)
897 || STATESTS(pState))
898 v |= RT_BIT(30);
899#define HDA_IS_STREAM_EVENT(pState, stream) \
900 ( (SDSTS((pState),stream) & HDA_REG_FIELD_FLAG_MASK(SDSTS, DE)) \
901 || (SDSTS((pState),stream) & HDA_REG_FIELD_FLAG_MASK(SDSTS, FE)) \
902 || (SDSTS((pState),stream) & HDA_REG_FIELD_FLAG_MASK(SDSTS, BCIS)))
903#define MARK_STREAM(pState, stream, v) do {(v) |= HDA_IS_STREAM_EVENT((pState),stream) ? RT_BIT((stream)) : 0;}while(0)
904 MARK_STREAM(pState, 0, v);
905 MARK_STREAM(pState, 1, v);
906 MARK_STREAM(pState, 2, v);
907 MARK_STREAM(pState, 3, v);
908 MARK_STREAM(pState, 4, v);
909 MARK_STREAM(pState, 5, v);
910 MARK_STREAM(pState, 6, v);
911 MARK_STREAM(pState, 7, v);
912 v |= v ? RT_BIT(31) : 0;
913 *pu32Value = v;
914 return VINF_SUCCESS;
915}
916
917DECLCALLBACK(int)hdaRegReadGCAP(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t *pu32Value)
918{
919 return hdaRegReadU16(pState, offset, index, pu32Value);
920}
921
922DECLCALLBACK(int)hdaRegWriteCORBRP(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t u32Value)
923{
924 if (u32Value & HDA_REG_FIELD_FLAG_MASK(CORBRP, RST))
925 CORBRP(pState) = 0;
926 else
927 return hdaRegWriteU8(pState, offset, index, u32Value);
928 return VINF_SUCCESS;
929}
930
931DECLCALLBACK(int)hdaRegWriteCORBCTL(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t u32Value)
932{
933 int rc = hdaRegWriteU8(pState, offset, index, u32Value);
934 AssertRC(rc);
935 if ( CORBWP(pState) != CORBRP(pState)
936 && HDA_REG_FLAG_VALUE(pState, CORBCTL, DMA) != 0)
937 return hdaCORBCmdProcess(pState);
938 return rc;
939}
940
941DECLCALLBACK(int)hdaRegWriteCORBSTS(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t u32Value)
942{
943 uint32_t v = CORBSTS(pState);
944 v = (v ^ u32Value) & v;
945 CORBSTS(pState) = v;
946 return VINF_SUCCESS;
947}
948
949DECLCALLBACK(int)hdaRegWriteCORBWP(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t u32Value)
950{
951 int rc;
952 rc = hdaRegWriteU16(pState, offset, index, u32Value);
953 if (RT_FAILURE(rc))
954 AssertRCReturn(rc, rc);
955 if (CORBWP(pState) == CORBRP(pState))
956 return VINF_SUCCESS;
957 if (!HDA_REG_FLAG_VALUE(pState, CORBCTL, DMA))
958 return VINF_SUCCESS;
959 rc = hdaCORBCmdProcess(pState);
960 return rc;
961}
962
963DECLCALLBACK(int)hdaRegReadSDCTL(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t *pu32Value)
964{
965 return hdaRegReadU24(pState, offset, index, pu32Value);
966}
967#define HDA_STREAM_BITMASK(offset) (1 << (((offset) - 0x80) >> 5))
968#define HDA_IS_STREAM_IN_RESET(pState, offset) ((pState)->u8StreamsInReset & HDA_STREAM_BITMASK((offset)))
969DECLCALLBACK(int)hdaRegWriteSDCTL(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t u32Value)
970{
971 if(u32Value & HDA_REG_FIELD_FLAG_MASK(SDCTL, SRST))
972 {
973 LogRel(("hda: guest has iniated hw stream reset\n"));
974 pState->u8StreamsInReset |= HDA_STREAM_BITMASK(offset);
975 hdaStreamReset(pState, offset);
976 HDA_REG_IND(pState, index) &= ~HDA_REG_FIELD_FLAG_MASK(SDCTL, SRST);
977 }
978 else if (HDA_IS_STREAM_IN_RESET(pState, offset))
979 {
980 LogRel(("hda: guest has iniated exit of stream reset\n"));
981 pState->u8StreamsInReset &= ~HDA_STREAM_BITMASK(offset);
982 HDA_REG_IND(pState, index) &= ~HDA_REG_FIELD_FLAG_MASK(SDCTL, SRST);
983 }
984 /* @todo: use right offsets for right streams */
985 if (u32Value & HDA_REG_FIELD_FLAG_MASK(SDCTL, RUN))
986 {
987 Log(("hda: DMA(%x) switched on\n", offset));
988 if (offset == 0x80)
989 AUD_set_active_in(ISD0FMT_TO_AUDIO_SELECTOR(pState), 1);
990 if (offset == 0x100)
991 {
992 uint64_t u64BaseDMA = SDBDPL(pState, 4);
993 u64BaseDMA |= (((uint64_t)SDBDPU(pState, 4)) << 32);
994 if (u64BaseDMA)
995 AUD_set_active_out(OSD0FMT_TO_AUDIO_SELECTOR(pState), 1);
996 }
997 }
998 else
999 {
1000 Log(("hda: DMA(%x) switched off\n", offset));
1001 if (offset == 0x80)
1002 {
1003 AUD_set_active_in(ISD0FMT_TO_AUDIO_SELECTOR(pState), 0);
1004 }
1005 if (offset == 0x100)
1006 {
1007 SDSTS(pState, 4) &= ~(1<<5);
1008 AUD_set_active_out(OSD0FMT_TO_AUDIO_SELECTOR(pState), 0);
1009 }
1010 }
1011 int rc = hdaRegWriteU24(pState, offset, index, u32Value);
1012 if (RT_FAILURE(rc))
1013 AssertRCReturn(rc, VINF_SUCCESS);
1014 return rc;
1015}
1016
1017DECLCALLBACK(int)hdaRegWriteSDSTS(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t u32Value)
1018{
1019 uint32_t v = HDA_REG_IND(pState, index);
1020 v ^= (u32Value & v);
1021 HDA_REG_IND(pState, index) = v;
1022 hdaProcessInterrupt(pState);
1023#if 0
1024 if ( v != u32Value
1025 && (INTCTL_SALL(pState) & (1 << ((offset - 0x83) >> 5))))
1026 {
1027 int rc;
1028 rc = hdaProcessInterrupt(pState);
1029 if (RT_FAILURE(rc))
1030 AssertRCReturn(rc, rc);
1031 }
1032#endif
1033 return VINF_SUCCESS;
1034}
1035DECLCALLBACK(int)hdaRegWriteSDLVI(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t u32Value)
1036{
1037 int rc = hdaRegWriteU32(pState, offset, index, u32Value);
1038 if (RT_FAILURE(rc))
1039 AssertRCReturn(rc, VINF_SUCCESS);
1040 return rc;
1041}
1042
1043DECLCALLBACK(int)hdaRegWriteSDBDPL(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t u32Value)
1044{
1045 int rc = hdaRegWriteU32(pState, offset, index, u32Value);
1046 if (RT_FAILURE(rc))
1047 AssertRCReturn(rc, VINF_SUCCESS);
1048 return rc;
1049}
1050
1051DECLCALLBACK(int)hdaRegWriteSDBDPU(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t u32Value)
1052{
1053 int rc = hdaRegWriteU32(pState, offset, index, u32Value);
1054 if (RT_FAILURE(rc))
1055 AssertRCReturn(rc, VINF_SUCCESS);
1056 return rc;
1057}
1058
1059DECLCALLBACK(int)hdaRegWriteIRS(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t u32Value)
1060{
1061 int rc = VINF_SUCCESS;
1062 uint64_t resp;
1063 PFNCODECVERBPROCESSOR pfn = (PFNCODECVERBPROCESSOR)NULL;
1064 if ( u32Value & HDA_REG_FIELD_FLAG_MASK(IRS, ICB)
1065 && !IRS_ICB(pState))
1066 {
1067 uint32_t cmd = IC(pState);
1068 IRS(pState) = HDA_REG_FIELD_FLAG_MASK(IRS, ICB); /* busy */
1069 Log(("hda: IC:%x\n", cmd));
1070 rc = pState->Codec.pfnLookup(&pState->Codec, cmd, &pfn);
1071 if (RT_FAILURE(rc))
1072 AssertRCReturn(rc, rc);
1073 rc = pfn(&pState->Codec, cmd, &resp);
1074 if (RT_FAILURE(rc))
1075 AssertRCReturn(rc, rc);
1076 IR(pState) = (uint32_t)resp;
1077 Log(("hda: IR:%x\n", IR(pState)));
1078 IRS(pState) = HDA_REG_FIELD_FLAG_MASK(IRS, IRV); /* clear busy, result is ready */
1079 return rc;
1080 }
1081 if ( u32Value & HDA_REG_FIELD_FLAG_MASK(IRS, IRV)
1082 && IRS_IRV(pState))
1083 IRS(pState) ^= HDA_REG_FIELD_FLAG_MASK(IRS, IRV);
1084 return rc;
1085}
1086
1087DECLCALLBACK(int)hdaRegWriteRIRBWP(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t u32Value)
1088{
1089 if (u32Value & HDA_REG_FIELD_FLAG_MASK(RIRBWP, RST))
1090 {
1091 RIRBWP(pState) = 0;
1092 }
1093 /*The rest of bits are O, see 6.2.22 */
1094 return VINF_SUCCESS;
1095}
1096
1097DECLCALLBACK(int)hdaRegWriteBase(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t u32Value)
1098{
1099 int rc = hdaRegWriteU32(pState, offset, index, u32Value);
1100 if (RT_FAILURE(rc))
1101 AssertRCReturn(rc, rc);
1102 switch(index)
1103 {
1104 case ICH6_HDA_REG_CORBLBASE:
1105 pState->u64CORBBase &= 0xFFFFFFFF00000000ULL;
1106 pState->u64CORBBase |= pState->au32Regs[index];
1107 break;
1108 case ICH6_HDA_REG_CORBUBASE:
1109 pState->u64CORBBase &= 0x00000000FFFFFFFFULL;
1110 pState->u64CORBBase |= ((uint64_t)pState->au32Regs[index] << 32);
1111 break;
1112 case ICH6_HDA_REG_RIRLBASE:
1113 pState->u64RIRBBase &= 0xFFFFFFFF00000000ULL;
1114 pState->u64RIRBBase |= pState->au32Regs[index];
1115 break;
1116 case ICH6_HDA_REG_RIRUBASE:
1117 pState->u64RIRBBase &= 0x00000000FFFFFFFFULL;
1118 pState->u64RIRBBase |= ((uint64_t)pState->au32Regs[index] << 32);
1119 break;
1120 case ICH6_HDA_REG_DPLBASE:
1121 /* @todo: first bit has special meaning */
1122 pState->u64DPBase &= 0xFFFFFFFF00000000ULL;
1123 pState->u64DPBase |= pState->au32Regs[index];
1124 break;
1125 case ICH6_HDA_REG_DPUBASE:
1126 pState->u64DPBase &= 0x00000000FFFFFFFFULL;
1127 pState->u64DPBase |= ((uint64_t)pState->au32Regs[index] << 32);
1128 break;
1129 default:
1130 AssertMsgFailed(("Invalid index"));
1131 }
1132 Log(("hda: CORB base:%llx RIRB base: %llx DP base: %llx\n", pState->u64CORBBase, pState->u64RIRBBase, pState->u64DPBase));
1133 return rc;
1134}
1135
1136DECLCALLBACK(int)hdaRegWriteRIRBSTS(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t u32Value)
1137{
1138 uint8_t nv = u32Value;
1139 uint8_t v = RIRBSTS(pState);
1140 RIRBSTS(pState) = (v ^ nv) & v;
1141
1142 return hdaProcessInterrupt(pState);
1143}
1144
1145static void dump_bd(INTELHDLinkState *pState, PHDABDLEDESC pBdle, uint64_t u64BaseDMA)
1146{
1147 uint64_t addr;
1148 uint32_t len;
1149 uint32_t ioc;
1150 uint8_t bdle[16];
1151 uint32_t counter;
1152 uint32_t i;
1153 uint32_t sum = 0;
1154 Assert(pBdle && pBdle->u32BdleMaxCvi);
1155 for (i = 0; i <= pBdle->u32BdleMaxCvi; ++i)
1156 {
1157 PDMDevHlpPhysRead(ICH6_HDASTATE_2_DEVINS(pState), u64BaseDMA + i*16, bdle, 16);
1158 addr = *(uint64_t *)bdle;
1159 len = *(uint32_t *)&bdle[8];
1160 ioc = *(uint32_t *)&bdle[12];
1161 Log(("hda: %s bdle[%d] a:%lx, len:%x, ioc:%d\n", (i == pBdle->u32BdleCvi? "[C]": " "), i, addr, len, ioc));
1162 sum += len;
1163 }
1164 Log(("hda: sum: %d\n", sum));
1165 for (i = 0; i < 8; ++i)
1166 {
1167 PDMDevHlpPhysRead(ICH6_HDASTATE_2_DEVINS(pState), (pState->u64DPBase & DPBASE_ADDR_MASK) + i*8, &counter, sizeof(&counter));
1168 Log(("hda: %s stream[%d] counter=%x\n", i == SDCTL_NUM(pState, 4) || i == SDCTL_NUM(pState, 0)? "[C]": " ",
1169 i , counter));
1170 }
1171}
1172static void fetch_bd(INTELHDLinkState *pState, PHDABDLEDESC pBdle, uint64_t u64BaseDMA)
1173{
1174 uint8_t bdle[16];
1175 Assert((u64BaseDMA && pBdle && pBdle->u32BdleMaxCvi));
1176 PDMDevHlpPhysRead(ICH6_HDASTATE_2_DEVINS(pState), u64BaseDMA + pBdle->u32BdleCvi*16, bdle, 16);
1177 pBdle->u64BdleCviAddr = *(uint64_t *)bdle;
1178 pBdle->u32BdleCviLen = *(uint32_t *)&bdle[8];
1179 pBdle->fBdleCviIoc = (*(uint32_t *)&bdle[12]) & 0x1;
1180 dump_bd(pState, pBdle, u64BaseDMA);
1181}
1182
1183static uint32_t read_audio(INTELHDLinkState *pState, int avail, bool *fStop)
1184{
1185 uint8_t tmpbuf[4096];
1186 uint32_t temp;
1187 uint32_t u32Rest = 0;
1188 uint32_t cbRead = 0;
1189 uint32_t to_copy = 0;
1190 /* todo: add input line detection */
1191 PHDABDLEDESC pBdle = &pState->stInBdle;
1192 SWVoiceIn *voice = ISD0FMT_TO_AUDIO_SELECTOR(pState);
1193 u32Rest = pBdle->u32BdleCviLen - pBdle->u32BdleCviPos;
1194 temp = audio_MIN(u32Rest, (uint32_t)avail);
1195 if (!temp)
1196 {
1197 *fStop = true;
1198 return cbRead;
1199 }
1200 while (temp)
1201 {
1202 int copied;
1203 to_copy = audio_MIN(temp, 4096U);
1204 copied = AUD_read (voice, tmpbuf, to_copy);
1205 Log (("hda: read_audio max=%x to_copy=%x copied=%x\n",
1206 avail, to_copy, copied));
1207 if (!copied)
1208 {
1209 *fStop = true;
1210 break;
1211 }
1212 PDMDevHlpPhysWrite(ICH6_HDASTATE_2_DEVINS(pState), pBdle->u64BdleCviAddr + pBdle->u32BdleCviPos, tmpbuf, copied);
1213 temp -= copied;
1214 cbRead += copied;
1215 pBdle->u32BdleCviPos += copied;
1216 }
1217 return cbRead;
1218}
1219static uint32_t write_audio(INTELHDLinkState *pState, int avail, bool *fStop)
1220{
1221 uint8_t tmpbuf[4096];
1222 uint32_t temp;
1223 uint32_t u32Rest;
1224 uint32_t written = 0;
1225 int to_copy = 0;
1226 PHDABDLEDESC pBdle = &pState->stOutBdle;
1227 u32Rest = pBdle->u32BdleCviLen - pBdle->u32BdleCviPos;
1228 temp = audio_MIN(u32Rest, (uint32_t)avail);
1229 if (!temp)
1230 {
1231 *fStop = true;
1232 return written;
1233 }
1234 while (temp)
1235 {
1236 int copied;
1237 to_copy = audio_MIN(temp, 4096U);
1238 PDMDevHlpPhysRead(ICH6_HDASTATE_2_DEVINS(pState), pBdle->u64BdleCviAddr + pBdle->u32BdleCviPos, tmpbuf, to_copy);
1239 copied = AUD_write (OSD0FMT_TO_AUDIO_SELECTOR(pState), tmpbuf, to_copy);
1240 Log (("hda: write_audio max=%x to_copy=%x copied=%x\n",
1241 avail, to_copy, copied));
1242 Assert((copied));
1243 if (!copied)
1244 {
1245 *fStop = true;
1246 break;
1247 }
1248 temp -= copied;
1249 written += copied;
1250 pBdle->u32BdleCviPos += copied;
1251 }
1252 return written;
1253}
1254
1255DECLCALLBACK(int) hdaCodecReset(CODECState *pCodecState)
1256{
1257 INTELHDLinkState *pState = (INTELHDLinkState *)pCodecState->pHDAState;
1258 return VINF_SUCCESS;
1259}
1260
1261DECLCALLBACK(void) hdaTransfer(CODECState *pCodecState, ENMSOUNDSOURCE src, int avail)
1262{
1263 bool fStop = false;
1264 uint64_t u64BaseDMA = 0;
1265 PHDABDLEDESC pBdle = NULL;
1266 INTELHDLinkState *pState = (INTELHDLinkState *)pCodecState->pHDAState;
1267 uint32_t nBytes;
1268 uint32_t u32Ctl;
1269 uint32_t *pu32Sts;
1270 uint8_t u8Strm;
1271 uint32_t *pu32Lpib;
1272 uint32_t u32Lcbl;
1273 switch (src)
1274 {
1275 case PO_INDEX:
1276 {
1277 u8Strm = 4;
1278 u32Ctl = SDCTL(pState, 4);
1279 u64BaseDMA = SDBDPL(pState, 4);
1280 u64BaseDMA |= (((uint64_t)SDBDPU(pState, 4)) << 32);
1281 pu32Lpib = &SDLPIB(pState, 4);
1282 pu32Sts = &SDSTS(pState, 4);
1283 u32Lcbl = SDLCBL(pState, 4);
1284 pBdle = &pState->stOutBdle;
1285 pBdle->u32BdleMaxCvi = SDLVI(pState, 4);
1286 break;
1287 }
1288 case PI_INDEX:
1289 {
1290 u8Strm = 0;
1291 u32Ctl = SDCTL(pState, 0);
1292 pu32Lpib = &SDLPIB(pState, 0);
1293 pu32Sts = &SDSTS(pState, 0);
1294 u32Lcbl = SDLCBL(pState, 0);
1295 u64BaseDMA = SDBDPL(pState, 0);
1296 u64BaseDMA |= (((uint64_t)SDBDPU(pState, 0)) << 32);
1297 pBdle = &pState->stInBdle;
1298 pBdle->u32BdleMaxCvi = SDLVI(pState, 0);
1299 break;
1300 }
1301 default:
1302 return;
1303 }
1304 if ( !(u32Ctl & HDA_REG_FIELD_FLAG_MASK(SDCTL, RUN))
1305 || !avail
1306 || !u64BaseDMA)
1307 return;
1308 /* Fetch the Buffer Descriptor Entry (BDE). */
1309 fetch_bd(pState, pBdle, u64BaseDMA);
1310 while( avail && !fStop)
1311 {
1312 switch (src)
1313 {
1314 case PO_INDEX:
1315 nBytes = write_audio(pState, avail, &fStop);
1316 break;
1317 case PI_INDEX:
1318 nBytes = read_audio(pState, avail, &fStop);
1319 break;
1320 default:
1321 nBytes = 0;
1322 fStop = true;
1323 AssertMsgFailed(("Unsupported"));
1324 }
1325 /* Update the buffer position and handle Cyclic Buffer Length (CBL) wraparound. */
1326 *pu32Lpib += nBytes;
1327 avail -= nBytes;
1328 if (*pu32Lpib >= u32Lcbl)
1329 *pu32Lpib -= u32Lcbl;
1330
1331 /* Optionally write back the current DMA position. */
1332 if (pState->u64DPBase & DPBASE_ENABLED)
1333 PDMDevHlpPhysWrite(ICH6_HDASTATE_2_DEVINS(pState),
1334 (pState->u64DPBase & DPBASE_ADDR_MASK) + u8Strm*8, pu32Lpib, sizeof(*pu32Lpib));
1335
1336 /* Process end of buffer condition. */
1337 if (pBdle->u32BdleCviPos == pBdle->u32BdleCviLen)
1338 {
1339 if (pBdle->fBdleCviIoc)
1340 {
1341 *pu32Sts |= HDA_REG_FIELD_FLAG_MASK(SDSTS, BCIS);
1342 hdaProcessInterrupt(pState);
1343 }
1344 pBdle->u32BdleCviPos = 0;
1345 pBdle->u32BdleCvi++;
1346 if (pBdle->u32BdleCvi == pBdle->u32BdleMaxCvi + 1)
1347 {
1348 pBdle->u32BdleCvi = 0;
1349 }
1350 fStop = true; /* Give the guest a chance to refill (or empty) buffers. */
1351 }
1352 }
1353}
1354
1355/**
1356 * Handle register read operation.
1357 *
1358 * Looks up and calls appropriate handler.
1359 *
1360 * @note: while implementation was detected so called "forgotten" or "hole" registers
1361 * which description is missed in RPM, datasheet or spec.
1362 *
1363 * @returns VBox status code.
1364 *
1365 * @param pState The device state structure.
1366 * @param uOffset Register offset in memory-mapped frame.
1367 * @param pv Where to fetch the value.
1368 * @param cb Number of bytes to write.
1369 * @thread EMT
1370 */
1371PDMBOTHCBDECL(int) hdaMMIORead(PPDMDEVINS pDevIns, void *pvUser, RTGCPHYS GCPhysAddr, void *pv, unsigned cb)
1372{
1373 int rc = VINF_SUCCESS;
1374 PCIINTELHDLinkState *pThis = PDMINS_2_DATA(pDevIns, PCIINTELHDLinkState *);
1375 uint32_t u32Offset = GCPhysAddr - pThis->hda.addrMMReg;
1376 int index = hdaLookup(&pThis->hda, u32Offset);
1377 if (pThis->hda.fInReset && index != ICH6_HDA_REG_GCTL)
1378 {
1379 Log(("hda: access to registers except GCTL is blocked while reset\n"));
1380 }
1381 if ( index != -1
1382 && cb <= 4)
1383 {
1384 LogRel(("hda: Invalid read access @0x%x(of bytes:%d)\n", u32Offset, cb));
1385 }
1386 if (index != -1)
1387 {
1388 uint32_t mask = 0;
1389 uint32_t shift = (u32Offset - s_ichIntelHDRegMap[index].offset) % sizeof(uint32_t) * 8;
1390 uint32_t v = 0;
1391 switch(cb)
1392 {
1393 case 1: mask = 0x000000ff; break;
1394 case 2: mask = 0x0000ffff; break;
1395 case 3: mask = 0x00ffffff; break;
1396 case 4: mask = 0xffffffff; break;
1397 }
1398 mask <<= shift;
1399 rc = s_ichIntelHDRegMap[index].pfnRead(&pThis->hda, u32Offset, index, &v);
1400 *(uint32_t *)pv = (v & mask) >> shift;
1401 Log(("hda: read %s[%x/%x]\n", s_ichIntelHDRegMap[index].abbrev, v, *(uint32_t *)pv));
1402 return rc;
1403 }
1404 *(uint32_t *)pv = 0xFF;
1405 Log(("hda: hole at %X is accessed for read\n", u32Offset));
1406 return rc;
1407}
1408
1409/**
1410 * Handle register write operation.
1411 *
1412 * Looks up and calls appropriate handler.
1413 *
1414 * @returns VBox status code.
1415 *
1416 * @param pState The device state structure.
1417 * @param uOffset Register offset in memory-mapped frame.
1418 * @param pv Where to fetch the value.
1419 * @param cb Number of bytes to write.
1420 * @thread EMT
1421 */
1422PDMBOTHCBDECL(int) hdaMMIOWrite(PPDMDEVINS pDevIns, void *pvUser, RTGCPHYS GCPhysAddr, void *pv, unsigned cb)
1423{
1424 int rc = VINF_SUCCESS;
1425 PCIINTELHDLinkState *pThis = PDMINS_2_DATA(pDevIns, PCIINTELHDLinkState *);
1426 uint32_t u32Offset = GCPhysAddr - pThis->hda.addrMMReg;
1427 int index = hdaLookup(&pThis->hda, u32Offset);
1428 if (pThis->hda.fInReset && index != ICH6_HDA_REG_GCTL)
1429 {
1430 Log(("hda: access to registers except GCTL is blocked while reset\n"));
1431 }
1432 if ( index != -1
1433 && cb <= 4)
1434 {
1435 LogRel(("hda: Invalid write access @0x%x(of bytes:%d)\n", u32Offset, cb));
1436 }
1437 if (index != -1)
1438 {
1439 uint32_t v = pThis->hda.au32Regs[index];
1440 uint32_t mask = 0;
1441 uint32_t shift = (u32Offset - s_ichIntelHDRegMap[index].offset) % sizeof(uint32_t) * 8;
1442 switch(cb)
1443 {
1444 case 1: mask = 0xffffff00; break;
1445 case 2: mask = 0xffff0000; break;
1446 case 3: mask = 0xff000000; break;
1447 case 4: mask = 0x00000000; break;
1448 }
1449 mask <<= shift;
1450 *(uint32_t *)pv = ((v & mask) | (*(uint32_t *)pv & ~mask)) >> shift;
1451 rc = s_ichIntelHDRegMap[index].pfnWrite(&pThis->hda, u32Offset, index, *(uint32_t *)pv);
1452 Log(("hda: write %s:(%x) %x => %x\n", s_ichIntelHDRegMap[index].abbrev, *(uint32_t *)pv, v, pThis->hda.au32Regs[index]));
1453 return rc;
1454 }
1455 Log(("hda: hole at %X is accessed for write\n", u32Offset));
1456 return rc;
1457}
1458
1459/**
1460 * Callback function for mapping a PCI I/O region.
1461 *
1462 * @return VBox status code.
1463 * @param pPciDev Pointer to PCI device.
1464 * Use pPciDev->pDevIns to get the device instance.
1465 * @param iRegion The region number.
1466 * @param GCPhysAddress Physical address of the region.
1467 * If iType is PCI_ADDRESS_SPACE_IO, this is an
1468 * I/O port, else it's a physical address.
1469 * This address is *NOT* relative
1470 * to pci_mem_base like earlier!
1471 * @param enmType One of the PCI_ADDRESS_SPACE_* values.
1472 */
1473static DECLCALLBACK(int) hdaMap (PPCIDEVICE pPciDev, int iRegion,
1474 RTGCPHYS GCPhysAddress, uint32_t cb,
1475 PCIADDRESSSPACE enmType)
1476{
1477 int rc;
1478 PPDMDEVINS pDevIns = pPciDev->pDevIns;
1479 RTIOPORT Port = (RTIOPORT)GCPhysAddress;
1480 PCIINTELHDLinkState *pThis = PCIDEV_2_ICH6_HDASTATE(pPciDev);
1481
1482 Assert(enmType == PCI_ADDRESS_SPACE_MEM);
1483 rc = PDMDevHlpMMIORegister(pPciDev->pDevIns, GCPhysAddress, cb, 0,
1484 hdaMMIOWrite, hdaMMIORead, NULL, "ICH6_HDA");
1485
1486 if (RT_FAILURE(rc))
1487 return rc;
1488
1489 pThis->hda.addrMMReg = GCPhysAddress;
1490 return VINF_SUCCESS;
1491}
1492
1493/**
1494 * Saves a state of the HDA device.
1495 *
1496 * @returns VBox status code.
1497 * @param pDevIns The device instance.
1498 * @param pSSMHandle The handle to save the state to.
1499 */
1500static DECLCALLBACK(int) hdaSaveExec (PPDMDEVINS pDevIns, PSSMHANDLE pSSMHandle)
1501{
1502 PCIINTELHDLinkState *pThis = PDMINS_2_DATA(pDevIns, PCIINTELHDLinkState *);
1503 /* Save Codec nodes states */
1504 codecSaveState(&pThis->hda.Codec, pSSMHandle);
1505 /* Save MMIO registers */
1506 SSMR3PutMem (pSSMHandle, pThis->hda.au32Regs, sizeof (pThis->hda.au32Regs));
1507 /* Save HDA dma counters */
1508 SSMR3PutMem (pSSMHandle, &pThis->hda.stOutBdle, sizeof (HDABDLEDESC));
1509 SSMR3PutMem (pSSMHandle, &pThis->hda.stMicBdle, sizeof (HDABDLEDESC));
1510 SSMR3PutMem (pSSMHandle, &pThis->hda.stInBdle, sizeof (HDABDLEDESC));
1511 return VINF_SUCCESS;
1512}
1513
1514/**
1515 * Loads a saved HDA device state.
1516 *
1517 * @returns VBox status code.
1518 * @param pDevIns The device instance.
1519 * @param pSSMHandle The handle to the saved state.
1520 * @param uVersion The data unit version number.
1521 * @param uPass The data pass.
1522 */
1523static DECLCALLBACK(int) hdaLoadExec (PPDMDEVINS pDevIns, PSSMHANDLE pSSMHandle,
1524 uint32_t uVersion, uint32_t uPass)
1525{
1526 PCIINTELHDLinkState *pThis = PDMINS_2_DATA(pDevIns, PCIINTELHDLinkState *);
1527 /* Load Codec nodes states */
1528 AssertMsgReturn (uVersion == HDA_SSM_VERSION, ("%d\n", uVersion), VERR_SSM_UNSUPPORTED_DATA_UNIT_VERSION);
1529 Assert (uPass == SSM_PASS_FINAL); NOREF(uPass);
1530
1531 codecLoadState(&pThis->hda.Codec, pSSMHandle);
1532 /* Load MMIO registers */
1533 SSMR3GetMem (pSSMHandle, pThis->hda.au32Regs, sizeof (pThis->hda.au32Regs));
1534 /* Load HDA dma counters */
1535 SSMR3GetMem (pSSMHandle, &pThis->hda.stOutBdle, sizeof (HDABDLEDESC));
1536 SSMR3GetMem (pSSMHandle, &pThis->hda.stMicBdle, sizeof (HDABDLEDESC));
1537 SSMR3GetMem (pSSMHandle, &pThis->hda.stInBdle, sizeof (HDABDLEDESC));
1538
1539 AUD_set_active_in(ISD0FMT_TO_AUDIO_SELECTOR(&pThis->hda), SDCTL(&pThis->hda, 0) & HDA_REG_FIELD_FLAG_MASK(SDCTL, RUN));
1540 AUD_set_active_out(OSD0FMT_TO_AUDIO_SELECTOR(&pThis->hda), SDCTL(&pThis->hda, 4) & HDA_REG_FIELD_FLAG_MASK(SDCTL, RUN));
1541
1542 pThis->hda.u64CORBBase = CORBLBASE(&pThis->hda);
1543 pThis->hda.u64CORBBase |= ((uint64_t)CORBUBASE(&pThis->hda)) << 32;
1544 pThis->hda.u64RIRBBase = RIRLBASE(&pThis->hda);
1545 pThis->hda.u64RIRBBase |= ((uint64_t)RIRUBASE(&pThis->hda)) << 32;
1546 pThis->hda.u64DPBase = DPLBASE(&pThis->hda);
1547 pThis->hda.u64DPBase |= ((uint64_t)DPUBASE(&pThis->hda)) << 32;
1548 return VINF_SUCCESS;
1549}
1550
1551/**
1552 * Reset notification.
1553 *
1554 * @returns VBox status.
1555 * @param pDevIns The device instance data.
1556 *
1557 * @remark The original sources didn't install a reset handler, but it seems to
1558 * make sense to me so we'll do it.
1559 */
1560static DECLCALLBACK(void) hdaReset (PPDMDEVINS pDevIns)
1561{
1562 PCIINTELHDLinkState *pThis = PDMINS_2_DATA(pDevIns, PCIINTELHDLinkState *);
1563 GCAP(&pThis->hda) = 0x4401; /* see 6.2.1 */
1564 VMIN(&pThis->hda) = 0x00; /* see 6.2.2 */
1565 VMAJ(&pThis->hda) = 0x01; /* see 6.2.3 */
1566 VMAJ(&pThis->hda) = 0x01; /* see 6.2.3 */
1567 OUTPAY(&pThis->hda) = 0x003C; /* see 6.2.4 */
1568 INPAY(&pThis->hda) = 0x001D; /* see 6.2.5 */
1569 pThis->hda.au32Regs[ICH6_HDA_REG_CORBSIZE] = 0x42; /* see 6.2.1 */
1570 pThis->hda.au32Regs[ICH6_HDA_REG_RIRBSIZE] = 0x42; /* see 6.2.1 */
1571 CORBRP(&pThis->hda) = 0x0;
1572 RIRBWP(&pThis->hda) = 0x0;
1573
1574 LogRel(("hda: inter HDA reset.\n"));
1575 //** @todo r=michaln: There should be LogRel statements when the guest initializes
1576 // or resets the HDA chip, and possibly also when opening the PCM streams.
1577 pThis->hda.cbCorbBuf = 256 * sizeof(uint32_t);
1578
1579 if (pThis->hda.pu32CorbBuf)
1580 memset(pThis->hda.pu32CorbBuf, 0, pThis->hda.cbCorbBuf);
1581 else
1582 pThis->hda.pu32CorbBuf = (uint32_t *)RTMemAllocZ(pThis->hda.cbCorbBuf);
1583
1584 pThis->hda.cbRirbBuf = 256 * sizeof(uint64_t);
1585 if (pThis->hda.pu64RirbBuf)
1586 memset(pThis->hda.pu64RirbBuf, 0, pThis->hda.cbRirbBuf);
1587 else
1588 pThis->hda.pu64RirbBuf = (uint64_t *)RTMemAllocZ(pThis->hda.cbRirbBuf);
1589
1590 /* Accoding to ICH6 datasheet, 0x40000 is default value for stream descriptor register 23:20
1591 * bits are reserved for stream number 18.2.33 */
1592 SDCTL(&pThis->hda, 0) = 0x40000;
1593 SDCTL(&pThis->hda, 1) = 0x40000;
1594 SDCTL(&pThis->hda, 2) = 0x40000;
1595 SDCTL(&pThis->hda, 3) = 0x40000;
1596 SDCTL(&pThis->hda, 4) = 0x40000;
1597 SDCTL(&pThis->hda, 5) = 0x40000;
1598 SDCTL(&pThis->hda, 6) = 0x40000;
1599 SDCTL(&pThis->hda, 7) = 0x40000;
1600
1601 /* ICH6 defines default values (0x77 for input and 0xBF for output descriptors) of FIFO size. 18.2.39 */
1602 SDFIFOS(&pThis->hda, 0) = 0x77;
1603 SDFIFOS(&pThis->hda, 1) = 0x77;
1604 SDFIFOS(&pThis->hda, 2) = 0x77;
1605 SDFIFOS(&pThis->hda, 3) = 0x77;
1606 SDFIFOS(&pThis->hda, 4) = 0xBF;
1607 SDFIFOS(&pThis->hda, 5) = 0xBF;
1608 SDFIFOS(&pThis->hda, 6) = 0xBF;
1609 SDFIFOS(&pThis->hda, 7) = 0xBF;
1610
1611 /* emulateion of codec "wake up" HDA spec (5.5.1 and 6.5)*/
1612 STATESTS(&pThis->hda) = 0x1;
1613
1614 Log(("hda: reset finished\n"));
1615}
1616
1617/**
1618 * @interface_method_impl{PDMIBASE,pfnQueryInterface}
1619 */
1620static DECLCALLBACK(void *) hdaQueryInterface (struct PDMIBASE *pInterface,
1621 const char *pszIID)
1622{
1623 PCIINTELHDLinkState *pThis = RT_FROM_MEMBER(pInterface, PCIINTELHDLinkState, hda.IBase);
1624 Assert(&pThis->hda.IBase == pInterface);
1625
1626 PDMIBASE_RETURN_INTERFACE(pszIID, PDMIBASE, &pThis->hda.IBase);
1627 return NULL;
1628}
1629
1630//#define HDA_AS_PCI_EXPRESS
1631
1632/**
1633 * @interface_method_impl{PDMDEVREG,pfnConstruct}
1634 */
1635static DECLCALLBACK(int) hdaConstruct (PPDMDEVINS pDevIns, int iInstance,
1636 PCFGMNODE pCfgHandle)
1637{
1638 PCIINTELHDLinkState *pThis = PDMINS_2_DATA(pDevIns, PCIINTELHDLinkState *);
1639 INTELHDLinkState *s = &pThis->hda;
1640 int rc;
1641
1642 Assert(iInstance == 0);
1643 PDMDEV_CHECK_VERSIONS_RETURN(pDevIns);
1644
1645 /*
1646 * Validations.
1647 */
1648 if (!CFGMR3AreValuesValid (pCfgHandle, "\0"))
1649 return PDMDEV_SET_ERROR (pDevIns, VERR_PDM_DEVINS_UNKNOWN_CFG_VALUES,
1650 N_ ("Invalid configuration for the INTELHD device"));
1651
1652 // ** @todo r=michaln: This device may need R0/RC enabling, especially if guests
1653 // poll some register(s).
1654
1655 /*
1656 * Initialize data (most of it anyway).
1657 */
1658 s->pDevIns = pDevIns;
1659 /* IBase */
1660 s->IBase.pfnQueryInterface = hdaQueryInterface;
1661
1662 /* PCI Device (the assertions will be removed later) */
1663#if defined(VBOX_WITH_HP_HDA)
1664 /* Linux kernel has whitelist for MSI-enabled HDA, this card seems to be there. */
1665 PCIDevSetVendorId (&pThis->dev, 0x103c); /* HP. */
1666 PCIDevSetDeviceId (&pThis->dev, 0x30f7); /* HP Pavilion dv4t-1300 */
1667#elif defined(VBOX_WITH_INTEL_HDA)
1668 PCIDevSetVendorId (&pThis->dev, 0x8086); /* 00 ro - intel. */
1669 PCIDevSetDeviceId (&pThis->dev, 0x2668); /* 02 ro - 82801 / 82801aa(?). */
1670#elif defined(VBOX_WITH_NVIDIA_HDA)
1671 PCIDevSetVendorId (&pThis->dev, 0x10de); /* nVidia */
1672 PCIDevSetDeviceId (&pThis->dev, 0x0ac0); /* HDA */
1673#else
1674# error "Please specify your HDA device vendor/device IDs"
1675#endif
1676 PCIDevSetCommand (&pThis->dev, 0x0000); /* 04 rw,ro - pcicmd. */
1677 PCIDevSetStatus (&pThis->dev, VBOX_PCI_STATUS_CAP_LIST); /* 06 rwc?,ro? - pcists. */
1678 PCIDevSetRevisionId (&pThis->dev, 0x01); /* 08 ro - rid. */
1679 PCIDevSetClassProg (&pThis->dev, 0x00); /* 09 ro - pi. */
1680 PCIDevSetClassSub (&pThis->dev, 0x03); /* 0a ro - scc; 03 == HDA. */
1681 PCIDevSetClassBase (&pThis->dev, 0x04); /* 0b ro - bcc; 04 == multimedia. */
1682 PCIDevSetHeaderType (&pThis->dev, 0x00); /* 0e ro - headtyp. */
1683 PCIDevSetBaseAddress (&pThis->dev, 0, /* 10 rw - MMIO */
1684 false /* fIoSpace */, false /* fPrefetchable */, true /* f64Bit */, 0x00000000);
1685 PCIDevSetInterruptLine (&pThis->dev, 0x00); /* 3c rw. */
1686 PCIDevSetInterruptPin (&pThis->dev, 0x01); /* 3d ro - INTA#. */
1687
1688#if defined(HDA_AS_PCI_EXPRESS)
1689 PCIDevSetCapabilityList (&pThis->dev, 0x80);
1690#elif defined(VBOX_WITH_MSI_DEVICES)
1691 PCIDevSetCapabilityList (&pThis->dev, 0x60);
1692#else
1693 PCIDevSetCapabilityList (&pThis->dev, 0x50); /* ICH6 datasheet 18.1.16 */
1694#endif
1695
1696 //** @todo r=michaln: If there are really no PCIDevSetXx for these, the meaning
1697 // of these values needs to be properly documented!
1698 /* HDCTL off 0x40 bit 0 selects signaling mode (1-HDA, 0 - Ac97) 18.1.19 */
1699 PCIDevSetByte(&pThis->dev, 0x40, 0x01);
1700
1701 /* Power Management */
1702 PCIDevSetByte(&pThis->dev, 0x50 + 0, VBOX_PCI_CAP_ID_PM);
1703 PCIDevSetByte(&pThis->dev, 0x50 + 1, 0x0); /* next */
1704 PCIDevSetWord(&pThis->dev, 0x50 + 2, VBOX_PCI_PM_CAP_DSI | 0x02 /* version, PM1.1 */ );
1705
1706#ifdef HDA_AS_PCI_EXPRESS
1707 /* PCI Express */
1708 PCIDevSetByte (&pThis->dev, 0x80 + 0, VBOX_PCI_CAP_ID_EXP); /* PCI_Express */
1709 PCIDevSetByte (&pThis->dev, 0x80 + 1, 0x60); /* next */
1710 /* Device flags */
1711 PCIDevSetWord (&pThis->dev, 0x80 + 2,
1712 /* version */ 0x1 |
1713 /* Root Complex Integrated Endpoint */ (VBOX_PCI_EXP_TYPE_ROOT_INT_EP << 4) |
1714 /* MSI */ (100) << 9
1715 );
1716 /* Device capabilities */
1717 PCIDevSetDWord (&pThis->dev, 0x80 + 4, VBOX_PCI_EXP_DEVCAP_FLRESET);
1718 /* Device control */
1719 PCIDevSetWord (&pThis->dev, 0x80 + 8, 0);
1720 /* Device status */
1721 PCIDevSetWord (&pThis->dev, 0x80 + 10, 0);
1722 /* Link caps */
1723 PCIDevSetDWord (&pThis->dev, 0x80 + 12, 0);
1724 /* Link control */
1725 PCIDevSetWord (&pThis->dev, 0x80 + 16, 0);
1726 /* Link status */
1727 PCIDevSetWord (&pThis->dev, 0x80 + 18, 0);
1728 /* Slot capabilities */
1729 PCIDevSetDWord (&pThis->dev, 0x80 + 20, 0);
1730 /* Slot control */
1731 PCIDevSetWord (&pThis->dev, 0x80 + 24, 0);
1732 /* Slot status */
1733 PCIDevSetWord (&pThis->dev, 0x80 + 26, 0);
1734 /* Root control */
1735 PCIDevSetWord (&pThis->dev, 0x80 + 28, 0);
1736 /* Root capabilities */
1737 PCIDevSetWord (&pThis->dev, 0x80 + 30, 0);
1738 /* Root status */
1739 PCIDevSetDWord (&pThis->dev, 0x80 + 32, 0);
1740 /* Device capabilities 2 */
1741 PCIDevSetDWord (&pThis->dev, 0x80 + 36, 0);
1742 /* Device control 2 */
1743 PCIDevSetQWord (&pThis->dev, 0x80 + 40, 0);
1744 /* Link control 2 */
1745 PCIDevSetQWord (&pThis->dev, 0x80 + 48, 0);
1746 /* Slot control 2 */
1747 PCIDevSetWord (&pThis->dev, 0x80 + 56, 0);
1748#endif
1749
1750 /*
1751 * Register the PCI device.
1752 */
1753 rc = PDMDevHlpPCIRegister (pDevIns, &pThis->dev);
1754 if (RT_FAILURE (rc))
1755 return rc;
1756
1757 rc = PDMDevHlpPCIIORegionRegister (pDevIns, 0, 0x4000, PCI_ADDRESS_SPACE_MEM,
1758 hdaMap);
1759 if (RT_FAILURE (rc))
1760 return rc;
1761
1762#ifdef VBOX_WITH_MSI_DEVICES
1763 PDMMSIREG aMsiReg;
1764
1765 RT_ZERO(aMsiReg);
1766 aMsiReg.cMsiVectors = 1;
1767 aMsiReg.iMsiCapOffset = 0x60;
1768 aMsiReg.iMsiNextOffset = 0x50;
1769 rc = PDMDevHlpPCIRegisterMsi(pDevIns, &aMsiReg);
1770 if (RT_FAILURE (rc))
1771 {
1772 LogRel(("Chipset cannot do MSI: %Rrc\n", rc));
1773 PCIDevSetCapabilityList (&pThis->dev, 0x50);
1774 }
1775#endif
1776
1777 rc = PDMDevHlpSSMRegister (pDevIns, HDA_SSM_VERSION, sizeof(*pThis), hdaSaveExec, hdaLoadExec);
1778 if (RT_FAILURE (rc))
1779 return rc;
1780
1781 /*
1782 * Attach driver.
1783 */
1784 rc = PDMDevHlpDriverAttach (pDevIns, 0, &s->IBase,
1785 &s->pDrvBase, "Audio Driver Port");
1786 if (rc == VERR_PDM_NO_ATTACHED_DRIVER)
1787 Log (("hda: No attached driver!\n"));
1788 else if (RT_FAILURE (rc))
1789 {
1790 AssertMsgFailed (("Failed to attach INTELHD LUN #0! rc=%Rrc\n", rc));
1791 return rc;
1792 }
1793
1794
1795
1796 pThis->hda.Codec.pHDAState = (void *)&pThis->hda;
1797 rc = codecConstruct(&pThis->hda.Codec, /* ALC885_CODEC */ STAC9220_CODEC);
1798 if (RT_FAILURE(rc))
1799 AssertRCReturn(rc, rc);
1800
1801 /* ICH6 datasheet defines 0 values for SVID and SID (18.1.14-15), which together with values returned for
1802 verb F20 should provide device/codec recognition. */
1803 Assert(pThis->hda.Codec.u16VendorId);
1804 Assert(pThis->hda.Codec.u16DeviceId);
1805 PCIDevSetSubSystemVendorId (&pThis->dev, pThis->hda.Codec.u16VendorId); /* 2c ro - intel.) */
1806 PCIDevSetSubSystemId (&pThis->dev, pThis->hda.Codec.u16DeviceId); /* 2e ro. */
1807
1808 hdaReset (pDevIns);
1809 pThis->hda.Codec.id = 0;
1810 pThis->hda.Codec.pfnTransfer = hdaTransfer;
1811 pThis->hda.Codec.pfnReset = hdaCodecReset;
1812 /*
1813 * 18.2.6,7 defines that values of this registers might be cleared on power on/reset
1814 * hdaReset shouldn't affects these registers.
1815 */
1816 WAKEEN(&pThis->hda) = 0x0;
1817 STATESTS(&pThis->hda) = 0x0;
1818
1819 return VINF_SUCCESS;
1820}
1821
1822/**
1823 * @interface_method_impl{PDMDEVREG,pfnDestruct}
1824 */
1825static DECLCALLBACK(int) hdaDestruct (PPDMDEVINS pDevIns)
1826{
1827 PCIINTELHDLinkState *pThis = PDMINS_2_DATA(pDevIns, PCIINTELHDLinkState *);
1828
1829 int rc = codecDestruct(&pThis->hda.Codec);
1830 AssertRC(rc);
1831 if (pThis->hda.pu32CorbBuf)
1832 RTMemFree(pThis->hda.pu32CorbBuf);
1833 if (pThis->hda.pu64RirbBuf)
1834 RTMemFree(pThis->hda.pu64RirbBuf);
1835 return VINF_SUCCESS;
1836}
1837
1838/**
1839 * The device registration structure.
1840 */
1841const PDMDEVREG g_DeviceICH6_HDA =
1842{
1843 /* u32Version */
1844 PDM_DEVREG_VERSION,
1845 /* szName */
1846 "hda",
1847 /* szRCMod */
1848 "",
1849 /* szR0Mod */
1850 "",
1851 /* pszDescription */
1852 "ICH IntelHD Audio Controller",
1853 /* fFlags */
1854 PDM_DEVREG_FLAGS_DEFAULT_BITS,
1855 /* fClass */
1856 PDM_DEVREG_CLASS_AUDIO,
1857 /* cMaxInstances */
1858 1,
1859 /* cbInstance */
1860 sizeof(PCIINTELHDLinkState),
1861 /* pfnConstruct */
1862 hdaConstruct,
1863 /* pfnDestruct */
1864 hdaDestruct,
1865 /* pfnRelocate */
1866 NULL,
1867 /* pfnIOCtl */
1868 NULL,
1869 /* pfnPowerOn */
1870 NULL,
1871 /* pfnReset */
1872 hdaReset,
1873 /* pfnSuspend */
1874 NULL,
1875 /* pfnResume */
1876 NULL,
1877 /* pfnAttach */
1878 NULL,
1879 /* pfnDetach */
1880 NULL,
1881 /* pfnQueryInterface. */
1882 NULL,
1883 /* pfnInitComplete */
1884 NULL,
1885 /* pfnPowerOff */
1886 NULL,
1887 /* pfnSoftReset */
1888 NULL,
1889 /* u32VersionEnd */
1890 PDM_DEVREG_VERSION
1891};
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