qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Jan Kiszka <jan.kiszka@siemens.com>
To: Avi Kivity <avi@redhat.com>, Marcelo Tosatti <mtosatti@redhat.com>
Cc: qemu-devel <qemu-devel@nongnu.org>,
	kvm@vger.kernel.org, "Michael S. Tsirkin" <mst@redhat.com>
Subject: [Qemu-devel] [PATCH v3 5/8] kvm: x86: Wire up MSI support for in-kernel irqchip
Date: Thu, 10 May 2012 18:02:54 -0300	[thread overview]
Message-ID: <ee1ecada2a7962ebaae9eed8c85d6eb4afd23ff0.1336683774.git.jan.kiszka@siemens.com> (raw)
In-Reply-To: <cover.1336683774.git.jan.kiszka@siemens.com>
In-Reply-To: <cover.1336683774.git.jan.kiszka@siemens.com>

Catch writes to the MSI MMIO region in the KVM APIC and forward them to
the kernel. Provide the kernel support GSI routing, this allows to
enable MSI support also for in-kernel irqchip mode.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
 hw/apic.c     |    1 +
 hw/kvm/apic.c |   34 ++++++++++++++++++++++++++++++++--
 2 files changed, 33 insertions(+), 2 deletions(-)

diff --git a/hw/apic.c b/hw/apic.c
index a337790..5fbf01c 100644
--- a/hw/apic.c
+++ b/hw/apic.c
@@ -19,6 +19,7 @@
 #include "apic_internal.h"
 #include "apic.h"
 #include "ioapic.h"
+#include "msi.h"
 #include "host-utils.h"
 #include "trace.h"
 #include "pc.h"
diff --git a/hw/kvm/apic.c b/hw/kvm/apic.c
index ffe7a52..8ba4079 100644
--- a/hw/kvm/apic.c
+++ b/hw/kvm/apic.c
@@ -10,6 +10,7 @@
  * See the COPYING file in the top-level directory.
  */
 #include "hw/apic_internal.h"
+#include "hw/msi.h"
 #include "kvm.h"
 
 static inline void kvm_apic_set_reg(struct kvm_lapic_state *kapic,
@@ -145,10 +146,39 @@ static void kvm_apic_external_nmi(APICCommonState *s)
     run_on_cpu(s->cpu_env, do_inject_external_nmi, s);
 }
 
+static uint64_t kvm_apic_mem_read(void *opaque, target_phys_addr_t addr,
+                                  unsigned size)
+{
+    return ~(uint64_t)0;
+}
+
+static void kvm_apic_mem_write(void *opaque, target_phys_addr_t addr,
+                               uint64_t data, unsigned size)
+{
+    MSIMessage msg = { .address = addr, .data = data };
+    int ret;
+
+    ret = kvm_irqchip_send_msi(kvm_state, msg);
+    if (ret < 0) {
+        fprintf(stderr, "KVM: injection failed, MSI lost (%s)\n",
+                strerror(-ret));
+    }
+}
+
+static const MemoryRegionOps kvm_apic_io_ops = {
+    .read = kvm_apic_mem_read,
+    .write = kvm_apic_mem_write,
+    .endianness = DEVICE_NATIVE_ENDIAN,
+};
+
 static void kvm_apic_init(APICCommonState *s)
 {
-    memory_region_init_reservation(&s->io_memory, "kvm-apic-msi",
-                                   MSI_SPACE_SIZE);
+    memory_region_init_io(&s->io_memory, &kvm_apic_io_ops, s, "kvm-apic-msi",
+                          MSI_SPACE_SIZE);
+
+    if (kvm_has_gsi_routing()) {
+        msi_supported = true;
+    }
 }
 
 static void kvm_apic_class_init(ObjectClass *klass, void *data)
-- 
1.7.3.4

  parent reply	other threads:[~2012-05-10 21:03 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-10 21:02 [Qemu-devel] [PATCH v3 0/8] uq/master: MSI support for in-kernel irqchip mode Jan Kiszka
2012-05-10 21:02 ` [Qemu-devel] [PATCH v3 1/8] kvm: Refactor KVMState::max_gsi to gsi_count Jan Kiszka
2012-05-10 21:02 ` [Qemu-devel] [PATCH v3 2/8] Introduce MSIMessage structure Jan Kiszka
2012-05-10 21:02 ` [Qemu-devel] [PATCH v3 3/8] kvm: Introduce basic MSI support for in-kernel irqchips Jan Kiszka
2012-05-16  3:27   ` Marcelo Tosatti
2012-05-16 11:15     ` Jan Kiszka
2012-05-16 17:31       ` Marcelo Tosatti
2012-05-16 18:18       ` Jan Kiszka
2012-05-10 21:02 ` [Qemu-devel] [PATCH v3 4/8] pc: Enable MSI support at APIC level Jan Kiszka
2012-05-11 16:24   ` Stefano Stabellini
2012-05-11 18:33     ` Jan Kiszka
2012-05-10 21:02 ` Jan Kiszka [this message]
2012-05-10 21:02 ` [Qemu-devel] [PATCH v3 6/8] kvm: Update kernel headers Jan Kiszka
2012-05-10 21:02 ` [Qemu-devel] [PATCH v3 7/8] kvm: Add support for direct MSI injections Jan Kiszka
2012-05-10 21:02 ` [Qemu-devel] [PATCH v3 8/8] kvm: Enable in-kernel irqchip support by default Jan Kiszka

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ee1ecada2a7962ebaae9eed8c85d6eb4afd23ff0.1336683774.git.jan.kiszka@siemens.com \
    --to=jan.kiszka@siemens.com \
    --cc=avi@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=mst@redhat.com \
    --cc=mtosatti@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).