sun3_pgtable.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. #ifndef _SUN3_PGTABLE_H
  2. #define _SUN3_PGTABLE_H
  3. #include <asm/sun3mmu.h>
  4. #ifndef __ASSEMBLY__
  5. #include <asm/virtconvert.h>
  6. #include <linux/linkage.h>
  7. /*
  8. * This file contains all the things which change drastically for the sun3
  9. * pagetable stuff, to avoid making too much of a mess of the generic m68k
  10. * `pgtable.h'; this should only be included from the generic file. --m
  11. */
  12. /* For virtual address to physical address conversion */
  13. #define VTOP(addr) __pa(addr)
  14. #define PTOV(addr) __va(addr)
  15. #endif /* !__ASSEMBLY__ */
  16. /* These need to be defined for compatibility although the sun3 doesn't use them */
  17. #define _PAGE_NOCACHE030 0x040
  18. #define _CACHEMASK040 (~0x060)
  19. #define _PAGE_NOCACHE_S 0x040
  20. /* Page protection values within PTE. */
  21. #define SUN3_PAGE_VALID (0x80000000)
  22. #define SUN3_PAGE_WRITEABLE (0x40000000)
  23. #define SUN3_PAGE_SYSTEM (0x20000000)
  24. #define SUN3_PAGE_NOCACHE (0x10000000)
  25. #define SUN3_PAGE_ACCESSED (0x02000000)
  26. #define SUN3_PAGE_MODIFIED (0x01000000)
  27. /* Externally used page protection values. */
  28. #define _PAGE_PRESENT (SUN3_PAGE_VALID)
  29. #define _PAGE_ACCESSED (SUN3_PAGE_ACCESSED)
  30. /* Compound page protection values. */
  31. //todo: work out which ones *should* have SUN3_PAGE_NOCACHE and fix...
  32. // is it just PAGE_KERNEL and PAGE_SHARED?
  33. #define PAGE_NONE __pgprot(SUN3_PAGE_VALID \
  34. | SUN3_PAGE_ACCESSED \
  35. | SUN3_PAGE_NOCACHE)
  36. #define PAGE_SHARED __pgprot(SUN3_PAGE_VALID \
  37. | SUN3_PAGE_WRITEABLE \
  38. | SUN3_PAGE_ACCESSED \
  39. | SUN3_PAGE_NOCACHE)
  40. #define PAGE_COPY __pgprot(SUN3_PAGE_VALID \
  41. | SUN3_PAGE_ACCESSED \
  42. | SUN3_PAGE_NOCACHE)
  43. #define PAGE_READONLY __pgprot(SUN3_PAGE_VALID \
  44. | SUN3_PAGE_ACCESSED \
  45. | SUN3_PAGE_NOCACHE)
  46. #define PAGE_KERNEL __pgprot(SUN3_PAGE_VALID \
  47. | SUN3_PAGE_WRITEABLE \
  48. | SUN3_PAGE_SYSTEM \
  49. | SUN3_PAGE_NOCACHE \
  50. | SUN3_PAGE_ACCESSED \
  51. | SUN3_PAGE_MODIFIED)
  52. #define PAGE_INIT __pgprot(SUN3_PAGE_VALID \
  53. | SUN3_PAGE_WRITEABLE \
  54. | SUN3_PAGE_SYSTEM \
  55. | SUN3_PAGE_NOCACHE)
  56. /*
  57. * Page protections for initialising protection_map. The sun3 has only two
  58. * protection settings, valid (implying read and execute) and writeable. These
  59. * are as close as we can get...
  60. */
  61. #define __P000 PAGE_NONE
  62. #define __P001 PAGE_READONLY
  63. #define __P010 PAGE_COPY
  64. #define __P011 PAGE_COPY
  65. #define __P100 PAGE_READONLY
  66. #define __P101 PAGE_READONLY
  67. #define __P110 PAGE_COPY
  68. #define __P111 PAGE_COPY
  69. #define __S000 PAGE_NONE
  70. #define __S001 PAGE_READONLY
  71. #define __S010 PAGE_SHARED
  72. #define __S011 PAGE_SHARED
  73. #define __S100 PAGE_READONLY
  74. #define __S101 PAGE_READONLY
  75. #define __S110 PAGE_SHARED
  76. #define __S111 PAGE_SHARED
  77. /* Use these fake page-protections on PMDs. */
  78. #define SUN3_PMD_VALID (0x00000001)
  79. #define SUN3_PMD_MASK (0x0000003F)
  80. #define SUN3_PMD_MAGIC (0x0000002B)
  81. #ifndef __ASSEMBLY__
  82. /*
  83. * Conversion functions: convert a page and protection to a page entry,
  84. * and a page entry and page directory to the page they refer to.
  85. */
  86. #define mk_pte(page, pgprot) pfn_pte(page_to_pfn(page), (pgprot))
  87. static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
  88. {
  89. pte_val(pte) = (pte_val(pte) & SUN3_PAGE_CHG_MASK) | pgprot_val(newprot);
  90. return pte;
  91. }
  92. #define pmd_set(pmdp,ptep) do {} while (0)
  93. static inline void pgd_set(pgd_t *pgdp, pmd_t *pmdp)
  94. {
  95. pgd_val(*pgdp) = virt_to_phys(pmdp);
  96. }
  97. #define __pte_page(pte) \
  98. ((unsigned long) __va ((pte_val (pte) & SUN3_PAGE_PGNUM_MASK) << PAGE_SHIFT))
  99. #define __pmd_page(pmd) \
  100. ((unsigned long) __va (pmd_val (pmd) & PAGE_MASK))
  101. static inline int pte_none (pte_t pte) { return !pte_val (pte); }
  102. static inline int pte_present (pte_t pte) { return pte_val (pte) & SUN3_PAGE_VALID; }
  103. static inline void pte_clear (struct mm_struct *mm, unsigned long addr, pte_t *ptep)
  104. {
  105. pte_val (*ptep) = 0;
  106. }
  107. #define pte_pfn(pte) (pte_val(pte) & SUN3_PAGE_PGNUM_MASK)
  108. #define pfn_pte(pfn, pgprot) \
  109. ({ pte_t __pte; pte_val(__pte) = pfn | pgprot_val(pgprot); __pte; })
  110. #define pte_page(pte) virt_to_page(__pte_page(pte))
  111. #define pmd_page(pmd) virt_to_page(__pmd_page(pmd))
  112. static inline int pmd_none2 (pmd_t *pmd) { return !pmd_val (*pmd); }
  113. #define pmd_none(pmd) pmd_none2(&(pmd))
  114. //static inline int pmd_bad (pmd_t pmd) { return (pmd_val (pmd) & SUN3_PMD_MASK) != SUN3_PMD_MAGIC; }
  115. static inline int pmd_bad2 (pmd_t *pmd) { return 0; }
  116. #define pmd_bad(pmd) pmd_bad2(&(pmd))
  117. static inline int pmd_present2 (pmd_t *pmd) { return pmd_val (*pmd) & SUN3_PMD_VALID; }
  118. /* #define pmd_present(pmd) pmd_present2(&(pmd)) */
  119. #define pmd_present(pmd) (!pmd_none2(&(pmd)))
  120. static inline void pmd_clear (pmd_t *pmdp) { pmd_val (*pmdp) = 0; }
  121. static inline int pgd_none (pgd_t pgd) { return 0; }
  122. static inline int pgd_bad (pgd_t pgd) { return 0; }
  123. static inline int pgd_present (pgd_t pgd) { return 1; }
  124. static inline void pgd_clear (pgd_t *pgdp) {}
  125. #define pte_ERROR(e) \
  126. printk("%s:%d: bad pte %08lx.\n", __FILE__, __LINE__, pte_val(e))
  127. #define pmd_ERROR(e) \
  128. printk("%s:%d: bad pmd %08lx.\n", __FILE__, __LINE__, pmd_val(e))
  129. #define pgd_ERROR(e) \
  130. printk("%s:%d: bad pgd %08lx.\n", __FILE__, __LINE__, pgd_val(e))
  131. /*
  132. * The following only work if pte_present() is true.
  133. * Undefined behaviour if not...
  134. * [we have the full set here even if they don't change from m68k]
  135. */
  136. static inline int pte_write(pte_t pte) { return pte_val(pte) & SUN3_PAGE_WRITEABLE; }
  137. static inline int pte_dirty(pte_t pte) { return pte_val(pte) & SUN3_PAGE_MODIFIED; }
  138. static inline int pte_young(pte_t pte) { return pte_val(pte) & SUN3_PAGE_ACCESSED; }
  139. static inline int pte_special(pte_t pte) { return 0; }
  140. static inline pte_t pte_wrprotect(pte_t pte) { pte_val(pte) &= ~SUN3_PAGE_WRITEABLE; return pte; }
  141. static inline pte_t pte_mkclean(pte_t pte) { pte_val(pte) &= ~SUN3_PAGE_MODIFIED; return pte; }
  142. static inline pte_t pte_mkold(pte_t pte) { pte_val(pte) &= ~SUN3_PAGE_ACCESSED; return pte; }
  143. static inline pte_t pte_mkwrite(pte_t pte) { pte_val(pte) |= SUN3_PAGE_WRITEABLE; return pte; }
  144. static inline pte_t pte_mkdirty(pte_t pte) { pte_val(pte) |= SUN3_PAGE_MODIFIED; return pte; }
  145. static inline pte_t pte_mkyoung(pte_t pte) { pte_val(pte) |= SUN3_PAGE_ACCESSED; return pte; }
  146. static inline pte_t pte_mknocache(pte_t pte) { pte_val(pte) |= SUN3_PAGE_NOCACHE; return pte; }
  147. // use this version when caches work...
  148. //static inline pte_t pte_mkcache(pte_t pte) { pte_val(pte) &= SUN3_PAGE_NOCACHE; return pte; }
  149. // until then, use:
  150. static inline pte_t pte_mkcache(pte_t pte) { return pte; }
  151. static inline pte_t pte_mkspecial(pte_t pte) { return pte; }
  152. extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
  153. extern pgd_t kernel_pg_dir[PTRS_PER_PGD];
  154. /* Find an entry in a pagetable directory. */
  155. #define pgd_index(address) ((address) >> PGDIR_SHIFT)
  156. #define pgd_offset(mm, address) \
  157. ((mm)->pgd + pgd_index(address))
  158. /* Find an entry in a kernel pagetable directory. */
  159. #define pgd_offset_k(address) pgd_offset(&init_mm, address)
  160. /* Find an entry in the second-level pagetable. */
  161. static inline pmd_t *pmd_offset (pgd_t *pgd, unsigned long address)
  162. {
  163. return (pmd_t *) pgd;
  164. }
  165. /* Find an entry in the third-level pagetable. */
  166. #define pte_index(address) ((address >> PAGE_SHIFT) & (PTRS_PER_PTE-1))
  167. #define pte_offset_kernel(pmd, address) ((pte_t *) __pmd_page(*pmd) + pte_index(address))
  168. #define pte_offset_map(pmd, address) ((pte_t *)page_address(pmd_page(*pmd)) + pte_index(address))
  169. #define pte_unmap(pte) do { } while (0)
  170. /* Macros to (de)construct the fake PTEs representing swap pages. */
  171. #define __swp_type(x) ((x).val & 0x7F)
  172. #define __swp_offset(x) (((x).val) >> 7)
  173. #define __swp_entry(type,offset) ((swp_entry_t) { ((type) | ((offset) << 7)) })
  174. #define __pte_to_swp_entry(pte) ((swp_entry_t) { pte_val(pte) })
  175. #define __swp_entry_to_pte(x) ((pte_t) { (x).val })
  176. #endif /* !__ASSEMBLY__ */
  177. #endif /* !_SUN3_PGTABLE_H */