blob: e63aa38e85fb23375ecefa40efe8cd9d76da6c43 [file] [log] [blame]
H. Peter Anvin1965aae2008-10-22 22:26:29 -07001#ifndef _ASM_X86_CACHEFLUSH_H
2#define _ASM_X86_CACHEFLUSH_H
Thomas Gleixnerb2bba722007-10-15 23:28:20 +02003
Thomas Gleixnerb2bba722007-10-15 23:28:20 +02004/* Caches aren't brain-dead on the intel. */
Akinobu Mitacc67ba632011-01-20 20:32:14 +09005#include <asm-generic/cacheflush.h>
David Howellsf05e7982012-03-28 18:11:12 +01006#include <asm/special_insns.h>
Ross Zwisler61031952015-06-25 03:08:39 -04007#include <asm/uaccess.h>
Thomas Gleixnerb2bba722007-10-15 23:28:20 +02008
Arjan van de Ven7219beb2008-04-17 17:41:31 +02009/*
10 * The set_memory_* API can be used to change various attributes of a virtual
11 * address range. The attributes include:
Toshi Kani623dffb2015-06-04 18:55:20 +020012 * Cachability : UnCached, WriteCombining, WriteThrough, WriteBack
Arjan van de Ven7219beb2008-04-17 17:41:31 +020013 * Executability : eXeutable, NoteXecutable
14 * Read/Write : ReadOnly, ReadWrite
15 * Presence : NotPresent
16 *
Lucas De Marchi0d2eb442011-03-17 16:24:16 -030017 * Within a category, the attributes are mutually exclusive.
Arjan van de Ven7219beb2008-04-17 17:41:31 +020018 *
19 * The implementation of this API will take care of various aspects that
20 * are associated with changing such attributes, such as:
21 * - Flushing TLBs
22 * - Flushing CPU caches
23 * - Making sure aliases of the memory behind the mapping don't violate
24 * coherency rules as defined by the CPU in the system.
25 *
26 * What this API does not do:
27 * - Provide exclusion between various callers - including callers that
28 * operation on other mappings of the same physical page
29 * - Restore default attributes when a page is freed
30 * - Guarantee that mappings other than the requested one are
31 * in any state, other than that these do not violate rules for
32 * the CPU you have. Do not depend on any effects on other mappings,
33 * CPUs other than the one you have may have more relaxed rules.
34 * The caller is required to take care of these.
35 */
Arjan van de Ven75cbade2008-01-30 13:34:06 +010036
venkatesh.pallipadi@intel.com12193332008-03-18 17:00:18 -070037int _set_memory_uc(unsigned long addr, int numpages);
venkatesh.pallipadi@intel.comef354af2008-03-18 17:00:23 -070038int _set_memory_wc(unsigned long addr, int numpages);
Toshi Kani623dffb2015-06-04 18:55:20 +020039int _set_memory_wt(unsigned long addr, int numpages);
venkatesh.pallipadi@intel.com12193332008-03-18 17:00:18 -070040int _set_memory_wb(unsigned long addr, int numpages);
Arjan van de Ven75cbade2008-01-30 13:34:06 +010041int set_memory_uc(unsigned long addr, int numpages);
venkatesh.pallipadi@intel.comef354af2008-03-18 17:00:23 -070042int set_memory_wc(unsigned long addr, int numpages);
Toshi Kani623dffb2015-06-04 18:55:20 +020043int set_memory_wt(unsigned long addr, int numpages);
Arjan van de Ven75cbade2008-01-30 13:34:06 +010044int set_memory_wb(unsigned long addr, int numpages);
45int set_memory_x(unsigned long addr, int numpages);
46int set_memory_nx(unsigned long addr, int numpages);
47int set_memory_ro(unsigned long addr, int numpages);
48int set_memory_rw(unsigned long addr, int numpages);
Ingo Molnarf62d0f02008-01-30 13:34:07 +010049int set_memory_np(unsigned long addr, int numpages);
Andi Kleenc9caa022008-03-12 03:53:29 +010050int set_memory_4k(unsigned long addr, int numpages);
Arjan van de Ven75cbade2008-01-30 13:34:06 +010051
Shaohua Lid75586a2008-08-21 10:46:06 +080052int set_memory_array_uc(unsigned long *addr, int addrinarray);
Pauli Nieminen4f646252010-04-01 12:45:01 +000053int set_memory_array_wc(unsigned long *addr, int addrinarray);
Toshi Kani623dffb2015-06-04 18:55:20 +020054int set_memory_array_wt(unsigned long *addr, int addrinarray);
Shaohua Lid75586a2008-08-21 10:46:06 +080055int set_memory_array_wb(unsigned long *addr, int addrinarray);
56
venkatesh.pallipadi@intel.com0f350752009-03-19 14:51:15 -070057int set_pages_array_uc(struct page **pages, int addrinarray);
Pauli Nieminen4f646252010-04-01 12:45:01 +000058int set_pages_array_wc(struct page **pages, int addrinarray);
Toshi Kani623dffb2015-06-04 18:55:20 +020059int set_pages_array_wt(struct page **pages, int addrinarray);
venkatesh.pallipadi@intel.com0f350752009-03-19 14:51:15 -070060int set_pages_array_wb(struct page **pages, int addrinarray);
61
Arjan van de Ven7219beb2008-04-17 17:41:31 +020062/*
63 * For legacy compatibility with the old APIs, a few functions
64 * are provided that work on a "struct page".
65 * These functions operate ONLY on the 1:1 kernel mapping of the
66 * memory that the struct page represents, and internally just
67 * call the set_memory_* function. See the description of the
68 * set_memory_* function for more details on conventions.
69 *
70 * These APIs should be considered *deprecated* and are likely going to
71 * be removed in the future.
72 * The reason for this is the implicit operation on the 1:1 mapping only,
73 * making this not a generally useful API.
74 *
75 * Specifically, many users of the old APIs had a virtual address,
76 * called virt_to_page() or vmalloc_to_page() on that address to
77 * get a struct page* that the old API required.
78 * To convert these cases, use set_memory_*() on the original
79 * virtual address, do not use these functions.
80 */
81
82int set_pages_uc(struct page *page, int numpages);
83int set_pages_wb(struct page *page, int numpages);
84int set_pages_x(struct page *page, int numpages);
85int set_pages_nx(struct page *page, int numpages);
86int set_pages_ro(struct page *page, int numpages);
87int set_pages_rw(struct page *page, int numpages);
88
89
Ingo Molnar4c61afc2008-01-30 13:34:09 +010090void clflush_cache_range(void *addr, unsigned int size);
Thomas Gleixnerb2bba722007-10-15 23:28:20 +020091
Ross Zwisler67a3e8f2015-08-27 13:14:20 -060092#define mmio_flush_range(addr, size) clflush_cache_range(addr, size)
93
Thomas Gleixnerb2bba722007-10-15 23:28:20 +020094#ifdef CONFIG_DEBUG_RODATA
95void mark_rodata_ro(void);
Harvey Harrison7bfeab92008-02-12 12:12:01 -080096extern const int rodata_test_data;
Suresh Siddha502f6602009-10-28 18:46:56 -080097extern int kernel_set_to_readonly;
Steven Rostedt16239632009-02-17 17:57:30 -050098void set_kernel_text_rw(void);
99void set_kernel_text_ro(void);
100#else
101static inline void set_kernel_text_rw(void) { }
102static inline void set_kernel_text_ro(void) { }
Thomas Gleixnerb2bba722007-10-15 23:28:20 +0200103#endif
Harvey Harrison7bfeab92008-02-12 12:12:01 -0800104
Arjan van de Venedeed302008-01-30 13:34:08 +0100105#ifdef CONFIG_DEBUG_RODATA_TEST
Harvey Harrison7bfeab92008-02-12 12:12:01 -0800106int rodata_test(void);
Arjan van de Venedeed302008-01-30 13:34:08 +0100107#else
Harvey Harrison7bfeab92008-02-12 12:12:01 -0800108static inline int rodata_test(void)
Arjan van de Venedeed302008-01-30 13:34:08 +0100109{
Harvey Harrison7bfeab92008-02-12 12:12:01 -0800110 return 0;
Arjan van de Venedeed302008-01-30 13:34:08 +0100111}
112#endif
Thomas Gleixnerb2bba722007-10-15 23:28:20 +0200113
H. Peter Anvin1965aae2008-10-22 22:26:29 -0700114#endif /* _ASM_X86_CACHEFLUSH_H */