cacheflush.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. #ifndef _ASM_X86_CACHEFLUSH_H
  2. #define _ASM_X86_CACHEFLUSH_H
  3. /* Keep includes the same across arches. */
  4. #include <linux/mm.h>
  5. /* Caches aren't brain-dead on the intel. */
  6. static inline void flush_cache_all(void) { }
  7. static inline void flush_cache_mm(struct mm_struct *mm) { }
  8. static inline void flush_cache_dup_mm(struct mm_struct *mm) { }
  9. static inline void flush_cache_range(struct vm_area_struct *vma,
  10. unsigned long start, unsigned long end) { }
  11. static inline void flush_cache_page(struct vm_area_struct *vma,
  12. unsigned long vmaddr, unsigned long pfn) { }
  13. #define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 0
  14. static inline void flush_dcache_page(struct page *page) { }
  15. static inline void flush_dcache_mmap_lock(struct address_space *mapping) { }
  16. static inline void flush_dcache_mmap_unlock(struct address_space *mapping) { }
  17. static inline void flush_icache_range(unsigned long start,
  18. unsigned long end) { }
  19. static inline void flush_icache_page(struct vm_area_struct *vma,
  20. struct page *page) { }
  21. static inline void flush_icache_user_range(struct vm_area_struct *vma,
  22. struct page *page,
  23. unsigned long addr,
  24. unsigned long len) { }
  25. static inline void flush_cache_vmap(unsigned long start, unsigned long end) { }
  26. static inline void flush_cache_vunmap(unsigned long start,
  27. unsigned long end) { }
  28. static inline void copy_to_user_page(struct vm_area_struct *vma,
  29. struct page *page, unsigned long vaddr,
  30. void *dst, const void *src,
  31. unsigned long len)
  32. {
  33. memcpy(dst, src, len);
  34. }
  35. static inline void copy_from_user_page(struct vm_area_struct *vma,
  36. struct page *page, unsigned long vaddr,
  37. void *dst, const void *src,
  38. unsigned long len)
  39. {
  40. memcpy(dst, src, len);
  41. }
  42. #define PG_WC PG_arch_1
  43. PAGEFLAG(WC, WC)
  44. #ifdef CONFIG_X86_PAT
  45. /*
  46. * X86 PAT uses page flags WC and Uncached together to keep track of
  47. * memory type of pages that have backing page struct. X86 PAT supports 3
  48. * different memory types, _PAGE_CACHE_WB, _PAGE_CACHE_WC and
  49. * _PAGE_CACHE_UC_MINUS and fourth state where page's memory type has not
  50. * been changed from its default (value of -1 used to denote this).
  51. * Note we do not support _PAGE_CACHE_UC here.
  52. *
  53. * Caller must hold memtype_lock for atomicity.
  54. */
  55. static inline unsigned long get_page_memtype(struct page *pg)
  56. {
  57. if (!PageUncached(pg) && !PageWC(pg))
  58. return -1;
  59. else if (!PageUncached(pg) && PageWC(pg))
  60. return _PAGE_CACHE_WC;
  61. else if (PageUncached(pg) && !PageWC(pg))
  62. return _PAGE_CACHE_UC_MINUS;
  63. else
  64. return _PAGE_CACHE_WB;
  65. }
  66. static inline void set_page_memtype(struct page *pg, unsigned long memtype)
  67. {
  68. switch (memtype) {
  69. case _PAGE_CACHE_WC:
  70. ClearPageUncached(pg);
  71. SetPageWC(pg);
  72. break;
  73. case _PAGE_CACHE_UC_MINUS:
  74. SetPageUncached(pg);
  75. ClearPageWC(pg);
  76. break;
  77. case _PAGE_CACHE_WB:
  78. SetPageUncached(pg);
  79. SetPageWC(pg);
  80. break;
  81. default:
  82. case -1:
  83. ClearPageUncached(pg);
  84. ClearPageWC(pg);
  85. break;
  86. }
  87. }
  88. #else
  89. static inline unsigned long get_page_memtype(struct page *pg) { return -1; }
  90. static inline void set_page_memtype(struct page *pg, unsigned long memtype) { }
  91. #endif
  92. /*
  93. * The set_memory_* API can be used to change various attributes of a virtual
  94. * address range. The attributes include:
  95. * Cachability : UnCached, WriteCombining, WriteBack
  96. * Executability : eXeutable, NoteXecutable
  97. * Read/Write : ReadOnly, ReadWrite
  98. * Presence : NotPresent
  99. *
  100. * Within a catagory, the attributes are mutually exclusive.
  101. *
  102. * The implementation of this API will take care of various aspects that
  103. * are associated with changing such attributes, such as:
  104. * - Flushing TLBs
  105. * - Flushing CPU caches
  106. * - Making sure aliases of the memory behind the mapping don't violate
  107. * coherency rules as defined by the CPU in the system.
  108. *
  109. * What this API does not do:
  110. * - Provide exclusion between various callers - including callers that
  111. * operation on other mappings of the same physical page
  112. * - Restore default attributes when a page is freed
  113. * - Guarantee that mappings other than the requested one are
  114. * in any state, other than that these do not violate rules for
  115. * the CPU you have. Do not depend on any effects on other mappings,
  116. * CPUs other than the one you have may have more relaxed rules.
  117. * The caller is required to take care of these.
  118. */
  119. int _set_memory_uc(unsigned long addr, int numpages);
  120. int _set_memory_wc(unsigned long addr, int numpages);
  121. int _set_memory_wb(unsigned long addr, int numpages);
  122. int set_memory_uc(unsigned long addr, int numpages);
  123. int set_memory_wc(unsigned long addr, int numpages);
  124. int set_memory_wb(unsigned long addr, int numpages);
  125. int set_memory_x(unsigned long addr, int numpages);
  126. int set_memory_nx(unsigned long addr, int numpages);
  127. int set_memory_ro(unsigned long addr, int numpages);
  128. int set_memory_rw(unsigned long addr, int numpages);
  129. int set_memory_np(unsigned long addr, int numpages);
  130. int set_memory_4k(unsigned long addr, int numpages);
  131. int set_memory_array_uc(unsigned long *addr, int addrinarray);
  132. int set_memory_array_wb(unsigned long *addr, int addrinarray);
  133. int set_pages_array_uc(struct page **pages, int addrinarray);
  134. int set_pages_array_wb(struct page **pages, int addrinarray);
  135. /*
  136. * For legacy compatibility with the old APIs, a few functions
  137. * are provided that work on a "struct page".
  138. * These functions operate ONLY on the 1:1 kernel mapping of the
  139. * memory that the struct page represents, and internally just
  140. * call the set_memory_* function. See the description of the
  141. * set_memory_* function for more details on conventions.
  142. *
  143. * These APIs should be considered *deprecated* and are likely going to
  144. * be removed in the future.
  145. * The reason for this is the implicit operation on the 1:1 mapping only,
  146. * making this not a generally useful API.
  147. *
  148. * Specifically, many users of the old APIs had a virtual address,
  149. * called virt_to_page() or vmalloc_to_page() on that address to
  150. * get a struct page* that the old API required.
  151. * To convert these cases, use set_memory_*() on the original
  152. * virtual address, do not use these functions.
  153. */
  154. int set_pages_uc(struct page *page, int numpages);
  155. int set_pages_wb(struct page *page, int numpages);
  156. int set_pages_x(struct page *page, int numpages);
  157. int set_pages_nx(struct page *page, int numpages);
  158. int set_pages_ro(struct page *page, int numpages);
  159. int set_pages_rw(struct page *page, int numpages);
  160. void clflush_cache_range(void *addr, unsigned int size);
  161. #ifdef CONFIG_DEBUG_RODATA
  162. void mark_rodata_ro(void);
  163. extern const int rodata_test_data;
  164. extern int kernel_set_to_readonly;
  165. void set_kernel_text_rw(void);
  166. void set_kernel_text_ro(void);
  167. #else
  168. static inline void set_kernel_text_rw(void) { }
  169. static inline void set_kernel_text_ro(void) { }
  170. #endif
  171. #ifdef CONFIG_DEBUG_RODATA_TEST
  172. int rodata_test(void);
  173. #else
  174. static inline int rodata_test(void)
  175. {
  176. return 0;
  177. }
  178. #endif
  179. #endif /* _ASM_X86_CACHEFLUSH_H */