Loading...
1/* SPDX-License-Identifier: GPL-2.0 */
2/*
3 * S390 version
4 * Copyright IBM Corp. 1999, 2000
5 * Author(s): Hartmut Penner (hp@de.ibm.com)
6 */
7
8#ifndef _S390_PAGE_H
9#define _S390_PAGE_H
10
11#include <linux/const.h>
12#include <asm/types.h>
13
14#define _PAGE_SHIFT 12
15#define _PAGE_SIZE (_AC(1, UL) << _PAGE_SHIFT)
16#define _PAGE_MASK (~(_PAGE_SIZE - 1))
17
18/* PAGE_SHIFT determines the page size */
19#define PAGE_SHIFT _PAGE_SHIFT
20#define PAGE_SIZE _PAGE_SIZE
21#define PAGE_MASK _PAGE_MASK
22#define PAGE_DEFAULT_ACC 0
23/* storage-protection override */
24#define PAGE_SPO_ACC 9
25#define PAGE_DEFAULT_KEY (PAGE_DEFAULT_ACC << 4)
26
27#define HPAGE_SHIFT 20
28#define HPAGE_SIZE (1UL << HPAGE_SHIFT)
29#define HPAGE_MASK (~(HPAGE_SIZE - 1))
30#define HUGETLB_PAGE_ORDER (HPAGE_SHIFT - PAGE_SHIFT)
31#define HUGE_MAX_HSTATE 2
32
33#define ARCH_HAS_SETCLEAR_HUGE_PTE
34#define ARCH_HAS_HUGE_PTE_TYPE
35#define ARCH_HAS_PREPARE_HUGEPAGE
36#define ARCH_HAS_HUGEPAGE_CLEAR_FLUSH
37
38#define HAVE_ARCH_HUGETLB_UNMAPPED_AREA
39
40#include <asm/setup.h>
41#ifndef __ASSEMBLY__
42
43void __storage_key_init_range(unsigned long start, unsigned long end);
44
45static inline void storage_key_init_range(unsigned long start, unsigned long end)
46{
47 if (PAGE_DEFAULT_KEY != 0)
48 __storage_key_init_range(start, end);
49}
50
51#define clear_page(page) memset((page), 0, PAGE_SIZE)
52
53/*
54 * copy_page uses the mvcl instruction with 0xb0 padding byte in order to
55 * bypass caches when copying a page. Especially when copying huge pages
56 * this keeps L1 and L2 data caches alive.
57 */
58static inline void copy_page(void *to, void *from)
59{
60 union register_pair dst, src;
61
62 dst.even = (unsigned long) to;
63 dst.odd = 0x1000;
64 src.even = (unsigned long) from;
65 src.odd = 0xb0001000;
66
67 asm volatile(
68 " mvcl %[dst],%[src]"
69 : [dst] "+&d" (dst.pair), [src] "+&d" (src.pair)
70 : : "memory", "cc");
71}
72
73#define clear_user_page(page, vaddr, pg) clear_page(page)
74#define copy_user_page(to, from, vaddr, pg) copy_page(to, from)
75
76#define alloc_zeroed_user_highpage_movable(vma, vaddr) \
77 alloc_page_vma(GFP_HIGHUSER_MOVABLE | __GFP_ZERO, vma, vaddr)
78#define __HAVE_ARCH_ALLOC_ZEROED_USER_HIGHPAGE_MOVABLE
79
80/*
81 * These are used to make use of C type-checking..
82 */
83
84typedef struct { unsigned long pgprot; } pgprot_t;
85typedef struct { unsigned long pgste; } pgste_t;
86typedef struct { unsigned long pte; } pte_t;
87typedef struct { unsigned long pmd; } pmd_t;
88typedef struct { unsigned long pud; } pud_t;
89typedef struct { unsigned long p4d; } p4d_t;
90typedef struct { unsigned long pgd; } pgd_t;
91typedef pte_t *pgtable_t;
92
93#define pgprot_val(x) ((x).pgprot)
94#define pgste_val(x) ((x).pgste)
95
96static inline unsigned long pte_val(pte_t pte)
97{
98 return pte.pte;
99}
100
101static inline unsigned long pmd_val(pmd_t pmd)
102{
103 return pmd.pmd;
104}
105
106static inline unsigned long pud_val(pud_t pud)
107{
108 return pud.pud;
109}
110
111static inline unsigned long p4d_val(p4d_t p4d)
112{
113 return p4d.p4d;
114}
115
116static inline unsigned long pgd_val(pgd_t pgd)
117{
118 return pgd.pgd;
119}
120
121#define __pgste(x) ((pgste_t) { (x) } )
122#define __pte(x) ((pte_t) { (x) } )
123#define __pmd(x) ((pmd_t) { (x) } )
124#define __pud(x) ((pud_t) { (x) } )
125#define __p4d(x) ((p4d_t) { (x) } )
126#define __pgd(x) ((pgd_t) { (x) } )
127#define __pgprot(x) ((pgprot_t) { (x) } )
128
129static inline void page_set_storage_key(unsigned long addr,
130 unsigned char skey, int mapped)
131{
132 if (!mapped)
133 asm volatile(".insn rrf,0xb22b0000,%0,%1,8,0"
134 : : "d" (skey), "a" (addr));
135 else
136 asm volatile("sske %0,%1" : : "d" (skey), "a" (addr));
137}
138
139static inline unsigned char page_get_storage_key(unsigned long addr)
140{
141 unsigned char skey;
142
143 asm volatile("iske %0,%1" : "=d" (skey) : "a" (addr));
144 return skey;
145}
146
147static inline int page_reset_referenced(unsigned long addr)
148{
149 int cc;
150
151 asm volatile(
152 " rrbe 0,%1\n"
153 " ipm %0\n"
154 " srl %0,28\n"
155 : "=d" (cc) : "a" (addr) : "cc");
156 return cc;
157}
158
159/* Bits int the storage key */
160#define _PAGE_CHANGED 0x02 /* HW changed bit */
161#define _PAGE_REFERENCED 0x04 /* HW referenced bit */
162#define _PAGE_FP_BIT 0x08 /* HW fetch protection bit */
163#define _PAGE_ACC_BITS 0xf0 /* HW access control bits */
164
165struct page;
166void arch_free_page(struct page *page, int order);
167void arch_alloc_page(struct page *page, int order);
168void arch_set_page_dat(struct page *page, int order);
169
170static inline int devmem_is_allowed(unsigned long pfn)
171{
172 return 0;
173}
174
175#define HAVE_ARCH_FREE_PAGE
176#define HAVE_ARCH_ALLOC_PAGE
177
178#if IS_ENABLED(CONFIG_PGSTE)
179int arch_make_page_accessible(struct page *page);
180#define HAVE_ARCH_MAKE_PAGE_ACCESSIBLE
181#endif
182
183#endif /* !__ASSEMBLY__ */
184
185#define __PAGE_OFFSET 0x0UL
186#define PAGE_OFFSET 0x0UL
187
188#define __pa(x) ((unsigned long)(x))
189#define __va(x) ((void *)(unsigned long)(x))
190
191#define phys_to_pfn(phys) ((phys) >> PAGE_SHIFT)
192#define pfn_to_phys(pfn) ((pfn) << PAGE_SHIFT)
193
194#define phys_to_page(phys) pfn_to_page(phys_to_pfn(phys))
195#define page_to_phys(page) pfn_to_phys(page_to_pfn(page))
196
197#define pfn_to_virt(pfn) __va(pfn_to_phys(pfn))
198#define virt_to_pfn(kaddr) (phys_to_pfn(__pa(kaddr)))
199#define pfn_to_kaddr(pfn) pfn_to_virt(pfn)
200
201#define virt_to_page(kaddr) pfn_to_page(virt_to_pfn(kaddr))
202#define page_to_virt(page) pfn_to_virt(page_to_pfn(page))
203
204#define virt_addr_valid(kaddr) pfn_valid(virt_to_pfn(kaddr))
205
206#define VM_DATA_DEFAULT_FLAGS VM_DATA_FLAGS_NON_EXEC
207
208#include <asm-generic/memory_model.h>
209#include <asm-generic/getorder.h>
210
211#endif /* _S390_PAGE_H */
1/*
2 * include/asm-s390/page.h
3 *
4 * S390 version
5 * Copyright (C) 1999,2000 IBM Deutschland Entwicklung GmbH, IBM Corporation
6 * Author(s): Hartmut Penner (hp@de.ibm.com)
7 */
8
9#ifndef _S390_PAGE_H
10#define _S390_PAGE_H
11
12#include <linux/const.h>
13#include <asm/types.h>
14
15/* PAGE_SHIFT determines the page size */
16#define PAGE_SHIFT 12
17#define PAGE_SIZE (_AC(1,UL) << PAGE_SHIFT)
18#define PAGE_MASK (~(PAGE_SIZE-1))
19#define PAGE_DEFAULT_ACC 0
20#define PAGE_DEFAULT_KEY (PAGE_DEFAULT_ACC << 4)
21
22#define HPAGE_SHIFT 20
23#define HPAGE_SIZE (1UL << HPAGE_SHIFT)
24#define HPAGE_MASK (~(HPAGE_SIZE - 1))
25#define HUGETLB_PAGE_ORDER (HPAGE_SHIFT - PAGE_SHIFT)
26
27#define ARCH_HAS_SETCLEAR_HUGE_PTE
28#define ARCH_HAS_HUGE_PTE_TYPE
29#define ARCH_HAS_PREPARE_HUGEPAGE
30#define ARCH_HAS_HUGEPAGE_CLEAR_FLUSH
31
32#include <asm/setup.h>
33#ifndef __ASSEMBLY__
34
35static inline void clear_page(void *page)
36{
37 if (MACHINE_HAS_PFMF) {
38 asm volatile(
39 " .insn rre,0xb9af0000,%0,%1"
40 : : "d" (0x10000), "a" (page) : "memory", "cc");
41 } else {
42 register unsigned long reg1 asm ("1") = 0;
43 register void *reg2 asm ("2") = page;
44 register unsigned long reg3 asm ("3") = 4096;
45 asm volatile(
46 " mvcl 2,0"
47 : "+d" (reg2), "+d" (reg3) : "d" (reg1)
48 : "memory", "cc");
49 }
50}
51
52static inline void copy_page(void *to, void *from)
53{
54 if (MACHINE_HAS_MVPG) {
55 register unsigned long reg0 asm ("0") = 0;
56 asm volatile(
57 " mvpg %0,%1"
58 : : "a" (to), "a" (from), "d" (reg0)
59 : "memory", "cc");
60 } else
61 asm volatile(
62 " mvc 0(256,%0),0(%1)\n"
63 " mvc 256(256,%0),256(%1)\n"
64 " mvc 512(256,%0),512(%1)\n"
65 " mvc 768(256,%0),768(%1)\n"
66 " mvc 1024(256,%0),1024(%1)\n"
67 " mvc 1280(256,%0),1280(%1)\n"
68 " mvc 1536(256,%0),1536(%1)\n"
69 " mvc 1792(256,%0),1792(%1)\n"
70 " mvc 2048(256,%0),2048(%1)\n"
71 " mvc 2304(256,%0),2304(%1)\n"
72 " mvc 2560(256,%0),2560(%1)\n"
73 " mvc 2816(256,%0),2816(%1)\n"
74 " mvc 3072(256,%0),3072(%1)\n"
75 " mvc 3328(256,%0),3328(%1)\n"
76 " mvc 3584(256,%0),3584(%1)\n"
77 " mvc 3840(256,%0),3840(%1)\n"
78 : : "a" (to), "a" (from) : "memory");
79}
80
81#define clear_user_page(page, vaddr, pg) clear_page(page)
82#define copy_user_page(to, from, vaddr, pg) copy_page(to, from)
83
84#define __alloc_zeroed_user_highpage(movableflags, vma, vaddr) \
85 alloc_page_vma(GFP_HIGHUSER | __GFP_ZERO | movableflags, vma, vaddr)
86#define __HAVE_ARCH_ALLOC_ZEROED_USER_HIGHPAGE
87
88/*
89 * These are used to make use of C type-checking..
90 */
91
92typedef struct { unsigned long pgprot; } pgprot_t;
93typedef struct { unsigned long pgste; } pgste_t;
94typedef struct { unsigned long pte; } pte_t;
95typedef struct { unsigned long pmd; } pmd_t;
96typedef struct { unsigned long pud; } pud_t;
97typedef struct { unsigned long pgd; } pgd_t;
98typedef pte_t *pgtable_t;
99
100#define pgprot_val(x) ((x).pgprot)
101#define pgste_val(x) ((x).pgste)
102#define pte_val(x) ((x).pte)
103#define pmd_val(x) ((x).pmd)
104#define pud_val(x) ((x).pud)
105#define pgd_val(x) ((x).pgd)
106
107#define __pgste(x) ((pgste_t) { (x) } )
108#define __pte(x) ((pte_t) { (x) } )
109#define __pmd(x) ((pmd_t) { (x) } )
110#define __pud(x) ((pud_t) { (x) } )
111#define __pgd(x) ((pgd_t) { (x) } )
112#define __pgprot(x) ((pgprot_t) { (x) } )
113
114static inline void page_set_storage_key(unsigned long addr,
115 unsigned char skey, int mapped)
116{
117 if (!mapped)
118 asm volatile(".insn rrf,0xb22b0000,%0,%1,8,0"
119 : : "d" (skey), "a" (addr));
120 else
121 asm volatile("sske %0,%1" : : "d" (skey), "a" (addr));
122}
123
124static inline unsigned char page_get_storage_key(unsigned long addr)
125{
126 unsigned char skey;
127
128 asm volatile("iske %0,%1" : "=d" (skey) : "a" (addr));
129 return skey;
130}
131
132static inline int page_reset_referenced(unsigned long addr)
133{
134 unsigned int ipm;
135
136 asm volatile(
137 " rrbe 0,%1\n"
138 " ipm %0\n"
139 : "=d" (ipm) : "a" (addr) : "cc");
140 return !!(ipm & 0x20000000);
141}
142
143/* Bits int the storage key */
144#define _PAGE_CHANGED 0x02 /* HW changed bit */
145#define _PAGE_REFERENCED 0x04 /* HW referenced bit */
146#define _PAGE_FP_BIT 0x08 /* HW fetch protection bit */
147#define _PAGE_ACC_BITS 0xf0 /* HW access control bits */
148
149/*
150 * Test and clear dirty bit in storage key.
151 * We can't clear the changed bit atomically. This is a potential
152 * race against modification of the referenced bit. This function
153 * should therefore only be called if it is not mapped in any
154 * address space.
155 */
156#define __HAVE_ARCH_PAGE_TEST_AND_CLEAR_DIRTY
157static inline int page_test_and_clear_dirty(unsigned long pfn, int mapped)
158{
159 unsigned char skey;
160
161 skey = page_get_storage_key(pfn << PAGE_SHIFT);
162 if (!(skey & _PAGE_CHANGED))
163 return 0;
164 page_set_storage_key(pfn << PAGE_SHIFT, skey & ~_PAGE_CHANGED, mapped);
165 return 1;
166}
167
168/*
169 * Test and clear referenced bit in storage key.
170 */
171#define __HAVE_ARCH_PAGE_TEST_AND_CLEAR_YOUNG
172static inline int page_test_and_clear_young(unsigned long pfn)
173{
174 return page_reset_referenced(pfn << PAGE_SHIFT);
175}
176
177struct page;
178void arch_free_page(struct page *page, int order);
179void arch_alloc_page(struct page *page, int order);
180
181static inline int devmem_is_allowed(unsigned long pfn)
182{
183 return 0;
184}
185
186#define HAVE_ARCH_FREE_PAGE
187#define HAVE_ARCH_ALLOC_PAGE
188
189#endif /* !__ASSEMBLY__ */
190
191#define __PAGE_OFFSET 0x0UL
192#define PAGE_OFFSET 0x0UL
193#define __pa(x) (unsigned long)(x)
194#define __va(x) (void *)(unsigned long)(x)
195#define virt_to_page(kaddr) pfn_to_page(__pa(kaddr) >> PAGE_SHIFT)
196#define page_to_phys(page) (page_to_pfn(page) << PAGE_SHIFT)
197#define virt_addr_valid(kaddr) pfn_valid(__pa(kaddr) >> PAGE_SHIFT)
198
199#define VM_DATA_DEFAULT_FLAGS (VM_READ | VM_WRITE | \
200 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
201
202#include <asm-generic/memory_model.h>
203#include <asm-generic/getorder.h>
204
205#define __HAVE_ARCH_GATE_AREA 1
206
207#endif /* _S390_PAGE_H */