xref: /openbmc/linux/include/linux/memregion.h (revision 9a87ffc99ec8eb8d35eed7c4f816d75f5cc9662e)
133dd7075SDan Williams /* SPDX-License-Identifier: GPL-2.0 */
233dd7075SDan Williams #ifndef _MEMREGION_H_
333dd7075SDan Williams #define _MEMREGION_H_
433dd7075SDan Williams #include <linux/types.h>
533dd7075SDan Williams #include <linux/errno.h>
6*fe098574SDan Williams #include <linux/range.h>
71156b441SDavidlohr Bueso #include <linux/bug.h>
833dd7075SDan Williams 
9a6c7f4c6SDan Williams struct memregion_info {
10a6c7f4c6SDan Williams 	int target_node;
11*fe098574SDan Williams 	struct range range;
12a6c7f4c6SDan Williams };
13a6c7f4c6SDan Williams 
1433dd7075SDan Williams #ifdef CONFIG_MEMREGION
1533dd7075SDan Williams int memregion_alloc(gfp_t gfp);
1633dd7075SDan Williams void memregion_free(int id);
1733dd7075SDan Williams #else
memregion_alloc(gfp_t gfp)1833dd7075SDan Williams static inline int memregion_alloc(gfp_t gfp)
1933dd7075SDan Williams {
2033dd7075SDan Williams 	return -ENOMEM;
2133dd7075SDan Williams }
memregion_free(int id)22f50974eeSDan Williams static inline void memregion_free(int id)
2333dd7075SDan Williams {
2433dd7075SDan Williams }
2533dd7075SDan Williams #endif
261156b441SDavidlohr Bueso 
271156b441SDavidlohr Bueso /**
281156b441SDavidlohr Bueso  * cpu_cache_invalidate_memregion - drop any CPU cached data for
291156b441SDavidlohr Bueso  *     memregions described by @res_desc
301156b441SDavidlohr Bueso  * @res_desc: one of the IORES_DESC_* types
311156b441SDavidlohr Bueso  *
321156b441SDavidlohr Bueso  * Perform cache maintenance after a memory event / operation that
331156b441SDavidlohr Bueso  * changes the contents of physical memory in a cache-incoherent manner.
341156b441SDavidlohr Bueso  * For example, device memory technologies like NVDIMM and CXL have
351156b441SDavidlohr Bueso  * device secure erase, and dynamic region provision that can replace
361156b441SDavidlohr Bueso  * the memory mapped to a given physical address.
371156b441SDavidlohr Bueso  *
381156b441SDavidlohr Bueso  * Limit the functionality to architectures that have an efficient way
391156b441SDavidlohr Bueso  * to writeback and invalidate potentially terabytes of address space at
401156b441SDavidlohr Bueso  * once.  Note that this routine may or may not write back any dirty
411156b441SDavidlohr Bueso  * contents while performing the invalidation. It is only exported for
421156b441SDavidlohr Bueso  * the explicit usage of the NVDIMM and CXL modules in the 'DEVMEM'
431156b441SDavidlohr Bueso  * symbol namespace on bare platforms.
441156b441SDavidlohr Bueso  *
451156b441SDavidlohr Bueso  * Returns 0 on success or negative error code on a failure to perform
461156b441SDavidlohr Bueso  * the cache maintenance.
471156b441SDavidlohr Bueso  */
481156b441SDavidlohr Bueso #ifdef CONFIG_ARCH_HAS_CPU_CACHE_INVALIDATE_MEMREGION
491156b441SDavidlohr Bueso int cpu_cache_invalidate_memregion(int res_desc);
501156b441SDavidlohr Bueso bool cpu_cache_has_invalidate_memregion(void);
511156b441SDavidlohr Bueso #else
cpu_cache_has_invalidate_memregion(void)521156b441SDavidlohr Bueso static inline bool cpu_cache_has_invalidate_memregion(void)
531156b441SDavidlohr Bueso {
541156b441SDavidlohr Bueso 	return false;
551156b441SDavidlohr Bueso }
561156b441SDavidlohr Bueso 
cpu_cache_invalidate_memregion(int res_desc)571156b441SDavidlohr Bueso static inline int cpu_cache_invalidate_memregion(int res_desc)
581156b441SDavidlohr Bueso {
591156b441SDavidlohr Bueso 	WARN_ON_ONCE("CPU cache invalidation required");
601156b441SDavidlohr Bueso 	return -ENXIO;
611156b441SDavidlohr Bueso }
621156b441SDavidlohr Bueso #endif
6333dd7075SDan Williams #endif /* _MEMREGION_H_ */
64