Skip to content

Commit

Permalink
MIPS: add detect_memory_region()
Browse files Browse the repository at this point in the history
Add a generic way of detecting the available RAM. This function is based on the
implementation already used by ath79.

Signed-off-by: John Crispin <blogic@openwrt.org>
Patchwork: http://patchwork.linux-mips.org/patch/5178/
  • Loading branch information
John Crispin authored and ralfbaechle committed May 7, 2013
1 parent 9d50094 commit 4d9f77d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions arch/mips/include/asm/bootinfo.h
Expand Up @@ -104,6 +104,7 @@ struct boot_mem_map {
extern struct boot_mem_map boot_mem_map;

extern void add_memory_region(phys_t start, phys_t size, long type);
extern void detect_memory_region(phys_t start, phys_t sz_min, phys_t sz_max);

extern void prom_init(void);
extern void prom_free_prom_memory(void);
Expand Down
22 changes: 22 additions & 0 deletions arch/mips/kernel/setup.c
Expand Up @@ -23,6 +23,7 @@
#include <linux/pfn.h>
#include <linux/debugfs.h>
#include <linux/kexec.h>
#include <linux/sizes.h>

#include <asm/addrspace.h>
#include <asm/bootinfo.h>
Expand Down Expand Up @@ -77,6 +78,8 @@ EXPORT_SYMBOL(mips_io_port_base);
static struct resource code_resource = { .name = "Kernel code", };
static struct resource data_resource = { .name = "Kernel data", };

static void *detect_magic __initdata = detect_memory_region;

void __init add_memory_region(phys_t start, phys_t size, long type)
{
int x = boot_mem_map.nr_map;
Expand Down Expand Up @@ -122,6 +125,25 @@ void __init add_memory_region(phys_t start, phys_t size, long type)
boot_mem_map.nr_map++;
}

void __init detect_memory_region(phys_t start, phys_t sz_min, phys_t sz_max)
{
void *dm = &detect_magic;
phys_t size;

for (size = sz_min; size < sz_max; size <<= 1) {
if (!memcmp(dm, dm + size, sizeof(detect_magic)))
break;
}

pr_debug("Memory: %lluMB of RAM detected at 0x%llx (min: %lluMB, max: %lluMB)\n",
((unsigned long long) size) / SZ_1M,
(unsigned long long) start,
((unsigned long long) sz_min) / SZ_1M,
((unsigned long long) sz_max) / SZ_1M);

add_memory_region(start, size, BOOT_MEM_RAM);
}

static void __init print_memory_map(void)
{
int i;
Expand Down

0 comments on commit 4d9f77d

Please sign in to comment.