Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* |
| 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | */ |
| 15 | #ifndef _LINUX_NODE_H_ |
| 16 | #define _LINUX_NODE_H_ |
| 17 | |
Kay Sievers | 10fbcf4 | 2011-12-21 14:48:43 -0800 | [diff] [blame] | 18 | #include <linux/device.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | #include <linux/cpumask.h> |
Lee Schermerhorn | 39da08c | 2009-12-14 17:58:36 -0800 | [diff] [blame] | 20 | #include <linux/workqueue.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | |
| 22 | struct node { |
Kay Sievers | 10fbcf4 | 2011-12-21 14:48:43 -0800 | [diff] [blame] | 23 | struct device dev; |
Lee Schermerhorn | 39da08c | 2009-12-14 17:58:36 -0800 | [diff] [blame] | 24 | |
| 25 | #if defined(CONFIG_MEMORY_HOTPLUG_SPARSE) && defined(CONFIG_HUGETLBFS) |
| 26 | struct work_struct node_work; |
| 27 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | }; |
| 29 | |
Gary Hade | c04fc58 | 2009-01-06 14:39:14 -0800 | [diff] [blame] | 30 | struct memory_block; |
Wen Congyang | 8732794 | 2012-12-11 16:00:56 -0800 | [diff] [blame] | 31 | extern struct node *node_devices[]; |
Lee Schermerhorn | 9a305230 | 2009-12-14 17:58:25 -0800 | [diff] [blame] | 32 | typedef void (*node_registration_func_t)(struct node *); |
Yasunori Goto | 0fc4415 | 2006-06-27 02:53:38 -0700 | [diff] [blame] | 33 | |
Michal Hocko | 9037a99 | 2017-07-06 15:37:49 -0700 | [diff] [blame] | 34 | #if defined(CONFIG_MEMORY_HOTPLUG_SPARSE) && defined(CONFIG_NUMA) |
| 35 | extern int link_mem_sections(int nid, unsigned long start_pfn, unsigned long nr_pages); |
| 36 | #else |
| 37 | static inline int link_mem_sections(int nid, unsigned long start_pfn, unsigned long nr_pages) |
| 38 | { |
| 39 | return 0; |
| 40 | } |
| 41 | #endif |
| 42 | |
Keiichiro Tokunaga | 4b45099 | 2005-05-08 21:28:53 +0900 | [diff] [blame] | 43 | extern void unregister_node(struct node *node); |
KAMEZAWA Hiroyuki | 36920e0 | 2006-08-27 01:23:52 -0700 | [diff] [blame] | 44 | #ifdef CONFIG_NUMA |
Michal Hocko | 9037a99 | 2017-07-06 15:37:49 -0700 | [diff] [blame] | 45 | /* Core of the node registration - only memory hotplug should use this */ |
| 46 | extern int __register_one_node(int nid); |
| 47 | |
| 48 | /* Registers an online node */ |
| 49 | static 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 Goto | 0fc4415 | 2006-06-27 02:53:38 -0700 | [diff] [blame] | 66 | extern void unregister_one_node(int nid); |
KAMEZAWA Hiroyuki | 76b67ed | 2006-06-27 02:53:41 -0700 | [diff] [blame] | 67 | extern int register_cpu_under_node(unsigned int cpu, unsigned int nid); |
| 68 | extern int unregister_cpu_under_node(unsigned int cpu, unsigned int nid); |
Gary Hade | c04fc58 | 2009-01-06 14:39:14 -0800 | [diff] [blame] | 69 | extern int register_mem_sect_under_node(struct memory_block *mem_blk, |
Pavel Tatashin | fc44f7f | 2018-04-05 16:22:56 -0700 | [diff] [blame] | 70 | int nid, bool check_nid); |
Nathan Fontenot | d336016 | 2011-01-20 10:44:29 -0600 | [diff] [blame] | 71 | extern int unregister_mem_sect_under_nodes(struct memory_block *mem_blk, |
| 72 | unsigned long phys_index); |
Lee Schermerhorn | 9a305230 | 2009-12-14 17:58:25 -0800 | [diff] [blame] | 73 | |
| 74 | #ifdef CONFIG_HUGETLBFS |
| 75 | extern void register_hugetlbfs_with_node(node_registration_func_t doregister, |
| 76 | node_registration_func_t unregister); |
| 77 | #endif |
KAMEZAWA Hiroyuki | 76b67ed | 2006-06-27 02:53:41 -0700 | [diff] [blame] | 78 | #else |
Michal Hocko | 9037a99 | 2017-07-06 15:37:49 -0700 | [diff] [blame] | 79 | static inline int __register_one_node(int nid) |
| 80 | { |
| 81 | return 0; |
| 82 | } |
KAMEZAWA Hiroyuki | 36920e0 | 2006-08-27 01:23:52 -0700 | [diff] [blame] | 83 | static inline int register_one_node(int nid) |
| 84 | { |
| 85 | return 0; |
| 86 | } |
| 87 | static inline int unregister_one_node(int nid) |
| 88 | { |
| 89 | return 0; |
| 90 | } |
KAMEZAWA Hiroyuki | 76b67ed | 2006-06-27 02:53:41 -0700 | [diff] [blame] | 91 | static inline int register_cpu_under_node(unsigned int cpu, unsigned int nid) |
| 92 | { |
| 93 | return 0; |
| 94 | } |
| 95 | static inline int unregister_cpu_under_node(unsigned int cpu, unsigned int nid) |
| 96 | { |
| 97 | return 0; |
| 98 | } |
Gary Hade | c04fc58 | 2009-01-06 14:39:14 -0800 | [diff] [blame] | 99 | static inline int register_mem_sect_under_node(struct memory_block *mem_blk, |
Pavel Tatashin | fc44f7f | 2018-04-05 16:22:56 -0700 | [diff] [blame] | 100 | int nid, bool check_nid) |
Gary Hade | c04fc58 | 2009-01-06 14:39:14 -0800 | [diff] [blame] | 101 | { |
| 102 | return 0; |
| 103 | } |
Nathan Fontenot | d336016 | 2011-01-20 10:44:29 -0600 | [diff] [blame] | 104 | static inline int unregister_mem_sect_under_nodes(struct memory_block *mem_blk, |
| 105 | unsigned long phys_index) |
Gary Hade | c04fc58 | 2009-01-06 14:39:14 -0800 | [diff] [blame] | 106 | { |
| 107 | return 0; |
| 108 | } |
Lee Schermerhorn | 9a305230 | 2009-12-14 17:58:25 -0800 | [diff] [blame] | 109 | |
| 110 | static inline void register_hugetlbfs_with_node(node_registration_func_t reg, |
| 111 | node_registration_func_t unreg) |
| 112 | { |
| 113 | } |
KAMEZAWA Hiroyuki | 76b67ed | 2006-06-27 02:53:41 -0700 | [diff] [blame] | 114 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | |
Kay Sievers | 10fbcf4 | 2011-12-21 14:48:43 -0800 | [diff] [blame] | 116 | #define to_node(device) container_of(device, struct node, dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | |
| 118 | #endif /* _LINUX_NODE_H_ */ |