blob: 479dc76e0eca148a14d796589259d72ba6a4cdef [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 * S390 version
Heiko Carstensa53c8fa2012-07-20 11:15:04 +02004 * Copyright IBM Corp. 1999, 2000
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 * Author(s): Hartmut Penner (hp@de.ibm.com)
6 */
7
8#ifndef _S390_PAGE_H
9#define _S390_PAGE_H
10
Sam Ravnborg52480ee2007-10-12 16:11:50 +020011#include <linux/const.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070012#include <asm/types.h>
13
Heiko Carstensc67da7c2017-06-16 17:24:39 +020014#define _PAGE_SHIFT 12
15#define _PAGE_SIZE (_AC(1, UL) << _PAGE_SHIFT)
16#define _PAGE_MASK (~(_PAGE_SIZE - 1))
17
Linus Torvalds1da177e2005-04-16 15:20:36 -070018/* PAGE_SHIFT determines the page size */
Heiko Carstensc67da7c2017-06-16 17:24:39 +020019#define PAGE_SHIFT _PAGE_SHIFT
20#define PAGE_SIZE _PAGE_SIZE
21#define PAGE_MASK _PAGE_MASK
Peter Oberparleiter0b642ed2005-05-01 08:58:58 -070022#define PAGE_DEFAULT_ACC 0
23#define PAGE_DEFAULT_KEY (PAGE_DEFAULT_ACC << 4)
Linus Torvalds1da177e2005-04-16 15:20:36 -070024
Dominik Dingel41318bf2015-07-17 16:23:34 -070025#define HPAGE_SHIFT 20
Gerald Schaefer53492b12008-04-30 13:38:46 +020026#define HPAGE_SIZE (1UL << HPAGE_SHIFT)
27#define HPAGE_MASK (~(HPAGE_SIZE - 1))
28#define HUGETLB_PAGE_ORDER (HPAGE_SHIFT - PAGE_SHIFT)
Gerald Schaeferd08de8e2016-07-04 14:47:01 +020029#define HUGE_MAX_HSTATE 2
Gerald Schaefer53492b12008-04-30 13:38:46 +020030
31#define ARCH_HAS_SETCLEAR_HUGE_PTE
32#define ARCH_HAS_HUGE_PTE_TYPE
33#define ARCH_HAS_PREPARE_HUGEPAGE
34#define ARCH_HAS_HUGEPAGE_CLEAR_FLUSH
35
Gerald Schaefer5f490a52020-01-16 19:59:04 +010036#define HAVE_ARCH_HUGETLB_UNMAPPED_AREA
37
Dominik Dingel41318bf2015-07-17 16:23:34 -070038#include <asm/setup.h>
39#ifndef __ASSEMBLY__
40
Heiko Carstensde3fa842016-06-14 06:55:43 +020041void __storage_key_init_range(unsigned long start, unsigned long end);
42
Martin Schwidefsky127c1fe2013-10-07 12:12:32 +020043static inline void storage_key_init_range(unsigned long start, unsigned long end)
44{
Nathan Chancellor38032472020-02-13 23:42:07 -070045 if (PAGE_DEFAULT_KEY != 0)
Heiko Carstensde3fa842016-06-14 06:55:43 +020046 __storage_key_init_range(start, end);
Martin Schwidefsky127c1fe2013-10-07 12:12:32 +020047}
Heiko Carstens6b70a922012-11-02 12:56:43 +010048
Christian Borntraegerfb3d1c02015-01-30 10:31:13 +010049#define clear_page(page) memset((page), 0, PAGE_SIZE)
Linus Torvalds1da177e2005-04-16 15:20:36 -070050
Heiko Carstensdba6bb6002013-11-19 14:25:17 +010051/*
52 * copy_page uses the mvcl instruction with 0xb0 padding byte in order to
53 * bypass caches when copying a page. Especially when copying huge pages
54 * this keeps L1 and L2 data caches alive.
55 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070056static inline void copy_page(void *to, void *from)
57{
Heiko Carstensdba6bb6002013-11-19 14:25:17 +010058 register void *reg2 asm ("2") = to;
59 register unsigned long reg3 asm ("3") = 0x1000;
60 register void *reg4 asm ("4") = from;
61 register unsigned long reg5 asm ("5") = 0xb0001000;
62 asm volatile(
63 " mvcl 2,4"
64 : "+d" (reg2), "+d" (reg3), "+d" (reg4), "+d" (reg5)
65 : : "memory", "cc");
Linus Torvalds1da177e2005-04-16 15:20:36 -070066}
67
Linus Torvalds1da177e2005-04-16 15:20:36 -070068#define clear_user_page(page, vaddr, pg) clear_page(page)
69#define copy_user_page(to, from, vaddr, pg) copy_page(to, from)
70
Peter Collingbourne79cb2552021-05-27 16:52:00 -070071#define alloc_zeroed_user_highpage_movable(vma, vaddr) \
72 alloc_page_vma(GFP_HIGHUSER_MOVABLE | __GFP_ZERO, vma, vaddr)
73#define __HAVE_ARCH_ALLOC_ZEROED_USER_HIGHPAGE_MOVABLE
Linus Torvalds1da177e2005-04-16 15:20:36 -070074
Linus Torvalds1da177e2005-04-16 15:20:36 -070075/*
76 * These are used to make use of C type-checking..
77 */
78
79typedef struct { unsigned long pgprot; } pgprot_t;
Martin Schwidefskyb2fa47e2011-05-23 10:24:40 +020080typedef struct { unsigned long pgste; } pgste_t;
Linus Torvalds1da177e2005-04-16 15:20:36 -070081typedef struct { unsigned long pte; } pte_t;
Linus Torvalds1da177e2005-04-16 15:20:36 -070082typedef struct { unsigned long pmd; } pmd_t;
Martin Schwidefsky190a1d72007-10-22 12:52:48 +020083typedef struct { unsigned long pud; } pud_t;
Martin Schwidefsky1aea9b32017-04-24 18:19:10 +020084typedef struct { unsigned long p4d; } p4d_t;
Linus Torvalds1da177e2005-04-16 15:20:36 -070085typedef struct { unsigned long pgd; } pgd_t;
Martin Schwidefsky146e4b32008-02-09 18:24:35 +010086typedef pte_t *pgtable_t;
Linus Torvalds1da177e2005-04-16 15:20:36 -070087
Martin Schwidefsky146e4b32008-02-09 18:24:35 +010088#define pgprot_val(x) ((x).pgprot)
Martin Schwidefskyb2fa47e2011-05-23 10:24:40 +020089#define pgste_val(x) ((x).pgste)
Martin Schwidefsky146e4b32008-02-09 18:24:35 +010090#define pte_val(x) ((x).pte)
91#define pmd_val(x) ((x).pmd)
Martin Schwidefsky190a1d72007-10-22 12:52:48 +020092#define pud_val(x) ((x).pud)
Martin Schwidefsky1aea9b32017-04-24 18:19:10 +020093#define p4d_val(x) ((x).p4d)
Linus Torvalds1da177e2005-04-16 15:20:36 -070094#define pgd_val(x) ((x).pgd)
95
Martin Schwidefskyb2fa47e2011-05-23 10:24:40 +020096#define __pgste(x) ((pgste_t) { (x) } )
Linus Torvalds1da177e2005-04-16 15:20:36 -070097#define __pte(x) ((pte_t) { (x) } )
98#define __pmd(x) ((pmd_t) { (x) } )
Martin Schwidefskyb2fa47e2011-05-23 10:24:40 +020099#define __pud(x) ((pud_t) { (x) } )
Martin Schwidefsky1aea9b32017-04-24 18:19:10 +0200100#define __p4d(x) ((p4d_t) { (x) } )
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101#define __pgd(x) ((pgd_t) { (x) } )
102#define __pgprot(x) ((pgprot_t) { (x) } )
103
Martin Schwidefsky2d425522011-05-23 10:24:39 +0200104static inline void page_set_storage_key(unsigned long addr,
105 unsigned char skey, int mapped)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106{
Martin Schwidefskye2b8d7a2010-10-25 16:10:14 +0200107 if (!mapped)
108 asm volatile(".insn rrf,0xb22b0000,%0,%1,8,0"
109 : : "d" (skey), "a" (addr));
110 else
111 asm volatile("sske %0,%1" : : "d" (skey), "a" (addr));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112}
113
Martin Schwidefsky2d425522011-05-23 10:24:39 +0200114static inline unsigned char page_get_storage_key(unsigned long addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115{
Martin Schwidefsky2d425522011-05-23 10:24:39 +0200116 unsigned char skey;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117
Martin Schwidefsky2d425522011-05-23 10:24:39 +0200118 asm volatile("iske %0,%1" : "=d" (skey) : "a" (addr));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119 return skey;
120}
121
Martin Schwidefsky2d425522011-05-23 10:24:39 +0200122static inline int page_reset_referenced(unsigned long addr)
123{
David Hildenbranda7e19ab2016-05-10 09:50:21 +0200124 int cc;
Martin Schwidefsky2d425522011-05-23 10:24:39 +0200125
126 asm volatile(
127 " rrbe 0,%1\n"
128 " ipm %0\n"
David Hildenbranda7e19ab2016-05-10 09:50:21 +0200129 " srl %0,28\n"
130 : "=d" (cc) : "a" (addr) : "cc");
131 return cc;
Martin Schwidefsky2d425522011-05-23 10:24:39 +0200132}
133
134/* Bits int the storage key */
135#define _PAGE_CHANGED 0x02 /* HW changed bit */
136#define _PAGE_REFERENCED 0x04 /* HW referenced bit */
137#define _PAGE_FP_BIT 0x08 /* HW fetch protection bit */
138#define _PAGE_ACC_BITS 0xf0 /* HW access control bits */
139
Martin Schwidefsky45e576b2008-05-07 09:22:59 +0200140struct page;
141void arch_free_page(struct page *page, int order);
142void arch_alloc_page(struct page *page, int order);
Martin Schwidefskyc9b5ad52016-06-14 12:56:01 +0200143void arch_set_page_dat(struct page *page, int order);
144void arch_set_page_nodat(struct page *page, int order);
145int arch_test_page_nodat(struct page *page);
Martin Schwidefsky638ad342011-10-30 15:17:13 +0100146void arch_set_page_states(int make_stable);
Martin Schwidefsky45e576b2008-05-07 09:22:59 +0200147
Hendrik Bruecknerec6743b2010-11-10 10:05:55 +0100148static inline int devmem_is_allowed(unsigned long pfn)
149{
150 return 0;
151}
152
Martin Schwidefsky45e576b2008-05-07 09:22:59 +0200153#define HAVE_ARCH_FREE_PAGE
154#define HAVE_ARCH_ALLOC_PAGE
155
Claudio Imbrenda214d9bb2020-01-21 09:48:44 +0100156#if IS_ENABLED(CONFIG_PGSTE)
157int arch_make_page_accessible(struct page *page);
158#define HAVE_ARCH_MAKE_PAGE_ACCESSIBLE
159#endif
160
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161#endif /* !__ASSEMBLY__ */
162
Heiko Carstens16f48642017-08-07 15:16:15 +0200163#define __PAGE_OFFSET 0x0UL
164#define PAGE_OFFSET 0x0UL
165
166#define __pa(x) ((unsigned long)(x))
167#define __va(x) ((void *)(unsigned long)(x))
168
Alexander Gordeev014b02042020-02-25 12:44:06 +0100169#define phys_to_pfn(phys) ((phys) >> PAGE_SHIFT)
170#define pfn_to_phys(pfn) ((pfn) << PAGE_SHIFT)
171
172#define phys_to_page(phys) pfn_to_page(phys_to_pfn(phys))
173#define page_to_phys(page) pfn_to_phys(page_to_pfn(page))
174
175#define pfn_to_virt(pfn) __va(pfn_to_phys(pfn))
176#define virt_to_pfn(kaddr) (phys_to_pfn(__pa(kaddr)))
Vasily Gorbik75f19542017-11-17 11:21:49 +0100177#define pfn_to_kaddr(pfn) pfn_to_virt(pfn)
Heiko Carstens16f48642017-08-07 15:16:15 +0200178
179#define virt_to_page(kaddr) pfn_to_page(virt_to_pfn(kaddr))
David Hildenbrand3d846832015-11-16 10:45:03 +0100180#define page_to_virt(page) pfn_to_virt(page_to_pfn(page))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181
Alexander Gordeev014b02042020-02-25 12:44:06 +0100182#define virt_addr_valid(kaddr) pfn_valid(virt_to_pfn(kaddr))
Heiko Carstens16f48642017-08-07 15:16:15 +0200183
Anshuman Khandualc62da0c2020-04-10 14:33:05 -0700184#define VM_DATA_DEFAULT_FLAGS VM_DATA_FLAGS_NON_EXEC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185
KAMEZAWA Hiroyukiaed63042006-03-27 01:15:45 -0800186#include <asm-generic/memory_model.h>
Arnd Bergmann5b17e1c2009-05-13 22:56:30 +0000187#include <asm-generic/getorder.h>
Stephen Rothwellfd4fd5a2005-09-03 15:54:30 -0700188
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189#endif /* _S390_PAGE_H */