From patchwork Fri Jun 5 15:06:30 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Auger X-Patchwork-Id: 6555971 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 92B3FC0020 for ; Fri, 5 Jun 2015 15:15:46 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C8C7E206D9 for ; Fri, 5 Jun 2015 15:15:44 +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 8E26820643 for ; Fri, 5 Jun 2015 15:15:39 +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 1Z0tEh-0006Se-05; Fri, 05 Jun 2015 15:08:43 +0000 Received: from mail-wi0-f172.google.com ([209.85.212.172]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Z0tDO-0005XV-1v for linux-arm-kernel@lists.infradead.org; Fri, 05 Jun 2015 15:07:23 +0000 Received: by wibdq8 with SMTP id dq8so22160968wib.1 for ; Fri, 05 Jun 2015 08:06:52 -0700 (PDT) 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=eZfEE9IkdYQHY7WMLYVekS5H5w3U5gmAbeCqoS3mZ2g=; b=RxSdSp/2qp2clj4SnmMJBTGW223oqOkOgEZZgDNcQKUP4K7bNEtvHgy/JGE35T+A9O Z/joYjhCKCaKUyQWwatAVMXR6eXabQcZk1auhtwMBmfGhZOZ+rkiHL1rX+lYtFZOUrwW +Whk70M+6PIQjqsSzCT0CpifTRUJfFKR6LZA+5z/HpIvOMiDF9PFRrPvMI0l1pLRMqMX JVwCAAb/NwXY3KS3NHL/PLhHpOTFCEwsRJERklCqk0rr7IGCLs+668KmK7TGOD2bzlPG bSB/t7Y/A6a9a/93O69pkzhUtLOW9F74GOW68Gt23QcqSx8Y7XcvJKA3Yg13pLhhLnmc g0qA== X-Gm-Message-State: ALoCoQk5m2tg7dcur/sIJsBrRZEgLwRksy0K0MfJjZhg2xwWPTZtRVGL2i6w0Wy8hL/iWAjlh957 X-Received: by 10.180.215.8 with SMTP id oe8mr2703369wic.0.1433516812193; Fri, 05 Jun 2015 08:06:52 -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 dz4sm3827133wib.17.2015.06.05.08.06.50 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 05 Jun 2015 08:06:50 -0700 (PDT) From: Eric Auger To: eric.auger@st.com, eric.auger@linaro.org, linux-arm-kernel@lists.infradead.org, alex.williamson@redhat.com, b.reynal@virtualopensystems.com Subject: [PATCH v2 2/4] VFIO: platform: add reset callback Date: Fri, 5 Jun 2015 17:06:30 +0200 Message-Id: <1433516792-16397-3-git-send-email-eric.auger@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1433516792-16397-1-git-send-email-eric.auger@linaro.org> References: <1433516792-16397-1-git-send-email-eric.auger@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150605_080722_290941_442EB0FD X-CRM114-Status: GOOD ( 13.92 ) X-Spam-Score: -0.7 (/) Cc: agraf@suse.de, linux-kernel@vger.kernel.org, christoffer.dall@linaro.org, patches@linaro.org 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 A new reset callback is introduced. If this callback is populated, the reset is invoked on device first open/last close or upon userspace ioctl. The modality is exposed on VFIO_DEVICE_GET_INFO. Signed-off-by: Eric Auger --- v1 -> v2: - reset now is also called on first open on top of last close - remove IS_ERR_OR_NULL --- drivers/vfio/platform/vfio_platform_common.c | 15 +++++++++++++-- drivers/vfio/platform/vfio_platform_private.h | 1 + 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/drivers/vfio/platform/vfio_platform_common.c b/drivers/vfio/platform/vfio_platform_common.c index d970776..995929b 100644 --- a/drivers/vfio/platform/vfio_platform_common.c +++ b/drivers/vfio/platform/vfio_platform_common.c @@ -106,6 +106,8 @@ static void vfio_platform_release(void *device_data) mutex_lock(&driver_lock); if (!(--vdev->refcnt)) { + if (vdev->reset) + vdev->reset(vdev); vfio_platform_regions_cleanup(vdev); vfio_platform_irq_cleanup(vdev); } @@ -133,6 +135,9 @@ static int vfio_platform_open(void *device_data) ret = vfio_platform_irq_init(vdev); if (ret) goto err_irq; + + if (vdev->reset) + vdev->reset(vdev); } vdev->refcnt++; @@ -165,6 +170,8 @@ static long vfio_platform_ioctl(void *device_data, if (info.argsz < minsz) return -EINVAL; + if (vdev->reset) + vdev->flags |= VFIO_DEVICE_FLAGS_RESET; info.flags = vdev->flags; info.num_regions = vdev->num_regions; info.num_irqs = vdev->num_irqs; @@ -258,8 +265,12 @@ static long vfio_platform_ioctl(void *device_data, return ret; - } else if (cmd == VFIO_DEVICE_RESET) - return -EINVAL; + } else if (cmd == VFIO_DEVICE_RESET) { + if (vdev->reset) + return vdev->reset(vdev); + else + return -EINVAL; + } return -ENOTTY; } diff --git a/drivers/vfio/platform/vfio_platform_private.h b/drivers/vfio/platform/vfio_platform_private.h index d864124..cccb3ba 100644 --- a/drivers/vfio/platform/vfio_platform_private.h +++ b/drivers/vfio/platform/vfio_platform_private.h @@ -72,6 +72,7 @@ struct vfio_platform_device { struct resource* (*get_resource)(struct vfio_platform_device *vdev, int i); int (*get_irq)(struct vfio_platform_device *vdev, int i); + int (*reset)(struct vfio_platform_device *vdev); }; struct vfio_platform_reset_combo {