18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci *  S390 version
48c2ecf20Sopenharmony_ci *    Copyright IBM Corp. 1999, 2000
58c2ecf20Sopenharmony_ci *    Author(s): Hartmut Penner (hp@de.ibm.com)
68c2ecf20Sopenharmony_ci */
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_ci#ifndef _S390_PAGE_H
98c2ecf20Sopenharmony_ci#define _S390_PAGE_H
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ci#include <linux/const.h>
128c2ecf20Sopenharmony_ci#include <asm/types.h>
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ci#define _PAGE_SHIFT	12
158c2ecf20Sopenharmony_ci#define _PAGE_SIZE	(_AC(1, UL) << _PAGE_SHIFT)
168c2ecf20Sopenharmony_ci#define _PAGE_MASK	(~(_PAGE_SIZE - 1))
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_ci/* PAGE_SHIFT determines the page size */
198c2ecf20Sopenharmony_ci#define PAGE_SHIFT	_PAGE_SHIFT
208c2ecf20Sopenharmony_ci#define PAGE_SIZE	_PAGE_SIZE
218c2ecf20Sopenharmony_ci#define PAGE_MASK	_PAGE_MASK
228c2ecf20Sopenharmony_ci#define PAGE_DEFAULT_ACC	0
238c2ecf20Sopenharmony_ci#define PAGE_DEFAULT_KEY	(PAGE_DEFAULT_ACC << 4)
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_ci#define HPAGE_SHIFT	20
268c2ecf20Sopenharmony_ci#define HPAGE_SIZE	(1UL << HPAGE_SHIFT)
278c2ecf20Sopenharmony_ci#define HPAGE_MASK	(~(HPAGE_SIZE - 1))
288c2ecf20Sopenharmony_ci#define HUGETLB_PAGE_ORDER	(HPAGE_SHIFT - PAGE_SHIFT)
298c2ecf20Sopenharmony_ci#define HUGE_MAX_HSTATE		2
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_ci#define ARCH_HAS_SETCLEAR_HUGE_PTE
328c2ecf20Sopenharmony_ci#define ARCH_HAS_HUGE_PTE_TYPE
338c2ecf20Sopenharmony_ci#define ARCH_HAS_PREPARE_HUGEPAGE
348c2ecf20Sopenharmony_ci#define ARCH_HAS_HUGEPAGE_CLEAR_FLUSH
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_ci#define HAVE_ARCH_HUGETLB_UNMAPPED_AREA
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ci#include <asm/setup.h>
398c2ecf20Sopenharmony_ci#ifndef __ASSEMBLY__
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_civoid __storage_key_init_range(unsigned long start, unsigned long end);
428c2ecf20Sopenharmony_ci
438c2ecf20Sopenharmony_cistatic inline void storage_key_init_range(unsigned long start, unsigned long end)
448c2ecf20Sopenharmony_ci{
458c2ecf20Sopenharmony_ci	if (PAGE_DEFAULT_KEY != 0)
468c2ecf20Sopenharmony_ci		__storage_key_init_range(start, end);
478c2ecf20Sopenharmony_ci}
488c2ecf20Sopenharmony_ci
498c2ecf20Sopenharmony_ci#define clear_page(page)	memset((page), 0, PAGE_SIZE)
508c2ecf20Sopenharmony_ci
518c2ecf20Sopenharmony_ci/*
528c2ecf20Sopenharmony_ci * copy_page uses the mvcl instruction with 0xb0 padding byte in order to
538c2ecf20Sopenharmony_ci * bypass caches when copying a page. Especially when copying huge pages
548c2ecf20Sopenharmony_ci * this keeps L1 and L2 data caches alive.
558c2ecf20Sopenharmony_ci */
568c2ecf20Sopenharmony_cistatic inline void copy_page(void *to, void *from)
578c2ecf20Sopenharmony_ci{
588c2ecf20Sopenharmony_ci	register void *reg2 asm ("2") = to;
598c2ecf20Sopenharmony_ci	register unsigned long reg3 asm ("3") = 0x1000;
608c2ecf20Sopenharmony_ci	register void *reg4 asm ("4") = from;
618c2ecf20Sopenharmony_ci	register unsigned long reg5 asm ("5") = 0xb0001000;
628c2ecf20Sopenharmony_ci	asm volatile(
638c2ecf20Sopenharmony_ci		"	mvcl	2,4"
648c2ecf20Sopenharmony_ci		: "+d" (reg2), "+d" (reg3), "+d" (reg4), "+d" (reg5)
658c2ecf20Sopenharmony_ci		: : "memory", "cc");
668c2ecf20Sopenharmony_ci}
678c2ecf20Sopenharmony_ci
688c2ecf20Sopenharmony_ci#define clear_user_page(page, vaddr, pg)	clear_page(page)
698c2ecf20Sopenharmony_ci#define copy_user_page(to, from, vaddr, pg)	copy_page(to, from)
708c2ecf20Sopenharmony_ci
718c2ecf20Sopenharmony_ci#define __alloc_zeroed_user_highpage(movableflags, vma, vaddr) \
728c2ecf20Sopenharmony_ci	alloc_page_vma(GFP_HIGHUSER | __GFP_ZERO | movableflags, vma, vaddr)
738c2ecf20Sopenharmony_ci#define __HAVE_ARCH_ALLOC_ZEROED_USER_HIGHPAGE
748c2ecf20Sopenharmony_ci
758c2ecf20Sopenharmony_ci/*
768c2ecf20Sopenharmony_ci * These are used to make use of C type-checking..
778c2ecf20Sopenharmony_ci */
788c2ecf20Sopenharmony_ci
798c2ecf20Sopenharmony_citypedef struct { unsigned long pgprot; } pgprot_t;
808c2ecf20Sopenharmony_citypedef struct { unsigned long pgste; } pgste_t;
818c2ecf20Sopenharmony_citypedef struct { unsigned long pte; } pte_t;
828c2ecf20Sopenharmony_citypedef struct { unsigned long pmd; } pmd_t;
838c2ecf20Sopenharmony_citypedef struct { unsigned long pud; } pud_t;
848c2ecf20Sopenharmony_citypedef struct { unsigned long p4d; } p4d_t;
858c2ecf20Sopenharmony_citypedef struct { unsigned long pgd; } pgd_t;
868c2ecf20Sopenharmony_citypedef pte_t *pgtable_t;
878c2ecf20Sopenharmony_ci
888c2ecf20Sopenharmony_ci#define pgprot_val(x)	((x).pgprot)
898c2ecf20Sopenharmony_ci#define pgste_val(x)	((x).pgste)
908c2ecf20Sopenharmony_ci#define pte_val(x)	((x).pte)
918c2ecf20Sopenharmony_ci#define pmd_val(x)	((x).pmd)
928c2ecf20Sopenharmony_ci#define pud_val(x)	((x).pud)
938c2ecf20Sopenharmony_ci#define p4d_val(x)	((x).p4d)
948c2ecf20Sopenharmony_ci#define pgd_val(x)      ((x).pgd)
958c2ecf20Sopenharmony_ci
968c2ecf20Sopenharmony_ci#define __pgste(x)	((pgste_t) { (x) } )
978c2ecf20Sopenharmony_ci#define __pte(x)        ((pte_t) { (x) } )
988c2ecf20Sopenharmony_ci#define __pmd(x)        ((pmd_t) { (x) } )
998c2ecf20Sopenharmony_ci#define __pud(x)	((pud_t) { (x) } )
1008c2ecf20Sopenharmony_ci#define __p4d(x)	((p4d_t) { (x) } )
1018c2ecf20Sopenharmony_ci#define __pgd(x)        ((pgd_t) { (x) } )
1028c2ecf20Sopenharmony_ci#define __pgprot(x)     ((pgprot_t) { (x) } )
1038c2ecf20Sopenharmony_ci
1048c2ecf20Sopenharmony_cistatic inline void page_set_storage_key(unsigned long addr,
1058c2ecf20Sopenharmony_ci					unsigned char skey, int mapped)
1068c2ecf20Sopenharmony_ci{
1078c2ecf20Sopenharmony_ci	if (!mapped)
1088c2ecf20Sopenharmony_ci		asm volatile(".insn rrf,0xb22b0000,%0,%1,8,0"
1098c2ecf20Sopenharmony_ci			     : : "d" (skey), "a" (addr));
1108c2ecf20Sopenharmony_ci	else
1118c2ecf20Sopenharmony_ci		asm volatile("sske %0,%1" : : "d" (skey), "a" (addr));
1128c2ecf20Sopenharmony_ci}
1138c2ecf20Sopenharmony_ci
1148c2ecf20Sopenharmony_cistatic inline unsigned char page_get_storage_key(unsigned long addr)
1158c2ecf20Sopenharmony_ci{
1168c2ecf20Sopenharmony_ci	unsigned char skey;
1178c2ecf20Sopenharmony_ci
1188c2ecf20Sopenharmony_ci	asm volatile("iske %0,%1" : "=d" (skey) : "a" (addr));
1198c2ecf20Sopenharmony_ci	return skey;
1208c2ecf20Sopenharmony_ci}
1218c2ecf20Sopenharmony_ci
1228c2ecf20Sopenharmony_cistatic inline int page_reset_referenced(unsigned long addr)
1238c2ecf20Sopenharmony_ci{
1248c2ecf20Sopenharmony_ci	int cc;
1258c2ecf20Sopenharmony_ci
1268c2ecf20Sopenharmony_ci	asm volatile(
1278c2ecf20Sopenharmony_ci		"	rrbe	0,%1\n"
1288c2ecf20Sopenharmony_ci		"	ipm	%0\n"
1298c2ecf20Sopenharmony_ci		"	srl	%0,28\n"
1308c2ecf20Sopenharmony_ci		: "=d" (cc) : "a" (addr) : "cc");
1318c2ecf20Sopenharmony_ci	return cc;
1328c2ecf20Sopenharmony_ci}
1338c2ecf20Sopenharmony_ci
1348c2ecf20Sopenharmony_ci/* Bits int the storage key */
1358c2ecf20Sopenharmony_ci#define _PAGE_CHANGED		0x02	/* HW changed bit		*/
1368c2ecf20Sopenharmony_ci#define _PAGE_REFERENCED	0x04	/* HW referenced bit		*/
1378c2ecf20Sopenharmony_ci#define _PAGE_FP_BIT		0x08	/* HW fetch protection bit	*/
1388c2ecf20Sopenharmony_ci#define _PAGE_ACC_BITS		0xf0	/* HW access control bits	*/
1398c2ecf20Sopenharmony_ci
1408c2ecf20Sopenharmony_cistruct page;
1418c2ecf20Sopenharmony_civoid arch_free_page(struct page *page, int order);
1428c2ecf20Sopenharmony_civoid arch_alloc_page(struct page *page, int order);
1438c2ecf20Sopenharmony_civoid arch_set_page_dat(struct page *page, int order);
1448c2ecf20Sopenharmony_civoid arch_set_page_nodat(struct page *page, int order);
1458c2ecf20Sopenharmony_ciint arch_test_page_nodat(struct page *page);
1468c2ecf20Sopenharmony_civoid arch_set_page_states(int make_stable);
1478c2ecf20Sopenharmony_ci
1488c2ecf20Sopenharmony_cistatic inline int devmem_is_allowed(unsigned long pfn)
1498c2ecf20Sopenharmony_ci{
1508c2ecf20Sopenharmony_ci	return 0;
1518c2ecf20Sopenharmony_ci}
1528c2ecf20Sopenharmony_ci
1538c2ecf20Sopenharmony_ci#define HAVE_ARCH_FREE_PAGE
1548c2ecf20Sopenharmony_ci#define HAVE_ARCH_ALLOC_PAGE
1558c2ecf20Sopenharmony_ci
1568c2ecf20Sopenharmony_ci#if IS_ENABLED(CONFIG_PGSTE)
1578c2ecf20Sopenharmony_ciint arch_make_page_accessible(struct page *page);
1588c2ecf20Sopenharmony_ci#define HAVE_ARCH_MAKE_PAGE_ACCESSIBLE
1598c2ecf20Sopenharmony_ci#endif
1608c2ecf20Sopenharmony_ci
1618c2ecf20Sopenharmony_ci#endif /* !__ASSEMBLY__ */
1628c2ecf20Sopenharmony_ci
1638c2ecf20Sopenharmony_ci#define __PAGE_OFFSET		0x0UL
1648c2ecf20Sopenharmony_ci#define PAGE_OFFSET		0x0UL
1658c2ecf20Sopenharmony_ci
1668c2ecf20Sopenharmony_ci#define __pa(x)			((unsigned long)(x))
1678c2ecf20Sopenharmony_ci#define __va(x)			((void *)(unsigned long)(x))
1688c2ecf20Sopenharmony_ci
1698c2ecf20Sopenharmony_ci#define phys_to_pfn(phys)	((phys) >> PAGE_SHIFT)
1708c2ecf20Sopenharmony_ci#define pfn_to_phys(pfn)	((pfn) << PAGE_SHIFT)
1718c2ecf20Sopenharmony_ci
1728c2ecf20Sopenharmony_ci#define phys_to_page(phys)	pfn_to_page(phys_to_pfn(phys))
1738c2ecf20Sopenharmony_ci#define page_to_phys(page)	pfn_to_phys(page_to_pfn(page))
1748c2ecf20Sopenharmony_ci
1758c2ecf20Sopenharmony_ci#define pfn_to_virt(pfn)	__va(pfn_to_phys(pfn))
1768c2ecf20Sopenharmony_ci#define virt_to_pfn(kaddr)	(phys_to_pfn(__pa(kaddr)))
1778c2ecf20Sopenharmony_ci#define pfn_to_kaddr(pfn)	pfn_to_virt(pfn)
1788c2ecf20Sopenharmony_ci
1798c2ecf20Sopenharmony_ci#define virt_to_page(kaddr)	pfn_to_page(virt_to_pfn(kaddr))
1808c2ecf20Sopenharmony_ci#define page_to_virt(page)	pfn_to_virt(page_to_pfn(page))
1818c2ecf20Sopenharmony_ci
1828c2ecf20Sopenharmony_ci#define virt_addr_valid(kaddr)	pfn_valid(virt_to_pfn(kaddr))
1838c2ecf20Sopenharmony_ci
1848c2ecf20Sopenharmony_ci#define VM_DATA_DEFAULT_FLAGS	VM_DATA_FLAGS_NON_EXEC
1858c2ecf20Sopenharmony_ci
1868c2ecf20Sopenharmony_ci#include <asm-generic/memory_model.h>
1878c2ecf20Sopenharmony_ci#include <asm-generic/getorder.h>
1888c2ecf20Sopenharmony_ci
1898c2ecf20Sopenharmony_ci#endif /* _S390_PAGE_H */
190