Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
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/range.h>
7#include <linux/bug.h>
8
9struct memregion_info {
10 int target_node;
11 struct range range;
12};
13
14#ifdef CONFIG_MEMREGION
15int memregion_alloc(gfp_t gfp);
16void memregion_free(int id);
17#else
18static inline int memregion_alloc(gfp_t gfp)
19{
20 return -ENOMEM;
21}
22static inline void memregion_free(int id)
23{
24}
25#endif
26
27/**
28 * cpu_cache_invalidate_memregion - drop any CPU cached data for
29 * memregion
30 * @start: start physical address of the target memory region.
31 * @len: length of the target memory region. -1 for all the regions of
32 * the target type.
33 *
34 * Perform cache maintenance after a memory event / operation that
35 * changes the contents of physical memory in a cache-incoherent manner.
36 * For example, device memory technologies like NVDIMM and CXL have
37 * device secure erase, and dynamic region provision that can replace
38 * the memory mapped to a given physical address.
39 *
40 * Limit the functionality to architectures that have an efficient way
41 * to writeback and invalidate potentially terabytes of address space at
42 * once. Note that this routine may or may not write back any dirty
43 * contents while performing the invalidation. It is only exported for
44 * the explicit usage of the NVDIMM and CXL modules in the 'DEVMEM'
45 * symbol namespace on bare platforms.
46 *
47 * Returns 0 on success or negative error code on a failure to perform
48 * the cache maintenance.
49 */
50#ifdef CONFIG_ARCH_HAS_CPU_CACHE_INVALIDATE_MEMREGION
51int cpu_cache_invalidate_memregion(phys_addr_t start, size_t len);
52bool cpu_cache_has_invalidate_memregion(void);
53#else
54static inline bool cpu_cache_has_invalidate_memregion(void)
55{
56 return false;
57}
58
59static inline int cpu_cache_invalidate_memregion(phys_addr_t start, size_t len)
60{
61 WARN_ON_ONCE("CPU cache invalidation required");
62 return -ENXIO;
63}
64#endif
65
66static inline int cpu_cache_invalidate_all(void)
67{
68 return cpu_cache_invalidate_memregion(0, -1);
69}
70
71#endif /* _MEMREGION_H_ */