Skip to contentSkip to conversation

Implement hart hotplug using HSM extension for AE350

PATCH Superseded Yu Chien Peter Lin 2 participants 9 messages Jan 18, 2023

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v2 cover Implement hart hotplug using HSM extension for AE350

The following patches include implementing hotplug with ATCSMU deep sleep mode using HSM extension, introduce ATCSMU system device and some fixes, base on OpenSBI v1.2 and test on AE350 platform with the CPU listed below:

RV64:
* AX45MP quad-core
* AX45MP octa-core
* AX25MP quad-core

RV32:
* A45MP quad-core
* A25MP quad-core

Changes v1 -> v2:
* Drop patch for adding secondary_boot callback
* Add a PATCH4 to move ATCSMU related code to lib/utils/sys
* Include RB tags

Yu Chien Peter Lin (6):
docs: generic.md: fix typo of andes-ae350
lib: sbi_hsm: handle failure when hart_stop returns SBI_ENOTSUPP
include: types: add always inline compiler attribute
lib: utils: atcsmu: Add Andes System Management Unit support
platform: andes/ae350: Implement hart hotplug using HSM extension
lib: reset/fdt_reset_atcwdt200: Use defined macros and function in
atcsmu.h

 docs/platform/generic.md                 |  2 +-
 include/sbi/sbi_hsm.h                    |  8 ++-
 include/sbi/sbi_types.h                  |  1 +
 include/sbi_utils/sys/atcsmu.h           | 63 ++++++++++++++++++
 lib/sbi/sbi_hsm.c                        |  7 +-
 lib/utils/reset/fdt_reset_atcwdt200.c    | 13 +---
 lib/utils/sys/Kconfig                    |  4 ++
 lib/utils/sys/atcsmu.c                   | 60 +++++++++++++++++
 lib/utils/sys/objects.mk                 |  1 +
 platform/generic/Kconfig                 |  1 +
 platform/generic/andes/ae350.c           | 84 ++++++++++++++++++++++++
 platform/generic/andes/objects.mk        |  2 +-
 platform/generic/andes/sleep.S           | 70 ++++++++++++++++++++
 platform/generic/include/andes/andes45.h | 10 +++
 14 files changed, 308 insertions(+), 18 deletions(-)
 create mode 100644 include/sbi_utils/sys/atcsmu.h
 create mode 100644 lib/utils/sys/atcsmu.c
 create mode 100644 platform/generic/andes/sleep.S
 create mode 100644 platform/generic/include/andes/andes45.h
Signature · 1 line
2.34.1
#1 lore raw

PATCH v2 1/6 docs: generic.md: fix typo of andes-ae350

Fix hyperlink due to the typo.

---
 docs/platform/generic.md | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
docs/platform/generic.md +1 -1
index 8e4cf2d..c29eb04 100644
@@ -53,7 +53,7 @@ RISC-V Platforms Using Generic Platform
 * **Spike** (*[spike.md]*)
 * **T-HEAD C9xx series Processors** (*[thead-c9xx.md]*)
 
-[andes-ae350.md]: andse-ae350.md
+[andes-ae350.md]: andes-ae350.md
 [qemu_virt.md]: qemu_virt.md
 [renesas-rzfive.md]: renesas-rzfive.md
 [shakti_cclass.md]: shakti_cclass.md
Signature · 1 line
2.34.1
#2 lore raw

PATCH v2 2/6 lib: sbi_hsm: handle failure when hart_stop returns SBI_ENOTSUPP

In reply to Yu Chien Peter Lin

Make use of generic warm-boot path when platform hart_stop callback returns SBI_ENOTSUPP, in case certain hart can not turn off its power domain, or it detects some error occured in power management unit, it can fall through warm-boot flow and wait for interrupt in sbi_hsm_hart_wait().

Also improves comment in sbi_hsm_hart_wait().

---
 include/sbi/sbi_hsm.h | 8 ++++++--
 lib/sbi/sbi_hsm.c     | 7 +++----
 2 files changed, 9 insertions(+), 6 deletions(-)
