2 * PowerPC memory management structures
4 * Dave Engebretsen & Mike Corrigan <{engebret|mikejc}@us.ibm.com>
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version
10 * 2 of the License, or (at your option) any later version.
16 #include <linux/config.h>
21 /* Time to allow for more things here */
22 typedef unsigned long mm_context_id_t;
25 #ifdef CONFIG_HUGETLB_PAGE
26 u16 htlb_segs; /* bitmask */
30 #ifdef CONFIG_HUGETLB_PAGE
31 #define KERNEL_LOW_HPAGES .htlb_segs = 0,
33 #define KERNEL_LOW_HPAGES
36 #define KERNEL_CONTEXT(ea) ({ \
37 mm_context_t ctx = { .id = REGION_ID(ea), KERNEL_LOW_HPAGES}; \
41 * Hardware Segment Lookaside Buffer Entry
42 * This structure has been padded out to two 64b doublewords (actual SLBE's are
43 * 94 bits). This padding facilites use by the segment management
47 unsigned long esid: 36; /* Effective segment ID */
48 unsigned long resv0:20; /* Reserved */
49 unsigned long v: 1; /* Entry valid (v=1) or invalid */
50 unsigned long resv1: 1; /* Reserved */
51 unsigned long ks: 1; /* Supervisor (privileged) state storage key */
52 unsigned long kp: 1; /* Problem state storage key */
53 unsigned long n: 1; /* No-execute if n=1 */
54 unsigned long resv2: 3; /* padding to a 64b boundary */
58 unsigned long vsid: 52; /* Virtual segment ID */
59 unsigned long resv0:12; /* Padding to a 64b boundary */
75 unsigned long esid: 36; /* Effective segment ID */
76 unsigned long v: 1; /* Entry valid (v=1) or invalid */
77 unsigned long null1:15; /* padding to a 64b boundary */
78 unsigned long index:12; /* Index to select SLB entry. Used by slbmte */
82 unsigned long vsid: 52; /* Virtual segment ID */
83 unsigned long ks: 1; /* Supervisor (privileged) state storage key */
84 unsigned long kp: 1; /* Problem state storage key */
85 unsigned long n: 1; /* No-execute if n=1 */
86 unsigned long l: 1; /* Virt pages are large (l=1) or 4KB (l=0) */
87 unsigned long c: 1; /* Class */
88 unsigned long resv0: 7; /* Padding to a 64b boundary */
104 * This structure is used in paca.h where the layout depends on the
110 unsigned long next_round_robin;
113 /* Hardware Page Table Entry */
115 #define HPTES_PER_GROUP 8
118 unsigned long avpn:57; /* vsid | api == avpn */
119 unsigned long : 2; /* Software use */
120 unsigned long bolted: 1; /* HPTE is "bolted" */
121 unsigned long lock: 1; /* lock on pSeries SMP */
122 unsigned long l: 1; /* Virtual page is large (L=1) or 4 KB (L=0) */
123 unsigned long h: 1; /* Hash function identifier */
124 unsigned long v: 1; /* Valid (v=1) or invalid (v=0) */
128 unsigned long pp0: 1; /* Page protection bit 0 */
129 unsigned long ts: 1; /* Tag set bit */
130 unsigned long rpn: 50; /* Real page number */
131 unsigned long : 2; /* Reserved */
132 unsigned long ac: 1; /* Address compare */
133 unsigned long r: 1; /* Referenced */
134 unsigned long c: 1; /* Changed */
135 unsigned long w: 1; /* Write-thru cache mode */
136 unsigned long i: 1; /* Cache inhibited */
137 unsigned long m: 1; /* Memory coherence required */
138 unsigned long g: 1; /* Guarded */
139 unsigned long n: 1; /* No-execute */
140 unsigned long pp: 2; /* Page protection bits 1:2 */
144 char padding[6]; /* padding */
145 unsigned long : 6; /* padding */
146 unsigned long flags: 10; /* HPTE flags */
151 unsigned long dword0;
156 unsigned long dword1;
158 Hpte_dword1_flags flags;
162 /* Values for PP (assumes Ks=0, Kp=1) */
163 /* pp0 will always be 0 for linux */
164 #define PP_RWXX 0 /* Supervisor read/write, User none */
165 #define PP_RWRX 1 /* Supervisor read/write, User read */
166 #define PP_RWRW 2 /* Supervisor read/write, User read/write */
167 #define PP_RXRX 3 /* Supervisor read, User read */
172 unsigned long htab_num_ptegs;
173 unsigned long htab_hash_mask;
174 unsigned long next_round_robin;
175 unsigned long last_kernel_address;
178 extern HTAB htab_data;
180 void invalidate_hpte( unsigned long slot );
181 long select_hpte_slot( unsigned long vpn );
182 void create_valid_hpte( unsigned long slot, unsigned long vpn,
183 unsigned long prpn, unsigned hash,
184 void * ptep, unsigned hpteflags,
187 #define PD_SHIFT (10+12) /* Page directory */
188 #define PD_MASK 0x02FF
189 #define PT_SHIFT (12) /* Page Table */
190 #define PT_MASK 0x02FF
192 #define LARGE_PAGE_SHIFT 24
194 static inline unsigned long hpt_hash(unsigned long vpn, int large)
207 return (vsid & 0x7fffffffff) ^ page;
210 static inline void __tlbie(unsigned long va, int large)
212 /* clear top 16 bits, non SLS segment */
213 va &= ~(0xffffULL << 48);
216 asm volatile("tlbie %0,1" : : "r"(va) : "memory");
218 asm volatile("tlbie %0,0" : : "r"(va) : "memory");
221 static inline void tlbie(unsigned long va, int large)
223 asm volatile("ptesync": : :"memory");
225 asm volatile("eieio; tlbsync; ptesync": : :"memory");
228 static inline void __tlbiel(unsigned long va)
230 /* clear top 16 bits, non SLS segment */
231 va &= ~(0xffffULL << 48);
234 * Thanks to Alan Modra we are now able to use machine specific
235 * assembly instructions (like tlbiel) by using the gas -many flag.
236 * However we have to support older toolchains so for the moment
240 asm volatile("tlbiel %0" : : "r"(va) : "memory");
242 asm volatile(".long 0x7c000224 | (%0 << 11)" : : "r"(va) : "memory");
246 static inline void tlbiel(unsigned long va)
248 asm volatile("ptesync": : :"memory");
250 asm volatile("ptesync": : :"memory");
254 * Handle a fault by adding an HPTE. If the address can't be determined
255 * to be valid via Linux page tables, return 1. If handled return 0
257 extern int __hash_page(unsigned long ea, unsigned long access,
258 unsigned long vsid, pte_t *ptep, unsigned long trap,
261 extern void htab_finish_init(void);
263 #endif /* __ASSEMBLY__ */
266 * Location of cpu0's segment table
268 #define STAB0_PAGE 0x9
269 #define STAB0_PHYS_ADDR (STAB0_PAGE<<PAGE_SHIFT)
270 #define STAB0_VIRT_ADDR (KERNELBASE+STAB0_PHYS_ADDR)
272 /* Block size masks */
273 #define BL_128K 0x000
274 #define BL_256K 0x001
275 #define BL_512K 0x003
283 #define BL_128M 0x3FF
284 #define BL_256M 0x7FF
286 /* Used to set up SDR1 register */
287 #define HASH_TABLE_SIZE_64K 0x00010000
288 #define HASH_TABLE_SIZE_128K 0x00020000
289 #define HASH_TABLE_SIZE_256K 0x00040000
290 #define HASH_TABLE_SIZE_512K 0x00080000
291 #define HASH_TABLE_SIZE_1M 0x00100000
292 #define HASH_TABLE_SIZE_2M 0x00200000
293 #define HASH_TABLE_SIZE_4M 0x00400000
294 #define HASH_TABLE_MASK_64K 0x000
295 #define HASH_TABLE_MASK_128K 0x001
296 #define HASH_TABLE_MASK_256K 0x003
297 #define HASH_TABLE_MASK_512K 0x007
298 #define HASH_TABLE_MASK_1M 0x00F
299 #define HASH_TABLE_MASK_2M 0x01F
300 #define HASH_TABLE_MASK_4M 0x03F
302 /* These are the Ks and Kp from the PowerPC books. For proper operation,
306 #define MI_Ks 0x80000000 /* Should not be set */
307 #define MI_Kp 0x40000000 /* Should always be set */
309 /* The effective page number register. When read, contains the information
310 * about the last instruction TLB miss. When MI_RPN is written, bits in
311 * this register are used to create the TLB entry.
314 #define MI_EPNMASK 0xfffff000 /* Effective page number for entry */
315 #define MI_EVALID 0x00000200 /* Entry is valid */
316 #define MI_ASIDMASK 0x0000000f /* ASID match value */
317 /* Reset value is undefined */
319 /* A "level 1" or "segment" or whatever you want to call it register.
320 * For the instruction TLB, it contains bits that get loaded into the
321 * TLB entry when the MI_RPN is written.
324 #define MI_APG 0x000001e0 /* Access protection group (0) */
325 #define MI_GUARDED 0x00000010 /* Guarded storage */
326 #define MI_PSMASK 0x0000000c /* Mask of page size bits */
327 #define MI_PS8MEG 0x0000000c /* 8M page size */
328 #define MI_PS512K 0x00000004 /* 512K page size */
329 #define MI_PS4K_16K 0x00000000 /* 4K or 16K page size */
330 #define MI_SVALID 0x00000001 /* Segment entry is valid */
331 /* Reset value is undefined */
333 /* Real page number. Defined by the pte. Writing this register
334 * causes a TLB entry to be created for the instruction TLB, using
335 * additional information from the MI_EPN, and MI_TWC registers.
339 /* Define an RPN value for mapping kernel memory to large virtual
340 * pages for boot initialization. This has real page number of 0,
341 * large page size, shared page, cache enabled, and valid.
342 * Also mark all subpages valid and write access.
344 #define MI_BOOTINIT 0x000001fd
346 #define MD_CTR 792 /* Data TLB control register */
347 #define MD_GPM 0x80000000 /* Set domain manager mode */
348 #define MD_PPM 0x40000000 /* Set subpage protection */
349 #define MD_CIDEF 0x20000000 /* Set cache inhibit when MMU dis */
350 #define MD_WTDEF 0x10000000 /* Set writethrough when MMU dis */
351 #define MD_RSV4I 0x08000000 /* Reserve 4 TLB entries */
352 #define MD_TWAM 0x04000000 /* Use 4K page hardware assist */
353 #define MD_PPCS 0x02000000 /* Use MI_RPN prob/priv state */
354 #define MD_IDXMASK 0x00001f00 /* TLB index to be loaded */
355 #define MD_RESETVAL 0x04000000 /* Value of register at reset */
357 #define M_CASID 793 /* Address space ID (context) to match */
358 #define MC_ASIDMASK 0x0000000f /* Bits used for ASID value */
361 /* These are the Ks and Kp from the PowerPC books. For proper operation,
365 #define MD_Ks 0x80000000 /* Should not be set */
366 #define MD_Kp 0x40000000 /* Should always be set */
368 /* The effective page number register. When read, contains the information
369 * about the last instruction TLB miss. When MD_RPN is written, bits in
370 * this register are used to create the TLB entry.
373 #define MD_EPNMASK 0xfffff000 /* Effective page number for entry */
374 #define MD_EVALID 0x00000200 /* Entry is valid */
375 #define MD_ASIDMASK 0x0000000f /* ASID match value */
376 /* Reset value is undefined */
378 /* The pointer to the base address of the first level page table.
379 * During a software tablewalk, reading this register provides the address
380 * of the entry associated with MD_EPN.
383 #define M_L1TB 0xfffff000 /* Level 1 table base address */
384 #define M_L1INDX 0x00000ffc /* Level 1 index, when read */
385 /* Reset value is undefined */
387 /* A "level 1" or "segment" or whatever you want to call it register.
388 * For the data TLB, it contains bits that get loaded into the TLB entry
389 * when the MD_RPN is written. It is also provides the hardware assist
390 * for finding the PTE address during software tablewalk.
393 #define MD_L2TB 0xfffff000 /* Level 2 table base address */
394 #define MD_L2INDX 0xfffffe00 /* Level 2 index (*pte), when read */
395 #define MD_APG 0x000001e0 /* Access protection group (0) */
396 #define MD_GUARDED 0x00000010 /* Guarded storage */
397 #define MD_PSMASK 0x0000000c /* Mask of page size bits */
398 #define MD_PS8MEG 0x0000000c /* 8M page size */
399 #define MD_PS512K 0x00000004 /* 512K page size */
400 #define MD_PS4K_16K 0x00000000 /* 4K or 16K page size */
401 #define MD_WT 0x00000002 /* Use writethrough page attribute */
402 #define MD_SVALID 0x00000001 /* Segment entry is valid */
403 /* Reset value is undefined */
406 /* Real page number. Defined by the pte. Writing this register
407 * causes a TLB entry to be created for the data TLB, using
408 * additional information from the MD_EPN, and MD_TWC registers.
412 /* This is a temporary storage register that could be used to save
413 * a processor working register during a tablewalk.
417 #endif /* _PPC64_MMU_H_ */