| Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame^] | 1 | #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 | |
| 9 | struct page; |
| 10 | struct zone; |
| 11 | struct pglist_data; |
| 12 | struct mem_section; |
| 13 | |
| 14 | extern unsigned long movable_reserved_start, movable_reserved_size; |
| 15 | extern unsigned long low_power_memory_start, low_power_memory_size; |
| 16 | |
| 17 | #ifdef CONFIG_MEMORY_HOTPLUG |
| 18 | |
| 19 | enum { |
| 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 | |
| 27 | static inline |
| 28 | void pgdat_resize_lock(struct pglist_data *pgdat, unsigned long *flags) |
| 29 | { |
| 30 | spin_lock_irqsave(&pgdat->node_size_lock, *flags); |
| 31 | } |
| 32 | static inline |
| 33 | void pgdat_resize_unlock(struct pglist_data *pgdat, unsigned long *flags) |
| 34 | { |
| 35 | spin_unlock_irqrestore(&pgdat->node_size_lock, *flags); |
| 36 | } |
| 37 | static inline |
| 38 | void pgdat_resize_init(struct pglist_data *pgdat) |
| 39 | { |
| 40 | spin_lock_init(&pgdat->node_size_lock); |
| 41 | } |
| 42 | static inline unsigned zone_span_seqbegin(struct zone *zone) |
| 43 | { |
| 44 | return read_seqbegin(&zone->span_seqlock); |
| 45 | } |
| 46 | static inline int zone_span_seqretry(struct zone *zone, unsigned iv) |
| 47 | { |
| 48 | return read_seqretry(&zone->span_seqlock, iv); |
| 49 | } |
| 50 | static inline void zone_span_writelock(struct zone *zone) |
| 51 | { |
| 52 | write_seqlock(&zone->span_seqlock); |
| 53 | } |
| 54 | static inline void zone_span_writeunlock(struct zone *zone) |
| 55 | { |
| 56 | write_sequnlock(&zone->span_seqlock); |
| 57 | } |
| 58 | static inline void zone_seqlock_init(struct zone *zone) |
| 59 | { |
| 60 | seqlock_init(&zone->span_seqlock); |
| 61 | } |
| 62 | extern int zone_grow_free_lists(struct zone *zone, unsigned long new_nr_pages); |
| 63 | extern int zone_grow_waitqueues(struct zone *zone, unsigned long nr_pages); |
| 64 | extern int add_one_highpage(struct page *page, int pfn, int bad_ppro); |
| 65 | extern int online_pages(unsigned long, unsigned long); |
| 66 | extern void __offline_isolated_pages(unsigned long, unsigned long); |
| 67 | |
| 68 | typedef void (*online_page_callback_t)(struct page *page); |
| 69 | |
| 70 | extern int set_online_page_callback(online_page_callback_t callback); |
| 71 | extern int restore_online_page_callback(online_page_callback_t callback); |
| 72 | |
| 73 | extern void __online_page_set_limits(struct page *page); |
| 74 | extern void __online_page_increment_counters(struct page *page); |
| 75 | extern void __online_page_free(struct page *page); |
| 76 | |
| 77 | #ifdef CONFIG_MEMORY_HOTREMOVE |
| 78 | extern bool is_pageblock_removable_nolock(struct page *page); |
| 79 | #endif |
| 80 | |
| 81 | extern int __add_pages(int nid, struct zone *zone, unsigned long start_pfn, |
| 82 | unsigned long nr_pages); |
| 83 | extern int __remove_pages(struct zone *zone, unsigned long start_pfn, |
| 84 | unsigned long nr_pages); |
| 85 | |
| 86 | #ifdef CONFIG_NUMA |
| 87 | extern int memory_add_physaddr_to_nid(u64 start); |
| 88 | #else |
| 89 | static inline int memory_add_physaddr_to_nid(u64 start) |
| 90 | { |
| 91 | return 0; |
| 92 | } |
| 93 | #endif |
| 94 | |
| 95 | #ifdef CONFIG_HAVE_ARCH_NODEDATA_EXTENSION |
| 96 | extern pg_data_t *arch_alloc_nodedata(int nid); |
| 97 | extern void arch_free_nodedata(pg_data_t *pgdat); |
| 98 | extern 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 | |
| 112 | extern pg_data_t *node_data[]; |
| 113 | static inline void arch_refresh_nodedata(int nid, pg_data_t *pgdat) |
| 114 | { |
| 115 | node_data[nid] = pgdat; |
| 116 | } |
| 117 | |
| 118 | #else |
| 119 | |
| 120 | static inline pg_data_t *generic_alloc_nodedata(int nid) |
| 121 | { |
| 122 | BUG(); |
| 123 | return NULL; |
| 124 | } |
| 125 | static inline void generic_free_nodedata(pg_data_t *pgdat) |
| 126 | { |
| 127 | } |
| 128 | static inline void arch_refresh_nodedata(int nid, pg_data_t *pgdat) |
| 129 | { |
| 130 | } |
| 131 | #endif |
| 132 | #endif |
| 133 | |
| 134 | #ifdef CONFIG_SPARSEMEM_VMEMMAP |
| 135 | static inline void register_page_bootmem_info_node(struct pglist_data *pgdat) |
| 136 | { |
| 137 | } |
| 138 | static inline void put_page_bootmem(struct page *page) |
| 139 | { |
| 140 | } |
| 141 | #else |
| 142 | extern void register_page_bootmem_info_node(struct pglist_data *pgdat); |
| 143 | extern void put_page_bootmem(struct page *page); |
| 144 | #endif |
| 145 | |
| 146 | |
| 147 | void lock_memory_hotplug(void); |
| 148 | void unlock_memory_hotplug(void); |
| 149 | |
| 150 | #else |
| 151 | static inline void pgdat_resize_lock(struct pglist_data *p, unsigned long *f) {} |
| 152 | static inline void pgdat_resize_unlock(struct pglist_data *p, unsigned long *f) {} |
| 153 | static inline void pgdat_resize_init(struct pglist_data *pgdat) {} |
| 154 | |
| 155 | static inline unsigned zone_span_seqbegin(struct zone *zone) |
| 156 | { |
| 157 | return 0; |
| 158 | } |
| 159 | static inline int zone_span_seqretry(struct zone *zone, unsigned iv) |
| 160 | { |
| 161 | return 0; |
| 162 | } |
| 163 | static inline void zone_span_writelock(struct zone *zone) {} |
| 164 | static inline void zone_span_writeunlock(struct zone *zone) {} |
| 165 | static inline void zone_seqlock_init(struct zone *zone) {} |
| 166 | |
| 167 | static 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 | |
| 174 | static inline void register_page_bootmem_info_node(struct pglist_data *pgdat) |
| 175 | { |
| 176 | } |
| 177 | |
| 178 | static inline void lock_memory_hotplug(void) {} |
| 179 | static inline void unlock_memory_hotplug(void) {} |
| 180 | |
| 181 | #endif |
| 182 | |
| 183 | #ifdef CONFIG_MEMORY_HOTREMOVE |
| 184 | |
| 185 | extern int is_mem_section_removable(unsigned long pfn, unsigned long nr_pages); |
| 186 | |
| 187 | #else |
| 188 | static inline int is_mem_section_removable(unsigned long pfn, |
| 189 | unsigned long nr_pages) |
| 190 | { |
| 191 | return 0; |
| 192 | } |
| 193 | #endif |
| 194 | |
| 195 | extern int mem_online_node(int nid); |
| 196 | extern int add_memory(int nid, u64 start, u64 size); |
| 197 | extern int arch_add_memory(int nid, u64 start, u64 size); |
| 198 | extern int remove_memory(u64 start, u64 size); |
| 199 | extern int sparse_add_one_section(struct zone *zone, unsigned long start_pfn, |
| 200 | int nr_pages); |
| 201 | extern void sparse_remove_one_section(struct zone *zone, struct mem_section *ms); |
| 202 | extern struct page *sparse_decode_mem_map(unsigned long coded_mem_map, |
| 203 | unsigned long pnum); |
| 204 | |
| 205 | extern void reserve_hotplug_pages(unsigned long start_pfn, |
| 206 | unsigned long nr_pages); |
| 207 | extern void unreserve_hotplug_pages(unsigned long start_pfn, |
| 208 | unsigned long nr_pages); |
| 209 | #endif |
| 210 | extern int physical_remove_memory(u64 start, u64 size); |
| 211 | extern int arch_physical_remove_memory(u64 start, u64 size); |
| 212 | extern int physical_low_power_memory(u64 start, u64 size); |
| 213 | extern int arch_physical_low_power_memory(u64 start, u64 size); |
| 214 | extern int physical_active_memory(u64 start, u64 size); |
| 215 | extern int arch_physical_active_memory(u64 start, u64 size); |