xref: /linux/arch/s390/include/asm/page.h (revision 75c89a2bc6ef00fd3c38c69cba82a92d0535887a)
1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
2c6557e7fSMartin Schwidefsky /*
3c6557e7fSMartin Schwidefsky  *  S390 version
4a53c8fabSHeiko Carstens  *    Copyright IBM Corp. 1999, 2000
5c6557e7fSMartin Schwidefsky  *    Author(s): Hartmut Penner (hp@de.ibm.com)
6c6557e7fSMartin Schwidefsky  */
7c6557e7fSMartin Schwidefsky 
8c6557e7fSMartin Schwidefsky #ifndef _S390_PAGE_H
9c6557e7fSMartin Schwidefsky #define _S390_PAGE_H
10c6557e7fSMartin Schwidefsky 
11c6557e7fSMartin Schwidefsky #include <linux/const.h>
12c6557e7fSMartin Schwidefsky #include <asm/types.h>
13c6557e7fSMartin Schwidefsky 
14c67da7c7SHeiko Carstens #define _PAGE_SHIFT	12
15c67da7c7SHeiko Carstens #define _PAGE_SIZE	(_AC(1, UL) << _PAGE_SHIFT)
16c67da7c7SHeiko Carstens #define _PAGE_MASK	(~(_PAGE_SIZE - 1))
17c67da7c7SHeiko Carstens 
18c6557e7fSMartin Schwidefsky /* PAGE_SHIFT determines the page size */
19c67da7c7SHeiko Carstens #define PAGE_SHIFT	_PAGE_SHIFT
20c67da7c7SHeiko Carstens #define PAGE_SIZE	_PAGE_SIZE
21c67da7c7SHeiko Carstens #define PAGE_MASK	_PAGE_MASK
22c6557e7fSMartin Schwidefsky #define PAGE_DEFAULT_ACC	0
23c6557e7fSMartin Schwidefsky #define PAGE_DEFAULT_KEY	(PAGE_DEFAULT_ACC << 4)
24c6557e7fSMartin Schwidefsky 
2541318bfeSDominik Dingel #define HPAGE_SHIFT	20
26c6557e7fSMartin Schwidefsky #define HPAGE_SIZE	(1UL << HPAGE_SHIFT)
27c6557e7fSMartin Schwidefsky #define HPAGE_MASK	(~(HPAGE_SIZE - 1))
28c6557e7fSMartin Schwidefsky #define HUGETLB_PAGE_ORDER	(HPAGE_SHIFT - PAGE_SHIFT)
29d08de8e2SGerald Schaefer #define HUGE_MAX_HSTATE		2
30c6557e7fSMartin Schwidefsky 
31c6557e7fSMartin Schwidefsky #define ARCH_HAS_SETCLEAR_HUGE_PTE
32c6557e7fSMartin Schwidefsky #define ARCH_HAS_HUGE_PTE_TYPE
33c6557e7fSMartin Schwidefsky #define ARCH_HAS_PREPARE_HUGEPAGE
34c6557e7fSMartin Schwidefsky #define ARCH_HAS_HUGEPAGE_CLEAR_FLUSH
35c6557e7fSMartin Schwidefsky 
365f490a52SGerald Schaefer #define HAVE_ARCH_HUGETLB_UNMAPPED_AREA
375f490a52SGerald Schaefer 
3841318bfeSDominik Dingel #include <asm/setup.h>
3941318bfeSDominik Dingel #ifndef __ASSEMBLY__
4041318bfeSDominik Dingel 
41de3fa841SHeiko Carstens void __storage_key_init_range(unsigned long start, unsigned long end);
42de3fa841SHeiko Carstens 
43127c1fefSMartin Schwidefsky static inline void storage_key_init_range(unsigned long start, unsigned long end)
44127c1fefSMartin Schwidefsky {
4538032473SNathan Chancellor 	if (PAGE_DEFAULT_KEY != 0)
46127c1fefSMartin Schwidefsky 		__storage_key_init_range(start, end);
47127c1fefSMartin Schwidefsky }
486b70a920SHeiko Carstens 
49fb3d1c08SChristian Borntraeger #define clear_page(page)	memset((page), 0, PAGE_SIZE)
50c6557e7fSMartin Schwidefsky 
51dba6bb60SHeiko Carstens /*
52dba6bb60SHeiko Carstens  * copy_page uses the mvcl instruction with 0xb0 padding byte in order to
53dba6bb60SHeiko Carstens  * bypass caches when copying a page. Especially when copying huge pages
54dba6bb60SHeiko Carstens  * this keeps L1 and L2 data caches alive.
55dba6bb60SHeiko Carstens  */
56c6557e7fSMartin Schwidefsky static inline void copy_page(void *to, void *from)
57c6557e7fSMartin Schwidefsky {
58*75c89a2bSHeiko Carstens 	union register_pair dst, src;
59*75c89a2bSHeiko Carstens 
60*75c89a2bSHeiko Carstens 	dst.even = (unsigned long) to;
61*75c89a2bSHeiko Carstens 	dst.odd  = 0x1000;
62*75c89a2bSHeiko Carstens 	src.even = (unsigned long) from;
63*75c89a2bSHeiko Carstens 	src.odd  = 0xb0001000;
64*75c89a2bSHeiko Carstens 
65c6557e7fSMartin Schwidefsky 	asm volatile(
66*75c89a2bSHeiko Carstens 		"	mvcl	%[dst],%[src]"
67*75c89a2bSHeiko Carstens 		: [dst] "+&d" (dst.pair), [src] "+&d" (src.pair)
68dba6bb60SHeiko Carstens 		: : "memory", "cc");
69c6557e7fSMartin Schwidefsky }
70c6557e7fSMartin Schwidefsky 
71c6557e7fSMartin Schwidefsky #define clear_user_page(page, vaddr, pg)	clear_page(page)
72c6557e7fSMartin Schwidefsky #define copy_user_page(to, from, vaddr, pg)	copy_page(to, from)
73c6557e7fSMartin Schwidefsky 
74c6557e7fSMartin Schwidefsky #define __alloc_zeroed_user_highpage(movableflags, vma, vaddr) \
75c6557e7fSMartin Schwidefsky 	alloc_page_vma(GFP_HIGHUSER | __GFP_ZERO | movableflags, vma, vaddr)
76c6557e7fSMartin Schwidefsky #define __HAVE_ARCH_ALLOC_ZEROED_USER_HIGHPAGE
77c6557e7fSMartin Schwidefsky 
78c6557e7fSMartin Schwidefsky /*
79c6557e7fSMartin Schwidefsky  * These are used to make use of C type-checking..
80c6557e7fSMartin Schwidefsky  */
81c6557e7fSMartin Schwidefsky 
82c6557e7fSMartin Schwidefsky typedef struct { unsigned long pgprot; } pgprot_t;
83b2fa47e6SMartin Schwidefsky typedef struct { unsigned long pgste; } pgste_t;
84c6557e7fSMartin Schwidefsky typedef struct { unsigned long pte; } pte_t;
85c6557e7fSMartin Schwidefsky typedef struct { unsigned long pmd; } pmd_t;
86c6557e7fSMartin Schwidefsky typedef struct { unsigned long pud; } pud_t;
871aea9b3fSMartin Schwidefsky typedef struct { unsigned long p4d; } p4d_t;
88c6557e7fSMartin Schwidefsky typedef struct { unsigned long pgd; } pgd_t;
89c6557e7fSMartin Schwidefsky typedef pte_t *pgtable_t;
90c6557e7fSMartin Schwidefsky 
91c6557e7fSMartin Schwidefsky #define pgprot_val(x)	((x).pgprot)
92b2fa47e6SMartin Schwidefsky #define pgste_val(x)	((x).pgste)
93c6557e7fSMartin Schwidefsky #define pte_val(x)	((x).pte)
94c6557e7fSMartin Schwidefsky #define pmd_val(x)	((x).pmd)
95c6557e7fSMartin Schwidefsky #define pud_val(x)	((x).pud)
961aea9b3fSMartin Schwidefsky #define p4d_val(x)	((x).p4d)
97c6557e7fSMartin Schwidefsky #define pgd_val(x)      ((x).pgd)
98c6557e7fSMartin Schwidefsky 
99b2fa47e6SMartin Schwidefsky #define __pgste(x)	((pgste_t) { (x) } )
100c6557e7fSMartin Schwidefsky #define __pte(x)        ((pte_t) { (x) } )
101c6557e7fSMartin Schwidefsky #define __pmd(x)        ((pmd_t) { (x) } )
102b2fa47e6SMartin Schwidefsky #define __pud(x)	((pud_t) { (x) } )
1031aea9b3fSMartin Schwidefsky #define __p4d(x)	((p4d_t) { (x) } )
104c6557e7fSMartin Schwidefsky #define __pgd(x)        ((pgd_t) { (x) } )
105c6557e7fSMartin Schwidefsky #define __pgprot(x)     ((pgprot_t) { (x) } )
106c6557e7fSMartin Schwidefsky 
1072d42552dSMartin Schwidefsky static inline void page_set_storage_key(unsigned long addr,
1082d42552dSMartin Schwidefsky 					unsigned char skey, int mapped)
109c6557e7fSMartin Schwidefsky {
110e2b8d7afSMartin Schwidefsky 	if (!mapped)
111e2b8d7afSMartin Schwidefsky 		asm volatile(".insn rrf,0xb22b0000,%0,%1,8,0"
112e2b8d7afSMartin Schwidefsky 			     : : "d" (skey), "a" (addr));
113e2b8d7afSMartin Schwidefsky 	else
114c6557e7fSMartin Schwidefsky 		asm volatile("sske %0,%1" : : "d" (skey), "a" (addr));
115c6557e7fSMartin Schwidefsky }
116c6557e7fSMartin Schwidefsky 
1172d42552dSMartin Schwidefsky static inline unsigned char page_get_storage_key(unsigned long addr)
118c6557e7fSMartin Schwidefsky {
1192d42552dSMartin Schwidefsky 	unsigned char skey;
120c6557e7fSMartin Schwidefsky 
1212d42552dSMartin Schwidefsky 	asm volatile("iske %0,%1" : "=d" (skey) : "a" (addr));
122c6557e7fSMartin Schwidefsky 	return skey;
123c6557e7fSMartin Schwidefsky }
124c6557e7fSMartin Schwidefsky 
1252d42552dSMartin Schwidefsky static inline int page_reset_referenced(unsigned long addr)
1262d42552dSMartin Schwidefsky {
127a7e19ab5SDavid Hildenbrand 	int cc;
1282d42552dSMartin Schwidefsky 
1292d42552dSMartin Schwidefsky 	asm volatile(
1302d42552dSMartin Schwidefsky 		"	rrbe	0,%1\n"
1312d42552dSMartin Schwidefsky 		"	ipm	%0\n"
132a7e19ab5SDavid Hildenbrand 		"	srl	%0,28\n"
133a7e19ab5SDavid Hildenbrand 		: "=d" (cc) : "a" (addr) : "cc");
134a7e19ab5SDavid Hildenbrand 	return cc;
1352d42552dSMartin Schwidefsky }
1362d42552dSMartin Schwidefsky 
1372d42552dSMartin Schwidefsky /* Bits int the storage key */
1382d42552dSMartin Schwidefsky #define _PAGE_CHANGED		0x02	/* HW changed bit		*/
1392d42552dSMartin Schwidefsky #define _PAGE_REFERENCED	0x04	/* HW referenced bit		*/
1402d42552dSMartin Schwidefsky #define _PAGE_FP_BIT		0x08	/* HW fetch protection bit	*/
1412d42552dSMartin Schwidefsky #define _PAGE_ACC_BITS		0xf0	/* HW access control bits	*/
1422d42552dSMartin Schwidefsky 
143c6557e7fSMartin Schwidefsky struct page;
144c6557e7fSMartin Schwidefsky void arch_free_page(struct page *page, int order);
145c6557e7fSMartin Schwidefsky void arch_alloc_page(struct page *page, int order);
146c9b5ad54SMartin Schwidefsky void arch_set_page_dat(struct page *page, int order);
147c9b5ad54SMartin Schwidefsky void arch_set_page_nodat(struct page *page, int order);
148c9b5ad54SMartin Schwidefsky int arch_test_page_nodat(struct page *page);
149638ad34aSMartin Schwidefsky void arch_set_page_states(int make_stable);
150c6557e7fSMartin Schwidefsky 
151ec6743bbSHendrik Brueckner static inline int devmem_is_allowed(unsigned long pfn)
152ec6743bbSHendrik Brueckner {
153ec6743bbSHendrik Brueckner 	return 0;
154ec6743bbSHendrik Brueckner }
155ec6743bbSHendrik Brueckner 
156c6557e7fSMartin Schwidefsky #define HAVE_ARCH_FREE_PAGE
157c6557e7fSMartin Schwidefsky #define HAVE_ARCH_ALLOC_PAGE
158c6557e7fSMartin Schwidefsky 
159214d9bbcSClaudio Imbrenda #if IS_ENABLED(CONFIG_PGSTE)
160214d9bbcSClaudio Imbrenda int arch_make_page_accessible(struct page *page);
161214d9bbcSClaudio Imbrenda #define HAVE_ARCH_MAKE_PAGE_ACCESSIBLE
162214d9bbcSClaudio Imbrenda #endif
163214d9bbcSClaudio Imbrenda 
164c6557e7fSMartin Schwidefsky #endif /* !__ASSEMBLY__ */
165c6557e7fSMartin Schwidefsky 
166c6557e7fSMartin Schwidefsky #define __PAGE_OFFSET		0x0UL
167c6557e7fSMartin Schwidefsky #define PAGE_OFFSET		0x0UL
16816f48641SHeiko Carstens 
16916f48641SHeiko Carstens #define __pa(x)			((unsigned long)(x))
17016f48641SHeiko Carstens #define __va(x)			((void *)(unsigned long)(x))
17116f48641SHeiko Carstens 
172014b0204SAlexander Gordeev #define phys_to_pfn(phys)	((phys) >> PAGE_SHIFT)
173014b0204SAlexander Gordeev #define pfn_to_phys(pfn)	((pfn) << PAGE_SHIFT)
174014b0204SAlexander Gordeev 
175014b0204SAlexander Gordeev #define phys_to_page(phys)	pfn_to_page(phys_to_pfn(phys))
176014b0204SAlexander Gordeev #define page_to_phys(page)	pfn_to_phys(page_to_pfn(page))
177014b0204SAlexander Gordeev 
178014b0204SAlexander Gordeev #define pfn_to_virt(pfn)	__va(pfn_to_phys(pfn))
179014b0204SAlexander Gordeev #define virt_to_pfn(kaddr)	(phys_to_pfn(__pa(kaddr)))
18075f19542SVasily Gorbik #define pfn_to_kaddr(pfn)	pfn_to_virt(pfn)
18116f48641SHeiko Carstens 
18216f48641SHeiko Carstens #define virt_to_page(kaddr)	pfn_to_page(virt_to_pfn(kaddr))
1833d84683bSDavid Hildenbrand #define page_to_virt(page)	pfn_to_virt(page_to_pfn(page))
184c6557e7fSMartin Schwidefsky 
185014b0204SAlexander Gordeev #define virt_addr_valid(kaddr)	pfn_valid(virt_to_pfn(kaddr))
18616f48641SHeiko Carstens 
187c62da0c3SAnshuman Khandual #define VM_DATA_DEFAULT_FLAGS	VM_DATA_FLAGS_NON_EXEC
188c6557e7fSMartin Schwidefsky 
189c6557e7fSMartin Schwidefsky #include <asm-generic/memory_model.h>
1905b17e1cdSArnd Bergmann #include <asm-generic/getorder.h>
191c6557e7fSMartin Schwidefsky 
192c6557e7fSMartin Schwidefsky #endif /* _S390_PAGE_H */
193