From patchwork Tue Apr 28 16:51:08 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Auger Eric X-Patchwork-Id: 47692 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f72.google.com (mail-la0-f72.google.com [209.85.215.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id E73FB20553 for ; Tue, 28 Apr 2015 16:51:38 +0000 (UTC) Received: by labgx2 with SMTP id gx2sf246988lab.1 for ; Tue, 28 Apr 2015 09:51:37 -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=bRzuKBsyH/7OwQQMpkxINcYIqr+bWa7YyN3nziMIIwA=; b=UsWibpF38VQ3OLp4UQLiCSSMF3ESKukTYyXEssNzSHPYECKQyIZB2Gt1wlaQUxANr2 +QGp8aQWM2KoA2oj29IoN/9XQWrSlSJ1wjVZh+WCsAf5D8uXM+RTIVozbemicKh4FrWo aM2jH0aAcL4sOfiiM5ajKCtKJAGmqR9i+LXFsNIi8gjdKyHzTz+wMedj4XCU1ZTp5b6M nWqC8HCER7+lwh3TPijwJJwYqYqwDE/sj2DzJ7hLBvX9AflhBPVG+zSOwn2aSpkMHfKB NUZqzhbDumo1VtfP6T4HP7o6Ve6FKperg2BYuvEnnvi0dunfll4zrlmM1/5jLkhk0Jcw JrtQ== X-Gm-Message-State: ALoCoQmU2q2tomJ3iW5w4fXhh1tDSJ8eqX1zPcDGoPNvbnQ5dRxfTHyLdoco//7vM/FeTWy6CWv9 X-Received: by 10.180.107.33 with SMTP id gz1mr10590654wib.3.1430239897951; Tue, 28 Apr 2015 09:51:37 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.153.6.35 with SMTP id cr3ls88074lad.47.gmail; Tue, 28 Apr 2015 09:51:37 -0700 (PDT) X-Received: by 10.112.181.68 with SMTP id du4mr14820039lbc.11.1430239897790; Tue, 28 Apr 2015 09:51:37 -0700 (PDT) Received: from mail-la0-f47.google.com (mail-la0-f47.google.com. [209.85.215.47]) by mx.google.com with ESMTPS id 3si11250987lav.0.2015.04.28.09.51.37 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 28 Apr 2015 09:51:37 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.47 as permitted sender) client-ip=209.85.215.47; Received: by laat2 with SMTP id t2so573621laa.1 for ; Tue, 28 Apr 2015 09:51:37 -0700 (PDT) X-Received: by 10.152.37.228 with SMTP id b4mr9308020lak.117.1430239897657; Tue, 28 Apr 2015 09:51:37 -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 l1csp2002245lbt; Tue, 28 Apr 2015 09:51:37 -0700 (PDT) X-Received: by 10.180.85.42 with SMTP id e10mr924741wiz.17.1430239890741; Tue, 28 Apr 2015 09:51:30 -0700 (PDT) Received: from mail-wi0-f178.google.com (mail-wi0-f178.google.com. [209.85.212.178]) by mx.google.com with ESMTPS id el1si18888881wib.120.2015.04.28.09.51.30 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 28 Apr 2015 09:51:30 -0700 (PDT) Received-SPF: pass (google.com: domain of eric.auger@linaro.org designates 209.85.212.178 as permitted sender) client-ip=209.85.212.178; Received: by wicmx19 with SMTP id mx19so112430671wic.1 for ; Tue, 28 Apr 2015 09:51:30 -0700 (PDT) X-Received: by 10.194.57.11 with SMTP id e11mr32425400wjq.19.1430239890491; Tue, 28 Apr 2015 09:51:30 -0700 (PDT) Received: from midway01-04-00.lavalab ([81.128.185.50]) by mx.google.com with ESMTPSA id gs7sm17255958wib.10.2015.04.28.09.51.28 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 28 Apr 2015 09:51:28 -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, kim.phillips@freescale.com, b.reynal@virtualopensystems.com, Bharat.Bhushan@freescale.com, vikrams@codeaurora.org Subject: [PATCH v13 07/12] kvm-all.c: add qemu_irq/gsi hash table and utility routines Date: Tue, 28 Apr 2015 17:51:08 +0100 Message-Id: <1430239873-31950-8-git-send-email-eric.auger@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1430239873-31950-1-git-send-email-eric.auger@linaro.org> References: <1430239873-31950-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.47 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 --- v2 -> v3: - 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 | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 41 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..6531062 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,37 @@ 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 +1447,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; }