From patchwork Mon Jun 15 09:09:43 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Auger X-Patchwork-Id: 6607361 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 8FFF6C0020 for ; Mon, 15 Jun 2015 09:13:21 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C134B20443 for ; Mon, 15 Jun 2015 09:13:20 +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 E772120416 for ; Mon, 15 Jun 2015 09:13:19 +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 1Z4QPu-0002pw-Sa; Mon, 15 Jun 2015 09:10:54 +0000 Received: from mail-wg0-f48.google.com ([74.125.82.48]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Z4QPY-0002gn-CO for linux-arm-kernel@lists.infradead.org; Mon, 15 Jun 2015 09:10:37 +0000 Received: by wgzl5 with SMTP id l5so38443131wgz.3 for ; Mon, 15 Jun 2015 02:10:10 -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=yrxQVTGB9kM0isrWe0YdgeY3cX/u/Xfy2KMprkjSzVM=; b=OUfXNyZFVTHhdplGroNVIqRYaeBEuVYZYlzatOOI8U8ldSRHaq49ay7GoaH0TykKBM PFapiTP2ayuXbZ7gkGCkR0xPtze+h++R6jVD1tDl8Rh9kQW+DLTtYwvJvLb+Tr/klHUS 3ojbPqTHD/rNeQRZtPyQ3zsDqlwNTeenmvZvLVhTTVMTwjseap0hNknwy+B29Nk69cWZ VVO1aEb5y4ExRWFCEbdt3yTvDpXoQ5Rwgnb9Nu7pFSFI0leEq7tdHTeK4An6hEDAc1pt TP7N/baY4ccuLUteUZt9eS9l8+MfOPqv6lZp3d+1ZyySW55wHmrN63Iw/Dkb3Wm5Gtgw evew== X-Gm-Message-State: ALoCoQmsyTA5kOPXxM+i/6VYbsnQAIYooZ4e1jJEjf5UeRS77G2rk9pCKTp2uz1+wzrxCACMKnl8 X-Received: by 10.195.17.199 with SMTP id gg7mr25960343wjd.121.1434359410453; Mon, 15 Jun 2015 02:10:10 -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 12sm17920944wjw.17.2015.06.15.02.10.08 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 15 Jun 2015 02:10:09 -0700 (PDT) From: Eric Auger To: eric.auger@st.com, eric.auger@linaro.org, linux-arm-kernel@lists.infradead.org, b.reynal@virtualopensystems.com, alex.williamson@redhat.com Subject: [PATCH v4 2/4] VFIO: platform: add reset callback Date: Mon, 15 Jun 2015 11:09:43 +0200 Message-Id: <1434359385-19916-3-git-send-email-eric.auger@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1434359385-19916-1-git-send-email-eric.auger@linaro.org> References: <1434359385-19916-1-git-send-email-eric.auger@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150615_021032_624811_0BCC784C X-CRM114-Status: GOOD ( 14.66 ) X-Spam-Score: -0.7 (/) Cc: 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.7 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, 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 611597e..6393581 100644 --- a/drivers/vfio/platform/vfio_platform_common.c +++ b/drivers/vfio/platform/vfio_platform_common.c @@ -103,6 +103,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); } @@ -130,6 +132,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++; @@ -162,6 +167,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; @@ -255,8 +262,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 9e37b9f..1c9b3d5 100644 --- a/drivers/vfio/platform/vfio_platform_private.h +++ b/drivers/vfio/platform/vfio_platform_private.h @@ -67,6 +67,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 {