From patchwork Thu Jul 2 13:17:12 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Auger X-Patchwork-Id: 6709091 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 2ECEBC05AD for ; Thu, 2 Jul 2015 13:18:19 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 17ECE2024D for ; Thu, 2 Jul 2015 13:18:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id EF1D22063B for ; Thu, 2 Jul 2015 13:18:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753065AbbGBNSN (ORCPT ); Thu, 2 Jul 2015 09:18:13 -0400 Received: from mail-wi0-f175.google.com ([209.85.212.175]:32932 "EHLO mail-wi0-f175.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752614AbbGBNSA (ORCPT ); Thu, 2 Jul 2015 09:18:00 -0400 Received: by wiwl6 with SMTP id l6so196694772wiw.0 for ; Thu, 02 Jul 2015 06:17:58 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=qE3WYGh4vdE3oxioP0qL5Unogt7U8QsQxxPX0SrsQzY=; b=aycIk49sSk9q008y4j0QgmtVlVVWTmCJKd1ztaQE+gzsJlL7pH1PVTwYEWGI+LtOvo KZsMBKajlsV0J9x3JlbQRYrdEOVfn4MwFtXoviaVchGxqg6nfpcnvw0yNExkymdO8yjh UIn8ogeeUfEwHLvbRcxKmpP4iPlVLZ6UOLYhYGPCzUvTiSiDdnYgh/7+zt8XBRNg3isk IgcC+Swwiw0ujFssv9XialL59tpWSQpM+YQ1FNVkuNN1xB8a5bgzB8wNZHS+aTg76WxG Sp1S2U03N887e/awoqkidzenhaWSV+a7VHPPqv7BjHCvhuR9Ou+d+ggf8XeW9iSd0eAx h+Lw== X-Gm-Message-State: ALoCoQmebxFnNp+yhvXx55Bw8WKJnW/ysYtkyxrd1q7JceoiC9NKWHtFGpAatmafDbtUOGDTSr+R X-Received: by 10.180.95.67 with SMTP id di3mr16082041wib.78.1435843078781; Thu, 02 Jul 2015 06:17:58 -0700 (PDT) Received: from gnx2579.home (LCaen-156-56-7-90.w80-11.abo.wanadoo.fr. [80.11.198.90]) by mx.google.com with ESMTPSA id tl3sm8157099wjc.20.2015.07.02.06.17.56 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 02 Jul 2015 06:17:57 -0700 (PDT) From: Eric Auger To: eric.auger@st.com, eric.auger@linaro.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, christoffer.dall@linaro.org, marc.zyngier@arm.com, alex.williamson@redhat.com, pbonzini@redhat.com, avi.kivity@gmail.com, mtosatti@redhat.com, feng.wu@intel.com, joro@8bytes.org, b.reynal@virtualopensystems.com Cc: linux-kernel@vger.kernel.org, patches@linaro.org Subject: [RFC 02/17] VFIO: platform: single handler using function pointer Date: Thu, 2 Jul 2015 15:17:12 +0200 Message-Id: <1435843047-6327-3-git-send-email-eric.auger@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1435843047-6327-1-git-send-email-eric.auger@linaro.org> References: <1435843047-6327-1-git-send-email-eric.auger@linaro.org> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP A single handler now is registered whatever the use case: automasked or not. A function pointer is set according to the wished behavior and the handler calls this function. The irq lock is taken/released in the root handler. eventfd_signal can be called in regions not allowed to sleep. Signed-off-by: Eric Auger --- v4: creation --- drivers/vfio/platform/vfio_platform_irq.c | 21 +++++++++++++++------ drivers/vfio/platform/vfio_platform_private.h | 1 + 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/drivers/vfio/platform/vfio_platform_irq.c b/drivers/vfio/platform/vfio_platform_irq.c index 132bb3f..8eb65c1 100644 --- a/drivers/vfio/platform/vfio_platform_irq.c +++ b/drivers/vfio/platform/vfio_platform_irq.c @@ -147,11 +147,8 @@ static int vfio_platform_set_irq_unmask(struct vfio_platform_device *vdev, static irqreturn_t vfio_automasked_irq_handler(int irq, void *dev_id) { struct vfio_platform_irq *irq_ctx = dev_id; - unsigned long flags; int ret = IRQ_NONE; - spin_lock_irqsave(&irq_ctx->lock, flags); - if (!irq_ctx->masked) { ret = IRQ_HANDLED; @@ -160,8 +157,6 @@ static irqreturn_t vfio_automasked_irq_handler(int irq, void *dev_id) irq_ctx->masked = true; } - spin_unlock_irqrestore(&irq_ctx->lock, flags); - if (ret == IRQ_HANDLED) eventfd_signal(irq_ctx->trigger, 1); @@ -177,6 +172,19 @@ static irqreturn_t vfio_irq_handler(int irq, void *dev_id) return IRQ_HANDLED; } +static irqreturn_t vfio_handler(int irq, void *dev_id) +{ + struct vfio_platform_irq *irq_ctx = dev_id; + unsigned long flags; + irqreturn_t ret; + + spin_lock_irqsave(&irq_ctx->lock, flags); + ret = irq_ctx->handler(irq, dev_id); + spin_unlock_irqrestore(&irq_ctx->lock, flags); + + return ret; +} + static int vfio_set_trigger(struct vfio_platform_device *vdev, int index, int fd, irq_handler_t handler) { @@ -206,9 +214,10 @@ static int vfio_set_trigger(struct vfio_platform_device *vdev, int index, } irq->trigger = trigger; + irq->handler = handler; irq_set_status_flags(irq->hwirq, IRQ_NOAUTOEN); - ret = request_irq(irq->hwirq, handler, 0, irq->name, irq); + ret = request_irq(irq->hwirq, vfio_handler, 0, irq->name, irq); if (ret) { kfree(irq->name); eventfd_ctx_put(trigger); diff --git a/drivers/vfio/platform/vfio_platform_private.h b/drivers/vfio/platform/vfio_platform_private.h index 1c9b3d5..413f575 100644 --- a/drivers/vfio/platform/vfio_platform_private.h +++ b/drivers/vfio/platform/vfio_platform_private.h @@ -37,6 +37,7 @@ struct vfio_platform_irq { spinlock_t lock; struct virqfd *unmask; struct virqfd *mask; + irqreturn_t (*handler)(int irq, void *dev_id); }; struct vfio_platform_region {