Received: by 2002:a05:7412:ba23:b0:fa:4c10:6cad with SMTP id jp35csp159872rdb; Wed, 17 Jan 2024 22:30:25 -0800 (PST) X-Google-Smtp-Source: AGHT+IE9mUHIv8zePsEBHLNk9pYDk5YX2Vh1/D+BOk9Bz3ETbf7QHnSxRKClnBhaW4bL8+yRT7RQ X-Received: by 2002:a05:622a:210:b0:42a:1437:fff2 with SMTP id b16-20020a05622a021000b0042a1437fff2mr2486111qtx.22.1705559425364; Wed, 17 Jan 2024 22:30:25 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705559425; cv=pass; d=google.com; s=arc-20160816; b=BuaUahnEXk57NCl4Cryt/m7NepatFPUSP4M5p+9HQF42cp9S/pXI8cJ/UqOG8dgaBO JAKG2TfHSIJvGQzUPe7WaLBdAd/i6prpH0QVw8bLrzaPsB2ZQltIRer66+/p+FTfDYsZ JrBrdJX8171BwYmPxUHjjxtTwepixo/zK1eQzy5Z0EcOSzgXVFcaZ+GyWwXI+4A19Lct rCRIBkfuxys4E3yoPet9NTt8hNofFDFHoj7PLbPhh5Jrm0pGxHiHI5Ig9BIOrGG4gDDg YPDCNV63prRwVueW5WRnx0ukWqB0fmY0Jp/NZBBpB0JYJiy8E4QqbQhTID6+IcP5UI7B 9ngg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=DgHlTEiNO6+vqShPGvlPveCet3Ph0raIL9TM7VU3mgo=; fh=/NgZocBoxwoVDYNWJj3XAC7nebNjB3lFda6Ayd/9fyM=; b=iJSUR1GGIspiQr+omNapX/V7AHSQIwwbhG8AkoLDtuZgb2M/0e4MgEAx5f1zuff6Gh jv8AjpZl7K1JGl3LFuhchiEew+pTPgqYrqrZsrG740eZ4sETLrnBHbG0v4QKoAbzGup6 3dNXNnvgGguSkGQ48udWRLhpD7MYJbF6u5cAhAlbhjt9UWsxzPkVY4bkQz9HoUYR2CQ5 0OpsHL2BS30GvtM3NQ2azteLaj7IkvHANf8l0VcO38ECsAdrA22r/PplslaLU52z049Z e2I3Xa/ufJjlMQVxtXvDJZFr311CgR2Ox9S9mtLhnovjxo8zX8L5Xmjop5GtNzGJRTzZ 0VXA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b="P6/AfooF"; arc=pass (i=1 spf=pass spfdomain=ventanamicro.com dkim=pass dkdomain=ventanamicro.com); spf=pass (google.com: domain of linux-kernel+bounces-29738-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-29738-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id v4-20020a05622a130400b00429b5a90b53si13126201qtk.409.2024.01.17.22.30.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Jan 2024 22:30:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-29738-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b="P6/AfooF"; arc=pass (i=1 spf=pass spfdomain=ventanamicro.com dkim=pass dkdomain=ventanamicro.com); spf=pass (google.com: domain of linux-kernel+bounces-29738-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-29738-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 1561F1C20B0D for ; Thu, 18 Jan 2024 06:30:25 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 78374BE66; Thu, 18 Jan 2024 06:29:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b="P6/AfooF" Received: from mail-il1-f174.google.com (mail-il1-f174.google.com [209.85.166.174]) (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 487A2C126 for ; Thu, 18 Jan 2024 06:29:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.174 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705559393; cv=none; b=JkJxQtL494wdhplXR0RHi8C9dBxgW1PlX5Wpf5nO+BTaibSrz8/HsXU4fQ1F0QHPAid++Lg608ilb/XHn1LtnYPOATrUo6LwKVwNJrKELXsF9umCTSxf5L483Sul3ZzM6Dqw8sy7xyRl7/GPCd21shMmfIa+llr3r5V0u+Fy5TE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705559393; c=relaxed/simple; bh=pwEogATDnqJCM9ezt5ZHVJ0B7PUv/0/V4PqFK6Nh9zg=; h=Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Google-Smtp-Source:X-Received:Received:From: To:Cc:Subject:Date:Message-Id:X-Mailer:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding; b=WYXDwEVXscQWAMvcr5+dr+YVvoYW0lqNskJ4Eal8+//1qSBXiFPSBbS/PRPGKljmnVyjgUvTyQ0JREn3q9AVvVponAI0Brk05/hg/a6V6by437hr3zLwluCGK/amdNz/HgoyxD6raePSaJ8r7gKq/L1pP24+/qH3/xtf4QCqNpk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com; spf=pass smtp.mailfrom=ventanamicro.com; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b=P6/AfooF; arc=none smtp.client-ip=209.85.166.174 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-il1-f174.google.com with SMTP id e9e14a558f8ab-3608bdb484fso966185ab.1 for ; Wed, 17 Jan 2024 22:29:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1705559391; x=1706164191; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=DgHlTEiNO6+vqShPGvlPveCet3Ph0raIL9TM7VU3mgo=; b=P6/AfooFmxhkhn/6ket0S1LTDr6QOL7GESDNNe23CGEA8wSyy7t3sCrigz54NyHX96 yudK3lodAw0AlgAcvIJX/fsXhuOZnZMhHTZUjq9QOqQj3W3qH5mk4HIBGCZPA/gsMgqm 6vQlF7HvnioXLkvCt2exsJnTc07TtKJWaTcmfm0bFLD9xDoxTdREXhhrmpi0PGUAQaP0 G3h5yc/RI488q1WCAiJtDkclIMUMJoOXNSvZAxxfdxaysVKeHNHfjNFzRuKx7C7RvMn0 ukULigBlkxJaLJZ7poafB1IBz17UnjrstQrRLiJ0ZA/MP1xB/AjDFv69c5B/PhUOCYBT Yw8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705559391; x=1706164191; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=DgHlTEiNO6+vqShPGvlPveCet3Ph0raIL9TM7VU3mgo=; b=qMcygwxgwTpc5VRg8h0l96de9cCx6S4KiCKMVynsy8E0tS15zH/dKLttx90LwQ+HM4 3RmpTt+zrsv9Ya325tWLXML36jTVDoW/8pAM5cVQ7xSTM/l9qK7rOOMoyfinaaz7pdpE 5ceWWs8qotWYHKHWVHTgT4nQGrUeGI4AsJr/Fr9z/OJnlgCFRX1v849rfYTDdpmwk0Lk FX7tPJ6dLVPamVgYslIE6+u9st8iHy0JRAv4WrsUiG+Jxt+LiPpySvFC0PCHQuU6jW1n PK15GDlbcBh3WDEmAElmGKLVDYvMz/U0ADY/xfFnfJM3jTXVr+u3ITZOL46ioYhcDZ/I C5kQ== X-Gm-Message-State: AOJu0Yzfp4NS4VqBfiVBbsfc//Tqe4sMj2cajLciiTmw5dr19EWE/zSE DYmpCZGwejWGmuZ31HbDM35kfDvO5mo42xDa/Q0FQDsfTs8Ce5IYEDb6QA4vKN8= X-Received: by 2002:a05:6e02:80b:b0:360:17a7:d88b with SMTP id u11-20020a056e02080b00b0036017a7d88bmr409483ilm.9.1705559391483; Wed, 17 Jan 2024 22:29:51 -0800 (PST) Received: from sunil-laptop.dc1.ventanamicro.com ([106.51.83.242]) by smtp.gmail.com with ESMTPSA id bn28-20020a056e02339c00b0035fec699584sm4663269ilb.13.2024.01.17.22.29.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Jan 2024 22:29:51 -0800 (PST) From: Sunil V L To: linux-pm@vger.kernel.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org Cc: "Rafael J . Wysocki" , Pavel Machek , Paul Walmsley , Palmer Dabbelt , Albert Ou , Len Brown , Anup Patel , Daniel Lezcano , Andrew Jones , Conor Dooley , Atish Kumar Patra , Sunil V L Subject: [PATCH v3 -next 2/3] ACPI: RISC-V: Add LPI driver Date: Thu, 18 Jan 2024 11:59:29 +0530 Message-Id: <20240118062930.245937-3-sunilvl@ventanamicro.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240118062930.245937-1-sunilvl@ventanamicro.com> References: <20240118062930.245937-1-sunilvl@ventanamicro.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Andrew Jones --- 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..624f9bbdb58c --- /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 (!riscv_sbi_hsm_is_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 (!riscv_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(riscv_sbi_hart_suspend, + lpi->index, + state); + else + return CPU_PM_CPU_IDLE_ENTER_RETENTION_PARAM(riscv_sbi_hart_suspend, + lpi->index, + state); +} -- 2.34.1