Received: by 10.192.165.148 with SMTP id m20csp2447939imm; Thu, 26 Apr 2018 11:08:34 -0700 (PDT) X-Google-Smtp-Source: AIpwx4845QkMTX0PeAKMQJV5tNRLZfzD+K3s3Tvk3tj8mirNQ7fvDwTAw9qGF/Uw6lmDxBVpIJRN X-Received: by 2002:a17:902:2924:: with SMTP id g33-v6mr32604923plb.26.1524766114335; Thu, 26 Apr 2018 11:08:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524766114; cv=none; d=google.com; s=arc-20160816; b=ERsmhdExDB69xYX2CiGZ5py/diMWotyRdd8xPmFEIEZlFZnIW3pW2KGPzs9Kp/gd1F TNjA9k3BOOMfv01MTJHD9KLbZ2Ye6O9F2wCRYyW4A/2ys6HAdfOpn6NDsatOArfjgHkn AW00kMecP/zkXX92xt2gNdHgbqFKNP1iqjN4NrxsZc7yx5/kuh0ySAufInq2KSAZ/eUp 0FX1aHgRCA4/oKBe7Xr2nXOxO9oCpvPUsGh93sTgNXIKjdBKQiBN2kLcYHq1KtlwYgyd JHT/G5eJvqoaO/CdC5Zq9FAkJ2QJyKHZjoI8KYjSDMu13JD+VtO7qlvuOn++yQuhjw7s 85IA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=TzJVUoJ8/HmEZcjn9AjRS4Npw+DK2eLRcB6LgV+nwYg=; b=juT4c2PdIdJUkw4VNiwlHQKgpRjfcezCd95m2gAdKpCE4Yc+Xkyf1LTzCSRpxOBP0w Mx4nXUbKufKaKLMpbaYdxcUyVzm/q6//z+2tUj6kqSBxWm1AjSCy3hsDQKwKss3gigxr cZ8lwtoMb5jGKml23rYKDe4e2K0Ah1uYce/rYrlhMwbQl7zkBEwl6qWSCfMosQFzq1V/ quR5ox8ueJoBhnYUBo7UgvCx8p8B8ZFososnMvU9yrb+PitUHg9giVqtFnZs6n4tiyVL ogsHkLoviEO2f5ZG76Q0omPQlgJKvlZ6BvSE5UUUMgvz1g8T15BrBTuRStC/mPamUoer YVjw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=niCIyABz; 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=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 7-v6si19402558plc.164.2018.04.26.11.08.19; Thu, 26 Apr 2018 11:08:34 -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; dkim=pass header.i=@chromium.org header.s=google header.b=niCIyABz; 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=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756918AbeDZSFf (ORCPT + 99 others); Thu, 26 Apr 2018 14:05:35 -0400 Received: from mail-pf0-f196.google.com ([209.85.192.196]:37611 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756723AbeDZSFb (ORCPT ); Thu, 26 Apr 2018 14:05:31 -0400 Received: by mail-pf0-f196.google.com with SMTP id p6so18989493pfn.4 for ; Thu, 26 Apr 2018 11:05:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=TzJVUoJ8/HmEZcjn9AjRS4Npw+DK2eLRcB6LgV+nwYg=; b=niCIyABzhiQHrSfz/3KA1Y187nXebpBrA2/dSjX//MxyNGSWUOtxwngDBnN58oCROt Tws02i+BPA0lCEXOpOYECM0trAn4ppxyXh96R/Glsdq6QBwehlYwmfFCpEaQbpOKTg+k Kffc7Dd+cddv1jtMqe6egW5RRqmP3MzmM/JDI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=TzJVUoJ8/HmEZcjn9AjRS4Npw+DK2eLRcB6LgV+nwYg=; b=kbUcrv3sI2JCHBLb5VwA5vEaVq0YBkq85dE2g8FzqMK27D47xcVdCHEss+iGHrpo5F d7ZImNoji5v1zlAYMURpWoL2lhHHbhPhrghlxNjrLqiONwfravENAcWGLZg3VpgV3f9G HtBpjAJRrXfz7+Uq6FdECFNwM3L208Cd79GK8PgkJGpigRQQBaWNkfb9QPiG9+bjWUwG Eng/yNliRSiaCwfBoy3MwD0Heb8mo8PJFevR+r++9mOsRYOkpOtxLiCOY/tCLV9c7B4T x9c5u7pTiAvo2Sc7Kg/SvWvgwewPH65OSQ/4LHXnlbz0UNvogsnOaqmp+gPSZRlcMcE4 aOhA== X-Gm-Message-State: ALQs6tCYVE9l1dhe0C33mjt5fjGy+pTy1B50yHqJ3YB4vpyQsNt8uGbm ZshfsQZmwbQAW6aJwenvkDtGug== X-Received: by 2002:a17:902:1e3:: with SMTP id b90-v6mr31706062plb.273.1524765930832; Thu, 26 Apr 2018 11:05:30 -0700 (PDT) Received: from localhost ([2620:0:1000:1501:8e2d:4727:1211:622]) by smtp.gmail.com with ESMTPSA id b3sm34090748pfi.54.2018.04.26.11.05.29 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 26 Apr 2018 11:05:30 -0700 (PDT) Date: Thu, 26 Apr 2018 11:05:29 -0700 From: Matthias Kaehlcke To: Lina Iyer 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 Message-ID: <20180426180529.GG243180@google.com> References: <20180419221635.17849-1-ilina@codeaurora.org> <20180419221635.17849-5-ilina@codeaurora.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20180419221635.17849-5-ilina@codeaurora.org> User-Agent: Mutt/1.9.2 (2017-12-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 > --- > > 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. > +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. 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. > +/** > + * 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' Matthias