From patchwork Tue Aug 20 00:00:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Hilman X-Patchwork-Id: 13769195 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7D023C3DA4A for ; Tue, 20 Aug 2024 00:01:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References :Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=sLE5hAB62v7p1beN0KLDfInOowT8azj61EJTe8F9z3I=; b=eSjrmxKQQSTLMLLHzjVOAK0f3x o5zy4WX1zJn9Fz1Tg3HI8ma+4f662pbxy+iz6V0Us7QLlhFRtIMRp7wlmwDYo3iH1RPJ6J1j/676d J3GCj7/oEk9yx3pRWLdrSp2V5iDiTqGZHO9WMQRf9zVLtkTjPZNKwIW6+PhetIWxbFBaxu/iolYaY 0+5qQkXubMXhTu2DqFLCO/354qntBtsJfoxmKxVOyFpGxzdLVG4AL4T7HxCamlTtWdj8ruOironnV k1luzKS/BjBI/XQYahX3sZGEWqKs4fBBQBrvYchoLyk/HJqDyaU8Vf+AwDIvtbAeMj0zKHB9wah44 AedvCz4A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sgCJF-00000003HO2-2Oq2; Tue, 20 Aug 2024 00:01:13 +0000 Received: from mail-pj1-x102b.google.com ([2607:f8b0:4864:20::102b]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sgCIX-00000003HDv-3eUY for linux-arm-kernel@lists.infradead.org; Tue, 20 Aug 2024 00:00:31 +0000 Received: by mail-pj1-x102b.google.com with SMTP id 98e67ed59e1d1-2d3c08541cdso3588907a91.2 for ; Mon, 19 Aug 2024 17:00:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1724112029; x=1724716829; darn=lists.infradead.org; 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=sLE5hAB62v7p1beN0KLDfInOowT8azj61EJTe8F9z3I=; b=kqjL3rQNLHBEtf+2Ykb8h/kAN7SlsL7QxyrLngz1IXFyh+z20XYYv+RUzUnTuLnXYe fEcnRPgxGI8W01jL4CcAkFLw+mo0NkJBnqS3APqVPuT75F7lN7brzXxORG9HP+6k0eRS D4m4TFrEFrJyXEWPox9oxVqizQltg1J5mmSkz+aj1ZnCkc38n1OqYAfIEYL+xjYNvP5z Z1CDPpBcl2co0Q61rXm+Qpn6TfVjaNwZkc1n+UsXZsnO96332FXvgOzmXsMhVGQrH/Cz VMSo6qCq0XoGJkVSpoAV7Dsva7POIIaWYnz1OKB2KzD0JrSFAQ8I+q2i7jQZnUzUSxhj x5xg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724112029; x=1724716829; 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=sLE5hAB62v7p1beN0KLDfInOowT8azj61EJTe8F9z3I=; b=iRUxuJ59beTTvznHYKrLjTPgXdJSOazZJ9nYd10eUC5I6UgMkhiIDnIlP42YNtk9/l hEUYHWvUMI+yVcEQrt7+RJNMZZKHpQFMtgVZqMDtHmXkCBgiQk4qeUMwkfGadll7tN94 em3ygxrnwySoDz6oolUaCRO9cqql83o7OXD0D2BISoDOz5vt6UFd4AgK3I1BopDq8gx8 H+1cQS+AGOZVCFnBv7K32TlEEUfbzidVT2S+L6rgN9KHDbwb+YPiuAod3L77lKOVdMbA t8jCQ7zXgDyl8XZeGHcnizDj1Pxu8m195vwSEgXaI3yV5FWj60dhlvZhInq6Lxt7DAZx xHmQ== X-Forwarded-Encrypted: i=1; AJvYcCU6Y1+ac7hbuD0hdKAclruvDMHrMUvn7tGz/XiV5LY9lDbPL/UCwJXzlBhL+CPKdEcKYRnrfmGAPr4MrbY6k7ng@lists.infradead.org X-Gm-Message-State: AOJu0YwnFdVfX5bfievUCJJ88Ig2fnXNf4xafGP6+1CMEfLbyHEqEmU+ ZaqpORlNjRZhDwc6W7YNqvefuqiAbBu6p7h19YNDdax7KZGARurCdtIvjROsb+A= X-Google-Smtp-Source: AGHT+IF3qZLIeCayxsLpMAWoTFuVPjgH1YPTWPIw/WqvEfRwrWzcax1rN4IpM+MAAYfrKW8qcN1A4w== X-Received: by 2002:a17:90b:33c2:b0:2d3:da6d:8330 with SMTP id 98e67ed59e1d1-2d5c0d79fe4mr726670a91.4.1724112028390; Mon, 19 Aug 2024 17:00:28 -0700 (PDT) Received: from localhost ([71.212.170.185]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2d3e3076130sm7955195a91.29.2024.08.19.17.00.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Aug 2024 17:00:28 -0700 (PDT) From: Kevin Hilman Date: Mon, 19 Aug 2024 17:00:11 -0700 Subject: [PATCH v2 1/3] pmdomain: ti_sci: add per-device latency constraint management MIME-Version: 1.0 Message-Id: <20240819-lpm-v6-10-constraints-pmdomain-v2-1-461325a6008f@baylibre.com> References: <20240819-lpm-v6-10-constraints-pmdomain-v2-0-461325a6008f@baylibre.com> In-Reply-To: <20240819-lpm-v6-10-constraints-pmdomain-v2-0-461325a6008f@baylibre.com> To: Ulf Hansson , linux-pm@vger.kernel.org Cc: Nishanth Menon , Vibhore Vardhan , Dhruva Gole , Akashdeep Kaur , Sebin Francis , Markus Schneider-Pargmann , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=openpgp-sha256; l=3743; i=khilman@baylibre.com; h=from:subject:message-id; bh=EsyOvHfUW/kIQJ0oYk1mZTfySSyGRxhdYE3KKRCGBak=; b=owEBbQKS/ZANAwAKAVk3GJrT+8ZlAcsmYgBmw9yavh3GVW7GdVcsaxRa3+zt6YHIUgUUkm+PB xaznFP/seGJAjMEAAEKAB0WIQR7h0YOFpJ/qfW/8QxZNxia0/vGZQUCZsPcmgAKCRBZNxia0/vG ZXaqD/9kEDcKjRDUuwAvfCW4lDul+xVVGKxjHy87Bc/XdpCDVJpMhCgaPnmwPaNZahraaii+WDc A/ikrbMk9jpbcRYi7RxIge80STHu3Re5Pk3OqI9flWtuQ4gCt8gAnXkPG8PYLvbsOIvG5XcuVs9 S30gGsGoQAUpJodgGrAIKNr/9TFhTFO6jGnFvWmXZ/BuGoRg73H2rXhTkrBHq2iYcfYQwcJH69d bPOMIGkk5eWMBspqH9pkvoqmR31aHUol5vro5ANeCMTvt7etKD/ug2qa6H9xkxMLxAQDP/vADXZ qevQIIw64jReIj8qbmjACgu2gyBLHqvsfjGDo3zEEKMzjFQz7iEV4D8njkqtdCy7FNgwsu9lDXG GkYgV0/ecBT+HMg9rn0TSkeQ3RjSmryLWbk2vmTQUwYrkM4plp67a3Az3xugrFsUW1VIc/LKO3X z3WXnnBuU7/BGZYNFWgrh6luqGgFhiiwxOTfmdtYgkIp8XF6lY0a3TeVTv6bL8PxjHlGcrdWct6 qrQFvxRyjh+6lalWWO72eHaBduZr6plINvEPjfwH34RhjO3ysRojgOwA+oop9KO54SsmfgkAyFa y2S3L5R6zC4pahzXCS/qTYy95trffxQg7Nq0Vg3XYvxh5ZZuyKPJIvecc9vCXR0arF6in5lDCYN cBBvQIb14J/+Iig== X-Developer-Key: i=khilman@baylibre.com; a=openpgp; fpr=7B87460E16927FA9F5BFF10C5937189AD3FBC665 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240819_170029_950212_17FC22E6 X-CRM114-Status: GOOD ( 17.61 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org For each device in a TI SCI PM domain, check whether the device has any resume latency constraints set via per-device PM QoS. If constraints are set, send them to DM via the new SCI constraints API. Checking for constraints happen for each device before system-wide suspend (via ->suspend() hook.) An important detail here is that the PM domain driver inserts itself into the path of both the ->suspend() and ->resume() hook path of *all* devices in the PM domain. This allows generic PM domain code to handle the constraint management and communication with TI SCI. Further, this allows device drivers to use existing PM QoS APIs to add/update constraints. DM firmware clears constraints during its resume, so Linux has to check/update/send constraints each time system suspends. Co-developed-by: Vibhore Vardhan Signed-off-by: Vibhore Vardhan Signed-off-by: Kevin Hilman Signed-off-by: Dhruva Gole --- drivers/pmdomain/ti/ti_sci_pm_domains.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/drivers/pmdomain/ti/ti_sci_pm_domains.c b/drivers/pmdomain/ti/ti_sci_pm_domains.c index 1510d5ddae3d..963272fa387b 100644 --- a/drivers/pmdomain/ti/ti_sci_pm_domains.c +++ b/drivers/pmdomain/ti/ti_sci_pm_domains.c @@ -13,6 +13,8 @@ #include #include #include +#include +#include #include #include @@ -51,6 +53,29 @@ struct ti_sci_pm_domain { #define genpd_to_ti_sci_pd(gpd) container_of(gpd, struct ti_sci_pm_domain, pd) +static inline bool ti_sci_pd_is_valid_constraint(s32 val) +{ + return val != PM_QOS_RESUME_LATENCY_NO_CONSTRAINT; +} + +static int ti_sci_pd_set_lat_constraint(struct device *dev, s32 val) +{ + struct generic_pm_domain *genpd = pd_to_genpd(dev->pm_domain); + struct ti_sci_pm_domain *pd = genpd_to_ti_sci_pd(genpd); + const struct ti_sci_handle *ti_sci = pd->parent->ti_sci; + int ret; + + ret = ti_sci->ops.pm_ops.set_latency_constraint(ti_sci, val, TISCI_MSG_CONSTRAINT_SET); + if (ret) + dev_err(dev, "ti_sci_pd: set latency constraint failed: ret=%d\n", + ret); + else + dev_dbg(dev, "ti_sci_pd: ID:%d set latency constraint %d\n", + pd->idx, val); + + return ret; +} + /* * ti_sci_pd_power_off(): genpd power down hook * @domain: pointer to the powerdomain to power off @@ -79,6 +104,22 @@ static int ti_sci_pd_power_on(struct generic_pm_domain *domain) return ti_sci->ops.dev_ops.get_device(ti_sci, pd->idx); } +static int ti_sci_pd_suspend(struct device *dev) +{ + int ret; + s32 val; + + ret = pm_generic_suspend(dev); + if (ret) + return ret; + + val = dev_pm_qos_read_value(dev, DEV_PM_QOS_RESUME_LATENCY); + if (ti_sci_pd_is_valid_constraint(val)) + ti_sci_pd_set_lat_constraint(dev, val); + + return 0; +} + /* * ti_sci_pd_xlate(): translation service for TI SCI genpds * @genpdspec: DT identification data for the genpd @@ -188,6 +229,13 @@ static int ti_sci_pm_domain_probe(struct platform_device *pdev) pd->pd.power_on = ti_sci_pd_power_on; pd->idx = args.args[0]; pd->parent = pd_provider; + /* + * If SCI constraint functions are present, then firmware + * supports the constraints API. + */ + if (pd_provider->ti_sci->ops.pm_ops.set_device_constraint && + pd_provider->ti_sci->ops.pm_ops.set_latency_constraint) + pd->pd.domain.ops.suspend = ti_sci_pd_suspend; pm_genpd_init(&pd->pd, NULL, true);