1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16#ifndef _LINUX_MEMORY_H_
17#define _LINUX_MEMORY_H_
18
19#include <linux/node.h>
20#include <linux/compiler.h>
21#include <linux/mutex.h>
22#include <linux/notifier.h>
23
24#define MIN_MEMORY_BLOCK_SIZE (1UL << SECTION_SIZE_BITS)
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52struct memory_group {
53 int nid;
54 struct list_head memory_blocks;
55 unsigned long present_kernel_pages;
56 unsigned long present_movable_pages;
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
68struct memory_block {
69 unsigned long start_section_nr;
70 unsigned long state;
71 int online_type;
72 int nid;
73 struct device dev;
74
75
76
77
78 unsigned long nr_vmemmap_pages;
79 struct memory_group *group;
80 struct list_head group_next;
81};
82
83int arch_get_memory_phys_device(unsigned long start_pfn);
84unsigned long memory_block_size_bytes(void);
85int set_memory_block_size_order(unsigned int order);
86
87
88#define MEM_ONLINE (1<<0)
89#define MEM_GOING_OFFLINE (1<<1)
90#define MEM_OFFLINE (1<<2)
91#define MEM_GOING_ONLINE (1<<3)
92#define MEM_CANCEL_ONLINE (1<<4)
93#define MEM_CANCEL_OFFLINE (1<<5)
94
95struct memory_notify {
96 unsigned long start_pfn;
97 unsigned long nr_pages;
98 int status_change_nid_normal;
99 int status_change_nid_high;
100 int status_change_nid;
101};
102
103struct notifier_block;
104struct mem_section;
105
106
107
108
109
110#define SLAB_CALLBACK_PRI 1
111#define IPC_CALLBACK_PRI 10
112
113#ifndef CONFIG_MEMORY_HOTPLUG_SPARSE
114static inline void memory_dev_init(void)
115{
116 return;
117}
118static inline int register_memory_notifier(struct notifier_block *nb)
119{
120 return 0;
121}
122static inline void unregister_memory_notifier(struct notifier_block *nb)
123{
124}
125static inline int memory_notify(unsigned long val, void *v)
126{
127 return 0;
128}
129#else
130extern int register_memory_notifier(struct notifier_block *nb);
131extern void unregister_memory_notifier(struct notifier_block *nb);
132int create_memory_block_devices(unsigned long start, unsigned long size,
133 unsigned long vmemmap_pages,
134 struct memory_group *group);
135void remove_memory_block_devices(unsigned long start, unsigned long size);
136extern void memory_dev_init(void);
137extern int memory_notify(unsigned long val, void *v);
138extern struct memory_block *find_memory_block(unsigned long section_nr);
139typedef int (*walk_memory_blocks_func_t)(struct memory_block *, void *);
140extern int walk_memory_blocks(unsigned long start, unsigned long size,
141 void *arg, walk_memory_blocks_func_t func);
142extern int for_each_memory_block(void *arg, walk_memory_blocks_func_t func);
143#define CONFIG_MEM_BLOCK_SIZE (PAGES_PER_SECTION<<PAGE_SHIFT)
144
145extern int memory_group_register_static(int nid, unsigned long max_pages);
146extern int memory_group_register_dynamic(int nid, unsigned long unit_pages);
147extern int memory_group_unregister(int mgid);
148struct memory_group *memory_group_find_by_id(int mgid);
149typedef int (*walk_memory_groups_func_t)(struct memory_group *, void *);
150int walk_dynamic_memory_groups(int nid, walk_memory_groups_func_t func,
151 struct memory_group *excluded, void *arg);
152#endif
153
154#ifdef CONFIG_MEMORY_HOTPLUG
155#define hotplug_memory_notifier(fn, pri) ({ \
156 static __meminitdata struct notifier_block fn##_mem_nb =\
157 { .notifier_call = fn, .priority = pri };\
158 register_memory_notifier(&fn##_mem_nb); \
159})
160#define register_hotmemory_notifier(nb) register_memory_notifier(nb)
161#define unregister_hotmemory_notifier(nb) unregister_memory_notifier(nb)
162#else
163static inline int hotplug_memory_notifier(notifier_fn_t fn, int pri)
164{
165 return 0;
166}
167
168#define register_hotmemory_notifier(nb) ({ (void)(nb); 0; })
169#define unregister_hotmemory_notifier(nb) ({ (void)(nb); })
170#endif
171
172
173
174
175
176extern struct mutex text_mutex;
177
178#endif
179