From patchwork Thu Mar 19 14:55:44 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Auger Eric X-Patchwork-Id: 46042 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f71.google.com (mail-la0-f71.google.com [209.85.215.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 8487121515 for ; Thu, 19 Mar 2015 14:58:40 +0000 (UTC) Received: by lams18 with SMTP id s18sf13067470lam.2 for ; Thu, 19 Mar 2015 07:58:39 -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=9/Ith8Ov1g8uCVweJklIXnfQelCPaquyK7jbcx+74Z8=; b=BrnDySnF3aan1pdhw2uzN58SR3xF1JaGPJITl/qsfmUYdLRb12W/qg00xhUomMvYCp bAN7OcBsQHpxq4XG4uu4nj0ajseusaHIKuuzmrF/b9y5xFwiBIUdMiRCNgrJPD3NB9Ha Y4b4CMIANLZbecD3bpwptC5acoVKLcAw1qm/MSJvd4OpM3LCbgrLGBVkBCXcx0uvptjj nmRnq+VdB5zUQBZ0FcFRaG8pXQ7WoM+Ac+5S1MCOoIW9NVzUqxr7kx97QARgl85FMEN4 p7wD/iug+8nEsEkBFT4IGpiiKjE2m8ihmA5U0KkDe946zuxhn4nQRyWDyTDgAE8l4b2H RxpQ== X-Gm-Message-State: ALoCoQnjct0grOZHHPcW74eNRQ0qm3ljHKiMdZveaNTfCZhWW4lHdbAA0K59EN2ASpt00GRS1vrJ X-Received: by 10.181.29.66 with SMTP id ju2mr1832507wid.1.1426777119464; Thu, 19 Mar 2015 07:58:39 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.153.7.75 with SMTP id da11ls289099lad.95.gmail; Thu, 19 Mar 2015 07:58:39 -0700 (PDT) X-Received: by 10.152.1.70 with SMTP id 6mr46088496lak.83.1426777119301; Thu, 19 Mar 2015 07:58:39 -0700 (PDT) Received: from mail-lb0-f177.google.com (mail-lb0-f177.google.com. [209.85.217.177]) by mx.google.com with ESMTPS id kt2si1127549lac.152.2015.03.19.07.58.39 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 19 Mar 2015 07:58:39 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.177 as permitted sender) client-ip=209.85.217.177; Received: by lbcgn8 with SMTP id gn8so54664991lbc.2 for ; Thu, 19 Mar 2015 07:58:39 -0700 (PDT) X-Received: by 10.112.201.231 with SMTP id kd7mr49115510lbc.35.1426777119157; Thu, 19 Mar 2015 07:58:39 -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.35.133 with SMTP id h5csp441441lbj; Thu, 19 Mar 2015 07:58:38 -0700 (PDT) X-Received: by 10.181.9.98 with SMTP id dr2mr16962679wid.62.1426777115978; Thu, 19 Mar 2015 07:58:35 -0700 (PDT) Received: from mail-wg0-f53.google.com (mail-wg0-f53.google.com. [74.125.82.53]) by mx.google.com with ESMTPS id e1si2784054wja.52.2015.03.19.07.58.35 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 19 Mar 2015 07:58:35 -0700 (PDT) Received-SPF: pass (google.com: domain of eric.auger@linaro.org designates 74.125.82.53 as permitted sender) client-ip=74.125.82.53; Received: by wggv3 with SMTP id v3so64837713wgg.1 for ; Thu, 19 Mar 2015 07:58:35 -0700 (PDT) X-Received: by 10.194.19.10 with SMTP id a10mr156034832wje.153.1426777115654; Thu, 19 Mar 2015 07:58:35 -0700 (PDT) Received: from gnx2579.gnb.st.com (weg38-3-78-232-41-119.fbx.proxad.net. [78.232.41.119]) by mx.google.com with ESMTPSA id a6sm1695350wiy.17.2015.03.19.07.58.33 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 19 Mar 2015 07:58:35 -0700 (PDT) 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, kvm@vger.kernel.org, alex.williamson@redhat.com Cc: linux-kernel@vger.kernel.org, patches@linaro.org, pbonzini@redhat.com, kim.phillips@freescale.com, b.reynal@virtualopensystems.com, feng.wu@intel.com Subject: [RFC v5 06/13] VFIO: platform: add vfio_external_{mask|is_active|set_automasked} Date: Thu, 19 Mar 2015 15:55:44 +0100 Message-Id: <1426776951-24901-7-git-send-email-eric.auger@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1426776951-24901-1-git-send-email-eric.auger@linaro.org> References: <1426776951-24901-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.177 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 b18c38f..7aa6330 100644 --- a/include/linux/vfio.h +++ b/include/linux/vfio.h @@ -105,6 +105,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);