From patchwork Wed Feb 11 08:32:16 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Auger X-Patchwork-Id: 5811101 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 94E049F37F for ; Wed, 11 Feb 2015 08:40:55 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B637A2021B for ; Wed, 11 Feb 2015 08:40:54 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id DDB3120211 for ; Wed, 11 Feb 2015 08:40:53 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1YLSoV-0006Cs-9T; Wed, 11 Feb 2015 08:38:27 +0000 Received: from mail-ig0-f173.google.com ([209.85.213.173]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1YLSln-0001hh-Eo for linux-arm-kernel@lists.infradead.org; Wed, 11 Feb 2015 08:35:40 +0000 Received: by mail-ig0-f173.google.com with SMTP id a13so29261343igq.0 for ; Wed, 11 Feb 2015 00:35:17 -0800 (PST) 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=X2x9/8md+TgHX+Lu0ecvMnBTZIASM70oZWaDig2hSZk=; b=I5C4IHRuqc3QV5CiIxcajEhONHW8kl9je+MLa2qdGdv+6gHq3OxxKOMHHW4TQihEfc JqoRPnsV1S901/ozIsC8D2mVH70IHQjOJAcCBgvjUZHj3qkq6RsEuoRxkmvxdNgxX+Rt nncCKtIWakfT3Yv84qFuACDjAiaFiZyGc3c8n2wNbDORe4i3RPNRDWOcN1VQq+8UCfko r8Jl/Jli/YMzNYvUlgUxWn0NHhAaOv794EpbMlIqzypsByjE8N2RMXJMXWGVGiyF7a8p +0SYTuvHiXS8IUMLRzhd4CF528Wx2dLD4ZsOeoxbbgBa/cgDp1PxbhzaVwetI8mRqcn/ dUqQ== X-Gm-Message-State: ALoCoQmM+yoy5/8zdcRVXeBLGfiN7ECTIskyT9YNair/7R/gpXGsh+D613Rfwysdw+K0vnkQcAPX X-Received: by 10.50.43.169 with SMTP id x9mr2279059igl.28.1423643717202; Wed, 11 Feb 2015 00:35:17 -0800 (PST) Received: from gnx2579.solutionip.com ([113.28.134.59]) by mx.google.com with ESMTPSA id m38sm62189ioi.39.2015.02.11.00.35.12 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 11 Feb 2015 00:35:16 -0800 (PST) From: Eric Auger To: eric.auger@st.com, eric.auger@linaro.org, christoffer.dall@linaro.org, marc.zyngier@arm.com, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, alex.williamson@redhat.com, feng.wu@intel.com Subject: [RFC v4 06/13] VFIO: platform: add vfio_external_{mask|is_active|set_automasked} Date: Wed, 11 Feb 2015 09:32:16 +0100 Message-Id: <1423643543-24409-7-git-send-email-eric.auger@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1423643543-24409-1-git-send-email-eric.auger@linaro.org> References: <1423643543-24409-1-git-send-email-eric.auger@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150211_003539_587735_254CFE60 X-CRM114-Status: GOOD ( 11.84 ) X-Spam-Score: -0.7 (/) Cc: b.reynal@virtualopensystems.com, patches@linaro.org, gleb@kernel.org, andre.przywara@arm.com, a.rigo@virtualopensystems.com, pbonzini@redhat.com, a.motakis@virtualopensystems.com X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable 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 Introduces 3 new external functions aimed at doining some actions on VFIO platform devices: - mask a VFIO IRQ - get the active status of a VFIO IRQ (active at interrupt controller level or masked by the level-sensitive automasking). - change the automasked property and the VFIO handler Note there is no way to discriminate between user-space masking and automasked handler masking. As a consequence, is_active will return true in case the IRQ was masked by the user-space. Signed-off-by: Eric Auger --- V4: creation --- drivers/vfio/platform/vfio_platform_irq.c | 43 +++++++++++++++++++++++++++++++ include/linux/vfio.h | 14 ++++++++++ 2 files changed, 57 insertions(+) diff --git a/drivers/vfio/platform/vfio_platform_irq.c b/drivers/vfio/platform/vfio_platform_irq.c index 8eb65c1..49994cb 100644 --- a/drivers/vfio/platform/vfio_platform_irq.c +++ b/drivers/vfio/platform/vfio_platform_irq.c @@ -231,6 +231,49 @@ static int vfio_set_trigger(struct vfio_platform_device *vdev, int index, return 0; } +void vfio_external_mask(struct vfio_platform_device *vdev, int index) +{ + vfio_platform_mask(&vdev->irqs[index]); +} +EXPORT_SYMBOL_GPL(vfio_external_mask); + +bool vfio_external_is_active(struct vfio_platform_device *vdev, int index) +{ + unsigned long flags; + struct vfio_platform_irq *irq = &vdev->irqs[index]; + bool active, masked, outstanding; + int ret; + + spin_lock_irqsave(&irq->lock, flags); + + ret = irq_get_irqchip_state(irq->hwirq, IRQCHIP_STATE_ACTIVE, &active); + BUG_ON(ret); + masked = irq->masked; + outstanding = active || masked; + + spin_unlock_irqrestore(&irq->lock, flags); + return outstanding; +} +EXPORT_SYMBOL_GPL(vfio_external_is_active); + +void vfio_external_set_automasked(struct vfio_platform_device *vdev, + int index, bool automasked) +{ + unsigned long flags; + struct vfio_platform_irq *irq = &vdev->irqs[index]; + + spin_lock_irqsave(&irq->lock, flags); + if (automasked) { + irq->flags |= VFIO_IRQ_INFO_AUTOMASKED; + irq->handler = vfio_automasked_irq_handler; + } else { + irq->flags &= ~VFIO_IRQ_INFO_AUTOMASKED; + irq->handler = vfio_irq_handler; + } + spin_unlock_irqrestore(&irq->lock, flags); +} +EXPORT_SYMBOL_GPL(vfio_external_set_automasked); + static int vfio_platform_set_irq_trigger(struct vfio_platform_device *vdev, unsigned index, unsigned start, unsigned count, uint32_t flags, diff --git a/include/linux/vfio.h b/include/linux/vfio.h index 77c334b..e04ca93 100644 --- a/include/linux/vfio.h +++ b/include/linux/vfio.h @@ -103,6 +103,20 @@ extern struct vfio_device *vfio_device_get_external_user(struct file *filep); extern void vfio_device_put_external_user(struct vfio_device *vdev); extern struct device *vfio_external_base_device(struct vfio_device *vdev); +struct vfio_platform_device; +extern void vfio_external_mask(struct vfio_platform_device *vdev, int index); +/* + * returns whether the VFIO IRQ is active: + * true if not yet deactivated at interrupt controller level or if + * automasked (level sensitive IRQ). Unfortunately there is no way to + * discriminate between handler auto-masking and user-space masking + */ +extern bool vfio_external_is_active(struct vfio_platform_device *vdev, + int index); + +extern void vfio_external_set_automasked(struct vfio_platform_device *vdev, + int index, bool automasked); + struct pci_dev; #ifdef CONFIG_EEH extern void vfio_spapr_pci_eeh_open(struct pci_dev *pdev);