Commit d2a38ef9 authored by Russell King's avatar Russell King Committed by Russell King

[ARM] mm: provide helpers for accessing membanks

Provide helpers for getting physical addresses or pfns from the
meminfo array, and use them.  Move for_each_nodebank() to
asm/setup.h alongside the meminfo structure definition.
Signed-off-by: default avatarRussell King <rmk+kernel@arm.linux.org.uk>
parent 6c5da7ac
...@@ -209,6 +209,17 @@ struct meminfo { ...@@ -209,6 +209,17 @@ struct meminfo {
struct membank bank[NR_BANKS]; struct membank bank[NR_BANKS];
}; };
#define for_each_nodebank(iter,mi,no) \
for (iter = 0; iter < mi->nr_banks; iter++) \
if (mi->bank[iter].node == no)
#define bank_pfn_start(bank) __phys_to_pfn((bank)->start)
#define bank_pfn_end(bank) __phys_to_pfn((bank)->start + (bank)->size)
#define bank_pfn_size(bank) ((bank)->size >> PAGE_SHIFT)
#define bank_phys_start(bank) (bank)->start
#define bank_phys_end(bank) ((bank)->start + (bank)->size)
#define bank_phys_size(bank) (bank)->size
/* /*
* Early command line parameters. * Early command line parameters.
*/ */
......
...@@ -69,10 +69,6 @@ __tagtable(ATAG_INITRD2, parse_tag_initrd2); ...@@ -69,10 +69,6 @@ __tagtable(ATAG_INITRD2, parse_tag_initrd2);
*/ */
static struct meminfo meminfo = { 0, }; static struct meminfo meminfo = { 0, };
#define for_each_nodebank(iter,mi,no) \
for (iter = 0; iter < mi->nr_banks; iter++) \
if (mi->bank[iter].node == no)
void show_mem(void) void show_mem(void)
{ {
int free = 0, total = 0, reserved = 0; int free = 0, total = 0, reserved = 0;
...@@ -86,11 +82,12 @@ void show_mem(void) ...@@ -86,11 +82,12 @@ void show_mem(void)
struct page *map = n->node_mem_map - n->node_start_pfn; struct page *map = n->node_mem_map - n->node_start_pfn;
for_each_nodebank (i,mi,node) { for_each_nodebank (i,mi,node) {
struct membank *bank = &mi->bank[i];
unsigned int pfn1, pfn2; unsigned int pfn1, pfn2;
struct page *page, *end; struct page *page, *end;
pfn1 = __phys_to_pfn(mi->bank[i].start); pfn1 = bank_pfn_start(bank);
pfn2 = __phys_to_pfn(mi->bank[i].size + mi->bank[i].start); pfn2 = bank_pfn_end(bank);
page = map + pfn1; page = map + pfn1;
end = map + pfn2; end = map + pfn2;
...@@ -129,17 +126,17 @@ void show_mem(void) ...@@ -129,17 +126,17 @@ void show_mem(void)
static unsigned int __init static unsigned int __init
find_bootmap_pfn(int node, struct meminfo *mi, unsigned int bootmap_pages) find_bootmap_pfn(int node, struct meminfo *mi, unsigned int bootmap_pages)
{ {
unsigned int start_pfn, bank, bootmap_pfn; unsigned int start_pfn, i, bootmap_pfn;
start_pfn = PAGE_ALIGN(__pa(&_end)) >> PAGE_SHIFT; start_pfn = PAGE_ALIGN(__pa(&_end)) >> PAGE_SHIFT;
bootmap_pfn = 0; bootmap_pfn = 0;
for_each_nodebank(bank, mi, node) { for_each_nodebank(i, mi, node) {
struct membank *bank = &mi->bank[i];
unsigned int start, end; unsigned int start, end;
start = mi->bank[bank].start >> PAGE_SHIFT; start = bank_pfn_start(bank);
end = (mi->bank[bank].size + end = bank_pfn_end(bank);
mi->bank[bank].start) >> PAGE_SHIFT;
if (end < start_pfn) if (end < start_pfn)
continue; continue;
...@@ -178,13 +175,10 @@ static int __init check_initrd(struct meminfo *mi) ...@@ -178,13 +175,10 @@ static int __init check_initrd(struct meminfo *mi)
initrd_node = -1; initrd_node = -1;
for (i = 0; i < mi->nr_banks; i++) { for (i = 0; i < mi->nr_banks; i++) {
unsigned long bank_end; struct membank *bank = &mi->bank[i];
if (bank_phys_start(bank) <= phys_initrd_start &&
bank_end = mi->bank[i].start + mi->bank[i].size; end <= bank_phys_end(bank))
initrd_node = bank->node;
if (mi->bank[i].start <= phys_initrd_start &&
end <= bank_end)
initrd_node = mi->bank[i].node;
} }
} }
...@@ -204,9 +198,9 @@ static inline void map_memory_bank(struct membank *bank) ...@@ -204,9 +198,9 @@ static inline void map_memory_bank(struct membank *bank)
#ifdef CONFIG_MMU #ifdef CONFIG_MMU
struct map_desc map; struct map_desc map;
map.pfn = __phys_to_pfn(bank->start); map.pfn = bank_pfn_start(bank);
map.virtual = __phys_to_virt(bank->start); map.virtual = __phys_to_virt(bank_phys_start(bank));
map.length = bank->size; map.length = bank_phys_size(bank);
map.type = MT_MEMORY; map.type = MT_MEMORY;
create_mapping(&map); create_mapping(&map);
...@@ -232,8 +226,8 @@ bootmem_init_node(int node, int initrd_node, struct meminfo *mi) ...@@ -232,8 +226,8 @@ bootmem_init_node(int node, int initrd_node, struct meminfo *mi)
struct membank *bank = &mi->bank[i]; struct membank *bank = &mi->bank[i];
unsigned long start, end; unsigned long start, end;
start = bank->start >> PAGE_SHIFT; start = bank_pfn_start(bank);
end = (bank->start + bank->size) >> PAGE_SHIFT; end = bank_pfn_end(bank);
if (start_pfn > start) if (start_pfn > start)
start_pfn = start; start_pfn = start;
...@@ -263,8 +257,10 @@ bootmem_init_node(int node, int initrd_node, struct meminfo *mi) ...@@ -263,8 +257,10 @@ bootmem_init_node(int node, int initrd_node, struct meminfo *mi)
pgdat = NODE_DATA(node); pgdat = NODE_DATA(node);
init_bootmem_node(pgdat, boot_pfn, start_pfn, end_pfn); init_bootmem_node(pgdat, boot_pfn, start_pfn, end_pfn);
for_each_nodebank(i, mi, node) for_each_nodebank(i, mi, node) {
free_bootmem_node(pgdat, mi->bank[i].start, mi->bank[i].size); struct membank *bank = &mi->bank[i];
free_bootmem_node(pgdat, bank_phys_start(bank), bank_phys_size(bank));
}
/* /*
* Reserve the bootmem bitmap for this node. * Reserve the bootmem bitmap for this node.
...@@ -317,7 +313,7 @@ bootmem_init_node(int node, int initrd_node, struct meminfo *mi) ...@@ -317,7 +313,7 @@ bootmem_init_node(int node, int initrd_node, struct meminfo *mi)
*/ */
zhole_size[0] = zone_size[0]; zhole_size[0] = zone_size[0];
for_each_nodebank(i, mi, node) for_each_nodebank(i, mi, node)
zhole_size[0] -= mi->bank[i].size >> PAGE_SHIFT; zhole_size[0] -= bank_pfn_size(&mi->bank[i]);
/* /*
* Adjust the sizes according to any special requirements for * Adjust the sizes according to any special requirements for
...@@ -427,7 +423,9 @@ static void __init free_unused_memmap_node(int node, struct meminfo *mi) ...@@ -427,7 +423,9 @@ static void __init free_unused_memmap_node(int node, struct meminfo *mi)
* information on the command line. * information on the command line.
*/ */
for_each_nodebank(i, mi, node) { for_each_nodebank(i, mi, node) {
bank_start = mi->bank[i].start >> PAGE_SHIFT; struct membank *bank = &mi->bank[i];
bank_start = bank_pfn_start(bank);
if (bank_start < prev_bank_end) { if (bank_start < prev_bank_end) {
printk(KERN_ERR "MEM: unordered memory banks. " printk(KERN_ERR "MEM: unordered memory banks. "
"Not freeing memmap.\n"); "Not freeing memmap.\n");
...@@ -441,8 +439,7 @@ static void __init free_unused_memmap_node(int node, struct meminfo *mi) ...@@ -441,8 +439,7 @@ static void __init free_unused_memmap_node(int node, struct meminfo *mi)
if (prev_bank_end && prev_bank_end != bank_start) if (prev_bank_end && prev_bank_end != bank_start)
free_memmap(node, prev_bank_end, bank_start); free_memmap(node, prev_bank_end, bank_start);
prev_bank_end = (mi->bank[i].start + prev_bank_end = bank_pfn_end(bank);
mi->bank[i].size) >> PAGE_SHIFT;
} }
} }
...@@ -487,8 +484,8 @@ void __init mem_init(void) ...@@ -487,8 +484,8 @@ void __init mem_init(void)
num_physpages = 0; num_physpages = 0;
for (i = 0; i < meminfo.nr_banks; i++) { for (i = 0; i < meminfo.nr_banks; i++) {
num_physpages += meminfo.bank[i].size >> PAGE_SHIFT; num_physpages += bank_pfn_size(&meminfo.bank[i]);
printk(" %ldMB", meminfo.bank[i].size >> 20); printk(" %ldMB", bank_phys_size(&meminfo.bank[i]) >> 20);
} }
printk(" = %luMB total\n", num_physpages >> (20 - PAGE_SHIFT)); printk(" = %luMB total\n", num_physpages >> (20 - PAGE_SHIFT));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment