Skip to contentSkip to conversation

Add hart state management and system suspend support for AE350

PATCH Applied Ben Zong-You Xie 3 participants 9 messages Dec 29, 2025 – Feb 23

lore
Share & tools
lore
#0 lore raw

cover Add hart state management and system suspend support for AE350

This patch series introduces support for hart state management and system suspend functionalities on the Andes AE350 platform. For the hart state management, AE350 platform supports CPU hotplug. For the system suspend, there are two platform-specific low-power modes, including deep sleep (suspend to RAM) and light sleep (suspend to standby).

Below is the patch summary:
[1/5]: The Andes System Management Unit (ATCSMU) logic is factored out into
a dedicated FDT-based HSM driver, improving code reuse and maintainability.
[2/5]: Implement the functions to save and restore platform-specific CSRs
which are lost during CPU hotplug or deep sleep.
[3/5]: Add the functions to enable/disable the cache.
[4/5]: A new Last Level Cache (LLC) driver is introduced to handle required
cache operations for deep sleep.
[5/5]: An ATCSMU-based suspend driver is implemented to support Andes deep
sleep and light sleep, providing the OS with access to standardized SBI system suspend extensions.

Ben Zong-You Xie (5):
lib: utils/hsm: factor out ATCSMU code into an HSM driver
platform: generic/andes: add CSR save and restore functions for AE350
platform
lib: utils/cache: add cache enable function
lib: utils/cache: add Andes last level cache controller
lib: utils/suspend: add Andes ATCSMU suspend driver

 include/sbi_utils/cache/cache.h              |  11 +
 include/sbi_utils/cache/fdt_cmo_helper.h     |  13 ++
 include/sbi_utils/hsm/fdt_hsm_andes_atcsmu.h |  65 ++++++
 include/sbi_utils/sys/atcsmu.h               |  59 ------
 lib/utils/cache/Kconfig                      |   5 +
 lib/utils/cache/cache.c                      |  11 +
 lib/utils/cache/fdt_andes_llcache.c          | 166 +++++++++++++++
 lib/utils/cache/fdt_cmo_helper.c             |  23 ++
 lib/utils/cache/objects.mk                   |   3 +
 lib/utils/hsm/Kconfig                        |   4 +
 lib/utils/hsm/fdt_hsm_andes_atcsmu.c         | 210 +++++++++++++++++++
 lib/utils/hsm/objects.mk                     |   5 +-
 lib/utils/reset/Kconfig                      |   2 +-
 lib/utils/reset/fdt_reset_atcwdt200.c        |  22 +-
 lib/utils/suspend/Kconfig                    |   5 +
 lib/utils/suspend/fdt_suspend_andes_atcsmu.c | 119 +++++++++++
 lib/utils/suspend/objects.mk                 |   3 +
 lib/utils/sys/Kconfig                        |   4 -
 lib/utils/sys/atcsmu.c                       |  89 --------
 lib/utils/sys/objects.mk                     |   1 -
 platform/generic/Kconfig                     |   1 -
 platform/generic/andes/ae350.c               | 147 +++++--------
 platform/generic/andes/objects.mk            |   2 +-
 platform/generic/andes/sleep.S               |  70 -------
 platform/generic/configs/defconfig           |   3 +
 platform/generic/include/andes/andes.h       |  84 +++++++-
 26 files changed, 791 insertions(+), 336 deletions(-)
 create mode 100644 include/sbi_utils/hsm/fdt_hsm_andes_atcsmu.h
 delete mode 100644 include/sbi_utils/sys/atcsmu.h
 create mode 100644 lib/utils/cache/fdt_andes_llcache.c
 create mode 100644 lib/utils/hsm/fdt_hsm_andes_atcsmu.c
 create mode 100644 lib/utils/suspend/fdt_suspend_andes_atcsmu.c
 delete mode 100644 lib/utils/sys/atcsmu.c
 delete mode 100644 platform/generic/andes/sleep.S

--
2.34.1

Signature · 3 lines
opensbi mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/opensbi
#1 lore raw

PATCH 1/5 lib: utils/hsm: factor out ATCSMU code into an HSM driver

Refactor ATCSMU (System Management Unit) support by moving it from a system utility into a dedicated FDT-based HSM driver.

Key changes include:

- Moving the functions in lib/utils/sys/atcsmu.c into the new HSM driver
- Moving hart start and stop operations on AE350 platform into the new HSM driver
- Converting the assembly-based functions in sleep.S to C code for the readability
- Updating the ATCWDT200 driver

---
 include/sbi_utils/hsm/fdt_hsm_andes_atcsmu.h |  49 ++++++
 include/sbi_utils/sys/atcsmu.h               |  59 -------
 lib/utils/hsm/Kconfig                        |   4 +
 lib/utils/hsm/fdt_hsm_andes_atcsmu.c         | 166 +++++++++++++++++++
 lib/utils/hsm/objects.mk                     |   5 +-
 lib/utils/reset/Kconfig                      |   2 +-
 lib/utils/reset/fdt_reset_atcwdt200.c        |  22 +--
 lib/utils/sys/Kconfig                        |   4 -
 lib/utils/sys/atcsmu.c                       |  89 ----------
 lib/utils/sys/objects.mk                     |   1 -
 platform/generic/Kconfig                     |   1 -
 platform/generic/andes/ae350.c               | 112 +------------
 platform/generic/andes/objects.mk            |   2 +-
 platform/generic/andes/sleep.S               |  70 --------
 platform/generic/configs/defconfig           |   1 +
 platform/generic/include/andes/andes.h       |  62 +++++++
 16 files changed, 301 insertions(+), 348 deletions(-)
 create mode 100644 include/sbi_utils/hsm/fdt_hsm_andes_atcsmu.h
 delete mode 100644 include/sbi_utils/sys/atcsmu.h
 create mode 100644 lib/utils/hsm/fdt_hsm_andes_atcsmu.c
 delete mode 100644 lib/utils/sys/atcsmu.c
 delete mode 100644 platform/generic/andes/sleep.S
include/sbi_utils/hsm/fdt_hsm_andes_atcsmu.h new file +49 -0
new file mode 100644
index 000000000000..881d8b215060
@@ -0,0 +1,49 @@
+/*
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2025 Andes Technology Corporation
+ */
+
+#ifndef __FDT_HSM_ANDES_ATCSMU_H__
+#define __FDT_HSM_ANDES_ATCSMU_H__
+
+#include <sbi/sbi_types.h>
+
+/* clang-format off */
+
+#define RESET_VEC_LO_OFFSET		0x50
+#define RESET_VEC_HI_OFFSET		0x60
+#define RESET_VEC_8CORE_OFFSET		0x1a0
+#define HARTn_RESET_VEC_LO(n)		(RESET_VEC_LO_OFFSET + \
+					((n) < 4 ? 0 : RESET_VEC_8CORE_OFFSET) + \
+					((n) * 0x4))
+#define HARTn_RESET_VEC_HI(n)		(RESET_VEC_HI_OFFSET + \
+					((n) < 4 ? 0 : RESET_VEC_8CORE_OFFSET) + \
+					((n) * 0x4))
+
+#define PCS0_CFG_OFFSET			0x80
+#define PCSm_CFG_OFFSET(i)		((i + 3) * 0x20 + PCS0_CFG_OFFSET)
+#define PCS_CFG_LIGHT_SLEEP		BIT(2)
+#define PCS_CFG_DEEP_SLEEP		BIT(3)
+
+#define PCS0_SCRATCH_OFFSET		0x84
+#define PCSm_SCRATCH_OFFSET(i)		((i + 3) * 0x20 + PCS0_SCRATCH_OFFSET)
+
+#define PCS0_WE_OFFSET			0x90
+#define PCSm_WE_OFFSET(i)		((i + 3) * 0x20 + PCS0_WE_OFFSET)
+
+#define PCS0_CTL_OFFSET			0x94
+#define PCSm_CTL_OFFSET(i)		((i + 3) * 0x20 + PCS0_CTL_OFFSET)
+#define LIGHT_SLEEP_CMD			0x3
+#define WAKEUP_CMD			0x8
+#define DEEP_SLEEP_CMD			0xb
+
+/* clang-format on */
+
+void atcsmu_set_wakeup_events(u32 events, u32 hartid);
+bool atcsmu_support_sleep_mode(u32 sleep_type, u32 hartid);
+void atcsmu_set_command(u32 pcs_ctl, u32 hartid);
+int atcsmu_set_reset_vector(u64 wakeup_addr, u32 hartid);
+u32 atcsmu_get_sleep_type(u32 hartid);
+
+#endif
include/sbi_utils/sys/atcsmu.h deleted +0 -59

59 lines not on this page · raw message

lib/utils/hsm/Kconfig +4 -0
index 94973c8fd7bd..1dfb243e3109 100644
@@ -9,6 +9,10 @@ config FDT_HSM
 
 if FDT_HSM
 
+config FDT_HSM_ANDES_ATCSMU
+	bool "FDT Andes ATCSMU driver"
+	default n
+
 config FDT_HSM_RPMI
 	bool "FDT RPMI HSM driver"
 	depends on FDT_MAILBOX && RPMI_MAILBOX
lib/utils/hsm/fdt_hsm_andes_atcsmu.c new file +166 -0

166 lines not on this page · raw message

lib/utils/hsm/objects.mk +4 -1
index 0d0054494f18..f76af03c5c0a 100644
@@ -7,6 +7,9 @@
 #   Anup Patel <[email protected]>
 #
 
+carray-fdt_early_drivers-$(CONFIG_FDT_HSM_ANDES_ATCSMU) += fdt_hsm_andes_atcsmu
+libsbiutils-objs-$(CONFIG_FDT_HSM_ANDES_ATCSMU) += hsm/fdt_hsm_andes_atcsmu.o
+
 carray-fdt_early_drivers-$(CONFIG_FDT_HSM_RPMI) += fdt_hsm_rpmi
 libsbiutils-objs-$(CONFIG_FDT_HSM_RPMI) += hsm/fdt_hsm_rpmi.o
 
@@ -14,4 +17,4 @@ carray-fdt_early_drivers-$(CONFIG_FDT_HSM_SPACEMIT) += fdt_hsm_spacemit
 libsbiutils-objs-$(CONFIG_FDT_HSM_SPACEMIT) += hsm/fdt_hsm_spacemit.o
 
 carray-fdt_early_drivers-$(CONFIG_FDT_HSM_SIFIVE_TMC0) += fdt_hsm_sifive_tmc0
