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: Auger Eric X-Patchwork-Id: 44562 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f200.google.com (mail-lb0-f200.google.com [209.85.217.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id DD06F21527 for ; Wed, 11 Feb 2015 08:35:21 +0000 (UTC) Received: by mail-lb0-f200.google.com with SMTP id u10sf1217948lbd.3 for ; Wed, 11 Feb 2015 00:35:20 -0800 (PST) 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=X2x9/8md+TgHX+Lu0ecvMnBTZIASM70oZWaDig2hSZk=; b=hFt7HF4bzKvxSrX6jXWlsFN7FXL0uhuQXL4QU4NbnHYWlcbtpM+PETnunK1wdgorll 13cQ2hAar8vlrcYiTSrFufuwsB5OmJqDl8dICv+XZEKOfjxzQop5RnbNBIIcmKe9vMfk 257inbYwnaPLymBaIiQqdIY6jxSe9NukxIwEcMDZkF9c4Culxh+1JoxWAFcGtX6Vvu/R LIY9WrAWRiOMtiABeKsuDaaAW+SHdngPD05sD2SHd5YxKk3oNlTWqEvzwh7/drMGQuZE E9T+8bZOCxkJibxlXpV8+XymGkHkhkouw3eUau5226xznRYIPvg2WHoBxsgiRhHZ+uqK Sxag== X-Gm-Message-State: ALoCoQlUgfNu945UMvAm02cGoqmNRij+9xZVyzyequ8pz6B3sV0+dGOX7peYZe+og8WQkwqBuTRV X-Received: by 10.152.87.15 with SMTP id t15mr3288034laz.9.1423643720887; Wed, 11 Feb 2015 00:35:20 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.29.7 with SMTP id f7ls30248lah.84.gmail; Wed, 11 Feb 2015 00:35:19 -0800 (PST) X-Received: by 10.152.88.107 with SMTP id bf11mr21495922lab.103.1423643719587; Wed, 11 Feb 2015 00:35:19 -0800 (PST) Received: from mail-la0-f52.google.com (mail-la0-f52.google.com. [209.85.215.52]) by mx.google.com with ESMTPS id l9si123275lah.3.2015.02.11.00.35.19 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 Feb 2015 00:35:19 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.52 as permitted sender) client-ip=209.85.215.52; Received: by labgq15 with SMTP id gq15so1891263lab.3 for ; Wed, 11 Feb 2015 00:35:19 -0800 (PST) X-Received: by 10.152.8.104 with SMTP id q8mr27460014laa.56.1423643719504; Wed, 11 Feb 2015 00:35:19 -0800 (PST) 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.35.133 with SMTP id h5csp1110209lbj; Wed, 11 Feb 2015 00:35:18 -0800 (PST) X-Received: by 10.50.32.33 with SMTP id f1mr2290804igi.9.1423643717956; Wed, 11 Feb 2015 00:35:17 -0800 (PST) Received: from mail-ie0-f174.google.com (mail-ie0-f174.google.com. [209.85.223.174]) by mx.google.com with ESMTPS id h78si123559iod.10.2015.02.11.00.35.17 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 Feb 2015 00:35:17 -0800 (PST) Received-SPF: pass (google.com: domain of eric.auger@linaro.org designates 209.85.223.174 as permitted sender) client-ip=209.85.223.174; Received: by iebtr6 with SMTP id tr6so2386866ieb.2 for ; Wed, 11 Feb 2015 00:35:17 -0800 (PST) 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 Cc: andre.przywara@arm.com, patches@linaro.org, a.motakis@virtualopensystems.com, a.rigo@virtualopensystems.com, b.reynal@virtualopensystems.com, gleb@kernel.org, pbonzini@redhat.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-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.215.52 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: , 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);