include/sbi/sbi_hsm.h +6 -2
index c2a728a..1170127 100644
@@ -21,8 +21,12 @@ struct sbi_hsm_device {
 	int (*hart_start)(u32 hartid, ulong saddr);
 
 	/**
-	 * Stop (or power-down) the current hart from running. This call
-	 * doesn't expect to return if success.
+	 * Stop (or power-down) the current hart from running.
+	 *
+	 * Return SBI_ENOTSUPP if the hart does not support platform-specific
+	 * stop actions.
+	 *
+	 * For successful stop, the call won't return.
 	 */
 	int (*hart_stop)(void);
 
lib/sbi/sbi_hsm.c +3 -4
index c0a5505..d4cce4a 100644
@@ -116,7 +116,7 @@ static void sbi_hsm_hart_wait(struct sbi_scratch *scratch, u32 hartid)
 	/* Set MSIE and MEIE bits to receive IPI */
 	csr_set(CSR_MIE, MIP_MSIP | MIP_MEIP);
 
-	/* Wait for hart_add call*/
+	/* Wait for state transition requested by sbi_hsm_hart_start() */
 	while (atomic_read(&hdata->state) != SBI_HSM_STATE_START_PENDING) {
 		wfi();
 	};
@@ -228,9 +228,8 @@ void __noreturn sbi_hsm_exit(struct sbi_scratch *scratch)
 		goto fail_exit;
 
 	if (hsm_device_has_hart_hotplug()) {
-		hsm_device_hart_stop();
-		/* It should never reach here */
-		goto fail_exit;
+		if (hsm_device_hart_stop() != SBI_ENOTSUPP)
+			goto fail_exit;
 	}
 
 	/**
Signature · 1 line
2.34.1
#3 lore raw

PATCH v2 3/6 include: types: add always inline compiler attribute

In reply to Yu Chien Peter Lin

Provide __always_inline to sbi_types header.

---
 include/sbi/sbi_types.h | 1 +
 1 file changed, 1 insertion(+)
include/sbi/sbi_types.h +1 -0
index 75cdddd..9c1fef3 100644
@@ -62,6 +62,7 @@ typedef unsigned long		physical_size_t;
 #define __packed		__attribute__((packed))
 #define __noreturn		__attribute__((noreturn))
 #define __aligned(x)		__attribute__((aligned(x)))
+#define __always_inline	inline __attribute__((always_inline))
 
 #define likely(x) __builtin_expect((x), 1)
 #define unlikely(x) __builtin_expect((x), 0)
Signature · 1 line
2.34.1
#4 lore raw

PATCH v2 4/6 lib: utils: atcsmu: Add Andes System Management Unit support

In reply to Yu Chien Peter Lin

This patch adds atcsmu support for Andes AE350 platforms. The SMU provides system management capabilities, including clock, reset and power control based on power domain partitions.

---
 include/sbi_utils/sys/atcsmu.h | 63 ++++++++++++++++++++++++++++++++++
 lib/utils/sys/Kconfig          |  4 +++
 lib/utils/sys/atcsmu.c         | 60 ++++++++++++++++++++++++++++++++
 lib/utils/sys/objects.mk       |  1 +
 platform/generic/Kconfig       |  1 +
 5 files changed, 129 insertions(+)
 create mode 100644 include/sbi_utils/sys/atcsmu.h
 create mode 100644 lib/utils/sys/atcsmu.c
include/sbi_utils/sys/atcsmu.h new file +63 -0
new file mode 100644
index 0000000..b7e4226
@@ -0,0 +1,63 @@
+/*
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ * Copyright (c) 2023 Andes Technology Corporation
+ */
+
+#ifndef _SYS_ATCSMU_H
+#define _SYS_ATCSMU_H
+
+#include <sbi_utils/sys/atcsmu.h>
+#include <sbi/sbi_bitops.h>
+#include <sbi/sbi_types.h>
+#include <sbi/riscv_asm.h>
+#include <andes/andes45.h>
+
+#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 PCS_CTL_CMD_SHIFT 0
+#define PCS_CTL_PARAM_SHIFT 3
+#define SLEEP_CMD 0x3
+#define WAKEUP_CMD (0x0 | (1 << PCS_CTL_PARAM_SHIFT))
+#define LIGHTSLEEP_MODE 0
+#define DEEPSLEEP_MODE 1
+#define LIGHT_SLEEP_CMD (SLEEP_CMD | (LIGHTSLEEP_MODE << PCS_CTL_PARAM_SHIFT))
+#define DEEP_SLEEP_CMD (SLEEP_CMD | (DEEPSLEEP_MODE << PCS_CTL_PARAM_SHIFT))
+
+#define PCS0_CFG_OFFSET 0x80
+#define PCSm_CFG_OFFSET(i) ((i + 3) * 0x20 + PCS0_CFG_OFFSET)
+#define PCS_CFG_LIGHT_SLEEP_SHIFT 2
+#define PCS_CFG_LIGHT_SLEEP (1 << PCS_CFG_LIGHT_SLEEP_SHIFT)
+#define PCS_CFG_DEEP_SLEEP_SHIFT 3
+#define PCS_CFG_DEEP_SLEEP (1 << PCS_CFG_DEEP_SLEEP_SHIFT)
+#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 PCS_MAX_NR 8
+#define FLASH_BASE 0x80000000ULL
+
+struct smu_data {
+	unsigned long addr;
+};
+
+static __always_inline bool is_andes25(void)
+{
+	ulong marchid = csr_read(CSR_MARCHID);
+	return !!(EXTRACT_FIELD(marchid, CSR_MARCHID_MICROID) == 0xa25);
+}
+
+void smu_set_wakeup_events(u32 events, u32 hartid);
+bool smu_support_sleep_mode(u32 sleep_mode, u32 hartid);
+void smu_set_command(u32 pcs_ctl, u32 hartid);
+void smu_set_reset_vector(ulong wakeup_addr, u32 hartid);
+
+#endif /* _SYS_ATCSMU_H */
lib/utils/sys/Kconfig +4 -0
index ee85b1a..76190f8 100644
@@ -2,6 +2,10 @@
 
 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 new file +60 -0

60 lines not on this page · raw message

lib/utils/sys/objects.mk +1 -0
index 9f67aee..03d6740 100644
@@ -9,3 +9,4 @@
 
 libsbiutils-objs-$(CONFIG_SYS_HTIF) += sys/htif.o
 libsbiutils-objs-$(CONFIG_SYS_SIFIVE_TEST) += sys/sifive_test.o
+libsbiutils-objs-$(CONFIG_SYS_ATCSMU) += sys/atcsmu.o
platform/generic/Kconfig +1 -0
index 47c10e5..c7f198a 100644
@@ -30,6 +30,7 @@ config PLATFORM_ALLWINNER_D1
 
 config PLATFORM_ANDES_AE350
 	bool "Andes AE350 support"
+	select SYS_ATCSMU
 	default n
 
 config PLATFORM_RENESAS_RZFIVE
Signature · 1 line
2.34.1
#5 lore raw

PATCH v2 4/6 lib: utils: atcsmu: Add Andes System Management Unit support

Quoted 26 lines · Yu Chien Peter Lin

This patch adds atcsmu support for Andes AE350 platforms. The SMU provides system management capabilities, including clock, reset and power control based on power domain partitions.

---
 include/sbi_utils/sys/atcsmu.h | 63 ++++++++++++++++++++++++++++++++++
 lib/utils/sys/Kconfig          |  4 +++
 lib/utils/sys/atcsmu.c         | 60 ++++++++++++++++++++++++++++++++
 lib/utils/sys/objects.mk       |  1 +
 platform/generic/Kconfig       |  1 +
 5 files changed, 129 insertions(+)
 create mode 100644 include/sbi_utils/sys/atcsmu.h
 create mode 100644 lib/utils/sys/atcsmu.c
include/sbi_utils/sys/atcsmu.h new file +4 -0
new file mode 100644
index 0000000..b7e4226
@@ -0,0 +1,63 @@
+/*
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ * Copyright (c) 2023 Andes Technology Corporation

include/sbi_utils/sys/atcsmu.h line 14

Quoted 10 lines
include/sbi_utils/sys/atcsmu.h new file +10 -0
+ */
+
+#ifndef _SYS_ATCSMU_H
+#define _SYS_ATCSMU_H
+
+#include <sbi_utils/sys/atcsmu.h>
+#include <sbi/sbi_bitops.h>
+#include <sbi/sbi_types.h>
+#include <sbi/riscv_asm.h>
+#include <andes/andes45.h>

Remove redundant includes from here.

Quoted 32 lines
include/sbi_utils/sys/atcsmu.h new file +32 -0
+
+#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 PCS_CTL_CMD_SHIFT 0
+#define PCS_CTL_PARAM_SHIFT 3
+#define SLEEP_CMD 0x3
+#define WAKEUP_CMD (0x0 | (1 << PCS_CTL_PARAM_SHIFT))
+#define LIGHTSLEEP_MODE 0
+#define DEEPSLEEP_MODE 1
+#define LIGHT_SLEEP_CMD (SLEEP_CMD | (LIGHTSLEEP_MODE << PCS_CTL_PARAM_SHIFT))
+#define DEEP_SLEEP_CMD (SLEEP_CMD | (DEEPSLEEP_MODE << PCS_CTL_PARAM_SHIFT))
+
+#define PCS0_CFG_OFFSET 0x80
+#define PCSm_CFG_OFFSET(i) ((i + 3) * 0x20 + PCS0_CFG_OFFSET)
+#define PCS_CFG_LIGHT_SLEEP_SHIFT 2
+#define PCS_CFG_LIGHT_SLEEP (1 << PCS_CFG_LIGHT_SLEEP_SHIFT)
+#define PCS_CFG_DEEP_SLEEP_SHIFT 3
+#define PCS_CFG_DEEP_SLEEP (1 << PCS_CFG_DEEP_SLEEP_SHIFT)
+#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 PCS_MAX_NR 8
+#define FLASH_BASE 0x80000000ULL

include/sbi_utils/sys/atcsmu.h line 56

Quoted 10 lines
include/sbi_utils/sys/atcsmu.h new file +10 -0
+
+struct smu_data {
+       unsigned long addr;
+};
+
+static __always_inline bool is_andes25(void)
+{
+       ulong marchid = csr_read(CSR_MARCHID);
+       return !!(EXTRACT_FIELD(marchid, CSR_MARCHID_MICROID) == 0xa25);
+}

The is_andes25() is not used anywhere in atcsmu.h and atchsmu.c so better to keep this in andes platform code for now.

Quoted 32 lines
include/sbi_utils/sys/atcsmu.h new file +7 -0
+
+void smu_set_wakeup_events(u32 events, u32 hartid);
+bool smu_support_sleep_mode(u32 sleep_mode, u32 hartid);
+void smu_set_command(u32 pcs_ctl, u32 hartid);
+void smu_set_reset_vector(ulong wakeup_addr, u32 hartid);
+
+#endif /* _SYS_ATCSMU_H */
lib/utils/sys/Kconfig +4 -0
index ee85b1a..76190f8 100644
@@ -2,6 +2,10 @@
 
 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 new file +4 -0
new file mode 100644
index 0000000..b38ec70
@@ -0,0 +1,60 @@
+/*
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ * Copyright (c) 2023 Andes Technology Corporation

lib/utils/sys/atcsmu.c line 14

Quoted 10 lines
lib/utils/sys/atcsmu.c new file +10 -0
+ */
+
+#include <sbi_utils/sys/atcsmu.h>
+#include <sbi/riscv_io.h>
+#include <sbi/sbi_bitops.h>
+#include <sbi/sbi_console.h>
+#include <sbi/sbi_error.h>
+#include <andes/andes45.h>
+
+extern struct smu_data smu;

If atcsmu is enabled from a platform not defining "smu" variable then it would result in linker error.

I suggest all functions in atcsmu.c should have "struct smu_data *smu" as a parameter and calling platform code will instantiate struct smu_data.

Regards,
Anup

Quoted 75 lines
lib/utils/sys/atcsmu.c new file +46 -0
+
+void smu_set_wakeup_events(u32 events, u32 hartid)
+{
+       writel(events, (void *)(smu.addr + PCSm_WE_OFFSET(hartid)));
+}
+
+bool smu_support_sleep_mode(u32 sleep_mode, u32 hartid)
+{
+       u32 pcs_cfg;
+
+       pcs_cfg = readl((void *)(smu.addr + PCSm_CFG_OFFSET(hartid)));
+
+       switch (sleep_mode) {
+       case LIGHTSLEEP_MODE:
+               if (EXTRACT_FIELD(pcs_cfg, PCS_CFG_LIGHT_SLEEP) == 0) {
+                       sbi_printf(
+                               "SMU: hart%d (PCS%d) does not support light sleep mode\n",
+                               hartid, hartid + 3);
+                       return false;
+               }
+               break;
+       case DEEPSLEEP_MODE:
+               if (EXTRACT_FIELD(pcs_cfg, PCS_CFG_DEEP_SLEEP) == 0) {
+                       sbi_printf(
+                               "SMU: hart%d (PCS%d) does not support deep sleep mode\n",
+                               hartid, hartid + 3);
+                       return false;
+               }
+               break;
+       }
+
+       return true;
+}
+
+void smu_set_command(u32 pcs_ctl, u32 hartid)
+{
+       writel(pcs_ctl, (void *)(smu.addr + PCSm_CTL_OFFSET(hartid)));
+}
+
+void smu_set_reset_vector(ulong wakeup_addr, u32 hartid)
+{
+       writel(wakeup_addr,
+              (void *)(smu.addr + HARTn_RESET_VEC_LO(hartid)));
+       writel((u64)wakeup_addr >> 32,
+              (void *)(smu.addr + HARTn_RESET_VEC_HI(hartid)));
+}
lib/utils/sys/objects.mk +1 -0
index 9f67aee..03d6740 100644
@@ -9,3 +9,4 @@
 
 libsbiutils-objs-$(CONFIG_SYS_HTIF) += sys/htif.o
 libsbiutils-objs-$(CONFIG_SYS_SIFIVE_TEST) += sys/sifive_test.o
+libsbiutils-objs-$(CONFIG_SYS_ATCSMU) += sys/atcsmu.o
platform/generic/Kconfig +1 -1
index 47c10e5..c7f198a 100644
@@ -30,6 +30,7 @@ config PLATFORM_ALLWINNER_D1
 
 config PLATFORM_ANDES_AE350
        bool "Andes AE350 support"
+       select SYS_ATCSMU
        default n
 
 config PLATFORM_RENESAS_RZFIVE
--

2.34.1

--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi

#6 lore raw

PATCH v2 5/6 platform: andes/ae350: Implement hart hotplug using HSM extension

In reply to Yu Chien Peter Lin

Add hart_start() and hart_stop() callbacks for the multi-core ae350 platform, it utilizes the ATCSMU to put the harts into power-gated deep sleep mode. The programming sequence is stated as below:

1. Set the wakeup events to PCSm_WE
2. Set the sleep command to PCSm_CTL
3. Set the reset vector to HARTm_RESET_VECTOR_{LO|HI}
4. Write back and invalidate D-cache by executing the CCTL command L1D_WBINVAL_ALL
5. Disable I/D-cache by clearing mcache_ctl.{I|D}C_EN
6. Disable D-cache coherency by clearing mcache_ctl_.DC_COHEN
7. Wait for mcache_ctl.DC_COHSTA to be cleared to ensure the previous step is completed
8. Execute WFI

---
 platform/generic/andes/ae350.c           | 84 ++++++++++++++++++++++++
 platform/generic/andes/objects.mk        |  2 +-
 platform/generic/andes/sleep.S           | 70 ++++++++++++++++++++
 platform/generic/include/andes/andes45.h | 10 +++
 4 files changed, 165 insertions(+), 1 deletion(-)
 create mode 100644 platform/generic/andes/sleep.S
 create mode 100644 platform/generic/include/andes/andes45.h
platform/generic/andes/ae350.c +84 -0
index cf7f6f2..18f3005 100644
@@ -10,6 +10,89 @@
 #include <platform_override.h>
 #include <sbi_utils/fdt/fdt_helper.h>
 #include <sbi_utils/fdt/fdt_fixup.h>
+#include <sbi_utils/sys/atcsmu.h>
+#include <sbi/sbi_error.h>
+#include <sbi/sbi_hsm.h>
+#include <sbi/sbi_ipi.h>
+#include <sbi/sbi_init.h>
+
+struct smu_data smu;
+extern void __ae350_enable_coherency_warmboot(void);
+extern void __ae350_disable_coherency(void);
+
+static int ae350_hart_start(u32 hartid, ulong saddr)
+{
+	if (!sbi_init_count(hartid) || (is_andes25() && hartid == 0))
+		return sbi_ipi_raw_send(hartid);
+
+	/* Write wakeup command to the sleep hart */
+	smu_set_command(WAKEUP_CMD, hartid);
+
+	return 0;
+}
+
+static int ae350_hart_stop(void)
+{
+	u32 hartid = current_hartid();
+
+	/**
+	 * The hart0 shares power domain with L2-cache,
+	 * instead of turning it off, it falls through
+	 * and jump to warmboot_addr.
+	 */
+	if (is_andes25() && hartid == 0)
+		return SBI_ENOTSUPP;
+
+	if (!smu_support_sleep_mode(DEEPSLEEP_MODE, hartid))
+		return SBI_ENOTSUPP;
+
+	/**
+	 * disable all events, the current hart will be
+	 * woken up from reset vector when other hart
+	 * writes its PCS (power control slot) control
+	 * register
+	 */
+	smu_set_wakeup_events(0x0, hartid);
+	smu_set_command(DEEP_SLEEP_CMD, hartid);
+	smu_set_reset_vector((ulong)__ae350_enable_coherency_warmboot,
+			       hartid);
+	__ae350_disable_coherency();
+
+	wfi();
+
+	/* It should never reach here */
+	sbi_hart_hang();
+	return 0;
+}
+
+static const struct sbi_hsm_device andes_smu = {
+	.name	      = "andes_smu",
+	.hart_start   = ae350_hart_start,
+	.hart_stop    = ae350_hart_stop,
+};
+
+static void ae350_hsm_device_init(void)
+{
+	int rc;
+	void *fdt;
+
+	fdt = fdt_get_address();
+
+	rc = fdt_parse_compat_addr(fdt, (uint64_t *)&smu.addr,
+				   "andestech,atcsmu");
+
+	if (!rc) {
+		sbi_hsm_set_device(&andes_smu);
+	}
+}
+
+static int ae350_final_init(bool cold_boot, const struct fdt_match *match)
+{
+	if (cold_boot)
+		ae350_hsm_device_init();
+
+	return 0;
+}
 
 static const struct fdt_match andes_ae350_match[] = {
 	{ .compatible = "andestech,ae350" },
@@ -18,4 +101,5 @@ static const struct fdt_match andes_ae350_match[] = {
 
 const struct platform_override andes_ae350 = {
 	.match_table = andes_ae350_match,
+	.final_init  = ae350_final_init,
 };
platform/generic/andes/objects.mk +1 -1
index dd6408d..28275ef 100644
@@ -3,4 +3,4 @@
 #
 
 carray-platform_override_modules-$(CONFIG_PLATFORM_ANDES_AE350) += andes_ae350
-platform-objs-$(CONFIG_PLATFORM_ANDES_AE350) += andes/ae350.o
+platform-objs-$(CONFIG_PLATFORM_ANDES_AE350) += andes/ae350.o andes/sleep.o
platform/generic/andes/sleep.S new file +70 -0

70 lines not on this page · raw message

platform/generic/include/andes/andes45.h new file +10 -0
new file mode 100644
index 0000000..08b3d18
@@ -0,0 +1,10 @@
+#ifndef _RISCV_ANDES45_H
+#define _RISCV_ANDES45_H
+
+#define CSR_MARCHID_MICROID 0xfff
+
+/* Memory and Miscellaneous Registers */
+#define CSR_MCACHE_CTL 0x7ca
+#define CSR_MCCTLCOMMAND 0x7cc
+
+#endif /* _RISCV_ANDES45_H */
Signature · 1 line
2.34.1
#7 lore raw

PATCH v2 6/6 lib: reset/fdt_reset_atcwdt200: Use defined macros and function in atcsmu.h

In reply to Yu Chien Peter Lin

Reuse the smu related macros and function in atcsmu.h.

---
 lib/utils/reset/fdt_reset_atcwdt200.c | 13 +++----------
 1 file changed, 3 insertions(+), 10 deletions(-)
lib/utils/reset/fdt_reset_atcwdt200.c +3 -10
index 91acc9f..c524f84 100644
@@ -16,6 +16,7 @@
 #include <sbi/sbi_system.h>
 #include <sbi_utils/fdt/fdt_helper.h>
 #include <sbi_utils/reset/fdt_reset.h>
+#include <sbi_utils/sys/atcsmu.h>
 
 #define ATCWDT200_WP_NUM 0x5aa5
 #define WREN_REG 0x18
@@ -41,12 +42,6 @@
 #define CLK_PCLK (1 << 1)
 #define WDT_EN (1 << 0)
 
-#define FLASH_BASE 0x80000000ULL
-#define SMU_RESET_VEC_LO_OFF 0x50
-#define SMU_RESET_VEC_HI_OFF 0x60
-#define SMU_HARTn_RESET_VEC_LO(n) (SMU_RESET_VEC_LO_OFF + (n * 0x4))
-#define SMU_HARTn_RESET_VEC_HI(n) (SMU_RESET_VEC_HI_OFF + (n * 0x4))
-
 static volatile char *wdt_addr;
 static volatile char *smu_addr;
 
@@ -66,10 +61,8 @@ static void ae350_system_reset(u32 type, u32 reason)
 {
 	const struct sbi_platform *plat = sbi_platform_thishart_ptr();
 
-	for (int i = 0; i < sbi_platform_hart_count(plat); i++) {
-		writel(FLASH_BASE, smu_addr + SMU_HARTn_RESET_VEC_LO(i));
-		writel(FLASH_BASE >> 32, smu_addr + SMU_HARTn_RESET_VEC_HI(i));
-	}
+	for (int i = 0; i < sbi_platform_hart_count(plat); i++)
+		smu_set_reset_vector(FLASH_BASE, i);
 
 	/* Program WDT control register  */
 	writew(ATCWDT200_WP_NUM, wdt_addr + WREN_REG);
Signature · 1 line
2.34.1
#8 lore raw

PATCH v2 6/6 lib: reset/fdt_reset_atcwdt200: Use defined macros and function in atcsmu.h

Quoted 34 lines · Yu Chien Peter Lin

Reuse the smu related macros and function in atcsmu.h.

---
 lib/utils/reset/fdt_reset_atcwdt200.c | 13 +++----------
 1 file changed, 3 insertions(+), 10 deletions(-)
lib/utils/reset/fdt_reset_atcwdt200.c +1 -6
index 91acc9f..c524f84 100644
@@ -16,6 +16,7 @@
 #include <sbi/sbi_system.h>
 #include <sbi_utils/fdt/fdt_helper.h>
 #include <sbi_utils/reset/fdt_reset.h>
+#include <sbi_utils/sys/atcsmu.h>
 
 #define ATCWDT200_WP_NUM 0x5aa5
 #define WREN_REG 0x18
@@ -41,12 +42,6 @@
 #define CLK_PCLK (1 << 1)
 #define WDT_EN (1 << 0)
 
-#define FLASH_BASE 0x80000000ULL
-#define SMU_RESET_VEC_LO_OFF 0x50
-#define SMU_RESET_VEC_HI_OFF 0x60
-#define SMU_HARTn_RESET_VEC_LO(n) (SMU_RESET_VEC_LO_OFF + (n * 0x4))
-#define SMU_HARTn_RESET_VEC_HI(n) (SMU_RESET_VEC_HI_OFF + (n * 0x4))
-
 static volatile char *wdt_addr;
 static volatile char *smu_addr;
 

lib/utils/reset/fdt_reset_atcwdt200.c static void ae350_system_reset(u32 type, u32 reason) · line 65

Quoted 9 lines
lib/utils/reset/fdt_reset_atcwdt200.c +2 -4
@@ -66,10 +61,8 @@ static void ae350_system_reset(u32 type, u32 reason)
 {
        const struct sbi_platform *plat = sbi_platform_thishart_ptr();
 
-       for (int i = 0; i < sbi_platform_hart_count(plat); i++) {
-               writel(FLASH_BASE, smu_addr + SMU_HARTn_RESET_VEC_LO(i));
-               writel(FLASH_BASE >> 32, smu_addr + SMU_HARTn_RESET_VEC_HI(i));
-       }
+       for (int i = 0; i < sbi_platform_hart_count(plat); i++)
+               smu_set_reset_vector(FLASH_BASE, i);

This also means that "config FDT_RESET_ATCWDT200" now depends upon SYS_ATCSMU

Regards,
Anup

Quoted 11 lines
lib/utils/reset/fdt_reset_atcwdt200.c +0 -1
        /* Program WDT control register  */
        writew(ATCWDT200_WP_NUM, wdt_addr + WREN_REG);
--

2.34.1

--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi