1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _LINUX_NUMA_H
3 #define _LINUX_NUMA_H
4 #include <linux/init.h>
5 #include <linux/types.h>
6 #include <linux/nodemask.h>
7 
8 #define	NUMA_NO_MEMBLK	(-1)
9 
numa_valid_node(int nid)10 static inline bool numa_valid_node(int nid)
11 {
12 	return nid >= 0 && nid < MAX_NUMNODES;
13 }
14 
15 /* optionally keep NUMA memory info available post init */
16 #ifdef CONFIG_NUMA_KEEP_MEMINFO
17 #define __initdata_or_meminfo
18 #else
19 #define __initdata_or_meminfo __initdata
20 #endif
21 
22 #ifdef CONFIG_NUMA
23 #include <asm/sparsemem.h>
24 
25 extern struct pglist_data *node_data[];
26 #define NODE_DATA(nid)	(node_data[nid])
27 
28 void __init alloc_node_data(int nid);
29 void __init alloc_offline_node_data(int nid);
30 
31 /* Generic implementation available */
32 int numa_nearest_node(int node, unsigned int state);
33 
34 int nearest_node_nodemask(int node, nodemask_t *mask);
35 
36 #ifndef memory_add_physaddr_to_nid
37 int memory_add_physaddr_to_nid(u64 start);
38 #endif
39 
40 #ifndef phys_to_target_node
41 int phys_to_target_node(u64 start);
42 #endif
43 
44 int numa_fill_memblks(u64 start, u64 end);
45 
46 #else /* !CONFIG_NUMA */
numa_nearest_node(int node,unsigned int state)47 static inline int numa_nearest_node(int node, unsigned int state)
48 {
49 	return NUMA_NO_NODE;
50 }
51 
nearest_node_nodemask(int node,nodemask_t * mask)52 static inline int nearest_node_nodemask(int node, nodemask_t *mask)
53 {
54 	return NUMA_NO_NODE;
55 }
56 
memory_add_physaddr_to_nid(u64 start)57 static inline int memory_add_physaddr_to_nid(u64 start)
58 {
59 	return 0;
60 }
phys_to_target_node(u64 start)61 static inline int phys_to_target_node(u64 start)
62 {
63 	return 0;
64 }
65 
alloc_offline_node_data(int nid)66 static inline void alloc_offline_node_data(int nid) {}
67 #endif
68 
69 #define numa_map_to_online_node(node) numa_nearest_node(node, N_ONLINE)
70 
71 #ifdef CONFIG_HAVE_ARCH_NODE_DEV_GROUP
72 extern const struct attribute_group arch_node_dev_group;
73 #endif
74 
75 #endif /* _LINUX_NUMA_H */
76