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 23e613d834SJanis Schoetterl-Glausch /* storage-protection override */ 24e613d834SJanis Schoetterl-Glausch #define PAGE_SPO_ACC 9 25c6557e7fSMartin Schwidefsky #define PAGE_DEFAULT_KEY (PAGE_DEFAULT_ACC << 4) 26c6557e7fSMartin Schwidefsky 2741318bfeSDominik Dingel #define HPAGE_SHIFT 20 28c6557e7fSMartin Schwidefsky #define HPAGE_SIZE (1UL << HPAGE_SHIFT) 29c6557e7fSMartin Schwidefsky #define HPAGE_MASK (~(HPAGE_SIZE - 1)) 30c6557e7fSMartin Schwidefsky #define HUGETLB_PAGE_ORDER (HPAGE_SHIFT - PAGE_SHIFT) 31d08de8e2SGerald Schaefer #define HUGE_MAX_HSTATE 2 32c6557e7fSMartin Schwidefsky 33c6557e7fSMartin Schwidefsky #define ARCH_HAS_SETCLEAR_HUGE_PTE 34c6557e7fSMartin Schwidefsky #define ARCH_HAS_HUGE_PTE_TYPE 35c6557e7fSMartin Schwidefsky #define ARCH_HAS_PREPARE_HUGEPAGE 36c6557e7fSMartin Schwidefsky #define ARCH_HAS_HUGEPAGE_CLEAR_FLUSH 37c6557e7fSMartin Schwidefsky 385f490a52SGerald Schaefer #define HAVE_ARCH_HUGETLB_UNMAPPED_AREA 395f490a52SGerald Schaefer 4041318bfeSDominik Dingel #include <asm/setup.h> 4141318bfeSDominik Dingel #ifndef __ASSEMBLY__ 4241318bfeSDominik Dingel 43de3fa841SHeiko Carstens void __storage_key_init_range(unsigned long start, unsigned long end); 44de3fa841SHeiko Carstens 45127c1fefSMartin Schwidefsky static inline void storage_key_init_range(unsigned long start, unsigned long end) 46127c1fefSMartin Schwidefsky { 4738032473SNathan Chancellor if (PAGE_DEFAULT_KEY != 0) 48127c1fefSMartin Schwidefsky __storage_key_init_range(start, end); 49127c1fefSMartin Schwidefsky } 506b70a920SHeiko Carstens 51fb3d1c08SChristian Borntraeger #define clear_page(page) memset((page), 0, PAGE_SIZE) 52c6557e7fSMartin Schwidefsky 53dba6bb60SHeiko Carstens /* 54dba6bb60SHeiko Carstens * copy_page uses the mvcl instruction with 0xb0 padding byte in order to 55dba6bb60SHeiko Carstens * bypass caches when copying a page. Especially when copying huge pages 56dba6bb60SHeiko Carstens * this keeps L1 and L2 data caches alive. 57dba6bb60SHeiko Carstens */ 58c6557e7fSMartin Schwidefsky static inline void copy_page(void *to, void *from) 59c6557e7fSMartin Schwidefsky { 6075c89a2bSHeiko Carstens union register_pair dst, src; 6175c89a2bSHeiko Carstens 6275c89a2bSHeiko Carstens dst.even = (unsigned long) to; 6375c89a2bSHeiko Carstens dst.odd = 0x1000; 6475c89a2bSHeiko Carstens src.even = (unsigned long) from; 6575c89a2bSHeiko Carstens src.odd = 0xb0001000; 6675c89a2bSHeiko Carstens 67c6557e7fSMartin Schwidefsky asm volatile( 6875c89a2bSHeiko Carstens " mvcl %[dst],%[src]" 6975c89a2bSHeiko Carstens : [dst] "+&d" (dst.pair), [src] "+&d" (src.pair) 70dba6bb60SHeiko Carstens : : "memory", "cc"); 71c6557e7fSMartin Schwidefsky } 72c6557e7fSMartin Schwidefsky 73c6557e7fSMartin Schwidefsky #define clear_user_page(page, vaddr, pg) clear_page(page) 74c6557e7fSMartin Schwidefsky #define copy_user_page(to, from, vaddr, pg) copy_page(to, from) 75c6557e7fSMartin Schwidefsky 76*6bc56a4dSMatthew Wilcox (Oracle) #define vma_alloc_zeroed_movable_folio(vma, vaddr) \ 77*6bc56a4dSMatthew Wilcox (Oracle) vma_alloc_folio(GFP_HIGHUSER_MOVABLE | __GFP_ZERO, 0, vma, vaddr, false) 78c6557e7fSMartin Schwidefsky 79c6557e7fSMartin Schwidefsky /* 80c6557e7fSMartin Schwidefsky * These are used to make use of C type-checking.. 81c6557e7fSMartin Schwidefsky */ 82c6557e7fSMartin Schwidefsky 83c6557e7fSMartin Schwidefsky typedef struct { unsigned long pgprot; } pgprot_t; 84b2fa47e6SMartin Schwidefsky typedef struct { unsigned long pgste; } pgste_t; 85c6557e7fSMartin Schwidefsky typedef struct { unsigned long pte; } pte_t; 86c6557e7fSMartin Schwidefsky typedef struct { unsigned long pmd; } pmd_t; 87c6557e7fSMartin Schwidefsky typedef struct { unsigned long pud; } pud_t; 881aea9b3fSMartin Schwidefsky typedef struct { unsigned long p4d; } p4d_t; 89c6557e7fSMartin Schwidefsky typedef struct { unsigned long pgd; } pgd_t; 90c6557e7fSMartin Schwidefsky typedef pte_t *pgtable_t; 91c6557e7fSMartin Schwidefsky 92c6557e7fSMartin Schwidefsky #define pgprot_val(x) ((x).pgprot) 93b2fa47e6SMartin Schwidefsky #define pgste_val(x) ((x).pgste) 94966ffbd8SHeiko Carstens 95966ffbd8SHeiko Carstens static inline unsigned long pte_val(pte_t pte) 96966ffbd8SHeiko Carstens { 97966ffbd8SHeiko Carstens return pte.pte; 98966ffbd8SHeiko Carstens } 99966ffbd8SHeiko Carstens 100966ffbd8SHeiko Carstens static inline unsigned long pmd_val(pmd_t pmd) 101966ffbd8SHeiko Carstens { 102966ffbd8SHeiko Carstens return pmd.pmd; 103966ffbd8SHeiko Carstens } 104966ffbd8SHeiko Carstens 105966ffbd8SHeiko Carstens static inline unsigned long pud_val(pud_t pud) 106966ffbd8SHeiko Carstens { 107966ffbd8SHeiko Carstens return pud.pud; 108966ffbd8SHeiko Carstens } 109966ffbd8SHeiko Carstens 110966ffbd8SHeiko Carstens static inline unsigned long p4d_val(p4d_t p4d) 111966ffbd8SHeiko Carstens { 112966ffbd8SHeiko Carstens return p4d.p4d; 113966ffbd8SHeiko Carstens } 114966ffbd8SHeiko Carstens 115966ffbd8SHeiko Carstens static inline unsigned long pgd_val(pgd_t pgd) 116966ffbd8SHeiko Carstens { 117966ffbd8SHeiko Carstens return pgd.pgd; 118966ffbd8SHeiko Carstens } 119c6557e7fSMartin Schwidefsky 120b2fa47e6SMartin Schwidefsky #define __pgste(x) ((pgste_t) { (x) } ) 121c6557e7fSMartin Schwidefsky #define __pte(x) ((pte_t) { (x) } ) 122c6557e7fSMartin Schwidefsky #define __pmd(x) ((pmd_t) { (x) } ) 123b2fa47e6SMartin Schwidefsky #define __pud(x) ((pud_t) { (x) } ) 1241aea9b3fSMartin Schwidefsky #define __p4d(x) ((p4d_t) { (x) } ) 125c6557e7fSMartin Schwidefsky #define __pgd(x) ((pgd_t) { (x) } ) 126c6557e7fSMartin Schwidefsky #define __pgprot(x) ((pgprot_t) { (x) } ) 127c6557e7fSMartin Schwidefsky 1282d42552dSMartin Schwidefsky static inline void page_set_storage_key(unsigned long addr, 1292d42552dSMartin Schwidefsky unsigned char skey, int mapped) 130c6557e7fSMartin Schwidefsky { 131e2b8d7afSMartin Schwidefsky if (!mapped) 132e2b8d7afSMartin Schwidefsky asm volatile(".insn rrf,0xb22b0000,%0,%1,8,0" 133e2b8d7afSMartin Schwidefsky : : "d" (skey), "a" (addr)); 134e2b8d7afSMartin Schwidefsky else 135c6557e7fSMartin Schwidefsky asm volatile("sske %0,%1" : : "d" (skey), "a" (addr)); 136c6557e7fSMartin Schwidefsky } 137c6557e7fSMartin Schwidefsky 1382d42552dSMartin Schwidefsky static inline unsigned char page_get_storage_key(unsigned long addr) 139c6557e7fSMartin Schwidefsky { 1402d42552dSMartin Schwidefsky unsigned char skey; 141c6557e7fSMartin Schwidefsky 1422d42552dSMartin Schwidefsky asm volatile("iske %0,%1" : "=d" (skey) : "a" (addr)); 143c6557e7fSMartin Schwidefsky return skey; 144c6557e7fSMartin Schwidefsky } 145c6557e7fSMartin Schwidefsky 1462d42552dSMartin Schwidefsky static inline int page_reset_referenced(unsigned long addr) 1472d42552dSMartin Schwidefsky { 148a7e19ab5SDavid Hildenbrand int cc; 1492d42552dSMartin Schwidefsky 1502d42552dSMartin Schwidefsky asm volatile( 1512d42552dSMartin Schwidefsky " rrbe 0,%1\n" 1522d42552dSMartin Schwidefsky " ipm %0\n" 153a7e19ab5SDavid Hildenbrand " srl %0,28\n" 154a7e19ab5SDavid Hildenbrand : "=d" (cc) : "a" (addr) : "cc"); 155a7e19ab5SDavid Hildenbrand return cc; 1562d42552dSMartin Schwidefsky } 1572d42552dSMartin Schwidefsky 1582d42552dSMartin Schwidefsky /* Bits int the storage key */ 1592d42552dSMartin Schwidefsky #define _PAGE_CHANGED 0x02 /* HW changed bit */ 1602d42552dSMartin Schwidefsky #define _PAGE_REFERENCED 0x04 /* HW referenced bit */ 1612d42552dSMartin Schwidefsky #define _PAGE_FP_BIT 0x08 /* HW fetch protection bit */ 1622d42552dSMartin Schwidefsky #define _PAGE_ACC_BITS 0xf0 /* HW access control bits */ 1632d42552dSMartin Schwidefsky 164c6557e7fSMartin Schwidefsky struct page; 165c6557e7fSMartin Schwidefsky void arch_free_page(struct page *page, int order); 166c6557e7fSMartin Schwidefsky void arch_alloc_page(struct page *page, int order); 167c9b5ad54SMartin Schwidefsky void arch_set_page_dat(struct page *page, int order); 168c6557e7fSMartin Schwidefsky 169ec6743bbSHendrik Brueckner static inline int devmem_is_allowed(unsigned long pfn) 170ec6743bbSHendrik Brueckner { 171ec6743bbSHendrik Brueckner return 0; 172ec6743bbSHendrik Brueckner } 173ec6743bbSHendrik Brueckner 174c6557e7fSMartin Schwidefsky #define HAVE_ARCH_FREE_PAGE 175c6557e7fSMartin Schwidefsky #define HAVE_ARCH_ALLOC_PAGE 176c6557e7fSMartin Schwidefsky 177214d9bbcSClaudio Imbrenda #if IS_ENABLED(CONFIG_PGSTE) 178214d9bbcSClaudio Imbrenda int arch_make_page_accessible(struct page *page); 179214d9bbcSClaudio Imbrenda #define HAVE_ARCH_MAKE_PAGE_ACCESSIBLE 180214d9bbcSClaudio Imbrenda #endif 181214d9bbcSClaudio Imbrenda 182c6557e7fSMartin Schwidefsky #endif /* !__ASSEMBLY__ */ 183c6557e7fSMartin Schwidefsky 184c6557e7fSMartin Schwidefsky #define __PAGE_OFFSET 0x0UL 185c6557e7fSMartin Schwidefsky #define PAGE_OFFSET 0x0UL 18616f48641SHeiko Carstens 18716f48641SHeiko Carstens #define __pa(x) ((unsigned long)(x)) 18816f48641SHeiko Carstens #define __va(x) ((void *)(unsigned long)(x)) 18916f48641SHeiko Carstens 190014b0204SAlexander Gordeev #define phys_to_pfn(phys) ((phys) >> PAGE_SHIFT) 191014b0204SAlexander Gordeev #define pfn_to_phys(pfn) ((pfn) << PAGE_SHIFT) 192014b0204SAlexander Gordeev 193014b0204SAlexander Gordeev #define phys_to_page(phys) pfn_to_page(phys_to_pfn(phys)) 194014b0204SAlexander Gordeev #define page_to_phys(page) pfn_to_phys(page_to_pfn(page)) 195014b0204SAlexander Gordeev 196014b0204SAlexander Gordeev #define pfn_to_virt(pfn) __va(pfn_to_phys(pfn)) 197014b0204SAlexander Gordeev #define virt_to_pfn(kaddr) (phys_to_pfn(__pa(kaddr))) 19875f19542SVasily Gorbik #define pfn_to_kaddr(pfn) pfn_to_virt(pfn) 19916f48641SHeiko Carstens 20016f48641SHeiko Carstens #define virt_to_page(kaddr) pfn_to_page(virt_to_pfn(kaddr)) 2013d84683bSDavid Hildenbrand #define page_to_virt(page) pfn_to_virt(page_to_pfn(page)) 202c6557e7fSMartin Schwidefsky 203014b0204SAlexander Gordeev #define virt_addr_valid(kaddr) pfn_valid(virt_to_pfn(kaddr)) 20416f48641SHeiko Carstens 205c62da0c3SAnshuman Khandual #define VM_DATA_DEFAULT_FLAGS VM_DATA_FLAGS_NON_EXEC 206c6557e7fSMartin Schwidefsky 207c6557e7fSMartin Schwidefsky #include <asm-generic/memory_model.h> 2085b17e1cdSArnd Bergmann #include <asm-generic/getorder.h> 209c6557e7fSMartin Schwidefsky 210c6557e7fSMartin Schwidefsky #endif /* _S390_PAGE_H */ 211