Received: by 10.192.165.156 with SMTP id m28csp480774imm; Wed, 11 Apr 2018 02:19:52 -0700 (PDT) X-Google-Smtp-Source: AIpwx49WBsE2kBr0iclY1Ye+eglvafQo0XWVpJnUg0AHa7KdlHykGQQDiKnUcidR+v861V8v7fc7 X-Received: by 10.167.130.22 with SMTP id k22mr3331673pfi.73.1523438391966; Wed, 11 Apr 2018 02:19:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523438391; cv=none; d=google.com; s=arc-20160816; b=nnacPoYXsAbqM/HjUthHyQRtJF1SkIhjhL1U/fEJK/6PrvgdLwh5pffAh/Sx5A90JW fQvOwMN0U9CPVrGEYyuPuzBW/xlBQKd+gn/4UKErgHfh9G5V69lasVwqQTgq3b+fGLg/ tXXIg4uDpyb9Od5rES3kJJTWRPqeqRq0yJsdIR3oesEW8Mz6vBJjS1yNmK96d6Y5MFia n3Rrpwydryx6fK8dS67uhxpvn6xuJfDIYK07pzxJgCJkHWcNE4Yz89xcneN4gcPLQhgh ZCpGqXJcKNYSFU1MELFVDX/0xN0+814rPI5amizVT7bKS+BZ+xsOKOaOF8PcGsc34Xqo FEKQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=neoQFPGIVZd1gR8JakqOPm8ORAiRz7PmSidHjNsTiiY=; b=zD+XTOYjpgsT7Hk7CTP1mMDkxmiCub50XuRBsR7n5ZQD3xrrdMzQ6vrTEzrNn94rSy sT+57Wbtf13D9PRFBfAUssskBQQq1k11LhyIscc8mCigW6KtM5LRJs0smEmScuuIP0yt f46MkCmSvoPDTkZd2BzJFNc8TJ0+EoK2+xY9aHKdUXaYsrI1oW1Wg5q4wwyiDf1ErtXL gus4wVrG5unNkfrH1mBeB1Y7iaw72xrtwomTFWKedqF4sC5ezCSoeoMYdOQTMZtT23Rf vjyBh5z5wQeEW7XvPgrHVwZ3sZi4AQ1QyuKnmmxm2829kSVw8cYxpHCwsWgKbCcm0htX +37Q== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 133si449309pgc.341.2018.04.11.02.19.15; Wed, 11 Apr 2018 02:19:51 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752530AbeDKJP5 (ORCPT + 99 others); Wed, 11 Apr 2018 05:15:57 -0400 Received: from laurent.telenet-ops.be ([195.130.137.89]:44220 "EHLO laurent.telenet-ops.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751889AbeDKJPy (ORCPT ); Wed, 11 Apr 2018 05:15:54 -0400 Received: from ayla.of.borg ([84.194.111.163]) by laurent.telenet-ops.be with bizsmtp id YxFs1x00E3XaVaC01xFsQ8; Wed, 11 Apr 2018 11:15:52 +0200 Received: from ramsan.of.borg ([192.168.97.29] helo=ramsan) by ayla.of.borg with esmtp (Exim 4.86_2) (envelope-from ) id 1f6Br6-0002Cz-9x; Wed, 11 Apr 2018 11:15:52 +0200 Received: from geert by ramsan with local (Exim 4.86_2) (envelope-from ) id 1f6Br6-0004II-8l; Wed, 11 Apr 2018 11:15:52 +0200 From: Geert Uytterhoeven To: Baptiste Reynal , Alex Williamson 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, Geert Uytterhoeven Subject: [PATCH v3 2/2] vfio: platform: Add generic DT reset support Date: Wed, 11 Apr 2018 11:15:49 +0200 Message-Id: <1523438149-16433-4-git-send-email-geert+renesas@glider.be> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1523438149-16433-1-git-send-email-geert+renesas@glider.be> References: <1523438149-16433-1-git-send-email-geert+renesas@glider.be> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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); + 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; /* -- 2.7.4