blob: c4b865112d2484709bf8b17b4ba3c830fc25232a [file] [log] [blame]
Aneesh Kumar K.V11a6f6a2016-04-29 23:25:41 +10001#ifndef _ASM_POWERPC_BOOK3S_64_MMU_H_
2#define _ASM_POWERPC_BOOK3S_64_MMU_H_
3
4#ifndef __ASSEMBLY__
5/*
6 * Page size definition
7 *
8 * shift : is the "PAGE_SHIFT" value for that page size
9 * sllp : is a bit mask with the value of SLB L || LP to be or'ed
10 * directly to a slbmte "vsid" value
11 * penc : is the HPTE encoding mask for the "LP" field:
12 *
13 */
14struct mmu_psize_def {
15 unsigned int shift; /* number of bits */
16 int penc[MMU_PAGE_COUNT]; /* HPTE encoding */
17 unsigned int tlbiel; /* tlbiel supported for that page size */
18 unsigned long avpnm; /* bits to mask out in AVPN in the HPTE */
Aneesh Kumar K.V2bfd65e2016-04-29 23:25:58 +100019 union {
20 unsigned long sllp; /* SLB L||LP (exact mask to use in slbmte) */
21 unsigned long ap; /* Ap encoding used by PowerISA 3.0 */
22 };
Aneesh Kumar K.V11a6f6a2016-04-29 23:25:41 +100023};
24extern struct mmu_psize_def mmu_psize_defs[MMU_PAGE_COUNT];
Aneesh Kumar K.V566ca992016-04-29 23:25:53 +100025
Aneesh Kumar K.V11a6f6a2016-04-29 23:25:41 +100026#endif /* __ASSEMBLY__ */
27
Aneesh Kumar K.V11a6f6a2016-04-29 23:25:41 +100028/* 64-bit classic hash table MMU */
29#include <asm/book3s/64/mmu-hash.h>
Aneesh Kumar K.V11a6f6a2016-04-29 23:25:41 +100030
31#ifndef __ASSEMBLY__
Aneesh Kumar K.Ve9983342016-04-29 23:25:42 +100032/*
Masahiro Yamada8ab102d2017-02-27 14:28:55 -080033 * ISA 3.0 partition and process table entry format
Aneesh Kumar K.Ve9983342016-04-29 23:25:42 +100034 */
35struct prtb_entry {
36 __be64 prtb0;
37 __be64 prtb1;
38};
39extern struct prtb_entry *process_tb;
40
41struct patb_entry {
42 __be64 patb0;
43 __be64 patb1;
44};
45extern struct patb_entry *partition_tb;
46
Paul Mackerrasdbcbfee2017-01-30 21:21:37 +110047/* Bits in patb0 field */
Aneesh Kumar K.Ve9983342016-04-29 23:25:42 +100048#define PATB_HR (1UL << 63)
Paul Mackerras70cd4c12017-02-27 11:51:37 +110049#define RPDB_MASK 0x0fffffffffffff00UL
Aneesh Kumar K.Ve9983342016-04-29 23:25:42 +100050#define RPDB_SHIFT (1UL << 8)
Paul Mackerrasdbcbfee2017-01-30 21:21:37 +110051#define RTS1_SHIFT 61 /* top 2 bits of radix tree size */
52#define RTS1_MASK (3UL << RTS1_SHIFT)
53#define RTS2_SHIFT 5 /* bottom 3 bits of radix tree size */
54#define RTS2_MASK (7UL << RTS2_SHIFT)
55#define RPDS_MASK 0x1f /* root page dir. size field */
56
57/* Bits in patb1 field */
58#define PATB_GR (1UL << 63) /* guest uses radix; must match HR */
59#define PRTS_MASK 0x1f /* process table size field */
Paul Mackerras70cd4c12017-02-27 11:51:37 +110060#define PRTB_MASK 0x0ffffffffffff000UL
Paul Mackerrasdbcbfee2017-01-30 21:21:37 +110061
Aneesh Kumar K.Ve9983342016-04-29 23:25:42 +100062/*
63 * Limit process table to PAGE_SIZE table. This
64 * also limit the max pid we can support.
65 * MAX_USER_CONTEXT * 16 bytes of space.
66 */
67#define PRTB_SIZE_SHIFT (CONTEXT_BITS + 4)
Michael Ellerman760573c2017-03-29 22:36:56 +110068#define PRTB_ENTRIES (1ul << CONTEXT_BITS)
69
Aneesh Kumar K.Ve9983342016-04-29 23:25:42 +100070/*
71 * Power9 currently only support 64K partition table size.
72 */
73#define PATB_SIZE_SHIFT 16
Aneesh Kumar K.V11a6f6a2016-04-29 23:25:41 +100074
75typedef unsigned long mm_context_id_t;
76struct spinlock;
77
78typedef struct {
79 mm_context_id_t id;
80 u16 user_psize; /* page size index */
81
82#ifdef CONFIG_PPC_MM_SLICES
83 u64 low_slices_psize; /* SLB page size encodings */
84 unsigned char high_slices_psize[SLICE_ARRAY_SIZE];
Aneesh Kumar K.V957b7782017-03-22 09:06:58 +053085 unsigned long addr_limit;
Aneesh Kumar K.V11a6f6a2016-04-29 23:25:41 +100086#else
87 u16 sllp; /* SLB page size encoding */
88#endif
89 unsigned long vdso_base;
90#ifdef CONFIG_PPC_SUBPAGE_PROT
91 struct subpage_prot_table spt;
92#endif /* CONFIG_PPC_SUBPAGE_PROT */
93#ifdef CONFIG_PPC_ICSWX
94 struct spinlock *cop_lockp; /* guard acop and cop_pid */
95 unsigned long acop; /* mask of enabled coprocessor types */
96 unsigned int cop_pid; /* pid value used with coprocessors */
97#endif /* CONFIG_PPC_ICSWX */
98#ifdef CONFIG_PPC_64K_PAGES
99 /* for 4K PTE fragment support */
100 void *pte_frag;
101#endif
102#ifdef CONFIG_SPAPR_TCE_IOMMU
103 struct list_head iommu_group_mem_list;
104#endif
105} mm_context_t;
106
107/*
108 * The current system page and segment sizes
109 */
110extern int mmu_linear_psize;
111extern int mmu_virtual_psize;
112extern int mmu_vmalloc_psize;
113extern int mmu_vmemmap_psize;
114extern int mmu_io_psize;
115
Aneesh Kumar K.V756d08d2016-04-29 23:25:57 +1000116/* MMU initialization */
Michael Ellerman1a01dc82016-07-26 20:09:30 +1000117void mmu_early_init_devtree(void);
Michael Ellermanbacf9cf2016-07-26 21:31:59 +1000118void hash__early_init_devtree(void);
Michael Ellerman2537b092016-07-26 21:55:27 +1000119void radix__early_init_devtree(void);
Aneesh Kumar K.V2bfd65e2016-04-29 23:25:58 +1000120extern void radix_init_native(void);
Aneesh Kumar K.V756d08d2016-04-29 23:25:57 +1000121extern void hash__early_init_mmu(void);
Aneesh Kumar K.V2bfd65e2016-04-29 23:25:58 +1000122extern void radix__early_init_mmu(void);
Aneesh Kumar K.V756d08d2016-04-29 23:25:57 +1000123static inline void early_init_mmu(void)
124{
Aneesh Kumar K.V2bfd65e2016-04-29 23:25:58 +1000125 if (radix_enabled())
126 return radix__early_init_mmu();
Aneesh Kumar K.V756d08d2016-04-29 23:25:57 +1000127 return hash__early_init_mmu();
128}
129extern void hash__early_init_mmu_secondary(void);
Aneesh Kumar K.V2bfd65e2016-04-29 23:25:58 +1000130extern void radix__early_init_mmu_secondary(void);
Aneesh Kumar K.V756d08d2016-04-29 23:25:57 +1000131static inline void early_init_mmu_secondary(void)
132{
Aneesh Kumar K.V2bfd65e2016-04-29 23:25:58 +1000133 if (radix_enabled())
134 return radix__early_init_mmu_secondary();
Aneesh Kumar K.V756d08d2016-04-29 23:25:57 +1000135 return hash__early_init_mmu_secondary();
136}
137
138extern void hash__setup_initial_memory_limit(phys_addr_t first_memblock_base,
139 phys_addr_t first_memblock_size);
Aneesh Kumar K.V2bfd65e2016-04-29 23:25:58 +1000140extern void radix__setup_initial_memory_limit(phys_addr_t first_memblock_base,
141 phys_addr_t first_memblock_size);
Aneesh Kumar K.V756d08d2016-04-29 23:25:57 +1000142static inline void setup_initial_memory_limit(phys_addr_t first_memblock_base,
143 phys_addr_t first_memblock_size)
144{
Aneesh Kumar K.Vb8f1b4f2016-07-23 14:42:35 +0530145 if (early_radix_enabled())
Aneesh Kumar K.V2bfd65e2016-04-29 23:25:58 +1000146 return radix__setup_initial_memory_limit(first_memblock_base,
147 first_memblock_size);
Aneesh Kumar K.V756d08d2016-04-29 23:25:57 +1000148 return hash__setup_initial_memory_limit(first_memblock_base,
149 first_memblock_size);
150}
Michael Ellermaneea81482016-08-04 15:32:06 +1000151
152extern int (*register_process_table)(unsigned long base, unsigned long page_size,
153 unsigned long tbl_size);
154
Paul Mackerrascc3d2942017-01-30 21:21:36 +1100155#ifdef CONFIG_PPC_PSERIES
156extern void radix_init_pseries(void);
157#else
158static inline void radix_init_pseries(void) { };
159#endif
160
Aneesh Kumar K.V11a6f6a2016-04-29 23:25:41 +1000161#endif /* __ASSEMBLY__ */
162#endif /* _ASM_POWERPC_BOOK3S_64_MMU_H_ */