Skip to content

Commit

Permalink
[ARM] rationalize memory configuration code some more
Browse files Browse the repository at this point in the history
Currently there are two instances of struct meminfo: one in
kernel/setup.c marked __initdata, and another in mm/init.c with
permanent storage.  Let's keep only the later to directly populate
the permanent version from arm_add_memory().

Also move common validation tests between the MMU and non-MMU cases
into arm_add_memory() to remove some duplication.  Protection against
overflowing the membank array is also moved in there in order to cover
the kernel cmdline parsing path as well.

Signed-off-by: Nicolas Pitre <nico@marvell.com>
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
  • Loading branch information
Nicolas Pitre authored and Russell King committed Nov 28, 2008
1 parent 43ae286 commit 4b5f32c
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 59 deletions.
6 changes: 4 additions & 2 deletions arch/arm/include/asm/setup.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,11 @@ struct meminfo {
struct membank bank[NR_BANKS];
};

extern struct meminfo meminfo;

#define for_each_nodebank(iter,mi,no) \
for (iter = 0; iter < mi->nr_banks; iter++) \
if (mi->bank[iter].node == 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)
Expand Down
37 changes: 21 additions & 16 deletions arch/arm/kernel/setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ static int __init fpe_setup(char *line)
__setup("fpe=", fpe_setup);
#endif

extern void paging_init(struct meminfo *, struct machine_desc *desc);
extern void paging_init(struct machine_desc *desc);
extern void reboot_setup(char *str);
extern void _text, _etext, __data_start, _edata, _end;

Expand Down Expand Up @@ -112,7 +112,6 @@ static struct stack stacks[NR_CPUS];
char elf_platform[ELF_PLATFORM_SIZE];
EXPORT_SYMBOL(elf_platform);

static struct meminfo meminfo __initdata = { 0, };
static const char *cpu_name;
static const char *machine_name;
static char __initdata command_line[COMMAND_LINE_SIZE];
Expand Down Expand Up @@ -367,21 +366,34 @@ static struct machine_desc * __init setup_machine(unsigned int nr)
return list;
}

static void __init arm_add_memory(unsigned long start, unsigned long size)
static int __init arm_add_memory(unsigned long start, unsigned long size)
{
struct membank *bank;
struct membank *bank = &meminfo.bank[meminfo.nr_banks];

if (meminfo.nr_banks >= NR_BANKS) {
printk(KERN_CRIT "NR_BANKS too low, "
"ignoring memory at %#lx\n", start);
return -EINVAL;
}

/*
* Ensure that start/size are aligned to a page boundary.
* Size is appropriately rounded down, start is rounded up.
*/
size -= start & ~PAGE_MASK;

bank = &meminfo.bank[meminfo.nr_banks++];

bank->start = PAGE_ALIGN(start);
bank->size = size & PAGE_MASK;
bank->node = PHYS_TO_NID(start);

/*
* Check whether this memory region has non-zero size or
* invalid node number.
*/
if (bank->size == 0 || bank->node >= MAX_NUMNODES)
return -EINVAL;

meminfo.nr_banks++;
return 0;
}

/*
Expand Down Expand Up @@ -539,14 +551,7 @@ __tagtable(ATAG_CORE, parse_tag_core);

static int __init parse_tag_mem32(const struct tag *tag)
{
if (meminfo.nr_banks >= NR_BANKS) {
printk(KERN_WARNING
"Ignoring memory bank 0x%08x size %dKB\n",
tag->u.mem.start, tag->u.mem.size / 1024);
return -EINVAL;
}
arm_add_memory(tag->u.mem.start, tag->u.mem.size);
return 0;
return arm_add_memory(tag->u.mem.start, tag->u.mem.size);
}

__tagtable(ATAG_MEM, parse_tag_mem32);
Expand Down Expand Up @@ -718,7 +723,7 @@ void __init setup_arch(char **cmdline_p)
memcpy(boot_command_line, from, COMMAND_LINE_SIZE);
boot_command_line[COMMAND_LINE_SIZE-1] = '\0';
parse_cmdline(cmdline_p, from);
paging_init(&meminfo, mdesc);
paging_init(mdesc);
request_standard_resources(&meminfo, mdesc);

#ifdef CONFIG_SMP
Expand Down
12 changes: 6 additions & 6 deletions arch/arm/mm/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,11 @@ static int __init parse_tag_initrd2(const struct tag *tag)
__tagtable(ATAG_INITRD2, parse_tag_initrd2);

/*
* This is used to pass memory configuration data from paging_init
* to mem_init, and by show_mem() to skip holes in the memory map.
* This keeps memory configuration data used by a couple memory
* initialization functions, as well as show_mem() for the skipping
* of holes in the memory map. It is populated by arm_add_memory().
*/
static struct meminfo meminfo = { 0, };
struct meminfo meminfo;

