From patchwork Wed Apr 5 15:01:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Konrad Dybcio X-Patchwork-Id: 671637 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5102BC77B6E for ; Wed, 5 Apr 2023 15:01:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229879AbjDEPBt (ORCPT ); Wed, 5 Apr 2023 11:01:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46686 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238489AbjDEPBr (ORCPT ); Wed, 5 Apr 2023 11:01:47 -0400 Received: from mail-lf1-x133.google.com (mail-lf1-x133.google.com [IPv6:2a00:1450:4864:20::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0DDEB46B3 for ; Wed, 5 Apr 2023 08:01:44 -0700 (PDT) Received: by mail-lf1-x133.google.com with SMTP id k37so47090637lfv.0 for ; Wed, 05 Apr 2023 08:01:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1680706902; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=W6Ju8CIEzaK87pEwl0n+uObDKxQlL1nqcBRnevkvACM=; b=JRvSWIp443spOoJuL6PTNeuwtXvRS6XHYbUUPBsNdAHtzGw2jkQyJ7l+3YXPUtQxl+ OBqcPq3uKdvvGVDzZv3aNeKulgqxNJCpTdTs+TvBgt6DxAGD6VbRgkuCdxjAR+6VYZuW 1Srm7vpHBj7+Ib5KVQ9y2YGCpJGcMDhun8T2D09XJA8If6I7Eqgmd6SO8/NI+ZEIK0Hp Zia5c68jkFMGBPX/nOp8bWyWSLqijzwXv6RPVfFFgc/RytgFoaz73nwqAXHibFs9+JjQ ERUC1XBUMMm3dxk30VyafZahz08HnSgqWJ9crWNk77p/IWQauIUIGJSxBgXgVjyHPTBY cnNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680706902; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=W6Ju8CIEzaK87pEwl0n+uObDKxQlL1nqcBRnevkvACM=; b=BurzqxP0bl1VSJl3WML9QQkTtJ9a/tL1HGrCMFUH6cNLy/t7KL8SmUBgAUnmLPsCEw xF0Ur7nToqC9C75mUZ3PGcbBUVqZ3aryvDGQf92sUHnuY/iSm4/xghiNoZF1rFp6yi0G +ZWa7tyAk9YLu4xTuFP8nYChzBJljs5PpCIO6swYR9xgimowPSTgCmMqDMzeeL6TGaja uhMoWD1tnoaDn3hED/ClMdIjomIkzDoh8zzWIgiAxHMyKP3/x+vAwCgnVsMeZ/N1FQ3/ NNCB1hWzcP4MNt1uSfHZzjAw9rSmjMcZ08cZaQ9iulj8oqkGX/mSI/a5VXQ+V/UwpuSN MOKA== X-Gm-Message-State: AAQBX9f1cFYOWQpA1frOuFJzu5HLqSDNsFXIH4PMrZ0BKNU7jx9/e39a 9kiO0k1Ytfu8W0zDHJ+1ypNaSw== X-Google-Smtp-Source: AKy350bcrLsgvnZEp83uglMTecfngvgNLBjJJ0rdOZ+HUySu3Xduj0QVb2DSDf6+BKt89TbZ3lKSjQ== X-Received: by 2002:ac2:43db:0:b0:4cb:4374:cc78 with SMTP id u27-20020ac243db000000b004cb4374cc78mr1825915lfl.26.1680706901595; Wed, 05 Apr 2023 08:01:41 -0700 (PDT) Received: from [192.168.1.101] (abxh37.neoplus.adsl.tpnet.pl. [83.9.1.37]) by smtp.gmail.com with ESMTPSA id 16-20020ac25690000000b004e84896253asm2833994lfr.251.2023.04.05.08.01.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 08:01:41 -0700 (PDT) From: Konrad Dybcio Date: Wed, 05 Apr 2023 17:01:35 +0200 Subject: [PATCH 1/2] dt-bindings: soc: qcom: Add RPM Master stats MIME-Version: 1.0 Message-Id: <20230405-topic-master_stats-v1-1-1b1fa2739953@linaro.org> References: <20230405-topic-master_stats-v1-0-1b1fa2739953@linaro.org> In-Reply-To: <20230405-topic-master_stats-v1-0-1b1fa2739953@linaro.org> To: Andy Gross , Bjorn Andersson , Rob Herring , Krzysztof Kozlowski Cc: Marijn Suijten , linux-arm-msm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Konrad Dybcio X-Mailer: b4 0.12.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1680706899; l=2156; i=konrad.dybcio@linaro.org; s=20230215; h=from:subject:message-id; bh=pOnWKQ9D5V1MjOyO4kKJpCciYdrkhMQtlWjnxKSUZfQ=; b=kgxETiISULWaSx50jp87qTXp6E9fgC29ravRA/S3GQbrjwlyxn37Hl8hhyYJffco835ubl/035zo o6vZrtGmAjlrRXgy2U4TnUyqjvt//XxEvqlDAN1x793Uyp1UgsSp X-Developer-Key: i=konrad.dybcio@linaro.org; a=ed25519; pk=iclgkYvtl2w05SSXO5EjjSYlhFKsJ+5OSZBjOkQuEms= Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org The RPM MSG RAM contains per-RPM-master (e.g. APPS, ADSP etc.) sleep statistics. They let one assess which core is actively preventing the system from entering a true low-power mode. Signed-off-by: Konrad Dybcio --- .../bindings/soc/qcom/rpm-master-stats.yaml | 53 ++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/Documentation/devicetree/bindings/soc/qcom/rpm-master-stats.yaml b/Documentation/devicetree/bindings/soc/qcom/rpm-master-stats.yaml new file mode 100644 index 000000000000..e8e71e75d161 --- /dev/null +++ b/Documentation/devicetree/bindings/soc/qcom/rpm-master-stats.yaml @@ -0,0 +1,53 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/soc/qcom/rpm-master-stats.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Qualcomm Technologies, Inc. (QTI) RPM Master Stats + +maintainers: + - Konrad Dybcio + +description: + Per-RPM-Master (e.g. APSS, ADSP, etc.) sleep statistics. + +properties: + compatible: + - const: qcom,rpm-master-stats + + qcom,rpm-msg-ram: + $ref: /schemas/types.yaml#/definitions/phandle-array + description: Phandle to an RPM MSG RAM slice containing the master stats + minItems: 1 + maxItems: 5 + + qcom,master-names: + $ref: /schemas/types.yaml#/definitions/string-array + description: RPM Master name + minItems: 1 + maxItems: 5 + +required: + - compatible + - qcom,rpm-msg-ram + - qcom,master-names + +additionalProperties: false + +examples: + - | + stats { + compatible = "qcom,rpm-master-stats"; + qcom,rpm-msg-ram = <&apss_master_stats>, + <&mpss_master_stats>, + <&adsp_master_stats>, + <&cdsp_master_stats>, + <&tz_master_stats>; + qcom,master-names = "APSS", + "MPSS", + "ADSP", + "CDSP", + "TZ"; + }; +... From patchwork Wed Apr 5 15:01:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Konrad Dybcio X-Patchwork-Id: 670429 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 16193C77B6C for ; Wed, 5 Apr 2023 15:01:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238526AbjDEPBu (ORCPT ); Wed, 5 Apr 2023 11:01:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46754 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238361AbjDEPBs (ORCPT ); Wed, 5 Apr 2023 11:01:48 -0400 Received: from mail-lf1-x132.google.com (mail-lf1-x132.google.com [IPv6:2a00:1450:4864:20::132]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DC9894EEE for ; Wed, 5 Apr 2023 08:01:44 -0700 (PDT) Received: by mail-lf1-x132.google.com with SMTP id c9so36602967lfb.1 for ; Wed, 05 Apr 2023 08:01:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1680706903; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=Enslf/wirWR/vFKVajt29WdovTFd9sBu4HdJK5iLVV8=; b=ZLKpkDYJBL1i3E5zK9vhu3Ry2Tog6qgOhFAv/eFFG+3ZWjzoUGVQgG4U2KdsbjzdJR Ul7w35P2cLihFz8D3hE50IJadFTSfhbDB3rDdcZlri8wtuCk8vJlxWnLGE06jZkGDHZW GgjARyDs0E8MaLfx0QL2dR/oqOUlIi3mmNh3RbgK9XoYmluTVdNTNCPSmSTqBodrrxyi tayLC75wtGMDIdAh8HnIw8QE9yVHCyEZjWe+oGRU1X+Qjph/qjzFYI35dwRjmDPXor+3 YLiFhhTYNlgG8gJVczs+agBQLVYtw0XuR2KZP+HAwGYjyposZxsgbwbMlPG/x9WymW72 sCAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680706903; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Enslf/wirWR/vFKVajt29WdovTFd9sBu4HdJK5iLVV8=; b=CW5janoSwFdrnIxEaeeakQI31LZq6SFWw46fA8vdWXN5Ul31MKAKgEHmrLSmx2YXDd 8HN5+GOskS9XJCEyZMl5tXCQJt+PKec6+S+XgTvqctObdSP1IBI1VweV2PFXeVaqzYa2 h0De/diTndJME8Y+++DoS38lu7B5Eas7xz76w+23ETw+eFPE3ET9MHRXIRBIIuoApdPy MZ4caks+dGxxQZ/dsgR3AWny2hn32DgHQToUsN2GVUxUE5pRjknHkoRMOJvdBMUol3+a RCyGbDVx1SxzhlUAYZFxtek00eyHyAtviQ93A3srr2P8rDClb0atnblKSEVmWkjwm5UA bFcA== X-Gm-Message-State: AAQBX9f0rGn8dH3fbw6v7Ke6ZoX9EH0e4NbDPsiQ73v99Yvz/dGSATRx CerUnmZdxi5sv0lr/34OQGGHYQ== X-Google-Smtp-Source: AKy350bFEWbqcOh52PgLamfiC+UN3gs5kBXP7o0H2B6ga0jJyt/MyQJ1j4DsNa+0qwYDsfYDIJypJg== X-Received: by 2002:ac2:5111:0:b0:4de:f972:6aa with SMTP id q17-20020ac25111000000b004def97206aamr1694910lfb.4.1680706903094; Wed, 05 Apr 2023 08:01:43 -0700 (PDT) Received: from [192.168.1.101] (abxh37.neoplus.adsl.tpnet.pl. [83.9.1.37]) by smtp.gmail.com with ESMTPSA id 16-20020ac25690000000b004e84896253asm2833994lfr.251.2023.04.05.08.01.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 08:01:42 -0700 (PDT) From: Konrad Dybcio Date: Wed, 05 Apr 2023 17:01:36 +0200 Subject: [PATCH 2/2] soc: qcom: Introduce RPM master stats driver MIME-Version: 1.0 Message-Id: <20230405-topic-master_stats-v1-2-1b1fa2739953@linaro.org> References: <20230405-topic-master_stats-v1-0-1b1fa2739953@linaro.org> In-Reply-To: <20230405-topic-master_stats-v1-0-1b1fa2739953@linaro.org> To: Andy Gross , Bjorn Andersson , Rob Herring , Krzysztof Kozlowski Cc: Marijn Suijten , linux-arm-msm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Konrad Dybcio X-Mailer: b4 0.12.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1680706899; l=7204; i=konrad.dybcio@linaro.org; s=20230215; h=from:subject:message-id; bh=UojBg6OM/XiZOOjQEvx052TRoaZQuzw+LM43xt276lg=; b=O7MAzoUHuFf4/U/KwYy3sM0ib5EvM8BsD4dzoO09CF0JNsrcOlt1mmu19Ugaayf4MVmuTkscpeRn zhsgQfVCBR6Z3C4M6sgfmCL9OC55Yq7+Sxi5xdmFA1llCFaiBdF/ X-Developer-Key: i=konrad.dybcio@linaro.org; a=ed25519; pk=iclgkYvtl2w05SSXO5EjjSYlhFKsJ+5OSZBjOkQuEms= Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org Introduce a driver to query and expose detailed, per-subsystem (as opposed to the existing qcom_stats driver which exposes SoC-wide data) about low power mode states of a given RPM master. That includes the APSS (ARM), MPSS (modem) and other remote cores, depending on the platform configuration. This is a vastly cleaned up and restructured version of a similar driver found in msm-5.4. Signed-off-by: Konrad Dybcio --- drivers/soc/qcom/Kconfig | 11 +++ drivers/soc/qcom/Makefile | 1 + drivers/soc/qcom/rpm_master_stats.c | 160 ++++++++++++++++++++++++++++++++++++ 3 files changed, 172 insertions(+) diff --git a/drivers/soc/qcom/Kconfig b/drivers/soc/qcom/Kconfig index a25df9e3c70e..325b733c102c 100644 --- a/drivers/soc/qcom/Kconfig +++ b/drivers/soc/qcom/Kconfig @@ -135,6 +135,17 @@ config QCOM_RMTFS_MEM Say y here if you intend to boot the modem remoteproc. +config QCOM_RPM_MASTER_STATS + tristate "Qualcomm RPM Master stats" + depends on ARCH_QCOM || COMPILE_TEST + help + The RPM Master sleep stats driver provides detailed per-subsystem + sleep/wake data, read from the RPM message RAM. It can be used to + assess whether all the low-power modes available are entered as + expected or to check which part of the SoC prevents it from sleeping. + + Say y here if you intend to debug or monitor platform sleep. + config QCOM_RPMH tristate "Qualcomm RPM-Hardened (RPMH) Communication" depends on ARCH_QCOM || COMPILE_TEST diff --git a/drivers/soc/qcom/Makefile b/drivers/soc/qcom/Makefile index 6e88da899f60..196bb87f2576 100644 --- a/drivers/soc/qcom/Makefile +++ b/drivers/soc/qcom/Makefile @@ -14,6 +14,7 @@ obj-$(CONFIG_QCOM_QMI_HELPERS) += qmi_helpers.o qmi_helpers-y += qmi_encdec.o qmi_interface.o obj-$(CONFIG_QCOM_RAMP_CTRL) += ramp_controller.o obj-$(CONFIG_QCOM_RMTFS_MEM) += rmtfs_mem.o +obj-$(CONFIG_QCOM_RPM_MASTER_STATS) += rpm_master_stats.o obj-$(CONFIG_QCOM_RPMH) += qcom_rpmh.o qcom_rpmh-y += rpmh-rsc.o qcom_rpmh-y += rpmh.o diff --git a/drivers/soc/qcom/rpm_master_stats.c b/drivers/soc/qcom/rpm_master_stats.c new file mode 100644 index 000000000000..759bfa1e01c4 --- /dev/null +++ b/drivers/soc/qcom/rpm_master_stats.c @@ -0,0 +1,160 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (c) 2012-2020, The Linux Foundation. All rights reserved. + * Copyright (c) 2023, Linaro Limited + * + * This driver supports what is known as "Master Stats v2", which seems to be + * the only version which has ever shipped, all the way from 2013 to 2023. + */ + +#include +#include +#include +#include +#include +#include + +struct master_stats_data { + void __iomem *base; + const char *label; +}; + +struct rpm_master_stats { + uint32_t active_cores; + uint32_t num_shutdowns; + uint64_t shutdown_req; + uint64_t wakeup_idx; + uint64_t bringup_req; + uint64_t bringup_ack; + uint32_t wakeup_reason; /* 0 = "rude wakeup", 1 = scheduled wakeup */ + uint32_t last_sleep_trans_dur; + uint32_t last_wake_trans_dur; + + /* Per-subsystem (*not necessarily* SoC-wide) XO shutdown stats */ + uint32_t xo_count; + uint64_t xo_last_enter; + uint64_t last_exit; + uint64_t xo_total_dur; +}; + +static int master_stats_show(struct seq_file *s, void *unused) +{ + struct master_stats_data *d = s->private; + struct rpm_master_stats stat; + + memcpy_fromio(&stat, d->base, sizeof(stat)); + + seq_printf(s, "%s:\n", d->label); + + seq_printf(s, "\tLast shutdown @ %llu\n", stat.shutdown_req); + seq_printf(s, "\tLast bringup req @ %llu\n", stat.bringup_req); + seq_printf(s, "\tLast bringup ack @ %llu\n", stat.bringup_ack); + seq_printf(s, "\tLast wakeup idx: %llu\n", stat.wakeup_idx); + seq_printf(s, "\tLast XO shutdown enter @ %llu\n", stat.xo_last_enter); + seq_printf(s, "\tLast XO shutdown exit @ %llu\n", stat.last_exit); + seq_printf(s, "\tXO total duration: %llu\n", stat.xo_total_dur); + seq_printf(s, "\tLast sleep transition duration: %u\n", stat.last_sleep_trans_dur); + seq_printf(s, "\tLast wake transition duration: %u\n", stat.last_wake_trans_dur); + seq_printf(s, "\tXO shutdown count: %u\n", stat.xo_count); + seq_printf(s, "\tWakeup reason: 0x%x\n", stat.wakeup_reason); + seq_printf(s, "\tShutdown count: %u\n", stat.num_shutdowns); + seq_printf(s, "\tActive cores bitmask: 0x%x\n", stat.active_cores); + + return 0; +} +DEFINE_SHOW_ATTRIBUTE(master_stats); + +static int master_stats_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct device_node *msgram_np; + struct master_stats_data *d; + struct dentry *dent, *root; + struct resource res; + int count, i, ret; + + count = of_property_count_strings(dev->of_node, "qcom,master-names"); + if (count < 0) + return count; + + d = devm_kzalloc(dev, count * sizeof(*d), GFP_KERNEL); + if (!d) + return -ENOMEM; + + root = debugfs_create_dir("rpm_master_stats", NULL); + platform_set_drvdata(pdev, root); + + for (i = 0; i < count; i++) { + msgram_np = of_parse_phandle(dev->of_node, "qcom,rpm-msg-ram", i); + if (!msgram_np) { + debugfs_remove_recursive(root); + return dev_err_probe(dev, -EINVAL, + "Couldn't parse MSG RAM phandle idx %s", i); + } + + /* + * Purposefully skip devm_platform helpers as we're using a + * shared resource. + */ + ret = of_address_to_resource(msgram_np, 0, &res); + if (ret < 0) { + debugfs_remove_recursive(root); + return ret; + } + + d[i].base = devm_ioremap(dev, res.start, resource_size(&res)); + if (IS_ERR(d[i].base)) { + debugfs_remove_recursive(root); + return dev_err_probe(dev, -EINVAL, + "Could not map the MSG RAM slice idx %d!\n", i); + } + + ret = of_property_read_string_index(dev->of_node, "qcom,master-names", i, + &d[i].label); + if (ret < 0) { + debugfs_remove_recursive(root); + return dev_err_probe(dev, ret, + "Could not read name idx %d!\n", i); + } + + /* + * Generally it's not advised to fail on debugfs errors, but this + * driver's only job is exposing data therein. + */ + dent = debugfs_create_file(d[i].label, 0444, root, + &d[i], &master_stats_fops); + if (!dent) { + debugfs_remove_recursive(root); + return -EINVAL; + } + } + + device_set_pm_not_required(dev); + + return 0; +} + +static void master_stats_remove(struct platform_device *pdev) +{ + struct dentry *root = platform_get_drvdata(pdev); + + debugfs_remove_recursive(root); +} + +static const struct of_device_id rpm_master_table[] = { + { .compatible = "qcom,rpm-master-stats" }, + { }, +}; + +static struct platform_driver master_stats_driver = { + .probe = master_stats_probe, + .remove_new = master_stats_remove, + .driver = { + .name = "rpm_master_stats", + .of_match_table = rpm_master_table, + }, +}; +module_platform_driver(master_stats_driver); + +MODULE_DESCRIPTION("RPM Master Statistics driver"); +MODULE_LICENSE("GPL");