Skip to content

Commit 5549ae0

Browse files
committed
change(esp_hw_support): not use ROM Cache invalidate in sleep process to avoid dirtying the L1 Cache
1 parent b29dc55 commit 5549ae0

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

components/esp_hw_support/include/esp_private/esp_pmu.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -279,11 +279,6 @@ void pmu_sleep_increase_ldo_volt(void);
279279
* power in the sleep and wake-up processes.
280280
*/
281281
void pmu_sleep_shutdown_dcdc(void);
282-
283-
/**
284-
* @brief DCDC has taken over power supply, shut down LDO to save power consumption
285-
*/
286-
void pmu_sleep_shutdown_ldo(void);
287282
#endif // SOC_DCDC_SUPPORTED
288283

289284
/**

components/esp_hw_support/port/esp32p4/pmu_sleep.c

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -318,17 +318,28 @@ void pmu_sleep_shutdown_dcdc(void) {
318318
pmu_ll_hp_set_regulator_dbias(&PMU, PMU_MODE_HP_ACTIVE, HP_CALI_ACTIVE_DBIAS_DEFAULT);
319319
}
320320

321-
void pmu_sleep_enable_dcdc(void) {
321+
FORCE_INLINE_ATTR void pmu_sleep_enable_dcdc(void) {
322322
CLEAR_PERI_REG_MASK(LP_SYSTEM_REG_SYS_CTRL_REG, LP_SYSTEM_REG_LP_FIB_DCDC_SWITCH); //0: enable, 1: disable
323323
SET_PERI_REG_MASK(PMU_DCM_CTRL_REG, PMU_DCDC_ON_REQ);
324324
REG_SET_FIELD(PMU_HP_ACTIVE_BIAS_REG, PMU_HP_ACTIVE_DCM_VSET, HP_CALI_ACTIVE_DCM_VSET_DEFAULT);
325325
}
326326

327-
void pmu_sleep_shutdown_ldo(void) {
327+
FORCE_INLINE_ATTR void pmu_sleep_shutdown_ldo(void) {
328328
CLEAR_PERI_REG_MASK(LP_SYSTEM_REG_SYS_CTRL_REG, LP_SYSTEM_REG_LP_FIB_DCDC_SWITCH); //0: enable, 1: disable
329329
CLEAR_PERI_REG_MASK(PMU_HP_ACTIVE_HP_REGULATOR0_REG, PMU_HP_ACTIVE_HP_REGULATOR_XPD);
330330
}
331331

332+
FORCE_INLINE_ATTR void pmu_sleep_cache_sync_items(uint32_t gid, uint32_t type, uint32_t map, uint32_t addr, uint32_t bytes)
333+
{
334+
REG_WRITE(CACHE_SYNC_ADDR_REG, addr);
335+
REG_WRITE(CACHE_SYNC_SIZE_REG, bytes);
336+
REG_WRITE(CACHE_SYNC_MAP_REG, map);
337+
REG_SET_FIELD(CACHE_SYNC_CTRL_REG, CACHE_SYNC_RGID, gid);
338+
REG_SET_BIT(CACHE_SYNC_CTRL_REG, type);
339+
while (!REG_GET_BIT(CACHE_SYNC_CTRL_REG, CACHE_SYNC_DONE))
340+
;
341+
}
342+
332343
static TCM_DRAM_ATTR uint32_t s_mpll_freq_mhz_before_sleep = 0;
333344

334345
TCM_IRAM_ATTR uint32_t pmu_sleep_start(uint32_t wakeup_opt, uint32_t reject_opt, uint32_t lslp_mem_inf_fpu, bool dslp)
@@ -343,11 +354,12 @@ TCM_IRAM_ATTR uint32_t pmu_sleep_start(uint32_t wakeup_opt, uint32_t reject_opt,
343354
pmu_ll_hp_clear_reject_intr_status(PMU_instance()->hal->dev);
344355
pmu_ll_hp_clear_reject_cause(PMU_instance()->hal->dev);
345356

346-
// For the sleep where powered down the TOP domain, the L1 cache data memory will be lost and needs to be written back here.
347-
// For the sleep without power down the TOP domain, regdma retention may still be enabled, and dirty data in the L1 cache needs
348-
// to be written back so that regdma can get the correct link. So we always need to write back to L1 DCache here.
349-
// !!! Need to manually check that data in L2 memory will not be modified from now on. !!!
350-
Cache_WriteBack_All(CACHE_MAP_L1_DCACHE);
357+
// 1. For the sleep where powered down the TOP domain, the L1 cache data memory will be lost and needs to be written back here.
358+
// 2. For the sleep without power down the TOP domain, regdma retention may still be enabled, and dirty data in the L1 cache needs
359+
// to be written back so that regdma can get the correct link.
360+
// 3. We cannot use the API provided by ROM to invalidate the cache, since it is a function calling that writes data to the stack during
361+
// the return process, which results in dirty cachelines in L1 Cache again.
362+
pmu_sleep_cache_sync_items(SMMU_GID_DEFAULT, CACHE_SYNC_WRITEBACK, CACHE_MAP_L1_DCACHE, 0, 0);
351363

352364
#if CONFIG_SPIRAM
353365
psram_ctrlr_ll_wait_all_transaction_done();

0 commit comments

Comments
 (0)