blob: 52cbafce143f0722e187dec9ad64aa3a0702c0f2 [file] [log] [blame]
Nicholas Flintham1e3d3112013-04-10 10:48:38 +01001#ifndef __LINUX_MEMORY_HOTPLUG_H
2#define __LINUX_MEMORY_HOTPLUG_H
3
4#include <linux/mmzone.h>
5#include <linux/spinlock.h>
6#include <linux/notifier.h>
7#include <linux/bug.h>
8
9struct page;
10struct zone;
11struct pglist_data;
12struct mem_section;
13
14extern unsigned long movable_reserved_start, movable_reserved_size;
15extern unsigned long low_power_memory_start, low_power_memory_size;
16
17#ifdef CONFIG_MEMORY_HOTPLUG
18
19enum {
20 MEMORY_HOTPLUG_MIN_BOOTMEM_TYPE = 12,
21 SECTION_INFO = MEMORY_HOTPLUG_MIN_BOOTMEM_TYPE,
22 MIX_SECTION_INFO,
23 NODE_INFO,
24 MEMORY_HOTPLUG_MAX_BOOTMEM_TYPE = NODE_INFO,
25};
26
27static inline
28void pgdat_resize_lock(struct pglist_data *pgdat, unsigned long *flags)
29{
30 spin_lock_irqsave(&pgdat->node_size_lock, *flags);
31}
32static inline
33void pgdat_resize_unlock(struct pglist_data *pgdat, unsigned long *flags)
34{
35 spin_unlock_irqrestore(&pgdat->node_size_lock, *flags);
36}
37static inline
38void pgdat_resize_init(struct pglist_data *pgdat)
39{
40 spin_lock_init(&pgdat->node_size_lock);
41}
42static inline unsigned zone_span_seqbegin(struct zone *zone)
43{
44 return read_seqbegin(&zone->span_seqlock);
45}
46static inline int zone_span_seqretry(struct zone *zone, unsigned iv)
47{
48 return read_seqretry(&zone->span_seqlock, iv);
49}
50static inline void zone_span_writelock(struct zone *zone)
51{
52 write_seqlock(&zone->span_seqlock);
53}
54static inline void zone_span_writeunlock(struct zone *zone)
55{
56 write_sequnlock(&zone->span_seqlock);
57}
58static inline void zone_seqlock_init(struct zone *zone)
59{
60 seqlock_init(&zone->span_seqlock);
61}
62extern int zone_grow_free_lists(struct zone *zone, unsigned long new_nr_pages);
63extern int zone_grow_waitqueues(struct zone *zone, unsigned long nr_pages);
64extern int add_one_highpage(struct page *page, int pfn, int bad_ppro);
65extern int online_pages(unsigned long, unsigned long);
66extern void __offline_isolated_pages(unsigned long, unsigned long);
67
68typedef void (*online_page_callback_t)(struct page *page);
69
70extern int set_online_page_callback(online_page_callback_t callback);
71extern int restore_online_page_callback(online_page_callback_t callback);
72
73extern void __online_page_set_limits(struct page *page);
74extern void __online_page_increment_counters(struct page *page);
75extern void __online_page_free(struct page *page);
76
77#ifdef CONFIG_MEMORY_HOTREMOVE
78extern bool is_pageblock_removable_nolock(struct page *page);
79#endif
80
81extern int __add_pages(int nid, struct zone *zone, unsigned long start_pfn,
82 unsigned long nr_pages);
83extern int __remove_pages(struct zone *zone, unsigned long start_pfn,
84 unsigned long nr_pages);
85
86#ifdef CONFIG_NUMA
87extern int memory_add_physaddr_to_nid(u64 start);
88#else
89static inline int memory_add_physaddr_to_nid(u64 start)
90{
91 return 0;
92}
93#endif
94
95#ifdef CONFIG_HAVE_ARCH_NODEDATA_EXTENSION
96extern pg_data_t *arch_alloc_nodedata(int nid);
97extern void arch_free_nodedata(pg_data_t *pgdat);
98extern void arch_refresh_nodedata(int nid, pg_data_t *pgdat);
99
100#else
101
102#define arch_alloc_nodedata(nid) generic_alloc_nodedata(nid)
103#define arch_free_nodedata(pgdat) generic_free_nodedata(pgdat)
104
105#ifdef CONFIG_NUMA
106#define generic_alloc_nodedata(nid) \
107({ \
108 kzalloc(sizeof(pg_data_t), GFP_KERNEL); \
109})
110#define generic_free_nodedata(pgdat) kfree(pgdat)
111
112extern pg_data_t *node_data[];
113static inline void arch_refresh_nodedata(int nid, pg_data_t *pgdat)
114{
115 node_data[nid] = pgdat;
116}
117
118#else
119
120static inline pg_data_t *generic_alloc_nodedata(int nid)
121{
122 BUG();
123 return NULL;
124}
125static inline void generic_free_nodedata(pg_data_t *pgdat)
126{
127}
128static inline void arch_refresh_nodedata(int nid, pg_data_t *pgdat)
129{
130}
131#endif
132#endif
133
134#ifdef CONFIG_SPARSEMEM_VMEMMAP
135static inline void register_page_bootmem_info_node(struct pglist_data *pgdat)
136{
137}
138static inline void put_page_bootmem(struct page *page)
139{
140}
141#else
142extern void register_page_bootmem_info_node(struct pglist_data *pgdat);
143extern void put_page_bootmem(struct page *page);
144#endif
145
146
147void lock_memory_hotplug(void);
148void unlock_memory_hotplug(void);
149
150#else
151static inline void pgdat_resize_lock(struct pglist_data *p, unsigned long *f) {}
152static inline void pgdat_resize_unlock(struct pglist_data *p, unsigned long *f) {}
153static inline void pgdat_resize_init(struct pglist_data *pgdat) {}
154
155static inline unsigned zone_span_seqbegin(struct zone *zone)
156{
157 return 0;
158}
159static inline int zone_span_seqretry(struct zone *zone, unsigned iv)
160{
161 return 0;
162}
163static inline void zone_span_writelock(struct zone *zone) {}
164static inline void zone_span_writeunlock(struct zone *zone) {}
165static inline void zone_seqlock_init(struct zone *zone) {}
166
167static inline int mhp_notimplemented(const char *func)
168{
169 printk(KERN_WARNING "%s() called, with CONFIG_MEMORY_HOTPLUG disabled\n", func);
170 dump_stack();
171 return -ENOSYS;
172}
173
174static inline void register_page_bootmem_info_node(struct pglist_data *pgdat)
175{
176}
177
178static inline void lock_memory_hotplug(void) {}
179static inline void unlock_memory_hotplug(void) {}
180
181#endif
182
183#ifdef CONFIG_MEMORY_HOTREMOVE
184
185extern int is_mem_section_removable(unsigned long pfn, unsigned long nr_pages);
186
187#else
188static inline int is_mem_section_removable(unsigned long pfn,
189 unsigned long nr_pages)
190{
191 return 0;
192}
193#endif
194
195extern int mem_online_node(int nid);
196extern int add_memory(int nid, u64 start, u64 size);
197extern int arch_add_memory(int nid, u64 start, u64 size);
198extern int remove_memory(u64 start, u64 size);
199extern int sparse_add_one_section(struct zone *zone, unsigned long start_pfn,
200 int nr_pages);
201extern void sparse_remove_one_section(struct zone *zone, struct mem_section *ms);
202extern struct page *sparse_decode_mem_map(unsigned long coded_mem_map,
203 unsigned long pnum);
204
205extern void reserve_hotplug_pages(unsigned long start_pfn,
206 unsigned long nr_pages);
207extern void unreserve_hotplug_pages(unsigned long start_pfn,
208 unsigned long nr_pages);
209#endif
210extern int physical_remove_memory(u64 start, u64 size);
211extern int arch_physical_remove_memory(u64 start, u64 size);
212extern int physical_low_power_memory(u64 start, u64 size);
213extern int arch_physical_low_power_memory(u64 start, u64 size);
214extern int physical_active_memory(u64 start, u64 size);
215extern int arch_physical_active_memory(u64 start, u64 size);