From nobody Fri Dec 19 07:35:39 2025 Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) (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 C9A2C49626 for ; Thu, 29 Aug 2024 03:39:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724902779; cv=none; b=GzI8jlSL9UusMma1euPdF70JW/lJ/+Rjl7sNvIcCfosJRgbgeMJ0wGm/SOzbhtWzj6PxC0JbNuMyv8XLu0tNwOVxgpBxM+/IH7L6OySk62KVLBTdtDCrr1IVP8yGlsyNivyD1fpvxwcTrbFlFcTDCw6JuKz4taary2EmD2XZO9g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724902779; c=relaxed/simple; bh=EbBEvc0PKXsSnG7+GH+yqgj1djjwXCeEDQP2lGPTKew=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=N46iaVRQZ3UmNTzrF4Z40qhEOry4iUzJZATYk7sPSDJ5WIAludvsws0KVZ8GQFV20zHEsfmJa1Q+CjwlGcbWIn0oF9DseFkzfHAP1NNsISfW0jrz57/Y6zIKsfLYr76EcIz55weKerlaw6BPrEEu9dQJzfyTbGPJErRSvOOV+uI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=sifive.com; spf=pass smtp.mailfrom=sifive.com; dkim=pass (2048-bit key) header.d=sifive.com header.i=@sifive.com header.b=QqROOwUh; arc=none smtp.client-ip=209.85.214.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=sifive.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sifive.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sifive.com header.i=@sifive.com header.b="QqROOwUh" Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-202376301e6so1490265ad.0 for ; Wed, 28 Aug 2024 20:39:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1724902776; x=1725507576; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=W3GAnBxuP0k13UOo0B/EnxeGCQ0ew6a+lFlFL3wfeVM=; b=QqROOwUhd5EyI5k97vdfTkdEbkoipbTIKQcIHtHtNtqnh3kcM0V7/I4b1QclvIfoqz h0ISggYy6MbUl1T5KqsdNOGETszwXJCVl4LuOr8BbUkL6Hk+EuCAiUvMEo2APzKgCLDl ATDqmdAzDUsq48LjyWozoSSkXIEWegS852/EneBDlnJfzeF1WeZJXPtMq28hlKhLhv/1 YInDuysa6n90K98yGymmduRaCcRLqQk3vnZuh2sQK8+kzqrjgR1HWSrapuHl6qIQJ64x jRr29aMM8XgcpIkZhNark9BJVRLj/Tvh5qj8GNo5IQRZUmTTiu079v++CQYl+aMOU+2e 08dQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724902776; x=1725507576; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=W3GAnBxuP0k13UOo0B/EnxeGCQ0ew6a+lFlFL3wfeVM=; b=U9eDarSmZyR1kzlbkHY+nXVL23ETPrIimavTanswxj6XZqYmrhiuwEh2MbybgWR6E3 r3lHVikPOOrgCaecEHuPXYOtLIbsUzFG5jymA12PnCHBhgpf3k5RhJblCkENKULkGXG6 VZtrmPJ/0iN0uTvEKNX3sv8CH/fUOeW8P+RGUiaitlk2OwJkbPqqLeg1A8qJxcBmhVoL wm14YvlNHKcLWdOpzaVyD8POWrTavxzPTGNTOi/ThioCR/duo20UrwLfS+FfBHgdFSQH f44BIjwHSS6hi2MVfzaPrLUHJJB37Tm0SR1ricXVetyNlqRucYiuzOUZ35M9IuLRwqnB BaRQ== X-Forwarded-Encrypted: i=1; AJvYcCVLpWvJnLsPyjWFQ4JyyOjreK9KkqtHokuwhd8Gl6+pON6b92lPaWGlS3WVCKWEq2Yt1AGbMK+1X2BhxUk=@vger.kernel.org X-Gm-Message-State: AOJu0YywhgDPnr+aQ/aCGsuQkBU0QorfjBIsWQUqsiIoJiov6KGp5pYd cqkyDI9aAKJtj7wvYn2gHOsAOSlK2C8C1S+Kn62Gqj7JMxTdfb9ZyOz0Y02zidk= X-Google-Smtp-Source: AGHT+IH/8fsuBgr/qoojKI4pyRmSBKKLvKU8OllZIsbVlPHRLEjgz17SXXEQ34o9DYQ5ZzKFjsFW3Q== X-Received: by 2002:a17:902:d50d:b0:202:5075:428d with SMTP id d9443c01a7336-2050c4b6ca4mr16399455ad.64.1724902775824; Wed, 28 Aug 2024 20:39:35 -0700 (PDT) Received: from hsinchu35-syssw01.internal.sifive.com (59-124-168-89.hinet-ip.hinet.net. [59.124.168.89]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-20515542498sm2056065ad.188.2024.08.28.20.39.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Aug 2024 20:39:35 -0700 (PDT) From: Nick Hu To: greentime.hu@sifive.com, zong.li@sifive.com, "Rafael J. Wysocki" , Pavel Machek , Paul Walmsley , Palmer Dabbelt , Albert Ou , Daniel Lezcano , Thomas Gleixner , Andrew Jones , Conor Dooley , Samuel Holland , Sunil V L , Nick Hu , linux-pm@vger.kernel.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/2] riscv: Add stimecmp save and restore Date: Thu, 29 Aug 2024 11:38:59 +0800 Message-Id: <20240829033904.477200-2-nick.hu@sifive.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240829033904.477200-1-nick.hu@sifive.com> References: <20240829033904.477200-1-nick.hu@sifive.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" If the HW support the SSTC extension, we should save and restore the stimecmp register while cpu non retention suspend. Signed-off-by: Nick Hu --- arch/riscv/include/asm/suspend.h | 4 ++++ arch/riscv/kernel/suspend.c | 13 +++++++++++++ 2 files changed, 17 insertions(+) diff --git a/arch/riscv/include/asm/suspend.h b/arch/riscv/include/asm/susp= end.h index 4ffb022b097f..ffaac2efabb5 100644 --- a/arch/riscv/include/asm/suspend.h +++ b/arch/riscv/include/asm/suspend.h @@ -16,6 +16,10 @@ struct suspend_context { unsigned long envcfg; unsigned long tvec; unsigned long ie; +#if __riscv_xlen < 64 + unsigned long stimecmph; +#endif + unsigned long stimecmp; #ifdef CONFIG_MMU unsigned long satp; #endif diff --git a/arch/riscv/kernel/suspend.c b/arch/riscv/kernel/suspend.c index c8cec0cc5833..3afd86e1abf7 100644 --- a/arch/riscv/kernel/suspend.c +++ b/arch/riscv/kernel/suspend.c @@ -19,6 +19,12 @@ void suspend_save_csrs(struct suspend_context *context) context->tvec =3D csr_read(CSR_TVEC); context->ie =3D csr_read(CSR_IE); =20 + if (riscv_has_extension_unlikely(RISCV_ISA_EXT_SSTC)) { + context->stimecmp =3D csr_read(CSR_STIMECMP); +#if __riscv_xlen < 64 + context->stimecmph =3D csr_read(CSR_STIMECMPH); +#endif + } /* * No need to save/restore IP CSR (i.e. MIP or SIP) because: * @@ -42,6 +48,13 @@ void suspend_restore_csrs(struct suspend_context *contex= t) csr_write(CSR_TVEC, context->tvec); csr_write(CSR_IE, context->ie); =20 + if (riscv_has_extension_unlikely(RISCV_ISA_EXT_SSTC)) { + csr_write(CSR_STIMECMP, context->stimecmp); +#if __riscv_xlen < 64 + csr_write(CSR_STIMECMPH, context->stimecmph); +#endif + } + #ifdef CONFIG_MMU csr_write(CSR_SATP, context->satp); #endif --=20 2.34.1