2 * include/asm-s390/pgtable.h
5 * Copyright (C) 1999,2000 IBM Deutschland Entwicklung GmbH, IBM Corporation
6 * Author(s): Hartmut Penner (hp@de.ibm.com)
7 * Ulrich Weigand (weigand@de.ibm.com)
8 * Martin Schwidefsky (schwidefsky@de.ibm.com)
10 * Derived from "include/asm-i386/pgtable.h"
13 #ifndef _ASM_S390_PGTABLE_H
14 #define _ASM_S390_PGTABLE_H
17 * The Linux memory management assumes a three-level page table setup. On
18 * the S390, we use that, but "fold" the mid level into the top-level page
19 * table, so that we physically have the same two-level page table as the
22 * The "pgd_xxx()" functions are trivial for a folded two-level
23 * setup: the pgd is never bad, and a pmd always exists (as it's folded
26 * This file contains the functions and defines necessary to modify and use
27 * the S390 page table tree.
30 #include <asm/processor.h>
31 #include <linux/threads.h>
33 extern pgd_t swapper_pg_dir[] __attribute__ ((aligned (4096)));
34 extern void paging_init(void);
36 /* Caches aren't brain-dead on S390. */
37 #define flush_cache_all() do { } while (0)
38 #define flush_cache_mm(mm) do { } while (0)
39 #define flush_cache_range(mm, start, end) do { } while (0)
40 #define flush_cache_page(vma, vmaddr) do { } while (0)
41 #define flush_page_to_ram(page) do { } while (0)
42 #define flush_dcache_page(page) do { } while (0)
43 #define flush_icache_range(start, end) do { } while (0)
44 #define flush_icache_page(vma,pg) do { } while (0)
45 #define flush_icache_user_range(vma,pg,adr,len) do { } while (0)
48 * The S390 doesn't have any external MMU info: the kernel page
49 * tables contain all the necessary information.
51 #define update_mmu_cache(vma, address, pte) do { } while (0)
54 * ZERO_PAGE is a global shared page that is always zero: used
55 * for zero-mapped memory areas etc..
57 extern char empty_zero_page[PAGE_SIZE];
58 #define ZERO_PAGE(vaddr) (virt_to_page(empty_zero_page))
59 #endif /* !__ASSEMBLY__ */
62 * PMD_SHIFT determines the size of the area a second-level page
66 #define PMD_SIZE (1UL << PMD_SHIFT)
67 #define PMD_MASK (~(PMD_SIZE-1))
69 /* PGDIR_SHIFT determines what a third-level page table entry can map */
70 #define PGDIR_SHIFT 22
71 #define PGDIR_SIZE (1UL << PGDIR_SHIFT)
72 #define PGDIR_MASK (~(PGDIR_SIZE-1))
75 * entries per page directory level: the S390 is two-level, so
76 * we don't really have any PMD directory physically.
77 * for S390 segment-table entries are combined to one PGD
78 * that leads to 1024 pte per pgd
80 #define PTRS_PER_PTE 1024
81 #define PTRS_PER_PMD 1
82 #define PTRS_PER_PGD 512
85 * pgd entries used up by user/kernel:
87 #define USER_PTRS_PER_PGD 512
88 #define USER_PGD_PTRS 512
89 #define KERNEL_PGD_PTRS 512
90 #define FIRST_USER_PGD_NR 0
92 #define pte_ERROR(e) \
93 printk("%s:%d: bad pte %08lx.\n", __FILE__, __LINE__, pte_val(e))
94 #define pmd_ERROR(e) \
95 printk("%s:%d: bad pmd %08lx.\n", __FILE__, __LINE__, pmd_val(e))
96 #define pgd_ERROR(e) \
97 printk("%s:%d: bad pgd %08lx.\n", __FILE__, __LINE__, pgd_val(e))
101 * Just any arbitrary offset to the start of the vmalloc VM area: the
102 * current 8MB value just means that there will be a 8MB "hole" after the
103 * physical memory until the kernel virtual memory starts. That means that
104 * any out-of-bounds memory accesses will hopefully be caught.
105 * The vmalloc() routines leaves a hole of 4kB between each vmalloced
106 * area for the same reason. ;)
108 #define VMALLOC_OFFSET (8*1024*1024)
109 #define VMALLOC_START (((unsigned long) high_memory + VMALLOC_OFFSET) \
110 & ~(VMALLOC_OFFSET-1))
111 #define VMALLOC_VMADDR(x) ((unsigned long)(x))
112 #define VMALLOC_END (0x7fffffffL)
116 * A pagetable entry of S390 has following format:
119 * 00000000001111111111222222222233
120 * 01234567890123456789012345678901
122 * I Page-Invalid Bit: Page is not available for address-translation
123 * P Page-Protection Bit: Store access not possible for page
125 * A segmenttable entry of S390 has following format:
126 * | P-table origin | |PTL
128 * 00000000001111111111222222222233
129 * 01234567890123456789012345678901
131 * I Segment-Invalid Bit: Segment is not available for address-translation
132 * C Common-Segment Bit: Segment is not private (PoP 3-30)
133 * PTL Page-Table-Length: Page-table length (PTL+1*16 entries -> up to 256)
135 * The segmenttable origin of S390 has following format:
137 * |S-table origin | | STL |
139 * 00000000001111111111222222222233
140 * 01234567890123456789012345678901
142 * X Space-Switch event:
143 * G Segment-Invalid Bit: *
144 * P Private-Space Bit: Segment is not private (PoP 3-30)
145 * S Storage-Alteration:
146 * STL Segment-Table-Length: Segment-table length (STL+1*16 entries -> up to 2048)
148 * A storage key has the following format:
152 * F : fetch protection bit
157 /* Bits in the page table entry */
158 #define _PAGE_PRESENT 0x001 /* Software */
159 #define _PAGE_ISCLEAN 0x004 /* Software */
160 #define _PAGE_RO 0x200 /* HW read-only */
161 #define _PAGE_INVALID 0x400 /* HW invalid */
163 /* Bits in the segment table entry */
164 #define _PAGE_TABLE_LEN 0xf /* only full page-tables */
165 #define _PAGE_TABLE_COM 0x10 /* common page-table */
166 #define _PAGE_TABLE_INV 0x20 /* invalid page-table */
167 #define _SEG_PRESENT 0x001 /* Software (overlap with PTL) */
169 /* Bits int the storage key */
170 #define _PAGE_CHANGED 0x02 /* HW changed bit */
171 #define _PAGE_REFERENCED 0x04 /* HW referenced bit */
173 #define _USER_SEG_TABLE_LEN 0x7f /* user-segment-table up to 2 GB */
174 #define _KERNEL_SEG_TABLE_LEN 0x7f /* kernel-segment-table up to 2 GB */
177 * User and Kernel pagetables are identical
179 #define _PAGE_TABLE (_PAGE_TABLE_LEN )
180 #define _KERNPG_TABLE (_PAGE_TABLE_LEN )
183 * The Kernel segment-tables includes the User segment-table
186 #define _SEGMENT_TABLE (_USER_SEG_TABLE_LEN|0x80000000|0x100)
187 #define _KERNSEG_TABLE (_KERNEL_SEG_TABLE_LEN)
190 * No mapping available
192 #define PAGE_INVALID __pgprot(_PAGE_INVALID)
193 #define PAGE_NONE_SHARED __pgprot(_PAGE_PRESENT|_PAGE_INVALID)
194 #define PAGE_NONE_PRIVATE __pgprot(_PAGE_PRESENT|_PAGE_INVALID|_PAGE_ISCLEAN)
195 #define PAGE_RO_SHARED __pgprot(_PAGE_PRESENT|_PAGE_RO)
196 #define PAGE_RO_PRIVATE __pgprot(_PAGE_PRESENT|_PAGE_RO|_PAGE_ISCLEAN)
197 #define PAGE_COPY __pgprot(_PAGE_PRESENT|_PAGE_RO|_PAGE_ISCLEAN)
198 #define PAGE_SHARED __pgprot(_PAGE_PRESENT)
199 #define PAGE_KERNEL __pgprot(_PAGE_PRESENT)
202 * The S390 can't do page protection for execute, and considers that the
203 * same are read. Also, write permissions imply read permissions. This is
204 * the closest we can get..
207 #define __P000 PAGE_NONE_PRIVATE
208 #define __P001 PAGE_RO_PRIVATE
209 #define __P010 PAGE_COPY
210 #define __P011 PAGE_COPY
211 #define __P100 PAGE_RO_PRIVATE
212 #define __P101 PAGE_RO_PRIVATE
213 #define __P110 PAGE_COPY
214 #define __P111 PAGE_COPY
216 #define __S000 PAGE_NONE_SHARED
217 #define __S001 PAGE_RO_SHARED
218 #define __S010 PAGE_SHARED
219 #define __S011 PAGE_SHARED
220 #define __S100 PAGE_RO_SHARED
221 #define __S101 PAGE_RO_SHARED
222 #define __S110 PAGE_SHARED
223 #define __S111 PAGE_SHARED
226 * Certain architectures need to do special things when PTEs
227 * within a page table are directly modified. Thus, the following
228 * hook is made available.
230 extern inline void set_pte(pte_t *pteptr, pte_t pteval)
235 #define pages_to_mb(x) ((x) >> (20-PAGE_SHIFT))
238 * pgd/pmd/pte query functions
240 extern inline int pgd_present(pgd_t pgd) { return 1; }
241 extern inline int pgd_none(pgd_t pgd) { return 0; }
242 extern inline int pgd_bad(pgd_t pgd) { return 0; }
244 extern inline int pmd_present(pmd_t pmd) { return pmd_val(pmd) & _SEG_PRESENT; }
245 extern inline int pmd_none(pmd_t pmd) { return pmd_val(pmd) & _PAGE_TABLE_INV; }
246 extern inline int pmd_bad(pmd_t pmd)
248 return (pmd_val(pmd) & (~PAGE_MASK & ~_PAGE_TABLE_INV)) != _PAGE_TABLE;
251 extern inline int pte_present(pte_t pte) { return pte_val(pte) & _PAGE_PRESENT; }
252 extern inline int pte_none(pte_t pte)
254 return ((pte_val(pte) &
255 (_PAGE_INVALID | _PAGE_RO | _PAGE_PRESENT)) == _PAGE_INVALID);
258 #define pte_same(a,b) (pte_val(a) == pte_val(b))
261 * query functions pte_write/pte_dirty/pte_young only work if
262 * pte_present() is true. Undefined behaviour if not..
264 extern inline int pte_write(pte_t pte)
266 return (pte_val(pte) & _PAGE_RO) == 0;
269 extern inline int pte_dirty(pte_t pte)
273 if (pte_val(pte) & _PAGE_ISCLEAN)
275 asm volatile ("iske %0,%1" : "=d" (skey) : "a" (pte_val(pte)));
276 return skey & _PAGE_CHANGED;
279 extern inline int pte_young(pte_t pte)
283 asm volatile ("iske %0,%1" : "=d" (skey) : "a" (pte_val(pte)));
284 return skey & _PAGE_REFERENCED;
288 * pgd/pmd/pte modification functions
290 extern inline void pgd_clear(pgd_t * pgdp) { }
292 extern inline void pmd_clear(pmd_t * pmdp)
294 pmd_val(pmdp[0]) = _PAGE_TABLE_INV;
295 pmd_val(pmdp[1]) = _PAGE_TABLE_INV;
296 pmd_val(pmdp[2]) = _PAGE_TABLE_INV;
297 pmd_val(pmdp[3]) = _PAGE_TABLE_INV;
300 extern inline void pte_clear(pte_t *ptep)
302 pte_val(*ptep) = _PAGE_INVALID;
305 #define PTE_INIT(x) pte_clear(x)
308 * The following pte modification functions only work if
309 * pte_present() is true. Undefined behaviour if not..
311 extern inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
313 pte_val(pte) &= PAGE_MASK | _PAGE_ISCLEAN;
314 pte_val(pte) |= pgprot_val(newprot) & ~_PAGE_ISCLEAN;
318 extern inline pte_t pte_wrprotect(pte_t pte)
320 pte_val(pte) |= _PAGE_RO;
324 extern inline pte_t pte_mkwrite(pte_t pte)
326 pte_val(pte) &= ~(_PAGE_RO | _PAGE_ISCLEAN);
330 extern inline pte_t pte_mkclean(pte_t pte)
332 /* The only user of pte_mkclean is the fork() code.
333 We must *not* clear the *physical* page dirty bit
334 just because fork() wants to clear the dirty bit in
335 *one* of the page's mappings. So we just do nothing. */
339 extern inline pte_t pte_mkdirty(pte_t pte)
341 /* We do not explicitly set the dirty bit because the
342 * sske instruction is slow. It is faster to let the
343 * next instruction set the dirty bit.
345 pte_val(pte) &= ~_PAGE_ISCLEAN;
349 extern inline pte_t pte_mkold(pte_t pte)
351 asm volatile ("rrbe 0,%0" : : "a" (pte_val(pte)) : "cc" );
355 extern inline pte_t pte_mkyoung(pte_t pte)
357 /* To set the referenced bit we read the first word from the real
358 * page with a special instruction: load using real address (lura).
359 * Isn't S/390 a nice architecture ?! */
360 asm volatile ("lura 0,%0" : : "a" (pte_val(pte) & PAGE_MASK) : "0" );
364 static inline int ptep_test_and_clear_young(pte_t *ptep)
368 asm volatile ("rrbe 0,%1\n\t"
371 : "=d" (ccode) : "a" (pte_val(*ptep)) : "cc" );
375 static inline int ptep_test_and_clear_dirty(pte_t *ptep)
379 if (pte_val(*ptep) & _PAGE_ISCLEAN)
381 asm volatile ("iske %0,%1" : "=d" (skey) : "a" (*ptep));
382 if ((skey & _PAGE_CHANGED) == 0)
384 /* We can't clear the changed bit atomically. For now we
385 * clear (!) the page referenced bit. */
386 asm volatile ("sske %0,%1"
387 : : "d" (get_storage_key()), "a" (*ptep));
391 static inline pte_t ptep_get_and_clear(pte_t *ptep)
398 static inline void ptep_set_wrprotect(pte_t *ptep)
400 pte_t old_pte = *ptep;
401 set_pte(ptep, pte_wrprotect(old_pte));
404 static inline void ptep_mkdirty(pte_t *ptep)
410 * Conversion functions: convert a page and protection to a page entry,
411 * and a page entry and page directory to the page they refer to.
413 static inline pte_t mk_pte_phys(unsigned long physpage, pgprot_t pgprot)
416 pte_val(__pte) = physpage + pgprot_val(pgprot);
420 #define mk_pte(pg, pgprot) \
422 struct page *__page = (pg); \
423 pgprot_t __pgprot = (pgprot); \
424 unsigned long __physpage = __pa((__page-mem_map) << PAGE_SHIFT); \
425 pte_t __pte = mk_pte_phys(__physpage, __pgprot); \
429 #define SetPageUptodate(_page) \
431 struct page *__page = (_page); \
432 if (!test_and_set_bit(PG_uptodate, &__page->flags)) \
433 asm volatile ("sske %0,%1" \
434 : : "d" (get_storage_key()), \
435 "a" (__pa((__page-mem_map) << PAGE_SHIFT)));\
438 #define pte_page(x) (mem_map+(unsigned long)((pte_val(x) >> PAGE_SHIFT)))
440 #define pmd_page(pmd) \
441 ((unsigned long) __va(pmd_val(pmd) & PAGE_MASK))
443 /* to find an entry in a page-table-directory */
444 #define pgd_index(address) ((address >> PGDIR_SHIFT) & (PTRS_PER_PGD-1))
445 #define pgd_offset(mm, address) ((mm)->pgd+pgd_index(address))
447 /* to find an entry in a kernel page-table-directory */
448 #define pgd_offset_k(address) pgd_offset(&init_mm, address)
450 /* Find an entry in the second-level page table.. */
451 extern inline pmd_t * pmd_offset(pgd_t * dir, unsigned long address)
453 return (pmd_t *) dir;
456 /* Find an entry in the third-level page table.. */
457 #define pte_offset(pmd, address) \
458 ((pte_t *) (pmd_page(*pmd) + ((address>>10) & ((PTRS_PER_PTE-1)<<2))))
461 * A page-table entry has some bits we have to treat in a special way.
462 * Bits 0, 20 and bit 23 have to be zero, otherwise an specification
463 * exception will occur instead of a page translation exception. The
464 * specifiation exception has the bad habit not to store necessary
465 * information in the lowcore.
466 * Bit 21 and bit 22 are the page invalid bit and the page protection
467 * bit. We set both to indicate a swapped page.
468 * Bit 31 is used as the software page present bit. If a page is
469 * swapped this obviously has to be zero.
470 * This leaves the bits 1-19 and bits 24-30 to store type and offset.
471 * We use the 7 bits from 24-30 for the type and the 19 bits from 1-19
473 * 0| offset |0110|type |0
474 * 00000000001111111111222222222233
475 * 01234567890123456789012345678901
477 extern inline pte_t mk_swap_pte(unsigned long type, unsigned long offset)
480 pte_val(pte) = (type << 1) | (offset << 12) | _PAGE_INVALID | _PAGE_RO;
481 pte_val(pte) &= 0x7ffff6fe; /* better to be paranoid */
485 #define SWP_TYPE(entry) (((entry).val >> 1) & 0x3f)
486 #define SWP_OFFSET(entry) (((entry).val >> 12) & 0x7FFFF )
487 #define SWP_ENTRY(type,offset) ((swp_entry_t) { pte_val(mk_swap_pte((type),(offset))) })
489 #define pte_to_swp_entry(pte) ((swp_entry_t) { pte_val(pte) })
490 #define swp_entry_to_pte(x) ((pte_t) { (x).val })
492 #endif /* !__ASSEMBLY__ */
494 /* Needs to be defined here and not in linux/mm.h, as it is arch dependent */
495 #define PageSkip(page) (0)
496 #define kern_addr_valid(addr) (1)
499 * No page table caches to initialise
501 #define pgtable_cache_init() do { } while (0)
503 #endif /* _S390_PAGE_H */