page.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. #ifndef __ASM_SH_PAGE_H
  2. #define __ASM_SH_PAGE_H
  3. /*
  4. * Copyright (C) 1999 Niibe Yutaka
  5. */
  6. #include <linux/const.h>
  7. /* PAGE_SHIFT determines the page size */
  8. #if defined(CONFIG_PAGE_SIZE_4KB)
  9. # define PAGE_SHIFT 12
  10. #elif defined(CONFIG_PAGE_SIZE_8KB)
  11. # define PAGE_SHIFT 13
  12. #elif defined(CONFIG_PAGE_SIZE_16KB)
  13. # define PAGE_SHIFT 14
  14. #elif defined(CONFIG_PAGE_SIZE_64KB)
  15. # define PAGE_SHIFT 16
  16. #else
  17. # error "Bogus kernel page size?"
  18. #endif
  19. #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
  20. #define PAGE_MASK (~(PAGE_SIZE-1))
  21. #define PTE_MASK PAGE_MASK
  22. #if defined(CONFIG_HUGETLB_PAGE_SIZE_64K)
  23. #define HPAGE_SHIFT 16
  24. #elif defined(CONFIG_HUGETLB_PAGE_SIZE_256K)
  25. #define HPAGE_SHIFT 18
  26. #elif defined(CONFIG_HUGETLB_PAGE_SIZE_1MB)
  27. #define HPAGE_SHIFT 20
  28. #elif defined(CONFIG_HUGETLB_PAGE_SIZE_4MB)
  29. #define HPAGE_SHIFT 22
  30. #elif defined(CONFIG_HUGETLB_PAGE_SIZE_64MB)
  31. #define HPAGE_SHIFT 26
  32. #elif defined(CONFIG_HUGETLB_PAGE_SIZE_512MB)
  33. #define HPAGE_SHIFT 29
  34. #endif
  35. #ifdef CONFIG_HUGETLB_PAGE
  36. #define HPAGE_SIZE (1UL << HPAGE_SHIFT)
  37. #define HPAGE_MASK (~(HPAGE_SIZE-1))
  38. #define HUGETLB_PAGE_ORDER (HPAGE_SHIFT-PAGE_SHIFT)
  39. #endif
  40. #ifndef __ASSEMBLY__
  41. #include <asm/uncached.h>
  42. extern unsigned long shm_align_mask;
  43. extern unsigned long max_low_pfn, min_low_pfn;
  44. extern unsigned long memory_start, memory_end, memory_limit;
  45. static inline unsigned long
  46. pages_do_alias(unsigned long addr1, unsigned long addr2)
  47. {
  48. return (addr1 ^ addr2) & shm_align_mask;
  49. }
  50. #define clear_page(page) memset((void *)(page), 0, PAGE_SIZE)
  51. extern void copy_page(void *to, void *from);
  52. #define copy_user_page(to, from, vaddr, pg) __copy_user(to, from, PAGE_SIZE)
  53. struct page;
  54. struct vm_area_struct;
  55. extern void copy_user_highpage(struct page *to, struct page *from,
  56. unsigned long vaddr, struct vm_area_struct *vma);
  57. #define __HAVE_ARCH_COPY_USER_HIGHPAGE
  58. extern void clear_user_highpage(struct page *page, unsigned long vaddr);
  59. #define clear_user_highpage clear_user_highpage
  60. /*
  61. * These are used to make use of C type-checking..
  62. */
  63. #ifdef CONFIG_X2TLB
  64. typedef struct { unsigned long pte_low, pte_high; } pte_t;
  65. typedef struct { unsigned long long pgprot; } pgprot_t;
  66. typedef struct { unsigned long long pgd; } pgd_t;
  67. #define pte_val(x) \
  68. ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
  69. #define __pte(x) \
  70. ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
  71. #elif defined(CONFIG_SUPERH32)
  72. typedef struct { unsigned long pte_low; } pte_t;
  73. typedef struct { unsigned long pgprot; } pgprot_t;
  74. typedef struct { unsigned long pgd; } pgd_t;
  75. #define pte_val(x) ((x).pte_low)
  76. #define __pte(x) ((pte_t) { (x) } )
  77. #else
  78. typedef struct { unsigned long long pte_low; } pte_t;
  79. typedef struct { unsigned long long pgprot; } pgprot_t;
  80. typedef struct { unsigned long pgd; } pgd_t;
  81. #define pte_val(x) ((x).pte_low)
  82. #define __pte(x) ((pte_t) { (x) } )
  83. #endif
  84. #define pgd_val(x) ((x).pgd)
  85. #define pgprot_val(x) ((x).pgprot)
  86. #define __pgd(x) ((pgd_t) { (x) } )
  87. #define __pgprot(x) ((pgprot_t) { (x) } )
  88. typedef struct page *pgtable_t;
  89. #define pte_pgprot(x) __pgprot(pte_val(x) & PTE_FLAGS_MASK)
  90. #endif /* !__ASSEMBLY__ */
  91. /*
  92. * __MEMORY_START and SIZE are the physical addresses and size of RAM.
  93. */
  94. #define __MEMORY_START CONFIG_MEMORY_START
  95. #define __MEMORY_SIZE CONFIG_MEMORY_SIZE
  96. /*
  97. * PHYSICAL_OFFSET is the offset in physical memory where the base
  98. * of the kernel is loaded.
  99. */
  100. #ifdef CONFIG_PHYSICAL_START
  101. #define PHYSICAL_OFFSET (CONFIG_PHYSICAL_START - __MEMORY_START)
  102. #else
  103. #define PHYSICAL_OFFSET 0
  104. #endif
  105. /*
  106. * PAGE_OFFSET is the virtual address of the start of kernel address
  107. * space.
  108. */
  109. #define PAGE_OFFSET CONFIG_PAGE_OFFSET
  110. /*
  111. * Virtual to physical RAM address translation.
  112. *
  113. * In 29 bit mode, the physical offset of RAM from address 0 is visible in
  114. * the kernel virtual address space, and thus we don't have to take
  115. * this into account when translating. However in 32 bit mode this offset
  116. * is not visible (it is part of the PMB mapping) and so needs to be
  117. * added or subtracted as required.
  118. */
  119. #ifdef CONFIG_PMB
  120. #define ___pa(x) ((x)-PAGE_OFFSET+__MEMORY_START)
  121. #define ___va(x) ((x)+PAGE_OFFSET-__MEMORY_START)
  122. #else
  123. #define ___pa(x) ((x)-PAGE_OFFSET)
  124. #define ___va(x) ((x)+PAGE_OFFSET)
  125. #endif
  126. #ifndef __ASSEMBLY__
  127. #define __pa(x) ___pa((unsigned long)x)
  128. #define __va(x) (void *)___va((unsigned long)x)
  129. #endif /* !__ASSEMBLY__ */
  130. #ifdef CONFIG_UNCACHED_MAPPING
  131. #if defined(CONFIG_29BIT)
  132. #define UNCAC_ADDR(addr) P2SEGADDR(addr)
  133. #define CAC_ADDR(addr) P1SEGADDR(addr)
  134. #else
  135. #define UNCAC_ADDR(addr) ((addr) - PAGE_OFFSET + uncached_start)
  136. #define CAC_ADDR(addr) ((addr) - uncached_start + PAGE_OFFSET)
  137. #endif
  138. #else
  139. #define UNCAC_ADDR(addr) ((addr))
  140. #define CAC_ADDR(addr) ((addr))
  141. #endif
  142. #define pfn_to_kaddr(pfn) __va((pfn) << PAGE_SHIFT)
  143. #define page_to_phys(page) (page_to_pfn(page) << PAGE_SHIFT)
  144. /*
  145. * PFN = physical frame number (ie PFN 0 == physical address 0)
  146. * PFN_START is the PFN of the first page of RAM. By defining this we
  147. * don't have struct page entries for the portion of address space
  148. * between physical address 0 and the start of RAM.
  149. */
  150. #define PFN_START (__MEMORY_START >> PAGE_SHIFT)
  151. #define ARCH_PFN_OFFSET (PFN_START)
  152. #define virt_to_page(kaddr) pfn_to_page(__pa(kaddr) >> PAGE_SHIFT)
  153. #ifdef CONFIG_FLATMEM
  154. #define pfn_valid(pfn) ((pfn) >= min_low_pfn && (pfn) < max_low_pfn)
  155. #endif
  156. #define virt_addr_valid(kaddr) pfn_valid(__pa(kaddr) >> PAGE_SHIFT)
  157. #define VM_DATA_DEFAULT_FLAGS (VM_READ | VM_WRITE | VM_EXEC | \
  158. VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
  159. #include <asm-generic/memory_model.h>
  160. #include <asm-generic/getorder.h>
  161. /*
  162. * Some drivers need to perform DMA into kmalloc'ed buffers
  163. * and so we have to increase the kmalloc minalign for this.
  164. */
  165. #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
  166. #ifdef CONFIG_SUPERH64
  167. /*
  168. * While BYTES_PER_WORD == 4 on the current sh64 ABI, GCC will still
  169. * happily generate {ld/st}.q pairs, requiring us to have 8-byte
  170. * alignment to avoid traps. The kmalloc alignment is guaranteed by
  171. * virtue of L1_CACHE_BYTES, requiring this to only be special cased
  172. * for slab caches.
  173. */
  174. #define ARCH_SLAB_MINALIGN 8
  175. #endif
  176. #endif /* __ASM_SH_PAGE_H */