VirtualBox

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

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

HDA: Added a few R/O registers.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 70.0 KB
Line 
1/* $Id: DevIchIntelHDA.cpp 31009 2010-07-22 15:41:21Z 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
43#define INTELHD_SSM_VERSION 1
44PDMBOTHCBDECL(int) hdaMMIORead(PPDMDEVINS pDevIns, void *pvUser, RTGCPHYS GCPhysAddr, void *pv, unsigned cb);
45PDMBOTHCBDECL(int) hdaMMIOWrite(PPDMDEVINS pDevIns, void *pvUser, RTGCPHYS GCPhysAddr, void *pv, unsigned cb);
46static DECLCALLBACK(void) hdaReset (PPDMDEVINS pDevIns);
47
48/* Registers */
49#define HDA_REG_IND_NAME(x) ICH6_HDA_REG_##x
50#define HDA_REG_FIELD_NAME(reg, x) ICH6_HDA_##reg##_##x
51#define HDA_REG_FIELD_MASK(reg, x) ICH6_HDA_##reg##_##x##_MASK
52#define HDA_REG_FIELD_FLAG_MASK(reg, x) RT_BIT(ICH6_HDA_##reg##_##x##_SHIFT)
53#define HDA_REG_FIELD_SHIFT(reg, x) ICH6_HDA_##reg##_##x##_SHIFT
54#define HDA_REG_IND(pState, x) ((pState)->au32Regs[(x)])
55#define HDA_REG(pState, x) (HDA_REG_IND((pState), HDA_REG_IND_NAME(x)))
56#define HDA_REG_VALUE(pState, reg, val) (HDA_REG((pState),reg) & (((HDA_REG_FIELD_MASK(reg, val))) << (HDA_REG_FIELD_SHIFT(reg, val))))
57#define HDA_REG_FLAG_VALUE(pState, reg, val) (HDA_REG((pState),reg) & (((HDA_REG_FIELD_FLAG_MASK(reg, val)))))
58#define HDA_REG_SVALUE(pState, reg, val) (HDA_REG_VALUE(pState, reg, val) >> (HDA_REG_FIELD_SHIFT(reg, val)))
59
60#define ICH6_HDA_REG_GCAP 0 /* range 0x00-0x01*/
61#define GCAP(pState) (HDA_REG((pState), GCAP))
62
63#define ICH6_HDA_REG_VMIN 1 /* range 0x02 */
64#define VMIN(pState) (HDA_REG((pState), VMIN))
65
66#define ICH6_HDA_REG_VMAJ 2 /* range 0x03 */
67#define VMAJ(pState) (HDA_REG((pState), VMAJ))
68
69#define ICH6_HDA_REG_OUTPAY 3 /* range 0x04-0x05 */
70#define OUTPAY(pState) (HDA_REG((pState), OUTPAY))
71
72#define ICH6_HDA_REG_INPAY 4 /* range 0x06-0x07 */
73#define INPAY(pState) (HDA_REG((pState), INPAY))
74
75#define ICH6_HDA_REG_GCTL (5)
76#define ICH6_HDA_GCTL_RST_SHIFT (0)
77#define ICH6_HDA_GCTL_FSH_SHIFT (1)
78#define GCTL(pState) (HDA_REG((pState), GCTL))
79
80#define ICH6_HDA_REG_STATES 7 /* range 0x0E */
81#define STATES(pState) (HDA_REG((pState), STATES))
82#define ICH6_HDA_STATES_SCSF 0x5
83
84#define ICH6_HDA_REG_GSTS 8 /* range 0x10-0x11*/
85#define ICH6_HDA_GSTS_FSH_SHIFT (1)
86#define GSTS(pState) (HDA_REG(pState, GSTS))
87
88#define ICH6_HDA_REG_INTCTL 9 /* 0x20 */
89#define ICH6_HDA_INTCTL_GIE_SHIFT 31
90#define ICH6_HDA_INTCTL_CIE_SHIFT 30
91#define ICH6_HDA_INTCTL_S0_SHIFT (0)
92#define ICH6_HDA_INTCTL_S1_SHIFT (1)
93#define ICH6_HDA_INTCTL_S2_SHIFT (2)
94#define ICH6_HDA_INTCTL_S3_SHIFT (3)
95#define ICH6_HDA_INTCTL_S4_SHIFT (4)
96#define ICH6_HDA_INTCTL_S5_SHIFT (5)
97#define ICH6_HDA_INTCTL_S6_SHIFT (6)
98#define ICH6_HDA_INTCTL_S7_SHIFT (7)
99#define INTCTL(pState) (HDA_REG((pState), INTCTL))
100#define INTCTL_GIE(pState) (HDA_REG_FLAG_VALUE(pState, INTCTL, GIE))
101#define INTCTL_CIE(pState) (HDA_REG_FLAG_VALUE(pState, INTCTL, CIE))
102#define INTCTL_SX(pState, X) (HDA_REG_FLAG_VALUE((pState), INTCTL, S##X))
103#define INTCTL_SALL(pState) (INTCTL((pState)) & 0xFF)
104
105/* Note: The HDA specification defines a SSYNC register at offset 0x38. The
106 * ICH6/ICH9 datahseet defines SSYNC at offset 0x34. The Linux HDA driver matches
107 * the datasheet.
108 */
109#define ICH6_HDA_REG_SSYNC 12 /* 0x34 */
110#define SSYNC(pState) (HDA_REG((pState), SSYNC))
111
112#define ICH6_HDA_REG_INTSTS 10 /* 0x24 */
113#define ICH6_HDA_INTSTS_GIS_SHIFT (31)
114#define ICH6_HDA_INTSTS_CIS_SHIFT (30)
115#define ICH6_HDA_INTSTS_S0_SHIFT (0)
116#define ICH6_HDA_INTSTS_S1_SHIFT (1)
117#define ICH6_HDA_INTSTS_S2_SHIFT (2)
118#define ICH6_HDA_INTSTS_S3_SHIFT (3)
119#define ICH6_HDA_INTSTS_S4_SHIFT (4)
120#define ICH6_HDA_INTSTS_S5_SHIFT (5)
121#define ICH6_HDA_INTSTS_S6_SHIFT (6)
122#define ICH6_HDA_INTSTS_S7_SHIFT (7)
123#define ICH6_HDA_INTSTS_S_MASK(num) RT_BIT(HDA_REG_FIELD_SHIFT(S##num))
124#define INTSTS(pState) (HDA_REG((pState), INTSTS))
125#define INTSTS_GIS(pState) (HDA_REG_FLAG_VALUE((pState), INTSTS, GIS)
126#define INTSTS_CIS(pState) (HDA_REG_FLAG_VALUE((pState), INTSTS, CIS)
127#define INTSTS_SX(pState, X) (HDA_REG_FLAG_VALUE(pState), INTSTS, S##X)
128#define INTSTS_SANY(pState) (INTSTS((pState)) & 0xFF)
129
130#define ICH6_HDA_REG_CORBLBASE 13 /* 0x40 */
131#define ICH6_HDA_REG_CORBUBASE 14 /* 0x44 */
132#define ICH6_HDA_REG_CORBWP 15 /* 48 */
133#define ICH6_HDA_REG_CORBRP 16 /* 4A */
134#define ICH6_HDA_CORBRP_RST_SHIFT 15
135#define ICH6_HDA_CORBRP_WP_SHIFT 0
136#define ICH6_HDA_CORBRP_WP_MASK 0xFF
137
138#define CORBRP(pState) (HDA_REG(pState, CORBRP))
139#define CORBWP(pState) (HDA_REG(pState, CORBWP))
140
141#define ICH6_HDA_REG_CORBCTL 17 /* 0x4C */
142#define ICH6_HDA_COBCTL_RUN_SHIFT (1)
143#define ICH6_HDA_COBCTL_CMEIE_SHIFT (0)
144
145#define ICH6_HDA_REG_CORBSTS 18 /* 0x4D */
146#define CORBSTS(pState) (HDA_REG(pState, CORBSTS))
147#define ICH6_HDA_CORBSTS_CMEI_SHIFT (0)
148
149#define ICH6_HDA_REG_CORBSIZE 19 /* 0x4E */
150#define ICH6_HDA_CORBSIZE_SZ_CAP 0xF0
151#define ICH6_HDA_CORBSIZE_SZ 0x3
152#define CORBSIZE_SZ(pState) (HDA_REG(pState, ICH6_HDA_REG_CORBSIZE) & ICH6_HDA_CORBSIZE_SZ)
153#define CORBSIZE_SZ_CAP(pState) (HDA_REG(pState, ICH6_HDA_REG_CORBSIZE) & ICH6_HDA_CORBSIZE_SZ_CAP)
154/* till ich 10 sizes of CORB and RIRB are harcoded to 256 in real hw */
155#define CORBSIZE(pState) (255)
156
157#define ICH6_HDA_REG_RIRLBASE 20 /* 0x50 */
158#define ICH6_HDA_REG_RIRUBASE 21 /* 0x54 */
159
160#define ICH6_HDA_REG_RIRBWP 22 /* 0x58 */
161#define ICH6_HDA_RIRBWP_RST_SHIFT (15)
162#define ICH6_HDA_RIRBWP_WP_MASK 0xFF
163#define RIRBWP(pState) (HDA_REG(pState, RIRBWP))
164
165#define ICH6_HDA_REG_RINTCNT 23 /* 0x5A */
166#define RINTCNT(pState) (HDA_REG((pState), RINTCNT))
167#define RINTCNT_N(pState) (RINTCNT((pState)) & 0xff)
168
169#define ICH6_HDA_REG_RIRBCTL 24 /* 0x5C */
170#define ICH6_HDA_RIRBCTL_RIC_SHIFT (0)
171#define ICH6_HDA_RIRBCTL_DMA_SHIFT (1)
172#define ICH6_HDA_ROI_DMA_SHIFT (2)
173#define RIRBCTL(pState) (HDA_REG((pState), RIRBCTL))
174#define RIRBCTL_RIRB_RIC(pState) (HDA_REG_FLAG_VALUE(pState, RIRBCTL, RIC))
175#define RIRBCTL_RIRB_DMA(pState) (HDA_REG_FLAG_VALUE((pState), RIRBCTL, DMA)
176#define RIRBCTL_ROI(pState) (HDA_REG_FLAG_VALUE((pState), RIRBCTL, ROI))
177
178#define ICH6_HDA_REG_RIRBSTS 25 /* 0x5D */
179#define ICH6_HDA_RIRBSTS_RINTFL_SHIFT (0)
180#define ICH6_HDA_RIRBSTS_RIRBOIS_SHIFT (2)
181#define RIRBSTS(pState) (HDA_REG(pState, RIRBSTS))
182#define RIRBSTS_RINTFL(pState) (HDA_REG_FLAG_VALUE(pState, RIRBSTS, RINTFL))
183#define RIRBSTS_RIRBOIS(pState) (HDA_REG_FLAG_VALUE(pState, RIRBSTS, RIRBOIS))
184
185#define ICH6_HDA_REG_RIRBSIZE 26 /* 0x5E */
186#define ICH6_HDA_RIRBSIZE_SZ_CAP 0xF0
187#define ICH6_HDA_RIRBSIZE_SZ 0x3
188
189#define RIRBSIZE_SZ(pState) (HDA_REG(pState, ICH6_HDA_REG_RIRBSIZE) & ICH6_HDA_RIRBSIZE_SZ)
190#define RIRBSIZE_SZ_CAP(pState) (HDA_REG(pState, ICH6_HDA_REG_RIRBSIZE) & ICH6_HDA_RIRBSIZE_SZ_CAP)
191#define RIRBSIZE(pState) (255)
192
193
194#define ICH6_HDA_REG_IC 27 /* 0x60 */
195#define IC(pState) (HDA_REG(pState, IC))
196#define ICH6_HDA_REG_IR 28 /* 0x64 */
197#define IR(pState) (HDA_REG(pState, IR))
198#define ICH6_HDA_REG_IRS 29 /* 0x68 */
199#define ICH6_HDA_IRS_ICB_SHIFT (0)
200#define ICH6_HDA_IRS_IRV_SHIFT (1)
201#define IRS(pState) (HDA_REG(pState, IRS))
202#define IRS_ICB(pState) (HDA_REG_FLAG_VALUE(pState, IRS, ICB))
203#define IRS_IRV(pState) (HDA_REG_FLAG_VALUE(pState, IRS, IRV))
204
205#define ICH6_HDA_REG_DPLBASE 30 /* 0x70 */
206#define DPLBASE(pState) (HDA_REG((pState), DPLBASE))
207#define ICH6_HDA_REG_DPUBASE 31 /* 0x74 */
208#define DPUBASE(pState) (HDA_REG((pState), DPUBASE))
209
210#define HDA_STREAM_REG_DEF(name, num) (ICH6_HDA_REG_SD##num##name)
211#define HDA_STREAM_REG(pState, name, num) (HDA_REG((pState), N_(HDA_STREAM_REG_DEF(name, num))))
212
213#define ICH6_HDA_REG_SD0CTL 32 /* 0x80 */
214#define ICH6_HDA_REG_SD1CTL (HDA_STREAM_REG_DEF(CTL, 0) + 10) /* 0xA0 */
215#define ICH6_HDA_REG_SD2CTL (HDA_STREAM_REG_DEF(CTL, 0) + 20) /* 0xC0 */
216#define ICH6_HDA_REG_SD3CTL (HDA_STREAM_REG_DEF(CTL, 0) + 30) /* 0xE0 */
217#define ICH6_HDA_REG_SD4CTL (HDA_STREAM_REG_DEF(CTL, 0) + 40) /* 0x100 */
218#define ICH6_HDA_REG_SD5CTL (HDA_STREAM_REG_DEF(CTL, 0) + 50) /* 0x120 */
219#define ICH6_HDA_REG_SD6CTL (HDA_STREAM_REG_DEF(CTL, 0) + 60) /* 0x140 */
220#define ICH6_HDA_REG_SD7CTL (HDA_STREAM_REG_DEF(CTL, 0) + 70) /* 0x160 */
221
222#define SD(func, num) SD##num##func
223#define SDCTL(pState, num) HDA_REG((pState), SD(CTL, num))
224#define SDCTL_NUM(pState, num) ((SDCTL((pState), num) & HDA_REG_FIELD_MASK(SDCTL,NUM)) >> HDA_REG_FIELD_SHIFT(SDCTL, NUM))
225#define ICH6_HDA_SDCTL_NUM_MASK (0xF)
226#define ICH6_HDA_SDCTL_NUM_SHIFT (20)
227#define ICH6_HDA_SDCTL_DEIE_SHIFT (4)
228#define ICH6_HDA_SDCTL_FEIE_SHIFT (3)
229#define ICH6_HDA_SDCTL_ICE_SHIFT (2)
230#define ICH6_HDA_SDCTL_RUN_SHIFT (1)
231#define ICH6_HDA_SDCTL_SRST_SHIFT (0)
232
233#define ICH6_HDA_REG_SD0STS 33 /* 0x83 */
234#define ICH6_HDA_REG_SD1STS (HDA_STREAM_REG_DEF(STS, 0) + 10) /* 0xA3 */
235#define ICH6_HDA_REG_SD2STS (HDA_STREAM_REG_DEF(STS, 0) + 20) /* 0xC3 */
236#define ICH6_HDA_REG_SD3STS (HDA_STREAM_REG_DEF(STS, 0) + 30) /* 0xE3 */
237#define ICH6_HDA_REG_SD4STS (HDA_STREAM_REG_DEF(STS, 0) + 40) /* 0x103 */
238#define ICH6_HDA_REG_SD5STS (HDA_STREAM_REG_DEF(STS, 0) + 50) /* 0x123 */
239#define ICH6_HDA_REG_SD6STS (HDA_STREAM_REG_DEF(STS, 0) + 60) /* 0x143 */
240#define ICH6_HDA_REG_SD7STS (HDA_STREAM_REG_DEF(STS, 0) + 70) /* 0x163 */
241
242#define SDSTS(pState, num) HDA_REG((pState), SD(STS, num))
243#define ICH6_HDA_SDSTS_FIFORDY_SHIFT (5)
244#define ICH6_HDA_SDSTS_DE_SHIFT (4)
245#define ICH6_HDA_SDSTS_FE_SHIFT (3)
246#define ICH6_HDA_SDSTS_BCIS_SHIFT (2)
247
248#define ICH6_HDA_REG_SD0LPIB 34 /* 0x84 */
249#define ICH6_HDA_REG_SD1LPIB (HDA_STREAM_REG_DEF(LPIB, 0) + 10) /* 0xA4 */
250#define ICH6_HDA_REG_SD2LPIB (HDA_STREAM_REG_DEF(LPIB, 0) + 20) /* 0xC4 */
251#define ICH6_HDA_REG_SD3LPIB (HDA_STREAM_REG_DEF(LPIB, 0) + 30) /* 0xE4 */
252#define ICH6_HDA_REG_SD4LPIB (HDA_STREAM_REG_DEF(LPIB, 0) + 40) /* 0x104 */
253#define ICH6_HDA_REG_SD5LPIB (HDA_STREAM_REG_DEF(LPIB, 0) + 50) /* 0x124 */
254#define ICH6_HDA_REG_SD6LPIB (HDA_STREAM_REG_DEF(LPIB, 0) + 60) /* 0x144 */
255#define ICH6_HDA_REG_SD7LPIB (HDA_STREAM_REG_DEF(LPIB, 0) + 70) /* 0x164 */
256
257#define SDLPIB(pState, num) HDA_REG((pState), SD(LPIB, num))
258
259#define ICH6_HDA_REG_SD0CBL 35 /* 0x88 */
260#define ICH6_HDA_REG_SD1CBL (HDA_STREAM_REG_DEF(CBL, 0) + 10) /* 0xA8 */
261#define ICH6_HDA_REG_SD2CBL (HDA_STREAM_REG_DEF(CBL, 0) + 20) /* 0xC8 */
262#define ICH6_HDA_REG_SD3CBL (HDA_STREAM_REG_DEF(CBL, 0) + 30) /* 0xE8 */
263#define ICH6_HDA_REG_SD4CBL (HDA_STREAM_REG_DEF(CBL, 0) + 40) /* 0x108 */
264#define ICH6_HDA_REG_SD5CBL (HDA_STREAM_REG_DEF(CBL, 0) + 50) /* 0x128 */
265#define ICH6_HDA_REG_SD6CBL (HDA_STREAM_REG_DEF(CBL, 0) + 60) /* 0x148 */
266#define ICH6_HDA_REG_SD7CBL (HDA_STREAM_REG_DEF(CBL, 0) + 70) /* 0x168 */
267
268#define SDLCBL(pState, num) HDA_REG((pState), SD(CBL, num))
269
270#define ICH6_HDA_REG_SD0LVI 36 /* 0x8C */
271#define ICH6_HDA_REG_SD1LVI (HDA_STREAM_REG_DEF(LVI, 0) + 10) /* 0xAC */
272#define ICH6_HDA_REG_SD2LVI (HDA_STREAM_REG_DEF(LVI, 0) + 20) /* 0xCC */
273#define ICH6_HDA_REG_SD3LVI (HDA_STREAM_REG_DEF(LVI, 0) + 30) /* 0xEC */
274#define ICH6_HDA_REG_SD4LVI (HDA_STREAM_REG_DEF(LVI, 0) + 40) /* 0x10C */
275#define ICH6_HDA_REG_SD5LVI (HDA_STREAM_REG_DEF(LVI, 0) + 50) /* 0x12C */
276#define ICH6_HDA_REG_SD6LVI (HDA_STREAM_REG_DEF(LVI, 0) + 60) /* 0x14C */
277#define ICH6_HDA_REG_SD7LVI (HDA_STREAM_REG_DEF(LVI, 0) + 70) /* 0x16C */
278
279#define SDLVI(pState, num) HDA_REG((pState), SD(LVI, num))
280
281#define ICH6_HDA_REG_SD0FIFOW 37 /* 0x8E */
282#define ICH6_HDA_REG_SD1FIFOW (HDA_STREAM_REG_DEF(FIFOW, 0) + 10) /* 0xAE */
283#define ICH6_HDA_REG_SD2FIFOW (HDA_STREAM_REG_DEF(FIFOW, 0) + 20) /* 0xCE */
284#define ICH6_HDA_REG_SD3FIFOW (HDA_STREAM_REG_DEF(FIFOW, 0) + 30) /* 0xEE */
285#define ICH6_HDA_REG_SD4FIFOW (HDA_STREAM_REG_DEF(FIFOW, 0) + 40) /* 0x10E */
286#define ICH6_HDA_REG_SD5FIFOW (HDA_STREAM_REG_DEF(FIFOW, 0) + 50) /* 0x12E */
287#define ICH6_HDA_REG_SD6FIFOW (HDA_STREAM_REG_DEF(FIFOW, 0) + 60) /* 0x14E */
288#define ICH6_HDA_REG_SD7FIFOW (HDA_STREAM_REG_DEF(FIFOW, 0) + 70) /* 0x16E */
289
290#define ICH6_HDA_REG_SD0FIFOS 38 /* 0x90 */
291#define ICH6_HDA_REG_SD1FIFOS (HDA_STREAM_REG_DEF(FIFOS, 0) + 10) /* 0xB0 */
292#define ICH6_HDA_REG_SD2FIFOS (HDA_STREAM_REG_DEF(FIFOS, 0) + 20) /* 0xD0 */
293#define ICH6_HDA_REG_SD3FIFOS (HDA_STREAM_REG_DEF(FIFOS, 0) + 30) /* 0xF0 */
294#define ICH6_HDA_REG_SD4FIFOS (HDA_STREAM_REG_DEF(FIFOS, 0) + 40) /* 0x110 */
295#define ICH6_HDA_REG_SD5FIFOS (HDA_STREAM_REG_DEF(FIFOS, 0) + 50) /* 0x130 */
296#define ICH6_HDA_REG_SD6FIFOS (HDA_STREAM_REG_DEF(FIFOS, 0) + 60) /* 0x150 */
297#define ICH6_HDA_REG_SD7FIFOS (HDA_STREAM_REG_DEF(FIFOS, 0) + 70) /* 0x170 */
298
299#define SDFIFOS(pState, num) HDA_REG((pState), SD(FIFOS, num))
300
301#define ICH6_HDA_REG_SD0FMT 39 /* 0x92 */
302#define ICH6_HDA_REG_SD1FMT (HDA_STREAM_REG_DEF(FMT, 0) + 10) /* 0xB2 */
303#define ICH6_HDA_REG_SD2FMT (HDA_STREAM_REG_DEF(FMT, 0) + 20) /* 0xD2 */
304#define ICH6_HDA_REG_SD3FMT (HDA_STREAM_REG_DEF(FMT, 0) + 30) /* 0xF2 */
305#define ICH6_HDA_REG_SD4FMT (HDA_STREAM_REG_DEF(FMT, 0) + 40) /* 0x112 */
306#define ICH6_HDA_REG_SD5FMT (HDA_STREAM_REG_DEF(FMT, 0) + 50) /* 0x132 */
307#define ICH6_HDA_REG_SD6FMT (HDA_STREAM_REG_DEF(FMT, 0) + 60) /* 0x152 */
308#define ICH6_HDA_REG_SD7FMT (HDA_STREAM_REG_DEF(FMT, 0) + 70) /* 0x172 */
309
310#define ICH6_HDA_REG_SD0BDPL 40 /* 0x98 */
311#define ICH6_HDA_REG_SD1BDPL (HDA_STREAM_REG_DEF(BDPL, 0) + 10) /* 0xB8 */
312#define ICH6_HDA_REG_SD2BDPL (HDA_STREAM_REG_DEF(BDPL, 0) + 20) /* 0xD8 */
313#define ICH6_HDA_REG_SD3BDPL (HDA_STREAM_REG_DEF(BDPL, 0) + 30) /* 0xF8 */
314#define ICH6_HDA_REG_SD4BDPL (HDA_STREAM_REG_DEF(BDPL, 0) + 40) /* 0x118 */
315#define ICH6_HDA_REG_SD5BDPL (HDA_STREAM_REG_DEF(BDPL, 0) + 50) /* 0x138 */
316#define ICH6_HDA_REG_SD6BDPL (HDA_STREAM_REG_DEF(BDPL, 0) + 60) /* 0x158 */
317#define ICH6_HDA_REG_SD7BDPL (HDA_STREAM_REG_DEF(BDPL, 0) + 70) /* 0x178 */
318
319#define SDBDPL(pState, num) HDA_REG((pState), SD(BDPL, num))
320
321#define ICH6_HDA_REG_SD0BDPU 41 /* 0x9C */
322#define ICH6_HDA_REG_SD1BDPU (HDA_STREAM_REG_DEF(BDPU, 0) + 10) /* 0xBC */
323#define ICH6_HDA_REG_SD2BDPU (HDA_STREAM_REG_DEF(BDPU, 0) + 20) /* 0xDC */
324#define ICH6_HDA_REG_SD3BDPU (HDA_STREAM_REG_DEF(BDPU, 0) + 30) /* 0xFC */
325#define ICH6_HDA_REG_SD4BDPU (HDA_STREAM_REG_DEF(BDPU, 0) + 40) /* 0x11C */
326#define ICH6_HDA_REG_SD5BDPU (HDA_STREAM_REG_DEF(BDPU, 0) + 50) /* 0x13C */
327#define ICH6_HDA_REG_SD6BDPU (HDA_STREAM_REG_DEF(BDPU, 0) + 60) /* 0x15C */
328#define ICH6_HDA_REG_SD7BDPU (HDA_STREAM_REG_DEF(BDPU, 0) + 70) /* 0x17C */
329
330#define SDBDPU(pState, num) HDA_REG((pState), SD(BDPU, num))
331
332/* Predicates */
333
334
335typedef struct INTELHDLinkState
336{
337 /** Pointer to the device instance. */
338 PPDMDEVINSR3 pDevIns;
339 /** Pointer to the connector of the attached audio driver. */
340 PPDMIAUDIOCONNECTOR pDrv;
341 /** Pointer to the attached audio driver. */
342 PPDMIBASE pDrvBase;
343 /** The base interface for LUN\#0. */
344 PDMIBASE IBase;
345 RTGCPHYS addrMMReg;
346 uint32_t au32Regs[113];
347 /* Current BD index */
348 uint32_t u32Cvi;
349 uint64_t u64CviAddr;
350 /* Length of current BD entry */
351 uint32_t u32CviLen;
352 uint32_t u32CviPos;
353 uint32_t u32Cbp;
354 /* Interrupt on completition */
355 bool fCviIoc;
356 uint64_t u64CORBBase;
357 uint64_t u64RIRBBase;
358 uint64_t u64DPBase;
359 uint8_t u8CORBRP;
360 uint8_t cResponse;
361 /* pointer on CORB buf */
362 uint32_t *pu32CorbBuf;
363 /* size in bytes of CORB buf */
364 uint32_t cbCorbBuf;
365 /* size in double words of CORB buf */
366 uint8_t cdwCorbBuf;
367 /* pointer on RIRB buf */
368 uint64_t *pu64RirbBuf;
369 /* size in bytes of RIRB buf */
370 uint32_t cbRirbBuf;
371 /* size in quad words of RIRB buf */
372 uint8_t cdqRirbBuf;
373 CODECState Codec;
374} INTELHDLinkState;
375
376#define ICH6_HDASTATE_2_DEVINS(pINTELHD) ((pINTELHD)->pDevIns)
377#define PCIDEV_2_ICH6_HDASTATE(pPciDev) ((PCIINTELHDLinkState *)(pPciDev))
378
379
380
381
382typedef struct PCIINTELHDLinkState
383{
384 PCIDevice dev;
385 INTELHDLinkState hda;
386} PCIINTELHDLinkState;
387
388DECLCALLBACK(int)hdaRegReadUnimplemented(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t *pu32Value);
389DECLCALLBACK(int)hdaRegWriteUnimplemented(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t pu32Value);
390DECLCALLBACK(int)hdaRegReadGCTL(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t *pu32Value);
391DECLCALLBACK(int)hdaRegWriteGCTL(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t pu32Value);
392DECLCALLBACK(int)hdaRegReadSTATESTS(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t *pu32Value);
393DECLCALLBACK(int)hdaRegWriteSTATESTS(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t pu32Value);
394DECLCALLBACK(int)hdaRegReadGCAP(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t *pu32Value);
395DECLCALLBACK(int)hdaRegReadINTSTS(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t *pu32Value);
396DECLCALLBACK(int)hdaRegWriteINTSTS(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t pu32Value);
397DECLCALLBACK(int)hdaRegWriteCORBWP(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t pu32Value);
398DECLCALLBACK(int)hdaRegWriteCORBRP(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t u32Value);
399DECLCALLBACK(int)hdaRegWriteCORBSTS(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t u32Value);
400DECLCALLBACK(int)hdaRegWriteRIRBWP(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t pu32Value);
401DECLCALLBACK(int)hdaRegWriteRIRBSTS(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t u32Value);
402DECLCALLBACK(int)hdaRegWriteIRS(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t u32Value);
403DECLCALLBACK(int)hdaRegWriteSDCTL(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t u32Value);
404DECLCALLBACK(int)hdaRegReadSDCTL(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t *pu32Value);
405
406DECLCALLBACK(int)hdaRegWriteSDSTS(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t u32Value);
407DECLCALLBACK(int)hdaRegWriteSDLVI(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t u32Value);
408DECLCALLBACK(int)hdaRegWriteSDBDPL(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t u32Value);
409DECLCALLBACK(int)hdaRegWriteSDBDPU(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t u32Value);
410DECLCALLBACK(int)hdaRegWriteBase(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t u32Value);
411DECLCALLBACK(int)hdaRegReadU32(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t *pu32Value);
412DECLCALLBACK(int)hdaRegWriteU32(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t pu32Value);
413DECLCALLBACK(int)hdaRegReadU24(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t *pu32Value);
414DECLCALLBACK(int)hdaRegWriteU24(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t pu32Value);
415DECLCALLBACK(int)hdaRegReadU16(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t *pu32Value);
416DECLCALLBACK(int)hdaRegWriteU16(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t pu32Value);
417DECLCALLBACK(int)hdaRegReadU8(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t *pu32Value);
418DECLCALLBACK(int)hdaRegWriteU8(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t pu32Value);
419static int hdaLookup(INTELHDLinkState* pState, uint32_t u32Offset);
420
421/* see 302349 p 6.2*/
422const static struct stIchIntelHDRegMap
423{
424 /** Register offset in the register space. */
425 uint32_t offset;
426 /** Size in bytes. Registers of size > 4 are in fact tables. */
427 uint32_t size;
428 /** Readable bits. */
429 uint32_t readable;
430 /** Writable bits. */
431 uint32_t writable;
432 /** Read callback. */
433 int (*pfnRead)(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t *pu32Value);
434 /** Write callback. */
435 int (*pfnWrite)(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t u32Value);
436 /** Abbreviated name. */
437 const char *abbrev;
438 /** Full name. */
439 const char *name;
440} s_ichIntelHDRegMap[] =
441{
442 /* offset size read mask write mask read callback write callback abbrev full name */
443 /*------- ------- ---------- ---------- ----------------------- ------------------------ ---------- ------------------------------*/
444 { 0x00000, 0x00002, 0x0000FFFB, 0x00000000, hdaRegReadGCAP , hdaRegWriteUnimplemented, "GCAP" , "Global Capabilities" },
445 { 0x00002, 0x00001, 0x000000FF, 0x00000000, hdaRegReadU8 , hdaRegWriteUnimplemented, "VMIN" , "Minor Version" },
446 { 0x00003, 0x00001, 0x000000FF, 0x00000000, hdaRegReadU8 , hdaRegWriteUnimplemented, "VMAJ" , "Major Version" },
447 { 0x00004, 0x00002, 0x0000FFFF, 0x00000000, hdaRegReadU16 , hdaRegWriteUnimplemented, "OUTPAY" , "Output Payload Capabilities" },
448 { 0x00006, 0x00002, 0x0000FFFF, 0x00000000, hdaRegReadU16 , hdaRegWriteUnimplemented, "INPAY" , "Input Payload Capabilities" },
449 { 0x00008, 0x00004, 0x00000103, 0x00000103, hdaRegReadGCTL , hdaRegWriteGCTL , "GCTL" , "Global Control" },
450 { 0x0000c, 0x00002, 0xFFFFFFFF, 0x00000000, hdaRegReadUnimplemented, hdaRegWriteUnimplemented, "WAKEEN" , "Wake Enable" },
451 { 0x0000e, 0x00002, 0x00000007, 0x00000007, hdaRegReadU8 , hdaRegWriteSTATESTS , "STATESTS" , "State Change Status" },
452 { 0x00010, 0x00002, 0xFFFFFFFF, 0x00000000, hdaRegReadUnimplemented, hdaRegWriteUnimplemented, "GSTS" , "Global Status" },
453 { 0x00020, 0x00004, 0xC00000FF, 0xC00000FF, hdaRegReadU32 , hdaRegWriteU32 , "INTCTL" , "Interrupt Control" },
454 { 0x00024, 0x00004, 0xC00000FF, 0x400000FF, hdaRegReadINTSTS , hdaRegWriteINTSTS , "INTSTS" , "Interrupt Status" },
455 //** @todo r=michaln: Are guests really not reading the WALCLK register at all?
456 { 0x00030, 0x00004, 0xFFFFFFFF, 0x00000000, hdaRegReadUnimplemented, hdaRegWriteUnimplemented, "WALCLK" , "Wall Clock Counter" },
457 //** @todo r=michaln: Doesn't the SSYNC register need to actually stop the stream(s)?
458 { 0x00034, 0x00004, 0x000000FF, 0x000000FF, hdaRegReadU32 , hdaRegWriteU32 , "SSYNC" , "Stream Synchronization" },
459 { 0x00040, 0x00004, 0xFFFFFF80, 0xFFFFFF80, hdaRegReadU32 , hdaRegWriteBase , "CORBLBASE" , "CORB Lower Base Address" },
460 { 0x00044, 0x00004, 0xFFFFFFFF, 0xFFFFFFFF, hdaRegReadU32 , hdaRegWriteBase , "CORBUBASE" , "CORB Upper Base Address" },
461 { 0x00048, 0x00002, 0x000000FF, 0x000000FF, hdaRegReadU16 , hdaRegWriteCORBWP , "CORBWP" , "CORB Write Pointer" },
462 { 0x0004A, 0x00002, 0x000000FF, 0x000080FF, hdaRegReadU8 , hdaRegWriteCORBRP , "CORBRP" , "CORB Read Pointer" },
463 { 0x0004C, 0x00001, 0x00000003, 0x00000003, hdaRegReadU8 , hdaRegWriteU8 , "CORBCTL" , "CORB Control" },
464 { 0x0004D, 0x00001, 0x00000001, 0x00000001, hdaRegReadU8 , hdaRegWriteCORBSTS , "CORBSTS" , "CORB Status" },
465 { 0x0004E, 0x00001, 0x000000F3, 0x00000000, hdaRegReadU8 , hdaRegWriteUnimplemented, "CORBSIZE" , "CORB Size" },
466 { 0x00050, 0x00004, 0xFFFFFF80, 0xFFFFFF80, hdaRegReadU32 , hdaRegWriteBase , "RIRBLBASE" , "RIRB Lower Base Address" },
467 { 0x00054, 0x00004, 0xFFFFFFFF, 0xFFFFFFFF, hdaRegReadU32 , hdaRegWriteBase , "RIRBUBASE" , "RIRB Upper Base Address" },
468 { 0x00058, 0x00002, 0x000000FF, 0x00008000, hdaRegReadU8, hdaRegWriteRIRBWP , "RIRBWP" , "RIRB Write Pointer" },
469 { 0x0005A, 0x00002, 0x000000FF, 0x000000FF, hdaRegReadU16 , hdaRegWriteU16 , "RINTCNT" , "Response Interrupt Count" },
470 { 0x0005C, 0x00001, 0x00000007, 0x00000007, hdaRegReadU8 , hdaRegWriteU8 , "RIRBCTL" , "RIRB Control" },
471 { 0x0005D, 0x00001, 0x00000005, 0x00000005, hdaRegReadU8 , hdaRegWriteRIRBSTS , "RIRBSTS" , "RIRB Status" },
472 { 0x0005E, 0x00001, 0x000000F3, 0x00000000, hdaRegReadU8 , hdaRegWriteUnimplemented, "RIRBSIZE" , "RIRB Size" },
473 { 0x00060, 0x00004, 0xFFFFFFFF, 0xFFFFFFFF, hdaRegReadU32 , hdaRegWriteU32 , "IC" , "Immediate Command" },
474 { 0x00064, 0x00004, 0x00000000, 0xFFFFFFFF, hdaRegReadU32 , hdaRegWriteUnimplemented, "IR" , "Immediate Response" },
475 { 0x00068, 0x00004, 0x00000002, 0x00000002, hdaRegReadU16 , hdaRegWriteIRS , "IRS" , "Immediate Command Status" },
476 { 0x00070, 0x00004, 0xFFFFFFFF, 0xFFFFFF81, hdaRegReadU32 , hdaRegWriteBase , "DPLBASE" , "DMA Position Lower Base" },
477 { 0x00074, 0x00004, 0xFFFFFFFF, 0xFFFFFFFF, hdaRegReadU32 , hdaRegWriteBase , "DPUBASE" , "DMA Position Upper Base" },
478
479 { 0x00080, 0x00003, 0x00FF001F, 0x00F0001F, hdaRegReadU24 , hdaRegWriteSDCTL , "ISD0CTL" , "Input Stream Descriptor 0 (ICD0) Control" },
480 { 0x00083, 0x00001, 0x0000001C, 0x0000003C, hdaRegReadU8 , hdaRegWriteSDSTS , "ISD0STS" , "ISD0 Status" },
481 { 0x00084, 0x00004, 0xFFFFFFFF, 0x00000000, hdaRegReadU32 , hdaRegWriteU32 , "ISD0LPIB" , "ISD0 Link Position In Buffer" },
482 { 0x00088, 0x00004, 0xFFFFFFFF, 0xFFFFFFFF, hdaRegReadU32 , hdaRegWriteU32 , "ISD0CBL" , "ISD0 Cyclic Buffer Length" },
483 { 0x0008C, 0x00002, 0x0000FFFF, 0x0000FFFF, hdaRegReadU16 , hdaRegWriteSDLVI , "ISD0LVI" , "ISD0 Last Valid Index" },
484 { 0x0008E, 0x00002, 0x00000005, 0x00000005, hdaRegReadU16 , hdaRegWriteU16 , "ISD0FIFOW", "ISD0 FIFO Watermark" },
485 { 0x00090, 0x00002, 0x000000FF, 0x000000FF, hdaRegReadU16 , hdaRegWriteU16 , "ISD0FIFOS", "ISD0 FIFO Size" },
486 { 0x00092, 0x00002, 0x00007F7F, 0x00007F7F, hdaRegReadU16 , hdaRegWriteU16 , "ISD0FMT" , "ISD0 Format" },
487 { 0x00098, 0x00004, 0xFFFFFF80, 0xFFFFFF80, hdaRegReadU32 , hdaRegWriteSDBDPL , "ISD0BDPL" , "ISD0 Buffer Descriptor List Pointer-Lower Base Address" },
488 { 0x0009C, 0x00004, 0xFFFFFFFF, 0xFFFFFFFF, hdaRegReadU32 , hdaRegWriteSDBDPU , "ISD0BDPU" , "ISD0 Buffer Descriptor List Pointer-Upper Base Address" },
489
490 { 0x000A0, 0x00003, 0x00FF001F, 0x00F0001F, hdaRegReadU24 , hdaRegWriteSDCTL , "ISD1CTL" , "Input Stream Descriptor 1 (ISD1) Control" },
491 { 0x000A3, 0x00001, 0x0000001C, 0x0000003C, hdaRegReadU8 , hdaRegWriteSDSTS , "ISD1STS" , "ISD1 Status" },
492 { 0x000A4, 0x00004, 0xFFFFFFFF, 0x00000000, hdaRegReadU32 , hdaRegWriteU32 , "ISD1LPIB" , "ISD1 Link Position In Buffer" },
493 { 0x000A8, 0x00004, 0xFFFFFFFF, 0xFFFFFFFF, hdaRegReadU32 , hdaRegWriteU32 , "ISD1CBL" , "ISD1 Cyclic Buffer Length" },
494 { 0x000AC, 0x00002, 0x0000FFFF, 0x0000FFFF, hdaRegReadU16 , hdaRegWriteSDLVI , "ISD1LVI" , "ISD1 Last Valid Index" },
495 { 0x000AE, 0x00002, 0x00000005, 0x00000005, hdaRegReadU16 , hdaRegWriteU16 , "ISD1FIFOW", "ISD1 FIFO Watermark" },
496 { 0x000B0, 0x00002, 0x000000FF, 0x000000FF, hdaRegReadU16 , hdaRegWriteU16 , "ISD1FIFOS", "ISD1 FIFO Size" },
497 { 0x000B2, 0x00002, 0x00007F7F, 0x00007F7F, hdaRegReadU16 , hdaRegWriteU16 , "ISD1FMT" , "ISD1 Format" },
498 { 0x000B8, 0x00004, 0xFFFFFF80, 0xFFFFFF80, hdaRegReadU32 , hdaRegWriteSDBDPL , "ISD1BDPL" , "ISD1 Buffer Descriptor List Pointer-Lower Base Address" },
499 { 0x000BC, 0x00004, 0xFFFFFFFF, 0xFFFFFFFF, hdaRegReadU32 , hdaRegWriteSDBDPU , "ISD1BDPU" , "ISD1 Buffer Descriptor List Pointer-Upper Base Address" },
500
501 { 0x000C0, 0x00003, 0x00FF001F, 0x00F0001F, hdaRegReadU24 , hdaRegWriteSDCTL , "ISD2CTL" , "Input Stream Descriptor 2 (ISD2) Control" },
502 { 0x000C3, 0x00001, 0x0000001C, 0x0000003C, hdaRegReadU8 , hdaRegWriteSDSTS , "ISD2STS" , "ISD2 Status" },
503 { 0x000C4, 0x00004, 0xFFFFFFFF, 0x00000000, hdaRegReadU32 , hdaRegWriteU32 , "ISD2LPIB" , "ISD2 Link Position In Buffer" },
504 { 0x000C8, 0x00004, 0xFFFFFFFF, 0xFFFFFFFF, hdaRegReadU32 , hdaRegWriteU32 , "ISD2CBL" , "ISD2 Cyclic Buffer Length" },
505 { 0x000CC, 0x00002, 0x0000FFFF, 0x0000FFFF, hdaRegReadU16 , hdaRegWriteSDLVI , "ISD2LVI" , "ISD2 Last Valid Index" },
506 { 0x000CE, 0x00002, 0x00000005, 0x00000005, hdaRegReadU16 , hdaRegWriteU16 , "ISD2FIFOW", "ISD2 FIFO Watermark" },
507 { 0x000D0, 0x00002, 0x000000FF, 0x000000FF, hdaRegReadU16 , hdaRegWriteU16 , "ISD2FIFOS", "ISD2 FIFO Size" },
508 { 0x000D2, 0x00002, 0x00007F7F, 0x00007F7F, hdaRegReadU16 , hdaRegWriteU16 , "ISD2FMT" , "ISD2 Format" },
509 { 0x000D8, 0x00004, 0xFFFFFF80, 0xFFFFFF80, hdaRegReadU32 , hdaRegWriteSDBDPL , "ISD2BDPL" , "ISD2 Buffer Descriptor List Pointer-Lower Base Address" },
510 { 0x000DC, 0x00004, 0xFFFFFFFF, 0xFFFFFFFF, hdaRegReadU32 , hdaRegWriteSDBDPU , "ISD2BDPU" , "ISD2 Buffer Descriptor List Pointer-Upper Base Address" },
511
512 { 0x000E0, 0x00003, 0x00FF001F, 0x00F0001F, hdaRegReadU24 , hdaRegWriteSDCTL , "ISD3CTL" , "Input Stream Descriptor 3 (ISD3) Control" },
513 { 0x000E3, 0x00001, 0x0000001C, 0x0000003C, hdaRegReadU8 , hdaRegWriteSDSTS , "ISD3STS" , "ISD3 Status" },
514 { 0x000E4, 0x00004, 0xFFFFFFFF, 0x00000000, hdaRegReadU32 , hdaRegWriteU32 , "ISD3LPIB" , "ISD3 Link Position In Buffer" },
515 { 0x000E8, 0x00004, 0xFFFFFFFF, 0xFFFFFFFF, hdaRegReadU32 , hdaRegWriteU32 , "ISD3CBL" , "ISD3 Cyclic Buffer Length" },
516 { 0x000EC, 0x00002, 0x0000FFFF, 0x0000FFFF, hdaRegReadU16 , hdaRegWriteSDLVI , "ISD3LVI" , "ISD3 Last Valid Index" },
517 { 0x000EE, 0x00002, 0x00000005, 0x00000005, hdaRegReadU16 , hdaRegWriteU16 , "ISD3FIFOW", "ISD3 FIFO Watermark" },
518 { 0x000F0, 0x00002, 0x000000FF, 0x000000FF, hdaRegReadU16 , hdaRegWriteU16 , "ISD3FIFOS", "ISD3 FIFO Size" },
519 { 0x000F2, 0x00002, 0x00007F7F, 0x00007F7F, hdaRegReadU16 , hdaRegWriteU16 , "ISD3FMT" , "ISD3 Format" },
520 { 0x000F8, 0x00004, 0xFFFFFF80, 0xFFFFFF80, hdaRegReadU32 , hdaRegWriteSDBDPL , "ISD3BDPL" , "ISD3 Buffer Descriptor List Pointer-Lower Base Address" },
521 { 0x000FC, 0x00004, 0xFFFFFFFF, 0xFFFFFFFF, hdaRegReadU32 , hdaRegWriteSDBDPU , "ISD3BDPU" , "ISD3 Buffer Descriptor List Pointer-Upper Base Address" },
522
523 { 0x00100, 0x00003, 0x00FF001F, 0x00F0001F, hdaRegReadSDCTL , hdaRegWriteSDCTL , "OSD0CTL" , "Input Stream Descriptor 0 (OSD0) Control" },
524 { 0x00103, 0x00001, 0x0000001C, 0x0000003C, hdaRegReadU8 , hdaRegWriteSDSTS , "OSD0STS" , "OSD0 Status" },
525 { 0x00104, 0x00004, 0xFFFFFFFF, 0x00000000, hdaRegReadU32 , hdaRegWriteU32 , "OSD0LPIB" , "OSD0 Link Position In Buffer" },
526 { 0x00108, 0x00004, 0xFFFFFFFF, 0xFFFFFFFF, hdaRegReadU32 , hdaRegWriteU32 , "OSD0CBL" , "OSD0 Cyclic Buffer Length" },
527 { 0x0010C, 0x00002, 0x0000FFFF, 0x0000FFFF, hdaRegReadU16 , hdaRegWriteSDLVI , "OSD0LVI" , "OSD0 Last Valid Index" },
528 { 0x0010E, 0x00002, 0x00000005, 0x00000005, hdaRegReadU16 , hdaRegWriteU16 , "OSD0FIFOW", "OSD0 FIFO Watermark" },
529 { 0x00110, 0x00002, 0x000000FF, 0x000000FF, hdaRegReadU16 , hdaRegWriteU16 , "OSD0FIFOS", "OSD0 FIFO Size" },
530 { 0x00112, 0x00002, 0x00007F7F, 0x00007F7F, hdaRegReadU16 , hdaRegWriteU16 , "OSD0FMT" , "OSD0 Format" },
531 { 0x00118, 0x00004, 0xFFFFFF80, 0xFFFFFF80, hdaRegReadU32 , hdaRegWriteSDBDPL , "OSD0BDPL" , "OSD0 Buffer Descriptor List Pointer-Lower Base Address" },
532 { 0x0011C, 0x00004, 0xFFFFFFFF, 0xFFFFFFFF, hdaRegReadU32 , hdaRegWriteSDBDPU , "OSD0BDPU" , "OSD0 Buffer Descriptor List Pointer-Upper Base Address" },
533
534 { 0x00120, 0x00003, 0x00FF001F, 0x00F0001F, hdaRegReadU24 , hdaRegWriteSDCTL , "OSD1CTL" , "Input Stream Descriptor 0 (OSD1) Control" },
535 { 0x00123, 0x00001, 0x0000001C, 0x0000003C, hdaRegReadU8 , hdaRegWriteSDSTS , "OSD1STS" , "OSD1 Status" },
536 { 0x00124, 0x00004, 0xFFFFFFFF, 0x00000000, hdaRegReadU32 , hdaRegWriteU32 , "OSD1LPIB" , "OSD1 Link Position In Buffer" },
537 { 0x00128, 0x00004, 0xFFFFFFFF, 0xFFFFFFFF, hdaRegReadU32 , hdaRegWriteU32 , "OSD1CBL" , "OSD1 Cyclic Buffer Length" },
538 { 0x0012C, 0x00002, 0x0000FFFF, 0x0000FFFF, hdaRegReadU16 , hdaRegWriteSDLVI , "OSD1LVI" , "OSD1 Last Valid Index" },
539 { 0x0012E, 0x00002, 0x00000005, 0x00000005, hdaRegReadU16 , hdaRegWriteU16 , "OSD1FIFOW", "OSD1 FIFO Watermark" },
540 { 0x00130, 0x00002, 0x000000FF, 0x000000FF, hdaRegReadU16 , hdaRegWriteU16 , "OSD1FIFOS", "OSD1 FIFO Size" },
541 { 0x00132, 0x00002, 0x00007F7F, 0x00007F7F, hdaRegReadU16 , hdaRegWriteU16 , "OSD1FMT" , "OSD1 Format" },
542 { 0x00138, 0x00004, 0xFFFFFF80, 0xFFFFFF80, hdaRegReadU32 , hdaRegWriteSDBDPL , "OSD1BDPL" , "OSD1 Buffer Descriptor List Pointer-Lower Base Address" },
543 { 0x0013C, 0x00004, 0xFFFFFFFF, 0xFFFFFFFF, hdaRegReadU32 , hdaRegWriteSDBDPU , "OSD1BDPU" , "OSD1 Buffer Descriptor List Pointer-Upper Base Address" },
544
545 { 0x00140, 0x00003, 0x00FF001F, 0x00F0001F, hdaRegReadU24 , hdaRegWriteSDCTL , "OSD2CTL" , "Input Stream Descriptor 0 (OSD2) Control" },
546 { 0x00143, 0x00001, 0x0000001C, 0x0000003C, hdaRegReadU8 , hdaRegWriteSDSTS , "OSD2STS" , "OSD2 Status" },
547 { 0x00144, 0x00004, 0xFFFFFFFF, 0x00000000, hdaRegReadU32 , hdaRegWriteU32 , "OSD2LPIB" , "OSD2 Link Position In Buffer" },
548 { 0x00148, 0x00004, 0xFFFFFFFF, 0xFFFFFFFF, hdaRegReadU32 , hdaRegWriteU32 , "OSD2CBL" , "OSD2 Cyclic Buffer Length" },
549 { 0x0014C, 0x00002, 0x0000FFFF, 0x0000FFFF, hdaRegReadU16 , hdaRegWriteSDLVI , "OSD2LVI" , "OSD2 Last Valid Index" },
550 { 0x0014E, 0x00002, 0x00000005, 0x00000005, hdaRegReadU16 , hdaRegWriteU16 , "OSD2FIFOW", "OSD2 FIFO Watermark" },
551 { 0x00150, 0x00002, 0x000000FF, 0x000000FF, hdaRegReadU16 , hdaRegWriteU16 , "OSD2FIFOS", "OSD2 FIFO Size" },
552 { 0x00152, 0x00002, 0x00007F7F, 0x00007F7F, hdaRegReadU16 , hdaRegWriteU16 , "OSD2FMT" , "OSD2 Format" },
553 { 0x00158, 0x00004, 0xFFFFFF80, 0xFFFFFF80, hdaRegReadU32 , hdaRegWriteSDBDPL , "OSD2BDPL" , "OSD2 Buffer Descriptor List Pointer-Lower Base Address" },
554 { 0x0015C, 0x00004, 0xFFFFFFFF, 0xFFFFFFFF, hdaRegReadU32 , hdaRegWriteSDBDPU , "OSD2BDPU" , "OSD2 Buffer Descriptor List Pointer-Upper Base Address" },
555
556 { 0x00160, 0x00003, 0x00FF001F, 0x00F0001F, hdaRegReadU24 , hdaRegWriteSDCTL , "OSD3CTL" , "Input Stream Descriptor 0 (OSD3) Control" },
557 { 0x00163, 0x00001, 0x0000001C, 0x0000003C, hdaRegReadU8 , hdaRegWriteSDSTS , "OSD3STS" , "OSD3 Status" },
558 { 0x00164, 0x00004, 0xFFFFFFFF, 0x00000000, hdaRegReadU32 , hdaRegWriteU32 , "OSD3LPIB" , "OSD3 Link Position In Buffer" },
559 { 0x00168, 0x00004, 0xFFFFFFFF, 0xFFFFFFFF, hdaRegReadU32 , hdaRegWriteU32 , "OSD3CBL" , "OSD3 Cyclic Buffer Length" },
560 { 0x0016C, 0x00002, 0x0000FFFF, 0x0000FFFF, hdaRegReadU16 , hdaRegWriteSDLVI , "OSD3LVI" , "OSD3 Last Valid Index" },
561 { 0x0016E, 0x00002, 0x00000005, 0x00000005, hdaRegReadU16 , hdaRegWriteU16 , "OSD3FIFOW", "OSD3 FIFO Watermark" },
562 { 0x00170, 0x00002, 0x000000FF, 0x000000FF, hdaRegReadU16 , hdaRegWriteU16 , "OSD3FIFOS", "OSD3 FIFO Size" },
563 { 0x00172, 0x00002, 0x00007F7F, 0x00007F7F, hdaRegReadU16 , hdaRegWriteU16 , "OSD3FMT" , "OSD3 Format" },
564 { 0x00178, 0x00004, 0xFFFFFF80, 0xFFFFFF80, hdaRegReadU32 , hdaRegWriteSDBDPL , "OSD3BDPL" , "OSD3 Buffer Descriptor List Pointer-Lower Base Address" },
565 { 0x0017C, 0x00004, 0xFFFFFFFF, 0xFFFFFFFF, hdaRegReadU32 , hdaRegWriteSDBDPU , "OSD3BDPU" , "OSD3 Buffer Descriptor List Pointer-Upper Base Address" },
566};
567
568static int hdaProcessInterrupt(INTELHDLinkState* pState)
569{
570 bool fIrq = false;
571 /* @todo add state change */
572 if( INTCTL_CIE(pState)
573 && ( RIRBSTS_RINTFL(pState)
574 || RIRBSTS_RIRBOIS(pState)))
575 {
576 INTSTS(pState) |= HDA_REG_FIELD_FLAG_MASK(INTSTS, CIS);
577 fIrq = true;
578 }
579 if ( INTCTL_SX(pState, 4)
580 && SDSTS(pState, 4) && HDA_REG_FIELD_FLAG_MASK(SDSTS, BCIS))
581 {
582 INTSTS(pState) |= HDA_REG_FIELD_FLAG_MASK(INTSTS, S4);
583 fIrq = true;
584 }
585 if (INTCTL_GIE(pState))
586 {
587 //** @todo r=michaln: This *must* be PCISetIrq instead
588
589 Log(("hda: irq %s\n", fIrq ? "asserted" : "deasserted"));
590 PDMDevHlpPCISetIrq(ICH6_HDASTATE_2_DEVINS(pState), 0 , fIrq);
591 }
592 return VINF_SUCCESS;
593}
594
595static int hdaLookup(INTELHDLinkState* pState, uint32_t u32Offset)
596{
597 int index = 0;
598 //** @todo r=michaln: A linear search of an array with over 100 elements is very inefficient.
599 for (;index < (int)(sizeof(s_ichIntelHDRegMap)/sizeof(s_ichIntelHDRegMap[0])); ++index)
600 {
601 if ( u32Offset >= s_ichIntelHDRegMap[index].offset
602 && u32Offset < s_ichIntelHDRegMap[index].offset + s_ichIntelHDRegMap[index].size)
603 {
604 return index;
605 }
606 }
607 return -1;
608}
609
610static int hdaCmdSync(INTELHDLinkState *pState, bool fLocal)
611{
612 int rc = VINF_SUCCESS;
613 if (fLocal)
614 {
615 rc = PDMDevHlpPhysRead(ICH6_HDASTATE_2_DEVINS(pState), pState->u64CORBBase, pState->pu32CorbBuf, pState->cbCorbBuf);
616 if (RT_FAILURE(rc))
617 AssertRCReturn(rc, rc);
618 uint8_t i = 0;
619 do
620 {
621 Log(("hda: corb%02x: ", i));
622 uint8_t j = 0;
623 do
624 {
625 const char *prefix;
626 if ((i + j) == CORBRP(pState))
627 prefix = "[R]";
628 else if ((i + j) == CORBWP(pState))
629 prefix = "[W]";
630 else
631 prefix = " "; /* three spaces */
632 Log(("%s%08x", prefix, pState->pu32CorbBuf[i + j]));
633 j++;
634 } while (j < 8);
635 Log(("\n"));
636 i += 8;
637 } while(i != 0);
638 }
639 else
640 {
641 rc = PDMDevHlpPhysWrite(ICH6_HDASTATE_2_DEVINS(pState), pState->u64RIRBBase, pState->pu64RirbBuf, pState->cbRirbBuf);
642 if (RT_FAILURE(rc))
643 AssertRCReturn(rc, rc);
644 uint8_t i = 0;
645 do {
646 Log(("hda: rirb%02x: ", i));
647 uint8_t j = 0;
648 do {
649 const char *prefix;
650 if ((i + j) == RIRBWP(pState))
651 prefix = "[W]";
652 else
653 prefix = " ";
654 Log((" %s%016x", prefix, pState->pu64RirbBuf[i + j]));
655 } while (++j < 8);
656 Log(("\n"));
657 i += 8;
658 } while (i != 0);
659 }
660 return rc;
661}
662static int hdaCORBCmdProcess(INTELHDLinkState *pState)
663{
664 int rc;
665 uint8_t corbRp;
666 uint8_t corbWp;
667 uint8_t rirbWp;
668
669 PFNCODECVERBPROCESSOR pfn = (PFNCODECVERBPROCESSOR)NULL;
670
671 rc = hdaCmdSync(pState, true);
672 if (RT_FAILURE(rc))
673 AssertRCReturn(rc, rc);
674 corbRp = CORBRP(pState);
675 corbWp = CORBWP(pState);
676 rirbWp = RIRBWP(pState);
677 Assert((corbWp != corbRp));
678 Log(("hda: CORB(RP:%x, WP:%x) RIRBWP:%x\n", CORBRP(pState), CORBWP(pState), RIRBWP(pState)));
679 while (corbRp != corbWp)
680 {
681 uint32_t cmd;
682 corbRp++;
683 cmd = pState->pu32CorbBuf[corbRp];
684 rc = (pState)->Codec.pfnLookup(&pState->Codec, cmd, &pfn);
685 if (RT_FAILURE(rc))
686 AssertRCReturn(rc, rc);
687 (rirbWp)++;
688 rc = pfn(&pState->Codec, cmd, &pState->pu64RirbBuf[rirbWp]);
689 if (RT_FAILURE(rc))
690 AssertRCReturn(rc, rc);
691 pState->cResponse++;
692 }
693 pState->au32Regs[ICH6_HDA_REG_CORBRP] = corbRp;
694 pState->au32Regs[ICH6_HDA_REG_RIRBWP] = rirbWp;
695 rc = hdaCmdSync(pState, false);
696 Log(("hda: CORB(RP:%x, WP:%x) RIRBWP:%x\n", CORBRP(pState), CORBWP(pState), RIRBWP(pState)));
697 if ( RIRBCTL_RIRB_RIC(pState)
698 && (pState)->cResponse == RINTCNT_N(pState))
699 {
700 RIRBSTS((pState)) |= HDA_REG_FIELD_FLAG_MASK(RIRBSTS,RINTFL);
701 rc = hdaProcessInterrupt(pState);
702 (pState)->cResponse = 0;
703 }
704 if (RT_FAILURE(rc))
705 AssertRCReturn(rc, rc);
706 return rc;
707}
708
709static void hdaStreamReset(INTELHDLinkState *pState, uint32_t u32Offset)
710{
711 Log(("hda: reset of stream (%x) started\n", u32Offset));
712 Log(("hda: reset of stream (%x) finished\n", u32Offset));
713}
714
715
716DECLCALLBACK(int)hdaRegReadUnimplemented(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t *pu32Value)
717{
718 *pu32Value = 0;
719 return VINF_SUCCESS;
720}
721DECLCALLBACK(int)hdaRegWriteUnimplemented(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t u32Value)
722{
723 return VINF_SUCCESS;
724}
725/* U8 */
726DECLCALLBACK(int)hdaRegReadU8(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t *pu32Value)
727{
728 Assert(((pState->au32Regs[index] & s_ichIntelHDRegMap[index].readable) & 0xffffff00) == 0);
729 return hdaRegReadU32(pState, offset, index, pu32Value);
730}
731
732DECLCALLBACK(int)hdaRegWriteU8(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t u32Value)
733{
734 Assert(((u32Value & 0xffffff00) == 0));
735 return hdaRegWriteU32(pState, offset, index, u32Value);
736}
737/* U16 */
738DECLCALLBACK(int)hdaRegReadU16(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t *pu32Value)
739{
740 Assert(((pState->au32Regs[index] & s_ichIntelHDRegMap[index].readable) & 0xffff0000) == 0);
741 return hdaRegReadU32(pState, offset, index, pu32Value);
742}
743
744DECLCALLBACK(int)hdaRegWriteU16(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t u32Value)
745{
746 Assert(((u32Value & 0xffff0000) == 0));
747 return hdaRegWriteU32(pState, offset, index, u32Value);
748}
749
750/* U24 */
751DECLCALLBACK(int)hdaRegReadU24(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t *pu32Value)
752{
753 Assert(((pState->au32Regs[index] & s_ichIntelHDRegMap[index].readable) & 0xff000000) == 0);
754 return hdaRegReadU32(pState, offset, index, pu32Value);
755}
756
757DECLCALLBACK(int)hdaRegWriteU24(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t u32Value)
758{
759 Assert(((u32Value & 0xff000000) == 0));
760 return hdaRegWriteU32(pState, offset, index, u32Value);
761}
762/* U32 */
763DECLCALLBACK(int)hdaRegReadU32(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t *pu32Value)
764{
765 *pu32Value = pState->au32Regs[index] & s_ichIntelHDRegMap[index].readable;
766 return VINF_SUCCESS;
767}
768
769DECLCALLBACK(int)hdaRegWriteU32(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t u32Value)
770{
771 pState->au32Regs[index] = (u32Value & s_ichIntelHDRegMap[index].writable)
772 | (pState->au32Regs[index] & ~s_ichIntelHDRegMap[index].writable);
773 return VINF_SUCCESS;
774}
775
776DECLCALLBACK(int)hdaRegReadGCTL(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t *pu32Value)
777{
778 return hdaRegReadU32(pState, offset, index, pu32Value);
779}
780
781DECLCALLBACK(int)hdaRegWriteGCTL(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t u32Value)
782{
783 if (u32Value & HDA_REG_FIELD_FLAG_MASK(GCTL, RST))
784 {
785 /* exit reset state */
786 GCTL(pState) |= HDA_REG_FIELD_FLAG_MASK(GCTL, RST);
787 }
788 else
789 {
790 /* enter reset state*/
791 hdaReset(ICH6_HDASTATE_2_DEVINS(pState));
792 }
793 if (u32Value & HDA_REG_FIELD_FLAG_MASK(GCTL, FSH))
794 {
795 /* Flush: GSTS:1 set, see 6.2.6*/
796 GSTS(pState) |= HDA_REG_FIELD_FLAG_MASK(GSTS, FSH); /* set the flush state */
797 /* DPLBASE and DPUBASE, should be initialized with initial value (see 6.2.6)*/
798 }
799 return VINF_SUCCESS;
800}
801
802DECLCALLBACK(int)hdaRegWriteSTATESTS(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t u32Value)
803{
804 uint32_t v = pState->au32Regs[index];
805 uint32_t nv = u32Value & ICH6_HDA_STATES_SCSF;
806 pState->au32Regs[index] = (v ^ nv) & v; /* write of 1 clears corresponding bit */
807 return VINF_SUCCESS;
808}
809
810DECLCALLBACK(int)hdaRegReadINTSTS(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t *pu32Value)
811{
812 uint32_t v = INTSTS(pState);
813 v &= ~HDA_REG_FIELD_FLAG_MASK(INTSTS, GIS);
814 v |= (v ? HDA_REG_FIELD_FLAG_MASK(INTSTS, GIS) : 0);
815 *pu32Value = v;
816 return VINF_SUCCESS;
817}
818
819DECLCALLBACK(int)hdaRegWriteINTSTS(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t u32Value)
820{
821 uint32_t v = INTSTS(pState);
822 INTSTS(pState) = (v ^ u32Value) & v;
823 return hdaProcessInterrupt(pState);
824}
825
826DECLCALLBACK(int)hdaRegReadGCAP(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t *pu32Value)
827{
828 return hdaRegReadU16(pState, offset, index, pu32Value);
829}
830
831DECLCALLBACK(int)hdaRegWriteCORBRP(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t u32Value)
832{
833 if (u32Value & HDA_REG_FIELD_FLAG_MASK(CORBRP, RST))
834 {
835 pState->u8CORBRP = 0;
836 CORBRP(pState) = 0;
837 }
838 else
839 return hdaRegWriteU8(pState, offset, index, u32Value);
840 return VINF_SUCCESS;
841}
842
843DECLCALLBACK(int)hdaRegWriteCORBSTS(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t u32Value)
844{
845 uint32_t v = CORBSTS(pState);
846 v = (v ^ u32Value) & v;
847 CORBSTS(pState) = v;
848 return VINF_SUCCESS;
849}
850
851DECLCALLBACK(int)hdaRegWriteCORBWP(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t u32Value)
852{
853 int rc;
854 rc = hdaRegWriteU16(pState, offset, index, u32Value);
855 if (RT_FAILURE(rc))
856 AssertRCReturn(rc, rc);
857 if (CORBWP(pState) == CORBRP(pState))
858 return VINF_SUCCESS;
859 rc = hdaCORBCmdProcess(pState);
860 return rc;
861}
862
863DECLCALLBACK(int)hdaRegReadSDCTL(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t *pu32Value)
864{
865 return hdaRegReadU24(pState, offset, index, pu32Value);
866}
867
868DECLCALLBACK(int)hdaRegWriteSDCTL(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t u32Value)
869{
870 if((u32Value & HDA_REG_FIELD_FLAG_MASK(SDCTL, SRST)))
871 {
872 hdaStreamReset(pState, offset);
873 }
874 /* @todo: use right offsets for right streams */
875 if (u32Value & HDA_REG_FIELD_FLAG_MASK(SDCTL, RUN))
876 {
877 Log(("hda: DMA(%x) switched on\n", offset));
878 AUD_set_active_in(pState->Codec.voice_pi, 1);
879 AUD_set_active_in(pState->Codec.voice_mc, 1);
880 if (offset == 0x100)
881 {
882 AUD_set_active_out(pState->Codec.voice_po, 1);
883 //SDSTS(pState, 4) |= (1<<5);
884 }
885 }
886 else
887 {
888 Log(("hda: DMA(%x) switched off\n", offset));
889 AUD_set_active_in(pState->Codec.voice_pi, 0);
890 AUD_set_active_in(pState->Codec.voice_mc, 0);
891 if (offset == 0x100)
892 {
893 SDSTS(pState, 4) &= ~(1<<5);
894 AUD_set_active_out(pState->Codec.voice_po, 0);
895 }
896 SSYNC(pState) &= ~(1<< (offset - 0x80));
897 }
898 int rc = hdaRegWriteU24(pState, offset, index, u32Value);
899 if (RT_FAILURE(rc))
900 AssertRCReturn(rc, VINF_SUCCESS);
901 return rc;
902}
903
904DECLCALLBACK(int)hdaRegWriteSDSTS(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t u32Value)
905{
906 uint32_t v = HDA_REG_IND(pState, index);
907 //int rc = hdaRegWriteU8(pState, offset, index, u32Value);
908 switch (offset)
909 {
910 case 0x83:
911 SDSTS(pState, 0) ^= u32Value;
912 break;
913 case 0xA3:
914 SDSTS(pState, 1) ^= u32Value;
915 break;
916 case 0xC3:
917 SDSTS(pState, 2) ^= u32Value;
918 break;
919 case 0xE3:
920 SDSTS(pState, 3) ^= u32Value;
921 break;
922 case 0x103:
923 SDSTS(pState, 4) ^= u32Value;
924 break;
925 case 0x123:
926 SDSTS(pState, 5) ^= u32Value;
927 break;
928 case 0x143:
929 SDSTS(pState, 6) ^= u32Value;
930 break;
931 case 0x163:
932 SDSTS(pState, 7) ^= u32Value;
933 break;
934 }
935 hdaProcessInterrupt(pState);
936#if 0
937 if ( v != u32Value
938 && (INTCTL_SALL(pState) & (1 << ((offset - 0x83) >> 5))))
939 {
940 int rc;
941 rc = hdaProcessInterrupt(pState);
942 if (RT_FAILURE(rc))
943 AssertRCReturn(rc, rc);
944 }
945#endif
946 return VINF_SUCCESS;
947}
948DECLCALLBACK(int)hdaRegWriteSDLVI(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t u32Value)
949{
950 int rc = hdaRegWriteU32(pState, offset, index, u32Value);
951 if (RT_FAILURE(rc))
952 AssertRCReturn(rc, VINF_SUCCESS);
953 return rc;
954}
955
956DECLCALLBACK(int)hdaRegWriteSDBDPL(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t u32Value)
957{
958 int rc = hdaRegWriteU32(pState, offset, index, u32Value);
959 if (RT_FAILURE(rc))
960 AssertRCReturn(rc, VINF_SUCCESS);
961 return rc;
962}
963
964DECLCALLBACK(int)hdaRegWriteSDBDPU(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t u32Value)
965{
966 int rc = hdaRegWriteU32(pState, offset, index, u32Value);
967 if (RT_FAILURE(rc))
968 AssertRCReturn(rc, VINF_SUCCESS);
969 return rc;
970}
971
972DECLCALLBACK(int)hdaRegWriteIRS(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t u32Value)
973{
974 int rc = VINF_SUCCESS;
975 uint64_t resp;
976 PFNCODECVERBPROCESSOR pfn = (PFNCODECVERBPROCESSOR)NULL;
977 if ( u32Value & HDA_REG_FIELD_FLAG_MASK(IRS, ICB)
978 && !IRS_ICB(pState))
979 {
980 uint32_t cmd = IC(pState);
981 IRS(pState) = HDA_REG_FIELD_FLAG_MASK(IRS, ICB); /* busy */
982 Log(("hda: IC:%x\n", cmd));
983 rc = pState->Codec.pfnLookup(&pState->Codec, cmd, &pfn);
984 if (RT_FAILURE(rc))
985 AssertRCReturn(rc, rc);
986 rc = pfn(&pState->Codec, cmd, &resp);
987 if (RT_FAILURE(rc))
988 AssertRCReturn(rc, rc);
989 IR(pState) = (uint32_t)resp;
990 Log(("hda: IR:%x\n", IR(pState)));
991 IRS(pState) = HDA_REG_FIELD_FLAG_MASK(IRS, IRV); /* clear busy, result is ready */
992 return rc;
993 }
994 if ( u32Value & HDA_REG_FIELD_FLAG_MASK(IRS, IRV)
995 && IRS_IRV(pState))
996 IRS(pState) ^= HDA_REG_FIELD_FLAG_MASK(IRS, IRV);
997 return rc;
998}
999
1000DECLCALLBACK(int)hdaRegWriteRIRBWP(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t u32Value)
1001{
1002 if (u32Value & HDA_REG_FIELD_FLAG_MASK(RIRBWP, RST))
1003 {
1004 RIRBWP(pState) = 0;
1005 }
1006 /*The rest of bits are O, see 6.2.22 */
1007 return VINF_SUCCESS;
1008}
1009
1010DECLCALLBACK(int)hdaRegWriteBase(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t u32Value)
1011{
1012 int rc = hdaRegWriteU32(pState, offset, index, u32Value);
1013 if (RT_FAILURE(rc))
1014 AssertRCReturn(rc, rc);
1015 switch(index)
1016 {
1017 case ICH6_HDA_REG_CORBLBASE:
1018 pState->u64CORBBase &= 0xFFFFFFFF00000000ULL;
1019 pState->u64CORBBase |= pState->au32Regs[index];
1020 break;
1021 case ICH6_HDA_REG_CORBUBASE:
1022 pState->u64CORBBase &= 0x00000000FFFFFFFFULL;
1023 pState->u64CORBBase |= ((uint64_t)pState->au32Regs[index] << 32);
1024 break;
1025 case ICH6_HDA_REG_RIRLBASE:
1026 pState->u64RIRBBase &= 0xFFFFFFFF00000000ULL;
1027 pState->u64RIRBBase |= pState->au32Regs[index];
1028 break;
1029 case ICH6_HDA_REG_RIRUBASE:
1030 pState->u64RIRBBase &= 0x00000000FFFFFFFFULL;
1031 pState->u64RIRBBase |= ((uint64_t)pState->au32Regs[index] << 32);
1032 break;
1033 case ICH6_HDA_REG_DPLBASE:
1034 /* @todo: first bit has special meaning */
1035 pState->u64DPBase &= 0xFFFFFFFF00000000ULL;
1036 pState->u64DPBase |= pState->au32Regs[index];
1037 break;
1038 case ICH6_HDA_REG_DPUBASE:
1039 pState->u64DPBase &= 0x00000000FFFFFFFFULL;
1040 pState->u64DPBase |= ((uint64_t)pState->au32Regs[index] << 32);
1041 break;
1042 default:
1043 AssertMsgFailed(("Invalid index"));
1044 }
1045 Log(("hda: CORB base:%llx RIRB base: %llx DP base: %llx\n", pState->u64CORBBase, pState->u64RIRBBase, pState->u64DPBase));
1046 return rc;
1047}
1048
1049DECLCALLBACK(int)hdaRegWriteRIRBSTS(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t u32Value)
1050{
1051 uint8_t nv = u32Value;
1052 uint8_t v = RIRBSTS(pState);
1053 RIRBSTS(pState) = (v ^ nv) & v;
1054
1055 return hdaProcessInterrupt(pState);
1056}
1057
1058static void dump_bd(INTELHDLinkState *pState)
1059{
1060 uint64_t addr;
1061 uint32_t len;
1062 uint32_t ioc;
1063 uint8_t bdle[16];
1064 uint32_t counter;
1065 uint32_t i;
1066 uint32_t sum = 0;
1067 for (i = 0; i <= SDLVI(pState, 4); ++i)
1068 {
1069 PDMDevHlpPhysRead(ICH6_HDASTATE_2_DEVINS(pState), SDBDPL(pState, 4) + i*16, bdle, 16);
1070 addr = *(uint64_t *)bdle;
1071 len = *(uint32_t *)&bdle[8];
1072 ioc = *(uint32_t *)&bdle[12];
1073 Log(("hda: %s bdle[%d] a:%x, len:%x, ios:%d\n", (i == pState->u32Cvi? "[C]": " "), i, addr, len, ioc));
1074 sum += len;
1075 }
1076 Log(("hda: sum: %d\n", sum));
1077 for (i = 0; i < 8; ++i)
1078 {
1079 PDMDevHlpPhysRead(ICH6_HDASTATE_2_DEVINS(pState), pState->u64DPBase + i*8, &counter, 4);
1080 Log(("hda: %s stream[%d] counter=%x\n", (i) == SDCTL_NUM(pState, 4)? "[C]": " ", i , counter));
1081 }
1082}
1083static void fetch_bd(INTELHDLinkState *pState)
1084{
1085 dump_bd(pState);
1086 pState->u32Cvi;
1087 uint8_t bdle[16];
1088 PDMDevHlpPhysRead(ICH6_HDASTATE_2_DEVINS(pState), SDBDPL(pState, 4) + pState->u32Cvi*16, bdle, 16);
1089 pState->u64CviAddr = *(uint64_t *)bdle;
1090 pState->u32CviLen = *(uint32_t *)&bdle[8];
1091 pState->fCviIoc = (*(uint32_t *)&bdle[12]) & 0x1;
1092}
1093
1094static uint32_t write_audio(INTELHDLinkState *pState, int avail, bool *fStop)
1095{
1096 uint8_t tmpbuf[4096];
1097 uint32_t temp;
1098 uint32_t u32Rest;
1099 uint32_t written = 0;
1100 int to_copy = 0;
1101 u32Rest = pState->u32CviLen - pState->u32CviPos;
1102 temp = audio_MIN(u32Rest, (uint32_t)avail);
1103 if (!temp)
1104 {
1105 *fStop = true;
1106 return written;
1107 }
1108 while (temp)
1109 {
1110 int copied;
1111 to_copy = audio_MIN(temp, 4096U);
1112 PDMDevHlpPhysRead(ICH6_HDASTATE_2_DEVINS(pState), pState->u64CviAddr + pState->u32CviPos, tmpbuf, to_copy);
1113 copied = AUD_write (pState->Codec.voice_po, tmpbuf, to_copy);
1114 Log (("hda: write_audio max=%x to_copy=%x copied=%x\n",
1115 avail, to_copy, copied));
1116 Assert((copied));
1117 if (!copied)
1118 {
1119 *fStop = true;
1120 break;
1121 }
1122 temp -= copied;
1123 written += copied;
1124 pState->u32CviPos += written;
1125 }
1126 return written;
1127}
1128
1129DECLCALLBACK(void) hdaTransfer(CODECState *pCodecState, ENMSOUNDSOURCE src, int avail)
1130{
1131 bool fStop = false;
1132 INTELHDLinkState *pState = (INTELHDLinkState *)pCodecState->pHDAState;
1133 switch(src)
1134 {
1135 case PO_INDEX:
1136 {
1137 uint32_t written;
1138 uint32_t u32Counter;
1139 if ( !(SDCTL(pState, 4) & HDA_REG_FIELD_FLAG_MASK(SDCTL, RUN))
1140 || avail == 0)
1141 return;
1142 SDCTL(pState, 4) |= ((pState->Codec.pNodes[2].adc.u32F06_param & (0x5 << 4)) >> 4) << 20;
1143 fetch_bd(pState);
1144 while( avail
1145 && !fStop)
1146 {
1147 PDMDevHlpPhysRead(ICH6_HDASTATE_2_DEVINS(pState), (pState->u64DPBase & ~0x1) + 4*8, &u32Counter, 4);
1148 written = write_audio(pState, avail, &fStop);
1149 if (fStop)
1150 break;
1151 SDLPIB(pState, 4) += written; /* bytes ? */
1152 avail -= written;
1153 u32Counter += written;
1154 PDMDevHlpPhysWrite(ICH6_HDASTATE_2_DEVINS(pState), (pState->u64DPBase & ~0x1) + 4*8, &u32Counter, 4);
1155 if (pState->u32CviPos == pState->u32CviLen
1156 || SDLPIB(pState, 4) == SDLCBL(pState, 4))
1157 {
1158 if ( SDCTL(pState, 4) & HDA_REG_FIELD_FLAG_MASK(SDCTL, ICE)
1159 && ( pState->u32CviPos == pState->u32CviLen
1160 || SDLPIB(pState, 4) == SDLCBL(pState, 4)))
1161 {
1162 SDSTS(pState,4) |= HDA_REG_FIELD_FLAG_MASK(SDSTS, BCIS);
1163 INTSTS(pState) |= HDA_REG_FIELD_FLAG_MASK(INTSTS, S4);
1164 hdaProcessInterrupt(pState);
1165 if (SDLPIB(pState, 4) == SDLCBL(pState, 4))
1166 {
1167 SDLPIB(pState, 4) = 0;
1168 u32Counter = 0;
1169 PDMDevHlpPhysWrite(ICH6_HDASTATE_2_DEVINS(pState), (pState->u64DPBase & ~0x1) + 4*8, &u32Counter, 4);
1170 }
1171 if (pState->u32CviPos == pState->u32CviLen)
1172 {
1173 pState->u32CviPos = 0;
1174 pState->u32Cvi++;
1175 if (pState->u32Cvi == SDLVI(pState, 4) + 1)
1176 pState->u32Cvi = 0;
1177 }
1178 }
1179 }
1180 fetch_bd(pState);
1181 }
1182 }
1183 break;
1184 AssertMsgFailed(("Unexpected index: %x\n", src));
1185 default:
1186 break;
1187 }
1188}
1189
1190/**
1191 * Handle register read operation.
1192 *
1193 * Looks up and calls appropriate handler.
1194 *
1195 * @note: while implementation was detected so called "forgotten" or "hole" registers
1196 * which description is missed in RPM, datasheet or spec.
1197 *
1198 * @returns VBox status code.
1199 *
1200 * @param pState The device state structure.
1201 * @param uOffset Register offset in memory-mapped frame.
1202 * @param pv Where to fetch the value.
1203 * @param cb Number of bytes to write.
1204 * @thread EMT
1205 */
1206PDMBOTHCBDECL(int) hdaMMIORead(PPDMDEVINS pDevIns, void *pvUser, RTGCPHYS GCPhysAddr, void *pv, unsigned cb)
1207{
1208 int rc = VINF_SUCCESS;
1209 PCIINTELHDLinkState *pThis = PDMINS_2_DATA(pDevIns, PCIINTELHDLinkState *);
1210 uint32_t u32Offset = GCPhysAddr - pThis->hda.addrMMReg;
1211 int index = hdaLookup(&pThis->hda, u32Offset);
1212 Assert( index != -1
1213 && u32Offset == s_ichIntelHDRegMap[index].offset
1214 && cb <= 4);
1215 if (index != -1)
1216 {
1217 uint32_t mask = 0;
1218 uint32_t v = 0;
1219 switch(cb)
1220 {
1221 case 1: mask = 0x000000ff; break;
1222 case 2: mask = 0x0000ffff; break;
1223 case 3: mask = 0x00ffffff; break;
1224 case 4: mask = 0xffffffff; break;
1225 }
1226 Assert(u32Offset == s_ichIntelHDRegMap[index].offset);
1227 rc = s_ichIntelHDRegMap[index].pfnRead(&pThis->hda, u32Offset, index, &v);
1228 *(uint32_t *)pv = v & mask;
1229 Log(("hda: read %s[%x/%x]\n", s_ichIntelHDRegMap[index].abbrev, v, *(uint32_t *)pv));
1230 return rc;
1231 }
1232 *(uint32_t *)pv = 0xFF;
1233 Log(("hda: hole at %X is accessed for read\n", u32Offset));
1234 return rc;
1235}
1236
1237/**
1238 * Handle register write operation.
1239 *
1240 * Looks up and calls appropriate handler.
1241 *
1242 * @returns VBox status code.
1243 *
1244 * @param pState The device state structure.
1245 * @param uOffset Register offset in memory-mapped frame.
1246 * @param pv Where to fetch the value.
1247 * @param cb Number of bytes to write.
1248 * @thread EMT
1249 */
1250PDMBOTHCBDECL(int) hdaMMIOWrite(PPDMDEVINS pDevIns, void *pvUser, RTGCPHYS GCPhysAddr, void *pv, unsigned cb)
1251{
1252 int rc = VINF_SUCCESS;
1253 PCIINTELHDLinkState *pThis = PDMINS_2_DATA(pDevIns, PCIINTELHDLinkState *);
1254 uint32_t u32Offset = GCPhysAddr - pThis->hda.addrMMReg;
1255 int index = hdaLookup(&pThis->hda, u32Offset);
1256 Assert( index != -1
1257 && u32Offset == s_ichIntelHDRegMap[index].offset
1258 && cb <= 4);
1259 if (index != -1)
1260 {
1261 Assert(u32Offset == s_ichIntelHDRegMap[index].offset);
1262 uint32_t v = pThis->hda.au32Regs[index];
1263 uint32_t mask = 0;
1264 switch(cb)
1265 {
1266 case 1: mask = 0xffffff00; break;
1267 case 2: mask = 0xffff0000; break;
1268 case 3: mask = 0xff000000; break;
1269 case 4: mask = 0x00000000; break;
1270 }
1271 *(uint32_t *)pv = (v & mask) | (*(uint32_t *)pv & ~mask);
1272 rc = s_ichIntelHDRegMap[index].pfnWrite(&pThis->hda, u32Offset, index, *(uint32_t *)pv);
1273 Log(("hda: write %s:(%x) %x => %x\n", s_ichIntelHDRegMap[index].abbrev, *(uint32_t *)pv, v, pThis->hda.au32Regs[index]));
1274 return rc;
1275 }
1276 Log(("hda: hole at %X is accessed for write\n", u32Offset));
1277 return rc;
1278}
1279
1280/**
1281 * Callback function for mapping a PCI I/O region.
1282 *
1283 * @return VBox status code.
1284 * @param pPciDev Pointer to PCI device.
1285 * Use pPciDev->pDevIns to get the device instance.
1286 * @param iRegion The region number.
1287 * @param GCPhysAddress Physical address of the region.
1288 * If iType is PCI_ADDRESS_SPACE_IO, this is an
1289 * I/O port, else it's a physical address.
1290 * This address is *NOT* relative
1291 * to pci_mem_base like earlier!
1292 * @param enmType One of the PCI_ADDRESS_SPACE_* values.
1293 */
1294static DECLCALLBACK(int) hdaMap (PPCIDEVICE pPciDev, int iRegion,
1295 RTGCPHYS GCPhysAddress, uint32_t cb,
1296 PCIADDRESSSPACE enmType)
1297{
1298 int rc;
1299 PPDMDEVINS pDevIns = pPciDev->pDevIns;
1300 RTIOPORT Port = (RTIOPORT)GCPhysAddress;
1301 PCIINTELHDLinkState *pThis = PCIDEV_2_ICH6_HDASTATE(pPciDev);
1302
1303 Assert(enmType == PCI_ADDRESS_SPACE_MEM);
1304 rc = PDMDevHlpMMIORegister(pPciDev->pDevIns, GCPhysAddress, cb, 0,
1305 hdaMMIOWrite, hdaMMIORead, NULL, "ICH6_HDA");
1306
1307 if (RT_FAILURE(rc))
1308 return rc;
1309
1310 pThis->hda.addrMMReg = GCPhysAddress;
1311 return VINF_SUCCESS;
1312}
1313
1314
1315/**
1316 * Reset notification.
1317 *
1318 * @returns VBox status.
1319 * @param pDevIns The device instance data.
1320 *
1321 * @remark The original sources didn't install a reset handler, but it seems to
1322 * make sense to me so we'll do it.
1323 */
1324static DECLCALLBACK(void) hdaReset (PPDMDEVINS pDevIns)
1325{
1326 PCIINTELHDLinkState *pThis = PDMINS_2_DATA(pDevIns, PCIINTELHDLinkState *);
1327 GCAP(&pThis->hda) = 0x4401; /* see 6.2.1 */
1328 VMIN(&pThis->hda) = 0x00; /* see 6.2.2 */
1329 VMAJ(&pThis->hda) = 0x01; /* see 6.2.3 */
1330 VMAJ(&pThis->hda) = 0x01; /* see 6.2.3 */
1331 OUTPAY(&pThis->hda) = 0x003C; /* see 6.2.4 */
1332 INPAY(&pThis->hda) = 0x001D; /* see 6.2.5 */
1333 pThis->hda.au32Regs[ICH6_HDA_REG_CORBSIZE] = 0x42; /* see 6.2.1 */
1334 pThis->hda.au32Regs[ICH6_HDA_REG_RIRBSIZE] = 0x42; /* see 6.2.1 */
1335 STATES(&pThis->hda) = 0x5;
1336 CORBRP(&pThis->hda) = 0x0;
1337 RIRBWP(&pThis->hda) = 0x0;
1338
1339 LogRel(("hda: inter HDA reset.\n"));
1340 //** @todo r=michaln: There should be LogRel statements when the guest initializes
1341 // or resets the HDA chip, and possibly also when opening the PCM streams.
1342 pThis->hda.cdwCorbBuf = CORBSIZE(&pThis->hda);
1343 pThis->hda.cbCorbBuf = CORBSIZE(&pThis->hda) * sizeof(uint32_t);
1344
1345 //** @todo r=michaln: Where are the Corb/RirbBuf allocations freed?
1346 if (pThis->hda.pu32CorbBuf)
1347 memset(pThis->hda.pu32CorbBuf, 0, pThis->hda.cbCorbBuf);
1348 else
1349 pThis->hda.pu32CorbBuf = (uint32_t *)RTMemAllocZ(pThis->hda.cbCorbBuf);
1350
1351 pThis->hda.cdqRirbBuf = RIRBSIZE(&pThis->hda);
1352 pThis->hda.cbRirbBuf = RIRBSIZE(&pThis->hda) * sizeof(uint64_t);
1353 if (pThis->hda.pu64RirbBuf)
1354 memset(pThis->hda.pu64RirbBuf, 0, pThis->hda.cbRirbBuf);
1355 else
1356 pThis->hda.pu64RirbBuf = (uint64_t *)RTMemAllocZ(pThis->hda.cbRirbBuf);
1357
1358 /* Accoding to ICH6 datasheet, 0x40000 is default value for stream descriptor register 23:20
1359 * bits are reserved for stream number 18.2.33 */
1360 SDCTL(&pThis->hda, 0) = 0x40000;
1361 SDCTL(&pThis->hda, 1) = 0x40000;
1362 SDCTL(&pThis->hda, 2) = 0x40000;
1363 SDCTL(&pThis->hda, 3) = 0x40000;
1364 SDCTL(&pThis->hda, 4) = 0x40000;
1365 SDCTL(&pThis->hda, 5) = 0x40000;
1366 SDCTL(&pThis->hda, 6) = 0x40000;
1367 SDCTL(&pThis->hda, 7) = 0x40000;
1368
1369 /* ICH6 defines default values (0x77 for input and 0xBF for output descriptors) of FIFO size. 18.2.39 */
1370 SDFIFOS(&pThis->hda, 0) = 0x77;
1371 SDFIFOS(&pThis->hda, 1) = 0x77;
1372 SDFIFOS(&pThis->hda, 2) = 0x77;
1373 SDFIFOS(&pThis->hda, 3) = 0x77;
1374 SDFIFOS(&pThis->hda, 4) = 0xBF;
1375 SDFIFOS(&pThis->hda, 5) = 0xBF;
1376 SDFIFOS(&pThis->hda, 6) = 0xBF;
1377 SDFIFOS(&pThis->hda, 7) = 0xBF;
1378
1379
1380 Log(("hda: reset finished\n"));
1381}
1382
1383/**
1384 * @interface_method_impl{PDMIBASE,pfnQueryInterface}
1385 */
1386static DECLCALLBACK(void *) hdaQueryInterface (struct PDMIBASE *pInterface,
1387 const char *pszIID)
1388{
1389 PCIINTELHDLinkState *pThis = RT_FROM_MEMBER(pInterface, PCIINTELHDLinkState, hda.IBase);
1390 Assert(&pThis->hda.IBase == pInterface);
1391
1392 PDMIBASE_RETURN_INTERFACE(pszIID, PDMIBASE, &pThis->hda.IBase);
1393 return NULL;
1394}
1395
1396/**
1397 * @interface_method_impl{PDMDEVREG,pfnConstruct}
1398 */
1399static DECLCALLBACK(int) hdaConstruct (PPDMDEVINS pDevIns, int iInstance,
1400 PCFGMNODE pCfgHandle)
1401{
1402 PCIINTELHDLinkState *pThis = PDMINS_2_DATA(pDevIns, PCIINTELHDLinkState *);
1403 INTELHDLinkState *s = &pThis->hda;
1404 int rc;
1405
1406 Assert(iInstance == 0);
1407 PDMDEV_CHECK_VERSIONS_RETURN(pDevIns);
1408
1409 /*
1410 * Validations.
1411 */
1412 if (!CFGMR3AreValuesValid (pCfgHandle, "\0"))
1413 return PDMDEV_SET_ERROR (pDevIns, VERR_PDM_DEVINS_UNKNOWN_CFG_VALUES,
1414 N_ ("Invalid configuration for the INTELHD device"));
1415
1416 // ** @todo r=michaln: This device may need R0/RC enabling, especially if guests
1417 // poll some register(s).
1418
1419 /*
1420 * Initialize data (most of it anyway).
1421 */
1422 s->pDevIns = pDevIns;
1423 /* IBase */
1424 s->IBase.pfnQueryInterface = hdaQueryInterface;
1425
1426 /* PCI Device (the assertions will be removed later) */
1427 PCIDevSetVendorId (&pThis->dev, 0x8086); /* 00 ro - intel. */
1428 PCIDevSetDeviceId (&pThis->dev, 0x2668); /* 02 ro - 82801 / 82801aa(?). */
1429 PCIDevSetCommand (&pThis->dev, 0x0000); /* 04 rw,ro - pcicmd. */
1430 PCIDevSetStatus (&pThis->dev, 0x0010); /* 06 rwc?,ro? - pcists. */
1431 PCIDevSetRevisionId (&pThis->dev, 0x01); /* 08 ro - rid. */
1432 PCIDevSetClassProg (&pThis->dev, 0x00); /* 09 ro - pi. */
1433 PCIDevSetClassSub (&pThis->dev, 0x03); /* 0a ro - scc; 01 == Audio. */
1434 PCIDevSetClassBase (&pThis->dev, 0x04); /* 0b ro - bcc; 04 == multimedia. */
1435 PCIDevSetHeaderType (&pThis->dev, 0x00); /* 0e ro - headtyp. */
1436 PCIDevSetBaseAddress (&pThis->dev, 0, /* 10 rw - MMIO */
1437 false /* fIoSpace */, false /* fPrefetchable */, true /* f64Bit */, 0x00000000);
1438 /* ICH6 datasheet defines 0 values for SVID and SID (18.1.14-15), which together with values returned for
1439 verb F20 should provide device/codec recognition. */
1440 PCIDevSetSubSystemVendorId (&pThis->dev, 0x0000); /* 2c ro - intel.) */
1441 PCIDevSetSubSystemId (&pThis->dev, 0x0000); /* 2e ro. */
1442 PCIDevSetInterruptLine (&pThis->dev, 0x00); /* 3c rw. */
1443 PCIDevSetInterruptPin (&pThis->dev, 0x01); /* 3d ro - INTA#. */ Assert (pThis->dev.config[0x3d] == 0x01);
1444 PCIDevSetCapabilityList(&pThis->dev, 0x50); /* ICH6 datasheet 18.1.16 */
1445
1446 //** @todo r=michaln: If there are really no PCIDevSetXx for these, the meaning
1447 // of these values needs to be properly documented!
1448 /* HDCTL off 0x40 bit 0 selects signaling mode (1-HDA, 0 - Ac97) 18.1.19 */
1449 pThis->dev.config[0x40] = 0x01;
1450
1451 pThis->dev.config[0x50] = 0x01;
1452 pThis->dev.config[0x51] = 0x60; /* next */
1453 pThis->dev.config[0x52] = 0x22;
1454 pThis->dev.config[0x53] = 0x00; /* PM - disabled, */
1455
1456 pThis->dev.config[0x60] = 0x05;
1457 pThis->dev.config[0x61] = 0x70; /* next */
1458 pThis->dev.config[0x62] = 0x00;
1459 pThis->dev.config[0x63] = 0x80;
1460
1461 /*
1462 * Register the PCI device.
1463 */
1464 rc = PDMDevHlpPCIRegister (pDevIns, &pThis->dev);
1465 if (RT_FAILURE (rc))
1466 return rc;
1467
1468 rc = PDMDevHlpPCIIORegionRegister (pDevIns, 0, 0x4000, PCI_ADDRESS_SPACE_MEM,
1469 hdaMap);
1470 if (RT_FAILURE (rc))
1471 return rc;
1472
1473 /*
1474 * Attach driver.
1475 */
1476 rc = PDMDevHlpDriverAttach (pDevIns, 0, &s->IBase,
1477 &s->pDrvBase, "Audio Driver Port");
1478 if (rc == VERR_PDM_NO_ATTACHED_DRIVER)
1479 Log (("hda: No attached driver!\n"));
1480 else if (RT_FAILURE (rc))
1481 {
1482 AssertMsgFailed (("Failed to attach INTELHD LUN #0! rc=%Rrc\n", rc));
1483 return rc;
1484 }
1485
1486
1487
1488 pThis->hda.Codec.pHDAState = (void *)&pThis->hda;
1489 rc = stac9220Construct(&pThis->hda.Codec);
1490 if (RT_FAILURE(rc))
1491 AssertRCReturn(rc, rc);
1492 hdaReset (pDevIns);
1493 pThis->hda.Codec.pfnTransfer = hdaTransfer;
1494
1495 return VINF_SUCCESS;
1496}
1497
1498/**
1499 * The device registration structure.
1500 */
1501const PDMDEVREG g_DeviceICH6_HDA =
1502{
1503 /* u32Version */
1504 PDM_DEVREG_VERSION,
1505 /* szName */
1506 "hda",
1507 /* szRCMod */
1508 "",
1509 /* szR0Mod */
1510 "",
1511 /* pszDescription */
1512 "ICH IntelHD Audio Controller",
1513 /* fFlags */
1514 PDM_DEVREG_FLAGS_DEFAULT_BITS,
1515 /* fClass */
1516 PDM_DEVREG_CLASS_AUDIO,
1517 /* cMaxInstances */
1518 1,
1519 /* cbInstance */
1520 sizeof(PCIINTELHDLinkState),
1521 /* pfnConstruct */
1522 hdaConstruct,
1523 /* pfnDestruct */
1524 NULL,
1525 /* pfnRelocate */
1526 NULL,
1527 /* pfnIOCtl */
1528 NULL,
1529 /* pfnPowerOn */
1530 NULL,
1531 /* pfnReset */
1532 hdaReset,
1533 /* pfnSuspend */
1534 NULL,
1535 /* pfnResume */
1536 NULL,
1537 /* pfnAttach */
1538 NULL,
1539 /* pfnDetach */
1540 NULL,
1541 /* pfnQueryInterface. */
1542 NULL,
1543 /* pfnInitComplete */
1544 NULL,
1545 /* pfnPowerOff */
1546 NULL,
1547 /* pfnSoftReset */
1548 NULL,
1549 /* u32VersionEnd */
1550 PDM_DEVREG_VERSION
1551};
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