From patchwork Fri Jun 26 17:29:23 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Auger Eric X-Patchwork-Id: 50368 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f199.google.com (mail-lb0-f199.google.com [209.85.217.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 29FD122902 for ; Fri, 26 Jun 2015 17:29:42 +0000 (UTC) Received: by lbbvz5 with SMTP id vz5sf28325994lbb.1 for ; Fri, 26 Jun 2015 10:29:41 -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=4U4yQl1tFUPVLx+ao/LwuKxbf+MBB1lSFbw3XVDgRqg=; b=gO51eOSnxwNkqoQWLg5MS1Yg5j7MLYYLNMGJ9b9a3aXKhZenFm2InLXj/0fwgu6GqG st9LVf+7oi40xyMi3pSp9zGTCbWqBu3IFE1QpSwJinyLWWcvwTD4LbuSa2t3HQkoucBE Ebl5GtF5ewgmXMqorWCG5RRDFqr7NIghfbxQwuA/w4OltzEp+D5bfg68rQVWjfOrB16i Uo5aHb5Lj14NORNXAievwwTD420Sd2iExXCaZBGgUv8PaPmtjbfMdRfuH505R1coXMDD /VuUp0lx0FFzzEM/f387TgeTaiHuGdYUtU/3ooNxH9MDS3E2f+AmAWlUgnRst33nmR1x rrqw== X-Gm-Message-State: ALoCoQk1qCMqpZwrSNGthvhTF3pg+knji/tN56Bst5YzLa/oeeI6RMJxOkPRKNStP8cbLox3prCI X-Received: by 10.194.81.136 with SMTP id a8mr1807067wjy.2.1435339780999; Fri, 26 Jun 2015 10:29:40 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.1.73 with SMTP id 9ls463158lak.17.gmail; Fri, 26 Jun 2015 10:29:40 -0700 (PDT) X-Received: by 10.112.212.9 with SMTP id ng9mr2559550lbc.57.1435339780701; Fri, 26 Jun 2015 10:29:40 -0700 (PDT) Received: from mail-lb0-f172.google.com (mail-lb0-f172.google.com. [209.85.217.172]) by mx.google.com with ESMTPS id d9si27925713lad.19.2015.06.26.10.29.40 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 26 Jun 2015 10:29:40 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.172 as permitted sender) client-ip=209.85.217.172; Received: by lbnk3 with SMTP id k3so68663989lbn.1 for ; Fri, 26 Jun 2015 10:29:40 -0700 (PDT) X-Received: by 10.112.209.106 with SMTP id ml10mr2539075lbc.112.1435339779787; Fri, 26 Jun 2015 10:29:39 -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.108.230 with SMTP id hn6csp69942lbb; Fri, 26 Jun 2015 10:29:39 -0700 (PDT) X-Received: by 10.194.172.130 with SMTP id bc2mr5053168wjc.85.1435339779037; Fri, 26 Jun 2015 10:29:39 -0700 (PDT) Received: from mail-wi0-f175.google.com (mail-wi0-f175.google.com. [209.85.212.175]) by mx.google.com with ESMTPS id v3si4016554wix.97.2015.06.26.10.29.38 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 26 Jun 2015 10:29:39 -0700 (PDT) Received-SPF: pass (google.com: domain of eric.auger@linaro.org designates 209.85.212.175 as permitted sender) client-ip=209.85.212.175; Received: by wiga1 with SMTP id a1so23336685wig.0 for ; Fri, 26 Jun 2015 10:29:38 -0700 (PDT) X-Received: by 10.194.71.82 with SMTP id s18mr5128088wju.102.1435339778786; Fri, 26 Jun 2015 10:29:38 -0700 (PDT) Received: from midway01-04-00.lavalab ([81.128.185.50]) by mx.google.com with ESMTPSA id m10sm3088489wib.17.2015.06.26.10.29.37 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 26 Jun 2015 10:29:37 -0700 (PDT) From: Eric Auger To: eric.auger@st.com, eric.auger@linaro.org, qemu-devel@nongnu.org, peter.maydell@linaro.org, alex.williamson@redhat.com, pbonzini@redhat.com Cc: peter.crosthwaite@xilinx.com, christoffer.dall@linaro.org, patches@linaro.org Subject: [PATCH v18 2/6] kvm-all.c: add qemu_irq/gsi hash table and utility routines Date: Fri, 26 Jun 2015 18:29:23 +0100 Message-Id: <1435339767-2301-3-git-send-email-eric.auger@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1435339767-2301-1-git-send-email-eric.auger@linaro.org> References: <1435339767-2301-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.172 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 patch 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 Tested-by: Vikram Sethi Acked-by: Paolo Bonzini Reviewed-by: Peter Maydell --- v16 -> v17 - replace GPOINTER_TO_UINT by GPOINTER_TO_INT - add Paolo's ack v15 -> v16: - Added Vikram's T-b 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 | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h index acb3025..ba612fc 100644 --- a/include/sysemu/kvm.h +++ b/include/sysemu/kvm.h @@ -19,6 +19,7 @@ #include "qemu/queue.h" #include "qom/cpu.h" #include "exec/memattrs.h" +#include "hw/irq.h" #ifdef CONFIG_KVM #include @@ -420,6 +421,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 730b818..cb76b38 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" @@ -98,6 +99,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; @@ -1339,6 +1341,35 @@ 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; + } + return kvm_irqchip_add_irqfd_notifier_gsi(s, n, rn, GPOINTER_TO_INT(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; + } + 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; @@ -1371,6 +1402,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; }