pgtable_32.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487
  1. #ifndef _SPARC_PGTABLE_H
  2. #define _SPARC_PGTABLE_H
  3. /* asm/pgtable.h: Defines and functions used to work
  4. * with Sparc page tables.
  5. *
  6. * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
  7. * Copyright (C) 1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
  8. */
  9. #include <linux/const.h>
  10. #ifndef __ASSEMBLY__
  11. #include <asm-generic/4level-fixup.h>
  12. #include <linux/spinlock.h>
  13. #include <linux/swap.h>
  14. #include <asm/types.h>
  15. #include <asm/pgtsrmmu.h>
  16. #include <asm/vac-ops.h>
  17. #include <asm/oplib.h>
  18. #include <asm/btfixup.h>
  19. #include <asm/cpu_type.h>
  20. struct vm_area_struct;
  21. struct page;
  22. extern void load_mmu(void);
  23. extern unsigned long calc_highpages(void);
  24. BTFIXUPDEF_SIMM13(pgdir_shift)
  25. BTFIXUPDEF_SETHI(pgdir_size)
  26. BTFIXUPDEF_SETHI(pgdir_mask)
  27. BTFIXUPDEF_SIMM13(ptrs_per_pmd)
  28. BTFIXUPDEF_SIMM13(ptrs_per_pgd)
  29. BTFIXUPDEF_SIMM13(user_ptrs_per_pgd)
  30. #define pte_ERROR(e) __builtin_trap()
  31. #define pmd_ERROR(e) __builtin_trap()
  32. #define pgd_ERROR(e) __builtin_trap()
  33. BTFIXUPDEF_INT(page_none)
  34. BTFIXUPDEF_INT(page_copy)
  35. BTFIXUPDEF_INT(page_readonly)
  36. BTFIXUPDEF_INT(page_kernel)
  37. #define PMD_SHIFT 22
  38. #define PMD_SIZE (1UL << PMD_SHIFT)
  39. #define PMD_MASK (~(PMD_SIZE-1))
  40. #define PMD_ALIGN(__addr) (((__addr) + ~PMD_MASK) & PMD_MASK)
  41. #define PGDIR_SHIFT BTFIXUP_SIMM13(pgdir_shift)
  42. #define PGDIR_SIZE BTFIXUP_SETHI(pgdir_size)
  43. #define PGDIR_MASK BTFIXUP_SETHI(pgdir_mask)
  44. #define PTRS_PER_PTE 1024
  45. #define PTRS_PER_PMD BTFIXUP_SIMM13(ptrs_per_pmd)
  46. #define PTRS_PER_PGD BTFIXUP_SIMM13(ptrs_per_pgd)
  47. #define USER_PTRS_PER_PGD BTFIXUP_SIMM13(user_ptrs_per_pgd)
  48. #define FIRST_USER_ADDRESS 0
  49. #define PTE_SIZE (PTRS_PER_PTE*4)
  50. #define PAGE_NONE __pgprot(BTFIXUP_INT(page_none))
  51. extern pgprot_t PAGE_SHARED;
  52. #define PAGE_COPY __pgprot(BTFIXUP_INT(page_copy))
  53. #define PAGE_READONLY __pgprot(BTFIXUP_INT(page_readonly))
  54. extern unsigned long page_kernel;
  55. #ifdef MODULE
  56. #define PAGE_KERNEL page_kernel
  57. #else
  58. #define PAGE_KERNEL __pgprot(BTFIXUP_INT(page_kernel))
  59. #endif
  60. /* Top-level page directory */
  61. extern pgd_t swapper_pg_dir[1024];
  62. extern void paging_init(void);
  63. /* Page table for 0-4MB for everybody, on the Sparc this
  64. * holds the same as on the i386.
  65. */
  66. extern pte_t pg0[1024];
  67. extern pte_t pg1[1024];
  68. extern pte_t pg2[1024];
  69. extern pte_t pg3[1024];
  70. extern unsigned long ptr_in_current_pgd;
  71. /* Here is a trick, since mmap.c need the initializer elements for
  72. * protection_map[] to be constant at compile time, I set the following
  73. * to all zeros. I set it to the real values after I link in the
  74. * appropriate MMU page table routines at boot time.
  75. */
  76. #define __P000 __pgprot(0)
  77. #define __P001 __pgprot(0)
  78. #define __P010 __pgprot(0)
  79. #define __P011 __pgprot(0)
  80. #define __P100 __pgprot(0)
  81. #define __P101 __pgprot(0)
  82. #define __P110 __pgprot(0)
  83. #define __P111 __pgprot(0)
  84. #define __S000 __pgprot(0)
  85. #define __S001 __pgprot(0)
  86. #define __S010 __pgprot(0)
  87. #define __S011 __pgprot(0)
  88. #define __S100 __pgprot(0)
  89. #define __S101 __pgprot(0)
  90. #define __S110 __pgprot(0)
  91. #define __S111 __pgprot(0)
  92. extern int num_contexts;
  93. /* First physical page can be anywhere, the following is needed so that
  94. * va-->pa and vice versa conversions work properly without performance
  95. * hit for all __pa()/__va() operations.
  96. */
  97. extern unsigned long phys_base;
  98. extern unsigned long pfn_base;
  99. /*
  100. * BAD_PAGETABLE is used when we need a bogus page-table, while
  101. * BAD_PAGE is used for a bogus page.
  102. *
  103. * ZERO_PAGE is a global shared page that is always zero: used
  104. * for zero-mapped memory areas etc..
  105. */
  106. extern pte_t * __bad_pagetable(void);
  107. extern pte_t __bad_page(void);
  108. extern unsigned long empty_zero_page;
  109. #define BAD_PAGETABLE __bad_pagetable()
  110. #define BAD_PAGE __bad_page()
  111. #define ZERO_PAGE(vaddr) (virt_to_page(&empty_zero_page))
  112. /*
  113. */
  114. BTFIXUPDEF_CALL_CONST(struct page *, pmd_page, pmd_t)
  115. BTFIXUPDEF_CALL_CONST(unsigned long, pgd_page_vaddr, pgd_t)
  116. #define pmd_page(pmd) BTFIXUP_CALL(pmd_page)(pmd)
  117. #define pgd_page_vaddr(pgd) BTFIXUP_CALL(pgd_page_vaddr)(pgd)
  118. BTFIXUPDEF_CALL_CONST(int, pte_present, pte_t)
  119. BTFIXUPDEF_CALL(void, pte_clear, pte_t *)
  120. static inline int pte_none(pte_t pte)
  121. {
  122. return !pte_val(pte);
  123. }
  124. #define pte_present(pte) BTFIXUP_CALL(pte_present)(pte)
  125. #define pte_clear(mm,addr,pte) BTFIXUP_CALL(pte_clear)(pte)
  126. BTFIXUPDEF_CALL_CONST(int, pmd_bad, pmd_t)
  127. BTFIXUPDEF_CALL_CONST(int, pmd_present, pmd_t)
  128. BTFIXUPDEF_CALL(void, pmd_clear, pmd_t *)
  129. static inline int pmd_none(pmd_t pmd)
  130. {
  131. return !pmd_val(pmd);
  132. }
  133. #define pmd_bad(pmd) BTFIXUP_CALL(pmd_bad)(pmd)
  134. #define pmd_present(pmd) BTFIXUP_CALL(pmd_present)(pmd)
  135. #define pmd_clear(pmd) BTFIXUP_CALL(pmd_clear)(pmd)
  136. BTFIXUPDEF_CALL_CONST(int, pgd_none, pgd_t)
  137. BTFIXUPDEF_CALL_CONST(int, pgd_bad, pgd_t)
  138. BTFIXUPDEF_CALL_CONST(int, pgd_present, pgd_t)
  139. BTFIXUPDEF_CALL(void, pgd_clear, pgd_t *)
  140. #define pgd_none(pgd) BTFIXUP_CALL(pgd_none)(pgd)
  141. #define pgd_bad(pgd) BTFIXUP_CALL(pgd_bad)(pgd)
  142. #define pgd_present(pgd) BTFIXUP_CALL(pgd_present)(pgd)
  143. #define pgd_clear(pgd) BTFIXUP_CALL(pgd_clear)(pgd)
  144. /*
  145. * The following only work if pte_present() is true.
  146. * Undefined behaviour if not..
  147. */
  148. BTFIXUPDEF_HALF(pte_writei)
  149. BTFIXUPDEF_HALF(pte_dirtyi)
  150. BTFIXUPDEF_HALF(pte_youngi)
  151. static int pte_write(pte_t pte) __attribute_const__;
  152. static inline int pte_write(pte_t pte)
  153. {
  154. return pte_val(pte) & BTFIXUP_HALF(pte_writei);
  155. }
  156. static int pte_dirty(pte_t pte) __attribute_const__;
  157. static inline int pte_dirty(pte_t pte)
  158. {
  159. return pte_val(pte) & BTFIXUP_HALF(pte_dirtyi);
  160. }
  161. static int pte_young(pte_t pte) __attribute_const__;
  162. static inline int pte_young(pte_t pte)
  163. {
  164. return pte_val(pte) & BTFIXUP_HALF(pte_youngi);
  165. }
  166. /*
  167. * The following only work if pte_present() is not true.
  168. */
  169. BTFIXUPDEF_HALF(pte_filei)
  170. static int pte_file(pte_t pte) __attribute_const__;
  171. static inline int pte_file(pte_t pte)
  172. {
  173. return pte_val(pte) & BTFIXUP_HALF(pte_filei);
  174. }
  175. static inline int pte_special(pte_t pte)
  176. {
  177. return 0;
  178. }
  179. /*
  180. */
  181. BTFIXUPDEF_HALF(pte_wrprotecti)
  182. BTFIXUPDEF_HALF(pte_mkcleani)
  183. BTFIXUPDEF_HALF(pte_mkoldi)
  184. static pte_t pte_wrprotect(pte_t pte) __attribute_const__;
  185. static inline pte_t pte_wrprotect(pte_t pte)
  186. {
  187. return __pte(pte_val(pte) & ~BTFIXUP_HALF(pte_wrprotecti));
  188. }
  189. static pte_t pte_mkclean(pte_t pte) __attribute_const__;
  190. static inline pte_t pte_mkclean(pte_t pte)
  191. {
  192. return __pte(pte_val(pte) & ~BTFIXUP_HALF(pte_mkcleani));
  193. }
  194. static pte_t pte_mkold(pte_t pte) __attribute_const__;
  195. static inline pte_t pte_mkold(pte_t pte)
  196. {
  197. return __pte(pte_val(pte) & ~BTFIXUP_HALF(pte_mkoldi));
  198. }
  199. BTFIXUPDEF_CALL_CONST(pte_t, pte_mkwrite, pte_t)
  200. BTFIXUPDEF_CALL_CONST(pte_t, pte_mkdirty, pte_t)
  201. BTFIXUPDEF_CALL_CONST(pte_t, pte_mkyoung, pte_t)
  202. #define pte_mkwrite(pte) BTFIXUP_CALL(pte_mkwrite)(pte)
  203. #define pte_mkdirty(pte) BTFIXUP_CALL(pte_mkdirty)(pte)
  204. #define pte_mkyoung(pte) BTFIXUP_CALL(pte_mkyoung)(pte)
  205. #define pte_mkspecial(pte) (pte)
  206. #define pfn_pte(pfn, prot) mk_pte(pfn_to_page(pfn), prot)
  207. BTFIXUPDEF_CALL(unsigned long, pte_pfn, pte_t)
  208. #define pte_pfn(pte) BTFIXUP_CALL(pte_pfn)(pte)
  209. #define pte_page(pte) pfn_to_page(pte_pfn(pte))
  210. /*
  211. * Conversion functions: convert a page and protection to a page entry,
  212. * and a page entry and page directory to the page they refer to.
  213. */
  214. BTFIXUPDEF_CALL_CONST(pte_t, mk_pte, struct page *, pgprot_t)
  215. BTFIXUPDEF_CALL_CONST(pte_t, mk_pte_phys, unsigned long, pgprot_t)
  216. BTFIXUPDEF_CALL_CONST(pte_t, mk_pte_io, unsigned long, pgprot_t, int)
  217. #define mk_pte(page,pgprot) BTFIXUP_CALL(mk_pte)(page,pgprot)
  218. #define mk_pte_phys(page,pgprot) BTFIXUP_CALL(mk_pte_phys)(page,pgprot)
  219. #define mk_pte_io(page,pgprot,space) BTFIXUP_CALL(mk_pte_io)(page,pgprot,space)
  220. #define pgprot_noncached pgprot_noncached
  221. static inline pgprot_t pgprot_noncached(pgprot_t prot)
  222. {
  223. prot &= ~__pgprot(SRMMU_CACHE);
  224. return prot;
  225. }
  226. BTFIXUPDEF_INT(pte_modify_mask)
  227. static pte_t pte_modify(pte_t pte, pgprot_t newprot) __attribute_const__;
  228. static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
  229. {
  230. return __pte((pte_val(pte) & BTFIXUP_INT(pte_modify_mask)) |
  231. pgprot_val(newprot));
  232. }
  233. #define pgd_index(address) ((address) >> PGDIR_SHIFT)
  234. /* to find an entry in a page-table-directory */
  235. #define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
  236. /* to find an entry in a kernel page-table-directory */
  237. #define pgd_offset_k(address) pgd_offset(&init_mm, address)
  238. /* Find an entry in the second-level page table.. */
  239. BTFIXUPDEF_CALL(pmd_t *, pmd_offset, pgd_t *, unsigned long)
  240. #define pmd_offset(dir,addr) BTFIXUP_CALL(pmd_offset)(dir,addr)
  241. /* Find an entry in the third-level page table.. */
  242. BTFIXUPDEF_CALL(pte_t *, pte_offset_kernel, pmd_t *, unsigned long)
  243. #define pte_offset_kernel(dir,addr) BTFIXUP_CALL(pte_offset_kernel)(dir,addr)
  244. /*
  245. * This shortcut works on sun4m (and sun4d) because the nocache area is static,
  246. * and sun4c is guaranteed to have no highmem anyway.
  247. */
  248. #define pte_offset_map(d, a) pte_offset_kernel(d,a)
  249. #define pte_unmap(pte) do{}while(0)
  250. /* Certain architectures need to do special things when pte's
  251. * within a page table are directly modified. Thus, the following
  252. * hook is made available.
  253. */
  254. BTFIXUPDEF_CALL(void, set_pte, pte_t *, pte_t)
  255. #define set_pte(ptep,pteval) BTFIXUP_CALL(set_pte)(ptep,pteval)
  256. #define set_pte_at(mm,addr,ptep,pteval) set_pte(ptep,pteval)
  257. struct seq_file;
  258. BTFIXUPDEF_CALL(void, mmu_info, struct seq_file *)
  259. #define mmu_info(p) BTFIXUP_CALL(mmu_info)(p)
  260. /* Fault handler stuff... */
  261. #define FAULT_CODE_PROT 0x1
  262. #define FAULT_CODE_WRITE 0x2
  263. #define FAULT_CODE_USER 0x4
  264. BTFIXUPDEF_CALL(void, update_mmu_cache, struct vm_area_struct *, unsigned long, pte_t *)
  265. #define update_mmu_cache(vma,addr,ptep) BTFIXUP_CALL(update_mmu_cache)(vma,addr,ptep)
  266. BTFIXUPDEF_CALL(void, sparc_mapiorange, unsigned int, unsigned long,
  267. unsigned long, unsigned int)
  268. BTFIXUPDEF_CALL(void, sparc_unmapiorange, unsigned long, unsigned int)
  269. #define sparc_mapiorange(bus,pa,va,len) BTFIXUP_CALL(sparc_mapiorange)(bus,pa,va,len)
  270. #define sparc_unmapiorange(va,len) BTFIXUP_CALL(sparc_unmapiorange)(va,len)
  271. extern int invalid_segment;
  272. /* Encode and de-code a swap entry */
  273. BTFIXUPDEF_CALL(unsigned long, __swp_type, swp_entry_t)
  274. BTFIXUPDEF_CALL(unsigned long, __swp_offset, swp_entry_t)
  275. BTFIXUPDEF_CALL(swp_entry_t, __swp_entry, unsigned long, unsigned long)
  276. #define __swp_type(__x) BTFIXUP_CALL(__swp_type)(__x)
  277. #define __swp_offset(__x) BTFIXUP_CALL(__swp_offset)(__x)
  278. #define __swp_entry(__type,__off) BTFIXUP_CALL(__swp_entry)(__type,__off)
  279. #define __pte_to_swp_entry(pte) ((swp_entry_t) { pte_val(pte) })
  280. #define __swp_entry_to_pte(x) ((pte_t) { (x).val })
  281. /* file-offset-in-pte helpers */
  282. static inline unsigned long pte_to_pgoff(pte_t pte)
  283. {
  284. return pte_val(pte) >> SRMMU_PTE_FILE_SHIFT;
  285. }
  286. static inline pte_t pgoff_to_pte(unsigned long pgoff)
  287. {
  288. return __pte((pgoff << SRMMU_PTE_FILE_SHIFT) | SRMMU_FILE);
  289. }
  290. /*
  291. * This is made a constant because mm/fremap.c required a constant.
  292. * Note that layout of these bits is different between sun4c.c and srmmu.c.
  293. */
  294. #define PTE_FILE_MAX_BITS 24
  295. /*
  296. */
  297. struct ctx_list {
  298. struct ctx_list *next;
  299. struct ctx_list *prev;
  300. unsigned int ctx_number;
  301. struct mm_struct *ctx_mm;
  302. };
  303. extern struct ctx_list *ctx_list_pool; /* Dynamically allocated */
  304. extern struct ctx_list ctx_free; /* Head of free list */
  305. extern struct ctx_list ctx_used; /* Head of used contexts list */
  306. #define NO_CONTEXT -1
  307. static inline void remove_from_ctx_list(struct ctx_list *entry)
  308. {
  309. entry->next->prev = entry->prev;
  310. entry->prev->next = entry->next;
  311. }
  312. static inline void add_to_ctx_list(struct ctx_list *head, struct ctx_list *entry)
  313. {
  314. entry->next = head;
  315. (entry->prev = head->prev)->next = entry;
  316. head->prev = entry;
  317. }
  318. #define add_to_free_ctxlist(entry) add_to_ctx_list(&ctx_free, entry)
  319. #define add_to_used_ctxlist(entry) add_to_ctx_list(&ctx_used, entry)
  320. static inline unsigned long
  321. __get_phys (unsigned long addr)
  322. {
  323. switch (sparc_cpu_model){
  324. case sun4m:
  325. case sun4d:
  326. return ((srmmu_get_pte (addr) & 0xffffff00) << 4);
  327. default:
  328. return 0;
  329. }
  330. }
  331. static inline int
  332. __get_iospace (unsigned long addr)
  333. {
  334. switch (sparc_cpu_model){
  335. case sun4m:
  336. case sun4d:
  337. return (srmmu_get_pte (addr) >> 28);
  338. default:
  339. return -1;
  340. }
  341. }
  342. extern unsigned long *sparc_valid_addr_bitmap;
  343. /* Needs to be defined here and not in linux/mm.h, as it is arch dependent */
  344. #define kern_addr_valid(addr) \
  345. (test_bit(__pa((unsigned long)(addr))>>20, sparc_valid_addr_bitmap))
  346. /*
  347. * For sparc32&64, the pfn in io_remap_pfn_range() carries <iospace> in
  348. * its high 4 bits. These macros/functions put it there or get it from there.
  349. */
  350. #define MK_IOSPACE_PFN(space, pfn) (pfn | (space << (BITS_PER_LONG - 4)))
  351. #define GET_IOSPACE(pfn) (pfn >> (BITS_PER_LONG - 4))
  352. #define GET_PFN(pfn) (pfn & 0x0fffffffUL)
  353. extern int remap_pfn_range(struct vm_area_struct *, unsigned long, unsigned long,
  354. unsigned long, pgprot_t);
  355. static inline int io_remap_pfn_range(struct vm_area_struct *vma,
  356. unsigned long from, unsigned long pfn,
  357. unsigned long size, pgprot_t prot)
  358. {
  359. unsigned long long offset, space, phys_base;
  360. offset = ((unsigned long long) GET_PFN(pfn)) << PAGE_SHIFT;
  361. space = GET_IOSPACE(pfn);
  362. phys_base = offset | (space << 32ULL);
  363. return remap_pfn_range(vma, from, phys_base >> PAGE_SHIFT, size, prot);
  364. }
  365. #define __HAVE_ARCH_PTEP_SET_ACCESS_FLAGS
  366. #define ptep_set_access_flags(__vma, __address, __ptep, __entry, __dirty) \
  367. ({ \
  368. int __changed = !pte_same(*(__ptep), __entry); \
  369. if (__changed) { \
  370. set_pte_at((__vma)->vm_mm, (__address), __ptep, __entry); \
  371. flush_tlb_page(__vma, __address); \
  372. } \
  373. __changed; \
  374. })
  375. #include <asm-generic/pgtable.h>
  376. #endif /* !(__ASSEMBLY__) */
  377. #define VMALLOC_START _AC(0xfe600000,UL)
  378. /* XXX Alter this when I get around to fixing sun4c - Anton */
  379. #define VMALLOC_END _AC(0xffc00000,UL)
  380. /* We provide our own get_unmapped_area to cope with VA holes for userland */
  381. #define HAVE_ARCH_UNMAPPED_AREA
  382. /*
  383. * No page table caches to initialise
  384. */
  385. #define pgtable_cache_init() do { } while (0)
  386. #endif /* !(_SPARC_PGTABLE_H) */