From nobody Wed Jul 1 16:40:04 2026 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 C43CBC433EF for ; Sat, 18 Dec 2021 13:00:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233227AbhLRNAe (ORCPT ); Sat, 18 Dec 2021 08:00:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33094 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232990AbhLRNAe (ORCPT ); Sat, 18 Dec 2021 08:00:34 -0500 Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 840BEC061574 for ; Sat, 18 Dec 2021 05:00:33 -0800 (PST) Received: by mail-wm1-x332.google.com with SMTP id i12so3420344wmq.4 for ; Sat, 18 Dec 2021 05:00:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=JCbNL7RiUna5qq8DaSMW/coH4epXCMjSWD6ZnOXRFI0=; b=u4gwbRii2rQYALroefHK1y6OAg/PaB5d8cxYkVOxNfQfP/GSpkOTw4lM0b9sykdRGn I5+TfxMLFW4Yz9DjXmmwADnnilA4jAI3OuH+2kj279neBPdyczuIvIKan+BZxt1abCOC PYvHZoojRGkGcKQVmwOZVt1XScnzpH93n3cT0kdV+KDJ4QLvkVW8g+u48CO+9sCgVbi+ IM8GXnnDHqRZPDHHNChAWlGub8OWoFq1V1IwRCwrtEzywv2SqESfkq3jDHxS/vHMIzCq Y/6l37BlHAuffQ5iGLgabgk+gX6l3IXwpC+2N3WfHvO+x+p5njBf0nTvVHjxH/2oigQn 0Nrw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=JCbNL7RiUna5qq8DaSMW/coH4epXCMjSWD6ZnOXRFI0=; b=dLxsE+9KrNT/DxCYwHvNERWxPpC5LSNMMOAd2W/jZSBBc1jowNnEoYGz7LvH5tqU+O ORdlAGaT4h5b0TQ8Dn9sJ3rYrq3GYQ7XSUUM4mPnEz3SHHbq8NyvsSabBSlFveUKWREA BQn/trf3IXmZCYdQKhyhGfVGxy03bp1tj90dXGy3oS0I7wrAEIGqUhIvv8gkQAWqk2zl QDCpoIY7tD0eEVUU6/nR62J2d61sbTP/RgjQCqrC0BlIanrsptGStyyTblWFUhq1NOE9 b7QYfMKdXLoDXlKBOmLQ86bQAxVPG2yRqXx/5OifDYvD0BGW9XOO6UifHpGDemeWbcWi zRcQ== X-Gm-Message-State: AOAM530r5aA2Ra/Z8bw340j70suYkGuwEU1Lxc2bF7SV0z69ifiQyOVS shs99CTmqfR35+h+LBWowki8OQ== X-Google-Smtp-Source: ABdhPJxXBs2crqxznWfWrplA3JeMlkC5cBhIFjXjof2wb1mGSFgRnncc6sy5NXR1PO3YD3c6rLebKQ== X-Received: by 2002:a05:600c:a4c:: with SMTP id c12mr6702096wmq.60.1639832431971; Sat, 18 Dec 2021 05:00:31 -0800 (PST) Received: from localhost.localdomain ([2a01:e34:ed2f:f020:1f0f:c9b8:ee5c:5c2f]) by smtp.gmail.com with ESMTPSA id j16sm1465785wms.12.2021.12.18.05.00.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Dec 2021 05:00:31 -0800 (PST) From: Daniel Lezcano To: daniel.lezcano@linaro.org, rjw@rjwysocki.net Cc: lukasz.luba@arm.com, robh@kernel.org, heiko@sntech.de, arnd@linaro.org, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, ulf.hansson@linaro.org, Arnd Bergmann , linux-arch@vger.kernel.org (open list:GENERIC INCLUDE/ASM HEADER FILES) Subject: [PATCH v5 1/6] powercap/drivers/dtpm: Move dtpm table from init to data section Date: Sat, 18 Dec 2021 14:00:09 +0100 Message-Id: <20211218130014.4037640-2-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211218130014.4037640-1-daniel.lezcano@linaro.org> References: <20211218130014.4037640-1-daniel.lezcano@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The dtpm table is used to let the different dtpm backends to register their setup callbacks in a single place and preventing to export multiple functions all around the kernel. That allows the dtpm code to be self-encapsulated. The dtpm hierarchy will be passed as a parameter by a platform specific code and that will lead to the creation of the different dtpm nodes. The function creating the hierarchy could be called from a module at init time or when it is loaded. However, at this moment the table is already freed as it belongs to the init section and the creation will lead to a invalid memory access. Fix this by moving the table to the data section. Signed-off-by: Daniel Lezcano --- include/asm-generic/vmlinux.lds.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinu= x.lds.h index 42f3866bca69..50d494d94d6c 100644 --- a/include/asm-generic/vmlinux.lds.h +++ b/include/asm-generic/vmlinux.lds.h @@ -362,7 +362,8 @@ BRANCH_PROFILE() \ TRACE_PRINTKS() \ BPF_RAW_TP() \ - TRACEPOINT_STR() + TRACEPOINT_STR() \ + DTPM_TABLE() =20 /* * Data section helpers @@ -723,7 +724,6 @@ ACPI_PROBE_TABLE(irqchip) \ ACPI_PROBE_TABLE(timer) \ THERMAL_TABLE(governor) \ - DTPM_TABLE() \ EARLYCON_TABLE() \ LSM_TABLE() \ EARLY_LSM_TABLE() \ --=20 2.25.1 From nobody Wed Jul 1 16:40:04 2026 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 74BC5C433EF for ; Sat, 18 Dec 2021 13:00:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233252AbhLRNAi (ORCPT ); Sat, 18 Dec 2021 08:00:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33112 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233231AbhLRNAf (ORCPT ); Sat, 18 Dec 2021 08:00:35 -0500 Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 376C4C06173F for ; Sat, 18 Dec 2021 05:00:35 -0800 (PST) Received: by mail-wr1-x42f.google.com with SMTP id v7so2061769wrv.12 for ; Sat, 18 Dec 2021 05:00:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Ex98898ORuSQfXO3nt1xbryRupEWOc+Ws7IWvi7Y958=; b=MSiX8872aULjxwwWkBGaY+6CBTB4Bk8og4GFTKrZcV/QR7h9Rib64/2uVR6t/iTRNM pWwECd2NZ7wsGlKxsobev/zTSah25gQzRty9YfL4JF2qZQE/yr/+2LyBKqswZLrz0x1V G3iM+/TXQR2kAdgQ9kjs0PeoHUJMrVTPEK1dtmTpT6CQ2ykfW04SYDVK2YcvQO/Ko9BL zbskONb+0IxVZKhEEuAsI1zBjWtLdQMf1iBfwPVV21B0l3DRSkp/p7s0cZ+sJCmf5/Zo N5ChbsSQrWozpzDLGQNEOClloAuIys7jA4GFvF2cWphyJqmsQxLJ0B2/RSvzsaQ7oLTR GTGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Ex98898ORuSQfXO3nt1xbryRupEWOc+Ws7IWvi7Y958=; b=LY2kDVl3HwwDucxj+rs+56xnCK18ZjkM7epZuk0ro/hg2wk8rHkuS358Jdf0QaUkWF RuCwNyFtQZ80Ic6Lp9nsSp4xfIRLXZQyhBWXxW1serzp1bcgRLolnNzjIEZz+pcgP4up wkI/xDY8S2BDwEhK5ClpkeV0dJp85GlmxcFao2/3ZyxaEaTmAsWhBtujxN3tzF//lvGV wVyj54kxii8eGIzDTxwqIcSbT1To+JP6GMCQ1ckv6J6E5Z2tYdryLVL07tSO5A/GZVx3 89mdqg99BHc025PmisHgdv9dZGdZ0JMX8xC45Dxu2/nArKVNxX/kckCZt4MEBNHOkwHj y7lw== X-Gm-Message-State: AOAM5323lckl0jijMvPduQSNQiZjBOvDASHCIPT9UtY3RsaUX/kx5GYF gSGZ1LiodKjRjHKs3zOxEWoiNj4IsLUxXA== X-Google-Smtp-Source: ABdhPJx1TFiCgA5HbwOo6OFSCSrP6j7DJZt+8Gf9pGtTd265i0qCfhzr2/PgJeD4Vo/417lUWht0IA== X-Received: by 2002:adf:cd8a:: with SMTP id q10mr6060897wrj.164.1639832433691; Sat, 18 Dec 2021 05:00:33 -0800 (PST) Received: from localhost.localdomain ([2a01:e34:ed2f:f020:1f0f:c9b8:ee5c:5c2f]) by smtp.gmail.com with ESMTPSA id j16sm1465785wms.12.2021.12.18.05.00.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Dec 2021 05:00:33 -0800 (PST) From: Daniel Lezcano To: daniel.lezcano@linaro.org, rjw@rjwysocki.net Cc: lukasz.luba@arm.com, robh@kernel.org, heiko@sntech.de, arnd@linaro.org, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, ulf.hansson@linaro.org, "Rafael J. Wysocki" , Daniel Lezcano Subject: [PATCH v5 2/6] powercap/drivers/dtpm: Add hierarchy creation Date: Sat, 18 Dec 2021 14:00:10 +0100 Message-Id: <20211218130014.4037640-3-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211218130014.4037640-1-daniel.lezcano@linaro.org> References: <20211218130014.4037640-1-daniel.lezcano@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The DTPM framework is available but without a way to configure it. This change provides a way to create a hierarchy of DTPM node where the power consumption reflects the sum of the children's power consumption. It is up to the platform to specify an array of dtpm nodes where each element has a pointer to its parent, except the top most one. The type of the node gives the indication of which initialization callback to call. At this time, we can create a virtual node, where its purpose is to be a parent in the hierarchy, and a DT node where the name describes its path. In order to ensure a nice self-encapsulation, the DTPM table descriptors contains a couple of initialization functions, one to setup the DTPM backend and one to initialize it up. With this approach, the DTPM framework has a very few material to export. Signed-off-by: Daniel Lezcano --- drivers/powercap/Kconfig | 1 + drivers/powercap/dtpm.c | 155 ++++++++++++++++++++++++++++++++++-- drivers/powercap/dtpm_cpu.c | 2 +- include/linux/dtpm.h | 21 ++++- 4 files changed, 171 insertions(+), 8 deletions(-) diff --git a/drivers/powercap/Kconfig b/drivers/powercap/Kconfig index 8242e8c5ed77..b1ca339957e3 100644 --- a/drivers/powercap/Kconfig +++ b/drivers/powercap/Kconfig @@ -46,6 +46,7 @@ config IDLE_INJECT =20 config DTPM bool "Power capping for Dynamic Thermal Power Management (EXPERIMENTAL)" + depends on OF help This enables support for the power capping for the dynamic thermal power management userspace engine. diff --git a/drivers/powercap/dtpm.c b/drivers/powercap/dtpm.c index 0fe70687c198..1611c86de5f5 100644 --- a/drivers/powercap/dtpm.c +++ b/drivers/powercap/dtpm.c @@ -23,6 +23,7 @@ #include #include #include +#include =20 #define DTPM_POWER_LIMIT_FLAG 0 =20 @@ -461,19 +462,163 @@ int dtpm_register(const char *name, struct dtpm *dtp= m, struct dtpm *parent) return 0; } =20 -static int __init init_dtpm(void) +static struct dtpm *dtpm_setup_virtual(const struct dtpm_node *hierarchy, + struct dtpm *parent) +{ + struct dtpm *dtpm; + int ret; + + dtpm =3D kzalloc(sizeof(*dtpm), GFP_KERNEL); + if (!dtpm) + return ERR_PTR(-ENOMEM); + dtpm_init(dtpm, NULL); + + ret =3D dtpm_register(hierarchy->name, dtpm, parent); + if (ret) { + pr_err("Failed to register dtpm node '%s': %d\n", + hierarchy->name, ret); + kfree(dtpm); + return ERR_PTR(ret); + } + + return dtpm; +} + +static struct dtpm *dtpm_setup_dt(const struct dtpm_node *hierarchy, + struct dtpm *parent) +{ + struct dtpm_descr *dtpm_descr; + struct device_node *np; + int ret; + + np =3D of_find_node_by_path(hierarchy->name); + if (!np) { + pr_err("Failed to find '%s'\n", hierarchy->name); + return ERR_PTR(-ENXIO); + } + + for_each_dtpm_table(dtpm_descr) { + + ret =3D dtpm_descr->setup(parent, np); + if (ret) { + pr_err("Failed to setup '%s': %d\n", hierarchy->name, ret); + of_node_put(np); + return ERR_PTR(ret); + } + + of_node_put(np); + } + + /* + * By returning a NULL pointer, we let know the caller there + * is no child for us as we are a leaf of the tree + */ + return NULL; +} + +typedef struct dtpm * (*dtpm_node_callback_t)(const struct dtpm_node *, st= ruct dtpm *); + +dtpm_node_callback_t dtpm_node_callback[] =3D { + [DTPM_NODE_VIRTUAL] =3D dtpm_setup_virtual, + [DTPM_NODE_DT] =3D dtpm_setup_dt, +}; + +static int dtpm_for_each_child(const struct dtpm_node *hierarchy, + const struct dtpm_node *it, struct dtpm *parent) +{ + struct dtpm *dtpm; + int i, ret; + + for (i =3D 0; hierarchy[i].name; i++) { + + if (hierarchy[i].parent !=3D it) + continue; + + dtpm =3D dtpm_node_callback[hierarchy[i].type](&hierarchy[i], parent); + if (!dtpm || IS_ERR(dtpm)) + continue; + + ret =3D dtpm_for_each_child(hierarchy, &hierarchy[i], dtpm); + if (ret) + return ret; + } + + return 0; +} + +/** + * dtpm_create_hierarchy - Create the dtpm hierarchy + * @hierarchy: An array of struct dtpm_node describing the hierarchy + * + * The function is called by the platform specific code with the + * description of the different node in the hierarchy. It creates the + * tree in the sysfs filesystem under the powercap dtpm entry. + * + * The expected tree has the format: + * + * struct dtpm_node hierarchy[] =3D { + * [0] { .name =3D "topmost" }, + * [1] { .name =3D "package", .parent =3D &hierarchy[0] }, + * [2] { .name =3D "/cpus/cpu0", .type =3D DTPM_NODE_DT, .parent =3D = &hierarchy[1] }, + * [3] { .name =3D "/cpus/cpu1", .type =3D DTPM_NODE_DT, .parent =3D = &hierarchy[1] }, + * [4] { .name =3D "/cpus/cpu2", .type =3D DTPM_NODE_DT, .parent =3D = &hierarchy[1] }, + * [5] { .name =3D "/cpus/cpu3", .type =3D DTPM_NODE_DT, .parent =3D = &hierarchy[1] }, + * [6] { } + * }; + * + * The last element is always an empty one and marks the end of the + * array. + * + * Return: zero on success, a negative value in case of error. Errors + * are reported back from the underlying functions. + */ +int dtpm_create_hierarchy(struct of_device_id *dtpm_match_table) { + const struct of_device_id *match; + const struct dtpm_node *hierarchy; struct dtpm_descr *dtpm_descr; + struct device_node *np; + int ret; + + np =3D of_find_node_by_path("/"); + if (!np) + return -ENODEV; + + match =3D of_match_node(dtpm_match_table, np); =20 + of_node_put(np); + + if (!match) + return -ENODEV; + + hierarchy =3D match->data; + if (!hierarchy) + return -EFAULT; + + ret =3D dtpm_for_each_child(hierarchy, NULL, NULL); + if (ret) + return ret; +=09 + for_each_dtpm_table(dtpm_descr) { + + if (!dtpm_descr->init) + continue; + + dtpm_descr->init(); + } + + return 0; +} +EXPORT_SYMBOL_GPL(dtpm_create_hierarchy); + +static int __init init_dtpm(void) +{ pct =3D powercap_register_control_type(NULL, "dtpm", NULL); if (IS_ERR(pct)) { pr_err("Failed to register control type\n"); return PTR_ERR(pct); } =20 - for_each_dtpm_table(dtpm_descr) - dtpm_descr->init(); - return 0; } -late_initcall(init_dtpm); +fs_initcall_sync(init_dtpm); diff --git a/drivers/powercap/dtpm_cpu.c b/drivers/powercap/dtpm_cpu.c index b740866b228d..6bffb44c75aa 100644 --- a/drivers/powercap/dtpm_cpu.c +++ b/drivers/powercap/dtpm_cpu.c @@ -269,4 +269,4 @@ static int __init dtpm_cpu_init(void) return 0; } =20 -DTPM_DECLARE(dtpm_cpu, dtpm_cpu_init); +DTPM_DECLARE(dtpm_cpu, dtpm_cpu_init, NULL); diff --git a/include/linux/dtpm.h b/include/linux/dtpm.h index d37e5d06a357..5a6b31eaf7e4 100644 --- a/include/linux/dtpm.h +++ b/include/linux/dtpm.h @@ -32,23 +32,39 @@ struct dtpm_ops { void (*release)(struct dtpm *); }; =20 +struct device_node; + typedef int (*dtpm_init_t)(void); +typedef int (*dtpm_setup_t)(struct dtpm *, struct device_node *); =20 struct dtpm_descr { dtpm_init_t init; + dtpm_setup_t setup; +}; + +enum DTPM_NODE_TYPE { + DTPM_NODE_VIRTUAL =3D 0, + DTPM_NODE_DT, +}; + +struct dtpm_node { + enum DTPM_NODE_TYPE type; + const char *name; + struct dtpm_node *parent; }; =20 /* Init section thermal table */ extern struct dtpm_descr __dtpm_table[]; extern struct dtpm_descr __dtpm_table_end[]; =20 -#define DTPM_TABLE_ENTRY(name, __init) \ +#define DTPM_TABLE_ENTRY(name, __init, __setup) \ static struct dtpm_descr __dtpm_table_entry_##name \ __used __section("__dtpm_table") =3D { \ .init =3D __init, \ + .setup =3D __setup, \ } =20 -#define DTPM_DECLARE(name, init) DTPM_TABLE_ENTRY(name, init) +#define DTPM_DECLARE(name, init, setup) DTPM_TABLE_ENTRY(name, init, setup) =20 #define for_each_dtpm_table(__dtpm) \ for (__dtpm =3D __dtpm_table; \ @@ -70,4 +86,5 @@ void dtpm_unregister(struct dtpm *dtpm); =20 int dtpm_register(const char *name, struct dtpm *dtpm, struct dtpm *parent= ); =20 +int dtpm_create_hierarchy(struct of_device_id *dtpm_match_table); #endif --=20 2.25.1 From nobody Wed Jul 1 16:40:04 2026 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 22ECEC433FE for ; Sat, 18 Dec 2021 13:00:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233267AbhLRNAk (ORCPT ); Sat, 18 Dec 2021 08:00:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33118 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231933AbhLRNAh (ORCPT ); Sat, 18 Dec 2021 08:00:37 -0500 Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 79922C06173E for ; Sat, 18 Dec 2021 05:00:36 -0800 (PST) Received: by mail-wm1-x32f.google.com with SMTP id a83-20020a1c9856000000b00344731e044bso3270414wme.1 for ; Sat, 18 Dec 2021 05:00:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=hik1Ew47qtvoaoQPBwSqmP9iF+Hk1zIVyb0fsefpwXU=; b=GzFN4UefBx0laykv6Zwg7pEq1+EAUbsyKbx6AVLTNdAHslCUEN3tBeGnzJroWjsmhh qUhWsji2g2tm27/NZyIG51JJQCSBJ0CqCa2+JQdMd0uAy9Otvl9FhnMoZ7HkiJcG76f4 gu+C+z+i7GqiYsF6KLSuEYxAihpkIC5damwHnVjUHG4EmVj/IFXBSyA2SipJy6vy8lET 9MXfTrIni9eKR2PMHrNeDMNmHnei5TtzQhtKnfeWSUm+ibx80VYY/M6Ez5dgWCKPA/wB uuOV0HRD44DO/ctS2Mg1EiJ/l0koYw+STrXylmet58LA6sEtqUfFHRN6Q8W8tGdSwn16 uUuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=hik1Ew47qtvoaoQPBwSqmP9iF+Hk1zIVyb0fsefpwXU=; b=jrmNfi4JgDtu9XaIb8QICtI18XeryDCSs0iTidgiBRebtYbBZzhYSTxhnUAZ6fdxBA JBL4A0C3h0JCsa6+ytEqk8F4RakIdbQOsKlvMQ05ry6kHf1as3UA3DXuAiqf7YTOEuD4 ef1KqaPD3QDml1IUwwGPuHTNJmv6AmmlexIiyl5Uwf6NIVjrqN8zNAsTQq+AftvZOele sHy3ZhuVuf2gZxVdN3v/DbNqZ7o2QUzJ0TGrKVS62zdTSafMylAagZOfqNA0fkvbHOEl 3UJr2IC7eELZLTfPZSOZyBfwCIoVDKv5R5cobcqQp1ZNL5sDkeMXCPqVhhf2MWv5V/UN QTtA== X-Gm-Message-State: AOAM530eGEdiTt+VsV+2a8GAOCIKwh/isVkoN/0hui81jGxR8l18dJEb ckNi1Dz67237iFYLq6+W+ti+Uw== X-Google-Smtp-Source: ABdhPJwByO/pO1dDzzwFGphL1YqsL1H2rh9fyawiwIX/hNuHVwXE2pcVQ3eqQc71yMLx0PPnvdfuOA== X-Received: by 2002:a05:600c:1f05:: with SMTP id bd5mr6638452wmb.171.1639832435001; Sat, 18 Dec 2021 05:00:35 -0800 (PST) Received: from localhost.localdomain ([2a01:e34:ed2f:f020:1f0f:c9b8:ee5c:5c2f]) by smtp.gmail.com with ESMTPSA id j16sm1465785wms.12.2021.12.18.05.00.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Dec 2021 05:00:34 -0800 (PST) From: Daniel Lezcano To: daniel.lezcano@linaro.org, rjw@rjwysocki.net Cc: lukasz.luba@arm.com, robh@kernel.org, heiko@sntech.de, arnd@linaro.org, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, ulf.hansson@linaro.org, Daniel Lezcano , "Rafael J. Wysocki" Subject: [PATCH v5 3/6] powercap/drivers/dtpm: Add CPU DT initialization support Date: Sat, 18 Dec 2021 14:00:11 +0100 Message-Id: <20211218130014.4037640-4-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211218130014.4037640-1-daniel.lezcano@linaro.org> References: <20211218130014.4037640-1-daniel.lezcano@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Based on the previous DT changes in the core code, use the 'setup' callback to initialize the CPU DTPM backend. Code is reorganized to stick to the DTPM table description. No functional changes. Signed-off-by: Daniel Lezcano Reviewed-by: Ulf Hansson --- drivers/powercap/dtpm_cpu.c | 37 ++++++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/drivers/powercap/dtpm_cpu.c b/drivers/powercap/dtpm_cpu.c index 6bffb44c75aa..ca605911523b 100644 --- a/drivers/powercap/dtpm_cpu.c +++ b/drivers/powercap/dtpm_cpu.c @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -176,6 +177,17 @@ static int cpuhp_dtpm_cpu_offline(unsigned int cpu) } =20 static int cpuhp_dtpm_cpu_online(unsigned int cpu) +{ + struct dtpm_cpu *dtpm_cpu; + + dtpm_cpu =3D per_cpu(dtpm_per_cpu, cpu); + if (dtpm_cpu) + return dtpm_update_power(&dtpm_cpu->dtpm); + + return 0; +} + +static int __dtpm_cpu_setup(int cpu, struct dtpm *parent) { struct dtpm_cpu *dtpm_cpu; struct cpufreq_policy *policy; @@ -183,6 +195,10 @@ static int cpuhp_dtpm_cpu_online(unsigned int cpu) char name[CPUFREQ_NAME_LEN]; int ret =3D -ENOMEM; =20 + dtpm_cpu =3D per_cpu(dtpm_per_cpu, cpu); + if (dtpm_cpu) + return 0; + policy =3D cpufreq_cpu_get(cpu); if (!policy) return 0; @@ -191,10 +207,6 @@ static int cpuhp_dtpm_cpu_online(unsigned int cpu) if (!pd) return -EINVAL; =20 - dtpm_cpu =3D per_cpu(dtpm_per_cpu, cpu); - if (dtpm_cpu) - return dtpm_update_power(&dtpm_cpu->dtpm); - dtpm_cpu =3D kzalloc(sizeof(*dtpm_cpu), GFP_KERNEL); if (!dtpm_cpu) return -ENOMEM; @@ -207,7 +219,7 @@ static int cpuhp_dtpm_cpu_online(unsigned int cpu) =20 snprintf(name, sizeof(name), "cpu%d-cpufreq", dtpm_cpu->cpu); =20 - ret =3D dtpm_register(name, &dtpm_cpu->dtpm, NULL); + ret =3D dtpm_register(name, &dtpm_cpu->dtpm, parent); if (ret) goto out_kfree_dtpm_cpu; =20 @@ -231,7 +243,18 @@ static int cpuhp_dtpm_cpu_online(unsigned int cpu) return ret; } =20 -static int __init dtpm_cpu_init(void) +static int dtpm_cpu_setup(struct dtpm *dtpm, struct device_node *np) +{ + int cpu; + + cpu =3D of_cpu_node_to_id(np); + if (cpu < 0) + return 0; + + return __dtpm_cpu_setup(cpu, dtpm); +} + +static int dtpm_cpu_init(void) { int ret; =20 @@ -269,4 +292,4 @@ static int __init dtpm_cpu_init(void) return 0; } =20 -DTPM_DECLARE(dtpm_cpu, dtpm_cpu_init, NULL); +DTPM_DECLARE(dtpm_cpu, dtpm_cpu_init, dtpm_cpu_setup); --=20 2.25.1 From nobody Wed Jul 1 16:40:04 2026 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 D20A2C4332F for ; Sat, 18 Dec 2021 13:00:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233278AbhLRNAm (ORCPT ); Sat, 18 Dec 2021 08:00:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33134 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233254AbhLRNAj (ORCPT ); Sat, 18 Dec 2021 08:00:39 -0500 Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5C989C06173E for ; Sat, 18 Dec 2021 05:00:38 -0800 (PST) Received: by mail-wm1-x32a.google.com with SMTP id i12so3420450wmq.4 for ; Sat, 18 Dec 2021 05:00:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=XRtSRhv3I6GjbIaBndvp8XiBC8v+f6H0Oym54m9OYJk=; b=Y2AOCv7Kfn4X9cGi87UWfX+lkA31SnWIHSQo7lkXKa/86ubsjsS80kg9ou94lsfeq6 Ed+4gRLsPEK42iatVPGqwkF4fpVahBaIGR2CQtkdtqKNkRjyrP5KP3uYoaNVOUWRexxE N7VqiOx+LIdoDB9UR/6DWGzwNEvDmdZq+lpoiaUAR57dnhll2jxpc2rYUgADUrl+JGh3 X6KmsR5MoRtWeNvN1qrZGqaZ4s7c8hTUL4nyA8PNEtaJnCoR8uBJTnv41oC8DADwvU+e 9o+YMgveHWaXhBVzwNYfzj2KKdV56g95TOG+VsOKF7mbvBimKjsNGEL2mKyCByqdeQPx wYyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=XRtSRhv3I6GjbIaBndvp8XiBC8v+f6H0Oym54m9OYJk=; b=Yh9KnbD86EV9q/HIfPCWf2kxG8ed3auqeUPUVNHuZd4uB9n7Wp4v0YNccn7iCkA+k3 +a1CUDMFHPcEguhOfiQ2o29Fz31VKCZ0Ihs3QtH9HLk6t+AnbAHSXKa8IQ1et67b1lNT GqqNFtSufBuWkFs6tCgMQJ9bUIup0pql1lX3LQErmHKPcqapHEPMyJ/HNaw9dlWFxX+W NNWEF7WS6Tvz5ujtChNm9pltDbISFBzCOVW2ls2j7KokboyrzkKYVP4xvu5Z0YwN9z5n 9jlK+xPZF0W3hetDNt4jV5sSV+Y3o6Q7O3iR/OSL2P2DQ6+cQEftTOtCoBlmD8f9DD2T qKNw== X-Gm-Message-State: AOAM533u3LFtset35tuJFPQ3dzdER7aON8ROT1qyHZc6eTlvNrRRyOhX hDRhUzKcoqP+VdXWCdn7TmK8+A== X-Google-Smtp-Source: ABdhPJz+P72nJND4uskpnWqEqh60n4W45WpWU5viO93fwHtP1aExU91V4shWycbTXMQIn+kVGd+Csw== X-Received: by 2002:a05:600c:a4a:: with SMTP id c10mr5596846wmq.145.1639832436842; Sat, 18 Dec 2021 05:00:36 -0800 (PST) Received: from localhost.localdomain ([2a01:e34:ed2f:f020:1f0f:c9b8:ee5c:5c2f]) by smtp.gmail.com with ESMTPSA id j16sm1465785wms.12.2021.12.18.05.00.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Dec 2021 05:00:36 -0800 (PST) From: Daniel Lezcano To: daniel.lezcano@linaro.org, rjw@rjwysocki.net Cc: lukasz.luba@arm.com, robh@kernel.org, heiko@sntech.de, arnd@linaro.org, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, ulf.hansson@linaro.org, Chanwoo Choi , Kyungmin Park , MyungJoo Ham , "Rafael J. Wysocki" , Daniel Lezcano Subject: [PATCH v5 4/6] powercap/drivers/dtpm: Add dtpm devfreq with energy model support Date: Sat, 18 Dec 2021 14:00:12 +0100 Message-Id: <20211218130014.4037640-5-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211218130014.4037640-1-daniel.lezcano@linaro.org> References: <20211218130014.4037640-1-daniel.lezcano@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Currently the dtpm supports the CPUs via cpufreq and the energy model. This change provides the same for the device which supports devfreq. Each device supporting devfreq and having an energy model can be added to the hierarchy. The concept is the same as the cpufreq DTPM support: the QoS is used to aggregate the requests and the energy model gives the value of the instantaneous power consumption ponderated by the load of the device. Cc: Chanwoo Choi Cc: Lukasz Luba Cc: Kyungmin Park Cc: MyungJoo Ham Signed-off-by: Daniel Lezcano --- drivers/powercap/Kconfig | 7 ++ drivers/powercap/Makefile | 1 + drivers/powercap/dtpm_devfreq.c | 201 ++++++++++++++++++++++++++++++++ 3 files changed, 209 insertions(+) create mode 100644 drivers/powercap/dtpm_devfreq.c diff --git a/drivers/powercap/Kconfig b/drivers/powercap/Kconfig index b1ca339957e3..515e3ceb3393 100644 --- a/drivers/powercap/Kconfig +++ b/drivers/powercap/Kconfig @@ -57,4 +57,11 @@ config DTPM_CPU help This enables support for CPU power limitation based on energy model. + +config DTPM_DEVFREQ + bool "Add device power capping based on the energy model" + depends on DTPM && ENERGY_MODEL + help + This enables support for device power limitation based on + energy model. endif diff --git a/drivers/powercap/Makefile b/drivers/powercap/Makefile index fabcf388a8d3..494617cdad88 100644 --- a/drivers/powercap/Makefile +++ b/drivers/powercap/Makefile @@ -1,6 +1,7 @@ # SPDX-License-Identifier: GPL-2.0-only obj-$(CONFIG_DTPM) +=3D dtpm.o obj-$(CONFIG_DTPM_CPU) +=3D dtpm_cpu.o +obj-$(CONFIG_DTPM_DEVFREQ) +=3D dtpm_devfreq.o obj-$(CONFIG_POWERCAP) +=3D powercap_sys.o obj-$(CONFIG_INTEL_RAPL_CORE) +=3D intel_rapl_common.o obj-$(CONFIG_INTEL_RAPL) +=3D intel_rapl_msr.o diff --git a/drivers/powercap/dtpm_devfreq.c b/drivers/powercap/dtpm_devfre= q.c new file mode 100644 index 000000000000..fd3817f71f44 --- /dev/null +++ b/drivers/powercap/dtpm_devfreq.c @@ -0,0 +1,201 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright 2021 Linaro Limited + * + * Author: Daniel Lezcano + * + * The devfreq device combined with the energy model and the load can + * give an estimation of the power consumption as well as limiting the + * power. + * + */ +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt + +#include +#include +#include +#include +#include +#include +#include +#include + +struct dtpm_devfreq { + struct dtpm dtpm; + struct dev_pm_qos_request qos_req; + struct devfreq *devfreq; +}; + +static struct dtpm_devfreq *to_dtpm_devfreq(struct dtpm *dtpm) +{ + return container_of(dtpm, struct dtpm_devfreq, dtpm); +} + +static int update_pd_power_uw(struct dtpm *dtpm) +{ + struct dtpm_devfreq *dtpm_devfreq =3D to_dtpm_devfreq(dtpm); + struct devfreq *devfreq =3D dtpm_devfreq->devfreq; + struct device *dev =3D devfreq->dev.parent; + struct em_perf_domain *pd =3D em_pd_get(dev); + + dtpm->power_min =3D pd->table[0].power; + dtpm->power_min *=3D MICROWATT_PER_MILLIWATT; + + dtpm->power_max =3D pd->table[pd->nr_perf_states - 1].power; + dtpm->power_max *=3D MICROWATT_PER_MILLIWATT; + + return 0; +} + +static u64 set_pd_power_limit(struct dtpm *dtpm, u64 power_limit) +{ + struct dtpm_devfreq *dtpm_devfreq =3D to_dtpm_devfreq(dtpm); + struct devfreq *devfreq =3D dtpm_devfreq->devfreq; + struct device *dev =3D devfreq->dev.parent; + struct em_perf_domain *pd =3D em_pd_get(dev); + unsigned long freq; + u64 power; + int i; + + for (i =3D 0; i < pd->nr_perf_states; i++) { + + power =3D pd->table[i].power * MICROWATT_PER_MILLIWATT; + if (power > power_limit) + break; + } + + freq =3D pd->table[i - 1].frequency; + + dev_pm_qos_update_request(&dtpm_devfreq->qos_req, freq); + + power_limit =3D pd->table[i - 1].power * MICROWATT_PER_MILLIWATT; + + return power_limit; +} + +static void _normalize_load(struct devfreq_dev_status *status) +{ + if (status->total_time > 0xfffff) { + status->total_time >>=3D 10; + status->busy_time >>=3D 10; + } + + status->busy_time <<=3D 10; + status->busy_time /=3D status->total_time ? : 1; + + status->busy_time =3D status->busy_time ? : 1; + status->total_time =3D 1024; +} + +static u64 get_pd_power_uw(struct dtpm *dtpm) +{ + struct dtpm_devfreq *dtpm_devfreq =3D to_dtpm_devfreq(dtpm); + struct devfreq *devfreq =3D dtpm_devfreq->devfreq; + struct device *dev =3D devfreq->dev.parent; + struct em_perf_domain *pd =3D em_pd_get(dev); + struct devfreq_dev_status status; + unsigned long freq; + u64 power; + int i; + + mutex_lock(&devfreq->lock); + status =3D devfreq->last_status; + mutex_unlock(&devfreq->lock); + + freq =3D DIV_ROUND_UP(status.current_frequency, HZ_PER_KHZ); + _normalize_load(&status); + + for (i =3D 0; i < pd->nr_perf_states; i++) { + + if (pd->table[i].frequency < freq) + continue; + + power =3D pd->table[i].power * MICROWATT_PER_MILLIWATT; + power *=3D status.busy_time; + power >>=3D 10; + + return power; + } + + return 0; +} + +static void pd_release(struct dtpm *dtpm) +{ + struct dtpm_devfreq *dtpm_devfreq =3D to_dtpm_devfreq(dtpm); + + if (dev_pm_qos_request_active(&dtpm_devfreq->qos_req)) + dev_pm_qos_remove_request(&dtpm_devfreq->qos_req); + + kfree(dtpm_devfreq); +} + +static struct dtpm_ops dtpm_ops =3D { + .set_power_uw =3D set_pd_power_limit, + .get_power_uw =3D get_pd_power_uw, + .update_power_uw =3D update_pd_power_uw, + .release =3D pd_release, +}; + +static int __dtpm_devfreq_setup(struct devfreq *devfreq, struct dtpm *pare= nt) +{ + struct device *dev =3D devfreq->dev.parent; + struct dtpm_devfreq *dtpm_devfreq; + struct em_perf_domain *pd; + int ret =3D -ENOMEM; + + pd =3D em_pd_get(dev); + if (!pd) { + ret =3D dev_pm_opp_of_register_em(dev, NULL); + if (ret) { + pr_err("No energy model available for '%s'\n", dev_name(dev)); + return -EINVAL; + } + } + + dtpm_devfreq =3D kzalloc(sizeof(*dtpm_devfreq), GFP_KERNEL); + if (!dtpm_devfreq) + return -ENOMEM; + + dtpm_init(&dtpm_devfreq->dtpm, &dtpm_ops); + + dtpm_devfreq->devfreq =3D devfreq; + + ret =3D dtpm_register(dev_name(dev), &dtpm_devfreq->dtpm, parent); + if (ret) { + pr_err("Failed to register '%s': %d\n", dev_name(dev), ret); + goto out_dtpm_devfreq; + } + + ret =3D dev_pm_qos_add_request(dev, &dtpm_devfreq->qos_req, + DEV_PM_QOS_MAX_FREQUENCY, + PM_QOS_MAX_FREQUENCY_DEFAULT_VALUE); + if (ret) { + pr_err("Failed to add QoS request: %d\n", ret); + goto out_dtpm_unregister; + } + + dtpm_update_power(&dtpm_devfreq->dtpm); + + return 0; + +out_dtpm_unregister: + dtpm_unregister(&dtpm_devfreq->dtpm); +out_dtpm_devfreq: + kfree(dtpm_devfreq); + + return ret; +} + +static int dtpm_devfreq_setup(struct dtpm *dtpm, struct device_node *np) +{ + struct devfreq *devfreq; + + devfreq =3D devfreq_get_devfreq_by_node(np); + if (IS_ERR(devfreq)) + return 0; + + return __dtpm_devfreq_setup(devfreq, dtpm); +} + +DTPM_DECLARE(dtpm_dev, NULL, dtpm_devfreq_setup); --=20 2.25.1 From nobody Wed Jul 1 16:40:04 2026 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 A0DAFC4332F for ; Sat, 18 Dec 2021 13:00:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233254AbhLRNAt (ORCPT ); Sat, 18 Dec 2021 08:00:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33150 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233283AbhLRNAm (ORCPT ); Sat, 18 Dec 2021 08:00:42 -0500 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 794F6C061401 for ; Sat, 18 Dec 2021 05:00:42 -0800 (PST) Received: by mail-wr1-x431.google.com with SMTP id j18so9416365wrd.2 for ; Sat, 18 Dec 2021 05:00:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=bFrG3jh1s5lAFnowWpm51QcHRy95WOWLO0hOKfLwkAQ=; b=h4X0nR9C/gIczMARHZo3uC+j/8Z2sId88Si8wlDGqCUt4kajYq+3wPntNdZyiy0fIX 7S/+1HawPe87vjZtswRqbxXlQGZ6n9RT9cHanwSNaXlMvAq5G5qv7DZ+gFSeIV1ybF41 VO+B5kODFNDtJMvvOax7rQHaSZFN6lVhWrOCWLI2UziVBb58Y+2hHA0yGp0tnr7WzBWE fNZPzY/lErvwKC+k1qE+ofcX7MIgLo8PPG66kaNErZrfrFuaR2WeV4aOq1l5vAB5btb3 nTJgw2lAY55Jee6TEIeLOrWFc45Sd3yXJxxzf5cBYYOwWOFtbX+BT4IJ4nx7gRV+3DeZ rQ7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=bFrG3jh1s5lAFnowWpm51QcHRy95WOWLO0hOKfLwkAQ=; b=UBnnHbXbr//1yI57i8b0cvaX6QYfog8tmmnlDIZyjAvtfi9qI5n97U/15GK3x6lkTT ltjQ4HOETakWHJPONIcGAwXXcsMEgHWxLsuhCOE3y62bbLPDOJRl/IhrXQ6HuLwPpMtt IaJ+t2YvuyZBrZSQc2pg6Gd5xfRYFRQdwTsRZkuBYkMp8aFAOAZD0qCt3p/gqFEf43hw PVxa9AJEx2Vw4FuJOLQwOMXW4+f8SAeqBJ7h2d4sMrwA8TQWVzyM4y4QnrnmCsO9YB0p lfKDuJD/3sSUbDsbU48h8b4mBRVap3MOKQyB+nIJ7L82EO7HAtsWukM18wwtKjfAx0z4 lKTw== X-Gm-Message-State: AOAM532l+HNsCx+cTQxYIfrSNDVdXLDzbAXlrjOvuy+8VfNuym/mEmyI f52bKbLbL6XwqO2H7fgJVg1V9A== X-Google-Smtp-Source: ABdhPJwQJq2AfoqfQVqk3a7iBERI4zg3RIYnxZCE9RJKE8RaDu3lhZqX9mQXoSWx5OoqfDCBv9GgdQ== X-Received: by 2002:a05:6000:18ad:: with SMTP id b13mr6142117wri.195.1639832441000; Sat, 18 Dec 2021 05:00:41 -0800 (PST) Received: from localhost.localdomain ([2a01:e34:ed2f:f020:1f0f:c9b8:ee5c:5c2f]) by smtp.gmail.com with ESMTPSA id j16sm1465785wms.12.2021.12.18.05.00.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Dec 2021 05:00:40 -0800 (PST) From: Daniel Lezcano To: daniel.lezcano@linaro.org, rjw@rjwysocki.net Cc: lukasz.luba@arm.com, robh@kernel.org, heiko@sntech.de, arnd@linaro.org, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, ulf.hansson@linaro.org, Geert Uytterhoeven , linux-arm-kernel@lists.infradead.org (moderated list:ARM/Rockchip SoC support), linux-rockchip@lists.infradead.org (open list:ARM/Rockchip SoC support) Subject: [PATCH v5 5/6] rockchip/soc/drivers: Add DTPM description for rk3399 Date: Sat, 18 Dec 2021 14:00:13 +0100 Message-Id: <20211218130014.4037640-6-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211218130014.4037640-1-daniel.lezcano@linaro.org> References: <20211218130014.4037640-1-daniel.lezcano@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The DTPM framework does support now the hierarchy description. The platform specific code can call the hierarchy creation function with an array of struct dtpm_node pointing to their parent. This patch provides a description of the big and Little CPUs and the GPU and tie them together under a virtual package name. Only rk3399 is described now. The description could be extended in the future with the memory controller with devfreq if it has the energy information. The hierarchy uses the GPU devfreq with the panfrost driver, and this one could be loaded as a module. If the hierarchy is created before the panfrost driver is loaded, it will fail. For this reason the Kconfig option depends on the panfrost Kconfig's option. If this one is compiled as a module, automatically the dtpm hierarchy code will be a module also. Module loading ordering will fix this chicken-egg problem. Signed-off-by: Daniel Lezcano --- drivers/soc/rockchip/Kconfig | 8 +++++ drivers/soc/rockchip/Makefile | 1 + drivers/soc/rockchip/dtpm.c | 56 +++++++++++++++++++++++++++++++++++ 3 files changed, 65 insertions(+) create mode 100644 drivers/soc/rockchip/dtpm.c diff --git a/drivers/soc/rockchip/Kconfig b/drivers/soc/rockchip/Kconfig index 25eb2c1e31bb..a88fe6d3064a 100644 --- a/drivers/soc/rockchip/Kconfig +++ b/drivers/soc/rockchip/Kconfig @@ -34,4 +34,12 @@ config ROCKCHIP_PM_DOMAINS =20 If unsure, say N. =20 +config ROCKCHIP_DTPM + tristate "Rockchip DTPM hierarchy" + depends on DTPM && DRM_PANFROST + help + Describe the hierarchy for the Dynamic Thermal Power + Management tree on this platform. That will create all the + power capping capable devices. + endif diff --git a/drivers/soc/rockchip/Makefile b/drivers/soc/rockchip/Makefile index 875032f7344e..05f31a4e743c 100644 --- a/drivers/soc/rockchip/Makefile +++ b/drivers/soc/rockchip/Makefile @@ -5,3 +5,4 @@ obj-$(CONFIG_ROCKCHIP_GRF) +=3D grf.o obj-$(CONFIG_ROCKCHIP_IODOMAIN) +=3D io-domain.o obj-$(CONFIG_ROCKCHIP_PM_DOMAINS) +=3D pm_domains.o +obj-$(CONFIG_ROCKCHIP_DTPM) +=3D dtpm.o diff --git a/drivers/soc/rockchip/dtpm.c b/drivers/soc/rockchip/dtpm.c new file mode 100644 index 000000000000..77edc565c110 --- /dev/null +++ b/drivers/soc/rockchip/dtpm.c @@ -0,0 +1,56 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright 2021 Linaro Limited + * + * Author: Daniel Lezcano + * + * DTPM hierarchy description + */ +#include +#include +#include +#include + +static struct dtpm_node __initdata rk3399_hierarchy[] =3D { + [0]{ .name =3D "rk3399" }, + [1]{ .name =3D "package", + .parent =3D &rk3399_hierarchy[0] }, + [2]{ .name =3D "/cpus/cpu@0", + .type =3D DTPM_NODE_DT, + .parent =3D &rk3399_hierarchy[1] }, + [3]{ .name =3D "/cpus/cpu@1", + .type =3D DTPM_NODE_DT, + .parent =3D &rk3399_hierarchy[1] }, + [4]{ .name =3D "/cpus/cpu@2", + .type =3D DTPM_NODE_DT, + .parent =3D &rk3399_hierarchy[1] }, + [5]{ .name =3D "/cpus/cpu@3", + .type =3D DTPM_NODE_DT, + .parent =3D &rk3399_hierarchy[1] }, + [6]{ .name =3D "/cpus/cpu@100", + .type =3D DTPM_NODE_DT, + .parent =3D &rk3399_hierarchy[1] }, + [7]{ .name =3D "/cpus/cpu@101", + .type =3D DTPM_NODE_DT, + .parent =3D &rk3399_hierarchy[1] }, + [8]{ .name =3D "rockchip,rk3399-mali", + .type =3D DTPM_NODE_DT, + .parent =3D &rk3399_hierarchy[1] }, + [9]{ }, +}; + +static struct of_device_id __initdata rockchip_dtpm_match_table[] =3D { + { .compatible =3D "rockchip,rk3399", .data =3D rk3399_hierarchy }, + {}, +}; + +static int __init rockchip_dtpm_init(void) +{ + return dtpm_create_hierarchy(rockchip_dtpm_match_table); +} +late_initcall(rockchip_dtpm_init); + +MODULE_DESCRIPTION("Rockchip DTPM driver"); +MODULE_LICENSE("GPL"); +MODULE_ALIAS("platform:dtpm"); +MODULE_AUTHOR("Daniel Lezcano 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 E8287C433EF for ; Sat, 18 Dec 2021 13:00:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233277AbhLRNAw (ORCPT ); Sat, 18 Dec 2021 08:00:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33168 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233184AbhLRNAq (ORCPT ); Sat, 18 Dec 2021 08:00:46 -0500 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3E829C061747 for ; Sat, 18 Dec 2021 05:00:44 -0800 (PST) Received: by mail-wr1-x430.google.com with SMTP id t26so9382113wrb.4 for ; Sat, 18 Dec 2021 05:00:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=p5i8bAyKNCVvvWULTiQQCBvHxMUgvB2ssJ2ppV6n34w=; b=ydyFnsfD0j+C/gkrXEBeottbW99utAA/sHLtcRwhIV96kBnR+kfAxiD804powfEdk3 ESRlm07ZyRHgcy0GXsdDDVTyepYfgM4cCrHVqBhN18vLwSeyaZijRkkEOFLjsQQDDgDw O4315YNQUfUL6GBHqaQ15dOHXQfp11u/HitiBLwoBJJePbDScrP3vxTwX4NN4G/Y/2d2 q6tcBpa4zVIA7S8P1OBo6XEY6miO366xOg/sy15cmckMSzPPquYfS+dJL7srkMI/yfE5 0+KH7frWDAr1SY8W7TUeEIcewXYTz8ezpcU31B3rAA3LcMf3tIEevPZqrZv6nXNiEKFw f83w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=p5i8bAyKNCVvvWULTiQQCBvHxMUgvB2ssJ2ppV6n34w=; b=XDjg9RR5XNJr7i7bRffQQcnbzvAC+TWEnDFpqYlkGuQBGVB1jC8dA/ObPkV3pcmbBp CmWmIaVV7uQfMIHzRYZCIN+RMhJjGCl0j2c4OSwWVf153ftkYzqCBaw2jJ9i5nv3+9PP E+OiBVkBaWqJxe7QfjxSa5B6l50U0VAHPGeri2B1jM57f27k/0RpV+91nDHMNchQ1snl TwNU/WuIDY2t/ph0I5axJRJA9YsdqMDKbn/CjjHuqRRKyKz1dUmJNjzU3F8HJmqMcuHU qZib/HTimBwR3K0SE5XjjN9YsXC79g17RNZVK7+qIxfpSZlVyUBIS7XaXSwu3eakf0gR CEUQ== X-Gm-Message-State: AOAM531RFWCRmwFJcFImkcWdJ4YQ1H083Svfi7iggG32GD3AHr0cNXZQ Nf46VYjh6Z/Da+YYW+o5rbgSWw== X-Google-Smtp-Source: ABdhPJys+xI4SwBaTi9xDAxJhmT8aMjKzm6rvNQgmGmf6cpusjutiCLuPZdAGACX4Zk4RK0Me0NI6Q== X-Received: by 2002:a5d:42d2:: with SMTP id t18mr1281979wrr.271.1639832442739; Sat, 18 Dec 2021 05:00:42 -0800 (PST) Received: from localhost.localdomain ([2a01:e34:ed2f:f020:1f0f:c9b8:ee5c:5c2f]) by smtp.gmail.com with ESMTPSA id j16sm1465785wms.12.2021.12.18.05.00.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Dec 2021 05:00:42 -0800 (PST) From: Daniel Lezcano To: daniel.lezcano@linaro.org, rjw@rjwysocki.net Cc: lukasz.luba@arm.com, robh@kernel.org, heiko@sntech.de, arnd@linaro.org, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, ulf.hansson@linaro.org, Andy Gross , Bjorn Andersson , linux-arm-msm@vger.kernel.org (open list:ARM/QUALCOMM SUPPORT) Subject: [PATCH v5 6/6] qcom/soc/drivers: Add DTPM description for sdm845 Date: Sat, 18 Dec 2021 14:00:14 +0100 Message-Id: <20211218130014.4037640-7-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211218130014.4037640-1-daniel.lezcano@linaro.org> References: <20211218130014.4037640-1-daniel.lezcano@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The DTPM framework does support now the hierarchy description. The platform specific code can call the hierarchy creation function with an array of struct dtpm_node pointing to their parents. This patch provides a description of the big and Little CPUs and the GPU and tie them together under a virtual package name. Only sdm845 is described. The description could be extended in the future with the memory controller with devfreq if it has the energy information. Signed-off-by: Daniel Lezcano --- drivers/soc/qcom/Kconfig | 9 ++++++ drivers/soc/qcom/Makefile | 1 + drivers/soc/qcom/dtpm.c | 65 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 75 insertions(+) create mode 100644 drivers/soc/qcom/dtpm.c diff --git a/drivers/soc/qcom/Kconfig b/drivers/soc/qcom/Kconfig index e718b8735444..f21c1df2f2f9 100644 --- a/drivers/soc/qcom/Kconfig +++ b/drivers/soc/qcom/Kconfig @@ -228,4 +228,13 @@ config QCOM_APR application processor and QDSP6. APR is used by audio driver to configure QDSP6 ASM, ADM and AFE modules. + +config QCOM_DTPM + tristate "Qualcomm DTPM hierarchy" + depends on DTPM + help + Describe the hierarchy for the Dynamic Thermal Power + Management tree on this platform. That will create all the + power capping capable devices. + endmenu diff --git a/drivers/soc/qcom/Makefile b/drivers/soc/qcom/Makefile index 70d5de69fd7b..cf38496c3f61 100644 --- a/drivers/soc/qcom/Makefile +++ b/drivers/soc/qcom/Makefile @@ -28,3 +28,4 @@ obj-$(CONFIG_QCOM_LLCC) +=3D llcc-qcom.o obj-$(CONFIG_QCOM_RPMHPD) +=3D rpmhpd.o obj-$(CONFIG_QCOM_RPMPD) +=3D rpmpd.o obj-$(CONFIG_QCOM_KRYO_L2_ACCESSORS) +=3D kryo-l2-accessors.o +obj-$(CONFIG_QCOM_DTPM) +=3D dtpm.o diff --git a/drivers/soc/qcom/dtpm.c b/drivers/soc/qcom/dtpm.c new file mode 100644 index 000000000000..c15283f59494 --- /dev/null +++ b/drivers/soc/qcom/dtpm.c @@ -0,0 +1,65 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright 2021 Linaro Limited + * + * Author: Daniel Lezcano + * + * DTPM hierarchy description + */ +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt + +#include +#include +#include +#include + +static struct dtpm_node __initdata sdm845_hierarchy[] =3D { + [0]{ .name =3D "sdm845" }, + [1]{ .name =3D "package", + .parent =3D &sdm845_hierarchy[0] }, + [2]{ .name =3D "/cpus/cpu@0", + .type =3D DTPM_NODE_DT, + .parent =3D &sdm845_hierarchy[1] }, + [3]{ .name =3D "/cpus/cpu@100", + .type =3D DTPM_NODE_DT, + .parent =3D &sdm845_hierarchy[1] }, + [4]{ .name =3D "/cpus/cpu@200", + .type =3D DTPM_NODE_DT, + .parent =3D &sdm845_hierarchy[1] }, + [5]{ .name =3D "/cpus/cpu@300", + .type =3D DTPM_NODE_DT, + .parent =3D &sdm845_hierarchy[1] }, + [6]{ .name =3D "/cpus/cpu@400", + .type =3D DTPM_NODE_DT, + .parent =3D &sdm845_hierarchy[1] }, + [7]{ .name =3D "/cpus/cpu@500", + .type =3D DTPM_NODE_DT, + .parent =3D &sdm845_hierarchy[1] }, + [8]{ .name =3D "/cpus/cpu@600", + .type =3D DTPM_NODE_DT, + .parent =3D &sdm845_hierarchy[1] }, + [9]{ .name =3D "/cpus/cpu@700", + .type =3D DTPM_NODE_DT, + .parent =3D &sdm845_hierarchy[1] }, + [10]{ .name =3D "/soc@0/gpu@5000000", + .type =3D DTPM_NODE_DT, + .parent =3D &sdm845_hierarchy[1] }, + [11]{ }, +}; + +static struct of_device_id __initdata sdm845_dtpm_match_table[] =3D { + { .compatible =3D "qcom,sdm845", .data =3D sdm845_hierarchy }, + {}, +}; + +static int __init sdm845_dtpm_init(void) +{ + return dtpm_create_hierarchy(sdm845_dtpm_match_table); +} +late_initcall(sdm845_dtpm_init); + +MODULE_DESCRIPTION("Qualcomm DTPM driver"); +MODULE_LICENSE("GPL"); +MODULE_ALIAS("platform:dtpm"); +MODULE_AUTHOR("Daniel Lezcano