GNU Linux-libre 4.9.309-gnu1
[releases.git] / arch / arm64 / include / asm / cachetype.h
1 /*
2  * Copyright (C) 2012 ARM Ltd.
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
15  */
16 #ifndef __ASM_CACHETYPE_H
17 #define __ASM_CACHETYPE_H
18
19 #include <asm/cputype.h>
20
21 #define CTR_L1IP_SHIFT          14
22 #define CTR_L1IP_MASK           3
23 #define CTR_CWG_SHIFT           24
24 #define CTR_CWG_MASK            15
25 #define CTR_DMINLINE_SHIFT      16
26 #define CTR_IMINLINE_SHIFT      0
27
28 #define CTR_CACHE_MINLINE_MASK  \
29         ((0xf << CTR_DMINLINE_SHIFT) | (0xf << CTR_IMINLINE_SHIFT))
30
31 #define ICACHE_POLICY_RESERVED  0
32 #define ICACHE_POLICY_AIVIVT    1
33 #define ICACHE_POLICY_VIPT      2
34 #define ICACHE_POLICY_PIPT      3
35
36 #ifndef __ASSEMBLY__
37
38 #include <linux/bitops.h>
39
40 #define CTR_L1IP(ctr)   (((ctr) >> CTR_L1IP_SHIFT) & CTR_L1IP_MASK)
41
42 #define ICACHEF_ALIASING        0
43 #define ICACHEF_AIVIVT          1
44
45 extern unsigned long __icache_flags;
46
47 /*
48  * NumSets, bits[27:13] - (Number of sets in cache) - 1
49  * Associativity, bits[12:3] - (Associativity of cache) - 1
50  * LineSize, bits[2:0] - (Log2(Number of words in cache line)) - 2
51  */
52 #define CCSIDR_EL1_WRITE_THROUGH        BIT(31)
53 #define CCSIDR_EL1_WRITE_BACK           BIT(30)
54 #define CCSIDR_EL1_READ_ALLOCATE        BIT(29)
55 #define CCSIDR_EL1_WRITE_ALLOCATE       BIT(28)
56 #define CCSIDR_EL1_LINESIZE_MASK        0x7
57 #define CCSIDR_EL1_LINESIZE(x)          ((x) & CCSIDR_EL1_LINESIZE_MASK)
58 #define CCSIDR_EL1_ASSOCIATIVITY_SHIFT  3
59 #define CCSIDR_EL1_ASSOCIATIVITY_MASK   0x3ff
60 #define CCSIDR_EL1_ASSOCIATIVITY(x)     \
61         (((x) >> CCSIDR_EL1_ASSOCIATIVITY_SHIFT) & CCSIDR_EL1_ASSOCIATIVITY_MASK)
62 #define CCSIDR_EL1_NUMSETS_SHIFT        13
63 #define CCSIDR_EL1_NUMSETS_MASK         0x7fff
64 #define CCSIDR_EL1_NUMSETS(x) \
65         (((x) >> CCSIDR_EL1_NUMSETS_SHIFT) & CCSIDR_EL1_NUMSETS_MASK)
66
67 #define CACHE_LINESIZE(x)       (16 << CCSIDR_EL1_LINESIZE(x))
68 #define CACHE_NUMSETS(x)        (CCSIDR_EL1_NUMSETS(x) + 1)
69 #define CACHE_ASSOCIATIVITY(x)  (CCSIDR_EL1_ASSOCIATIVITY(x) + 1)
70
71 extern u64 __attribute_const__ cache_get_ccsidr(u64 csselr);
72
73 /* Helpers for Level 1 Instruction cache csselr = 1L */
74 static inline int icache_get_linesize(void)
75 {
76         return CACHE_LINESIZE(cache_get_ccsidr(1L));
77 }
78
79 static inline int icache_get_numsets(void)
80 {
81         return CACHE_NUMSETS(cache_get_ccsidr(1L));
82 }
83
84 /*
85  * Whilst the D-side always behaves as PIPT on AArch64, aliasing is
86  * permitted in the I-cache.
87  */
88 static inline int icache_is_aliasing(void)
89 {
90         return test_bit(ICACHEF_ALIASING, &__icache_flags);
91 }
92
93 static inline int icache_is_aivivt(void)
94 {
95         return test_bit(ICACHEF_AIVIVT, &__icache_flags);
96 }
97
98 static inline u32 cache_type_cwg(void)
99 {
100         return (read_cpuid_cachetype() >> CTR_CWG_SHIFT) & CTR_CWG_MASK;
101 }
102
103 #endif  /* __ASSEMBLY__ */
104
105 #endif  /* __ASM_CACHETYPE_H */