From patchwork Thu Nov 19 14:53:54 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Auger X-Patchwork-Id: 7657791 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 2CB3ABF90C for ; Thu, 19 Nov 2015 14:54:38 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 9589C2063C for ; Thu, 19 Nov 2015 14:54:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B0A41206A7 for ; Thu, 19 Nov 2015 14:54:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758754AbbKSOyX (ORCPT ); Thu, 19 Nov 2015 09:54:23 -0500 Received: from mail-wm0-f44.google.com ([74.125.82.44]:36633 "EHLO mail-wm0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757273AbbKSOyT (ORCPT ); Thu, 19 Nov 2015 09:54:19 -0500 Received: by wmww144 with SMTP id w144so241827535wmw.1 for ; Thu, 19 Nov 2015 06:54:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=hRRAqOqPn9ZKzVpLD9RckfvNossiSj+Bth8kvxS5CaQ=; b=LuFdt/ukWxds4Yns7j55AqgARwTBzLFfODvxJf08dPv5owwOlDcssemUOSkbv9b+Vr bU5GrJPwIj3ZNKCwMv1yVmzeh2vDS3ZGp/Usd22njGEtx7ln0OPrHO0D+GrUXH20Nfal BG74qoVrA3bd/yIE6Urooma/FcDSPIP2W3LRiKx0knZf7ipHGa6ULJ1rk9fc7TnLII1C k0qNEOa2ww/5OyjUBm2//2TxdLDTNTRzzNe/8k5G5b0IV38EcvcJmV0OcVrmwxQLWeZE Z9uj9YBgHR75Z/IvhD73/u+Tm7A66fGBaEpFi1EJM3S1bf0VJbCzv1fmL4XHkRHIi50z 0HiQ== 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=hRRAqOqPn9ZKzVpLD9RckfvNossiSj+Bth8kvxS5CaQ=; b=SDTu9gq98kUhZw3XHmC20M03ds1Oyvabp1KOM7q9yPXlV6kHd57ZbIOzmEdQsYExh4 2QBM5T0eDgO2xDowVKdQEbFW+H34Y8AeMooI/nGct1gSzjQRwp99xiEQ2ypOUwafFng4 pbrPSUziHwgcxbsnamsH9//lc2zcDqj+zhoct41nyS69lX9kEPDJFtLaS1rdmrK7989x NeMOVvdFZPCIyKiqY6EdvJlmBax03qJwEEi6G71lpXrgpfJLMFJ/dE8eELq8Wxkc7bly Zi82+/A43iq9/SuBqUcd9+HhzrMLsmc8ArPAgArA4gJpE8nQrtSNaZPCddxn5pfvZ0Wu kqEQ== X-Gm-Message-State: ALoCoQlTWHZyK+lF+BF1icnkIBc4OT1+AmgoguF2SlNwoEcKuBXgpuL82KKhucAX48/VGxm6j2jn X-Received: by 10.28.89.129 with SMTP id n123mr3441373wmb.2.1447944856695; Thu, 19 Nov 2015 06:54:16 -0800 (PST) Received: from new-host-3.home (LMontsouris-657-1-37-90.w80-11.abo.wanadoo.fr. [80.11.198.90]) by smtp.gmail.com with ESMTPSA id h67sm34493865wmf.17.2015.11.19.06.54.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 19 Nov 2015 06:54:15 -0800 (PST) From: Eric Auger To: eric.auger@st.com, eric.auger@linaro.org, alex.williamson@redhat.com, b.reynal@virtualopensystems.com, christoffer.dall@linaro.org, marc.zyngier@arm.com, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org Cc: andre.przywara@arm.com, linux-kernel@vger.kernel.org, patches@linaro.org Subject: [PATCH v4 04/13] VFIO: platform: single handler using function pointer Date: Thu, 19 Nov 2015 14:53:54 +0000 Message-Id: <1447944843-17731-5-git-send-email-eric.auger@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1447944843-17731-1-git-send-email-eric.auger@linaro.org> References: <1447944843-17731-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.3 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,T_DKIM_INVALID,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 d4462fd..c58e0ad 100644 --- a/drivers/vfio/platform/vfio_platform_irq.c +++ b/drivers/vfio/platform/vfio_platform_irq.c @@ -148,11 +148,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; @@ -161,8 +158,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); @@ -178,6 +173,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 void vfio_platform_irq_bypass_stop(struct irq_bypass_producer *prod) { } @@ -230,9 +238,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 55e8043..8a8c050 100644 --- a/drivers/vfio/platform/vfio_platform_private.h +++ b/drivers/vfio/platform/vfio_platform_private.h @@ -40,6 +40,7 @@ struct vfio_platform_irq { struct virqfd *mask; struct irq_bypass_producer producer; bool forwarded; + irqreturn_t (*handler)(int irq, void *dev_id); }; struct vfio_platform_region {