From patchwork Mon Oct 28 03:39:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nick Hu X-Patchwork-Id: 13852963 Received: from mail-pj1-f42.google.com (mail-pj1-f42.google.com [209.85.216.42]) (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 19D85161 for ; Mon, 28 Oct 2024 03:39:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730086783; cv=none; b=knkfatQbTsEW8MeWqbSH5WCGw275HdOwHUnrr5S11nsk2nKlhWIqzpEHiSjZTfze5diLJJwJE4qe/1Op8UEeB7S82vdeG5D/e3/eiMYlF20ZU/VlE91TAlrQV5jqqnLS7RmoL0zwjtuxh3NpG776+i93im8AU6EDlbrQovUadZI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730086783; c=relaxed/simple; bh=IOaCLXtRKMj1XaFGEqYfcoGSRq0kGRGrZLs1Q90y+f4=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Wu6mxf0KAh5mcv85/Fh1/v9J5naRqVSktBEdu4S4faeruA00aHllq6IeIMVqz7S4WxFe985ZM7ZvXuGIi9VJw/YF7FVwz8KyZ/IC+llLKFW+bZ5Wftqxn07MM/4zukEjEBCcXbCZkAHpTFfh31c9GhTimrTBGcYTBcKLwaa5DlI= 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=cTo/Yzyr; arc=none smtp.client-ip=209.85.216.42 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="cTo/Yzyr" Received: by mail-pj1-f42.google.com with SMTP id 98e67ed59e1d1-2e2c6bc4840so2827572a91.2 for ; Sun, 27 Oct 2024 20:39:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1730086781; x=1730691581; 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=riHqjf4TEkSfIjrBl/2OcUP/uMFiYpg8/raWLqLOU7Y=; b=cTo/YzyriVjyxoo3WAYLN1GXww0W6Ok830S2VEszvPSeLEvE5Kx19S0rYdQel/0nO+ 0rivDnTkqnYhCiq+jalsniPPQkqUAo0FppzWEHe1A0X4wo9Yw700UvUsbUYCk3NjlVhP gaXGfGS3FRpgKcOarrHr40yB/UWWCST1u/5UiPqTD9nu/JpNlJ7mfnhXFOBl4J+onS2/ 2pt5sI3WoMVdANsJzb/ilVml6FFqX88fc1b5nFAb1Xb665p4369ggB2Dg9hEVeVY//VN MJmXnpj5/37mjVUbn3LkCwTBBIVaMs8p8udjjKrDDyfnUcbsN8Vwig5fI4P2lUd6r6aT M+4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730086781; x=1730691581; 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=riHqjf4TEkSfIjrBl/2OcUP/uMFiYpg8/raWLqLOU7Y=; b=dR1NKM7d5UsVts6xN85aZ37MJPxnEZF48eev7LJShLuMqzerXsN3tHmlYBzI4jFSvg OTvU3qw9wafUTDjXt4jgfK+6nqgYz1SOysZk0SbpmW8TyvzooIrkBGoy+2ihzqPFkH3h gdB1vHXzzkTU7nbsKk5XcCr3fkSg3Fvy6TlpdQJppud78tbYvzx/WJ8Yl7Hz8IE6KGZB YW8ftnAc6mkw3ZlzPCb0JYeQCq5aqc27AlECxg43TkMocjJ0gS2gxeMohWYJ67UDc+Xn CwEwiy+Mw/UXCA/iZnaxzo5XhNqFvlaVfgs6AaJQhwdvNfz1lCrZxvtZOMifpvp7tV3S aKmQ== X-Forwarded-Encrypted: i=1; AJvYcCXlV6FRbRIx1HGBkjmBXAOLNRfucgPNJ5RXSNOMrHXa2RH64idq8T7V7d+MQKbzv2+UsfWd4yST1g==@vger.kernel.org X-Gm-Message-State: AOJu0Yx3JL43YiD/N28jaBmWE/pGSiM7rzG4Dvm8C7F6gBDrzqJ8RsFN 5ZZMlRCL4+1oh7dbyK4gu7IUbErbw5bFpe2wLeQFXLrbZPXJ8m17vjygnTtlHXU= X-Google-Smtp-Source: AGHT+IFvmxoPCy/7sSomoKgH2rLyOpEyqOsKkL4VWxhavzi+tm5x5d2JksHbArO8sToXYxd+TOAmNQ== X-Received: by 2002:a17:90a:1c16:b0:2e2:e937:7141 with SMTP id 98e67ed59e1d1-2e8f107d831mr7994236a91.20.1730086781313; Sun, 27 Oct 2024 20:39:41 -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 98e67ed59e1d1-2e8e340e544sm5961888a91.0.2024.10.27.20.39.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 27 Oct 2024 20:39:41 -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 , Samuel Holland , Conor Dooley , Sunil V L , Nick Hu , linux-pm@vger.kernel.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 1/2] riscv: Add stimecmp save and restore Date: Mon, 28 Oct 2024 11:39:25 +0800 Message-Id: <20241028033928.223218-2-nick.hu@sifive.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241028033928.223218-1-nick.hu@sifive.com> References: <20241028033928.223218-1-nick.hu@sifive.com> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 Reviewed-by: Anup Patel --- arch/riscv/include/asm/suspend.h | 4 ++++ arch/riscv/kernel/suspend.c | 14 ++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/arch/riscv/include/asm/suspend.h b/arch/riscv/include/asm/suspend.h index 4ffb022b097f..dc5782b5fbad 100644 --- a/arch/riscv/include/asm/suspend.h +++ b/arch/riscv/include/asm/suspend.h @@ -18,6 +18,10 @@ struct suspend_context { unsigned long ie; #ifdef CONFIG_MMU unsigned long satp; + unsigned long stimecmp; +#if __riscv_xlen < 64 + unsigned long stimecmph; +#endif #endif }; diff --git a/arch/riscv/kernel/suspend.c b/arch/riscv/kernel/suspend.c index 9a8a0dc035b2..24b3f57d467f 100644 --- a/arch/riscv/kernel/suspend.c +++ b/arch/riscv/kernel/suspend.c @@ -30,6 +30,13 @@ void suspend_save_csrs(struct suspend_context *context) */ #ifdef CONFIG_MMU + if (riscv_has_extension_unlikely(RISCV_ISA_EXT_SSTC)) { + context->stimecmp = csr_read(CSR_STIMECMP); +#if __riscv_xlen < 64 + context->stimecmph = csr_read(CSR_STIMECMPH); +#endif + } + context->satp = csr_read(CSR_SATP); #endif } @@ -43,6 +50,13 @@ void suspend_restore_csrs(struct suspend_context *context) csr_write(CSR_IE, context->ie); #ifdef CONFIG_MMU + 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 + } + csr_write(CSR_SATP, context->satp); #endif } From patchwork Mon Oct 28 03:39:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nick Hu X-Patchwork-Id: 13852964 Received: from mail-pj1-f52.google.com (mail-pj1-f52.google.com [209.85.216.52]) (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 A5688188A18 for ; Mon, 28 Oct 2024 03:39:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730086789; cv=none; b=lOqKduI0xK2/TKZ8Y4Jic0xfU9ca9bdgMWGwpbkafJvfFk1ESdDHEDEWGcD/bihxZQknhBZdfGdwJuySTUCyGHGRTHs04sU8wxjcuah3GMUW/0X/Y39x9NzMsUfgnuKQOXydrhN72XsAthiSnjdhCsaxAGzoZbQ9de7j/8xY1Tw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730086789; c=relaxed/simple; bh=KZDYF/jddIYvikTmAtIIGcfQR++5pOmWB1T42u1iP6E=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=LsnrirYgYaRaGM5SzRc1rUgxGMqSOC86+ZsOtiZJQmkNWTslmQQLRAGtA0254GO88QkFPgm05YzW8uL9F9Jo187u74a8FSzlXOQ4hPIIzGGE3DA6B5kaA1yKCidoP1k3fCRg5vCxhhRtJdjDf9ApZoIqN9VUyq5rn/+w9lvijFI= 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=isYBWge8; arc=none smtp.client-ip=209.85.216.52 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="isYBWge8" Received: by mail-pj1-f52.google.com with SMTP id 98e67ed59e1d1-2e3d523a24dso2878063a91.0 for ; Sun, 27 Oct 2024 20:39:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1730086787; x=1730691587; 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=ARDip39wIVC1qk/I+1tz8/feGtYsfateMnYyYJ2nUtE=; b=isYBWge8LIdvrm7FIYkezvG8T+pxsE8EX2x48dmBcUUFNweE3nGhpS64P36Tu9f5Zo b37IqGjHFaKd+cQd+ikjHGqxgb1MPbX5hcb6jx113CB0fbySStSKxFDi3aB41OFo3C38 WdHwkRfLp8So9vklWC6OSv9YpylbBDZ/xtjHR9vHja97TYzFz26LaDVbJq764x7plm9h X1mI4MWKgTwdAeD+ULTJ5ppEJbneZuu11uhngex7E61fOL/WyZI/Vu8M4QZ4PiGgjjah fd1Vob5lCNxShUjqqUhDV1w5kQaIt02YEfWry+qeGKwosyCin6e/13xqkRT3lN2uW91b Smfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730086787; x=1730691587; 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=ARDip39wIVC1qk/I+1tz8/feGtYsfateMnYyYJ2nUtE=; b=oq9wYtrAyVYzfMPRLPku2KX0NdgqkgqLLoMUxZbHdsjHG/o3wy2Xg0KYE4GghRV5sj UKVGTFOjmkEQLyu3Jf6W6x88v48AGU3wDFcROvzHX32erYdEp8FnJSd2stfQzCQ7x96X K+uM1RDYLIdlOHwwelQyCvTHlpmUkCDwBdD48Ha4LiQhrCynzrHirE/zE153Oxp+X34M zBpQT94/jyQX4luvAFLl3vZb2licA8CZkXBVsU4Ta0SGhEpDz0xoIs/x8WCGYtNz1NrO OLhJoXd1wCUJK3L19LrLOnTd3lzU+fngf6Tix3qHAWd8G8AfYI5C9OldzjwPPmti4TEu XV/g== X-Forwarded-Encrypted: i=1; AJvYcCU/feE+A3REecQmJD0gzdIK7d2MN5maoQvK/ymr7zNUGDZ3q2LEjsM0wJ59XySGzdpiRQYub298Fw==@vger.kernel.org X-Gm-Message-State: AOJu0Yyp+5hZkBuOV1bSpe1Kv9Zcpe4pZAbG9VmM7KwuyFsO7xzs+B/z Elat6NAOLDngHbRL3PH1dXRpsa06qTl4EZXNclUJYttdckxTZaXtfCDr7TuawvM= X-Google-Smtp-Source: AGHT+IHaM+aLcSm1w4qstTcoHx8cZ8OUu/YAd0POOhZWcxfHlNfvpu6ayZbkZQqDbe3fkAu25t7G5Q== X-Received: by 2002:a17:90a:b109:b0:2e2:da81:40ca with SMTP id 98e67ed59e1d1-2e8f104cb14mr8132454a91.2.1730086786918; Sun, 27 Oct 2024 20:39:46 -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 98e67ed59e1d1-2e8e340e544sm5961888a91.0.2024.10.27.20.39.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 27 Oct 2024 20:39:46 -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 , Nick Hu , Sunil V L , linux-pm@vger.kernel.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Anup Patel Subject: [PATCH v3 2/2] clocksource/drivers/timer-riscv: Stop stimecmp when cpu hotplug Date: Mon, 28 Oct 2024 11:39:26 +0800 Message-Id: <20241028033928.223218-3-nick.hu@sifive.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241028033928.223218-1-nick.hu@sifive.com> References: <20241028033928.223218-1-nick.hu@sifive.com> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Stop the timer when the cpu is going to be offline otherwise the timer interrupt may be pending while performing power-down. Suggested-by: Anup Patel Link: https://lore.kernel.org/lkml/20240829033904.477200-3-nick.hu@sifive.com/T/#u Signed-off-by: Nick Hu Reviewed-by: Anup Patel --- drivers/clocksource/timer-riscv.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/clocksource/timer-riscv.c b/drivers/clocksource/timer-riscv.c index 48ce50c5f5e6..166dee14e46b 100644 --- a/drivers/clocksource/timer-riscv.c +++ b/drivers/clocksource/timer-riscv.c @@ -127,6 +127,12 @@ static int riscv_timer_starting_cpu(unsigned int cpu) static int riscv_timer_dying_cpu(unsigned int cpu) { disable_percpu_irq(riscv_clock_event_irq); + /* + * Stop the timer when the cpu is going to be offline otherwise + * the timer interrupt may be pending while performing power-down. + */ + riscv_clock_event_stop(); + return 0; }