1 From 2ccca2ac0b54eb21890412c888cf5a5bda656bba Mon Sep 17 00:00:00 2001
2 From: John Crispin <blogic@openwrt.org>
3 Date: Sat, 13 Apr 2013 13:15:47 +0200
4 Subject: [PATCH 121/164] MIPS: add detect_memory_region()
6 Add a generic way of detecting the available RAM. This function is based on the
7 implementation already used by ath79.
9 Signed-off-by: John Crispin <blogic@openwrt.org>
10 Patchwork: http://patchwork.linux-mips.org/patch/5178/
12 arch/mips/include/asm/bootinfo.h | 1 +
13 arch/mips/kernel/setup.c | 20 ++++++++++++++++++++
14 2 files changed, 21 insertions(+)
16 --- a/arch/mips/include/asm/bootinfo.h
17 +++ b/arch/mips/include/asm/bootinfo.h
18 @@ -104,6 +104,7 @@ struct boot_mem_map {
19 extern struct boot_mem_map boot_mem_map;
21 extern void add_memory_region(phys_t start, phys_t size, long type);
22 +extern void detect_memory_region(phys_t start, phys_t sz_min, phys_t sz_max);
24 extern void prom_init(void);
25 extern void prom_free_prom_memory(void);
26 --- a/arch/mips/kernel/setup.c
27 +++ b/arch/mips/kernel/setup.c
29 #include <linux/pfn.h>
30 #include <linux/debugfs.h>
31 #include <linux/kexec.h>
32 +#include <linux/sizes.h>
34 #include <asm/addrspace.h>
35 #include <asm/bootinfo.h>
36 @@ -122,6 +123,25 @@ void __init add_memory_region(phys_t sta
37 boot_mem_map.nr_map++;
40 +void __init detect_memory_region(phys_t start, phys_t sz_min, phys_t sz_max)
44 + for (size = sz_min; size < sz_max; size <<= 1) {
45 + if (!memcmp(detect_memory_region,
46 + detect_memory_region + size, 1024))
50 + pr_debug("Memory: %lluMB of RAM detected at 0x%llx (min: %lluMB, max: %lluMB)\n",
51 + ((unsigned long long) size) / SZ_1M,
52 + (unsigned long long) start,
53 + ((unsigned long long) sz_min) / SZ_1M,
54 + ((unsigned long long) sz_max) / SZ_1M);
56 + add_memory_region(start, size, BOOT_MEM_RAM);
59 static void __init print_memory_map(void)