From patchwork Tue Oct 12 09:58:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 12551913 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7E1F7C433F5 for ; Tue, 12 Oct 2021 10:03:44 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 415A460724 for ; Tue, 12 Oct 2021 10:03:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 415A460724 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=wdc.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=a/qals9N6cua7hiI5QvDqepN6rOxfQC9lN5TfwtAw0U=; b=38b+m08H5BR5t8 aGpEuuK16ixnf68fFuWNg/nNphQOPCKlGZM1WwGOn+Ufe4IZMn7FzuL+Hmv08309Pti6mm+ODeDyr uFP92zVir5fJN/BWaELEHHEcNKO2Lb5fFfFd+x6oNnxMqUQie98iZFtbiccipEm9uFADgDb1LnJ97 r150bqqOaKQxeo4iyd3DqYocVOvqwH8oM8RytKQg19tmpmeHY+VDwa3UNRVjDPdL3oOF287MSI7At OdZpxsJinVjvV3/Il+fY7zYT1/eHma8Ox54tyEvTSyCIw82ZBkeAwEEkPCbSzejgzFNFSs0qxMt4V pDjLTep4Bbh9kpa28Qng==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1maEd0-00CLSH-2a; Tue, 12 Oct 2021 10:03:22 +0000 Received: from esa5.hgst.iphmx.com ([216.71.153.144]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1maEZf-00CK8h-P8; Tue, 12 Oct 2021 09:59:58 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1634032795; x=1665568795; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=rvE/g+CVNRd/cKXoslQvV3X4nr1n1UFoBX8EKfr0C3s=; b=QJ1Gv9LLjLfSwpRUK3QboDOy44nQbP6uGvVguBqAUyuBOKMMp5I5/QEv mAqrtDS728f89wJQBt1v81YmRtR2fC9N7JLUP15Ee5cISDZpSlKDZ85eN M/rYKXdpGvAQchmM1lNurKx7toJt3tnCrfKhgepGA+J/6FdNHmaTDjzOm 0kz8xCqHZmJsgiykGRHF91F0ArznHhd4IJOr6XvsZ3A89okNJx4M/EuX/ 9932ISnpir9jlmDL5V+YdGLJ6VEkGE3cYMBb1SR5rbaai7Idyxv9Ulvfd xyRP/at7tUflyEp2hYhYdBH1SCUhad3CvF2oKcrNI0ehUm+zeeWlCYsMM g==; X-IronPort-AV: E=Sophos;i="5.85,367,1624291200"; d="scan'208";a="182592173" Received: from mail-dm6nam12lp2177.outbound.protection.outlook.com (HELO NAM12-DM6-obe.outbound.protection.outlook.com) ([104.47.59.177]) by ob1.hgst.iphmx.com with ESMTP; 12 Oct 2021 17:59:53 +0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MSzUuxwlkAdasPvy2AH/vCZM+PiKAvfPq5KyVskYn15ScYYeOEoDxZOA9v8qqFv+c8h+XfPyYuFEBGyn9PM7FvK4mgDPkAe4AHdqHxE7ElYSe9HDg++zOXiOxwldzZvABfgWOCwzP1+WH30GcsUiET+AmwUV8J+mNIfymQ+pJenwIQld2zOC9zmKo+CuRG8KLYHBSetJBcWHLuSPpdduOJAjyQaFPOdrmlWO3osrkad9l2gP9sCE8Kw+d2KO69NnJHLsQgSA7EW/plRAuaGAjilNl0ofhI8I2fpfRSNVIPOF3eD4Pwj5peDdIaxRyyeVgz3SM2q4KW2vXNEKzoAbCQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=XLvNkDJifV3Ha4j3JttH7s5CN1gObb1yVbFlM+bAAQ8=; b=EUIC/YZPNpdGaona9FbfYYeP1kRgokb8VHaPane6YlvicfYueUtYpUlavdn1/98luOS1k1rFxcg2FPwXtH3QKc0+M9oh77qncIFq/TXVzIsqGcsbA6qxNti1uAVEeJiMSB7omMrmTNMhLk9j4r8bcbVcXa1nLEo0aihqkFkQY2EedoxGQV25xqSieYaNQJTmbppURlnPzvxJvWzf7j76lg34xzgvO7zi+lYw+AJ/byjIv1lL0dmqmMJ39CFFYkXfExmo4m8h63I4PQ9uYHWj4JrRMhyJK0NqGoPiQ1mB3a70lxIYgEBn+jgbN7HzJJZK8BQIfwOKwuBELVFqrhlvgw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=wdc.com; dmarc=pass action=none header.from=wdc.com; dkim=pass header.d=wdc.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sharedspace.onmicrosoft.com; s=selector2-sharedspace-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=XLvNkDJifV3Ha4j3JttH7s5CN1gObb1yVbFlM+bAAQ8=; b=vtFJt5PtWkFi86R0Nv9DiYwx+suwpEJgIx+r0GIMf2bpRRxsifMc5uZAC+D5MLi89IdwcjeU1EvjDiZMyrQAcsFTSMZhMiaJjXjl+cXOy65h4tsaVmom13rG1zOL/t8YmS9K4TW3SGLiZlHm6A/+sP1cNYy0YhQeW1wR7Ji0Geg= Authentication-Results: dabbelt.com; dkim=none (message not signed) header.d=none;dabbelt.com; dmarc=none action=none header.from=wdc.com; Received: from CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) by CO6PR04MB8348.namprd04.prod.outlook.com (2603:10b6:303:137::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.18; Tue, 12 Oct 2021 09:59:52 +0000 Received: from CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::8100:4308:5b21:8d97]) by CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::8100:4308:5b21:8d97%9]) with mapi id 15.20.4587.026; Tue, 12 Oct 2021 09:59:52 +0000 From: Anup Patel To: Palmer Dabbelt , Palmer Dabbelt , Paul Walmsley , Albert Ou , Daniel Lezcano , Ulf Hansson , "Rafael J . Wysocki" , Pavel Machek , Rob Herring Cc: Sandeep Tripathy , Atish Patra , Alistair Francis , Liush , Anup Patel , devicetree@vger.kernel.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Anup Patel Subject: [PATCH v9 5/8] cpuidle: Factor-out power domain related code from PSCI domain driver Date: Tue, 12 Oct 2021 15:28:54 +0530 Message-Id: <20211012095857.1314214-6-anup.patel@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211012095857.1314214-1-anup.patel@wdc.com> References: <20211012095857.1314214-1-anup.patel@wdc.com> X-ClientProxiedBy: MAXPR01CA0106.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:5d::24) To CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) MIME-Version: 1.0 Received: from wdc.com (122.179.114.63) by MAXPR01CA0106.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:5d::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.24 via Frontend Transport; Tue, 12 Oct 2021 09:59:47 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: c45a6b0f-42cd-4cb3-4aab-08d98d6708e2 X-MS-TrafficTypeDiagnostic: CO6PR04MB8348: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: WDCIPOUTBOUND: EOP-TRUE X-MS-Oob-TLC-OOBClassifiers: OLM:5797; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: v8Wkmmoyi7N41mruPAFYYPSPBdTVT2mo+pnw0YX+RrnDdf4BxNqCfqPb/UiRS7raT7IijdgCTj/i79Gm2Sf2YPjDJUSrhg/gj8hCIWHxDj6ADfQEi3Du3qVe+fcJxlTze1m7kh2KmilVa/k0VPCvOxu9X4eaLk0zlwGJIH5MRoaxEh2A7s4XeHPHbhWGRUDAM5tK+F0wvimIIUc+IGVLzKS/H6TLSreEzuzwweFkb+iwD61wIqkSu3/tTqN/nROJFnEThgb5DHwjfG8W6PaoqsXnXK1a2rLAl8z1gb6A/K4aT6enqQLLK39/nL8Swg57Y09T4XencJSgIa/loaLVsBajfs+InyUhJ6s76EqhUYMuu072QFTjwpev7VVn5Pg3QV3RwWF+YEkdHCHEDJlFtfEDE4e2v+tRYbNa8dBSiCu/dluJ7QhyYXUPiSjGd/kk7Z/ldSTJZNY+wed//lPKKc3jf0p7aPfN6T13uWM6tat3ktllkwjqWh8S7yZwSzQjT2R1yzkVO/r6gVS2odvPjAJRdwn6WZb/QY7IJh0LRaOxBUi9j4Ma3nII4bjjIWcv8WEPHSbbwpifNodWK92YN/SHGV8qXBUcdQkbVIBLk5ucNtfUyzNy9iHY3Cvfo6dzxWfSjttCswy+F9h/UieFAHon0daXry9B4KtqtzB2KzV1mT034jC9NFfyd0KHk/KJWnMTVXtlTQlIKT1BHMVShg== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:CO6PR04MB7812.namprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(8936002)(6666004)(1076003)(8676002)(316002)(110136005)(44832011)(7416002)(508600001)(8886007)(54906003)(4326008)(2906002)(956004)(2616005)(38100700002)(55016002)(26005)(7696005)(83380400001)(36756003)(52116002)(186003)(38350700002)(66946007)(86362001)(66556008)(66476007)(30864003)(5660300002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: lMelOJmSjvVnw8rIXu+ovW75A33un9BEU1pa1ixHxgK3zM+T+g5jLZlCGotcSj6oUzWUewwS22LTW9ZbWuvOirlnpHo10D7ls5k65PMicygVDUgDQEwW7pzXojklybvtx5Fh0kttp1xz7OFfJ2XgI71T5nPPbRi+4mTnA8xKvJgHeyrkud67jElDIsnqLdD03JnXO2YLDcoibgSQ4F4OW+DsHB+KJcj4Bw04zMrmHZCqq88JyH9q3tQZHNC7KpoKKT9WSgM+m5v1vOWKtGOYfAiD0MXY/e6HghydNIVDpNzxi77UdlVfdu4020CviE3MsmfiwYFOO3NHtDOWK40ROlefJIMohlUtakYpfubOCX0GKO3kyoR33gBJBu5U2sAMcpBgVjNuPTbhi5QpjaJY74djV8je+BWqq3Rvfv7XllE+dmJUWjL7jBPpGYvBaXcLhbIXOxm4vZO9GE6CKQMIfKidQs/mvgsXl0BORfgOHZpE/BLf3O1Nz7I0z9MG1zTWcMa0A6R4gxEVp9iscIiLh0x5w48dWRaW3ZSLUxubsHbl4srXCCC3QKn3/IrtjAQ473EwNC+k8udAFZIvKqyKaKhQD2hjyAByHkm0BLfG0fJBmV7LZfn3KkHZmK5mCwcia4xEdVHGITVhdAvq4m9ZIwzYq+e4GK/H68rf8Mg+ZLoSoXKuhQvOVyJh1A8x1tqrrEVLmEYl5c3WTTzrzIS+XkUlL/m9GRW/0CbKtGCqle6xes4UG7O01cE3pRMgL5KoCHNxn9Va89loJmFbgKGiRfNymsLljyJY3MYArO03+uU7J6qtpOp2SRIw4Gid4jSWrjle5an6ol1xQFsb73bGPa/TnP33UwrBm1oz9jQVsvWyqDiXSwsbptcVdf9GlwuNrvf82EZjnNPwQilnzT7B4v0MLUacO2ZC5kZw2gsIg6yWkeWGLHzfDeo4jux3o+UkJMoDna/j9qV1t6dnsGzOUol4hEFiwwITMlnK3JiVHSUwHWJGRDGeLLLHDcDDIMBhLZlUyv3E8w+Nt8M8zBoOQbjZdT+oAANh7ZwnWg0Iirb9JsrJSX3Z/2W4pdrci8OMiLJMBPuOG/+W12W6e105lCExp+ULqhUx8XhybkMFEfVTzrZotxL5OmiTyF/JNRd4y7ay5hG26SkkrkWWBD/piiOPcmylRPgFWTqvnNIBkuOg/LA6iMCA28eThW7t6Kmn5N5w/h//V6gMvK1Xph1U0IvndUi7b1hTBByWeTBWe9Gh/0F5ASkONjbYdy11jdyK/gSgdzNrZ8zrgxyFVtO+3sKJkwuXBLOHNiwCJlTWem0BjFAl9HB6hNELPQCq5P6m X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: c45a6b0f-42cd-4cb3-4aab-08d98d6708e2 X-MS-Exchange-CrossTenant-AuthSource: CO6PR04MB7812.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Oct 2021 09:59:52.2868 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: b61c8803-16f3-4c35-9b17-6f65f441df86 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: i11WzYaddaG2yZSCEau1nvWTSd13QJTOsP6ZvP6YQGDiJNGp5l7Idi7C3jhdOOQPoZJH11e+Pyh2L26nIbYwXg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO6PR04MB8348 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211012_025955_894522_BE70CF4D X-CRM114-Status: GOOD ( 22.00 ) X-BeenThere: linux-riscv@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-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org The generic power domain related code in PSCI domain driver is largely independent of PSCI and can be shared with RISC-V SBI domain driver hence we factor-out this code into dt_idle_genpd.c and dt_idle_genpd.h. Signed-off-by: Anup Patel Reviewed-by: Ulf Hansson Tested-by: Heiko Stuebner --- MAINTAINERS | 7 + drivers/cpuidle/Kconfig | 4 + drivers/cpuidle/Kconfig.arm | 1 + drivers/cpuidle/Makefile | 1 + drivers/cpuidle/cpuidle-psci-domain.c | 138 +------------------- drivers/cpuidle/cpuidle-psci.h | 15 ++- drivers/cpuidle/dt_idle_genpd.c | 177 ++++++++++++++++++++++++++ drivers/cpuidle/dt_idle_genpd.h | 50 ++++++++ 8 files changed, 258 insertions(+), 135 deletions(-) create mode 100644 drivers/cpuidle/dt_idle_genpd.c create mode 100644 drivers/cpuidle/dt_idle_genpd.h diff --git a/MAINTAINERS b/MAINTAINERS index a4a0c2baaf27..c30b51511844 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -4911,6 +4911,13 @@ S: Supported F: drivers/cpuidle/cpuidle-psci.h F: drivers/cpuidle/cpuidle-psci-domain.c +CPUIDLE DRIVER - DT IDLE PM DOMAIN +M: Ulf Hansson +L: linux-pm@vger.kernel.org +S: Supported +F: drivers/cpuidle/dt_idle_genpd.c +F: drivers/cpuidle/dt_idle_genpd.h + CRAMFS FILESYSTEM M: Nicolas Pitre S: Maintained diff --git a/drivers/cpuidle/Kconfig b/drivers/cpuidle/Kconfig index c0aeedd66f02..f1afe7ab6b54 100644 --- a/drivers/cpuidle/Kconfig +++ b/drivers/cpuidle/Kconfig @@ -47,6 +47,10 @@ config CPU_IDLE_GOV_HALTPOLL config DT_IDLE_STATES bool +config DT_IDLE_GENPD + depends on PM_GENERIC_DOMAINS_OF + bool + menu "ARM CPU Idle Drivers" depends on ARM || ARM64 source "drivers/cpuidle/Kconfig.arm" diff --git a/drivers/cpuidle/Kconfig.arm b/drivers/cpuidle/Kconfig.arm index 334f83e56120..be12a9ca78f0 100644 --- a/drivers/cpuidle/Kconfig.arm +++ b/drivers/cpuidle/Kconfig.arm @@ -27,6 +27,7 @@ config ARM_PSCI_CPUIDLE_DOMAIN bool "PSCI CPU idle Domain" depends on ARM_PSCI_CPUIDLE depends on PM_GENERIC_DOMAINS_OF + select DT_IDLE_GENPD default y help Select this to enable the PSCI based CPUidle driver to use PM domains, diff --git a/drivers/cpuidle/Makefile b/drivers/cpuidle/Makefile index 26bbc5e74123..11a26cef279f 100644 --- a/drivers/cpuidle/Makefile +++ b/drivers/cpuidle/Makefile @@ -6,6 +6,7 @@ obj-y += cpuidle.o driver.o governor.o sysfs.o governors/ obj-$(CONFIG_ARCH_NEEDS_CPU_IDLE_COUPLED) += coupled.o obj-$(CONFIG_DT_IDLE_STATES) += dt_idle_states.o +obj-$(CONFIG_DT_IDLE_GENPD) += dt_idle_genpd.o obj-$(CONFIG_ARCH_HAS_CPU_RELAX) += poll_state.o obj-$(CONFIG_HALTPOLL_CPUIDLE) += cpuidle-haltpoll.o diff --git a/drivers/cpuidle/cpuidle-psci-domain.c b/drivers/cpuidle/cpuidle-psci-domain.c index ff2c3f8e4668..755bbdfc5b82 100644 --- a/drivers/cpuidle/cpuidle-psci-domain.c +++ b/drivers/cpuidle/cpuidle-psci-domain.c @@ -47,73 +47,14 @@ static int psci_pd_power_off(struct generic_pm_domain *pd) return 0; } -static int psci_pd_parse_state_nodes(struct genpd_power_state *states, - int state_count) -{ - int i, ret; - u32 psci_state, *psci_state_buf; - - for (i = 0; i < state_count; i++) { - ret = psci_dt_parse_state_node(to_of_node(states[i].fwnode), - &psci_state); - if (ret) - goto free_state; - - psci_state_buf = kmalloc(sizeof(u32), GFP_KERNEL); - if (!psci_state_buf) { - ret = -ENOMEM; - goto free_state; - } - *psci_state_buf = psci_state; - states[i].data = psci_state_buf; - } - - return 0; - -free_state: - i--; - for (; i >= 0; i--) - kfree(states[i].data); - return ret; -} - -static int psci_pd_parse_states(struct device_node *np, - struct genpd_power_state **states, int *state_count) -{ - int ret; - - /* Parse the domain idle states. */ - ret = of_genpd_parse_idle_states(np, states, state_count); - if (ret) - return ret; - - /* Fill out the PSCI specifics for each found state. */ - ret = psci_pd_parse_state_nodes(*states, *state_count); - if (ret) - kfree(*states); - - return ret; -} - -static void psci_pd_free_states(struct genpd_power_state *states, - unsigned int state_count) -{ - int i; - - for (i = 0; i < state_count; i++) - kfree(states[i].data); - kfree(states); -} - static int psci_pd_init(struct device_node *np, bool use_osi) { struct generic_pm_domain *pd; struct psci_pd_provider *pd_provider; struct dev_power_governor *pd_gov; - struct genpd_power_state *states = NULL; int ret = -ENOMEM, state_count = 0; - pd = kzalloc(sizeof(*pd), GFP_KERNEL); + pd = dt_idle_pd_alloc(np, psci_dt_parse_state_node); if (!pd) goto out; @@ -121,22 +62,6 @@ static int psci_pd_init(struct device_node *np, bool use_osi) if (!pd_provider) goto free_pd; - pd->name = kasprintf(GFP_KERNEL, "%pOF", np); - if (!pd->name) - goto free_pd_prov; - - /* - * Parse the domain idle states and let genpd manage the state selection - * for those being compatible with "domain-idle-state". - */ - ret = psci_pd_parse_states(np, &states, &state_count); - if (ret) - goto free_name; - - pd->free_states = psci_pd_free_states; - pd->name = kbasename(pd->name); - pd->states = states; - pd->state_count = state_count; pd->flags |= GENPD_FLAG_IRQ_SAFE | GENPD_FLAG_CPU_DOMAIN; /* Allow power off when OSI has been successfully enabled. */ @@ -149,10 +74,8 @@ static int psci_pd_init(struct device_node *np, bool use_osi) pd_gov = state_count > 0 ? &pm_domain_cpu_gov : NULL; ret = pm_genpd_init(pd, pd_gov, false); - if (ret) { - psci_pd_free_states(states, state_count); - goto free_name; - } + if (ret) + goto free_pd_prov; ret = of_genpd_add_provider_simple(np, pd); if (ret) @@ -166,12 +89,10 @@ static int psci_pd_init(struct device_node *np, bool use_osi) remove_pd: pm_genpd_remove(pd); -free_name: - kfree(pd->name); free_pd_prov: kfree(pd_provider); free_pd: - kfree(pd); + dt_idle_pd_free(pd); out: pr_err("failed to init PM domain ret=%d %pOF\n", ret, np); return ret; @@ -195,30 +116,6 @@ static void psci_pd_remove(void) } } -static int psci_pd_init_topology(struct device_node *np) -{ - struct device_node *node; - struct of_phandle_args child, parent; - int ret; - - for_each_child_of_node(np, node) { - if (of_parse_phandle_with_args(node, "power-domains", - "#power-domain-cells", 0, &parent)) - continue; - - child.np = node; - child.args_count = 0; - ret = of_genpd_add_subdomain(&parent, &child); - of_node_put(parent.np); - if (ret) { - of_node_put(node); - return ret; - } - } - - return 0; -} - static bool psci_pd_try_set_osi_mode(void) { int ret; @@ -282,7 +179,7 @@ static int psci_cpuidle_domain_probe(struct platform_device *pdev) goto no_pd; /* Link genpd masters/subdomains to model the CPU topology. */ - ret = psci_pd_init_topology(np); + ret = dt_idle_pd_init_topology(np); if (ret) goto remove_pd; @@ -314,28 +211,3 @@ static int __init psci_idle_init_domains(void) return platform_driver_register(&psci_cpuidle_domain_driver); } subsys_initcall(psci_idle_init_domains); - -struct device *psci_dt_attach_cpu(int cpu) -{ - struct device *dev; - - dev = dev_pm_domain_attach_by_name(get_cpu_device(cpu), "psci"); - if (IS_ERR_OR_NULL(dev)) - return dev; - - pm_runtime_irq_safe(dev); - if (cpu_online(cpu)) - pm_runtime_get_sync(dev); - - dev_pm_syscore_device(dev, true); - - return dev; -} - -void psci_dt_detach_cpu(struct device *dev) -{ - if (IS_ERR_OR_NULL(dev)) - return; - - dev_pm_domain_detach(dev, false); -} diff --git a/drivers/cpuidle/cpuidle-psci.h b/drivers/cpuidle/cpuidle-psci.h index d8e925e84c27..4e132640ed64 100644 --- a/drivers/cpuidle/cpuidle-psci.h +++ b/drivers/cpuidle/cpuidle-psci.h @@ -10,8 +10,19 @@ void psci_set_domain_state(u32 state); int psci_dt_parse_state_node(struct device_node *np, u32 *state); #ifdef CONFIG_ARM_PSCI_CPUIDLE_DOMAIN -struct device *psci_dt_attach_cpu(int cpu); -void psci_dt_detach_cpu(struct device *dev); + +#include "dt_idle_genpd.h" + +static inline struct device *psci_dt_attach_cpu(int cpu) +{ + return dt_idle_attach_cpu(cpu, "psci"); +} + +static inline void psci_dt_detach_cpu(struct device *dev) +{ + dt_idle_detach_cpu(dev); +} + #else static inline struct device *psci_dt_attach_cpu(int cpu) { return NULL; } static inline void psci_dt_detach_cpu(struct device *dev) { } diff --git a/drivers/cpuidle/dt_idle_genpd.c b/drivers/cpuidle/dt_idle_genpd.c new file mode 100644 index 000000000000..db385fd2507e --- /dev/null +++ b/drivers/cpuidle/dt_idle_genpd.c @@ -0,0 +1,177 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * PM domains for CPUs via genpd. + * + * Copyright (C) 2019 Linaro Ltd. + * Author: Ulf Hansson + * + * Copyright (c) 2021 Western Digital Corporation or its affiliates. + */ + +#define pr_fmt(fmt) "dt-idle-genpd: " fmt + +#include +#include +#include +#include +#include +#include +#include + +#include "dt_idle_genpd.h" + +static int pd_parse_state_nodes( + int (*parse_state)(struct device_node *, u32 *), + struct genpd_power_state *states, int state_count) +{ + int i, ret; + u32 state, *state_buf; + + for (i = 0; i < state_count; i++) { + ret = parse_state(to_of_node(states[i].fwnode), &state); + if (ret) + goto free_state; + + state_buf = kmalloc(sizeof(u32), GFP_KERNEL); + if (!state_buf) { + ret = -ENOMEM; + goto free_state; + } + *state_buf = state; + states[i].data = state_buf; + } + + return 0; + +free_state: + i--; + for (; i >= 0; i--) + kfree(states[i].data); + return ret; +} + +static int pd_parse_states(struct device_node *np, + int (*parse_state)(struct device_node *, u32 *), + struct genpd_power_state **states, + int *state_count) +{ + int ret; + + /* Parse the domain idle states. */ + ret = of_genpd_parse_idle_states(np, states, state_count); + if (ret) + return ret; + + /* Fill out the dt specifics for each found state. */ + ret = pd_parse_state_nodes(parse_state, *states, *state_count); + if (ret) + kfree(*states); + + return ret; +} + +static void pd_free_states(struct genpd_power_state *states, + unsigned int state_count) +{ + int i; + + for (i = 0; i < state_count; i++) + kfree(states[i].data); + kfree(states); +} + +void dt_idle_pd_free(struct generic_pm_domain *pd) +{ + pd_free_states(pd->states, pd->state_count); + kfree(pd->name); + kfree(pd); +} + +struct generic_pm_domain *dt_idle_pd_alloc(struct device_node *np, + int (*parse_state)(struct device_node *, u32 *)) +{ + struct generic_pm_domain *pd; + struct genpd_power_state *states = NULL; + int ret, state_count = 0; + + pd = kzalloc(sizeof(*pd), GFP_KERNEL); + if (!pd) + goto out; + + pd->name = kasprintf(GFP_KERNEL, "%pOF", np); + if (!pd->name) + goto free_pd; + + /* + * Parse the domain idle states and let genpd manage the state selection + * for those being compatible with "domain-idle-state". + */ + ret = pd_parse_states(np, parse_state, &states, &state_count); + if (ret) + goto free_name; + + pd->free_states = pd_free_states; + pd->name = kbasename(pd->name); + pd->states = states; + pd->state_count = state_count; + + pr_debug("alloc PM domain %s\n", pd->name); + return pd; + +free_name: + kfree(pd->name); +free_pd: + kfree(pd); +out: + pr_err("failed to alloc PM domain %pOF\n", np); + return NULL; +} + +int dt_idle_pd_init_topology(struct device_node *np) +{ + struct device_node *node; + struct of_phandle_args child, parent; + int ret; + + for_each_child_of_node(np, node) { + if (of_parse_phandle_with_args(node, "power-domains", + "#power-domain-cells", 0, &parent)) + continue; + + child.np = node; + child.args_count = 0; + ret = of_genpd_add_subdomain(&parent, &child); + of_node_put(parent.np); + if (ret) { + of_node_put(node); + return ret; + } + } + + return 0; +} + +struct device *dt_idle_attach_cpu(int cpu, const char *name) +{ + struct device *dev; + + dev = dev_pm_domain_attach_by_name(get_cpu_device(cpu), name); + if (IS_ERR_OR_NULL(dev)) + return dev; + + pm_runtime_irq_safe(dev); + if (cpu_online(cpu)) + pm_runtime_get_sync(dev); + + dev_pm_syscore_device(dev, true); + + return dev; +} + +void dt_idle_detach_cpu(struct device *dev) +{ + if (IS_ERR_OR_NULL(dev)) + return; + + dev_pm_domain_detach(dev, false); +} diff --git a/drivers/cpuidle/dt_idle_genpd.h b/drivers/cpuidle/dt_idle_genpd.h new file mode 100644 index 000000000000..a95483d08a02 --- /dev/null +++ b/drivers/cpuidle/dt_idle_genpd.h @@ -0,0 +1,50 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __DT_IDLE_GENPD +#define __DT_IDLE_GENPD + +struct device_node; +struct generic_pm_domain; + +#ifdef CONFIG_DT_IDLE_GENPD + +void dt_idle_pd_free(struct generic_pm_domain *pd); + +struct generic_pm_domain *dt_idle_pd_alloc(struct device_node *np, + int (*parse_state)(struct device_node *, u32 *)); + +int dt_idle_pd_init_topology(struct device_node *np); + +struct device *dt_idle_attach_cpu(int cpu, const char *name); + +void dt_idle_detach_cpu(struct device *dev); + +#else + +static inline void dt_idle_pd_free(struct generic_pm_domain *pd) +{ +} + +static inline struct generic_pm_domain *dt_idle_pd_alloc( + struct device_node *np, + int (*parse_state)(struct device_node *, u32 *)) +{ + return NULL; +} + +static inline int dt_idle_pd_init_topology(struct device_node *np) +{ + return 0; +} + +static inline struct device *dt_idle_attach_cpu(int cpu, const char *name) +{ + return NULL; +} + +static inline void dt_idle_detach_cpu(struct device *dev) +{ +} + +#endif + +#endif