From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jan Kiszka Subject: [PATCH] kvm-userspace: Make PC speaker emulation aware of in-kernel PIT Date: Thu, 23 Apr 2009 22:24:05 +0200 Message-ID: <49F0CE65.4050005@web.de> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="------------enig761B85E7603F3EAD0D427B8D" Cc: kvm-devel To: Avi Kivity Return-path: Received: from fmmailgate01.web.de ([217.72.192.221]:51254 "EHLO fmmailgate01.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752645AbZDWUYI (ORCPT ); Thu, 23 Apr 2009 16:24:08 -0400 Sender: kvm-owner@vger.kernel.org List-ID: This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enig761B85E7603F3EAD0D427B8D Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: quoted-printable When using the in-kernel PIT the speaker emulation has to synchronize the PIT state with KVM. Enhance the existing speaker sound device and allow it to take over port 0x61 by using KVM_CREATE_PIT_NOSPKR when available. This unbreaks -soundhw pcspk in KVM mode. Signed-off-by: Jan Kiszka --- libkvm/libkvm-x86.c | 13 +++++++++++++ qemu/hw/pcspk.c | 43 +++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 54 insertions(+), 2 deletions(-) diff --git a/libkvm/libkvm-x86.c b/libkvm/libkvm-x86.c index 2fc4fce..03b1939 100644 --- a/libkvm/libkvm-x86.c +++ b/libkvm/libkvm-x86.c @@ -59,6 +59,19 @@ int kvm_create_pit(kvm_context_t kvm) =20 kvm->pit_in_kernel =3D 0; if (!kvm->no_pit_creation) { +#ifdef KVM_CAP_PIT_NOSPKR + r =3D ioctl(kvm->fd, KVM_CHECK_EXTENSION, KVM_CAP_PIT_NOSPKR); + if (r > 0) { + r =3D ioctl(kvm->vm_fd, KVM_CREATE_PIT_NOSPKR); + if (r >=3D 0) { + kvm->pit_in_kernel =3D 1; + return 0; + } else { + fprintf(stderr, "Create kernel PIC irqchip failed\n"); + return r; + } + } +#endif r =3D ioctl(kvm->fd, KVM_CHECK_EXTENSION, KVM_CAP_PIT); if (r > 0) { r =3D ioctl(kvm->vm_fd, KVM_CREATE_PIT); diff --git a/qemu/hw/pcspk.c b/qemu/hw/pcspk.c index ec1d0c6..4752518 100644 --- a/qemu/hw/pcspk.c +++ b/qemu/hw/pcspk.c @@ -27,6 +27,8 @@ #include "isa.h" #include "audio/audio.h" #include "qemu-timer.h" +#include "i8254.h" +#include "qemu-kvm.h" =20 #define PCSPK_BUF_LEN 1792 #define PCSPK_SAMPLE_RATE 32000 @@ -71,7 +73,15 @@ static void pcspk_callback(void *opaque, int free) { PCSpkState *s =3D opaque; unsigned int n; +#ifdef USE_KVM_PIT + struct kvm_pit_state pit_state; =20 + if (kvm_enabled() && qemu_kvm_pit_in_kernel()) { + kvm_get_pit(kvm_context, &pit_state); + s->pit->channels[2].mode =3D pit_state.channels[2].mode; + s->pit->channels[2].count =3D pit_state.channels[2].count; + } +#endif if (pit_get_mode(s->pit, 2) !=3D 3) return; =20 @@ -120,7 +130,17 @@ static uint32_t pcspk_ioport_read(void *opaque, uint= 32_t addr) { PCSpkState *s =3D opaque; int out; - +#ifdef USE_KVM_PIT + struct kvm_pit_state pit_state; + + if (kvm_enabled() && qemu_kvm_pit_in_kernel()) { + kvm_get_pit(kvm_context, &pit_state); + s->pit->channels[2].mode =3D pit_state.channels[2].mode; + s->pit->channels[2].count =3D pit_state.channels[2].count; + s->pit->channels[2].count_load_time =3D pit_state.channels[2].co= unt_load_time; + s->pit->channels[2].gate =3D pit_state.channels[2].gate; + } +#endif s->dummy_refresh_clock ^=3D (1 << 4); out =3D pit_get_out(s->pit, 2, qemu_get_clock(vm_clock)) << 5; =20 @@ -131,7 +151,17 @@ static void pcspk_ioport_write(void *opaque, uint32_= t addr, uint32_t val) { PCSpkState *s =3D opaque; const int gate =3D val & 1; - +#ifdef USE_KVM_PIT + struct kvm_pit_state pit_state; + + if (kvm_enabled() && qemu_kvm_pit_in_kernel()) { + kvm_get_pit(kvm_context, &pit_state); + s->pit->channels[2].mode =3D pit_state.channels[2].mode; + s->pit->channels[2].count =3D pit_state.channels[2].count; + s->pit->channels[2].count_load_time =3D pit_state.channels[2].co= unt_load_time; + s->pit->channels[2].gate =3D pit_state.channels[2].gate; + } +#endif s->data_on =3D (val >> 1) & 1; pit_set_gate(s->pit, 2, gate); if (s->voice) { @@ -139,6 +169,15 @@ static void pcspk_ioport_write(void *opaque, uint32_= t addr, uint32_t val) s->play_pos =3D 0; AUD_set_active_out(s->voice, gate & s->data_on); } +#ifdef USE_KVM_PIT + if (kvm_enabled() && qemu_kvm_pit_in_kernel()) { + pit_state.channels[2].mode =3D s->pit->channels[2].mode; + pit_state.channels[2].count =3D s->pit->channels[2].count; + pit_state.channels[2].count_load_time =3D s->pit->channels[2].co= unt_load_time; + pit_state.channels[2].gate =3D s->pit->channels[2].gate; + kvm_set_pit(kvm_context, &pit_state); + } +#endif } =20 void pcspk_init(PITState *pit) --------------enig761B85E7603F3EAD0D427B8D Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.9 (GNU/Linux) Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org iEUEARECAAYFAknwzmUACgkQniDOoMHTA+mc1wCeNINSVXwnvZPbgx7v+sAwX/Hi v1QAmJX8Z0E61xDjl3cuGpxnH+j8Xh8= =KfOU -----END PGP SIGNATURE----- --------------enig761B85E7603F3EAD0D427B8D--