blob: 24daf8fc4d7c71e4c36ed0063849c01a3b31d022 [file] [log] [blame]
Yinghai Lu95f72d12010-07-12 14:36:09 +10001#ifndef _LINUX_MEMBLOCK_H
2#define _LINUX_MEMBLOCK_H
3#ifdef __KERNEL__
4
Yinghai Luf0b37fa2010-07-28 15:28:21 +10005#ifdef CONFIG_HAVE_MEMBLOCK
Yinghai Lu95f72d12010-07-12 14:36:09 +10006/*
7 * Logical memory blocks.
8 *
9 * Copyright (C) 2001 Peter Bergner, IBM Corp.
10 *
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version
14 * 2 of the License, or (at your option) any later version.
15 */
16
17#include <linux/init.h>
18#include <linux/mm.h>
19
Yinghai Lu37d8d4b2010-07-28 15:20:58 +100020#define INIT_MEMBLOCK_REGIONS 128
Philipp Hachtmann70210ed2014-01-29 18:16:01 +010021#define INIT_PHYSMEM_REGIONS 4
Yinghai Lu95f72d12010-07-12 14:36:09 +100022
Tang Chen66b16ed2014-01-21 15:49:23 -080023/* Definition of memblock flags. */
Tony Luckfc6daaf2015-06-24 16:58:09 -070024enum {
25 MEMBLOCK_NONE = 0x0, /* No special request */
26 MEMBLOCK_HOTPLUG = 0x1, /* hotpluggable region */
Tony Lucka3f5baf2015-06-24 16:58:12 -070027 MEMBLOCK_MIRROR = 0x2, /* mirrored region */
Tony Luckfc6daaf2015-06-24 16:58:09 -070028};
Tang Chen66b16ed2014-01-21 15:49:23 -080029
Benjamin Herrenschmidte3239ff2010-08-04 14:06:41 +100030struct memblock_region {
Benjamin Herrenschmidt2898cc42010-08-04 13:34:42 +100031 phys_addr_t base;
32 phys_addr_t size;
Tang Chen66a20752014-01-21 15:49:20 -080033 unsigned long flags;
Tejun Heo7c0caeb2011-07-14 11:43:42 +020034#ifdef CONFIG_HAVE_MEMBLOCK_NODE_MAP
35 int nid;
36#endif
Yinghai Lu95f72d12010-07-12 14:36:09 +100037};
38
Benjamin Herrenschmidte3239ff2010-08-04 14:06:41 +100039struct memblock_type {
Benjamin Herrenschmidtbf23c512010-07-06 15:39:06 -070040 unsigned long cnt; /* number of regions */
41 unsigned long max; /* size of the allocated array */
Tejun Heo1440c4e2011-12-08 10:22:08 -080042 phys_addr_t total_size; /* size of all regions */
Benjamin Herrenschmidtbf23c512010-07-06 15:39:06 -070043 struct memblock_region *regions;
Yinghai Lu95f72d12010-07-12 14:36:09 +100044};
45
46struct memblock {
Tang Chen79442ed2013-11-12 15:07:59 -080047 bool bottom_up; /* is bottom up direction? */
Benjamin Herrenschmidt2898cc42010-08-04 13:34:42 +100048 phys_addr_t current_limit;
Benjamin Herrenschmidte3239ff2010-08-04 14:06:41 +100049 struct memblock_type memory;
50 struct memblock_type reserved;
Philipp Hachtmann70210ed2014-01-29 18:16:01 +010051#ifdef CONFIG_HAVE_MEMBLOCK_PHYS_MAP
52 struct memblock_type physmem;
53#endif
Yinghai Lu95f72d12010-07-12 14:36:09 +100054};
55
56extern struct memblock memblock;
Yinghai Lu5e63cf42010-07-28 15:07:21 +100057extern int memblock_debug;
Tang Chen55ac5902014-01-21 15:49:35 -080058#ifdef CONFIG_MOVABLE_NODE
59/* If movable_node boot option specified */
60extern bool movable_node_enabled;
61#endif /* CONFIG_MOVABLE_NODE */
Yinghai Lu5e63cf42010-07-28 15:07:21 +100062
63#define memblock_dbg(fmt, ...) \
64 if (memblock_debug) printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
Yinghai Lu95f72d12010-07-12 14:36:09 +100065
Grygorii Strashko87029ee2014-01-21 15:50:14 -080066phys_addr_t memblock_find_in_range_node(phys_addr_t size, phys_addr_t align,
67 phys_addr_t start, phys_addr_t end,
Tony Luckfc6daaf2015-06-24 16:58:09 -070068 int nid, ulong flags);
Tejun Heofc769a82011-07-12 09:58:10 +020069phys_addr_t memblock_find_in_range(phys_addr_t start, phys_addr_t end,
70 phys_addr_t size, phys_addr_t align);
Yinghai Lu29f67382012-07-11 14:02:56 -070071phys_addr_t get_allocated_memblock_reserved_regions_info(phys_addr_t *addr);
Philipp Hachtmann5e270e22014-01-23 15:53:11 -080072phys_addr_t get_allocated_memblock_memory_regions_info(phys_addr_t *addr);
Tejun Heo1aadc052011-12-08 10:22:08 -080073void memblock_allow_resize(void);
Tejun Heo7fb0bc32011-12-08 10:22:08 -080074int memblock_add_node(phys_addr_t base, phys_addr_t size, int nid);
Tejun Heo581adcb2011-12-08 10:22:06 -080075int memblock_add(phys_addr_t base, phys_addr_t size);
76int memblock_remove(phys_addr_t base, phys_addr_t size);
77int memblock_free(phys_addr_t base, phys_addr_t size);
78int memblock_reserve(phys_addr_t base, phys_addr_t size);
Yinghai Lu6ede1fd2012-10-22 16:35:18 -070079void memblock_trim_memory(phys_addr_t align);
Tang Chen95cf82e2015-09-08 15:02:03 -070080bool memblock_overlaps_region(struct memblock_type *type,
81 phys_addr_t base, phys_addr_t size);
Tang Chen66b16ed2014-01-21 15:49:23 -080082int memblock_mark_hotplug(phys_addr_t base, phys_addr_t size);
83int memblock_clear_hotplug(phys_addr_t base, phys_addr_t size);
Tony Lucka3f5baf2015-06-24 16:58:12 -070084int memblock_mark_mirror(phys_addr_t base, phys_addr_t size);
85ulong choose_memblock_flags(void);
Philipp Hachtmannf1af9d32014-01-29 18:16:01 +010086
87/* Low level functions */
88int memblock_add_range(struct memblock_type *type,
89 phys_addr_t base, phys_addr_t size,
90 int nid, unsigned long flags);
91
Tony Luckfc6daaf2015-06-24 16:58:09 -070092void __next_mem_range(u64 *idx, int nid, ulong flags,
93 struct memblock_type *type_a,
Philipp Hachtmannf1af9d32014-01-29 18:16:01 +010094 struct memblock_type *type_b, phys_addr_t *out_start,
95 phys_addr_t *out_end, int *out_nid);
96
Tony Luckfc6daaf2015-06-24 16:58:09 -070097void __next_mem_range_rev(u64 *idx, int nid, ulong flags,
98 struct memblock_type *type_a,
Philipp Hachtmannf1af9d32014-01-29 18:16:01 +010099 struct memblock_type *type_b, phys_addr_t *out_start,
100 phys_addr_t *out_end, int *out_nid);
101
Robin Holt8e7a7f82015-06-30 14:56:41 -0700102void __next_reserved_mem_region(u64 *idx, phys_addr_t *out_start,
103 phys_addr_t *out_end);
104
Philipp Hachtmannf1af9d32014-01-29 18:16:01 +0100105/**
106 * for_each_mem_range - iterate through memblock areas from type_a and not
107 * included in type_b. Or just type_a if type_b is NULL.
108 * @i: u64 used as loop variable
109 * @type_a: ptr to memblock_type to iterate
110 * @type_b: ptr to memblock_type which excludes from the iteration
111 * @nid: node selector, %NUMA_NO_NODE for all nodes
Tony Luckfc6daaf2015-06-24 16:58:09 -0700112 * @flags: pick from blocks based on memory attributes
Philipp Hachtmannf1af9d32014-01-29 18:16:01 +0100113 * @p_start: ptr to phys_addr_t for start address of the range, can be %NULL
114 * @p_end: ptr to phys_addr_t for end address of the range, can be %NULL
115 * @p_nid: ptr to int for nid of the range, can be %NULL
116 */
Tony Luckfc6daaf2015-06-24 16:58:09 -0700117#define for_each_mem_range(i, type_a, type_b, nid, flags, \
Philipp Hachtmannf1af9d32014-01-29 18:16:01 +0100118 p_start, p_end, p_nid) \
Tony Luckfc6daaf2015-06-24 16:58:09 -0700119 for (i = 0, __next_mem_range(&i, nid, flags, type_a, type_b, \
Philipp Hachtmannf1af9d32014-01-29 18:16:01 +0100120 p_start, p_end, p_nid); \
121 i != (u64)ULLONG_MAX; \
Tony Luckfc6daaf2015-06-24 16:58:09 -0700122 __next_mem_range(&i, nid, flags, type_a, type_b, \
Philipp Hachtmannf1af9d32014-01-29 18:16:01 +0100123 p_start, p_end, p_nid))
124
125/**
126 * for_each_mem_range_rev - reverse iterate through memblock areas from
127 * type_a and not included in type_b. Or just type_a if type_b is NULL.
128 * @i: u64 used as loop variable
129 * @type_a: ptr to memblock_type to iterate
130 * @type_b: ptr to memblock_type which excludes from the iteration
131 * @nid: node selector, %NUMA_NO_NODE for all nodes
Tony Luckfc6daaf2015-06-24 16:58:09 -0700132 * @flags: pick from blocks based on memory attributes
Philipp Hachtmannf1af9d32014-01-29 18:16:01 +0100133 * @p_start: ptr to phys_addr_t for start address of the range, can be %NULL
134 * @p_end: ptr to phys_addr_t for end address of the range, can be %NULL
135 * @p_nid: ptr to int for nid of the range, can be %NULL
136 */
Tony Luckfc6daaf2015-06-24 16:58:09 -0700137#define for_each_mem_range_rev(i, type_a, type_b, nid, flags, \
Philipp Hachtmannf1af9d32014-01-29 18:16:01 +0100138 p_start, p_end, p_nid) \
139 for (i = (u64)ULLONG_MAX, \
Tony Luckfc6daaf2015-06-24 16:58:09 -0700140 __next_mem_range_rev(&i, nid, flags, type_a, type_b,\
Philipp Hachtmannf1af9d32014-01-29 18:16:01 +0100141 p_start, p_end, p_nid); \
142 i != (u64)ULLONG_MAX; \
Tony Luckfc6daaf2015-06-24 16:58:09 -0700143 __next_mem_range_rev(&i, nid, flags, type_a, type_b, \
Philipp Hachtmannf1af9d32014-01-29 18:16:01 +0100144 p_start, p_end, p_nid))
145
Robin Holt8e7a7f82015-06-30 14:56:41 -0700146/**
147 * for_each_reserved_mem_region - iterate over all reserved memblock areas
148 * @i: u64 used as loop variable
149 * @p_start: ptr to phys_addr_t for start address of the range, can be %NULL
150 * @p_end: ptr to phys_addr_t for end address of the range, can be %NULL
151 *
152 * Walks over reserved areas of memblock. Available as soon as memblock
153 * is initialized.
154 */
155#define for_each_reserved_mem_region(i, p_start, p_end) \
156 for (i = 0UL, \
157 __next_reserved_mem_region(&i, p_start, p_end); \
158 i != (u64)ULLONG_MAX; \
159 __next_reserved_mem_region(&i, p_start, p_end))
160
Tang Chen55ac5902014-01-21 15:49:35 -0800161#ifdef CONFIG_MOVABLE_NODE
162static inline bool memblock_is_hotpluggable(struct memblock_region *m)
163{
164 return m->flags & MEMBLOCK_HOTPLUG;
165}
166
167static inline bool movable_node_is_enabled(void)
168{
169 return movable_node_enabled;
170}
171#else
172static inline bool memblock_is_hotpluggable(struct memblock_region *m)
173{
174 return false;
175}
176static inline bool movable_node_is_enabled(void)
177{
178 return false;
179}
180#endif
Benjamin Herrenschmidte63075a2010-07-06 15:39:01 -0700181
Tony Lucka3f5baf2015-06-24 16:58:12 -0700182static inline bool memblock_is_mirror(struct memblock_region *m)
183{
184 return m->flags & MEMBLOCK_MIRROR;
185}
186
Tejun Heo0ee332c2011-12-08 10:22:09 -0800187#ifdef CONFIG_HAVE_MEMBLOCK_NODE_MAP
Yinghai Lue76b63f2013-09-11 14:22:17 -0700188int memblock_search_pfn_nid(unsigned long pfn, unsigned long *start_pfn,
189 unsigned long *end_pfn);
Tejun Heo0ee332c2011-12-08 10:22:09 -0800190void __next_mem_pfn_range(int *idx, int nid, unsigned long *out_start_pfn,
191 unsigned long *out_end_pfn, int *out_nid);
192
193/**
194 * for_each_mem_pfn_range - early memory pfn range iterator
195 * @i: an integer used as loop variable
196 * @nid: node selector, %MAX_NUMNODES for all nodes
197 * @p_start: ptr to ulong for start pfn of the range, can be %NULL
198 * @p_end: ptr to ulong for end pfn of the range, can be %NULL
199 * @p_nid: ptr to int for nid of the range, can be %NULL
200 *
Wanpeng Lif2d52fe2012-10-08 16:32:24 -0700201 * Walks over configured memory ranges.
Tejun Heo0ee332c2011-12-08 10:22:09 -0800202 */
203#define for_each_mem_pfn_range(i, nid, p_start, p_end, p_nid) \
204 for (i = -1, __next_mem_pfn_range(&i, nid, p_start, p_end, p_nid); \
205 i >= 0; __next_mem_pfn_range(&i, nid, p_start, p_end, p_nid))
206#endif /* CONFIG_HAVE_MEMBLOCK_NODE_MAP */
207
Tejun Heo35fd0802011-07-12 11:15:59 +0200208/**
209 * for_each_free_mem_range - iterate through free memblock areas
210 * @i: u64 used as loop variable
Grygorii Strashkob1154232014-01-21 15:50:16 -0800211 * @nid: node selector, %NUMA_NO_NODE for all nodes
Tejun Heo35fd0802011-07-12 11:15:59 +0200212 * @p_start: ptr to phys_addr_t for start address of the range, can be %NULL
213 * @p_end: ptr to phys_addr_t for end address of the range, can be %NULL
214 * @p_nid: ptr to int for nid of the range, can be %NULL
Tony Luckfc6daaf2015-06-24 16:58:09 -0700215 * @flags: pick from blocks based on memory attributes
Tejun Heo35fd0802011-07-12 11:15:59 +0200216 *
217 * Walks over free (memory && !reserved) areas of memblock. Available as
218 * soon as memblock is initialized.
219 */
Tony Luckfc6daaf2015-06-24 16:58:09 -0700220#define for_each_free_mem_range(i, nid, flags, p_start, p_end, p_nid) \
Philipp Hachtmannf1af9d32014-01-29 18:16:01 +0100221 for_each_mem_range(i, &memblock.memory, &memblock.reserved, \
Tony Luckfc6daaf2015-06-24 16:58:09 -0700222 nid, flags, p_start, p_end, p_nid)
Tejun Heo7bd0b0f2011-12-08 10:22:09 -0800223
224/**
225 * for_each_free_mem_range_reverse - rev-iterate through free memblock areas
226 * @i: u64 used as loop variable
Grygorii Strashkob1154232014-01-21 15:50:16 -0800227 * @nid: node selector, %NUMA_NO_NODE for all nodes
Tejun Heo7bd0b0f2011-12-08 10:22:09 -0800228 * @p_start: ptr to phys_addr_t for start address of the range, can be %NULL
229 * @p_end: ptr to phys_addr_t for end address of the range, can be %NULL
230 * @p_nid: ptr to int for nid of the range, can be %NULL
Tony Luckfc6daaf2015-06-24 16:58:09 -0700231 * @flags: pick from blocks based on memory attributes
Tejun Heo7bd0b0f2011-12-08 10:22:09 -0800232 *
233 * Walks over free (memory && !reserved) areas of memblock in reverse
234 * order. Available as soon as memblock is initialized.
235 */
Tony Luckfc6daaf2015-06-24 16:58:09 -0700236#define for_each_free_mem_range_reverse(i, nid, flags, p_start, p_end, \
237 p_nid) \
Philipp Hachtmannf1af9d32014-01-29 18:16:01 +0100238 for_each_mem_range_rev(i, &memblock.memory, &memblock.reserved, \
Tony Luckfc6daaf2015-06-24 16:58:09 -0700239 nid, flags, p_start, p_end, p_nid)
Tejun Heo7bd0b0f2011-12-08 10:22:09 -0800240
Tang Chen66b16ed2014-01-21 15:49:23 -0800241static inline void memblock_set_region_flags(struct memblock_region *r,
242 unsigned long flags)
243{
244 r->flags |= flags;
245}
246
247static inline void memblock_clear_region_flags(struct memblock_region *r,
248 unsigned long flags)
249{
250 r->flags &= ~flags;
251}
252
Tejun Heo7c0caeb2011-07-14 11:43:42 +0200253#ifdef CONFIG_HAVE_MEMBLOCK_NODE_MAP
Tang Chene7e8de52014-01-21 15:49:26 -0800254int memblock_set_node(phys_addr_t base, phys_addr_t size,
255 struct memblock_type *type, int nid);
Tejun Heo7c0caeb2011-07-14 11:43:42 +0200256
257static inline void memblock_set_region_node(struct memblock_region *r, int nid)
258{
259 r->nid = nid;
260}
261
262static inline int memblock_get_region_node(const struct memblock_region *r)
263{
264 return r->nid;
265}
266#else
267static inline void memblock_set_region_node(struct memblock_region *r, int nid)
268{
269}
270
271static inline int memblock_get_region_node(const struct memblock_region *r)
272{
273 return 0;
274}
275#endif /* CONFIG_HAVE_MEMBLOCK_NODE_MAP */
276
Tejun Heo581adcb2011-12-08 10:22:06 -0800277phys_addr_t memblock_alloc_nid(phys_addr_t size, phys_addr_t align, int nid);
278phys_addr_t memblock_alloc_try_nid(phys_addr_t size, phys_addr_t align, int nid);
Benjamin Herrenschmidt9d1e2492010-07-06 15:39:17 -0700279
Tejun Heo581adcb2011-12-08 10:22:06 -0800280phys_addr_t memblock_alloc(phys_addr_t size, phys_addr_t align);
Benjamin Herrenschmidte63075a2010-07-06 15:39:01 -0700281
Tang Chen79442ed2013-11-12 15:07:59 -0800282#ifdef CONFIG_MOVABLE_NODE
283/*
284 * Set the allocation direction to bottom-up or top-down.
285 */
Fabian Frederick2cfb3662014-08-06 16:05:03 -0700286static inline void __init memblock_set_bottom_up(bool enable)
Tang Chen79442ed2013-11-12 15:07:59 -0800287{
288 memblock.bottom_up = enable;
289}
290
291/*
292 * Check if the allocation direction is bottom-up or not.
293 * if this is true, that said, memblock will allocate memory
294 * in bottom-up direction.
295 */
296static inline bool memblock_bottom_up(void)
297{
298 return memblock.bottom_up;
299}
300#else
Fabian Frederick2cfb3662014-08-06 16:05:03 -0700301static inline void __init memblock_set_bottom_up(bool enable) {}
Tang Chen79442ed2013-11-12 15:07:59 -0800302static inline bool memblock_bottom_up(void) { return false; }
303#endif
304
Benjamin Herrenschmidte63075a2010-07-06 15:39:01 -0700305/* Flags for memblock_alloc_base() amd __memblock_alloc_base() */
Benjamin Herrenschmidt2898cc42010-08-04 13:34:42 +1000306#define MEMBLOCK_ALLOC_ANYWHERE (~(phys_addr_t)0)
Benjamin Herrenschmidte63075a2010-07-06 15:39:01 -0700307#define MEMBLOCK_ALLOC_ACCESSIBLE 0
308
Akinobu Mita2bfc2862014-06-04 16:06:53 -0700309phys_addr_t __init memblock_alloc_range(phys_addr_t size, phys_addr_t align,
Tony Luckfc6daaf2015-06-24 16:58:09 -0700310 phys_addr_t start, phys_addr_t end,
311 ulong flags);
Tejun Heo581adcb2011-12-08 10:22:06 -0800312phys_addr_t memblock_alloc_base(phys_addr_t size, phys_addr_t align,
313 phys_addr_t max_addr);
314phys_addr_t __memblock_alloc_base(phys_addr_t size, phys_addr_t align,
315 phys_addr_t max_addr);
316phys_addr_t memblock_phys_mem_size(void);
Yinghai Lu595ad9a2013-01-24 12:20:09 -0800317phys_addr_t memblock_mem_size(unsigned long limit_pfn);
Tejun Heo581adcb2011-12-08 10:22:06 -0800318phys_addr_t memblock_start_of_DRAM(void);
319phys_addr_t memblock_end_of_DRAM(void);
320void memblock_enforce_memory_limit(phys_addr_t memory_limit);
321int memblock_is_memory(phys_addr_t addr);
322int memblock_is_region_memory(phys_addr_t base, phys_addr_t size);
323int memblock_is_reserved(phys_addr_t addr);
Tang Chenc5c5c9d2015-09-08 15:02:00 -0700324bool memblock_is_region_reserved(phys_addr_t base, phys_addr_t size);
Yinghai Lu95f72d12010-07-12 14:36:09 +1000325
Tejun Heo4ff7b822011-12-08 10:22:06 -0800326extern void __memblock_dump_all(void);
327
328static inline void memblock_dump_all(void)
329{
330 if (memblock_debug)
331 __memblock_dump_all();
332}
Yinghai Lu95f72d12010-07-12 14:36:09 +1000333
Benjamin Herrenschmidte63075a2010-07-06 15:39:01 -0700334/**
335 * memblock_set_current_limit - Set the current allocation limit to allow
336 * limiting allocations to what is currently
337 * accessible during boot
338 * @limit: New limit value (physical address)
339 */
Tejun Heo581adcb2011-12-08 10:22:06 -0800340void memblock_set_current_limit(phys_addr_t limit);
Benjamin Herrenschmidte63075a2010-07-06 15:39:01 -0700341
Benjamin Herrenschmidt35a1f0b2010-07-06 15:38:58 -0700342
Laura Abbottfec51012014-02-27 01:23:43 +0100343phys_addr_t memblock_get_current_limit(void);
344
Benjamin Herrenschmidt5b385f22010-08-04 13:40:38 +1000345/*
346 * pfn conversion functions
347 *
348 * While the memory MEMBLOCKs should always be page aligned, the reserved
349 * MEMBLOCKs may not be. This accessor attempt to provide a very clear
350 * idea of what they return for such non aligned MEMBLOCKs.
351 */
352
353/**
Yinghai Luc7fc2de2010-10-12 14:07:09 -0700354 * memblock_region_memory_base_pfn - Return the lowest pfn intersecting with the memory region
Benjamin Herrenschmidt5b385f22010-08-04 13:40:38 +1000355 * @reg: memblock_region structure
356 */
Yinghai Luc7fc2de2010-10-12 14:07:09 -0700357static inline unsigned long memblock_region_memory_base_pfn(const struct memblock_region *reg)
Benjamin Herrenschmidt5b385f22010-08-04 13:40:38 +1000358{
Yinghai Luc7fc2de2010-10-12 14:07:09 -0700359 return PFN_UP(reg->base);
Benjamin Herrenschmidt5b385f22010-08-04 13:40:38 +1000360}
361
362/**
Yinghai Luc7fc2de2010-10-12 14:07:09 -0700363 * memblock_region_memory_end_pfn - Return the end_pfn this region
Benjamin Herrenschmidt5b385f22010-08-04 13:40:38 +1000364 * @reg: memblock_region structure
365 */
Yinghai Luc7fc2de2010-10-12 14:07:09 -0700366static inline unsigned long memblock_region_memory_end_pfn(const struct memblock_region *reg)
Benjamin Herrenschmidt5b385f22010-08-04 13:40:38 +1000367{
Yinghai Luc7fc2de2010-10-12 14:07:09 -0700368 return PFN_DOWN(reg->base + reg->size);
Benjamin Herrenschmidt5b385f22010-08-04 13:40:38 +1000369}
370
371/**
Yinghai Luc7fc2de2010-10-12 14:07:09 -0700372 * memblock_region_reserved_base_pfn - Return the lowest pfn intersecting with the reserved region
Benjamin Herrenschmidt5b385f22010-08-04 13:40:38 +1000373 * @reg: memblock_region structure
374 */
Yinghai Luc7fc2de2010-10-12 14:07:09 -0700375static inline unsigned long memblock_region_reserved_base_pfn(const struct memblock_region *reg)
Benjamin Herrenschmidt5b385f22010-08-04 13:40:38 +1000376{
Yinghai Luc7fc2de2010-10-12 14:07:09 -0700377 return PFN_DOWN(reg->base);
Benjamin Herrenschmidt5b385f22010-08-04 13:40:38 +1000378}
379
380/**
Yinghai Luc7fc2de2010-10-12 14:07:09 -0700381 * memblock_region_reserved_end_pfn - Return the end_pfn this region
Benjamin Herrenschmidt5b385f22010-08-04 13:40:38 +1000382 * @reg: memblock_region structure
383 */
Yinghai Luc7fc2de2010-10-12 14:07:09 -0700384static inline unsigned long memblock_region_reserved_end_pfn(const struct memblock_region *reg)
Benjamin Herrenschmidt5b385f22010-08-04 13:40:38 +1000385{
Yinghai Luc7fc2de2010-10-12 14:07:09 -0700386 return PFN_UP(reg->base + reg->size);
Benjamin Herrenschmidt5b385f22010-08-04 13:40:38 +1000387}
388
389#define for_each_memblock(memblock_type, region) \
390 for (region = memblock.memblock_type.regions; \
391 region < (memblock.memblock_type.regions + memblock.memblock_type.cnt); \
392 region++)
393
394
Tejun Heoc378ddd2011-07-14 11:46:03 +0200395#ifdef CONFIG_ARCH_DISCARD_MEMBLOCK
Tejun Heo67e24bc2011-07-14 11:42:03 +0200396#define __init_memblock __meminit
397#define __initdata_memblock __meminitdata
Yinghai Lu10d06432010-07-28 15:43:02 +1000398#else
399#define __init_memblock
400#define __initdata_memblock
401#endif
402
Vladimir Murzin4a207992015-04-14 15:48:27 -0700403#ifdef CONFIG_MEMTEST
Vladimir Murzin7f70bae2015-04-14 15:48:30 -0700404extern void early_memtest(phys_addr_t start, phys_addr_t end);
Vladimir Murzin4a207992015-04-14 15:48:27 -0700405#else
Vladimir Murzin7f70bae2015-04-14 15:48:30 -0700406static inline void early_memtest(phys_addr_t start, phys_addr_t end)
Vladimir Murzin4a207992015-04-14 15:48:27 -0700407{
408}
409#endif
410
Yinghai Lu95dde502011-05-24 17:13:19 -0700411#else
412static inline phys_addr_t memblock_alloc(phys_addr_t size, phys_addr_t align)
413{
Tejun Heo1f5026a2011-07-12 09:58:09 +0200414 return 0;
Yinghai Lu95dde502011-05-24 17:13:19 -0700415}
416
Yinghai Luf0b37fa2010-07-28 15:28:21 +1000417#endif /* CONFIG_HAVE_MEMBLOCK */
418
Yinghai Lu95f72d12010-07-12 14:36:09 +1000419#endif /* __KERNEL__ */
420
421#endif /* _LINUX_MEMBLOCK_H */