Commit d1401e1d authored by Michael Hennerich's avatar Michael Hennerich Committed by Mike Frysinger

Blackfin: fix DMA/cache bug when resuming from suspend to RAM

The dma_memcpy() function takes care of flushing different caches for us.
Normally this is what we want, but when resuming from mem, we don't yet
have caches enabled.  If these functions happen to be placed into L1 mem
(which is what we're trying to relocate), then things aren't going to
work.  So define a non-cache dma_memcpy() variant to utilize in situations
like this.
Signed-off-by: default avatarMichael Hennerich <michael.hennerich@analog.com>
Signed-off-by: default avatarMike Frysinger <vapier@gentoo.org>
parent 502c8a0e
...@@ -276,6 +276,7 @@ static inline void clear_dma_irqstat(unsigned int channel) ...@@ -276,6 +276,7 @@ static inline void clear_dma_irqstat(unsigned int channel)
} }
void *dma_memcpy(void *dest, const void *src, size_t count); void *dma_memcpy(void *dest, const void *src, size_t count);
void *dma_memcpy_nocache(void *dest, const void *src, size_t count);
void *safe_dma_memcpy(void *dest, const void *src, size_t count); void *safe_dma_memcpy(void *dest, const void *src, size_t count);
void blackfin_dma_early_init(void); void blackfin_dma_early_init(void);
void early_dma_memcpy(void *dest, const void *src, size_t count); void early_dma_memcpy(void *dest, const void *src, size_t count);
......
...@@ -450,7 +450,6 @@ void *dma_memcpy(void *pdst, const void *psrc, size_t size) ...@@ -450,7 +450,6 @@ void *dma_memcpy(void *pdst, const void *psrc, size_t size)
{ {
unsigned long dst = (unsigned long)pdst; unsigned long dst = (unsigned long)pdst;
unsigned long src = (unsigned long)psrc; unsigned long src = (unsigned long)psrc;
size_t bulk, rest;
if (bfin_addr_dcacheable(src)) if (bfin_addr_dcacheable(src))
blackfin_dcache_flush_range(src, src + size); blackfin_dcache_flush_range(src, src + size);
...@@ -458,6 +457,22 @@ void *dma_memcpy(void *pdst, const void *psrc, size_t size) ...@@ -458,6 +457,22 @@ void *dma_memcpy(void *pdst, const void *psrc, size_t size)
if (bfin_addr_dcacheable(dst)) if (bfin_addr_dcacheable(dst))
blackfin_dcache_invalidate_range(dst, dst + size); blackfin_dcache_invalidate_range(dst, dst + size);
return dma_memcpy_nocache(pdst, psrc, size);
}
EXPORT_SYMBOL(dma_memcpy);
/**
* dma_memcpy_nocache - DMA memcpy under mutex lock
* - No cache flush/invalidate
*
* Do not check arguments before starting the DMA memcpy. Break the transfer
* up into two pieces. The first transfer is in multiples of 64k and the
* second transfer is the piece smaller than 64k.
*/
void *dma_memcpy_nocache(void *pdst, const void *psrc, size_t size)
{
size_t bulk, rest;
bulk = size & ~0xffff; bulk = size & ~0xffff;
rest = size - bulk; rest = size - bulk;
if (bulk) if (bulk)
...@@ -465,7 +480,7 @@ void *dma_memcpy(void *pdst, const void *psrc, size_t size) ...@@ -465,7 +480,7 @@ void *dma_memcpy(void *pdst, const void *psrc, size_t size)
_dma_memcpy(pdst + bulk, psrc + bulk, rest); _dma_memcpy(pdst + bulk, psrc + bulk, rest);
return pdst; return pdst;
} }
EXPORT_SYMBOL(dma_memcpy); EXPORT_SYMBOL(dma_memcpy_nocache);
/** /**
* safe_dma_memcpy - DMA memcpy w/argument checking * safe_dma_memcpy - DMA memcpy w/argument checking
......
...@@ -61,10 +61,11 @@ void bfin_pm_suspend_standby_enter(void) ...@@ -61,10 +61,11 @@ void bfin_pm_suspend_standby_enter(void)
int bf53x_suspend_l1_mem(unsigned char *memptr) int bf53x_suspend_l1_mem(unsigned char *memptr)
{ {
dma_memcpy(memptr, (const void *) L1_CODE_START, L1_CODE_LENGTH); dma_memcpy_nocache(memptr, (const void *) L1_CODE_START,
dma_memcpy(memptr + L1_CODE_LENGTH, (const void *) L1_DATA_A_START, L1_CODE_LENGTH);
L1_DATA_A_LENGTH); dma_memcpy_nocache(memptr + L1_CODE_LENGTH,
dma_memcpy(memptr + L1_CODE_LENGTH + L1_DATA_A_LENGTH, (const void *) L1_DATA_A_START, L1_DATA_A_LENGTH);
dma_memcpy_nocache(memptr + L1_CODE_LENGTH + L1_DATA_A_LENGTH,
(const void *) L1_DATA_B_START, L1_DATA_B_LENGTH); (const void *) L1_DATA_B_START, L1_DATA_B_LENGTH);
memcpy(memptr + L1_CODE_LENGTH + L1_DATA_A_LENGTH + memcpy(memptr + L1_CODE_LENGTH + L1_DATA_A_LENGTH +
L1_DATA_B_LENGTH, (const void *) L1_SCRATCH_START, L1_DATA_B_LENGTH, (const void *) L1_SCRATCH_START,
...@@ -75,10 +76,10 @@ int bf53x_suspend_l1_mem(unsigned char *memptr) ...@@ -75,10 +76,10 @@ int bf53x_suspend_l1_mem(unsigned char *memptr)
int bf53x_resume_l1_mem(unsigned char *memptr) int bf53x_resume_l1_mem(unsigned char *memptr)
{ {
dma_memcpy((void *) L1_CODE_START, memptr, L1_CODE_LENGTH); dma_memcpy_nocache((void *) L1_CODE_START, memptr, L1_CODE_LENGTH);
dma_memcpy((void *) L1_DATA_A_START, memptr + L1_CODE_LENGTH, dma_memcpy_nocache((void *) L1_DATA_A_START, memptr + L1_CODE_LENGTH,
L1_DATA_A_LENGTH); L1_DATA_A_LENGTH);
dma_memcpy((void *) L1_DATA_B_START, memptr + L1_CODE_LENGTH + dma_memcpy_nocache((void *) L1_DATA_B_START, memptr + L1_CODE_LENGTH +
L1_DATA_A_LENGTH, L1_DATA_B_LENGTH); L1_DATA_A_LENGTH, L1_DATA_B_LENGTH);
memcpy((void *) L1_SCRATCH_START, memptr + L1_CODE_LENGTH + memcpy((void *) L1_SCRATCH_START, memptr + L1_CODE_LENGTH +
L1_DATA_A_LENGTH + L1_DATA_B_LENGTH, L1_SCRATCH_LENGTH); L1_DATA_A_LENGTH + L1_DATA_B_LENGTH, L1_SCRATCH_LENGTH);
...@@ -167,7 +168,7 @@ int bfin_pm_suspend_mem_enter(void) ...@@ -167,7 +168,7 @@ int bfin_pm_suspend_mem_enter(void)
_disable_icplb(); _disable_icplb();
bf53x_suspend_l1_mem(memptr); bf53x_suspend_l1_mem(memptr);
do_hibernate(wakeup | vr_wakeup); /* Goodbye */ do_hibernate(wakeup | vr_wakeup); /* See you later! */
bf53x_resume_l1_mem(memptr); bf53x_resume_l1_mem(memptr);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment