From: Jagadeesh Kona <quic_jkona@quicinc.com>
To: Ulf Hansson <ulf.hansson@linaro.org>,
Bjorn Andersson <andersson@kernel.org>,
Abel Vesa <abel.vesa@linaro.org>
Cc: "Rafael J. Wysocki" <rafael@kernel.org>,
Kevin Hilman <khilman@kernel.org>, Pavel Machek <pavel@ucw.cz>,
Len Brown <len.brown@intel.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
"Andy Gross" <agross@kernel.org>,
Konrad Dybcio <konrad.dybcio@linaro.org>,
"Michael Turquette" <mturquette@baylibre.com>,
Stephen Boyd <sboyd@kernel.org>,
Stanimir Varbanov <stanimir.k.varbanov@gmail.com>,
Vikash Garodia <quic_vgarodia@quicinc.com>,
Bryan O'Donoghue <bryan.odonoghue@linaro.org>,
Mauro Carvalho Chehab <mchehab@kernel.org>,
Taniya Das <quic_tdas@quicinc.com>,
Dmitry Baryshkov <dmitry.baryshkov@linaro.org>,
<linux-pm@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
<linux-arm-msm@vger.kernel.org>, <linux-clk@vger.kernel.org>,
<linux-media@vger.kernel.org>
Subject: Re: [PATCH v4 1/5] PM: domains: Allow devices attached to genpd to be managed by HW
Date: Tue, 13 Feb 2024 18:40:05 +0530 [thread overview]
Message-ID: <87b7967f-d8c4-426e-92ed-5a418c702481@quicinc.com> (raw)
In-Reply-To: <CAPDyKFp1vg2+-pHJ_idkdhb_zZUMpq7W17DnCCGj0eTwd4jFbQ@mail.gmail.com>
On 2/2/2024 5:59 PM, Ulf Hansson wrote:
> On Fri, 2 Feb 2024 at 00:51, Bjorn Andersson <andersson@kernel.org> wrote:
>>
>> On Wed, Jan 31, 2024 at 01:12:00PM +0100, Ulf Hansson wrote:
>>> On Wed, 31 Jan 2024 at 02:09, Bjorn Andersson <andersson@kernel.org> wrote:
>>>>
>>>> On Mon, Jan 22, 2024 at 10:47:01AM +0200, Abel Vesa wrote:
>>>>> From: Ulf Hansson <ulf.hansson@linaro.org>
>>>>>
>>>>> Some power-domains may be capable of relying on the HW to control the power
>>>>> for a device that's hooked up to it. Typically, for these kinds of
>>>>> configurations the consumer driver should be able to change the behavior of
>>>>> power domain at runtime, control the power domain in SW mode for certain
>>>>> configurations and handover the control to HW mode for other usecases.
>>>>>
>>>>> To allow a consumer driver to change the behaviour of the PM domain for its
>>>>> device, let's provide a new function, dev_pm_genpd_set_hwmode(). Moreover,
>>>>> let's add a corresponding optional genpd callback, ->set_hwmode_dev(),
>>>>> which the genpd provider should implement if it can support switching
>>>>> between HW controlled mode and SW controlled mode. Similarly, add the
>>>>> dev_pm_genpd_get_hwmode() to allow consumers to read the current mode and
>>>>> its corresponding optional genpd callback, ->get_hwmode_dev(), which the
>>>>> genpd provider can also implement for reading back the mode from the
>>>>> hardware.
>>>>>
>>>>> Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
>>>>> Signed-off-by: Abel Vesa <abel.vesa@linaro.org>
>>>>> Reviewed-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
>>>>> ---
>>>>> drivers/pmdomain/core.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++
>>>>> include/linux/pm_domain.h | 17 ++++++++++++
>>>>> 2 files changed, 86 insertions(+)
>>>>>
>>>>> diff --git a/drivers/pmdomain/core.c b/drivers/pmdomain/core.c
>>>>> index a1f6cba3ae6c..41b6411d0ef5 100644
>>>>> --- a/drivers/pmdomain/core.c
>>>>> +++ b/drivers/pmdomain/core.c
>>>>> @@ -548,6 +548,75 @@ void dev_pm_genpd_synced_poweroff(struct device *dev)
>>>>> }
>>>>> EXPORT_SYMBOL_GPL(dev_pm_genpd_synced_poweroff);
>>>>>
>>>>> +/**
>>>>> + * dev_pm_genpd_set_hwmode - Set the HW mode for the device and its PM domain.
>>>>
>>>> This isn't proper kernel-doc
>>>
>>> Sorry, I didn't quite get that. What is wrong?
>>>
>>
>> https://docs.kernel.org/doc-guide/kernel-doc.html#function-documentation
>> says that there should be () after the function name, and below there
>> should be a Return:
>
> Thanks for the pointers!
>
>>
>>>>
>>>>> + *
>>>>> + * @dev: Device for which the HW-mode should be changed.
>>>>> + * @enable: Value to set or unset the HW-mode.
>>>>> + *
>>>>> + * Some PM domains can rely on HW signals to control the power for a device. To
>>>>> + * allow a consumer driver to switch the behaviour for its device in runtime,
>>>>> + * which may be beneficial from a latency or energy point of view, this function
>>>>> + * may be called.
>>>>> + *
>>>>> + * It is assumed that the users guarantee that the genpd wouldn't be detached
>>>>> + * while this routine is getting called.
>>>>> + *
>>>>> + * Returns 0 on success and negative error values on failures.
>>>>> + */
>>>>> +int dev_pm_genpd_set_hwmode(struct device *dev, bool enable)
>>>>> +{
>>>>> + struct generic_pm_domain *genpd;
>>>>> + int ret = 0;
>>>>> +
>>>>> + genpd = dev_to_genpd_safe(dev);
>>>>> + if (!genpd)
>>>>> + return -ENODEV;
>>>>> +
>>>>> + if (!genpd->set_hwmode_dev)
>>>>> + return -EOPNOTSUPP;
>>>>> +
>>>>> + genpd_lock(genpd);
>>>>> +
>>>>> + if (dev_gpd_data(dev)->hw_mode == enable)
>>>>
>>>> Between this and the gdsc patch, the hw_mode state might not match the
>>>> hardware state at boot.
>>>>
>>>> With hw_mode defaulting to false, your first dev_pm_genpd_set_hwmode(,
>>>> false) will not bring control to SW - which might be fatal.
>>>
>>> Right, good point.
>>>
>>> I think we have two ways to deal with this:
>>> 1) If the provider is supporting ->get_hwmode_dev(), we can let
>>> genpd_add_device() invoke it to synchronize the state.
>>
>> I'd suggest that we skip the optimization for now and just let the
>> update hit the driver on each call.
>
> Okay.
>
>>
>>> 2) If the provider doesn't support ->get_hwmode_dev() we need to call
>>> ->set_hwmode_dev() to allow an initial state to be set.
>>>
>>> The question is then, if we need to allow ->get_hwmode_dev() to be
>>> optional, if the ->set_hwmode_dev() is supported - or if we can
>>> require it. What's your thoughts around this?
>>>
>>
>> Iiuc this resource can be shared between multiple clients, and we're
>> in either case returning the shared state. That would mean a client
>> acting upon the returned value, is subject to races.
>
> Not sure I understand this, but I also don't have in-depth knowledge
> of how the HW works.
>
> Isn't the HW mode set on a per device basis?
>
>>
>> I'm therefore inclined to say that we shouldn't have a getter, other
>> than for debugging purposes, in which case reading the HW-state or
>> failing would be reasonable outcomes.
>
> If you only want this for debug purposes, it seems better to keep it
> closer to the rpmh code, rather than adding generic callbacks to the
> genpd interface.
>
> So to conclude, you think having a ->set_hwmode_dev() callback should
> be sufficient and no caching of the current state?
>
> Abel, what's your thoughts around this?
>
We believe it is good to have get_hwmode_dev() callback supported from
GenPD, since if multiple devices share a GenPD, and if one device moves
the GenPD to HW mode, the other device won't be aware of it and second
device's dev_gpd_data(dev)->hw_mode will still be false.
If we have this dev_pm_genpd_get_hwmode() API supported and if we assign
dev_gpd_data(dev)->hw_mode after getting the mode from get_hwmode_dev()
callback, consumer drivers can use this API to sync the actual HW mode
of the GenPD.
Thanks,
Jagadeesh
> Kind regards
> Uffe
next prev parent reply other threads:[~2024-02-13 13:10 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-22 8:47 [PATCH v4 0/5] PM: domains: Add control for switching back and forth to HW control Abel Vesa
2024-01-22 8:47 ` [PATCH v4 1/5] PM: domains: Allow devices attached to genpd to be managed by HW Abel Vesa
2024-01-23 12:53 ` Ulf Hansson
2024-01-31 1:09 ` Bjorn Andersson
2024-01-31 12:12 ` Ulf Hansson
2024-02-01 23:51 ` Bjorn Andersson
2024-02-02 12:29 ` Ulf Hansson
2024-02-13 13:10 ` Jagadeesh Kona [this message]
2024-02-13 13:51 ` Ulf Hansson
2024-02-14 4:29 ` Jagadeesh Kona
2024-02-15 16:27 ` Ulf Hansson
2024-02-16 8:00 ` Jagadeesh Kona
2024-02-28 14:53 ` Ulf Hansson
2024-03-01 11:24 ` Jagadeesh Kona
2024-01-22 8:47 ` [PATCH v4 2/5] PM: domains: Add the domain HW-managed mode to the summary Abel Vesa
2024-01-22 8:47 ` [PATCH v4 3/5] clk: qcom: gdsc: Add set and get hwmode callbacks to switch GDSC mode Abel Vesa
2024-01-30 23:00 ` Bjorn Andersson
2024-01-31 0:19 ` Bjorn Andersson
2024-02-13 13:08 ` Jagadeesh Kona
2024-02-13 13:04 ` Jagadeesh Kona
2024-01-22 8:47 ` [PATCH v4 4/5] clk: qcom: Use HW_CTRL_TRIGGER flag to switch video GDSC to HW mode Abel Vesa
2024-01-22 8:47 ` [PATCH v4 5/5] venus: pm_helpers: Use dev_pm_genpd_set_hwmode to switch GDSC mode Abel Vesa
2024-01-31 1:05 ` Bjorn Andersson
2024-02-13 13:06 ` Jagadeesh Kona
2024-01-23 13:00 ` [PATCH v4 0/5] PM: domains: Add control for switching back and forth to HW control Ulf Hansson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87b7967f-d8c4-426e-92ed-5a418c702481@quicinc.com \
--to=quic_jkona@quicinc.com \
--cc=abel.vesa@linaro.org \
--cc=agross@kernel.org \
--cc=andersson@kernel.org \
--cc=bryan.odonoghue@linaro.org \
--cc=dmitry.baryshkov@linaro.org \
--cc=gregkh@linuxfoundation.org \
--cc=khilman@kernel.org \
--cc=konrad.dybcio@linaro.org \
--cc=len.brown@intel.com \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-clk@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=mchehab@kernel.org \
--cc=mturquette@baylibre.com \
--cc=pavel@ucw.cz \
--cc=quic_tdas@quicinc.com \
--cc=quic_vgarodia@quicinc.com \
--cc=rafael@kernel.org \
--cc=sboyd@kernel.org \
--cc=stanimir.k.varbanov@gmail.com \
--cc=ulf.hansson@linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®