Received: by 2002:a05:7412:8d11:b0:fa:4934:9f with SMTP id bj17csp598464rdb; Mon, 15 Jan 2024 07:26:04 -0800 (PST) X-Google-Smtp-Source: AGHT+IHBI9p+MSXc9ckm+SbYFxNw6p8+srIvYh3DTyOkcBHRI3EtCY4Cp7uFCFKri+NQpCdk5l1K X-Received: by 2002:a17:906:b0d2:b0:a2a:dc24:849 with SMTP id bk18-20020a170906b0d200b00a2adc240849mr5209368ejb.43.1705332364102; Mon, 15 Jan 2024 07:26:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705332364; cv=none; d=google.com; s=arc-20160816; b=pgyOMzpMhxmCQJH0AXfDFLvQkphr03B2e/vsMjRSeQ0HRKpAgv+pumlr42CLRnkg+j 8EqVtVREzXoxwG33wTQFfPcJYf+xBWdHzsXD200DIesmv1QYNgpNdxmKtoQKNRLTcgpn EFJPgFTKStSXYLlnCv1YHW5EfY/2b3mEEcq9s0E5vfjTS/Z2QlnyVVo8bDGRS/QvsJCh XeYzAsxY+6TMI/TxLndT0D5PvBdzeEH8Fhgx1sKPOGuJvZLYhY9FEf+V+u6o1rxgApVt 71gLOEOfn2uk92hCIGF6hejWCSTuu+HKhSJ4xMTYCuH+V18/XZ15qOyI2QkYszzpDkSS viww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=V3Au/gRaaczdqwoxq154l1Vb0TSRdBUZsRRgmxL/3EA=; fh=wbi7vOghq0LlEdFndf5ZjcFK5QSstDGtqHa91PdDbOg=; b=1LN0wanh5UaOJnga2ZrhfxZMKwLi4G/2UY/7yATK8jTqleTqkuWwDxNF8tyDckXCnv tWiD/DCbyDwmmpmJRhyeEwfenq5+7iJjfS/7nnYGCa1GL4ratqJdcaqXEDgsYrlcK4w9 XSdOPvPs3vwMiW8mz75EgIuLE/CCQYhU4UKkfJicuY0PhAR1n50UFkGEbklXvj93dHf7 nzlEpgjfinHUtAI75V4IF7LlzjrXS9NYcYpDKjlO0bjsZSKpHV6wTt35ON1wUPpGtCb2 10Sim1r7FL57zPEx2jl1XREbmV5nu42LnCgk7aw7DeM78vFnYgugCO7lHc2oXFw4UhoP 0vaw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b=S04UjvDx; spf=pass (google.com: domain of linux-kernel+bounces-26170-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-26170-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id u14-20020a17090626ce00b00a28e96fef36si3715570ejc.743.2024.01.15.07.26.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Jan 2024 07:26:04 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-26170-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b=S04UjvDx; spf=pass (google.com: domain of linux-kernel+bounces-26170-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-26170-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id BB3A21F21BD6 for ; Mon, 15 Jan 2024 15:26:00 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 446D617BA8; Mon, 15 Jan 2024 15:25:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b="S04UjvDx" Received: from mail-ed1-f50.google.com (mail-ed1-f50.google.com [209.85.208.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E210D179B2 for ; Mon, 15 Jan 2024 15:25:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ventanamicro.com Received: by mail-ed1-f50.google.com with SMTP id 4fb4d7f45d1cf-557bfc7f7b4so13188307a12.0 for ; Mon, 15 Jan 2024 07:25:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1705332317; x=1705937117; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=V3Au/gRaaczdqwoxq154l1Vb0TSRdBUZsRRgmxL/3EA=; b=S04UjvDxCv+YJv+ugX5uV3+beXSeeLRov+lehLqMSpkd8QTum/jqGWqjflt2haN3CS CgpZQfYEWBqrmyGJK7Q17nS+eP++ks0juctFVvZ7xw3MMVPVA6hIwGuydFHDg37hglOq 2WyzuOIOvdzPfebTb/bYQxVkH+Pzach3nstMq9E2ysVmddap+CgvI585VE40ujQnrXjS IwRjXSZWZsOwRkPWaSSswZZ1xU2KjJD4waZniGCHroTmFWRpushu8Z6PoFCig8DkrYZ0 x3oM+J8dBoyTpBi1faJR5FX2yD8Smgqm4DQIkhmh9vUG+pFcYtgg5IwB92VKv7niRhgN ejjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705332317; x=1705937117; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=V3Au/gRaaczdqwoxq154l1Vb0TSRdBUZsRRgmxL/3EA=; b=kgNSSQY2qFgvDJjmo1cSaNdopZugpysaN8cJG36T3mDw+wQF78II2hKfeBEZ0pYo5t +XDOfh+ieZf0IrDtS+JY9IRblD3nuDmiJFPBcHTk2oDn/OCOgnUdYzrJ/2npqNOobMVv s2pIabv0hgnZNVxejluuIFp1YHdWcTxJ8xLs6EHf/oQ3Nh1V1Yeds5VeWm7xuYcolfO2 H+R43dePIKxbpjKF5J+esZnf5o0iSicrh41jgLEL/6WcoTd5efWNhKiKj8iVRULasl55 jE4h1z9rr+M6CrPY9VakTopLWYYmCHIPfM6HFFpY9VZDfnFXibtfrxXwDZHF4U+bx3Fi 1D2w== X-Gm-Message-State: AOJu0YwvRZqOc4YLl/94CbeEbTWM5Ht9iymKq3zFJQRl+eb4X1o+mJR3 46Q6jrRfb1W7P+o4CRlycHPfPdhyXYgW1A== X-Received: by 2002:a05:6402:1ca8:b0:558:b48a:b5f1 with SMTP id cz8-20020a0564021ca800b00558b48ab5f1mr6094220edb.7.1705332317286; Mon, 15 Jan 2024 07:25:17 -0800 (PST) Received: from localhost (2001-1ae9-1c2-4c00-20f-c6b4-1e57-7965.ip6.tmcz.cz. [2001:1ae9:1c2:4c00:20f:c6b4:1e57:7965]) by smtp.gmail.com with ESMTPSA id b23-20020a056402139700b0055920196ddesm2446466edv.54.2024.01.15.07.25.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Jan 2024 07:25:16 -0800 (PST) Date: Mon, 15 Jan 2024 16:25:16 +0100 From: Andrew Jones To: Sunil V L Cc: linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, linux-riscv@lists.infradead.org, "Rafael J . Wysocki" , Len Brown , Anup Patel , Daniel Lezcano , Paul Walmsley , Palmer Dabbelt , Albert Ou , Conor Dooley , Atish Kumar Patra , Pavel Machek Subject: Re: [PATCH v2 -next 2/3] ACPI: RISC-V: Add LPI driver Message-ID: <20240115-94bdb396ea417ca1d834548d@orel> References: <20240115101056.429471-1-sunilvl@ventanamicro.com> <20240115101056.429471-3-sunilvl@ventanamicro.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240115101056.429471-3-sunilvl@ventanamicro.com> On Mon, Jan 15, 2024 at 03:40:55PM +0530, Sunil V L wrote: > Enable Low Power Idle (LPI) based cpuidle driver for RISC-V platforms. > It depends on SBI HSM calls for idle state transitions. > > Signed-off-by: Sunil V L > --- > drivers/acpi/riscv/Makefile | 3 +- > drivers/acpi/riscv/cpuidle.c | 81 ++++++++++++++++++++++++++++++++++++ > 2 files changed, 83 insertions(+), 1 deletion(-) > create mode 100644 drivers/acpi/riscv/cpuidle.c > > diff --git a/drivers/acpi/riscv/Makefile b/drivers/acpi/riscv/Makefile > index 8b3b126e0b94..7309d92dd477 100644 > --- a/drivers/acpi/riscv/Makefile > +++ b/drivers/acpi/riscv/Makefile > @@ -1,2 +1,3 @@ > # SPDX-License-Identifier: GPL-2.0-only > -obj-y += rhct.o > +obj-y += rhct.o > +obj-$(CONFIG_ACPI_PROCESSOR_IDLE) += cpuidle.o > diff --git a/drivers/acpi/riscv/cpuidle.c b/drivers/acpi/riscv/cpuidle.c > new file mode 100644 > index 000000000000..052ec3942902 > --- /dev/null > +++ b/drivers/acpi/riscv/cpuidle.c > @@ -0,0 +1,81 @@ > +// SPDX-License-Identifier: GPL-2.0-only > +/* > + * Copyright (C) 2024, Ventana Micro Systems Inc > + * Author: Sunil V L > + * > + */ > + > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +#define RISCV_FFH_LPI_TYPE_MASK GENMASK_ULL(63, 60) > +#define RISCV_FFH_LPI_RSVD_MASK GENMASK_ULL(59, 32) > + > +#define RISCV_FFH_LPI_TYPE_SBI BIT_ULL(60) > + > +static int acpi_cpu_init_idle(unsigned int cpu) > +{ > + int i; > + struct acpi_lpi_state *lpi; > + struct acpi_processor *pr = per_cpu(processors, cpu); > + > + if (unlikely(!pr || !pr->flags.has_lpi)) > + return -EINVAL; > + > + if (!is_sbi_hsm_supported()) > + return -ENODEV; > + > + if (pr->power.count <= 1) > + return -ENODEV; > + > + for (i = 1; i < pr->power.count; i++) { > + u32 state; > + > + lpi = &pr->power.lpi_states[i]; > + > + /* > + * Validate Entry Method as per FFH spec. > + * bits[63:60] should be 0x1 > + * bits[59:32] should be 0x0 > + * bits[31:0] represent a SBI power_state > + */ > + if (((lpi->address & RISCV_FFH_LPI_TYPE_MASK) != RISCV_FFH_LPI_TYPE_SBI) || > + (lpi->address & RISCV_FFH_LPI_RSVD_MASK)) { > + pr_warn("Invalid LPI entry method %#llx\n", lpi->address); > + return -EINVAL; > + } > + > + state = lpi->address; > + if (!sbi_suspend_state_is_valid(state)) { > + pr_warn("Invalid SBI power state %#x\n", state); > + return -EINVAL; > + } > + } > + > + return 0; > +} > + > +int acpi_processor_ffh_lpi_probe(unsigned int cpu) > +{ > + return acpi_cpu_init_idle(cpu); > +} > + > +int acpi_processor_ffh_lpi_enter(struct acpi_lpi_state *lpi) > +{ > + u32 state = lpi->address; > + > + if (state & SBI_HSM_SUSP_NON_RET_BIT) > + return CPU_PM_CPU_IDLE_ENTER_PARAM(sbi_suspend, > + lpi->index, > + state); > + else > + return CPU_PM_CPU_IDLE_ENTER_RETENTION_PARAM(sbi_suspend, > + lpi->index, > + state); > +} > -- > 2.34.1 > Reviewed-by: Andrew Jones