Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * include/linux/node.h - generic node definition |
| 3 | * |
| 4 | * This is mainly for topological representation. We define the |
| 5 | * basic 'struct node' here, which can be embedded in per-arch |
| 6 | * definitions of processors. |
| 7 | * |
| 8 | * Basic handling of the devices is done in drivers/base/node.c |
| 9 | * and system devices are handled in drivers/base/sys.c. |
| 10 | * |
| 11 | * Nodes are exported via driverfs in the class/node/devices/ |
| 12 | * directory. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | */ |
| 14 | #ifndef _LINUX_NODE_H_ |
| 15 | #define _LINUX_NODE_H_ |
| 16 | |
Kay Sievers | 10fbcf4 | 2011-12-21 14:48:43 -0800 | [diff] [blame] | 17 | #include <linux/device.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | #include <linux/cpumask.h> |
Lee Schermerhorn | 39da08c | 2009-12-14 17:58:36 -0800 | [diff] [blame] | 19 | #include <linux/workqueue.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | |
| 21 | struct node { |
Kay Sievers | 10fbcf4 | 2011-12-21 14:48:43 -0800 | [diff] [blame] | 22 | struct device dev; |
Lee Schermerhorn | 39da08c | 2009-12-14 17:58:36 -0800 | [diff] [blame] | 23 | |
| 24 | #if defined(CONFIG_MEMORY_HOTPLUG_SPARSE) && defined(CONFIG_HUGETLBFS) |
| 25 | struct work_struct node_work; |
| 26 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | }; |
| 28 | |
Gary Hade | c04fc58 | 2009-01-06 14:39:14 -0800 | [diff] [blame] | 29 | struct memory_block; |
Wen Congyang | 8732794 | 2012-12-11 16:00:56 -0800 | [diff] [blame] | 30 | extern struct node *node_devices[]; |
Lee Schermerhorn | 9a305230 | 2009-12-14 17:58:25 -0800 | [diff] [blame] | 31 | typedef void (*node_registration_func_t)(struct node *); |
Yasunori Goto | 0fc4415 | 2006-06-27 02:53:38 -0700 | [diff] [blame] | 32 | |
Michal Hocko | 9037a99 | 2017-07-06 15:37:49 -0700 | [diff] [blame] | 33 | #if defined(CONFIG_MEMORY_HOTPLUG_SPARSE) && defined(CONFIG_NUMA) |
| 34 | extern int link_mem_sections(int nid, unsigned long start_pfn, unsigned long nr_pages); |
| 35 | #else |
| 36 | static inline int link_mem_sections(int nid, unsigned long start_pfn, unsigned long nr_pages) |
| 37 | { |
| 38 | return 0; |
| 39 | } |
| 40 | #endif |
| 41 | |
Keiichiro Tokunaga | 4b45099 | 2005-05-08 21:28:53 +0900 | [diff] [blame] | 42 | extern void unregister_node(struct node *node); |
KAMEZAWA Hiroyuki | 36920e0 | 2006-08-27 01:23:52 -0700 | [diff] [blame] | 43 | #ifdef CONFIG_NUMA |
Michal Hocko | 9037a99 | 2017-07-06 15:37:49 -0700 | [diff] [blame] | 44 | /* Core of the node registration - only memory hotplug should use this */ |
| 45 | extern int __register_one_node(int nid); |
| 46 | |
| 47 | /* Registers an online node */ |
| 48 | static inline int register_one_node(int nid) |
| 49 | { |
| 50 | int error = 0; |
| 51 | |
| 52 | if (node_online(nid)) { |
| 53 | struct pglist_data *pgdat = NODE_DATA(nid); |
| 54 | |
| 55 | error = __register_one_node(nid); |
| 56 | if (error) |
| 57 | return error; |
| 58 | /* link memory sections under this node */ |
| 59 | error = link_mem_sections(nid, pgdat->node_start_pfn, pgdat->node_spanned_pages); |
| 60 | } |
| 61 | |
| 62 | return error; |
| 63 | } |
| 64 | |
Yasunori Goto | 0fc4415 | 2006-06-27 02:53:38 -0700 | [diff] [blame] | 65 | extern void unregister_one_node(int nid); |
KAMEZAWA Hiroyuki | 76b67ed | 2006-06-27 02:53:41 -0700 | [diff] [blame] | 66 | extern int register_cpu_under_node(unsigned int cpu, unsigned int nid); |
| 67 | extern int unregister_cpu_under_node(unsigned int cpu, unsigned int nid); |
Gary Hade | c04fc58 | 2009-01-06 14:39:14 -0800 | [diff] [blame] | 68 | extern int register_mem_sect_under_node(struct memory_block *mem_blk, |
| 69 | int nid); |
Nathan Fontenot | d336016 | 2011-01-20 10:44:29 -0600 | [diff] [blame] | 70 | extern int unregister_mem_sect_under_nodes(struct memory_block *mem_blk, |
| 71 | unsigned long phys_index); |
Lee Schermerhorn | 9a305230 | 2009-12-14 17:58:25 -0800 | [diff] [blame] | 72 | |
| 73 | #ifdef CONFIG_HUGETLBFS |
| 74 | extern void register_hugetlbfs_with_node(node_registration_func_t doregister, |
| 75 | node_registration_func_t unregister); |
| 76 | #endif |
KAMEZAWA Hiroyuki | 76b67ed | 2006-06-27 02:53:41 -0700 | [diff] [blame] | 77 | #else |
Michal Hocko | 9037a99 | 2017-07-06 15:37:49 -0700 | [diff] [blame] | 78 | static inline int __register_one_node(int nid) |
| 79 | { |
| 80 | return 0; |
| 81 | } |
KAMEZAWA Hiroyuki | 36920e0 | 2006-08-27 01:23:52 -0700 | [diff] [blame] | 82 | static inline int register_one_node(int nid) |
| 83 | { |
| 84 | return 0; |
| 85 | } |
| 86 | static inline int unregister_one_node(int nid) |
| 87 | { |
| 88 | return 0; |
| 89 | } |
KAMEZAWA Hiroyuki | 76b67ed | 2006-06-27 02:53:41 -0700 | [diff] [blame] | 90 | static inline int register_cpu_under_node(unsigned int cpu, unsigned int nid) |
| 91 | { |
| 92 | return 0; |
| 93 | } |
| 94 | static inline int unregister_cpu_under_node(unsigned int cpu, unsigned int nid) |
| 95 | { |
| 96 | return 0; |
| 97 | } |
Gary Hade | c04fc58 | 2009-01-06 14:39:14 -0800 | [diff] [blame] | 98 | static inline int register_mem_sect_under_node(struct memory_block *mem_blk, |
| 99 | int nid) |
| 100 | { |
| 101 | return 0; |
| 102 | } |
Nathan Fontenot | d336016 | 2011-01-20 10:44:29 -0600 | [diff] [blame] | 103 | static inline int unregister_mem_sect_under_nodes(struct memory_block *mem_blk, |
| 104 | unsigned long phys_index) |
Gary Hade | c04fc58 | 2009-01-06 14:39:14 -0800 | [diff] [blame] | 105 | { |
| 106 | return 0; |
| 107 | } |
Lee Schermerhorn | 9a305230 | 2009-12-14 17:58:25 -0800 | [diff] [blame] | 108 | |
| 109 | static inline void register_hugetlbfs_with_node(node_registration_func_t reg, |
| 110 | node_registration_func_t unreg) |
| 111 | { |
| 112 | } |
KAMEZAWA Hiroyuki | 76b67ed | 2006-06-27 02:53:41 -0700 | [diff] [blame] | 113 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | |
Kay Sievers | 10fbcf4 | 2011-12-21 14:48:43 -0800 | [diff] [blame] | 115 | #define to_node(device) container_of(device, struct node, dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | |
| 117 | #endif /* _LINUX_NODE_H_ */ |