Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * include/asm-s390/page.h |
| 3 | * |
| 4 | * S390 version |
| 5 | * Copyright (C) 1999,2000 IBM Deutschland Entwicklung GmbH, IBM Corporation |
| 6 | * Author(s): Hartmut Penner (hp@de.ibm.com) |
| 7 | */ |
| 8 | |
| 9 | #ifndef _S390_PAGE_H |
| 10 | #define _S390_PAGE_H |
| 11 | |
Sam Ravnborg | 52480ee | 2007-10-12 16:11:50 +0200 | [diff] [blame] | 12 | #include <linux/const.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | #include <asm/types.h> |
| 14 | |
| 15 | /* PAGE_SHIFT determines the page size */ |
| 16 | #define PAGE_SHIFT 12 |
Sam Ravnborg | 52480ee | 2007-10-12 16:11:50 +0200 | [diff] [blame] | 17 | #define PAGE_SIZE (_AC(1,UL) << PAGE_SHIFT) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | #define PAGE_MASK (~(PAGE_SIZE-1)) |
Peter Oberparleiter | 0b642ed | 2005-05-01 08:58:58 -0700 | [diff] [blame] | 19 | #define PAGE_DEFAULT_ACC 0 |
| 20 | #define PAGE_DEFAULT_KEY (PAGE_DEFAULT_ACC << 4) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | |
Gerald Schaefer | 53492b1 | 2008-04-30 13:38:46 +0200 | [diff] [blame] | 22 | #define HPAGE_SHIFT 20 |
| 23 | #define HPAGE_SIZE (1UL << HPAGE_SHIFT) |
| 24 | #define HPAGE_MASK (~(HPAGE_SIZE - 1)) |
| 25 | #define HUGETLB_PAGE_ORDER (HPAGE_SHIFT - PAGE_SHIFT) |
| 26 | |
| 27 | #define ARCH_HAS_SETCLEAR_HUGE_PTE |
| 28 | #define ARCH_HAS_HUGE_PTE_TYPE |
| 29 | #define ARCH_HAS_PREPARE_HUGEPAGE |
| 30 | #define ARCH_HAS_HUGEPAGE_CLEAR_FLUSH |
| 31 | |
David Woodhouse | 274f594 | 2006-04-27 04:47:10 +0100 | [diff] [blame] | 32 | #include <asm/setup.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | #ifndef __ASSEMBLY__ |
| 34 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | static inline void clear_page(void *page) |
| 36 | { |
Gerald Schaefer | 53492b1 | 2008-04-30 13:38:46 +0200 | [diff] [blame] | 37 | if (MACHINE_HAS_PFMF) { |
| 38 | asm volatile( |
| 39 | " .insn rre,0xb9af0000,%0,%1" |
| 40 | : : "d" (0x10000), "a" (page) : "memory", "cc"); |
| 41 | } else { |
| 42 | register unsigned long reg1 asm ("1") = 0; |
| 43 | register void *reg2 asm ("2") = page; |
| 44 | register unsigned long reg3 asm ("3") = 4096; |
| 45 | asm volatile( |
| 46 | " mvcl 2,0" |
| 47 | : "+d" (reg2), "+d" (reg3) : "d" (reg1) |
| 48 | : "memory", "cc"); |
| 49 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | static inline void copy_page(void *to, void *from) |
| 53 | { |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 54 | if (MACHINE_HAS_MVPG) { |
| 55 | register unsigned long reg0 asm ("0") = 0; |
| 56 | asm volatile( |
| 57 | " mvpg %0,%1" |
| 58 | : : "a" (to), "a" (from), "d" (reg0) |
| 59 | : "memory", "cc"); |
| 60 | } else |
| 61 | asm volatile( |
| 62 | " mvc 0(256,%0),0(%1)\n" |
| 63 | " mvc 256(256,%0),256(%1)\n" |
| 64 | " mvc 512(256,%0),512(%1)\n" |
| 65 | " mvc 768(256,%0),768(%1)\n" |
| 66 | " mvc 1024(256,%0),1024(%1)\n" |
| 67 | " mvc 1280(256,%0),1280(%1)\n" |
| 68 | " mvc 1536(256,%0),1536(%1)\n" |
| 69 | " mvc 1792(256,%0),1792(%1)\n" |
| 70 | " mvc 2048(256,%0),2048(%1)\n" |
| 71 | " mvc 2304(256,%0),2304(%1)\n" |
| 72 | " mvc 2560(256,%0),2560(%1)\n" |
| 73 | " mvc 2816(256,%0),2816(%1)\n" |
| 74 | " mvc 3072(256,%0),3072(%1)\n" |
| 75 | " mvc 3328(256,%0),3328(%1)\n" |
| 76 | " mvc 3584(256,%0),3584(%1)\n" |
| 77 | " mvc 3840(256,%0),3840(%1)\n" |
| 78 | : : "a" (to), "a" (from) : "memory"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | } |
| 80 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | #define clear_user_page(page, vaddr, pg) clear_page(page) |
| 82 | #define copy_user_page(to, from, vaddr, pg) copy_page(to, from) |
| 83 | |
Mel Gorman | 769848c | 2007-07-17 04:03:05 -0700 | [diff] [blame] | 84 | #define __alloc_zeroed_user_highpage(movableflags, vma, vaddr) \ |
| 85 | alloc_page_vma(GFP_HIGHUSER | __GFP_ZERO | movableflags, vma, vaddr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | #define __HAVE_ARCH_ALLOC_ZEROED_USER_HIGHPAGE |
| 87 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | /* |
| 89 | * These are used to make use of C type-checking.. |
| 90 | */ |
| 91 | |
| 92 | typedef struct { unsigned long pgprot; } pgprot_t; |
Martin Schwidefsky | b2fa47e | 2011-05-23 10:24:40 +0200 | [diff] [blame] | 93 | typedef struct { unsigned long pgste; } pgste_t; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | typedef struct { unsigned long pte; } pte_t; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | typedef struct { unsigned long pmd; } pmd_t; |
Martin Schwidefsky | 190a1d7 | 2007-10-22 12:52:48 +0200 | [diff] [blame] | 96 | typedef struct { unsigned long pud; } pud_t; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | typedef struct { unsigned long pgd; } pgd_t; |
Martin Schwidefsky | 146e4b3 | 2008-02-09 18:24:35 +0100 | [diff] [blame] | 98 | typedef pte_t *pgtable_t; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | |
Martin Schwidefsky | 146e4b3 | 2008-02-09 18:24:35 +0100 | [diff] [blame] | 100 | #define pgprot_val(x) ((x).pgprot) |
Martin Schwidefsky | b2fa47e | 2011-05-23 10:24:40 +0200 | [diff] [blame] | 101 | #define pgste_val(x) ((x).pgste) |
Martin Schwidefsky | 146e4b3 | 2008-02-09 18:24:35 +0100 | [diff] [blame] | 102 | #define pte_val(x) ((x).pte) |
| 103 | #define pmd_val(x) ((x).pmd) |
Martin Schwidefsky | 190a1d7 | 2007-10-22 12:52:48 +0200 | [diff] [blame] | 104 | #define pud_val(x) ((x).pud) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | #define pgd_val(x) ((x).pgd) |
| 106 | |
Martin Schwidefsky | b2fa47e | 2011-05-23 10:24:40 +0200 | [diff] [blame] | 107 | #define __pgste(x) ((pgste_t) { (x) } ) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | #define __pte(x) ((pte_t) { (x) } ) |
| 109 | #define __pmd(x) ((pmd_t) { (x) } ) |
Martin Schwidefsky | b2fa47e | 2011-05-23 10:24:40 +0200 | [diff] [blame] | 110 | #define __pud(x) ((pud_t) { (x) } ) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | #define __pgd(x) ((pgd_t) { (x) } ) |
| 112 | #define __pgprot(x) ((pgprot_t) { (x) } ) |
| 113 | |
Martin Schwidefsky | 2d42552 | 2011-05-23 10:24:39 +0200 | [diff] [blame] | 114 | static inline void page_set_storage_key(unsigned long addr, |
| 115 | unsigned char skey, int mapped) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | { |
Martin Schwidefsky | e2b8d7a | 2010-10-25 16:10:14 +0200 | [diff] [blame] | 117 | if (!mapped) |
| 118 | asm volatile(".insn rrf,0xb22b0000,%0,%1,8,0" |
| 119 | : : "d" (skey), "a" (addr)); |
| 120 | else |
| 121 | asm volatile("sske %0,%1" : : "d" (skey), "a" (addr)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | } |
| 123 | |
Martin Schwidefsky | 2d42552 | 2011-05-23 10:24:39 +0200 | [diff] [blame] | 124 | static inline unsigned char page_get_storage_key(unsigned long addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | { |
Martin Schwidefsky | 2d42552 | 2011-05-23 10:24:39 +0200 | [diff] [blame] | 126 | unsigned char skey; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | |
Martin Schwidefsky | 2d42552 | 2011-05-23 10:24:39 +0200 | [diff] [blame] | 128 | asm volatile("iske %0,%1" : "=d" (skey) : "a" (addr)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | return skey; |
| 130 | } |
| 131 | |
Martin Schwidefsky | 2d42552 | 2011-05-23 10:24:39 +0200 | [diff] [blame] | 132 | static inline int page_reset_referenced(unsigned long addr) |
| 133 | { |
| 134 | unsigned int ipm; |
| 135 | |
| 136 | asm volatile( |
| 137 | " rrbe 0,%1\n" |
| 138 | " ipm %0\n" |
| 139 | : "=d" (ipm) : "a" (addr) : "cc"); |
| 140 | return !!(ipm & 0x20000000); |
| 141 | } |
| 142 | |
| 143 | /* Bits int the storage key */ |
| 144 | #define _PAGE_CHANGED 0x02 /* HW changed bit */ |
| 145 | #define _PAGE_REFERENCED 0x04 /* HW referenced bit */ |
| 146 | #define _PAGE_FP_BIT 0x08 /* HW fetch protection bit */ |
| 147 | #define _PAGE_ACC_BITS 0xf0 /* HW access control bits */ |
| 148 | |
| 149 | /* |
| 150 | * Test and clear dirty bit in storage key. |
| 151 | * We can't clear the changed bit atomically. This is a potential |
| 152 | * race against modification of the referenced bit. This function |
| 153 | * should therefore only be called if it is not mapped in any |
| 154 | * address space. |
| 155 | */ |
| 156 | #define __HAVE_ARCH_PAGE_TEST_AND_CLEAR_DIRTY |
| 157 | static inline int page_test_and_clear_dirty(unsigned long pfn, int mapped) |
| 158 | { |
| 159 | unsigned char skey; |
| 160 | |
| 161 | skey = page_get_storage_key(pfn << PAGE_SHIFT); |
| 162 | if (!(skey & _PAGE_CHANGED)) |
| 163 | return 0; |
| 164 | page_set_storage_key(pfn << PAGE_SHIFT, skey & ~_PAGE_CHANGED, mapped); |
| 165 | return 1; |
| 166 | } |
| 167 | |
| 168 | /* |
| 169 | * Test and clear referenced bit in storage key. |
| 170 | */ |
| 171 | #define __HAVE_ARCH_PAGE_TEST_AND_CLEAR_YOUNG |
| 172 | static inline int page_test_and_clear_young(unsigned long pfn) |
| 173 | { |
| 174 | return page_reset_referenced(pfn << PAGE_SHIFT); |
| 175 | } |
| 176 | |
Martin Schwidefsky | 45e576b | 2008-05-07 09:22:59 +0200 | [diff] [blame] | 177 | struct page; |
| 178 | void arch_free_page(struct page *page, int order); |
| 179 | void arch_alloc_page(struct page *page, int order); |
Martin Schwidefsky | 638ad34 | 2011-10-30 15:17:13 +0100 | [diff] [blame] | 180 | void arch_set_page_states(int make_stable); |
Martin Schwidefsky | 45e576b | 2008-05-07 09:22:59 +0200 | [diff] [blame] | 181 | |
Hendrik Brueckner | ec6743b | 2010-11-10 10:05:55 +0100 | [diff] [blame] | 182 | static inline int devmem_is_allowed(unsigned long pfn) |
| 183 | { |
| 184 | return 0; |
| 185 | } |
| 186 | |
Martin Schwidefsky | 45e576b | 2008-05-07 09:22:59 +0200 | [diff] [blame] | 187 | #define HAVE_ARCH_FREE_PAGE |
| 188 | #define HAVE_ARCH_ALLOC_PAGE |
| 189 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | #endif /* !__ASSEMBLY__ */ |
| 191 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | #define __PAGE_OFFSET 0x0UL |
| 193 | #define PAGE_OFFSET 0x0UL |
| 194 | #define __pa(x) (unsigned long)(x) |
| 195 | #define __va(x) (void *)(unsigned long)(x) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | #define virt_to_page(kaddr) pfn_to_page(__pa(kaddr) >> PAGE_SHIFT) |
Heiko Carstens | 0b2b6e1 | 2006-10-04 20:02:23 +0200 | [diff] [blame] | 197 | #define page_to_phys(page) (page_to_pfn(page) << PAGE_SHIFT) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | #define virt_addr_valid(kaddr) pfn_valid(__pa(kaddr) >> PAGE_SHIFT) |
| 199 | |
Martin Schwidefsky | 146e4b3 | 2008-02-09 18:24:35 +0100 | [diff] [blame] | 200 | #define VM_DATA_DEFAULT_FLAGS (VM_READ | VM_WRITE | \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC) |
| 202 | |
KAMEZAWA Hiroyuki | aed6304 | 2006-03-27 01:15:45 -0800 | [diff] [blame] | 203 | #include <asm-generic/memory_model.h> |
Arnd Bergmann | 5b17e1c | 2009-05-13 22:56:30 +0000 | [diff] [blame] | 204 | #include <asm-generic/getorder.h> |
Stephen Rothwell | fd4fd5a | 2005-09-03 15:54:30 -0700 | [diff] [blame] | 205 | |
Martin Schwidefsky | b020632 | 2008-12-25 13:38:36 +0100 | [diff] [blame] | 206 | #define __HAVE_ARCH_GATE_AREA 1 |
| 207 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | #endif /* _S390_PAGE_H */ |