From patchwork Mon Nov 28 14:05:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Georgi Vlaev X-Patchwork-Id: 26786 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp5695315wrr; Mon, 28 Nov 2022 06:10:57 -0800 (PST) X-Google-Smtp-Source: AA0mqf4Z6Da+6ZO3o627/Lg2eT1zhvZbD9fXPbmEtxwH4KdE4moeUGi7gIR4z8i3JSDfL/QHUpqb X-Received: by 2002:a05:6638:1a98:b0:375:61b2:825a with SMTP id ce24-20020a0566381a9800b0037561b2825amr24540226jab.147.1669644657511; Mon, 28 Nov 2022 06:10:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669644657; cv=none; d=google.com; s=arc-20160816; b=Cfmk0HXY2jWTBQLRTUJvAXT9iMF+wsUQ6XOIXS2FE4Hq+wgcIEu7l+f21pAv+BZftp 7AsoUrgF277nnn1wHSWWjw0xPmEwpiBht4ALclgwxlcMPO45yG1/yQChbfrLCQMZBiK3 847WMiUWvROg1LEto5yJuur/JJWafE2tA0biTOCu6LXlAi/lh6rCKX4++gFd09An/nli wm0Dq+Li3qLUPBn08pN6pshra+QZ1d/1fiipG6hKv2YdDidfWkbFfSOLXJgBXcp6gwO9 lTxDZLnLXU9E4S1puCWxknLgNMWIUBJpMEmjvdU++5tH1PaJ3hKAY0Ttz57UeniEsWsD nbNw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=EL2GD7RH1r/qBE+G7f9QX035vVk4JvRCI5hwA6WOgqA=; b=N+8cOMqPvCiqufedeBeYUatHetydLvM5w4BS+faWWMh+adpTW8rREUiszRbZKmjlKU In6En+dQ3haLAtOSZBvFtdv+/RQeDgLBCVycUTVEMN2sfv8Wvp+EVwd1GasY6ImP0GR/ I3w1PIhEb2pe6xVee85gX5DZF5o+qoZgIxMG2YAMFaPapAekhO+dl6Xtl4mZZODwAHe3 pC+mIPlPeBzWnfqL7wbj8p7ySC+HUTyLR1yXaIRRXIhsQu6dcN12LBirV/KSx41l7+A5 n8AdhPz1DytfwWqsJlFbhTOTyh7ocLhHyISkTOcWcSSzjY55psLE6ApospGmXldlVNov vZiQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=fU9uCxWv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w19-20020a05640234d300b004619867344csi11934764edc.0.2022.11.28.06.10.27; Mon, 28 Nov 2022 06:10:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=fU9uCxWv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232284AbiK1OFr (ORCPT + 99 others); Mon, 28 Nov 2022 09:05:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32944 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231317AbiK1OFp (ORCPT ); Mon, 28 Nov 2022 09:05:45 -0500 Received: from lelv0142.ext.ti.com (lelv0142.ext.ti.com [198.47.23.249]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EACF5178B0; Mon, 28 Nov 2022 06:05:44 -0800 (PST) Received: from lelv0265.itg.ti.com ([10.180.67.224]) by lelv0142.ext.ti.com (8.15.2/8.15.2) with ESMTP id 2ASE5cQ6080222; Mon, 28 Nov 2022 08:05:38 -0600 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1669644338; bh=EL2GD7RH1r/qBE+G7f9QX035vVk4JvRCI5hwA6WOgqA=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=fU9uCxWvs4f9JT4QP8p+JcLrRSMUc+/EwBIuvKT8Hxz29kiW0Qi4mPmBuXlu816+L 2LA4CdCXfRvpXHOHUxJAqQfQWJWQ7fA6/DMffWTilTNqr7OzOlqmQeOHa47YMxdpv6 TMsBujxLfOlLOPSumN+ZKz8tYDsg4GBZ5YNVr36Q= Received: from DFLE105.ent.ti.com (dfle105.ent.ti.com [10.64.6.26]) by lelv0265.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 2ASE5c8c023701 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 28 Nov 2022 08:05:38 -0600 Received: from DFLE103.ent.ti.com (10.64.6.24) by DFLE105.ent.ti.com (10.64.6.26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.16; Mon, 28 Nov 2022 08:05:37 -0600 Received: from fllv0039.itg.ti.com (10.64.41.19) by DFLE103.ent.ti.com (10.64.6.24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.16 via Frontend Transport; Mon, 28 Nov 2022 08:05:37 -0600 Received: from jti.ent.ti.com (ileaxei01-snat2.itg.ti.com [10.180.69.6]) by fllv0039.itg.ti.com (8.15.2/8.15.2) with ESMTP id 2ASE5NQa125815; Mon, 28 Nov 2022 08:05:31 -0600 From: Georgi Vlaev To: Nishanth Menon , Tero Kristo , Santosh Shilimkar , Rob Herring , Krzysztof Kozlowski CC: , , , Vibhore Vardhan , Vignesh Raghavendra , Roger Quadros , Georgi Vlaev , Rob Herring Subject: [PATCH v5 1/6] dt-bindings: ti, sci: Add lpm region and firmware-name Date: Mon, 28 Nov 2022 16:05:17 +0200 Message-ID: <20221128140522.49474-2-g-vlaev@ti.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221128140522.49474-1-g-vlaev@ti.com> References: <20221128140522.49474-1-g-vlaev@ti.com> MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750749316253020385?= X-GMAIL-MSGID: =?utf-8?q?1750749316253020385?= From: Dave Gerlach Add documentation for the lpm region which tells the ti-sci driver where to load the FS Stub low power mode firmware and also the firmware-name which tells the driver which binary to load. Both of these are optional for normal system operation but required to enabled suspend-to-mem usage of Deep Sleep state. Signed-off-by: Dave Gerlach Signed-off-by: Vibhore Vardhan Signed-off-by: Georgi Vlaev Reviewed-by: Rob Herring --- .../bindings/arm/keystone/ti,sci.yaml | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/Documentation/devicetree/bindings/arm/keystone/ti,sci.yaml b/Documentation/devicetree/bindings/arm/keystone/ti,sci.yaml index 34f5f877d444..4c5213de24bc 100644 --- a/Documentation/devicetree/bindings/arm/keystone/ti,sci.yaml +++ b/Documentation/devicetree/bindings/arm/keystone/ti,sci.yaml @@ -42,12 +42,19 @@ properties: - const: ti,am654-sci reg-names: - description: | - Specifies the debug messages memory mapped region that is optionally - made available from TI-SCI controller. - const: debug_messages + items: + - const: debug_messages + - const: lpm + minItems: 1 reg: + items: + - description: | + Specifies the debug messages memory mapped region that is optionally + made available from TI-SCI controller. + - description: | + Specifies the lpm memory mapped region where the FS Stub low power + firmware is to be loaded. minItems: 1 mbox-names: @@ -83,6 +90,12 @@ properties: type: object $ref: /schemas/reset/ti,sci-reset.yaml# + firmware-name: + description: | + Name of binary of FS Stub low power firmware located on the + firmware search path. + $ref: /schemas/types.yaml#/definitions/string + required: - compatible - mbox-names From patchwork Mon Nov 28 14:05:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Georgi Vlaev X-Patchwork-Id: 26788 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp5695733wrr; Mon, 28 Nov 2022 06:11:25 -0800 (PST) X-Google-Smtp-Source: AA0mqf4QyB+84TWZX2MOXOJqPY92Fh9545QDjNx5NdW9jOq6Txozbw+sOiVsQeR66ADwT+h33kZJ X-Received: by 2002:a17:906:c08:b0:7bf:99a6:95aa with SMTP id s8-20020a1709060c0800b007bf99a695aamr4998926ejf.7.1669644685061; Mon, 28 Nov 2022 06:11:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669644685; cv=none; d=google.com; s=arc-20160816; b=PF7UpEYXL0oYFyAMCAsLh65y5NeHylm8s+4/Hij5XTIK4ECds/kdJV/Fxdvw4R2mR/ WwYxaLc5fP3tIIeL5sa1adkTfXrBh4wU8BfhP2R2OoLTNcjLa+rOzLfEecqqAnCOxfYK f0ey5c4wGtAXkacLD5PGrX/YfO1y/b0pLOfEPTh38QGYWX63XcFvTnuuQ68ZtpFQpRQ7 mK15HcZVRDdSBi6bWf4oid91kJKV3QQGsVneAw4WvR9hc/yTjJRBVK3Fb1sNh+3shQKO 1EiJ7h9wz2yoVF1FoSjS1lDGa0qWCnoSVAz7Otr4/vHz9LsunItchfCkRVWOvPqacZon iVAg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=y5YHKmHVxmak5XKdcTGYPNkdUMPsKExUcJdgTk7n1N0=; b=im1lU/s/u8Xmmc56VcfFIXQAcN5PCj/fkF9hSELetmBEwooak8ys2TJfe5Ouc+EzDh 1pUTde9iIPfHHb88XBkLFSx27nGyKkKIgu6BI4BYGw/SETukKfYdX9Lstwj2FuSTnuoK jX0V4Zwl3tjpmtwdwf19Zs6fHCfefowcvHbmj1x7Hv0UCC+qwQFvF85LAkeBwtV/D7lA Fn4J+234yL6sEHLm8VM1b0Sj98RdeVO4DF+kGW7r2Z/FgbRTviWRlLf+UnYMd/1IKDsq K7C1ydOS2BBObR4kvJje+8Y3NC/U+XHSQNpuMtcFURNnZo9CbyQPSYmGG8QLDoJNoZzx qTLA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=j6BbUZPw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g7-20020aa7d1c7000000b00461d5afea01si9079011edp.165.2022.11.28.06.10.56; Mon, 28 Nov 2022 06:11:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=j6BbUZPw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232320AbiK1OGH (ORCPT + 99 others); Mon, 28 Nov 2022 09:06:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33138 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231374AbiK1OGC (ORCPT ); Mon, 28 Nov 2022 09:06:02 -0500 Received: from fllv0016.ext.ti.com (fllv0016.ext.ti.com [198.47.19.142]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 075C020F5D; Mon, 28 Nov 2022 06:06:00 -0800 (PST) Received: from fllv0035.itg.ti.com ([10.64.41.0]) by fllv0016.ext.ti.com (8.15.2/8.15.2) with ESMTP id 2ASE5ip9086746; Mon, 28 Nov 2022 08:05:44 -0600 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1669644344; bh=y5YHKmHVxmak5XKdcTGYPNkdUMPsKExUcJdgTk7n1N0=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=j6BbUZPwrO2WOgYOJ3oIzs1DB0Mgc9yKS8zyhVaSgSe3x6uub8Fbkl9jIPGt1Rjm8 5OvgZMQK2bweGk8c4ViOYw4MXi/lwwsE5tDAHzmRpTK/PzlIfSGsozcUIxwyxZ3s1a xUhI5YVm0EkOHWxDrec+HpQJDSE3o8AKm1vahiWA= Received: from DLEE112.ent.ti.com (dlee112.ent.ti.com [157.170.170.23]) by fllv0035.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 2ASE5iDr036232 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 28 Nov 2022 08:05:44 -0600 Received: from DLEE113.ent.ti.com (157.170.170.24) by DLEE112.ent.ti.com (157.170.170.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.16; Mon, 28 Nov 2022 08:05:44 -0600 Received: from fllv0039.itg.ti.com (10.64.41.19) by DLEE113.ent.ti.com (157.170.170.24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.16 via Frontend Transport; Mon, 28 Nov 2022 08:05:44 -0600 Received: from jti.ent.ti.com (ileaxei01-snat2.itg.ti.com [10.180.69.6]) by fllv0039.itg.ti.com (8.15.2/8.15.2) with ESMTP id 2ASE5NQb125815; Mon, 28 Nov 2022 08:05:38 -0600 From: Georgi Vlaev To: Nishanth Menon , Tero Kristo , Santosh Shilimkar , Rob Herring , Krzysztof Kozlowski CC: , , , Vibhore Vardhan , Vignesh Raghavendra , Roger Quadros , Georgi Vlaev Subject: [PATCH v5 2/6] firmware: ti_sci: Introduce Power Management Ops Date: Mon, 28 Nov 2022 16:05:18 +0200 Message-ID: <20221128140522.49474-3-g-vlaev@ti.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221128140522.49474-1-g-vlaev@ti.com> References: <20221128140522.49474-1-g-vlaev@ti.com> MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750749345326607982?= X-GMAIL-MSGID: =?utf-8?q?1750749345326607982?= From: Dave Gerlach Introduce power management ops supported by the TISCI Low Power Mode API [1]. These messages are currently supported only on AM62x platforms. 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_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. 3) TISCI_MSG_SET_IO_ISOLATION Control the IO isolation for Low Power Mode. [1] https://software-dl.ti.com/tisci/esd/latest/2_tisci_msgs/pm/lpm.html Signed-off-by: Dave Gerlach Signed-off-by: Vibhore Vardhan [g-vlaev@ti.com: LPM_WAKE_REASON and IO_ISOLATION support] Signed-off-by: Georgi Vlaev Tested-by: Roger Quadros --- drivers/firmware/ti_sci.c | 175 +++++++++++++++++++++++++ drivers/firmware/ti_sci.h | 64 ++++++++- include/linux/soc/ti/ti_sci_protocol.h | 44 +++++++ 3 files changed, 282 insertions(+), 1 deletion(-) diff --git a/drivers/firmware/ti_sci.c b/drivers/firmware/ti_sci.c index ebc32bbd9b83..bace9e9cd478 100644 --- a/drivers/firmware/ti_sci.c +++ b/drivers/firmware/ti_sci.c @@ -1667,6 +1667,176 @@ static int ti_sci_cmd_clk_get_freq(const struct ti_sci_handle *handle, return ret; } +/** + * 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 = 0; + + if (IS_ERR(handle)) + return PTR_ERR(handle); + if (!handle) + return -EINVAL; + + info = handle_to_ti_sci_info(handle); + dev = info->dev; + + xfer = 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 = PTR_ERR(xfer); + dev_err(dev, "Message alloc failed(%d)\n", ret); + return ret; + } + + req = (struct ti_sci_msg_req_prepare_sleep *)xfer->xfer_buf; + req->mode = mode; + req->ctx_lo = ctx_lo; + req->ctx_hi = ctx_hi; + req->debug_flags = debug_flags; + + ret = ti_sci_do_xfer(info, xfer); + if (ret) { + dev_err(dev, "Mbox send fail %d\n", ret); + goto fail; + } + + resp = (struct ti_sci_msg_hdr *)xfer->xfer_buf; + + ret = ti_sci_is_response_ack(resp) ? 0 : -ENODEV; + +fail: + ti_sci_put_one_xfer(&info->minfo, xfer); + + return ret; +} + +/** + * 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 + * + * 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 *handle, + u32 *source, u64 *timestamp) +{ + struct ti_sci_info *info; + struct ti_sci_xfer *xfer; + struct ti_sci_msg_resp_lpm_wake_reason *resp; + struct device *dev; + int ret = 0; + + if (IS_ERR(handle)) + return PTR_ERR(handle); + if (!handle) + return -EINVAL; + + info = handle_to_ti_sci_info(handle); + dev = info->dev; + + xfer = 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 = PTR_ERR(xfer); + dev_err(dev, "Message alloc failed(%d)\n", ret); + return ret; + } + + ret = ti_sci_do_xfer(info, xfer); + if (ret) { + dev_err(dev, "Mbox send fail %d\n", ret); + goto fail; + } + + resp = (struct ti_sci_msg_resp_lpm_wake_reason *)xfer->xfer_buf; + + if (!ti_sci_is_response_ack(resp)) { + ret = -ENODEV; + goto fail; + } + + if (source) + *source = resp->wake_source; + if (timestamp) + *timestamp = resp->wake_timestamp; + +fail: + ti_sci_put_one_xfer(&info->minfo, xfer); + + return ret; +} + +/** + * 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 = 0; + + if (IS_ERR(handle)) + return PTR_ERR(handle); + if (!handle) + return -EINVAL; + + info = handle_to_ti_sci_info(handle); + dev = info->dev; + + xfer = 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 = PTR_ERR(xfer); + dev_err(dev, "Message alloc failed(%d)\n", ret); + return ret; + } + req = (struct ti_sci_msg_req_set_io_isolation *)xfer->xfer_buf; + req->state = state; + + ret = ti_sci_do_xfer(info, xfer); + if (ret) { + dev_err(dev, "Mbox send fail %d\n", ret); + goto fail; + } + + resp = (struct ti_sci_msg_hdr *)xfer->xfer_buf; + + ret = ti_sci_is_response_ack(resp) ? 0 : -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; @@ -2808,6 +2978,7 @@ static void ti_sci_setup_ops(struct ti_sci_info *info) struct ti_sci_core_ops *core_ops = &ops->core_ops; struct ti_sci_dev_ops *dops = &ops->dev_ops; struct ti_sci_clk_ops *cops = &ops->clk_ops; + struct ti_sci_pm_ops *pmops = &ops->pm_ops; struct ti_sci_rm_core_ops *rm_core_ops = &ops->rm_core_ops; struct ti_sci_rm_irq_ops *iops = &ops->rm_irq_ops; struct ti_sci_rm_ringacc_ops *rops = &ops->rm_ring_ops; @@ -2847,6 +3018,10 @@ static void ti_sci_setup_ops(struct ti_sci_info *info) cops->set_freq = ti_sci_cmd_clk_set_freq; cops->get_freq = ti_sci_cmd_clk_get_freq; + pmops->prepare_sleep = ti_sci_cmd_prepare_sleep; + pmops->lpm_wake_reason = ti_sci_msg_cmd_lpm_wake_reason; + pmops->set_io_isolation = ti_sci_cmd_set_io_isolation; + rm_core_ops->get_range = ti_sci_cmd_get_resource_range; rm_core_ops->get_range_from_shost = ti_sci_cmd_get_resource_range_from_shost; diff --git a/drivers/firmware/ti_sci.h b/drivers/firmware/ti_sci.h index ef3a8214d002..e4bfe146c43d 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: http://processors.wiki.ti.com/index.php/TISCI for details * - * Copyright (C) 2015-2016 Texas Instruments Incorporated - https://www.ti.com/ + * Copyright (C) 2015-2022 Texas Instruments Incorporated - https://www.ti.com/ */ #ifndef __TI_SCI_H @@ -35,6 +35,11 @@ #define TI_SCI_MSG_QUERY_CLOCK_FREQ 0x010d #define TI_SCI_MSG_GET_CLOCK_FREQ 0x010e +/* 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 + /* Resource Management Requests */ #define TI_SCI_MSG_GET_RESOURCE_RANGE 0x1500 @@ -545,6 +550,63 @@ struct ti_sci_msg_resp_get_clock_freq { u64 freq_hz; } __packed; +#define TISCI_MSG_VALUE_SLEEP_MODE_DEEP_SLEEP 0x0 +#define TISCI_MSG_VALUE_SLEEP_MODE_MCU_ONLY 0x1 +#define TISCI_MSG_VALUE_SLEEP_MODE_STANDBY 0x2 + +/** + * struct tisci_msg_prepare_sleep_req - Request for TISCI_MSG_PREPARE_SLEEP. + * + * @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 context save. + * @debug_flags Flags that can be set to halt the sequence during suspend 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; + u8 mode; + u32 ctx_lo; + u32 ctx_hi; + u32 debug_flags; +} __packed; + +/** + * struct ti_sci_msg_resp_lpm_wake_reason - Response for TI_SCI_MSG_LPM_WAKE_REASON. + * + * @hdr: Generic header. + * @wake_source: The wake up source that woke soc from LPM. + * @wake_timestamp: Timestamp at which soc woke. + * + * Response to a generic message with message type TI_SCI_MSG_LPM_WAKE_REASON, + * used to query the wake up source from low power mode. + */ +struct ti_sci_msg_resp_lpm_wake_reason { + struct ti_sci_msg_hdr hdr; + u32 wake_source; + u64 wake_timestamp; +} __packed; + +/** + * struct tisci_msg_set_io_isolation_req - Request for TI_SCI_MSG_SET_IO_ISOLATION. + * + * @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 /** diff --git a/include/linux/soc/ti/ti_sci_protocol.h b/include/linux/soc/ti/ti_sci_protocol.h index bd0d11af76c5..f2d1d74ab8fc 100644 --- a/include/linux/soc/ti/ti_sci_protocol.h +++ b/include/linux/soc/ti/ti_sci_protocol.h @@ -195,6 +195,49 @@ struct ti_sci_clk_ops { u64 *current_freq); }; +/* TISCI LPM wake up sources */ +#define TISCI_MSG_VALUE_LPM_WAKE_SOURCE_WKUP_I2C0 0x00 +#define TISCI_MSG_VALUE_LPM_WAKE_SOURCE_WKUP_UART0 0x10 +#define TISCI_MSG_VALUE_LPM_WAKE_SOURCE_MCU_GPIO0 0x20 +#define TISCI_MSG_VALUE_LPM_WAKE_SOURCE_WKUP_ICEMELTER0 0x30 +#define TISCI_MSG_VALUE_LPM_WAKE_SOURCE_WKUP_TIMER0 0x40 +#define TISCI_MSG_VALUE_LPM_WAKE_SOURCE_WKUP_TIMER1 0x41 +#define TISCI_MSG_VALUE_LPM_WAKE_SOURCE_WKUP_RTC0 0x50 +#define TISCI_MSG_VALUE_LPM_WAKE_SOURCE_RESET 0x60 +#define TISCI_MSG_VALUE_LPM_WAKE_SOURCE_USB0 0x70 +#define TISCI_MSG_VALUE_LPM_WAKE_SOURCE_USB1 0x71 +#define TISCI_MSG_VALUE_LPM_WAKE_SOURCE_MAIN_IO 0x80 +#define TISCI_MSG_VALUE_LPM_WAKE_SOURCE_MCU_IO 0x81 +#define TISCI_MSG_VALUE_LPM_WAKE_SOURCE_CAN_IO 0x82 +#define TISCI_MSG_VALUE_LPM_WAKE_SOURCE_INVALID 0xFF + +/* TISCI LPM IO isolation control values */ +#define TISCI_MSG_VALUE_IO_ENABLE 1 +#define TISCI_MSG_VALUE_IO_DISABLE 0 + +/** + * struct ti_sci_pm_ops - Low Power Mode (LPM) control operations + * @prepare_sleep: Prepare to enter low power mode + * - mode: Low power mode to enter. + * - ctx_lo: Low 32-bits of physical address for context save. + * - ctx_hi: High 32-bits of physical address for context save. + * - ctx_lo: 'true' if frequency change is desired. + * - debug_flags: JTAG control flags for debug. + * @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_io_isolation: Enable or disable IO isolation + * - state: The desired state of the IO isolation. + */ +struct ti_sci_pm_ops { + int (*prepare_sleep)(const struct ti_sci_handle *handle, u8 mode, + u32 ctx_lo, u32 ctx_hi, u32 flags); + int (*lpm_wake_reason)(const struct ti_sci_handle *handle, + u32 *source, u64 *timestamp); + int (*set_io_isolation)(const struct ti_sci_handle *handle, + u8 state); +}; + /** * struct ti_sci_resource_desc - Description of TI SCI resource instance range. * @start: Start index of the first resource range. @@ -539,6 +582,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; From patchwork Mon Nov 28 14:05:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Georgi Vlaev X-Patchwork-Id: 26787 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp5695526wrr; Mon, 28 Nov 2022 06:11:12 -0800 (PST) X-Google-Smtp-Source: AA0mqf5SVtvNj84h1L7SUOeufQqLQPYcyaVHlBANDiZU7CPEeqwRbe0I9kV3eV1Ym3huSEEMLVXp X-Received: by 2002:a63:4d01:0:b0:476:898c:deda with SMTP id a1-20020a634d01000000b00476898cdedamr26789364pgb.222.1669644670400; Mon, 28 Nov 2022 06:11:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669644670; cv=none; d=google.com; s=arc-20160816; b=TGU605GlA7cRqRZHFNIhiGjwzbxXLhgQXBp2X/PSWquW2HCFWOX5oy8W0x19P8svwo G+cvtmiuvsoGq0wp6CKMI9CB2Ax3ohzEu3yP+BqWwDXFqZZCmTDYGmeDLjqqJpbxiNiz wg2PTFQXZYIN8PCivfPphBIQs3YZj1jL3Ux+4IeKADuII3DklpQYwV0vCoeChhFewNvN fXPD9ckZKlnJM/L7FMIKZuefM6RgRepj6xaR6ZJ2W5b7BUA4nfa9Yc7hAt4MrC1bOECb 5W26Fge7P2TzOSlSdZLd/r1OyXfTDg7IlYgppIatyw/u6weZazKln+/7gYTeBPJc58Nb M0iA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=yJGD9dUZPktIgmbSEnoYDWr8lwSvo0rr9GJtL7kjW6M=; b=TF3e8i3Df7At5UuBY911Bd2P0gY//s5FxdvLCNlaSC2A/KABfVIA7OkZq4X5DioiVw N/NffdthCc/+wUy470AS8TnZL+HAMjNzXd083/QVHQN+0IUkIX46D2kKDxjt2p0HT3px aRHEDNaTQRi8MwO6+ofhrhhdZVVavqkyDPxvUo84xJEaFiVHudUc4c6XMifZ4C5huuOX HGR738xcmRFbdbDk8V01NIsHaYt2jVY8BtbgMscE61ttpRPSxslcnrfM6KoVAmET52AE tCNANZZ/kEJZC+IpIUU6fptShpw76697Pg09VnvGQk6IToZdbOzZKlr1DhcNBddlBKTY CT/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=HY95ibaT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e11-20020a17090a684b00b001fe1cc52234si11380556pjm.67.2022.11.28.06.10.40; Mon, 28 Nov 2022 06:11:10 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=HY95ibaT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231382AbiK1OGD (ORCPT + 99 others); Mon, 28 Nov 2022 09:06:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33068 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232300AbiK1OF7 (ORCPT ); Mon, 28 Nov 2022 09:05:59 -0500 Received: from lelv0142.ext.ti.com (lelv0142.ext.ti.com [198.47.23.249]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 78D8C20BD8; Mon, 28 Nov 2022 06:05:58 -0800 (PST) Received: from fllv0035.itg.ti.com ([10.64.41.0]) by lelv0142.ext.ti.com (8.15.2/8.15.2) with ESMTP id 2ASE5pFQ080281; Mon, 28 Nov 2022 08:05:51 -0600 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1669644351; bh=yJGD9dUZPktIgmbSEnoYDWr8lwSvo0rr9GJtL7kjW6M=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=HY95ibaTlByV+u9X0bN0VJ3qnX9PtyxzeKoWOJOf+o95cCv3sYeSWiojXbKlnIBlr 3DZL5bECUXFxpMvh9XcNRkfka7HXi1b29GNWdfbAl9nwx35aO5hGbgiDclxvtTsKgO ljYg3uRvsftQEfDWNUJT4Xfw/hVqQyRCoSOeoTW0= Received: from DFLE106.ent.ti.com (dfle106.ent.ti.com [10.64.6.27]) by fllv0035.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 2ASE5pF3036300 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 28 Nov 2022 08:05:51 -0600 Received: from DFLE106.ent.ti.com (10.64.6.27) by DFLE106.ent.ti.com (10.64.6.27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.16; Mon, 28 Nov 2022 08:05:51 -0600 Received: from fllv0039.itg.ti.com (10.64.41.19) by DFLE106.ent.ti.com (10.64.6.27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.16 via Frontend Transport; Mon, 28 Nov 2022 08:05:51 -0600 Received: from jti.ent.ti.com (ileaxei01-snat2.itg.ti.com [10.180.69.6]) by fllv0039.itg.ti.com (8.15.2/8.15.2) with ESMTP id 2ASE5NQc125815; Mon, 28 Nov 2022 08:05:45 -0600 From: Georgi Vlaev To: Nishanth Menon , Tero Kristo , Santosh Shilimkar , Rob Herring , Krzysztof Kozlowski CC: , , , Vibhore Vardhan , Vignesh Raghavendra , Roger Quadros , Georgi Vlaev Subject: [PATCH v5 3/6] firmware: ti_sci: Add support for querying the firmware caps Date: Mon, 28 Nov 2022 16:05:19 +0200 Message-ID: <20221128140522.49474-4-g-vlaev@ti.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221128140522.49474-1-g-vlaev@ti.com> References: <20221128140522.49474-1-g-vlaev@ti.com> MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750749329607829275?= X-GMAIL-MSGID: =?utf-8?q?1750749329607829275?= This patch adds 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 featutes of the FW/SoC. As there's no other kernel consumers yet, this is not added to struct ti_sci_core_ops. [1] https://software-dl.ti.com/tisci/esd/latest/2_tisci_msgs/general/core.html Signed-off-by: Georgi Vlaev --- drivers/firmware/ti_sci.c | 56 +++++++++++++++++++++++++++++++++++++++ drivers/firmware/ti_sci.h | 26 ++++++++++++++++++ 2 files changed, 82 insertions(+) diff --git a/drivers/firmware/ti_sci.c b/drivers/firmware/ti_sci.c index bace9e9cd478..caa7b9d2bd48 100644 --- a/drivers/firmware/ti_sci.c +++ b/drivers/firmware/ti_sci.c @@ -1726,6 +1726,62 @@ static int ti_sci_cmd_prepare_sleep(const struct ti_sci_handle *handle, u8 mode, return ret; } +/** + * 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 + * + * 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 = 0; + + if (IS_ERR(handle)) + return PTR_ERR(handle); + if (!handle) + return -EINVAL; + + info = handle_to_ti_sci_info(handle); + dev = info->dev; + + xfer = 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 = PTR_ERR(xfer); + dev_err(dev, "Message alloc failed(%d)\n", ret); + return ret; + } + + ret = ti_sci_do_xfer(info, xfer); + if (ret) { + dev_err(dev, "Mbox send fail %d\n", ret); + goto fail; + } + + resp = (struct ti_sci_msg_resp_query_fw_caps *)xfer->xfer_buf; + + if (!ti_sci_is_response_ack(resp)) { + ret = -ENODEV; + goto fail; + } + + if (fw_caps) + *fw_caps = resp->fw_caps; + +fail: + ti_sci_put_one_xfer(&info->minfo, xfer); + + return ret; +} + /** * ti_sci_msg_cmd_lpm_wake_reason() - Get the wakeup source from LPM * @handle: Pointer to TI SCI handle diff --git a/drivers/firmware/ti_sci.h b/drivers/firmware/ti_sci.h index e4bfe146c43d..d5b23d91b9b9 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 /* Device requests */ #define TI_SCI_MSG_SET_DEVICE_STATE 0x0200 @@ -137,6 +138,31 @@ struct ti_sci_msg_req_reboot { struct ti_sci_msg_hdr hdr; } __packed; +/** + * 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_DEEP_SLEEP: Deep Sleep LPM + * MSG_FLAG_CAPS_LPM_MCU_ONLY: MCU only LPM + * MSG_FLAG_CAPS_LPM_STANDBY: Standby LPM + * MSG_FLAG_CAPS_LPM_PARTIAL_IO: Partial IO in LPM + * + * 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_DEEP_SLEEP TI_SCI_MSG_FLAG(1) +#define MSG_FLAG_CAPS_LPM_MCU_ONLY TI_SCI_MSG_FLAG(2) +#define MSG_FLAG_CAPS_LPM_STANDBY TI_SCI_MSG_FLAG(3) +#define MSG_FLAG_CAPS_LPM_PARTIAL_IO TI_SCI_MSG_FLAG(4) +#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 device * @hdr: Generic header From patchwork Mon Nov 28 14:05:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Georgi Vlaev X-Patchwork-Id: 26789 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp5695850wrr; Mon, 28 Nov 2022 06:11:37 -0800 (PST) X-Google-Smtp-Source: AA0mqf7kpQ88Eo6oEDROLMxL6TxtWPFYALvI5ibqff2LVD/2MckCa50zFV0EDd+8vMYuDeQQNmQ4 X-Received: by 2002:a17:902:bc4a:b0:189:6795:d945 with SMTP id t10-20020a170902bc4a00b001896795d945mr16193279plz.136.1669644696967; Mon, 28 Nov 2022 06:11:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669644696; cv=none; d=google.com; s=arc-20160816; b=LHWFiEqcG0HlwU+w0x93qTN4wfkpCIvqPEnSPqmvIzyoXV/KoyBEw2f0MnoGIydxJD q4JJ9pSM5fgdpEigV3dvsksRuGx4ZRtVpG+1mmOOByLhhJym0bw+dZTvbGeHeaTYM3sB 1jtDp7CbjjijR10PHiAU6z63S93n9JBkRW7NlqjFSbgLAJMsLTeEJRZGT8f3DWHTcfBZ 2uhx4WTINoBYlmkO+96/h5IgygPNGNNSRLMVGX2w4DLmcxup1Y2VfYHTj2q/QCPPzkDj 5gBthKQg7StE0wHEI2ZmL9efRu0BeNoxzsP5JElWateA9Mq8SwNw8pjOO+EUrbybLIbf xuRw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=7jkAENbaGQCGj8274ocsGwp0BivC0m9EFpVsZaWJ+lw=; b=f9FW4fwHvadKCD1BCZRK7TTmyZ5nR6epnWkTaAG4yuq5Z7+oUk0FAZ25FAco0KjjAo IBfGU4x4wL0Z8yG5aSyQPZiKDOTqxp5QBTp4LBKt2SrcoAH5aZ8Jf0vGGYkIwdXSjAmK pbHgKTSefR5C4XyPIgLD3c5d18behnK8nD2Bqfj86gwWagGykVeT0iExxYVRYQW/bLvB GwWrUwOGKTUQH75xgav0BdIFnQ8JGXo/PBOSx+xkUFcHUl3bZ/fzgEukDsDORE2XmH1/ Aoy2jg0Ln0XRE998ahQxbP72JgXaVvkvY4KdXXCeooq9bTl+MHADZd86Ey2tupcddMBW jwDQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=HWxYgAwn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f5-20020a170902860500b0017cc894c78esi10968819plo.447.2022.11.28.06.11.22; Mon, 28 Nov 2022 06:11:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=HWxYgAwn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232305AbiK1OGV (ORCPT + 99 others); Mon, 28 Nov 2022 09:06:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33304 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232314AbiK1OGG (ORCPT ); Mon, 28 Nov 2022 09:06:06 -0500 Received: from lelv0143.ext.ti.com (lelv0143.ext.ti.com [198.47.23.248]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 471EF20BDC; Mon, 28 Nov 2022 06:06:05 -0800 (PST) Received: from lelv0265.itg.ti.com ([10.180.67.224]) by lelv0143.ext.ti.com (8.15.2/8.15.2) with ESMTP id 2ASE5wFB044432; Mon, 28 Nov 2022 08:05:58 -0600 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1669644358; bh=7jkAENbaGQCGj8274ocsGwp0BivC0m9EFpVsZaWJ+lw=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=HWxYgAwnlxvn6a2iqF74VwkwYDzy2xLuiVXxA+LvdYu24l6xb0vGGgvPNZPZsE+Nk jEwF4dTIj12E76fxi3d5T8G9GsTBB1hlbV+9t5U4M6KoY7xd/5OEQvci6iNS/AzX+6 tug/oix7YFyuHrfHxvZ2SV/o6sDP7DUr12f9ugfg= Received: from DFLE106.ent.ti.com (dfle106.ent.ti.com [10.64.6.27]) by lelv0265.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 2ASE5wYp023854 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 28 Nov 2022 08:05:58 -0600 Received: from DFLE112.ent.ti.com (10.64.6.33) by DFLE106.ent.ti.com (10.64.6.27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.16; Mon, 28 Nov 2022 08:05:58 -0600 Received: from fllv0039.itg.ti.com (10.64.41.19) by DFLE112.ent.ti.com (10.64.6.33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.16 via Frontend Transport; Mon, 28 Nov 2022 08:05:57 -0600 Received: from jti.ent.ti.com (ileaxei01-snat2.itg.ti.com [10.180.69.6]) by fllv0039.itg.ti.com (8.15.2/8.15.2) with ESMTP id 2ASE5NQd125815; Mon, 28 Nov 2022 08:05:52 -0600 From: Georgi Vlaev To: Nishanth Menon , Tero Kristo , Santosh Shilimkar , Rob Herring , Krzysztof Kozlowski CC: , , , Vibhore Vardhan , Vignesh Raghavendra , Roger Quadros , Georgi Vlaev Subject: [PATCH v5 4/6] firmware: ti_sci: Allocate memory for the LPM modes Date: Mon, 28 Nov 2022 16:05:20 +0200 Message-ID: <20221128140522.49474-5-g-vlaev@ti.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221128140522.49474-1-g-vlaev@ti.com> References: <20221128140522.49474-1-g-vlaev@ti.com> MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750749357545629981?= X-GMAIL-MSGID: =?utf-8?q?1750749357545629981?= From: Dave Gerlach A region of memory in DDR must be used during Deep Sleep for saving of some system context when using the ti_sci firmware. From DM's point of view, this can be any contiguous region in the DDR, so can allocate 512KB of DMA reserved memory in probe(), instead of another carveout. Also send a TISCI_MSG_QUERY_FW_CAPS message to the firmware during probe to determine if any low power modes are supported and if ti_sci_init_suspend should be called based on the response received. Signed-off-by: Dave Gerlach Signed-off-by: Vibhore Vardhan Signed-off-by: Georgi Vlaev Tested-by: Roger Quadros --- drivers/firmware/ti_sci.c | 40 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/drivers/firmware/ti_sci.c b/drivers/firmware/ti_sci.c index caa7b9d2bd48..b49d81527e29 100644 --- a/drivers/firmware/ti_sci.c +++ b/drivers/firmware/ti_sci.c @@ -10,6 +10,7 @@ #include #include +#include #include #include #include @@ -25,6 +26,9 @@ #include "ti_sci.h" +/* Low power mode memory context size */ +#define LPM_CTX_MEM_SIZE 0x80000 + /* List of all TI SCI devices active in system */ static LIST_HEAD(ti_sci_list); /* Protection for the entire list */ @@ -96,6 +100,9 @@ struct ti_sci_desc { * @minfo: Message info * @node: list head * @host_id: Host ID + * @ctx_mem_addr: Low power context memory phys address + * @ctx_mem_buf: Low power context memory buffer + * @fw_caps: FW/SoC low power capabilities * @users: Number of users of this instance * @is_suspending: Flag set to indicate in suspend path. */ @@ -114,6 +121,9 @@ struct ti_sci_info { struct ti_sci_xfers_info minfo; struct list_head node; u8 host_id; + dma_addr_t ctx_mem_addr; + void *ctx_mem_buf; + u64 fw_caps; /* protected by ti_sci_list_mutex */ int users; bool is_suspending; @@ -3543,6 +3553,23 @@ static int ti_sci_resume(struct device *dev) static DEFINE_SIMPLE_DEV_PM_OPS(ti_sci_pm_ops, ti_sci_suspend, ti_sci_resume); +static int ti_sci_init_suspend(struct platform_device *pdev, + struct ti_sci_info *info) +{ + struct device *dev = &pdev->dev; + + dma_set_mask_and_coherent(dev, DMA_BIT_MASK(64)); + info->ctx_mem_buf = dma_alloc_coherent(info->dev, LPM_CTX_MEM_SIZE, + &info->ctx_mem_addr, + GFP_KERNEL); + if (!info->ctx_mem_buf) { + dev_err(info->dev, "Failed to allocate LPM context memory\n"); + return -ENOMEM; + } + + return 0; +} + /* Description for K2G */ static const struct ti_sci_desc ti_sci_pmmc_k2g_desc = { .default_host_id = 2, @@ -3695,6 +3722,15 @@ static int ti_sci_probe(struct platform_device *pdev) } } + /* + * Check if the firmware supports any optional low power modes + * and initialize them if present. Old revisions of TIFS (< 08.04) + * will NACK the request. + */ + ret = ti_sci_msg_cmd_query_fw_caps(&info->handle, &info->fw_caps); + if (!ret && (info->fw_caps & MSG_MASK_CAPS_LPM)) + ti_sci_init_suspend(pdev, info); + dev_info(dev, "ABI: %d.%d (firmware rev 0x%04x '%s')\n", info->handle.version.abi_major, info->handle.version.abi_minor, info->handle.version.firmware_revision, @@ -3742,6 +3778,10 @@ static int ti_sci_remove(struct platform_device *pdev) mbox_free_channel(info->chan_rx); } + if (info->ctx_mem_buf) + dma_free_coherent(info->dev, LPM_CTX_MEM_SIZE, + info->ctx_mem_buf, + info->ctx_mem_addr); return ret; } From patchwork Mon Nov 28 14:05:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Georgi Vlaev X-Patchwork-Id: 26790 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp5696172wrr; Mon, 28 Nov 2022 06:12:02 -0800 (PST) X-Google-Smtp-Source: AA0mqf7OiXzl0WwCJqXQ2mGu6wWGJcE0IZjWBxWtC/KEE0sbMv94yPzlcfs1XI8ORmLkGijCUCEl X-Received: by 2002:a17:90b:48cf:b0:205:e1af:68d1 with SMTP id li15-20020a17090b48cf00b00205e1af68d1mr59686870pjb.121.1669644721700; Mon, 28 Nov 2022 06:12:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669644721; cv=none; d=google.com; s=arc-20160816; b=FB5v6ygloP6JuyAzoyKdnnsXmlC/1E9oBoYODZhmfVSi4lT6Sew3c7vPm4FHoiwAda myVPXGqvZDL9eNZz01KexUCw1jr+NuK0XhWTClbP9mY5kc/aFMKRk3Fnfy47tasIJ7WX AJ11WwPXUqtwwR9hW8xWuMVm3Bj5WO15eyktzn9Oj0eXYzwp9egckfPECLOpn0uociYU 4Gh2l/SZbJIYSjrFFswaAZ1r7U79aotf7LU7rkwgQQd29kwm0Oc+D+jPC9+/G4jrmnT5 QAWvIviV43yzbNm+0t17IYuBdJpxAcCCKnvJ9Fw8zuWJCN8Itaye69I+gozdYgCxtM0M dRDg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Y5bYIwxBAyewV7VFRd+QNGjtZnR0wvKPVaj9QfuzHLc=; b=xf7eiiPEr14xeFs+1JycjOC4YKigsuO3SBCCXpb40ntgW35o2vBb0CCrOX4mpvsVnM uoaM7D4cxRxvC03NvEWkVTvwbpeXMlfkPmcfuQtX0sS2+J1VfelePgrkRJoj0tjAo00Y m6BIp0St1SBzLEj4D7S3NTtZLgEgQX87L/JEZS0j0eignYuL75xLUijmyCfxnuacd+QD dctzBs9jhFvxmbeK2npt9PWY+Lc/jB6hD6ZYDX4oqB5Id6fSXs2vJA4msW5uNjibWyY8 fHaxpgpbwyYbsCU4H16e1BfvUcRrj5fzox4AcnwJTpHW/VOBKphRYxtnnlwYeDKVW0jd CA0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=W6cM07ji; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id om1-20020a17090b3a8100b0020d542eb5f0si15824796pjb.110.2022.11.28.06.11.48; Mon, 28 Nov 2022 06:12:01 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=W6cM07ji; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232366AbiK1OGb (ORCPT + 99 others); Mon, 28 Nov 2022 09:06:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33570 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232333AbiK1OGS (ORCPT ); Mon, 28 Nov 2022 09:06:18 -0500 Received: from fllv0015.ext.ti.com (fllv0015.ext.ti.com [198.47.19.141]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 22F6321820; Mon, 28 Nov 2022 06:06:15 -0800 (PST) Received: from lelv0266.itg.ti.com ([10.180.67.225]) by fllv0015.ext.ti.com (8.15.2/8.15.2) with ESMTP id 2ASE64Zo109885; Mon, 28 Nov 2022 08:06:04 -0600 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1669644364; bh=Y5bYIwxBAyewV7VFRd+QNGjtZnR0wvKPVaj9QfuzHLc=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=W6cM07ji8xMilWghyQmaUk8W1XSImZBEcuhdwWDglootHoacEhK3sCnMZIJKyccyE Ogz5xehQQKX6eweSBvu49cSr5SsG4AnlHt0Z+u65Fz6BvHt7bqbJH+a1rWj9u60hlu V9ZpGGxO6SbZJ+YlBhq6jzdtMSzGq91fCv9KKUss= Received: from DLEE112.ent.ti.com (dlee112.ent.ti.com [157.170.170.23]) by lelv0266.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 2ASE64JY099170 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 28 Nov 2022 08:06:04 -0600 Received: from DLEE113.ent.ti.com (157.170.170.24) by DLEE112.ent.ti.com (157.170.170.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.16; Mon, 28 Nov 2022 08:06:04 -0600 Received: from fllv0039.itg.ti.com (10.64.41.19) by DLEE113.ent.ti.com (157.170.170.24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.16 via Frontend Transport; Mon, 28 Nov 2022 08:06:04 -0600 Received: from jti.ent.ti.com (ileaxei01-snat2.itg.ti.com [10.180.69.6]) by fllv0039.itg.ti.com (8.15.2/8.15.2) with ESMTP id 2ASE5NQe125815; Mon, 28 Nov 2022 08:05:58 -0600 From: Georgi Vlaev To: Nishanth Menon , Tero Kristo , Santosh Shilimkar , Rob Herring , Krzysztof Kozlowski CC: , , , Vibhore Vardhan , Vignesh Raghavendra , Roger Quadros , Georgi Vlaev Subject: [PATCH v5 5/6] firmware: ti_sci: Use dt provided fw name and address to load at suspend time Date: Mon, 28 Nov 2022 16:05:21 +0200 Message-ID: <20221128140522.49474-6-g-vlaev@ti.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221128140522.49474-1-g-vlaev@ti.com> References: <20221128140522.49474-1-g-vlaev@ti.com> MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750749383989300056?= X-GMAIL-MSGID: =?utf-8?q?1750749383989300056?= From: Dave Gerlach Use request_firmware_direct to load the fs stub LPM firmware to a provided memory region. The filename for the firmware is provided in the device tree as "firmware-name". Use a pm_notifier for loading of the low power firmware during PM_SUSPEND_PREPARE phase so that it can be loaded from the rootfs before it is suspended. It is possible in the future for this firmware to require reload, so add a check to indicate that the firmware is currently loaded so it is only loaded once. Signed-off-by: Dave Gerlach Signed-off-by: Vibhore Vardhan Signed-off-by: Georgi Vlaev Tested-by: Roger Quadros --- drivers/firmware/ti_sci.c | 102 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) diff --git a/drivers/firmware/ti_sci.c b/drivers/firmware/ti_sci.c index b49d81527e29..09bca1a15d74 100644 --- a/drivers/firmware/ti_sci.c +++ b/drivers/firmware/ti_sci.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -22,6 +23,7 @@ #include #include #include +#include #include #include "ti_sci.h" @@ -89,10 +91,13 @@ struct ti_sci_desc { * @dev: Device pointer * @desc: SoC description for this instance * @nb: Reboot Notifier block + * @pm_nb: PM notifier block * @d: Debugfs file entry * @debug_region: Memory region where the debug message are available * @debug_region_size: Debug region size * @debug_buffer: Buffer allocated to copy debug messages. + * @lpm_region: Memory region where the FS Stub LPM Firmware will be stored + * @lpm_region_size: LPM region size * @handle: Instance of TI SCI handle to send to clients. * @cl: Mailbox Client * @chan_tx: Transmit mailbox channel @@ -105,15 +110,20 @@ struct ti_sci_desc { * @fw_caps: FW/SoC low power capabilities * @users: Number of users of this instance * @is_suspending: Flag set to indicate in suspend path. + * @lpm_firmware_loaded: Flag to indicate if LPM firmware has been loaded + * @lpm_firmware_name: Name of firmware binary to load from fw search path */ struct ti_sci_info { struct device *dev; struct notifier_block nb; + struct notifier_block pm_nb; const struct ti_sci_desc *desc; struct dentry *d; void __iomem *debug_region; char *debug_buffer; size_t debug_region_size; + void __iomem *lpm_region; + size_t lpm_region_size; struct ti_sci_handle handle; struct mbox_client cl; struct mbox_chan *chan_tx; @@ -127,11 +137,14 @@ struct ti_sci_info { /* protected by ti_sci_list_mutex */ int users; bool is_suspending; + bool lpm_firmware_loaded; + const char *lpm_firmware_name; }; #define cl_to_ti_sci_info(c) container_of(c, struct ti_sci_info, cl) #define handle_to_ti_sci_info(h) container_of(h, struct ti_sci_info, handle) #define reboot_to_ti_sci_info(n) container_of(n, struct ti_sci_info, nb) +#define pm_nb_to_ti_sci_info(n) container_of(n, struct ti_sci_info, pm_nb) #ifdef CONFIG_DEBUG_FS @@ -3524,6 +3537,32 @@ static int tisci_reboot_handler(struct notifier_block *nb, unsigned long mode, return NOTIFY_BAD; } +static int ti_sci_load_lpm_firmware(struct device *dev, struct ti_sci_info *info) +{ + const struct firmware *firmware; + int ret = 0; + + /* If no firmware name is set, do not attempt to load. */ + if (!info->lpm_firmware_name) + return -EINVAL; + + ret = request_firmware_direct(&firmware, info->lpm_firmware_name, dev); + if (ret) { + dev_warn(dev, "Cannot load %s\n", info->lpm_firmware_name); + return ret; + } + + if (firmware->size > info->lpm_region_size) { + release_firmware(firmware); + return -ENOMEM; + } + + memcpy_toio(info->lpm_region, firmware->data, firmware->size); + + release_firmware(firmware); + + return ret; +} static void ti_sci_set_is_suspending(struct ti_sci_info *info, bool is_suspending) { info->is_suspending = is_suspending; @@ -3553,10 +3592,33 @@ static int ti_sci_resume(struct device *dev) static DEFINE_SIMPLE_DEV_PM_OPS(ti_sci_pm_ops, ti_sci_suspend, ti_sci_resume); +static int tisci_pm_handler(struct notifier_block *nb, unsigned long pm_event, + void *unused) +{ + struct ti_sci_info *info = pm_nb_to_ti_sci_info(nb); + int ret; + + /* Load the LPM firmware on PM_SUSPEND_PREPARE if not loaded yet */ + if (pm_event != PM_SUSPEND_PREPARE || info->lpm_firmware_loaded) + return NOTIFY_DONE; + + ret = ti_sci_load_lpm_firmware(info->dev, info); + if (ret) { + dev_err(info->dev, "Failed to load LPM firmware (%d)\n", ret); + return NOTIFY_BAD; + } + + info->lpm_firmware_loaded = true; + + return NOTIFY_OK; +} + static int ti_sci_init_suspend(struct platform_device *pdev, struct ti_sci_info *info) { struct device *dev = &pdev->dev; + struct resource *res; + int ret; dma_set_mask_and_coherent(dev, DMA_BIT_MASK(64)); info->ctx_mem_buf = dma_alloc_coherent(info->dev, LPM_CTX_MEM_SIZE, @@ -3567,7 +3629,44 @@ static int ti_sci_init_suspend(struct platform_device *pdev, return -ENOMEM; } + res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "lpm"); + if (!res) { + dev_warn(dev, + "lpm region is required for suspend but not provided.\n"); + ret = -EINVAL; + goto err; + } + + info->lpm_region = devm_ioremap_resource(dev, res); + if (IS_ERR(info->lpm_region)) { + ret = PTR_ERR(info->lpm_region); + goto err; + } + info->lpm_region_size = resource_size(res); + + if (of_property_read_string(dev->of_node, "firmware-name", + &info->lpm_firmware_name)) { + dev_warn(dev, + "firmware-name is required for suspend but not provided.\n"); + ret = -EINVAL; + goto err; + } + + info->pm_nb.notifier_call = tisci_pm_handler; + info->pm_nb.priority = 128; + + ret = register_pm_notifier(&info->pm_nb); + if (ret) { + dev_err(dev, "pm_notifier registration fail (%d)\n", ret); + goto err; + } + return 0; +err: + dma_free_coherent(info->dev, LPM_CTX_MEM_SIZE, + info->ctx_mem_buf, + info->ctx_mem_addr); + return ret; } /* Description for K2G */ @@ -3760,6 +3859,9 @@ static int ti_sci_remove(struct platform_device *pdev) info = platform_get_drvdata(pdev); + if (info->pm_nb.notifier_call) + unregister_pm_notifier(&info->pm_nb); + if (info->nb.notifier_call) unregister_restart_handler(&info->nb); From patchwork Mon Nov 28 14:05:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Georgi Vlaev X-Patchwork-Id: 26791 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp5696225wrr; Mon, 28 Nov 2022 06:12:04 -0800 (PST) X-Google-Smtp-Source: AA0mqf51dYSIYPSnekuqAbMb44zOC17WVMFFTMYfbN75RA3mDadrR7uJGt30R6qH6S8AlVoHCBU6 X-Received: by 2002:a17:906:32ce:b0:78d:9022:f146 with SMTP id k14-20020a17090632ce00b0078d9022f146mr27025311ejk.656.1669644724709; Mon, 28 Nov 2022 06:12:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669644724; cv=none; d=google.com; s=arc-20160816; b=y//ly0EXT7YqLrG/P2gApzkCWdvHZeF5hyMbpPWAZuTiqrXXf6CxF28gLsNILQjpco mCl9ROv2ItJuUVQ7KWqTq9+7IdhFY0NUbFGfQ8p0gCrG4Oer7jSBlXtFhXOxZFSp//WG 3C8mWZtYevS3ck+V+JSAnLTovqrUqCB2+6SqhF7NyVdh72UBcUhZN0w05cDj/U8c8wph 3a7A3tAjlGX5xjff1ctm8DMheNJlqodyYg5ajCy4BcHOVnoEgfsUAY8hN1sIrpXKxBkP Mm5PBdCuN4iBeIbMrfakYFnSyAGtnExzjFSKa5541PaUL+CqFNXMn6lFPKmuRKxZ4Bqq XhKQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=flzB7Wa6hAMqJiGA/2RH5eCO5QhcD1qsRfBay0L5uTc=; b=ihiiHZzKRJuZ5YC2/sfWyaUuHxSQDf/egKko4LqpkWZRdEm+uvaA5NgiEBG60wmnzh PD8zeEoAelWOsVOqmXzur/KBKptndzzA52R7ZchZ4xVYcaec9cqKOiXm+BgN5igXPoWF DSz9T3H9/5DDGGHj2BnhHFnj7dH63d/MccXatWRwk8i7A1aX5vtGHkVYKoY8WD6a9R4v 9tlbiRVr9utXmfiWtWqGbbfWMK7vyU/LAN+lA8t761yelTZeBDaOzRLFvWB72T4YRoyg /PmsLMteSe6HVCcoG9R0pYLoi5kwNyf7hSc+s0gQPlNyBwljHaMJ8eSx6cbKy5ns35jQ 2ZNA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=sgMOVTnJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ga19-20020a1709070c1300b007c0553fad58si1700664ejc.422.2022.11.28.06.11.40; Mon, 28 Nov 2022 06:12:04 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=sgMOVTnJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232345AbiK1OGo (ORCPT + 99 others); Mon, 28 Nov 2022 09:06:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33580 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232304AbiK1OGU (ORCPT ); Mon, 28 Nov 2022 09:06:20 -0500 Received: from fllv0015.ext.ti.com (fllv0015.ext.ti.com [198.47.19.141]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E15E12127C; Mon, 28 Nov 2022 06:06:17 -0800 (PST) Received: from lelv0266.itg.ti.com ([10.180.67.225]) by fllv0015.ext.ti.com (8.15.2/8.15.2) with ESMTP id 2ASE6B2q109903; Mon, 28 Nov 2022 08:06:11 -0600 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1669644371; bh=flzB7Wa6hAMqJiGA/2RH5eCO5QhcD1qsRfBay0L5uTc=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=sgMOVTnJHWvOyE9ZMBJX+tx/TohEOpBUJNp3+CQBK5YnqFI9L7yRh/VtMWTZaNovl YAy9TszD8Rd3Hu8n05BQDO49QwIOQJOLYviEJQLtAJ41jgBSvXQ10xdgRQbjlxVYTC CvLaVGZX3TLHnCMfH/mm2pX6pnC8TpfpVCJSOpSo= Received: from DLEE104.ent.ti.com (dlee104.ent.ti.com [157.170.170.34]) by lelv0266.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 2ASE6Bkb099220 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 28 Nov 2022 08:06:11 -0600 Received: from DLEE114.ent.ti.com (157.170.170.25) by DLEE104.ent.ti.com (157.170.170.34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.16; Mon, 28 Nov 2022 08:06:11 -0600 Received: from fllv0039.itg.ti.com (10.64.41.19) by DLEE114.ent.ti.com (157.170.170.25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.16 via Frontend Transport; Mon, 28 Nov 2022 08:06:11 -0600 Received: from jti.ent.ti.com (ileaxei01-snat2.itg.ti.com [10.180.69.6]) by fllv0039.itg.ti.com (8.15.2/8.15.2) with ESMTP id 2ASE5NQf125815; Mon, 28 Nov 2022 08:06:05 -0600 From: Georgi Vlaev To: Nishanth Menon , Tero Kristo , Santosh Shilimkar , Rob Herring , Krzysztof Kozlowski CC: , , , Vibhore Vardhan , Vignesh Raghavendra , Roger Quadros , Georgi Vlaev Subject: [PATCH v5 6/6] firmware: ti_sci: Introduce prepare system suspend call Date: Mon, 28 Nov 2022 16:05:22 +0200 Message-ID: <20221128140522.49474-7-g-vlaev@ti.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221128140522.49474-1-g-vlaev@ti.com> References: <20221128140522.49474-1-g-vlaev@ti.com> MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750749386603763118?= X-GMAIL-MSGID: =?utf-8?q?1750749386603763118?= From: Dave Gerlach Introduce 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 is being entered and the address for allocated memory for storing the context during Deep Sleep. 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. Signed-off-by: Dave Gerlach Signed-off-by: Vibhore Vardhan Signed-off-by: Georgi Vlaev Tested-by: Roger Quadros --- drivers/firmware/ti_sci.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/drivers/firmware/ti_sci.c b/drivers/firmware/ti_sci.c index 09bca1a15d74..681f2ebb3fe4 100644 --- a/drivers/firmware/ti_sci.c +++ b/drivers/firmware/ti_sci.c @@ -3568,9 +3568,46 @@ static void ti_sci_set_is_suspending(struct ti_sci_info *info, bool is_suspendin info->is_suspending = is_suspending; } +static int ti_sci_prepare_system_suspend(struct ti_sci_info *info) +{ +#if IS_ENABLED(CONFIG_SUSPEND) + u8 mode; + + /* Map and validate the target Linux suspend state to TISCI LPM. */ + switch (pm_suspend_target_state) { + case PM_SUSPEND_MEM: + /* S2MEM is not supported by the firmware. */ + if (!(info->fw_caps & MSG_FLAG_CAPS_LPM_DEEP_SLEEP)) + return 0; + /* S2MEM can't continue if the LPM firmware is not loaded. */ + if (!info->lpm_firmware_loaded) + return -EINVAL; + mode = TISCI_MSG_VALUE_SLEEP_MODE_DEEP_SLEEP; + break; + default: + /* + * Do not fail if we don't have action to take for a + * specific suspend mode. + */ + return 0; + } + + return ti_sci_cmd_prepare_sleep(&info->handle, mode, + (u32)(info->ctx_mem_addr & 0xffffffff), + (u32)((u64)info->ctx_mem_addr >> 32), 0); +#else + return 0; +#endif +} + static int ti_sci_suspend(struct device *dev) { struct ti_sci_info *info = dev_get_drvdata(dev); + int ret; + + ret = ti_sci_prepare_system_suspend(info); + if (ret) + return ret; /* * We must switch operation to polled mode now as drivers and the genpd * layer may make late TI SCI calls to change clock and device states