xref: /linux/arch/s390/include/asm/page.h (revision 214d9bbcd3a67230b932f6cea83c078ab34d9e70)
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 {
45de3fa841SHeiko Carstens 	if (PAGE_DEFAULT_KEY)
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 {
58dba6bb60SHeiko Carstens 	register void *reg2 asm ("2") = to;
59dba6bb60SHeiko Carstens 	register unsigned long reg3 asm ("3") = 0x1000;
60dba6bb60SHeiko Carstens 	register void *reg4 asm ("4") = from;
61dba6bb60SHeiko Carstens 	register unsigned long reg5 asm ("5") = 0xb0001000;
62c6557e7fSMartin Schwidefsky 	asm volatile(
63dba6bb60SHeiko Carstens 		"	mvcl	2,4"
64dba6bb60SHeiko Carstens 		: "+d" (reg2), "+d" (reg3), "+d" (reg4), "+d" (reg5)
65dba6bb60SHeiko Carstens 		: : "memory", "cc");
66c6557e7fSMartin Schwidefsky }
67c6557e7fSMartin Schwidefsky 
68c6557e7fSMartin Schwidefsky #define clear_user_page(page, vaddr, pg)	clear_page(page)
69c6557e7fSMartin Schwidefsky #define copy_user_page(to, from, vaddr, pg)	copy_page(to, from)
70c6557e7fSMartin Schwidefsky 
71c6557e7fSMartin Schwidefsky #define __alloc_zeroed_user_highpage(movableflags, vma, vaddr) \
72c6557e7fSMartin Schwidefsky 	alloc_page_vma(GFP_HIGHUSER | __GFP_ZERO | movableflags, vma, vaddr)
73c6557e7fSMartin Schwidefsky #define __HAVE_ARCH_ALLOC_ZEROED_USER_HIGHPAGE
74c6557e7fSMartin Schwidefsky 
75c6557e7fSMartin Schwidefsky /*
76c6557e7fSMartin Schwidefsky  * These are used to make use of C type-checking..
77c6557e7fSMartin Schwidefsky  */
78c6557e7fSMartin Schwidefsky 
79c6557e7fSMartin Schwidefsky typedef struct { unsigned long pgprot; } pgprot_t;
80b2fa47e6SMartin Schwidefsky typedef struct { unsigned long pgste; } pgste_t;
81c6557e7fSMartin Schwidefsky typedef struct { unsigned long pte; } pte_t;
82c6557e7fSMartin Schwidefsky typedef struct { unsigned long pmd; } pmd_t;
83c6557e7fSMartin Schwidefsky typedef struct { unsigned long pud; } pud_t;
841aea9b3fSMartin Schwidefsky typedef struct { unsigned long p4d; } p4d_t;
85c6557e7fSMartin Schwidefsky typedef struct { unsigned long pgd; } pgd_t;
86c6557e7fSMartin Schwidefsky typedef pte_t *pgtable_t;
87c6557e7fSMartin Schwidefsky 
88c6557e7fSMartin Schwidefsky #define pgprot_val(x)	((x).pgprot)
89b2fa47e6SMartin Schwidefsky #define pgste_val(x)	((x).pgste)
90c6557e7fSMartin Schwidefsky #define pte_val(x)	((x).pte)
91c6557e7fSMartin Schwidefsky #define pmd_val(x)	((x).pmd)
92c6557e7fSMartin Schwidefsky #define pud_val(x)	((x).pud)
931aea9b3fSMartin Schwidefsky #define p4d_val(x)	((x).p4d)
94c6557e7fSMartin Schwidefsky #define pgd_val(x)      ((x).pgd)
95c6557e7fSMartin Schwidefsky 
96b2fa47e6SMartin Schwidefsky #define __pgste(x)	((pgste_t) { (x) } )
97c6557e7fSMartin Schwidefsky #define __pte(x)        ((pte_t) { (x) } )
98c6557e7fSMartin Schwidefsky #define __pmd(x)        ((pmd_t) { (x) } )
99b2fa47e6SMartin Schwidefsky #define __pud(x)	((pud_t) { (x) } )
1001aea9b3fSMartin Schwidefsky #define __p4d(x)	((p4d_t) { (x) } )
101c6557e7fSMartin Schwidefsky #define __pgd(x)        ((pgd_t) { (x) } )
102c6557e7fSMartin Schwidefsky #define __pgprot(x)     ((pgprot_t) { (x) } )
103c6557e7fSMartin Schwidefsky 
1042d42552dSMartin Schwidefsky static inline void page_set_storage_key(unsigned long addr,
1052d42552dSMartin Schwidefsky 					unsigned char skey, int mapped)
106c6557e7fSMartin Schwidefsky {
107e2b8d7afSMartin Schwidefsky 	if (!mapped)
108e2b8d7afSMartin Schwidefsky 		asm volatile(".insn rrf,0xb22b0000,%0,%1,8,0"
109e2b8d7afSMartin Schwidefsky 			     : : "d" (skey), "a" (addr));
110e2b8d7afSMartin Schwidefsky 	else
111c6557e7fSMartin Schwidefsky 		asm volatile("sske %0,%1" : : "d" (skey), "a" (addr));
112c6557e7fSMartin Schwidefsky }
113c6557e7fSMartin Schwidefsky 
1142d42552dSMartin Schwidefsky static inline unsigned char page_get_storage_key(unsigned long addr)
115c6557e7fSMartin Schwidefsky {
1162d42552dSMartin Schwidefsky 	unsigned char skey;
117c6557e7fSMartin Schwidefsky 
1182d42552dSMartin Schwidefsky 	asm volatile("iske %0,%1" : "=d" (skey) : "a" (addr));
119c6557e7fSMartin Schwidefsky 	return skey;
120c6557e7fSMartin Schwidefsky }
121c6557e7fSMartin Schwidefsky 
1222d42552dSMartin Schwidefsky static inline int page_reset_referenced(unsigned long addr)
1232d42552dSMartin Schwidefsky {
124a7e19ab5SDavid Hildenbrand 	int cc;
1252d42552dSMartin Schwidefsky 
1262d42552dSMartin Schwidefsky 	asm volatile(
1272d42552dSMartin Schwidefsky 		"	rrbe	0,%1\n"
1282d42552dSMartin Schwidefsky 		"	ipm	%0\n"
129a7e19ab5SDavid Hildenbrand 		"	srl	%0,28\n"
130a7e19ab5SDavid Hildenbrand 		: "=d" (cc) : "a" (addr) : "cc");
131a7e19ab5SDavid Hildenbrand 	return cc;
1322d42552dSMartin Schwidefsky }
1332d42552dSMartin Schwidefsky 
1342d42552dSMartin Schwidefsky /* Bits int the storage key */
1352d42552dSMartin Schwidefsky #define _PAGE_CHANGED		0x02	/* HW changed bit		*/
1362d42552dSMartin Schwidefsky #define _PAGE_REFERENCED	0x04	/* HW referenced bit		*/
1372d42552dSMartin Schwidefsky #define _PAGE_FP_BIT		0x08	/* HW fetch protection bit	*/
1382d42552dSMartin Schwidefsky #define _PAGE_ACC_BITS		0xf0	/* HW access control bits	*/
1392d42552dSMartin Schwidefsky 
140c6557e7fSMartin Schwidefsky struct page;
141c6557e7fSMartin Schwidefsky void arch_free_page(struct page *page, int order);
142c6557e7fSMartin Schwidefsky void arch_alloc_page(struct page *page, int order);
143c9b5ad54SMartin Schwidefsky void arch_set_page_dat(struct page *page, int order);
144c9b5ad54SMartin Schwidefsky void arch_set_page_nodat(struct page *page, int order);
145c9b5ad54SMartin Schwidefsky int arch_test_page_nodat(struct page *page);
146638ad34aSMartin Schwidefsky void arch_set_page_states(int make_stable);
147c6557e7fSMartin Schwidefsky 
148ec6743bbSHendrik Brueckner static inline int devmem_is_allowed(unsigned long pfn)
149ec6743bbSHendrik Brueckner {
150ec6743bbSHendrik Brueckner 	return 0;
151ec6743bbSHendrik Brueckner }
152ec6743bbSHendrik Brueckner 
153c6557e7fSMartin Schwidefsky #define HAVE_ARCH_FREE_PAGE
154c6557e7fSMartin Schwidefsky #define HAVE_ARCH_ALLOC_PAGE
155c6557e7fSMartin Schwidefsky 
156*214d9bbcSClaudio Imbrenda #if IS_ENABLED(CONFIG_PGSTE)
157*214d9bbcSClaudio Imbrenda int arch_make_page_accessible(struct page *page);
158*214d9bbcSClaudio Imbrenda #define HAVE_ARCH_MAKE_PAGE_ACCESSIBLE
159*214d9bbcSClaudio Imbrenda #endif
160*214d9bbcSClaudio Imbrenda 
161c6557e7fSMartin Schwidefsky #endif /* !__ASSEMBLY__ */
162c6557e7fSMartin Schwidefsky 
163c6557e7fSMartin Schwidefsky #define __PAGE_OFFSET		0x0UL
164c6557e7fSMartin Schwidefsky #define PAGE_OFFSET		0x0UL
16516f48641SHeiko Carstens 
16616f48641SHeiko Carstens #define __pa(x)			((unsigned long)(x))
16716f48641SHeiko Carstens #define __va(x)			((void *)(unsigned long)(x))
16816f48641SHeiko Carstens 
16916f48641SHeiko Carstens #define virt_to_pfn(kaddr)	(__pa(kaddr) >> PAGE_SHIFT)
1703d84683bSDavid Hildenbrand #define pfn_to_virt(pfn)	__va((pfn) << PAGE_SHIFT)
17175f19542SVasily Gorbik #define pfn_to_kaddr(pfn)	pfn_to_virt(pfn)
17216f48641SHeiko Carstens 
17316f48641SHeiko Carstens #define virt_to_page(kaddr)	pfn_to_page(virt_to_pfn(kaddr))
1743d84683bSDavid Hildenbrand #define page_to_virt(page)	pfn_to_virt(page_to_pfn(page))
175c6557e7fSMartin Schwidefsky 
17616f48641SHeiko Carstens #define phys_to_pfn(kaddr)	((kaddr) >> PAGE_SHIFT)
17716f48641SHeiko Carstens #define pfn_to_phys(pfn)	((pfn) << PAGE_SHIFT)
17816f48641SHeiko Carstens 
17916f48641SHeiko Carstens #define phys_to_page(kaddr)	pfn_to_page(phys_to_pfn(kaddr))
18016f48641SHeiko Carstens #define page_to_phys(page)	(page_to_pfn(page) << PAGE_SHIFT)
18116f48641SHeiko Carstens 
18216f48641SHeiko Carstens #define virt_addr_valid(kaddr)	pfn_valid(__pa(kaddr) >> PAGE_SHIFT)
18316f48641SHeiko Carstens 
184c6557e7fSMartin Schwidefsky #define VM_DATA_DEFAULT_FLAGS	(VM_READ | VM_WRITE | \
185c6557e7fSMartin Schwidefsky 				 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
186c6557e7fSMartin Schwidefsky 
187c6557e7fSMartin Schwidefsky #include <asm-generic/memory_model.h>
1885b17e1cdSArnd Bergmann #include <asm-generic/getorder.h>
189c6557e7fSMartin Schwidefsky 
190c6557e7fSMartin Schwidefsky #endif /* _S390_PAGE_H */
191