From patchwork Mon Aug 5 23:38:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Hilman X-Patchwork-Id: 13754248 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 554F4C3DA4A for ; Mon, 5 Aug 2024 23:40:02 +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=u7ZxYmXnQ2uNgyq0sl55f3TGVTSwdU9KJbJgLapC8Mw=; b=RSVzvTFlBTatzMLGtQfb+byo7+ Zba0s4TSi17fjHAdHxi4mXAy3qj75W50M2TtRygkuJNwLekcivcsbqKTzAhdL4EunndlVETE5lMtR MCwx9ASBQym+w/NS//Hg7q2lrdPS+A0UUr1vvYw0wew4CmiUFFAQraf0a0EfrrKbVgra0snXgSqSy y4NmheNWBRpiW3SpXWDn1U5g/nFqvDis1O2wA0X1Rtvp3EesH/EkmBan+RLccEEzy+N8T4xQGRiai y6iQN4+T+tfjWaKUxZmu8zhfcr/J6tmG8vt2Q9elok1U7qvqI20vIBLIFTOgqXQdjN+Cd0pC56fmM EzWlI3Ww==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sb7Ip-0000000Ham7-1wMK; Mon, 05 Aug 2024 23:39:47 +0000 Received: from mail-pf1-x42a.google.com ([2607:f8b0:4864:20::42a]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sb7IJ-0000000Haf9-2fVk for linux-arm-kernel@lists.infradead.org; Mon, 05 Aug 2024 23:39:17 +0000 Received: by mail-pf1-x42a.google.com with SMTP id d2e1a72fcca58-70d316f0060so4046462b3a.1 for ; Mon, 05 Aug 2024 16:39:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1722901155; x=1723505955; 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=u7ZxYmXnQ2uNgyq0sl55f3TGVTSwdU9KJbJgLapC8Mw=; b=isL2UmFcI1fK+7vudum9i1CoqlR/ZT9hdwMwsyQt6LwhFWsdkXEOT2XPPhZMs+3oFZ kEZZOSEYutQZIDALrct47fWqG2stmI3x8MFut/S4VxYYKhhV1cJPBze0pRezG732+/um GWBUax9sXK0C7+wy4M5J5wKJUvHufTZ36DzYPNev3ugI95s1PqY3zsDsj84Dt8So2a6y /YA+rskUZObifgkF1yKHRSwd4zqTtfyWFCCUjSBJEzFCn+CG7nS7ByHUGgMenKlrPGE2 tbYJj+4GNNvOaij9IDPjScRITSd1mJhKtF4uDOUPwlz6GsJpy/pKsfVBKazJZbSJkTqa 6GqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722901155; x=1723505955; 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=u7ZxYmXnQ2uNgyq0sl55f3TGVTSwdU9KJbJgLapC8Mw=; b=YUMnZdQ0FWtyIHxL+MkZIZPYhYWaffIl6CyTc+Ts5w8CBZ/0gq1OfCH4ASklgdKE7x dXHtVTscccDBNe2O2bgacPf/HgCl8PA8C+fsLZsti+hg9ECMBsEkbKWMrplXq0q2KSEd kLOzi6bfIA6IN/nGqUs8t4/JChxgITiauNjYfxiKdAPzIBlIaRYvzZXnoicGp6WqjtQZ G8+OS7tSeMQN2oLkbc/3MHiLwP+m3VgLnQ4DOCKywcch1PxFEY/mh44iOVmHvKRLkQkG JoIJLhtp+FIivT04NPoPKAmGmbcRkMjB3tncldFPZfGEircDXkETSMWF/k8pLMPYyqiK unMw== X-Forwarded-Encrypted: i=1; AJvYcCXa1zH2SdJnhLeTCKXaIs6CGeohdGitJxiuUo2/KCeWyqg+iQhlI6lrAdcvf/EZUc1EB6gBECbd5okgdfx5OLkKJVSsbn3Xg6BFYYp7XSn+26eS2Cg= X-Gm-Message-State: AOJu0YxwKiQGijAmmIHWS/2k7UdBYOFc9NCZPNse+fll0/m+OJtYXEUv ULh3Mm/p35ghmPjFEwfXSuMq0Rb11HNIw/7zy/VkO7dsilI8LXGJmxbLdRLZ6Io= X-Google-Smtp-Source: AGHT+IGset5hmzuq7qwgVG5jO7FGUImBhiqZ/zJ/EfQifRXafS7aAqsaS9KrWxySb9UyoA8woG2GCw== X-Received: by 2002:a05:6a20:1581:b0:1c4:919f:3667 with SMTP id adf61e73a8af0-1c6943c8a6fmr23565497637.17.1722901154658; Mon, 05 Aug 2024 16:39:14 -0700 (PDT) Received: from localhost ([71.212.170.185]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7b762e9f83bsm6046136a12.7.2024.08.05.16.39.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Aug 2024 16:39:14 -0700 (PDT) From: Kevin Hilman Date: Mon, 05 Aug 2024 16:38:39 -0700 Subject: [PATCH 1/3] pmdomain: ti_sci: add per-device latency constraint management MIME-Version: 1.0 Message-Id: <20240805-lpm-v6-10-constraints-pmdomain-v1-1-d186b68ded4c@baylibre.com> References: <20240805-lpm-v6-10-constraints-pmdomain-v1-0-d186b68ded4c@baylibre.com> In-Reply-To: <20240805-lpm-v6-10-constraints-pmdomain-v1-0-d186b68ded4c@baylibre.com> To: Ulf Hansson Cc: Nishanth Menon , Vibhore Vardhan , Dhruva Gole , Akashdeep Kaur , Sebin Francis , Markus Schneider-Pargmann , linux-arm-kernel@lists.infradead.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, 20240801195422.2296347-1-msp@baylibre.com X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=openpgp-sha256; l=6319; i=khilman@baylibre.com; h=from:subject:message-id; bh=og+oz6R3XYFQe2i2DejxnXQaA9AXpva6vUP3tRWt3gM=; b=owEBbQKS/ZANAwAKAVk3GJrT+8ZlAcsmYgBmsWKfpIl4kZWvuypKcaH/eqGQlC1R6P1bjGM74 NFkYiMkch2JAjMEAAEKAB0WIQR7h0YOFpJ/qfW/8QxZNxia0/vGZQUCZrFinwAKCRBZNxia0/vG ZWHuEACoyTYvgkZj4fO9WVi1F+v4gbnUdFZ8AfidMqghcPI+M+ZW+xA8M2hD9OT/EQ3FDGCb+YF h0y2FTJ7xQF39jqC1+m8Cri3TXfb4lFfZnYIYWZSZ4gJh4LV3ZR3nP07CsXF7R9d+PhI7J2Awxf cXXji95+a8Qcg5NDOuo2JLrbaIuBdPCkgMJNCaR3NF5Os9ybWzasRloUeSf7voIn9M6Ne7T03h6 7cnMGGcEVOiLRU2PPrJLPIeQISxuddDvONH36Z+81DTmiyfmZIEgSfFGdnIwoHXp37hBWZ1lFkO S0bhEvfYIlA+YKxJvHFK5qMje5IevKYQbaeGjAus4FsZsh5QwnCE32+CooazB9VUbNCrq7sKJT/ E8wkwc/h1WKLrWLpwlLAN335iIyVn2qhczOflmvOTOJdCYgIdy8XpXNHoNJeD4IJblvDCMV3eBS G69dAERtX1IMhbDbvgywok89uo8MvoR7/kq+EIS2T1eSourc+7AZvWdMEZ4jFJPYNZ3SP043kL1 SZSxXBofP5UrpVS3zceZ22O2wu5uhc26Ju3/11u6Tk96DJ4pmZHvyXRZSGcP3bvZlUjpIwQdVfp G/TF89TG/DW/g2kNs1srkuLms95COmDPqYIwySMwgHhZr9StvXCxMI34KNMCqdwOV45tpoQRh52 rjBPTAeMast9MmQ== 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-20240805_163915_717089_91C4DF2A X-CRM114-Status: GOOD ( 24.75 ) 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: 1) before SCI PM domain power off (->power_off() hook) 2) before system-wide suspend (via ->suspend() hook) For TI SCI devices that are runtime PM enabled, check (1) will be the primary method, and will happen when the TI SCI PM domain is powered off (e.g. when the runtime PM usecount of the last device in that domain goes to zero.) For devices that are either not runtime PM enabled, or are not yet runtime suspended (e.g. due to being used during the suspend path), the constraints check will happen by check(2). Since constraints can be sent by either (1) or (2), driver keeps track of whether a valid constraint has been sent already. 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 Reviewed-by: Markus Schneider-Pargmann --- drivers/pmdomain/ti/ti_sci_pm_domains.c | 92 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 91 insertions(+), 1 deletion(-) diff --git a/drivers/pmdomain/ti/ti_sci_pm_domains.c b/drivers/pmdomain/ti/ti_sci_pm_domains.c index 1510d5ddae3d..4dc48a97f9b8 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 @@ -47,10 +49,46 @@ struct ti_sci_pm_domain { struct generic_pm_domain pd; struct list_head node; struct ti_sci_genpd_provider *parent; + s32 lat_constraint; + bool constraint_sent; }; #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_send_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) { + pd->constraint_sent = true; + dev_dbg(dev, "ti_sci_pd: ID:%d set latency constraint %d\n", + pd->idx, val); + } else { + dev_err(dev, "ti_sci_pd: set latency constraint failed: ret=%d\n", + ret); + } + + return ret; +} + +static inline void ti_sci_pd_clear_constraints(struct device *dev) +{ + struct generic_pm_domain *genpd = pd_to_genpd(dev->pm_domain); + struct ti_sci_pm_domain *pd = genpd_to_ti_sci_pd(genpd); + + pd->lat_constraint = PM_QOS_RESUME_LATENCY_NO_CONSTRAINT; + pd->constraint_sent = false; +} + /* * ti_sci_pd_power_off(): genpd power down hook * @domain: pointer to the powerdomain to power off @@ -59,6 +97,18 @@ static int ti_sci_pd_power_off(struct generic_pm_domain *domain) { struct ti_sci_pm_domain *pd = genpd_to_ti_sci_pd(domain); const struct ti_sci_handle *ti_sci = pd->parent->ti_sci; + struct pm_domain_data *pdd; + + list_for_each_entry(pdd, &domain->dev_list, list_node) { + struct device *dev = pdd->dev; + s32 val; + + /* If device has any resume latency constraints, send 'em */ + val = dev_pm_qos_read_value(dev, DEV_PM_QOS_RESUME_LATENCY); + if (ti_sci_pd_is_valid_constraint(val) && !pd->constraint_sent) + ti_sci_pd_send_constraint(dev, val); + pd->lat_constraint = val; + } return ti_sci->ops.dev_ops.put_device(ti_sci, pd->idx); } @@ -79,6 +129,38 @@ 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_resume(struct device *dev) +{ + ti_sci_pd_clear_constraints(dev); + return pm_generic_resume(dev); +} + +static int ti_sci_pd_suspend(struct device *dev) +{ + struct generic_pm_domain *genpd = pd_to_genpd(dev->pm_domain); + struct ti_sci_pm_domain *pd = genpd_to_ti_sci_pd(genpd); + s32 val; + int ret; + + ret = pm_generic_suspend(dev); + if (ret) + return ret; + + /* Check if device has any resume latency constraints */ + val = dev_pm_qos_read_value(dev, DEV_PM_QOS_RESUME_LATENCY); + if (ti_sci_pd_is_valid_constraint(val) && !pd->constraint_sent) { + if (genpd && genpd->status == GENPD_STATE_OFF) + dev_warn(dev, "%s: %s: already off.\n", genpd->name, __func__); + else if (pm_runtime_suspended(dev)) + dev_warn(dev, "%s: %s: already RPM suspended.\n", genpd->name, __func__); + else + ti_sci_pd_send_constraint(dev, val); + } + pd->lat_constraint = val; + + return 0; +} + /* * ti_sci_pd_xlate(): translation service for TI SCI genpds * @genpdspec: DT identification data for the genpd @@ -188,7 +270,15 @@ 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; - + pd->lat_constraint = PM_QOS_RESUME_LATENCY_NO_CONSTRAINT; + /* + * If SCI constraint functions are present, then firmware + * supports the constraints API. + */ + if (pd_provider->ti_sci->ops.pm_ops.set_device_constraint) { + pd->pd.domain.ops.resume = ti_sci_pd_resume; + pd->pd.domain.ops.suspend = ti_sci_pd_suspend; + } pm_genpd_init(&pd->pd, NULL, true); list_add(&pd->node, &pd_provider->pd_list); From patchwork Mon Aug 5 23:38:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Hilman X-Patchwork-Id: 13754250 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 94B8FC3DA7F for ; Mon, 5 Aug 2024 23:41:00 +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=dnncB28XY0s0oOAoP5k3joEIwhuPT0nv/d7oPA6DHTI=; b=W34T2vnmssftRCz/vG5ntfVrrQ 20Vu428Bv6fR+xMCF8keiVlyu71kiqkhM1qhnmZBr45DuEpO+UvPJ4bgO28lAom0JjlMOS4FfhiSs o2KlyYqaVY8Dbd/Ju9Al+fZpVgmv7afnaoAYGd2Ys11Xdg1jXD0khCK3neUqRUuWO4JnC6F1GuoXq WlBGf1nGsNxa9V3PEX2H3/JwOSrBSJE85bV/eQP3IOkNQUeOe5N1r+VMo73r1IQogUYGwT5ShW8rD EMww6MViZg23cq6tbOJ8OBoEc2qEeP20j6dhEbR0yqW4adwN7OBlZI447UYfChkJhlzwJAOg61/vG lz1X1iHA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sb7Jo-0000000Hb5J-31hf; Mon, 05 Aug 2024 23:40:48 +0000 Received: from mail-pl1-x632.google.com ([2607:f8b0:4864:20::632]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sb7IK-0000000Hafi-2oNX for linux-arm-kernel@lists.infradead.org; Mon, 05 Aug 2024 23:39:18 +0000 Received: by mail-pl1-x632.google.com with SMTP id d9443c01a7336-1ff3d5c6e9eso24545ad.1 for ; Mon, 05 Aug 2024 16:39:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1722901156; x=1723505956; 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=dnncB28XY0s0oOAoP5k3joEIwhuPT0nv/d7oPA6DHTI=; b=ps59fNCgtcmSaUj6XkLPBaK18p7kaj7lQPRA1jNV+XIdhgp0fy3oO+CQNKFfnspO7F fm7o6nkBTwjBRaEguqOHtJxpMEm0vaa/2c8JinFE7P270vRsfSENYjIgBF7HvCYAkZ8m hNkDHDczE+RxaTelpnepvAM3JrL8I/QovymcUIJAF+dsTHPwXKpL+qgebO9hY6G7Ts0/ hAJajBYFLa+P5KP8HlMbP90XCLmljMzu3G6qlpBPHo40DPVlKciqf81djLhDFnw7DZK2 j7WumAK4hsLNlcHa025quo/DNeMxK/Q76WXkjsGzzc0FP/ktNTr+KYAmt5VH8OOROBdU x5FA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722901156; x=1723505956; 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=dnncB28XY0s0oOAoP5k3joEIwhuPT0nv/d7oPA6DHTI=; b=OY6nG9gz7ypOAnILRSS0/grhROVJjJdhDG5pioiqn8jNAl9hTR+o+gre6fbIkDPNUv TZnP9FGRoRVD/jZHLjGR+xL67tz+LdOXY6PoRut3vaNdfnfaL07hHPJeGjbc6kZGHzEH EvQ/bN7qAfduq4azezY41uaF93En706dTnzfFYa3l27LW9a6cum+pMNR2WU81Q2olHUC 7uWVBRUnIbG7fUQDiUpY5cQ387klwJBFYqCLogMPlr1cJvuZOkQNwIw5OfQxhvKXchts T9XNQi93sIF7wAbTsjeoEn+0PVtAICRxpWN0bGsnzCcsnfAGIXE88PaKzdjW6lAnRJ1s V2Aw== X-Forwarded-Encrypted: i=1; AJvYcCWqZxI28JWdxV8f33ofx7icsOyh4irmVnxvhCA8TeR8TPFftQKfC4iFllEOLcCugpAj2ohYIY0XxTKer//dzvO8fVMvkhOqSDXv6EoAbOTPqamwwgU= X-Gm-Message-State: AOJu0YyOVbiCDvdYfz7h5ZU5Xsz8aP9p9BzYICKk/CldLK2U/N/LngZE /JTP+qmBbc9OQ6+m40mpATAzINn0gr8fKmlTHJh0SLoiCVOB+dJTS5b8iLlbP6o= X-Google-Smtp-Source: AGHT+IHobvQnstPph5Yb+ux00NdxLtNlQ9qF1pXoXFjnb5XD56fo2xQmXa90/jkJt5RoCFpipa+Xlg== X-Received: by 2002:a17:902:e84a:b0:1ff:39d7:a1b0 with SMTP id d9443c01a7336-1ff57495cb2mr144665765ad.50.1722901155669; Mon, 05 Aug 2024 16:39:15 -0700 (PDT) Received: from localhost ([71.212.170.185]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1ff5928ee8dsm74218375ad.230.2024.08.05.16.39.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Aug 2024 16:39:15 -0700 (PDT) From: Kevin Hilman Date: Mon, 05 Aug 2024 16:38:40 -0700 Subject: [PATCH 2/3] pmdomain: ti_sci: add wakeup constraint management MIME-Version: 1.0 Message-Id: <20240805-lpm-v6-10-constraints-pmdomain-v1-2-d186b68ded4c@baylibre.com> References: <20240805-lpm-v6-10-constraints-pmdomain-v1-0-d186b68ded4c@baylibre.com> In-Reply-To: <20240805-lpm-v6-10-constraints-pmdomain-v1-0-d186b68ded4c@baylibre.com> To: Ulf Hansson Cc: Nishanth Menon , Vibhore Vardhan , Dhruva Gole , Akashdeep Kaur , Sebin Francis , Markus Schneider-Pargmann , linux-arm-kernel@lists.infradead.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, 20240801195422.2296347-1-msp@baylibre.com X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=openpgp-sha256; l=2001; i=khilman@baylibre.com; h=from:subject:message-id; bh=fQs2VJ8lfyMR9SmNHWMLjdsigTfsq4Jxqit4bVCGBXo=; b=owEBbQKS/ZANAwAKAVk3GJrT+8ZlAcsmYgBmsWKggzNV78j/AecMl1EMuzfzjzwYnxTYwr5x8 x7D5mlMcnuJAjMEAAEKAB0WIQR7h0YOFpJ/qfW/8QxZNxia0/vGZQUCZrFioAAKCRBZNxia0/vG ZW/ED/9MaNuCpYxFfobOqYpMTwSVORQik9ViMNI3YunHM+6xvl2bejNcU/Z4/VLi71VgnPkiE/S +3fHFhryjLo6CyDnG06Tx2NTFyvzJ1LWU7D2IGgu04Oif1ZkCtTLnqF/bT7ef5CMiM5n2GTkCCV MwPfleDsab5aeKMGq7wqjiw5USlC/QpkV5sXFViEvl4lcBfC9/2PAeEMFloZZyrqBd88wPxoaBU QOQ0u3CaLwDMrfRzv7bf1qtbiwF5IaUYLOUUbADewasZMakk9OBG6MsP16c1VgIJx+zar2YEwUn e3+lvuPJy7zsnnkgGKxlgjMaA58yTaug0tuHfAb8bHQRp/v/UyPCLUSiKXtk2UDKocyTXlk+wqC jEcVJSEWUK6IqFRhAMndi/BmrRUuD+r+n4oOQVJV9tvfOFirZNAWrZP7Zcg8ng1i8NDzBfCLTcZ maEyngcANbznb48ts2he44FewEQFwfbnO0UIb5mXcb3DmcpZGKMX9Wd2bV/koMpyKRNO/0GjrUM cZkb0xfy6E0R3enQK3twcCJUvNRbM7gckNenDS7YoWeG6zl20T8McPPsZoJU+mjF8cMJV1O3NXB Jl9AZkcX5UVjKe9O0eV1MUTU9G6BN95yY0TK1R0DuQaX382qjPZJIcoOb/XMBrCdG39Gv+U9V3U 90oy9xdSJYM4VHg== 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-20240805_163916_745083_1C8812F7 X-CRM114-Status: GOOD ( 13.69 ) 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 During system-wide suspend, check all devices connected to PM domain to see if they are wakeup-enabled. If so, set a TI SCI device constraint. Note: DM firmware clears all constraints on resume. 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 | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/drivers/pmdomain/ti/ti_sci_pm_domains.c b/drivers/pmdomain/ti/ti_sci_pm_domains.c index 4dc48a97f9b8..7cd6ae957289 100644 --- a/drivers/pmdomain/ti/ti_sci_pm_domains.c +++ b/drivers/pmdomain/ti/ti_sci_pm_domains.c @@ -51,6 +51,7 @@ struct ti_sci_pm_domain { struct ti_sci_genpd_provider *parent; s32 lat_constraint; bool constraint_sent; + bool wkup_constraint; }; #define genpd_to_ti_sci_pd(gpd) container_of(gpd, struct ti_sci_pm_domain, pd) @@ -87,6 +88,26 @@ static inline void ti_sci_pd_clear_constraints(struct device *dev) pd->lat_constraint = PM_QOS_RESUME_LATENCY_NO_CONSTRAINT; pd->constraint_sent = false; + pd->wkup_constraint = false; +} + +static inline bool ti_sci_pd_check_wkup_constraint(struct device *dev) +{ + 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; + + if (device_may_wakeup(dev)) { + ret = ti_sci->ops.pm_ops.set_device_constraint(ti_sci, pd->idx, + TISCI_MSG_CONSTRAINT_SET); + if (!ret) { + pd->wkup_constraint = true; + dev_dbg(dev, "ti_sci_pd: ID:%d set device constraint.\n", pd->idx); + } + } + + return pd->wkup_constraint; } /* @@ -158,6 +179,8 @@ static int ti_sci_pd_suspend(struct device *dev) } pd->lat_constraint = val; + ti_sci_pd_check_wkup_constraint(dev); + return 0; } From patchwork Mon Aug 5 23:38:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Hilman X-Patchwork-Id: 13754251 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 70122C3DA7F for ; Mon, 5 Aug 2024 23:41: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=lMoK0Qo5SMl4nszA83I1OdSyVHO6YrX7RhAtuco02KE=; b=09e9yAK0RQBOBmOz46xi7rf/u8 F45yUeqn03S3agSP9YHeG/oIxHb1DIHvhqLJm4H/d9a5NCARwAVT/6NzmPIJ7Oh02vNL+641C2GX8 i9cmvt6dyZxiKrm0oG6T+QiPJezGE4yGn6S/WYx8XcHKL8GK3YLFSFLv/UCUPbk/QBkxMp0nHYst4 hSmzsXl9/cmh8lGGo+PL0hgj11/vbIC/CZheqv8j3C5UuULtwma3HDHsO9YnzoDYdpPAAXcl9KsPN 4bPgtqFoBDS2PiJ8a28MN+IbCpkvG9qZTc/RSs5whIOMW+9F4z3Zq5/HwbooN3XyoeaGGg+OspF8j ogWrMxtQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sb7KL-000000000D2-1mST; Mon, 05 Aug 2024 23:41:21 +0000 Received: from mail-pl1-x62f.google.com ([2607:f8b0:4864:20::62f]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sb7IL-0000000Hafw-2RrL for linux-arm-kernel@lists.infradead.org; Mon, 05 Aug 2024 23:39:19 +0000 Received: by mail-pl1-x62f.google.com with SMTP id d9443c01a7336-1fc52394c92so2096875ad.1 for ; Mon, 05 Aug 2024 16:39:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1722901157; x=1723505957; 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=lMoK0Qo5SMl4nszA83I1OdSyVHO6YrX7RhAtuco02KE=; b=Yff/LdR3W4bK2oSjkcZ5pOMmVZMKeYSYhAfCuBLYeGfRZ2BQmBa8PBTXYX/8bEq47e 6X6m0TQiYkJ+B7DZZtFAjkZrsJVwo//GglUkirnVeYlGwejB5J7RqxklkzcFOUVCORhw dvBGJrzKBLnboDf9AP0rmUuSMZMFz7VHaPKpOS/50TT2tEffan/cGgaOaj+BFQ8i4ILY xhGDnRleYcB4tOsdhFE5wjkiFp1nTW8XDYGy8yDonYtOVGJRNjkaotjcDpak6+BFghEF lLKLYuAErC+rKTL+54Y/sw2A0aTk1E8u02C8DaAiny/ilkiq4LkSJFOzJW3+fGBtML4W 8UfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722901157; x=1723505957; 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=lMoK0Qo5SMl4nszA83I1OdSyVHO6YrX7RhAtuco02KE=; b=jPujVUgzs1MflrXqVAaNYi93w0FUiEZonnWyQH6tnn2UfmLEshCAiVu+urO4artNOC PTFuGcQwWClOae8XagTiKod5tbK7hqfml31EZLWFwcMJqCcoe8IGXSk4Gr0XauwoshO/ fZwMNquY9+rKMNjEYY5eVaIwabDjzAFlAVE0ia9AaVkxqneyrAgssWI6/PfUC6uEtspO 1p8FCIf9BznPJriI3svrhs7rugNr6JYs5CmoTu4DPDTeSuV2GaGqz0AdYCPU6t4URVOL 2nOBB6rl/TDT+sGNTvpwaNvtlAMidNbNwbQcCMA90zVpg42U8cHv9h97YCb43d29jIjO MBiQ== X-Forwarded-Encrypted: i=1; AJvYcCX9HplsMUytZXrKxxPxgc7/WL9BfMLct1hGpGuvYTu1EKVqCHyLwtgQG/EFNtQNZnWm1eHVmnGLKQ+JDW45PPyuz4I2MTFcu0OKcQioEm6p/3XVU9g= X-Gm-Message-State: AOJu0Yx3dcHPFUaOVy0cWOeE+sYrCa+rKS9IvniIDLoHSHkl/dZCILhJ kODdQ4xXX/16ikPytjifR6MltHg8DaTOmGiyOpJZCfeSKmjce1etGaKigmfRLUI= X-Google-Smtp-Source: AGHT+IGU2ua9T3+pEZaILj3eRYOvNhkdYAh1SxJhl0qoN7WB7rqpH1SxarYAFcOGXTS/PVZZH6t9lA== X-Received: by 2002:a17:902:e743:b0:1ff:5150:911d with SMTP id d9443c01a7336-1ff574a2318mr180660445ad.60.1722901156706; Mon, 05 Aug 2024 16:39:16 -0700 (PDT) Received: from localhost ([71.212.170.185]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1ff5927efe8sm73931945ad.224.2024.08.05.16.39.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Aug 2024 16:39:16 -0700 (PDT) From: Kevin Hilman Date: Mon, 05 Aug 2024 16:38:41 -0700 Subject: [PATCH 3/3] pmdomain: ti_sci: handle wake IRQs for IO daisy chain wakeups MIME-Version: 1.0 Message-Id: <20240805-lpm-v6-10-constraints-pmdomain-v1-3-d186b68ded4c@baylibre.com> References: <20240805-lpm-v6-10-constraints-pmdomain-v1-0-d186b68ded4c@baylibre.com> In-Reply-To: <20240805-lpm-v6-10-constraints-pmdomain-v1-0-d186b68ded4c@baylibre.com> To: Ulf Hansson Cc: Nishanth Menon , Vibhore Vardhan , Dhruva Gole , Akashdeep Kaur , Sebin Francis , Markus Schneider-Pargmann , linux-arm-kernel@lists.infradead.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, 20240801195422.2296347-1-msp@baylibre.com X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=openpgp-sha256; l=1549; i=khilman@baylibre.com; h=from:subject:message-id; bh=aUhXQyVPFrL0JWTJ8beXrItrMemL62+rc4k2qIkw/uA=; b=owEBbQKS/ZANAwAKAVk3GJrT+8ZlAcsmYgBmsWKg+0bREECCIN99S3Y6KtlAALU9lAthCgDzf Bf4iUGVt6aJAjMEAAEKAB0WIQR7h0YOFpJ/qfW/8QxZNxia0/vGZQUCZrFioAAKCRBZNxia0/vG Zcf1EACSk4ZidtH82/O+s8oj6aWPnpde20zrx47lXaBfxZfk0Bg80Aac1G+fXTSB1wBWdiVYqXZ f8R4hmikfvYDiac9B30IHEdPIUbIPqdRn7ouG+s/sqMxGOBoH2PQJJ1J3Jtc9KtbTRCncF34XX6 LTuThT7ogDmORnkIaXRVyagjAZ1IJTc0EnMnR1p18UmEyvRU4Tnx19xTKSBf89qtRJ6XIyT3RCB xkv+zSXstVjWJ9BhWjjesoRPAsBWo/nAUe45SCa9QYIYP8HBsJqquVQgO6gkAPZoCGmJ8qp0tYl NWiBge+F5xzaRtPytFj56HpbbCL0WhVPmxlacDy13Iu1G7RR3OWn7MvcIOezcRzAdu8z42NYsHe 9uqVT9dysnzMrnBrigY6PFsrbVG003BAC6bpvVwtujdtftYYnYVdyrsr0tSetCUDLjvBbYhLiMp leryBok4AlVHNLdzo+7B1L4JyAy2/2cjlDPSSJi9NQ9XLkPRXJiH3WV9EBEG+Sfzaf3LJi3VqpC CAPBKtyhB+JRgFpkUtLeSVMthYqDXQWJvUPVOeq6XJFA8xZoo2l/yLxXZ9K9+NVQMopkdd2q08b iIkDPIN+/rSFqJnfNQCy5tLkaHjHQbHkkVNWUXGLM/SeV237JdTeCmuGy/WtkFE4+uiXPQWBK3U 95qwGdvjz76jp1A== 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-20240805_163917_847775_1E186AFB X-CRM114-Status: GOOD ( 13.41 ) 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 When a device supports IO daisy-chain wakeups, it uses a dedicated wake IRQ. Devices with IO daisy-chain wakeups enabled should not set wakeup constraints since these can happen even from deep power states, so should not prevent the DM from picking deep power states. Wake IRQs are set with dev_pm_set_wake_irq() or dev_pm_set_dedicated_wake_irq(). The latter is used by the serial driver used on K3 platforms (drivers/tty/serial/8250/8250_omap.c) when the interrupts-extended property is used to describe the dedicated wakeup interrupt. Detect these wake IRQs in the suspend path, and if set, skip sending constraint. Signed-off-by: Kevin Hilman --- drivers/pmdomain/ti/ti_sci_pm_domains.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/drivers/pmdomain/ti/ti_sci_pm_domains.c b/drivers/pmdomain/ti/ti_sci_pm_domains.c index 7cd6ae957289..4c85ce50510f 100644 --- a/drivers/pmdomain/ti/ti_sci_pm_domains.c +++ b/drivers/pmdomain/ti/ti_sci_pm_domains.c @@ -99,6 +99,15 @@ static inline bool ti_sci_pd_check_wkup_constraint(struct device *dev) int ret; if (device_may_wakeup(dev)) { + /* + * If device can wakeup using IO daisy chain wakeups, + * we do not want to set a constraint. + */ + if (dev->power.wakeirq) { + dev_dbg(dev, "%s: has wake IRQ, not setting constraints\n", __func__); + return false; + } + ret = ti_sci->ops.pm_ops.set_device_constraint(ti_sci, pd->idx, TISCI_MSG_CONSTRAINT_SET); if (!ret) {