blob: 257bb3d6d0143740188f93c1cd0f9c58eb4697e6 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
3 * include/linux/node.h - generic node definition
4 *
5 * This is mainly for topological representation. We define the
6 * basic 'struct node' here, which can be embedded in per-arch
7 * definitions of processors.
8 *
9 * Basic handling of the devices is done in drivers/base/node.c
10 * and system devices are handled in drivers/base/sys.c.
11 *
12 * Nodes are exported via driverfs in the class/node/devices/
13 * directory.
Linus Torvalds1da177e2005-04-16 15:20:36 -070014 */
15#ifndef _LINUX_NODE_H_
16#define _LINUX_NODE_H_
17
Kay Sievers10fbcf42011-12-21 14:48:43 -080018#include <linux/device.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070019#include <linux/cpumask.h>
Lee Schermerhorn39da08c2009-12-14 17:58:36 -080020#include <linux/workqueue.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070021
22struct node {
Kay Sievers10fbcf42011-12-21 14:48:43 -080023 struct device dev;
Lee Schermerhorn39da08c2009-12-14 17:58:36 -080024
25#if defined(CONFIG_MEMORY_HOTPLUG_SPARSE) && defined(CONFIG_HUGETLBFS)
26 struct work_struct node_work;
27#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070028};
29
Gary Hadec04fc582009-01-06 14:39:14 -080030struct memory_block;
Wen Congyang87327942012-12-11 16:00:56 -080031extern struct node *node_devices[];
Lee Schermerhorn9a3052302009-12-14 17:58:25 -080032typedef void (*node_registration_func_t)(struct node *);
Yasunori Goto0fc44152006-06-27 02:53:38 -070033
Michal Hocko9037a992017-07-06 15:37:49 -070034#if defined(CONFIG_MEMORY_HOTPLUG_SPARSE) && defined(CONFIG_NUMA)
Jonathan Camerona2155862018-05-25 14:47:53 -070035extern int link_mem_sections(int nid, unsigned long start_pfn,
Oscar Salvador4fbce632018-08-17 15:46:22 -070036 unsigned long end_pfn);
Michal Hocko9037a992017-07-06 15:37:49 -070037#else
Jonathan Camerona2155862018-05-25 14:47:53 -070038static inline int link_mem_sections(int nid, unsigned long start_pfn,
Oscar Salvador4fbce632018-08-17 15:46:22 -070039 unsigned long end_pfn)
Michal Hocko9037a992017-07-06 15:37:49 -070040{
41 return 0;
42}
43#endif
44
Keiichiro Tokunaga4b450992005-05-08 21:28:53 +090045extern void unregister_node(struct node *node);
KAMEZAWA Hiroyuki36920e02006-08-27 01:23:52 -070046#ifdef CONFIG_NUMA
Michal Hocko9037a992017-07-06 15:37:49 -070047/* Core of the node registration - only memory hotplug should use this */
48extern int __register_one_node(int nid);
49
50/* Registers an online node */
51static inline int register_one_node(int nid)
52{
53 int error = 0;
54
55 if (node_online(nid)) {
56 struct pglist_data *pgdat = NODE_DATA(nid);
Oscar Salvador4fbce632018-08-17 15:46:22 -070057 unsigned long start_pfn = pgdat->node_start_pfn;
58 unsigned long end_pfn = start_pfn + pgdat->node_spanned_pages;
Michal Hocko9037a992017-07-06 15:37:49 -070059
60 error = __register_one_node(nid);
61 if (error)
62 return error;
63 /* link memory sections under this node */
Oscar Salvador4fbce632018-08-17 15:46:22 -070064 error = link_mem_sections(nid, start_pfn, end_pfn);
Michal Hocko9037a992017-07-06 15:37:49 -070065 }
66
67 return error;
68}
69
Yasunori Goto0fc44152006-06-27 02:53:38 -070070extern void unregister_one_node(int nid);
KAMEZAWA Hiroyuki76b67ed2006-06-27 02:53:41 -070071extern int register_cpu_under_node(unsigned int cpu, unsigned int nid);
72extern int unregister_cpu_under_node(unsigned int cpu, unsigned int nid);
Gary Hadec04fc582009-01-06 14:39:14 -080073extern int register_mem_sect_under_node(struct memory_block *mem_blk,
Oscar Salvador4fbce632018-08-17 15:46:22 -070074 void *arg);
Nathan Fontenotd3360162011-01-20 10:44:29 -060075extern int unregister_mem_sect_under_nodes(struct memory_block *mem_blk,
76 unsigned long phys_index);
Lee Schermerhorn9a3052302009-12-14 17:58:25 -080077
78#ifdef CONFIG_HUGETLBFS
79extern void register_hugetlbfs_with_node(node_registration_func_t doregister,
80 node_registration_func_t unregister);
81#endif
KAMEZAWA Hiroyuki76b67ed2006-06-27 02:53:41 -070082#else
Michal Hocko9037a992017-07-06 15:37:49 -070083static inline int __register_one_node(int nid)
84{
85 return 0;
86}
KAMEZAWA Hiroyuki36920e02006-08-27 01:23:52 -070087static inline int register_one_node(int nid)
88{
89 return 0;
90}
91static inline int unregister_one_node(int nid)
92{
93 return 0;
94}
KAMEZAWA Hiroyuki76b67ed2006-06-27 02:53:41 -070095static inline int register_cpu_under_node(unsigned int cpu, unsigned int nid)
96{
97 return 0;
98}
99static inline int unregister_cpu_under_node(unsigned int cpu, unsigned int nid)
100{
101 return 0;
102}
Gary Hadec04fc582009-01-06 14:39:14 -0800103static inline int register_mem_sect_under_node(struct memory_block *mem_blk,
Oscar Salvador4fbce632018-08-17 15:46:22 -0700104 void *arg)
Gary Hadec04fc582009-01-06 14:39:14 -0800105{
106 return 0;
107}
Nathan Fontenotd3360162011-01-20 10:44:29 -0600108static inline int unregister_mem_sect_under_nodes(struct memory_block *mem_blk,
109 unsigned long phys_index)
Gary Hadec04fc582009-01-06 14:39:14 -0800110{
111 return 0;
112}
Lee Schermerhorn9a3052302009-12-14 17:58:25 -0800113
114static inline void register_hugetlbfs_with_node(node_registration_func_t reg,
115 node_registration_func_t unreg)
116{
117}
KAMEZAWA Hiroyuki76b67ed2006-06-27 02:53:41 -0700118#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119
Kay Sievers10fbcf42011-12-21 14:48:43 -0800120#define to_node(device) container_of(device, struct node, dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121
122#endif /* _LINUX_NODE_H_ */