mirror of
https://github.com/Fishwaldo/linux-bl808.git
synced 2025-03-31 03:14:24 +00:00
mm/memblock: introduce for_each_memblock_type()
We already have the for_each_memblock() macro in <linux/memblock.h> which provides ability to iterate over memblock regions of a known type. The for_each_memblock() macro allows us to pass the pointer to the struct memblock_type, instead we need to pass name of the type. This patch introduces a new macro for_each_memblock_type() which allows us iterate over memblock regions with the given type when the type is unknown. Signed-off-by: Alexander Kuleshov <kuleshovmail@gmail.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
parent
f14516fbf0
commit
8c9c1701c7
2 changed files with 21 additions and 16 deletions
|
@ -399,6 +399,11 @@ static inline unsigned long memblock_region_reserved_end_pfn(const struct memblo
|
||||||
region < (memblock.memblock_type.regions + memblock.memblock_type.cnt); \
|
region < (memblock.memblock_type.regions + memblock.memblock_type.cnt); \
|
||||||
region++)
|
region++)
|
||||||
|
|
||||||
|
#define for_each_memblock_type(memblock_type, rgn) \
|
||||||
|
idx = 0; \
|
||||||
|
rgn = &memblock_type->regions[idx]; \
|
||||||
|
for (idx = 0; idx < memblock_type->cnt; \
|
||||||
|
idx++,rgn = &memblock_type->regions[idx])
|
||||||
|
|
||||||
#ifdef CONFIG_ARCH_DISCARD_MEMBLOCK
|
#ifdef CONFIG_ARCH_DISCARD_MEMBLOCK
|
||||||
#define __init_memblock __meminit
|
#define __init_memblock __meminit
|
||||||
|
|
|
@ -525,7 +525,8 @@ int __init_memblock memblock_add_range(struct memblock_type *type,
|
||||||
bool insert = false;
|
bool insert = false;
|
||||||
phys_addr_t obase = base;
|
phys_addr_t obase = base;
|
||||||
phys_addr_t end = base + memblock_cap_size(base, &size);
|
phys_addr_t end = base + memblock_cap_size(base, &size);
|
||||||
int i, nr_new;
|
int idx, nr_new;
|
||||||
|
struct memblock_region *rgn;
|
||||||
|
|
||||||
if (!size)
|
if (!size)
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -549,8 +550,7 @@ repeat:
|
||||||
base = obase;
|
base = obase;
|
||||||
nr_new = 0;
|
nr_new = 0;
|
||||||
|
|
||||||
for (i = 0; i < type->cnt; i++) {
|
for_each_memblock_type(type, rgn) {
|
||||||
struct memblock_region *rgn = &type->regions[i];
|
|
||||||
phys_addr_t rbase = rgn->base;
|
phys_addr_t rbase = rgn->base;
|
||||||
phys_addr_t rend = rbase + rgn->size;
|
phys_addr_t rend = rbase + rgn->size;
|
||||||
|
|
||||||
|
@ -569,7 +569,7 @@ repeat:
|
||||||
WARN_ON(flags != rgn->flags);
|
WARN_ON(flags != rgn->flags);
|
||||||
nr_new++;
|
nr_new++;
|
||||||
if (insert)
|
if (insert)
|
||||||
memblock_insert_region(type, i++, base,
|
memblock_insert_region(type, idx++, base,
|
||||||
rbase - base, nid,
|
rbase - base, nid,
|
||||||
flags);
|
flags);
|
||||||
}
|
}
|
||||||
|
@ -581,7 +581,7 @@ repeat:
|
||||||
if (base < end) {
|
if (base < end) {
|
||||||
nr_new++;
|
nr_new++;
|
||||||
if (insert)
|
if (insert)
|
||||||
memblock_insert_region(type, i, base, end - base,
|
memblock_insert_region(type, idx, base, end - base,
|
||||||
nid, flags);
|
nid, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -648,7 +648,8 @@ static int __init_memblock memblock_isolate_range(struct memblock_type *type,
|
||||||
int *start_rgn, int *end_rgn)
|
int *start_rgn, int *end_rgn)
|
||||||
{
|
{
|
||||||
phys_addr_t end = base + memblock_cap_size(base, &size);
|
phys_addr_t end = base + memblock_cap_size(base, &size);
|
||||||
int i;
|
int idx;
|
||||||
|
struct memblock_region *rgn;
|
||||||
|
|
||||||
*start_rgn = *end_rgn = 0;
|
*start_rgn = *end_rgn = 0;
|
||||||
|
|
||||||
|
@ -660,8 +661,7 @@ static int __init_memblock memblock_isolate_range(struct memblock_type *type,
|
||||||
if (memblock_double_array(type, base, size) < 0)
|
if (memblock_double_array(type, base, size) < 0)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
for (i = 0; i < type->cnt; i++) {
|
for_each_memblock_type(type, rgn) {
|
||||||
struct memblock_region *rgn = &type->regions[i];
|
|
||||||
phys_addr_t rbase = rgn->base;
|
phys_addr_t rbase = rgn->base;
|
||||||
phys_addr_t rend = rbase + rgn->size;
|
phys_addr_t rend = rbase + rgn->size;
|
||||||
|
|
||||||
|
@ -678,7 +678,7 @@ static int __init_memblock memblock_isolate_range(struct memblock_type *type,
|
||||||
rgn->base = base;
|
rgn->base = base;
|
||||||
rgn->size -= base - rbase;
|
rgn->size -= base - rbase;
|
||||||
type->total_size -= base - rbase;
|
type->total_size -= base - rbase;
|
||||||
memblock_insert_region(type, i, rbase, base - rbase,
|
memblock_insert_region(type, idx, rbase, base - rbase,
|
||||||
memblock_get_region_node(rgn),
|
memblock_get_region_node(rgn),
|
||||||
rgn->flags);
|
rgn->flags);
|
||||||
} else if (rend > end) {
|
} else if (rend > end) {
|
||||||
|
@ -689,14 +689,14 @@ static int __init_memblock memblock_isolate_range(struct memblock_type *type,
|
||||||
rgn->base = end;
|
rgn->base = end;
|
||||||
rgn->size -= end - rbase;
|
rgn->size -= end - rbase;
|
||||||
type->total_size -= end - rbase;
|
type->total_size -= end - rbase;
|
||||||
memblock_insert_region(type, i--, rbase, end - rbase,
|
memblock_insert_region(type, idx--, rbase, end - rbase,
|
||||||
memblock_get_region_node(rgn),
|
memblock_get_region_node(rgn),
|
||||||
rgn->flags);
|
rgn->flags);
|
||||||
} else {
|
} else {
|
||||||
/* @rgn is fully contained, record it */
|
/* @rgn is fully contained, record it */
|
||||||
if (!*end_rgn)
|
if (!*end_rgn)
|
||||||
*start_rgn = i;
|
*start_rgn = idx;
|
||||||
*end_rgn = i + 1;
|
*end_rgn = idx + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1638,12 +1638,12 @@ static void __init_memblock memblock_dump(struct memblock_type *type, char *name
|
||||||
{
|
{
|
||||||
unsigned long long base, size;
|
unsigned long long base, size;
|
||||||
unsigned long flags;
|
unsigned long flags;
|
||||||
int i;
|
int idx;
|
||||||
|
struct memblock_region *rgn;
|
||||||
|
|
||||||
pr_info(" %s.cnt = 0x%lx\n", name, type->cnt);
|
pr_info(" %s.cnt = 0x%lx\n", name, type->cnt);
|
||||||
|
|
||||||
for (i = 0; i < type->cnt; i++) {
|
for_each_memblock_type(type, rgn) {
|
||||||
struct memblock_region *rgn = &type->regions[i];
|
|
||||||
char nid_buf[32] = "";
|
char nid_buf[32] = "";
|
||||||
|
|
||||||
base = rgn->base;
|
base = rgn->base;
|
||||||
|
@ -1655,7 +1655,7 @@ static void __init_memblock memblock_dump(struct memblock_type *type, char *name
|
||||||
memblock_get_region_node(rgn));
|
memblock_get_region_node(rgn));
|
||||||
#endif
|
#endif
|
||||||
pr_info(" %s[%#x]\t[%#016llx-%#016llx], %#llx bytes%s flags: %#lx\n",
|
pr_info(" %s[%#x]\t[%#016llx-%#016llx], %#llx bytes%s flags: %#lx\n",
|
||||||
name, i, base, base + size - 1, size, nid_buf, flags);
|
name, idx, base, base + size - 1, size, nid_buf, flags);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue