From nobody Thu Dec 18 23:39:09 2025 Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C761C1BA877 for ; Thu, 29 Aug 2024 20:16:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724962581; cv=none; b=p03+Qu7hBRqf3oPKYiQF60qP/brNtSnyGKoIDOP0ycfo3jCCpYf2+ET5i8kJ/sAKKQ7Gbt1Yt84lRChAwijDbZbNWmp7h/Iy5NfxTtG0fqea4Jiia+kj1fu7RpGxZfdzDJ2TiEWuc947pGOVVTcjx64hbMF8t3w6GIlNKMGYz1M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724962581; c=relaxed/simple; bh=zGxaD8U9T+U4b4C+2/HJJQNmmk4gYPbj991Oi1n/7Ts=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=l+SffrpXpG2aPOaBKSBwFd8+PF7QxK9hVqcguTNCkAw99xxFzLLfDPYmenOiQcy+LVuqOOyfKnmeE1HJhFbYEnEDVgsOkk9VjeXfrmlPFf++vp6zEK0nq9U0+SRO8F95dXLVAIEbYhxqNAsiDAfYvNmnoSLXl40VtyNsP6fxbgc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com; spf=pass smtp.mailfrom=baylibre.com; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b=kuA7eU8e; arc=none smtp.client-ip=209.85.128.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=baylibre.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="kuA7eU8e" Received: by mail-wm1-f49.google.com with SMTP id 5b1f17b1804b1-429ec9f2155so9346855e9.2 for ; Thu, 29 Aug 2024 13:16:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1724962576; x=1725567376; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=XGlk+6RhKnBgzhvhm0ocxM8uELwMTtl2eqHYRSP1FzQ=; b=kuA7eU8ejXZTRSCaRg1bnkDK4/xK2duSTsArL8LMSu6oPvOMp80rwUv49FuS8+XIkU Q+y1WfNqqVrTODWJd6xhz9iEtK93RiQgtfjPuzvTfjQPcSZi4XpdRoKr+Waa7n+gQvgR bFN4qnam6eXaR0jXfw/mdS3GfeIjs53GjocxEOyfqn/ub1FQ1+bNREKiInh7WqQktzkA AUQUOSvuQbN4e/lK9OyGXDA2rSxvuRCIERB0korigKz3LvyfXmjH6eUPSLyevPoFJLEZ CIeTXjuM1b3LGsxqYfEuhnVdL6x/RWkchDvDydlZqGFnZqbmCRcMKXP4z+NDHkojpOdm 14Iw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724962576; x=1725567376; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=XGlk+6RhKnBgzhvhm0ocxM8uELwMTtl2eqHYRSP1FzQ=; b=mYn3eMS/FynNb7BC2D2yt64Nq7gHp6k8p2IdqBvdm+tvrXZHWYF4s8ONrQVkWYni6a 7tAfrVxMXRmW2ATGLvCmcsKJQyYUi8o9hj/MkFv4hPp69HifHtqo+8088ju1lxR1rZ63 2dJVRdjm28kP1pPZygbXCAelBAJPvPorkEdlL1THTQAE82EUR/F+LVzMG5rV4MLcXH8P Au+VzeeKG30LtduIixX0+Yzeh42OMxaaDi0irG8VMCwrxTbmQsidONe1oXDbzzrq35lp gWjKatBnuTRZdaxYSTFoftFikLLoVySc8+EBWmW9R7EpfRazEWGNHVpJHFi+obna/Lhe URlg== X-Forwarded-Encrypted: i=1; AJvYcCW7cIRiCskuPV6wcBlTulZnS2QjWBnhjDBQKY4IyBLiIyh5KdAl0f4Nd4CbAvfq4cXloZXsdSH1DbXVZhY=@vger.kernel.org X-Gm-Message-State: AOJu0YwzylDIAoQxlglklJlW6ngBMGy+bTgKLatokJt0rng+OhaqU8QQ qeENAWhwfDYnknulOsfBftTxWbOeM7+cugYYA8IITN2XnMoG8ewVADNmbM5iKuo= X-Google-Smtp-Source: AGHT+IEX9BEL/aSSY4fkZb4HqB4p1WoEr4eolcIacJOSg8a9+g4vDR3ZPBbzPuaUQ5RK8ohKWgpiWQ== X-Received: by 2002:a05:600c:4fcd:b0:426:58ca:5a3 with SMTP id 5b1f17b1804b1-42bb032caf5mr26615175e9.30.1724962575865; Thu, 29 Aug 2024 13:16:15 -0700 (PDT) Received: from blmsp.fritz.box ([2001:4091:a245:802f:3a47:b29:5530:28a2]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42bb6deb303sm26681385e9.9.2024.08.29.13.16.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Aug 2024 13:16:15 -0700 (PDT) From: Markus Schneider-Pargmann To: Nishanth Menon , Tero Kristo , Santosh Shilimkar Cc: Vibhore Vardhan , Kevin Hilman , Dhruva Gole , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Georgi Vlaev , Markus Schneider-Pargmann Subject: [PATCH v11 1/4] firmware: ti_sci: Add support for querying the firmware caps Date: Thu, 29 Aug 2024 22:16:02 +0200 Message-ID: <20240829201606.1407773-2-msp@baylibre.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240829201606.1407773-1-msp@baylibre.com> References: <20240829201606.1407773-1-msp@baylibre.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Georgi Vlaev Add support for the TISCI_MSG_QUERY_FW_CAPS message, used to retrieve the firmware capabilities of the currently running system firmware. The message belongs to the TISCI general core message API [1] and is available in SysFW version 08.04.03 and above. Currently, the message is supported on devices with split architecture of the system firmware (DM + TIFS) like AM62x. Old revisions or not yet supported platforms will NACK this request. We're using this message locally in ti_sci.c to get the low power features of the FW/SoC. As there's no other kernel consumers yet, this is not added to struct ti_sci_core_ops. Sysfw version >=3D 10.00.04 support LPM_DM_MANAGED capability [2], where Device Mgr firmware now manages which low power mode is chosen. Going forward, this is the default configuration supported for TI AM62 family of devices. The state chosen by the DM can be influenced by sending constraints using the new LPM constraint APIs. [1] https://software-dl.ti.com/tisci/esd/latest/2_tisci_msgs/general/core.h= tml [2] https://software-dl.ti.com/tisci/esd/latest/2_tisci_msgs/general/core.h= tml#tisci-msg-query-fw-caps Signed-off-by: Georgi Vlaev [vibhore@ti.com: Support for LPM_DM_MANAGED mode] Signed-off-by: Vibhore Vardhan Signed-off-by: Kevin Hilman Tested-by: Dhruva Gole Signed-off-by: Markus Schneider-Pargmann Acked-by: Dhruva Gole --- drivers/firmware/ti_sci.c | 74 ++++++++++++++++++++++++++++++++++++++- drivers/firmware/ti_sci.h | 22 ++++++++++++ 2 files changed, 95 insertions(+), 1 deletion(-) diff --git a/drivers/firmware/ti_sci.c b/drivers/firmware/ti_sci.c index 160968301b1f..bed7c8892341 100644 --- a/drivers/firmware/ti_sci.c +++ b/drivers/firmware/ti_sci.c @@ -2,10 +2,11 @@ /* * Texas Instruments System Control Interface Protocol Driver * - * Copyright (C) 2015-2022 Texas Instruments Incorporated - https://www.ti= .com/ + * Copyright (C) 2015-2024 Texas Instruments Incorporated - https://www.ti= .com/ * Nishanth Menon */ =20 +#include "linux/dev_printk.h" #define pr_fmt(fmt) "%s: " fmt, __func__ =20 #include @@ -24,6 +25,7 @@ #include #include #include +#include #include =20 #include "ti_sci.h" @@ -98,6 +100,7 @@ struct ti_sci_desc { * @minfo: Message info * @node: list head * @host_id: Host ID + * @fw_caps: FW/SoC low power capabilities * @users: Number of users of this instance */ struct ti_sci_info { @@ -114,6 +117,7 @@ struct ti_sci_info { struct ti_sci_xfers_info minfo; struct list_head node; u8 host_id; + u64 fw_caps; /* protected by ti_sci_list_mutex */ int users; }; @@ -1651,6 +1655,67 @@ static int ti_sci_cmd_clk_get_freq(const struct ti_s= ci_handle *handle, return ret; } =20 +/** + * ti_sci_msg_cmd_query_fw_caps() - Get the FW/SoC capabilities + * @handle: Pointer to TI SCI handle + * @fw_caps: Each bit in fw_caps indicating one FW/SOC capability + * + * Check if the firmware supports any optional low power modes. + * Old revisions of TIFS (< 08.04) will NACK the request which results in + * -ENODEV being returned. + * + * Return: 0 if all went well, else returns appropriate error value. + */ +static int ti_sci_msg_cmd_query_fw_caps(const struct ti_sci_handle *handle, + u64 *fw_caps) +{ + struct ti_sci_info *info; + struct ti_sci_xfer *xfer; + struct ti_sci_msg_resp_query_fw_caps *resp; + struct device *dev; + int ret =3D 0; + + if (IS_ERR(handle)) + return PTR_ERR(handle); + if (!handle) + return -EINVAL; + + info =3D handle_to_ti_sci_info(handle); + dev =3D info->dev; + + xfer =3D ti_sci_get_one_xfer(info, TI_SCI_MSG_QUERY_FW_CAPS, + TI_SCI_FLAG_REQ_ACK_ON_PROCESSED, + sizeof(struct ti_sci_msg_hdr), + sizeof(*resp)); + if (IS_ERR(xfer)) { + ret =3D PTR_ERR(xfer); + dev_err(dev, "Message alloc failed(%d)\n", ret); + return ret; + } + + ret =3D ti_sci_do_xfer(info, xfer); + if (ret) { + dev_err(dev, "Mbox send fail %d\n", ret); + goto fail; + } + + resp =3D (struct ti_sci_msg_resp_query_fw_caps *)xfer->xfer_buf; + + if (!ti_sci_is_response_ack(resp)) { + dev_err(dev, "Failed to get capabilities\n"); + ret =3D -ENODEV; + goto fail; + } + + if (fw_caps) + *fw_caps =3D resp->fw_caps; + +fail: + ti_sci_put_one_xfer(&info->minfo, xfer); + + return ret; +} + static int ti_sci_cmd_core_reboot(const struct ti_sci_handle *handle) { struct ti_sci_info *info; @@ -3390,6 +3455,13 @@ static int ti_sci_probe(struct platform_device *pdev) goto out; } =20 + ti_sci_msg_cmd_query_fw_caps(&info->handle, &info->fw_caps); + dev_dbg(dev, "Detected firmware capabilities: %s%s%s\n", + info->fw_caps & MSG_FLAG_CAPS_GENERIC ? "Generic" : "", + info->fw_caps & MSG_FLAG_CAPS_LPM_PARTIAL_IO ? " Partial-IO" : "", + info->fw_caps & MSG_FLAG_CAPS_LPM_DM_MANAGED ? " DM-Managed" : "" + ); + ti_sci_setup_ops(info); =20 ret =3D devm_register_restart_handler(dev, tisci_reboot_handler, info); diff --git a/drivers/firmware/ti_sci.h b/drivers/firmware/ti_sci.h index 5846c60220f5..73ca9503606b 100644 --- a/drivers/firmware/ti_sci.h +++ b/drivers/firmware/ti_sci.h @@ -19,6 +19,7 @@ #define TI_SCI_MSG_WAKE_REASON 0x0003 #define TI_SCI_MSG_GOODBYE 0x0004 #define TI_SCI_MSG_SYS_RESET 0x0005 +#define TI_SCI_MSG_QUERY_FW_CAPS 0x0022 =20 /* Device requests */ #define TI_SCI_MSG_SET_DEVICE_STATE 0x0200 @@ -132,6 +133,27 @@ struct ti_sci_msg_req_reboot { struct ti_sci_msg_hdr hdr; } __packed; =20 +/** + * struct ti_sci_msg_resp_query_fw_caps - Response for query firmware caps + * @hdr: Generic header + * @fw_caps: Each bit in fw_caps indicating one FW/SOC capability + * MSG_FLAG_CAPS_GENERIC: Generic capability (LPM not supported) + * MSG_FLAG_CAPS_LPM_PARTIAL_IO: Partial IO in LPM + * MSG_FLAG_CAPS_LPM_DM_MANAGED: LPM can be managed by DM + * + * Response to a generic message with message type TI_SCI_MSG_QUERY_FW_CAPS + * providing currently available SOC/firmware capabilities. SoC that don't + * support low power modes return only MSG_FLAG_CAPS_GENERIC capability. + */ +struct ti_sci_msg_resp_query_fw_caps { + struct ti_sci_msg_hdr hdr; +#define MSG_FLAG_CAPS_GENERIC TI_SCI_MSG_FLAG(0) +#define MSG_FLAG_CAPS_LPM_PARTIAL_IO TI_SCI_MSG_FLAG(4) +#define MSG_FLAG_CAPS_LPM_DM_MANAGED TI_SCI_MSG_FLAG(5) +#define MSG_MASK_CAPS_LPM GENMASK_ULL(4, 1) + u64 fw_caps; +} __packed; + /** * struct ti_sci_msg_req_set_device_state - Set the desired state of the d= evice * @hdr: Generic header --=20 2.45.2 From nobody Thu Dec 18 23:39:09 2025 Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8A1301BA882 for ; Thu, 29 Aug 2024 20:16:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724962581; cv=none; b=J/8jsKC6SLnT5F37Wp+x+UzMz484F2ET435i9jcV5pq6pfpgaqymAvizm9Rz6khMaeRQvhtt83WJ/l5vzTf/WxNaTWMloXIjC96918ch70KgZemH7Ze1MQFxH1nk+CLOoCPMBvZR4+GGYyQAJSvgZn3MP7p9T6D3kbCWvkSlluA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724962581; c=relaxed/simple; bh=So+QR1H7UTFsrN2KzCZH+aJD18yr6yPO4k39Loh9Vos=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=L8prJJtAHmKk5P0DzawR4ARrPjv+7edcWqfed9pbmOqen3OlV1SFyFWp/q1eh7sceetll3jIHt+QvLgbzch1nQRBcfcwEyNnim2I6sHOuQYsb/FspLr6MF95KxgepixwifLCKdambDLXuZ+Hk04UudBWvIdtFKwIxQNnxvEitnk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com; spf=pass smtp.mailfrom=baylibre.com; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b=a3cE2c+N; arc=none smtp.client-ip=209.85.128.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=baylibre.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="a3cE2c+N" Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-4281d812d3eso11942525e9.3 for ; Thu, 29 Aug 2024 13:16:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1724962577; x=1725567377; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=LodsHN6ErMm8ud8I1c+jnkeAh6yIwKqYwAyRW5ne69Y=; b=a3cE2c+NbEHdcvMxC2fbllu2jXdJJ0Yz+9kXmf+VfrjTuboG8ht0suLdmTUmHN/lEr MYEZlq67QlzHZFAMzMqElk79BqH0VkAAl7ujCMXbuD6QWRBNbFcteVxu5e+kb9G9EMan zEyuKqTCJsbA/xOinGyBMrpaurpQlbhXbbbRsK1mgFdbDViC4vpUtZigAwPVctBO6LJL Sq6VXP0OhnSc9DalpfOQ7O7LnK0BUpL+nr8xo8dJaXXKW5np7f9/cjk28fK2ZYPXIdaP NX+tNXa+2NF+gmof3pzzfCOEBThRwkQjfeMRE+Nk/nc0MxyqN1j8FaTUOTYS+/UkjVcY lb7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724962577; x=1725567377; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=LodsHN6ErMm8ud8I1c+jnkeAh6yIwKqYwAyRW5ne69Y=; b=uRF7i1XczlkbK656du56ieTS8GgH8JsKCTL+iuHsHwmJxWjP9OOdNqXVb/CJygxVQv 3OCOKPQMhwdxiCQdy9nTxMPJxZloBtfKWGfvz5b9v3+bLRk3oVTsKtna1TnPsy5V5fI3 LtP1sWsdTZ0UbH/Cooq6ed0sENwP8qXZ7IHVGTqqp/26dlhoI1gDe2MqO9DK7viWDlHz /wHxk8K0LPNjnAQsiFYi0Z9G3rDLlaZcl1gceW0xcSTeNKqC/mldA7AyUqikVypZVGaK fLq+zAX7Ae+VKhQWNST1HM+JkA2DauR1redUkB4Ge4iqV/mLS1uGPPxPDkoseaQuAEnY nLCA== X-Forwarded-Encrypted: i=1; AJvYcCW/pAyEzfuKALVovB0s8r4gfa89wh5s7wC+eBjEXCQlTJP26aW16G1eOmf/Jh1+v6z311JJlEEw+xSY0go=@vger.kernel.org X-Gm-Message-State: AOJu0YyrM9fCQ8oewqXi3PbKGpMOzv6WjRniDuTgyQrG3G5LEo3pU2ih gOjCj9KQ9qSdfh+UZBMYAV7l3l3jwO8zCZYW3WDZzWQzhYRNA0d1Z6BDeVpOTlA= X-Google-Smtp-Source: AGHT+IECSB50MXx+BfwG2vtb8X49S00D85Tdel6FMzdTwn5cB4lcbHCao7mKV+rdfS5rjMk+B3kojA== X-Received: by 2002:a05:600c:1c83:b0:426:59fe:ac27 with SMTP id 5b1f17b1804b1-42bb01edc2amr39072725e9.26.1724962576803; Thu, 29 Aug 2024 13:16:16 -0700 (PDT) Received: from blmsp.fritz.box ([2001:4091:a245:802f:3a47:b29:5530:28a2]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42bb6deb303sm26681385e9.9.2024.08.29.13.16.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Aug 2024 13:16:16 -0700 (PDT) From: Markus Schneider-Pargmann To: Nishanth Menon , Tero Kristo , Santosh Shilimkar Cc: Vibhore Vardhan , Kevin Hilman , Dhruva Gole , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Dave Gerlach , Georgi Vlaev , Markus Schneider-Pargmann Subject: [PATCH v11 2/4] firmware: ti_sci: Add system suspend and resume call Date: Thu, 29 Aug 2024 22:16:03 +0200 Message-ID: <20240829201606.1407773-3-msp@baylibre.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240829201606.1407773-1-msp@baylibre.com> References: <20240829201606.1407773-1-msp@baylibre.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Vibhore Vardhan Introduce system suspend call that enables the ti_sci driver to support low power mode when the user space issues a suspend to mem. The following power management operations defined in the TISCI Low Power Mode API [1] are implemented to support suspend and resume: 1) TISCI_MSG_PREPARE_SLEEP Prepare the SOC for entering into a low power mode and provide details to firmware about the state being entered. 2) TISCI_MSG_SET_IO_ISOLATION Control the IO isolation for Low Power Mode. Also, write a ti_sci_prepare_system_suspend call to be used in the driver suspend handler to allow the system to identify the low power mode being entered and if necessary, send TISCI_MSG_PREPARE_SLEEP with information about the mode being entered. Sysfw version >=3D 10.00.04 support LPM_DM_MANAGED capability [2], where Device Mgr firmware now manages which low power mode is chosen. Going forward, this is the default configuration supported for TI AM62 family of devices. The state chosen by the DM can be influenced by sending constraints using the new LPM constraint APIs. In case the firmware does not support LPM_DM_MANAGED mode, the mode selection logic can be extended as needed. If no suspend-to-RAM modes are supported, return without taking any action. We're using "pm_suspend_target_state" to map the kernel's target suspend state to SysFW low power mode. Make sure this is available only when CONFIG_SUSPEND is enabled. Suspend has to be split into two parts, ti_sci_suspend() will send the prepare sleep message to prepare suspend. ti_sci_suspend_noirq() sets IO isolation which needs to be done as late as possible to avoid any issues. On resume this has to be done as early as possible. [1] https://software-dl.ti.com/tisci/esd/latest/2_tisci_msgs/pm/lpm.html Co-developed-by: Dave Gerlach Signed-off-by: Dave Gerlach Signed-off-by: Georgi Vlaev Signed-off-by: Dhruva Gole Signed-off-by: Vibhore Vardhan Signed-off-by: Kevin Hilman Tested-by: Dhruva Gole Signed-off-by: Markus Schneider-Pargmann --- drivers/firmware/ti_sci.c | 196 +++++++++++++++++++++++++ drivers/firmware/ti_sci.h | 45 +++++- include/linux/soc/ti/ti_sci_protocol.h | 4 + 3 files changed, 244 insertions(+), 1 deletion(-) diff --git a/drivers/firmware/ti_sci.c b/drivers/firmware/ti_sci.c index bed7c8892341..8a772b378ffa 100644 --- a/drivers/firmware/ti_sci.c +++ b/drivers/firmware/ti_sci.c @@ -25,6 +25,7 @@ #include #include #include +#include #include #include =20 @@ -1655,6 +1656,68 @@ static int ti_sci_cmd_clk_get_freq(const struct ti_s= ci_handle *handle, return ret; } =20 +/** + * ti_sci_cmd_prepare_sleep() - Prepare system for system suspend + * @handle: pointer to TI SCI handle + * @mode: Device identifier + * @ctx_lo: Low part of address for context save + * @ctx_hi: High part of address for context save + * @debug_flags: Debug flags to pass to firmware + * + * Return: 0 if all went well, else returns appropriate error value. + */ +static int ti_sci_cmd_prepare_sleep(const struct ti_sci_handle *handle, u8= mode, + u32 ctx_lo, u32 ctx_hi, u32 debug_flags) +{ + struct ti_sci_info *info; + struct ti_sci_msg_req_prepare_sleep *req; + struct ti_sci_msg_hdr *resp; + struct ti_sci_xfer *xfer; + struct device *dev; + int ret =3D 0; + + if (IS_ERR(handle)) + return PTR_ERR(handle); + if (!handle) + return -EINVAL; + + info =3D handle_to_ti_sci_info(handle); + dev =3D info->dev; + + xfer =3D ti_sci_get_one_xfer(info, TI_SCI_MSG_PREPARE_SLEEP, + TI_SCI_FLAG_REQ_ACK_ON_PROCESSED, + sizeof(*req), sizeof(*resp)); + if (IS_ERR(xfer)) { + ret =3D PTR_ERR(xfer); + dev_err(dev, "Message alloc failed(%d)\n", ret); + return ret; + } + + req =3D (struct ti_sci_msg_req_prepare_sleep *)xfer->xfer_buf; + req->mode =3D mode; + req->ctx_lo =3D ctx_lo; + req->ctx_hi =3D ctx_hi; + req->debug_flags =3D debug_flags; + + ret =3D ti_sci_do_xfer(info, xfer); + if (ret) { + dev_err(dev, "Mbox send fail %d\n", ret); + goto fail; + } + + resp =3D (struct ti_sci_msg_hdr *)xfer->xfer_buf; + + if (!ti_sci_is_response_ack(resp)) { + dev_err(dev, "Failed to prepare sleep\n"); + ret =3D -ENODEV; + } + +fail: + ti_sci_put_one_xfer(&info->minfo, xfer); + + return ret; +} + /** * ti_sci_msg_cmd_query_fw_caps() - Get the FW/SoC capabilities * @handle: Pointer to TI SCI handle @@ -1716,6 +1779,61 @@ static int ti_sci_msg_cmd_query_fw_caps(const struct= ti_sci_handle *handle, return ret; } =20 +/** + * ti_sci_cmd_set_io_isolation() - Enable IO isolation in LPM + * @handle: Pointer to TI SCI handle + * @state: The desired state of the IO isolation + * + * Return: 0 if all went well, else returns appropriate error value. + */ +static int ti_sci_cmd_set_io_isolation(const struct ti_sci_handle *handle, + u8 state) +{ + struct ti_sci_info *info; + struct ti_sci_msg_req_set_io_isolation *req; + struct ti_sci_msg_hdr *resp; + struct ti_sci_xfer *xfer; + struct device *dev; + int ret =3D 0; + + if (IS_ERR(handle)) + return PTR_ERR(handle); + if (!handle) + return -EINVAL; + + info =3D handle_to_ti_sci_info(handle); + dev =3D info->dev; + + xfer =3D ti_sci_get_one_xfer(info, TI_SCI_MSG_SET_IO_ISOLATION, + TI_SCI_FLAG_REQ_ACK_ON_PROCESSED, + sizeof(*req), sizeof(*resp)); + if (IS_ERR(xfer)) { + ret =3D PTR_ERR(xfer); + dev_err(dev, "Message alloc failed(%d)\n", ret); + return ret; + } + req =3D (struct ti_sci_msg_req_set_io_isolation *)xfer->xfer_buf; + req->state =3D state; + + ret =3D ti_sci_do_xfer(info, xfer); + if (ret) { + dev_err(dev, "Mbox send fail %d\n", ret); + goto fail; + } + + resp =3D (struct ti_sci_msg_hdr *)xfer->xfer_buf; + + if (!ti_sci_is_response_ack(resp)) { + dev_err(dev, "Failed to set IO isolation\n"); + ret =3D -ENODEV; + } + +fail: + ti_sci_put_one_xfer(&info->minfo, xfer); + + return ret; +} + static int ti_sci_cmd_core_reboot(const struct ti_sci_handle *handle) { struct ti_sci_info *info; @@ -3327,6 +3445,83 @@ static int tisci_reboot_handler(struct sys_off_data = *data) return NOTIFY_BAD; } =20 +static int ti_sci_prepare_system_suspend(struct ti_sci_info *info) +{ + /* + * Map and validate the target Linux suspend state to TISCI LPM. + * Default is to let Device Manager select the low power mode. + */ + switch (pm_suspend_target_state) { + case PM_SUSPEND_MEM: + if (info->fw_caps & MSG_FLAG_CAPS_LPM_DM_MANAGED) { + /* + * For the DM_MANAGED mode the context is reserved for + * internal use and can be 0 + */ + return ti_sci_cmd_prepare_sleep(&info->handle, + TISCI_MSG_VALUE_SLEEP_MODE_DM_MANAGED, + 0, 0, 0); + } else { + /* DM Managed is not supported by the firmware. */ + dev_err(info->dev, "Suspend to memory is not supported by the firmware\= n"); + return -EOPNOTSUPP; + } + break; + default: + /* + * Do not fail if we don't have action to take for a + * specific suspend mode. + */ + return 0; + } + + return 0; +} + +static int __maybe_unused ti_sci_suspend(struct device *dev) +{ + struct ti_sci_info *info =3D dev_get_drvdata(dev); + int ret; + + ret =3D ti_sci_prepare_system_suspend(info); + if (ret) + return ret; + + return 0; +} + +static int __maybe_unused ti_sci_suspend_noirq(struct device *dev) +{ + struct ti_sci_info *info =3D dev_get_drvdata(dev); + int ret =3D 0; + + ret =3D ti_sci_cmd_set_io_isolation(&info->handle, TISCI_MSG_VALUE_IO_ENA= BLE); + if (ret) + return ret; + + return 0; +} + +static int __maybe_unused ti_sci_resume_noirq(struct device *dev) +{ + struct ti_sci_info *info =3D dev_get_drvdata(dev); + int ret =3D 0; + + ret =3D ti_sci_cmd_set_io_isolation(&info->handle, TISCI_MSG_VALUE_IO_DIS= ABLE); + if (ret) + return ret; + + return 0; +} + +static const struct dev_pm_ops ti_sci_pm_ops =3D { +#ifdef CONFIG_PM_SLEEP + .suspend =3D ti_sci_suspend, + .suspend_noirq =3D ti_sci_suspend_noirq, + .resume_noirq =3D ti_sci_resume_noirq, +#endif +}; + /* Description for K2G */ static const struct ti_sci_desc ti_sci_pmmc_k2g_desc =3D { .default_host_id =3D 2, @@ -3495,6 +3690,7 @@ static struct platform_driver ti_sci_driver =3D { .name =3D "ti-sci", .of_match_table =3D of_match_ptr(ti_sci_of_match), .suppress_bind_attrs =3D true, + .pm =3D &ti_sci_pm_ops, }, }; module_platform_driver(ti_sci_driver); diff --git a/drivers/firmware/ti_sci.h b/drivers/firmware/ti_sci.h index 73ca9503606b..8efe4d0e61fb 100644 --- a/drivers/firmware/ti_sci.h +++ b/drivers/firmware/ti_sci.h @@ -6,7 +6,7 @@ * The system works in a message response protocol * See: https://software-dl.ti.com/tisci/esd/latest/index.html for details * - * Copyright (C) 2015-2016 Texas Instruments Incorporated - https://www.t= i.com/ + * Copyright (C) 2015-2024 Texas Instruments Incorporated - https://www.t= i.com/ */ =20 #ifndef __TI_SCI_H @@ -36,6 +36,10 @@ #define TI_SCI_MSG_QUERY_CLOCK_FREQ 0x010d #define TI_SCI_MSG_GET_CLOCK_FREQ 0x010e =20 +/* Low Power Mode Requests */ +#define TI_SCI_MSG_PREPARE_SLEEP 0x0300 +#define TI_SCI_MSG_SET_IO_ISOLATION 0x0307 + /* Resource Management Requests */ #define TI_SCI_MSG_GET_RESOURCE_RANGE 0x1500 =20 @@ -567,6 +571,45 @@ struct ti_sci_msg_resp_get_clock_freq { u64 freq_hz; } __packed; =20 +/** + * struct tisci_msg_req_prepare_sleep - Request for TISCI_MSG_PREPARE_SLEE= P. + * + * @hdr TISCI header to provide ACK/NAK flags to the host. + * @mode Low power mode to enter. + * @ctx_lo Low 32-bits of physical pointer to address to use for context= save. + * @ctx_hi High 32-bits of physical pointer to address to use for contex= t save. + * @debug_flags Flags that can be set to halt the sequence during suspen= d or + * resume to allow JTAG connection and debug. + * + * This message is used as the first step of entering a low power mode. It + * allows configurable information, including which state to enter to be + * easily shared from the application, as this is a non-secure message and + * therefore can be sent by anyone. + */ +struct ti_sci_msg_req_prepare_sleep { + struct ti_sci_msg_hdr hdr; + +#define TISCI_MSG_VALUE_SLEEP_MODE_DM_MANAGED 0xfd + u8 mode; + u32 ctx_lo; + u32 ctx_hi; + u32 debug_flags; +} __packed; + +/** + * struct tisci_msg_set_io_isolation_req - Request for TI_SCI_MSG_SET_IO_I= SOLATION. + * + * @hdr: Generic header + * @state: The deseared state of the IO isolation. + * + * This message is used to enable/disable IO isolation for low power modes. + * Response is generic ACK / NACK message. + */ +struct ti_sci_msg_req_set_io_isolation { + struct ti_sci_msg_hdr hdr; + u8 state; +} __packed; + #define TI_SCI_IRQ_SECONDARY_HOST_INVALID 0xff =20 /** diff --git a/include/linux/soc/ti/ti_sci_protocol.h b/include/linux/soc/ti/= ti_sci_protocol.h index bd0d11af76c5..1f1871e23f76 100644 --- a/include/linux/soc/ti/ti_sci_protocol.h +++ b/include/linux/soc/ti/ti_sci_protocol.h @@ -195,6 +195,10 @@ struct ti_sci_clk_ops { u64 *current_freq); }; =20 +/* TISCI LPM IO isolation control values */ +#define TISCI_MSG_VALUE_IO_ENABLE 1 +#define TISCI_MSG_VALUE_IO_DISABLE 0 + /** * struct ti_sci_resource_desc - Description of TI SCI resource instance r= ange. * @start: Start index of the first resource range. --=20 2.45.2 From nobody Thu Dec 18 23:39:09 2025 Received: from mail-wr1-f44.google.com (mail-wr1-f44.google.com [209.85.221.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 98D1626296 for ; Thu, 29 Aug 2024 20:16:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724962582; cv=none; b=UvGrLIqXseVXuPVu87VNuIdUd5Y0L3FzdpP+ykZCYa67+ujbWVGGea2gRLGBQulo8bydvnL/JNXMv3kS2rZo0fCYTPIZolhIyTie8ryxfWEJuQObrULgYeO2R2FrO6Avl6kY+bpnrfkPsDxbu9gHDDCoD5DNwGOtbZhq/UCqtkY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724962582; c=relaxed/simple; bh=2YLbQOl6WOhv1G4HHICKVjYmxtSAiu7Sijn/5qjxjdM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=N8KEPZh3iPsw+5nzwdseTtrD6iZEYWgQ1sKGd2dRDDHEM281uRiOWqd3mn0OUtU0qs/sQjNrS3tI56mEopCsXzdbQFAgq4zN2yod+uzLdx3aUdlIJaUN8/WoigxdzB2fJok8Vgg8EU3CL1S2+rCajjueJfafdrnA/mz5qOLVJ+E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com; spf=pass smtp.mailfrom=baylibre.com; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b=U3OP/jeX; arc=none smtp.client-ip=209.85.221.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=baylibre.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="U3OP/jeX" Received: by mail-wr1-f44.google.com with SMTP id ffacd0b85a97d-3730749ee7aso722672f8f.2 for ; Thu, 29 Aug 2024 13:16:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1724962578; x=1725567378; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=0NSe3kJCdAnk8fxBGYDM5JR1V1f/i3ndMrx1xJImgPc=; b=U3OP/jeXeaz4oqI4A0lO4+OndD2DkmzZADhLJhdpuy23rxWffDDGmgeetJ0lpDcBrI KKnH1Pzuv7aPhyK8ZTS07l1s98L5wovMWcIF8KF2RVrlZl9b8Lxu9eDLEO1BHZcJPdio nVGOCqenjX6NheKrtq7Ez/zYJ+A/uCWO/mdwYDZ416bfL1lwuySU/Pso4hLIycCM3I7z lN/kJxNJFmmFNbERczeTNjLIWxnDgbtu3uyKznk+NQEtzMVZn8k8uGTMerfrcCjepV1p B796ffajT/B7Viufqg8LP8qDtVoNf7/44cBkk5VUJutFKphuizctXN3WAhYgL8E+w56C kn0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724962578; x=1725567378; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=0NSe3kJCdAnk8fxBGYDM5JR1V1f/i3ndMrx1xJImgPc=; b=g9R8QJ00dG4xbNI2kJQngzXtF9PHpmuEE6MmYRCuirX/yk9Lk1LLC4Pbs11g7S5cQn c6ak/fa2AFXOfZXrfmhxrscREtf9ItfHWWv180zWsMbYbSylaRsOIdR7QxH3Olg6sECG hQOXamlnWowo/sgAtYXt7OJFEa0OOJ0TEUF6iiAHnE9Uf9f7nHC7QdjHb7ExL4TeTWme VwzwZ8teJ2RR6wGawwx7PbQiV9RYnUZ6vOVkAefoDDI+ZMw4ouoz+aR4pczYWE8pAt8K dniu9RvQXZOCEk9SI9fAuMdRGeYJ1GdUfKP/FvsYPNoPzbsc/imHFTzSow0WXBIpGE40 HIFA== X-Forwarded-Encrypted: i=1; AJvYcCVUr2uFbemvjkGeJKa7mhYDsXVy1zdEvbOgeLb+YbiSERU9EA9J9eXy5PgB+v3VrlYwedps4PoA05YDR6c=@vger.kernel.org X-Gm-Message-State: AOJu0Yz1FJ3+1xktyhZFcuGJfoM0zP2JCmdMz5spPJtVXcpYcysUYaFY tj28zrDVpGXFtd7RgnwcT53LVQRrSHFE2XDo42a8f4aNQlEVy32E4UmBZ43Pfj0= X-Google-Smtp-Source: AGHT+IEwBCg3v0reTBTsBgwPvgqpkZez+Txf1nVrUpVsg2nvKWLfe7Nn37pnVbgRe07amPYMjnlFzg== X-Received: by 2002:a05:6000:104c:b0:368:3f60:8725 with SMTP id ffacd0b85a97d-3749b57ecccmr2665767f8f.39.1724962577905; Thu, 29 Aug 2024 13:16:17 -0700 (PDT) Received: from blmsp.fritz.box ([2001:4091:a245:802f:3a47:b29:5530:28a2]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42bb6deb303sm26681385e9.9.2024.08.29.13.16.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Aug 2024 13:16:17 -0700 (PDT) From: Markus Schneider-Pargmann To: Nishanth Menon , Tero Kristo , Santosh Shilimkar Cc: Vibhore Vardhan , Kevin Hilman , Dhruva Gole , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Dave Gerlach , Georgi Vlaev , Akashdeep Kaur , Markus Schneider-Pargmann Subject: [PATCH v11 3/4] firmware: ti_sci: Introduce Power Management Ops Date: Thu, 29 Aug 2024 22:16:04 +0200 Message-ID: <20240829201606.1407773-4-msp@baylibre.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240829201606.1407773-1-msp@baylibre.com> References: <20240829201606.1407773-1-msp@baylibre.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Dave Gerlach Introduce power management ops supported by the TISCI Low Power Mode API [1]. 1) TISCI_MSG_LPM_WAKE_REASON Get which wake up source woke the SoC from Low Power Mode. The wake up source IDs will be common for all K3 platforms. 2) TISCI_MSG_LPM_SET_DEVICE_CONSTRAINT Set LPM constraint on behalf of a device. By setting a constraint, the device ensures that it will not be powered off or reset in the selected mode. 3) TISCI_MSG_LPM_SET_LATENCY_CONSTRAINT Set LPM resume latency constraint. By setting a constraint, the host ensures that the resume time from selected mode will be less than the constraint value. [1] https://software-dl.ti.com/tisci/esd/latest/2_tisci_msgs/pm/lpm.html Signed-off-by: Dave Gerlach [g-vlaev@ti.com: LPM_WAKE_REASON and IO_ISOLATION support] Signed-off-by: Georgi Vlaev [a-kaur@ti.com: SET_DEVICE_CONSTRAINT support] Signed-off-by: Akashdeep Kaur [vibhore@ti.com: SET_LATENCY_CONSTRAINT support] Signed-off-by: Vibhore Vardhan Signed-off-by: Kevin Hilman Reviewed-by: Akashdeep Kaur Tested-by: Dhruva Gole Signed-off-by: Markus Schneider-Pargmann Acked-by: Dhruva Gole --- drivers/firmware/ti_sci.c | 198 +++++++++++++++++++++++++ drivers/firmware/ti_sci.h | 76 ++++++++++ include/linux/soc/ti/ti_sci_protocol.h | 26 ++++ 3 files changed, 300 insertions(+) diff --git a/drivers/firmware/ti_sci.c b/drivers/firmware/ti_sci.c index 8a772b378ffa..8482b7077eef 100644 --- a/drivers/firmware/ti_sci.c +++ b/drivers/firmware/ti_sci.c @@ -1834,6 +1834,186 @@ static int ti_sci_cmd_set_io_isolation(const struct= ti_sci_handle *handle, return ret; } =20 +/** + * ti_sci_msg_cmd_lpm_wake_reason() - Get the wakeup source from LPM + * @handle: Pointer to TI SCI handle + * @source: The wakeup source that woke the SoC from LPM + * @timestamp: Timestamp of the wakeup event + * @pin: The pin that has triggered wake up + * @mode: The last entered low power mode + * + * Return: 0 if all went well, else returns appropriate error value. + */ +static int ti_sci_msg_cmd_lpm_wake_reason(const struct ti_sci_handle *hand= le, + u32 *source, u64 *timestamp, u8 *pin, u8 *mode) +{ + struct ti_sci_info *info; + struct ti_sci_xfer *xfer; + struct ti_sci_msg_resp_lpm_wake_reason *resp; + struct device *dev; + int ret =3D 0; + + if (IS_ERR(handle)) + return PTR_ERR(handle); + if (!handle) + return -EINVAL; + + info =3D handle_to_ti_sci_info(handle); + dev =3D info->dev; + + xfer =3D ti_sci_get_one_xfer(info, TI_SCI_MSG_LPM_WAKE_REASON, + TI_SCI_FLAG_REQ_ACK_ON_PROCESSED, + sizeof(struct ti_sci_msg_hdr), + sizeof(*resp)); + if (IS_ERR(xfer)) { + ret =3D PTR_ERR(xfer); + dev_err(dev, "Message alloc failed(%d)\n", ret); + return ret; + } + + ret =3D ti_sci_do_xfer(info, xfer); + if (ret) { + dev_err(dev, "Mbox send fail %d\n", ret); + goto fail; + } + + resp =3D (struct ti_sci_msg_resp_lpm_wake_reason *)xfer->xfer_buf; + + if (!ti_sci_is_response_ack(resp)) { + dev_err(dev, "Failed to get wake reason\n"); + ret =3D -ENODEV; + goto fail; + } + + if (source) + *source =3D resp->wake_source; + if (timestamp) + *timestamp =3D resp->wake_timestamp; + if (pin) + *pin =3D resp->wake_pin; + if (mode) + *mode =3D resp->mode; + +fail: + ti_sci_put_one_xfer(&info->minfo, xfer); + + return ret; +} + +/** + * ti_sci_cmd_set_device_constraint() - Set LPM constraint on behalf of a = device + * @handle: pointer to TI SCI handle + * @id: Device identifier + * @state: The desired state of device constraint: set or clear + * + * Return: 0 if all went well, else returns appropriate error value. + */ +static int ti_sci_cmd_set_device_constraint(const struct ti_sci_handle *ha= ndle, + u32 id, u8 state) +{ + struct ti_sci_info *info; + struct ti_sci_msg_req_lpm_set_device_constraint *req; + struct ti_sci_msg_hdr *resp; + struct ti_sci_xfer *xfer; + struct device *dev; + int ret =3D 0; + + if (IS_ERR(handle)) + return PTR_ERR(handle); + if (!handle) + return -EINVAL; + + info =3D handle_to_ti_sci_info(handle); + dev =3D info->dev; + + xfer =3D ti_sci_get_one_xfer(info, TI_SCI_MSG_LPM_SET_DEVICE_CONSTRAINT, + TI_SCI_FLAG_REQ_ACK_ON_PROCESSED, + sizeof(*req), sizeof(*resp)); + if (IS_ERR(xfer)) { + ret =3D PTR_ERR(xfer); + dev_err(dev, "Message alloc failed(%d)\n", ret); + return ret; + } + req =3D (struct ti_sci_msg_req_lpm_set_device_constraint *)xfer->xfer_buf; + req->id =3D id; + req->state =3D state; + + ret =3D ti_sci_do_xfer(info, xfer); + if (ret) { + dev_err(dev, "Mbox send fail %d\n", ret); + goto fail; + } + + resp =3D (struct ti_sci_msg_hdr *)xfer->xfer_buf; + + if (!ti_sci_is_response_ack(resp)) { + dev_err(dev, "Failed to set device constraint\n"); + ret =3D -ENODEV; + } + +fail: + ti_sci_put_one_xfer(&info->minfo, xfer); + + return ret; +} + +/** + * ti_sci_cmd_set_latency_constraint() - Set LPM resume latency constraint + * @handle: pointer to TI SCI handle + * @latency: maximum acceptable latency (in ms) to wake up from LPM + * @state: The desired state of latency constraint: set or clear + * + * Return: 0 if all went well, else returns appropriate error value. + */ +static int ti_sci_cmd_set_latency_constraint(const struct ti_sci_handle *h= andle, + u16 latency, u8 state) +{ + struct ti_sci_info *info; + struct ti_sci_msg_req_lpm_set_latency_constraint *req; + struct ti_sci_msg_hdr *resp; + struct ti_sci_xfer *xfer; + struct device *dev; + int ret =3D 0; + + if (IS_ERR(handle)) + return PTR_ERR(handle); + if (!handle) + return -EINVAL; + + info =3D handle_to_ti_sci_info(handle); + dev =3D info->dev; + + xfer =3D ti_sci_get_one_xfer(info, TI_SCI_MSG_LPM_SET_LATENCY_CONSTRAINT, + TI_SCI_FLAG_REQ_ACK_ON_PROCESSED, + sizeof(*req), sizeof(*resp)); + if (IS_ERR(xfer)) { + ret =3D PTR_ERR(xfer); + dev_err(dev, "Message alloc failed(%d)\n", ret); + return ret; + } + req =3D (struct ti_sci_msg_req_lpm_set_latency_constraint *)xfer->xfer_bu= f; + req->latency =3D latency; + req->state =3D state; + + ret =3D ti_sci_do_xfer(info, xfer); + if (ret) { + dev_err(dev, "Mbox send fail %d\n", ret); + goto fail; + } + + resp =3D (struct ti_sci_msg_hdr *)xfer->xfer_buf; + + if (!ti_sci_is_response_ack(resp)) { + dev_err(dev, "Failed to set device constraint\n"); + ret =3D -ENODEV; + } + +fail: + ti_sci_put_one_xfer(&info->minfo, xfer); + + return ret; +} + static int ti_sci_cmd_core_reboot(const struct ti_sci_handle *handle) { struct ti_sci_info *info; @@ -2976,6 +3156,7 @@ static void ti_sci_setup_ops(struct ti_sci_info *info) struct ti_sci_core_ops *core_ops =3D &ops->core_ops; struct ti_sci_dev_ops *dops =3D &ops->dev_ops; struct ti_sci_clk_ops *cops =3D &ops->clk_ops; + struct ti_sci_pm_ops *pmops =3D &ops->pm_ops; struct ti_sci_rm_core_ops *rm_core_ops =3D &ops->rm_core_ops; struct ti_sci_rm_irq_ops *iops =3D &ops->rm_irq_ops; struct ti_sci_rm_ringacc_ops *rops =3D &ops->rm_ring_ops; @@ -3015,6 +3196,13 @@ static void ti_sci_setup_ops(struct ti_sci_info *inf= o) cops->set_freq =3D ti_sci_cmd_clk_set_freq; cops->get_freq =3D ti_sci_cmd_clk_get_freq; =20 + if (info->fw_caps & MSG_FLAG_CAPS_LPM_DM_MANAGED) { + pr_debug("detected DM managed LPM in fw_caps\n"); + pmops->lpm_wake_reason =3D ti_sci_msg_cmd_lpm_wake_reason; + pmops->set_device_constraint =3D ti_sci_cmd_set_device_constraint; + pmops->set_latency_constraint =3D ti_sci_cmd_set_latency_constraint; + } + rm_core_ops->get_range =3D ti_sci_cmd_get_resource_range; rm_core_ops->get_range_from_shost =3D ti_sci_cmd_get_resource_range_from_shost; @@ -3506,11 +3694,21 @@ static int __maybe_unused ti_sci_resume_noirq(struc= t device *dev) { struct ti_sci_info *info =3D dev_get_drvdata(dev); int ret =3D 0; + u32 source; + u64 time; + u8 pin; + u8 mode; =20 ret =3D ti_sci_cmd_set_io_isolation(&info->handle, TISCI_MSG_VALUE_IO_DIS= ABLE); if (ret) return ret; =20 + ret =3D ti_sci_msg_cmd_lpm_wake_reason(&info->handle, &source, &time, &pi= n, &mode); + /* Do not fail to resume on error as the wake reason is not critical */ + if (!ret) + dev_info(dev, "ti_sci: wakeup source:0x%x, pin:0x%x, mode:0x%x\n", + source, pin, mode); + return 0; } =20 diff --git a/drivers/firmware/ti_sci.h b/drivers/firmware/ti_sci.h index 8efe4d0e61fb..053387d7baa0 100644 --- a/drivers/firmware/ti_sci.h +++ b/drivers/firmware/ti_sci.h @@ -38,7 +38,10 @@ =20 /* Low Power Mode Requests */ #define TI_SCI_MSG_PREPARE_SLEEP 0x0300 +#define TI_SCI_MSG_LPM_WAKE_REASON 0x0306 #define TI_SCI_MSG_SET_IO_ISOLATION 0x0307 +#define TI_SCI_MSG_LPM_SET_DEVICE_CONSTRAINT 0x0309 +#define TI_SCI_MSG_LPM_SET_LATENCY_CONSTRAINT 0x030A =20 /* Resource Management Requests */ #define TI_SCI_MSG_GET_RESOURCE_RANGE 0x1500 @@ -610,6 +613,79 @@ struct ti_sci_msg_req_set_io_isolation { u8 state; } __packed; =20 +/** + * struct ti_sci_msg_resp_lpm_wake_reason - Response for TI_SCI_MSG_LPM_WA= KE_REASON. + * + * @hdr: Generic header. + * @wake_source: The wake up source that woke soc from LPM. + * @wake_timestamp: Timestamp at which soc woke. + * @wake_pin: The pin that has triggered wake up. + * @mode: The last entered low power mode. + * @rsvd: Reserved for future use. + * + * Response to a generic message with message type TI_SCI_MSG_LPM_WAKE_REA= SON, + * used to query the wake up source, pin and entered low power mode. + */ +struct ti_sci_msg_resp_lpm_wake_reason { + struct ti_sci_msg_hdr hdr; + u32 wake_source; + u64 wake_timestamp; + u8 wake_pin; + u8 mode; + u32 rsvd[2]; +} __packed; + +/** + * struct ti_sci_msg_req_lpm_set_device_constraint - Request for + * TISCI_MSG_LPM_SET_DEVICE_CONSTRAINT. + * + * @hdr: TISCI header to provide ACK/NAK flags to the host. + * @id: Device ID of device whose constraint has to be modified. + * @state: The desired state of device constraint: set or clear. + * @rsvd: Reserved for future use. + * + * This message is used by host to set constraint on the device. This can = be + * sent anytime after boot before prepare sleep message. Any device can se= t a + * constraint on the low power mode that the SoC can enter. It allows + * configurable information to be easily shared from the application, as t= his + * is a non-secure message and therefore can be sent by anyone. By setting= a + * constraint, the device ensures that it will not be powered off or reset= in + * the selected mode. Note: Access Restriction: Exclusivity flag of Device= will + * be honored. If some other host already has constraint on this device ID, + * NACK will be returned. + */ +struct ti_sci_msg_req_lpm_set_device_constraint { + struct ti_sci_msg_hdr hdr; + u32 id; + u8 state; + u32 rsvd[2]; +} __packed; + +/** + * struct ti_sci_msg_req_lpm_set_latency_constraint - Request for + * TISCI_MSG_LPM_SET_LATENCY_CONSTRAINT. + * + * @hdr: TISCI header to provide ACK/NAK flags to the host. + * @wkup_latency: The maximum acceptable latency to wake up from low power= mode + * in milliseconds. The deeper the state, the higher the latency. + * @state: The desired state of wakeup latency constraint: set or clear. + * @rsvd: Reserved for future use. + * + * This message is used by host to set wakeup latency from low power mode.= This can + * be sent anytime after boot before prepare sleep message, and can be sen= t after + * current low power mode is exited. Any device can set a constraint on th= e low power + * mode that the SoC can enter. It allows configurable information to be e= asily shared + * from the application, as this is a non-secure message and therefore can= be sent by + * anyone. By setting a wakeup latency constraint, the host ensures that t= he resume time + * from selected low power mode will be less than the constraint value. + */ +struct ti_sci_msg_req_lpm_set_latency_constraint { + struct ti_sci_msg_hdr hdr; + u16 latency; + u8 state; + u32 rsvd; +} __packed; + #define TI_SCI_IRQ_SECONDARY_HOST_INVALID 0xff =20 /** diff --git a/include/linux/soc/ti/ti_sci_protocol.h b/include/linux/soc/ti/= ti_sci_protocol.h index 1f1871e23f76..fd104b666836 100644 --- a/include/linux/soc/ti/ti_sci_protocol.h +++ b/include/linux/soc/ti/ti_sci_protocol.h @@ -199,6 +199,31 @@ struct ti_sci_clk_ops { #define TISCI_MSG_VALUE_IO_ENABLE 1 #define TISCI_MSG_VALUE_IO_DISABLE 0 =20 +/* TISCI LPM constraint state values */ +#define TISCI_MSG_CONSTRAINT_SET 1 +#define TISCI_MSG_CONSTRAINT_CLR 0 + +/** + * struct ti_sci_pm_ops - Low Power Mode (LPM) control operations + * @lpm_wake_reason: Get the wake up source that woke the SoC from LPM + * - source: The wake up source that woke soc from LPM. + * - timestamp: Timestamp at which soc woke. + * @set_device_constraint: Set LPM constraint on behalf of a device + * - id: Device Identifier + * - state: The desired state of device constraint: set or clear. + * @set_latency_constraint: Set LPM resume latency constraint + * - latency: maximum acceptable latency to wake up from low power mode + * - state: The desired state of latency constraint: set or clear. + */ +struct ti_sci_pm_ops { + int (*lpm_wake_reason)(const struct ti_sci_handle *handle, + u32 *source, u64 *timestamp, u8 *pin, u8 *mode); + int (*set_device_constraint)(const struct ti_sci_handle *handle, + u32 id, u8 state); + int (*set_latency_constraint)(const struct ti_sci_handle *handle, + u16 latency, u8 state); +}; + /** * struct ti_sci_resource_desc - Description of TI SCI resource instance r= ange. * @start: Start index of the first resource range. @@ -543,6 +568,7 @@ struct ti_sci_ops { struct ti_sci_core_ops core_ops; struct ti_sci_dev_ops dev_ops; struct ti_sci_clk_ops clk_ops; + struct ti_sci_pm_ops pm_ops; struct ti_sci_rm_core_ops rm_core_ops; struct ti_sci_rm_irq_ops rm_irq_ops; struct ti_sci_rm_ringacc_ops rm_ring_ops; --=20 2.45.2 From nobody Thu Dec 18 23:39:09 2025 Received: from mail-wm1-f52.google.com (mail-wm1-f52.google.com [209.85.128.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8CBF61BA88F for ; Thu, 29 Aug 2024 20:16:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724962582; cv=none; b=AifXg9RQg3bkZ3JDHGsi/BmyYKUqj3pkCbcw6J6eO1vfjSThsQOulk38HRs/2DSYoKnRm9Rr/EPdMEuAp6ukzZJBly6VyTYycd2pO1+GArSEiD+qN0fb4WDGQNbzJbYX/1+KrDgU+J7C+XDbPwcWm4B91Zo/ghNRMQcwxOY0VJU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724962582; c=relaxed/simple; bh=A6Dz60AD+ga95ilNqCCxo3WOK2G69iNC5GdueqoGzbE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FMmkwNtyRrmNcTQECzyyKqkLt53og+w/2fpRbiEsQuMNnw6unPNJ+FfQk+CZ4Ie4irFoeRt+1Y9SiFgAWDMciMLPiDmmFbVCVVsUU+hWpb3q4U6WaVXM0D6HjpbEOsADPY7c+lmahd7zEHGQVfCrCCRJ2zD8X0F0YEELYLH3DFA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com; spf=pass smtp.mailfrom=baylibre.com; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b=pyLnjCIe; arc=none smtp.client-ip=209.85.128.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=baylibre.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="pyLnjCIe" Received: by mail-wm1-f52.google.com with SMTP id 5b1f17b1804b1-42bb6d3e260so9424435e9.1 for ; Thu, 29 Aug 2024 13:16:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1724962579; x=1725567379; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=JWfsv29r3VhWhUdf7/jPyF2un00LRMtxeQCEnGIAQLs=; b=pyLnjCIe79H6Ig4QaHUDFzQWwYkUfdHHFOl0kDN2nnVB6QGivk1sTg4FCmpEmBPJjG LczjcHzR9KdooMpndI44MCArQ6QmnZT9HUdBLaR6+hQIX+sd9oeRa5fZ76JalLB8QoMv P3/J/Eswed65VOdBE58N1tF5cAcj99LWkw6FnGGmHun5eZfsjfv3h5JAcjN1PW5h2Q9K NR2UpjUR3MQmHRufQmvnCyeEXTp1adpwda3SayTUHgaJR15u5fBOikmNL2qFGRrQ/hjm D3+MClQManRtnpOf539JUGWtPTL5+BGC8XNkjRhkDKtZkpBc13Qyb3mw5n+PjGhqNRjm WHPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724962579; x=1725567379; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=JWfsv29r3VhWhUdf7/jPyF2un00LRMtxeQCEnGIAQLs=; b=l47fdVbYKVB0BfylBAE074AWI5mfmiZ70ot/cZG7xSOQaHwltNHlIXEsFZxb4dOK6X ZQVjZIr83ondJr1TxJFxt8y1fD+pySzHU8KDzX5m9FG+8+EydNqqUcqZO3CNZrUTivW5 YrO+v5YhdTrvT8InW5LEwyvw8PgQTNSvMC4xnXnXmN9tLMjMeizeToIciBCr17DmGanC OJRRpDxh1VX51jfJhsVQSWt8FjgikNkYkaoP9GOMwAKz7TtAWXUqDKLBrVXft+lgai24 8sDgAvjSecPDcAIHM0VsedPlr4H/iVaETmaveq/jRPjVXMhpH3GC5RNzbAqSCQPyPCzr 3xQw== X-Forwarded-Encrypted: i=1; AJvYcCWVn4xD8IBbB9os5p2jh8mQztGqIFlEuCTpw6V6pwHC8dy6k7Dwo6pE5ufBMZcu31SSTnPT2NW73ZvwHfI=@vger.kernel.org X-Gm-Message-State: AOJu0YyC3w28Li5uXOX/+eFu3uf3tuIpXlHfq8rmy9CiQPUHUlAVyoeW gJCg0EpG5jvPw8F/RV0Kgtq02jI6eJKV4IeApLjAdDpTdcVRkS/nze946HHhzM4= X-Google-Smtp-Source: AGHT+IENmqCm1q5qqRQc1yXcMb059f8u73uG8GUWYmbtJQbfirOWVwNs39SXI20l1WQ9ce5IcIBbGQ== X-Received: by 2002:a05:600c:3b11:b0:426:6667:5c42 with SMTP id 5b1f17b1804b1-42bb023cdc0mr33044905e9.4.1724962578764; Thu, 29 Aug 2024 13:16:18 -0700 (PDT) Received: from blmsp.fritz.box ([2001:4091:a245:802f:3a47:b29:5530:28a2]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42bb6deb303sm26681385e9.9.2024.08.29.13.16.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Aug 2024 13:16:18 -0700 (PDT) From: Markus Schneider-Pargmann To: Nishanth Menon , Tero Kristo , Santosh Shilimkar Cc: Vibhore Vardhan , Kevin Hilman , Dhruva Gole , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Markus Schneider-Pargmann Subject: [PATCH v11 4/4] firmware: ti_sci: add CPU latency constraint management Date: Thu, 29 Aug 2024 22:16:05 +0200 Message-ID: <20240829201606.1407773-5-msp@baylibre.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240829201606.1407773-1-msp@baylibre.com> References: <20240829201606.1407773-1-msp@baylibre.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Kevin Hilman During system-wide suspend, check if any of the CPUs have PM QoS resume latency constraints set. If so, set TI SCI constraint. TI SCI has a single system-wide latency constraint, so use the max of any of the CPU latencies as the system-wide value. Note: DM firmware clears all constraints at resume time, so constraints need to be checked/updated/sent at each system suspend. Co-developed-by: Vibhore Vardhan Signed-off-by: Vibhore Vardhan Reviewed-by: Dhruva Gole Signed-off-by: Dhruva Gole Signed-off-by: Kevin Hilman Tested-by: Dhruva Gole Signed-off-by: Markus Schneider-Pargmann --- drivers/firmware/ti_sci.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/drivers/firmware/ti_sci.c b/drivers/firmware/ti_sci.c index 8482b7077eef..d5d64e5ffbd7 100644 --- a/drivers/firmware/ti_sci.c +++ b/drivers/firmware/ti_sci.c @@ -10,6 +10,7 @@ #define pr_fmt(fmt) "%s: " fmt, __func__ =20 #include +#include #include #include #include @@ -20,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -3669,7 +3671,27 @@ static int ti_sci_prepare_system_suspend(struct ti_s= ci_info *info) static int __maybe_unused ti_sci_suspend(struct device *dev) { struct ti_sci_info *info =3D dev_get_drvdata(dev); - int ret; + struct device *cpu_dev, *cpu_dev_max =3D NULL; + s32 val, cpu_lat =3D 0; + int i, ret; + + if (info->fw_caps & MSG_FLAG_CAPS_LPM_DM_MANAGED) { + for_each_possible_cpu(i) { + cpu_dev =3D get_cpu_device(i); + val =3D dev_pm_qos_read_value(cpu_dev, DEV_PM_QOS_RESUME_LATENCY); + if (val !=3D PM_QOS_RESUME_LATENCY_NO_CONSTRAINT) { + cpu_lat =3D max(cpu_lat, val); + cpu_dev_max =3D cpu_dev; + } + } + if (cpu_dev_max) { + dev_dbg(cpu_dev_max, "%s: sending max CPU latency=3D%u\n", __func__, cp= u_lat); + ret =3D ti_sci_cmd_set_latency_constraint(&info->handle, + cpu_lat, TISCI_MSG_CONSTRAINT_SET); + if (ret) + return ret; + } + } =20 ret =3D ti_sci_prepare_system_suspend(info); if (ret) --=20 2.45.2