pgtable.h 33 KB

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