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: Auger Eric X-Patchwork-Id: 57005 Delivered-To: patches@linaro.org Received: by 10.112.155.196 with SMTP id vy4csp3227050lbb; Thu, 19 Nov 2015 06:54:20 -0800 (PST) X-Received: by 10.28.23.136 with SMTP id 130mr1113063wmx.94.1447944856938; Thu, 19 Nov 2015 06:54:16 -0800 (PST) Return-Path: Received: from mail-wm0-x22e.google.com (mail-wm0-x22e.google.com. [2a00:1450:400c:c09::22e]) by mx.google.com with ESMTPS id iq7si7779930wjb.143.2015.11.19.06.54.16 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 19 Nov 2015 06:54:16 -0800 (PST) Received-SPF: pass (google.com: domain of eric.auger@linaro.org designates 2a00:1450:400c:c09::22e as permitted sender) client-ip=2a00:1450:400c:c09::22e; Authentication-Results: mx.google.com; spf=pass (google.com: domain of eric.auger@linaro.org designates 2a00:1450:400c:c09::22e as permitted sender) smtp.mailfrom=eric.auger@linaro.org; dkim=pass header.i=@linaro-org.20150623.gappssmtp.com Received: by wmww144 with SMTP id w144so119950089wmw.0 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=U70ZbCQ4p0AG+BLHFp6g7ymcEz0P2j8Ow29mbVhrMMHETGCV7n9Q39HEe+DY30iJKr LShYapqpUkJdkMmoCpzbEmAYC2Jxzed5GVnie5tJ5oUyJ7wPpi6J3BT/SjD4JHU+fmLl S/HSDo8FanqcNtYlTTGg3LWhnd1WLVn95H8wgO05eFgfTonZ8C6HuXSshZtIPA79vgSt /Z3GUqn9Pmwequ7QwH34LyjnRXML3lWAEc2YkU/td/N7ubhCHmgPUxCTB7hRfpQ9L+pT OAXOUOyDkgmwxogCtyqwJoqgsSW+L/SSmqkaak1rYYP0VqT0fI92dxWsTBG757NVllBf jEhA== X-Gm-Message-State: ALoCoQkYdEgUCgRQ96EmF+ZCUCsHwDheqmODUgF8sxUwFuJe+GikmgJIdv808xPlFoiD6WeOIFgG X-Received: by 10.28.89.129 with SMTP id n123mr3441373wmb.2.1447944856695; Thu, 19 Nov 2015 06:54:16 -0800 (PST) Return-Path: 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> 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(-) -- 1.9.1 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 {