From patchwork Mon Jun 15 16:33:55 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Auger Eric X-Patchwork-Id: 49887 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f71.google.com (mail-wg0-f71.google.com [74.125.82.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 836B3205DE for ; Mon, 15 Jun 2015 16:34:35 +0000 (UTC) Received: by wgv5 with SMTP id 5sf26280089wgv.0 for ; Mon, 15 Jun 2015 09:34: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=FBTGCq2U0xv0V1a/GB87faceG3DiId3MiNQrSpv0TQI=; b=AKjH659trPjiQQDwbkNQqxjQZvypAcyfMsCVXYiaU8jiZ3IPOOBLXyqsbT6e7wQW3x AlzOisvAnku+30u3zYtKZfL4ksz6z6bpHcTeoaqDj0rKq0Uj+ofYLHvmp+eidkMGeYHc qvjpusXvPfEEtPGnnX9uJ/Yrf2HcFiT1B+4sVBACHGWC7KcA3nQGkspKiOVoBBkI6umt INsd25xoy3QLQ+ISiZ7AWjTEmXCg89ugPwx9zeqfeoE3G/lCH0NzYiT74mcJgM2JJuQ3 MftVTvYH/XtdyJ2Lx3vGDqsP5z1lIy5oUCllg1LqRO8mrscVuhJpbJJ3S+8uOv814DPL QNPw== X-Gm-Message-State: ALoCoQnUIU+LASm1HKd4qFsCtTQlw24yoWnpkdF+CPtl+fQPm9/bH7Yr/fsUT5/V6kLBK0I4imkC X-Received: by 10.112.142.67 with SMTP id ru3mr902615lbb.1.1434386074764; Mon, 15 Jun 2015 09:34:34 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.179.39 with SMTP id dd7ls930975lac.60.gmail; Mon, 15 Jun 2015 09:34:34 -0700 (PDT) X-Received: by 10.152.225.166 with SMTP id rl6mr27969473lac.36.1434386074491; Mon, 15 Jun 2015 09:34:34 -0700 (PDT) Received: from mail-la0-f46.google.com (mail-la0-f46.google.com. [209.85.215.46]) by mx.google.com with ESMTPS id bo7si10882341lbb.108.2015.06.15.09.34.34 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 15 Jun 2015 09:34:34 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.46 as permitted sender) client-ip=209.85.215.46; Received: by lacny3 with SMTP id ny3so41684589lac.3 for ; Mon, 15 Jun 2015 09:34:34 -0700 (PDT) X-Received: by 10.152.225.166 with SMTP id rl6mr27969459lac.36.1434386074366; Mon, 15 Jun 2015 09:34: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.108.230 with SMTP id hn6csp1533918lbb; Mon, 15 Jun 2015 09:34:33 -0700 (PDT) X-Received: by 10.180.7.169 with SMTP id k9mr33680128wia.84.1434386069001; Mon, 15 Jun 2015 09:34:29 -0700 (PDT) Received: from mail-wi0-f170.google.com (mail-wi0-f170.google.com. [209.85.212.170]) by mx.google.com with ESMTPS id o2si1508791wiz.49.2015.06.15.09.34.28 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 15 Jun 2015 09:34:28 -0700 (PDT) Received-SPF: pass (google.com: domain of eric.auger@linaro.org designates 209.85.212.170 as permitted sender) client-ip=209.85.212.170; Received: by wifx6 with SMTP id x6so84401788wif.0 for ; Mon, 15 Jun 2015 09:34:28 -0700 (PDT) X-Received: by 10.194.7.97 with SMTP id i1mr54144551wja.107.1434386068846; Mon, 15 Jun 2015 09:34:28 -0700 (PDT) Received: from midway01-04-00.lavalab ([81.128.185.50]) by mx.google.com with ESMTPSA id bh7sm19677484wjb.8.2015.06.15.09.34.27 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 15 Jun 2015 09:34:28 -0700 (PDT) From: Eric Auger To: eric.auger@st.com, eric.auger@linaro.org, qemu-devel@nongnu.org, peter.maydell@linaro.org, peter.crosthwaite@xilinx.com, pbonzini@redhat.com, alex.williamson@redhat.com Cc: christoffer.dall@linaro.org, patches@linaro.org, b.reynal@virtualopensystems.com, vikrams@codeaurora.org Subject: [RESEND PATCH v16 3/6] kvm-all.c: add qemu_irq/gsi hash table and utility routines Date: Mon, 15 Jun 2015 17:33:55 +0100 Message-Id: <1434386038-9246-4-git-send-email-eric.auger@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1434386038-9246-1-git-send-email-eric.auger@linaro.org> References: <1434386038-9246-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.46 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 Tested-by: Vikram Sethi --- 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 | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 43 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..939bfc4 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,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; @@ -1371,6 +1406,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; }