Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp5021073pxj; Wed, 9 Jun 2021 07:27:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzUlxNbijPgB7SjIRmOLedtiAqGXRXMU+zczud+4qzYqu4pEy0lS0CsJCaj9eD8VY4DNPnK X-Received: by 2002:a17:906:9706:: with SMTP id k6mr152739ejx.456.1623248867302; Wed, 09 Jun 2021 07:27:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623248867; cv=none; d=google.com; s=arc-20160816; b=ab32qRALt8d6tzfK7Hl/kFu8NTV99GQT7GMfQ9/hBVJkYO5HaW4sYm2GbMUu5Y+uYP yVbR08Kvtq23OOvaYS5Co5zHUXesXA9kI/3KWJXlTKveywI9SKb8kunEGkzjptJX5tsd cVcLUtUw/G6gQiWCUHwDZxGEait/UqFAhFs3EW03JyzXfHb9VijDq3ryyvlKazJWQqBQ NmLaYOnVX+THHfJWrUjGlv1Uedi7ZqX0oBgIqloHjSWdy2Xl0vgj8GSdr+ECOa+lab2t 4SblYkEjQ3w70s9d8nGs1FXX31m5zgBJkm8IalTaj4cHQve2M5fdxZkNFwN/FqDi9xUO ZnYw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=rYodVtyswGkxjPZ1N4VGwVug/p/tXWlRC7vMIsTSrBI=; b=ZFgtgSzfe/o1yQbM+17AfVO49oKCezzTEYyuFS/yewN5whp5NjTRVA703yBvxgq/Cu L+N37Ie8IB4S3lVrZeF4CVcVn+DfRkPHICFOfTitGQwCnBH0l+OhoG1m2q03cEOibs3A veC5exKAHwHRphYeok3tqVbvxvfUgZBT8vMIP5EhV1hPdZ6foE0GPVF8zehoCOa0cuDB aUd2VwWrS4+C9rXvGHQlB2TF2JuM734WUzNDInrBrZzhAy/4QNpvwzp74AakqbUAeYNh 0SGB80pTaLIFwgqooXshLeK+UU8P5up2UwMJ6vHbwZzkVW20BHM7zZwoqa8axeM3pzNm JYaA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@brainfault-org.20150623.gappssmtp.com header.s=20150623 header.b=bPJatgBr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y3si2555086edp.547.2021.06.09.07.27.23; Wed, 09 Jun 2021 07:27:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@brainfault-org.20150623.gappssmtp.com header.s=20150623 header.b=bPJatgBr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237858AbhFIKkJ (ORCPT + 99 others); Wed, 9 Jun 2021 06:40:09 -0400 Received: from mail-wm1-f45.google.com ([209.85.128.45]:55012 "EHLO mail-wm1-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237198AbhFIKkI (ORCPT ); Wed, 9 Jun 2021 06:40:08 -0400 Received: by mail-wm1-f45.google.com with SMTP id o127so3686116wmo.4 for ; Wed, 09 Jun 2021 03:38:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brainfault-org.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=rYodVtyswGkxjPZ1N4VGwVug/p/tXWlRC7vMIsTSrBI=; b=bPJatgBr7cf/n/nozcV2QXkJ6KuYcmc76wQhAXvk8Hq+0jiCf6/weX5BvAxYuOgBWL tWw35amLPl4/ErMRBcCXdpHGnDsivP8d9+T96WJsPIFQQuvwIwuFoyuH2TlXYHmZ2ekD ZHqceoPEjeLEw6zJEJ06j9uYxHOY54DttYbKMAdqmOlbIrAWgymewLD+n551uHTZtvzs sOjOc8+zgOxmMeABVYyDzKOSdJcSU9UhkbnQi+/fvmYNGPmcUMs04w8EC+rjHzLRf0ns 4vQ2+Re0/hFuAliL64jRfAkIloDs4EoP1BMiVF3mO1y7nPY5SiFjRYqqgQMKjLc0z6Y9 jWDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=rYodVtyswGkxjPZ1N4VGwVug/p/tXWlRC7vMIsTSrBI=; b=DqZAAtoXNtH57DUsOW1nWtyPjE2+3VbiXZHe+cGBxck5EgaZmND1d9gPYtlS+MMZS9 ld1CKD6TjqhCagr/FfXmmQ1v5Q0LNq5dr6+M422r60LPDDRnYWNGqKxnIi7e5uiqnneE +bTxPc/Fmxw4LMC6fNUpvL4Ii8c6CnFlMoICPibuXkqyxt8iXKcB3426dwpQoPPmFP6+ gDPj2/SeJYXXOMIwd4JJZ4+XOInHH7VyfAwSEBFrSaJIhq1UkmxzQYEoI00n9lkTqtPH GxOm53RTsSas14oS8brAm6YKqkF+8w6l6UUA93yPthN4qFpmrA77s/vUS1LcpJd4LrNX Uf+g== X-Gm-Message-State: AOAM530ePQEVIeaw82C5gvycZRBwHP5AS5yI5ZtDXvxjik6Z9+nLP1my tDxOUfDxL12aW+m2xQv5DMNDiY39sDunCiZSFAahag== X-Received: by 2002:a05:600c:4ec7:: with SMTP id g7mr13233266wmq.157.1623235022430; Wed, 09 Jun 2021 03:37:02 -0700 (PDT) MIME-Version: 1.0 References: <20210602112321.2241566-1-anup.patel@wdc.com> <20210602112321.2241566-7-anup.patel@wdc.com> <26cddfa8-75e2-7b5b-1a47-e01cc1c7821e@sholland.org> In-Reply-To: <26cddfa8-75e2-7b5b-1a47-e01cc1c7821e@sholland.org> From: Anup Patel Date: Wed, 9 Jun 2021 16:06:51 +0530 Message-ID: Subject: Re: [PATCH v5 6/8] cpuidle: Add RISC-V SBI CPU idle driver To: Samuel Holland Cc: Anup Patel , Sandeep Tripathy , Atish Patra , Alistair Francis , Liush , DTML , linux-riscv , "linux-kernel@vger.kernel.org List" , "open list:THERMAL" , linux-arm-kernel , Palmer Dabbelt , Palmer Dabbelt , Ulf Hansson , Rob Herring , Albert Ou , "Rafael J . Wysocki" , Daniel Lezcano , Paul Walmsley , Pavel Machek Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jun 7, 2021 at 12:09 AM Samuel Holland wrote: > > On 6/2/21 6:23 AM, Anup Patel wrote: > > 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 | 626 ++++++++++++++++++++++++++++++++++ > > 5 files changed, 657 insertions(+) > > create mode 100644 drivers/cpuidle/Kconfig.riscv > > create mode 100644 drivers/cpuidle/cpuidle-sbi.c > > > > ... > > diff --git a/drivers/cpuidle/cpuidle-sbi.c b/drivers/cpuidle/cpuidle-sbi.c > > new file mode 100644 > > index 000000000000..f743684d07de > > --- /dev/null > > +++ b/drivers/cpuidle/cpuidle-sbi.c > > @@ -0,0 +1,626 @@ > > ... > > + /* 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) > > This function should be moved inside the CONFIG_DT_IDLE_GENPD block > below. Otherwise it is defined but unused. Indeed, sbi_cpuidle_pd_power_off() should be under "#ifdef CONFIG_DT_IDLE_GENPD". I will update in the next patch revision. > > > +{ > > + 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_idle_pd_alloc(np, sbi_dt_parse_state_node); > > + if (!pd) > > + goto out; > > ... Regards, Anup