blob: 6d336e38d155e46ad4deff6dbabb7bf413795b5b [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,
36 unsigned long nr_pages, bool check_nid);
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,
39 unsigned long nr_pages, bool check_nid)
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);
57
58 error = __register_one_node(nid);
59 if (error)
60 return error;
61 /* link memory sections under this node */
Jonathan Camerona2155862018-05-25 14:47:53 -070062 error = link_mem_sections(nid, pgdat->node_start_pfn, pgdat->node_spanned_pages, true);
Michal Hocko9037a992017-07-06 15:37:49 -070063 }
64
65 return error;
66}
67
Yasunori Goto0fc44152006-06-27 02:53:38 -070068extern void unregister_one_node(int nid);
KAMEZAWA Hiroyuki76b67ed2006-06-27 02:53:41 -070069extern int register_cpu_under_node(unsigned int cpu, unsigned int nid);
70extern int unregister_cpu_under_node(unsigned int cpu, unsigned int nid);
Gary Hadec04fc582009-01-06 14:39:14 -080071extern int register_mem_sect_under_node(struct memory_block *mem_blk,
Pavel Tatashinfc44f7f2018-04-05 16:22:56 -070072 int nid, bool check_nid);
Nathan Fontenotd3360162011-01-20 10:44:29 -060073extern int unregister_mem_sect_under_nodes(struct memory_block *mem_blk,
74 unsigned long phys_index);
Lee Schermerhorn9a3052302009-12-14 17:58:25 -080075
76#ifdef CONFIG_HUGETLBFS
77extern void register_hugetlbfs_with_node(node_registration_func_t doregister,
78 node_registration_func_t unregister);
79#endif
KAMEZAWA Hiroyuki76b67ed2006-06-27 02:53:41 -070080#else
Michal Hocko9037a992017-07-06 15:37:49 -070081static inline int __register_one_node(int nid)
82{
83 return 0;
84}
KAMEZAWA Hiroyuki36920e02006-08-27 01:23:52 -070085static inline int register_one_node(int nid)
86{
87 return 0;
88}
89static inline int unregister_one_node(int nid)
90{
91 return 0;
92}
KAMEZAWA Hiroyuki76b67ed2006-06-27 02:53:41 -070093static inline int register_cpu_under_node(unsigned int cpu, unsigned int nid)
94{
95 return 0;
96}
97static inline int unregister_cpu_under_node(unsigned int cpu, unsigned int nid)
98{
99 return 0;
100}
Gary Hadec04fc582009-01-06 14:39:14 -0800101static inline int register_mem_sect_under_node(struct memory_block *mem_blk,
Pavel Tatashinfc44f7f2018-04-05 16:22:56 -0700102 int nid, bool check_nid)
Gary Hadec04fc582009-01-06 14:39:14 -0800103{
104 return 0;
105}
Nathan Fontenotd3360162011-01-20 10:44:29 -0600106static inline int unregister_mem_sect_under_nodes(struct memory_block *mem_blk,
107 unsigned long phys_index)
Gary Hadec04fc582009-01-06 14:39:14 -0800108{
109 return 0;
110}
Lee Schermerhorn9a3052302009-12-14 17:58:25 -0800111
112static inline void register_hugetlbfs_with_node(node_registration_func_t reg,
113 node_registration_func_t unreg)
114{
115}
KAMEZAWA Hiroyuki76b67ed2006-06-27 02:53:41 -0700116#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117
Kay Sievers10fbcf42011-12-21 14:48:43 -0800118#define to_node(device) container_of(device, struct node, dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119
120#endif /* _LINUX_NODE_H_ */