Commit d98fc70f authored by Christophe Leroy's avatar Christophe Leroy Committed by Michael Ellerman

powerpc/32: define helpers to get L1 cache sizes.

This patch defines C helpers to retrieve the size of
cache blocks and uses them in the cacheflush functions.
Signed-off-by: default avatarChristophe Leroy <christophe.leroy@c-s.fr>
Signed-off-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
parent 1cfb725f
...@@ -33,7 +33,8 @@ ...@@ -33,7 +33,8 @@
#define IFETCH_ALIGN_BYTES (1 << IFETCH_ALIGN_SHIFT) #define IFETCH_ALIGN_BYTES (1 << IFETCH_ALIGN_SHIFT)
#if defined(__powerpc64__) && !defined(__ASSEMBLY__) #if !defined(__ASSEMBLY__)
#ifdef CONFIG_PPC64
struct ppc_cache_info { struct ppc_cache_info {
u32 size; u32 size;
...@@ -53,7 +54,18 @@ struct ppc64_caches { ...@@ -53,7 +54,18 @@ struct ppc64_caches {
}; };
extern struct ppc64_caches ppc64_caches; extern struct ppc64_caches ppc64_caches;
#endif /* __powerpc64__ && ! __ASSEMBLY__ */ #else
static inline u32 l1_cache_shift(void)
{
return L1_CACHE_SHIFT;
}
static inline u32 l1_cache_bytes(void)
{
return L1_CACHE_BYTES;
}
#endif
#endif /* ! __ASSEMBLY__ */
#if defined(__ASSEMBLY__) #if defined(__ASSEMBLY__)
/* /*
......
...@@ -67,11 +67,13 @@ static inline void __flush_dcache_icache_phys(unsigned long physaddr) ...@@ -67,11 +67,13 @@ static inline void __flush_dcache_icache_phys(unsigned long physaddr)
*/ */
static inline void flush_dcache_range(unsigned long start, unsigned long stop) static inline void flush_dcache_range(unsigned long start, unsigned long stop)
{ {
void *addr = (void *)(start & ~(L1_CACHE_BYTES - 1)); unsigned long shift = l1_cache_shift();
unsigned long size = stop - (unsigned long)addr + (L1_CACHE_BYTES - 1); unsigned long bytes = l1_cache_bytes();
void *addr = (void *)(start & ~(bytes - 1));
unsigned long size = stop - (unsigned long)addr + (bytes - 1);
unsigned long i; unsigned long i;
for (i = 0; i < size >> L1_CACHE_SHIFT; i++, addr += L1_CACHE_BYTES) for (i = 0; i < size >> shift; i++, addr += bytes)
dcbf(addr); dcbf(addr);
mb(); /* sync */ mb(); /* sync */
} }
...@@ -83,11 +85,13 @@ static inline void flush_dcache_range(unsigned long start, unsigned long stop) ...@@ -83,11 +85,13 @@ static inline void flush_dcache_range(unsigned long start, unsigned long stop)
*/ */
static inline void clean_dcache_range(unsigned long start, unsigned long stop) static inline void clean_dcache_range(unsigned long start, unsigned long stop)
{ {
void *addr = (void *)(start & ~(L1_CACHE_BYTES - 1)); unsigned long shift = l1_cache_shift();
unsigned long size = stop - (unsigned long)addr + (L1_CACHE_BYTES - 1); unsigned long bytes = l1_cache_bytes();
void *addr = (void *)(start & ~(bytes - 1));
unsigned long size = stop - (unsigned long)addr + (bytes - 1);
unsigned long i; unsigned long i;
for (i = 0; i < size >> L1_CACHE_SHIFT; i++, addr += L1_CACHE_BYTES) for (i = 0; i < size >> shift; i++, addr += bytes)
dcbst(addr); dcbst(addr);
mb(); /* sync */ mb(); /* sync */
} }
...@@ -100,11 +104,13 @@ static inline void clean_dcache_range(unsigned long start, unsigned long stop) ...@@ -100,11 +104,13 @@ static inline void clean_dcache_range(unsigned long start, unsigned long stop)
static inline void invalidate_dcache_range(unsigned long start, static inline void invalidate_dcache_range(unsigned long start,
unsigned long stop) unsigned long stop)
{ {
void *addr = (void *)(start & ~(L1_CACHE_BYTES - 1)); unsigned long shift = l1_cache_shift();
unsigned long size = stop - (unsigned long)addr + (L1_CACHE_BYTES - 1); unsigned long bytes = l1_cache_bytes();
void *addr = (void *)(start & ~(bytes - 1));
unsigned long size = stop - (unsigned long)addr + (bytes - 1);
unsigned long i; unsigned long i;
for (i = 0; i < size >> L1_CACHE_SHIFT; i++, addr += L1_CACHE_BYTES) for (i = 0; i < size >> shift; i++, addr += bytes)
dcbi(addr); dcbi(addr);
mb(); /* sync */ mb(); /* sync */
} }
......
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