PageRenderTime 1933ms CodeModel.GetById 22ms RepoModel.GetById 294ms app.codeStats 1ms

/arch/s390/include/asm/pgtable.h

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