-libsbiutils-objs-$(CONFIG_FDT_HSM_SIFIVE_TMC0) += hsm/fdt_hsm_sifive_tmc0.o
\ No newline at end of file
+libsbiutils-objs-$(CONFIG_FDT_HSM_SIFIVE_TMC0) += hsm/fdt_hsm_sifive_tmc0.o
lib/utils/reset/Kconfig +1 -1
index 68e667163b5d..4835921f4b90 100644
@@ -11,7 +11,7 @@ if FDT_RESET
 
 config FDT_RESET_ATCWDT200
 	bool "Andes WDT FDT reset driver"
-	depends on SYS_ATCSMU
+	depends on FDT_HSM_ANDES_ATCSMU
 	default n
 
 config FDT_RESET_GPIO
lib/utils/reset/fdt_reset_atcwdt200.c +5 -17
index 2304582a9513..5dad8ac96d48 100644
@@ -1,10 +1,7 @@
 /*
  * SPDX-License-Identifier: BSD-2-Clause
  *
- * Copyright (c) 2022 Andes Technology Corporation
- *
- * Authors:
- *   Yu Chien Peter Lin <[email protected]>
+ * Copyright (c) 2025 Andes Technology Corporation
  */
 
 #include <libfdt.h>
@@ -15,7 +12,7 @@
 #include <sbi/sbi_system.h>
 #include <sbi_utils/fdt/fdt_driver.h>
 #include <sbi_utils/fdt/fdt_helper.h>
-#include <sbi_utils/sys/atcsmu.h>
+#include <sbi_utils/hsm/fdt_hsm_andes_atcsmu.h>
 
 #define ATCWDT200_WP_NUM 0x5aa5
 #define WREN_REG 0x18
@@ -41,8 +38,9 @@
 #define CLK_PCLK (1 << 1)
 #define WDT_EN (1 << 0)
 
+#define AE350_FLASH_BASE 0x80000000
+
 static volatile char *wdt_addr = NULL;
