xref: /openbmc/linux/include/linux/memregion.h (revision 363d7c22)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _MEMREGION_H_
3 #define _MEMREGION_H_
4 #include <linux/types.h>
5 #include <linux/errno.h>
6 #include <linux/bug.h>
7 
8 struct memregion_info {
9 	int target_node;
10 };
11 
12 #ifdef CONFIG_MEMREGION
13 int memregion_alloc(gfp_t gfp);
14 void memregion_free(int id);
15 #else
16 static inline int memregion_alloc(gfp_t gfp)
17 {
18 	return -ENOMEM;
19 }
20 static inline void memregion_free(int id)
21 {
22 }
23 #endif
24 
25 /**
26  * cpu_cache_invalidate_memregion - drop any CPU cached data for
27  *     memregions described by @res_desc
28  * @res_desc: one of the IORES_DESC_* types
29  *
30  * Perform cache maintenance after a memory event / operation that
31  * changes the contents of physical memory in a cache-incoherent manner.
32  * For example, device memory technologies like NVDIMM and CXL have
33  * device secure erase, and dynamic region provision that can replace
34  * the memory mapped to a given physical address.
35  *
36  * Limit the functionality to architectures that have an efficient way
37  * to writeback and invalidate potentially terabytes of address space at
38  * once.  Note that this routine may or may not write back any dirty
39  * contents while performing the invalidation. It is only exported for
40  * the explicit usage of the NVDIMM and CXL modules in the 'DEVMEM'
41  * symbol namespace on bare platforms.
42  *
43  * Returns 0 on success or negative error code on a failure to perform
44  * the cache maintenance.
45  */
46 #ifdef CONFIG_ARCH_HAS_CPU_CACHE_INVALIDATE_MEMREGION
47 int cpu_cache_invalidate_memregion(int res_desc);
48 bool cpu_cache_has_invalidate_memregion(void);
49 #else
50 static inline bool cpu_cache_has_invalidate_memregion(void)
51 {
52 	return false;
53 }
54 
55 static inline int cpu_cache_invalidate_memregion(int res_desc)
56 {
57 	WARN_ON_ONCE("CPU cache invalidation required");
58 	return -ENXIO;
59 }
60 #endif
61 #endif /* _MEMREGION_H_ */
62