Commit | Line | Data |
---|---|---|
b2441318 | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
3947be19 DH |
2 | /* |
3 | * include/linux/memory.h - generic memory definition | |
4 | * | |
5 | * This is mainly for topological representation. We define the | |
6 | * basic "struct memory_block" here, which can be embedded in per-arch | |
7 | * definitions or NUMA information. | |
8 | * | |
9 | * Basic handling of the devices is done in drivers/base/memory.c | |
10 | * and system devices are handled in drivers/base/sys.c. | |
11 | * | |
12 | * Memory block are exported via sysfs in the class/memory/devices/ | |
13 | * directory. | |
14 | * | |
15 | */ | |
16 | #ifndef _LINUX_MEMORY_H_ | |
17 | #define _LINUX_MEMORY_H_ | |
18 | ||
3947be19 DH |
19 | #include <linux/node.h> |
20 | #include <linux/compiler.h> | |
da19cbcf | 21 | #include <linux/mutex.h> |
f02c6968 | 22 | #include <linux/notifier.h> |
3947be19 | 23 | |
05cf9639 | 24 | #define MIN_MEMORY_BLOCK_SIZE (1UL << SECTION_SIZE_BITS) |
a63fdc51 | 25 | |
028fc57a DH |
26 | /** |
27 | * struct memory_group - a logical group of memory blocks | |
28 | * @nid: The node id for all memory blocks inside the memory group. | |
29 | * @blocks: List of all memory blocks belonging to this memory group. | |
836809ec DH |
30 | * @present_kernel_pages: Present (online) memory outside ZONE_MOVABLE of this |
31 | * memory group. | |
32 | * @present_movable_pages: Present (online) memory in ZONE_MOVABLE of this | |
33 | * memory group. | |
028fc57a DH |
34 | * @is_dynamic: The memory group type: static vs. dynamic |
35 | * @s.max_pages: Valid with &memory_group.is_dynamic == false. The maximum | |
36 | * number of pages we'll have in this static memory group. | |
37 | * @d.unit_pages: Valid with &memory_group.is_dynamic == true. Unit in pages | |
38 | * in which memory is added/removed in this dynamic memory group. | |
39 | * This granularity defines the alignment of a unit in physical | |
40 | * address space; it has to be at least as big as a single | |
41 | * memory block. | |
42 | * | |
43 | * A memory group logically groups memory blocks; each memory block | |
44 | * belongs to at most one memory group. A memory group corresponds to | |
45 | * a memory device, such as a DIMM or a NUMA node, which spans multiple | |
46 | * memory blocks and might even span multiple non-contiguous physical memory | |
47 | * ranges. | |
48 | * | |
49 | * Modification of members after registration is serialized by memory | |
50 | * hot(un)plug code. | |
51 | */ | |
52 | struct memory_group { | |
53 | int nid; | |
54 | struct list_head memory_blocks; | |
836809ec DH |
55 | unsigned long present_kernel_pages; |
56 | unsigned long present_movable_pages; | |
028fc57a DH |
57 | bool is_dynamic; |
58 | union { | |
59 | struct { | |
60 | unsigned long max_pages; | |
61 | } s; | |
62 | struct { | |
63 | unsigned long unit_pages; | |
64 | } d; | |
65 | }; | |
66 | }; | |
67 | ||
3947be19 | 68 | struct memory_block { |
d3360164 | 69 | unsigned long start_section_nr; |
fa2be40f | 70 | unsigned long state; /* serialized by the dev->lock */ |
fa2be40f | 71 | int online_type; /* for passing data to online routine */ |
d0dc12e8 | 72 | int nid; /* NID for this memory block */ |
395f6081 DH |
73 | /* |
74 | * The single zone of this memory block if all PFNs of this memory block | |
75 | * that are System RAM (not a memory hole, not ZONE_DEVICE ranges) are | |
76 | * managed by a single zone. NULL if multiple zones (including nodes) | |
77 | * apply. | |
78 | */ | |
79 | struct zone *zone; | |
e9a2e48e | 80 | struct device dev; |
a08a2ae3 OS |
81 | /* |
82 | * Number of vmemmap pages. These pages | |
83 | * lay at the beginning of the memory block. | |
84 | */ | |
85 | unsigned long nr_vmemmap_pages; | |
028fc57a DH |
86 | struct memory_group *group; /* group (if any) for this block */ |
87 | struct list_head group_next; /* next block inside memory group */ | |
3947be19 DH |
88 | }; |
89 | ||
bc32df00 | 90 | int arch_get_memory_phys_device(unsigned long start_pfn); |
e0a8400c | 91 | unsigned long memory_block_size_bytes(void); |
f642fb58 | 92 | int set_memory_block_size_order(unsigned int order); |
bc32df00 | 93 | |
3947be19 DH |
94 | /* These states are exposed to userspace as text strings in sysfs */ |
95 | #define MEM_ONLINE (1<<0) /* exposed to userspace */ | |
96 | #define MEM_GOING_OFFLINE (1<<1) /* exposed to userspace */ | |
97 | #define MEM_OFFLINE (1<<2) /* exposed to userspace */ | |
7b78d335 YG |
98 | #define MEM_GOING_ONLINE (1<<3) |
99 | #define MEM_CANCEL_ONLINE (1<<4) | |
100 | #define MEM_CANCEL_OFFLINE (1<<5) | |
3947be19 | 101 | |
7b78d335 YG |
102 | struct memory_notify { |
103 | unsigned long start_pfn; | |
104 | unsigned long nr_pages; | |
d9713679 | 105 | int status_change_nid_normal; |
7b78d335 YG |
106 | int status_change_nid; |
107 | }; | |
3947be19 | 108 | |
8c65b4a6 TS |
109 | struct notifier_block; |
110 | struct mem_section; | |
111 | ||
0c40ba4f ND |
112 | /* |
113 | * Priorities for the hotplug memory callback routines (stored in decreasing | |
114 | * order in the callback chain) | |
115 | */ | |
116 | #define SLAB_CALLBACK_PRI 1 | |
b6b337ad | 117 | #define IPC_CALLBACK_PRI 10 |
0c40ba4f | 118 | |
50f9481e | 119 | #ifndef CONFIG_MEMORY_HOTPLUG |
902ce63b | 120 | static inline void memory_dev_init(void) |
3947be19 | 121 | { |
902ce63b | 122 | return; |
3947be19 DH |
123 | } |
124 | static inline int register_memory_notifier(struct notifier_block *nb) | |
125 | { | |
126 | return 0; | |
127 | } | |
128 | static inline void unregister_memory_notifier(struct notifier_block *nb) | |
129 | { | |
130 | } | |
7b78d335 YG |
131 | static inline int memory_notify(unsigned long val, void *v) |
132 | { | |
133 | return 0; | |
134 | } | |
50f9481e DH |
135 | static inline int hotplug_memory_notifier(notifier_fn_t fn, int pri) |
136 | { | |
137 | return 0; | |
138 | } | |
139 | /* These aren't inline functions due to a GCC bug. */ | |
140 | #define register_hotmemory_notifier(nb) ({ (void)(nb); 0; }) | |
141 | #define unregister_hotmemory_notifier(nb) ({ (void)(nb); }) | |
142 | #else /* CONFIG_MEMORY_HOTPLUG */ | |
7b78d335 YG |
143 | extern int register_memory_notifier(struct notifier_block *nb); |
144 | extern void unregister_memory_notifier(struct notifier_block *nb); | |
a08a2ae3 | 145 | int create_memory_block_devices(unsigned long start, unsigned long size, |
028fc57a DH |
146 | unsigned long vmemmap_pages, |
147 | struct memory_group *group); | |
4c4b7f9b | 148 | void remove_memory_block_devices(unsigned long start, unsigned long size); |
902ce63b | 149 | extern void memory_dev_init(void); |
7b78d335 | 150 | extern int memory_notify(unsigned long val, void *v); |
fc1f5e98 | 151 | extern struct memory_block *find_memory_block(unsigned long section_nr); |
ea884641 DH |
152 | typedef int (*walk_memory_blocks_func_t)(struct memory_block *, void *); |
153 | extern int walk_memory_blocks(unsigned long start, unsigned long size, | |
154 | void *arg, walk_memory_blocks_func_t func); | |
2c91f8fc | 155 | extern int for_each_memory_block(void *arg, walk_memory_blocks_func_t func); |
028fc57a DH |
156 | |
157 | extern int memory_group_register_static(int nid, unsigned long max_pages); | |
158 | extern int memory_group_register_dynamic(int nid, unsigned long unit_pages); | |
159 | extern int memory_group_unregister(int mgid); | |
160 | struct memory_group *memory_group_find_by_id(int mgid); | |
3fcebf90 DH |
161 | typedef int (*walk_memory_groups_func_t)(struct memory_group *, void *); |
162 | int walk_dynamic_memory_groups(int nid, walk_memory_groups_func_t func, | |
163 | struct memory_group *excluded, void *arg); | |
f02c6968 | 164 | #define hotplug_memory_notifier(fn, pri) ({ \ |
02d0e675 | 165 | static __meminitdata struct notifier_block fn##_mem_nb =\ |
f02c6968 | 166 | { .notifier_call = fn, .priority = pri };\ |
3947be19 | 167 | register_memory_notifier(&fn##_mem_nb); \ |
f02c6968 AM |
168 | }) |
169 | #define register_hotmemory_notifier(nb) register_memory_notifier(nb) | |
170 | #define unregister_hotmemory_notifier(nb) unregister_memory_notifier(nb) | |
395f6081 DH |
171 | |
172 | #ifdef CONFIG_NUMA | |
173 | void memory_block_add_nid(struct memory_block *mem, int nid, | |
174 | enum meminit_context context); | |
175 | #endif /* CONFIG_NUMA */ | |
50f9481e | 176 | #endif /* CONFIG_MEMORY_HOTPLUG */ |
3947be19 | 177 | |
0e39ac44 MD |
178 | /* |
179 | * Kernel text modification mutex, used for code patching. Users of this lock | |
180 | * can sleep. | |
181 | */ | |
182 | extern struct mutex text_mutex; | |
183 | ||
3947be19 | 184 | #endif /* _LINUX_MEMORY_H_ */ |