void show_mem(void)
{
Expand Down Expand Up @@ -331,13 +332,12 @@ static void __init bootmem_free_node(int node, struct meminfo *mi)
free_area_init_node(node, zone_size, start_pfn, zhole_size);
}

void __init bootmem_init(struct meminfo *mi)
void __init bootmem_init(void)
{
struct meminfo *mi = &meminfo;
unsigned long memend_pfn = 0;
int node, initrd_node;

memcpy(&meminfo, mi, sizeof(meminfo));

/*
* Locate which node contains the ramdisk image, if any.
*/
Expand Down
2 changes: 1 addition & 1 deletion arch/arm/mm/mm.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ struct meminfo;
struct pglist_data;

void __init create_mapping(struct map_desc *md);
void __init bootmem_init(struct meminfo *mi);
void __init bootmem_init(void);
void reserve_node_zero(struct pglist_data *pgdat);

extern void _text, _stext, _etext, __data_start, _end, __init_begin, __init_end;
29 changes: 11 additions & 18 deletions arch/arm/mm/mmu.c
Original file line number Diff line number Diff line change
Expand Up @@ -653,13 +653,6 @@ __early_param("vmalloc=", early_vmalloc);

static int __init check_membank_valid(struct membank *mb)
{
/*
* Check whether this memory region has non-zero size or
* invalid node number.
*/
if (mb->size == 0 || mb->node >= MAX_NUMNODES)
return 0;

/*
* Check whether this memory region would entirely overlap
* the vmalloc area.
Expand Down Expand Up @@ -689,18 +682,18 @@ static int __init check_membank_valid(struct membank *mb)
return 1;
}

static void __init sanity_check_meminfo(struct meminfo *mi)
static void __init sanity_check_meminfo(void)
{
int i, j;

for (i = 0, j = 0; i < mi->nr_banks; i++) {
if (check_membank_valid(&mi->bank[i]))
mi->bank[j++] = mi->bank[i];
for (i = 0, j = 0; i < meminfo.nr_banks; i++) {
if (check_membank_valid(&meminfo.bank[i]))
meminfo.bank[j++] = meminfo.bank[i];
}
mi->nr_banks = j;
meminfo.nr_banks = j;
}

static inline void prepare_page_table(struct meminfo *mi)
static inline void prepare_page_table(void)
{
unsigned long addr;

Expand All @@ -721,7 +714,7 @@ static inline void prepare_page_table(struct meminfo *mi)
* Clear out all the kernel space mappings, except for the first
* memory bank, up to the end of the vmalloc region.
*/
for (addr = __phys_to_virt(mi->bank[0].start + mi->bank[0].size);
for (addr = __phys_to_virt(bank_phys_end(&meminfo.bank[0]));
addr < VMALLOC_END; addr += PGDIR_SIZE)
pmd_clear(pmd_off_k(addr));
}
Expand Down Expand Up @@ -880,14 +873,14 @@ static void __init devicemaps_init(struct machine_desc *mdesc)
* paging_init() sets up the page tables, initialises the zone memory
* maps, and sets up the zero page, bad page and bad page tables.
*/
void __init paging_init(struct meminfo *mi, struct machine_desc *mdesc)
void __init paging_init(struct machine_desc *mdesc)
{
void *zero_page;

build_mem_type_table();
sanity_check_meminfo(mi);
prepare_page_table(mi);
bootmem_init(mi);
sanity_check_meminfo();
prepare_page_table();
bootmem_init();
devicemaps_init(mdesc);

top_pmd = pmd_off_k(0xffff0000);
Expand Down
18 changes: 2 additions & 16 deletions arch/arm/mm/nommu.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,27 +41,13 @@ void __init reserve_node_zero(pg_data_t *pgdat)
BOOTMEM_DEFAULT);
}

static void __init sanity_check_meminfo(struct meminfo *mi)
{
int i, j;

for (i = 0, j = 0; i < mi->nr_banks; i++) {
struct membank *mb = &mi->bank[i];

if (mb->size != 0 && mb->node < MAX_NUMNODES)
mi->bank[j++] = mi->bank[i];
}
mi->nr_banks = j;
}

/*
* paging_init() sets up the page tables, initialises the zone memory
* maps, and sets up the zero page, bad page and bad page tables.
*/
void __init paging_init(struct meminfo *mi, struct machine_desc *mdesc)
void __init paging_init(struct machine_desc *mdesc)
{
sanity_check_meminfo(mi);
bootmem_init(mi);
bootmem_init();
}

/*
Expand Down

0 comments on commit 4b5f32c

Please sign in to comment.