pgtable.h 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092
  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. /*
  15. * The Linux memory management assumes a three-level page table setup. For
  16. * s390 31 bit we "fold" the mid level into the top-level page table, so
  17. * that we physically have the same two-level page table as the s390 mmu
  18. * expects in 31 bit mode. For s390 64 bit we use three of the five levels
  19. * the hardware provides (region first and region second tables are not
  20. * used).
  21. *
  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
  24. * into the pgd entry)
  25. *
  26. * This file contains the functions and defines necessary to modify and use
  27. * the S390 page table tree.
  28. */
  29. #ifndef __ASSEMBLY__
  30. #include <linux/mm_types.h>
  31. #include <asm/bitops.h>
  32. #include <asm/bug.h>
  33. #include <asm/processor.h>
  34. extern pgd_t swapper_pg_dir[] __attribute__ ((aligned (4096)));
  35. extern void paging_init(void);
  36. extern void vmem_map_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 20
  56. # define PUD_SHIFT 20
  57. # define PGDIR_SHIFT 20
  58. #else /* __s390x__ */
  59. # define PMD_SHIFT 20
  60. # define PUD_SHIFT 31
  61. # define PGDIR_SHIFT 42
  62. #endif /* __s390x__ */
  63. #define PMD_SIZE (1UL << PMD_SHIFT)
  64. #define PMD_MASK (~(PMD_SIZE-1))
  65. #define PUD_SIZE (1UL << PUD_SHIFT)
  66. #define PUD_MASK (~(PUD_SIZE-1))
  67. #define PGDIR_SIZE (1UL << PGDIR_SHIFT)
  68. #define PGDIR_MASK (~(PGDIR_SIZE-1))
  69. /*
  70. * entries per page directory level: the S390 is two-level, so
  71. * we don't really have any PMD directory physically.
  72. * for S390 segment-table entries are combined to one PGD
  73. * that leads to 1024 pte per pgd
  74. */
  75. #define PTRS_PER_PTE 256
  76. #ifndef __s390x__
  77. #define PTRS_PER_PMD 1
  78. #define PTRS_PER_PUD 1
  79. #else /* __s390x__ */
  80. #define PTRS_PER_PMD 2048
  81. #define PTRS_PER_PUD 2048
  82. #endif /* __s390x__ */
  83. #define PTRS_PER_PGD 2048
  84. #define FIRST_USER_ADDRESS 0
  85. #define pte_ERROR(e) \
  86. printk("%s:%d: bad pte %p.\n", __FILE__, __LINE__, (void *) pte_val(e))
  87. #define pmd_ERROR(e) \
  88. printk("%s:%d: bad pmd %p.\n", __FILE__, __LINE__, (void *) pmd_val(e))
  89. #define pud_ERROR(e) \
  90. printk("%s:%d: bad pud %p.\n", __FILE__, __LINE__, (void *) pud_val(e))
  91. #define pgd_ERROR(e) \
  92. printk("%s:%d: bad pgd %p.\n", __FILE__, __LINE__, (void *) pgd_val(e))
  93. #ifndef __ASSEMBLY__
  94. /*
  95. * The vmalloc area will always be on the topmost area of the kernel
  96. * mapping. We reserve 96MB (31bit) / 1GB (64bit) for vmalloc,
  97. * which should be enough for any sane case.
  98. * By putting vmalloc at the top, we maximise the gap between physical
  99. * memory and vmalloc to catch misplaced memory accesses. As a side
  100. * effect, this also makes sure that 64 bit module code cannot be used
  101. * as system call address.
  102. */
  103. #ifndef __s390x__
  104. #define VMALLOC_START 0x78000000UL
  105. #define VMALLOC_END 0x7e000000UL
  106. #define VMEM_MAP_END 0x80000000UL
  107. #else /* __s390x__ */
  108. #define VMALLOC_START 0x3e000000000UL
  109. #define VMALLOC_END 0x3e040000000UL
  110. #define VMEM_MAP_END 0x40000000000UL
  111. #endif /* __s390x__ */
  112. /*
  113. * VMEM_MAX_PHYS is the highest physical address that can be added to the 1:1
  114. * mapping. This needs to be calculated at compile time since the size of the
  115. * VMEM_MAP is static but the size of struct page can change.
  116. */
  117. #define VMEM_MAX_PAGES ((VMEM_MAP_END - VMALLOC_END) / sizeof(struct page))
  118. #define VMEM_MAX_PFN min(VMALLOC_START >> PAGE_SHIFT, VMEM_MAX_PAGES)
  119. #define VMEM_MAX_PHYS ((VMEM_MAX_PFN << PAGE_SHIFT) & ~((16 << 20) - 1))
  120. #define vmemmap ((struct page *) VMALLOC_END)
  121. /*
  122. * A 31 bit pagetable entry of S390 has following format:
  123. * | PFRA | | OS |
  124. * 0 0IP0
  125. * 00000000001111111111222222222233
  126. * 01234567890123456789012345678901
  127. *
  128. * I Page-Invalid Bit: Page is not available for address-translation
  129. * P Page-Protection Bit: Store access not possible for page
  130. *
  131. * A 31 bit segmenttable entry of S390 has following format:
  132. * | P-table origin | |PTL
  133. * 0 IC
  134. * 00000000001111111111222222222233
  135. * 01234567890123456789012345678901
  136. *
  137. * I Segment-Invalid Bit: Segment is not available for address-translation
  138. * C Common-Segment Bit: Segment is not private (PoP 3-30)
  139. * PTL Page-Table-Length: Page-table length (PTL+1*16 entries -> up to 256)
  140. *
  141. * The 31 bit segmenttable origin of S390 has following format:
  142. *
  143. * |S-table origin | | STL |
  144. * X **GPS
  145. * 00000000001111111111222222222233
  146. * 01234567890123456789012345678901
  147. *
  148. * X Space-Switch event:
  149. * G Segment-Invalid Bit: *
  150. * P Private-Space Bit: Segment is not private (PoP 3-30)
  151. * S Storage-Alteration:
  152. * STL Segment-Table-Length: Segment-table length (STL+1*16 entries -> up to 2048)
  153. *
  154. * A 64 bit pagetable entry of S390 has following format:
  155. * | PFRA |0IP0| OS |
  156. * 0000000000111111111122222222223333333333444444444455555555556666
  157. * 0123456789012345678901234567890123456789012345678901234567890123
  158. *
  159. * I Page-Invalid Bit: Page is not available for address-translation
  160. * P Page-Protection Bit: Store access not possible for page
  161. *
  162. * A 64 bit segmenttable entry of S390 has following format:
  163. * | P-table origin | TT
  164. * 0000000000111111111122222222223333333333444444444455555555556666
  165. * 0123456789012345678901234567890123456789012345678901234567890123
  166. *
  167. * I Segment-Invalid Bit: Segment is not available for address-translation
  168. * C Common-Segment Bit: Segment is not private (PoP 3-30)
  169. * P Page-Protection Bit: Store access not possible for page
  170. * TT Type 00
  171. *
  172. * A 64 bit region table entry of S390 has following format:
  173. * | S-table origin | TF TTTL
  174. * 0000000000111111111122222222223333333333444444444455555555556666
  175. * 0123456789012345678901234567890123456789012345678901234567890123
  176. *
  177. * I Segment-Invalid Bit: Segment is not available for address-translation
  178. * TT Type 01
  179. * TF
  180. * TL Table length
  181. *
  182. * The 64 bit regiontable origin of S390 has following format:
  183. * | region table origon | DTTL
  184. * 0000000000111111111122222222223333333333444444444455555555556666
  185. * 0123456789012345678901234567890123456789012345678901234567890123
  186. *
  187. * X Space-Switch event:
  188. * G Segment-Invalid Bit:
  189. * P Private-Space Bit:
  190. * S Storage-Alteration:
  191. * R Real space
  192. * TL Table-Length:
  193. *
  194. * A storage key has the following format:
  195. * | ACC |F|R|C|0|
  196. * 0 3 4 5 6 7
  197. * ACC: access key
  198. * F : fetch protection bit
  199. * R : referenced bit
  200. * C : changed bit
  201. */
  202. /* Hardware bits in the page table entry */
  203. #define _PAGE_RO 0x200 /* HW read-only bit */
  204. #define _PAGE_INVALID 0x400 /* HW invalid bit */
  205. /* Software bits in the page table entry */
  206. #define _PAGE_SWT 0x001 /* SW pte type bit t */
  207. #define _PAGE_SWX 0x002 /* SW pte type bit x */
  208. #define _PAGE_SPECIAL 0x004 /* SW associated with special page */
  209. #define __HAVE_ARCH_PTE_SPECIAL
  210. /* Set of bits not changed in pte_modify */
  211. #define _PAGE_CHG_MASK (PAGE_MASK | _PAGE_SPECIAL)
  212. /* Six different types of pages. */
  213. #define _PAGE_TYPE_EMPTY 0x400
  214. #define _PAGE_TYPE_NONE 0x401
  215. #define _PAGE_TYPE_SWAP 0x403
  216. #define _PAGE_TYPE_FILE 0x601 /* bit 0x002 is used for offset !! */
  217. #define _PAGE_TYPE_RO 0x200
  218. #define _PAGE_TYPE_RW 0x000
  219. #define _PAGE_TYPE_EX_RO 0x202
  220. #define _PAGE_TYPE_EX_RW 0x002
  221. /*
  222. * Only four types for huge pages, using the invalid bit and protection bit
  223. * of a segment table entry.
  224. */
  225. #define _HPAGE_TYPE_EMPTY 0x020 /* _SEGMENT_ENTRY_INV */
  226. #define _HPAGE_TYPE_NONE 0x220
  227. #define _HPAGE_TYPE_RO 0x200 /* _SEGMENT_ENTRY_RO */
  228. #define _HPAGE_TYPE_RW 0x000
  229. /*
  230. * PTE type bits are rather complicated. handle_pte_fault uses pte_present,
  231. * pte_none and pte_file to find out the pte type WITHOUT holding the page
  232. * table lock. ptep_clear_flush on the other hand uses ptep_clear_flush to
  233. * invalidate a given pte. ipte sets the hw invalid bit and clears all tlbs
  234. * for the page. The page table entry is set to _PAGE_TYPE_EMPTY afterwards.
  235. * This change is done while holding the lock, but the intermediate step
  236. * of a previously valid pte with the hw invalid bit set can be observed by
  237. * handle_pte_fault. That makes it necessary that all valid pte types with
  238. * the hw invalid bit set must be distinguishable from the four pte types
  239. * empty, none, swap and file.
  240. *
  241. * irxt ipte irxt
  242. * _PAGE_TYPE_EMPTY 1000 -> 1000
  243. * _PAGE_TYPE_NONE 1001 -> 1001
  244. * _PAGE_TYPE_SWAP 1011 -> 1011
  245. * _PAGE_TYPE_FILE 11?1 -> 11?1
  246. * _PAGE_TYPE_RO 0100 -> 1100
  247. * _PAGE_TYPE_RW 0000 -> 1000
  248. * _PAGE_TYPE_EX_RO 0110 -> 1110
  249. * _PAGE_TYPE_EX_RW 0010 -> 1010
  250. *
  251. * pte_none is true for bits combinations 1000, 1010, 1100, 1110
  252. * pte_present is true for bits combinations 0000, 0010, 0100, 0110, 1001
  253. * pte_file is true for bits combinations 1101, 1111
  254. * swap pte is 1011 and 0001, 0011, 0101, 0111 are invalid.
  255. */
  256. /* Page status table bits for virtualization */
  257. #define RCP_PCL_BIT 55
  258. #define RCP_HR_BIT 54
  259. #define RCP_HC_BIT 53
  260. #define RCP_GR_BIT 50
  261. #define RCP_GC_BIT 49
  262. #ifndef __s390x__
  263. /* Bits in the segment table address-space-control-element */
  264. #define _ASCE_SPACE_SWITCH 0x80000000UL /* space switch event */
  265. #define _ASCE_ORIGIN_MASK 0x7ffff000UL /* segment table origin */
  266. #define _ASCE_PRIVATE_SPACE 0x100 /* private space control */
  267. #define _ASCE_ALT_EVENT 0x80 /* storage alteration event control */
  268. #define _ASCE_TABLE_LENGTH 0x7f /* 128 x 64 entries = 8k */
  269. /* Bits in the segment table entry */
  270. #define _SEGMENT_ENTRY_ORIGIN 0x7fffffc0UL /* page table origin */
  271. #define _SEGMENT_ENTRY_INV 0x20 /* invalid segment table entry */
  272. #define _SEGMENT_ENTRY_COMMON 0x10 /* common segment bit */
  273. #define _SEGMENT_ENTRY_PTL 0x0f /* page table length */
  274. #define _SEGMENT_ENTRY (_SEGMENT_ENTRY_PTL)
  275. #define _SEGMENT_ENTRY_EMPTY (_SEGMENT_ENTRY_INV)
  276. #else /* __s390x__ */
  277. /* Bits in the segment/region table address-space-control-element */
  278. #define _ASCE_ORIGIN ~0xfffUL/* segment table origin */
  279. #define _ASCE_PRIVATE_SPACE 0x100 /* private space control */
  280. #define _ASCE_ALT_EVENT 0x80 /* storage alteration event control */
  281. #define _ASCE_SPACE_SWITCH 0x40 /* space switch event */
  282. #define _ASCE_REAL_SPACE 0x20 /* real space control */
  283. #define _ASCE_TYPE_MASK 0x0c /* asce table type mask */
  284. #define _ASCE_TYPE_REGION1 0x0c /* region first table type */
  285. #define _ASCE_TYPE_REGION2 0x08 /* region second table type */
  286. #define _ASCE_TYPE_REGION3 0x04 /* region third table type */
  287. #define _ASCE_TYPE_SEGMENT 0x00 /* segment table type */
  288. #define _ASCE_TABLE_LENGTH 0x03 /* region table length */
  289. /* Bits in the region table entry */
  290. #define _REGION_ENTRY_ORIGIN ~0xfffUL/* region/segment table origin */
  291. #define _REGION_ENTRY_INV 0x20 /* invalid region table entry */
  292. #define _REGION_ENTRY_TYPE_MASK 0x0c /* region/segment table type mask */
  293. #define _REGION_ENTRY_TYPE_R1 0x0c /* region first table type */
  294. #define _REGION_ENTRY_TYPE_R2 0x08 /* region second table type */
  295. #define _REGION_ENTRY_TYPE_R3 0x04 /* region third table type */
  296. #define _REGION_ENTRY_LENGTH 0x03 /* region third length */
  297. #define _REGION1_ENTRY (_REGION_ENTRY_TYPE_R1 | _REGION_ENTRY_LENGTH)
  298. #define _REGION1_ENTRY_EMPTY (_REGION_ENTRY_TYPE_R1 | _REGION_ENTRY_INV)
  299. #define _REGION2_ENTRY (_REGION_ENTRY_TYPE_R2 | _REGION_ENTRY_LENGTH)
  300. #define _REGION2_ENTRY_EMPTY (_REGION_ENTRY_TYPE_R2 | _REGION_ENTRY_INV)
  301. #define _REGION3_ENTRY (_REGION_ENTRY_TYPE_R3 | _REGION_ENTRY_LENGTH)
  302. #define _REGION3_ENTRY_EMPTY (_REGION_ENTRY_TYPE_R3 | _REGION_ENTRY_INV)
  303. /* Bits in the segment table entry */
  304. #define _SEGMENT_ENTRY_ORIGIN ~0x7ffUL/* segment table origin */
  305. #define _SEGMENT_ENTRY_RO 0x200 /* page protection bit */
  306. #define _SEGMENT_ENTRY_INV 0x20 /* invalid segment table entry */
  307. #define _SEGMENT_ENTRY (0)
  308. #define _SEGMENT_ENTRY_EMPTY (_SEGMENT_ENTRY_INV)
  309. #define _SEGMENT_ENTRY_LARGE 0x400 /* STE-format control, large page */
  310. #define _SEGMENT_ENTRY_CO 0x100 /* change-recording override */
  311. #endif /* __s390x__ */
  312. /*
  313. * A user page table pointer has the space-switch-event bit, the
  314. * private-space-control bit and the storage-alteration-event-control
  315. * bit set. A kernel page table pointer doesn't need them.
  316. */
  317. #define _ASCE_USER_BITS (_ASCE_SPACE_SWITCH | _ASCE_PRIVATE_SPACE | \
  318. _ASCE_ALT_EVENT)
  319. /* Bits int the storage key */
  320. #define _PAGE_CHANGED 0x02 /* HW changed bit */
  321. #define _PAGE_REFERENCED 0x04 /* HW referenced bit */
  322. /*
  323. * Page protection definitions.
  324. */
  325. #define PAGE_NONE __pgprot(_PAGE_TYPE_NONE)
  326. #define PAGE_RO __pgprot(_PAGE_TYPE_RO)
  327. #define PAGE_RW __pgprot(_PAGE_TYPE_RW)
  328. #define PAGE_EX_RO __pgprot(_PAGE_TYPE_EX_RO)
  329. #define PAGE_EX_RW __pgprot(_PAGE_TYPE_EX_RW)
  330. #define PAGE_KERNEL PAGE_RW
  331. #define PAGE_COPY PAGE_RO
  332. /*
  333. * Dependent on the EXEC_PROTECT option s390 can do execute protection.
  334. * Write permission always implies read permission. In theory with a
  335. * primary/secondary page table execute only can be implemented but
  336. * it would cost an additional bit in the pte to distinguish all the
  337. * different pte types. To avoid that execute permission currently
  338. * implies read permission as well.
  339. */
  340. /*xwr*/
  341. #define __P000 PAGE_NONE
  342. #define __P001 PAGE_RO
  343. #define __P010 PAGE_RO
  344. #define __P011 PAGE_RO
  345. #define __P100 PAGE_EX_RO
  346. #define __P101 PAGE_EX_RO
  347. #define __P110 PAGE_EX_RO
  348. #define __P111 PAGE_EX_RO
  349. #define __S000 PAGE_NONE
  350. #define __S001 PAGE_RO
  351. #define __S010 PAGE_RW
  352. #define __S011 PAGE_RW
  353. #define __S100 PAGE_EX_RO
  354. #define __S101 PAGE_EX_RO
  355. #define __S110 PAGE_EX_RW
  356. #define __S111 PAGE_EX_RW
  357. #ifndef __s390x__
  358. # define PxD_SHADOW_SHIFT 1
  359. #else /* __s390x__ */
  360. # define PxD_SHADOW_SHIFT 2
  361. #endif /* __s390x__ */
  362. static inline void *get_shadow_table(void *table)
  363. {
  364. unsigned long addr, offset;
  365. struct page *page;
  366. addr = (unsigned long) table;
  367. offset = addr & ((PAGE_SIZE << PxD_SHADOW_SHIFT) - 1);
  368. page = virt_to_page((void *)(addr ^ offset));
  369. return (void *)(addr_t)(page->index ? (page->index | offset) : 0UL);
  370. }
  371. /*
  372. * Certain architectures need to do special things when PTEs
  373. * within a page table are directly modified. Thus, the following
  374. * hook is made available.
  375. */
  376. static inline void set_pte_at(struct mm_struct *mm, unsigned long addr,
  377. pte_t *ptep, pte_t entry)
  378. {
  379. *ptep = entry;
  380. if (mm->context.noexec) {
  381. if (!(pte_val(entry) & _PAGE_INVALID) &&
  382. (pte_val(entry) & _PAGE_SWX))
  383. pte_val(entry) |= _PAGE_RO;
  384. else
  385. pte_val(entry) = _PAGE_TYPE_EMPTY;
  386. ptep[PTRS_PER_PTE] = entry;
  387. }
  388. }
  389. /*
  390. * pgd/pmd/pte query functions
  391. */
  392. #ifndef __s390x__
  393. static inline int pgd_present(pgd_t pgd) { return 1; }
  394. static inline int pgd_none(pgd_t pgd) { return 0; }
  395. static inline int pgd_bad(pgd_t pgd) { return 0; }
  396. static inline int pud_present(pud_t pud) { return 1; }
  397. static inline int pud_none(pud_t pud) { return 0; }
  398. static inline int pud_bad(pud_t pud) { return 0; }
  399. #else /* __s390x__ */
  400. static inline int pgd_present(pgd_t pgd)
  401. {
  402. if ((pgd_val(pgd) & _REGION_ENTRY_TYPE_MASK) < _REGION_ENTRY_TYPE_R2)
  403. return 1;
  404. return (pgd_val(pgd) & _REGION_ENTRY_ORIGIN) != 0UL;
  405. }
  406. static inline int pgd_none(pgd_t pgd)
  407. {
  408. if ((pgd_val(pgd) & _REGION_ENTRY_TYPE_MASK) < _REGION_ENTRY_TYPE_R2)
  409. return 0;
  410. return (pgd_val(pgd) & _REGION_ENTRY_INV) != 0UL;
  411. }
  412. static inline int pgd_bad(pgd_t pgd)
  413. {
  414. /*
  415. * With dynamic page table levels the pgd can be a region table
  416. * entry or a segment table entry. Check for the bit that are
  417. * invalid for either table entry.
  418. */
  419. unsigned long mask =
  420. ~_SEGMENT_ENTRY_ORIGIN & ~_REGION_ENTRY_INV &
  421. ~_REGION_ENTRY_TYPE_MASK & ~_REGION_ENTRY_LENGTH;
  422. return (pgd_val(pgd) & mask) != 0;
  423. }
  424. static inline int pud_present(pud_t pud)
  425. {
  426. if ((pud_val(pud) & _REGION_ENTRY_TYPE_MASK) < _REGION_ENTRY_TYPE_R3)
  427. return 1;
  428. return (pud_val(pud) & _REGION_ENTRY_ORIGIN) != 0UL;
  429. }
  430. static inline int pud_none(pud_t pud)
  431. {
  432. if ((pud_val(pud) & _REGION_ENTRY_TYPE_MASK) < _REGION_ENTRY_TYPE_R3)
  433. return 0;
  434. return (pud_val(pud) & _REGION_ENTRY_INV) != 0UL;
  435. }
  436. static inline int pud_bad(pud_t pud)
  437. {
  438. /*
  439. * With dynamic page table levels the pud can be a region table
  440. * entry or a segment table entry. Check for the bit that are
  441. * invalid for either table entry.
  442. */
  443. unsigned long mask =
  444. ~_SEGMENT_ENTRY_ORIGIN & ~_REGION_ENTRY_INV &
  445. ~_REGION_ENTRY_TYPE_MASK & ~_REGION_ENTRY_LENGTH;
  446. return (pud_val(pud) & mask) != 0;
  447. }
  448. #endif /* __s390x__ */
  449. static inline int pmd_present(pmd_t pmd)
  450. {
  451. return (pmd_val(pmd) & _SEGMENT_ENTRY_ORIGIN) != 0UL;
  452. }
  453. static inline int pmd_none(pmd_t pmd)
  454. {
  455. return (pmd_val(pmd) & _SEGMENT_ENTRY_INV) != 0UL;
  456. }
  457. static inline int pmd_bad(pmd_t pmd)
  458. {
  459. unsigned long mask = ~_SEGMENT_ENTRY_ORIGIN & ~_SEGMENT_ENTRY_INV;
  460. return (pmd_val(pmd) & mask) != _SEGMENT_ENTRY;
  461. }
  462. static inline int pte_none(pte_t pte)
  463. {
  464. return (pte_val(pte) & _PAGE_INVALID) && !(pte_val(pte) & _PAGE_SWT);
  465. }
  466. static inline int pte_present(pte_t pte)
  467. {
  468. unsigned long mask = _PAGE_RO | _PAGE_INVALID | _PAGE_SWT | _PAGE_SWX;
  469. return (pte_val(pte) & mask) == _PAGE_TYPE_NONE ||
  470. (!(pte_val(pte) & _PAGE_INVALID) &&
  471. !(pte_val(pte) & _PAGE_SWT));
  472. }
  473. static inline int pte_file(pte_t pte)
  474. {
  475. unsigned long mask = _PAGE_RO | _PAGE_INVALID | _PAGE_SWT;
  476. return (pte_val(pte) & mask) == _PAGE_TYPE_FILE;
  477. }
  478. static inline int pte_special(pte_t pte)
  479. {
  480. return (pte_val(pte) & _PAGE_SPECIAL);
  481. }
  482. #define __HAVE_ARCH_PTE_SAME
  483. #define pte_same(a,b) (pte_val(a) == pte_val(b))
  484. static inline void rcp_lock(pte_t *ptep)
  485. {
  486. #ifdef CONFIG_PGSTE
  487. unsigned long *pgste = (unsigned long *) (ptep + PTRS_PER_PTE);
  488. preempt_disable();
  489. while (test_and_set_bit(RCP_PCL_BIT, pgste))
  490. ;
  491. #endif
  492. }
  493. static inline void rcp_unlock(pte_t *ptep)
  494. {
  495. #ifdef CONFIG_PGSTE
  496. unsigned long *pgste = (unsigned long *) (ptep + PTRS_PER_PTE);
  497. clear_bit(RCP_PCL_BIT, pgste);
  498. preempt_enable();
  499. #endif
  500. }
  501. /* forward declaration for SetPageUptodate in page-flags.h*/
  502. static inline void page_clear_dirty(struct page *page);
  503. #include <linux/page-flags.h>
  504. static inline void ptep_rcp_copy(pte_t *ptep)
  505. {
  506. #ifdef CONFIG_PGSTE
  507. struct page *page = virt_to_page(pte_val(*ptep));
  508. unsigned int skey;
  509. unsigned long *pgste = (unsigned long *) (ptep + PTRS_PER_PTE);
  510. skey = page_get_storage_key(page_to_phys(page));
  511. if (skey & _PAGE_CHANGED)
  512. set_bit_simple(RCP_GC_BIT, pgste);
  513. if (skey & _PAGE_REFERENCED)
  514. set_bit_simple(RCP_GR_BIT, pgste);
  515. if (test_and_clear_bit_simple(RCP_HC_BIT, pgste))
  516. SetPageDirty(page);
  517. if (test_and_clear_bit_simple(RCP_HR_BIT, pgste))
  518. SetPageReferenced(page);
  519. #endif
  520. }
  521. /*
  522. * query functions pte_write/pte_dirty/pte_young only work if
  523. * pte_present() is true. Undefined behaviour if not..
  524. */
  525. static inline int pte_write(pte_t pte)
  526. {
  527. return (pte_val(pte) & _PAGE_RO) == 0;
  528. }
  529. static inline int pte_dirty(pte_t pte)
  530. {
  531. /* A pte is neither clean nor dirty on s/390. The dirty bit
  532. * is in the storage key. See page_test_and_clear_dirty for
  533. * details.
  534. */
  535. return 0;
  536. }
  537. static inline int pte_young(pte_t pte)
  538. {
  539. /* A pte is neither young nor old on s/390. The young bit
  540. * is in the storage key. See page_test_and_clear_young for
  541. * details.
  542. */
  543. return 0;
  544. }
  545. /*
  546. * pgd/pmd/pte modification functions
  547. */
  548. #ifndef __s390x__
  549. #define pgd_clear(pgd) do { } while (0)
  550. #define pud_clear(pud) do { } while (0)
  551. #else /* __s390x__ */
  552. static inline void pgd_clear_kernel(pgd_t * pgd)
  553. {
  554. if ((pgd_val(*pgd) & _REGION_ENTRY_TYPE_MASK) == _REGION_ENTRY_TYPE_R2)
  555. pgd_val(*pgd) = _REGION2_ENTRY_EMPTY;
  556. }
  557. static inline void pgd_clear(pgd_t * pgd)
  558. {
  559. pgd_t *shadow = get_shadow_table(pgd);
  560. pgd_clear_kernel(pgd);
  561. if (shadow)
  562. pgd_clear_kernel(shadow);
  563. }
  564. static inline void pud_clear_kernel(pud_t *pud)
  565. {
  566. if ((pud_val(*pud) & _REGION_ENTRY_TYPE_MASK) == _REGION_ENTRY_TYPE_R3)
  567. pud_val(*pud) = _REGION3_ENTRY_EMPTY;
  568. }
  569. static inline void pud_clear(pud_t *pud)
  570. {
  571. pud_t *shadow = get_shadow_table(pud);
  572. pud_clear_kernel(pud);
  573. if (shadow)
  574. pud_clear_kernel(shadow);
  575. }
  576. #endif /* __s390x__ */
  577. static inline void pmd_clear_kernel(pmd_t * pmdp)
  578. {
  579. pmd_val(*pmdp) = _SEGMENT_ENTRY_EMPTY;
  580. }
  581. static inline void pmd_clear(pmd_t *pmd)
  582. {
  583. pmd_t *shadow = get_shadow_table(pmd);
  584. pmd_clear_kernel(pmd);
  585. if (shadow)
  586. pmd_clear_kernel(shadow);
  587. }
  588. static inline void pte_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
  589. {
  590. if (mm->context.pgstes)
  591. ptep_rcp_copy(ptep);
  592. pte_val(*ptep) = _PAGE_TYPE_EMPTY;
  593. if (mm->context.noexec)
  594. pte_val(ptep[PTRS_PER_PTE]) = _PAGE_TYPE_EMPTY;
  595. }
  596. /*
  597. * The following pte modification functions only work if
  598. * pte_present() is true. Undefined behaviour if not..
  599. */
  600. static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
  601. {
  602. pte_val(pte) &= _PAGE_CHG_MASK;
  603. pte_val(pte) |= pgprot_val(newprot);
  604. return pte;
  605. }
  606. static inline pte_t pte_wrprotect(pte_t pte)
  607. {
  608. /* Do not clobber _PAGE_TYPE_NONE pages! */
  609. if (!(pte_val(pte) & _PAGE_INVALID))
  610. pte_val(pte) |= _PAGE_RO;
  611. return pte;
  612. }
  613. static inline pte_t pte_mkwrite(pte_t pte)
  614. {
  615. pte_val(pte) &= ~_PAGE_RO;
  616. return pte;
  617. }
  618. static inline pte_t pte_mkclean(pte_t pte)
  619. {
  620. /* The only user of pte_mkclean is the fork() code.
  621. We must *not* clear the *physical* page dirty bit
  622. just because fork() wants to clear the dirty bit in
  623. *one* of the page's mappings. So we just do nothing. */
  624. return pte;
  625. }
  626. static inline pte_t pte_mkdirty(pte_t pte)
  627. {
  628. /* We do not explicitly set the dirty bit because the
  629. * sske instruction is slow. It is faster to let the
  630. * next instruction set the dirty bit.
  631. */
  632. return pte;
  633. }
  634. static inline pte_t pte_mkold(pte_t pte)
  635. {
  636. /* S/390 doesn't keep its dirty/referenced bit in the pte.
  637. * There is no point in clearing the real referenced bit.
  638. */
  639. return pte;
  640. }
  641. static inline pte_t pte_mkyoung(pte_t pte)
  642. {
  643. /* S/390 doesn't keep its dirty/referenced bit in the pte.
  644. * There is no point in setting the real referenced bit.
  645. */
  646. return pte;
  647. }
  648. static inline pte_t pte_mkspecial(pte_t pte)
  649. {
  650. pte_val(pte) |= _PAGE_SPECIAL;
  651. return pte;
  652. }
  653. #define __HAVE_ARCH_PTEP_TEST_AND_CLEAR_YOUNG
  654. static inline int ptep_test_and_clear_young(struct vm_area_struct *vma,
  655. unsigned long addr, pte_t *ptep)
  656. {
  657. #ifdef CONFIG_PGSTE
  658. unsigned long physpage;
  659. int young;
  660. unsigned long *pgste;
  661. if (!vma->vm_mm->context.pgstes)
  662. return 0;
  663. physpage = pte_val(*ptep) & PAGE_MASK;
  664. pgste = (unsigned long *) (ptep + PTRS_PER_PTE);
  665. young = ((page_get_storage_key(physpage) & _PAGE_REFERENCED) != 0);
  666. rcp_lock(ptep);
  667. if (young)
  668. set_bit_simple(RCP_GR_BIT, pgste);
  669. young |= test_and_clear_bit_simple(RCP_HR_BIT, pgste);
  670. rcp_unlock(ptep);
  671. return young;
  672. #endif
  673. return 0;
  674. }
  675. #define __HAVE_ARCH_PTEP_CLEAR_YOUNG_FLUSH
  676. static inline int ptep_clear_flush_young(struct vm_area_struct *vma,
  677. unsigned long address, pte_t *ptep)
  678. {
  679. /* No need to flush TLB
  680. * On s390 reference bits are in storage key and never in TLB
  681. * With virtualization we handle the reference bit, without we
  682. * we can simply return */
  683. #ifdef CONFIG_PGSTE
  684. return ptep_test_and_clear_young(vma, address, ptep);
  685. #endif
  686. return 0;
  687. }
  688. static inline void __ptep_ipte(unsigned long address, pte_t *ptep)
  689. {
  690. if (!(pte_val(*ptep) & _PAGE_INVALID)) {
  691. #ifndef __s390x__
  692. /* pto must point to the start of the segment table */
  693. pte_t *pto = (pte_t *) (((unsigned long) ptep) & 0x7ffffc00);
  694. #else
  695. /* ipte in zarch mode can do the math */
  696. pte_t *pto = ptep;
  697. #endif
  698. asm volatile(
  699. " ipte %2,%3"
  700. : "=m" (*ptep) : "m" (*ptep),
  701. "a" (pto), "a" (address));
  702. }
  703. }
  704. static inline void ptep_invalidate(struct mm_struct *mm,
  705. unsigned long address, pte_t *ptep)
  706. {
  707. if (mm->context.pgstes) {
  708. rcp_lock(ptep);
  709. __ptep_ipte(address, ptep);
  710. ptep_rcp_copy(ptep);
  711. pte_val(*ptep) = _PAGE_TYPE_EMPTY;
  712. rcp_unlock(ptep);
  713. return;
  714. }
  715. __ptep_ipte(address, ptep);
  716. pte_val(*ptep) = _PAGE_TYPE_EMPTY;
  717. if (mm->context.noexec) {
  718. __ptep_ipte(address, ptep + PTRS_PER_PTE);
  719. pte_val(*(ptep + PTRS_PER_PTE)) = _PAGE_TYPE_EMPTY;
  720. }
  721. }
  722. /*
  723. * This is hard to understand. ptep_get_and_clear and ptep_clear_flush
  724. * both clear the TLB for the unmapped pte. The reason is that
  725. * ptep_get_and_clear is used in common code (e.g. change_pte_range)
  726. * to modify an active pte. The sequence is
  727. * 1) ptep_get_and_clear
  728. * 2) set_pte_at
  729. * 3) flush_tlb_range
  730. * On s390 the tlb needs to get flushed with the modification of the pte
  731. * if the pte is active. The only way how this can be implemented is to
  732. * have ptep_get_and_clear do the tlb flush. In exchange flush_tlb_range
  733. * is a nop.
  734. */
  735. #define __HAVE_ARCH_PTEP_GET_AND_CLEAR
  736. #define ptep_get_and_clear(__mm, __address, __ptep) \
  737. ({ \
  738. pte_t __pte = *(__ptep); \
  739. if (atomic_read(&(__mm)->mm_users) > 1 || \
  740. (__mm) != current->active_mm) \
  741. ptep_invalidate(__mm, __address, __ptep); \
  742. else \
  743. pte_clear((__mm), (__address), (__ptep)); \
  744. __pte; \
  745. })
  746. #define __HAVE_ARCH_PTEP_CLEAR_FLUSH
  747. static inline pte_t ptep_clear_flush(struct vm_area_struct *vma,
  748. unsigned long address, pte_t *ptep)
  749. {
  750. pte_t pte = *ptep;
  751. ptep_invalidate(vma->vm_mm, address, ptep);
  752. return pte;
  753. }
  754. /*
  755. * The batched pte unmap code uses ptep_get_and_clear_full to clear the
  756. * ptes. Here an optimization is possible. tlb_gather_mmu flushes all
  757. * tlbs of an mm if it can guarantee that the ptes of the mm_struct
  758. * cannot be accessed while the batched unmap is running. In this case
  759. * full==1 and a simple pte_clear is enough. See tlb.h.
  760. */
  761. #define __HAVE_ARCH_PTEP_GET_AND_CLEAR_FULL
  762. static inline pte_t ptep_get_and_clear_full(struct mm_struct *mm,
  763. unsigned long addr,
  764. pte_t *ptep, int full)
  765. {
  766. pte_t pte = *ptep;
  767. if (full)
  768. pte_clear(mm, addr, ptep);
  769. else
  770. ptep_invalidate(mm, addr, ptep);
  771. return pte;
  772. }
  773. #define __HAVE_ARCH_PTEP_SET_WRPROTECT
  774. #define ptep_set_wrprotect(__mm, __addr, __ptep) \
  775. ({ \
  776. pte_t __pte = *(__ptep); \
  777. if (pte_write(__pte)) { \
  778. if (atomic_read(&(__mm)->mm_users) > 1 || \
  779. (__mm) != current->active_mm) \
  780. ptep_invalidate(__mm, __addr, __ptep); \
  781. set_pte_at(__mm, __addr, __ptep, pte_wrprotect(__pte)); \
  782. } \
  783. })
  784. #define __HAVE_ARCH_PTEP_SET_ACCESS_FLAGS
  785. #define ptep_set_access_flags(__vma, __addr, __ptep, __entry, __dirty) \
  786. ({ \
  787. int __changed = !pte_same(*(__ptep), __entry); \
  788. if (__changed) { \
  789. ptep_invalidate((__vma)->vm_mm, __addr, __ptep); \
  790. set_pte_at((__vma)->vm_mm, __addr, __ptep, __entry); \
  791. } \
  792. __changed; \
  793. })
  794. /*
  795. * Test and clear dirty bit in storage key.
  796. * We can't clear the changed bit atomically. This is a potential
  797. * race against modification of the referenced bit. This function
  798. * should therefore only be called if it is not mapped in any
  799. * address space.
  800. */
  801. #define __HAVE_ARCH_PAGE_TEST_DIRTY
  802. static inline int page_test_dirty(struct page *page)
  803. {
  804. return (page_get_storage_key(page_to_phys(page)) & _PAGE_CHANGED) != 0;
  805. }
  806. #define __HAVE_ARCH_PAGE_CLEAR_DIRTY
  807. static inline void page_clear_dirty(struct page *page)
  808. {
  809. page_set_storage_key(page_to_phys(page), PAGE_DEFAULT_KEY);
  810. }
  811. /*
  812. * Test and clear referenced bit in storage key.
  813. */
  814. #define __HAVE_ARCH_PAGE_TEST_AND_CLEAR_YOUNG
  815. static inline int page_test_and_clear_young(struct page *page)
  816. {
  817. unsigned long physpage = page_to_phys(page);
  818. int ccode;
  819. asm volatile(
  820. " rrbe 0,%1\n"
  821. " ipm %0\n"
  822. " srl %0,28\n"
  823. : "=d" (ccode) : "a" (physpage) : "cc" );
  824. return ccode & 2;
  825. }
  826. /*
  827. * Conversion functions: convert a page and protection to a page entry,
  828. * and a page entry and page directory to the page they refer to.
  829. */
  830. static inline pte_t mk_pte_phys(unsigned long physpage, pgprot_t pgprot)
  831. {
  832. pte_t __pte;
  833. pte_val(__pte) = physpage + pgprot_val(pgprot);
  834. return __pte;
  835. }
  836. static inline pte_t mk_pte(struct page *page, pgprot_t pgprot)
  837. {
  838. unsigned long physpage = page_to_phys(page);
  839. return mk_pte_phys(physpage, pgprot);
  840. }
  841. #define pgd_index(address) (((address) >> PGDIR_SHIFT) & (PTRS_PER_PGD-1))
  842. #define pud_index(address) (((address) >> PUD_SHIFT) & (PTRS_PER_PUD-1))
  843. #define pmd_index(address) (((address) >> PMD_SHIFT) & (PTRS_PER_PMD-1))
  844. #define pte_index(address) (((address) >> PAGE_SHIFT) & (PTRS_PER_PTE-1))
  845. #define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
  846. #define pgd_offset_k(address) pgd_offset(&init_mm, address)
  847. #ifndef __s390x__
  848. #define pmd_deref(pmd) (pmd_val(pmd) & _SEGMENT_ENTRY_ORIGIN)
  849. #define pud_deref(pmd) ({ BUG(); 0UL; })
  850. #define pgd_deref(pmd) ({ BUG(); 0UL; })
  851. #define pud_offset(pgd, address) ((pud_t *) pgd)
  852. #define pmd_offset(pud, address) ((pmd_t *) pud + pmd_index(address))
  853. #else /* __s390x__ */
  854. #define pmd_deref(pmd) (pmd_val(pmd) & _SEGMENT_ENTRY_ORIGIN)
  855. #define pud_deref(pud) (pud_val(pud) & _REGION_ENTRY_ORIGIN)
  856. #define pgd_deref(pgd) (pgd_val(pgd) & _REGION_ENTRY_ORIGIN)
  857. static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
  858. {
  859. pud_t *pud = (pud_t *) pgd;
  860. if ((pgd_val(*pgd) & _REGION_ENTRY_TYPE_MASK) == _REGION_ENTRY_TYPE_R2)
  861. pud = (pud_t *) pgd_deref(*pgd);
  862. return pud + pud_index(address);
  863. }
  864. static inline pmd_t *pmd_offset(pud_t *pud, unsigned long address)
  865. {
  866. pmd_t *pmd = (pmd_t *) pud;
  867. if ((pud_val(*pud) & _REGION_ENTRY_TYPE_MASK) == _REGION_ENTRY_TYPE_R3)
  868. pmd = (pmd_t *) pud_deref(*pud);
  869. return pmd + pmd_index(address);
  870. }
  871. #endif /* __s390x__ */
  872. #define pfn_pte(pfn,pgprot) mk_pte_phys(__pa((pfn) << PAGE_SHIFT),(pgprot))
  873. #define pte_pfn(x) (pte_val(x) >> PAGE_SHIFT)
  874. #define pte_page(x) pfn_to_page(pte_pfn(x))
  875. #define pmd_page(pmd) pfn_to_page(pmd_val(pmd) >> PAGE_SHIFT)
  876. /* Find an entry in the lowest level page table.. */
  877. #define pte_offset(pmd, addr) ((pte_t *) pmd_deref(*(pmd)) + pte_index(addr))
  878. #define pte_offset_kernel(pmd, address) pte_offset(pmd,address)
  879. #define pte_offset_map(pmd, address) pte_offset_kernel(pmd, address)
  880. #define pte_offset_map_nested(pmd, address) pte_offset_kernel(pmd, address)
  881. #define pte_unmap(pte) do { } while (0)
  882. #define pte_unmap_nested(pte) do { } while (0)
  883. /*
  884. * 31 bit swap entry format:
  885. * A page-table entry has some bits we have to treat in a special way.
  886. * Bits 0, 20 and bit 23 have to be zero, otherwise an specification
  887. * exception will occur instead of a page translation exception. The
  888. * specifiation exception has the bad habit not to store necessary
  889. * information in the lowcore.
  890. * Bit 21 and bit 22 are the page invalid bit and the page protection
  891. * bit. We set both to indicate a swapped page.
  892. * Bit 30 and 31 are used to distinguish the different page types. For
  893. * a swapped page these bits need to be zero.
  894. * This leaves the bits 1-19 and bits 24-29 to store type and offset.
  895. * We use the 5 bits from 25-29 for the type and the 20 bits from 1-19
  896. * plus 24 for the offset.
  897. * 0| offset |0110|o|type |00|
  898. * 0 0000000001111111111 2222 2 22222 33
  899. * 0 1234567890123456789 0123 4 56789 01
  900. *
  901. * 64 bit swap entry format:
  902. * A page-table entry has some bits we have to treat in a special way.
  903. * Bits 52 and bit 55 have to be zero, otherwise an specification
  904. * exception will occur instead of a page translation exception. The
  905. * specifiation exception has the bad habit not to store necessary
  906. * information in the lowcore.
  907. * Bit 53 and bit 54 are the page invalid bit and the page protection
  908. * bit. We set both to indicate a swapped page.
  909. * Bit 62 and 63 are used to distinguish the different page types. For
  910. * a swapped page these bits need to be zero.
  911. * This leaves the bits 0-51 and bits 56-61 to store type and offset.
  912. * We use the 5 bits from 57-61 for the type and the 53 bits from 0-51
  913. * plus 56 for the offset.
  914. * | offset |0110|o|type |00|
  915. * 0000000000111111111122222222223333333333444444444455 5555 5 55566 66
  916. * 0123456789012345678901234567890123456789012345678901 2345 6 78901 23
  917. */
  918. #ifndef __s390x__
  919. #define __SWP_OFFSET_MASK (~0UL >> 12)
  920. #else
  921. #define __SWP_OFFSET_MASK (~0UL >> 11)
  922. #endif
  923. static inline pte_t mk_swap_pte(unsigned long type, unsigned long offset)
  924. {
  925. pte_t pte;
  926. offset &= __SWP_OFFSET_MASK;
  927. pte_val(pte) = _PAGE_TYPE_SWAP | ((type & 0x1f) << 2) |
  928. ((offset & 1UL) << 7) | ((offset & ~1UL) << 11);
  929. return pte;
  930. }
  931. #define __swp_type(entry) (((entry).val >> 2) & 0x1f)
  932. #define __swp_offset(entry) (((entry).val >> 11) | (((entry).val >> 7) & 1))
  933. #define __swp_entry(type,offset) ((swp_entry_t) { pte_val(mk_swap_pte((type),(offset))) })
  934. #define __pte_to_swp_entry(pte) ((swp_entry_t) { pte_val(pte) })
  935. #define __swp_entry_to_pte(x) ((pte_t) { (x).val })
  936. #ifndef __s390x__
  937. # define PTE_FILE_MAX_BITS 26
  938. #else /* __s390x__ */
  939. # define PTE_FILE_MAX_BITS 59
  940. #endif /* __s390x__ */
  941. #define pte_to_pgoff(__pte) \
  942. ((((__pte).pte >> 12) << 7) + (((__pte).pte >> 1) & 0x7f))
  943. #define pgoff_to_pte(__off) \
  944. ((pte_t) { ((((__off) & 0x7f) << 1) + (((__off) >> 7) << 12)) \
  945. | _PAGE_TYPE_FILE })
  946. #endif /* !__ASSEMBLY__ */
  947. #define kern_addr_valid(addr) (1)
  948. extern int vmem_add_mapping(unsigned long start, unsigned long size);
  949. extern int vmem_remove_mapping(unsigned long start, unsigned long size);
  950. extern int s390_enable_sie(void);
  951. /*
  952. * No page table caches to initialise
  953. */
  954. #define pgtable_cache_init() do { } while (0)
  955. #include <asm-generic/pgtable.h>
  956. #endif /* _S390_PAGE_H */