From patchwork Fri Jun 26 15:30:30 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Auger Eric X-Patchwork-Id: 50362 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 8EC3C228FD for ; Fri, 26 Jun 2015 15:30:52 +0000 (UTC) Received: by lagh6 with SMTP id h6sf27878077lag.0 for ; Fri, 26 Jun 2015 08:30:51 -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=KYIcqScm9PllyrPYlAzOvYfmeVMCVKVnCE8ATk030jxNR50lHCN0s/xAKlLwr6Dj/p aWSinJBD6E85JXA62yHSIJzxDesXs+bYtSuIopb0P9+xSlAJyfJgpfXEx+cGZlM+aTfZ FzPuukgl5/XUB+zqQOO/LoKJTEvivR7dSGFYPdGyCWG3CZnouVZ4GjJNReiCfhHK6TZa VBukmmrdbRUnI7TBeRYzTVJAVBHelmntmE0O+EO8QYfdvou3b/FqQ9O/R0+Adi2RWOpj NhGMWCleHGydONpVm+7sVNi4lX/lfrXy77bdw8JRZgfo8SsE70wG85GNhKBNoWFiQEqA Y0QQ== X-Gm-Message-State: ALoCoQmA4fWQqMfwNh+J5ckuwbzHDhn0OKoTdmpMiOi4svST8LBwcXSE0Z4UCMtQYv2lza1QbmTS X-Received: by 10.112.85.69 with SMTP id f5mr1457557lbz.23.1435332651550; Fri, 26 Jun 2015 08:30:51 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.207.65 with SMTP id lu1ls158884lac.104.gmail; Fri, 26 Jun 2015 08:30:51 -0700 (PDT) X-Received: by 10.152.22.168 with SMTP id e8mr2140997laf.40.1435332651406; Fri, 26 Jun 2015 08:30:51 -0700 (PDT) Received: from mail-la0-f51.google.com (mail-la0-f51.google.com. [209.85.215.51]) by mx.google.com with ESMTPS id ky4si27666510lab.70.2015.06.26.08.30.51 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 26 Jun 2015 08:30:51 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.51 as permitted sender) client-ip=209.85.215.51; Received: by lacny3 with SMTP id ny3so65769193lac.3 for ; Fri, 26 Jun 2015 08:30:51 -0700 (PDT) X-Received: by 10.152.7.7 with SMTP id f7mr2138151laa.106.1435332650979; Fri, 26 Jun 2015 08:30:50 -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 hn6csp4759lbb; Fri, 26 Jun 2015 08:30:50 -0700 (PDT) X-Received: by 10.180.95.10 with SMTP id dg10mr5909909wib.41.1435332648628; Fri, 26 Jun 2015 08:30:48 -0700 (PDT) Received: from mail-wi0-f179.google.com (mail-wi0-f179.google.com. [209.85.212.179]) by mx.google.com with ESMTPS id hh13si3512514wib.51.2015.06.26.08.30.48 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 26 Jun 2015 08:30:48 -0700 (PDT) Received-SPF: pass (google.com: domain of eric.auger@linaro.org designates 209.85.212.179 as permitted sender) client-ip=209.85.212.179; Received: by wibdq8 with SMTP id dq8so20978624wib.1 for ; Fri, 26 Jun 2015 08:30:48 -0700 (PDT) X-Received: by 10.180.103.227 with SMTP id fz3mr5926428wib.45.1435332648357; Fri, 26 Jun 2015 08:30:48 -0700 (PDT) Received: from midway01-04-00.lavalab ([81.128.185.50]) by mx.google.com with ESMTPSA id b5sm2688575wic.3.2015.06.26.08.30.46 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 26 Jun 2015 08:30:47 -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 v17 2/6] kvm-all.c: add qemu_irq/gsi hash table and utility routines Date: Fri, 26 Jun 2015 16:30:30 +0100 Message-Id: <1435332634-10721-3-git-send-email-eric.auger@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1435332634-10721-1-git-send-email-eric.auger@linaro.org> References: <1435332634-10721-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.215.51 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 --- 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; }