xref: /openbmc/linux/arch/powerpc/include/asm/page_64.h (revision 78f1dbde9fd020419313c2a0c3b602ea2427118f)
1b8b572e1SStephen Rothwell #ifndef _ASM_POWERPC_PAGE_64_H
2b8b572e1SStephen Rothwell #define _ASM_POWERPC_PAGE_64_H
3b8b572e1SStephen Rothwell 
4b8b572e1SStephen Rothwell /*
5b8b572e1SStephen Rothwell  * Copyright (C) 2001 PPC64 Team, IBM Corp
6b8b572e1SStephen Rothwell  *
7b8b572e1SStephen Rothwell  * This program is free software; you can redistribute it and/or
8b8b572e1SStephen Rothwell  * modify it under the terms of the GNU General Public License
9b8b572e1SStephen Rothwell  * as published by the Free Software Foundation; either version
10b8b572e1SStephen Rothwell  * 2 of the License, or (at your option) any later version.
11b8b572e1SStephen Rothwell  */
12b8b572e1SStephen Rothwell 
13b8b572e1SStephen Rothwell /*
14b8b572e1SStephen Rothwell  * We always define HW_PAGE_SHIFT to 12 as use of 64K pages remains Linux
15b8b572e1SStephen Rothwell  * specific, every notion of page number shared with the firmware, TCEs,
16b8b572e1SStephen Rothwell  * iommu, etc... still uses a page size of 4K.
17b8b572e1SStephen Rothwell  */
18b8b572e1SStephen Rothwell #define HW_PAGE_SHIFT		12
19b8b572e1SStephen Rothwell #define HW_PAGE_SIZE		(ASM_CONST(1) << HW_PAGE_SHIFT)
20b8b572e1SStephen Rothwell #define HW_PAGE_MASK		(~(HW_PAGE_SIZE-1))
21b8b572e1SStephen Rothwell 
22b8b572e1SStephen Rothwell /*
23b8b572e1SStephen Rothwell  * PAGE_FACTOR is the number of bits factor between PAGE_SHIFT and
24b8b572e1SStephen Rothwell  * HW_PAGE_SHIFT, that is 4K pages.
25b8b572e1SStephen Rothwell  */
26b8b572e1SStephen Rothwell #define PAGE_FACTOR		(PAGE_SHIFT - HW_PAGE_SHIFT)
27b8b572e1SStephen Rothwell 
28b8b572e1SStephen Rothwell /* Segment size; normal 256M segments */
29b8b572e1SStephen Rothwell #define SID_SHIFT		28
30b8b572e1SStephen Rothwell #define SID_MASK		ASM_CONST(0xfffffffff)
31b8b572e1SStephen Rothwell #define ESID_MASK		0xfffffffff0000000UL
32b8b572e1SStephen Rothwell #define GET_ESID(x)		(((x) >> SID_SHIFT) & SID_MASK)
33b8b572e1SStephen Rothwell 
34b8b572e1SStephen Rothwell /* 1T segments */
35b8b572e1SStephen Rothwell #define SID_SHIFT_1T		40
36b8b572e1SStephen Rothwell #define SID_MASK_1T		0xffffffUL
37b8b572e1SStephen Rothwell #define ESID_MASK_1T		0xffffff0000000000UL
38b8b572e1SStephen Rothwell #define GET_ESID_1T(x)		(((x) >> SID_SHIFT_1T) & SID_MASK_1T)
39b8b572e1SStephen Rothwell 
40b8b572e1SStephen Rothwell #ifndef __ASSEMBLY__
41b8b572e1SStephen Rothwell #include <asm/cache.h>
42b8b572e1SStephen Rothwell 
43b8b572e1SStephen Rothwell typedef unsigned long pte_basic_t;
44b8b572e1SStephen Rothwell 
45b8b572e1SStephen Rothwell static __inline__ void clear_page(void *addr)
46b8b572e1SStephen Rothwell {
47b8b572e1SStephen Rothwell 	unsigned long lines, line_size;
48b8b572e1SStephen Rothwell 
49b8b572e1SStephen Rothwell 	line_size = ppc64_caches.dline_size;
50b8b572e1SStephen Rothwell 	lines = ppc64_caches.dlines_per_page;
51b8b572e1SStephen Rothwell 
52b8b572e1SStephen Rothwell 	__asm__ __volatile__(
53b8b572e1SStephen Rothwell 	"mtctr	%1	# clear_page\n\
54b8b572e1SStephen Rothwell 1:      dcbz	0,%0\n\
55b8b572e1SStephen Rothwell 	add	%0,%0,%3\n\
56b8b572e1SStephen Rothwell 	bdnz+	1b"
57b8b572e1SStephen Rothwell         : "=r" (addr)
58b8b572e1SStephen Rothwell         : "r" (lines), "0" (addr), "r" (line_size)
59b8b572e1SStephen Rothwell 	: "ctr", "memory");
60b8b572e1SStephen Rothwell }
61b8b572e1SStephen Rothwell 
62d988f0e3SAnton Blanchard extern void copy_page(void *to, void *from);
63b8b572e1SStephen Rothwell 
64b8b572e1SStephen Rothwell /* Log 2 of page table size */
65b8b572e1SStephen Rothwell extern u64 ppc64_pft_size;
66b8b572e1SStephen Rothwell 
67b8b572e1SStephen Rothwell #endif /* __ASSEMBLY__ */
68b8b572e1SStephen Rothwell 
69b8b572e1SStephen Rothwell #ifdef CONFIG_PPC_MM_SLICES
70b8b572e1SStephen Rothwell 
71b8b572e1SStephen Rothwell #define SLICE_LOW_SHIFT		28
72b8b572e1SStephen Rothwell #define SLICE_HIGH_SHIFT	40
73b8b572e1SStephen Rothwell 
74b8b572e1SStephen Rothwell #define SLICE_LOW_TOP		(0x100000000ul)
75b8b572e1SStephen Rothwell #define SLICE_NUM_LOW		(SLICE_LOW_TOP >> SLICE_LOW_SHIFT)
76b8b572e1SStephen Rothwell #define SLICE_NUM_HIGH		(PGTABLE_RANGE >> SLICE_HIGH_SHIFT)
77b8b572e1SStephen Rothwell 
78b8b572e1SStephen Rothwell #define GET_LOW_SLICE_INDEX(addr)	((addr) >> SLICE_LOW_SHIFT)
79b8b572e1SStephen Rothwell #define GET_HIGH_SLICE_INDEX(addr)	((addr) >> SLICE_HIGH_SHIFT)
80b8b572e1SStephen Rothwell 
81*78f1dbdeSAneesh Kumar K.V /*
82*78f1dbdeSAneesh Kumar K.V  * 1 bit per slice and we have one slice per 1TB
83*78f1dbdeSAneesh Kumar K.V  * Right now we support only 64TB.
84*78f1dbdeSAneesh Kumar K.V  * IF we change this we will have to change the type
85*78f1dbdeSAneesh Kumar K.V  * of high_slices
86*78f1dbdeSAneesh Kumar K.V  */
87*78f1dbdeSAneesh Kumar K.V #define SLICE_MASK_SIZE 8
88*78f1dbdeSAneesh Kumar K.V 
89b8b572e1SStephen Rothwell #ifndef __ASSEMBLY__
90b8b572e1SStephen Rothwell 
91b8b572e1SStephen Rothwell struct slice_mask {
92b8b572e1SStephen Rothwell 	u16 low_slices;
937aa0727fSAneesh Kumar K.V 	u64 high_slices;
94b8b572e1SStephen Rothwell };
95b8b572e1SStephen Rothwell 
96b8b572e1SStephen Rothwell struct mm_struct;
97b8b572e1SStephen Rothwell 
98b8b572e1SStephen Rothwell extern unsigned long slice_get_unmapped_area(unsigned long addr,
99b8b572e1SStephen Rothwell 					     unsigned long len,
100b8b572e1SStephen Rothwell 					     unsigned long flags,
101b8b572e1SStephen Rothwell 					     unsigned int psize,
102b8b572e1SStephen Rothwell 					     int topdown,
103b8b572e1SStephen Rothwell 					     int use_cache);
104b8b572e1SStephen Rothwell 
105b8b572e1SStephen Rothwell extern unsigned int get_slice_psize(struct mm_struct *mm,
106b8b572e1SStephen Rothwell 				    unsigned long addr);
107b8b572e1SStephen Rothwell 
108b8b572e1SStephen Rothwell extern void slice_init_context(struct mm_struct *mm, unsigned int psize);
109b8b572e1SStephen Rothwell extern void slice_set_user_psize(struct mm_struct *mm, unsigned int psize);
110b8b572e1SStephen Rothwell extern void slice_set_range_psize(struct mm_struct *mm, unsigned long start,
111b8b572e1SStephen Rothwell 				  unsigned long len, unsigned int psize);
112b8b572e1SStephen Rothwell 
113ee7a2aa3SMichael Ellerman #define slice_mm_new_context(mm)	((mm)->context.id == MMU_NO_CONTEXT)
114b8b572e1SStephen Rothwell 
115b8b572e1SStephen Rothwell #endif /* __ASSEMBLY__ */
116b8b572e1SStephen Rothwell #else
117b8b572e1SStephen Rothwell #define slice_init()
11857e2a99fSBenjamin Herrenschmidt #ifdef CONFIG_PPC_STD_MMU_64
119b8b572e1SStephen Rothwell #define get_slice_psize(mm, addr)	((mm)->context.user_psize)
120b8b572e1SStephen Rothwell #define slice_set_user_psize(mm, psize)		\
121b8b572e1SStephen Rothwell do {						\
122b8b572e1SStephen Rothwell 	(mm)->context.user_psize = (psize);	\
123b8b572e1SStephen Rothwell 	(mm)->context.sllp = SLB_VSID_USER | mmu_psize_defs[(psize)].sllp; \
124b8b572e1SStephen Rothwell } while (0)
12557e2a99fSBenjamin Herrenschmidt #else /* CONFIG_PPC_STD_MMU_64 */
12657e2a99fSBenjamin Herrenschmidt #ifdef CONFIG_PPC_64K_PAGES
12757e2a99fSBenjamin Herrenschmidt #define get_slice_psize(mm, addr)	MMU_PAGE_64K
12857e2a99fSBenjamin Herrenschmidt #else /* CONFIG_PPC_64K_PAGES */
12957e2a99fSBenjamin Herrenschmidt #define get_slice_psize(mm, addr)	MMU_PAGE_4K
13057e2a99fSBenjamin Herrenschmidt #endif /* !CONFIG_PPC_64K_PAGES */
13157e2a99fSBenjamin Herrenschmidt #define slice_set_user_psize(mm, psize)	do { BUG(); } while(0)
13257e2a99fSBenjamin Herrenschmidt #endif /* !CONFIG_PPC_STD_MMU_64 */
13357e2a99fSBenjamin Herrenschmidt 
134b8b572e1SStephen Rothwell #define slice_set_range_psize(mm, start, len, psize)	\
135b8b572e1SStephen Rothwell 	slice_set_user_psize((mm), (psize))
136b8b572e1SStephen Rothwell #define slice_mm_new_context(mm)	1
137b8b572e1SStephen Rothwell #endif /* CONFIG_PPC_MM_SLICES */
138b8b572e1SStephen Rothwell 
139b8b572e1SStephen Rothwell #ifdef CONFIG_HUGETLB_PAGE
140b8b572e1SStephen Rothwell 
14176512959SBecky Bruce #ifdef CONFIG_PPC_MM_SLICES
142b8b572e1SStephen Rothwell #define HAVE_ARCH_HUGETLB_UNMAPPED_AREA
14376512959SBecky Bruce #endif
144b8b572e1SStephen Rothwell 
145b8b572e1SStephen Rothwell #endif /* !CONFIG_HUGETLB_PAGE */
146b8b572e1SStephen Rothwell 
147b8b572e1SStephen Rothwell #define VM_DATA_DEFAULT_FLAGS \
148cab175f9SDenis Kirjanov 	(is_32bit_task() ? \
149b8b572e1SStephen Rothwell 	 VM_DATA_DEFAULT_FLAGS32 : VM_DATA_DEFAULT_FLAGS64)
150b8b572e1SStephen Rothwell 
151b8b572e1SStephen Rothwell /*
152b8b572e1SStephen Rothwell  * This is the default if a program doesn't have a PT_GNU_STACK
153b8b572e1SStephen Rothwell  * program header entry. The PPC64 ELF ABI has a non executable stack
15425985edcSLucas De Marchi  * stack by default, so in the absence of a PT_GNU_STACK program header
155b8b572e1SStephen Rothwell  * we turn execute permission off.
156b8b572e1SStephen Rothwell  */
157b8b572e1SStephen Rothwell #define VM_STACK_DEFAULT_FLAGS32	(VM_READ | VM_WRITE | VM_EXEC | \
158b8b572e1SStephen Rothwell 					 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
159b8b572e1SStephen Rothwell 
160b8b572e1SStephen Rothwell #define VM_STACK_DEFAULT_FLAGS64	(VM_READ | VM_WRITE | \
161b8b572e1SStephen Rothwell 					 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
162b8b572e1SStephen Rothwell 
163b8b572e1SStephen Rothwell #define VM_STACK_DEFAULT_FLAGS \
164cab175f9SDenis Kirjanov 	(is_32bit_task() ? \
165b8b572e1SStephen Rothwell 	 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
166b8b572e1SStephen Rothwell 
1675b17e1cdSArnd Bergmann #include <asm-generic/getorder.h>
168b8b572e1SStephen Rothwell 
169b8b572e1SStephen Rothwell #endif /* _ASM_POWERPC_PAGE_64_H */
170