blob: d1751beb462ca3792c02747feb72c6a35c29fd80 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * include/linux/node.h - generic node definition
3 *
4 * This is mainly for topological representation. We define the
5 * basic 'struct node' here, which can be embedded in per-arch
6 * definitions of processors.
7 *
8 * Basic handling of the devices is done in drivers/base/node.c
9 * and system devices are handled in drivers/base/sys.c.
10 *
11 * Nodes are exported via driverfs in the class/node/devices/
12 * directory.
Linus Torvalds1da177e2005-04-16 15:20:36 -070013 */
14#ifndef _LINUX_NODE_H_
15#define _LINUX_NODE_H_
16
Kay Sievers10fbcf42011-12-21 14:48:43 -080017#include <linux/device.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#include <linux/cpumask.h>
Lee Schermerhorn39da08c2009-12-14 17:58:36 -080019#include <linux/workqueue.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020
21struct node {
Kay Sievers10fbcf42011-12-21 14:48:43 -080022 struct device dev;
Lee Schermerhorn39da08c2009-12-14 17:58:36 -080023
24#if defined(CONFIG_MEMORY_HOTPLUG_SPARSE) && defined(CONFIG_HUGETLBFS)
25 struct work_struct node_work;
26#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070027};
28
Gary Hadec04fc582009-01-06 14:39:14 -080029struct memory_block;
Wen Congyang87327942012-12-11 16:00:56 -080030extern struct node *node_devices[];
Lee Schermerhorn9a3052302009-12-14 17:58:25 -080031typedef void (*node_registration_func_t)(struct node *);
Yasunori Goto0fc44152006-06-27 02:53:38 -070032
Michal Hocko9037a992017-07-06 15:37:49 -070033#if defined(CONFIG_MEMORY_HOTPLUG_SPARSE) && defined(CONFIG_NUMA)
34extern int link_mem_sections(int nid, unsigned long start_pfn, unsigned long nr_pages);
35#else
36static inline int link_mem_sections(int nid, unsigned long start_pfn, unsigned long nr_pages)
37{
38 return 0;
39}
40#endif
41
Keiichiro Tokunaga4b450992005-05-08 21:28:53 +090042extern void unregister_node(struct node *node);
KAMEZAWA Hiroyuki36920e02006-08-27 01:23:52 -070043#ifdef CONFIG_NUMA
Michal Hocko9037a992017-07-06 15:37:49 -070044/* Core of the node registration - only memory hotplug should use this */
45extern int __register_one_node(int nid);
46
47/* Registers an online node */
48static inline int register_one_node(int nid)
49{
50 int error = 0;
51
52 if (node_online(nid)) {
53 struct pglist_data *pgdat = NODE_DATA(nid);
54
55 error = __register_one_node(nid);
56 if (error)
57 return error;
58 /* link memory sections under this node */
59 error = link_mem_sections(nid, pgdat->node_start_pfn, pgdat->node_spanned_pages);
60 }
61
62 return error;
63}
64
Yasunori Goto0fc44152006-06-27 02:53:38 -070065extern void unregister_one_node(int nid);
KAMEZAWA Hiroyuki76b67ed2006-06-27 02:53:41 -070066extern int register_cpu_under_node(unsigned int cpu, unsigned int nid);
67extern int unregister_cpu_under_node(unsigned int cpu, unsigned int nid);
Gary Hadec04fc582009-01-06 14:39:14 -080068extern int register_mem_sect_under_node(struct memory_block *mem_blk,
69 int nid);
Nathan Fontenotd3360162011-01-20 10:44:29 -060070extern int unregister_mem_sect_under_nodes(struct memory_block *mem_blk,
71 unsigned long phys_index);
Lee Schermerhorn9a3052302009-12-14 17:58:25 -080072
73#ifdef CONFIG_HUGETLBFS
74extern void register_hugetlbfs_with_node(node_registration_func_t doregister,
75 node_registration_func_t unregister);
76#endif
KAMEZAWA Hiroyuki76b67ed2006-06-27 02:53:41 -070077#else
Michal Hocko9037a992017-07-06 15:37:49 -070078static inline int __register_one_node(int nid)
79{
80 return 0;
81}
KAMEZAWA Hiroyuki36920e02006-08-27 01:23:52 -070082static inline int register_one_node(int nid)
83{
84 return 0;
85}
86static inline int unregister_one_node(int nid)
87{
88 return 0;
89}
KAMEZAWA Hiroyuki76b67ed2006-06-27 02:53:41 -070090static inline int register_cpu_under_node(unsigned int cpu, unsigned int nid)
91{
92 return 0;
93}
94static inline int unregister_cpu_under_node(unsigned int cpu, unsigned int nid)
95{
96 return 0;
97}
Gary Hadec04fc582009-01-06 14:39:14 -080098static inline int register_mem_sect_under_node(struct memory_block *mem_blk,
99 int nid)
100{
101 return 0;
102}
Nathan Fontenotd3360162011-01-20 10:44:29 -0600103static inline int unregister_mem_sect_under_nodes(struct memory_block *mem_blk,
104 unsigned long phys_index)
Gary Hadec04fc582009-01-06 14:39:14 -0800105{
106 return 0;
107}
Lee Schermerhorn9a3052302009-12-14 17:58:25 -0800108
109static inline void register_hugetlbfs_with_node(node_registration_func_t reg,
110 node_registration_func_t unreg)
111{
112}
KAMEZAWA Hiroyuki76b67ed2006-06-27 02:53:41 -0700113#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114
Kay Sievers10fbcf42011-12-21 14:48:43 -0800115#define to_node(device) container_of(device, struct node, dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116
117#endif /* _LINUX_NODE_H_ */