blob: 0abeb0e2d616d5376646361836f63db0c8a32819 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Aneesh Kumar K.V11a6f6a2016-04-29 23:25:41 +10002#ifndef _ASM_POWERPC_BOOK3S_64_MMU_H_
3#define _ASM_POWERPC_BOOK3S_64_MMU_H_
4
5#ifndef __ASSEMBLY__
6/*
7 * Page size definition
8 *
9 * shift : is the "PAGE_SHIFT" value for that page size
10 * sllp : is a bit mask with the value of SLB L || LP to be or'ed
11 * directly to a slbmte "vsid" value
12 * penc : is the HPTE encoding mask for the "LP" field:
13 *
14 */
15struct mmu_psize_def {
16 unsigned int shift; /* number of bits */
17 int penc[MMU_PAGE_COUNT]; /* HPTE encoding */
18 unsigned int tlbiel; /* tlbiel supported for that page size */
19 unsigned long avpnm; /* bits to mask out in AVPN in the HPTE */
Aneesh Kumar K.V2bfd65e2016-04-29 23:25:58 +100020 union {
21 unsigned long sllp; /* SLB L||LP (exact mask to use in slbmte) */
22 unsigned long ap; /* Ap encoding used by PowerISA 3.0 */
23 };
Aneesh Kumar K.V11a6f6a2016-04-29 23:25:41 +100024};
25extern struct mmu_psize_def mmu_psize_defs[MMU_PAGE_COUNT];
Aneesh Kumar K.V566ca992016-04-29 23:25:53 +100026
Aneesh Kumar K.V11a6f6a2016-04-29 23:25:41 +100027#endif /* __ASSEMBLY__ */
28
Aneesh Kumar K.V11a6f6a2016-04-29 23:25:41 +100029/* 64-bit classic hash table MMU */
30#include <asm/book3s/64/mmu-hash.h>
Aneesh Kumar K.V11a6f6a2016-04-29 23:25:41 +100031
32#ifndef __ASSEMBLY__
Aneesh Kumar K.Ve9983342016-04-29 23:25:42 +100033/*
Masahiro Yamada8ab102d2017-02-27 14:28:55 -080034 * ISA 3.0 partition and process table entry format
Aneesh Kumar K.Ve9983342016-04-29 23:25:42 +100035 */
36struct prtb_entry {
37 __be64 prtb0;
38 __be64 prtb1;
39};
40extern struct prtb_entry *process_tb;
41
42struct patb_entry {
43 __be64 patb0;
44 __be64 patb1;
45};
46extern struct patb_entry *partition_tb;
47
Paul Mackerrasdbcbfee2017-01-30 21:21:37 +110048/* Bits in patb0 field */
Aneesh Kumar K.Ve9983342016-04-29 23:25:42 +100049#define PATB_HR (1UL << 63)
Paul Mackerras70cd4c12017-02-27 11:51:37 +110050#define RPDB_MASK 0x0fffffffffffff00UL
Aneesh Kumar K.Ve9983342016-04-29 23:25:42 +100051#define RPDB_SHIFT (1UL << 8)
Paul Mackerrasdbcbfee2017-01-30 21:21:37 +110052#define RTS1_SHIFT 61 /* top 2 bits of radix tree size */
53#define RTS1_MASK (3UL << RTS1_SHIFT)
54#define RTS2_SHIFT 5 /* bottom 3 bits of radix tree size */
55#define RTS2_MASK (7UL << RTS2_SHIFT)
56#define RPDS_MASK 0x1f /* root page dir. size field */
57
58/* Bits in patb1 field */
59#define PATB_GR (1UL << 63) /* guest uses radix; must match HR */
60#define PRTS_MASK 0x1f /* process table size field */
Paul Mackerras70cd4c12017-02-27 11:51:37 +110061#define PRTB_MASK 0x0ffffffffffff000UL
Paul Mackerrasdbcbfee2017-01-30 21:21:37 +110062
Benjamin Herrenschmidta25bd722017-07-24 14:26:06 +100063/* Number of supported PID bits */
64extern unsigned int mmu_pid_bits;
65
66/* Base PID to allocate from */
67extern unsigned int mmu_base_pid;
68
69#define PRTB_SIZE_SHIFT (mmu_pid_bits + 4)
70#define PRTB_ENTRIES (1ul << mmu_pid_bits)
Michael Ellerman760573c2017-03-29 22:36:56 +110071
Aneesh Kumar K.Ve9983342016-04-29 23:25:42 +100072/*
73 * Power9 currently only support 64K partition table size.
74 */
75#define PATB_SIZE_SHIFT 16
Aneesh Kumar K.V11a6f6a2016-04-29 23:25:41 +100076
77typedef unsigned long mm_context_id_t;
78struct spinlock;
79
Alistair Popple1ab66d12017-04-03 19:51:44 +100080/* Maximum possible number of NPUs in a system. */
81#define NV_MAX_NPUS 8
82
Aneesh Kumar K.V11a6f6a2016-04-29 23:25:41 +100083typedef struct {
84 mm_context_id_t id;
85 u16 user_psize; /* page size index */
86
Benjamin Herrenschmidta619e592017-07-24 14:28:02 +100087 /* Number of bits in the mm_cpumask */
88 atomic_t active_cpus;
89
Alistair Popple1ab66d12017-04-03 19:51:44 +100090 /* NPU NMMU context */
91 struct npu_context *npu_context;
92
Aneesh Kumar K.V11a6f6a2016-04-29 23:25:41 +100093#ifdef CONFIG_PPC_MM_SLICES
94 u64 low_slices_psize; /* SLB page size encodings */
95 unsigned char high_slices_psize[SLICE_ARRAY_SIZE];
Nicholas Piggin47224762017-11-10 04:27:40 +110096 unsigned long slb_addr_limit;
Aneesh Kumar K.V11a6f6a2016-04-29 23:25:41 +100097#else
98 u16 sllp; /* SLB page size encoding */
99#endif
100 unsigned long vdso_base;
101#ifdef CONFIG_PPC_SUBPAGE_PROT
102 struct subpage_prot_table spt;
103#endif /* CONFIG_PPC_SUBPAGE_PROT */
Aneesh Kumar K.V11a6f6a2016-04-29 23:25:41 +1000104#ifdef CONFIG_PPC_64K_PAGES
105 /* for 4K PTE fragment support */
106 void *pte_frag;
107#endif
108#ifdef CONFIG_SPAPR_TCE_IOMMU
109 struct list_head iommu_group_mem_list;
110#endif
Ram Pai4fb158f2018-01-18 17:50:25 -0800111
112#ifdef CONFIG_PPC_MEM_KEYS
113 /*
114 * Each bit represents one protection key.
115 * bit set -> key allocated
116 * bit unset -> key available for allocation
117 */
118 u32 pkey_allocation_map;
Ram Pai5586cf62018-01-18 17:50:32 -0800119 s16 execute_only_pkey; /* key holding execute-only protection */
Ram Pai4fb158f2018-01-18 17:50:25 -0800120#endif
Aneesh Kumar K.V11a6f6a2016-04-29 23:25:41 +1000121} mm_context_t;
122
123/*
124 * The current system page and segment sizes
125 */
126extern int mmu_linear_psize;
127extern int mmu_virtual_psize;
128extern int mmu_vmalloc_psize;
129extern int mmu_vmemmap_psize;
130extern int mmu_io_psize;
131
Aneesh Kumar K.V756d08d2016-04-29 23:25:57 +1000132/* MMU initialization */
Michael Ellerman1a01dc82016-07-26 20:09:30 +1000133void mmu_early_init_devtree(void);
Michael Ellermanbacf9cf2016-07-26 21:31:59 +1000134void hash__early_init_devtree(void);
Michael Ellerman2537b092016-07-26 21:55:27 +1000135void radix__early_init_devtree(void);
Aneesh Kumar K.V2bfd65e2016-04-29 23:25:58 +1000136extern void radix_init_native(void);
Aneesh Kumar K.V756d08d2016-04-29 23:25:57 +1000137extern void hash__early_init_mmu(void);
Aneesh Kumar K.V2bfd65e2016-04-29 23:25:58 +1000138extern void radix__early_init_mmu(void);
Aneesh Kumar K.V756d08d2016-04-29 23:25:57 +1000139static inline void early_init_mmu(void)
140{
Aneesh Kumar K.V2bfd65e2016-04-29 23:25:58 +1000141 if (radix_enabled())
142 return radix__early_init_mmu();
Aneesh Kumar K.V756d08d2016-04-29 23:25:57 +1000143 return hash__early_init_mmu();
144}
145extern void hash__early_init_mmu_secondary(void);
Aneesh Kumar K.V2bfd65e2016-04-29 23:25:58 +1000146extern void radix__early_init_mmu_secondary(void);
Aneesh Kumar K.V756d08d2016-04-29 23:25:57 +1000147static inline void early_init_mmu_secondary(void)
148{
Aneesh Kumar K.V2bfd65e2016-04-29 23:25:58 +1000149 if (radix_enabled())
150 return radix__early_init_mmu_secondary();
Aneesh Kumar K.V756d08d2016-04-29 23:25:57 +1000151 return hash__early_init_mmu_secondary();
152}
153
154extern void hash__setup_initial_memory_limit(phys_addr_t first_memblock_base,
155 phys_addr_t first_memblock_size);
Aneesh Kumar K.V2bfd65e2016-04-29 23:25:58 +1000156extern void radix__setup_initial_memory_limit(phys_addr_t first_memblock_base,
157 phys_addr_t first_memblock_size);
Aneesh Kumar K.V756d08d2016-04-29 23:25:57 +1000158static inline void setup_initial_memory_limit(phys_addr_t first_memblock_base,
159 phys_addr_t first_memblock_size)
160{
Aneesh Kumar K.Vb8f1b4f2016-07-23 14:42:35 +0530161 if (early_radix_enabled())
Aneesh Kumar K.V2bfd65e2016-04-29 23:25:58 +1000162 return radix__setup_initial_memory_limit(first_memblock_base,
163 first_memblock_size);
Aneesh Kumar K.V756d08d2016-04-29 23:25:57 +1000164 return hash__setup_initial_memory_limit(first_memblock_base,
165 first_memblock_size);
166}
Michael Ellermaneea81482016-08-04 15:32:06 +1000167
168extern int (*register_process_table)(unsigned long base, unsigned long page_size,
169 unsigned long tbl_size);
170
Paul Mackerrascc3d2942017-01-30 21:21:36 +1100171#ifdef CONFIG_PPC_PSERIES
172extern void radix_init_pseries(void);
173#else
174static inline void radix_init_pseries(void) { };
175#endif
176
Aneesh Kumar K.V11a6f6a2016-04-29 23:25:41 +1000177#endif /* __ASSEMBLY__ */
178#endif /* _ASM_POWERPC_BOOK3S_64_MMU_H_ */