From patchwork Mon May 17 13:08:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 12261865 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2374FC433ED for ; Mon, 17 May 2021 13:09:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F2319611BE for ; Mon, 17 May 2021 13:09:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237248AbhEQNKw (ORCPT ); Mon, 17 May 2021 09:10:52 -0400 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:39727 "EHLO esa1.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237245AbhEQNKv (ORCPT ); Mon, 17 May 2021 09:10:51 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1621256975; x=1652792975; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=wEHH9KQgEMsvLCrTYZOkd42zk4RD29DDsOSgOkBr7kM=; b=HFMxekGhx7aUiYUHARHS1fOFPCd+/Y5TEIdWjzr2uSDLKQC1kBB32Y6J AeZT28LY0z/bWh2jbmcKl26dlw2cGVSXg95taVb8nC+yHYrgV5Z8lrDwq 5s00KU/oQbiRHM/5xGPCJu1e3T90NGOSgakO0Wzff9UM5UWPrF1PerZ4S LT3Zcs7/F1Oab7wpNNh3qJLF/QauRtg7EINrUNf77NwzJ6gWgvsXYYZnX AQzOYwDexseC1O740USut3LtcNG/IRCULBQbcH//v7zjROdT5sqW4MQf1 tAenOcx5o9cea9Jfe5ycouEvqnSMvTEe+KJbqOGmsi8iCx5XpggMyD5LQ Q==; IronPort-SDR: V6FTQCZ7BY8UsiAR9wglK6g3bDPUmTw8Q0Kt6JlhZdQ453p9xKwyA8gyNXR67h1xMIVTgC84nq /3EhGjK4QCdue0fNtYqjCs/IaUHL9HbwkcFftadLCSRsPCEAmP783PRanYH6ak3mbCfD68dvsK 5jIPWzETjLA1jk155+YOXyo0pxx34nO7mAVr1RPR8KPFdmngpgUYh9RdX8Qisx5zR+42Q/fwaa J1j1+L29zlcm2WxK2CgxI+c3vNztjFawT4NPDHpTRPnNPbLYf5D+5wG6fjgQARxHgCGW8W97+E TCI= X-IronPort-AV: E=Sophos;i="5.82,307,1613404800"; d="scan'208";a="279668200" Received: from mail-bn8nam08lp2044.outbound.protection.outlook.com (HELO NAM04-BN8-obe.outbound.protection.outlook.com) ([104.47.74.44]) by ob1.hgst.iphmx.com with ESMTP; 17 May 2021 21:09:28 +0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jUw1TGYpqrGSSBFUBVrmYiUhAjq2cjNNU99M2cUtUedFZK5AAZilC/jpp7AlJlXkO1vSgXu33nhUNm+fk4Upmk3GNbTpWKLQ43lUVpxcMEjJbv7mwdGQzqh+NqpMRckKLY8nCM8/xJFU5kMqMYumIkVBU++/KMu84/XGo/R9jWpNr49T9K7VAaSFDtJecu67WWn3FQTDSV8au6K14w0h/KSRK5HRr6IRbbiOEFaS+CfxqO1lNMrmDJNp90J4HJ1gpwG0vnftz62krSKx3Bkcy1lj05y3UTpOaUDN5u1pAeET0K8sQYMKcNaCEnO1kL3cK+E0BhakZP10kHIzhXy/6Q== 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-SenderADCheck; bh=vd66ecKx9q2t9o7QVLlDpOcbqmauJmomlXUBQ5vOQpY=; b=X1Tr8EJn18TVkd1Wr1/SQqc4UT9HY+7Q4PATMNh/xHjQsqX9zrt+8WlfCZ32X8YEfsmWQ0HOOIYUAwo7dOt6TLD0Q4WpV97nfGWkKUc/TyNrinZ649uwYhU+jf0Mg/ghty92XLkIhITcAzE9lJwEiTFC+LgmHPHgA63bWCkZ+rwzOmAHxF1ssHVLmNpKaYsYkEH+2/FhxDhZet4vd2HV0LaSNj2e3hN2PUHApUHcXQWoYID+HmHwp3A88cYvEd8uU0EzNmqTewFBuphB8yMT4FAu1MEaEWkgH49WfptUb2jy1+3MWqBEFULUKmBfC+98AsRwBKJNU8MSLXVAh6FcPw== 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=vd66ecKx9q2t9o7QVLlDpOcbqmauJmomlXUBQ5vOQpY=; b=Gtn2Q4ZnBAwl0e4iSPFHCxZYyMbu6KgcBsS1GgLXw7R2Ph+jI+loQzO8mueRAz+IRkvbME7SB6TZsS9voEEux5HKaaa3qozd1nUD08BsmjIIiSCIigomGVpWvZHLAgIPMEnbpZ+bo1aX1Q1iX+zkI0Bn6IJULmzLDrVYzJzjVds= 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 CO6PR04MB7778.namprd04.prod.outlook.com (2603:10b6:303:13e::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4129.26; Mon, 17 May 2021 13:09:27 +0000 Received: from CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::88a0:bf18:b01d:1a50]) by CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::88a0:bf18:b01d:1a50%4]) with mapi id 15.20.4129.031; Mon, 17 May 2021 13:09:27 +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: [RFC PATCH v4 1/8] RISC-V: Enable CPU_IDLE drivers Date: Mon, 17 May 2021 18:38:16 +0530 Message-Id: <20210517130823.796963-2-anup.patel@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210517130823.796963-1-anup.patel@wdc.com> References: <20210517130823.796963-1-anup.patel@wdc.com> X-Originating-IP: [122.179.32.240] X-ClientProxiedBy: MA1PR0101CA0024.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:21::34) To CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from wdc.com (122.179.32.240) by MA1PR0101CA0024.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:21::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4108.25 via Frontend Transport; Mon, 17 May 2021 13:09:12 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: fe99f538-ae5f-4f0d-6347-08d91934ffb6 X-MS-TrafficTypeDiagnostic: CO6PR04MB7778: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: WDCIPOUTBOUND: EOP-TRUE X-MS-Oob-TLC-OOBClassifiers: OLM:5236; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: NBuHqQav0m3ziwtC7GFiGDKjJdCROHjpJ7mn0a9MuQqBy3MkdyOFdQ3IRgvB5hzXmaFts8xIL1n5f3k1rXHW2iFmscCbMJf/gVECLyuEfR5OYjFw6n2DJjuplfBrVUFqQGa+XitdFn4GaTEPg6nmpZIQeFkbS0Od/fpBnIJhUJBGRME9ys5aNKl0miQTiiXvDwHWJ9jyW9iQ0uYr1JakQ4+nZn0ZlHyDK9pRHN2ujWspItSJU+FAMCLGlKX5MfbK81jstW/WgI6KjmKJRTBpEHrwU7KggJrFp9abF3OHODUdh6xGhoiSLRsJyP2AT0ZfWbIgVGUr48dqgWbe37qVsvbZQrhMP4zMlf7vmg1LJZj20F8Jt35zChbIKRn7feL5buMs3qDByDW9hK/zbuhBMLcp+p4a+NcuIdnZeCjlQBZTLDGTos0S9GbRBoJI6A4WiY0PdPEpgpV3Ig8POpvkU5Jsn+45Y+O7DK8apjcp4pribFSDOf2lJCEbMV/ZEiAqqjMt+x+gN0jEyI9Xiff7gJckfSZK4sFiKeDvR3Lg2ODx/FTlgPS0HAqUglYvqmGdllhxSOd0bhF4Ggdj1SlmW18NO4QaBHjQ1qwAslVTvxZuNHkRNmgiX/YcQOIPbLgjYWSXwUpTASzd/xRQySBKJKv3Ifho5oz0r5Svmdx3BF8= 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)(39850400004)(396003)(346002)(136003)(376002)(83380400001)(38100700002)(1076003)(26005)(8886007)(66946007)(44832011)(86362001)(38350700002)(316002)(4326008)(55016002)(2616005)(956004)(52116002)(7696005)(110136005)(54906003)(478600001)(8936002)(8676002)(186003)(7416002)(16526019)(66556008)(66476007)(2906002)(36756003)(5660300002);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData: yfdgX473o2gNIkYp4bTSYVJH8AJhoaorQCbdE9M1mENpd0iIQTf950oVIrCR7McyG/YyKR6zgCPBc3j/J+Q+EX+bFyWOUfhfCP4MMwl2rpjArDw27n4V7GlM43YIfvQlo+xonZac16k0VhY8Grgi8fuy6Ei10NnQCR4325STwc7vJSa8YX52WlUw9T+0b6kDyQAyNSZBkbCuknkf9Ypo/iCETFxqm7ZUTFxcm0YLLklo9zUfrQeeMncoZpHog6nLvO6q1kk7DFuExUoxyjlEWnkC8Q4tRQo16GXu7l3ZfC3zFyZDF5FchRktD9Dsr1pvKPBgSlegHv9R7hcbV6IILIRUlYEYsjQgZB3r1Ig/bbVRfscmBKhL5V5TjFdvNQz7IIVLjLXO8dPr4oNvkcdLntCzz6O47SHp56lsmDl8MJ12ecybfFsgYvFvz5IGltxhNTDXqo1gOmhFuxGXVDkdxcGoKO3ixA+ujUw5POfmwPKth9B0aP4mRnRe/tk1EFwrD3fXsiNbstLvWPiwAxw30gj0aThbv24j/llUYHH3xhC1ZJ1DJogLHK+wVoYyGstboPvziNKXgRizAlzKWd+dpYCbXXQtX/boaqo8hla728p2Od3y4i1JxH8MR+WKisF5rmqTB+q53XhtILsrXw9AxDIu87V/Nm5xcMAbKkyrr5naw/X+8QVJpne1Pqq8szbNt8kRVMfRGPAWEucFCQWxnmHA+fdxDVuZN10QsAyA2m1wEAcb9pvSfMhazgJXMw0HlmzqUv+bN70cCzAz+C36tSVZBA+9YJGsi4/B0rGLmnx3PGd7BfoAIZZt7n0TguvHYt5jNv6/z765eNJNxyKD/f1Mzs1TdpltlIUGZOdepyB1CB8aDbIz41vl7zKyc5otKTnjL8SdJ51ShU0Zs0GtlX3I0qlS9gnI6y4Dg3cHIGn2q6rAb3gRswN7AjXUTuFbhmuKwuCpk7ybgUu3SjUE3XHdNcbEAUeDTeIjUYl6aP2m2CYITGX85Bpm1aaWqzZabe9Fij8jfkFg24k46pP7LdDMD43jwvgpQj6xNLWY0y9XBTlQk9+zYqVkMvVP9rFUJplOhTup3tQ78t8SEAVMp5urehtvOvmlKQlgOA4jMcQz1gKGVatNY6fZAUS+Z4teBd1MtrJK1K3PLjAY3snBr0kzP/6MIWh0OsfNCgMdOm7EUySCzBOHAbxkou20qReLs37oLc6EtAs/gm2cdRMETHdOxbwzUtbaHQep5DogrZxKwzO5Z1U2E0DmSN8V1O6iNDa+EIk817fMzKR8haky54lyoveMsbkKuxGmt3w1zBvS7lLoJOdTDbKOARkoe/zB X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: fe99f538-ae5f-4f0d-6347-08d91934ffb6 X-MS-Exchange-CrossTenant-AuthSource: CO6PR04MB7812.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 May 2021 13:09:26.9758 (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: mY4hgigs6eVMyQ0tekNTaTZ/4x6wI6rydzBFiDjgXktjDSsEuiVkZV/4f8QLB3Y8UBYATjHXziOQXfEfJ0d5NQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO6PR04MB7778 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org We force select CPU_PM and provide asm/cpuidle.h so that we can use CPU IDLE drivers for Linux RISC-V kernel. Signed-off-by: Anup Patel --- arch/riscv/Kconfig | 7 +++++++ arch/riscv/configs/defconfig | 12 +++++------- arch/riscv/configs/rv32_defconfig | 5 ++--- arch/riscv/include/asm/cpuidle.h | 24 ++++++++++++++++++++++++ arch/riscv/kernel/process.c | 3 ++- 5 files changed, 40 insertions(+), 11 deletions(-) create mode 100644 arch/riscv/include/asm/cpuidle.h diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig index 195c6d319ab8..f607fd33014f 100644 --- a/arch/riscv/Kconfig +++ b/arch/riscv/Kconfig @@ -42,6 +42,7 @@ config RISCV select CLONE_BACKWARDS select CLINT_TIMER if !MMU select COMMON_CLK + select CPU_PM if CPU_IDLE select EDAC_SUPPORT select GENERIC_ARCH_TOPOLOGY if SMP select GENERIC_ATOMIC64 if !64BIT @@ -555,4 +556,10 @@ source "kernel/power/Kconfig" endmenu +menu "CPU Power Management" + +source "drivers/cpuidle/Kconfig" + +endmenu + source "drivers/firmware/Kconfig" diff --git a/arch/riscv/configs/defconfig b/arch/riscv/configs/defconfig index 1f2be234b11c..57a24d40d43f 100644 --- a/arch/riscv/configs/defconfig +++ b/arch/riscv/configs/defconfig @@ -13,12 +13,14 @@ CONFIG_USER_NS=y CONFIG_CHECKPOINT_RESTORE=y CONFIG_BLK_DEV_INITRD=y CONFIG_EXPERT=y +# CONFIG_SYSFS_SYSCALL is not set CONFIG_BPF_SYSCALL=y +CONFIG_SOC_MICROCHIP_POLARFIRE=y CONFIG_SOC_SIFIVE=y CONFIG_SOC_VIRT=y -CONFIG_SOC_MICROCHIP_POLARFIRE=y CONFIG_SMP=y CONFIG_HOTPLUG_CPU=y +CONFIG_CPU_IDLE=y CONFIG_JUMP_LABEL=y CONFIG_MODULES=y CONFIG_MODULE_UNLOAD=y @@ -66,10 +68,9 @@ CONFIG_HW_RANDOM=y CONFIG_HW_RANDOM_VIRTIO=y CONFIG_SPI=y CONFIG_SPI_SIFIVE=y +# CONFIG_PTP_1588_CLOCK is not set CONFIG_GPIOLIB=y CONFIG_GPIO_SIFIVE=y -# CONFIG_PTP_1588_CLOCK is not set -CONFIG_POWER_RESET=y CONFIG_DRM=y CONFIG_DRM_RADEON=y CONFIG_DRM_VIRTIO_GPU=y @@ -83,10 +84,10 @@ CONFIG_USB_OHCI_HCD=y CONFIG_USB_OHCI_HCD_PLATFORM=y CONFIG_USB_STORAGE=y CONFIG_USB_UAS=y +CONFIG_MMC=y CONFIG_MMC_SDHCI=y CONFIG_MMC_SDHCI_PLTFM=y CONFIG_MMC_SDHCI_CADENCE=y -CONFIG_MMC=y CONFIG_MMC_SPI=y CONFIG_RTC_CLASS=y CONFIG_VIRTIO_PCI=y @@ -135,6 +136,3 @@ CONFIG_RCU_EQS_DEBUG=y CONFIG_DEBUG_BLOCK_EXT_DEVT=y # CONFIG_FTRACE is not set # CONFIG_RUNTIME_TESTING_MENU is not set -CONFIG_MEMTEST=y -# CONFIG_SYSFS_SYSCALL is not set -CONFIG_EFI=y diff --git a/arch/riscv/configs/rv32_defconfig b/arch/riscv/configs/rv32_defconfig index 8dd02b842fef..97d899df2445 100644 --- a/arch/riscv/configs/rv32_defconfig +++ b/arch/riscv/configs/rv32_defconfig @@ -13,12 +13,14 @@ CONFIG_USER_NS=y CONFIG_CHECKPOINT_RESTORE=y CONFIG_BLK_DEV_INITRD=y CONFIG_EXPERT=y +# CONFIG_SYSFS_SYSCALL is not set CONFIG_BPF_SYSCALL=y CONFIG_SOC_SIFIVE=y CONFIG_SOC_VIRT=y CONFIG_ARCH_RV32I=y CONFIG_SMP=y CONFIG_HOTPLUG_CPU=y +CONFIG_CPU_IDLE=y CONFIG_JUMP_LABEL=y CONFIG_MODULES=y CONFIG_MODULE_UNLOAD=y @@ -67,7 +69,6 @@ CONFIG_HW_RANDOM_VIRTIO=y CONFIG_SPI=y CONFIG_SPI_SIFIVE=y # CONFIG_PTP_1588_CLOCK is not set -CONFIG_POWER_RESET=y CONFIG_DRM=y CONFIG_DRM_RADEON=y CONFIG_DRM_VIRTIO_GPU=y @@ -130,5 +131,3 @@ CONFIG_RCU_EQS_DEBUG=y CONFIG_DEBUG_BLOCK_EXT_DEVT=y # CONFIG_FTRACE is not set # CONFIG_RUNTIME_TESTING_MENU is not set -CONFIG_MEMTEST=y -# CONFIG_SYSFS_SYSCALL is not set diff --git a/arch/riscv/include/asm/cpuidle.h b/arch/riscv/include/asm/cpuidle.h new file mode 100644 index 000000000000..71fdc607d4bc --- /dev/null +++ b/arch/riscv/include/asm/cpuidle.h @@ -0,0 +1,24 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright (C) 2021 Allwinner Ltd + * Copyright (C) 2021 Western Digital Corporation or its affiliates. + */ + +#ifndef _ASM_RISCV_CPUIDLE_H +#define _ASM_RISCV_CPUIDLE_H + +#include +#include + +static inline void cpu_do_idle(void) +{ + /* + * Add mb() here to ensure that all + * IO/MEM accesses are completed prior + * to entering WFI. + */ + mb(); + wait_for_interrupt(); +} + +#endif diff --git a/arch/riscv/kernel/process.c b/arch/riscv/kernel/process.c index f9cd57c9c67d..461520222589 100644 --- a/arch/riscv/kernel/process.c +++ b/arch/riscv/kernel/process.c @@ -23,6 +23,7 @@ #include #include #include +#include register unsigned long gp_in_global __asm__("gp"); @@ -37,7 +38,7 @@ extern asmlinkage void ret_from_kernel_thread(void); void arch_cpu_idle(void) { - wait_for_interrupt(); + cpu_do_idle(); raw_local_irq_enable(); } From patchwork Mon May 17 13:08:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 12261869 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 78C58C433ED for ; Mon, 17 May 2021 13:09:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5ABC561076 for ; Mon, 17 May 2021 13:09:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237266AbhEQNLF (ORCPT ); Mon, 17 May 2021 09:11:05 -0400 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:59438 "EHLO esa4.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237271AbhEQNLC (ORCPT ); Mon, 17 May 2021 09:11:02 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1621256985; x=1652792985; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=qMoC26aE1t/imsmMoQjUxEhGnzi1b1hiqgTM5NyeOBU=; b=IR+daVCXf5NrYfgfRId4AIFecmkRwbiOpBRPDAD49Euk0GoMgNZDhQ1J BQjMV1qIjaFxwaBNjlt9QFn3mQriNlY8sm8zrsfGGKlGMkfZNA6zqbc04 7tmCb3vyPKsM4RlJSMUZJAsWxLRyvO08PhqMixMGX1gMNYWIv0WF7CWnm N76r8XVhvQZJyHuAs6dmUzrWL9vzEUI/rrpgqBBwfYHj/8wrh5FbI4bjs bOK6BZ06QQxSLCS5xYHf36CrAdm8TQSBuQ+raauatZ+0azfV3hxKXwKi4 ZfrRYGvrQQzKU+yUyGyX3ULHz9+GWZmiqnpfC6Jwhk5ByXGGeJA99Vw3U Q==; IronPort-SDR: kHIDTtIGNac6tukh+OnZLiAVIZf/6MZevu4TUAvzxlvX+azH9KBrjyv9qeOZZfYSgYOEfzZvrf vCKgkinlXv4iA+o9NldsLeJO9aCM0dTSn535qELBIA/tpR6SQM7FHmEdAPnnh9f3qOLTwsulab hV9gMo5jWaZ12f6p1axvw1ZjJP8DmC+QPda623XNQ+CIB2zGFO3h9zUo7rkPOFPN3z9HNoVVY6 QWqsPl/VTiImRXPXy+l7z2AJC+b4wYKPcFoA+r8O1MMYaABKGrK6f8pDNJlABvPYsEDOV4gBHg 8nc= X-IronPort-AV: E=Sophos;i="5.82,307,1613404800"; d="scan'208";a="167757123" Received: from mail-bn8nam08lp2047.outbound.protection.outlook.com (HELO NAM04-BN8-obe.outbound.protection.outlook.com) ([104.47.74.47]) by ob1.hgst.iphmx.com with ESMTP; 17 May 2021 21:09:42 +0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=G4vwg/sgPy/0WuzSVJtu9HS1t1NIjP1a4D1D89Nuc1AKQ6W4ZWdtya+ZSv3/K1U3OXt67hcQ2BOTNKM9uoTjklZMG33pVWnXEA4Bao56Z6KeRpbpmgK6rcxI2R1CLfmuCemuE1eZyzh/1y5QIipznk+PTVtfpS6n1DBGF0aMhSBBiGNW3I9WlKsVJyDvCL2rRKFC1X9XLUs+Aap7nPs1iRVK1Ppe68Z9FNv3GNEwiQQ38ESfjPCUwJ5asv9xcJvvMhsKA9Ex/7ukBGCJXnBkYBZcO5pA7nk79oK3EhmTbvzmIRtsIBXscn1YIxZSuFQGwSven+oFoeeYKCsVg9uVBQ== 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-SenderADCheck; bh=GdFS0rAEtKE6yd9Zx3nNwSnuIUcrKnIom98JvQmaI1w=; b=a7Z1oXsUZY6M9UVauXWvogkT7EzkJaELp754rbe9HqYFdiL/2a0En6ACylNMJVAT0QpK++a7xD9NRA9p6bobea7ZUdI7COPHQAMWUJaDSdHkcjHILArwWbn4V+yih2xseOcnHSSpMAeCX8RtQ/pJ0EDiCdeLeCZ/jC5ziQzY5duVa9RRG5HT/4nP6kuguCB1aRiWhkYmwHHAVP8UMa0KtLKrdEsLyh3EZ/NdvMC8GpCEja9rkcHRlywgDmUeZM4QwDxqxjaAX7OG95IwdZxsXgThYXox3EeG13DoE3/hSHSm0gKIilk0UGIocLKeux93dUvDe8QEiT0dt5St3+abFA== 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=GdFS0rAEtKE6yd9Zx3nNwSnuIUcrKnIom98JvQmaI1w=; b=Uk13wtcSWWyFrhnR9ETG5UAYZL7OuO1UaB/ePq0+COsWvXBZmGgVRSs/j5yAJtU9N3Iihz8WyXUeIgBPMM/v+vsqlZAgeZP0cdp4Ir2Ux867PBBySO6MXOZmPhPM91nsXoCP3ReskV4tw3EZcaFLcZkVMWhYJADRINsLzDkBpg4= 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 CO6PR04MB7778.namprd04.prod.outlook.com (2603:10b6:303:13e::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4129.26; Mon, 17 May 2021 13:09:41 +0000 Received: from CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::88a0:bf18:b01d:1a50]) by CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::88a0:bf18:b01d:1a50%4]) with mapi id 15.20.4129.031; Mon, 17 May 2021 13:09:41 +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: [RFC PATCH v4 2/8] RISC-V: Rename relocate() and make it global Date: Mon, 17 May 2021 18:38:17 +0530 Message-Id: <20210517130823.796963-3-anup.patel@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210517130823.796963-1-anup.patel@wdc.com> References: <20210517130823.796963-1-anup.patel@wdc.com> X-Originating-IP: [122.179.32.240] X-ClientProxiedBy: MA1PR0101CA0024.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:21::34) To CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from wdc.com (122.179.32.240) by MA1PR0101CA0024.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:21::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4108.25 via Frontend Transport; Mon, 17 May 2021 13:09:28 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 33b08c30-3463-4ffc-6519-08d91935084f X-MS-TrafficTypeDiagnostic: CO6PR04MB7778: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: WDCIPOUTBOUND: EOP-TRUE X-MS-Oob-TLC-OOBClassifiers: OLM:3276; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ijAKrR/gXpiwkTveWZ6X1xtGPJ0pk61CJMXTlD6n0hj4WTke5YDr90SCsvL/TudCL16KK2IhogIaXps3pB15oHbIy79d/ezIng22aUvg7Mb9/QqdF6gZcZpPimH+cbuybQ6TVpKwxrQ2Dw37AXpguQUF4Zh0kMIyMfEvGKEdW9/X+xpscOX2yW9keB+9pZTznxn3hbK0z9TeOe7nALeWMOpSKrlC8FWSWPNDA5XukZb2NMFa7GbwUwyWRzCitUvHWKqgp10eHNmvrSgmp41lINzbZnVb4QtRhx2jrP8gRb1xLQ5vD3EWgorZm67OuzfG3oS2yoTobZCEy74/v768UeN1UP9T9/f46TkY4zrqcggouF3y7qKs5I7VQQS0/MpSD0orm2fSy/hfi8E+Ej6vlIYzmnnBLMnXr0Kp+Z/oRbwJJbjCRyz1G8eKxQbL9b7U6Kn5gH0fuPza2o++/bPPKNb3hn8+jd7s21f5yFSXJWtBy3mZIPLQgF1TmevC3sfPlIEk0bf2/hznx9e6jgQu08vksi6nL9Zg+zMELdRmQTGKi6ZpVVGSBquR6QoJUV81X3sRDP4Hcn8PwcTAcFhk8fyCC8I2jq5vmU4cAcJfR24Nt6yil7AHIxfcwXyBEZtPVU9Qan4rMQA1VY6cmzfkBLPHT9TbWPM69OIwfYzZvNo= 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)(39850400004)(396003)(346002)(136003)(376002)(83380400001)(38100700002)(6666004)(1076003)(26005)(8886007)(66946007)(44832011)(86362001)(38350700002)(316002)(4326008)(55016002)(2616005)(956004)(52116002)(7696005)(110136005)(54906003)(478600001)(8936002)(8676002)(186003)(7416002)(16526019)(66556008)(66476007)(2906002)(36756003)(5660300002);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData: L0CeysElzwAiKFFsOItXgi1WmIv1R+A6hz6qL4X1ibdGUTOfmn4wZCaSR3OgqDheGt1kuwVrHdKNS1Mv6cmMCX614QdvDiHbBr3G377CnuknX0e36esAn2HdP0QodzQXHIdUXDUJGFCtrIPuLTk8h5cbxTy6nFRKCNczylju1utwjmpnJMnI8DxI5+sPWSaldGiqlpNDoL0W3vgvzKZwwTRSvVs/cbuxJysimdeyytgb5asmxC14VC3C+vw1s3t9ExPSbZAa8SvrRA8P54x2NrO7S72oVmkodrsnuYJ+RaXziV7qeVRhq1fxPoqQaHxLKVmSFtL27M4MdyI5c0ychSmtCtN8tmdmC7H5VJjRYyDR+g2aTVyQbxdvuI/FhwWZvb/it3Ts87R03tky9zbYr4auHcDYey66yQjkeCuIN5yrp2e4KtHLaNU4fTMCCNTVLLnngyG4BH/MfaWtQmMz4hR+qYjfMr4zBFDtw7elA6+HF1t+4HWS720AhSzvHE/ygSTV+8BnANXNjJl6tQx4A2ngboT8EB1d07TR2AmocO6bKPd+BK/fRPcAetbafUWAgAX0l0VIuAgd5W4/MZzxTRgQ95d5eEuIqj4QeZET/B1Il29bfBVmzGRYtJtNymKaDp8Mg6rwu00BUdXcWWdKgYZOOf3uqEnhxguqeLUX+xnsPDOe9WayXy/U2PCgWpMDx+uKacBa0j8d9DWPh0wFr/ZBiyfR8dW0+YpgGe1gOc4P/Gls/qkci7nApLhiedvepPCRG+Y7x6WUF2R0uss/qRBwgQgarotXBKe1VKYtsrxKMyEJEpjk22iZ/0+fgWki0EkHLdkBh0P1LZ6KU219dTDEpCb47f0Hu0qjaTp8WgTXgoYMv2VKVpdOr0lifdifxNtozRgX3U6aZ28mQqoU1AM0I8c6ue0W4bR21IbywgEy4Rro03Pw3pLiNAwuEN7T1QxC8BvwREDEUC84l//iJ2aEmXIFxXao08d6BH5VEzr4TbE/S7G+8QCmSMEx5hjQIOZZ0mhQqqdAp7pr03AlE/n1QA19z5ipxNqyCaZA0aSla2nakKKEkj27YtmGOim3g/fwukUdEEvB6ZiRzuUEfxceyqdSRlRE5kjMdW2On+6w9vUa7Mll2Ro/UsP/XqyM8LvQ+xIPd/kmDVfb6awWOJceOIXn0oYSpZKMcmQb2xtknfLImrno8OzpgiGZolTwa50vN/wolabWPR+FI+VQLELzPnOjQ7XXnqxBbaZ7GMz0fAgqlIvJg9/GCP+rM13kAa7rj3xCcZ69Fl1bhcbqeLQaWqBPuQLQflqAyvK5Opom7VRxVAKm0qQ2OfRFh2ZF X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: 33b08c30-3463-4ffc-6519-08d91935084f X-MS-Exchange-CrossTenant-AuthSource: CO6PR04MB7812.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 May 2021 13:09:41.4172 (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: t2D8RI4graMwz/FyhxLdODKVIp7em+6KE3nQ0UUOzzXAOfP12Sg1Evf18g+f2K7y180Knd4KTNt3bUO5Mf3oAg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO6PR04MB7778 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org The low-level relocate() function enables mmu and relocates execution to link-time addresses. We rename relocate() function to relocate_enable_mmu() function which is more informative. Also, the relocate_enable_mmu() function will be used in the resume path when a CPU wakes-up from a non-retentive suspend so we make it global symbol. Signed-off-by: Anup Patel --- arch/riscv/kernel/head.S | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/arch/riscv/kernel/head.S b/arch/riscv/kernel/head.S index 89cc58ab52b4..a44c0bc9c2f3 100644 --- a/arch/riscv/kernel/head.S +++ b/arch/riscv/kernel/head.S @@ -79,7 +79,8 @@ pe_head_start: .align 2 #ifdef CONFIG_MMU -relocate: + .global relocate_enable_mmu +relocate_enable_mmu: /* Relocate return address */ la a1, kernel_virt_addr XIP_FIXUP_OFFSET a1 @@ -174,7 +175,7 @@ secondary_start_common: /* Enable virtual memory and relocate to virtual address */ la a0, swapper_pg_dir XIP_FIXUP_OFFSET a0 - call relocate + call relocate_enable_mmu #endif call setup_trap_vector tail smp_callin @@ -311,7 +312,7 @@ clear_bss_done: #ifdef CONFIG_MMU la a0, early_pg_dir XIP_FIXUP_OFFSET a0 - call relocate + call relocate_enable_mmu #endif /* CONFIG_MMU */ call setup_trap_vector From patchwork Mon May 17 13:08:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 12261871 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B1309C433ED for ; Mon, 17 May 2021 13:09:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 90D286128E for ; Mon, 17 May 2021 13:09:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237294AbhEQNLO (ORCPT ); Mon, 17 May 2021 09:11:14 -0400 Received: from esa2.hgst.iphmx.com ([68.232.143.124]:48853 "EHLO esa2.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234106AbhEQNLO (ORCPT ); Mon, 17 May 2021 09:11:14 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1621256999; x=1652792999; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=WRiii23Z6QzfuX16+FZ4tI7GR0aXkmDaWpjIGuDJwLM=; b=m8x+5+e7LYzMZ2l3VB0AuealuUvbCOqMa09ECquwctNb9svV3qWsSpep ree+JGC8FC+aNTsGB9fqMI4cqaGgrO7+tnENPtsTOK+Jhf0WdJ2aRDz97 WofwAolVWYLPbS7ftwtohx249PHmAv7G8C6C9XwTCpSHLSnD4iEytXoyP oJpzrdlUC6gWnOUu4J/uYLpkM3lawDlRxZaxaIQ0p2h3W5tt5UgmooLIu O9AA2paSidZaHX3YmGSqv+k/r0KxEbDlML30ree0cxiYQThxZuOuc/0rN EGpLlwSPfvI51Kc2/AwP5nErHQRDBTnkpb6UduQ8TpeJ6Evz3XUSY/L4b g==; IronPort-SDR: d1+BZb2ifKf6YE3HGZYR8sIEMEQ5+eNfeAH6S0WtbPtCEFEn0XnGvoLmWjmHvNfECzYwvpXvYE lY9ztGdVZ2q37Q84dFYGOSyso3rPfeJNIf0nOciPKZguhn99Upr+3WNkHCLVt/I8jbCijxoPC9 ZdJbF6VNlJ/+rdSRs6TnXkCdZCW/6KXTo6T7EaE/6vrv5eSO7vbXpV82WYIXldj0vVGj0k+f95 59hl9zfdiSBTAMW55YZ2818E3k3sRDva+tpundqqZ0Kr9da4v292ObP1ckCsuhr8+wbBAFKccH ghI= X-IronPort-AV: E=Sophos;i="5.82,307,1613404800"; d="scan'208";a="272394624" Received: from mail-mw2nam10lp2100.outbound.protection.outlook.com (HELO NAM10-MW2-obe.outbound.protection.outlook.com) ([104.47.55.100]) by ob1.hgst.iphmx.com with ESMTP; 17 May 2021 21:10:19 +0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bCVSHTYcikP4dH9ZhCTu2W6Y/xrZA4g4Ej23BAEmC0VOIW5NrjGIfAInnPUsryTXnGuO8RMwhbMV29E2SsznUMjiusYY4w2iPYtZDqWf0JLTt/muxqykNBH/KVrrdu78kDUWdrPqH+Rm0Y+Tu/qogDqKIFpbA9Cdp6synImWzIBdiFDn28RS8//xvRnDC8TFOCe0BHJ+YL2m5Cl8RFB7NAMcRJG4RxrqgOiOxlZ0SxK83tZY3NVQXIj4xUj560EMzjPNIT/NAbsedKHpazQhRlaVECnIbFiqLMGS9yC2er3HydYXFY+QUCo7qDqQjJ12Rm7Ue7KzDg9/J1J48gpr9A== 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-SenderADCheck; bh=lUYD4VxNiVhQdYFN5kCIwzDGeWn5RGAjIKEex8OoBz4=; b=LVnPZClGgeLXGlOHF3ec/yPfheYl3qLQk3EQfBOV8bNghYkOp5Y6Zuab82IyqVgrx2EPpAwVjw95IlQL6wNm+yID57WKBmbY9HNoyyQp8zTQqLddS3QugGbC7koGmJSoNcRDeqMQ4z6gqy/D1fG0s6fVDy/MgwHN3uEnRoB04RbMykBZnJvC3ixchGCec69Hr1zx9QK1fYogJ28MtfmmNFfI7FWY7mc4e79yfJmfwp02t5nN42o/PIF/5IH4LZ2R6FDoU4v67IPjEHFaRuGqPUZIgElBsG46mWOEWf4BCD0H2qWgFitDu6vVhG7MlhcWRhWW42rb+LFRlFqNR0Y4gA== 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=lUYD4VxNiVhQdYFN5kCIwzDGeWn5RGAjIKEex8OoBz4=; b=vxTzOSUFjtBYTWPLHJiTCQFt3zwg2okSAL6SiF4Jtjhkw6BrYKtI8TOP7IPwg5CpmExEz3qPZFcz12lxN04qSVnVXeC8Bq3HxQzaHjgpLQmmp7yewAyDnSrGyCJNRO8QkoR5grywpUsDzz6P5Z2PO2QmQ1lPStFYo1MVFI9pnNw= 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 CO6PR04MB7778.namprd04.prod.outlook.com (2603:10b6:303:13e::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4129.26; Mon, 17 May 2021 13:09:55 +0000 Received: from CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::88a0:bf18:b01d:1a50]) by CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::88a0:bf18:b01d:1a50%4]) with mapi id 15.20.4129.031; Mon, 17 May 2021 13:09:55 +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: [RFC PATCH v4 3/8] RISC-V: Add arch functions for non-retentive suspend entry/exit Date: Mon, 17 May 2021 18:38:18 +0530 Message-Id: <20210517130823.796963-4-anup.patel@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210517130823.796963-1-anup.patel@wdc.com> References: <20210517130823.796963-1-anup.patel@wdc.com> X-Originating-IP: [122.179.32.240] X-ClientProxiedBy: MA1PR0101CA0024.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:21::34) To CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from wdc.com (122.179.32.240) by MA1PR0101CA0024.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:21::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4108.25 via Frontend Transport; Mon, 17 May 2021 13:09:41 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: f7fb3298-ae22-49fd-bb35-08d91935108b X-MS-TrafficTypeDiagnostic: CO6PR04MB7778: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: WDCIPOUTBOUND: EOP-TRUE X-MS-Oob-TLC-OOBClassifiers: OLM:8273; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: L4Pe9kx5byXeBhCuQlnsbzvWZ/Y9bsnM0iSBMySGjZpxmVrWnMGEOnZOhCv3+xpoyIDFqDhgzlNxMpNZ+wccmXeeohhd3Bw5p6m6kGwsQsUsXVCIlU84Os6ma0LI/B3EurGha0kR/97AZRGkHKsR9qQ23uGORq0B0qAH8YiqLWzXU+l6Nfq8+jnlbxI6yeBzand0vCBvpyA1/vw/DXbKltbIRejRhly7nKwxLvTiEC0F8pN5Bn45gi0QLX3s5z+fP532K7SKfKlcqX7/BePnwYXbs/8lN4wTMU8yeJlHssZk97f4oVyOY4JuXPEXanKueGBEMiCqDcNXwYuNUnZrFy4/mXtkGaeQe/JzbRI7/puc+HEzBvgfwZNsTxbnCml4nK0tILE+TS77uSofx4Vn6s4XrHGnnjdLh3kH0RNa7UkYnxhFAtqpL07GNV1B95qa24G9cCJ4UYpOQe49Vy85N5Zg83ITSBa5XfUQ8TicLGIBe9WznOSBzKlne91MsHBJOtaUCiAY0lVXmf87KI7LvHyJ5GsbOhcFR6Lb5iTxltMwTqWTVSsQUlTV9rZZalQaJq57tM2jxC894IQJWEEPBxwSi8EADCOotjJ5OKLlzKIctOp8S+xGG2ILafpoAhoeb8yZ4kwO+mMH5lOL8XD4Mw== 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)(39850400004)(396003)(346002)(136003)(376002)(15650500001)(83380400001)(38100700002)(6666004)(1076003)(26005)(8886007)(66946007)(44832011)(86362001)(38350700002)(316002)(4326008)(55016002)(2616005)(956004)(30864003)(52116002)(7696005)(110136005)(54906003)(478600001)(8936002)(8676002)(186003)(7416002)(16526019)(66556008)(66476007)(2906002)(36756003)(5660300002);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData: P7HM+L3p0+bcYSSFwr3LJlgk5OopXDn8S34v3XxLpZomw+B3k4AOrz06t6NFCYse2ljDJzC+ANHcS394NnSxMK7HejU/vGWztE73aXotVIUKjR10Gkr4qSQ+fOheic8OxYL9pueD23R8RNVr4ujFyqNT+XuLd6YT2fEq5M5kBZQHDFIFv/TIMr9WqhQhMvXpngGdVY4PX1YKX9nTsxQhUNY1VQvOWuoT6Opsdt8ez/qaIcdNJ5iPF3zVdPvMwsKMrR4S1NvjUpbqep7sfOE8h7QLz+DA2k9oxzm692TPdR9d85O5GXLxeSI79KE5UKaeNWWkq42/HrpaXe/g3oyF3pRI8ycyaBCjvQAMLCVBSMcB8HX+IX/5TFcrdDs+n4WoUDrkaUezVby7FSDzP2jYRKdnoglRDSFzI5wwViK/gU+SJTc3yenUwqDpYim7GKpfH+Cy21Udm+N0B5pB8SnBlrdxsqymlBUESed0NYSMKuq4FHAZH991+L9MuYfzfZ2WM4a0u6/R1urTtH7djHLopJ8HU+P6RptgiE5dPc2NxyHB4FRUI0roTmthWgO6Njm5nxwfLacOWwWWFX5/um+z8nBF3D/vxQKFYucXNAxsHg9lXlw0aMrv7WQ+5akufp9Y1eyK6obLfLpn+qfHp9MBt5dFuXQkPW3j/c8a6kXaY9pp0hlMv3Egonq6IjcuDiSLXkykJxaLYnyV9bIz4BWGZDCYWRi2fo1h/43U1phDPdAdbTVfnNKfKay9oFnVKj3+g7HB6L9o1R3RURCksJfhWcWmbXWxLOso3EBzpxCGnPZfKjM2dWvlK+lfyspf7ijzvu/btbY3bWgFC4UEV/TUFpFguK5zH2UhsOhSEOowsaJeHMCDDD01fL6nkJqj/isEDTLyFe7Hene7iPkAT3JMWFEMrWaCtMpe3rDkORkOnoWA6YZdD3VU2Q6mqrGSoWQ0GTa/uZnHxUwqzA5cvJPG4mkT/foeeRokHO+6RBUPEtC4AKZzmpy9qD27bD/XafDgS3XZdsjTmQ2PdH58AdqE7pk3EZ1vxaJHJwAOUk49yn7+xuLjn0pcb3nuq3Hc7jugRSsaw5ukq2ihuzADdfilKXf0mkQRk+8Pv1hz5PputuNKEk4NpWyLOmNUbjN1WUUNIp0mJrs3cAILgvxWnXHGIyHJcsicNoqbOa2eNpOIGhmjK8UPhbkgYW4M8Ylnd4z0YbNXv9A1G3HcXa6bdD8gsUi8hc0Gc1BNha2+tB6dH+9hTnBQ2B7jdoRntVGgc3aQNIHgTxbMjuC5KKiHTsHVcCLLBSvsvIrhU41bWxMZtC8FG+6YPxpz/N0l4y0vCSD8 X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: f7fb3298-ae22-49fd-bb35-08d91935108b X-MS-Exchange-CrossTenant-AuthSource: CO6PR04MB7812.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 May 2021 13:09:55.2872 (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: qzL+q2bnYEHYiRNIUCfJU32nujt4PsQjOuFxCf4hhnQvpq1B1Zv1RwKCRr1uuWj+T4R9c4wD6klS6R2cL2Ob1Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO6PR04MB7778 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org The hart registers and CSRs are not preserved in non-retentative suspend state so we provide arch specific helper functions which will save/restore hart context upon entry/exit to non-retentive suspend state. These helper functions can be used by cpuidle drivers for non-retentive suspend entry/exit. Signed-off-by: Anup Patel --- arch/riscv/include/asm/asm.h | 17 +++++ arch/riscv/include/asm/suspend.h | 35 +++++++++ arch/riscv/kernel/Makefile | 2 + arch/riscv/kernel/asm-offsets.c | 3 + arch/riscv/kernel/head.S | 11 --- arch/riscv/kernel/suspend.c | 86 +++++++++++++++++++++ arch/riscv/kernel/suspend_entry.S | 123 ++++++++++++++++++++++++++++++ 7 files changed, 266 insertions(+), 11 deletions(-) create mode 100644 arch/riscv/include/asm/suspend.h create mode 100644 arch/riscv/kernel/suspend.c create mode 100644 arch/riscv/kernel/suspend_entry.S diff --git a/arch/riscv/include/asm/asm.h b/arch/riscv/include/asm/asm.h index 618d7c5af1a2..6c93f2806eb7 100644 --- a/arch/riscv/include/asm/asm.h +++ b/arch/riscv/include/asm/asm.h @@ -67,4 +67,21 @@ #error "Unexpected __SIZEOF_SHORT__" #endif +#ifdef __ASSEMBLY__ + +/* Common assembly source macros */ + +#ifdef CONFIG_XIP_KERNEL +.macro XIP_FIXUP_OFFSET reg + REG_L t0, _xip_fixup + add \reg, \reg, t0 +.endm +_xip_fixup: .dword CONFIG_PHYS_RAM_BASE - CONFIG_XIP_PHYS_ADDR - XIP_OFFSET +#else +.macro XIP_FIXUP_OFFSET reg +.endm +#endif /* CONFIG_XIP_KERNEL */ + +#endif + #endif /* _ASM_RISCV_ASM_H */ diff --git a/arch/riscv/include/asm/suspend.h b/arch/riscv/include/asm/suspend.h new file mode 100644 index 000000000000..63e9f434fb89 --- /dev/null +++ b/arch/riscv/include/asm/suspend.h @@ -0,0 +1,35 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Copyright (c) 2021 Western Digital Corporation or its affiliates. + */ + +#ifndef _ASM_RISCV_SUSPEND_H +#define _ASM_RISCV_SUSPEND_H + +#include + +struct suspend_context { + /* Saved and restored by low-level functions */ + struct pt_regs regs; + /* Saved and restored by high-level functions */ + unsigned long scratch; + unsigned long tvec; + unsigned long ie; +#ifdef CONFIG_MMU + unsigned long satp; +#endif +}; + +/* Low-level CPU suspend entry function */ +int __cpu_suspend_enter(struct suspend_context *context); + +/* High-level CPU suspend which will save context and call finish() */ +int cpu_suspend(unsigned long arg, + int (*finish)(unsigned long arg, + unsigned long entry, + unsigned long context)); + +/* Low-level CPU resume entry function */ +int __cpu_resume_enter(unsigned long hartid, unsigned long context); + +#endif diff --git a/arch/riscv/kernel/Makefile b/arch/riscv/kernel/Makefile index d3081e4d9600..5a2fc649ad11 100644 --- a/arch/riscv/kernel/Makefile +++ b/arch/riscv/kernel/Makefile @@ -47,6 +47,8 @@ obj-$(CONFIG_SMP) += cpu_ops_spinwait.o obj-$(CONFIG_MODULES) += module.o obj-$(CONFIG_MODULE_SECTIONS) += module-sections.o +obj-$(CONFIG_CPU_PM) += suspend_entry.o suspend.o + obj-$(CONFIG_FUNCTION_TRACER) += mcount.o ftrace.o obj-$(CONFIG_DYNAMIC_FTRACE) += mcount-dyn.o diff --git a/arch/riscv/kernel/asm-offsets.c b/arch/riscv/kernel/asm-offsets.c index 9ef33346853c..2628dfd0f77d 100644 --- a/arch/riscv/kernel/asm-offsets.c +++ b/arch/riscv/kernel/asm-offsets.c @@ -10,6 +10,7 @@ #include #include #include +#include void asm_offsets(void); @@ -111,6 +112,8 @@ void asm_offsets(void) OFFSET(PT_BADADDR, pt_regs, badaddr); OFFSET(PT_CAUSE, pt_regs, cause); + OFFSET(SUSPEND_CONTEXT_REGS, suspend_context, regs); + /* * THREAD_{F,X}* might be larger than a S-type offset can handle, but * these are used in performance-sensitive assembly so we can't resort diff --git a/arch/riscv/kernel/head.S b/arch/riscv/kernel/head.S index a44c0bc9c2f3..03bf2edfe9b2 100644 --- a/arch/riscv/kernel/head.S +++ b/arch/riscv/kernel/head.S @@ -15,17 +15,6 @@ #include #include "efi-header.S" -#ifdef CONFIG_XIP_KERNEL -.macro XIP_FIXUP_OFFSET reg - REG_L t0, _xip_fixup - add \reg, \reg, t0 -.endm -_xip_fixup: .dword CONFIG_PHYS_RAM_BASE - CONFIG_XIP_PHYS_ADDR - XIP_OFFSET -#else -.macro XIP_FIXUP_OFFSET reg -.endm -#endif /* CONFIG_XIP_KERNEL */ - __HEAD ENTRY(_start) /* diff --git a/arch/riscv/kernel/suspend.c b/arch/riscv/kernel/suspend.c new file mode 100644 index 000000000000..49dddec30e99 --- /dev/null +++ b/arch/riscv/kernel/suspend.c @@ -0,0 +1,86 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (c) 2021 Western Digital Corporation or its affiliates. + */ + +#include +#include +#include + +static void suspend_save_csrs(struct suspend_context *context) +{ + context->scratch = csr_read(CSR_SCRATCH); + context->tvec = csr_read(CSR_TVEC); + context->ie = csr_read(CSR_IE); + + /* + * No need to save/restore IP CSR (i.e. MIP or SIP) because: + * + * 1. For no-MMU (M-mode) kernel, the bits in MIP are set by + * external devices (such as interrupt controller, timer, etc). + * 2. For MMU (S-mode) kernel, the bits in SIP are set by + * M-mode firmware and external devices (such as interrupt + * controller, etc). + */ + +#ifdef CONFIG_MMU + context->satp = csr_read(CSR_SATP); +#endif +} + +static void suspend_restore_csrs(struct suspend_context *context) +{ + csr_write(CSR_SCRATCH, context->scratch); + csr_write(CSR_TVEC, context->tvec); + csr_write(CSR_IE, context->ie); + +#ifdef CONFIG_MMU + csr_write(CSR_SATP, context->satp); +#endif +} + +int cpu_suspend(unsigned long arg, + int (*finish)(unsigned long arg, + unsigned long entry, + unsigned long context)) +{ + int rc = 0; + struct suspend_context context = { 0 }; + + /* Finisher should be non-NULL */ + if (!finish) + return -EINVAL; + + /* Save additional CSRs*/ + suspend_save_csrs(&context); + + /* + * Function graph tracer state gets incosistent when the kernel + * calls functions that never return (aka finishers) hence disable + * graph tracing during their execution. + */ + pause_graph_tracing(); + + /* Save context on stack */ + if (__cpu_suspend_enter(&context)) { + /* Call the finisher */ + rc = finish(arg, __pa_symbol(__cpu_resume_enter), + (ulong)&context); + + /* + * Should never reach here, unless the suspend finisher + * fails. Successful cpu_suspend() should return from + * __cpu_resume_entry() + */ + if (!rc) + rc = -EOPNOTSUPP; + } + + /* Enable function graph tracer */ + unpause_graph_tracing(); + + /* Restore additional CSRs */ + suspend_restore_csrs(&context); + + return rc; +} diff --git a/arch/riscv/kernel/suspend_entry.S b/arch/riscv/kernel/suspend_entry.S new file mode 100644 index 000000000000..b8d20decfc28 --- /dev/null +++ b/arch/riscv/kernel/suspend_entry.S @@ -0,0 +1,123 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Copyright (c) 2021 Western Digital Corporation or its affiliates. + */ + +#include +#include +#include +#include + + .text + .altmacro + .option norelax + +ENTRY(__cpu_suspend_enter) + /* Save registers (except A0 and T0-T6) */ + REG_S ra, (SUSPEND_CONTEXT_REGS + PT_RA)(a0) + REG_S sp, (SUSPEND_CONTEXT_REGS + PT_SP)(a0) + REG_S gp, (SUSPEND_CONTEXT_REGS + PT_GP)(a0) + REG_S tp, (SUSPEND_CONTEXT_REGS + PT_TP)(a0) + REG_S s0, (SUSPEND_CONTEXT_REGS + PT_S0)(a0) + REG_S s1, (SUSPEND_CONTEXT_REGS + PT_S1)(a0) + REG_S a1, (SUSPEND_CONTEXT_REGS + PT_A1)(a0) + REG_S a2, (SUSPEND_CONTEXT_REGS + PT_A2)(a0) + REG_S a3, (SUSPEND_CONTEXT_REGS + PT_A3)(a0) + REG_S a4, (SUSPEND_CONTEXT_REGS + PT_A4)(a0) + REG_S a5, (SUSPEND_CONTEXT_REGS + PT_A5)(a0) + REG_S a6, (SUSPEND_CONTEXT_REGS + PT_A6)(a0) + REG_S a7, (SUSPEND_CONTEXT_REGS + PT_A7)(a0) + REG_S s2, (SUSPEND_CONTEXT_REGS + PT_S2)(a0) + REG_S s3, (SUSPEND_CONTEXT_REGS + PT_S3)(a0) + REG_S s4, (SUSPEND_CONTEXT_REGS + PT_S4)(a0) + REG_S s5, (SUSPEND_CONTEXT_REGS + PT_S5)(a0) + REG_S s6, (SUSPEND_CONTEXT_REGS + PT_S6)(a0) + REG_S s7, (SUSPEND_CONTEXT_REGS + PT_S7)(a0) + REG_S s8, (SUSPEND_CONTEXT_REGS + PT_S8)(a0) + REG_S s9, (SUSPEND_CONTEXT_REGS + PT_S9)(a0) + REG_S s10, (SUSPEND_CONTEXT_REGS + PT_S10)(a0) + REG_S s11, (SUSPEND_CONTEXT_REGS + PT_S11)(a0) + + /* Save CSRs */ + csrr t0, CSR_EPC + REG_S t0, (SUSPEND_CONTEXT_REGS + PT_EPC)(a0) + csrr t0, CSR_STATUS + REG_S t0, (SUSPEND_CONTEXT_REGS + PT_STATUS)(a0) + csrr t0, CSR_TVAL + REG_S t0, (SUSPEND_CONTEXT_REGS + PT_BADADDR)(a0) + csrr t0, CSR_CAUSE + REG_S t0, (SUSPEND_CONTEXT_REGS + PT_CAUSE)(a0) + + /* Return non-zero value */ + li a0, 1 + + /* Return to C code */ + ret +END(__cpu_suspend_enter) + +ENTRY(__cpu_resume_enter) + /* Load the global pointer */ + .option push + .option norelax + la gp, __global_pointer$ + .option pop + +#ifdef CONFIG_MMU + /* Save A0 and A1 */ + add t0, a0, zero + add t1, a1, zero + + /* Enable MMU */ + la a0, swapper_pg_dir + XIP_FIXUP_OFFSET a0 + call relocate_enable_mmu + + /* Restore A0 and A1 */ + add a0, t0, zero + add a1, t1, zero +#endif + + /* Make A0 point to suspend context */ + add a0, a1, zero + + /* Restore CSRs */ + REG_L t0, (SUSPEND_CONTEXT_REGS + PT_EPC)(a0) + csrw CSR_EPC, t0 + REG_L t0, (SUSPEND_CONTEXT_REGS + PT_STATUS)(a0) + csrw CSR_STATUS, t0 + REG_L t0, (SUSPEND_CONTEXT_REGS + PT_BADADDR)(a0) + csrw CSR_TVAL, t0 + REG_L t0, (SUSPEND_CONTEXT_REGS + PT_CAUSE)(a0) + csrw CSR_CAUSE, t0 + + /* Restore registers (except A0 and T0-T6) */ + REG_L ra, (SUSPEND_CONTEXT_REGS + PT_RA)(a0) + REG_L sp, (SUSPEND_CONTEXT_REGS + PT_SP)(a0) + REG_L gp, (SUSPEND_CONTEXT_REGS + PT_GP)(a0) + REG_L tp, (SUSPEND_CONTEXT_REGS + PT_TP)(a0) + REG_L s0, (SUSPEND_CONTEXT_REGS + PT_S0)(a0) + REG_L s1, (SUSPEND_CONTEXT_REGS + PT_S1)(a0) + REG_L a1, (SUSPEND_CONTEXT_REGS + PT_A1)(a0) + REG_L a2, (SUSPEND_CONTEXT_REGS + PT_A2)(a0) + REG_L a3, (SUSPEND_CONTEXT_REGS + PT_A3)(a0) + REG_L a4, (SUSPEND_CONTEXT_REGS + PT_A4)(a0) + REG_L a5, (SUSPEND_CONTEXT_REGS + PT_A5)(a0) + REG_L a6, (SUSPEND_CONTEXT_REGS + PT_A6)(a0) + REG_L a7, (SUSPEND_CONTEXT_REGS + PT_A7)(a0) + REG_L s2, (SUSPEND_CONTEXT_REGS + PT_S2)(a0) + REG_L s3, (SUSPEND_CONTEXT_REGS + PT_S3)(a0) + REG_L s4, (SUSPEND_CONTEXT_REGS + PT_S4)(a0) + REG_L s5, (SUSPEND_CONTEXT_REGS + PT_S5)(a0) + REG_L s6, (SUSPEND_CONTEXT_REGS + PT_S6)(a0) + REG_L s7, (SUSPEND_CONTEXT_REGS + PT_S7)(a0) + REG_L s8, (SUSPEND_CONTEXT_REGS + PT_S8)(a0) + REG_L s9, (SUSPEND_CONTEXT_REGS + PT_S9)(a0) + REG_L s10, (SUSPEND_CONTEXT_REGS + PT_S10)(a0) + REG_L s11, (SUSPEND_CONTEXT_REGS + PT_S11)(a0) + + /* Return zero value */ + add a0, zero, zero + + /* Return to C code */ + ret +END(__cpu_resume_enter) From patchwork Mon May 17 13:08:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 12261873 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2A799C433B4 for ; Mon, 17 May 2021 13:10:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 08D7361028 for ; Mon, 17 May 2021 13:10:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237284AbhEQNL6 (ORCPT ); Mon, 17 May 2021 09:11:58 -0400 Received: from esa2.hgst.iphmx.com ([68.232.143.124]:48887 "EHLO esa2.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237311AbhEQNLn (ORCPT ); Mon, 17 May 2021 09:11:43 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1621257043; x=1652793043; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=UeD+FgLO9aIjFzdKrHDcrkqDgbjr4ljOtP7t6+n6Irg=; b=KGfkhf68coXF4kratIzmDS87TMTnldCm9w2+CrtMmn29dVcUB894L3Ss M1JoO+RqO724nsJtI39ULLLbT/z2E2Z8dU8uwEk1vtcwnCaCT0kZ7VoOi 2g8a+u5uaom15if95IevinFfPT/eCN2ooVzL2k5pMjbZH8jQWf2fxksZR 1JcUISZCi/0BbuxoSIVfBoS1EODHWxab479xLppGFOQuxe3VKDbGyhNjn 3/PVHZ97jzr9HXcC61D/VNVvvxmBsN8bsPT5j+IwMGOCI8Pi/GKLnWUXz xa/t45GlF1I1roXuB61Wfv2ZukiZy+Zt6Tb6s1wPZdWsnd4rhHRsRFw7B g==; IronPort-SDR: ytVehe1d4/oFE8OOQKKrFzAxWvwXCBaYrJ4NVbct7Y+X/BbZ7YJJXdLHxiWsuNfGkgnF0nnBzx 1i7iMFpHp/s/1oNOrIhXzlaRHXbwMm9NpcS17CwIGi8BJ3kC0jDfZzNeBBViJE0nDIzkhs4Yb7 JPQVoWBJYmuo9fcPEtrz+tjal/7YOyPGQuMuGdSrwb4qqq6ePZQaP628RygUtZYsW1JTduNGeJ 6GcZg5AV4qYPrbsYRoNcvxmTa/VROA/zKudd6gQd0VVCIYP6lMNld0RiXhsLblMN6KWeNpIjvc Bi4= X-IronPort-AV: E=Sophos;i="5.82,307,1613404800"; d="scan'208";a="272394640" Received: from mail-mw2nam10lp2102.outbound.protection.outlook.com (HELO NAM10-MW2-obe.outbound.protection.outlook.com) ([104.47.55.102]) by ob1.hgst.iphmx.com with ESMTP; 17 May 2021 21:10:19 +0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VO3duxMRIXAvKINVN58UEUWGTopFoc90pyHWAVzPqRra29BBc6aZUnaGx+Lc1at+cWtqZFzOe7benq5yXw+jX/RoFqqy0Hzfei2m2Z7Mnz5T8A4+1/5hTMR9lsx5SAmE8E6SjEUqr8VlgUbFUIchmDb3tfkjdNI46EIL+LQV/1t9ojjgMDATao5zDmiza0cHFjvc5+AaY9jyZDE15j/bP+fCzlI2e3xZuVAyqMDqGq/cy96TbW4QytyCm1Q9lzo6znRvMbyaRUm8S6YlOujOan1ueWrZKumTlE0S119psB4kkUrZ1bpI5Dn6samWAXw6aCPig93sSJcBzu6rkI5GOA== 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-SenderADCheck; bh=4QXaNsRGTyDgz2Sn7I2zPdXMtXIGlsEhVecpbL/TqiQ=; b=bbI2vMjqTfvNxkKODAnArt0RepgwbDRA7M1hubQqPsIXeKuckFh8C9CU1cRaub+ELDpmqpb7GlVoaikOSfRIKsD/ychOa8/2tE9FwMq3cFfkf0MurN8RW1deLBUCufiIULw57WJiFXjmO8dkOARSxKZitr512eDEamnPxSp1S+Wsu7ItyIGF+kddCxF25rUGAtLASN0cYSSHvCnFLQh4NSHEKuwjpaTQIG0vg65czrR6411pTODMTv/MExiqVgGz1cC0+mbKKCM9O08ZYXIYJB6ibAa4odFvy6B5SExPUnBaOExq/+n8e9hdeYtBNv3w8cxKj99OjIm8G+uAp8Cz0w== 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=4QXaNsRGTyDgz2Sn7I2zPdXMtXIGlsEhVecpbL/TqiQ=; b=NF/oqX7PiF50qAZGACG8i7aCPo1FMeX0GDeZ/yj/MI7bCQnKOl28JBqbfKblbyVMHAo86YZxhf8PQ0hC//YMDImK2b7oqiwo54nAdVqz8mMOe9Wqr/eQXknBpAk2ONOCC95HjWLkPOIy9H9CyHTxkvkMI8/yJOTwJMTGcc1ZQNE= 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 CO6PR04MB7778.namprd04.prod.outlook.com (2603:10b6:303:13e::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4129.26; Mon, 17 May 2021 13:10:09 +0000 Received: from CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::88a0:bf18:b01d:1a50]) by CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::88a0:bf18:b01d:1a50%4]) with mapi id 15.20.4129.031; Mon, 17 May 2021 13:10:09 +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: [RFC PATCH v4 4/8] RISC-V: Add SBI HSM suspend related defines Date: Mon, 17 May 2021 18:38:19 +0530 Message-Id: <20210517130823.796963-5-anup.patel@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210517130823.796963-1-anup.patel@wdc.com> References: <20210517130823.796963-1-anup.patel@wdc.com> X-Originating-IP: [122.179.32.240] X-ClientProxiedBy: MA1PR0101CA0024.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:21::34) To CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from wdc.com (122.179.32.240) by MA1PR0101CA0024.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:21::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4108.25 via Frontend Transport; Mon, 17 May 2021 13:09:56 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 15823ea9-349b-4d6f-cfe4-08d919351912 X-MS-TrafficTypeDiagnostic: CO6PR04MB7778: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: WDCIPOUTBOUND: EOP-TRUE X-MS-Oob-TLC-OOBClassifiers: OLM:220; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: EYc76wK8qhpqGTrcKR9+vck86bB2eGOnEtx3lYN06bu9i3mQBzQvMza6zOk9iDGZQcpn9m+Zn6PdemKQduO7Y9Cr3YGg/Qtn+oK7s/H3YM85LXW1X8GZrVN0A3WM+DXYBQa8+goVahfuuCHU20VA92DGSUVm4d/9qKOU6f3Xqnm/4pQ2Ehfm+uSchcn4ezvQGCfdo2+MP4LG38IoGoQqJrPWn0KgiDIL9ucRmT9296JjSVXwTgIFG/9J+mO7n+qa7P9VDAt1XGFjW5PrKHjA94a7jmb8M1XBfUFqEnm/Rnt30XRRkaAXKRcafpCxlb16zS+MIuzdI2qKn3lj11ucSWipHvyLZS4I6h6qBH32+Ok7CaajtTOD1ZFqFliLyqLjK9+Z4eooKz/yxmQzV2Rlpa6QLEzULyH+xG40tWML4qqJqf7O0toZ/cpjHAsC1wQRSw270aDAm1M0ifly3ZSlCGKa79trO3MzVtlV78eJXySiqSo+B9SLugq1FzkEW7CSLJzA/H1rllNHShpsyJ4moa2WawbnccLtol2AcZtdkiybtRPDCYlThUcDnExh4RUQDS3I7dRXo50OQyTV1k64tavNRbSx8RyIIBbcVtzidYoWrgJczoomMSgNikveD94FBSLQsce6WYoSGX0kCKWg3gLV9MIgBLdSQjK+0UTfReI= 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)(39850400004)(396003)(346002)(136003)(376002)(15650500001)(83380400001)(38100700002)(6666004)(1076003)(26005)(8886007)(66946007)(44832011)(86362001)(38350700002)(316002)(4326008)(55016002)(2616005)(956004)(52116002)(7696005)(110136005)(54906003)(478600001)(8936002)(8676002)(186003)(7416002)(16526019)(66556008)(66476007)(2906002)(36756003)(5660300002);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData: vQi3HD2upGpq3QD46dNSvOAvJTdenCxKtH2IxtoWlbnPU2/tyZMGiu6e+sKMldsO2H5O2j5XQTNzRTo/qLCpDf7FZ8gCKEF2lxZguT5RUbLlOdH/6tddwIPUYQh/w98dyrhUGuRp54RvkDpSH8UY8uN/neX4n9O2an5sMiLTELrgG+dqQ8w28leEqloBJGVp0JEl+5v7zn3BvjeGxoM54W65GvPDlE7LFmDCLM7nbu3GkEWuMnpd9rCP88ztUPPkMM+GipoxehnUISz3Rq7g+QQeCr/oDoYrNYWNHvajmeVxJcP2I36Y25Ifr2lPzh0OYOsrApuMWU3z6utPhEPWxpN1xnPImLesQN93idgZA01ARES4UkIpzF+1yca+BwOXIOGIav+PKb/RVXdp7a9w1GDLJiKHrJB+cT8+qnWA8cELDITlBb56aycX2fjaSorPXvaKWC4FY7ZK+PnG4LhPfSxRNZ2G3T4qrYuwHtRBLbgdMNCpDuRseF/Ahqr6+5W0xy5XgSeQXLg4OZUdMhiwhygC7c7pfcn3y95TUP1WRx3hfZ1ClDboCiJCBy66d2DkYuoqx7X1zj5CUMnbZLrlYSin3dredBcAaESsaEwPjkJrjVRAW6hJPPYIO6ORZ3ntSibPIi3YhzGgJnqx76awmt4/39dlcp6gDl9GXOD/J+qILhbQqwWnY2zAkyEBfeBiRPczI7fcOejvEkAdduis5jgud9W4YEVZIV0xzofPfWgzLH6sD8IuEmnM4pptye/8Toj1NQSQGrV7rL/gK+5+dShb8gIMn9ofFp6EEr283ajZENPCqOoTx3T5XsmemBn7Y4RWOrp87t0luPSgl8RiALx4qUoSfLLJXZsK0NWTArBYVZeXw3TgKDe/2IhQfvC1UkSzl2wNWM5QeTarQMtLs16UbFbI6bygIi9zKkmcbb+w4+ZbMe7c45ThOP1orUjJfOnQk8FTLkhvbjnGKqmeIjiai1lcsiv83GugmSUfGvMPmi+G3dwJul5P2qUDEl6BGwincNZh4V/47rFOdwUZq7JlfB0u+vsQrtWGrUwBhAcz0Cenp17vcDgbeflFVUwYMMt+L9Hg/Wi3oWUmpQd2sUW4SiZLiUCyPaqKM5I1w5qzr0NaVF6d4VCq6hGTW+EO5Qy6w+i5jVByxem4ALDcU4/NAXvTghR1tlM/YnmqqcY+DFrUHT1pXYqfYxDwLH6l6jl83WJyg9fJOCYv/JgkmFC5756/VfKgG7L6l6fEfnaIupWFbxcTdCydbeICUkZSB91P0qkujLborMttN9Yui3kz7SU+AtojrRjvwRksX66WxuTSnEs8UCVS+4czBtAR X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: 15823ea9-349b-4d6f-cfe4-08d919351912 X-MS-Exchange-CrossTenant-AuthSource: CO6PR04MB7812.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 May 2021 13:10:09.6968 (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: 0ZDKPJENpOkLrmtkzkJlbStDlIee4J19QwU320vSKemfqchtxBmQQbFtVmtOTpO/Gwq3LkQ/9USfHpoNN9XgBA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO6PR04MB7778 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org We add defines related to SBI HSM suspend call and also update HSM states naming as-per latest SBI specification. Signed-off-by: Anup Patel --- arch/riscv/include/asm/sbi.h | 27 ++++++++++++++++++++++----- arch/riscv/kernel/cpu_ops_sbi.c | 2 +- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/arch/riscv/include/asm/sbi.h b/arch/riscv/include/asm/sbi.h index 289621da4a2a..ab9782f8da52 100644 --- a/arch/riscv/include/asm/sbi.h +++ b/arch/riscv/include/asm/sbi.h @@ -62,15 +62,32 @@ enum sbi_ext_hsm_fid { SBI_EXT_HSM_HART_START = 0, SBI_EXT_HSM_HART_STOP, SBI_EXT_HSM_HART_STATUS, + SBI_EXT_HSM_HART_SUSPEND, }; -enum sbi_hsm_hart_status { - SBI_HSM_HART_STATUS_STARTED = 0, - SBI_HSM_HART_STATUS_STOPPED, - SBI_HSM_HART_STATUS_START_PENDING, - SBI_HSM_HART_STATUS_STOP_PENDING, +enum sbi_hsm_hart_state { + SBI_HSM_STATE_STARTED = 0, + SBI_HSM_STATE_STOPPED, + SBI_HSM_STATE_START_PENDING, + SBI_HSM_STATE_STOP_PENDING, + SBI_HSM_STATE_SUSPENDED, + SBI_HSM_STATE_SUSPEND_PENDING, + SBI_HSM_STATE_RESUME_PENDING, }; +#define SBI_HSM_SUSP_BASE_MASK 0x7fffffff +#define SBI_HSM_SUSP_NON_RET_BIT 0x80000000 +#define SBI_HSM_SUSP_PLAT_BASE 0x10000000 + +#define SBI_HSM_SUSPEND_RET_DEFAULT 0x00000000 +#define SBI_HSM_SUSPEND_RET_PLATFORM SBI_HSM_SUSP_PLAT_BASE +#define SBI_HSM_SUSPEND_RET_LAST SBI_HSM_SUSP_BASE_MASK +#define SBI_HSM_SUSPEND_NON_RET_DEFAULT SBI_HSM_SUSP_NON_RET_BIT +#define SBI_HSM_SUSPEND_NON_RET_PLATFORM (SBI_HSM_SUSP_NON_RET_BIT | \ + SBI_HSM_SUSP_PLAT_BASE) +#define SBI_HSM_SUSPEND_NON_RET_LAST (SBI_HSM_SUSP_NON_RET_BIT | \ + SBI_HSM_SUSP_BASE_MASK) + enum sbi_ext_srst_fid { SBI_EXT_SRST_RESET = 0, }; diff --git a/arch/riscv/kernel/cpu_ops_sbi.c b/arch/riscv/kernel/cpu_ops_sbi.c index 685fae72b7f5..5fd90f03a3e9 100644 --- a/arch/riscv/kernel/cpu_ops_sbi.c +++ b/arch/riscv/kernel/cpu_ops_sbi.c @@ -97,7 +97,7 @@ static int sbi_cpu_is_stopped(unsigned int cpuid) rc = sbi_hsm_hart_get_status(hartid); - if (rc == SBI_HSM_HART_STATUS_STOPPED) + if (rc == SBI_HSM_STATE_STOPPED) return 0; return rc; } From patchwork Mon May 17 13:08:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 12261875 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E2918C43461 for ; Mon, 17 May 2021 13:10:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C72EA61042 for ; Mon, 17 May 2021 13:10:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237301AbhEQNL6 (ORCPT ); Mon, 17 May 2021 09:11:58 -0400 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:59496 "EHLO esa4.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237312AbhEQNLn (ORCPT ); Mon, 17 May 2021 09:11:43 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1621257026; x=1652793026; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=W26lc1r24KGvt1ZTmzzesXIwYHpMFrJ3fW7dDbzK/fI=; b=HoOfIee7kK1AwKMr1YIPYA4hU41FSAOBqriru1FFEjGa8q7oTHiuAXy2 YVl6n5QSkqkwop+eGksX+qd9gep6o0EaTjfjVNcWxj4qZG4h/0/1o0wYu ZBa2RECwejl5uAiBCFKoSS+E7H23kTAr7AELmSvJLFsGuMxcwEgws1sdh rXi4B3nPkCWupWkFAYucKqCIoBwZ8XNHX+U1s9bzI38GhifxUWdcJpJQC 5ztEQwIcGQLUCNtyRYv4MtiojXwyxgPUGr1Li1SXfpDbMt1IgvNcnemXw dWVfv+69fooO4EyZ/b4GhSu6i9MwKvAoLIudLFcBOAu7jy8dhRApadOsq Q==; IronPort-SDR: nBawk/WxO2f9zEZk4IWdYXA3+84YyowJatLZXqEnA7S+UUN6DJfdWpEQVtvQaA9x67TRUwX+aL WU/lKSxNh3hqdOQPGVEYSGNbw0hkRWkX6RKOBOvv0lLVV1MzTkek9Ab1CwAybxSrBcR5ksoHyX FB5vVvK8JT+3rJe76RLgyWFc7n3Wg3vUttYrlyBThZPP8qeRB02aWt0UvBjOTPsR+uIUQaHieV ucaB0PaQ+R6inkpfWl0qaN0zbHz93z/2+2H2+OaHowhFl+50/LzT54TMTYq1kyz2iL6chBOkHU DlM= X-IronPort-AV: E=Sophos;i="5.82,307,1613404800"; d="scan'208";a="167757222" Received: from mail-mw2nam10lp2104.outbound.protection.outlook.com (HELO NAM10-MW2-obe.outbound.protection.outlook.com) ([104.47.55.104]) by ob1.hgst.iphmx.com with ESMTP; 17 May 2021 21:10:25 +0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QqvWaSdoT/g3PO7Dr4DF1xd0/JhuoJZDXgC+pqNLvcbTH0+3HXi+pw6ERuUlEgYG0C0a/SOxugv5pFqRy9IulF1Yf/Hfspl62gj8XmQHek0dUvqIxez43gzd/zOAlKOIEGm48EHFmu5BdXz95L5HwetNFOBFg4QaXsjIayZgsWiH+d8SbSXen7ZwE3R96iK2nrNI5oGfOxtS26tvH+PO8nZox9Hefj9n8GvU5aiZf1aXLRlF5TbyHKbEeC7RmVscfHUa/JeUsoorQVJa9oRZIsMzSfEYHsIwXGd1DEoA65T1iPf8rCwBRVs2a781DaJBpZ7u0ATltO6CeESTH8sP1A== 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-SenderADCheck; bh=cZtmHLhpl09igiCVrvzyfQ1S3z/ZYdkoZsbRroVkSE0=; b=BghN5FV5NwfUhxry1cNDPgGGK0EOYJKWFkGKJUVo5fYsCBN+/DYAmbz2c2syF927/93MXQlAr6vVlK+qCawX5jIJYYAl6VKRyUwPIbYl0rE3Fv97ditJeTjmY9l7a8hZlyfhfd7RlCLE1r3ArlsyDH1RDH2u0oHNYOpn64Q3Z2mjSbOEraLs/tmEHiYD/rzmeTl8uG/Y0vJmGkLKtpEbsT1DRMP0Sja+BfEufpwZhsfQCftiTOwKuJtjfb7GLugXxPFGxsjOQEremvqrU1p1JsAz9+IE56uP+HB8qC3fqWcXNEjEp0HJkb7RaSFfLQoO00b4PVPGQtvAwNBuHFTJ2Q== 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=cZtmHLhpl09igiCVrvzyfQ1S3z/ZYdkoZsbRroVkSE0=; b=Dtcqv6OJ9Ams0WIdFsxYeLcaHnFAZfAUTbqBjA8AHHMBWaY/1x4DNo+eXwfmWQ4BrfkImi9fx0pzHrJWqEw5dN+9ZtBjPsvCCMrnX9oCaCbjgxL3yORs5a38GFQUMoCrVFsRhTRE54RhI+DZjcK8qX6KFeajL/vIJ4NcUeGmGF8= 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 CO6PR04MB7778.namprd04.prod.outlook.com (2603:10b6:303:13e::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4129.26; Mon, 17 May 2021 13:10:24 +0000 Received: from CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::88a0:bf18:b01d:1a50]) by CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::88a0:bf18:b01d:1a50%4]) with mapi id 15.20.4129.031; Mon, 17 May 2021 13:10:24 +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: [RFC PATCH v4 5/8] cpuidle: Factor-out power domain related code from PSCI domain driver Date: Mon, 17 May 2021 18:38:20 +0530 Message-Id: <20210517130823.796963-6-anup.patel@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210517130823.796963-1-anup.patel@wdc.com> References: <20210517130823.796963-1-anup.patel@wdc.com> X-Originating-IP: [122.179.32.240] X-ClientProxiedBy: MA1PR0101CA0024.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:21::34) To CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from wdc.com (122.179.32.240) by MA1PR0101CA0024.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:21::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4108.25 via Frontend Transport; Mon, 17 May 2021 13:10:10 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 54fb0717-def2-4192-60fb-08d9193521bc X-MS-TrafficTypeDiagnostic: CO6PR04MB7778: 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-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: rT2aI2uSQvTL9m2aPiZRGS7+Wp3bJ9BRbZTliUPK5IHP12ets91CKSVCxbIJYJSbptcnEpMF8rduWxoCJvcv0KrGDPZiYQBA0G7VmaPk+fVyQAX2SGkG0Bn7e6BzcL8cWiNoaMJG/b+OWrKG+ze681JIParA6h6Z8iM56hlGxc+ExfWnH4lkArRfAgSLOpdLBN4pU2aIO/nks3oXUaxPWfiAu1LkRbzyfUxc/LRm5Z27WVFTZ4p3nk+9IZnrFKJfqaoPI3mWv4ypdMvh26cGo+Rwrtzu3Ebm9AavFbykmdvF2tXyzT+KXtviePnNACXW41qBL0LjXh/VUChVAHSPuJ48PgePAS+svPA97msOZs06MdTNfK268R4onrKTJIP9T38Q2dG0D0d4Fwa7mw540gU33t85aVK8Co819R2/FlcxrL0CrLrzbscYpzU63mhDq27w8jBxyyqfMM2fDexamx5s0p7XeDw8UPr/bBAEG60QA1hV7hXdxSyVWZb6GiheBRRhWVlmnJjZsm0kzwqkG8uE8aInA8Ng5l7lpbzg7FCgUcoI/9WhvgspJyq6RipR7XXD/RAVKQMfH3devx6U/QXABW2SjkDDw0y4x4r6kFIJSxrhf7CSg71Xpu2Hd9UftNmx/JMv1821U8gZ8LCVzEN1EOIxnHN05oxX2TiAtRA= 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)(39850400004)(396003)(346002)(136003)(376002)(83380400001)(38100700002)(6666004)(1076003)(26005)(8886007)(66946007)(44832011)(86362001)(38350700002)(316002)(4326008)(55016002)(2616005)(956004)(30864003)(52116002)(7696005)(110136005)(54906003)(478600001)(8936002)(8676002)(186003)(7416002)(16526019)(66556008)(66476007)(2906002)(36756003)(5660300002);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData: XSYd2XTFW6IItss7keK6ZpkMquXMOP2oExsMz4YJOtcPSzlup/PBymzukMtYU2pSYbZo2/CYJm+VO+XpcpuAPI8oaNZwFrRMSoV5w7VUSO+BqIL1Qw/TOjddphy5LV9090m8O2AH1K3nZ0eial5uiSlbMGV8ZSNjeijCfXNlj70fUQQSVcvSgkobRHpzYkQQdiCddVK7+9fl4jLEilOcD2h8tIOaCNhEXYUEuKu518g0V0vYGPg+bFtkfY5CVjTks9Yye93vsR/Vaz7k7qwFs+cY7TJ5bOzbmjSYHgdK4h/SNLQmB1oGPmMhqroCJ1qFI2+jlckjhIRFZNqHVSNL2WOMy7bI6cx0nqJDuNJTQRcRDq1aOTaXlvPU+kVIQ67Yo+VZ+qyTWX6MGx22z88XuzKNqgZPY8zp9nYwLPK7CDYBc9N69hnypRDc3nKnaudBcQ8E01uwVGHGcfHlFfMqDO9x6wJ4qWHHAbyDCdvuyi2s6BFLnyv0UMQ/Ikm5SWcNhVrBa5OQbuzFVQOIXL3oNfkj493eESqcPyVqCfcevUeXRGDLnK4nWmQGXqKObENtGl0oDCgyE23WKg4l22wrsIksBnV7GxembO91Eb9sqsoy2woggrCtdX5sDjJTU3CyyWofmp26kqLCPOuj3B7ULhkRH+hTdJURftVRJs9En5y2YwUtSl7dH732+a6xqiBf/qf5J1U9eYzStAGYlj/MdywDGAgmTRWdSh3aRqfFwFdni12+H4sO5DCiWoXPq4CrSStnAa9808kVM78Z1wuRKyiPZAlmBRNJUdFUiQa7OEzndpBNDdRFZwgWjLCrTbICw3eVmJ9giaK46vhVKlFpSzEN6VaNvTaYqlLNL2SHHsqhXwkG/O8r+67SAQiuRpaFOfXOtQzwH/dJzJJj7M+dka0rJtdsx+TpnS/qYFH87OhhBekSfz0MV7GzaPXW5ZcRUn+wvJijfu1pDeeH6EDLuEW5rykPL5heBHkaUkN54K7fqju7XPF1/sNcmQvBcwYAy/tlNn65n+KlXj+TA7zLqbhqsXnRGzT8EfbA9tANjAWTqkYuX172ufWIwX+V+BbmmY8mz/uBq7SJRgqZo5Cepajw37/AibUgXBSTrfCnEPwlXaxLHTvSz+OnoHMttr7S/whT2A+UIb6kWcpAzONn9uCZaOatAsz8q4f5k4l6Qjk8/i65WDZuT9TNtE2eyfrLj7jGNcR0w9+1hKfd+fZB4CZxzCeqvjWTaj0Dm0IFJHiZC7ZD9hDPLx1vJ+Eurh2zAgoIVO2XNJUKHYUy+7A3Okoit2YZvD9cqaeFXGIatAwt7NqFf5rX4bsTHyB69WPx X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: 54fb0717-def2-4192-60fb-08d9193521bc X-MS-Exchange-CrossTenant-AuthSource: CO6PR04MB7812.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 May 2021 13:10:24.2229 (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: /yw60oVDPv+Zq9LvbFC3kYSf8nwOqEbXzrz0aq/ZAJhS9S3uGVIr8Uw902hoc0fv4czLhNmAesBrnuiJdTibHw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO6PR04MB7778 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.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 --- 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 | 182 ++++++++++++++++++++++++++ drivers/cpuidle/dt_idle_genpd.h | 50 +++++++ 7 files changed, 256 insertions(+), 135 deletions(-) create mode 100644 drivers/cpuidle/dt_idle_genpd.c create mode 100644 drivers/cpuidle/dt_idle_genpd.h 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..3ceec0ee9f02 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_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_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_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..70de1e3c00af 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_genpd_attach_cpu(cpu, "psci"); +} + +static inline void psci_dt_detach_cpu(struct device *dev) +{ + dt_idle_genpd_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..5a901773db60 --- /dev/null +++ b/drivers/cpuidle/dt_idle_genpd.c @@ -0,0 +1,182 @@ +// 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 dt_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 dt_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 = dt_pd_parse_state_nodes(parse_state, *states, *state_count); + if (ret) + kfree(*states); + + return ret; +} + +static void dt_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_pd_free(struct generic_pm_domain *pd) +{ + dt_pd_free_states(pd->states, pd->state_count); + kfree(pd->name); + kfree(pd); +} +EXPORT_SYMBOL_GPL(dt_pd_free); + +struct generic_pm_domain *dt_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 = dt_pd_parse_states(np, parse_state, &states, &state_count); + if (ret) + goto free_name; + + pd->free_states = dt_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; +} +EXPORT_SYMBOL_GPL(dt_pd_alloc); + +int dt_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; +} +EXPORT_SYMBOL_GPL(dt_pd_init_topology); + +struct device *dt_idle_genpd_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; +} +EXPORT_SYMBOL_GPL(dt_idle_genpd_attach_cpu); + +void dt_idle_genpd_detach_cpu(struct device *dev) +{ + if (IS_ERR_OR_NULL(dev)) + return; + + dev_pm_domain_detach(dev, false); +} +EXPORT_SYMBOL_GPL(dt_idle_genpd_detach_cpu); diff --git a/drivers/cpuidle/dt_idle_genpd.h b/drivers/cpuidle/dt_idle_genpd.h new file mode 100644 index 000000000000..23ebf6050e74 --- /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_pd_free(struct generic_pm_domain *pd); + +struct generic_pm_domain *dt_pd_alloc(struct device_node *np, + int (*parse_state)(struct device_node *, u32 *)); + +int dt_pd_init_topology(struct device_node *np); + +struct device *dt_idle_genpd_attach_cpu(int cpu, const char *name); + +void dt_idle_genpd_detach_cpu(struct device *dev); + +#else + +static inline void dt_pd_free(struct generic_pm_domain *pd) +{ +} + +static inline struct generic_pm_domain *dt_pd_alloc(struct device_node *np, + int (*parse_state)(struct device_node *, u32 *)); +{ + return NULL; +} + +static inline int dt_pd_init_topology(struct device_node *np) +{ + return 0; +} + +static inline struct device *dt_idle_genpd_attach_cpu(int cpu, + const char *name) +{ + return NULL; +} + +static inline void dt_idle_genpd_detach_cpu(struct device *dev) +{ +} + +#endif + +#endif From patchwork Mon May 17 13:08:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 12261877 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.9 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE,SPF_PASS, UNWANTED_LANGUAGE_BODY,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6638BC433ED for ; Mon, 17 May 2021 13:10:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4821361261 for ; Mon, 17 May 2021 13:10:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235408AbhEQNME (ORCPT ); Mon, 17 May 2021 09:12:04 -0400 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:59496 "EHLO esa4.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235293AbhEQNMB (ORCPT ); Mon, 17 May 2021 09:12:01 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1621257044; x=1652793044; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=gPZJhOjUvbrcJwOiMQnb2VVblc5tAEMDfAAPGyjuTPM=; b=co+Ux0Z5d9lyfoOHpWaTTBtTPp752o9D9OBcrCE6Xe3NuTfIr7xuI8TJ kYeHRBbqWzfKK1BAA7njzF7KA6SIoX9KISen5WZ5R5s/Zv2rBP00EfKja QPCzOrPf9NWQWVhvAzb9Q66D0/UkqiOmil6ZfMhj1ufFuvpTBWwLq7JxE cdjPFAN+KPr5qUaA+L8C4CSO5q9XQnL904V+T2m9DXTF5sjB8E5/EYvZU Mil1/+iAQ2P5yVemcSaLU5QjtzZYgx2gU9KTZpwENb97I35giCEU0UlM8 Nv0SxIU0ei3X0JQyBq+6v/5WSkAviE59pg8xXwUGTRDk92c4FAX3kdqEu A==; IronPort-SDR: /12HMSUKC5BO3hcAYr8CsfmRywlhfNQ1EZocZgiz4rzmpLfPnbZ2MPux+qN0fN6ouEsj6UD8Kz n+z/+9shF9npcMVR1MQZtRfOq75Cl1ISKaPd4LYVpw0+rKKI2s3rTq1mYf5MXyh5uADlIbdVWX nGBtf8f86s32qxh7/5V0SmSkuZa40MehNtK2EH4xuT4+Y+HQ1E7gb4e9r7XGOmmv2g6z5vX8Gx OBpOKa88zFr94xNHrv4TxpopLIxRlymsucwJF8X2IWJNrZyf86/xXvYwe/WW55bbZlqS6XtsFB bqE= X-IronPort-AV: E=Sophos;i="5.82,307,1613404800"; d="scan'208";a="167757245" Received: from mail-mw2nam10lp2102.outbound.protection.outlook.com (HELO NAM10-MW2-obe.outbound.protection.outlook.com) ([104.47.55.102]) by ob1.hgst.iphmx.com with ESMTP; 17 May 2021 21:10:43 +0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QijHB/YKGW5AswUqE+Q9ay1JvGTwl0MTwIzryRXm+2NZgu9ZBVwm4vQJ7NGjve+Ckd+V0mpC028uIkOe7T9+st7fwOrdkP4SQySkv8B0ETuIubMb1hrjdDpCaP30YGxFJBSHwmPZXa2MGjRz40qYjm9hDJgCpik8Dc8xgiFD2mdoNMj38ZvmgJBmPOFDXanuqr1OdBwe6xNYGQmGj8oUUypYFAy8HBRDurKBJAW4OgnsOIEHWfrlLkVj9LKfN6o+IiWFhiiwDs2RyoZaVSbCgVssopdkDsA3f9gDZt/3UOhJg2WOOv5UeqDzjyCC9no4uXidwMeNkh7dMfSkHGWcCg== 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-SenderADCheck; bh=5i5B4iAWmgJhrJL3e642CMnic7+KUJMeQqeV4tzXi8w=; b=YgeJpgtcaRYa5BUfw2YOL46DTAoGvGaimALViQ/kQuuFiBD1vaC2NPd0od4yYkorUAmH81ALoA6cUVvMdPdb8T6rZlmGM/2dvb+u0wcoyMa/UTn1P7ClGVRwAP7wiYHfhBigKJ/ePw03os/yZ5FHwXj5KVHy8AAVHdQfzJL52KXs93Fh/qot+m7bvsMlUoWfh/QfzX9Ri4vCzM+F+GSxRkj/CPytpPPYrwjz05NUeCiIn7nfhRyMJvfByKupRCYTPD+fW/gMoy39n7joRFYFOdSJLZwbKbbSq2FOWT/YENcs7/aj4M8s2crpY5u65+N75ve+ZXZtm+0AriOKQ0F20w== 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=5i5B4iAWmgJhrJL3e642CMnic7+KUJMeQqeV4tzXi8w=; b=rmVXmOcX79idXWLuox/vfCAg7xGzB05jVhBnxQOihK/tDrCAa/RktxKRdhH0BFR9NBZ+7KkjfUj53mf/KA7EPqSpMlgNJYyQcoqeFmVDu8yucOKvxL5GwweXLlvL80H0EdKGKaZkK2Um6zsI94VV3QRZ8FBY9cYv+iuOWDVJkds= 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 CO6PR04MB7778.namprd04.prod.outlook.com (2603:10b6:303:13e::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4129.26; Mon, 17 May 2021 13:10:42 +0000 Received: from CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::88a0:bf18:b01d:1a50]) by CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::88a0:bf18:b01d:1a50%4]) with mapi id 15.20.4129.031; Mon, 17 May 2021 13:10:42 +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: [RFC PATCH v4 6/8] cpuidle: Add RISC-V SBI CPU idle driver Date: Mon, 17 May 2021 18:38:21 +0530 Message-Id: <20210517130823.796963-7-anup.patel@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210517130823.796963-1-anup.patel@wdc.com> References: <20210517130823.796963-1-anup.patel@wdc.com> X-Originating-IP: [122.179.32.240] X-ClientProxiedBy: MA1PR0101CA0024.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:21::34) To CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from wdc.com (122.179.32.240) by MA1PR0101CA0024.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:21::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4108.25 via Frontend Transport; Mon, 17 May 2021 13:10:24 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: cc1bf399-2c03-4604-9c2d-08d919352cc0 X-MS-TrafficTypeDiagnostic: CO6PR04MB7778: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: WDCIPOUTBOUND: EOP-TRUE X-MS-Oob-TLC-OOBClassifiers: OLM:9508; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: +TWH/gg/gOsUMeFls0Nfw/mO0dIO9MfIIVd3WX3kIEKIEoC1PVNxqtiy5v4MJwqH620wGy0jz1UPzHYaP26zu8K0x8hXGGZy/GOxR34ep2oyeDwYUl2eaQAB/7NfE80QgyaV4TydQZQhAgHdTSOPDPJPDmjoOyk93s+POcY2GUSGMkkRkbjYVlf/hgzdPTELMDRd7siK3mZNjUO2dxqpkLtDcYQT2LlovKWfbvpDHn2a9kIKrbCT+PpO5H2q/c+LXu3ovnDjm6RNPUJxG65O/HIZnEzEbrnX3WjrFqOekVwVdcurOoH5ST83CJWBwrEaTAdGK3CwqSsuHd4G3LZJoUCuYGhDCRNyX5a6Eq0qDkK7XqqEsjzBHwHvHjZVqE9mnhGtGpbZVtPYA2KXSddzRMF4zTFqrLFZ7g8OH+p8dLyZ/7Uk57hiAAPY91bNgDYK07yeYCone57ejQqifr1AFa9/jUVN4eLsXwo4q5CFuVHxug+LWSxSbPiKG80eABvGHLYD0WcqBqRR56swBGhWNNGcthFuXwiN0qpM8xg89J3IcRwyHhHQwYdlnSDUORe7V0N5mtu5ufelpgJ26LKux1jJYWuKfIV/gzTDZ/rCL+7IEi2ztEnWXYE0R8EFeFQJ89WudTEIRkeWppBA9MVFsg== 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)(39850400004)(396003)(346002)(136003)(376002)(83380400001)(38100700002)(6666004)(1076003)(26005)(8886007)(66946007)(44832011)(86362001)(38350700002)(316002)(4326008)(55016002)(2616005)(956004)(30864003)(52116002)(7696005)(110136005)(54906003)(478600001)(8936002)(8676002)(186003)(7416002)(16526019)(66556008)(66476007)(2906002)(36756003)(5660300002);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData: O6hWtot2CcjM7KIH6+YWBq4UXv1Y3+SX++26GYRXAiagN93cxU0ea49hqoaKdH2QoQP8LtmtiBHMEMfHlo+e0ENOn/eZbIy3+2Gm0YlHNAySvZA2oKz9bWhA6TOwDvdpz2OEQt+SFWkAwVr+m7cIE6KmROS9hDf+a1Og4xvtJs8xcjKFAMccaGT5v/BgT7rABjK5gFXzavJERdRPX/xWi8a21L2T/KRB1dQSHGMvVcRdii2WHonK2JaoJP8Xf//MtrymSanyY1Urap5hiL+Pw/gqiCZ1ONRj6Tw//p6GnqpBZoCKg7X+EAmwWQjGFU0XqZ5YfQ5sLXArlpcNO+TlxAFDCX5Py3fdSzf1i5Jtl9Zp5azTp9AETo5XhI/BKc/jzCrfQxLW9KBHnm7tuwoa/B03UEM53kBP5PREcBTtzH4AvLPE91QiCbQSFGdUt2PSksTy80sWWKrpWEEENByjkBbPY77TN2+4xjSrGiKNCUwkN5q0QJb50gk7UwZehXpgFo+UOOd3QVj5c/Ago9hKki+HoD4ZGXGIXkw6Aoy6TAr/Avk7+KDlAyrbGsgoSIsn63/cMgUKzeYKNuoLJ0v76k360v/UaNg0qq8Oz/XER1bg5QWiEXyU9WRbRRqnq5WhPfg/MkFGzjZVF2dfOOZnAJwEiG0Df0Ep4zBCJT/Pc0kyJ1k9pGwfTMfS73ElFR8v86ntaUsV//85y7reoBWKAu/QE3Sze3+xAB3cUlV47KmdMOw0vOpap9HyCxpPBO74g6NmwQW5rEGI2hxTp35GP9r1TEUATbimFuP2FZUkQxustxz6FjJMxuFUwIN0pPKrc1UBD3n3zWgdwluoD9Rn1yktTXCrdDUvajv8n4xvtvbP2LIt4ID9Gq6ly8+gu5v+4M3zTHW6ceKcweq6D6y6XTG254WhXUHUmHiIJAOL0ZghBZR7xcHPviNDZyZKncOhIAwTtDwkiidT6/jINAgdcwStxnMF026ucw4P3Lz2KrwylOSyTXvHOM902pK3/qkDUqq3VD3GbSffqdBPxFajTu+mJ7fjq/STarBgLzus6XCTZbEXG+VRJqopwSTrwOFGwHrYVAqLzK7L4mgw6UlCORDaMgNimM3V2/cinK5lWkaPfS6mqkvNADP8feeWOiZiXX3lk3fFtQJ2njWShxwWXzmNzcOKK3h90vSdl633PlkkKNmusQmDa0GzrZIMn2Tq/44xgmH02roEUV6VfczpW0LlXwomk9RGk+8Wyk2LtU1UvjwML+2M4ZPm5Iji3/K4ozZyNYGZK+jmLj7C1O1sf0Slol8nDwCeuqFc2QxTLEn5PA0I0b/EcF+UufhXCxcA X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: cc1bf399-2c03-4604-9c2d-08d919352cc0 X-MS-Exchange-CrossTenant-AuthSource: CO6PR04MB7812.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 May 2021 13:10:42.6229 (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: No2ufWzVmwaax9/L08c3uAtQi22s3sphjxaSePhqXv5R3AH8ZGSmx7aVk5uwVxGfRblR+ICjDnB+k7SxYYHc8w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO6PR04MB7778 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org The RISC-V SBI HSM extension provides HSM suspend call which can be used by Linux RISC-V to enter platform specific low-power state. This patch adds a CPU idle driver based on RISC-V SBI calls which will populate idle states from device tree and use SBI calls to entry these idle states. Signed-off-by: Anup Patel --- MAINTAINERS | 7 + drivers/cpuidle/Kconfig | 5 + drivers/cpuidle/Kconfig.riscv | 15 + drivers/cpuidle/Makefile | 4 + drivers/cpuidle/cpuidle-sbi.c | 625 ++++++++++++++++++++++++++++++++++ 5 files changed, 656 insertions(+) create mode 100644 drivers/cpuidle/Kconfig.riscv create mode 100644 drivers/cpuidle/cpuidle-sbi.c diff --git a/MAINTAINERS b/MAINTAINERS index 008fcad7ac00..a44f74e36ce4 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -4780,6 +4780,13 @@ S: Supported F: drivers/cpuidle/cpuidle-psci.h F: drivers/cpuidle/cpuidle-psci-domain.c +CPUIDLE DRIVER - RISC-V SBI +M: Anup Patel +L: linux-pm@vger.kernel.org +L: linux-riscv@lists.infradead.org +S: Supported +F: drivers/cpuidle/cpuidle-sbi.c + CRAMFS FILESYSTEM M: Nicolas Pitre S: Maintained diff --git a/drivers/cpuidle/Kconfig b/drivers/cpuidle/Kconfig index f1afe7ab6b54..ff71dd662880 100644 --- a/drivers/cpuidle/Kconfig +++ b/drivers/cpuidle/Kconfig @@ -66,6 +66,11 @@ depends on PPC source "drivers/cpuidle/Kconfig.powerpc" endmenu +menu "RISC-V CPU Idle Drivers" +depends on RISCV +source "drivers/cpuidle/Kconfig.riscv" +endmenu + config HALTPOLL_CPUIDLE tristate "Halt poll cpuidle driver" depends on X86 && KVM_GUEST diff --git a/drivers/cpuidle/Kconfig.riscv b/drivers/cpuidle/Kconfig.riscv new file mode 100644 index 000000000000..78518c26af74 --- /dev/null +++ b/drivers/cpuidle/Kconfig.riscv @@ -0,0 +1,15 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +# RISC-V CPU Idle drivers +# + +config RISCV_SBI_CPUIDLE + bool "RISC-V SBI CPU idle Driver" + depends on RISCV_SBI + select DT_IDLE_STATES + select CPU_IDLE_MULTIPLE_DRIVERS + select DT_IDLE_GENPD if PM_GENERIC_DOMAINS_OF + help + Select this option to enable RISC-V SBI firmware based CPU idle + driver for RISC-V systems. This drivers also supports hierarchical + DT based layout of the idle state. diff --git a/drivers/cpuidle/Makefile b/drivers/cpuidle/Makefile index 11a26cef279f..a36922c18510 100644 --- a/drivers/cpuidle/Makefile +++ b/drivers/cpuidle/Makefile @@ -35,3 +35,7 @@ obj-$(CONFIG_MIPS_CPS_CPUIDLE) += cpuidle-cps.o # POWERPC drivers obj-$(CONFIG_PSERIES_CPUIDLE) += cpuidle-pseries.o obj-$(CONFIG_POWERNV_CPUIDLE) += cpuidle-powernv.o + +############################################################################### +# RISC-V drivers +obj-$(CONFIG_RISCV_SBI_CPUIDLE) += cpuidle-sbi.o diff --git a/drivers/cpuidle/cpuidle-sbi.c b/drivers/cpuidle/cpuidle-sbi.c new file mode 100644 index 000000000000..d1dfe2589246 --- /dev/null +++ b/drivers/cpuidle/cpuidle-sbi.c @@ -0,0 +1,625 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * RISC-V SBI CPU idle driver. + * + * Copyright (c) 2021 Western Digital Corporation or its affiliates. + */ + +#define pr_fmt(fmt) "cpuidle-sbi: " fmt + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "dt_idle_states.h" +#include "dt_idle_genpd.h" + +struct sbi_cpuidle_data { + u32 *states; + struct device *dev; +}; + +struct sbi_domain_state { + bool available; + u32 state; +}; + +static DEFINE_PER_CPU_READ_MOSTLY(struct sbi_cpuidle_data, sbi_cpuidle_data); +static DEFINE_PER_CPU(struct sbi_domain_state, domain_state); +static bool sbi_cpuidle_use_osi; +static bool sbi_cpuidle_use_cpuhp; +static bool sbi_cpuidle_pd_allow_domain_state; + +static inline void sbi_set_domain_state(u32 state) +{ + struct sbi_domain_state *data = this_cpu_ptr(&domain_state); + + data->available = true; + data->state = state; +} + +static inline u32 sbi_get_domain_state(void) +{ + struct sbi_domain_state *data = this_cpu_ptr(&domain_state); + + return data->state; +} + +static inline void sbi_clear_domain_state(void) +{ + struct sbi_domain_state *data = this_cpu_ptr(&domain_state); + + data->available = false; +} + +static inline bool sbi_is_domain_state_available(void) +{ + struct sbi_domain_state *data = this_cpu_ptr(&domain_state); + + return data->available; +} + +static int sbi_suspend_finisher(unsigned long suspend_type, + unsigned long resume_addr, + unsigned long opaque) +{ + struct sbiret ret; + + ret = sbi_ecall(SBI_EXT_HSM, SBI_EXT_HSM_HART_SUSPEND, + suspend_type, resume_addr, opaque, 0, 0, 0); + + return (ret.error) ? sbi_err_map_linux_errno(ret.error) : 0; +} + +static int sbi_suspend(u32 state) +{ + if (state & SBI_HSM_SUSP_NON_RET_BIT) + return cpu_suspend(state, sbi_suspend_finisher); + else + return sbi_suspend_finisher(state, 0, 0); +} + +static int sbi_cpuidle_enter_state(struct cpuidle_device *dev, + struct cpuidle_driver *drv, int idx) +{ + u32 *states = __this_cpu_read(sbi_cpuidle_data.states); + + return CPU_PM_CPU_IDLE_ENTER_PARAM(sbi_suspend, idx, states[idx]); +} + +static int __sbi_enter_domain_idle_state(struct cpuidle_device *dev, + struct cpuidle_driver *drv, int idx, + bool s2idle) +{ + struct sbi_cpuidle_data *data = this_cpu_ptr(&sbi_cpuidle_data); + u32 *states = data->states; + struct device *pd_dev = data->dev; + u32 state; + int ret; + + ret = cpu_pm_enter(); + if (ret) + return -1; + + /* Do runtime PM to manage a hierarchical CPU toplogy. */ + rcu_irq_enter_irqson(); + if (s2idle) + dev_pm_genpd_suspend(pd_dev); + else + pm_runtime_put_sync_suspend(pd_dev); + rcu_irq_exit_irqson(); + + if (sbi_is_domain_state_available()) + state = sbi_get_domain_state(); + else + state = states[idx]; + + ret = sbi_suspend(state) ? -1 : idx; + + rcu_irq_enter_irqson(); + if (s2idle) + dev_pm_genpd_resume(pd_dev); + else + pm_runtime_get_sync(pd_dev); + rcu_irq_exit_irqson(); + + cpu_pm_exit(); + + /* Clear the domain state to start fresh when back from idle. */ + sbi_clear_domain_state(); + return ret; +} + +static int sbi_enter_domain_idle_state(struct cpuidle_device *dev, + struct cpuidle_driver *drv, int idx) +{ + return __sbi_enter_domain_idle_state(dev, drv, idx, false); +} + +static int sbi_enter_s2idle_domain_idle_state(struct cpuidle_device *dev, + struct cpuidle_driver *drv, + int idx) +{ + return __sbi_enter_domain_idle_state(dev, drv, idx, true); +} + +static int sbi_cpuidle_cpuhp_up(unsigned int cpu) +{ + struct device *pd_dev = __this_cpu_read(sbi_cpuidle_data.dev); + + if (pd_dev) + pm_runtime_get_sync(pd_dev); + + return 0; +} + +static int sbi_cpuidle_cpuhp_down(unsigned int cpu) +{ + struct device *pd_dev = __this_cpu_read(sbi_cpuidle_data.dev); + + if (pd_dev) { + pm_runtime_put_sync(pd_dev); + /* Clear domain state to start fresh at next online. */ + sbi_clear_domain_state(); + } + + return 0; +} + +static void sbi_idle_init_cpuhp(void) +{ + int err; + + if (!sbi_cpuidle_use_cpuhp) + return; + + err = cpuhp_setup_state_nocalls(CPUHP_AP_CPU_PM_STARTING, + "cpuidle/sbi:online", + sbi_cpuidle_cpuhp_up, + sbi_cpuidle_cpuhp_down); + if (err) + pr_warn("Failed %d while setup cpuhp state\n", err); +} + +static const struct of_device_id sbi_cpuidle_state_match[] = { + { .compatible = "riscv,idle-state", + .data = sbi_cpuidle_enter_state }, + { }, +}; + +static bool sbi_suspend_state_is_valid(u32 state) +{ + if (state > SBI_HSM_SUSPEND_RET_DEFAULT && + state < SBI_HSM_SUSPEND_RET_PLATFORM) + return false; + if (state > SBI_HSM_SUSPEND_NON_RET_DEFAULT && + state < SBI_HSM_SUSPEND_NON_RET_PLATFORM) + return false; + return true; +} + +static int sbi_dt_parse_state_node(struct device_node *np, u32 *state) +{ + int err = of_property_read_u32(np, "riscv,sbi-suspend-param", state); + + if (err) { + pr_warn("%pOF missing riscv,sbi-suspend-param property\n", np); + return err; + } + + if (!sbi_suspend_state_is_valid(*state)) { + pr_warn("Invalid SBI suspend state %#x\n", *state); + return -EINVAL; + } + + return 0; +} + +static int sbi_dt_cpu_init_topology(struct cpuidle_driver *drv, + struct sbi_cpuidle_data *data, + unsigned int state_count, int cpu) +{ + /* Currently limit the hierarchical topology to be used in OSI mode. */ + if (!sbi_cpuidle_use_osi) + return 0; + + data->dev = dt_idle_genpd_attach_cpu(cpu, "sbi"); + if (IS_ERR_OR_NULL(data->dev)) + return PTR_ERR_OR_ZERO(data->dev); + + /* + * Using the deepest state for the CPU to trigger a potential selection + * of a shared state for the domain, assumes the domain states are all + * deeper states. + */ + drv->states[state_count - 1].enter = sbi_enter_domain_idle_state; + drv->states[state_count - 1].enter_s2idle = sbi_enter_s2idle_domain_idle_state; + sbi_cpuidle_use_cpuhp = true; + + return 0; +} + +static int sbi_cpuidle_dt_init_states(struct device *dev, + struct cpuidle_driver *drv, + unsigned int cpu, + unsigned int state_count) +{ + struct sbi_cpuidle_data *data = per_cpu_ptr(&sbi_cpuidle_data, cpu); + struct device_node *state_node; + struct device_node *cpu_node; + u32 *states; + int i, ret; + + cpu_node = of_cpu_device_node_get(cpu); + if (!cpu_node) + return -ENODEV; + + states = devm_kcalloc(dev, state_count, sizeof(*states), GFP_KERNEL); + if (!states) { + ret = -ENOMEM; + goto fail; + } + + /* Parse SBI specific details from state DT nodes */ + for (i = 1; i < state_count; i++) { + state_node = of_get_cpu_state_node(cpu_node, i - 1); + if (!state_node) + break; + + ret = sbi_dt_parse_state_node(state_node, &states[i]); + of_node_put(state_node); + + if (ret) + return ret; + + pr_debug("sbi-state %#x index %d\n", states[i], i); + } + if (i != state_count) { + ret = -ENODEV; + goto fail; + } + + /* Initialize optional data, used for the hierarchical topology. */ + ret = sbi_dt_cpu_init_topology(drv, data, state_count, cpu); + if (ret < 0) + return ret; + + /* Store states in the per-cpu struct. */ + data->states = states; + +fail: + of_node_put(cpu_node); + + return ret; +} + +static void sbi_cpuidle_deinit_cpu(int cpu) +{ + struct sbi_cpuidle_data *data = per_cpu_ptr(&sbi_cpuidle_data, cpu); + + dt_idle_genpd_detach_cpu(data->dev); + sbi_cpuidle_use_cpuhp = false; +} + +static int sbi_cpuidle_init_cpu(struct device *dev, int cpu) +{ + struct cpuidle_driver *drv; + unsigned int state_count = 0; + int ret = 0; + + drv = devm_kzalloc(dev, sizeof(*drv), GFP_KERNEL); + if (!drv) + return -ENOMEM; + + drv->name = "sbi_cpuidle"; + drv->owner = THIS_MODULE; + drv->cpumask = (struct cpumask *)cpumask_of(cpu); + + /* RISC-V architectural WFI to be represented as state index 0. */ + drv->states[0].enter = sbi_cpuidle_enter_state; + drv->states[0].exit_latency = 1; + drv->states[0].target_residency = 1; + drv->states[0].power_usage = UINT_MAX; + strcpy(drv->states[0].name, "WFI"); + strcpy(drv->states[0].desc, "RISC-V WFI"); + + /* + * If no DT idle states are detected (ret == 0) let the driver + * initialization fail accordingly since there is no reason to + * initialize the idle driver if only wfi is supported, the + * default archictectural back-end already executes wfi + * on idle entry. + */ + ret = dt_init_idle_driver(drv, sbi_cpuidle_state_match, 1); + if (ret <= 0) { + pr_debug("HART%ld: failed to parse DT idle states\n", + cpuid_to_hartid_map(cpu)); + return ret ? : -ENODEV; + } + state_count = ret + 1; /* Include WFI state as well */ + + /* Initialize idle states from DT. */ + ret = sbi_cpuidle_dt_init_states(dev, drv, cpu, state_count); + if (ret) { + pr_err("HART%ld: failed to init idle states\n", + cpuid_to_hartid_map(cpu)); + return ret; + } + + ret = cpuidle_register(drv, NULL); + if (ret) + goto deinit; + + cpuidle_cooling_register(drv); + + return 0; +deinit: + sbi_cpuidle_deinit_cpu(cpu); + return ret; +} + +static int sbi_cpuidle_pd_power_off(struct generic_pm_domain *pd) +{ + struct genpd_power_state *state = &pd->states[pd->state_idx]; + u32 *pd_state; + + if (!state->data) + return 0; + + if (!sbi_cpuidle_pd_allow_domain_state) + return -EBUSY; + + /* OSI mode is enabled, set the corresponding domain state. */ + pd_state = state->data; + sbi_set_domain_state(*pd_state); + + return 0; +} + +static void sbi_cpuidle_domain_sync_state(struct device *dev) +{ + /* + * All devices have now been attached/probed to the PM domain + * topology, hence it's fine to allow domain states to be picked. + */ + sbi_cpuidle_pd_allow_domain_state = true; +} + +#ifdef CONFIG_DT_IDLE_GENPD + +struct sbi_pd_provider { + struct list_head link; + struct device_node *node; +}; + +static LIST_HEAD(sbi_pd_providers); + +static int sbi_pd_init(struct device_node *np) +{ + struct generic_pm_domain *pd; + struct sbi_pd_provider *pd_provider; + struct dev_power_governor *pd_gov; + int ret = -ENOMEM, state_count = 0; + + pd = dt_pd_alloc(np, sbi_dt_parse_state_node); + if (!pd) + goto out; + + pd_provider = kzalloc(sizeof(*pd_provider), GFP_KERNEL); + if (!pd_provider) + goto free_pd; + + pd->flags |= GENPD_FLAG_IRQ_SAFE | GENPD_FLAG_CPU_DOMAIN; + + /* Allow power off when OSI is available. */ + if (sbi_cpuidle_use_osi) + pd->power_off = sbi_cpuidle_pd_power_off; + else + pd->flags |= GENPD_FLAG_ALWAYS_ON; + + /* Use governor for CPU PM domains if it has some states to manage. */ + pd_gov = state_count > 0 ? &pm_domain_cpu_gov : NULL; + + ret = pm_genpd_init(pd, pd_gov, false); + if (ret) + goto free_pd_prov; + + ret = of_genpd_add_provider_simple(np, pd); + if (ret) + goto remove_pd; + + pd_provider->node = of_node_get(np); + list_add(&pd_provider->link, &sbi_pd_providers); + + pr_debug("init PM domain %s\n", pd->name); + return 0; + +remove_pd: + pm_genpd_remove(pd); +free_pd_prov: + kfree(pd_provider); +free_pd: + dt_pd_free(pd); +out: + pr_err("failed to init PM domain ret=%d %pOF\n", ret, np); + return ret; +} + +static void sbi_pd_remove(void) +{ + struct sbi_pd_provider *pd_provider, *it; + struct generic_pm_domain *genpd; + + list_for_each_entry_safe(pd_provider, it, &sbi_pd_providers, link) { + of_genpd_del_provider(pd_provider->node); + + genpd = of_genpd_remove_last(pd_provider->node); + if (!IS_ERR(genpd)) + kfree(genpd); + + of_node_put(pd_provider->node); + list_del(&pd_provider->link); + kfree(pd_provider); + } +} + +static int sbi_genpd_probe(struct device_node *np) +{ + struct device_node *node; + int ret = 0, pd_count = 0; + + if (!np) + return -ENODEV; + + /* + * Parse child nodes for the "#power-domain-cells" property and + * initialize a genpd/genpd-of-provider pair when it's found. + */ + for_each_child_of_node(np, node) { + if (!of_find_property(node, "#power-domain-cells", NULL)) + continue; + + ret = sbi_pd_init(node); + if (ret) + goto put_node; + + pd_count++; + } + + /* Bail out if not using the hierarchical CPU topology. */ + if (!pd_count) + goto no_pd; + + /* Link genpd masters/subdomains to model the CPU topology. */ + ret = dt_pd_init_topology(np); + if (ret) + goto remove_pd; + + return 0; + +put_node: + of_node_put(node); +remove_pd: + sbi_pd_remove(); + pr_err("failed to create CPU PM domains ret=%d\n", ret); +no_pd: + return ret; +} + +#else + +static inline int sbi_genpd_probe(struct device_node *np) +{ + return 0; +} + +#endif + +static int sbi_cpuidle_probe(struct platform_device *pdev) +{ + int cpu, ret; + struct cpuidle_driver *drv; + struct cpuidle_device *dev; + struct device_node *np, *pds_node; + + /* Detect OSI support based on CPU DT nodes */ + sbi_cpuidle_use_osi = true; + for_each_possible_cpu(cpu) { + np = of_cpu_device_node_get(cpu); + if (np && + of_find_property(np, "power-domains", NULL) && + of_find_property(np, "power-domain-names", NULL)) { + continue; + } else { + sbi_cpuidle_use_osi = false; + break; + } + } + + /* Populate generic power domains from DT nodes */ + pds_node = of_find_node_by_path("/cpus/power-domains"); + if (pds_node) { + ret = sbi_genpd_probe(pds_node); + of_node_put(pds_node); + if (ret) + return ret; + } + + /* Initialize CPU idle driver for each CPU */ + for_each_possible_cpu(cpu) { + ret = sbi_cpuidle_init_cpu(&pdev->dev, cpu); + if (ret) { + pr_debug("HART%ld: idle driver init failed\n", + cpuid_to_hartid_map(cpu)); + goto out_fail; + } + } + + /* Setup CPU hotplut notifiers */ + sbi_idle_init_cpuhp(); + + pr_info("idle driver registered for all CPUs\n"); + + return 0; + +out_fail: + while (--cpu >= 0) { + dev = per_cpu(cpuidle_devices, cpu); + drv = cpuidle_get_cpu_driver(dev); + cpuidle_unregister(drv); + sbi_cpuidle_deinit_cpu(cpu); + } + + return ret; +} + +static struct platform_driver sbi_cpuidle_driver = { + .probe = sbi_cpuidle_probe, + .driver = { + .name = "sbi-cpuidle", + .sync_state = sbi_cpuidle_domain_sync_state, + }, +}; + +static int __init sbi_cpuidle_init(void) +{ + int ret; + struct platform_device *pdev; + + /* + * The SBI HSM suspend function is only available when: + * 1) SBI version is 0.3 or higher + * 2) SBI HSM extension is available + */ + if ((sbi_spec_version < sbi_mk_version(0, 3)) || + sbi_probe_extension(SBI_EXT_HSM) <= 0) { + pr_info("HSM suspend not available\n"); + return 0; + } + + ret = platform_driver_register(&sbi_cpuidle_driver); + if (ret) + return ret; + + pdev = platform_device_register_simple("sbi-cpuidle", + -1, NULL, 0); + if (IS_ERR(pdev)) { + platform_driver_unregister(&sbi_cpuidle_driver); + return PTR_ERR(pdev); + } + + return 0; +} +device_initcall(sbi_cpuidle_init); From patchwork Mon May 17 13:08:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 12261879 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-21.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 75FE7C433B4 for ; Mon, 17 May 2021 13:11:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5565361028 for ; Mon, 17 May 2021 13:11:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230192AbhEQNMf (ORCPT ); Mon, 17 May 2021 09:12:35 -0400 Received: from esa2.hgst.iphmx.com ([68.232.143.124]:48980 "EHLO esa2.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237329AbhEQNMQ (ORCPT ); Mon, 17 May 2021 09:12:16 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1621257066; x=1652793066; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=MeKl9jhPLjMFZAjDeIRMh39HlWEM175ktYhp3+Q4Yqc=; b=JA7ogTjVtPCgTxvtaq9IMaYOJBurezicBp0TIYbO3VNeB3YEP/u2xCWE BG5IjSWVvIetUmSjGgQXUT008R2hHUDTy/3DpBb9hzNg5h2nILw1AEndz BnSm/ycqazaUoNqhbTx6keIZxwvVVSaI/lawXWUH2wo+Lp+IwAqG6OJMw Bml69bmzrxry9DtJY6uOIaIDOmyPZlGv+qcXBuUfryIGQ2LRBzD7p+kCd vNmr9BoK6QcEKIjcKL2OVMUcJXUvQJf5trpzByzddlhY6n39ppfZ3v0JN 5XPyr6ZEj344xBEd+1sI7uHuj895uBm1GPxXLVQKRsdWWl4mPMoofLT3D A==; IronPort-SDR: RW4hUSwRRvyvSWpfx5lNRGJAw8VHvHJ5DYXS8kZ51UAhjpMuBRK6Pe3D7AFqQyzyo0n+fWIxqQ Ll2lYHO6ZRhyMgPgZVJjQdGRRsUrod6MvqrUF4QrYY7/KCU30g0jUKfnW1bxDx4eL4/FxloB3S Vq1Fwt235+W7CkiQd4mCfQL9N244NxX+NrRFvqCgGdCJa7jee4nzmbdUeK59SM0F5yUDeadHwd GcWn2RhzPJJ2OWeKRsIBaIKlt8z6PFMBZyOMgC4folMRnxpnUqrdxTolvhUUWNcF2feu0yU4eZ zo0= X-IronPort-AV: E=Sophos;i="5.82,307,1613404800"; d="scan'208";a="272394720" Received: from mail-mw2nam10lp2100.outbound.protection.outlook.com (HELO NAM10-MW2-obe.outbound.protection.outlook.com) ([104.47.55.100]) by ob1.hgst.iphmx.com with ESMTP; 17 May 2021 21:11:04 +0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=oD9BQ65eC8xC8/XJxdSnRO3pP64qJxt3N4wlXjfWE7Yv53c+hc5wckTEZHMcxJLri1B5lm9ue7WqST0Q2ZC+7Q2oJ0bZica612gJEcKyuPsXRqmAd4LZ7tCFuNGGZaGPwEX6Sk4BSyukr+qs+wkMfziyfWcoTQ4CPCsC7FHwM00/Jdj+3sjvE/3O5wv+NVxdyYqcVrI1McMjsiesuPmCNPvUezUWgRIJ7xQTk5PNK/FtRzKKT7lCELx9Kt8kcgFbJYn6wCEU/BZTMl65f202lvGpGZiqD/jrQDVLDa9EH1PctMzlJ8/ZMZgjHLWTnmK8Ay5LJztbRLacQiEMiGeRqA== 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-SenderADCheck; bh=Jdb7LYKd4zYfz891hXSsl1k21D0B8sMSIEAMlC4gzCs=; b=Hp1pk+vgVs+4bnf4cQcT3SXGo4yUIcfLG3GOzbu8CGdUahLCtcvjTbS0QLiLI3GIesHn8fY5CE9Nh7c8J6BRR20mBrg+/Qe4b/meubnJdLRG/Wwc4b13oOvPe0SeLbZs5mk/fAtFF5zOC08cJjBGuR16qKnyeyq6U6owF81sIZXt1BxkzwvBPpvppKXDfj+C9CCgF+f/NHhSPRE1Cj8l27gfdfK/b4/LvrE3oAt9jcebbWrlCF0YkhxjpfaSQS1ZojpzvAr9G2pdSxHQVD12AO+s2EvNjLgCrjJBmKtnqFsCljEfM77PPcCblklQO183xTx+ToJ3nVvR6fz2wt3fkw== 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=Jdb7LYKd4zYfz891hXSsl1k21D0B8sMSIEAMlC4gzCs=; b=bzWu9Oup2CCOnsLEA/WYKw1de4dpojGDqgHZCy993dh8Vml2BuG+nsawqu8YzzRLABEmAPl3zMpqT71SVprngjH7/IZ0kSYai58PcEA9VAJZcLFfOxEfAO5HgOscTrozp3RvAeDAirkoJuZ4KbIZT0Stw3YbossejZ7ILD4tzR8= 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 CO6PR04MB7778.namprd04.prod.outlook.com (2603:10b6:303:13e::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4129.26; Mon, 17 May 2021 13:10:58 +0000 Received: from CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::88a0:bf18:b01d:1a50]) by CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::88a0:bf18:b01d:1a50%4]) with mapi id 15.20.4129.031; Mon, 17 May 2021 13:10:58 +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 , Rob Herring Subject: [RFC PATCH v4 7/8] dt-bindings: Add common bindings for ARM and RISC-V idle states Date: Mon, 17 May 2021 18:38:22 +0530 Message-Id: <20210517130823.796963-8-anup.patel@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210517130823.796963-1-anup.patel@wdc.com> References: <20210517130823.796963-1-anup.patel@wdc.com> X-Originating-IP: [122.179.32.240] X-ClientProxiedBy: MA1PR0101CA0024.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:21::34) To CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from wdc.com (122.179.32.240) by MA1PR0101CA0024.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:21::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4108.25 via Frontend Transport; Mon, 17 May 2021 13:10:44 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 838da732-6741-477a-eccc-08d9193535cc X-MS-TrafficTypeDiagnostic: CO6PR04MB7778: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: WDCIPOUTBOUND: EOP-TRUE X-MS-Oob-TLC-OOBClassifiers: OLM:8273; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: oCqf4kZe5GBSzXTzM1+oN/8QosO6uH0mgLZMo72jvQcC+WFII03kim9elnTelqESUrCpLB4KcSNV8epndCWRsCWTqjtLPJhnrZufY0ExamCDlIJvzPMy7/KiRC060C9bZF2+tMAWrtVGkj155MnfIitjIT+Ck53MHTPoT2R7DjKu+88pc0Nm1v2ghdLTMUgh0KTdq6qyC8Mxbd2jw9MMTwnuJaOAt1KO1rUm7uqGPNblPtlMREBY9e+pdIPNuKDCwb3NEn/QhbkZ28QbX6oHZvmYD+//cHILl1mLkMVOVFjWh5a1Lb50zNrOXhiqQlCM/8y1k/yNhkg2/sFlbNM4vHv5vRUQoTLVOisgCWbQYsD0Dp1HnukIapG0988iQR4ZpkwSvVg2h3Fqjmt1IUYA51Af0nRt+uW2M4pZHRU7TdX+E9x06yHU/oOJ6q+V/bUkLaha04kI8bFXEbMMxxs0CkaisCI142cjniJ8LDzQgQkArDwdFxRKN3zGKpFYtrvZFc0HPrGdzSSYNHum/9NLGcm3kpvWoBAHKiAtw4/XNKm+BNEM8NDu3hd1Q2jVD3qLSvIvxaiXomgcg5qV2mX/7XIpQwIfz7BCMa8ZLeEd9jj+n2ekNLiftB6uIU7qg4hoUHUfTQhE4uBG/Q01eAezVZn8yj8BYVwHtdrOTmgMceFpGcjnXTZSAwIjWX6Op2jsj06I7gppksO9zAIf9lF7TeyXtiEQsZyLSa8FNr0RQs4= 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)(83380400001)(38100700002)(6666004)(1076003)(26005)(8886007)(66946007)(44832011)(86362001)(38350700002)(4326008)(55016002)(2616005)(956004)(30864003)(52116002)(7696005)(110136005)(54906003)(8936002)(498600001)(8676002)(186003)(7416002)(16526019)(66556008)(66476007)(2906002)(966005)(36756003)(5660300002);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData: RNnQZkACo2ygtVF5FL5O9dfbq3phxhw4XnKNNuxsEMHGsaRFlxzwb844FFmNtDpVAhK/UCKnxzT/uYtQSraXFUlENAd1fQT0NIww9el3QgQLlBPIsfUcO1ySsdS9KirHV4WBGUH6cYPplLsvewyAzmna9/JvYRoIfcX6l6fRFVVj6fx9+llEL8b61heOP9G4Ror/Xa6TqNOn3OxdD7Y6aqS9DuJTIwQVKXT3EgZ+SeKJnsiulvuw73PuzVLy8WUKfTc7d6/ah1TBsR7esWvsv9aI87Q3OatWPl6WOiBQey96eYAfn0+ovcG5maA1k6FlNYGtqFpG/SdCAV6rQlxcy/S2zyPKSmIomX9AjDE0/yvfT0pO4+APAhcp6GwxerQqIEsMbg2En/KWPAz5V1yqv7Ql8iocJm394w+OgQ7eGXJ7/b8gfjzkRjwBHLYOByDSlazBGd5dypiqS+H1Xar5sJJrDxJmdtQJ/S5LUsm17twVZ19/P95pYc0l0h90DQ6kY5ZbOl3J4EhnmdPrDGaOn8V9EcsufELSo/GziCePrlQXovdOgs6/cDbrfktgLMa42aA+XsIOCupQgrrfYWJaIPpy+OhTeGdfYsY1W3+DjPekUaMNk8wM23N8SwZox2JzzTsUUXRQyXo4Ixjb4ZPnlHK8kaqRMbG0UnKqWPSlknnuhZ2Is0a//wsaLcIebNX2nJ8U6Zv9Xxft8F50Ze+UGMCmo3EPyHsI+g875psR/JdJpOg+/IT5dzQ5Vzer/6wzVZ3A720NRdstQat3A28KzKhFFeL0k+fies7QHsSppsd1ZKfue92NjCVh8JBIb5i5qdfzmHNDR+bAoZeKqvtlLVR/0o5bxi9Qhjl66idgRsZhpmB/aKZrMajp/9gJnn8hjDvsCMsjHhS9A45vZhZ9iRmNk0EV1i0qD+Y5D3XHQ3EwRZikiFJlIW9H5Es0oTBli2X5u5xYwCjJ3h/yCnRYqQjGIipSWCbiKqTMlVxZDhqQsK0qyWMdjqZWJTruT9G7IisTBkRhltGj6bk9CZsfTfk4ngHL5JKDDeJoisIJX0F6xyMuraZ/5kxlO64pKKQgmQ92xS4ZkW9QdnhsFiRzB4PohYhvuXBkXAfj0/s6VSnIotPjmUHBvf1tH1vcBQg6WzgaB/k4H8qj2fK9dlIPrtp+5iRgh16BXUkH1bc6pXoMPZSZ0o8gv+EKcyT9XJHRm+atuNS5jDDw1yf31J/qndj1XuXDAuFTqZLrD9UyHj3YvoYxydO3aaH06fphxCk69IZ07eh6x63cTc5yWJ2byTb8L0Q4s8dcp/TAwy+KXtQqrAVlT3sdqi3AzhnfURw9 X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: 838da732-6741-477a-eccc-08d9193535cc X-MS-Exchange-CrossTenant-AuthSource: CO6PR04MB7812.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 May 2021 13:10:57.9893 (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: 8Bg3IX+QugZzEvGt5GOMnQxIjAdN6OHItngW8+6HZYymHSjjZ8zoNP3VE42z3eSl4CtW3zLTCyBzxyBLg+ZLCg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO6PR04MB7778 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org The RISC-V CPU idle states will be described in under the /cpus/idle-states DT node in the same way as ARM CPU idle states. This patch adds common bindings documentation for both ARM and RISC-V idle states. Signed-off-by: Anup Patel Reviewed-by: Rob Herring --- .../bindings/{arm => cpu}/idle-states.yaml | 228 ++++++++++++++++-- .../devicetree/bindings/riscv/cpus.yaml | 6 + 2 files changed, 217 insertions(+), 17 deletions(-) rename Documentation/devicetree/bindings/{arm => cpu}/idle-states.yaml (74%) diff --git a/Documentation/devicetree/bindings/arm/idle-states.yaml b/Documentation/devicetree/bindings/cpu/idle-states.yaml similarity index 74% rename from Documentation/devicetree/bindings/arm/idle-states.yaml rename to Documentation/devicetree/bindings/cpu/idle-states.yaml index 52bce5dbb11f..74466f160cb2 100644 --- a/Documentation/devicetree/bindings/arm/idle-states.yaml +++ b/Documentation/devicetree/bindings/cpu/idle-states.yaml @@ -1,25 +1,30 @@ # SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) %YAML 1.2 --- -$id: http://devicetree.org/schemas/arm/idle-states.yaml# +$id: http://devicetree.org/schemas/cpu/idle-states.yaml# $schema: http://devicetree.org/meta-schemas/core.yaml# -title: ARM idle states binding description +title: Idle states binding description maintainers: - Lorenzo Pieralisi + - Anup Patel description: |+ ========================================== 1 - Introduction ========================================== - ARM systems contain HW capable of managing power consumption dynamically, - where cores can be put in different low-power states (ranging from simple wfi - to power gating) according to OS PM policies. The CPU states representing the - range of dynamic idle states that a processor can enter at run-time, can be - specified through device tree bindings representing the parameters required to - enter/exit specific idle states on a given processor. + ARM and RISC-V systems contain HW capable of managing power consumption + dynamically, where cores can be put in different low-power states (ranging + from simple wfi to power gating) according to OS PM policies. The CPU states + representing the range of dynamic idle states that a processor can enter at + run-time, can be specified through device tree bindings representing the + parameters required to enter/exit specific idle states on a given processor. + + ========================================== + 2 - ARM idle states + ========================================== According to the Server Base System Architecture document (SBSA, [3]), the power states an ARM CPU can be put into are identified by the following list: @@ -43,8 +48,23 @@ description: |+ The device tree binding definition for ARM idle states is the subject of this document. + ========================================== + 3 - RISC-V idle states + ========================================== + + On RISC-V systems, the HARTs (or CPUs) [6] can be put in platform specific + suspend (or idle) states (ranging from simple WFI, power gating, etc). The + RISC-V SBI v0.3 (or higher) [7] hart state management extension provides a + standard mechanism for OS to request HART state transitions. + + The platform specific suspend (or idle) states of a hart can be either + retentive or non-rententive in nature. A retentive suspend state will + preserve HART registers and CSR values for all privilege modes whereas + a non-retentive suspend state will not preserve HART registers and CSR + values. + =========================================== - 2 - idle-states definitions + 4 - idle-states definitions =========================================== Idle states are characterized for a specific system through a set of @@ -211,10 +231,10 @@ description: |+ properties specification that is the subject of the following sections. =========================================== - 3 - idle-states node + 5 - idle-states node =========================================== - ARM processor idle states are defined within the idle-states node, which is + The processor idle states are defined within the idle-states node, which is a direct child of the cpus node [1] and provides a container where the processor idle states, defined as device tree nodes, are listed. @@ -223,7 +243,7 @@ description: |+ just supports idle_standby, an idle-states node is not required. =========================================== - 4 - References + 6 - References =========================================== [1] ARM Linux Kernel documentation - CPUs bindings @@ -238,9 +258,15 @@ description: |+ [4] ARM Architecture Reference Manuals http://infocenter.arm.com/help/index.jsp - [6] ARM Linux Kernel documentation - Booting AArch64 Linux + [5] ARM Linux Kernel documentation - Booting AArch64 Linux Documentation/arm64/booting.rst + [6] RISC-V Linux Kernel documentation - CPUs bindings + Documentation/devicetree/bindings/riscv/cpus.yaml + + [7] RISC-V Supervisor Binary Interface (SBI) + http://github.com/riscv/riscv-sbi-doc/riscv-sbi.adoc + properties: $nodename: const: idle-states @@ -253,7 +279,7 @@ properties: On ARM 32-bit systems this property is optional This assumes that the "enable-method" property is set to "psci" in the cpu - node[6] that is responsible for setting up CPU idle management in the OS + node[5] that is responsible for setting up CPU idle management in the OS implementation. const: psci @@ -265,8 +291,8 @@ patternProperties: as follows. The idle state entered by executing the wfi instruction (idle_standby - SBSA,[3][4]) is considered standard on all ARM platforms and therefore - must not be listed. + SBSA,[3][4]) is considered standard on all ARM and RISC-V platforms and + therefore must not be listed. In addition to the properties listed above, a state node may require additional properties specific to the entry-method defined in the @@ -275,7 +301,27 @@ patternProperties: properties: compatible: - const: arm,idle-state + oneOf: + - const: arm,idle-state + - const: riscv,idle-state + + arm,psci-suspend-param: + $ref: /schemas/types.yaml#/definitions/uint32 + description: | + power_state parameter to pass to the ARM PSCI suspend call. + + Device tree nodes that require usage of PSCI CPU_SUSPEND function + (i.e. idle states node with entry-method property is set to "psci") + must specify this property. + + riscv,sbi-suspend-param: + $ref: /schemas/types.yaml#/definitions/uint32 + description: | + suspend_type parameter to pass to the RISC-V SBI HSM suspend call. + + This property is required in idle state nodes of device tree meant + for RISC-V systems. For more details on the suspend_type parameter + refer the SBI specifiation v0.3 (or higher) [7]. local-timer-stop: description: @@ -317,6 +363,8 @@ patternProperties: description: A string used as a descriptive name for the idle state. + additionalProperties: false + required: - compatible - entry-latency-us @@ -658,4 +706,150 @@ examples: }; }; + - | + // Example 3 (RISC-V 64-bit, 4-cpu systems, two clusters): + + cpus { + #size-cells = <0>; + #address-cells = <1>; + + cpu@0 { + device_type = "cpu"; + compatible = "riscv"; + reg = <0x0>; + riscv,isa = "rv64imafdc"; + mmu-type = "riscv,sv48"; + cpu-idle-states = <&CPU_RET_0_0 &CPU_NONRET_0_0 + &CLUSTER_RET_0 &CLUSTER_NONRET_0>; + + cpu_intc0: interrupt-controller { + #interrupt-cells = <1>; + compatible = "riscv,cpu-intc"; + interrupt-controller; + }; + }; + + cpu@1 { + device_type = "cpu"; + compatible = "riscv"; + reg = <0x1>; + riscv,isa = "rv64imafdc"; + mmu-type = "riscv,sv48"; + cpu-idle-states = <&CPU_RET_0_0 &CPU_NONRET_0_0 + &CLUSTER_RET_0 &CLUSTER_NONRET_0>; + + cpu_intc1: interrupt-controller { + #interrupt-cells = <1>; + compatible = "riscv,cpu-intc"; + interrupt-controller; + }; + }; + + cpu@10 { + device_type = "cpu"; + compatible = "riscv"; + reg = <0x10>; + riscv,isa = "rv64imafdc"; + mmu-type = "riscv,sv48"; + cpu-idle-states = <&CPU_RET_1_0 &CPU_NONRET_1_0 + &CLUSTER_RET_1 &CLUSTER_NONRET_1>; + + cpu_intc10: interrupt-controller { + #interrupt-cells = <1>; + compatible = "riscv,cpu-intc"; + interrupt-controller; + }; + }; + + cpu@11 { + device_type = "cpu"; + compatible = "riscv"; + reg = <0x11>; + riscv,isa = "rv64imafdc"; + mmu-type = "riscv,sv48"; + cpu-idle-states = <&CPU_RET_1_0 &CPU_NONRET_1_0 + &CLUSTER_RET_1 &CLUSTER_NONRET_1>; + + cpu_intc11: interrupt-controller { + #interrupt-cells = <1>; + compatible = "riscv,cpu-intc"; + interrupt-controller; + }; + }; + + idle-states { + CPU_RET_0_0: cpu-retentive-0-0 { + compatible = "riscv,idle-state"; + riscv,sbi-suspend-param = <0x10000000>; + entry-latency-us = <20>; + exit-latency-us = <40>; + min-residency-us = <80>; + }; + + CPU_NONRET_0_0: cpu-nonretentive-0-0 { + compatible = "riscv,idle-state"; + riscv,sbi-suspend-param = <0x90000000>; + entry-latency-us = <250>; + exit-latency-us = <500>; + min-residency-us = <950>; + }; + + CLUSTER_RET_0: cluster-retentive-0 { + compatible = "riscv,idle-state"; + riscv,sbi-suspend-param = <0x11000000>; + local-timer-stop; + entry-latency-us = <50>; + exit-latency-us = <100>; + min-residency-us = <250>; + wakeup-latency-us = <130>; + }; + + CLUSTER_NONRET_0: cluster-nonretentive-0 { + compatible = "riscv,idle-state"; + riscv,sbi-suspend-param = <0x91000000>; + local-timer-stop; + entry-latency-us = <600>; + exit-latency-us = <1100>; + min-residency-us = <2700>; + wakeup-latency-us = <1500>; + }; + + CPU_RET_1_0: cpu-retentive-1-0 { + compatible = "riscv,idle-state"; + riscv,sbi-suspend-param = <0x10000010>; + entry-latency-us = <20>; + exit-latency-us = <40>; + min-residency-us = <80>; + }; + + CPU_NONRET_1_0: cpu-nonretentive-1-0 { + compatible = "riscv,idle-state"; + riscv,sbi-suspend-param = <0x90000010>; + entry-latency-us = <250>; + exit-latency-us = <500>; + min-residency-us = <950>; + }; + + CLUSTER_RET_1: cluster-retentive-1 { + compatible = "riscv,idle-state"; + riscv,sbi-suspend-param = <0x11000010>; + local-timer-stop; + entry-latency-us = <50>; + exit-latency-us = <100>; + min-residency-us = <250>; + wakeup-latency-us = <130>; + }; + + CLUSTER_NONRET_1: cluster-nonretentive-1 { + compatible = "riscv,idle-state"; + riscv,sbi-suspend-param = <0x91000010>; + local-timer-stop; + entry-latency-us = <600>; + exit-latency-us = <1100>; + min-residency-us = <2700>; + wakeup-latency-us = <1500>; + }; + }; + }; + ... diff --git a/Documentation/devicetree/bindings/riscv/cpus.yaml b/Documentation/devicetree/bindings/riscv/cpus.yaml index e534f6a7cfa1..482936630525 100644 --- a/Documentation/devicetree/bindings/riscv/cpus.yaml +++ b/Documentation/devicetree/bindings/riscv/cpus.yaml @@ -95,6 +95,12 @@ properties: - compatible - interrupt-controller + cpu-idle-states: + $ref: '/schemas/types.yaml#/definitions/phandle-array' + description: | + List of phandles to idle state nodes supported + by this hart (see ./idle-states.yaml). + required: - riscv,isa - interrupt-controller From patchwork Mon May 17 13:08:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 12261881 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AE634C433ED for ; Mon, 17 May 2021 13:11:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9461D6124C for ; Mon, 17 May 2021 13:11:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237315AbhEQNMj (ORCPT ); Mon, 17 May 2021 09:12:39 -0400 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:64954 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237348AbhEQNM2 (ORCPT ); Mon, 17 May 2021 09:12:28 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1621257070; x=1652793070; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=1uLrgPfppmFH2vM6/L/JqMHBvAu4tkt7ZHOK+EuhRKU=; b=Qcf28jcROccMbQD4xG0pqHeY7PR1edE/3Ru2F88kxBZ55QKGZp8GgTA6 cvxx8wQx8z/rrS6sJQ/tZWfEoizScUZEhJUBFaX8LzSnbaekwWmtJJJrA mL6YFD7XjjJXtcWHlx1rKnDgXeUGfBqyl9te387wxDhg+NSOExLpT7g2O Xc3VxtBQSMtFGJPDe8R8IJA/xphh79qA1h7ZC1upCHD85TpODjh8yTEhv VtCU0BGKcnMnOwYdghizYGSF/Gb6R0H8EVJOK62zgymwAQsIevGzP2lQh tamiD0obrTtSfk6cArSEVLpjunTvOC3wyR4a+eLLCHtSoDjsZr4udUiRj A==; IronPort-SDR: r3ApJRUivDBz+wMnRIIUAOZU5euVJLI6NCF/+8iQxo0yN9/T2ct0Wdw1B/QXsy/IYFBwOH8qzR b9JAa1FHmcIxOzKt2mNGnt1co9aeIe+DE/P253Yfj4+S45v+BsefKACOy+c/sIVPTfW20AegUx ZJ7bGfPOzquV0bWi3/GBdOOaEguRI4uv2caWyobSiNxhcRvrmazT8GRH5PriJ2LLOAs6C0WInB pYpURYC2xmUzbwnL7j4dBo+FhXdNn5qIajUHGkRx3X3GS54mwk6dfDzcD31Sk7vMEsG82tgxzv 1h0= X-IronPort-AV: E=Sophos;i="5.82,307,1613404800"; d="scan'208";a="168450205" Received: from mail-dm6nam08lp2046.outbound.protection.outlook.com (HELO NAM04-DM6-obe.outbound.protection.outlook.com) ([104.47.73.46]) by ob1.hgst.iphmx.com with ESMTP; 17 May 2021 21:11:08 +0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SMWoFXxzpqpqHXHpDKRD3BURh87R0KhuR9Ck00jKZLp9ixJFKtkzJdjHRHnUU4R54QyyfMlWAII5py3De2sL4aarikQtAP1s8MiH3vl+uIb/3YAIwRE5SiiGHIJFcMCrNAfbiHj9u5Gofzk2NgaCYZodu7hUuI9Oukmnh67W17WHE0a0j3fJN8ABIgK89lq68wHb0hCOqFdO47v5JiQm+yLBSCxCt7nyVqur0T3SzzLRfU47xTTt6w/bnncWmTklboQpaiyrQUXWP9XJQo2JJMgRJRZthEFkoWMdJ6eBka5I3i1YlDO+Esfee78oo0EFIRcddUHsGS5sgp2jChKckQ== 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-SenderADCheck; bh=rip7XFR0BFk/jcVrblzy2OjHhUZycRZYHU6/NmyDcb8=; b=IWu4y8r9yNIaqO2F5z2tAJ2AOWr211rIujuza1p74wO4w44q+2oUUH6ymN8cJ4EP5GWEmE7AhHbg2nqH+HaigEj8EawM6E/KVTNmq+pj1LQiAg6N7OMCh+YEBuHTZyN7byEovi5zlmceV3UnN7VKYfyQ9L+EznUTiUMzKSU2HmeX4TA/jqTBBhr/YtAs2ct1LLt4xkPM6WTh0AFoXXhguaMWYGiz84S6AgFNcmYxcdFJ0oAoUqJwBvreCskvLxxNX+BbDkDDalAnIkXAGHIX4H/q3uRHU1nIc+9RHQq72wsJDFzx2Sc1PjePG//RsEh3ZhBVVCqzHOaE/4qaWwCRww== 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=rip7XFR0BFk/jcVrblzy2OjHhUZycRZYHU6/NmyDcb8=; b=ZZqJ7gPbYsgEwYivMTHG1H7Ur+AQ9o881RybsoaSW5Oi6XjdLuGL9yiCrff6nMZ9S6RfPEb19MF6sv/JwCAwTLSV22KE91H5shn1SNPGSUvimTFHCkpi5cYuJEVCxz4b2uod18Tbqp6534EPZM2wG07r/slx0f1/TUdfz4TVagE= 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 CO6PR04MB7875.namprd04.prod.outlook.com (2603:10b6:303:13c::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4129.26; Mon, 17 May 2021 13:11:08 +0000 Received: from CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::88a0:bf18:b01d:1a50]) by CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::88a0:bf18:b01d:1a50%4]) with mapi id 15.20.4129.031; Mon, 17 May 2021 13:11:08 +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: [RFC PATCH v4 8/8] RISC-V: Enable RISC-V SBI CPU Idle driver for QEMU virt machine Date: Mon, 17 May 2021 18:38:23 +0530 Message-Id: <20210517130823.796963-9-anup.patel@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210517130823.796963-1-anup.patel@wdc.com> References: <20210517130823.796963-1-anup.patel@wdc.com> X-Originating-IP: [122.179.32.240] X-ClientProxiedBy: MA1PR0101CA0024.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:21::34) To CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from wdc.com (122.179.32.240) by MA1PR0101CA0024.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:21::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4108.25 via Frontend Transport; Mon, 17 May 2021 13:10:59 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 1824654c-d81f-4e81-437a-08d919353c42 X-MS-TrafficTypeDiagnostic: CO6PR04MB7875: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: WDCIPOUTBOUND: EOP-TRUE X-MS-Oob-TLC-OOBClassifiers: OLM:849; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: CoHKaSn4sPUUi1qmd2Yd+VpYX41PhCn9CYsIt0CNOcPRTgrLdCY0UhmjiNIgH6tWQSrupMVaF6U7LH7abDmAdUSF70rbhbhxvxRexUHCIhNRlkrZVFqTPkln+aFzZ40RA5MV2Jw0fbSODFcXl7hH7BO3HckC4OoiZ+67f3sVpIqyZD8vq1AphzH5L7pmahnt/AiBSlIRmYPTLu2BAfhJ6WG6+bLC88KxIY522XGHEj7gBXJ+0siI0zUEEYRbEp6w9s4pigsfYkUqN0FfB2T5j6E+aXSd1J0ucG8TNi2weg9s9n5jC1Co76lB1VnvcoV9XbPlJjh1MeX9XZuvErkoFjzJElnTVjJstYyRmRy1ztH9pmA2QKpRHuSyf7x4H/8kl0UvXnme2N81KHmLrO41azx79v/rzAf8EYsgOECADBNNYSxrcIhawLp1nqmDHjIbn4QM8WaePpr69mCP+u2r1C45dKh2pFIVm8nwlF5GEZQLlZgcU0wUB+VSv4c0gm75i8CBbCU1D++APw1BdqBNKKGQgm7tnM/p7C5a+ge4oNezBbo/PNz7dQMdqxQDBajtZT/QLJtL86uT4beWb2hMyD9PVpdbCXpL9W8v6S2TEEhbqYZAeXF7MgEnTcs7gM3gzKVru/x1ACztX0AQSFc7wg== 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)(136003)(396003)(366004)(376002)(346002)(39850400004)(110136005)(44832011)(4326008)(66556008)(66946007)(956004)(55016002)(54906003)(316002)(8886007)(7416002)(186003)(7696005)(8936002)(26005)(478600001)(52116002)(86362001)(2616005)(8676002)(6666004)(38100700002)(38350700002)(2906002)(5660300002)(36756003)(1076003)(66476007)(16526019);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData: yw2tRjt1GUgB42pw0YSpGLQ1WTIHj7NC0fJ5fJCJSnzUusQaP7WfRKFQdX6XitR1e/coyh6X/br/ZMK+0ljkh7RV8a9t3iKxXNSL79LCEiaGH7U1MMUZasomhCzzFyFBQjdsoiTEqbcVkrOnC9Nv0LXmpFmbMEREdWyMs4xWxCJx3xasgucs3pC42yIGZObc7AYlJllky/FmVOEkXaLUjot3Ki3L7jo9+Zh56qvSlBMHUo85YM4MEDxoC7SV4JmFAyT+PewVztEepJX0Nno3OycykiCgNiiTwx+lZXZSLO7WJ5Uc0hMPxwHWm/rM0oxFSWZe5G0Aqf4klCvNxxL+wkuXrzKwRnShc71YTL7B6M9L6LV7aDtkg/McejjAu3QUg4WrZL/cnJLLo74dlMhB1YilBUp9cun7qPCS5Jn4tEIA8i/M2prqfck/iZ+G4TifqMljCQX4z/22U4oYgJntdXR11q9xeY2Y11NujDGXgXeBwC0tVk3wq1q10+pjhMRpMGvbpPUAgNPP24rYdJSaizi47r/od4utP/doNp6GormdVRTmw6MVHvfZEIjRY6tgyOBZn+f38oe0RDNg0501NtisR5z6Ld2dW9dy304f5peLXlFFIjcgF77r0+iAvdZI+W7OpabuN2if+zanlkd4nZqvh8piXr8/ERuYZggXyDF5K4ld5LT4Ngzy3K/bHAmex1jUSmW0fUTHLranBax4IwfsxtNCNCCYzHTwdxNxeU2lXiMCvs7o1Q/ACul+tnFnC28cqM9Q9gPsu8JbLCpYEW+L2Bp9iPAX1OTa6cAd43xqKr63jVdThxkoiOQNEq+ziFokJItqpB3KNx6E970fqaFtBnVslGOv4F4lPAXtM4ZdVAqz4Hrzd4NRJ5vFe0vP60B6akG0LNKoaDp56EA7PI56F9Agis00NioLzpNQJz7HsUqObnLhxjjy+fuxwi8+mrMV+/0tMSqNYgJu6NDh9TabSN6jsJxfOH/gtJVIiul/zC9n2/BoFZD3J8eOambUjxH8QAJDepUgbFMhKi+zRY6ixMRQLIwO8qEQf6XvxH3n9gStCu/bst4TOzaBU0ig8ladFrYsgTcqr7MGY1IBO0l1UTaoguUoW+CKq76AfcPp4BFcDSH9XgJFw0YLBTdhp8fU+F0eSLv5WfRmTYRFXprcDJF2rTpwI0jibPbEGMgWVKgf1bYMpBh5NaflCmbGvNTRDTeOVIcmu3RodkLXsLWblRiGxAdoKk6e1qP2BPAceJbL7NZM6uBJCfR2qLGf1sZjiRPPWbhMsTiT4LhSPr3o1j5kfb7fy9qNQkY7awRJ1UidiLGh1x9VaQMvrRJB X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1824654c-d81f-4e81-437a-08d919353c42 X-MS-Exchange-CrossTenant-AuthSource: CO6PR04MB7812.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 May 2021 13:11:08.5767 (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: BFvYWe8TfmCBfcDo9Khyi8nf8JMzQCgA70P2r1VzIhOraftn9egcw3DkEyAUmjcWDTcgzgrpOYFxuNhOipuDrw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO6PR04MB7875 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org We enable RISC-V SBI CPU Idle driver for QEMU virt machine to test SBI HSM Supend on QEMU. Signed-off-by: Anup Patel --- arch/riscv/Kconfig.socs | 3 +++ arch/riscv/configs/defconfig | 1 + arch/riscv/configs/rv32_defconfig | 1 + 3 files changed, 5 insertions(+) diff --git a/arch/riscv/Kconfig.socs b/arch/riscv/Kconfig.socs index ed963761fbd2..3ae937121a77 100644 --- a/arch/riscv/Kconfig.socs +++ b/arch/riscv/Kconfig.socs @@ -27,6 +27,9 @@ config SOC_VIRT select GOLDFISH select RTC_DRV_GOLDFISH if RTC_CLASS select SIFIVE_PLIC + select PM_GENERIC_DOMAINS if PM + select PM_GENERIC_DOMAINS_OF if PM && OF + select RISCV_SBI_CPUIDLE if CPU_IDLE help This enables support for QEMU Virt Machine. diff --git a/arch/riscv/configs/defconfig b/arch/riscv/configs/defconfig index 57a24d40d43f..ed71f125cbc9 100644 --- a/arch/riscv/configs/defconfig +++ b/arch/riscv/configs/defconfig @@ -20,6 +20,7 @@ CONFIG_SOC_SIFIVE=y CONFIG_SOC_VIRT=y CONFIG_SMP=y CONFIG_HOTPLUG_CPU=y +CONFIG_PM=y CONFIG_CPU_IDLE=y CONFIG_JUMP_LABEL=y CONFIG_MODULES=y diff --git a/arch/riscv/configs/rv32_defconfig b/arch/riscv/configs/rv32_defconfig index 97d899df2445..0088d6989332 100644 --- a/arch/riscv/configs/rv32_defconfig +++ b/arch/riscv/configs/rv32_defconfig @@ -20,6 +20,7 @@ CONFIG_SOC_VIRT=y CONFIG_ARCH_RV32I=y CONFIG_SMP=y CONFIG_HOTPLUG_CPU=y +CONFIG_PM=y CONFIG_CPU_IDLE=y CONFIG_JUMP_LABEL=y CONFIG_MODULES=y