Skip to content

Commit

Permalink
[FIXUP] esp32_dport: fix cache invalidation
Browse files Browse the repository at this point in the history
Reported in #46
  • Loading branch information
igrr committed Jul 20, 2022
1 parent b8c4c24 commit 3bb3c19
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions hw/misc/esp32_dport.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@

static void esp32_cache_state_update(Esp32CacheState* cs);
static void esp32_cache_data_sync(Esp32CacheRegionState* crs);
static void esp32_cache_invalidate_all_entries(Esp32CacheRegionState* crs);

static inline uint32_t get_mmu_entry(Esp32CacheRegionState* crs, hwaddr base, hwaddr addr)
{
Expand Down Expand Up @@ -159,7 +160,9 @@ static void esp32_dport_write(void *opaque, hwaddr addr,
if (FIELD_EX32(value, DPORT_PRO_CACHE_CTRL, CACHE_FLUSH_ENA)) {
value |= R_DPORT_PRO_CACHE_CTRL_CACHE_FLUSH_DONE_MASK;
value &= ~R_DPORT_PRO_CACHE_CTRL_CACHE_FLUSH_ENA_MASK;
esp32_cache_invalidate_all_entries(&s->cache_state[0].drom0);
esp32_cache_data_sync(&s->cache_state[0].drom0);
esp32_cache_invalidate_all_entries(&s->cache_state[0].iram0);
esp32_cache_data_sync(&s->cache_state[0].iram0);
}
old_val = s->cache_state[0].cache_ctrl_reg;
Expand All @@ -179,7 +182,9 @@ static void esp32_dport_write(void *opaque, hwaddr addr,
if (FIELD_EX32(value, DPORT_APP_CACHE_CTRL, CACHE_FLUSH_ENA)) {
value |= R_DPORT_APP_CACHE_CTRL_CACHE_FLUSH_DONE_MASK;
value &= ~R_DPORT_APP_CACHE_CTRL_CACHE_FLUSH_ENA_MASK;
esp32_cache_invalidate_all_entries(&s->cache_state[1].drom0);
esp32_cache_data_sync(&s->cache_state[1].drom0);
esp32_cache_invalidate_all_entries(&s->cache_state[1].iram0);
esp32_cache_data_sync(&s->cache_state[1].iram0);
}
old_val = s->cache_state[1].cache_ctrl_reg;
Expand Down Expand Up @@ -266,6 +271,13 @@ static void esp32_cache_data_sync(Esp32CacheRegionState* crs)
memory_region_flush_rom_device(&crs->mem, 0, ESP32_CACHE_REGION_SIZE);
}

static void esp32_cache_invalidate_all_entries(Esp32CacheRegionState* crs)
{
for (int i = 0; i < ESP32_CACHE_PAGES_PER_REGION; ++i) {
crs->mmu_table[i] |= ESP32_CACHE_MMU_ENTRY_CHANGED;
}
}

static void esp32_cache_state_update(Esp32CacheState* cs)
{
bool cache_enabled = FIELD_EX32(cs->cache_ctrl_reg, DPORT_PRO_CACHE_CTRL, CACHE_ENA) != 0;
Expand Down

0 comments on commit 3bb3c19

Please sign in to comment.