From patchwork Thu Apr 23 15:08:35 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Auger Eric X-Patchwork-Id: 47464 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f72.google.com (mail-wg0-f72.google.com [74.125.82.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id D4F782121F for ; Thu, 23 Apr 2015 15:08:50 +0000 (UTC) Received: by wgin8 with SMTP id n8sf5049049wgi.0 for ; Thu, 23 Apr 2015 08:08:49 -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=GIffWHOdXEHdGFPQH62u6I2GdtkofpOwLj6wcKPddVQ=; b=GcwF50rI+IBVJWKOeNq5UitpdLdpuKDHN4aR5CHiMt6/fW1X8xyWNliFC6hhiFP6zP lu8+kYdx5LZ9AEmLieO2di9Y9wUgjQpwxdUzRGVAEcXA0573LtITzRATXcKuB7367/Em yvb3lNRhi7eCnL/CF0+o9/VrhT+waNbRjXWv7sxc3kkIjrwEBWj1tLJn1tK27uNPWqlQ UsUQAF6Nb5xPknSbQxyLXNRw9djPT+LLhZX3AxHzKMostk0R9pVmPS8Up1Uo+rDYLpPI xOnqmFyIFHGYDnQ1cgyhaWobb0bmqXDFMgkmuDE3Bw2alVuAkF6Un3P0Rlf1+2jQTnly dp5g== X-Gm-Message-State: ALoCoQnV0VHBVCHgHx10nI6CFscCwGWzI65NGUrW4hXnnyMi4cuFDEu+jDxijyvkBgMEu+P4eksh X-Received: by 10.180.105.226 with SMTP id gp2mr4142116wib.1.1429801729208; Thu, 23 Apr 2015 08:08:49 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.22.134 with SMTP id d6ls338148laf.95.gmail; Thu, 23 Apr 2015 08:08:49 -0700 (PDT) X-Received: by 10.112.29.36 with SMTP id g4mr2935710lbh.56.1429801728985; Thu, 23 Apr 2015 08:08:48 -0700 (PDT) Received: from mail-lb0-f178.google.com (mail-lb0-f178.google.com. [209.85.217.178]) by mx.google.com with ESMTPS id ac10si6147780lbc.134.2015.04.23.08.08.48 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 23 Apr 2015 08:08:48 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.178 as permitted sender) client-ip=209.85.217.178; Received: by lbbuc2 with SMTP id uc2so15492702lbb.2 for ; Thu, 23 Apr 2015 08:08:48 -0700 (PDT) X-Received: by 10.152.27.1 with SMTP id p1mr2803277lag.112.1429801728711; Thu, 23 Apr 2015 08:08:48 -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 l1csp631726lbt; Thu, 23 Apr 2015 08:08:48 -0700 (PDT) X-Received: by 10.194.63.225 with SMTP id j1mr6437121wjs.120.1429801727854; Thu, 23 Apr 2015 08:08:47 -0700 (PDT) Received: from mail-wg0-f52.google.com (mail-wg0-f52.google.com. [74.125.82.52]) by mx.google.com with ESMTPS id hq9si14220262wjb.91.2015.04.23.08.08.47 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 23 Apr 2015 08:08:47 -0700 (PDT) Received-SPF: pass (google.com: domain of eric.auger@linaro.org designates 74.125.82.52 as permitted sender) client-ip=74.125.82.52; Received: by wgso17 with SMTP id o17so21710291wgs.1 for ; Thu, 23 Apr 2015 08:08:47 -0700 (PDT) X-Received: by 10.194.2.16 with SMTP id 16mr6283600wjq.46.1429801727365; Thu, 23 Apr 2015 08:08:47 -0700 (PDT) Received: from midway01-04-00.lavalab ([81.128.185.50]) by mx.google.com with ESMTPSA id wo10sm12545993wjb.35.2015.04.23.08.08.46 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 23 Apr 2015 08:08:46 -0700 (PDT) From: Eric Auger To: eric.auger@st.com, eric.auger@linaro.org, qemu-devel@nongnu.org, peter.maydell@linaro.org, agraf@suse.de, pbonzini@redhat.com Cc: christoffer.dall@linaro.org, kvmarm@lists.cs.columbia.edu, patches@linaro.org, alex.williamson@redhat.com Subject: [PATCH v2 1/2] kvm-all.c: add qemu_irq/gsi hash table and utility routines Date: Thu, 23 Apr 2015 16:08:35 +0100 Message-Id: <1429801716-8027-2-git-send-email-eric.auger@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1429801716-8027-1-git-send-email-eric.auger@linaro.org> References: <1429801716-8027-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.178 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]_qemuirq_irqfd_notifier allows to setup/tear down irqfd directly from the qemu_irq. Signed-off-by: Eric Auger --- 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 197e6c0..911aaa8 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 @@ -416,6 +417,11 @@ int kvm_irqchip_add_adapter_route(KVMState *s, AdapterInfo *adapter); int kvm_irqchip_add_irqfd_notifier(KVMState *s, EventNotifier *n, EventNotifier *rn, int virq); int kvm_irqchip_remove_irqfd_notifier(KVMState *s, EventNotifier *n, int virq); +int kvm_irqchip_add_qemuirq_irqfd_notifier(KVMState *s, EventNotifier *n, + EventNotifier *rn, qemu_irq irq); +int kvm_irqchip_remove_qemuirq_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 dd44f8c..ec9f4ac 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; @@ -1381,6 +1383,37 @@ int kvm_irqchip_remove_irqfd_notifier(KVMState *s, EventNotifier *n, int virq) false); } +int kvm_irqchip_add_qemuirq_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(s, n, rn, GPOINTER_TO_UINT(gsi)); + } +} + +int kvm_irqchip_remove_qemuirq_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(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; @@ -1413,6 +1446,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; }