Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp1562060pxu; Thu, 17 Dec 2020 13:00:45 -0800 (PST) X-Google-Smtp-Source: ABdhPJycPx80PvT28q++07Cm1lWwdxIS5XQ2BCR15kQQp8sjEgy/3fySdAeAMldL9hqjRzkdoVnh X-Received: by 2002:a50:e84d:: with SMTP id k13mr1271605edn.154.1608238844890; Thu, 17 Dec 2020 13:00:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1608238844; cv=none; d=google.com; s=arc-20160816; b=d4OdNY1wjg7ZBrhPcKr8LQ0NS3KAKeoLRZZjta4Av17sF7803FXPi40dBiN1TY0zB1 6cLSTNCinakDQtU7VixSNAY7rfHR6d4TweZ7v4P0dGhZLUeS14wx2fiwvonVcp36Hrfs w8KTspX24VjCoczhxOfu7iZXtR43vtshKvm9foSCh3Op1+nGbJkQsRICUkf2o8pNALso bkyLWHm0VCoafxTbNlya/QmPCWhNq7b8krh8oWGmdIBNHW0xQvIZS/X2cz617Qy+G2wl 6hwYpPKNxFbMApmTNf5kf+Q5Z5ssJaK5HXUw1FLJ+EEeTbI0M5JG0SfCLyw8Ms/fNq7h 40vw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:references:cc :to:from:subject:dkim-signature; bh=2zaYEPU3Dc5zFOFGXsYjz12iYiWYHN8N3O6lakukl/s=; b=iIe6Lv2Qm5/gGwRQF/pd8OnI0TbCkgFFfjq/84N/ppTSb/dfj5+o/PpVTpjlT9/7kH Ii6INumMQXvBsYK9nbZ5ljuoExBgWxnMFJ7REVSUBWl17LJvWWxIEFjKWy4RD4rBSAYe /65Xl0k6p8CaXJk7zXj80JpPpQnqPvXoyC6QhjSptwLK/STTfOHvt2r/IzS593lLRvHT SJq+5EEWxnAUdYXjZsFhWRmUlpAMwPLPXv0maoK707WB3PSHTAIfea0Uk3Rk3uQX9zq/ WSQ7ABlN9Diudj6YVNHDPmDA1LlZbB+jeX6FjWE49Rw0spVmCvkMCO8eDzSJRdYAssc8 /ctQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=qgHdy+aV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d8si5208974edo.441.2020.12.17.13.00.21; Thu, 17 Dec 2020 13:00:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=qgHdy+aV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731679AbgLQU7N (ORCPT + 99 others); Thu, 17 Dec 2020 15:59:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40088 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729655AbgLQU7M (ORCPT ); Thu, 17 Dec 2020 15:59:12 -0500 Received: from mail-lf1-x129.google.com (mail-lf1-x129.google.com [IPv6:2a00:1450:4864:20::129]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A5B81C061794; Thu, 17 Dec 2020 12:58:31 -0800 (PST) Received: by mail-lf1-x129.google.com with SMTP id m25so61160843lfc.11; Thu, 17 Dec 2020 12:58:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:from:to:cc:references:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=2zaYEPU3Dc5zFOFGXsYjz12iYiWYHN8N3O6lakukl/s=; b=qgHdy+aVZrcGxyULYw4C/dnhEhXcHqnIi3WOZ6PUyWeJ1T2KuwB4MyFcAMVcIxtEkN P0wC9L1L3/OzQP2N4oOFkRUNhuvP6BbgtM9veJ1+/75E6Miy7hj7Bf2nEtboXPbzthOR kxxro9rjbhD5efC41F1HFL2RxEsBF22ZTFXdF10FlYyRqWRrEuRkkxNHvNJAyiBiyHb5 xCx3hJCcAYykCnF/aKI0AxMDTkj4x39+lQJUW1SrSIqcsl3UFk3eY07U8IrPb8AhV1uo MAvO3Efc7ekB1pIAMLvXK67v6Yhq5T7IZPOk04vo8zGuFhsht5N49PaRJoPc7WLTbass MfYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:to:cc:references:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=2zaYEPU3Dc5zFOFGXsYjz12iYiWYHN8N3O6lakukl/s=; b=mk6ECNMHIfaJnfdVJza6zr3sQqMHNSUgYAr5ydti1HnQ46TwMYNrMnbwcfUw3Asi+C b2yLSIDIROzMJ4LukAW2nI6g0WCFx2Rgp+mq9uJog4e5eFieaS5jShXCayMwSEf11HGI X7T6jbjuu9QqNTxS95tA8I7QTHbfhwKEw7O527CzXhBDqmwJB2aYLR5Vft2Ixka435tP sKi/5FxDUB5UY0wKD7LEMy2xHnmF6UqG0UXampjezxvUVSZ0coNYem4z9WPl2kLL7U+2 bq2afagXnH6yG2+yTpWrD+kO3pjf0QaM+NxG/+yqMZulq4kQBMVz/5debAdh5xrh1HEk 1smw== X-Gm-Message-State: AOAM531DD07vwJRGTuaLZMKW502LLUivI2AlWRZnvbbClbo+msHB3e2f ilcxzGuwW0eCPCm8RSbXdQ77KmaKBMA= X-Received: by 2002:a05:6512:3089:: with SMTP id z9mr233591lfd.433.1608238709941; Thu, 17 Dec 2020 12:58:29 -0800 (PST) Received: from [192.168.2.145] (109-252-192-57.dynamic.spd-mgts.ru. [109.252.192.57]) by smtp.googlemail.com with ESMTPSA id z26sm789139ljn.98.2020.12.17.12.58.28 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 17 Dec 2020 12:58:29 -0800 (PST) Subject: Re: [PATCH v2 34/48] gpu: host1x: Support power management From: Dmitry Osipenko To: Mikko Perttunen , Thierry Reding , Jonathan Hunter , Mark Brown , Liam Girdwood , Ulf Hansson , Mauro Carvalho Chehab , Rob Herring , Peter Geis , Nicolas Chauvet , Krzysztof Kozlowski , "Rafael J. Wysocki" , Kevin Hilman , Peter De Schrijver , Viresh Kumar , Stephen Boyd , Michael Turquette Cc: devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-media@vger.kernel.org, linux-tegra@vger.kernel.org, linux-clk@vger.kernel.org References: <20201217180638.22748-1-digetx@gmail.com> <20201217180638.22748-35-digetx@gmail.com> Message-ID: <5523b804-f5de-a529-fd4e-751c39ab663b@gmail.com> Date: Thu, 17 Dec 2020 23:58:28 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.4.2 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 17.12.2020 21:45, Dmitry Osipenko пишет: > 17.12.2020 21:21, Mikko Perttunen пишет: >> On 12/17/20 8:06 PM, Dmitry Osipenko wrote: >>> Add suspend/resume and generic power domain support to the Host1x driver. >>> This is required for enabling system-wide DVFS and supporting dynamic >>> power management using a generic power domain. >>> >>> Tested-by: Peter Geis >>> Tested-by: Nicolas Chauvet >>> Signed-off-by: Dmitry Osipenko >>> --- >>>   drivers/gpu/host1x/dev.c | 102 ++++++++++++++++++++++++++++++++++----- >>>   1 file changed, 91 insertions(+), 11 deletions(-) >>> >>> diff --git a/drivers/gpu/host1x/dev.c b/drivers/gpu/host1x/dev.c >>> index d0ebb70e2fdd..c1525cffe7b1 100644 >>> --- a/drivers/gpu/host1x/dev.c >>> +++ b/drivers/gpu/host1x/dev.c >>> @@ -12,6 +12,7 @@ >>>   #include >>>   #include >>>   #include >>> +#include >>>   #include >>>     #define CREATE_TRACE_POINTS >>> @@ -417,7 +418,7 @@ static int host1x_probe(struct platform_device *pdev) >>>           return err; >>>       } >>>   -    host->rst = devm_reset_control_get(&pdev->dev, "host1x"); >>> +    host->rst = devm_reset_control_get_exclusive_released(&pdev->dev, >>> "host1x"); >>>       if (IS_ERR(host->rst)) { >>>           err = PTR_ERR(host->rst); >>>           dev_err(&pdev->dev, "failed to get reset: %d\n", err); >>> @@ -437,16 +438,15 @@ static int host1x_probe(struct platform_device >>> *pdev) >>>           goto iommu_exit; >>>       } >>>   -    err = clk_prepare_enable(host->clk); >>> -    if (err < 0) { >>> -        dev_err(&pdev->dev, "failed to enable clock\n"); >>> -        goto free_channels; >>> -    } >>> +    pm_runtime_enable(&pdev->dev); >>> +    err = pm_runtime_get_sync(&pdev->dev); >>> +    if (err < 0) >>> +        goto rpm_disable; >>>         err = reset_control_deassert(host->rst); >>>       if (err < 0) { >>>           dev_err(&pdev->dev, "failed to deassert reset: %d\n", err); >>> -        goto unprepare_disable; >>> +        goto rpm_disable; >>>       } >>>         err = host1x_syncpt_init(host); >>> @@ -485,9 +485,10 @@ static int host1x_probe(struct platform_device >>> *pdev) >>>       host1x_syncpt_deinit(host); >>>   reset_assert: >>>       reset_control_assert(host->rst); >>> -unprepare_disable: >>> -    clk_disable_unprepare(host->clk); >>> -free_channels: >>> +rpm_disable: >>> +    pm_runtime_put(&pdev->dev); >>> +    pm_runtime_disable(&pdev->dev); >>> + >>>       host1x_channel_list_free(&host->channel_list); >>>   iommu_exit: >>>       host1x_iommu_exit(host); >>> @@ -504,16 +505,95 @@ static int host1x_remove(struct platform_device >>> *pdev) >>>       host1x_intr_deinit(host); >>>       host1x_syncpt_deinit(host); >>>       reset_control_assert(host->rst); >>> -    clk_disable_unprepare(host->clk); >>> +    pm_runtime_put(&pdev->dev); >>> +    pm_runtime_disable(&pdev->dev); >>>       host1x_iommu_exit(host); >>>         return 0; >>>   } >>>   +static int __maybe_unused host1x_runtime_suspend(struct device *dev) >>> +{ >>> +    struct host1x *host = dev_get_drvdata(dev); >>> + >>> +    clk_disable_unprepare(host->clk); >>> +    reset_control_release(host->rst); >>> + >>> +    return 0; >>> +} >>> + >>> +static int __maybe_unused host1x_runtime_resume(struct device *dev) >>> +{ >>> +    struct host1x *host = dev_get_drvdata(dev); >>> +    int err; >>> + >>> +    err = reset_control_acquire(host->rst); >>> +    if (err) { >>> +        dev_err(dev, "failed to acquire reset: %d\n", err); >>> +        return err; >>> +    } >>> + >>> +    err = clk_prepare_enable(host->clk); >>> +    if (err) { >>> +        dev_err(dev, "failed to enable clock: %d\n", err); >>> +        goto release_reset; >>> +    } >>> + >>> +    return 0; >>> + >>> +release_reset: >>> +    reset_control_release(host->rst); >>> + >>> +    return err; >>> +} >>> + >>> +static __maybe_unused int host1x_suspend(struct device *dev) >>> +{ >>> +    struct host1x *host = dev_get_drvdata(dev); >>> +    int err; >>> + >>> +    host1x_syncpt_save(host); >>> + >>> +    err = pm_runtime_force_suspend(dev); >>> +    if (err < 0) >>> +        return err; >>> + >>> +    return 0; >>> +} >>> + >>> +static __maybe_unused int host1x_resume(struct device *dev) >>> +{ >>> +    struct host1x *host = dev_get_drvdata(dev); >>> +    struct host1x_channel *channel; >>> +    unsigned int index; >>> +    int err; >>> + >>> +    err = pm_runtime_force_resume(dev); >>> +    if (err < 0) >>> +        return err; >>> + >>> +    host1x_syncpt_restore(host); >> >> We also need to execute 'host1x_setup_sid_table' upon resume. > > Indeed, thanks. I'll correct it in the next revision. > > Perhaps the actual save/restore needs to be moved to the runtime > callbacks. At least I can't remember right now why this wasn't done in > the first place. > I looked at the save/restore once again and recalled why it's done so. The reason is that the host1x touches hardware during the driver probe, and thus, RPM needs to be resumed first. It will be a bigger change to properly decouple the hardware initialization so that it all could be put it into the RPM callback. I'll try to do it in v3.