-static struct smu_data smu = { 0 };
 
 static int ae350_system_reset_check(u32 type, u32 reason)
 {
@@ -59,7 +57,7 @@ static int ae350_system_reset_check(u32 type, u32 reason)
 static void ae350_system_reset(u32 type, u32 reason)
 {
 	sbi_for_each_hartindex(i)
-		if (smu_set_reset_vector(&smu, FLASH_BASE, i))
+		if (atcsmu_set_reset_vector(AE350_FLASH_BASE, i))
 			goto fail;
 
 	/* Program WDT control register  */
@@ -88,16 +86,6 @@ static int atcwdt200_reset_init(const void *fdt, int nodeoff,
 		return SBI_ENODEV;
 
 	wdt_addr = (volatile char *)(unsigned long)reg_addr;
-
-	/*
-	 * The reset device requires smu to program the reset
-	 * vector for each hart.
-	 */
-	if (fdt_parse_compat_addr(fdt, &reg_addr, "andestech,atcsmu"))
-		return SBI_ENODEV;
-
-	smu.addr = (unsigned long)reg_addr;
-
 	sbi_system_reset_add_device(&atcwdt200_reset);
 
 	return 0;
lib/utils/sys/Kconfig +0 -4
index a22191cd7c26..fc388665524d 100644
@@ -2,10 +2,6 @@
 
 menu "System Device Support"
 
-config SYS_ATCSMU
-	bool "Andes System Management Unit (SMU) support"
-	default n
-
 config SYS_HTIF
 	bool "Host transfere interface (HTIF) support"
 	default n
lib/utils/sys/atcsmu.c deleted +0 -89

89 lines not on this page · raw message

lib/utils/sys/objects.mk +0 -1
index 409d7e8c7ef6..d9c67077a3a6 100644
@@ -8,4 +8,3 @@
 #
 
 libsbiutils-objs-$(CONFIG_SYS_HTIF) += sys/htif.o
-libsbiutils-objs-$(CONFIG_SYS_ATCSMU) += sys/atcsmu.o
platform/generic/Kconfig +0 -1
index 716fab42a7b7..0c11fbd2c29f 100644
@@ -36,7 +36,6 @@ config PLATFORM_ALLWINNER_D1
 
 config PLATFORM_ANDES_AE350
 	bool "Andes AE350 support"
-	select SYS_ATCSMU
 	select ANDES_PMU
 	select ANDES_PMA
 	default n
platform/generic/andes/ae350.c +8 -104

129 lines not on this page · raw message

platform/generic/andes/objects.mk +1 -1
index f85ad48162b2..660546c312fe 100644
@@ -3,7 +3,7 @@
 #
 
 carray-platform_override_modules-$(CONFIG_PLATFORM_ANDES_AE350) += andes_ae350
-platform-objs-$(CONFIG_PLATFORM_ANDES_AE350) += andes/ae350.o andes/sleep.o
+platform-objs-$(CONFIG_PLATFORM_ANDES_AE350) += andes/ae350.o
 
 carray-platform_override_modules-$(CONFIG_PLATFORM_ANDES_QILAI) += andes_qilai
 platform-objs-$(CONFIG_PLATFORM_ANDES_QILAI) += andes/qilai.o
platform/generic/andes/sleep.S deleted +0 -70

70 lines not on this page · raw message

platform/generic/configs/defconfig +1 -0
index aab1560f2399..d85da930edbc 100644
@@ -23,6 +23,7 @@ CONFIG_FDT_GPIO_DESIGNWARE=y
 CONFIG_FDT_GPIO_SIFIVE=y
 CONFIG_FDT_GPIO_STARFIVE=y
 CONFIG_FDT_HSM=y
+CONFIG_FDT_HSM_ANDES_ATCSMU=y
 CONFIG_FDT_HSM_RPMI=y
 CONFIG_FDT_HSM_SIFIVE_TMC0=y
 CONFIG_FDT_I2C=y
platform/generic/include/andes/andes.h +62 -0

85 lines not on this page · raw message

Signature · 7 lines
2.34.1


-- 
opensbi mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/opensbi
#2 lore raw

PATCH 2/5 platform: generic/andes: add CSR save and restore functions for AE350 platform

In reply to Ben Zong-You Xie

Implement a save and restore mechanism for Andes-specific CSRs to support hardware power-saving modes, such as CPU hotplug or suspend to RAM.

---
 lib/utils/hsm/fdt_hsm_andes_atcsmu.c   |  1 +
 platform/generic/andes/ae350.c         | 55 ++++++++++++++++++++++++++
 platform/generic/include/andes/andes.h | 22 ++++++++++-
 3 files changed, 77 insertions(+), 1 deletion(-)
lib/utils/hsm/fdt_hsm_andes_atcsmu.c +1 -0
index ee7873dc6d00..3fe931aa1816 100644
@@ -126,6 +126,7 @@ static int ae350_hart_stop(void)
 	if (rc)
 		return SBI_EFAIL;
 
+	ae350_non_ret_save(sbi_scratch_thishart_ptr());
 	ae350_disable_coherency();
 	wfi();
 	return 0;
platform/generic/andes/ae350.c +55 -0

73 lines not on this page · raw message

platform/generic/include/andes/andes.h +21 -1
index 1b5893925c10..dd2451718d00 100644
@@ -10,16 +10,21 @@
 #include <sbi/sbi_scratch.h>
 
 /* Memory and Miscellaneous Registers */
+#define CSR_MPFT_CTL		0x7c5
 #define CSR_MCACHE_CTL		0x7ca
 #define CSR_MCCTLCOMMAND	0x7cc
+#define CSR_MMISC_CTL		0x7d0
 
 /* Configuration Control & Status Registers */
 #define CSR_MICM_CFG		0xfc0
 #define CSR_MDCM_CFG		0xfc1
 #define CSR_MMSC_CFG		0xfc2
 
-/* Machine Trap Related Registers */
+/* Trap Related Registers */
+#define CSR_MXSTATUS		0x7c4
 #define CSR_MSLIDELEG		0x7d5
+#define CSR_SLIE		0x9c4
+#define CSR_SLIP		0x9c5
 
 /* Counter Related Registers */
 #define CSR_MCOUNTERWEN		0x7ce
@@ -80,6 +85,21 @@
 
 #endif /* __ASSEMBLER__ */
 
+struct andes_hart_data {
+	unsigned long mcache_ctl;
+	unsigned long mmisc_ctl;
+	unsigned long mpft_ctl;
+	unsigned long mslideleg;
+	unsigned long mxstatus;
+	unsigned long slie;
+	unsigned long slip;
+	unsigned long pmacfg0;
+	unsigned long pmacfg2;
+	unsigned long pmaaddrX[16];
+};
+
+void ae350_non_ret_save(struct sbi_scratch *scratch);
+void ae350_non_ret_restore(struct sbi_scratch *scratch);
 void ae350_enable_coherency_warmboot(void);
 
 /*
Signature · 7 lines
2.34.1


-- 
opensbi mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/opensbi
#3 lore raw

PATCH 3/5 lib: utils/cache: add cache enable function

In reply to Ben Zong-You Xie

Add functions to enable/disable the cache.

---
 include/sbi_utils/cache/cache.h          | 11 +++++++++++
 include/sbi_utils/cache/fdt_cmo_helper.h | 13 +++++++++++++
 lib/utils/cache/cache.c                  | 11 +++++++++++
 lib/utils/cache/fdt_cmo_helper.c         | 23 +++++++++++++++++++++++
 4 files changed, 58 insertions(+)
include/sbi_utils/cache/cache.h +11 -0
index 70d9286f9a0a..de6cf50d1da6 100644
@@ -19,6 +19,8 @@ struct cache_ops {
 	int (*warm_init)(struct cache_device *dev);
 	/** Flush entire cache **/
 	int (*cache_flush_all)(struct cache_device *dev);
+	/** Enable/Disable cache **/
+	int (*cache_enable)(struct cache_device *dev, bool enable);
 };
 
 struct cache_device {
@@ -66,4 +68,13 @@ int cache_add(struct cache_device *dev);
  */
 int cache_flush_all(struct cache_device *dev);
 
+/**
+ * Enable/Disable the cache
+ *
+ * @param dev the cache to enable/disable
+ *
+ * @return 0 on success, or a negative error code on failure
+ */
+int cache_enable(struct cache_device *dev, bool enable);
+
 #endif
include/sbi_utils/cache/fdt_cmo_helper.h +13 -0
index a6a28db9ede2..8b3ec89b9c15 100644
@@ -22,6 +22,19 @@ int fdt_cmo_private_flc_flush_all(void);
  */
 int fdt_cmo_llc_flush_all(void);
 
+/**
+ * Enable/Disable the private first level cache of the current hart
+ *
+ * @return 0 on success, or a negative error code on failure
+ */
+int fdt_cmo_private_flc_enable(bool enable);
+
+/**
+ * Enable/Disable the last level cache of the current hart
+ *
+ * @return 0 on success, or a negative error code on failure
+ */
+int fdt_cmo_llc_enable(bool enable);
 /**
  * Initialize the cache devices for each hart
  *
lib/utils/cache/cache.c +11 -0
index 6bc3d10e9347..2810d5e9570c 100644
@@ -44,3 +44,14 @@ int cache_flush_all(struct cache_device *dev)
 
 	return dev->ops->cache_flush_all(dev);
 }
+
+int cache_enable(struct cache_device *dev, bool enable)
+{
+	if (!dev)
+		return SBI_ENODEV;
+
+	if (!dev->ops || !dev->ops->cache_enable)
+		return SBI_ENOTSUPP;
+
+	return dev->ops->cache_enable(dev, enable);
+}
lib/utils/cache/fdt_cmo_helper.c +23 -0
index d87bab76ca00..3ab8abe667ba 100644
@@ -41,6 +41,29 @@ int fdt_cmo_llc_flush_all(void)
 	return cache_flush_all(llc);
 }
 
+int fdt_cmo_private_flc_enable(bool enable)
+{
+	struct cache_device *flc = get_hart_flc(sbi_scratch_thishart_ptr());
+
+	if (!flc || !flc->cpu_private)
+		return SBI_ENODEV;
+
+	return cache_enable(flc, enable);
+}
+
+int fdt_cmo_llc_enable(bool enable)
+{
+	struct cache_device *llc = get_hart_flc(sbi_scratch_thishart_ptr());
+
+	if (!llc)
+		return SBI_ENODEV;
+
+	while (llc->next)
+		llc = llc->next;
+
+	return cache_enable(llc, enable);
+}
+
 static int fdt_cmo_cold_init(const void *fdt)
 {
 	struct sbi_scratch *scratch;
Signature · 7 lines
2.34.1


-- 
opensbi mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/opensbi
#4 lore raw

PATCH 4/5 lib: utils/cache: add Andes last level cache controller

In reply to Ben Zong-You Xie

Introduce a FDT-based driver for the Andes Last Level Cache (LLC) controller to support cache maintenance operations.

---
 include/sbi_utils/hsm/fdt_hsm_andes_atcsmu.h |  15 ++
 lib/utils/cache/Kconfig                      |   5 +
 lib/utils/cache/fdt_andes_llcache.c          | 166 +++++++++++++++++++
 lib/utils/cache/objects.mk                   |   3 +
 lib/utils/hsm/fdt_hsm_andes_atcsmu.c         |  10 ++
 platform/generic/configs/defconfig           |   1 +
 6 files changed, 200 insertions(+)
 create mode 100644 lib/utils/cache/fdt_andes_llcache.c
include/sbi_utils/hsm/fdt_hsm_andes_atcsmu.h +15 -0
index 881d8b215060..ef851b7501b5 100644
@@ -11,6 +11,8 @@
 
 /* clang-format off */
 
+#define SCRATCH_PAD_OFFSET		0x40
+
 #define RESET_VEC_LO_OFFSET		0x50
 #define RESET_VEC_HI_OFFSET		0x60
 #define RESET_VEC_8CORE_OFFSET		0x1a0
@@ -31,6 +33,9 @@
 
 #define PCS0_WE_OFFSET			0x90
 #define PCSm_WE_OFFSET(i)		((i + 3) * 0x20 + PCS0_WE_OFFSET)
+#define PCS_WAKEUP_RTC_ALARM_MASK	BIT(2)
+#define PCS_WAKEUP_UART2_MASK		BIT(9)
+#define PCS_WAKEUP_MSIP_MASK		BIT(29)
 
 #define PCS0_CTL_OFFSET			0x94
 #define PCSm_CTL_OFFSET(i)		((i + 3) * 0x20 + PCS0_CTL_OFFSET)
@@ -38,6 +43,14 @@
 #define WAKEUP_CMD			0x8
 #define DEEP_SLEEP_CMD			0xb
 
+#define PCS0_STATUS_OFFSET		0x98
+#define PCSm_STATUS_OFFSET(i)		((i + 3) * 0x20 + PCS0_STATUS_OFFSET)
+#define PD_TYPE_MASK			GENMASK(2, 0)
+#define PD_TYPE_SLEEP			2
+#define PD_STATUS_MASK			GENMASK(7, 3)
+#define PD_STATUS_LIGHT_SLEEP		0
+#define PD_STATUS_DEEP_SLEEP		0x10
+
 /* clang-format on */
 
 void atcsmu_set_wakeup_events(u32 events, u32 hartid);
@@ -45,5 +58,7 @@ bool atcsmu_support_sleep_mode(u32 sleep_type, u32 hartid);
 void atcsmu_set_command(u32 pcs_ctl, u32 hartid);
 int atcsmu_set_reset_vector(u64 wakeup_addr, u32 hartid);
 u32 atcsmu_get_sleep_type(u32 hartid);
+void atcsmu_write_scratch(u32 value);
+u32 atcsmu_read_scratch(void);
 
 #endif
lib/utils/cache/Kconfig +5 -0
index be7d57c37d24..ea815dc4ef03 100644
@@ -10,6 +10,11 @@ config FDT_CACHE
 
 if FDT_CACHE
 
+config FDT_CACHE_ANDES_LLCACHE
+	bool "Andes FDT last level cache driver"
+	depends on FDT_HSM_ANDES_ATCSMU
+	default n
+
 config FDT_CACHE_SIFIVE_CCACHE
 	bool "SiFive CCACHE FDT cache driver"
 	default n
lib/utils/cache/fdt_andes_llcache.c new file +166 -0

166 lines not on this page · raw message

lib/utils/cache/objects.mk +3 -0
index aa76adc2e3bc..6c9bce84903e 100644
@@ -8,6 +8,9 @@ libsbiutils-objs-$(CONFIG_FDT_CACHE) += cache/fdt_cache.o
 libsbiutils-objs-$(CONFIG_FDT_CACHE) += cache/fdt_cache_drivers.carray.o
 libsbiutils-objs-$(CONFIG_FDT_CACHE) += cache/fdt_cmo_helper.o
 
+carray-fdt_cache_drivers-$(CONFIG_FDT_CACHE_ANDES_LLCACHE) += fdt_andes_llcache
+libsbiutils-objs-$(CONFIG_FDT_CACHE_ANDES_LLCACHE) += cache/fdt_andes_llcache.o
+
 carray-fdt_cache_drivers-$(CONFIG_FDT_CACHE_SIFIVE_CCACHE) += fdt_sifive_ccache
 libsbiutils-objs-$(CONFIG_FDT_CACHE_SIFIVE_CCACHE) += cache/fdt_sifive_ccache.o
 
lib/utils/hsm/fdt_hsm_andes_atcsmu.c +10 -0
index 3fe931aa1816..32f6fef808c6 100644
@@ -84,6 +84,16 @@ u32 atcsmu_get_sleep_type(u32 hartid)
 	return readl_relaxed((char *)atcsmu_base + PCSm_SCRATCH_OFFSET(hartid));
 }
 
+void atcsmu_write_scratch(u32 value)
+{
+	writel_relaxed(value, (char *)atcsmu_base + SCRATCH_PAD_OFFSET);
+}
+
+u32 atcsmu_read_scratch(void)
+{
+	return readl_relaxed((char *)atcsmu_base + SCRATCH_PAD_OFFSET);
+}
+
 static int ae350_hart_start(u32 hartid, ulong saddr)
 {
 	u32 hartindex = sbi_hartid_to_hartindex(hartid);
platform/generic/configs/defconfig +1 -0
index d85da930edbc..4b7615d6c51b 100644
@@ -13,6 +13,7 @@ CONFIG_PLATFORM_THEAD=y
 CONFIG_PLATFORM_MIPS_P8700=y
 CONFIG_PLATFORM_SPACEMIT_K1=y
 CONFIG_FDT_CACHE=y
+CONFIG_FDT_CACHE_ANDES_LLCACHE=y
 CONFIG_FDT_CACHE_SIFIVE_CCACHE=y
 CONFIG_FDT_CACHE_SIFIVE_EC=y
 CONFIG_FDT_CACHE_SIFIVE_PL2=y
Signature · 7 lines
2.34.1


-- 
opensbi mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/opensbi
#5 lore raw

PATCH 5/5 lib: utils/suspend: add Andes ATCSMU suspend driver

In reply to Ben Zong-You Xie

Implement a system-wide suspend driver for the Andes AE350 platform. This driver supports Andes-specific deep sleep (suspend to RAM) and light sleep (suspend to standby) functionalities via the ATCSMU.

The major differences between deep sleep and light sleep are:

- Power Domain and Resume Path: Deep sleep powers down the core domain. Consequently, harts waking from deep sleep resume from the reset vector. Light sleep utilizes clock gating to the core domain; harts maintain state and resume execution at the instruction immediately following the WFI instruction.

- Primary Hart Wakeup: In both modes, the primary hart is woken by UART or RTC alarm interrupts. In deep sleep, the primary hart is additionally responsible for re-enabling the Last Level Cache (LLC) and restoring Andes-specific CSRs.

- Secondary Hart Wakeup: In light sleep, secondary harts are woken by an IPI sent from the primary hart. In deep sleep, they are woken by an ATCSMU hardware wake-up command. Furthermore, secondary harts must restore Andes-specific CSRs when returning from deep sleep.

---
 include/sbi_utils/hsm/fdt_hsm_andes_atcsmu.h |   1 +
 lib/utils/hsm/fdt_hsm_andes_atcsmu.c         |  49 ++++++--
 lib/utils/suspend/Kconfig                    |   5 +
 lib/utils/suspend/fdt_suspend_andes_atcsmu.c | 119 +++++++++++++++++++
 lib/utils/suspend/objects.mk                 |   3 +
 platform/generic/andes/ae350.c               |  10 +-
 platform/generic/configs/defconfig           |   1 +
 7 files changed, 178 insertions(+), 10 deletions(-)
 create mode 100644 lib/utils/suspend/fdt_suspend_andes_atcsmu.c
include/sbi_utils/hsm/fdt_hsm_andes_atcsmu.h +1 -0
index ef851b7501b5..5e71fab7c69e 100644
@@ -60,5 +60,6 @@ int atcsmu_set_reset_vector(u64 wakeup_addr, u32 hartid);
 u32 atcsmu_get_sleep_type(u32 hartid);
 void atcsmu_write_scratch(u32 value);
 u32 atcsmu_read_scratch(void);
+bool atcsmu_pcs_is_sleep(u32 hartid, bool deep_sleep);
 
 #endif
lib/utils/hsm/fdt_hsm_andes_atcsmu.c +41 -8

73 lines not on this page · raw message

lib/utils/suspend/Kconfig +5 -0
index 6c09d95253d2..8d05aff67ace 100644
@@ -9,6 +9,11 @@ config FDT_SUSPEND
 
 if FDT_SUSPEND
 
+config FDT_SUSPEND_ANDES_ATCSMU
+	bool "FDT Andes ATCSMU suspend driver"
+	depends on FDT_HSM_ANDES_ATCSMU && FDT_CACHE_ANDES_LLCACHE
+	default n
+
 config FDT_SUSPEND_RPMI
 	bool "FDT RPMI suspend driver"
 	depends on FDT_MAILBOX && RPMI_MAILBOX
lib/utils/suspend/fdt_suspend_andes_atcsmu.c new file +119 -0

119 lines not on this page · raw message

lib/utils/suspend/objects.mk +3 -0
index 1fb29b5e7941..fb1ad9ae34c7 100644
@@ -7,6 +7,9 @@
 #   Anup Patel <[email protected]>
 #
 
+carray-fdt_early_drivers-$(CONFIG_FDT_SUSPEND_ANDES_ATCSMU) += fdt_suspend_andes_atcsmu
+libsbiutils-objs-$(CONFIG_FDT_SUSPEND_ANDES_ATCSMU) += suspend/fdt_suspend_andes_atcsmu.o
+
 carray-fdt_early_drivers-$(CONFIG_FDT_SUSPEND_RPMI) += fdt_suspend_rpmi
 libsbiutils-objs-$(CONFIG_FDT_SUSPEND_RPMI) += suspend/fdt_suspend_rpmi.o
 
platform/generic/andes/ae350.c +8 -2
index 9bd1554394b7..4cf7e26def54 100644
@@ -8,9 +8,12 @@
 #include <andes/andes_pmu.h>
 #include <andes/andes_sbi.h>
 #include <platform_override.h>
+#include <sbi/sbi_ecall_interface.h>
+#include <sbi/riscv_asm.h>
 #include <sbi/sbi_init.h>
 #include <sbi/sbi_scratch.h>
 #include <sbi_utils/fdt/fdt_helper.h>
+#include <sbi_utils/hsm/fdt_hsm_andes_atcsmu.h>
 
 static unsigned long andes_hart_data_offset;
 extern void _start_warm(void);
@@ -59,14 +62,17 @@ void ae350_enable_coherency_warmboot(void)
 
 static int ae350_early_init(bool cold_boot)
 {
+	u32 hartid = current_hartid();
+	u32 sleep_type = atcsmu_get_sleep_type(hartid);
+
 	if (cold_boot) {
 		andes_hart_data_offset = sbi_scratch_alloc_offset(sizeof(struct andes_hart_data));
 		if (!andes_hart_data_offset)
 			return SBI_ENOMEM;
 	}
 
-	/* Don't restore Andes CSRs during boot */
-	if (sbi_init_count(current_hartindex()))
+	/* Don't restore Andes CSRs during boot or wake up from light sleep */
+	if (sbi_init_count(current_hartindex()) && sleep_type == SBI_SUSP_SLEEP_TYPE_SUSPEND)
 		ae350_non_ret_restore(sbi_scratch_thishart_ptr());
 
 	return generic_early_init(cold_boot);
platform/generic/configs/defconfig +1 -0
index 4b7615d6c51b..19a73a247765 100644
@@ -62,6 +62,7 @@ CONFIG_FDT_SERIAL_UART8250=y
 CONFIG_FDT_SERIAL_XILINX_UARTLITE=y
 CONFIG_SERIAL_SEMIHOSTING=y
 CONFIG_FDT_SUSPEND=y
+CONFIG_FDT_SUSPEND_ANDES_ATCSMU=y
 CONFIG_FDT_SUSPEND_RPMI=y
 CONFIG_FDT_SUSPEND_SIFIVE_SMC0=y
 CONFIG_FDT_TIMER=y
Signature · 7 lines
2.34.1


-- 
opensbi mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/opensbi
#6 lore raw

Re: [PATCH 5/5] lib: utils/suspend: add Andes ATCSMU suspend driver

On Mon, Dec 29, 2025 at 03:19:14PM +0800, Ben Zong-You Xie wrote:
...

Quoted 22 lines
lib/utils/hsm/fdt_hsm_andes_atcsmu.c +13 -5
@@ -130,16 +152,27 @@ static int ae350_hart_stop(void)
 	/* Prevent the core leaving the WFI mode unexpectedly */
 	csr_write(CSR_MIE, 0);
 
-	atcsmu_set_wakeup_events(0x0, hartid);
-	atcsmu_set_command(DEEP_SLEEP_CMD, hartid);
-	rc = atcsmu_set_reset_vector((u64)ae350_enable_coherency_warmboot, hartid);
-	if (rc)
-		return SBI_EFAIL;
+	if (sleep_type == SBI_SUSP_AE350_LIGHT_SLEEP) {
+		csr_write(CSR_MIE, MIP_MSIP);
+		atcsmu_set_wakeup_events(PCS_WAKEUP_MSIP_MASK, hartid);
+		atcsmu_set_command(LIGHT_SLEEP_CMD, hartid);
+	} else if (sleep_type == SBI_SUSP_SLEEP_TYPE_SUSPEND) {
+		atcsmu_set_wakeup_events(0x0, hartid);
+		atcsmu_set_command(DEEP_SLEEP_CMD, hartid);
+		rc = atcsmu_set_reset_vector((u64)ae350_enable_coherency_warmboot, hartid);
+		if (rc)
+			return SBI_EFAIL;
+
+		ae350_non_ret_save(sbi_scratch_thishart_ptr());
+	}

lib/utils/hsm/fdt_hsm_andes_atcsmu.c static int ae350_hart_stop(void) · line 175

Quoted 10 lines
lib/utils/hsm/fdt_hsm_andes_atcsmu.c +5 -2
 
-	ae350_non_ret_save(sbi_scratch_thishart_ptr());
 	ae350_disable_coherency();
 	wfi();
-	return 0;
+
+	/* Light sleep resumes here */
+	ae350_enable_coherency();
+
+	return SBI_ENOTSUPP;

I just skimmed this patch really fast, so I probably missed something, but it seems odd to return SBI_ENOTSUPP here.

Thanks,
drew

Signature · 3 lines
opensbi mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/opensbi
#7 lore raw

Re: [PATCH 5/5] lib: utils/suspend: add Andes ATCSMU suspend driver

Quoted 14 lines

lib/utils/hsm/fdt_hsm_andes_atcsmu.c static int ae350_hart_stop(void) · line 175

Quoted 10 lines
lib/utils/hsm/fdt_hsm_andes_atcsmu.c +5 -2
-     ae350_non_ret_save(sbi_scratch_thishart_ptr());
      ae350_disable_coherency();
      wfi();
-     return 0;
+
+     /* Light sleep resumes here */
+     ae350_enable_coherency();
+
+     return SBI_ENOTSUPP;

I just skimmed this patch really fast, so I probably missed something, but it seems odd to return SBI_ENOTSUPP here.

Quoted 2 lines

Thanks,
drew

Hi Drew,

The reason for returning SBI_ENOTSUPP here is to satisfy the logic in sbi_hsm_exit(). In sbi_hsm_exit(), there is a specific check:

  if (hsm_device_has_hart_hotplug()) {
    if (hsm_device_hart_stop() != SBI_ENOTSUPP)
      goto fail_exit;
  }

/**
* As platform is lacking support for hotplug, directly jump to warmboot
* and wait for interrupts in warmboot. We do it preemptively in order
* preserve the hart states and reuse the code path for hotplug. */
jump_warmboot();

If we return 0 (SBI_OK), the condition (0 != SBI_ENOTSUPP) evaluates to true, and the code jumps to fail_exit, hanging the hart.

Returning SBI_ENOTSUPP allows the execution to fall through to the jump_warmboot() path, which is the intended behavior for 'light sleep' on AE350 platform.

Signature · 3 lines
opensbi mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/opensbi
Applied
#8 lore raw
In reply to Ben Zong-You Xie
Quoted 20 lines · Ben Zong-You Xie

This patch series introduces support for hart state management and system suspend functionalities on the Andes AE350 platform. For the hart state management, AE350 platform supports CPU hotplug. For the system suspend, there are two platform-specific low-power modes, including deep sleep (suspend to RAM) and light sleep (suspend to standby).

Below is the patch summary:
[1/5]: The Andes System Management Unit (ATCSMU) logic is factored out into
a dedicated FDT-based HSM driver, improving code reuse and maintainability.
[2/5]: Implement the functions to save and restore platform-specific CSRs
which are lost during CPU hotplug or deep sleep.
[3/5]: Add the functions to enable/disable the cache.
[4/5]: A new Last Level Cache (LLC) driver is introduced to handle required
cache operations for deep sleep.
[5/5]: An ATCSMU-based suspend driver is implemented to support Andes deep
sleep and light sleep, providing the OS with access to standardized SBI system suspend extensions.

Quoted 7 lines

Ben Zong-You Xie (5):
lib: utils/hsm: factor out ATCSMU code into an HSM driver
platform: generic/andes: add CSR save and restore functions for AE350
platform
lib: utils/cache: add cache enable function
lib: utils/cache: add Andes last level cache controller
lib: utils/suspend: add Andes ATCSMU suspend driver

Applied this series to the riscv/opensbi repo.

Thanks,
Anup

Signature · 3 lines
opensbi mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/opensbi