2 * Meta cache partition manipulation.
4 * Copyright 2010 Imagination Technologies Ltd.
7 #include <linux/kernel.h>
9 #include <linux/errno.h>
10 #include <asm/processor.h>
11 #include <asm/cachepart.h>
12 #include <asm/metag_isa.h>
13 #include <asm/metag_mem.h>
15 #define SYSC_DCPART(n) (SYSC_DCPART0 + SYSC_xCPARTn_STRIDE * (n))
16 #define SYSC_ICPART(n) (SYSC_ICPART0 + SYSC_xCPARTn_STRIDE * (n))
18 #define CACHE_ASSOCIATIVITY 4 /* 4 way set-assosiative */
22 /* The CORE_CONFIG2 register is not available on Meta 1 */
23 #ifdef CONFIG_METAG_META21
24 unsigned int get_dcache_size(void)
26 unsigned int config2
= metag_in32(METAC_CORE_CONFIG2
);
27 return 0x1000 << ((config2
& METAC_CORECFG2_DCSZ_BITS
)
28 >> METAC_CORECFG2_DCSZ_S
);
31 unsigned int get_icache_size(void)
33 unsigned int config2
= metag_in32(METAC_CORE_CONFIG2
);
34 return 0x1000 << ((config2
& METAC_CORE_C2ICSZ_BITS
)
35 >> METAC_CORE_C2ICSZ_S
);
38 unsigned int get_global_dcache_size(void)
40 unsigned int cpart
= metag_in32(SYSC_DCPART(hard_processor_id()));
41 unsigned int temp
= cpart
& SYSC_xCPARTG_AND_BITS
;
42 return (get_dcache_size() * ((temp
>> SYSC_xCPARTG_AND_S
) + 1)) >> 4;
45 unsigned int get_global_icache_size(void)
47 unsigned int cpart
= metag_in32(SYSC_ICPART(hard_processor_id()));
48 unsigned int temp
= cpart
& SYSC_xCPARTG_AND_BITS
;
49 return (get_icache_size() * ((temp
>> SYSC_xCPARTG_AND_S
) + 1)) >> 4;
52 static unsigned int get_thread_cache_size(unsigned int cache
, int thread_id
)
54 unsigned int cache_size
;
55 unsigned int t_cache_part
;
56 unsigned int isEnabled
;
57 unsigned int offset
= 0;
58 isEnabled
= (cache
== DCACHE
? metag_in32(MMCU_DCACHE_CTRL_ADDR
) & 0x1 :
59 metag_in32(MMCU_ICACHE_CTRL_ADDR
) & 0x1);
62 #if PAGE_OFFSET >= LINGLOBAL_BASE
63 /* Checking for global cache */
64 cache_size
= (cache
== DCACHE
? get_global_dache_size() :
65 get_global_icache_size());
68 cache_size
= (cache
== DCACHE
? get_dcache_size() :
71 t_cache_part
= (cache
== DCACHE
?
72 (metag_in32(SYSC_DCPART(thread_id
)) >> offset
) & 0xF :
73 (metag_in32(SYSC_ICPART(thread_id
)) >> offset
) & 0xF);
74 switch (t_cache_part
) {
78 return cache_size
/ 2;
80 return cache_size
/ 4;
82 return cache_size
/ 8;
84 return cache_size
/ 16;
89 void check_for_cache_aliasing(int thread_id
)
91 unsigned int thread_cache_size
;
92 unsigned int cache_type
;
93 for (cache_type
= ICACHE
; cache_type
<= DCACHE
; cache_type
++) {
95 get_thread_cache_size(cache_type
, thread_id
);
96 if (thread_cache_size
< 0)
97 pr_emerg("Can't read %s cache size", \
98 cache_type
? "DCACHE" : "ICACHE");
99 else if (thread_cache_size
== 0)
100 /* Cache is off. No need to check for aliasing */
102 if (thread_cache_size
/ CACHE_ASSOCIATIVITY
> PAGE_SIZE
) {
103 pr_emerg("Cache aliasing detected in %s on Thread %d",
104 cache_type
? "DCACHE" : "ICACHE", thread_id
);
105 pr_warn("Total %s size: %u bytes",
106 cache_type
? "DCACHE" : "ICACHE ",
107 cache_type
? get_dcache_size()
108 : get_icache_size());
109 pr_warn("Thread %s size: %d bytes",
110 cache_type
? "CACHE" : "ICACHE",
112 pr_warn("Page Size: %lu bytes", PAGE_SIZE
);
119 void check_for_cache_aliasing(int thread_id
)
This page took 0.034841 seconds and 5 git commands to generate.