blob: bb288817ed331a66f1642bb0b6f476a4c5ad016c [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>
Keith Busch08d9dbe2019-03-11 14:56:00 -060020#include <linux/list.h>
Lee Schermerhorn39da08c2009-12-14 17:58:36 -080021#include <linux/workqueue.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070022
23struct node {
Kay Sievers10fbcf42011-12-21 14:48:43 -080024 struct device dev;
Keith Busch08d9dbe2019-03-11 14:56:00 -060025 struct list_head access_list;
Lee Schermerhorn39da08c2009-12-14 17:58:36 -080026
27#if defined(CONFIG_MEMORY_HOTPLUG_SPARSE) && defined(CONFIG_HUGETLBFS)
28 struct work_struct node_work;
29#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070030};
31
Gary Hadec04fc582009-01-06 14:39:14 -080032struct memory_block;
Wen Congyang87327942012-12-11 16:00:56 -080033extern struct node *node_devices[];
Lee Schermerhorn9a3052302009-12-14 17:58:25 -080034typedef void (*node_registration_func_t)(struct node *);
Yasunori Goto0fc44152006-06-27 02:53:38 -070035
Michal Hocko9037a992017-07-06 15:37:49 -070036#if defined(CONFIG_MEMORY_HOTPLUG_SPARSE) && defined(CONFIG_NUMA)
Jonathan Camerona2155862018-05-25 14:47:53 -070037extern int link_mem_sections(int nid, unsigned long start_pfn,
Oscar Salvador4fbce632018-08-17 15:46:22 -070038 unsigned long end_pfn);
Michal Hocko9037a992017-07-06 15:37:49 -070039#else
Jonathan Camerona2155862018-05-25 14:47:53 -070040static inline int link_mem_sections(int nid, unsigned long start_pfn,
Oscar Salvador4fbce632018-08-17 15:46:22 -070041 unsigned long end_pfn)
Michal Hocko9037a992017-07-06 15:37:49 -070042{
43 return 0;
44}
45#endif
46
Keiichiro Tokunaga4b450992005-05-08 21:28:53 +090047extern void unregister_node(struct node *node);
KAMEZAWA Hiroyuki36920e02006-08-27 01:23:52 -070048#ifdef CONFIG_NUMA
Michal Hocko9037a992017-07-06 15:37:49 -070049/* Core of the node registration - only memory hotplug should use this */
50extern int __register_one_node(int nid);
51
52/* Registers an online node */
53static inline int register_one_node(int nid)
54{
55 int error = 0;
56
57 if (node_online(nid)) {
58 struct pglist_data *pgdat = NODE_DATA(nid);
Oscar Salvador4fbce632018-08-17 15:46:22 -070059 unsigned long start_pfn = pgdat->node_start_pfn;
60 unsigned long end_pfn = start_pfn + pgdat->node_spanned_pages;
Michal Hocko9037a992017-07-06 15:37:49 -070061
62 error = __register_one_node(nid);
63 if (error)
64 return error;
65 /* link memory sections under this node */
Oscar Salvador4fbce632018-08-17 15:46:22 -070066 error = link_mem_sections(nid, start_pfn, end_pfn);
Michal Hocko9037a992017-07-06 15:37:49 -070067 }
68
69 return error;
70}
71
Yasunori Goto0fc44152006-06-27 02:53:38 -070072extern void unregister_one_node(int nid);
KAMEZAWA Hiroyuki76b67ed2006-06-27 02:53:41 -070073extern int register_cpu_under_node(unsigned int cpu, unsigned int nid);
74extern int unregister_cpu_under_node(unsigned int cpu, unsigned int nid);
Gary Hadec04fc582009-01-06 14:39:14 -080075extern int register_mem_sect_under_node(struct memory_block *mem_blk,
Oscar Salvador4fbce632018-08-17 15:46:22 -070076 void *arg);
Nathan Fontenotd3360162011-01-20 10:44:29 -060077extern int unregister_mem_sect_under_nodes(struct memory_block *mem_blk,
78 unsigned long phys_index);
Lee Schermerhorn9a3052302009-12-14 17:58:25 -080079
Keith Busch08d9dbe2019-03-11 14:56:00 -060080extern int register_memory_node_under_compute_node(unsigned int mem_nid,
81 unsigned int cpu_nid,
82 unsigned access);
83
Lee Schermerhorn9a3052302009-12-14 17:58:25 -080084#ifdef CONFIG_HUGETLBFS
85extern void register_hugetlbfs_with_node(node_registration_func_t doregister,
86 node_registration_func_t unregister);
87#endif
KAMEZAWA Hiroyuki76b67ed2006-06-27 02:53:41 -070088#else
Michal Hocko9037a992017-07-06 15:37:49 -070089static inline int __register_one_node(int nid)
90{
91 return 0;
92}
KAMEZAWA Hiroyuki36920e02006-08-27 01:23:52 -070093static inline int register_one_node(int nid)
94{
95 return 0;
96}
97static inline int unregister_one_node(int nid)
98{
99 return 0;
100}
KAMEZAWA Hiroyuki76b67ed2006-06-27 02:53:41 -0700101static inline int register_cpu_under_node(unsigned int cpu, unsigned int nid)
102{
103 return 0;
104}
105static inline int unregister_cpu_under_node(unsigned int cpu, unsigned int nid)
106{
107 return 0;
108}
Gary Hadec04fc582009-01-06 14:39:14 -0800109static inline int register_mem_sect_under_node(struct memory_block *mem_blk,
Oscar Salvador4fbce632018-08-17 15:46:22 -0700110 void *arg)
Gary Hadec04fc582009-01-06 14:39:14 -0800111{
112 return 0;
113}
Nathan Fontenotd3360162011-01-20 10:44:29 -0600114static inline int unregister_mem_sect_under_nodes(struct memory_block *mem_blk,
115 unsigned long phys_index)
Gary Hadec04fc582009-01-06 14:39:14 -0800116{
117 return 0;
118}
Lee Schermerhorn9a3052302009-12-14 17:58:25 -0800119
120static inline void register_hugetlbfs_with_node(node_registration_func_t reg,
121 node_registration_func_t unreg)
122{
123}
KAMEZAWA Hiroyuki76b67ed2006-06-27 02:53:41 -0700124#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125
Kay Sievers10fbcf42011-12-21 14:48:43 -0800126#define to_node(device) container_of(device, struct node, dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127
128#endif /* _LINUX_NODE_H_ */