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: Auger Eric X-Patchwork-Id: 50576 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f69.google.com (mail-wg0-f69.google.com [74.125.82.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id B62B0214B3 for ; Thu, 2 Jul 2015 13:18:00 +0000 (UTC) Received: by wgbbj7 with SMTP id bj7sf21248692wgb.2 for ; Thu, 02 Jul 2015 06:18:00 -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=qE3WYGh4vdE3oxioP0qL5Unogt7U8QsQxxPX0SrsQzY=; b=N/B7cF4CtniXGR+AwrmIn3jH5TKfZ+RBT+IItuZSAe17zliZQZku+CpvGpsmWtljfr 0XD6Q3VtBhdwAQR/r/9DYDsaGKrQdHyvi8LKMSx1QB1tD8mBaz9fJ4NqC+Er+uiiIhn7 LtCOepCJlbCfIA8LMpJs6cpXiv0m9igH1ho41RhVXvIv9IrKr8f+ttJMILEgFdAcswUx iM+d744Tz/qPhy2vDdhY4036Qglwosz+Qz8d80FIc7bzy3lsY1ASPyyYEG3uSRkLqmrx KTbwr0zc4ea6CYd0Mq8MDe/MAz2f88MO8P6HM2bDY/ZRqA8g8/hGAdjVdJTpGG82zjtM j6xQ== X-Gm-Message-State: ALoCoQli+pMnN3FDa6X+ni4rF6lnbwxhjBZFXRZ32PI/BIr5POuu7PNyRPmzSQqdHkzaQrIGnzfo X-Received: by 10.180.9.197 with SMTP id c5mr3334215wib.0.1435843080036; Thu, 02 Jul 2015 06:18:00 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.36.34 with SMTP id n2ls316034laj.15.gmail; Thu, 02 Jul 2015 06:17:59 -0700 (PDT) X-Received: by 10.152.20.228 with SMTP id q4mr31215863lae.12.1435843079881; Thu, 02 Jul 2015 06:17:59 -0700 (PDT) Received: from mail-lb0-f170.google.com (mail-lb0-f170.google.com. [209.85.217.170]) by mx.google.com with ESMTPS id uo6si4466512lbc.21.2015.07.02.06.17.59 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 02 Jul 2015 06:17:59 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.170 as permitted sender) client-ip=209.85.217.170; Received: by lbbpo10 with SMTP id po10so31804695lbb.3 for ; Thu, 02 Jul 2015 06:17:59 -0700 (PDT) X-Received: by 10.152.4.163 with SMTP id l3mr31045942lal.35.1435843079779; Thu, 02 Jul 2015 06:17:59 -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 hn6csp476012lbb; Thu, 2 Jul 2015 06:17:59 -0700 (PDT) X-Received: by 10.180.211.106 with SMTP id nb10mr15905202wic.33.1435843079075; Thu, 02 Jul 2015 06:17:59 -0700 (PDT) Received: from mail-wg0-f44.google.com (mail-wg0-f44.google.com. [74.125.82.44]) by mx.google.com with ESMTPS id dm2si9496126wib.6.2015.07.02.06.17.58 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 02 Jul 2015 06:17:59 -0700 (PDT) Received-SPF: pass (google.com: domain of eric.auger@linaro.org designates 74.125.82.44 as permitted sender) client-ip=74.125.82.44; Received: by wguu7 with SMTP id u7so63049780wgu.3 for ; Thu, 02 Jul 2015 06:17:58 -0700 (PDT) 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> 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.170 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: , 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 {