Received: by 10.192.165.156 with SMTP id m28csp1786815imm; Thu, 12 Apr 2018 03:34:43 -0700 (PDT) X-Google-Smtp-Source: AIpwx497FP/QZQ9L6HKI76vT1zgQigNMklhVFsIBbwVhgGktuaP3Sa/X2cZ1nTzLalijWHTc7bvp X-Received: by 10.99.96.129 with SMTP id u123mr285874pgb.348.1523529283452; Thu, 12 Apr 2018 03:34:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523529283; cv=none; d=google.com; s=arc-20160816; b=I7sgx9PpL4241xPiFRpgInf0D4SqOKRz5G+5J4suh6jN+NH0IuIuR8LqM4W2xWGO1S fLbmnSvEvtRzBacXAuu7LxMiYGGNBcHU48Ov40jsxWdAudxMMjYPx1DMy7CqyHSiAePk 7xXDIVwfMxOlSGCwMLs511HE23fKaTzkJb3cqELkRdKwsZbdKL5lUUDDgKZRGGp26r4I Lv9lZTc+lD5kIIer3lltFeEyB5EKRRiRRDI13C7JEXIdar7xznFzI1O6bhZ+d2sHLwj/ 560ycWlKvwryZCZ2qd/9s9UaIIjJztDyY1xGUjWIkLI2JjrAYmzJqooRf+VrhR6/mfAV DJjw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:in-reply-to :mime-version:user-agent:date:message-id:from:cc:references:to :subject:arc-authentication-results; bh=CKgOZn/R33Svv8E11kfKWxm1rwyIubgc8fa4P+npG58=; b=djdH0cjwvyuWZtN0NIQmLo6smiS/PqQ3gqnVmIAzFmIuZ7WvXlCm+LSUKWlcKMMW0o rlRza5lk2xqJwBMbJwhROrFQBINu0rl7xHSaKXe5bcmtxpX0hCNBlqWcV+pYQwujmbso lYfcpIGTcu9jirwuTAsXOUUQRnj1q2pspWHVnwNdaI3BOpAHrT1Zj2fMsHNi8UeACPlg J3325vLRp9LzESLUK/B9FqZ3YhUfUgAVfpnAFpCAcidIkenyrRpUr3ol7sQGU3n2ssy7 O2yDYTXCvsywErgdLR4JWqAVpowzUnK/saRHxKA89nRQcMeZwh0jRQLOHg/1P+eASG5e N+pA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z79si2425111pfa.120.2018.04.12.03.33.57; Thu, 12 Apr 2018 03:34:43 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752558AbeDLKbQ (ORCPT + 99 others); Thu, 12 Apr 2018 06:31:16 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:49630 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751870AbeDLKbO (ORCPT ); Thu, 12 Apr 2018 06:31:14 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DA23A7C6B0; Thu, 12 Apr 2018 10:31:13 +0000 (UTC) Received: from localhost.localdomain (ovpn-116-192.ams2.redhat.com [10.36.116.192]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 44B5C215CDC6; Thu, 12 Apr 2018 10:31:11 +0000 (UTC) Subject: Re: [PATCH v3 2/2] vfio: platform: Add generic DT reset support To: Geert Uytterhoeven , Baptiste Reynal , Alex Williamson References: <1523438149-16433-1-git-send-email-geert+renesas@glider.be> <1523438149-16433-4-git-send-email-geert+renesas@glider.be> Cc: Philipp Zabel , Rob Herring , Mark Rutland , kvm@vger.kernel.org, devicetree@vger.kernel.org, linux-renesas-soc@vger.kernel.org, linux-kernel@vger.kernel.org From: Auger Eric Message-ID: Date: Thu, 12 Apr 2018 12:31:09 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 In-Reply-To: <1523438149-16433-4-git-send-email-geert+renesas@glider.be> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Thu, 12 Apr 2018 10:31:13 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Thu, 12 Apr 2018 10:31:13 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'eric.auger@redhat.com' RCPT:'' Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Geert, Philipp, On 11/04/18 11:15, Geert Uytterhoeven wrote: > Vfio-platform requires reset support, provided either by ACPI, or, on DT > platforms, by a device-specific reset driver matching against the > device's compatible value. > > On many SoCs, devices are connected to an SoC-internal reset controller. > If the reset hierarchy is described in DT using "resets" properties, > such devices can be reset in a generic way through the reset controller > subsystem. Hence add support for this, avoiding the need to write > device-specific reset drivers for each single device on affected SoCs. > > Devices that do require a more complex reset procedure can still provide > a device-specific reset driver, as that takes precedence. > > Note that this functionality depends on CONFIG_RESET_CONTROLLER=y, and > becomes a no-op (as in: "No reset function found for device") if reset > controller support is disabled. > > Signed-off-by: Geert Uytterhoeven > Reviewed-by: Philipp Zabel > --- > v3: > - Add Reviewed-by, > - Merge similar checks in vfio_platform_has_reset(), > > v2: > - Don't store error values in vdev->reset_control, > - Use of_reset_control_get_exclusive() instead of > __of_reset_control_get(), > - Improve description. > --- > drivers/vfio/platform/vfio_platform_common.c | 20 ++++++++++++++++++-- > drivers/vfio/platform/vfio_platform_private.h | 1 + > 2 files changed, 19 insertions(+), 2 deletions(-) > > diff --git a/drivers/vfio/platform/vfio_platform_common.c b/drivers/vfio/platform/vfio_platform_common.c > index b60bb5326668498c..ef9b9e3220ebe939 100644 > --- a/drivers/vfio/platform/vfio_platform_common.c > +++ b/drivers/vfio/platform/vfio_platform_common.c > @@ -17,6 +17,7 @@ > #include > #include > #include > +#include > #include > #include > #include > @@ -112,11 +113,13 @@ static bool vfio_platform_has_reset(struct vfio_platform_device *vdev) > if (VFIO_PLATFORM_IS_ACPI(vdev)) > return vfio_platform_acpi_has_reset(vdev); > > - return vdev->of_reset ? true : false; > + return vdev->of_reset || vdev->reset_control; > } > > static int vfio_platform_get_reset(struct vfio_platform_device *vdev) > { > + struct reset_control *rstc; > + > if (VFIO_PLATFORM_IS_ACPI(vdev)) > return vfio_platform_acpi_has_reset(vdev) ? 0 : -ENOENT; > > @@ -127,8 +130,16 @@ static int vfio_platform_get_reset(struct vfio_platform_device *vdev) > vdev->of_reset = vfio_platform_lookup_reset(vdev->compat, > &vdev->reset_module); > } > + if (vdev->of_reset) > + return 0; > + > + rstc = of_reset_control_get_exclusive(vdev->device->of_node, NULL); Shouldn't we prefer the top level reset_control_get_exclusive()? To make sure about the exclusive/shared terminology, does get_reset_control_get_exclusive() check we have an exclusive wire between this device and the reset controller? Thanks Eric > + if (!IS_ERR(rstc)) { > + vdev->reset_control = rstc; > + return 0; > + } > > - return vdev->of_reset ? 0 : -ENOENT; > + return PTR_ERR(rstc); > } > > static void vfio_platform_put_reset(struct vfio_platform_device *vdev) > @@ -138,6 +149,8 @@ static void vfio_platform_put_reset(struct vfio_platform_device *vdev) > > if (vdev->of_reset) > module_put(vdev->reset_module); > + > + reset_control_put(vdev->reset_control); > } > > static int vfio_platform_regions_init(struct vfio_platform_device *vdev) > @@ -217,6 +230,9 @@ static int vfio_platform_call_reset(struct vfio_platform_device *vdev, > } else if (vdev->of_reset) { > dev_info(vdev->device, "reset\n"); > return vdev->of_reset(vdev); > + } else if (vdev->reset_control) { > + dev_info(vdev->device, "reset\n"); > + return reset_control_reset(vdev->reset_control); > } > > dev_warn(vdev->device, "no reset function found!\n"); > diff --git a/drivers/vfio/platform/vfio_platform_private.h b/drivers/vfio/platform/vfio_platform_private.h > index 85ffe5d9d1abd94e..a56e80ae5986540b 100644 > --- a/drivers/vfio/platform/vfio_platform_private.h > +++ b/drivers/vfio/platform/vfio_platform_private.h > @@ -60,6 +60,7 @@ struct vfio_platform_device { > const char *compat; > const char *acpihid; > struct module *reset_module; > + struct reset_control *reset_control; > struct device *device; > > /* >