xref: /linux/arch/s390/include/asm/page.h (revision 4246b92cf9fb32da8d8b060c92d8302797c6fbea)
1 /*
2  *  S390 version
3  *    Copyright IBM Corp. 1999, 2000
4  *    Author(s): Hartmut Penner (hp@de.ibm.com)
5  */
6 
7 #ifndef _S390_PAGE_H
8 #define _S390_PAGE_H
9 
10 #include <linux/const.h>
11 #include <asm/types.h>
12 
13 #define _PAGE_SHIFT	12
14 #define _PAGE_SIZE	(_AC(1, UL) << _PAGE_SHIFT)
15 #define _PAGE_MASK	(~(_PAGE_SIZE - 1))
16 
17 /* PAGE_SHIFT determines the page size */
18 #define PAGE_SHIFT	_PAGE_SHIFT
19 #define PAGE_SIZE	_PAGE_SIZE
20 #define PAGE_MASK	_PAGE_MASK
21 #define PAGE_DEFAULT_ACC	0
22 #define PAGE_DEFAULT_KEY	(PAGE_DEFAULT_ACC << 4)
23 
24 #define HPAGE_SHIFT	20
25 #define HPAGE_SIZE	(1UL << HPAGE_SHIFT)
26 #define HPAGE_MASK	(~(HPAGE_SIZE - 1))
27 #define HUGETLB_PAGE_ORDER	(HPAGE_SHIFT - PAGE_SHIFT)
28 #define HUGE_MAX_HSTATE		2
29 
30 #define ARCH_HAS_SETCLEAR_HUGE_PTE
31 #define ARCH_HAS_HUGE_PTE_TYPE
32 #define ARCH_HAS_PREPARE_HUGEPAGE
33 #define ARCH_HAS_HUGEPAGE_CLEAR_FLUSH
34 
35 #include <asm/setup.h>
36 #ifndef __ASSEMBLY__
37 
38 void __storage_key_init_range(unsigned long start, unsigned long end);
39 
40 static inline void storage_key_init_range(unsigned long start, unsigned long end)
41 {
42 	if (PAGE_DEFAULT_KEY)
43 		__storage_key_init_range(start, end);
44 }
45 
46 #define clear_page(page)	memset((page), 0, PAGE_SIZE)
47 
48 /*
49  * copy_page uses the mvcl instruction with 0xb0 padding byte in order to
50  * bypass caches when copying a page. Especially when copying huge pages
51  * this keeps L1 and L2 data caches alive.
52  */
53 static inline void copy_page(void *to, void *from)
54 {
55 	register void *reg2 asm ("2") = to;
56 	register unsigned long reg3 asm ("3") = 0x1000;
57 	register void *reg4 asm ("4") = from;
58 	register unsigned long reg5 asm ("5") = 0xb0001000;
59 	asm volatile(
60 		"	mvcl	2,4"
61 		: "+d" (reg2), "+d" (reg3), "+d" (reg4), "+d" (reg5)
62 		: : "memory", "cc");
63 }
64 
65 #define clear_user_page(page, vaddr, pg)	clear_page(page)
66 #define copy_user_page(to, from, vaddr, pg)	copy_page(to, from)
67 
68 #define __alloc_zeroed_user_highpage(movableflags, vma, vaddr) \
69 	alloc_page_vma(GFP_HIGHUSER | __GFP_ZERO | movableflags, vma, vaddr)
70 #define __HAVE_ARCH_ALLOC_ZEROED_USER_HIGHPAGE
71 
72 /*
73  * These are used to make use of C type-checking..
74  */
75 
76 typedef struct { unsigned long pgprot; } pgprot_t;
77 typedef struct { unsigned long pgste; } pgste_t;
78 typedef struct { unsigned long pte; } pte_t;
79 typedef struct { unsigned long pmd; } pmd_t;
80 typedef struct { unsigned long pud; } pud_t;
81 typedef struct { unsigned long p4d; } p4d_t;
82 typedef struct { unsigned long pgd; } pgd_t;
83 typedef pte_t *pgtable_t;
84 
85 #define pgprot_val(x)	((x).pgprot)
86 #define pgste_val(x)	((x).pgste)
87 #define pte_val(x)	((x).pte)
88 #define pmd_val(x)	((x).pmd)
89 #define pud_val(x)	((x).pud)
90 #define p4d_val(x)	((x).p4d)
91 #define pgd_val(x)      ((x).pgd)
92 
93 #define __pgste(x)	((pgste_t) { (x) } )
94 #define __pte(x)        ((pte_t) { (x) } )
95 #define __pmd(x)        ((pmd_t) { (x) } )
96 #define __pud(x)	((pud_t) { (x) } )
97 #define __p4d(x)	((p4d_t) { (x) } )
98 #define __pgd(x)        ((pgd_t) { (x) } )
99 #define __pgprot(x)     ((pgprot_t) { (x) } )
100 
101 static inline void page_set_storage_key(unsigned long addr,
102 					unsigned char skey, int mapped)
103 {
104 	if (!mapped)
105 		asm volatile(".insn rrf,0xb22b0000,%0,%1,8,0"
106 			     : : "d" (skey), "a" (addr));
107 	else
108 		asm volatile("sske %0,%1" : : "d" (skey), "a" (addr));
109 }
110 
111 static inline unsigned char page_get_storage_key(unsigned long addr)
112 {
113 	unsigned char skey;
114 
115 	asm volatile("iske %0,%1" : "=d" (skey) : "a" (addr));
116 	return skey;
117 }
118 
119 static inline int page_reset_referenced(unsigned long addr)
120 {
121 	int cc;
122 
123 	asm volatile(
124 		"	rrbe	0,%1\n"
125 		"	ipm	%0\n"
126 		"	srl	%0,28\n"
127 		: "=d" (cc) : "a" (addr) : "cc");
128 	return cc;
129 }
130 
131 /* Bits int the storage key */
132 #define _PAGE_CHANGED		0x02	/* HW changed bit		*/
133 #define _PAGE_REFERENCED	0x04	/* HW referenced bit		*/
134 #define _PAGE_FP_BIT		0x08	/* HW fetch protection bit	*/
135 #define _PAGE_ACC_BITS		0xf0	/* HW access control bits	*/
136 
137 struct page;
138 void arch_free_page(struct page *page, int order);
139 void arch_alloc_page(struct page *page, int order);
140 void arch_set_page_dat(struct page *page, int order);
141 void arch_set_page_nodat(struct page *page, int order);
142 int arch_test_page_nodat(struct page *page);
143 void arch_set_page_states(int make_stable);
144 
145 static inline int devmem_is_allowed(unsigned long pfn)
146 {
147 	return 0;
148 }
149 
150 #define HAVE_ARCH_FREE_PAGE
151 #define HAVE_ARCH_ALLOC_PAGE
152 
153 #endif /* !__ASSEMBLY__ */
154 
155 #define __PAGE_OFFSET		0x0UL
156 #define PAGE_OFFSET		0x0UL
157 
158 #define __pa(x)			((unsigned long)(x))
159 #define __va(x)			((void *)(unsigned long)(x))
160 
161 #define virt_to_pfn(kaddr)	(__pa(kaddr) >> PAGE_SHIFT)
162 #define pfn_to_virt(pfn)	__va((pfn) << PAGE_SHIFT)
163 
164 #define virt_to_page(kaddr)	pfn_to_page(virt_to_pfn(kaddr))
165 #define page_to_virt(page)	pfn_to_virt(page_to_pfn(page))
166 
167 #define phys_to_pfn(kaddr)	((kaddr) >> PAGE_SHIFT)
168 #define pfn_to_phys(pfn)	((pfn) << PAGE_SHIFT)
169 
170 #define phys_to_page(kaddr)	pfn_to_page(phys_to_pfn(kaddr))
171 #define page_to_phys(page)	(page_to_pfn(page) << PAGE_SHIFT)
172 
173 #define virt_addr_valid(kaddr)	pfn_valid(__pa(kaddr) >> PAGE_SHIFT)
174 
175 #define VM_DATA_DEFAULT_FLAGS	(VM_READ | VM_WRITE | \
176 				 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
177 
178 #include <asm-generic/memory_model.h>
179 #include <asm-generic/getorder.h>
180 
181 #endif /* _S390_PAGE_H */
182