LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Lina Iyer <ilina@codeaurora.org>
To: Matthias Kaehlcke <mka@chromium.org>
Cc: andy.gross@linaro.org, david.brown@linaro.org,
linux-arm-msm@vger.kernel.org, linux-soc@vger.kernel.org,
rnayak@codeaurora.org, bjorn.andersson@linaro.org,
linux-kernel@vger.kernel.org, sboyd@kernel.org,
evgreen@chromium.org, dianders@chromium.org
Subject: Re: [PATCH v6 04/10] drivers: qcom: rpmh: add RPMH helper functions
Date: Fri, 27 Apr 2018 10:55:36 -0600 [thread overview]
Message-ID: <20180427165536.GC6380@codeaurora.org> (raw)
In-Reply-To: <20180426180529.GG243180@google.com>
On Thu, Apr 26 2018 at 12:05 -0600, Matthias Kaehlcke wrote:
>Hi Lina,
>
>On Thu, Apr 19, 2018 at 04:16:29PM -0600, Lina Iyer wrote:
>> Sending RPMH requests and waiting for response from the controller
>> through a callback is common functionality across all platform drivers.
>> To simplify drivers, add a library functions to create RPMH client and
>> send resource state requests.
>>
>> rpmh_write() is a synchronous blocking call that can be used to send
>> active state requests.
>>
>> Signed-off-by: Lina Iyer <ilina@codeaurora.org>
>> ---
>>
>> Changes in v6:
>> - replace rpmh_client with device
>> - inline wait_for_tx_done()
>>
>> Changes in v4:
>> - use const struct tcs_cmd in API
>> - remove wait count from this patch
>> - changed -EFAULT to -EINVAL
>> ---
>> drivers/soc/qcom/Makefile | 4 +-
>> drivers/soc/qcom/rpmh-internal.h | 6 ++
>> drivers/soc/qcom/rpmh-rsc.c | 8 ++
>> drivers/soc/qcom/rpmh.c | 168 +++++++++++++++++++++++++++++++
>> include/soc/qcom/rpmh.h | 25 +++++
>> 5 files changed, 210 insertions(+), 1 deletion(-)
>> create mode 100644 drivers/soc/qcom/rpmh.c
>> create mode 100644 include/soc/qcom/rpmh.h
>>
>> diff --git a/drivers/soc/qcom/Makefile b/drivers/soc/qcom/Makefile
>> index cb6300f6a8e9..bb395c3202ca 100644
>> --- a/drivers/soc/qcom/Makefile
>> +++ b/drivers/soc/qcom/Makefile
>> @@ -7,7 +7,9 @@ obj-$(CONFIG_QCOM_PM) += spm.o
>> obj-$(CONFIG_QCOM_QMI_HELPERS) += qmi_helpers.o
>> qmi_helpers-y += qmi_encdec.o qmi_interface.o
>> obj-$(CONFIG_QCOM_RMTFS_MEM) += rmtfs_mem.o
>> -obj-$(CONFIG_QCOM_RPMH) += rpmh-rsc.o
>> +obj-$(CONFIG_QCOM_RPMH) += qcom_rpmh.o
>> +qcom_rpmh-y += rpmh-rsc.o
>> +qcom_rpmh-y += rpmh.o
>> obj-$(CONFIG_QCOM_SMD_RPM) += smd-rpm.o
>> obj-$(CONFIG_QCOM_SMEM) += smem.o
>> obj-$(CONFIG_QCOM_SMEM_STATE) += smem_state.o
>> diff --git a/drivers/soc/qcom/rpmh-internal.h b/drivers/soc/qcom/rpmh-internal.h
>> index cc29176f1303..d9a21726e568 100644
>> --- a/drivers/soc/qcom/rpmh-internal.h
>> +++ b/drivers/soc/qcom/rpmh-internal.h
>> @@ -14,6 +14,7 @@
>> #define MAX_CMDS_PER_TCS 16
>> #define MAX_TCS_PER_TYPE 3
>> #define MAX_TCS_NR (MAX_TCS_PER_TYPE * TCS_TYPE_NR)
>> +#define RPMH_MAX_CTRLR 2
>>
>> struct rsc_drv;
>>
>> @@ -52,6 +53,7 @@ struct tcs_group {
>> * @tcs: TCS groups
>> * @tcs_in_use: s/w state of the TCS
>> * @lock: synchronize state of the controller
>> + * @list: element in list of drv
>> */
>> struct rsc_drv {
>> const char *name;
>> @@ -61,9 +63,13 @@ struct rsc_drv {
>> struct tcs_group tcs[TCS_TYPE_NR];
>> DECLARE_BITMAP(tcs_in_use, MAX_TCS_NR);
>> spinlock_t lock;
>> + struct list_head list;
>> };
>>
>> +extern struct list_head rsc_drv_list;
>>
>> int rpmh_rsc_send_data(struct rsc_drv *drv, const struct tcs_request *msg);
>>
>> +void rpmh_tx_done(const struct tcs_request *msg, int r);
> ~
>
>nit: consider using a more expressive name, like status, rc, res or
>err.
>
OK. Will fix.
><snip>
>
>> +static struct rpmh_ctrlr *get_rpmh_ctrlr(const struct device *dev)
>> +{
>> + int i;
>> + struct rsc_drv *p, *drv = dev_get_drvdata(dev->parent);
>> + struct rpmh_ctrlr *ctrlr = ERR_PTR(-EINVAL);
>> +
>> + if (!drv)
>> + return ctrlr;
>> +
>> + for (i = 0; i < RPMH_MAX_CTRLR; i++) {
>> + if (rpmh_rsc[i].drv == drv) {
>> + ctrlr = &rpmh_rsc[i];
>> + return ctrlr;
>> + }
>> + }
>> +
>> + list_for_each_entry(p, &rsc_drv_list, list) {
>> + if (drv == p) {
>> + for (i = 0; i < RPMH_MAX_CTRLR; i++) {
>> + if (!rpmh_rsc[i].drv)
>> + break;
>> + }
>> + rpmh_rsc[i].drv = drv;
>
>There is a race condition, get_rpmh_ctrlr() could be executed
>simulatenously in different contexts, and select the same
>controller instance for different DRVs.
>
True. This will need to be serialized.
>It's probably an unlikely case, but to be safe you'd have to do
>something like this:
>
>retry:
>for (i = 0; i < RPMH_MAX_CTRLR; i++) {
> if (!rpmh_rsc[i].drv)
> break;
>}
>
>spin_lock(&rpmh_rsc[i].lock);
>
>if (!rpmh_rsc[i].drv) {
> rpmh_rsc[i].drv = drv;
> ctrlr = &rpmh_rsc[i];
>} else {
> spin_unlock(&rpmh_rsc[i].lock);
> goto retry;
>}
>
>spin_unlock(&rpmh_rsc[i].lock);
>
>
>The above code doesn't address another potential error case, where
>#DRV > RPMH_MAX_CTRLR. In this case we'd access memory beyond
>rpmh_rsc. This would be a configuration error, not sure if it's
>strictly necessary to handle it.
>
I think I might be able to solve for this a bit simpler with another
spinlock for the rpmh_rsc.
><snip>
>
>> +/**
>> + * rpmh_write: Write a set of RPMH commands and block until response
>> + *
>> + * @rc: The RPMh handle got from rpmh_get_client
> ~~~~
>
>nit: Other than this the driver consistently uses 'RPMH'
>
OK.
Thanks for the review Matthias.
-- Lina
next prev parent reply other threads:[~2018-04-27 16:55 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-04-19 22:16 [PATCH v6 00/10] drivers/qcom: add RPMH communication support Lina Iyer
2018-04-19 22:16 ` [PATCH v6 01/10] drivers: qcom: rpmh-rsc: add RPMH controller for QCOM SoCs Lina Iyer
2018-04-19 22:16 ` [PATCH v6 02/10] dt-bindings: introduce RPMH RSC bindings for Qualcomm SoCs Lina Iyer
2018-05-01 23:45 ` Doug Anderson
2018-05-02 14:56 ` Lina Iyer
2018-04-19 22:16 ` [PATCH v6 03/10] drivers: qcom: rpmh-rsc: log RPMH requests in FTRACE Lina Iyer
2018-04-19 22:16 ` [PATCH v6 04/10] drivers: qcom: rpmh: add RPMH helper functions Lina Iyer
2018-04-26 18:05 ` Matthias Kaehlcke
2018-04-27 16:55 ` Lina Iyer [this message]
2018-04-19 22:16 ` [PATCH v6 05/10] drivers: qcom: rpmh-rsc: write sleep/wake requests to TCS Lina Iyer
2018-04-25 21:41 ` Matthias Kaehlcke
2018-04-27 17:39 ` Lina Iyer
2018-04-27 18:40 ` Matthias Kaehlcke
2018-04-27 19:45 ` Lina Iyer
2018-04-27 20:06 ` Matthias Kaehlcke
2018-04-27 21:32 ` Lina Iyer
2018-04-27 21:54 ` Matthias Kaehlcke
2018-04-27 23:24 ` Doug Anderson
2018-05-01 16:10 ` Lina Iyer
2018-05-01 16:42 ` Doug Anderson
2018-05-01 17:35 ` Lina Iyer
2018-05-01 16:45 ` Matthias Kaehlcke
2018-04-19 22:16 ` [PATCH v6 06/10] drivers: qcom: rpmh-rsc: allow invalidation of sleep/wake TCS Lina Iyer
2018-04-25 22:11 ` Matthias Kaehlcke
2018-04-27 16:44 ` Lina Iyer
2018-04-27 16:54 ` Matthias Kaehlcke
2018-04-19 22:16 ` [PATCH v6 07/10] drivers: qcom: rpmh: cache sleep/wake state requests Lina Iyer
2018-04-19 22:16 ` [PATCH v6 08/10] drivers: qcom: rpmh: allow requests to be sent asynchronously Lina Iyer
2018-04-19 22:16 ` [PATCH v6 09/10] drivers: qcom: rpmh: add support for batch RPMH request Lina Iyer
2018-04-25 23:41 ` Matthias Kaehlcke
2018-04-27 16:24 ` Lina Iyer
2018-04-19 22:16 ` [PATCH v6 10/10] drivers: qcom: rpmh-rsc: allow active requests from wake TCS Lina Iyer
2018-04-26 1:14 ` Matthias Kaehlcke
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=20180427165536.GC6380@codeaurora.org \
--to=ilina@codeaurora.org \
--cc=andy.gross@linaro.org \
--cc=bjorn.andersson@linaro.org \
--cc=david.brown@linaro.org \
--cc=dianders@chromium.org \
--cc=evgreen@chromium.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-soc@vger.kernel.org \
--cc=mka@chromium.org \
--cc=rnayak@codeaurora.org \
--cc=sboyd@kernel.org \
--subject='Re: [PATCH v6 04/10] drivers: qcom: rpmh: add RPMH helper functions' \
/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
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).