^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * S390 version
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Copyright IBM Corp. 1999, 2000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Author(s): Hartmut Penner (hp@de.ibm.com)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #ifndef _S390_PAGE_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #define _S390_PAGE_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/const.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <asm/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #define _PAGE_SHIFT 12
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #define _PAGE_SIZE (_AC(1, UL) << _PAGE_SHIFT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #define _PAGE_MASK (~(_PAGE_SIZE - 1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) /* PAGE_SHIFT determines the page size */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #define PAGE_SHIFT _PAGE_SHIFT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #define PAGE_SIZE _PAGE_SIZE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #define PAGE_MASK _PAGE_MASK
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #define PAGE_DEFAULT_ACC 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #define PAGE_DEFAULT_KEY (PAGE_DEFAULT_ACC << 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #define HPAGE_SHIFT 20
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #define HPAGE_SIZE (1UL << HPAGE_SHIFT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #define HPAGE_MASK (~(HPAGE_SIZE - 1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #define HUGETLB_PAGE_ORDER (HPAGE_SHIFT - PAGE_SHIFT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #define HUGE_MAX_HSTATE 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #define ARCH_HAS_SETCLEAR_HUGE_PTE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #define ARCH_HAS_HUGE_PTE_TYPE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #define ARCH_HAS_PREPARE_HUGEPAGE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #define ARCH_HAS_HUGEPAGE_CLEAR_FLUSH
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #define HAVE_ARCH_HUGETLB_UNMAPPED_AREA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #include <asm/setup.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #ifndef __ASSEMBLY__
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) void __storage_key_init_range(unsigned long start, unsigned long end);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) static inline void storage_key_init_range(unsigned long start, unsigned long end)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) if (PAGE_DEFAULT_KEY != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) __storage_key_init_range(start, end);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) #define clear_page(page) memset((page), 0, PAGE_SIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) * copy_page uses the mvcl instruction with 0xb0 padding byte in order to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) * bypass caches when copying a page. Especially when copying huge pages
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) * this keeps L1 and L2 data caches alive.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) static inline void copy_page(void *to, void *from)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) register void *reg2 asm ("2") = to;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) register unsigned long reg3 asm ("3") = 0x1000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) register void *reg4 asm ("4") = from;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) register unsigned long reg5 asm ("5") = 0xb0001000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) asm volatile(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) " mvcl 2,4"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) : "+d" (reg2), "+d" (reg3), "+d" (reg4), "+d" (reg5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) : : "memory", "cc");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) #define clear_user_page(page, vaddr, pg) clear_page(page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) #define copy_user_page(to, from, vaddr, pg) copy_page(to, from)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) #define alloc_zeroed_user_highpage_movable(vma, vaddr) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) alloc_page_vma(GFP_HIGHUSER_MOVABLE | __GFP_ZERO, vma, vaddr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) #define __HAVE_ARCH_ALLOC_ZEROED_USER_HIGHPAGE_MOVABLE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) * These are used to make use of C type-checking..
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) typedef struct { unsigned long pgprot; } pgprot_t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) typedef struct { unsigned long pgste; } pgste_t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) typedef struct { unsigned long pte; } pte_t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) typedef struct { unsigned long pmd; } pmd_t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) typedef struct { unsigned long pud; } pud_t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) typedef struct { unsigned long p4d; } p4d_t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) typedef struct { unsigned long pgd; } pgd_t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) typedef pte_t *pgtable_t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) #define pgprot_val(x) ((x).pgprot)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) #define pgste_val(x) ((x).pgste)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) #define pte_val(x) ((x).pte)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) #define pmd_val(x) ((x).pmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) #define pud_val(x) ((x).pud)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) #define p4d_val(x) ((x).p4d)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) #define pgd_val(x) ((x).pgd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) #define __pgste(x) ((pgste_t) { (x) } )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) #define __pte(x) ((pte_t) { (x) } )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) #define __pmd(x) ((pmd_t) { (x) } )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) #define __pud(x) ((pud_t) { (x) } )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) #define __p4d(x) ((p4d_t) { (x) } )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) #define __pgd(x) ((pgd_t) { (x) } )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) #define __pgprot(x) ((pgprot_t) { (x) } )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) static inline void page_set_storage_key(unsigned long addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) unsigned char skey, int mapped)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) if (!mapped)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) asm volatile(".insn rrf,0xb22b0000,%0,%1,8,0"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) : : "d" (skey), "a" (addr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) asm volatile("sske %0,%1" : : "d" (skey), "a" (addr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) static inline unsigned char page_get_storage_key(unsigned long addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) unsigned char skey;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) asm volatile("iske %0,%1" : "=d" (skey) : "a" (addr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) return skey;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) static inline int page_reset_referenced(unsigned long addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) int cc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) asm volatile(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) " rrbe 0,%1\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) " ipm %0\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) " srl %0,28\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) : "=d" (cc) : "a" (addr) : "cc");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) return cc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) /* Bits int the storage key */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) #define _PAGE_CHANGED 0x02 /* HW changed bit */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) #define _PAGE_REFERENCED 0x04 /* HW referenced bit */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) #define _PAGE_FP_BIT 0x08 /* HW fetch protection bit */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) #define _PAGE_ACC_BITS 0xf0 /* HW access control bits */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) struct page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) void arch_free_page(struct page *page, int order);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) void arch_alloc_page(struct page *page, int order);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) void arch_set_page_dat(struct page *page, int order);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) void arch_set_page_nodat(struct page *page, int order);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) int arch_test_page_nodat(struct page *page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) void arch_set_page_states(int make_stable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) static inline int devmem_is_allowed(unsigned long pfn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) #define HAVE_ARCH_FREE_PAGE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) #define HAVE_ARCH_ALLOC_PAGE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) #if IS_ENABLED(CONFIG_PGSTE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) int arch_make_page_accessible(struct page *page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) #define HAVE_ARCH_MAKE_PAGE_ACCESSIBLE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) #endif /* !__ASSEMBLY__ */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) #define __PAGE_OFFSET 0x0UL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) #define PAGE_OFFSET 0x0UL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) #define __pa(x) ((unsigned long)(x))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) #define __va(x) ((void *)(unsigned long)(x))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) #define phys_to_pfn(phys) ((phys) >> PAGE_SHIFT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) #define pfn_to_phys(pfn) ((pfn) << PAGE_SHIFT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) #define phys_to_page(phys) pfn_to_page(phys_to_pfn(phys))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) #define page_to_phys(page) pfn_to_phys(page_to_pfn(page))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) #define pfn_to_virt(pfn) __va(pfn_to_phys(pfn))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) #define virt_to_pfn(kaddr) (phys_to_pfn(__pa(kaddr)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) #define pfn_to_kaddr(pfn) pfn_to_virt(pfn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) #define virt_to_page(kaddr) pfn_to_page(virt_to_pfn(kaddr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) #define page_to_virt(page) pfn_to_virt(page_to_pfn(page))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) #define virt_addr_valid(kaddr) pfn_valid(virt_to_pfn(kaddr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) #define VM_DATA_DEFAULT_FLAGS VM_DATA_FLAGS_NON_EXEC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) #include <asm-generic/memory_model.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) #include <asm-generic/getorder.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) #endif /* _S390_PAGE_H */