blob: 6364f5c2cc3e6bbee1244a8a6dce09f968987b70 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Paul Mackerras047ea782005-11-19 20:17:32 +11002#ifndef _ASM_POWERPC_MMU_H_
3#define _ASM_POWERPC_MMU_H_
Arnd Bergmann88ced032005-12-16 22:43:46 +01004#ifdef __KERNEL__
Paul Mackerras047ea782005-11-19 20:17:32 +11005
Benjamin Herrenschmidtcd3db0c2010-07-06 15:39:02 -07006#include <linux/types.h>
7
Benjamin Herrenschmidt7c03d652008-12-18 19:13:32 +00008#include <asm/asm-compat.h>
9#include <asm/feature-fixups.h>
10
11/*
12 * MMU features bit definitions
13 */
14
15/*
Aneesh Kumar K.V5a25b6f2016-07-27 13:19:01 +100016 * MMU families
Benjamin Herrenschmidt7c03d652008-12-18 19:13:32 +000017 */
18#define MMU_FTR_HPTE_TABLE ASM_CONST(0x00000001)
19#define MMU_FTR_TYPE_8xx ASM_CONST(0x00000002)
20#define MMU_FTR_TYPE_40x ASM_CONST(0x00000004)
21#define MMU_FTR_TYPE_44x ASM_CONST(0x00000008)
22#define MMU_FTR_TYPE_FSL_E ASM_CONST(0x00000010)
Michael Ellermancd680982014-07-08 17:10:45 +100023#define MMU_FTR_TYPE_47x ASM_CONST(0x00000020)
Benjamin Herrenschmidt7c03d652008-12-18 19:13:32 +000024
Aneesh Kumar K.V5a25b6f2016-07-27 13:19:01 +100025/* Radix page table supported and enabled */
26#define MMU_FTR_TYPE_RADIX ASM_CONST(0x00000040)
27
Benjamin Herrenschmidt7c03d652008-12-18 19:13:32 +000028/*
Aneesh Kumar K.V5a25b6f2016-07-27 13:19:01 +100029 * Individual features below.
Benjamin Herrenschmidt7c03d652008-12-18 19:13:32 +000030 */
Aneesh Kumar K.V5a25b6f2016-07-27 13:19:01 +100031
Aneesh Kumar K.Vaccfad72016-07-13 15:05:24 +053032/*
Aneesh Kumar K.Ve6f81a92017-03-29 17:21:53 +110033 * Support for 68 bit VA space. We added that from ISA 2.05
34 */
35#define MMU_FTR_68_BIT_VA ASM_CONST(0x00002000)
36/*
Aneesh Kumar K.V984d7a12016-11-24 15:09:54 +053037 * Kernel read only support.
38 * We added the ppp value 0b110 in ISA 2.04.
39 */
40#define MMU_FTR_KERNEL_RO ASM_CONST(0x00004000)
41
42/*
Aneesh Kumar K.Vaccfad72016-07-13 15:05:24 +053043 * We need to clear top 16bits of va (from the remaining 64 bits )in
44 * tlbie* instructions
45 */
46#define MMU_FTR_TLBIE_CROP_VA ASM_CONST(0x00008000)
Benjamin Herrenschmidt7c03d652008-12-18 19:13:32 +000047
48/* Enable use of high BAT registers */
49#define MMU_FTR_USE_HIGH_BATS ASM_CONST(0x00010000)
50
51/* Enable >32-bit physical addresses on 32-bit processor, only used
52 * by CONFIG_6xx currently as BookE supports that from day 1
53 */
54#define MMU_FTR_BIG_PHYS ASM_CONST(0x00020000)
55
Benjamin Herrenschmidtf048aac2008-12-18 19:13:38 +000056/* Enable use of broadcast TLB invalidations. We don't always set it
57 * on processors that support it due to other constraints with the
58 * use of such invalidations
59 */
60#define MMU_FTR_USE_TLBIVAX_BCAST ASM_CONST(0x00040000)
61
Kumar Galac3071952009-02-10 22:26:06 -060062/* Enable use of tlbilx invalidate instructions.
Benjamin Herrenschmidtf048aac2008-12-18 19:13:38 +000063 */
Kumar Galac3071952009-02-10 22:26:06 -060064#define MMU_FTR_USE_TLBILX ASM_CONST(0x00080000)
Benjamin Herrenschmidtf048aac2008-12-18 19:13:38 +000065
66/* This indicates that the processor cannot handle multiple outstanding
67 * broadcast tlbivax or tlbsync. This makes the code use a spinlock
68 * around such invalidate forms.
69 */
70#define MMU_FTR_LOCK_BCAST_INVAL ASM_CONST(0x00100000)
71
Kumar Gala2319f122009-03-19 03:55:41 +000072/* This indicates that the processor doesn't handle way selection
73 * properly and needs SW to track and update the LRU state. This
74 * is specific to an errata on e300c2/c3/c4 class parts
75 */
76#define MMU_FTR_NEED_DTLB_SW_LRU ASM_CONST(0x00200000)
77
Kumar Galadf5d6ec2009-08-24 15:52:48 +000078/* Enable use of TLB reservation. Processor should support tlbsrx.
79 * instruction and MAS0[WQ].
80 */
81#define MMU_FTR_USE_TLBRSRV ASM_CONST(0x00800000)
82
83/* Use paired MAS registers (MAS7||MAS3, etc.)
84 */
85#define MMU_FTR_USE_PAIRED_MAS ASM_CONST(0x01000000)
86
Michael Ellerman13b3d132014-07-10 12:29:20 +100087/* Doesn't support the B bit (1T segment) in SLBIE
Matt Evans44ae3ab2011-04-06 19:48:50 +000088 */
Michael Ellerman13b3d132014-07-10 12:29:20 +100089#define MMU_FTR_NO_SLBIE_B ASM_CONST(0x02000000)
Matt Evans44ae3ab2011-04-06 19:48:50 +000090
91/* Support 16M large pages
92 */
93#define MMU_FTR_16M_PAGE ASM_CONST(0x04000000)
94
95/* Supports TLBIEL variant
96 */
97#define MMU_FTR_TLBIEL ASM_CONST(0x08000000)
98
99/* Supports tlbies w/o locking
100 */
101#define MMU_FTR_LOCKLESS_TLBIE ASM_CONST(0x10000000)
102
103/* Large pages can be marked CI
104 */
105#define MMU_FTR_CI_LARGE_PAGE ASM_CONST(0x20000000)
106
107/* 1T segments available
108 */
109#define MMU_FTR_1T_SEGMENT ASM_CONST(0x40000000)
110
Matt Evans44ae3ab2011-04-06 19:48:50 +0000111/* MMU feature bit sets for various CPUs */
112#define MMU_FTRS_DEFAULT_HPTE_ARCH_V2 \
113 MMU_FTR_HPTE_TABLE | MMU_FTR_PPCAS_ARCH_V2
114#define MMU_FTRS_POWER4 MMU_FTRS_DEFAULT_HPTE_ARCH_V2
Aneesh Kumar K.Vaccfad72016-07-13 15:05:24 +0530115#define MMU_FTRS_PPC970 MMU_FTRS_POWER4 | MMU_FTR_TLBIE_CROP_VA
Matt Evans44ae3ab2011-04-06 19:48:50 +0000116#define MMU_FTRS_POWER5 MMU_FTRS_POWER4 | MMU_FTR_LOCKLESS_TLBIE
Aneesh Kumar K.Ve6f81a92017-03-29 17:21:53 +1100117#define MMU_FTRS_POWER6 MMU_FTRS_POWER5 | MMU_FTR_KERNEL_RO | MMU_FTR_68_BIT_VA
118#define MMU_FTRS_POWER7 MMU_FTRS_POWER6
119#define MMU_FTRS_POWER8 MMU_FTRS_POWER6
120#define MMU_FTRS_POWER9 MMU_FTRS_POWER6
Matt Evans44ae3ab2011-04-06 19:48:50 +0000121#define MMU_FTRS_CELL MMU_FTRS_DEFAULT_HPTE_ARCH_V2 | \
122 MMU_FTR_CI_LARGE_PAGE
123#define MMU_FTRS_PA6T MMU_FTRS_DEFAULT_HPTE_ARCH_V2 | \
124 MMU_FTR_CI_LARGE_PAGE | MMU_FTR_NO_SLBIE_B
Benjamin Herrenschmidt7c03d652008-12-18 19:13:32 +0000125#ifndef __ASSEMBLY__
Kevin Hao4db73272016-07-23 14:42:41 +0530126#include <linux/bug.h>
Benjamin Herrenschmidt7c03d652008-12-18 19:13:32 +0000127#include <asm/cputable.h>
128
Becky Bruce3160b092011-06-28 14:54:47 -0500129#ifdef CONFIG_PPC_FSL_BOOK3E
130#include <asm/percpu.h>
131DECLARE_PER_CPU(int, next_tlbcam_idx);
132#endif
133
Michael Ellerman773edea2016-05-11 15:30:47 +1000134enum {
135 MMU_FTRS_POSSIBLE = MMU_FTR_HPTE_TABLE | MMU_FTR_TYPE_8xx |
136 MMU_FTR_TYPE_40x | MMU_FTR_TYPE_44x | MMU_FTR_TYPE_FSL_E |
137 MMU_FTR_TYPE_47x | MMU_FTR_USE_HIGH_BATS | MMU_FTR_BIG_PHYS |
138 MMU_FTR_USE_TLBIVAX_BCAST | MMU_FTR_USE_TLBILX |
139 MMU_FTR_LOCK_BCAST_INVAL | MMU_FTR_NEED_DTLB_SW_LRU |
140 MMU_FTR_USE_TLBRSRV | MMU_FTR_USE_PAIRED_MAS |
141 MMU_FTR_NO_SLBIE_B | MMU_FTR_16M_PAGE | MMU_FTR_TLBIEL |
142 MMU_FTR_LOCKLESS_TLBIE | MMU_FTR_CI_LARGE_PAGE |
Aneesh Kumar K.Vaccfad72016-07-13 15:05:24 +0530143 MMU_FTR_1T_SEGMENT | MMU_FTR_TLBIE_CROP_VA |
Aneesh Kumar K.Ve6f81a92017-03-29 17:21:53 +1100144 MMU_FTR_KERNEL_RO | MMU_FTR_68_BIT_VA |
Aneesh Kumar K.Va8ed87c2016-04-29 23:26:06 +1000145#ifdef CONFIG_PPC_RADIX_MMU
Aneesh Kumar K.V5a25b6f2016-07-27 13:19:01 +1000146 MMU_FTR_TYPE_RADIX |
Aneesh Kumar K.Va8ed87c2016-04-29 23:26:06 +1000147#endif
148 0,
Michael Ellerman773edea2016-05-11 15:30:47 +1000149};
150
Michael Ellermana141cca2016-07-27 20:48:36 +1000151static inline bool early_mmu_has_feature(unsigned long feature)
Benjamin Herrenschmidt7c03d652008-12-18 19:13:32 +0000152{
Michael Ellermana81dc9d2016-07-27 13:39:42 +1000153 return !!(MMU_FTRS_POSSIBLE & cur_cpu_spec->mmu_features & feature);
Benjamin Herrenschmidt7c03d652008-12-18 19:13:32 +0000154}
155
Kevin Haoc12e6f22016-07-23 14:42:42 +0530156#ifdef CONFIG_JUMP_LABEL_FEATURE_CHECKS
157#include <linux/jump_label.h>
158
159#define NUM_MMU_FTR_KEYS 32
160
161extern struct static_key_true mmu_feature_keys[NUM_MMU_FTR_KEYS];
162
163extern void mmu_feature_keys_init(void);
164
165static __always_inline bool mmu_has_feature(unsigned long feature)
166{
167 int i;
168
Michael Ellermanb5fa0f72017-01-24 16:36:57 +1100169#ifndef __clang__ /* clang can't cope with this */
Kevin Haoc12e6f22016-07-23 14:42:42 +0530170 BUILD_BUG_ON(!__builtin_constant_p(feature));
Michael Ellermanb5fa0f72017-01-24 16:36:57 +1100171#endif
Kevin Haoc12e6f22016-07-23 14:42:42 +0530172
Aneesh Kumar K.Vc812c7d2016-07-23 14:42:43 +0530173#ifdef CONFIG_JUMP_LABEL_FEATURE_CHECK_DEBUG
174 if (!static_key_initialized) {
175 printk("Warning! mmu_has_feature() used prior to jump label init!\n");
176 dump_stack();
177 return early_mmu_has_feature(feature);
178 }
179#endif
180
Kevin Haoc12e6f22016-07-23 14:42:42 +0530181 if (!(MMU_FTRS_POSSIBLE & feature))
182 return false;
183
184 i = __builtin_ctzl(feature);
185 return static_branch_likely(&mmu_feature_keys[i]);
186}
187
188static inline void mmu_clear_feature(unsigned long feature)
189{
190 int i;
191
192 i = __builtin_ctzl(feature);
193 cur_cpu_spec->mmu_features &= ~feature;
194 static_branch_disable(&mmu_feature_keys[i]);
195}
196#else
197
198static inline void mmu_feature_keys_init(void)
199{
200
201}
202
Michael Ellermana141cca2016-07-27 20:48:36 +1000203static inline bool mmu_has_feature(unsigned long feature)
204{
205 return early_mmu_has_feature(feature);
206}
207
Dave Kleikamp91b191c2011-07-04 18:38:03 +0000208static inline void mmu_clear_feature(unsigned long feature)
209{
210 cur_cpu_spec->mmu_features &= ~feature;
211}
Kevin Haoc12e6f22016-07-23 14:42:42 +0530212#endif /* CONFIG_JUMP_LABEL */
Dave Kleikamp91b191c2011-07-04 18:38:03 +0000213
Benjamin Herrenschmidt7c03d652008-12-18 19:13:32 +0000214extern unsigned int __start___mmu_ftr_fixup, __stop___mmu_ftr_fixup;
215
Benjamin Herrenschmidtcd3db0c2010-07-06 15:39:02 -0700216#ifdef CONFIG_PPC64
217/* This is our real memory area size on ppc64 server, on embedded, we
218 * make it match the size our of bolted TLB area
219 */
220extern u64 ppc64_rma_size;
Benjamin Herrenschmidtfe036a02016-08-19 14:22:37 +0530221
222/* Cleanup function used by kexec */
223extern void mmu_cleanup_all(void);
224extern void radix__mmu_cleanup_all(void);
Paul Mackerras9d661952016-11-21 16:00:58 +1100225
226/* Functions for creating and updating partition table on POWER9 */
227extern void mmu_partition_table_init(void);
228extern void mmu_partition_table_set_entry(unsigned int lpid, unsigned long dw0,
229 unsigned long dw1);
Benjamin Herrenschmidtcd3db0c2010-07-06 15:39:02 -0700230#endif /* CONFIG_PPC64 */
231
Aneesh Kumar K.V78f1dbd2012-09-10 02:52:57 +0000232struct mm_struct;
233#ifdef CONFIG_DEBUG_VM
234extern void assert_pte_locked(struct mm_struct *mm, unsigned long addr);
235#else /* CONFIG_DEBUG_VM */
236static inline void assert_pte_locked(struct mm_struct *mm, unsigned long addr)
237{
238}
239#endif /* !CONFIG_DEBUG_VM */
240
Michael Ellermanbab4c8d2016-07-27 13:37:58 +1000241#ifdef CONFIG_PPC_RADIX_MMU
242static inline bool radix_enabled(void)
243{
244 return mmu_has_feature(MMU_FTR_TYPE_RADIX);
245}
Michael Ellermana141cca2016-07-27 20:48:36 +1000246
247static inline bool early_radix_enabled(void)
248{
249 return early_mmu_has_feature(MMU_FTR_TYPE_RADIX);
250}
Michael Ellermanbab4c8d2016-07-27 13:37:58 +1000251#else
252static inline bool radix_enabled(void)
253{
254 return false;
255}
Michael Ellermana141cca2016-07-27 20:48:36 +1000256
257static inline bool early_radix_enabled(void)
258{
259 return false;
260}
Michael Ellermanbab4c8d2016-07-27 13:37:58 +1000261#endif
262
Benjamin Herrenschmidt7c03d652008-12-18 19:13:32 +0000263#endif /* !__ASSEMBLY__ */
264
Benjamin Herrenschmidt57e2a992009-07-28 11:59:34 +1000265/* The kernel use the constants below to index in the page sizes array.
266 * The use of fixed constants for this purpose is better for performances
267 * of the low level hash refill handlers.
268 *
269 * A non supported page size has a "shift" field set to 0
270 *
271 * Any new page size being implemented can get a new entry in here. Whether
272 * the kernel will use it or not is a different matter though. The actual page
273 * size used by hugetlbfs is not defined here and may be made variable
274 *
275 * Note: This array ended up being a false good idea as it's growing to the
276 * point where I wonder if we should replace it with something different,
277 * to think about, feedback welcome. --BenH.
278 */
279
Scott Wooda8b91e42012-06-14 13:40:55 +0000280/* These are #defines as they have to be used in assembly */
Benjamin Herrenschmidt57e2a992009-07-28 11:59:34 +1000281#define MMU_PAGE_4K 0
282#define MMU_PAGE_16K 1
283#define MMU_PAGE_64K 2
284#define MMU_PAGE_64K_AP 3 /* "Admixed pages" (hash64 only) */
285#define MMU_PAGE_256K 4
Christophe Leroy4b9142862016-12-07 08:47:28 +0100286#define MMU_PAGE_512K 5
287#define MMU_PAGE_1M 6
288#define MMU_PAGE_2M 7
289#define MMU_PAGE_4M 8
290#define MMU_PAGE_8M 9
291#define MMU_PAGE_16M 10
292#define MMU_PAGE_64M 11
293#define MMU_PAGE_256M 12
294#define MMU_PAGE_1G 13
295#define MMU_PAGE_16G 14
296#define MMU_PAGE_64G 15
Benjamin Herrenschmidt57e2a992009-07-28 11:59:34 +1000297
Aneesh Kumar K.Ve6f81a92017-03-29 17:21:53 +1100298/*
299 * N.B. we need to change the type of hpte_page_sizes if this gets to be > 16
300 * Also we need to change he type of mm_context.low/high_slices_psize.
301 */
Christophe Leroy4b9142862016-12-07 08:47:28 +0100302#define MMU_PAGE_COUNT 16
Benjamin Herrenschmidt7c03d652008-12-18 19:13:32 +0000303
Aneesh Kumar K.V11a6f6a2016-04-29 23:25:41 +1000304#ifdef CONFIG_PPC_BOOK3S_64
305#include <asm/book3s/64/mmu.h>
306#else /* CONFIG_PPC_BOOK3S_64 */
307
Aneesh Kumar K.V756d08d2016-04-29 23:25:57 +1000308#ifndef __ASSEMBLY__
309/* MMU initialization */
310extern void early_init_mmu(void);
311extern void early_init_mmu_secondary(void);
312extern void setup_initial_memory_limit(phys_addr_t first_memblock_base,
313 phys_addr_t first_memblock_size);
Michael Ellerman1a01dc82016-07-26 20:09:30 +1000314static inline void mmu_early_init_devtree(void) { }
Aneesh Kumar K.V756d08d2016-04-29 23:25:57 +1000315#endif /* __ASSEMBLY__ */
Aneesh Kumar K.V11a6f6a2016-04-29 23:25:41 +1000316#endif
317
318#if defined(CONFIG_PPC_STD_MMU_32)
David Gibson4db68bf2007-06-13 14:52:54 +1000319/* 32-bit classic hash table MMU */
Aneesh Kumar K.Vf64e8082016-03-01 12:59:20 +0530320#include <asm/book3s/32/mmu-hash.h>
Josh Boyer4d922c82007-08-20 07:28:48 -0500321#elif defined(CONFIG_40x)
322/* 40x-style software loaded TLB */
323# include <asm/mmu-40x.h>
David Gibson57d79092007-04-30 14:06:25 +1000324#elif defined(CONFIG_44x)
325/* 44x-style software loaded TLB */
326# include <asm/mmu-44x.h>
Kumar Gala70fe3af2009-02-12 16:12:40 -0600327#elif defined(CONFIG_PPC_BOOK3E_MMU)
328/* Freescale Book-E software loaded TLB or Book-3e (ISA 2.06+) MMU */
329# include <asm/mmu-book3e.h>
David Gibson31202342007-06-22 14:58:55 +1000330#elif defined (CONFIG_PPC_8xx)
331/* Motorola/Freescale 8xx software loaded TLB */
332# include <asm/mmu-8xx.h>
David Gibson1f8d4192005-05-05 16:15:13 -0700333#endif
David Gibson1f8d4192005-05-05 16:15:13 -0700334
Arnd Bergmann88ced032005-12-16 22:43:46 +0100335#endif /* __KERNEL__ */
Paul Mackerras047ea782005-11-19 20:17:32 +1100336#endif /* _ASM_POWERPC_MMU_H_ */