Received: by 10.192.165.148 with SMTP id m20csp47588imm; Thu, 3 May 2018 14:36:21 -0700 (PDT) X-Google-Smtp-Source: AB8JxZor8pDrqOmo7I1f8BvyCz7Vr0aLoMI91cexwUhY5ET48CNhUvS8a4YH/kuRY+YvtI0pOL9n X-Received: by 2002:a65:510a:: with SMTP id f10-v6mr9939259pgq.248.1525383381106; Thu, 03 May 2018 14:36:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525383381; cv=none; d=google.com; s=arc-20160816; b=K7w8YpYhDBfl0gGuu7pBp+fgEmr1HAxca42uZe8soxy2C83WAZbPXV3ZYAVAwO20dn wtsifdnQSZ+yNgcyXr94X1yFxYU/n2ymBaFlX+FIT8EO1J5ST+X/8ppy8Dd6YC/Jo2j6 jCyNe/Wykf/WXKgMy3N33NgOmWFQdnQLIkxXhpKIc45wVeoS2BHRuINU0x6QCTfv8XSc AbeX9j2WOydOTmgjJeV2sFmajkbCi26Pse788LBDES7tmEfs65ecI2UBas8kEkxl3CNX PotUnbaNNqpicfpv+JaVEyTHGpOjlzMiQuujyAdu7CxDhaBdmYpeNRz+LZscACykr8gw /cWA== 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=FjjH//SbsQYtZsCFWeuHKbYrDCTXYmmiP//dSYMscGk=; b=W+HYB4JAHT8UDt6S3OKNwH2Zf1xUAmZg5GUXSMCK2v9UUkLXHHKtA06aEDz/F4Y1jN Nz/ecq4qr/Id7N6CxbOGQ2SJxEQLs1YNJOd5UrC9X16MngoeMKcLRlSoGk5S8RrvW+QP IMXzqeIPovk4ApZgXD87cThWh9Y5cEvuHlv1404FMcg+rUQcu44xd8RhX9Sqpf98VXwf FRRO+dMQngGtbsfrdc4gdHMTw3Jws9KnRkwZvyB+AURNXDAnl8mS6gBY9PcpDsNZNtTG Oh6ZzIDTzrKBRq7RE7SxQHx2d+QQQAwVx64Ud+lKlzf7lMpxAFQF5nlvedNEVPIY/Lz6 6hvA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=mF/BxFhr; 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 t23-v6si12004683pgu.285.2018.05.03.14.36.05; Thu, 03 May 2018 14:36:21 -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=mF/BxFhr; 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 S1751308AbeECVfn (ORCPT + 99 others); Thu, 3 May 2018 17:35:43 -0400 Received: from mail-pg0-f66.google.com ([74.125.83.66]:44924 "EHLO mail-pg0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751074AbeECVfl (ORCPT ); Thu, 3 May 2018 17:35:41 -0400 Received: by mail-pg0-f66.google.com with SMTP id 82-v6so14017418pge.11 for ; Thu, 03 May 2018 14:35:41 -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=FjjH//SbsQYtZsCFWeuHKbYrDCTXYmmiP//dSYMscGk=; b=mF/BxFhrx47Tw2733V5gk+d5yC9H0hbbuw4893q4xrHsB8t7VBZWpMchGemFSJLq6V D4zrO1rUgR517dEbonbhpxUUuJqd691VnbTCgupeYTEieRAGh6ANsU651Q4Z4cHqLXTg 3vZebkbQtGDrC0a5LDsT//tCsvmK9U4/txiuQ= 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=FjjH//SbsQYtZsCFWeuHKbYrDCTXYmmiP//dSYMscGk=; b=QjTT27AS5rF9E1bcWU6c+sRef6crXKtsQZJbAiA0n6uR/+MKSkjiht5xb++HhIM9CU UbFCQTwBSCs7rePfITnyPB/VWjg9Jl2KJaRIPdJPqTRFs1f9EvsLWbvMrvnDYEMFWxOV c21Ay8B3uykjNxcChC2QgsdJT63levtp1bH6PurGZudKg+aWXKpWeLB0OuGZ7iB08pui f50LGa44fI5YHZkcMRIIKN1tfkMVoK7AtJKQ0jvuAjMwOfUZ/937brbM0LBWC5rbrog+ RY2XANIfdpJDyKCEe3ehku5r+uPyT2oH5Lfy9a8dICbFcRToV3NdV49OPL3vx/S17oiW AxUg== X-Gm-Message-State: ALQs6tC00on8j4t0rhLHiJcS3TabpgenHSuw0QaKgdV9gAZcyzrinWNz E7bnYzSBX7DxJ+jcWiz7QGVwmg== X-Received: by 10.98.153.215 with SMTP id t84mr13467307pfk.252.1525383341103; Thu, 03 May 2018 14:35:41 -0700 (PDT) Received: from localhost ([2620:0:1000:1501:8e2d:4727:1211:622]) by smtp.gmail.com with ESMTPSA id e126sm29377237pfh.5.2018.05.03.14.35.40 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 03 May 2018 14:35:40 -0700 (PDT) Date: Thu, 3 May 2018 14:35:39 -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 v7 05/10] drivers: qcom: rpmh-rsc: write sleep/wake requests to TCS Message-ID: <20180503213539.GA19594@google.com> References: <20180502193749.31004-1-ilina@codeaurora.org> <20180502193749.31004-6-ilina@codeaurora.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20180502193749.31004-6-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 Wed, May 02, 2018 at 01:37:44PM -0600, Lina Iyer wrote: > Sleep and wake requests are sent when the application processor > subsystem of the SoC is entering deep sleep states like in suspend. > These requests help lower the system power requirements when the > resources are not in use. > > Sleep and wake requests are written to the TCS slots but are not > triggered at the time of writing. The TCS are triggered by the firmware > after the last of the CPUs has executed its WFI. Since these requests > may come in different batches of requests, it is the job of this > controller driver to find and arrange the requests into the available > TCSes. > > Signed-off-by: Lina Iyer > Reviewed-by: Evan Green > > --- > > Changes in v7: > - Bug fix in find_match() > --- > drivers/soc/qcom/rpmh-internal.h | 8 +++ > drivers/soc/qcom/rpmh-rsc.c | 118 +++++++++++++++++++++++++++++++ > 2 files changed, 126 insertions(+) > > diff --git a/drivers/soc/qcom/rpmh-internal.h b/drivers/soc/qcom/rpmh-internal.h > index d9a21726e568..6e19fe458c31 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 MAX_TCS_SLOTS (MAX_CMDS_PER_TCS * MAX_TCS_PER_TYPE) > #define RPMH_MAX_CTRLR 2 > > struct rsc_drv; > @@ -30,6 +31,8 @@ struct rsc_drv; > * @ncpt: number of commands in each TCS > * @lock: lock for synchronizing this TCS writes > * @req: requests that are sent from the TCS > + * @cmd_cache: flattened cache of cmds in sleep/wake TCS > + * @slots: indicates which of @cmd_addr are occupied > */ > struct tcs_group { > struct rsc_drv *drv; > @@ -40,6 +43,8 @@ struct tcs_group { > int ncpt; > spinlock_t lock; > const struct tcs_request *req[MAX_TCS_PER_TYPE]; > + u32 *cmd_cache; > + DECLARE_BITMAP(slots, MAX_TCS_SLOTS); > }; > > /** > @@ -69,6 +74,9 @@ struct rsc_drv { > extern struct list_head rsc_drv_list; > > int rpmh_rsc_send_data(struct rsc_drv *drv, const struct tcs_request *msg); > +int rpmh_rsc_write_ctrl_data(struct rsc_drv *drv, > + const struct tcs_request *msg); > +int rpmh_rsc_invalidate(struct rsc_drv *drv); > > void rpmh_tx_done(const struct tcs_request *msg, int r); > > diff --git a/drivers/soc/qcom/rpmh-rsc.c b/drivers/soc/qcom/rpmh-rsc.c > index 33270b1d5991..4e2144a14c31 100644 > --- a/drivers/soc/qcom/rpmh-rsc.c > +++ b/drivers/soc/qcom/rpmh-rsc.c > @@ -113,6 +113,12 @@ static struct tcs_group *get_tcs_for_msg(struct rsc_drv *drv, > case RPMH_ACTIVE_ONLY_STATE: > type = ACTIVE_TCS; > break; > + case RPMH_WAKE_ONLY_STATE: > + type = WAKE_TCS; > + break; > + case RPMH_SLEEP_STATE: > + type = SLEEP_TCS; > + break; > default: > return ERR_PTR(-EINVAL); > } > @@ -353,6 +359,105 @@ int rpmh_rsc_send_data(struct rsc_drv *drv, const struct tcs_request *msg) > } > EXPORT_SYMBOL(rpmh_rsc_send_data); > > +static int find_match(const struct tcs_group *tcs, const struct tcs_cmd *cmd, > + int len) > +{ > + int i, j; > + > + /* Check for already cached commands */ > + for_each_set_bit(i, tcs->slots, MAX_TCS_SLOTS) { > + if (tcs->cmd_cache[i] != cmd[0].addr) > + continue; > + for (j = 0; j < len; j++) { > + if (tcs->cmd_cache[i + j] != cmd[j].addr) { As mentioned in the review of v6, the code could read memory beyond tcs->cmd_cache if 'i + len > ARRAY_SIZE(tcs->cmd_cache)' > + WARN(1, "Message does not match previous sequence.\n"); > + return -EINVAL; > + } > + } > + return i; > + } > + > + return -ENODATA; > +} > + > +static int find_slots(struct tcs_group *tcs, const struct tcs_request *msg, > + int *tcs_id, int *cmd_id) The change from m/n => tcs_id/cmd_id in v7 greatly improves readability, thanks! Matthias PS: Please remember to include reviewers of earlier revisions to cc: