pgtable.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801
  1. /*
  2. * include/asm-s390/pgtable.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. * Ulrich Weigand (weigand@de.ibm.com)
  8. * Martin Schwidefsky (schwidefsky@de.ibm.com)
  9. *
  10. * Derived from "include/asm-i386/pgtable.h"
  11. */
  12. #ifndef _ASM_S390_PGTABLE_H
  13. #define _ASM_S390_PGTABLE_H
  14. #include <asm-generic/4level-fixup.h>
  15. /*
  16. * The Linux memory management assumes a three-level page table setup. For
  17. * s390 31 bit we "fold" the mid level into the top-level page table, so
  18. * that we physically have the same two-level page table as the s390 mmu
  19. * expects in 31 bit mode. For s390 64 bit we use three of the five levels
  20. * the hardware provides (region first and region second tables are not
  21. * used).
  22. *
  23. * The "pgd_xxx()" functions are trivial for a folded two-level
  24. * setup: the pgd is never bad, and a pmd always exists (as it's folded
  25. * into the pgd entry)
  26. *
  27. * This file contains the functions and defines necessary to modify and use
  28. * the S390 page table tree.
  29. */
  30. #ifndef __ASSEMBLY__
  31. #include <asm/bug.h>
  32. #include <asm/processor.h>
  33. #include <linux/threads.h>
  34. struct vm_area_struct; /* forward declaration (include/linux/mm.h) */
  35. struct mm_struct;
  36. extern pgd_t swapper_pg_dir[] __attribute__ ((aligned (4096)));
  37. extern void paging_init(void);
  38. /*
  39. * The S390 doesn't have any external MMU info: the kernel page
  40. * tables contain all the necessary information.
  41. */
  42. #define update_mmu_cache(vma, address, pte) do { } while (0)
  43. /*
  44. * ZERO_PAGE is a global shared page that is always zero: used
  45. * for zero-mapped memory areas etc..
  46. */
  47. extern char empty_zero_page[PAGE_SIZE];
  48. #define ZERO_PAGE(vaddr) (virt_to_page(empty_zero_page))
  49. #endif /* !__ASSEMBLY__ */
  50. /*
  51. * PMD_SHIFT determines the size of the area a second-level page
  52. * table can map
  53. * PGDIR_SHIFT determines what a third-level page table entry can map
  54. */
  55. #ifndef __s390x__
  56. # define PMD_SHIFT 22
  57. # define PGDIR_SHIFT 22
  58. #else /* __s390x__ */
  59. # define PMD_SHIFT 21
  60. # define PGDIR_SHIFT 31
  61. #endif /* __s390x__ */
  62. #define PMD_SIZE (1UL << PMD_SHIFT)
  63. #define PMD_MASK (~(PMD_SIZE-1))
  64. #define PGDIR_SIZE (1UL << PGDIR_SHIFT)
  65. #define PGDIR_MASK (~(PGDIR_SIZE-1))
  66. /*
  67. * entries per page directory level: the S390 is two-level, so
  68. * we don't really have any PMD directory physically.
  69. * for S390 segment-table entries are combined to one PGD
  70. * that leads to 1024 pte per pgd
  71. */
  72. #ifndef __s390x__
  73. # define PTRS_PER_PTE 1024
  74. # define PTRS_PER_PMD 1
  75. # define PTRS_PER_PGD 512
  76. #else /* __s390x__ */
  77. # define PTRS_PER_PTE 512
  78. # define PTRS_PER_PMD 1024
  79. # define PTRS_PER_PGD 2048
  80. #endif /* __s390x__ */
  81. #define FIRST_USER_ADDRESS 0
  82. #define pte_ERROR(e) \
  83. printk("%s:%d: bad pte %p.\n", __FILE__, __LINE__, (void *) pte_val(e))
  84. #define pmd_ERROR(e) \
  85. printk("%s:%d: bad pmd %p.\n", __FILE__, __LINE__, (void *) pmd_val(e))
  86. #define pgd_ERROR(e) \
  87. printk("%s:%d: bad pgd %p.\n", __FILE__, __LINE__, (void *) pgd_val(e))
  88. #ifndef __ASSEMBLY__
  89. /*
  90. * Just any arbitrary offset to the start of the vmalloc VM area: the
  91. * current 8MB value just means that there will be a 8MB "hole" after the
  92. * physical memory until the kernel virtual memory starts. That means that
  93. * any out-of-bounds memory accesses will hopefully be caught.
  94. * The vmalloc() routines leaves a hole of 4kB between each vmalloced
  95. * area for the same reason. ;)
  96. */
  97. #define VMALLOC_OFFSET (8*1024*1024)
  98. #define VMALLOC_START (((unsigned long) high_memory + VMALLOC_OFFSET) \
  99. & ~(VMALLOC_OFFSET-1))
  100. #ifndef __s390x__
  101. # define VMALLOC_END (0x7fffffffL)
  102. #else /* __s390x__ */
  103. # define VMALLOC_END (0x40000000000L)
  104. #endif /* __s390x__ */
  105. /*
  106. * A 31 bit pagetable entry of S390 has following format:
  107. * | PFRA | | OS |
  108. * 0 0IP0
  109. * 00000000001111111111222222222233
  110. * 01234567890123456789012345678901
  111. *
  112. * I Page-Invalid Bit: Page is not available for address-translation
  113. * P Page-Protection Bit: Store access not possible for page
  114. *
  115. * A 31 bit segmenttable entry of S390 has following format:
  116. * | P-table origin | |PTL
  117. * 0 IC
  118. * 00000000001111111111222222222233
  119. * 01234567890123456789012345678901
  120. *
  121. * I Segment-Invalid Bit: Segment is not available for address-translation
  122. * C Common-Segment Bit: Segment is not private (PoP 3-30)
  123. * PTL Page-Table-Length: Page-table length (PTL+1*16 entries -> up to 256)
  124. *
  125. * The 31 bit segmenttable origin of S390 has following format:
  126. *
  127. * |S-table origin | | STL |
  128. * X **GPS
  129. * 00000000001111111111222222222233
  130. * 01234567890123456789012345678901
  131. *
  132. * X Space-Switch event:
  133. * G Segment-Invalid Bit: *
  134. * P Private-Space Bit: Segment is not private (PoP 3-30)
  135. * S Storage-Alteration:
  136. * STL Segment-Table-Length: Segment-table length (STL+1*16 entries -> up to 2048)
  137. *
  138. * A 64 bit pagetable entry of S390 has following format:
  139. * | PFRA |0IP0| OS |
  140. * 0000000000111111111122222222223333333333444444444455555555556666
  141. * 0123456789012345678901234567890123456789012345678901234567890123
  142. *
  143. * I Page-Invalid Bit: Page is not available for address-translation
  144. * P Page-Protection Bit: Store access not possible for page
  145. *
  146. * A 64 bit segmenttable entry of S390 has following format:
  147. * | P-table origin | TT
  148. * 0000000000111111111122222222223333333333444444444455555555556666
  149. * 0123456789012345678901234567890123456789012345678901234567890123
  150. *
  151. * I Segment-Invalid Bit: Segment is not available for address-translation
  152. * C Common-Segment Bit: Segment is not private (PoP 3-30)
  153. * P Page-Protection Bit: Store access not possible for page
  154. * TT Type 00
  155. *
  156. * A 64 bit region table entry of S390 has following format:
  157. * | S-table origin | TF TTTL
  158. * 0000000000111111111122222222223333333333444444444455555555556666
  159. * 0123456789012345678901234567890123456789012345678901234567890123
  160. *
  161. * I Segment-Invalid Bit: Segment is not available for address-translation
  162. * TT Type 01
  163. * TF
  164. * TL Table lenght
  165. *
  166. * The 64 bit regiontable origin of S390 has following format:
  167. * | region table origon | DTTL
  168. * 0000000000111111111122222222223333333333444444444455555555556666
  169. * 0123456789012345678901234567890123456789012345678901234567890123
  170. *
  171. * X Space-Switch event:
  172. * G Segment-Invalid Bit:
  173. * P Private-Space Bit:
  174. * S Storage-Alteration:
  175. * R Real space
  176. * TL Table-Length:
  177. *
  178. * A storage key has the following format:
  179. * | ACC |F|R|C|0|
  180. * 0 3 4 5 6 7
  181. * ACC: access key
  182. * F : fetch protection bit
  183. * R : referenced bit
  184. * C : changed bit
  185. */
  186. /* Hardware bits in the page table entry */
  187. #define _PAGE_RO 0x200 /* HW read-only */
  188. #define _PAGE_INVALID 0x400 /* HW invalid */
  189. /* Mask and six different types of pages. */
  190. #define _PAGE_TYPE_MASK 0x601
  191. #define _PAGE_TYPE_EMPTY 0x400
  192. #define _PAGE_TYPE_NONE 0x401
  193. #define _PAGE_TYPE_SWAP 0x600
  194. #define _PAGE_TYPE_FILE 0x601
  195. #define _PAGE_TYPE_RO 0x200
  196. #define _PAGE_TYPE_RW 0x000
  197. #ifndef __s390x__
  198. /* Bits in the segment table entry */
  199. #define _PAGE_TABLE_LEN 0xf /* only full page-tables */
  200. #define _PAGE_TABLE_COM 0x10 /* common page-table */
  201. #define _PAGE_TABLE_INV 0x20 /* invalid page-table */
  202. #define _SEG_PRESENT 0x001 /* Software (overlap with PTL) */
  203. /* Bits int the storage key */
  204. #define _PAGE_CHANGED 0x02 /* HW changed bit */
  205. #define _PAGE_REFERENCED 0x04 /* HW referenced bit */
  206. #define _USER_SEG_TABLE_LEN 0x7f /* user-segment-table up to 2 GB */
  207. #define _KERNEL_SEG_TABLE_LEN 0x7f /* kernel-segment-table up to 2 GB */
  208. /*
  209. * User and Kernel pagetables are identical
  210. */
  211. #define _PAGE_TABLE _PAGE_TABLE_LEN
  212. #define _KERNPG_TABLE _PAGE_TABLE_LEN
  213. /*
  214. * The Kernel segment-tables includes the User segment-table
  215. */
  216. #define _SEGMENT_TABLE (_USER_SEG_TABLE_LEN|0x80000000|0x100)
  217. #define _KERNSEG_TABLE _KERNEL_SEG_TABLE_LEN
  218. #define USER_STD_MASK 0x00000080UL
  219. #else /* __s390x__ */
  220. /* Bits in the segment table entry */
  221. #define _PMD_ENTRY_INV 0x20 /* invalid segment table entry */
  222. #define _PMD_ENTRY 0x00
  223. /* Bits in the region third table entry */
  224. #define _PGD_ENTRY_INV 0x20 /* invalid region table entry */
  225. #define _PGD_ENTRY 0x07
  226. /*
  227. * User and kernel page directory
  228. */
  229. #define _REGION_THIRD 0x4
  230. #define _REGION_THIRD_LEN 0x3
  231. #define _REGION_TABLE (_REGION_THIRD|_REGION_THIRD_LEN|0x40|0x100)
  232. #define _KERN_REGION_TABLE (_REGION_THIRD|_REGION_THIRD_LEN)
  233. #define USER_STD_MASK 0x0000000000000080UL
  234. /* Bits in the storage key */
  235. #define _PAGE_CHANGED 0x02 /* HW changed bit */
  236. #define _PAGE_REFERENCED 0x04 /* HW referenced bit */
  237. #endif /* __s390x__ */
  238. /*
  239. * Page protection definitions.
  240. */
  241. #define PAGE_NONE __pgprot(_PAGE_TYPE_NONE)
  242. #define PAGE_RO __pgprot(_PAGE_TYPE_RO)
  243. #define PAGE_RW __pgprot(_PAGE_TYPE_RW)
  244. #define PAGE_KERNEL PAGE_RW
  245. #define PAGE_COPY PAGE_RO
  246. /*
  247. * The S390 can't do page protection for execute, and considers that the
  248. * same are read. Also, write permissions imply read permissions. This is
  249. * the closest we can get..
  250. */
  251. /*xwr*/
  252. #define __P000 PAGE_NONE
  253. #define __P001 PAGE_RO
  254. #define __P010 PAGE_RO
  255. #define __P011 PAGE_RO
  256. #define __P100 PAGE_RO
  257. #define __P101 PAGE_RO
  258. #define __P110 PAGE_RO
  259. #define __P111 PAGE_RO
  260. #define __S000 PAGE_NONE
  261. #define __S001 PAGE_RO
  262. #define __S010 PAGE_RW
  263. #define __S011 PAGE_RW
  264. #define __S100 PAGE_RO
  265. #define __S101 PAGE_RO
  266. #define __S110 PAGE_RW
  267. #define __S111 PAGE_RW
  268. /*
  269. * Certain architectures need to do special things when PTEs
  270. * within a page table are directly modified. Thus, the following
  271. * hook is made available.
  272. */
  273. static inline void set_pte(pte_t *pteptr, pte_t pteval)
  274. {
  275. *pteptr = pteval;
  276. }
  277. #define set_pte_at(mm,addr,ptep,pteval) set_pte(ptep,pteval)
  278. /*
  279. * pgd/pmd/pte query functions
  280. */
  281. #ifndef __s390x__
  282. static inline int pgd_present(pgd_t pgd) { return 1; }
  283. static inline int pgd_none(pgd_t pgd) { return 0; }
  284. static inline int pgd_bad(pgd_t pgd) { return 0; }
  285. static inline int pmd_present(pmd_t pmd) { return pmd_val(pmd) & _SEG_PRESENT; }
  286. static inline int pmd_none(pmd_t pmd) { return pmd_val(pmd) & _PAGE_TABLE_INV; }
  287. static inline int pmd_bad(pmd_t pmd)
  288. {
  289. return (pmd_val(pmd) & (~PAGE_MASK & ~_PAGE_TABLE_INV)) != _PAGE_TABLE;
  290. }
  291. #else /* __s390x__ */
  292. static inline int pgd_present(pgd_t pgd)
  293. {
  294. return (pgd_val(pgd) & ~PAGE_MASK) == _PGD_ENTRY;
  295. }
  296. static inline int pgd_none(pgd_t pgd)
  297. {
  298. return pgd_val(pgd) & _PGD_ENTRY_INV;
  299. }
  300. static inline int pgd_bad(pgd_t pgd)
  301. {
  302. return (pgd_val(pgd) & (~PAGE_MASK & ~_PGD_ENTRY_INV)) != _PGD_ENTRY;
  303. }
  304. static inline int pmd_present(pmd_t pmd)
  305. {
  306. return (pmd_val(pmd) & ~PAGE_MASK) == _PMD_ENTRY;
  307. }
  308. static inline int pmd_none(pmd_t pmd)
  309. {
  310. return pmd_val(pmd) & _PMD_ENTRY_INV;
  311. }
  312. static inline int pmd_bad(pmd_t pmd)
  313. {
  314. return (pmd_val(pmd) & (~PAGE_MASK & ~_PMD_ENTRY_INV)) != _PMD_ENTRY;
  315. }
  316. #endif /* __s390x__ */
  317. static inline int pte_none(pte_t pte)
  318. {
  319. return (pte_val(pte) & _PAGE_TYPE_MASK) == _PAGE_TYPE_EMPTY;
  320. }
  321. static inline int pte_present(pte_t pte)
  322. {
  323. return !(pte_val(pte) & _PAGE_INVALID) ||
  324. (pte_val(pte) & _PAGE_TYPE_MASK) == _PAGE_TYPE_NONE;
  325. }
  326. static inline int pte_file(pte_t pte)
  327. {
  328. return (pte_val(pte) & _PAGE_TYPE_MASK) == _PAGE_TYPE_FILE;
  329. }
  330. #define pte_same(a,b) (pte_val(a) == pte_val(b))
  331. /*
  332. * query functions pte_write/pte_dirty/pte_young only work if
  333. * pte_present() is true. Undefined behaviour if not..
  334. */
  335. static inline int pte_write(pte_t pte)
  336. {
  337. return (pte_val(pte) & _PAGE_RO) == 0;
  338. }
  339. static inline int pte_dirty(pte_t pte)
  340. {
  341. /* A pte is neither clean nor dirty on s/390. The dirty bit
  342. * is in the storage key. See page_test_and_clear_dirty for
  343. * details.
  344. */
  345. return 0;
  346. }
  347. static inline int pte_young(pte_t pte)
  348. {
  349. /* A pte is neither young nor old on s/390. The young bit
  350. * is in the storage key. See page_test_and_clear_young for
  351. * details.
  352. */
  353. return 0;
  354. }
  355. static inline int pte_read(pte_t pte)
  356. {
  357. /* All pages are readable since we don't use the fetch
  358. * protection bit in the storage key.
  359. */
  360. return 1;
  361. }
  362. /*
  363. * pgd/pmd/pte modification functions
  364. */
  365. #ifndef __s390x__
  366. static inline void pgd_clear(pgd_t * pgdp) { }
  367. static inline void pmd_clear(pmd_t * pmdp)
  368. {
  369. pmd_val(pmdp[0]) = _PAGE_TABLE_INV;
  370. pmd_val(pmdp[1]) = _PAGE_TABLE_INV;
  371. pmd_val(pmdp[2]) = _PAGE_TABLE_INV;
  372. pmd_val(pmdp[3]) = _PAGE_TABLE_INV;
  373. }
  374. #else /* __s390x__ */
  375. static inline void pgd_clear(pgd_t * pgdp)
  376. {
  377. pgd_val(*pgdp) = _PGD_ENTRY_INV | _PGD_ENTRY;
  378. }
  379. static inline void pmd_clear(pmd_t * pmdp)
  380. {
  381. pmd_val(*pmdp) = _PMD_ENTRY_INV | _PMD_ENTRY;
  382. pmd_val1(*pmdp) = _PMD_ENTRY_INV | _PMD_ENTRY;
  383. }
  384. #endif /* __s390x__ */
  385. static inline void pte_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
  386. {
  387. pte_val(*ptep) = _PAGE_TYPE_EMPTY;
  388. }
  389. /*
  390. * The following pte modification functions only work if
  391. * pte_present() is true. Undefined behaviour if not..
  392. */
  393. static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
  394. {
  395. pte_val(pte) &= PAGE_MASK;
  396. pte_val(pte) |= pgprot_val(newprot);
  397. return pte;
  398. }
  399. static inline pte_t pte_wrprotect(pte_t pte)
  400. {
  401. /* Do not clobber _PAGE_TYPE_NONE pages! */
  402. if (!(pte_val(pte) & _PAGE_INVALID))
  403. pte_val(pte) |= _PAGE_RO;
  404. return pte;
  405. }
  406. static inline pte_t pte_mkwrite(pte_t pte)
  407. {
  408. pte_val(pte) &= ~_PAGE_RO;
  409. return pte;
  410. }
  411. static inline pte_t pte_mkclean(pte_t pte)
  412. {
  413. /* The only user of pte_mkclean is the fork() code.
  414. We must *not* clear the *physical* page dirty bit
  415. just because fork() wants to clear the dirty bit in
  416. *one* of the page's mappings. So we just do nothing. */
  417. return pte;
  418. }
  419. static inline pte_t pte_mkdirty(pte_t pte)
  420. {
  421. /* We do not explicitly set the dirty bit because the
  422. * sske instruction is slow. It is faster to let the
  423. * next instruction set the dirty bit.
  424. */
  425. return pte;
  426. }
  427. static inline pte_t pte_mkold(pte_t pte)
  428. {
  429. /* S/390 doesn't keep its dirty/referenced bit in the pte.
  430. * There is no point in clearing the real referenced bit.
  431. */
  432. return pte;
  433. }
  434. static inline pte_t pte_mkyoung(pte_t pte)
  435. {
  436. /* S/390 doesn't keep its dirty/referenced bit in the pte.
  437. * There is no point in setting the real referenced bit.
  438. */
  439. return pte;
  440. }
  441. static inline int ptep_test_and_clear_young(struct vm_area_struct *vma, unsigned long addr, pte_t *ptep)
  442. {
  443. return 0;
  444. }
  445. static inline int
  446. ptep_clear_flush_young(struct vm_area_struct *vma,
  447. unsigned long address, pte_t *ptep)
  448. {
  449. /* No need to flush TLB; bits are in storage key */
  450. return ptep_test_and_clear_young(vma, address, ptep);
  451. }
  452. static inline int ptep_test_and_clear_dirty(struct vm_area_struct *vma, unsigned long addr, pte_t *ptep)
  453. {
  454. return 0;
  455. }
  456. static inline int
  457. ptep_clear_flush_dirty(struct vm_area_struct *vma,
  458. unsigned long address, pte_t *ptep)
  459. {
  460. /* No need to flush TLB; bits are in storage key */
  461. return ptep_test_and_clear_dirty(vma, address, ptep);
  462. }
  463. static inline pte_t ptep_get_and_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
  464. {
  465. pte_t pte = *ptep;
  466. pte_clear(mm, addr, ptep);
  467. return pte;
  468. }
  469. static inline void __ptep_ipte(unsigned long address, pte_t *ptep)
  470. {
  471. if (!(pte_val(*ptep) & _PAGE_INVALID)) {
  472. #ifndef __s390x__
  473. /* S390 has 1mb segments, we are emulating 4MB segments */
  474. pte_t *pto = (pte_t *) (((unsigned long) ptep) & 0x7ffffc00);
  475. #else
  476. /* ipte in zarch mode can do the math */
  477. pte_t *pto = ptep;
  478. #endif
  479. asm volatile ("ipte %2,%3"
  480. : "=m" (*ptep) : "m" (*ptep),
  481. "a" (pto), "a" (address) );
  482. }
  483. pte_val(*ptep) = _PAGE_TYPE_EMPTY;
  484. }
  485. static inline pte_t
  486. ptep_clear_flush(struct vm_area_struct *vma,
  487. unsigned long address, pte_t *ptep)
  488. {
  489. pte_t pte = *ptep;
  490. __ptep_ipte(address, ptep);
  491. return pte;
  492. }
  493. static inline void ptep_set_wrprotect(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
  494. {
  495. pte_t old_pte = *ptep;
  496. set_pte_at(mm, addr, ptep, pte_wrprotect(old_pte));
  497. }
  498. static inline void
  499. ptep_establish(struct vm_area_struct *vma,
  500. unsigned long address, pte_t *ptep,
  501. pte_t entry)
  502. {
  503. ptep_clear_flush(vma, address, ptep);
  504. set_pte(ptep, entry);
  505. }
  506. #define ptep_set_access_flags(__vma, __address, __ptep, __entry, __dirty) \
  507. ptep_establish(__vma, __address, __ptep, __entry)
  508. /*
  509. * Test and clear dirty bit in storage key.
  510. * We can't clear the changed bit atomically. This is a potential
  511. * race against modification of the referenced bit. This function
  512. * should therefore only be called if it is not mapped in any
  513. * address space.
  514. */
  515. #define page_test_and_clear_dirty(_page) \
  516. ({ \
  517. struct page *__page = (_page); \
  518. unsigned long __physpage = __pa((__page-mem_map) << PAGE_SHIFT); \
  519. int __skey = page_get_storage_key(__physpage); \
  520. if (__skey & _PAGE_CHANGED) \
  521. page_set_storage_key(__physpage, __skey & ~_PAGE_CHANGED);\
  522. (__skey & _PAGE_CHANGED); \
  523. })
  524. /*
  525. * Test and clear referenced bit in storage key.
  526. */
  527. #define page_test_and_clear_young(page) \
  528. ({ \
  529. struct page *__page = (page); \
  530. unsigned long __physpage = __pa((__page-mem_map) << PAGE_SHIFT); \
  531. int __ccode; \
  532. asm volatile ("rrbe 0,%1\n\t" \
  533. "ipm %0\n\t" \
  534. "srl %0,28\n\t" \
  535. : "=d" (__ccode) : "a" (__physpage) : "cc" ); \
  536. (__ccode & 2); \
  537. })
  538. /*
  539. * Conversion functions: convert a page and protection to a page entry,
  540. * and a page entry and page directory to the page they refer to.
  541. */
  542. static inline pte_t mk_pte_phys(unsigned long physpage, pgprot_t pgprot)
  543. {
  544. pte_t __pte;
  545. pte_val(__pte) = physpage + pgprot_val(pgprot);
  546. return __pte;
  547. }
  548. #define mk_pte(pg, pgprot) \
  549. ({ \
  550. struct page *__page = (pg); \
  551. pgprot_t __pgprot = (pgprot); \
  552. unsigned long __physpage = __pa((__page-mem_map) << PAGE_SHIFT); \
  553. pte_t __pte = mk_pte_phys(__physpage, __pgprot); \
  554. __pte; \
  555. })
  556. #define pfn_pte(pfn, pgprot) \
  557. ({ \
  558. pgprot_t __pgprot = (pgprot); \
  559. unsigned long __physpage = __pa((pfn) << PAGE_SHIFT); \
  560. pte_t __pte = mk_pte_phys(__physpage, __pgprot); \
  561. __pte; \
  562. })
  563. #ifdef __s390x__
  564. #define pfn_pmd(pfn, pgprot) \
  565. ({ \
  566. pgprot_t __pgprot = (pgprot); \
  567. unsigned long __physpage = __pa((pfn) << PAGE_SHIFT); \
  568. pmd_t __pmd = __pmd(__physpage + pgprot_val(__pgprot)); \
  569. __pmd; \
  570. })
  571. #endif /* __s390x__ */
  572. #define pte_pfn(x) (pte_val(x) >> PAGE_SHIFT)
  573. #define pte_page(x) pfn_to_page(pte_pfn(x))
  574. #define pmd_page_vaddr(pmd) (pmd_val(pmd) & PAGE_MASK)
  575. #define pmd_page(pmd) (mem_map+(pmd_val(pmd) >> PAGE_SHIFT))
  576. #define pgd_page_vaddr(pgd) (pgd_val(pgd) & PAGE_MASK)
  577. #define pgd_page(pgd) (mem_map+(pgd_val(pgd) >> PAGE_SHIFT))
  578. /* to find an entry in a page-table-directory */
  579. #define pgd_index(address) (((address) >> PGDIR_SHIFT) & (PTRS_PER_PGD-1))
  580. #define pgd_offset(mm, address) ((mm)->pgd+pgd_index(address))
  581. /* to find an entry in a kernel page-table-directory */
  582. #define pgd_offset_k(address) pgd_offset(&init_mm, address)
  583. #ifndef __s390x__
  584. /* Find an entry in the second-level page table.. */
  585. static inline pmd_t * pmd_offset(pgd_t * dir, unsigned long address)
  586. {
  587. return (pmd_t *) dir;
  588. }
  589. #else /* __s390x__ */
  590. /* Find an entry in the second-level page table.. */
  591. #define pmd_index(address) (((address) >> PMD_SHIFT) & (PTRS_PER_PMD-1))
  592. #define pmd_offset(dir,addr) \
  593. ((pmd_t *) pgd_page_vaddr(*(dir)) + pmd_index(addr))
  594. #endif /* __s390x__ */
  595. /* Find an entry in the third-level page table.. */
  596. #define pte_index(address) (((address) >> PAGE_SHIFT) & (PTRS_PER_PTE-1))
  597. #define pte_offset_kernel(pmd, address) \
  598. ((pte_t *) pmd_page_vaddr(*(pmd)) + pte_index(address))
  599. #define pte_offset_map(pmd, address) pte_offset_kernel(pmd, address)
  600. #define pte_offset_map_nested(pmd, address) pte_offset_kernel(pmd, address)
  601. #define pte_unmap(pte) do { } while (0)
  602. #define pte_unmap_nested(pte) do { } while (0)
  603. /*
  604. * 31 bit swap entry format:
  605. * A page-table entry has some bits we have to treat in a special way.
  606. * Bits 0, 20 and bit 23 have to be zero, otherwise an specification
  607. * exception will occur instead of a page translation exception. The
  608. * specifiation exception has the bad habit not to store necessary
  609. * information in the lowcore.
  610. * Bit 21 and bit 22 are the page invalid bit and the page protection
  611. * bit. We set both to indicate a swapped page.
  612. * Bit 30 and 31 are used to distinguish the different page types. For
  613. * a swapped page these bits need to be zero.
  614. * This leaves the bits 1-19 and bits 24-29 to store type and offset.
  615. * We use the 5 bits from 25-29 for the type and the 20 bits from 1-19
  616. * plus 24 for the offset.
  617. * 0| offset |0110|o|type |00|
  618. * 0 0000000001111111111 2222 2 22222 33
  619. * 0 1234567890123456789 0123 4 56789 01
  620. *
  621. * 64 bit swap entry format:
  622. * A page-table entry has some bits we have to treat in a special way.
  623. * Bits 52 and bit 55 have to be zero, otherwise an specification
  624. * exception will occur instead of a page translation exception. The
  625. * specifiation exception has the bad habit not to store necessary
  626. * information in the lowcore.
  627. * Bit 53 and bit 54 are the page invalid bit and the page protection
  628. * bit. We set both to indicate a swapped page.
  629. * Bit 62 and 63 are used to distinguish the different page types. For
  630. * a swapped page these bits need to be zero.
  631. * This leaves the bits 0-51 and bits 56-61 to store type and offset.
  632. * We use the 5 bits from 57-61 for the type and the 53 bits from 0-51
  633. * plus 56 for the offset.
  634. * | offset |0110|o|type |00|
  635. * 0000000000111111111122222222223333333333444444444455 5555 5 55566 66
  636. * 0123456789012345678901234567890123456789012345678901 2345 6 78901 23
  637. */
  638. #ifndef __s390x__
  639. #define __SWP_OFFSET_MASK (~0UL >> 12)
  640. #else
  641. #define __SWP_OFFSET_MASK (~0UL >> 11)
  642. #endif
  643. static inline pte_t mk_swap_pte(unsigned long type, unsigned long offset)
  644. {
  645. pte_t pte;
  646. offset &= __SWP_OFFSET_MASK;
  647. pte_val(pte) = _PAGE_TYPE_SWAP | ((type & 0x1f) << 2) |
  648. ((offset & 1UL) << 7) | ((offset & ~1UL) << 11);
  649. return pte;
  650. }
  651. #define __swp_type(entry) (((entry).val >> 2) & 0x1f)
  652. #define __swp_offset(entry) (((entry).val >> 11) | (((entry).val >> 7) & 1))
  653. #define __swp_entry(type,offset) ((swp_entry_t) { pte_val(mk_swap_pte((type),(offset))) })
  654. #define __pte_to_swp_entry(pte) ((swp_entry_t) { pte_val(pte) })
  655. #define __swp_entry_to_pte(x) ((pte_t) { (x).val })
  656. #ifndef __s390x__
  657. # define PTE_FILE_MAX_BITS 26
  658. #else /* __s390x__ */
  659. # define PTE_FILE_MAX_BITS 59
  660. #endif /* __s390x__ */
  661. #define pte_to_pgoff(__pte) \
  662. ((((__pte).pte >> 12) << 7) + (((__pte).pte >> 1) & 0x7f))
  663. #define pgoff_to_pte(__off) \
  664. ((pte_t) { ((((__off) & 0x7f) << 1) + (((__off) >> 7) << 12)) \
  665. | _PAGE_TYPE_FILE })
  666. #endif /* !__ASSEMBLY__ */
  667. #define kern_addr_valid(addr) (1)
  668. /*
  669. * No page table caches to initialise
  670. */
  671. #define pgtable_cache_init() do { } while (0)
  672. #define __HAVE_ARCH_PTEP_ESTABLISH
  673. #define __HAVE_ARCH_PTEP_SET_ACCESS_FLAGS
  674. #define __HAVE_ARCH_PTEP_TEST_AND_CLEAR_YOUNG
  675. #define __HAVE_ARCH_PTEP_CLEAR_YOUNG_FLUSH
  676. #define __HAVE_ARCH_PTEP_TEST_AND_CLEAR_DIRTY
  677. #define __HAVE_ARCH_PTEP_CLEAR_DIRTY_FLUSH
  678. #define __HAVE_ARCH_PTEP_GET_AND_CLEAR
  679. #define __HAVE_ARCH_PTEP_CLEAR_FLUSH
  680. #define __HAVE_ARCH_PTEP_SET_WRPROTECT
  681. #define __HAVE_ARCH_PTE_SAME
  682. #define __HAVE_ARCH_PAGE_TEST_AND_CLEAR_DIRTY
  683. #define __HAVE_ARCH_PAGE_TEST_AND_CLEAR_YOUNG
  684. #include <asm-generic/pgtable.h>
  685. #endif /* _S390_PAGE_H */