From patchwork Tue Oct 18 15:28:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 4224 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp2021872wrs; Tue, 18 Oct 2022 08:32:49 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7PmbLZGxM+drXMBkjs6usSMQS+XQznYM1Xn83U19Ph3yU88XLMw6d8Oi8WznvCDaZbExwH X-Received: by 2002:a05:6402:847:b0:453:943b:bf4 with SMTP id b7-20020a056402084700b00453943b0bf4mr3132634edz.301.1666107157354; Tue, 18 Oct 2022 08:32:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666107157; cv=none; d=google.com; s=arc-20160816; b=0eSu0GgMZlDLek9pZwPbg1o9KEjFos7ec++TMTExU7YxV68KUO2eh2IkU4Y5b3/Y+A jI2huOwUkLOJuzWshq9hiZ9cQ0qvOIhLnWlfcYDAQYbiu3nUoOn3WjiaWMluGNlyzN0M 8CBXbyMSvLmo2lh58wVRRZxTGlqPQeno1HR10+N0Ax1OuVdbbVW7DfnJeXDhkV2AP0OV Cus9/rm+bzWlyG/ytu4wkaalJh7TKqQ18SAgdJdv+BCWJbzWzPnu6R1XHfBx2diicSLm gbMQkguVlhJ2cYbnoraFRMvBTJ1JlHsfQPvTzGHOg+f596ntOmXELtodyqsdW3pkQ6gL U7dw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=eICgBxGNGKtE/hLPDQo1kEkz5yh4bfsSzqIE+62FuGc=; b=FM3hPpQ3fejgCpnh4bH3Om00MQOQH65GKsxTurdJjqzyKQZfW8Nu1LguorbpCKGHxI nOKXMOi2EeJr2VRnwpl8FE8fPv43DXBKwo3ssnH2qc0Z2pAelXFFTNFXoaMPLEcKxxtM IrAQDIz4S/djocTVlQrlAwb32IYAds8JYOoBL6fk9rJT2SSciTlVhGtiC+ZLClUyzCm2 7Gjo54tYiTruJtKOExIaMdp9c5Ngv/oSe59XOHBirqHXxBHUkQ/3O+m50HDKUfCCxUBd uuyPPus7+2EbBJWfcK3u6EXUUfMekh4BnVxtKe9fk9KEU9o/oiEggUGROqF71UuTuCKz HOFg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="j6s/UUFb"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j4-20020aa7c404000000b0045832636efesi10373457edq.239.2022.10.18.08.32.11; Tue, 18 Oct 2022 08:32:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="j6s/UUFb"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230496AbiJRP3f (ORCPT + 99 others); Tue, 18 Oct 2022 11:29:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37902 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230309AbiJRP3I (ORCPT ); Tue, 18 Oct 2022 11:29:08 -0400 Received: from mail-lj1-x22e.google.com (mail-lj1-x22e.google.com [IPv6:2a00:1450:4864:20::22e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EC979BC614 for ; Tue, 18 Oct 2022 08:29:06 -0700 (PDT) Received: by mail-lj1-x22e.google.com with SMTP id i21so15547763ljh.12 for ; Tue, 18 Oct 2022 08:29:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=eICgBxGNGKtE/hLPDQo1kEkz5yh4bfsSzqIE+62FuGc=; b=j6s/UUFbfhlBYCdMnWA56JZ+mwYLJIEgwXMq32ZQS1GcetQZ+NJTTy1Aj1+LLmDgB3 GEOhnN1Y6hIMvy4XhvzVzpYUDDn4/BbsB3kb4jeIiJfwUsDhNZ7+2ze8DwPOFohEHrr8 lncpiqcR6imDPWMC3S8/Rj0dbcYGw4y4lpv7fn0+ayfHy4mDUEE14aIzLXHH7TjSf0+U z/xy8ddv/dCz7VR+LIjWh2HtKFN8R5DOdbCJuEUFtL/x8YjQXVp3aLF0H/YI+QsJC8qT xEohCYEaRTC0JuhfrXqB+oXYVypynotGxAvo/o0/yhKGCTimVGCkN75okRTM4UxkE1R5 Jjng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=eICgBxGNGKtE/hLPDQo1kEkz5yh4bfsSzqIE+62FuGc=; b=l760Br4Yx0YDXHulR1UFVZgeaMYRzJDfhlKqZkQVj70ufQAbekiStHUp+7kHG7UJwP Aa5srAD8ubwZvdj7+lIY3z4PBEhF5AWY2i+MfmrarkEuU6lUJ/1JKYQ20XUyIqXTQXIR qx4ZjUjGawESQNV6bSy1VjjtruOcIYUGf1Q6hqGPaD6VWB0aRBk/s+Nl3yvOiKqPW8K8 11WX3R22p/37s+HyXYFNvYjST+7hD4nqRZu7X74f+HDa0fPC7/q21qJXJGmY+JVgTAA+ V6dAT9d9XtsCLd3bPQwYD8hey4rMgdTZpHijCSht5tBBXDVnXA+FrW2pHcy8UdTEDU1o FwmA== X-Gm-Message-State: ACrzQf0xjENUC+tcSXbYQzUBzck80mt2/nPgKeoJGdGqEWwQeJImf/cZ 8oMXrPHc6ooKCTHOJH6z2YXRIw== X-Received: by 2002:a2e:a589:0:b0:26f:d394:dbe2 with SMTP id m9-20020a2ea589000000b0026fd394dbe2mr1327724ljp.485.1666106945164; Tue, 18 Oct 2022 08:29:05 -0700 (PDT) Received: from uffe-XPS13.. (h-94-254-63-18.NA.cust.bahnhof.se. [94.254.63.18]) by smtp.gmail.com with ESMTPSA id a9-20020a05651c030900b0026ddd41aecasm1998617ljp.135.2022.10.18.08.29.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Oct 2022 08:29:04 -0700 (PDT) From: Ulf Hansson To: Andy Gross , Bjorn Andersson , Konrad Dybcio Cc: Dmitry Baryshkov , Maulik Shah , Rajendra Nayak , Sudeep Holla , Amit Pundir , Ulf Hansson , linux-arm-msm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 6/6] soc: qcom: rpmh-rsc: Write CONTROL_TCS with next timer wakeup Date: Tue, 18 Oct 2022 17:28:37 +0200 Message-Id: <20221018152837.619426-7-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221018152837.619426-1-ulf.hansson@linaro.org> References: <20221018152837.619426-1-ulf.hansson@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747039978366296732?= X-GMAIL-MSGID: =?utf-8?q?1747039978366296732?= From: Maulik Shah The next wakeup timer value needs to be set in always on domain timer as the arch timer interrupt can not wakeup the SoC if after the deepest CPUidle states the SoC also enters deepest low power state. To wakeup the SoC in such scenarios the earliest wakeup time is set in CONTROL_TCS and the firmware takes care of setting up its own timer in always on domain with next wakeup time. The timer wakes up the RSC and sets resources back to wake state. Signed-off-by: Maulik Shah Reviewed-by: Ulf Hansson Tested-by: Dmitry Baryshkov # SM8450 --- drivers/soc/qcom/rpmh-internal.h | 3 ++ drivers/soc/qcom/rpmh-rsc.c | 61 ++++++++++++++++++++++++++++++++ drivers/soc/qcom/rpmh.c | 4 ++- 3 files changed, 67 insertions(+), 1 deletion(-) diff --git a/drivers/soc/qcom/rpmh-internal.h b/drivers/soc/qcom/rpmh-internal.h index 7866bb1e5361..39f53586f724 100644 --- a/drivers/soc/qcom/rpmh-internal.h +++ b/drivers/soc/qcom/rpmh-internal.h @@ -112,6 +112,7 @@ struct rpmh_ctrlr { * @tcs_wait: Wait queue used to wait for @tcs_in_use to free up a * slot * @client: Handle to the DRV's client. + * @dev: RSC device. */ struct rsc_drv { const char *name; @@ -127,12 +128,14 @@ struct rsc_drv { spinlock_t lock; wait_queue_head_t tcs_wait; struct rpmh_ctrlr client; + struct device *dev; }; 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); void rpmh_rsc_invalidate(struct rsc_drv *drv); +void rpmh_rsc_write_next_wakeup(struct rsc_drv *drv); void rpmh_tx_done(const struct tcs_request *msg, int r); int rpmh_flush(struct rpmh_ctrlr *ctrlr); diff --git a/drivers/soc/qcom/rpmh-rsc.c b/drivers/soc/qcom/rpmh-rsc.c index 8e01697f59af..25b838bf9078 100644 --- a/drivers/soc/qcom/rpmh-rsc.c +++ b/drivers/soc/qcom/rpmh-rsc.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -25,6 +26,7 @@ #include #include +#include #include #include #include @@ -49,6 +51,14 @@ #define DRV_NCPT_MASK 0x1F #define DRV_NCPT_SHIFT 27 +/* Offsets for CONTROL TCS Registers */ +#define RSC_DRV_CTL_TCS_DATA_HI 0x38 +#define RSC_DRV_CTL_TCS_DATA_HI_MASK 0xFFFFFF +#define RSC_DRV_CTL_TCS_DATA_HI_VALID BIT(31) +#define RSC_DRV_CTL_TCS_DATA_LO 0x40 +#define RSC_DRV_CTL_TCS_DATA_LO_MASK 0xFFFFFFFF +#define RSC_DRV_CTL_TCS_DATA_SIZE 32 + /* Offsets for common TCS Registers, one bit per TCS */ #define RSC_DRV_IRQ_ENABLE 0x00 #define RSC_DRV_IRQ_STATUS 0x04 @@ -142,6 +152,14 @@ * +---------------------------------------------------+ */ +#define USECS_TO_CYCLES(time_usecs) \ + xloops_to_cycles((time_usecs) * 0x10C7UL) + +static inline unsigned long xloops_to_cycles(unsigned long xloops) +{ + return (xloops * loops_per_jiffy * HZ) >> 32; +} + static inline void __iomem * tcs_reg_addr(const struct rsc_drv *drv, int reg, int tcs_id) { @@ -756,6 +774,48 @@ static bool rpmh_rsc_ctrlr_is_busy(struct rsc_drv *drv) return set < max; } +/** + * rpmh_rsc_write_next_wakeup() - Write next wakeup in CONTROL_TCS. + * @drv: The controller + * + * Writes maximum wakeup cycles when called from suspend. + * Writes earliest hrtimer wakeup when called from idle. + */ +void rpmh_rsc_write_next_wakeup(struct rsc_drv *drv) +{ + ktime_t now, wakeup; + u64 wakeup_us, wakeup_cycles = ~0; + u32 lo, hi; + + if (!drv->tcs[CONTROL_TCS].num_tcs || !drv->genpd_nb.notifier_call) + return; + + /* Set highest time when system (timekeeping) is suspended */ + if (system_state == SYSTEM_SUSPEND) + goto exit; + + /* Find the earliest hrtimer wakeup from online cpus */ + wakeup = dev_pm_genpd_get_next_hrtimer(drv->dev); + + /* Find the relative wakeup in kernel time scale */ + now = ktime_get(); + wakeup = ktime_sub(wakeup, now); + wakeup_us = ktime_to_us(wakeup); + + /* Convert the wakeup to arch timer scale */ + wakeup_cycles = USECS_TO_CYCLES(wakeup_us); + wakeup_cycles += arch_timer_read_counter(); + +exit: + lo = wakeup_cycles & RSC_DRV_CTL_TCS_DATA_LO_MASK; + hi = wakeup_cycles >> RSC_DRV_CTL_TCS_DATA_SIZE; + hi &= RSC_DRV_CTL_TCS_DATA_HI_MASK; + hi |= RSC_DRV_CTL_TCS_DATA_HI_VALID; + + writel_relaxed(lo, drv->base + RSC_DRV_CTL_TCS_DATA_LO); + writel_relaxed(hi, drv->base + RSC_DRV_CTL_TCS_DATA_HI); +} + /** * rpmh_rsc_cpu_pm_callback() - Check if any of the AMCs are busy. * @nfb: Pointer to the notifier block in struct rsc_drv. @@ -1035,6 +1095,7 @@ static int rpmh_rsc_probe(struct platform_device *pdev) INIT_LIST_HEAD(&drv->client.batch_cache); dev_set_drvdata(&pdev->dev, drv); + drv->dev = &pdev->dev; ret = devm_of_platform_populate(&pdev->dev); if (ret && pdev->dev.pm_domain) { diff --git a/drivers/soc/qcom/rpmh.c b/drivers/soc/qcom/rpmh.c index 01765ee9cdfb..3a53ed99d03c 100644 --- a/drivers/soc/qcom/rpmh.c +++ b/drivers/soc/qcom/rpmh.c @@ -450,7 +450,7 @@ int rpmh_flush(struct rpmh_ctrlr *ctrlr) if (!ctrlr->dirty) { pr_debug("Skipping flush, TCS has latest data.\n"); - goto exit; + goto write_next_wakeup; } /* Invalidate the TCSes first to avoid stale data */ @@ -479,6 +479,8 @@ int rpmh_flush(struct rpmh_ctrlr *ctrlr) ctrlr->dirty = false; +write_next_wakeup: + rpmh_rsc_write_next_wakeup(ctrlr_to_drv(ctrlr)); exit: spin_unlock(&ctrlr->cache_lock); return ret;