blob: 41f171861dccdc4aa6727303e2261e702bbfe6bd [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)
35extern int link_mem_sections(int nid, unsigned long start_pfn, unsigned long nr_pages);
36#else
37static inline int link_mem_sections(int nid, unsigned long start_pfn, unsigned long nr_pages)
38{
39 return 0;
40}
41#endif
42
Keiichiro Tokunaga4b450992005-05-08 21:28:53 +090043extern void unregister_node(struct node *node);
KAMEZAWA Hiroyuki36920e02006-08-27 01:23:52 -070044#ifdef CONFIG_NUMA
Michal Hocko9037a992017-07-06 15:37:49 -070045/* Core of the node registration - only memory hotplug should use this */
46extern int __register_one_node(int nid);
47
48/* Registers an online node */
49static inline int register_one_node(int nid)
50{
51 int error = 0;
52
53 if (node_online(nid)) {
54 struct pglist_data *pgdat = NODE_DATA(nid);
55
56 error = __register_one_node(nid);
57 if (error)
58 return error;
59 /* link memory sections under this node */
60 error = link_mem_sections(nid, pgdat->node_start_pfn, pgdat->node_spanned_pages);
61 }
62
63 return error;
64}
65
Yasunori Goto0fc44152006-06-27 02:53:38 -070066extern void unregister_one_node(int nid);
KAMEZAWA Hiroyuki76b67ed2006-06-27 02:53:41 -070067extern int register_cpu_under_node(unsigned int cpu, unsigned int nid);
68extern int unregister_cpu_under_node(unsigned int cpu, unsigned int nid);
Gary Hadec04fc582009-01-06 14:39:14 -080069extern int register_mem_sect_under_node(struct memory_block *mem_blk,
Pavel Tatashinfc44f7f2018-04-05 16:22:56 -070070 int nid, bool check_nid);
Nathan Fontenotd3360162011-01-20 10:44:29 -060071extern int unregister_mem_sect_under_nodes(struct memory_block *mem_blk,
72 unsigned long phys_index);
Lee Schermerhorn9a3052302009-12-14 17:58:25 -080073
74#ifdef CONFIG_HUGETLBFS
75extern void register_hugetlbfs_with_node(node_registration_func_t doregister,
76 node_registration_func_t unregister);
77#endif
KAMEZAWA Hiroyuki76b67ed2006-06-27 02:53:41 -070078#else
Michal Hocko9037a992017-07-06 15:37:49 -070079static inline int __register_one_node(int nid)
80{
81 return 0;
82}
KAMEZAWA Hiroyuki36920e02006-08-27 01:23:52 -070083static inline int register_one_node(int nid)
84{
85 return 0;
86}
87static inline int unregister_one_node(int nid)
88{
89 return 0;
90}
KAMEZAWA Hiroyuki76b67ed2006-06-27 02:53:41 -070091static inline int register_cpu_under_node(unsigned int cpu, unsigned int nid)
92{
93 return 0;
94}
95static inline int unregister_cpu_under_node(unsigned int cpu, unsigned int nid)
96{
97 return 0;
98}
Gary Hadec04fc582009-01-06 14:39:14 -080099static inline int register_mem_sect_under_node(struct memory_block *mem_blk,
Pavel Tatashinfc44f7f2018-04-05 16:22:56 -0700100 int nid, bool check_nid)
Gary Hadec04fc582009-01-06 14:39:14 -0800101{
102 return 0;
103}
Nathan Fontenotd3360162011-01-20 10:44:29 -0600104static inline int unregister_mem_sect_under_nodes(struct memory_block *mem_blk,
105 unsigned long phys_index)
Gary Hadec04fc582009-01-06 14:39:14 -0800106{
107 return 0;
108}
Lee Schermerhorn9a3052302009-12-14 17:58:25 -0800109
110static inline void register_hugetlbfs_with_node(node_registration_func_t reg,
111 node_registration_func_t unreg)
112{
113}
KAMEZAWA Hiroyuki76b67ed2006-06-27 02:53:41 -0700114#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115
Kay Sievers10fbcf42011-12-21 14:48:43 -0800116#define to_node(device) container_of(device, struct node, dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117
118#endif /* _LINUX_NODE_H_ */