xref: /openbmc/linux/arch/powerpc/include/asm/page_64.h (revision e2827fe5c1566f66a922dd7493cbe4522c50580a)
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 
45e35735b9SAnton Blanchard static inline void clear_page(void *addr)
46b8b572e1SStephen Rothwell {
47e35735b9SAnton Blanchard 	unsigned long iterations;
48e35735b9SAnton Blanchard 	unsigned long onex, twox, fourx, eightx;
49b8b572e1SStephen Rothwell 
50*e2827fe5SBenjamin Herrenschmidt 	iterations = ppc64_caches.l1d.blocks_per_page / 8;
51b8b572e1SStephen Rothwell 
52e35735b9SAnton Blanchard 	/*
53e35735b9SAnton Blanchard 	 * Some verisions of gcc use multiply instructions to
54e35735b9SAnton Blanchard 	 * calculate the offsets so lets give it a hand to
55e35735b9SAnton Blanchard 	 * do better.
56e35735b9SAnton Blanchard 	 */
57*e2827fe5SBenjamin Herrenschmidt 	onex = ppc64_caches.l1d.block_size;
58e35735b9SAnton Blanchard 	twox = onex << 1;
59e35735b9SAnton Blanchard 	fourx = onex << 2;
60e35735b9SAnton Blanchard 	eightx = onex << 3;
61e35735b9SAnton Blanchard 
62e35735b9SAnton Blanchard 	asm volatile(
63b8b572e1SStephen Rothwell 	"mtctr	%1	# clear_page\n\
64e35735b9SAnton Blanchard 	.balign	16\n\
65b8b572e1SStephen Rothwell 1:	dcbz	0,%0\n\
66e35735b9SAnton Blanchard 	dcbz	%3,%0\n\
67e35735b9SAnton Blanchard 	dcbz	%4,%0\n\
68e35735b9SAnton Blanchard 	dcbz	%5,%0\n\
69e35735b9SAnton Blanchard 	dcbz	%6,%0\n\
70e35735b9SAnton Blanchard 	dcbz	%7,%0\n\
71e35735b9SAnton Blanchard 	dcbz	%8,%0\n\
72e35735b9SAnton Blanchard 	dcbz	%9,%0\n\
73e35735b9SAnton Blanchard 	add	%0,%0,%10\n\
74b8b572e1SStephen Rothwell 	bdnz+	1b"
75e35735b9SAnton Blanchard 	: "=&r" (addr)
76e35735b9SAnton Blanchard 	: "r" (iterations), "0" (addr), "b" (onex), "b" (twox),
77e35735b9SAnton Blanchard 		"b" (twox+onex), "b" (fourx), "b" (fourx+onex),
78e35735b9SAnton Blanchard 		"b" (twox+fourx), "b" (eightx-onex), "r" (eightx)
79b8b572e1SStephen Rothwell 	: "ctr", "memory");
80b8b572e1SStephen Rothwell }
81b8b572e1SStephen Rothwell 
82d988f0e3SAnton Blanchard extern void copy_page(void *to, void *from);
83b8b572e1SStephen Rothwell 
84b8b572e1SStephen Rothwell /* Log 2 of page table size */
85b8b572e1SStephen Rothwell extern u64 ppc64_pft_size;
86b8b572e1SStephen Rothwell 
87b8b572e1SStephen Rothwell #endif /* __ASSEMBLY__ */
88b8b572e1SStephen Rothwell 
89b8b572e1SStephen Rothwell #ifdef CONFIG_PPC_MM_SLICES
90b8b572e1SStephen Rothwell 
91b8b572e1SStephen Rothwell #define SLICE_LOW_SHIFT		28
92b8b572e1SStephen Rothwell #define SLICE_HIGH_SHIFT	40
93b8b572e1SStephen Rothwell 
94b8b572e1SStephen Rothwell #define SLICE_LOW_TOP		(0x100000000ul)
95b8b572e1SStephen Rothwell #define SLICE_NUM_LOW		(SLICE_LOW_TOP >> SLICE_LOW_SHIFT)
96dd1842a2SAneesh Kumar K.V #define SLICE_NUM_HIGH		(H_PGTABLE_RANGE >> SLICE_HIGH_SHIFT)
97b8b572e1SStephen Rothwell 
98b8b572e1SStephen Rothwell #define GET_LOW_SLICE_INDEX(addr)	((addr) >> SLICE_LOW_SHIFT)
99b8b572e1SStephen Rothwell #define GET_HIGH_SLICE_INDEX(addr)	((addr) >> SLICE_HIGH_SHIFT)
100b8b572e1SStephen Rothwell 
10178f1dbdeSAneesh Kumar K.V /*
10278f1dbdeSAneesh Kumar K.V  * 1 bit per slice and we have one slice per 1TB
10378f1dbdeSAneesh Kumar K.V  * Right now we support only 64TB.
10478f1dbdeSAneesh Kumar K.V  * IF we change this we will have to change the type
10578f1dbdeSAneesh Kumar K.V  * of high_slices
10678f1dbdeSAneesh Kumar K.V  */
10778f1dbdeSAneesh Kumar K.V #define SLICE_MASK_SIZE 8
10878f1dbdeSAneesh Kumar K.V 
109b8b572e1SStephen Rothwell #ifndef __ASSEMBLY__
110b8b572e1SStephen Rothwell 
111b8b572e1SStephen Rothwell struct slice_mask {
112b8b572e1SStephen Rothwell 	u16 low_slices;
1137aa0727fSAneesh Kumar K.V 	u64 high_slices;
114b8b572e1SStephen Rothwell };
115b8b572e1SStephen Rothwell 
116b8b572e1SStephen Rothwell struct mm_struct;
117b8b572e1SStephen Rothwell 
118b8b572e1SStephen Rothwell extern unsigned long slice_get_unmapped_area(unsigned long addr,
119b8b572e1SStephen Rothwell 					     unsigned long len,
120b8b572e1SStephen Rothwell 					     unsigned long flags,
121b8b572e1SStephen Rothwell 					     unsigned int psize,
12234d07177SMichel Lespinasse 					     int topdown);
123b8b572e1SStephen Rothwell 
124b8b572e1SStephen Rothwell extern unsigned int get_slice_psize(struct mm_struct *mm,
125b8b572e1SStephen Rothwell 				    unsigned long addr);
126b8b572e1SStephen Rothwell 
127b8b572e1SStephen Rothwell extern void slice_set_user_psize(struct mm_struct *mm, unsigned int psize);
128b8b572e1SStephen Rothwell extern void slice_set_range_psize(struct mm_struct *mm, unsigned long start,
129b8b572e1SStephen Rothwell 				  unsigned long len, unsigned int psize);
130b8b572e1SStephen Rothwell 
131b8b572e1SStephen Rothwell #endif /* __ASSEMBLY__ */
132b8b572e1SStephen Rothwell #else
133b8b572e1SStephen Rothwell #define slice_init()
13457e2a99fSBenjamin Herrenschmidt #ifdef CONFIG_PPC_STD_MMU_64
135b8b572e1SStephen Rothwell #define get_slice_psize(mm, addr)	((mm)->context.user_psize)
136b8b572e1SStephen Rothwell #define slice_set_user_psize(mm, psize)		\
137b8b572e1SStephen Rothwell do {						\
138b8b572e1SStephen Rothwell 	(mm)->context.user_psize = (psize);	\
139b8b572e1SStephen Rothwell 	(mm)->context.sllp = SLB_VSID_USER | mmu_psize_defs[(psize)].sllp; \
140b8b572e1SStephen Rothwell } while (0)
14157e2a99fSBenjamin Herrenschmidt #else /* CONFIG_PPC_STD_MMU_64 */
14257e2a99fSBenjamin Herrenschmidt #ifdef CONFIG_PPC_64K_PAGES
14357e2a99fSBenjamin Herrenschmidt #define get_slice_psize(mm, addr)	MMU_PAGE_64K
14457e2a99fSBenjamin Herrenschmidt #else /* CONFIG_PPC_64K_PAGES */
14557e2a99fSBenjamin Herrenschmidt #define get_slice_psize(mm, addr)	MMU_PAGE_4K
14657e2a99fSBenjamin Herrenschmidt #endif /* !CONFIG_PPC_64K_PAGES */
14757e2a99fSBenjamin Herrenschmidt #define slice_set_user_psize(mm, psize)	do { BUG(); } while(0)
14857e2a99fSBenjamin Herrenschmidt #endif /* !CONFIG_PPC_STD_MMU_64 */
14957e2a99fSBenjamin Herrenschmidt 
150b8b572e1SStephen Rothwell #define slice_set_range_psize(mm, start, len, psize)	\
151b8b572e1SStephen Rothwell 	slice_set_user_psize((mm), (psize))
152b8b572e1SStephen Rothwell #endif /* CONFIG_PPC_MM_SLICES */
153b8b572e1SStephen Rothwell 
154b8b572e1SStephen Rothwell #ifdef CONFIG_HUGETLB_PAGE
155b8b572e1SStephen Rothwell 
15676512959SBecky Bruce #ifdef CONFIG_PPC_MM_SLICES
157b8b572e1SStephen Rothwell #define HAVE_ARCH_HUGETLB_UNMAPPED_AREA
15876512959SBecky Bruce #endif
159b8b572e1SStephen Rothwell 
160b8b572e1SStephen Rothwell #endif /* !CONFIG_HUGETLB_PAGE */
161b8b572e1SStephen Rothwell 
162b8b572e1SStephen Rothwell #define VM_DATA_DEFAULT_FLAGS \
163cab175f9SDenis Kirjanov 	(is_32bit_task() ? \
164b8b572e1SStephen Rothwell 	 VM_DATA_DEFAULT_FLAGS32 : VM_DATA_DEFAULT_FLAGS64)
165b8b572e1SStephen Rothwell 
166b8b572e1SStephen Rothwell /*
167b8b572e1SStephen Rothwell  * This is the default if a program doesn't have a PT_GNU_STACK
168b8b572e1SStephen Rothwell  * program header entry. The PPC64 ELF ABI has a non executable stack
16925985edcSLucas De Marchi  * stack by default, so in the absence of a PT_GNU_STACK program header
170b8b572e1SStephen Rothwell  * we turn execute permission off.
171b8b572e1SStephen Rothwell  */
172b8b572e1SStephen Rothwell #define VM_STACK_DEFAULT_FLAGS32	(VM_READ | VM_WRITE | VM_EXEC | \
173b8b572e1SStephen Rothwell 					 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
174b8b572e1SStephen Rothwell 
175b8b572e1SStephen Rothwell #define VM_STACK_DEFAULT_FLAGS64	(VM_READ | VM_WRITE | \
176b8b572e1SStephen Rothwell 					 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
177b8b572e1SStephen Rothwell 
178b8b572e1SStephen Rothwell #define VM_STACK_DEFAULT_FLAGS \
179cab175f9SDenis Kirjanov 	(is_32bit_task() ? \
180b8b572e1SStephen Rothwell 	 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
181b8b572e1SStephen Rothwell 
1825b17e1cdSArnd Bergmann #include <asm-generic/getorder.h>
183b8b572e1SStephen Rothwell 
184b8b572e1SStephen Rothwell #endif /* _ASM_POWERPC_PAGE_64_H */
185