pgtable.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506
  1. #ifndef __ASM_SH64_PGTABLE_H
  2. #define __ASM_SH64_PGTABLE_H
  3. #include <asm-generic/4level-fixup.h>
  4. /*
  5. * This file is subject to the terms and conditions of the GNU General Public
  6. * License. See the file "COPYING" in the main directory of this archive
  7. * for more details.
  8. *
  9. * include/asm-sh64/pgtable.h
  10. *
  11. * Copyright (C) 2000, 2001 Paolo Alberelli
  12. * Copyright (C) 2003, 2004 Paul Mundt
  13. * Copyright (C) 2003, 2004 Richard Curnow
  14. *
  15. * This file contains the functions and defines necessary to modify and use
  16. * the SuperH page table tree.
  17. */
  18. #ifndef __ASSEMBLY__
  19. #include <asm/processor.h>
  20. #include <asm/page.h>
  21. #include <linux/threads.h>
  22. #include <linux/config.h>
  23. struct vm_area_struct;
  24. extern void paging_init(void);
  25. /* We provide our own get_unmapped_area to avoid cache synonym issue */
  26. #define HAVE_ARCH_UNMAPPED_AREA
  27. /*
  28. * Basically we have the same two-level (which is the logical three level
  29. * Linux page table layout folded) page tables as the i386.
  30. */
  31. /*
  32. * ZERO_PAGE is a global shared page that is always zero: used
  33. * for zero-mapped memory areas etc..
  34. */
  35. extern unsigned char empty_zero_page[PAGE_SIZE];
  36. #define ZERO_PAGE(vaddr) (mem_map + MAP_NR(empty_zero_page))
  37. #endif /* !__ASSEMBLY__ */
  38. /*
  39. * NEFF and NPHYS related defines.
  40. * FIXME : These need to be model-dependent. For now this is OK, SH5-101 and SH5-103
  41. * implement 32 bits effective and 32 bits physical. But future implementations may
  42. * extend beyond this.
  43. */
  44. #define NEFF 32
  45. #define NEFF_SIGN (1LL << (NEFF - 1))
  46. #define NEFF_MASK (-1LL << NEFF)
  47. #define NPHYS 32
  48. #define NPHYS_SIGN (1LL << (NPHYS - 1))
  49. #define NPHYS_MASK (-1LL << NPHYS)
  50. /* Typically 2-level is sufficient up to 32 bits of virtual address space, beyond
  51. that 3-level would be appropriate. */
  52. #if defined(CONFIG_SH64_PGTABLE_2_LEVEL)
  53. /* For 4k pages, this contains 512 entries, i.e. 9 bits worth of address. */
  54. #define PTRS_PER_PTE ((1<<PAGE_SHIFT)/sizeof(unsigned long long))
  55. #define PTE_MAGNITUDE 3 /* sizeof(unsigned long long) magnit. */
  56. #define PTE_SHIFT PAGE_SHIFT
  57. #define PTE_BITS (PAGE_SHIFT - PTE_MAGNITUDE)
  58. /* top level: PMD. */
  59. #define PGDIR_SHIFT (PTE_SHIFT + PTE_BITS)
  60. #define PGD_BITS (NEFF - PGDIR_SHIFT)
  61. #define PTRS_PER_PGD (1<<PGD_BITS)
  62. /* middle level: PMD. This doesn't do anything for the 2-level case. */
  63. #define PTRS_PER_PMD (1)
  64. #define PGDIR_SIZE (1UL << PGDIR_SHIFT)
  65. #define PGDIR_MASK (~(PGDIR_SIZE-1))
  66. #define PMD_SHIFT PGDIR_SHIFT
  67. #define PMD_SIZE PGDIR_SIZE
  68. #define PMD_MASK PGDIR_MASK
  69. #elif defined(CONFIG_SH64_PGTABLE_3_LEVEL)
  70. /*
  71. * three-level asymmetric paging structure: PGD is top level.
  72. * The asymmetry comes from 32-bit pointers and 64-bit PTEs.
  73. */
  74. /* bottom level: PTE. It's 9 bits = 512 pointers */
  75. #define PTRS_PER_PTE ((1<<PAGE_SHIFT)/sizeof(unsigned long long))
  76. #define PTE_MAGNITUDE 3 /* sizeof(unsigned long long) magnit. */
  77. #define PTE_SHIFT PAGE_SHIFT
  78. #define PTE_BITS (PAGE_SHIFT - PTE_MAGNITUDE)
  79. /* middle level: PMD. It's 10 bits = 1024 pointers */
  80. #define PTRS_PER_PMD ((1<<PAGE_SHIFT)/sizeof(unsigned long long *))
  81. #define PMD_MAGNITUDE 2 /* sizeof(unsigned long long *) magnit. */
  82. #define PMD_SHIFT (PTE_SHIFT + PTE_BITS)
  83. #define PMD_BITS (PAGE_SHIFT - PMD_MAGNITUDE)
  84. /* top level: PMD. It's 1 bit = 2 pointers */
  85. #define PGDIR_SHIFT (PMD_SHIFT + PMD_BITS)
  86. #define PGD_BITS (NEFF - PGDIR_SHIFT)
  87. #define PTRS_PER_PGD (1<<PGD_BITS)
  88. #define PMD_SIZE (1UL << PMD_SHIFT)
  89. #define PMD_MASK (~(PMD_SIZE-1))
  90. #define PGDIR_SIZE (1UL << PGDIR_SHIFT)
  91. #define PGDIR_MASK (~(PGDIR_SIZE-1))
  92. #else
  93. #error "No defined number of page table levels"
  94. #endif
  95. /*
  96. * Error outputs.
  97. */
  98. #define pte_ERROR(e) \
  99. printk("%s:%d: bad pte %016Lx.\n", __FILE__, __LINE__, pte_val(e))
  100. #define pmd_ERROR(e) \
  101. printk("%s:%d: bad pmd %08lx.\n", __FILE__, __LINE__, pmd_val(e))
  102. #define pgd_ERROR(e) \
  103. printk("%s:%d: bad pgd %08lx.\n", __FILE__, __LINE__, pgd_val(e))
  104. /*
  105. * Table setting routines. Used within arch/mm only.
  106. */
  107. #define set_pgd(pgdptr, pgdval) (*(pgdptr) = pgdval)
  108. #define set_pmd(pmdptr, pmdval) (*(pmdptr) = pmdval)
  109. static __inline__ void set_pte(pte_t *pteptr, pte_t pteval)
  110. {
  111. unsigned long long x = ((unsigned long long) pteval.pte);
  112. unsigned long long *xp = (unsigned long long *) pteptr;
  113. /*
  114. * Sign-extend based on NPHYS.
  115. */
  116. *(xp) = (x & NPHYS_SIGN) ? (x | NPHYS_MASK) : x;
  117. }
  118. #define set_pte_at(mm,addr,ptep,pteval) set_pte(ptep,pteval)
  119. static __inline__ void pmd_set(pmd_t *pmdp,pte_t *ptep)
  120. {
  121. pmd_val(*pmdp) = (unsigned long) ptep;
  122. }
  123. /*
  124. * PGD defines. Top level.
  125. */
  126. /* To find an entry in a generic PGD. */
  127. #define pgd_index(address) (((address) >> PGDIR_SHIFT) & (PTRS_PER_PGD-1))
  128. #define __pgd_offset(address) pgd_index(address)
  129. #define pgd_offset(mm, address) ((mm)->pgd+pgd_index(address))
  130. /* To find an entry in a kernel PGD. */
  131. #define pgd_offset_k(address) pgd_offset(&init_mm, address)
  132. /*
  133. * PGD level access routines.
  134. *
  135. * Note1:
  136. * There's no need to use physical addresses since the tree walk is all
  137. * in performed in software, until the PTE translation.
  138. *
  139. * Note 2:
  140. * A PGD entry can be uninitialized (_PGD_UNUSED), generically bad,
  141. * clear (_PGD_EMPTY), present. When present, lower 3 nibbles contain
  142. * _KERNPG_TABLE. Being a kernel virtual pointer also bit 31 must
  143. * be 1. Assuming an arbitrary clear value of bit 31 set to 0 and
  144. * lower 3 nibbles set to 0xFFF (_PGD_EMPTY) any other value is a
  145. * bad pgd that must be notified via printk().
  146. *
  147. */
  148. #define _PGD_EMPTY 0x0
  149. #if defined(CONFIG_SH64_PGTABLE_2_LEVEL)
  150. static inline int pgd_none(pgd_t pgd) { return 0; }
  151. static inline int pgd_bad(pgd_t pgd) { return 0; }
  152. #define pgd_present(pgd) ((pgd_val(pgd) & _PAGE_PRESENT) ? 1 : 0)
  153. #define pgd_clear(xx) do { } while(0)
  154. #elif defined(CONFIG_SH64_PGTABLE_3_LEVEL)
  155. #define pgd_present(pgd_entry) (1)
  156. #define pgd_none(pgd_entry) (pgd_val((pgd_entry)) == _PGD_EMPTY)
  157. /* TODO: Think later about what a useful definition of 'bad' would be now. */
  158. #define pgd_bad(pgd_entry) (0)
  159. #define pgd_clear(pgd_entry_p) (set_pgd((pgd_entry_p), __pgd(_PGD_EMPTY)))
  160. #endif
  161. #define pgd_page(pgd_entry) ((unsigned long) (pgd_val(pgd_entry) & PAGE_MASK))
  162. /*
  163. * PMD defines. Middle level.
  164. */
  165. /* PGD to PMD dereferencing */
  166. #if defined(CONFIG_SH64_PGTABLE_2_LEVEL)
  167. static inline pmd_t * pmd_offset(pgd_t * dir, unsigned long address)
  168. {
  169. return (pmd_t *) dir;
  170. }
  171. #elif defined(CONFIG_SH64_PGTABLE_3_LEVEL)
  172. #define __pmd_offset(address) \
  173. (((address) >> PMD_SHIFT) & (PTRS_PER_PMD-1))
  174. #define pmd_offset(dir, addr) \
  175. ((pmd_t *) ((pgd_val(*(dir))) & PAGE_MASK) + __pmd_offset((addr)))
  176. #endif
  177. /*
  178. * PMD level access routines. Same notes as above.
  179. */
  180. #define _PMD_EMPTY 0x0
  181. /* Either the PMD is empty or present, it's not paged out */
  182. #define pmd_present(pmd_entry) (pmd_val(pmd_entry) & _PAGE_PRESENT)
  183. #define pmd_clear(pmd_entry_p) (set_pmd((pmd_entry_p), __pmd(_PMD_EMPTY)))
  184. #define pmd_none(pmd_entry) (pmd_val((pmd_entry)) == _PMD_EMPTY)
  185. #define pmd_bad(pmd_entry) ((pmd_val(pmd_entry) & (~PAGE_MASK & ~_PAGE_USER)) != _KERNPG_TABLE)
  186. #define pmd_page_kernel(pmd_entry) \
  187. ((unsigned long) __va(pmd_val(pmd_entry) & PAGE_MASK))
  188. #define pmd_page(pmd) \
  189. (virt_to_page(pmd_val(pmd)))
  190. /* PMD to PTE dereferencing */
  191. #define pte_index(address) \
  192. ((address >> PAGE_SHIFT) & (PTRS_PER_PTE - 1))
  193. #define pte_offset_kernel(dir, addr) \
  194. ((pte_t *) ((pmd_val(*(dir))) & PAGE_MASK) + pte_index((addr)))
  195. #define pte_offset_map(dir,addr) pte_offset_kernel(dir, addr)
  196. #define pte_offset_map_nested(dir,addr) pte_offset_kernel(dir, addr)
  197. #define pte_unmap(pte) do { } while (0)
  198. #define pte_unmap_nested(pte) do { } while (0)
  199. /* Round it up ! */
  200. #define USER_PTRS_PER_PGD ((TASK_SIZE+PGDIR_SIZE-1)/PGDIR_SIZE)
  201. #define FIRST_USER_ADDRESS 0
  202. #ifndef __ASSEMBLY__
  203. #define VMALLOC_END 0xff000000
  204. #define VMALLOC_START 0xf0000000
  205. #define VMALLOC_VMADDR(x) ((unsigned long)(x))
  206. #define IOBASE_VADDR 0xff000000
  207. #define IOBASE_END 0xffffffff
  208. /*
  209. * PTEL coherent flags.
  210. * See Chapter 17 ST50 CPU Core Volume 1, Architecture.
  211. */
  212. /* The bits that are required in the SH-5 TLB are placed in the h/w-defined
  213. positions, to avoid expensive bit shuffling on every refill. The remaining
  214. bits are used for s/w purposes and masked out on each refill.
  215. Note, the PTE slots are used to hold data of type swp_entry_t when a page is
  216. swapped out. Only the _PAGE_PRESENT flag is significant when the page is
  217. swapped out, and it must be placed so that it doesn't overlap either the
  218. type or offset fields of swp_entry_t. For x86, offset is at [31:8] and type
  219. at [6:1], with _PAGE_PRESENT at bit 0 for both pte_t and swp_entry_t. This
  220. scheme doesn't map to SH-5 because bit [0] controls cacheability. So bit
  221. [2] is used for _PAGE_PRESENT and the type field of swp_entry_t is split
  222. into 2 pieces. That is handled by SWP_ENTRY and SWP_TYPE below. */
  223. #define _PAGE_WT 0x001 /* CB0: if cacheable, 1->write-thru, 0->write-back */
  224. #define _PAGE_DEVICE 0x001 /* CB0: if uncacheable, 1->device (i.e. no write-combining or reordering at bus level) */
  225. #define _PAGE_CACHABLE 0x002 /* CB1: uncachable/cachable */
  226. #define _PAGE_PRESENT 0x004 /* software: page referenced */
  227. #define _PAGE_FILE 0x004 /* software: only when !present */
  228. #define _PAGE_SIZE0 0x008 /* SZ0-bit : size of page */
  229. #define _PAGE_SIZE1 0x010 /* SZ1-bit : size of page */
  230. #define _PAGE_SHARED 0x020 /* software: reflects PTEH's SH */
  231. #define _PAGE_READ 0x040 /* PR0-bit : read access allowed */
  232. #define _PAGE_EXECUTE 0x080 /* PR1-bit : execute access allowed */
  233. #define _PAGE_WRITE 0x100 /* PR2-bit : write access allowed */
  234. #define _PAGE_USER 0x200 /* PR3-bit : user space access allowed */
  235. #define _PAGE_DIRTY 0x400 /* software: page accessed in write */
  236. #define _PAGE_ACCESSED 0x800 /* software: page referenced */
  237. /* Mask which drops software flags */
  238. #define _PAGE_FLAGS_HARDWARE_MASK 0xfffffffffffff3dbLL
  239. /*
  240. * HugeTLB support
  241. */
  242. #if defined(CONFIG_HUGETLB_PAGE_SIZE_64K)
  243. #define _PAGE_SZHUGE (_PAGE_SIZE0)
  244. #elif defined(CONFIG_HUGETLB_PAGE_SIZE_1MB)
  245. #define _PAGE_SZHUGE (_PAGE_SIZE1)
  246. #elif defined(CONFIG_HUGETLB_PAGE_SIZE_512MB)
  247. #define _PAGE_SZHUGE (_PAGE_SIZE0 | _PAGE_SIZE1)
  248. #endif
  249. /*
  250. * Default flags for a Kernel page.
  251. * This is fundametally also SHARED because the main use of this define
  252. * (other than for PGD/PMD entries) is for the VMALLOC pool which is
  253. * contextless.
  254. *
  255. * _PAGE_EXECUTE is required for modules
  256. *
  257. */
  258. #define _KERNPG_TABLE (_PAGE_PRESENT | _PAGE_READ | _PAGE_WRITE | \
  259. _PAGE_EXECUTE | \
  260. _PAGE_CACHABLE | _PAGE_ACCESSED | _PAGE_DIRTY | \
  261. _PAGE_SHARED)
  262. /* Default flags for a User page */
  263. #define _PAGE_TABLE (_KERNPG_TABLE | _PAGE_USER)
  264. #define _PAGE_CHG_MASK (PTE_MASK | _PAGE_ACCESSED | _PAGE_DIRTY)
  265. #define PAGE_NONE __pgprot(_PAGE_CACHABLE | _PAGE_ACCESSED)
  266. #define PAGE_SHARED __pgprot(_PAGE_PRESENT | _PAGE_READ | _PAGE_WRITE | \
  267. _PAGE_CACHABLE | _PAGE_ACCESSED | _PAGE_USER | \
  268. _PAGE_SHARED)
  269. /* We need to include PAGE_EXECUTE in PAGE_COPY because it is the default
  270. * protection mode for the stack. */
  271. #define PAGE_COPY __pgprot(_PAGE_PRESENT | _PAGE_READ | _PAGE_CACHABLE | \
  272. _PAGE_ACCESSED | _PAGE_USER | _PAGE_EXECUTE)
  273. #define PAGE_READONLY __pgprot(_PAGE_PRESENT | _PAGE_READ | _PAGE_CACHABLE | \
  274. _PAGE_ACCESSED | _PAGE_USER)
  275. #define PAGE_KERNEL __pgprot(_KERNPG_TABLE)
  276. /*
  277. * In ST50 we have full permissions (Read/Write/Execute/Shared).
  278. * Just match'em all. These are for mmap(), therefore all at least
  279. * User/Cachable/Present/Accessed. No point in making Fault on Write.
  280. */
  281. #define __MMAP_COMMON (_PAGE_PRESENT | _PAGE_USER | _PAGE_CACHABLE | _PAGE_ACCESSED)
  282. /* sxwr */
  283. #define __P000 __pgprot(__MMAP_COMMON)
  284. #define __P001 __pgprot(__MMAP_COMMON | _PAGE_READ)
  285. #define __P010 __pgprot(__MMAP_COMMON)
  286. #define __P011 __pgprot(__MMAP_COMMON | _PAGE_READ)
  287. #define __P100 __pgprot(__MMAP_COMMON | _PAGE_EXECUTE)
  288. #define __P101 __pgprot(__MMAP_COMMON | _PAGE_EXECUTE | _PAGE_READ)
  289. #define __P110 __pgprot(__MMAP_COMMON | _PAGE_EXECUTE)
  290. #define __P111 __pgprot(__MMAP_COMMON | _PAGE_EXECUTE | _PAGE_READ)
  291. #define __S000 __pgprot(__MMAP_COMMON | _PAGE_SHARED)
  292. #define __S001 __pgprot(__MMAP_COMMON | _PAGE_SHARED | _PAGE_READ)
  293. #define __S010 __pgprot(__MMAP_COMMON | _PAGE_SHARED | _PAGE_WRITE)
  294. #define __S011 __pgprot(__MMAP_COMMON | _PAGE_SHARED | _PAGE_READ | _PAGE_WRITE)
  295. #define __S100 __pgprot(__MMAP_COMMON | _PAGE_SHARED | _PAGE_EXECUTE)
  296. #define __S101 __pgprot(__MMAP_COMMON | _PAGE_SHARED | _PAGE_EXECUTE | _PAGE_READ)
  297. #define __S110 __pgprot(__MMAP_COMMON | _PAGE_SHARED | _PAGE_EXECUTE | _PAGE_WRITE)
  298. #define __S111 __pgprot(__MMAP_COMMON | _PAGE_SHARED | _PAGE_EXECUTE | _PAGE_READ | _PAGE_WRITE)
  299. /* Make it a device mapping for maximum safety (e.g. for mapping device
  300. registers into user-space via /dev/map). */
  301. #define pgprot_noncached(x) __pgprot(((x).pgprot & ~(_PAGE_CACHABLE)) | _PAGE_DEVICE)
  302. #define pgprot_writecombine(prot) __pgprot(pgprot_val(prot) & ~_PAGE_CACHABLE)
  303. /*
  304. * Handling allocation failures during page table setup.
  305. */
  306. extern void __handle_bad_pmd_kernel(pmd_t * pmd);
  307. #define __handle_bad_pmd(x) __handle_bad_pmd_kernel(x)
  308. /*
  309. * PTE level access routines.
  310. *
  311. * Note1:
  312. * It's the tree walk leaf. This is physical address to be stored.
  313. *
  314. * Note 2:
  315. * Regarding the choice of _PTE_EMPTY:
  316. We must choose a bit pattern that cannot be valid, whether or not the page
  317. is present. bit[2]==1 => present, bit[2]==0 => swapped out. If swapped
  318. out, bits [31:8], [6:3], [1:0] are under swapper control, so only bit[7] is
  319. left for us to select. If we force bit[7]==0 when swapped out, we could use
  320. the combination bit[7,2]=2'b10 to indicate an empty PTE. Alternatively, if
  321. we force bit[7]==1 when swapped out, we can use all zeroes to indicate
  322. empty. This is convenient, because the page tables get cleared to zero
  323. when they are allocated.
  324. */
  325. #define _PTE_EMPTY 0x0
  326. #define pte_present(x) (pte_val(x) & _PAGE_PRESENT)
  327. #define pte_clear(mm,addr,xp) (set_pte_at(mm, addr, xp, __pte(_PTE_EMPTY)))
  328. #define pte_none(x) (pte_val(x) == _PTE_EMPTY)
  329. /*
  330. * Some definitions to translate between mem_map, PTEs, and page
  331. * addresses:
  332. */
  333. /*
  334. * Given a PTE, return the index of the mem_map[] entry corresponding
  335. * to the page frame the PTE. Get the absolute physical address, make
  336. * a relative physical address and translate it to an index.
  337. */
  338. #define pte_pagenr(x) (((unsigned long) (pte_val(x)) - \
  339. __MEMORY_START) >> PAGE_SHIFT)
  340. /*
  341. * Given a PTE, return the "struct page *".
  342. */
  343. #define pte_page(x) (mem_map + pte_pagenr(x))
  344. /*
  345. * Return number of (down rounded) MB corresponding to x pages.
  346. */
  347. #define pages_to_mb(x) ((x) >> (20-PAGE_SHIFT))
  348. /*
  349. * The following have defined behavior only work if pte_present() is true.
  350. */
  351. static inline int pte_read(pte_t pte) { return pte_val(pte) & _PAGE_READ; }
  352. static inline int pte_exec(pte_t pte) { return pte_val(pte) & _PAGE_EXECUTE; }
  353. static inline int pte_dirty(pte_t pte){ return pte_val(pte) & _PAGE_DIRTY; }
  354. static inline int pte_young(pte_t pte){ return pte_val(pte) & _PAGE_ACCESSED; }
  355. static inline int pte_file(pte_t pte) { return pte_val(pte) & _PAGE_FILE; }
  356. static inline int pte_write(pte_t pte){ return pte_val(pte) & _PAGE_WRITE; }
  357. static inline pte_t pte_rdprotect(pte_t pte) { set_pte(&pte, __pte(pte_val(pte) & ~_PAGE_READ)); return pte; }
  358. static inline pte_t pte_wrprotect(pte_t pte) { set_pte(&pte, __pte(pte_val(pte) & ~_PAGE_WRITE)); return pte; }
  359. static inline pte_t pte_exprotect(pte_t pte) { set_pte(&pte, __pte(pte_val(pte) & ~_PAGE_EXECUTE)); return pte; }
  360. static inline pte_t pte_mkclean(pte_t pte) { set_pte(&pte, __pte(pte_val(pte) & ~_PAGE_DIRTY)); return pte; }
  361. static inline pte_t pte_mkold(pte_t pte) { set_pte(&pte, __pte(pte_val(pte) & ~_PAGE_ACCESSED)); return pte; }
  362. static inline pte_t pte_mkread(pte_t pte) { set_pte(&pte, __pte(pte_val(pte) | _PAGE_READ)); return pte; }
  363. static inline pte_t pte_mkwrite(pte_t pte) { set_pte(&pte, __pte(pte_val(pte) | _PAGE_WRITE)); return pte; }
  364. static inline pte_t pte_mkexec(pte_t pte) { set_pte(&pte, __pte(pte_val(pte) | _PAGE_EXECUTE)); return pte; }
  365. static inline pte_t pte_mkdirty(pte_t pte) { set_pte(&pte, __pte(pte_val(pte) | _PAGE_DIRTY)); return pte; }
  366. static inline pte_t pte_mkyoung(pte_t pte) { set_pte(&pte, __pte(pte_val(pte) | _PAGE_ACCESSED)); return pte; }
  367. static inline pte_t pte_mkhuge(pte_t pte) { set_pte(&pte, __pte(pte_val(pte) | _PAGE_SZHUGE)); return pte; }
  368. /*
  369. * Conversion functions: convert a page and protection to a page entry.
  370. *
  371. * extern pte_t mk_pte(struct page *page, pgprot_t pgprot)
  372. */
  373. #define mk_pte(page,pgprot) \
  374. ({ \
  375. pte_t __pte; \
  376. \
  377. set_pte(&__pte, __pte((((page)-mem_map) << PAGE_SHIFT) | \
  378. __MEMORY_START | pgprot_val((pgprot)))); \
  379. __pte; \
  380. })
  381. /*
  382. * This takes a (absolute) physical page address that is used
  383. * by the remapping functions
  384. */
  385. #define mk_pte_phys(physpage, pgprot) \
  386. ({ pte_t __pte; set_pte(&__pte, __pte(physpage | pgprot_val(pgprot))); __pte; })
  387. static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
  388. { set_pte(&pte, __pte((pte_val(pte) & _PAGE_CHG_MASK) | pgprot_val(newprot))); return pte; }
  389. typedef pte_t *pte_addr_t;
  390. #define pgtable_cache_init() do { } while (0)
  391. extern void update_mmu_cache(struct vm_area_struct * vma,
  392. unsigned long address, pte_t pte);
  393. /* Encode and decode a swap entry */
  394. #define __swp_type(x) (((x).val & 3) + (((x).val >> 1) & 0x3c))
  395. #define __swp_offset(x) ((x).val >> 8)
  396. #define __swp_entry(type, offset) ((swp_entry_t) { ((offset << 8) + ((type & 0x3c) << 1) + (type & 3)) })
  397. #define __pte_to_swp_entry(pte) ((swp_entry_t) { pte_val(pte) })
  398. #define __swp_entry_to_pte(x) ((pte_t) { (x).val })
  399. /* Encode and decode a nonlinear file mapping entry */
  400. #define PTE_FILE_MAX_BITS 29
  401. #define pte_to_pgoff(pte) (pte_val(pte))
  402. #define pgoff_to_pte(off) ((pte_t) { (off) | _PAGE_FILE })
  403. /* Needs to be defined here and not in linux/mm.h, as it is arch dependent */
  404. #define PageSkip(page) (0)
  405. #define kern_addr_valid(addr) (1)
  406. #define io_remap_pfn_range(vma, vaddr, pfn, size, prot) \
  407. remap_pfn_range(vma, vaddr, pfn, size, prot)
  408. #define MK_IOSPACE_PFN(space, pfn) (pfn)
  409. #define GET_IOSPACE(pfn) 0
  410. #define GET_PFN(pfn) (pfn)
  411. #endif /* !__ASSEMBLY__ */
  412. /*
  413. * No page table caches to initialise
  414. */
  415. #define pgtable_cache_init() do { } while (0)
  416. #define pte_pfn(x) (((unsigned long)((x).pte)) >> PAGE_SHIFT)
  417. #define pfn_pte(pfn, prot) __pte(((pfn) << PAGE_SHIFT) | pgprot_val(prot))
  418. #define pfn_pmd(pfn, prot) __pmd(((pfn) << PAGE_SHIFT) | pgprot_val(prot))
  419. extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
  420. #include <asm-generic/pgtable.h>
  421. #endif /* __ASM_SH64_PGTABLE_H */