2 * Copyright (C) 2010 Red Hat, Inc.
4 * written by Gerd Hoffmann <kraxel@redhat.com>
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 or
9 * (at your option) version 3 of the License.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
20 #include "qemu/osdep.h"
21 #include "hw/pci/pci.h"
22 #include "hw/qdev-properties.h"
23 #include "intel-hda.h"
24 #include "migration/vmstate.h"
25 #include "qemu/module.h"
26 #include "intel-hda-defs.h"
27 #include "audio/audio.h"
29 #include "qom/object.h"
31 /* -------------------------------------------------------------------------- */
33 typedef struct desc_param
{
38 typedef struct desc_node
{
41 const desc_param
*params
;
49 typedef struct desc_codec
{
52 const desc_node
*nodes
;
56 static const desc_param
* hda_codec_find_param(const desc_node
*node
, uint32_t id
)
60 for (i
= 0; i
< node
->nparams
; i
++) {
61 if (node
->params
[i
].id
== id
) {
62 return &node
->params
[i
];
68 static const desc_node
* hda_codec_find_node(const desc_codec
*codec
, uint32_t nid
)
72 for (i
= 0; i
< codec
->nnodes
; i
++) {
73 if (codec
->nodes
[i
].nid
== nid
) {
74 return &codec
->nodes
[i
];
80 static void hda_codec_parse_fmt(uint32_t format
, struct audsettings
*as
)
82 if (format
& AC_FMT_TYPE_NON_PCM
) {
86 as
->freq
= (format
& AC_FMT_BASE_44K
) ? 44100 : 48000;
88 switch ((format
& AC_FMT_MULT_MASK
) >> AC_FMT_MULT_SHIFT
) {
89 case 1: as
->freq
*= 2; break;
90 case 2: as
->freq
*= 3; break;
91 case 3: as
->freq
*= 4; break;
94 switch ((format
& AC_FMT_DIV_MASK
) >> AC_FMT_DIV_SHIFT
) {
95 case 1: as
->freq
/= 2; break;
96 case 2: as
->freq
/= 3; break;
97 case 3: as
->freq
/= 4; break;
98 case 4: as
->freq
/= 5; break;
99 case 5: as
->freq
/= 6; break;
100 case 6: as
->freq
/= 7; break;
101 case 7: as
->freq
/= 8; break;
104 switch (format
& AC_FMT_BITS_MASK
) {
105 case AC_FMT_BITS_8
: as
->fmt
= AUDIO_FORMAT_S8
; break;
106 case AC_FMT_BITS_16
: as
->fmt
= AUDIO_FORMAT_S16
; break;
107 case AC_FMT_BITS_32
: as
->fmt
= AUDIO_FORMAT_S32
; break;
110 as
->nchannels
= ((format
& AC_FMT_CHAN_MASK
) >> AC_FMT_CHAN_SHIFT
) + 1;
113 /* -------------------------------------------------------------------------- */
115 * HDA codec descriptions
120 #define QEMU_HDA_ID_VENDOR 0x1af4
121 #define QEMU_HDA_PCM_FORMATS (AC_SUPPCM_BITS_16 | \
122 0x1fc /* 16 -> 96 kHz */)
123 #define QEMU_HDA_AMP_NONE (0)
124 #define QEMU_HDA_AMP_STEPS 0x4a
128 #include "hda-codec-common.h"
130 #define PARAM nomixemu
131 #include "hda-codec-common.h"
133 #define HDA_TIMER_TICKS (SCALE_MS)
134 #define B_SIZE sizeof(st->buf)
135 #define B_MASK (sizeof(st->buf) - 1)
137 /* -------------------------------------------------------------------------- */
139 static const char *fmt2name
[] = {
140 [ AUDIO_FORMAT_U8
] = "PCM-U8",
141 [ AUDIO_FORMAT_S8
] = "PCM-S8",
142 [ AUDIO_FORMAT_U16
] = "PCM-U16",
143 [ AUDIO_FORMAT_S16
] = "PCM-S16",
144 [ AUDIO_FORMAT_U32
] = "PCM-U32",
145 [ AUDIO_FORMAT_S32
] = "PCM-S32",
148 #define TYPE_HDA_AUDIO "hda-audio"
149 OBJECT_DECLARE_SIMPLE_TYPE(HDAAudioState
, HDA_AUDIO
)
151 typedef struct HDAAudioStream HDAAudioStream
;
153 struct HDAAudioStream
{
154 HDAAudioState
*state
;
155 const desc_node
*node
;
156 bool output
, running
;
160 uint32_t gain_left
, gain_right
;
161 bool mute_left
, mute_right
;
162 struct audsettings as
;
167 uint8_t compat_buf
[HDA_BUFFER_SIZE
];
168 uint32_t compat_bpos
;
169 uint8_t buf
[8192]; /* size must be power of two */
176 struct HDAAudioState
{
181 const desc_codec
*desc
;
182 HDAAudioStream st
[4];
183 bool running_compat
[16];
184 bool running_real
[2 * 16];
192 static inline int64_t hda_bytes_per_second(HDAAudioStream
*st
)
194 return 2LL * st
->as
.nchannels
* st
->as
.freq
;
197 static inline void hda_timer_sync_adjust(HDAAudioStream
*st
, int64_t target_pos
)
199 int64_t limit
= B_SIZE
/ 8;
202 if (target_pos
> limit
) {
203 corr
= HDA_TIMER_TICKS
;
205 if (target_pos
< -limit
) {
206 corr
= -HDA_TIMER_TICKS
;
208 if (target_pos
< -(2 * limit
)) {
209 corr
= -(4 * HDA_TIMER_TICKS
);
215 trace_hda_audio_adjust(st
->node
->name
, target_pos
);
216 st
->buft_start
+= corr
;
219 static void hda_audio_input_timer(void *opaque
)
221 HDAAudioStream
*st
= opaque
;
223 int64_t now
= qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL
);
225 int64_t buft_start
= st
->buft_start
;
226 int64_t wpos
= st
->wpos
;
227 int64_t rpos
= st
->rpos
;
229 int64_t wanted_rpos
= hda_bytes_per_second(st
) * (now
- buft_start
)
230 / NANOSECONDS_PER_SECOND
;
231 wanted_rpos
&= -4; /* IMPORTANT! clip to frames */
233 if (wanted_rpos
<= rpos
) {
234 /* we already transmitted the data */
238 int64_t to_transfer
= MIN(wpos
- rpos
, wanted_rpos
- rpos
);
239 while (to_transfer
) {
240 uint32_t start
= (rpos
& B_MASK
);
241 uint32_t chunk
= MIN(B_SIZE
- start
, to_transfer
);
242 int rc
= hda_codec_xfer(
243 &st
->state
->hda
, st
->stream
, false, st
->buf
+ start
, chunk
);
248 to_transfer
-= chunk
;
255 timer_mod_anticipate_ns(st
->buft
, now
+ HDA_TIMER_TICKS
);
259 static void hda_audio_input_cb(void *opaque
, int avail
)
261 HDAAudioStream
*st
= opaque
;
263 int64_t wpos
= st
->wpos
;
264 int64_t rpos
= st
->rpos
;
266 int64_t to_transfer
= MIN(B_SIZE
- (wpos
- rpos
), avail
);
268 while (to_transfer
) {
269 uint32_t start
= (uint32_t) (wpos
& B_MASK
);
270 uint32_t chunk
= (uint32_t) MIN(B_SIZE
- start
, to_transfer
);
271 uint32_t read
= AUD_read(st
->voice
.in
, st
->buf
+ start
, chunk
);
280 hda_timer_sync_adjust(st
, -((wpos
- rpos
) - (B_SIZE
>> 1)));
283 static void hda_audio_output_timer(void *opaque
)
285 HDAAudioStream
*st
= opaque
;
287 int64_t now
= qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL
);
289 int64_t buft_start
= st
->buft_start
;
290 int64_t wpos
= st
->wpos
;
291 int64_t rpos
= st
->rpos
;
293 int64_t wanted_wpos
= hda_bytes_per_second(st
) * (now
- buft_start
)
294 / NANOSECONDS_PER_SECOND
;
295 wanted_wpos
&= -4; /* IMPORTANT! clip to frames */
297 if (wanted_wpos
<= wpos
) {
298 /* we already received the data */
302 int64_t to_transfer
= MIN(B_SIZE
- (wpos
- rpos
), wanted_wpos
- wpos
);
303 while (to_transfer
) {
304 uint32_t start
= (wpos
& B_MASK
);
305 uint32_t chunk
= MIN(B_SIZE
- start
, to_transfer
);
306 int rc
= hda_codec_xfer(
307 &st
->state
->hda
, st
->stream
, true, st
->buf
+ start
, chunk
);
312 to_transfer
-= chunk
;
319 timer_mod_anticipate_ns(st
->buft
, now
+ HDA_TIMER_TICKS
);
323 static void hda_audio_output_cb(void *opaque
, int avail
)
325 HDAAudioStream
*st
= opaque
;
327 int64_t wpos
= st
->wpos
;
328 int64_t rpos
= st
->rpos
;
330 int64_t to_transfer
= MIN(wpos
- rpos
, avail
);
332 if (wpos
- rpos
== B_SIZE
) {
333 /* drop buffer, reset timer adjust */
336 st
->buft_start
= qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL
);
337 trace_hda_audio_overrun(st
->node
->name
);
341 while (to_transfer
) {
342 uint32_t start
= (uint32_t) (rpos
& B_MASK
);
343 uint32_t chunk
= (uint32_t) MIN(B_SIZE
- start
, to_transfer
);
344 uint32_t written
= AUD_write(st
->voice
.out
, st
->buf
+ start
, chunk
);
346 to_transfer
-= written
;
348 if (chunk
!= written
) {
353 hda_timer_sync_adjust(st
, (wpos
- rpos
) - (B_SIZE
>> 1));
356 static void hda_audio_compat_input_cb(void *opaque
, int avail
)
358 HDAAudioStream
*st
= opaque
;
363 while (avail
- recv
>= sizeof(st
->compat_buf
)) {
364 if (st
->compat_bpos
!= sizeof(st
->compat_buf
)) {
365 len
= AUD_read(st
->voice
.in
, st
->compat_buf
+ st
->compat_bpos
,
366 sizeof(st
->compat_buf
) - st
->compat_bpos
);
367 st
->compat_bpos
+= len
;
369 if (st
->compat_bpos
!= sizeof(st
->compat_buf
)) {
373 rc
= hda_codec_xfer(&st
->state
->hda
, st
->stream
, false,
374 st
->compat_buf
, sizeof(st
->compat_buf
));
382 static void hda_audio_compat_output_cb(void *opaque
, int avail
)
384 HDAAudioStream
*st
= opaque
;
389 while (avail
- sent
>= sizeof(st
->compat_buf
)) {
390 if (st
->compat_bpos
== sizeof(st
->compat_buf
)) {
391 rc
= hda_codec_xfer(&st
->state
->hda
, st
->stream
, true,
392 st
->compat_buf
, sizeof(st
->compat_buf
));
398 len
= AUD_write(st
->voice
.out
, st
->compat_buf
+ st
->compat_bpos
,
399 sizeof(st
->compat_buf
) - st
->compat_bpos
);
400 st
->compat_bpos
+= len
;
402 if (st
->compat_bpos
!= sizeof(st
->compat_buf
)) {
408 static void hda_audio_set_running(HDAAudioStream
*st
, bool running
)
410 if (st
->node
== NULL
) {
413 if (st
->running
== running
) {
416 st
->running
= running
;
417 trace_hda_audio_running(st
->node
->name
, st
->stream
, st
->running
);
418 if (st
->state
->use_timer
) {
420 int64_t now
= qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL
);
423 st
->buft_start
= now
;
424 timer_mod_anticipate_ns(st
->buft
, now
+ HDA_TIMER_TICKS
);
430 AUD_set_active_out(st
->voice
.out
, st
->running
);
432 AUD_set_active_in(st
->voice
.in
, st
->running
);
436 static void hda_audio_set_amp(HDAAudioStream
*st
)
439 uint32_t left
, right
;
441 if (st
->node
== NULL
) {
445 muted
= st
->mute_left
&& st
->mute_right
;
446 left
= st
->mute_left
? 0 : st
->gain_left
;
447 right
= st
->mute_right
? 0 : st
->gain_right
;
449 left
= left
* 255 / QEMU_HDA_AMP_STEPS
;
450 right
= right
* 255 / QEMU_HDA_AMP_STEPS
;
452 if (!st
->state
->mixer
) {
456 AUD_set_volume_out(st
->voice
.out
, muted
, left
, right
);
458 AUD_set_volume_in(st
->voice
.in
, muted
, left
, right
);
462 static void hda_audio_setup(HDAAudioStream
*st
)
464 bool use_timer
= st
->state
->use_timer
;
465 audio_callback_fn cb
;
467 if (st
->node
== NULL
) {
471 trace_hda_audio_format(st
->node
->name
, st
->as
.nchannels
,
472 fmt2name
[st
->as
.fmt
], st
->as
.freq
);
476 cb
= hda_audio_output_cb
;
477 st
->buft
= timer_new_ns(QEMU_CLOCK_VIRTUAL
,
478 hda_audio_output_timer
, st
);
480 cb
= hda_audio_compat_output_cb
;
482 st
->voice
.out
= AUD_open_out(&st
->state
->card
, st
->voice
.out
,
483 st
->node
->name
, st
, cb
, &st
->as
);
486 cb
= hda_audio_input_cb
;
487 st
->buft
= timer_new_ns(QEMU_CLOCK_VIRTUAL
,
488 hda_audio_input_timer
, st
);
490 cb
= hda_audio_compat_input_cb
;
492 st
->voice
.in
= AUD_open_in(&st
->state
->card
, st
->voice
.in
,
493 st
->node
->name
, st
, cb
, &st
->as
);
497 static void hda_audio_command(HDACodecDevice
*hda
, uint32_t nid
, uint32_t data
)
499 HDAAudioState
*a
= HDA_AUDIO(hda
);
501 const desc_node
*node
= NULL
;
502 const desc_param
*param
;
503 uint32_t verb
, payload
, response
, count
, shift
;
505 if ((data
& 0x70000) == 0x70000) {
506 /* 12/8 id/payload */
507 verb
= (data
>> 8) & 0xfff;
508 payload
= data
& 0x00ff;
510 /* 4/16 id/payload */
511 verb
= (data
>> 8) & 0xf00;
512 payload
= data
& 0xffff;
515 node
= hda_codec_find_node(a
->desc
, nid
);
519 dprint(a
, 2, "%s: nid %d (%s), verb 0x%x, payload 0x%x\n",
520 __func__
, nid
, node
->name
, verb
, payload
);
524 case AC_VERB_PARAMETERS
:
525 param
= hda_codec_find_param(node
, payload
);
529 hda_codec_response(hda
, true, param
->val
);
531 case AC_VERB_GET_SUBSYSTEM_ID
:
532 hda_codec_response(hda
, true, a
->desc
->iid
);
536 case AC_VERB_GET_CONNECT_LIST
:
537 param
= hda_codec_find_param(node
, AC_PAR_CONNLIST_LEN
);
538 count
= param
? param
->val
: 0;
541 while (payload
< count
&& shift
< 32) {
542 response
|= node
->conn
[payload
] << shift
;
546 hda_codec_response(hda
, true, response
);
550 case AC_VERB_GET_CONFIG_DEFAULT
:
551 hda_codec_response(hda
, true, node
->config
);
553 case AC_VERB_GET_PIN_WIDGET_CONTROL
:
554 hda_codec_response(hda
, true, node
->pinctl
);
556 case AC_VERB_SET_PIN_WIDGET_CONTROL
:
557 if (node
->pinctl
!= payload
) {
558 dprint(a
, 1, "unhandled pin control bit\n");
560 hda_codec_response(hda
, true, 0);
563 /* audio in/out widget */
564 case AC_VERB_SET_CHANNEL_STREAMID
:
565 st
= a
->st
+ node
->stindex
;
566 if (st
->node
== NULL
) {
569 hda_audio_set_running(st
, false);
570 st
->stream
= (payload
>> 4) & 0x0f;
571 st
->channel
= payload
& 0x0f;
572 dprint(a
, 2, "%s: stream %d, channel %d\n",
573 st
->node
->name
, st
->stream
, st
->channel
);
574 hda_audio_set_running(st
, a
->running_real
[st
->output
* 16 + st
->stream
]);
575 hda_codec_response(hda
, true, 0);
577 case AC_VERB_GET_CONV
:
578 st
= a
->st
+ node
->stindex
;
579 if (st
->node
== NULL
) {
582 response
= st
->stream
<< 4 | st
->channel
;
583 hda_codec_response(hda
, true, response
);
585 case AC_VERB_SET_STREAM_FORMAT
:
586 st
= a
->st
+ node
->stindex
;
587 if (st
->node
== NULL
) {
590 st
->format
= payload
;
591 hda_codec_parse_fmt(st
->format
, &st
->as
);
593 hda_codec_response(hda
, true, 0);
595 case AC_VERB_GET_STREAM_FORMAT
:
596 st
= a
->st
+ node
->stindex
;
597 if (st
->node
== NULL
) {
600 hda_codec_response(hda
, true, st
->format
);
602 case AC_VERB_GET_AMP_GAIN_MUTE
:
603 st
= a
->st
+ node
->stindex
;
604 if (st
->node
== NULL
) {
607 if (payload
& AC_AMP_GET_LEFT
) {
608 response
= st
->gain_left
| (st
->mute_left
? AC_AMP_MUTE
: 0);
610 response
= st
->gain_right
| (st
->mute_right
? AC_AMP_MUTE
: 0);
612 hda_codec_response(hda
, true, response
);
614 case AC_VERB_SET_AMP_GAIN_MUTE
:
615 st
= a
->st
+ node
->stindex
;
616 if (st
->node
== NULL
) {
619 dprint(a
, 1, "amp (%s): %s%s%s%s index %d gain %3d %s\n",
621 (payload
& AC_AMP_SET_OUTPUT
) ? "o" : "-",
622 (payload
& AC_AMP_SET_INPUT
) ? "i" : "-",
623 (payload
& AC_AMP_SET_LEFT
) ? "l" : "-",
624 (payload
& AC_AMP_SET_RIGHT
) ? "r" : "-",
625 (payload
& AC_AMP_SET_INDEX
) >> AC_AMP_SET_INDEX_SHIFT
,
626 (payload
& AC_AMP_GAIN
),
627 (payload
& AC_AMP_MUTE
) ? "muted" : "");
628 if (payload
& AC_AMP_SET_LEFT
) {
629 st
->gain_left
= payload
& AC_AMP_GAIN
;
630 st
->mute_left
= payload
& AC_AMP_MUTE
;
632 if (payload
& AC_AMP_SET_RIGHT
) {
633 st
->gain_right
= payload
& AC_AMP_GAIN
;
634 st
->mute_right
= payload
& AC_AMP_MUTE
;
636 hda_audio_set_amp(st
);
637 hda_codec_response(hda
, true, 0);
641 case AC_VERB_SET_POWER_STATE
:
642 case AC_VERB_GET_POWER_STATE
:
643 case AC_VERB_GET_SDI_SELECT
:
644 hda_codec_response(hda
, true, 0);
652 dprint(a
, 1, "%s: not handled: nid %d (%s), verb 0x%x, payload 0x%x\n",
653 __func__
, nid
, node
? node
->name
: "?", verb
, payload
);
654 hda_codec_response(hda
, true, 0);
657 static void hda_audio_stream(HDACodecDevice
*hda
, uint32_t stnr
, bool running
, bool output
)
659 HDAAudioState
*a
= HDA_AUDIO(hda
);
662 a
->running_compat
[stnr
] = running
;
663 a
->running_real
[output
* 16 + stnr
] = running
;
664 for (s
= 0; s
< ARRAY_SIZE(a
->st
); s
++) {
665 if (a
->st
[s
].node
== NULL
) {
668 if (a
->st
[s
].output
!= output
) {
671 if (a
->st
[s
].stream
!= stnr
) {
674 hda_audio_set_running(&a
->st
[s
], running
);
678 static void hda_audio_init(HDACodecDevice
*hda
,
679 const struct desc_codec
*desc
,
682 HDAAudioState
*a
= HDA_AUDIO(hda
);
684 const desc_node
*node
;
685 const desc_param
*param
;
688 if (!AUD_register_card("hda", &a
->card
, errp
)) {
693 a
->name
= object_get_typename(OBJECT(a
));
694 dprint(a
, 1, "%s: cad %d\n", __func__
, a
->hda
.cad
);
696 for (i
= 0; i
< a
->desc
->nnodes
; i
++) {
697 node
= a
->desc
->nodes
+ i
;
698 param
= hda_codec_find_param(node
, AC_PAR_AUDIO_WIDGET_CAP
);
702 type
= (param
->val
& AC_WCAP_TYPE
) >> AC_WCAP_TYPE_SHIFT
;
706 assert(node
->stindex
< ARRAY_SIZE(a
->st
));
707 st
= a
->st
+ node
->stindex
;
710 if (type
== AC_WID_AUD_OUT
) {
711 /* unmute output by default */
712 st
->gain_left
= QEMU_HDA_AMP_STEPS
;
713 st
->gain_right
= QEMU_HDA_AMP_STEPS
;
714 st
->compat_bpos
= sizeof(st
->compat_buf
);
719 st
->format
= AC_FMT_TYPE_PCM
| AC_FMT_BITS_16
|
720 (1 << AC_FMT_CHAN_SHIFT
);
721 hda_codec_parse_fmt(st
->format
, &st
->as
);
728 static void hda_audio_exit(HDACodecDevice
*hda
)
730 HDAAudioState
*a
= HDA_AUDIO(hda
);
734 dprint(a
, 1, "%s\n", __func__
);
735 for (i
= 0; i
< ARRAY_SIZE(a
->st
); i
++) {
737 if (st
->node
== NULL
) {
744 AUD_close_out(&a
->card
, st
->voice
.out
);
746 AUD_close_in(&a
->card
, st
->voice
.in
);
749 AUD_remove_card(&a
->card
);
752 static int hda_audio_post_load(void *opaque
, int version
)
754 HDAAudioState
*a
= opaque
;
758 dprint(a
, 1, "%s\n", __func__
);
760 /* assume running_compat[] is for output streams */
761 for (i
= 0; i
< ARRAY_SIZE(a
->running_compat
); i
++)
762 a
->running_real
[16 + i
] = a
->running_compat
[i
];
765 for (i
= 0; i
< ARRAY_SIZE(a
->st
); i
++) {
767 if (st
->node
== NULL
)
769 hda_codec_parse_fmt(st
->format
, &st
->as
);
771 hda_audio_set_amp(st
);
772 hda_audio_set_running(st
, a
->running_real
[st
->output
* 16 + st
->stream
]);
777 static void hda_audio_reset(DeviceState
*dev
)
779 HDAAudioState
*a
= HDA_AUDIO(dev
);
783 dprint(a
, 1, "%s\n", __func__
);
784 for (i
= 0; i
< ARRAY_SIZE(a
->st
); i
++) {
786 if (st
->node
!= NULL
) {
787 hda_audio_set_running(st
, false);
792 static bool vmstate_hda_audio_stream_buf_needed(void *opaque
)
794 HDAAudioStream
*st
= opaque
;
795 return st
->state
&& st
->state
->use_timer
;
798 static const VMStateDescription vmstate_hda_audio_stream_buf
= {
799 .name
= "hda-audio-stream/buffer",
801 .needed
= vmstate_hda_audio_stream_buf_needed
,
802 .fields
= (VMStateField
[]) {
803 VMSTATE_BUFFER(buf
, HDAAudioStream
),
804 VMSTATE_INT64(rpos
, HDAAudioStream
),
805 VMSTATE_INT64(wpos
, HDAAudioStream
),
806 VMSTATE_TIMER_PTR(buft
, HDAAudioStream
),
807 VMSTATE_INT64(buft_start
, HDAAudioStream
),
808 VMSTATE_END_OF_LIST()
812 static const VMStateDescription vmstate_hda_audio_stream
= {
813 .name
= "hda-audio-stream",
815 .fields
= (VMStateField
[]) {
816 VMSTATE_UINT32(stream
, HDAAudioStream
),
817 VMSTATE_UINT32(channel
, HDAAudioStream
),
818 VMSTATE_UINT32(format
, HDAAudioStream
),
819 VMSTATE_UINT32(gain_left
, HDAAudioStream
),
820 VMSTATE_UINT32(gain_right
, HDAAudioStream
),
821 VMSTATE_BOOL(mute_left
, HDAAudioStream
),
822 VMSTATE_BOOL(mute_right
, HDAAudioStream
),
823 VMSTATE_UINT32(compat_bpos
, HDAAudioStream
),
824 VMSTATE_BUFFER(compat_buf
, HDAAudioStream
),
825 VMSTATE_END_OF_LIST()
827 .subsections
= (const VMStateDescription
* []) {
828 &vmstate_hda_audio_stream_buf
,
833 static const VMStateDescription vmstate_hda_audio
= {
836 .post_load
= hda_audio_post_load
,
837 .fields
= (VMStateField
[]) {
838 VMSTATE_STRUCT_ARRAY(st
, HDAAudioState
, 4, 0,
839 vmstate_hda_audio_stream
,
841 VMSTATE_BOOL_ARRAY(running_compat
, HDAAudioState
, 16),
842 VMSTATE_BOOL_ARRAY_V(running_real
, HDAAudioState
, 2 * 16, 2),
843 VMSTATE_END_OF_LIST()
847 static Property hda_audio_properties
[] = {
848 DEFINE_AUDIO_PROPERTIES(HDAAudioState
, card
),
849 DEFINE_PROP_UINT32("debug", HDAAudioState
, debug
, 0),
850 DEFINE_PROP_BOOL("mixer", HDAAudioState
, mixer
, true),
851 DEFINE_PROP_BOOL("use-timer", HDAAudioState
, use_timer
, true),
852 DEFINE_PROP_END_OF_LIST(),
855 static void hda_audio_init_output(HDACodecDevice
*hda
, Error
**errp
)
857 HDAAudioState
*a
= HDA_AUDIO(hda
);
858 const struct desc_codec
*desc
= &output_nomixemu
;
861 desc
= &output_mixemu
;
864 hda_audio_init(hda
, desc
, errp
);
867 static void hda_audio_init_duplex(HDACodecDevice
*hda
, Error
**errp
)
869 HDAAudioState
*a
= HDA_AUDIO(hda
);
870 const struct desc_codec
*desc
= &duplex_nomixemu
;
873 desc
= &duplex_mixemu
;
876 hda_audio_init(hda
, desc
, errp
);
879 static void hda_audio_init_micro(HDACodecDevice
*hda
, Error
**errp
)
881 HDAAudioState
*a
= HDA_AUDIO(hda
);
882 const struct desc_codec
*desc
= µ_nomixemu
;
885 desc
= µ_mixemu
;
888 hda_audio_init(hda
, desc
, errp
);
891 static void hda_audio_base_class_init(ObjectClass
*klass
, void *data
)
893 DeviceClass
*dc
= DEVICE_CLASS(klass
);
894 HDACodecDeviceClass
*k
= HDA_CODEC_DEVICE_CLASS(klass
);
896 k
->exit
= hda_audio_exit
;
897 k
->command
= hda_audio_command
;
898 k
->stream
= hda_audio_stream
;
899 set_bit(DEVICE_CATEGORY_SOUND
, dc
->categories
);
900 dc
->reset
= hda_audio_reset
;
901 dc
->vmsd
= &vmstate_hda_audio
;
902 device_class_set_props(dc
, hda_audio_properties
);
905 static const TypeInfo hda_audio_info
= {
906 .name
= TYPE_HDA_AUDIO
,
907 .parent
= TYPE_HDA_CODEC_DEVICE
,
908 .instance_size
= sizeof(HDAAudioState
),
909 .class_init
= hda_audio_base_class_init
,
913 static void hda_audio_output_class_init(ObjectClass
*klass
, void *data
)
915 DeviceClass
*dc
= DEVICE_CLASS(klass
);
916 HDACodecDeviceClass
*k
= HDA_CODEC_DEVICE_CLASS(klass
);
918 k
->init
= hda_audio_init_output
;
919 dc
->desc
= "HDA Audio Codec, output-only (line-out)";
922 static const TypeInfo hda_audio_output_info
= {
923 .name
= "hda-output",
924 .parent
= TYPE_HDA_AUDIO
,
925 .class_init
= hda_audio_output_class_init
,
928 static void hda_audio_duplex_class_init(ObjectClass
*klass
, void *data
)
930 DeviceClass
*dc
= DEVICE_CLASS(klass
);
931 HDACodecDeviceClass
*k
= HDA_CODEC_DEVICE_CLASS(klass
);
933 k
->init
= hda_audio_init_duplex
;
934 dc
->desc
= "HDA Audio Codec, duplex (line-out, line-in)";
937 static const TypeInfo hda_audio_duplex_info
= {
938 .name
= "hda-duplex",
939 .parent
= TYPE_HDA_AUDIO
,
940 .class_init
= hda_audio_duplex_class_init
,
943 static void hda_audio_micro_class_init(ObjectClass
*klass
, void *data
)
945 DeviceClass
*dc
= DEVICE_CLASS(klass
);
946 HDACodecDeviceClass
*k
= HDA_CODEC_DEVICE_CLASS(klass
);
948 k
->init
= hda_audio_init_micro
;
949 dc
->desc
= "HDA Audio Codec, duplex (speaker, microphone)";
952 static const TypeInfo hda_audio_micro_info
= {
954 .parent
= TYPE_HDA_AUDIO
,
955 .class_init
= hda_audio_micro_class_init
,
958 static void hda_audio_register_types(void)
960 type_register_static(&hda_audio_info
);
961 type_register_static(&hda_audio_output_info
);
962 type_register_static(&hda_audio_duplex_info
);
963 type_register_static(&hda_audio_micro_info
);
966 type_init(hda_audio_register_types
)