cacheflush.h 6.7 KB

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