From patchwork Thu Aug 1 19:54:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Markus Schneider-Pargmann X-Patchwork-Id: 13750874 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BA90CC3DA4A for ; Thu, 1 Aug 2024 19:56:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=pcvr3sCzC6JRh5BWaUixpZzO8bdpYlRw3Ht2YY2cy6g=; b=QFo5wJEL+pD08j1mwb+vJfgk0X Dh9frNafB3vXfattjVhYygt+4+sRPdidwKQdNVr55ZjaAb6Gg564jsiHjDEiDoRx6SCYrdDHOTO/u GT3N9+yH0BnKPWrU8tZmj+8flaGkYT9aXDhleAsfPGqhxTfu+YHxsaCGJNRPmlmxtbVpS7sp9SYAb YuBtgSSiDqUe7fL5Ys/0CiSWUrsUARfwfilxnI6T95VIXfnlsFlvLkDYm3+f7tQzscyzw24+wXbxU fLq72SQK2BLWcyVPq5ZtFchDw5An/MKBb/mng9PEgGwiIrHJHc6QzXiPCyOSHkLiw3ZHYcqSV7FmB QgdTakhA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sZbuE-00000006b4r-0WsI; Thu, 01 Aug 2024 19:56:10 +0000 Received: from mail-io1-xd34.google.com ([2607:f8b0:4864:20::d34]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sZbsq-00000006acn-3G1f for linux-arm-kernel@lists.infradead.org; Thu, 01 Aug 2024 19:54:46 +0000 Received: by mail-io1-xd34.google.com with SMTP id ca18e2360f4ac-81f83b14d65so320194439f.1 for ; Thu, 01 Aug 2024 12:54:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1722542084; x=1723146884; darn=lists.infradead.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=pcvr3sCzC6JRh5BWaUixpZzO8bdpYlRw3Ht2YY2cy6g=; b=yWIVi2lqIW5fmJ8jyE7PLDD3jWIIX6n0Ufgtm9qif920S/edxfSuiS7HB+eGmrwMoW XqhyiYzTAPVzh0ViB4JHpGJ9cwQyf7D4E4x6LMGro1LIcxFNJ9uA8oC4I3/xpLke0H/9 U7hF8Ig2uAx0cvr/32GJr3L8MPS3//rvg7vA2KywJfiSQY4Ee9TwSNu+9FPfz9hXEJcH LEz6JxqUc2WkptpX/B3sI4YAEo9UpObhY6n4P7VxUHIeHH0enQf5GHfWRNQeoED7H9Oa DNYj0LWz0m2jQnNp6dCO3qaQnBnYOGu2ZziCPeFdBuk9PFCnad2X9nV0fn4o/ujKGPfg IhKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722542084; x=1723146884; 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=pcvr3sCzC6JRh5BWaUixpZzO8bdpYlRw3Ht2YY2cy6g=; b=NKBrrZ44z0vJgDyPrKVQsDTO5b4WBdaXy4CLur7AFuWz+oNCUUgsWnC7Y6qq/5Cz83 GinDcDIWhSFQk1y9/yz1wZMi706D4AmA4+kDG/F+OKooiavlydGTjXwoRlml6Rj+gOPn h5rK5U1bhKU2Vh36O67vjbdfZP7neXowLonoEG7bCA6TP26wOteW4RVE7gzJqbZdJqgX 2hMtSJgWhy9dG8KKdtYfBtYBHKAgDD56jfn47CUuyYu7PdFNH+hItCBMLkYCJS3ffdmo GG4tRMfHy9s5Lg62270FF/HKk7HRS0XY6X8RouwAHryILDP6uiAGL2HK1Zp+Kw/0zgh8 aFgQ== X-Forwarded-Encrypted: i=1; AJvYcCXaLYmqgNOzkV7rn5n89NShoBdVJPcLGQ6r4TsZlFB1V8DXXLtt/2nUKpYLswRoPatkDfBKfI2/HtzN3AaOEhxhYkFn+0hr95Jp1B7p32NJuugt2KM= X-Gm-Message-State: AOJu0YwI02W04jdFF4VSdoRdxKiL3x3yPF+Qw28nJoe/WpX1o+FU5qi/ DYv1I5RUvbdW4kmxiXocgZ/xkvxsndIyxB3TGudZds03kLVvIXrwHuMxCn0EuXc= X-Google-Smtp-Source: AGHT+IFFPU4SQ/ve1pnNOqa00XykUHQ6+BnwhBlaeI8hCGJOnC+c5xzIcxEhjQ70PpZH2B/3i1qQzA== X-Received: by 2002:a05:6602:1507:b0:806:7f5a:1fb7 with SMTP id ca18e2360f4ac-81fd434beddmr171669739f.5.1722542084014; Thu, 01 Aug 2024 12:54:44 -0700 (PDT) Received: from blmsp.fritz.box ([2001:4091:a245:8609:c1c4:a4f8:94c8:31f2]) by smtp.gmail.com with ESMTPSA id ca18e2360f4ac-81fd4d1b7ddsm14395039f.3.2024.08.01.12.54.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Aug 2024 12:54:43 -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 v8 2/3] firmware: ti_sci: Add support for querying the firmware caps Date: Thu, 1 Aug 2024 21:54:21 +0200 Message-ID: <20240801195422.2296347-3-msp@baylibre.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240801195422.2296347-1-msp@baylibre.com> References: <20240801195422.2296347-1-msp@baylibre.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240801_125444_864750_B6509885 X-CRM114-Status: GOOD ( 24.35 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 featutes of the FW/SoC. As there's no other kernel consumers yet, this is not added to struct ti_sci_core_ops. Sysfw version >= 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.html [2] https://downloads.ti.com/tisci/esd/latest/2_tisci_msgs/general/core.html#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: Markus Schneider-Pargmann --- drivers/firmware/ti_sci.c | 73 +++++++++++++++++++++++++++++++++++++++ drivers/firmware/ti_sci.h | 22 ++++++++++++ 2 files changed, 95 insertions(+) diff --git a/drivers/firmware/ti_sci.c b/drivers/firmware/ti_sci.c index 3599aeecef86..d7a3990a6353 100644 --- a/drivers/firmware/ti_sci.c +++ b/drivers/firmware/ti_sci.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include "ti_sci.h" @@ -98,6 +99,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 +116,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; }; @@ -1929,6 +1932,62 @@ static int ti_sci_cmd_set_latency_constraint(const struct ti_sci_handle *handle, 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; +} + static int ti_sci_cmd_core_reboot(const struct ti_sci_handle *handle) { struct ti_sci_info *info; @@ -3113,6 +3172,12 @@ static void ti_sci_setup_ops(struct ti_sci_info *info) pmops->lpm_wake_reason = ti_sci_msg_cmd_lpm_wake_reason; + if (info->fw_caps & MSG_FLAG_CAPS_LPM_DM_MANAGED) { + pr_debug("detected DM managed LPM in fw_caps\n"); + ops->pm_ops.set_device_constraint = ti_sci_cmd_set_device_constraint; + ops->pm_ops.set_latency_constraint = ti_sci_cmd_set_latency_constraint; + } + 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; @@ -3671,6 +3736,14 @@ static int ti_sci_probe(struct platform_device *pdev) goto out; } + /* + * Check if the firmware supports any optional low power modes. + * 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_FLAG_CAPS_GENERIC)) + pr_debug("Unable to detect LPM capabilities in fw_caps\n"); + ti_sci_setup_ops(info); ret = devm_register_restart_handler(dev, tisci_reboot_handler, info); diff --git a/drivers/firmware/ti_sci.h b/drivers/firmware/ti_sci.h index 424bc192ce3e..b8bba5d521d7 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 @@ -139,6 +140,27 @@ 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_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 device * @hdr: Generic header