From patchwork Fri Jan 30 13:46:17 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baptiste Reynal X-Patchwork-Id: 5750401 Return-Path: X-Original-To: patchwork-kvm@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 A1DBD9F358 for ; Fri, 30 Jan 2015 13:52:23 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A79D820279 for ; Fri, 30 Jan 2015 13:52:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7BAA52025B for ; Fri, 30 Jan 2015 13:52:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1762460AbbA3NtG (ORCPT ); Fri, 30 Jan 2015 08:49:06 -0500 Received: from mail-we0-f177.google.com ([74.125.82.177]:37366 "EHLO mail-we0-f177.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1762449AbbA3NtD (ORCPT ); Fri, 30 Jan 2015 08:49:03 -0500 Received: by mail-we0-f177.google.com with SMTP id l61so27185527wev.8 for ; Fri, 30 Jan 2015 05:49:01 -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=wi35M0C3aMUNWOnLBSwNGtQYBOISueGp1uH92g8+O2E=; b=jLzmCy6xElhfvk8C9Jh+8X1xLSxNy7pBTMhvzll/N8I4cKafkM7txzL9Hqm+rbz+/s BaAUy1+cHq3rqGBQSDAzQQORRVz6Baz/kVYNlmMTeLudtUqGcFDMEgq8EjCC1ezZmIXd cpf32JU7QYSGEsPd8VFMY8M4dXHU4rWDMhzntrzE2GwlC+mR5zguPwZSHTQcrNgrBnHw EOdEJUWEBSo11oNVh9R0HzogWequavPJpg+xNz+gUaA9SamcgVGc9UQNuUMAc0bjRBsQ G+UgmnK1qRz/AV7sQ1LW/aNEyzlxswCvETK76hndUFggyPW57KhbEMi+Oi8X+g0JVbe/ T8bg== X-Gm-Message-State: ALoCoQnKsWXd4U3+mHKzGbNZz+oY5uaDad1/NdgSXM2yQLI+niIM0wbBZ+fBNE81vS1WNTwrFBRK X-Received: by 10.180.106.5 with SMTP id gq5mr5193813wib.34.1422625741492; Fri, 30 Jan 2015 05:49:01 -0800 (PST) Received: from localhost (LPuteaux-656-1-278-113.w80-15.abo.wanadoo.fr. [80.15.154.113]) by mx.google.com with ESMTPSA id p6sm7029621wia.14.2015.01.30.05.49.00 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 30 Jan 2015 05:49:00 -0800 (PST) From: Baptiste Reynal To: kvmarm@lists.cs.columbia.edu, iommu@lists.linux-foundation.org, alex.williamson@redhat.com Cc: will.deacon@arm.com, tech@virtualopensystems.com, christoffer.dall@linaro.org, eric.auger@linaro.org, kim.phillips@freescale.com, marc.zyngier@arm.com, Antonios Motakis , Baptiste Reynal , kvm@vger.kernel.org (open list:VFIO DRIVER), linux-kernel@vger.kernel.org (open list) Subject: [PATCH v13 11/18] vfio/platform: support for level sensitive interrupts Date: Fri, 30 Jan 2015 14:46:17 +0100 Message-Id: <1422625584-3741-12-git-send-email-b.reynal@virtualopensystems.com> X-Mailer: git-send-email 2.2.2 In-Reply-To: <1422625584-3741-1-git-send-email-b.reynal@virtualopensystems.com> References: <1422625584-3741-1-git-send-email-b.reynal@virtualopensystems.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, 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 From: Antonios Motakis Level sensitive interrupts are exposed as maskable and automasked interrupts and are masked and disabled automatically when they fire. Signed-off-by: Antonios Motakis [Baptiste Reynal: Move masked interrupt initialization from "vfio/platform: trigger an interrupt via eventfd"] Signed-off-by: Baptiste Reynal --- drivers/vfio/platform/vfio_platform_irq.c | 103 +++++++++++++++++++++++++- drivers/vfio/platform/vfio_platform_private.h | 2 + 2 files changed, 102 insertions(+), 3 deletions(-) diff --git a/drivers/vfio/platform/vfio_platform_irq.c b/drivers/vfio/platform/vfio_platform_irq.c index 611ec80..e0e6388 100644 --- a/drivers/vfio/platform/vfio_platform_irq.c +++ b/drivers/vfio/platform/vfio_platform_irq.c @@ -23,12 +23,59 @@ #include "vfio_platform_private.h" +static void vfio_platform_mask(struct vfio_platform_irq *irq_ctx) +{ + unsigned long flags; + + spin_lock_irqsave(&irq_ctx->lock, flags); + + if (!irq_ctx->masked) { + disable_irq_nosync(irq_ctx->hwirq); + irq_ctx->masked = true; + } + + spin_unlock_irqrestore(&irq_ctx->lock, flags); +} + static int vfio_platform_set_irq_mask(struct vfio_platform_device *vdev, unsigned index, unsigned start, unsigned count, uint32_t flags, void *data) { - return -EINVAL; + if (start != 0 || count != 1) + return -EINVAL; + + if (!(vdev->irqs[index].flags & VFIO_IRQ_INFO_MASKABLE)) + return -EINVAL; + + if (flags & VFIO_IRQ_SET_DATA_EVENTFD) + return -EINVAL; /* not implemented yet */ + + if (flags & VFIO_IRQ_SET_DATA_NONE) { + vfio_platform_mask(&vdev->irqs[index]); + + } else if (flags & VFIO_IRQ_SET_DATA_BOOL) { + uint8_t mask = *(uint8_t *)data; + + if (mask) + vfio_platform_mask(&vdev->irqs[index]); + } + + return 0; +} + +static void vfio_platform_unmask(struct vfio_platform_irq *irq_ctx) +{ + unsigned long flags; + + spin_lock_irqsave(&irq_ctx->lock, flags); + + if (irq_ctx->masked) { + enable_irq(irq_ctx->hwirq); + irq_ctx->masked = false; + } + + spin_unlock_irqrestore(&irq_ctx->lock, flags); } static int vfio_platform_set_irq_unmask(struct vfio_platform_device *vdev, @@ -36,7 +83,50 @@ static int vfio_platform_set_irq_unmask(struct vfio_platform_device *vdev, unsigned count, uint32_t flags, void *data) { - return -EINVAL; + if (start != 0 || count != 1) + return -EINVAL; + + if (!(vdev->irqs[index].flags & VFIO_IRQ_INFO_MASKABLE)) + return -EINVAL; + + if (flags & VFIO_IRQ_SET_DATA_EVENTFD) + return -EINVAL; /* not implemented yet */ + + if (flags & VFIO_IRQ_SET_DATA_NONE) { + vfio_platform_unmask(&vdev->irqs[index]); + + } else if (flags & VFIO_IRQ_SET_DATA_BOOL) { + uint8_t unmask = *(uint8_t *)data; + + if (unmask) + vfio_platform_unmask(&vdev->irqs[index]); + } + + return 0; +} + +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; + + /* automask maskable interrupts */ + disable_irq_nosync(irq_ctx->hwirq); + irq_ctx->masked = true; + } + + spin_unlock_irqrestore(&irq_ctx->lock, flags); + + if (ret == IRQ_HANDLED) + eventfd_signal(irq_ctx->trigger, 1); + + return ret; } static irqreturn_t vfio_irq_handler(int irq, void *dev_id) @@ -78,6 +168,7 @@ static int vfio_set_trigger(struct vfio_platform_device *vdev, int index, irq->trigger = trigger; + irq_set_status_flags(irq->hwirq, IRQ_NOAUTOEN); ret = request_irq(irq->hwirq, handler, 0, irq->name, irq); if (ret) { kfree(irq->name); @@ -86,6 +177,9 @@ static int vfio_set_trigger(struct vfio_platform_device *vdev, int index, return ret; } + if (!irq->masked) + enable_irq(irq->hwirq); + return 0; } @@ -98,7 +192,7 @@ static int vfio_platform_set_irq_trigger(struct vfio_platform_device *vdev, irq_handler_t handler; if (vdev->irqs[index].flags & VFIO_IRQ_INFO_AUTOMASKED) - return -EINVAL; /* not implemented */ + handler = vfio_automasked_irq_handler; else handler = vfio_irq_handler; @@ -170,6 +264,8 @@ int vfio_platform_irq_init(struct vfio_platform_device *vdev) if (hwirq < 0) goto err; + spin_lock_init(&vdev->irqs[i].lock); + vdev->irqs[i].flags = VFIO_IRQ_INFO_EVENTFD; if (irq_get_trigger_type(hwirq) & IRQ_TYPE_LEVEL_MASK) @@ -178,6 +274,7 @@ int vfio_platform_irq_init(struct vfio_platform_device *vdev) vdev->irqs[i].count = 1; vdev->irqs[i].hwirq = hwirq; + vdev->irqs[i].masked = false; } vdev->num_irqs = cnt; diff --git a/drivers/vfio/platform/vfio_platform_private.h b/drivers/vfio/platform/vfio_platform_private.h index aa01cc3..ff2db1d 100644 --- a/drivers/vfio/platform/vfio_platform_private.h +++ b/drivers/vfio/platform/vfio_platform_private.h @@ -33,6 +33,8 @@ struct vfio_platform_irq { int hwirq; char *name; struct eventfd_ctx *trigger; + bool masked; + spinlock_t lock; }; struct vfio_platform_region {