mirror of
https://github.com/apache/nuttx.git
synced 2026-05-28 20:08:15 +08:00
xtensa/esp32: Fix himem driver crash in SMP mode
This commit is contained in:
@@ -34,6 +34,7 @@
|
|||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
#include <nuttx/config.h>
|
#include <nuttx/config.h>
|
||||||
#include <nuttx/spinlock.h>
|
#include <nuttx/spinlock.h>
|
||||||
|
#include <nuttx/init.h>
|
||||||
|
|
||||||
#include "esp32_spiram.h"
|
#include "esp32_spiram.h"
|
||||||
#include "esp32_spicache.h"
|
#include "esp32_spicache.h"
|
||||||
@@ -85,7 +86,9 @@ unsigned int IRAM_ATTR cache_sram_mmu_set(int cpu_no, int pid,
|
|||||||
uint32_t regval;
|
uint32_t regval;
|
||||||
uint32_t statecpu0;
|
uint32_t statecpu0;
|
||||||
#ifdef CONFIG_SMP
|
#ifdef CONFIG_SMP
|
||||||
|
int cpu_to_stop = 0;
|
||||||
uint32_t statecpu1;
|
uint32_t statecpu1;
|
||||||
|
bool smp_start = OSINIT_OS_READY();
|
||||||
#endif
|
#endif
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
unsigned int shift;
|
unsigned int shift;
|
||||||
@@ -168,14 +171,24 @@ unsigned int IRAM_ATTR cache_sram_mmu_set(int cpu_no, int pid,
|
|||||||
* the flash guards to make sure the cache is disabled.
|
* the flash guards to make sure the cache is disabled.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
flags = spin_lock_irqsave(NULL);
|
flags = enter_critical_section();
|
||||||
|
|
||||||
spi_disable_cache(0, &statecpu0);
|
|
||||||
|
|
||||||
#ifdef CONFIG_SMP
|
#ifdef CONFIG_SMP
|
||||||
|
/* The other CPU might be accessing the cache at the same time, just by
|
||||||
|
* using variables in external RAM.
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (smp_start)
|
||||||
|
{
|
||||||
|
cpu_to_stop = up_cpu_index() == 1 ? 0 : 1;
|
||||||
|
up_cpu_pause(cpu_to_stop);
|
||||||
|
}
|
||||||
|
|
||||||
spi_disable_cache(1, &statecpu1);
|
spi_disable_cache(1, &statecpu1);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
spi_disable_cache(0, &statecpu0);
|
||||||
|
|
||||||
/* mmu change */
|
/* mmu change */
|
||||||
|
|
||||||
for (i = 0; i < num; i++)
|
for (i = 0; i < num; i++)
|
||||||
@@ -203,9 +216,14 @@ unsigned int IRAM_ATTR cache_sram_mmu_set(int cpu_no, int pid,
|
|||||||
spi_enable_cache(0, statecpu0);
|
spi_enable_cache(0, statecpu0);
|
||||||
#ifdef CONFIG_SMP
|
#ifdef CONFIG_SMP
|
||||||
spi_enable_cache(1, statecpu1);
|
spi_enable_cache(1, statecpu1);
|
||||||
|
|
||||||
|
if (smp_start)
|
||||||
|
{
|
||||||
|
up_cpu_resume(cpu_to_stop);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
spin_unlock_irqrestore(NULL, flags);
|
leave_critical_section(flags);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user