blob: 53eacbd4f09bf4c32ac051f1be7f9d3e5445e0df [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 * S390 version
Heiko Carstensa53c8fa2012-07-20 11:15:04 +02003 * Copyright IBM Corp. 1999, 2000
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 * Author(s): Hartmut Penner (hp@de.ibm.com)
5 */
6
7#ifndef _S390_PAGE_H
8#define _S390_PAGE_H
9
Sam Ravnborg52480ee2007-10-12 16:11:50 +020010#include <linux/const.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070011#include <asm/types.h>
12
13/* PAGE_SHIFT determines the page size */
14#define PAGE_SHIFT 12
Sam Ravnborg52480ee2007-10-12 16:11:50 +020015#define PAGE_SIZE (_AC(1,UL) << PAGE_SHIFT)
Linus Torvalds1da177e2005-04-16 15:20:36 -070016#define PAGE_MASK (~(PAGE_SIZE-1))
Peter Oberparleiter0b642ed2005-05-01 08:58:58 -070017#define PAGE_DEFAULT_ACC 0
18#define PAGE_DEFAULT_KEY (PAGE_DEFAULT_ACC << 4)
Linus Torvalds1da177e2005-04-16 15:20:36 -070019
Dominik Dingel41318bf2015-07-17 16:23:34 -070020#define HPAGE_SHIFT 20
Gerald Schaefer53492b12008-04-30 13:38:46 +020021#define HPAGE_SIZE (1UL << HPAGE_SHIFT)
22#define HPAGE_MASK (~(HPAGE_SIZE - 1))
23#define HUGETLB_PAGE_ORDER (HPAGE_SHIFT - PAGE_SHIFT)
24
25#define ARCH_HAS_SETCLEAR_HUGE_PTE
26#define ARCH_HAS_HUGE_PTE_TYPE
27#define ARCH_HAS_PREPARE_HUGEPAGE
28#define ARCH_HAS_HUGEPAGE_CLEAR_FLUSH
29
Dominik Dingel41318bf2015-07-17 16:23:34 -070030#include <asm/setup.h>
31#ifndef __ASSEMBLY__
32
Martin Schwidefsky127c1fe2013-10-07 12:12:32 +020033static inline void storage_key_init_range(unsigned long start, unsigned long end)
34{
35#if PAGE_DEFAULT_KEY
36 __storage_key_init_range(start, end);
37#endif
38}
Heiko Carstens6b70a922012-11-02 12:56:43 +010039
Christian Borntraegerfb3d1c02015-01-30 10:31:13 +010040#define clear_page(page) memset((page), 0, PAGE_SIZE)
Linus Torvalds1da177e2005-04-16 15:20:36 -070041
Heiko Carstensdba6bb6002013-11-19 14:25:17 +010042/*
43 * copy_page uses the mvcl instruction with 0xb0 padding byte in order to
44 * bypass caches when copying a page. Especially when copying huge pages
45 * this keeps L1 and L2 data caches alive.
46 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070047static inline void copy_page(void *to, void *from)
48{
Heiko Carstensdba6bb6002013-11-19 14:25:17 +010049 register void *reg2 asm ("2") = to;
50 register unsigned long reg3 asm ("3") = 0x1000;
51 register void *reg4 asm ("4") = from;
52 register unsigned long reg5 asm ("5") = 0xb0001000;
53 asm volatile(
54 " mvcl 2,4"
55 : "+d" (reg2), "+d" (reg3), "+d" (reg4), "+d" (reg5)
56 : : "memory", "cc");
Linus Torvalds1da177e2005-04-16 15:20:36 -070057}
58
Linus Torvalds1da177e2005-04-16 15:20:36 -070059#define clear_user_page(page, vaddr, pg) clear_page(page)
60#define copy_user_page(to, from, vaddr, pg) copy_page(to, from)
61
Mel Gorman769848c2007-07-17 04:03:05 -070062#define __alloc_zeroed_user_highpage(movableflags, vma, vaddr) \
63 alloc_page_vma(GFP_HIGHUSER | __GFP_ZERO | movableflags, vma, vaddr)
Linus Torvalds1da177e2005-04-16 15:20:36 -070064#define __HAVE_ARCH_ALLOC_ZEROED_USER_HIGHPAGE
65
Linus Torvalds1da177e2005-04-16 15:20:36 -070066/*
67 * These are used to make use of C type-checking..
68 */
69
70typedef struct { unsigned long pgprot; } pgprot_t;
Martin Schwidefskyb2fa47e2011-05-23 10:24:40 +020071typedef struct { unsigned long pgste; } pgste_t;
Linus Torvalds1da177e2005-04-16 15:20:36 -070072typedef struct { unsigned long pte; } pte_t;
Linus Torvalds1da177e2005-04-16 15:20:36 -070073typedef struct { unsigned long pmd; } pmd_t;
Martin Schwidefsky190a1d72007-10-22 12:52:48 +020074typedef struct { unsigned long pud; } pud_t;
Linus Torvalds1da177e2005-04-16 15:20:36 -070075typedef struct { unsigned long pgd; } pgd_t;
Martin Schwidefsky146e4b32008-02-09 18:24:35 +010076typedef pte_t *pgtable_t;
Linus Torvalds1da177e2005-04-16 15:20:36 -070077
Martin Schwidefsky146e4b32008-02-09 18:24:35 +010078#define pgprot_val(x) ((x).pgprot)
Martin Schwidefskyb2fa47e2011-05-23 10:24:40 +020079#define pgste_val(x) ((x).pgste)
Martin Schwidefsky146e4b32008-02-09 18:24:35 +010080#define pte_val(x) ((x).pte)
81#define pmd_val(x) ((x).pmd)
Martin Schwidefsky190a1d72007-10-22 12:52:48 +020082#define pud_val(x) ((x).pud)
Linus Torvalds1da177e2005-04-16 15:20:36 -070083#define pgd_val(x) ((x).pgd)
84
Martin Schwidefskyb2fa47e2011-05-23 10:24:40 +020085#define __pgste(x) ((pgste_t) { (x) } )
Linus Torvalds1da177e2005-04-16 15:20:36 -070086#define __pte(x) ((pte_t) { (x) } )
87#define __pmd(x) ((pmd_t) { (x) } )
Martin Schwidefskyb2fa47e2011-05-23 10:24:40 +020088#define __pud(x) ((pud_t) { (x) } )
Linus Torvalds1da177e2005-04-16 15:20:36 -070089#define __pgd(x) ((pgd_t) { (x) } )
90#define __pgprot(x) ((pgprot_t) { (x) } )
91
Martin Schwidefsky2d425522011-05-23 10:24:39 +020092static inline void page_set_storage_key(unsigned long addr,
93 unsigned char skey, int mapped)
Linus Torvalds1da177e2005-04-16 15:20:36 -070094{
Martin Schwidefskye2b8d7a2010-10-25 16:10:14 +020095 if (!mapped)
96 asm volatile(".insn rrf,0xb22b0000,%0,%1,8,0"
97 : : "d" (skey), "a" (addr));
98 else
99 asm volatile("sske %0,%1" : : "d" (skey), "a" (addr));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100}
101
Martin Schwidefsky2d425522011-05-23 10:24:39 +0200102static inline unsigned char page_get_storage_key(unsigned long addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103{
Martin Schwidefsky2d425522011-05-23 10:24:39 +0200104 unsigned char skey;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105
Martin Schwidefsky2d425522011-05-23 10:24:39 +0200106 asm volatile("iske %0,%1" : "=d" (skey) : "a" (addr));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107 return skey;
108}
109
Martin Schwidefsky2d425522011-05-23 10:24:39 +0200110static inline int page_reset_referenced(unsigned long addr)
111{
112 unsigned int ipm;
113
114 asm volatile(
115 " rrbe 0,%1\n"
116 " ipm %0\n"
117 : "=d" (ipm) : "a" (addr) : "cc");
118 return !!(ipm & 0x20000000);
119}
120
121/* Bits int the storage key */
122#define _PAGE_CHANGED 0x02 /* HW changed bit */
123#define _PAGE_REFERENCED 0x04 /* HW referenced bit */
124#define _PAGE_FP_BIT 0x08 /* HW fetch protection bit */
125#define _PAGE_ACC_BITS 0xf0 /* HW access control bits */
126
Martin Schwidefsky45e576b2008-05-07 09:22:59 +0200127struct page;
128void arch_free_page(struct page *page, int order);
129void arch_alloc_page(struct page *page, int order);
Martin Schwidefsky638ad342011-10-30 15:17:13 +0100130void arch_set_page_states(int make_stable);
Martin Schwidefsky45e576b2008-05-07 09:22:59 +0200131
Hendrik Bruecknerec6743b2010-11-10 10:05:55 +0100132static inline int devmem_is_allowed(unsigned long pfn)
133{
134 return 0;
135}
136
Martin Schwidefsky45e576b2008-05-07 09:22:59 +0200137#define HAVE_ARCH_FREE_PAGE
138#define HAVE_ARCH_ALLOC_PAGE
139
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140#endif /* !__ASSEMBLY__ */
141
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142#define __PAGE_OFFSET 0x0UL
143#define PAGE_OFFSET 0x0UL
144#define __pa(x) (unsigned long)(x)
145#define __va(x) (void *)(unsigned long)(x)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146#define virt_to_page(kaddr) pfn_to_page(__pa(kaddr) >> PAGE_SHIFT)
Heiko Carstens0b2b6e1d2006-10-04 20:02:23 +0200147#define page_to_phys(page) (page_to_pfn(page) << PAGE_SHIFT)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148#define virt_addr_valid(kaddr) pfn_valid(__pa(kaddr) >> PAGE_SHIFT)
149
Martin Schwidefsky146e4b32008-02-09 18:24:35 +0100150#define VM_DATA_DEFAULT_FLAGS (VM_READ | VM_WRITE | \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
152
KAMEZAWA Hiroyukiaed63042006-03-27 01:15:45 -0800153#include <asm-generic/memory_model.h>
Arnd Bergmann5b17e1c2009-05-13 22:56:30 +0000154#include <asm-generic/getorder.h>
Stephen Rothwellfd4fd5a2005-09-03 15:54:30 -0700155
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156#endif /* _S390_PAGE_H */