pgtable.h 25 KB

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