From patchwork Wed Apr 29 14:52:04 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Auger X-Patchwork-Id: 466118 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 98C1E140320 for ; Thu, 30 Apr 2015 00:55:26 +1000 (AEST) Received: from localhost ([::1]:39459 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YnTOW-0001N8-Lj for incoming@patchwork.ozlabs.org; Wed, 29 Apr 2015 10:55:24 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56517) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YnTLh-0003sa-WE for qemu-devel@nongnu.org; Wed, 29 Apr 2015 10:52:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YnTLc-0001eT-NY for qemu-devel@nongnu.org; Wed, 29 Apr 2015 10:52:29 -0400 Received: from mail-wg0-f46.google.com ([74.125.82.46]:36437) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YnTLc-0001eJ-FA for qemu-devel@nongnu.org; Wed, 29 Apr 2015 10:52:24 -0400 Received: by wgen6 with SMTP id n6so31099109wge.3 for ; Wed, 29 Apr 2015 07:52:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=UaNkorBaMBNS11JvYo2QH4Mzmmuoc9gqlrL+MRM9bOw=; b=UY/Ivwy4rlwuym5WTaqH66u4jOucoYaWjLgZrv/ByjP02fEag4sjf9gV3AYvl+JXX0 m1j5BHtuYF7uH+akk/24zmuUW0MuUe6FfSiviCdcWZJgI0tcyHFe36fhU8g2NV3y2vdA Bsumtn1NmvmPhH15f2ZoO9OCJcamtG5iGvTabjepyHLKhofUBupqc53yh6SaoTsO8tI4 WBo4rlOw1/hg7noFu2lY1bGYuzD6R3VuEIt82JjqquX2zwOnTgV05edHscj0rts8RwN2 WbpDLZOVR7l9znj3MtzPooDe0NW6lnrS4WEshgNkCGvz/mxtBU/CZx2ZIfISWznASBXA hn3g== X-Gm-Message-State: ALoCoQknBodp5Jp5SnlVSIYenzcSpDRoV616/TZvdnPIGEfs/aDuia3tbEnwichJqtEw2axdtN+s X-Received: by 10.194.234.38 with SMTP id ub6mr7215543wjc.9.1430319143812; Wed, 29 Apr 2015 07:52:23 -0700 (PDT) Received: from midway01-04-00.lavalab ([81.128.185.50]) by mx.google.com with ESMTPSA id it5sm21555782wid.3.2015.04.29.07.52.22 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 29 Apr 2015 07:52:22 -0700 (PDT) From: Eric Auger To: eric.auger@st.com, eric.auger@linaro.org, qemu-devel@nongnu.org, alex.williamson@redhat.com, agraf@suse.de, pbonzini@redhat.com, peter.crosthwaite@xilinx.com Date: Wed, 29 Apr 2015 15:52:04 +0100 Message-Id: <1430319127-25907-8-git-send-email-eric.auger@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1430319127-25907-1-git-send-email-eric.auger@linaro.org> References: <1430319127-25907-1-git-send-email-eric.auger@linaro.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 74.125.82.46 Cc: peter.maydell@linaro.org, b.reynal@virtualopensystems.com, vikrams@codeaurora.org, patches@linaro.org, Bharat.Bhushan@freescale.com, borntraeger@de.ibm.com, cornelia.huck@de.ibm.com, alex.bennee@linaro.org, kvmarm@lists.cs.columbia.edu, christoffer.dall@linaro.org Subject: [Qemu-devel] [PATCH v14 07/10] kvm-all.c: add qemu_irq/gsi hash table and utility routines X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org VFIO platform device needs to setup irqfd but it does not know the gsi corresponding to the device qemu_irq. This series proposes to store a hash table in kvm_state using the qemu_irq as key and the gsi as a value. kvm_irqchip_set_qemuirq_gsi allows to insert such a pair. The interrupt controller is supposed to use it. kvm_irqchip_[add, remove]_irqfd_notifier allows to setup/tear down irqfd directly from the qemu_irq. Signed-off-by: Eric Auger --- v13 -> v14: - correct checkpatch warning v2 -> v3 (integration into VFIO series v13): - rename kvm_irqchip_[add, remove]_qemuirq_irqfd_notifier into kvm_irqchip_[add, remove]_irqfd_notifier. Possible since legacy functions were also renamed with _gsi suffix. V1 -> v2: - qemu_irq get_gsi callback replaced by hash table stored in kvm --- include/sysemu/kvm.h | 6 ++++++ kvm-all.c | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h index 0f28d6f..bc3f230 100644 --- a/include/sysemu/kvm.h +++ b/include/sysemu/kvm.h @@ -18,6 +18,7 @@ #include "config-host.h" #include "qemu/queue.h" #include "qom/cpu.h" +#include "hw/irq.h" #ifdef CONFIG_KVM #include @@ -417,6 +418,11 @@ int kvm_irqchip_add_irqfd_notifier_gsi(KVMState *s, EventNotifier *n, EventNotifier *rn, int virq); int kvm_irqchip_remove_irqfd_notifier_gsi(KVMState *s, EventNotifier *n, int virq); +int kvm_irqchip_add_irqfd_notifier(KVMState *s, EventNotifier *n, + EventNotifier *rn, qemu_irq irq); +int kvm_irqchip_remove_irqfd_notifier(KVMState *s, EventNotifier *n, + qemu_irq irq); +void kvm_irqchip_set_qemuirq_gsi(KVMState *s, qemu_irq irq, int gsi); void kvm_pc_gsi_handler(void *opaque, int n, int level); void kvm_pc_setup_irq_routing(bool pci_enabled); void kvm_init_irq_routing(KVMState *s); diff --git a/kvm-all.c b/kvm-all.c index 42bb923..d2cb7ed 100644 --- a/kvm-all.c +++ b/kvm-all.c @@ -37,6 +37,7 @@ #include "exec/address-spaces.h" #include "qemu/event_notifier.h" #include "trace.h" +#include "hw/irq.h" #include "hw/boards.h" @@ -99,6 +100,7 @@ struct KVMState * unsigned, and treating them as signed here can break things */ unsigned irq_set_ioctl; unsigned int sigmask_len; + GHashTable *gsimap; #ifdef KVM_CAP_IRQ_ROUTING struct kvm_irq_routing *irq_routes; int nr_allocated_irq_routes; @@ -1382,6 +1384,39 @@ int kvm_irqchip_remove_irqfd_notifier_gsi(KVMState *s, EventNotifier *n, false); } +int kvm_irqchip_add_irqfd_notifier(KVMState *s, EventNotifier *n, + EventNotifier *rn, qemu_irq irq) +{ + gpointer key, gsi; + gboolean found = g_hash_table_lookup_extended(s->gsimap, irq, &key, &gsi); + + if (!found) { + return -ENXIO; + } else { + return kvm_irqchip_add_irqfd_notifier_gsi(s, n, rn, + GPOINTER_TO_UINT(gsi)); + } +} + +int kvm_irqchip_remove_irqfd_notifier(KVMState *s, EventNotifier *n, + qemu_irq irq) +{ + gpointer key, gsi; + gboolean found = g_hash_table_lookup_extended(s->gsimap, irq, &key, &gsi); + + if (!found) { + return -ENXIO; + } else { + return kvm_irqchip_remove_irqfd_notifier_gsi(s, n, + GPOINTER_TO_INT(gsi)); + } +} + +void kvm_irqchip_set_qemuirq_gsi(KVMState *s, qemu_irq irq, int gsi) +{ + g_hash_table_insert(s->gsimap, irq, GINT_TO_POINTER(gsi)); +} + static int kvm_irqchip_create(MachineState *machine, KVMState *s) { int ret; @@ -1414,6 +1449,8 @@ static int kvm_irqchip_create(MachineState *machine, KVMState *s) kvm_init_irq_routing(s); + s->gsimap = g_hash_table_new(g_direct_hash, g_direct_equal); + return 0; }