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