From patchwork Wed Nov 16 18:13:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Georgi Vlaev X-Patchwork-Id: 21211 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp286587wru; Wed, 16 Nov 2022 10:17:10 -0800 (PST) X-Google-Smtp-Source: AA0mqf4/eovzMsn1TCqNLLiAhd9GgCgBKlyIesSLN4PAcLD5+B8IczHZlKvvddNFTe7fbwrpzCC3 X-Received: by 2002:a05:6a00:848:b0:572:4ea6:ddc7 with SMTP id q8-20020a056a00084800b005724ea6ddc7mr11719810pfk.26.1668622630655; Wed, 16 Nov 2022 10:17:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668622630; cv=none; d=google.com; s=arc-20160816; b=i6NYOxSkEuKSn+jRCa7omOoON60OJ19H7Bdhu2yoOc3QV7HXaoqgENP/lGfCxlhksa z8/suWbpINbDJukagFBQKo8OiJwxShkKUkzZTMHIjtIwvwB1puHY+tLza6IO4Ep6J8YP +ElumkLMtCnqEKWwiieo87LNMsDrlRDIjkfqYDKbgGxMA7ArFVhnGqtXdhKwld+jJWMs I59QrIWl0PD2fpKIL1bZcuRkIh0yXwCTldj5VFK7fdQbXSdHhFRFbJOIIgq+mJc5xrSr fB+kXkJyUB8vS7obdY9XttamgbTedZSwj14NM0Z5PDkrm30WvBAGDqBqloznRiUDilg4 8JkA== 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=+pUPfu6D5XgFFVua4ROE4mLQk/P6WEBcwKvBGZ9M8Co=; b=oxcETip3sKWqxPzChUCF4xE7iWhKnkBQfPTCIvw45bmJBfTqQco+AswLp9nB8OE/xt JU9TuVgbJ8nTSBeKBNvukhNs8//UqilwLjw/HFv5tpiW+dpeB00hqcbDn8cM68RrKBV8 60UKzVe5hQfO2P8PB7zNc4nXheihGzyUu0j0+BGnGExcczeBZlOyQ438lklSKDYsrHQg R4OW5cIoS3kyZrlMlff7HnVrxD+GKd4UzSIZltIe5s2ITJ7SI/H3RE9bFN8tnw/Hee7c /BkKlnzI8bFAwzdFby3BcwO8TSg2W4ne6YynIOESPuT8VKcZPYRZ7xui6uuOtnWQSN0k 6+1w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=dCGcX+Xy; 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 ms15-20020a17090b234f00b002131407c208si2234793pjb.101.2022.11.16.10.16.57; Wed, 16 Nov 2022 10:17: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=dCGcX+Xy; 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 S238985AbiKPSOK (ORCPT + 99 others); Wed, 16 Nov 2022 13:14:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52990 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237845AbiKPSN5 (ORCPT ); Wed, 16 Nov 2022 13:13:57 -0500 Received: from fllv0016.ext.ti.com (fllv0016.ext.ti.com [198.47.19.142]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A406461759; Wed, 16 Nov 2022 10:13:54 -0800 (PST) Received: from lelv0265.itg.ti.com ([10.180.67.224]) by fllv0016.ext.ti.com (8.15.2/8.15.2) with ESMTP id 2AGIDjSI001358; Wed, 16 Nov 2022 12:13:45 -0600 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1668622425; bh=+pUPfu6D5XgFFVua4ROE4mLQk/P6WEBcwKvBGZ9M8Co=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=dCGcX+Xy+zPuV81msUP/C9EJuImsYYnYikMhxmqFvA4eEG0iFqrHD02z1O1zXSE35 VIquY8960zWxR90DlTZnfTB8hHTz18JTJP1sY1P6MRfCcV1nurq7s6lqkyrLusjidh JkeGkI1pVSVdbxA3R5X4eU7GHiRB3WdemQxZB1Xk= Received: from DFLE103.ent.ti.com (dfle103.ent.ti.com [10.64.6.24]) by lelv0265.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 2AGIDjfm023797 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 16 Nov 2022 12:13:45 -0600 Received: from DFLE105.ent.ti.com (10.64.6.26) 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.6; Wed, 16 Nov 2022 12:13:45 -0600 Received: from fllv0039.itg.ti.com (10.64.41.19) 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.6 via Frontend Transport; Wed, 16 Nov 2022 12:13:45 -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 2AGID8MH026690; Wed, 16 Nov 2022 12:13:37 -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 v4 3/5] firmware: ti_sci: Allocate memory for the LPM modes Date: Wed, 16 Nov 2022 20:13:05 +0200 Message-ID: <20221116181307.198209-4-g-vlaev@ti.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221116181307.198209-1-g-vlaev@ti.com> References: <20221116181307.198209-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?1749677643730859919?= X-GMAIL-MSGID: =?utf-8?q?1749677643730859919?= 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_PREPARE_SUSPEND message to the firmware during probe to determine if system suspend is 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 | 55 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/drivers/firmware/ti_sci.c b/drivers/firmware/ti_sci.c index bace9e9cd478..acd4d3c040a2 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,8 @@ 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 * @users: Number of users of this instance * @is_suspending: Flag set to indicate in suspend path. */ @@ -114,6 +120,8 @@ 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; /* protected by ti_sci_list_mutex */ int users; bool is_suspending; @@ -3487,6 +3495,41 @@ 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; + 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, + &info->ctx_mem_addr, + GFP_KERNEL); + if (!info->ctx_mem_buf) { + dev_err(info->dev, "Failed to allocate LPM context memory\n"); + return -ENOMEM; + } + + /* + * Attempt to call prepare_sleep, this will be NAK'd if suspend is not + * supported by firmware in use, in which case we will not attempt to + * init suspend. + */ + ret = ti_sci_cmd_prepare_sleep(&info->handle, 0, + (u32)(info->ctx_mem_addr & 0xffffffff), + (u32)((u64)info->ctx_mem_addr >> 32), 0); + + if (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 */ static const struct ti_sci_desc ti_sci_pmmc_k2g_desc = { .default_host_id = 2, @@ -3639,6 +3682,14 @@ static int ti_sci_probe(struct platform_device *pdev) } } + ret = ti_sci_init_suspend(pdev, info); + if (ret) + dev_warn(dev, + "ti_sci_init_suspend failed, mem suspend will be non-functional.\n"); + + /* Suspend is an optional feature, reset return value and continue. */ + ret = 0; + 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, @@ -3686,6 +3737,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; }