Fix and improve the Andes ATCSMU and LLC drivers
cover Fix and improve the Andes ATCSMU and LLC drivers
Fixes and cleanups for the Andes last level cache, HSM and suspend drivers, collected while bringing up suspend to RAM on the AE350 platform.
Below is the summary of this patch set:
- Patch 1 makes andes_llcache_enable() return 0 on success, as the cache_enable() callback is documented to. Nothing checks it today, but patch 7 does.
- Patch 2 puts the SMU and LLC register regions in the root domain, so the supervisor can reach them under Smepmp.
- Patch 3 pairs the non-retentive CSR save and restore with an explicit flag instead of inferring it from the boot count and sleep type.
- Patch 4 restores those CSRs on the system-suspend resume path, which never reached the old call site.
- Patch 5 wakes a sleeping hart with a plain IPI and drops the SMU WAKEUP_CMD path.
- Patch 6 polls the secondary harts until they are really asleep instead of checking once.
- Patch 7 arms the SMU last and unwinds an aborted suspend rather than leaving the hart half configured.
Ben Zong-You Xie (7):
lib: utils/cache: fix andes_llcache_enable() return value
lib: utils/andes: add the SMU and LLC registers to the root domain
platform: generic/andes: pair non-retentive CSR save/restore with a
flag
lib: utils/suspend: restore Andes CSRs on system-suspend resume
lib: utils/hsm: wake sleeping Andes harts with an IPI
lib: utils/suspend: wait for the secondary Andes harts to sleep
lib: utils/andes: arm the SMU sleep command last
include/sbi_utils/hsm/fdt_hsm_andes_atcsmu.h | 8 ++- lib/utils/cache/fdt_andes_llcache.c | 23 +++++-- lib/utils/hsm/fdt_hsm_andes_atcsmu.c | 64 ++++++++---------- lib/utils/suspend/fdt_suspend_andes_atcsmu.c | 70 ++++++++++++++------ platform/generic/andes/ae350.c | 26 ++++++-- platform/generic/include/andes/andes.h | 4 ++ 6 files changed, 129 insertions(+), 66 deletions(-)
--
2.34.1
Signature · 3 lines
opensbi mailing list [email protected] http://lists.infradead.org/mailman/listinfo/opensbi
PATCH 1/7 lib: utils/cache: fix andes_llcache_enable() return value
The driver returned 1 on success where callers expect 0, so the suspend to RAM aborted right after disabling the LLC and before flushing it.
--- lib/utils/cache/fdt_andes_llcache.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
lib/utils/cache/fdt_andes_llcache.c +4 -1
@@ -102,7 +102,10 @@ static int andes_llcache_enable(struct cache_device *dev, bool enable) } llcache_ctrl =readl (ctrl_addr); -return enable ==EXTRACT_FIELD (llcache_ctrl,LLCACHE_REG_CTRL_EN_MASK ); +if (enable !=EXTRACT_FIELD (llcache_ctrl,LLCACHE_REG_CTRL_EN_MASK )) +return SBI_EFAIL ; + +return SBI_OK ; }static struct cache_ops andes_llcache_ops = {
Signature · 7 lines
2.34.1 -- opensbi mailing list [email protected] http://lists.infradead.org/mailman/listinfo/opensbi
PATCH 2/7 lib: utils/andes: add the SMU and LLC registers to the root domain
In reply to Ben Zong-You XieWhen a hart implements Smepmp, S-mode and U-mode cannot reach either device unless its region is shared explicitly. Suspend and resume then take an access violation as soon as the supervisor touches the SMU or the LLC.
Share both regions, and take their sizes from the DT nodes rather than ignoring them.
--- lib/utils/cache/fdt_andes_llcache.c | 18 +++++++++++++++--- lib/utils/hsm/fdt_hsm_andes_atcsmu.c | 17 +++++++++++++---- 2 files changed, 28 insertions(+), 7 deletions(-)
lib/utils/cache/fdt_andes_llcache.c +15 -3
@@ -5,8 +5,11 @@*/ #include <sbi/riscv_io.h> +#include <sbi/sbi_domain.h> #include <sbi/sbi_error.h> +#include <sbi/sbi_hart.h> #include <sbi/sbi_heap.h> +#include <sbi/sbi_scratch.h> #include <sbi_utils/cache/fdt_cache.h> #include <sbi_utils/fdt/fdt_driver.h> #include <sbi_utils/hsm/fdt_hsm_andes_atcsmu.h>
@@ -116,13 +119,13 @@ static struct cache_ops andes_llcache_ops = {static int andes_llcache_probe (const void *fdt,int nodeoff,const struct fdt_match *match) {int rc; -u64 llcache_base =0 ; +u64 llcache_base =0 , size;struct andes_llcache *llcache;struct cache_device *dev;uint32_t llcache_cfg; - rc =fdt_get_node_addr_size (fdt, nodeoff,0 , &llcache_base,NULL ); -if (rc <0 || !llcache_base) + rc =fdt_get_node_addr_size (fdt, nodeoff,0 , &llcache_base, &size); +if (rc <0 || !llcache_base || !size)return SBI_ENODEV ; llcache =sbi_zalloc (sizeof (*llcache));
@@ -151,6 +154,15 @@ static int andes_llcache_probe(const void *fdt, int nodeoff, const struct fdt_ma llcache->status_core_stride =4 ; } +if (sbi_hart_has_extension (sbi_scratch_thishart_ptr (),SBI_HART_EXT_SMEPMP )) { + rc =sbi_domain_root_add_memrange ( + (unsigned long )llcache->base, (unsigned long )size,PAGE_SIZE , +SBI_DOMAIN_MEMREGION_MMIO | +SBI_DOMAIN_MEMREGION_SHARED_SURW_MRW ); +if (rc) +return rc; + } +/* Wait for the hardware initialization done */ while (!andes_llcache_init_done (llcache)) ;
lib/utils/hsm/fdt_hsm_andes_atcsmu.c +13 -4
@@ -184,18 +184,27 @@ static const struct sbi_hsm_device hsm_andes_atcsmu = {static int hsm_andes_atcsmu_probe (const void *fdt,int nodeoff,const struct fdt_match *match) {int poff, rc; -u64 addr; +u64 addr, size;/* Need to find the parent for the address property */ poff =fdt_parent_offset (fdt, nodeoff);if (poff <0 )return SBI_EINVAL ; - rc =fdt_get_node_addr_size (fdt, poff,0 , &addr,NULL ); -if (rc <0 || !addr) + rc =fdt_get_node_addr_size (fdt, poff,0 , &addr, &size); +if (rc <0 || !addr || !size)return SBI_ENODEV ; - atcsmu_base = addr; +if (sbi_hart_has_extension (sbi_scratch_thishart_ptr (),SBI_HART_EXT_SMEPMP )) { + rc =sbi_domain_root_add_memrange ( + (unsigned long )addr, (unsigned long )size,PAGE_SIZE , +SBI_DOMAIN_MEMREGION_MMIO | +SBI_DOMAIN_MEMREGION_SHARED_SURW_MRW ); +if (rc) +return rc; + } + + atcsmu_base = addr;sbi_hsm_set_device (&hsm_andes_atcsmu);return 0 ; }
Signature · 7 lines
2.34.1 -- opensbi mailing list [email protected] http://lists.infradead.org/mailman/listinfo/opensbi
PATCH 3/7 platform: generic/andes: pair non-retentive CSR save/restore with a flag
In reply to Ben Zong-You XieThe restore was gated on sbi_init_count() and the current sleep type, which is only a proxy for "did this hart actually save its CSRs". Track it explicitly instead, so restore is self-guarding and the call site needs no conditions.
--- platform/generic/andes/ae350.c | 18 ++++++++++++------ platform/generic/include/andes/andes.h | 3 +++ 2 files changed, 15 insertions(+), 6 deletions(-)
platform/generic/andes/ae350.c +12 -6
@@ -34,6 +34,8 @@ void ae350_non_ret_save(struct sbi_scratch *scratch) andes_hdata->pmacfg2 =csr_read_num (CSR_PMACFG0 +2 );for (int i =0 ; i <16 ; i++) andes_hdata->pmaaddrX[i] =csr_read_num (CSR_PMAADDR0 + i); + + andes_hdata->saved = true; }void ae350_non_ret_restore (struct sbi_scratch *scratch)
@@ -41,6 +43,9 @@ void ae350_non_ret_restore(struct sbi_scratch *scratch)struct andes_hart_data *andes_hdata =sbi_scratch_offset_ptr (scratch, andes_hart_data_offset); +if (!andes_hdata->saved) +return ; +csr_write (CSR_MCACHE_CTL , andes_hdata->mcache_ctl);csr_write (CSR_MMISC_CTL , andes_hdata->mmisc_ctl);csr_write (CSR_MPFT_CTL , andes_hdata->mpft_ctl);
@@ -52,6 +57,8 @@ void ae350_non_ret_restore(struct sbi_scratch *scratch)csr_write_num (CSR_PMACFG0 +2 , andes_hdata->pmacfg2);for (int i =0 ; i <16 ; i++)csr_write_num (CSR_PMAADDR0 + i, andes_hdata->pmaaddrX[i]); + + andes_hdata->saved = false; }void ae350_enable_coherency_warmboot (void )
@@ -62,18 +69,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 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 ()); +/* +* This is a no-op unless this hart actually saved them, so it is safe +* to call on every path. +*/ +ae350_non_ret_restore (sbi_scratch_thishart_ptr ());return generic_early_init (cold_boot); }
platform/generic/include/andes/andes.h +3 -0
@@ -96,6 +96,9 @@ struct andes_hart_data {unsigned long pmacfg0;unsigned long pmacfg2;unsigned long pmaaddrX[16 ]; + +/* Set when the CSRs above hold a saved copy awaiting restore */ +bool saved; };void ae350_non_ret_save (struct sbi_scratch *scratch);
Signature · 7 lines
2.34.1 -- opensbi mailing list [email protected] http://lists.infradead.org/mailman/listinfo/opensbi
PATCH 4/7 lib: utils/suspend: restore Andes CSRs on system-suspend resume
In reply to Ben Zong-You XieA deep sleep resume leaves the boot hart in SUSPENDED state, so init_warmboot() dispatches to init_warm_resume(), which calls the SUSP device's system_resume callback and not sbi_platform_early_init(). The restore in ae350_early_init() is dead code on that path.
--- lib/utils/suspend/fdt_suspend_andes_atcsmu.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
lib/utils/suspend/fdt_suspend_andes_atcsmu.c +3 -1
@@ -91,8 +91,10 @@ static void ae350_system_resume(void)u32 hartid =current_hartid ();u32 sleep_type =atcsmu_get_sleep_type (hartid); -if (sleep_type ==SBI_SUSP_SLEEP_TYPE_SUSPEND ) +if (sleep_type ==SBI_SUSP_SLEEP_TYPE_SUSPEND ) {fdt_cmo_llc_enable (true); +ae350_non_ret_restore (sbi_scratch_thishart_ptr ()); + } }static struct sbi_system_suspend_device suspend_andes_atcsmu = {
Signature · 7 lines
2.34.1 -- opensbi mailing list [email protected] http://lists.infradead.org/mailman/listinfo/opensbi
PATCH 5/7 lib: utils/hsm: wake sleeping Andes harts with an IPI
In reply to Ben Zong-You XieAn IPI wakes a hart from light sleep and, once MSIP is kept as an SMU wakeup event, from deep sleep too. Drop the WAKEUP_CMD path and the boot state, hart type and sleep type conditions that selected it.
--- include/sbi_utils/hsm/fdt_hsm_andes_atcsmu.h | 1 + lib/utils/hsm/fdt_hsm_andes_atcsmu.c | 21 +++++--------------- lib/utils/suspend/fdt_suspend_andes_atcsmu.c | 8 +++----- 3 files changed, 9 insertions(+), 21 deletions(-)
include/sbi_utils/hsm/fdt_hsm_andes_atcsmu.h +1 -0
@@ -36,6 +36,7 @@#define PCS_WAKEUP_RTC_ALARM_MASK BIT(2)#define PCS_WAKEUP_UART2_MASK BIT(9)#define PCS_WAKEUP_MSIP_MASK BIT(29) +#define PCS_WAKEUP_MEIP_MASK BIT(31)#define PCS0_CTL_OFFSET 0x94#define PCSm_CTL_OFFSET (i) ((i + 3) * 0x20 + PCS0_CTL_OFFSET)
lib/utils/hsm/fdt_hsm_andes_atcsmu.c +5 -16
@@ -116,20 +116,8 @@ bool atcsmu_pcs_is_sleep(u32 hartid, bool deep_sleep)static int ae350_hart_start (u32 hartid,ulong saddr) {u32 hartindex =sbi_hartid_to_hartindex (hartid); -u32 sleep_type =atcsmu_get_sleep_type (hartid); -/* -* Don't send wakeup command when: -* 1) boot time -* 2) the target hart is non-sleepable 25-series hart0 -* 3) light sleep -*/ -if (!sbi_init_count (hartindex) || (is_andes (25 ) && hartid ==0 ) || - sleep_type ==SBI_SUSP_AE350_LIGHT_SLEEP ) -return sbi_ipi_raw_send (hartindex, false); - -atcsmu_set_command (WAKEUP_CMD , hartid); -return 0 ; +return sbi_ipi_raw_send (hartindex, false); }static int ae350_hart_stop (void )
@@ -152,12 +140,13 @@ static int ae350_hart_stop(void)/* Prevent the core leaving the WFI mode unexpectedly */ csr_write (CSR_MIE ,0 ); +atcsmu_set_wakeup_events (PCS_WAKEUP_MSIP_MASK |PCS_WAKEUP_MEIP_MASK , hartid);if (sleep_type ==SBI_SUSP_AE350_LIGHT_SLEEP ) { -csr_write (CSR_MIE ,MIP_MSIP ); -atcsmu_set_wakeup_events (PCS_WAKEUP_MSIP_MASK , hartid); +/* Clock-gated only: needs MSI or MEI set to resume past the WFI */ +csr_set (CSR_MIE ,MIP_MSIP |MIP_MEIP );atcsmu_set_command (LIGHT_SLEEP_CMD , hartid); }else if (sleep_type ==SBI_SUSP_SLEEP_TYPE_SUSPEND ) { -atcsmu_set_wakeup_events (0x0 , hartid); +/* Power-gated: SMU wakes it via cold reset, interrupts not needed */ atcsmu_set_command (DEEP_SLEEP_CMD , hartid); rc =atcsmu_set_reset_vector ((ulong )ae350_enable_coherency_warmboot, hartid);if (rc)
lib/utils/suspend/fdt_suspend_andes_atcsmu.c +3 -5
@@ -47,11 +47,7 @@ static int ae350_system_suspend(u32 sleep_type, unsigned long addr)/* Prevent the core leaving the WFI mode unexpectedly */ csr_write (CSR_MIE ,0 ); -/* -* Only allow the S-mode external interrupts (UART2 and RTC alarm) to -* wake up the primary hart -*/ -csr_set (CSR_SIE ,MIP_SEIP ); +/* SMU wakes the primary hart on RTC alarm / UART2 */ atcsmu_set_wakeup_events (PCS_WAKEUP_RTC_ALARM_MASK |PCS_WAKEUP_UART2_MASK , hartid);if (sleep_type ==SBI_SUSP_AE350_LIGHT_SLEEP ) {
@@ -59,6 +55,8 @@ static int ae350_system_suspend(u32 sleep_type, unsigned long addr)if (rc)return rc; +/* Clock-gated only: enable SEI to resume past the WFI */ +csr_set (CSR_MIE ,MIP_SEIP );atcsmu_set_command (LIGHT_SLEEP_CMD , hartid); }else if (sleep_type ==SBI_SUSP_SLEEP_TYPE_SUSPEND ) { rc =check_secondary_harts_sleep (hartid, true);
Signature · 7 lines
2.34.1 -- opensbi mailing list [email protected] http://lists.infradead.org/mailman/listinfo/opensbi
PATCH 6/7 lib: utils/suspend: wait for the secondary Andes harts to sleep
In reply to Ben Zong-You XieA secondary hart may not have reached the target sleep state by the time the primary checks, so the one-shot check could fail spuriously. Poll each PCS status instead and give up after HART_SLEEP_TIMEOUT_MS.
Rework atcsmu_pcs_is_sleep() into the atcsmu_hart_is_sleep() predicate so sbi_timer_waitms_until() can drive it.
--- include/sbi_utils/hsm/fdt_hsm_andes_atcsmu.h | 7 ++++- lib/utils/hsm/fdt_hsm_andes_atcsmu.c | 22 ++++++---------- lib/utils/suspend/fdt_suspend_andes_atcsmu.c | 27 +++++++++++++++----- 3 files changed, 35 insertions(+), 21 deletions(-)
include/sbi_utils/hsm/fdt_hsm_andes_atcsmu.h +6 -1
@@ -9,6 +9,11 @@#include <sbi/sbi_types.h> +struct atcsmu_sleep_arg { +u32 hartid; +bool deep_sleep; +}; +/* clang-format off */ #define SCRATCH_PAD_OFFSET 0x40
@@ -61,6 +66,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); +bool atcsmu_hart_is_sleep (void *opaque);#endif
lib/utils/hsm/fdt_hsm_andes_atcsmu.c +8 -14
@@ -94,23 +94,17 @@ u32 atcsmu_read_scratch(void)return readl_relaxed ((char *)atcsmu_base +SCRATCH_PAD_OFFSET ); } -bool atcsmu_pcs_is_sleep (u32 hartid,bool deep_sleep) +bool atcsmu_hart_is_sleep (void *opaque) { -u32 pcs_status =readl_relaxed ((char *)atcsmu_base +PCSm_STATUS_OFFSET (hartid)); -u32 pd_status = deep_sleep ?PD_STATUS_DEEP_SLEEP :PD_STATUS_LIGHT_SLEEP ; +struct atcsmu_sleep_arg *arg = opaque; -if (EXTRACT_FIELD (pcs_status,PD_TYPE_MASK ) !=PD_TYPE_SLEEP ) { -sbi_printf ("ATCSMU: hart%d (PCS%d): failed to sleep\n" , hartid, hartid +3 ); -return false; - } - -if (EXTRACT_FIELD (pcs_status,PD_STATUS_MASK ) != pd_status) { -sbi_printf ("ATCSMU: hart%d (PCS%d): failed to enter %s sleep\n" , - hartid, hartid +3 , deep_sleep ?"deep" :"light" ); -return false; - } +u32 pcs_status =readl_relaxed ((char *)atcsmu_base + +PCSm_STATUS_OFFSET (arg->hartid)); +u32 pd_status = arg->deep_sleep ?PD_STATUS_DEEP_SLEEP : +PD_STATUS_LIGHT_SLEEP ; -return true; +return EXTRACT_FIELD (pcs_status,PD_TYPE_MASK ) ==PD_TYPE_SLEEP && +EXTRACT_FIELD (pcs_status,PD_STATUS_MASK ) == pd_status; }static int ae350_hart_start (u32 hartid,ulong saddr)
lib/utils/suspend/fdt_suspend_andes_atcsmu.c +21 -6
@@ -12,22 +12,37 @@#include <sbi/sbi_ecall_interface.h> #include <sbi/sbi_hart.h> #include <sbi/sbi_system.h> +#include <sbi/sbi_timer.h> #include <sbi_utils/cache/fdt_cmo_helper.h> #include <sbi_utils/fdt/fdt_driver.h> #include <sbi_utils/fdt/fdt_helper.h> #include <sbi_utils/hsm/fdt_hsm_andes_atcsmu.h> -static int check_secondary_harts_sleep (u32 hartid,bool deep_sleep) +#define HART_SLEEP_TIMEOUT_MS 1000 + +static int wait_secondary_harts_sleep (u32 hartid,bool deep_sleep) {const struct sbi_domain *dom = &root;unsigned long i;u32 target; +struct atcsmu_sleep_arg arg; + + arg.deep_sleep = deep_sleep; -/* Ensure the secondary harts entering the corresponding sleep state */ +/* Wait for the secondary harts entering the corresponding sleep state */ sbi_hartmask_for_each_hartindex (i, dom->possible_harts) { target =sbi_hartindex_to_hartid (i); -if (target != hartid && !atcsmu_pcs_is_sleep (target, deep_sleep)) -return SBI_EFAIL ; +if (target == hartid) +continue ; + + arg.hartid = target; +if (!sbi_timer_waitms_until (atcsmu_hart_is_sleep, &arg, +HART_SLEEP_TIMEOUT_MS )) { +sbi_printf ("ATCSMU: hart%u (PCS%u): timed out waiting for %s sleep\n" , + target, target +3 , + deep_sleep ?"deep" :"light" ); +return SBI_ETIMEOUT ; + } }return SBI_OK ;
@@ -51,7 +66,7 @@ static int ae350_system_suspend(u32 sleep_type, unsigned long addr)atcsmu_set_wakeup_events (PCS_WAKEUP_RTC_ALARM_MASK |PCS_WAKEUP_UART2_MASK , hartid);if (sleep_type ==SBI_SUSP_AE350_LIGHT_SLEEP ) { - rc =check_secondary_harts_sleep (hartid, false); + rc =wait_secondary_harts_sleep (hartid, false);if (rc)return rc;
@@ -59,7 +74,7 @@ static int ae350_system_suspend(u32 sleep_type, unsigned long addr)csr_set (CSR_MIE ,MIP_SEIP );atcsmu_set_command (LIGHT_SLEEP_CMD , hartid); }else if (sleep_type ==SBI_SUSP_SLEEP_TYPE_SUSPEND ) { - rc =check_secondary_harts_sleep (hartid, true); + rc =wait_secondary_harts_sleep (hartid, true);if (rc)return rc;
Signature · 7 lines
2.34.1 -- opensbi mailing list [email protected] http://lists.infradead.org/mailman/listinfo/opensbi
PATCH 7/7 lib: utils/andes: arm the SMU sleep command last
In reply to Ben Zong-You XieOnce the sleep command is written, the next WFI puts the core to sleep, so everything that can fail has to run before it.
Also, use writel() so the command store cannot still be in flight at the WFI.
--- lib/utils/hsm/fdt_hsm_andes_atcsmu.c | 4 +-- lib/utils/suspend/fdt_suspend_andes_atcsmu.c | 31 +++++++++++++++----- platform/generic/andes/ae350.c | 8 +++++ platform/generic/include/andes/andes.h | 1 + 4 files changed, 35 insertions(+), 9 deletions(-)
lib/utils/hsm/fdt_hsm_andes_atcsmu.c +2 -2
@@ -56,7 +56,7 @@ bool atcsmu_support_sleep_mode(u32 sleep_type, u32 hartid)void atcsmu_set_command (u32 pcs_ctl,u32 hartid) { -writel_relaxed (pcs_ctl, (char *)atcsmu_base +PCSm_CTL_OFFSET (hartid)); +writel (pcs_ctl, (char *)atcsmu_base +PCSm_CTL_OFFSET (hartid)); }int atcsmu_set_reset_vector (u64 wakeup_addr,u32 hartid)
@@ -141,12 +141,12 @@ static int ae350_hart_stop(void)atcsmu_set_command (LIGHT_SLEEP_CMD , hartid); }else if (sleep_type ==SBI_SUSP_SLEEP_TYPE_SUSPEND ) {/* Power-gated: SMU wakes it via cold reset, interrupts not needed */ -atcsmu_set_command (DEEP_SLEEP_CMD , hartid); rc =atcsmu_set_reset_vector ((ulong )ae350_enable_coherency_warmboot, hartid);if (rc)return SBI_EFAIL ;ae350_non_ret_save (sbi_scratch_thishart_ptr ()); +atcsmu_set_command (DEEP_SLEEP_CMD , hartid); }ae350_disable_coherency ();
lib/utils/suspend/fdt_suspend_andes_atcsmu.c +24 -7
@@ -57,9 +57,11 @@ static int ae350_system_suspend_check(u32 sleep_type)static int ae350_system_suspend (u32 sleep_type,unsigned long addr) {u32 hartid =current_hartid (); +unsigned long saved_mie;int rc;/* Prevent the core leaving the WFI mode unexpectedly */ + saved_mie =csr_read (CSR_MIE );csr_write (CSR_MIE ,0 );/* SMU wakes the primary hart on RTC alarm / UART2 */
@@ -68,7 +70,7 @@ static int ae350_system_suspend(u32 sleep_type, unsigned long addr)if (sleep_type ==SBI_SUSP_AE350_LIGHT_SLEEP ) { rc =wait_secondary_harts_sleep (hartid, false);if (rc) -return rc; + goto err_restore_mie;/* Clock-gated only: enable SEI to resume past the WFI */ csr_set (CSR_MIE ,MIP_SEIP );
@@ -76,18 +78,24 @@ static int ae350_system_suspend(u32 sleep_type, unsigned long addr) }else if (sleep_type ==SBI_SUSP_SLEEP_TYPE_SUSPEND ) { rc =wait_secondary_harts_sleep (hartid, true);if (rc) -return rc; + goto err_restore_mie; -atcsmu_set_command (DEEP_SLEEP_CMD , hartid); rc =atcsmu_set_reset_vector ((ulong )ae350_enable_coherency_warmboot, hartid);if (rc) -return rc; + goto err_restore_mie;ae350_non_ret_save (sbi_scratch_thishart_ptr ()); -fdt_cmo_llc_enable (false); + +/* No LLC is fine; only fail on real errors */ + rc =fdt_cmo_llc_enable (false); +if (rc && rc !=SBI_ENODEV ) + goto err_discard_save; + rc =fdt_cmo_llc_flush_all (); -if (rc) -return rc; +if (rc && rc !=SBI_ENODEV ) + goto err_enable_llc; + +atcsmu_set_command (DEEP_SLEEP_CMD , hartid); }ae350_disable_coherency ();
@@ -97,6 +105,15 @@ static int ae350_system_suspend(u32 sleep_type, unsigned long addr)ae350_enable_coherency ();return SBI_OK ; + +err_enable_llc: +fdt_cmo_llc_enable (true); +err_discard_save: +ae350_non_ret_discard (sbi_scratch_thishart_ptr ()); +err_restore_mie: +csr_write (CSR_MIE , saved_mie); + +return rc; }static void ae350_system_resume (void )
platform/generic/andes/ae350.c +8 -0
@@ -38,6 +38,14 @@ void ae350_non_ret_save(struct sbi_scratch *scratch) andes_hdata->saved = true; } +void ae350_non_ret_discard (struct sbi_scratch *scratch) +{ +struct andes_hart_data *andes_hdata =sbi_scratch_offset_ptr (scratch, + andes_hart_data_offset); + + andes_hdata->saved = false; +} +void ae350_non_ret_restore (struct sbi_scratch *scratch) { struct andes_hart_data *andes_hdata = sbi_scratch_offset_ptr(scratch,
platform/generic/include/andes/andes.h +1 -0
@@ -102,6 +102,7 @@ struct andes_hart_data { };void ae350_non_ret_save (struct sbi_scratch *scratch); +void ae350_non_ret_discard (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
Anup Patel
AppliedQuoted 24 lines · Ben Zong-You Xie
Fixes and cleanups for the Andes last level cache, HSM and suspend drivers, collected while bringing up suspend to RAM on the AE350 platform.
Below is the summary of this patch set:
- Patch 1 makesandes_llcache_enable()return 0 on success, as thecache_enable()callback is documented to. Nothing checks it today, but patch 7 does.
- Patch 2 puts the SMU and LLC register regions in the root domain, so the supervisor can reach them under Smepmp.
- Patch 3 pairs the non-retentive CSR save and restore with an explicit flag instead of inferring it from the boot count and sleep type.
- Patch 4 restores those CSRs on the system-suspend resume path, which never reached the old call site.
- Patch 5 wakes a sleeping hart with a plain IPI and drops the SMUWAKEUP_CMDpath.
- Patch 6 polls the secondary harts until they are really asleep instead of checking once.
- Patch 7 arms the SMU last and unwinds an aborted suspend rather than leaving the hart half configured.Signed-off-by Ben Zong-You Xie <[email protected]>
Quoted 9 lines
Ben Zong-You Xie (7):
lib: utils/cache: fixandes_llcache_enable()return value
lib: utils/andes: add the SMU and LLC registers to the root domain
platform: generic/andes: pair non-retentive CSR save/restore with a
flag
lib: utils/suspend: restore Andes CSRs on system-suspend resume
lib: utils/hsm: wake sleeping Andes harts with an IPI
lib: utils/suspend: wait for the secondary Andes harts to sleep
lib: utils/andes: arm the SMU sleep command last
Applied this series to the riscv/opensbi repo.
Thanks,
Anup
Quoted 16 lines
include/sbi_utils/hsm/fdt_hsm_andes_atcsmu.h | 8 ++- lib/utils/cache/fdt_andes_llcache.c | 23 +++++-- lib/utils/hsm/fdt_hsm_andes_atcsmu.c | 64 ++++++++---------- lib/utils/suspend/fdt_suspend_andes_atcsmu.c | 70 ++++++++++++++------ platform/generic/andes/ae350.c | 26 ++++++-- platform/generic/include/andes/andes.h | 4 ++ 6 files changed, 129 insertions(+), 66 deletions(-)--
2.34.1--
opensbi mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/opensbi
Signature · 3 lines
opensbi mailing list [email protected] http://lists.infradead.org/mailman/listinfo/opensbi