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: Auger Eric X-Patchwork-Id: 47720 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f71.google.com (mail-la0-f71.google.com [209.85.215.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 10E812121F for ; Wed, 29 Apr 2015 14:52:36 +0000 (UTC) Received: by laat2 with SMTP id t2sf7399854laa.2 for ; Wed, 29 Apr 2015 07:52:34 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=UaNkorBaMBNS11JvYo2QH4Mzmmuoc9gqlrL+MRM9bOw=; b=hHcSutZ/pIVMGTw3pk8OZBdDP+U7C85gY/UoKz2rXkx3BMgl+gNOnmSb1SXFkSqvhT soMok6WSaGmFTnRMar0mfCaNYUoSp0IMpbeP8z2RFCaHHgCPCQdZmJESK5STaxN7fdOI IQWUvXz+UirxndkBg/IvzE3VpfLAPSM85Bc7RmunVRhfTOhPBANj8YBM9CFmZpHLMJ1k SYaldCiS6wEehtX6IFO+9Aw1/GkISaKOt/+9ekgy2rb7FACheS0Af642Xz/BRZm6FTcH sOrT0N45JGntSj45EeUxfTx3PxchwOMf3kbxqTuSDspwMZtEB2sGEOHFsPTAIV/Yx85S bdFg== X-Gm-Message-State: ALoCoQlJ2C8l/HeLwBmtNdzKYiFNp6NO6RqkCx4aPB4X3A1+bX7qRWSEs3P/krxZAQCTj1Kje9kH X-Received: by 10.180.105.226 with SMTP id gp2mr13276004wib.1.1430319154764; Wed, 29 Apr 2015 07:52:34 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.10.208 with SMTP id k16ls252312lab.42.gmail; Wed, 29 Apr 2015 07:52:34 -0700 (PDT) X-Received: by 10.153.5.8 with SMTP id ci8mr19457723lad.62.1430319154610; Wed, 29 Apr 2015 07:52:34 -0700 (PDT) Received: from mail-lb0-f173.google.com (mail-lb0-f173.google.com. [209.85.217.173]) by mx.google.com with ESMTPS id pj6si19370941lbb.17.2015.04.29.07.52.34 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 29 Apr 2015 07:52:34 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.173 as permitted sender) client-ip=209.85.217.173; Received: by lbcga7 with SMTP id ga7so22231419lbc.1 for ; Wed, 29 Apr 2015 07:52:34 -0700 (PDT) X-Received: by 10.152.27.98 with SMTP id s2mr19412365lag.106.1430319154500; Wed, 29 Apr 2015 07:52:34 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.112.67.65 with SMTP id l1csp2553792lbt; Wed, 29 Apr 2015 07:52:34 -0700 (PDT) X-Received: by 10.194.187.71 with SMTP id fq7mr1554133wjc.87.1430319144094; Wed, 29 Apr 2015 07:52:24 -0700 (PDT) Received: from mail-wg0-f47.google.com (mail-wg0-f47.google.com. [74.125.82.47]) by mx.google.com with ESMTPS id c8si23765805wiy.41.2015.04.29.07.52.23 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 29 Apr 2015 07:52:24 -0700 (PDT) Received-SPF: pass (google.com: domain of eric.auger@linaro.org designates 74.125.82.47 as permitted sender) client-ip=74.125.82.47; Received: by wgyo15 with SMTP id o15so31177056wgy.2 for ; Wed, 29 Apr 2015 07:52:23 -0700 (PDT) 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 Cc: christoffer.dall@linaro.org, kvmarm@lists.cs.columbia.edu, patches@linaro.org, peter.maydell@linaro.org, alex.bennee@linaro.org, b.reynal@virtualopensystems.com, Bharat.Bhushan@freescale.com, vikrams@codeaurora.org, cornelia.huck@de.ibm.com, borntraeger@de.ibm.com Subject: [PATCH v14 07/10] kvm-all.c: add qemu_irq/gsi hash table and utility routines 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-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: eric.auger@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.173 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , 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; }